Example #1
0
        public TileMap(List <Layer> layers, List <BGOVERLAY_DEF> overlayList, List <BGANIM_DEF> animList, uint factor)
        {
            Int32 minX, minY, maxX, maxY;

            TileMap.GetBounds(overlayList, 0, out minX, out minY, out maxX, out maxY);
            this.SizeX   = (maxX - minX) / 16;
            this.SizeY   = (maxY - minY) / 16;
            _cameraIndex = overlayList[0].camNdx;
            _overlays    = new Dictionary <int, Overlay>();
            _animList    = animList;

            bool[] animationArray = new bool[overlayList.Count];
            for (var m = 0; m < animList.Count; m++)
            {
                BGANIM_DEF animation = animList[m];
                for (var n = 0; n < animation.frameList.Count; n++)
                {
                    int index = animation.frameList[n].target;
                    animationArray[index] = true;
                }
            }
            for (int i = 0; i < overlayList.Count; i++)
            {
                BGOVERLAY_DEF info          = overlayList[i];
                Layer         layer         = layers[i];
                bool          animationFlag = animationArray[i];
                Overlay       overlay       = new Overlay(CopyBytesHelper.GetImageData(layer, info, factor), info, i, this.SizeX, this.SizeY, minX, minY, maxX, maxY, animationFlag);
                _overlays[i] = overlay;
            }

            TDMap = new TileDepthMap(_overlays, this.SizeX, this.SizeY);
        }
Example #2
0
 public void SetOffset(String name, List <BGOVERLAY_DEF> overlayList)
 {
     if (this.offsetDict.ContainsKey(name))
     {
         FieldMapExtraOffset.ExtraOffset[] array = this.offsetDict[name];
         for (Int32 i = 0; i < (Int32)array.Length; i++)
         {
             FieldMapExtraOffset.ExtraOffset extraOffset = array[i];
             if (extraOffset.spriteIndex == -1)
             {
                 BGOVERLAY_DEF bgoverlay_DEF = overlayList[extraOffset.overlayIndex];
                 bgoverlay_DEF.orgZ = (UInt16)(bgoverlay_DEF.orgZ + (UInt16)extraOffset.zOffset);
                 BGOVERLAY_DEF bgoverlay_DEF2 = overlayList[extraOffset.overlayIndex];
                 bgoverlay_DEF2.curZ = (UInt16)(bgoverlay_DEF2.curZ + (UInt16)extraOffset.zOffset);
             }
             else if (extraOffset.spriteIndex == -2)
             {
                 overlayList[extraOffset.overlayIndex].orgZ = (UInt16)extraOffset.zOffset;
                 overlayList[extraOffset.overlayIndex].curZ = (UInt16)extraOffset.zOffset;
             }
             else if (!(Localization.language == "Japanese") || !(name == "FBG_N18_GTRE_MAP360_GT_GRD_0") || extraOffset.overlayIndex != 12 || extraOffset.spriteIndex != 12)
             {
                 overlayList[extraOffset.overlayIndex].spriteList[extraOffset.spriteIndex].depth += extraOffset.zOffset;
             }
         }
     }
 }
Example #3
0
    private void _LoadDummyEBG(BGSCENE_DEF sceneUS, String path, String newName, FieldMapLocalizeAreaTitleInfo info, String localizeSymbol)
    {
        this.name = newName;
        TextAsset textAsset = AssetManager.Load <TextAsset>(String.Concat(path, newName, "_", localizeSymbol, ".bgs"), false);

        if (textAsset == null)
        {
            return;
        }
        this.ebgBin = textAsset.bytes;
        using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(this.ebgBin)))
        {
            this.ExtractHeaderData(binaryReader);
            this.ExtractOverlayData(binaryReader);
            Int32 atlasWidth       = info.atlasWidth;
            Int32 startOvrIdx      = info.startOvrIdx;
            Int32 endOvrIdx        = info.endOvrIdx;
            Int32 spriteStartIndex = info.GetSpriteStartIndex(localizeSymbol);
            Int32 num  = atlasWidth / 36;
            Int32 num2 = spriteStartIndex;
            for (Int32 i = startOvrIdx; i <= endOvrIdx; i++)
            {
                BGOVERLAY_DEF bGOVERLAY_DEF = this.overlayList[i];
                binaryReader.BaseStream.Seek(bGOVERLAY_DEF.prmOffset, SeekOrigin.Begin);
                for (Int32 j = 0; j < (Int32)bGOVERLAY_DEF.spriteCount; j++)
                {
                    BGSPRITE_LOC_DEF bGSPRITE_LOC_DEF = new BGSPRITE_LOC_DEF();
                    bGSPRITE_LOC_DEF.ReadData_BGSPRITE_DEF(binaryReader);
                    bGOVERLAY_DEF.spriteList.Add(bGSPRITE_LOC_DEF);
                }
                binaryReader.BaseStream.Seek(bGOVERLAY_DEF.locOffset, SeekOrigin.Begin);
                for (Int32 k = 0; k < (Int32)bGOVERLAY_DEF.spriteCount; k++)
                {
                    BGSPRITE_LOC_DEF bGSPRITE_LOC_DEF2 = bGOVERLAY_DEF.spriteList[k];
                    bGSPRITE_LOC_DEF2.ReadData_BGSPRITELOC_DEF(binaryReader);
                    if (this.useUpscaleFM)
                    {
                        bGSPRITE_LOC_DEF2.atlasX = (UInt16)(2 + num2 % num * 36);
                        bGSPRITE_LOC_DEF2.atlasY = (UInt16)(2 + num2 / num * 36);
                        bGSPRITE_LOC_DEF2.w      = 32;
                        bGSPRITE_LOC_DEF2.h      = 32;
                        num2++;
                    }
                }
            }
            for (Int32 l = startOvrIdx; l <= endOvrIdx; l++)
            {
                sceneUS.overlayList[l] = this.overlayList[l];
            }
        }
    }
