Beispiel #1
0
        private static void ExportMapSafe(String mapName)
        {
            try
            {
                String relativePath    = FieldMap.GetMapResourcePath(mapName);
                String outputDirectory = Path.Combine(Configuration.Export.Path, relativePath);
                String outputPath      = outputDirectory + "Atlas.png";
                if (File.Exists(outputPath))
                {
                    Log.Warning($"[FieldSceneExporter] Export was skipped bacause a file already exists: [{outputPath}].");
                    return;
                }

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

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

                String directoryPath = Path.GetDirectoryName(outputPath);
                if (directoryPath != null)
                {
                    Directory.CreateDirectory(directoryPath);
                }
                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);
            }
        }
Beispiel #2
0
    private void SetQuad(BGSCENE_DEF scene, Int32 camIdx, Vector2 offset)
    {
        Color[] array = new Color[]
        {
            Color.cyan,
            Color.blue,
            Color.green,
            Color.yellow,
            Color.red,
            Color.white,
            Color.black,
            Color.grey
        };
        BGCAM_DEF bgcam_DEF = scene.cameraList[camIdx];

        Int32[] array2 = new Int32[]
        {
            2222,
            -5555,
            -2222,
            -5555,
            -2222,
            -4080,
            2222,
            -4080
        };
        Int32[] quad = this.fieldMapData[this.currentQuad].quad;
        String  str  = String.Empty;

        for (Int32 i = 0; i < (Int32)quad.Length; i++)
        {
            str = str + ", " + quad[i].ToString();
        }
        Vector3[] array3 = new Vector3[(Int32)quad.Length / 2];
        for (Int32 j = 0; j < (Int32)array3.Length; j++)
        {
            array3[j] = new Vector3((Single)quad[j * 2], 0f, (Single)quad[j * 2 + 1]);
            array3[j] = PSX.CalculateGTE_RTPT(array3[j], Matrix4x4.identity, bgcam_DEF.GetMatrixRT(), bgcam_DEF.GetViewDistance(), offset);
            Color   color = array[j];
            Single  num   = 5f;
            Vector3 b     = new Vector3(0f, 0f, (Single)scene.curZ);
            global::Debug.DrawLine(array3[j] + new Vector3(-num, -num, 0f) + b, array3[j] + new Vector3(num, num, 0f) + b, color, 0f, true);
            global::Debug.DrawLine(array3[j] + new Vector3(-num, num, 0f) + b, array3[j] + new Vector3(num, -num, 0f) + b, color, 0f, true);
        }
        for (Int32 k = 0; k < (Int32)array3.Length; k++)
        {
            Int32  num2 = (Int32)array3.Length - 1;
            Int32  num3 = (Int32)((k - 1 >= 0) ? (k - 1) : num2);
            Int32  num4 = (Int32)((k + 1 <= num2) ? (k + 1) : 0);
            Single num5 = Vector3.Angle(array3[k] - array3[num3], array3[k] - array3[num4]);
        }
        for (Int32 l = 0; l < (Int32)array3.Length - 1; l++)
        {
            global::Debug.DrawLine(array3[l], array3[l + 1], Color.cyan, 0f, true);
            global::Debug.DrawLine(array3[0], array3[l + 1], Color.cyan, 0f, true);
        }
    }
Beispiel #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];
            }
        }
    }
Beispiel #4
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);
    }
Beispiel #5
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);
            }
        }
Beispiel #6
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();
        }
Beispiel #7
0
    public void LoadEBG(FieldMap fieldMap, String path, String newName)
    {
        this.name = newName;
        if (!this.useUpscaleFM)
        {
            this.InitPSXTextureAtlas();
        }
        else
        {
            Texture2D x = AssetManager.Load <Texture2D>(Path.Combine(path, "atlas"), false);
            if (x != null)
            {
                this.atlas = x;
                if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.WindowsEditor)
                {
                    this.atlasAlpha = AssetManager.Load <Texture2D>(Path.Combine(path, "atlas_a"), false);
                }
                else
                {
                    this.atlasAlpha = null;
                }
                this.SPRITE_W = 32u;
                this.SPRITE_H = 32u;
            }
            else
            {
                this.useUpscaleFM = false;
                this.InitPSXTextureAtlas();
            }
        }
        if (!this.useUpscaleFM)
        {
            this.vram.LoadTIMs(path);
        }
        TextAsset textAsset;

        if (!FieldMapEditor.useOriginalVersion)
        {
            textAsset = AssetManager.Load <TextAsset>(path + FieldMapEditor.GetFieldMapModName(newName) + ".bgs", false);
            if (textAsset == null)
            {
                Debug.Log("Cannot find MOD version.");
                textAsset = AssetManager.Load <TextAsset>(path + newName + ".bgs", false);
            }
        }
        else
        {
            textAsset = AssetManager.Load <TextAsset>(path + newName + ".bgs", false);
        }

        if (textAsset == null)
        {
            return;
        }

        this.ebgBin = textAsset.bytes;
        using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(this.ebgBin)))
        {
            this.ReadData(binaryReader);
        }
        String symbol = Localization.GetSymbol();

        if (symbol != "US")
        {
            FieldMapLocalizeAreaTitleInfo info = FieldMapInfo.localizeAreaTitle.GetInfo(newName);
            if (info != null)
            {
                if (symbol != "UK" || info.hasUK)
                {
                    BGSCENE_DEF bGSCENE_DEF = new BGSCENE_DEF(this.useUpscaleFM);
                    bGSCENE_DEF._LoadDummyEBG(this, path, newName, info, symbol);
                }
            }
        }
        FieldMapInfo.fieldmapExtraOffset.SetOffset(newName, this.overlayList);
        if (!this.useUpscaleFM)
        {
            this.GenerateAtlasFromBinary();
        }

        this.CreateMaterials();
        if (fieldMap != null)
        {
            this.CreateScene(fieldMap, this.useUpscaleFM);
        }
    }
Beispiel #8
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);
            }
        }