Example #4
0
 private void ExtractOverlayData(BinaryReader reader)
 {
     reader.BaseStream.Seek(this.overlayOffset, SeekOrigin.Begin);
     for (Int32 i = 0; i < (Int32)this.overlayCount; i++)
     {
         BGOVERLAY_DEF bGOVERLAY_DEF = new BGOVERLAY_DEF();
         bGOVERLAY_DEF.ReadData(reader);
         bGOVERLAY_DEF.minX = -32768;
         bGOVERLAY_DEF.maxX = 32767;
         bGOVERLAY_DEF.minY = -32768;
         bGOVERLAY_DEF.maxY = 32767;
         this.overlayList.Add(bGOVERLAY_DEF);
     }
 }
Example #5
0
        public TileMap(int fieldMapNumber, List <Layer> layers, List <BGOVERLAY_DEF> overlayList, List <BGANIM_DEF> animList, List <BGLIGHT_DEF> lightList, int cameraIndex, uint factor)
        {
            Int32 minX, minY, maxX, maxY;

            TileMap.GetBounds(overlayList, cameraIndex, out minX, out minY, out maxX, out maxY);
            this.MinX       = minX;
            this.MinY       = minY;
            this.SizeX      = (maxX - minX) / 16 + 1;
            this.SizeY      = (maxY - minY) / 16 + 1;
            _fieldMapNumber = fieldMapNumber;
            _cameraIndex    = cameraIndex;
            _overlays       = new Dictionary <int, Overlay>();
            _animList       = animList;
            _lightList      = lightList;

            bool[] animationArray = new bool[overlayList.Count];
            for (var m = 0; m < animList.Count; m++)
            {
                BGANIM_DEF animation = animList[m];
                for (var n = 0; n < animation.frameList.Count; n++)
                {
                    int index = animation.frameList[n].target;
                    animationArray[index] = true;
                }
            }
            for (var m = 0; m < lightList.Count; m++)
            {
                BGLIGHT_DEF lightDef = lightList[m];
            }
            for (int i = 0; i < overlayList.Count; i++)
            {
                BGOVERLAY_DEF info = overlayList[i];
                if (info.camNdx != _cameraIndex)
                {
                    continue;
                }
                Layer   layer         = layers[i];
                bool    animationFlag = animationArray[i];
                bool    isLight       = false;
                Overlay overlay       = new Overlay(CopyBytesHelper.GetImageData(layer, info, factor), info, i, this.SizeX, this.SizeY, minX, minY, maxX, maxY, animationFlag);
                _overlays[i] = overlay;
            }

            TDMap = new TileDepthMap(_overlays, this.SizeX, this.SizeY);
        }
Example #6
0
    private void ExtractSpriteData(BinaryReader reader)
    {
        this.spriteCount = 0;
        for (Int32 i = 0; i < (Int32)this.overlayCount; i++)
        {
            BGOVERLAY_DEF bGOVERLAY_DEF = this.overlayList[i];
            this.spriteCount += bGOVERLAY_DEF.spriteCount;
        }
        if (this.useUpscaleFM)
        {
            this.ATLAS_H = (UInt32)this.atlas.height;
            this.ATLAS_W = (UInt32)this.atlas.width;
        }
        Int32 num  = this.atlas.width / 36;
        Int32 num2 = 0;

        for (Int32 j = 0; j < (Int32)this.overlayCount; j++)
        {
            BGOVERLAY_DEF bGOVERLAY_DEF2 = this.overlayList[j];
            reader.BaseStream.Seek(bGOVERLAY_DEF2.prmOffset, SeekOrigin.Begin);
            for (Int32 k = 0; k < (Int32)bGOVERLAY_DEF2.spriteCount; k++)
            {
                BGSPRITE_LOC_DEF bGSPRITE_LOC_DEF = new BGSPRITE_LOC_DEF();
                bGSPRITE_LOC_DEF.ReadData_BGSPRITE_DEF(reader);
                bGOVERLAY_DEF2.spriteList.Add(bGSPRITE_LOC_DEF);
            }
            reader.BaseStream.Seek(bGOVERLAY_DEF2.locOffset, SeekOrigin.Begin);
            for (Int32 l = 0; l < (Int32)bGOVERLAY_DEF2.spriteCount; l++)
            {
                BGSPRITE_LOC_DEF bGSPRITE_LOC_DEF2 = bGOVERLAY_DEF2.spriteList[l];
                bGSPRITE_LOC_DEF2.ReadData_BGSPRITELOC_DEF(reader);
                if (this.useUpscaleFM)
                {
                    bGSPRITE_LOC_DEF2.atlasX = (UInt16)(2 + num2 % num * 36);
                    bGSPRITE_LOC_DEF2.atlasY = (UInt16)(2 + num2 / num * 36);
                    bGSPRITE_LOC_DEF2.w      = 32;
                    bGSPRITE_LOC_DEF2.h      = 32;
                    num2++;
                }
            }
        }
    }
Example #7
0
    public void SaveFieldMap()
    {
        BGSCENE_DEF scene = this.fieldMap.scene;

        Byte[] ebgBin          = scene.ebgBin;
        String mapName         = this.fieldMap.mapName;
        String fieldMapModName = FieldMapEditor.GetFieldMapModName(mapName);
        String mapResourcePath = FieldMap.GetMapResourcePath(mapName);

        using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(ebgBin)))
        {
            for (Int32 i = 0; i < (Int32)scene.overlayCount; i++)
            {
                BGOVERLAY_DEF bgoverlay_DEF = scene.overlayList[i];
                UInt32        oriData       = bgoverlay_DEF.oriData;
                UInt16        num           = (UInt16)bgoverlay_DEF.transform.localPosition.z;
                UInt16        num2          = (UInt16)(oriData >> 8 & 4095u);
                UInt32        num3          = oriData;
                UInt32        num4          = 1048320u;
                num3 &= ~num4;
                num3 |= (UInt32)((Int64)((Int64)num << 8) & (Int64)((UInt64)num4));
                global::Debug.Log(String.Concat(new Object[]
                {
                    i,
                    " : data  :",
                    oriData,
                    ", curZ : ",
                    num,
                    ", oriZ : ",
                    num2,
                    ", res : ",
                    num3
                }));
                binaryWriter.BaseStream.Seek(bgoverlay_DEF.startOffset, SeekOrigin.Begin);
                binaryWriter.Write(num3);
            }
        }
        String path = "Assets/Resources/" + mapResourcePath + fieldMapModName + ".bgs.bytes";

        File.WriteAllBytes(path, ebgBin);
    }
Example #8
0
 private static void GetBounds(List <BGOVERLAY_DEF> overlayList, int camIndex, out Int32 minX, out Int32 minY, out Int32 maxX, out Int32 maxY)
 {
     maxX = Int32.MinValue;
     minX = Int32.MaxValue;
     maxY = Int32.MinValue;
     minY = Int32.MaxValue;
     for (int i = 0; i < overlayList.Count; i++)
     {
         BGOVERLAY_DEF overlay = overlayList[i];
         if (camIndex != overlay.camNdx)
         {
             continue;
         }
         for (int k = 0; k < overlay.spriteList.Count; k++)
         {
             BGSPRITE_LOC_DEF sprite = overlay.spriteList[k];
             int offX = sprite.offX + overlay.curX;
             int offY = sprite.offY + overlay.curY;
             if (offX < minX)
             {
                 minX = offX;
             }
             if (offX > maxX)
             {
                 maxX = offX;
             }
             if (offY < minY)
             {
                 minY = offY;
             }
             if (offY > maxY)
             {
                 maxY = offY;
             }
         }
     }
 }
Example #9
0
 public Overlay(byte[] layerImageData, BGOVERLAY_DEF overlayInfo, int orderNumber,
                int sizeX, int sizeY, Int32 minX, Int32 minY, Int32 maxX, Int32 maxY, bool animationFlag)
 {
     info           = overlayInfo;
     imageData      = layerImageData;
     _orderNumber   = orderNumber;
     _map           = new Tile[sizeX, sizeY];
     _sizeX         = sizeX;
     _sizeY         = sizeY;
     _animationFlag = animationFlag;
     _isAlpha       = false;
     if (info.spriteList.Count > 0 && info.spriteList[0].alpha != 0)
     {
         _isAlpha = true;
     }
     for (var k = 0; k < info.spriteList.Count; k++)
     {
         Tile tileToPush = new Tile();
         tileToPush.info = info.spriteList[k];
         BGSPRITE_LOC_DEF spriteInfo = info.spriteList[k];
         tileToPush.x       = (info.orgX + spriteInfo.offX - minX) / 16; // get global x
         tileToPush.y       = (info.orgY + spriteInfo.offY - minY) / 16; // get global y
         tileToPush.overlay = this;
         _map[tileToPush.x, tileToPush.y] = tileToPush;
     }
     // for debug
     //Log.Message($"Overlay {orderNumber} map");
     //for(var j = 0; j < _sizeY; j++)
     //{
     //    String str = "";
     //    for(var i = 0; i < _sizeX; i++)
     //    {
     //        str += _map[i, j].info == null ? "0" : "1";
     //    }
     //    Log.Message(str);
     //}
 }
Example #10
0
        private static void ExportMapSafe(String mapName)
        {
            try
            {
                String relativePath    = FieldMap.GetMapResourcePath(mapName);
                String outputDirectory = Path.Combine(Configuration.Export.Path, relativePath);
                if (Directory.Exists(outputDirectory))
                {
                    Log.Warning($"Export was not skipped because kostyli");
                    //Log.Warning($"[FieldSceneExporter] Export was skipped bacause a directory already exists: [{outputDirectory}].");
                    //return;
                }

                Log.Message("[FieldSceneExporter] Exporting [{0}]...", mapName);

                BGSCENE_DEF scene = new BGSCENE_DEF(true);
                scene.LoadEBG(null, relativePath, mapName);

                //String directoryPath = Path.GetDirectoryName(outputPath);
                Directory.CreateDirectory(outputDirectory);

                Texture2D atlasTexture  = TextureHelper.CopyAsReadable(scene.atlas);
                Int32     factor        = (Int32)scene.SPRITE_W / 16;
                Int32     textureWidth  = (Int32)(scene.overlayList.SelectMany(s => s.spriteList).Max(s => s.offY * factor) + scene.SPRITE_H);
                Int32     textureHeight = (Int32)(scene.overlayList.SelectMany(s => s.spriteList).Max(s => s.offX * factor) + scene.SPRITE_W);

                using (Stream output = File.Create(outputDirectory + "test.psd"))
                {
                    PsdFile file = new PsdFile();
                    file.BitDepth     = 8;
                    file.ChannelCount = 4;
                    file.ColorMode    = PsdColorMode.Rgb;
                    file.RowCount     = textureWidth;
                    file.ColumnCount  = textureHeight;
                    file.Resolution   = new ResolutionInfo
                    {
                        Name = "ResolutionInfo ",

                        HDpi              = new UFixed1616(72, 0),
                        HResDisplayUnit   = ResolutionInfo.ResUnit.PxPerInch,
                        HeightDisplayUnit = ResolutionInfo.Unit.Centimeters,

                        VDpi             = new UFixed1616(72, 0),
                        VResDisplayUnit  = ResolutionInfo.ResUnit.PxPerInch,
                        WidthDisplayUnit = ResolutionInfo.Unit.Centimeters
                    };

                    file.BaseLayer.Name = "Base";
                    for (Int16 i = 0; i < 4; i++)
                    {
                        Channel channel = new Channel(i, file.BaseLayer);
                        channel.ImageCompression = file.ImageCompression;
                        channel.Length           = file.RowCount * Util.BytesPerRow(file.BaseLayer.Rect.Size, file.BitDepth);
                        channel.ImageData        = new Byte[channel.Length];
                        file.BaseLayer.Channels.Add(channel);
                    }

                    file.BaseLayer.Channels.Last().ID = -1;

                    for (Int32 index = scene.overlayList.Count - 1; index >= 0; index--) //scene.overlayList.Count
                    {
                        BGOVERLAY_DEF overlay    = scene.overlayList[index];
                        String        outputPath = outputDirectory + $"Overlay{index}.png";
                        ExportOverlayTest(overlay, atlasTexture, outputPath, scene, file);
                        //return;
                    }

                    file.Save(output, Encoding.UTF8);
                }

                //TextureHelper.WriteTextureToFile(TextureHelper.CopyAsReadable(scene.atlas), outputPath);

                Log.Message("[FieldSceneExporter] Exporting completed successfully.");
            }
            catch (Exception ex)
            {
                Log.Error(ex, "[FieldSceneExporter] Failed to export map [{0}].", mapName);
            }
        }
Example #11
0
        private static void ExportOverlayTest(BGOVERLAY_DEF overlay, Texture2D atlas, String outputPath, BGSCENE_DEF scene, PsdFile psd)
        {
            Int32 factor = (Int32)scene.SPRITE_W / 16;

            Log.Message($"Transform: {overlay.transform?.name}, Factor: {factor}");
            Log.Message($"SPRITE_H: {scene.SPRITE_H:D2} SPRITE_W {scene.SPRITE_W:D2}");
            if (overlay.spriteList.Count < 1)
            {
                Log.Message("Overlay is empty.");
                return;
            }

            Layer layer = new Layer(psd);

            psd.Layers.Add(layer);

            Int32     textureWidth  = (Int32)(overlay.spriteList.Max(s => s.offX * factor) + scene.SPRITE_W);
            Int32     textureHeight = (Int32)(overlay.spriteList.Max(s => s.offY * factor) + scene.SPRITE_H);
            Texture2D result        = new Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false);
            //Log.Message("depth;h;w;u;v;offX;offY;oriData;pad;res;startOffset;texX;texY;trans;localPosition;name");

            Channel r = new Channel(0, layer);
            Channel g = new Channel(1, layer);
            Channel b = new Channel(2, layer);
            Channel a = new Channel(-1, layer);

            layer.Channels.Add(r);
            layer.Channels.Add(g);
            layer.Channels.Add(b);
            layer.Channels.Add(a);

            Int32 channelSize = textureWidth * textureHeight;

            r.Length    = channelSize;
            g.Length    = channelSize;
            b.Length    = channelSize;
            a.Length    = channelSize;
            r.ImageData = new Byte[channelSize];
            g.ImageData = new Byte[channelSize];
            b.ImageData = new Byte[channelSize];
            a.ImageData = new Byte[channelSize];

            foreach (BGSPRITE_LOC_DEF s in overlay.spriteList)
            {
                //Log.Message($"{s.depth};{s.h};{s.w};{s.u};{s.v};{s.offX};{s.offY};{s.oriData};{s.pad};{s.res};{s.startOffset};{s.texX};{s.texY};{s.trans};{s.transform?.localPosition};{s.transform?.name}");

                Int32 w = (Int32)scene.SPRITE_W;
                Int32 h = (Int32)scene.SPRITE_H;

                Int32   sx     = s.atlasX;
                Int32   sy     = (Int32)(scene.ATLAS_H - s.atlasY + 1 * factor - scene.SPRITE_H);
                Color[] pixels = atlas.GetPixels(sx, sy, w, h);

                Int32 tx = s.offX * factor;
                Int32 ty = textureHeight - s.offY * factor;
                result.SetPixels(tx, ty, w, h, pixels);

                for (Int32 y = 0; y < h; y++)
                {
                    for (Int32 x = 0; x < w; x++)
                    {
                        Int32 sourceOffset = (h - y - 1) * w + x;
                        Int32 targetOffset = (s.offY * factor + y) * textureWidth + tx + x;

                        Color color = pixels[sourceOffset];
                        r.ImageData[targetOffset] = (Byte)(color.r * 255);
                        g.ImageData[targetOffset] = (Byte)(color.g * 255);
                        b.ImageData[targetOffset] = (Byte)(color.b * 255);
                        a.ImageData[targetOffset] = (Byte)(color.a * 255);
                    }
                }

                //result.ReadPixels(new Rect(s.atlasX, s.atlasY, scene.SPRITE_W, scene.SPRITE_H), s.offX * factor, textureHeight - s.offY * factor);
            }
            TextureHelper.WriteTextureToFile(result, outputPath);

            layer.Name               = Path.GetFileNameWithoutExtension(outputPath);
            layer.Opacity            = 255;
            layer.Rect               = new System.Drawing.Rectangle(overlay.curX * factor, overlay.curY * factor, textureWidth, textureHeight);
            layer.Masks              = new MaskInfo();
            layer.BlendingRangesData = new BlendingRanges(layer);
            layer.CreateMissingChannels();
        }
Example #12
0
    private void CreateScene(FieldMap fieldMap, Boolean UseUpscalFM)
    {
        GameObject gameObject = new GameObject("Background");

        gameObject.transform.parent        = fieldMap.transform;
        gameObject.transform.localPosition = new Vector3(this.curX - 160f, -(this.curY - 112f), this.curZ);
        gameObject.transform.localScale    = new Vector3(1f, -1f, 1f);
        for (Int32 i = 0; i < this.cameraList.Count; i++)
        {
            BGCAM_DEF  bGCAM_DEF   = this.cameraList[i];
            GameObject gameObject2 = new GameObject(String.Concat("Camera_", i.ToString("D2"), " : ", bGCAM_DEF.vrpMaxX + 160f, " x ", bGCAM_DEF.vrpMaxY + 112f));
            Transform  transform   = gameObject2.transform;
            transform.parent    = gameObject.transform;
            bGCAM_DEF.transform = transform;
            bGCAM_DEF.transform.localPosition = Vector3.zero;
            bGCAM_DEF.transform.localScale    = new Vector3(1f, 1f, 1f);
        }
        List <Vector3> list  = new List <Vector3>();
        List <Vector2> list2 = new List <Vector2>();
        List <Int32>   list3 = new List <Int32>();

        for (Int32 j = 0; j < this.overlayList.Count; j++)
        {
            BGOVERLAY_DEF bGOVERLAY_DEF = this.overlayList[j];
            String        str           = "Overlay_" + j.ToString("D2");
            GameObject    gameObject3   = new GameObject(str);
            Transform     transform2    = gameObject3.transform;
            transform2.parent        = this.cameraList[bGOVERLAY_DEF.camNdx].transform;
            transform2.localPosition = new Vector3(bGOVERLAY_DEF.curX * 1f, bGOVERLAY_DEF.curY * 1f, bGOVERLAY_DEF.curZ);
            transform2.localScale    = new Vector3(1f, 1f, 1f);
            bGOVERLAY_DEF.transform  = transform2;
            for (Int32 k = 0; k < bGOVERLAY_DEF.spriteList.Count; k++)
            {
                BGSPRITE_LOC_DEF bGSPRITE_LOC_DEF = bGOVERLAY_DEF.spriteList[k];
                var        num         = bGSPRITE_LOC_DEF.depth;
                GameObject gameObject4 = new GameObject(str + "_Sprite_" + k.ToString("D3"));
                Transform  transform3  = gameObject4.transform;
                transform3.parent = transform2;
                {
                    transform3.localPosition = new Vector3(bGSPRITE_LOC_DEF.offX * 1f, (bGSPRITE_LOC_DEF.offY + 16) * 1f, num);
                }
                transform3.localScale      = new Vector3(1f, 1f, 1f);
                bGSPRITE_LOC_DEF.transform = transform3;
                list.Clear();
                list2.Clear();
                list3.Clear();
                list.Add(new Vector3(0f, -16f, 0f));
                list.Add(new Vector3(16f, -16f, 0f));
                list.Add(new Vector3(16f, 0f, 0f));
                list.Add(new Vector3(0f, 0f, 0f));
                Single num2 = this.ATLAS_W;
                Single num3 = this.ATLAS_H;
                Single x;
                Single y;
                Single x2;
                Single y2;
                if (UseUpscalFM)
                {
                    Single num4 = 0.5f;
                    x  = (bGSPRITE_LOC_DEF.atlasX - num4) / num2;
                    y  = (this.ATLAS_H - bGSPRITE_LOC_DEF.atlasY + num4) / num3;
                    x2 = (bGSPRITE_LOC_DEF.atlasX + this.SPRITE_W - num4) / num2;
                    y2 = (this.ATLAS_H - (bGSPRITE_LOC_DEF.atlasY + this.SPRITE_H) + num4) / num3;
                }
                else
                {
                    Single num5 = 0.5f;
                    x  = (bGSPRITE_LOC_DEF.atlasX + num5) / num2;
                    y  = (bGSPRITE_LOC_DEF.atlasY + num5) / num3;
                    x2 = (bGSPRITE_LOC_DEF.atlasX + this.SPRITE_W - num5) / num2;
                    y2 = (bGSPRITE_LOC_DEF.atlasY + this.SPRITE_H - num5) / num3;
                }
                list2.Add(new Vector2(x, y));
                list2.Add(new Vector2(x2, y));
                list2.Add(new Vector2(x2, y2));
                list2.Add(new Vector2(x, y2));
                list3.Add(2);
                list3.Add(1);
                list3.Add(0);
                list3.Add(3);
                list3.Add(2);
                list3.Add(0);
                Mesh mesh = new Mesh
                {
                    vertices  = list.ToArray(),
                    uv        = list2.ToArray(),
                    triangles = list3.ToArray()
                };
                MeshRenderer meshRenderer = gameObject4.AddComponent <MeshRenderer>();
                MeshFilter   meshFilter   = gameObject4.AddComponent <MeshFilter>();
                meshFilter.mesh = mesh;
                Int32      num6     = this.curZ + (Int16)bGOVERLAY_DEF.curZ + bGSPRITE_LOC_DEF.depth;
                GameObject expr_5B4 = gameObject4;
                expr_5B4.name = expr_5B4.name + "_Depth(" + num6.ToString("D5") + ")";
                String text;
                if (bGSPRITE_LOC_DEF.trans != 0)
                {
                    if (bGSPRITE_LOC_DEF.alpha == 0)
                    {
                        text = "abr_0";
                    }
                    else if (bGSPRITE_LOC_DEF.alpha == 1)
                    {
                        text = "abr_1";
                    }
                    else if (bGSPRITE_LOC_DEF.alpha == 2)
                    {
                        text = "abr_2";
                    }
                    else
                    {
                        text = "abr_3";
                    }
                }
                else
                {
                    text = "abr_none";
                }
                if (fieldMap.mapName == "FBG_N39_UUVL_MAP671_UV_DEP_0" && j == 14)
                {
                    text = "abr_none";
                }
                GameObject expr_671 = gameObject4;
                expr_671.name         = expr_671.name + "_[" + text + "]";
                meshRenderer.material = this.materialList[text];
            }
            bGOVERLAY_DEF.transform.gameObject.SetActive((bGOVERLAY_DEF.flags & 2) != 0);
        }
        for (Int32 l = 0; l < this.animList.Count; l++)
        {
            BGANIM_DEF bGANIM_DEF = this.animList[l];
            for (Int32 m = 0; m < bGANIM_DEF.frameList.Count; m++)
            {
                GameObject gameObject5 = this.overlayList[bGANIM_DEF.frameList[m].target].transform.gameObject;
                GameObject expr_754    = gameObject5;
                expr_754.name = expr_754.name + "_[anim_" + l.ToString("D2") + "]";
                GameObject expr_77C = gameObject5;
                String     text2    = expr_77C.name;
                expr_77C.name = String.Concat(text2, "_[frame_", m.ToString("D2"), "_of_", bGANIM_DEF.frameList.Count.ToString("D2"), "]");
            }
        }
    }
Example #13
0
    private void GenerateAtlasFromBinary()
    {
        UInt32 num = this.ATLAS_W * this.ATLAS_H;

        Color32[] array = new Color32[num];
        UInt32    num2  = 0u;
        UInt32    num3  = 1u;

        for (Int32 i = 0; i < (Int32)this.overlayCount; i++)
        {
            BGOVERLAY_DEF bGOVERLAY_DEF = this.overlayList[i];
            for (Int32 j = 0; j < (Int32)bGOVERLAY_DEF.spriteCount; j++)
            {
                BGSPRITE_LOC_DEF bGSPRITE_LOC_DEF = bGOVERLAY_DEF.spriteList[j];
                bGSPRITE_LOC_DEF.atlasX = (UInt16)num2;
                bGSPRITE_LOC_DEF.atlasY = (UInt16)num3;
                if (bGSPRITE_LOC_DEF.res == 0)
                {
                    Int32 index = ArrayUtil.GetIndex(bGSPRITE_LOC_DEF.clutX * 16, bGSPRITE_LOC_DEF.clutY, (Int32)this.vram.width, (Int32)this.vram.height);
                    for (UInt32 num4 = 0u; num4 < (UInt32)bGSPRITE_LOC_DEF.h; num4 += 1u)
                    {
                        Int32  index2 = ArrayUtil.GetIndex(bGSPRITE_LOC_DEF.texX * 64 + bGSPRITE_LOC_DEF.u / 4, (Int32)(bGSPRITE_LOC_DEF.texY * 256u + bGSPRITE_LOC_DEF.v + num4), (Int32)this.vram.width, (Int32)this.vram.height);
                        Int32  index3 = ArrayUtil.GetIndex((Int32)num2, (Int32)(num3 + num4), (Int32)this.ATLAS_W, (Int32)this.ATLAS_H);
                        UInt32 num5   = 0u;
                        while (num5 < (UInt64)(bGSPRITE_LOC_DEF.w / 2))
                        {
                            Byte   b    = this.vram.rawData[index2 * 2 + (Int32)num5];
                            Byte   b2   = (Byte)(b & 15);
                            Byte   b3   = (Byte)(b >> 4 & 15);
                            Int32  num6 = (index + b2) * 2;
                            UInt16 num7 = (UInt16)(this.vram.rawData[num6] | this.vram.rawData[num6 + 1] << 8);
                            Int32  num8 = index3 + (Int32)(num5 * 2u);
                            ConvertColor16toColor32(num7, out array[num8]);
                            if (bGSPRITE_LOC_DEF.trans != 0 && num7 != 0)
                            {
                                if (bGSPRITE_LOC_DEF.alpha == 0)
                                {
                                    array[num8].a = 127;
                                }
                                else if (bGSPRITE_LOC_DEF.alpha == 3)
                                {
                                    array[num8].a = 63;
                                }
                            }
                            num6 = (index + b3) * 2;
                            num7 = (UInt16)(this.vram.rawData[num6] | this.vram.rawData[num6 + 1] << 8);
                            num8 = index3 + (Int32)(num5 * 2u) + 1;
                            ConvertColor16toColor32(num7, out array[num8]);
                            if (bGSPRITE_LOC_DEF.trans != 0 && num7 != 0)
                            {
                                if (bGSPRITE_LOC_DEF.alpha == 0)
                                {
                                    array[num8].a = 127;
                                }
                                else if (bGSPRITE_LOC_DEF.alpha == 3)
                                {
                                    array[num8].a = 63;
                                }
                            }
                            num5 += 1u;
                        }
                    }
                }
                else if (bGSPRITE_LOC_DEF.res == 1)
                {
                    Int32 index4 = ArrayUtil.GetIndex(bGSPRITE_LOC_DEF.clutX * 16, bGSPRITE_LOC_DEF.clutY, (Int32)this.vram.width, (Int32)this.vram.height);
                    for (UInt32 num9 = 0u; num9 < (UInt32)bGSPRITE_LOC_DEF.h; num9 += 1u)
                    {
                        Int32 index5 = ArrayUtil.GetIndex(bGSPRITE_LOC_DEF.texX * 64 + bGSPRITE_LOC_DEF.u / 2, (Int32)(bGSPRITE_LOC_DEF.texY * 256u + bGSPRITE_LOC_DEF.v + num9), (Int32)this.vram.width, (Int32)this.vram.height);
                        Int32 index6 = ArrayUtil.GetIndex((Int32)num2, (Int32)(num3 + num9), (Int32)this.ATLAS_W, (Int32)this.ATLAS_H);
                        for (UInt32 num10 = 0u; num10 < (UInt32)bGSPRITE_LOC_DEF.w; num10 += 1u)
                        {
                            Byte   b4    = this.vram.rawData[index5 * 2 + (Int32)num10];
                            Int32  num11 = (index4 + b4) * 2;
                            UInt16 num12 = (UInt16)(this.vram.rawData[num11] | this.vram.rawData[num11 + 1] << 8);
                            Int32  num13 = index6 + (Int32)num10;
                            ConvertColor16toColor32(num12, out array[num13]);
                            if (bGSPRITE_LOC_DEF.trans != 0 && num12 != 0)
                            {
                                if (bGSPRITE_LOC_DEF.alpha == 0)
                                {
                                    array[num13].a = 127;
                                }
                                else if (bGSPRITE_LOC_DEF.alpha == 3)
                                {
                                    array[num13].a = 63;
                                }
                            }
                        }
                    }
                }
                for (UInt32 num14 = 0u; num14 < (UInt32)bGSPRITE_LOC_DEF.h; num14 += 1u)
                {
                    Int32 index7 = ArrayUtil.GetIndex((Int32)(num2 + this.SPRITE_W), (Int32)(num3 + num14), (Int32)this.ATLAS_W, (Int32)this.ATLAS_H);
                    array[index7] = array[index7 - 1];
                }
                for (UInt32 num15 = 0u; num15 < (UInt32)bGSPRITE_LOC_DEF.w; num15 += 1u)
                {
                    Int32 index8 = ArrayUtil.GetIndex((Int32)(num2 + num15), (Int32)num3, (Int32)this.ATLAS_W, (Int32)this.ATLAS_H);
                    Int32 index9 = ArrayUtil.GetIndex((Int32)(num2 + num15), (Int32)(num3 - 1u), (Int32)this.ATLAS_W, (Int32)this.ATLAS_H);
                    array[index9] = array[index8];
                }
                Int32 index10 = ArrayUtil.GetIndex((Int32)(num2 + this.SPRITE_W - 1u), (Int32)num3, (Int32)this.ATLAS_W, (Int32)this.ATLAS_H);
                Int32 index11 = ArrayUtil.GetIndex((Int32)(num2 + this.SPRITE_W), (Int32)(num3 - 1u), (Int32)this.ATLAS_W, (Int32)this.ATLAS_H);
                array[index11] = array[index10];
                num2          += this.SPRITE_W + 1u;
                if (num2 >= this.ATLAS_W || this.ATLAS_W - num2 < this.SPRITE_W + 1u)
                {
                    num2  = 0u;
                    num3 += this.SPRITE_H + 1u;
                }
            }
        }
        this.atlas.SetPixels32(array);
        this.atlas.Apply();
    }
Example #14
0
        public static byte[] GetImageData(Layer layer, BGOVERLAY_DEF overlayInfo, uint factor)
        {
            int SPRITE_H = 16 * (int)factor;
            int SPRITE_W = 16 * (int)factor;

            long overlayHeight = overlayInfo.h * factor;
            long overlayWidth  = overlayInfo.w * factor;

            Rectangle rect             = layer.Rect;
            long      left             = overlayInfo.curX;
            long      right            = left + overlayInfo.w;
            long      top              = overlayInfo.curY;
            long      bottom           = top + overlayInfo.h;
            long      product          = overlayHeight * overlayWidth;
            long      verticalOffset   = (SPRITE_H - rect.Bottom % SPRITE_H) % SPRITE_H;
            long      horizontalOffset = rect.Left % SPRITE_W;
            Rectangle currentRect      = layer.Rect;

            // fill overlay with transparency

            byte[] layerbytes = new byte[product * 4];
            for (var i = 0; i < product * 4; i++)
            {
                if (i % 4 == 3)
                {
                    layerbytes[i] = 0;
                }
                layerbytes[i] = 1;
            }

            Int32 width = rect.Width, height = rect.Height;
            Int32 initialCorrection = (Int32)(overlayWidth * (verticalOffset) + horizontalOffset);
            long  initialX          = currentRect.Left - left * factor;
            long  initialY          = bottom * factor - currentRect.Bottom;

            foreach (var channel in layer.Channels)
            {
                byte[] imgdata = channel.ImageData;
                Int32  offset  = channel.ID;
                if (offset == -1)
                {
                    offset = 3;
                }
                // rows are flipped vertically in
                for (var y = 0; y < rect.Height; y++)
                {
                    for (var x = 0; x < width; x++)
                    {
                        var dstCoordX = x + initialX;
                        if (dstCoordX < 0 || dstCoordX > overlayWidth - 1)
                        {
                            continue;
                        }
                        var dstCoordY = rect.Height - y - 1 + initialY;
                        if (dstCoordY < 0 || dstCoordY > overlayHeight - 1)
                        {
                            continue;
                        }
                        var dstIndex = (dstCoordY * overlayWidth + dstCoordX) * 4;
                        layerbytes[dstIndex + offset] = imgdata[x + y * width];
                    }
                }
            }
            return(layerbytes);
        }
Example #15
0
        private static void ExportMapSafe(String mapName)
        {
            try
            {
                String relativePath    = FieldMap.GetMapResourcePath(mapName);
                String outputDirectory = Path.Combine(Configuration.Export.Path, relativePath);
                // TODO: uncomment this when all is well
                //if (Directory.Exists(outputDirectory))
                //{

                //    Log.Warning($"[FieldSceneExporter] Export was skipped bacause a directory already exists: [{outputDirectory}].");
                //    //return;
                //}

                Log.Message("[FieldSceneExporter] Exporting [{0}]...", mapName);

                BGSCENE_DEF scene = new BGSCENE_DEF(true);
                scene.LoadResources(null, relativePath, mapName);

                //String directoryPath = Path.GetDirectoryName(outputPath);

                Directory.CreateDirectory(outputDirectory);

                Texture2D atlasTexture  = TextureHelper.CopyAsReadable(scene.atlas);
                Int32     factor        = (Int32)scene.SPRITE_W / 16;
                Int32     textureWidth  = (Int32)(scene.overlayList.SelectMany(s => s.spriteList).Max(s => s.offY * factor) + scene.SPRITE_H);
                Int32     textureHeight = (Int32)(scene.overlayList.SelectMany(s => s.spriteList).Max(s => s.offX * factor) + scene.SPRITE_W);

                using (Stream output = File.Create(outputDirectory + "test.psd"))
                {
                    PsdFile file = new PsdFile();
                    file.BitDepth     = 8;
                    file.ChannelCount = 4;
                    file.ColorMode    = PsdColorMode.Rgb;
                    file.RowCount     = textureWidth;
                    file.ColumnCount  = textureHeight;
                    file.Resolution   = new ResolutionInfo
                    {
                        Name = "ResolutionInfo ",

                        HDpi              = new UFixed1616(72, 0),
                        HResDisplayUnit   = ResolutionInfo.ResUnit.PxPerInch,
                        HeightDisplayUnit = ResolutionInfo.Unit.Centimeters,

                        VDpi             = new UFixed1616(72, 0),
                        VResDisplayUnit  = ResolutionInfo.ResUnit.PxPerInch,
                        WidthDisplayUnit = ResolutionInfo.Unit.Centimeters
                    };

                    file.BaseLayer.Name = "Base";
                    for (Int16 i = 0; i < 4; i++)
                    {
                        Channel channel = new Channel(i, file.BaseLayer);
                        channel.ImageCompression = file.ImageCompression;
                        channel.Length           = file.RowCount * Util.BytesPerRow(file.BaseLayer.Rect.Size, file.BitDepth);
                        channel.ImageData        = new Byte[channel.Length];
                        file.BaseLayer.Channels.Add(channel);
                    }

                    file.BaseLayer.Channels.Last().ID = -1;

                    for (Int32 index = scene.overlayList.Count - 1; index >= 0; index--) //scene.overlayList.Count
                    {
                        BGOVERLAY_DEF overlay    = scene.overlayList[index];
                        String        outputPath = outputDirectory + $"Overlay{index}.png";
                        ExportOverlay(overlay, atlasTexture, outputPath, scene, file);
                    }

                    // get all languages
                    FieldMapLocalizeAreaTitleInfo info = FieldMapInfo.localizeAreaTitle.GetInfo(mapName);
                    if (info != null)
                    {
                        Int32    startOvrIdx  = info.startOvrIdx;
                        Int32    endOvrIdx    = info.endOvrIdx;
                        String[] allLanguages = Configuration.Export.Languages;
                        foreach (var language in allLanguages)
                        {
                            BGSCENE_DEF localeScene = new BGSCENE_DEF(scene.GetUseUpscaleFM());
                            localeScene.LoadLocale(scene, relativePath, mapName, info, language);
                            for (Int32 index = startOvrIdx; index <= endOvrIdx; index++)
                            {
                                BGOVERLAY_DEF overlay    = scene.overlayList[index];
                                String        outputPath = outputDirectory + $"Overlay{index}_{language}.png";
                                ExportOverlay(overlay, atlasTexture, outputPath, scene, file);
                            }
                        }
                    }

                    file.Save(output, Encoding.UTF8);
                }

                string strings            = $"[PsdSection]\nLayerOrder=name\nReversed = 0";
                System.IO.StreamWriter sw = new System.IO.StreamWriter(Path.Combine(outputDirectory, "psd.meta"));
                sw.WriteLine(strings);
                sw.Close();


                TextureHelper.WriteTextureToFile(atlasTexture, Path.Combine(outputDirectory, "atlas.png"));

                Log.Message("[FieldSceneExporter] Exporting completed successfully.");
            }
            catch (Exception ex)
            {
                Log.Error(ex, "[FieldSceneExporter] Failed to export map [{0}].", mapName);
            }
        }