コード例 #1
0
ファイル: R1_Saturn_Manager.cs プロジェクト: PluMGMK/Ray1Map
        public override async UniTask ExportMenuSpritesAsync(GameSettings settings, string outputPath, bool exportAnimFrames)
        {
            using (var menuContext = new Context(settings))
            {
                using (var bigRayContext = new Context(settings))
                {
                    // Load allfix
                    await LoadFile(menuContext, GetAllfixFilePath(), BaseAddress);

                    var fix = FileFactory.Read <R1_PS1_AllfixBlock>(GetAllfixFilePath(), menuContext, onPreSerialize: (s, o) => o.Length = s.CurrentLength);
                    await LoadFile(menuContext, GetFixImageFilePath());

                    // Load exe
                    await LoadFile(menuContext, ExeFilePath);
                    await LoadFile(bigRayContext, ExeFilePath);

                    // Save font
                    menuContext.StoreObject("Font", fix.FontData);

                    // Read the BigRay file
                    await LoadFile(bigRayContext, GetBigRayFilePath(), 0x00280000);
                    await LoadFile(bigRayContext, GetBigRayImageFilePath());

                    var br = FileFactory.Read <R1_PS1_BigRayBlock>(GetBigRayFilePath(), bigRayContext, onPreSerialize: (s, o) => o.Length = s.CurrentLength);

                    // Export
                    await ExportMenuSpritesAsync(menuContext, bigRayContext, outputPath, exportAnimFrames, fix.FontData, fix.WldObj, br);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Exports every sprite from the game
        /// </summary>
        /// <param name="baseGameSettings">The game settings</param>
        /// <param name="outputDir">The output directory</param>
        /// <param name="exportAnimFrames">True if animation frames should be exported, false if sprites should be exported</param>
        /// <returns>The task</returns>
        public override async UniTask ExportAllSpritesAsync(GameSettings baseGameSettings, string outputDir, bool exportAnimFrames)
        {
            // Create the context
            using (var context = new Context(baseGameSettings))
            {
                // Load the game data
                await LoadFilesAsync(context);

                // Serialize the rom
                var rom = FileFactory.Read <R1Jaguar_ROM>(GetROMFilePath, context);

                var usedNames = new List <string>();
                // Helper method to get the name for a pointer
                string GetPointerName(Pointer p)
                {
                    string name = rom.References.FirstOrDefault(x => x.DataPointer == p && !usedNames.Contains(x.String))
                                  ?.String ?? $"{rom.References.First(x => x.DataPointer == p)?.String}";

                    usedNames.Add(name);

                    return(name);
                }

                // Enumerate every graphics
                foreach (var sprKey in rom.ImageBuffers.Keys)
                {
                    // Get data
                    var imgBuffer = rom.ImageBuffers[sprKey];
                    var imgDescr  = rom.ImageBufferDescriptors[sprKey];
                    var pal       = rom.SpritePalette;
                    var desName   = rom.References.Last(x => x.DataValue == sprKey).String.Substring(4);

                    if (exportAnimFrames)
                    {
                        // Enumerate every event definition which uses this image buffer
                        foreach (var ed in rom.EventDefinitions.Where(x => x.ImageBufferMemoryPointerPointer >> 8 == sprKey))
                        {
                            // Create template
                            var animations = new List <ExportAnim>();

                            // Add single animation
                            if (ed.AnimationLayers != null)
                            {
                                animations.Add(new ExportAnim()
                                {
                                    Anim           = ed.ToCommonAnimation(),
                                    AnimationSpeed = 1,
                                    Pointer        = ed.AnimationPointer - 4
                                });
                            }

                            // Add state animations
                            if (ed.States != null)
                            {
                                animations.AddRange(ed.States.Where(x => x.Animation?.Layers != null).Select(x => new ExportAnim()
                                {
                                    Anim           = x.Animation.ToCommonAnimation(ed),
                                    AnimationSpeed = (byte)(x.AnimationSpeed & 0b1111),
                                    Pointer        = x.Animation.Offset
                                }));
コード例 #3
0
ファイル: R1_Kit_Manager.cs プロジェクト: PluMGMK/Ray1Map
        public async UniTask IncreaseMemAlloc(GameSettings settings)
        {
            const int newMemAlloc = 2048; // 2 MiB should be enough!

            using (var context = new Context(settings))
            {
                await LoadFilesAsync(context);

                Debug.Log("Opening version file...");
                var commonDat       = FileFactory.Read <R1_PC_EncryptedFileArchive>(GetCommonArchiveFilePath(), context);
                var versionFileName = R1_PC_ArchiveFileName.VERSION.ToString();
                var versionFile     = commonDat.ReadFile <R1_PC_VersionFile>(context, versionFileName);

                Debug.Log("Increasing memory allocation...");
                // Increase the memory allocated for each version.
                foreach (var verMemInfo in versionFile.VersionMemoryInfos)
                {
                    if (verMemInfo.TailleMainMemWorld < newMemAlloc)
                    {
                        verMemInfo.TailleMainMemWorld = newMemAlloc;
                    }
                    if (verMemInfo.TailleMainMemSprite < newMemAlloc)
                    {
                        verMemInfo.TailleMainMemSprite = newMemAlloc;
                    }
                }

                Debug.Log("Saving version file...");
                // Reserialize and save out the updated archive.
                commonDat.RepackArchive(context, new Dictionary <string, Action <SerializerObject> > {
                    { versionFileName, x => x.SerializeObject <R1_PC_VersionFile>(versionFile, name: versionFileName) }
                });
                Debug.Log("Version file saved.");
            }
        }
コード例 #4
0
        public override async UniTask <Texture2D> LoadLevelBackgroundAsync(Context context)
        {
            var exe = FileFactory.Read <R1_PS1_Executable>(ExeFilePath, context);

            if (context.Settings.R1_World != R1_World.Menu)
            {
                if (exe.LevelBackgroundIndexTable == null)
                {
                    return(null);
                }

                var bgIndex       = exe.LevelBackgroundIndexTable[context.Settings.World - 1][context.Settings.Level - 1];
                var fndStartIndex = exe.GetFileTypeIndex(this, R1_PS1_FileType.fnd_file);

                if (fndStartIndex == -1)
                {
                    return(null);
                }

                string bgFilePath = exe.FileTable[fndStartIndex + bgIndex].ProcessedFilePath;

                await LoadExtraFile(context, bgFilePath, true);

                var bg = FileFactory.Read <R1_PS1_BackgroundVignetteFile>(bgFilePath, context);

                return(bg.ImageBlock.ToTexture(context));
            }
            else
            {
                string bgFilePath = exe.FileTable[exe.GetFileTypeIndex(this, R1_PS1_FileType.img_file) + 2].ProcessedFilePath;
                await LoadExtraFile(context, bgFilePath, true);

                return(FileFactory.Read <R1_PS1_VignetteBlockGroup>(bgFilePath, context, onPreSerialize: (s, x) => x.BlockGroupSize = (int)(s.CurrentLength / 2)).ToTexture(context));
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets a command from the raw bytes
        /// </summary>
        /// <param name="bytes">The command bytes</param>
        /// <param name="settings">The game settings</param>
        /// <returns>The command</returns>
        public static R1_EventCommandCollection FromBytes(byte[] bytes, GameSettings settings)
        {
            // Make sure there are bytes
            if (!bytes.Any())
            {
                return new R1_EventCommandCollection()
                       {
                           Commands = new R1_EventCommand[0]
                       }
            }
            ;

            // Create a new context
            using (var context = new Context(settings)) {
                // Create a memory stream
                using (var memStream = new MemoryStream(bytes)) {
                    // Stream key
                    const string key = "PC_EventCommand";

                    // Add the stream
                    context.AddStreamFile(key, memStream);

                    // Deserialize the bytes
                    return(FileFactory.Read <R1_EventCommandCollection>(key, context));
                }
            }
        }
コード例 #6
0
        public async UniTask ExportDataBasesAsync(GameSettings settings, string outputDir)
        {
            using (var context = new Context(settings))
            {
                var s = context.Deserializer;

                foreach (var filePath in Directory.GetFiles(context.BasePath, "*", SearchOption.TopDirectoryOnly))
                {
                    var ext  = Path.GetExtension(filePath);
                    var type = ext == ".pdb" ? Palm_Database.DatabaseType.PDB : (ext == ".prc" ? Palm_Database.DatabaseType.PRC : (Palm_Database.DatabaseType?)null);

                    if (type == null)
                    {
                        continue;
                    }

                    var relPath = Path.GetFileName(filePath);
                    await context.AddLinearSerializedFileAsync(relPath, BinaryFile.Endian.Big);

                    if (type == Palm_Database.DatabaseType.PDB)
                    {
                        var dataFile = FileFactory.Read <LUDI_PalmOS_DataFile>(relPath, context);
                        ExportLUDIDataFile(dataFile, s, Path.Combine(outputDir, Path.GetFileNameWithoutExtension(relPath)));
                    }
                    else
                    {
                        var dataBase = FileFactory.Read <Palm_Database>(relPath, context, (so, pd) => pd.Type = type.Value);

                        for (int i = 0; i < dataBase.RecordsCount; i++)
                        {
                            var record = dataBase.Records[i];
                            var name   = type == Palm_Database.DatabaseType.PRC ? $"{record.Name}_{record.ID}" : $"{i}";

                            string filename = $"{name}.bin";
                            var    bytes    = s.DoAt(record.DataPointer, () => s.SerializeArray <byte>(default, record.Length, name: $"Record[{i}]"));
コード例 #7
0
        protected override Dictionary <SpecialEventType, Pointer> GetSpecialEventPointers(Context context)
        {
            // Read the rom
            var     rom     = FileFactory.Read <R1Jaguar_ROM>(GetROMFilePath, context);
            Pointer baseOff = rom.EventDefinitions[0].Offset;

            return(new Dictionary <SpecialEventType, Pointer>()
            {
                [SpecialEventType.RayPos] = baseOff + 0x1BF8,
                [SpecialEventType.Gendoor] = null, // Doesn't exist
                [SpecialEventType.Piranha] = baseOff + 0xDE8,
                [SpecialEventType.Piranha2] = baseOff + 0xE10,
                [SpecialEventType.ScrollFast] = baseOff + 0xFA0,
                [SpecialEventType.ScrollSlow] = baseOff + 0xFC8,
                [SpecialEventType.RayOnBzzit] = null, // baseOff + 0x1C20
                [SpecialEventType.BzzitDemo] = rom.Offset + 0x1183C8,

                [SpecialEventType.RaymanVisual] = baseOff,
                [SpecialEventType.GendoorVisual] = baseOff + 0x5A0,
                [SpecialEventType.PiranhaVisual] = baseOff + 0xE38,
                [SpecialEventType.ScrollVisual] = baseOff + 0x1040,
                [SpecialEventType.RayOnBzzitVisual] = null,
                [SpecialEventType.BzzitDemoVisual] = rom.Offset + 0x11DCC8,
                //[SpecialEventType.BetillaDemoVisual] = rom.Offset + 0x6BA20,
            });
        }
コード例 #8
0
ファイル: R1_Saturn_Manager.cs プロジェクト: PluMGMK/Ray1Map
        /// <summary>
        /// Fills the PS1 v-ram and returns it
        /// </summary>
        /// <param name="context">The context</param>
        /// <param name="mode">The blocks to fill</param>
        /// <returns>The filled v-ram</returns>
        protected override void FillVRAM(Context context, VRAMMode mode)
        {
            string fixPath    = GetFixImageFilePath();
            string bigRayPath = GetBigRayImageFilePath();

            var fixImg    = context.FileExists(fixPath) && mode != VRAMMode.BigRay ? FileFactory.Read <Array <byte> >(fixPath, context, (y, x) => x.Length = y.CurrentLength) : null;
            var worldImg  = mode == VRAMMode.Level && context.FileExists(GetWorldImageFilePath(context)) ? FileFactory.Read <Array <byte> >(GetWorldImageFilePath(context), context, (y, x) => x.Length = y.CurrentLength) : null;
            var levelImg  = mode == VRAMMode.Level && context.FileExists(GetLevelImageFilePath(context)) ? FileFactory.Read <Array <byte> >(GetLevelImageFilePath(context), context, (y, x) => x.Length = y.CurrentLength) : null;
            var bigRayImg = context.FileExists(bigRayPath) && mode == VRAMMode.BigRay ? FileFactory.Read <Array <byte> >(bigRayPath, context, (y, x) => x.Length = y.CurrentLength) : null;

            ImageBuffer buf = new ImageBuffer();

            if (fixImg != null)
            {
                buf.AddData(fixImg.Value);
            }
            if (worldImg != null)
            {
                buf.AddData(worldImg.Value);
            }
            if (levelImg != null)
            {
                buf.AddData(levelImg.Value);
            }
            if (bigRayImg != null)
            {
                buf.AddData(bigRayImg.Value);
            }
            context.StoreObject("vram", buf);
        }
コード例 #9
0
        public async UniTask TestBinRead(GameSettings settings)
        {
            using (var context = new Context(settings)) {
                await context.AddLinearSerializedFileAsync("disc.bin");

                var binFile = FileFactory.Read <ISO9960_BinFile>("disc.bin", context);
            }
        }
コード例 #10
0
ファイル: R1_Saturn_Manager.cs プロジェクト: PluMGMK/Ray1Map
        /// <summary>
        /// Loads the specified level for the editor
        /// </summary>
        /// <param name="context">The serialization context</param>
        /// <param name="loadTextures">Indicates if textures should be loaded</param>
        /// <returns>The level</returns>
        public override async UniTask <Unity_Level> LoadAsync(Context context, bool loadTextures)
        {
            // Get the paths
            var allfixFilePath = GetAllfixFilePath();

            uint baseAddress = BaseAddress;

            // Load the memory mapped files
            baseAddress += await LoadFile(context, allfixFilePath, baseAddress);

            R1_PS1_EventBlock eventBlock = null;
            MapData           mapData;

            if (context.Settings.R1_World != R1_World.Menu)
            {
                var worldFilePath                    = GetWorldFilePath(context.Settings);
                var levelFilePath                    = GetLevelFilePath(context.Settings);
                var tileSetPaletteFilePath           = GetTileSetPaletteFilePath(context);
                var tileSetPaletteIndexTableFilePath = GetTileSetPaletteIndexTableFilePath(context);
                var tileSetFilePath                  = GetTileSetFilePath(context);
                var mapFilePath = GetMapFilePath(context);

                baseAddress += await LoadFile(context, worldFilePath, baseAddress);

                baseAddress += await LoadFile(context, levelFilePath, baseAddress);

                // Load the files
                await LoadFile(context, tileSetPaletteFilePath);
                await LoadFile(context, tileSetPaletteIndexTableFilePath);
                await LoadFile(context, tileSetFilePath);
                await LoadFile(context, mapFilePath);

                if (FileSystem.FileExists(context.BasePath + levelFilePath))
                {
                    await LoadFile(context, GetWorldImageFilePath(context));
                    await LoadFile(context, GetLevelImageFilePath(context));
                }

                // Read the map block
                mapData = FileFactory.Read <MapData>(mapFilePath, context);

                if (FileSystem.FileExists(context.BasePath + levelFilePath))
                {
                    // Read the event block
                    eventBlock = FileFactory.Read <R1_PS1_EventBlock>(levelFilePath, context);
                }
            }
            else
            {
                mapData = MapData.GetEmptyMapData(384 / Settings.CellSize, 288 / Settings.CellSize);
            }

            // Load the texture files
            await LoadFile(context, GetFixImageFilePath());

            // Load the level
            return(await LoadAsync(context, mapData, eventBlock?.Events, eventBlock?.EventLinkingTable.Select(b => (ushort)b).ToArray(), loadTextures));
        }
コード例 #11
0
        public async UniTask ExportPaletteImageAsync(GameSettings settings, string outputPath)
        {
            var spritePals = new List <ARGB1555Color[]>();
            var tilePals   = new List <ARGB1555Color[]>();

            void Add(ICollection <ARGB1555Color[]> pals, ARGB1555Color[] pal)
            {
                if (pal != null && !pals.Any(x => x.SequenceEqual(pal)))
                {
                    pals.Add(pal);
                }
            }

            // Enumerate every world
            foreach (var world in GetLevels(settings).First().Worlds)
            {
                settings.World = world.Index;
                settings.Level = 1;

                using (var context = new Context(settings))
                {
                    // Read the allfix file
                    await LoadExtraFile(context, GetAllfixFilePath(context.Settings), false);

                    var allfix = FileFactory.Read <R1_PS1_AllfixFile>(GetAllfixFilePath(context.Settings), context);

                    // Read the BigRay file
                    await LoadExtraFile(context, GetBigRayFilePath(context.Settings), false);

                    var br = FileFactory.Read <R1_PS1_BigRayFile>(GetBigRayFilePath(context.Settings), context);

                    Add(spritePals, allfix.Palette1);
                    Add(spritePals, allfix.Palette2);
                    Add(spritePals, allfix.Palette3);
                    Add(spritePals, allfix.Palette4);
                    Add(spritePals, allfix.Palette5);
                    Add(spritePals, allfix.Palette6);
                    Add(spritePals, br.Palette1);
                    Add(spritePals, br.Palette2);

                    // Read the world file
                    await LoadExtraFile(context, GetWorldFilePath(context.Settings), false);

                    var wld = FileFactory.Read <R1_PS1_WorldFile>(GetWorldFilePath(context.Settings), context);

                    Add(spritePals, wld.EventPalette1);
                    Add(spritePals, wld.EventPalette2);

                    foreach (var tilePal in wld.TilePalettes ?? new ARGB1555Color[0][])
                    {
                        Add(tilePals, tilePal);
                    }
                }
            }

            // Export
            PaletteHelpers.ExportPalette(Path.Combine(outputPath, $"{settings.GameModeSelection}.png"), spritePals.Concat(tilePals).SelectMany(x => x).ToArray(), optionalWrap: 256);
        }
コード例 #12
0
        /// <summary>
        /// Gets the tile set to use
        /// </summary>
        /// <param name="context">The context</param>
        /// <param name="map">The map</param>
        /// <returns>The tile set to use</returns>
        public Unity_TileSet GetTileSet(Context context, int map)
        {
            var tileSetPath = GetSubMapTilesetPath(map);
            var palettePath = GetSubMapPalettePath(map);
            var tileSet     = FileFactory.Read <Array <byte> >(tileSetPath, context, (s, x) => x.Length = s.CurrentLength);
            var palette     = FileFactory.Read <ObjectArray <RGBA5551Color> >(palettePath, context, (s, x) => x.Length = s.CurrentLength / 2);

            return(new Unity_TileSet(tileSet.Value.Select(ind => palette.Value[ind]).ToArray(), TileSetWidth, Settings.CellSize));
        }
コード例 #13
0
        public override Dictionary <Unity_ObjectManager_R1.WldObjType, R1_EventData> GetEventTemplates(Context context)
        {
            var level = FileFactory.Read <R1_PS1JPDemo_LevFile>(GetLevelFilePath(context.Settings), context);

            return(new Dictionary <Unity_ObjectManager_R1.WldObjType, R1_EventData>()
            {
                [Unity_ObjectManager_R1.WldObjType.Ray] = level.RaymanEvent,
            });
        }
コード例 #14
0
        public override async UniTask <Texture2D> LoadLevelBackgroundAsync(Context context)
        {
            const string bgFilePath = "JUN_F01.R16";

            await LoadExtraFile(context, bgFilePath, true);

            var bg = FileFactory.Read <R1_PS1_VignetteBlockGroup>(bgFilePath, context, onPreSerialize: (s, x) => x.BlockGroupSize = (int)(s.CurrentLength / 2));

            return(bg.ToTexture(context));
        }
コード例 #15
0
        /// <summary>
        /// Gets the tile set to use
        /// </summary>
        /// <param name="context">The context</param>
        /// <returns>The tile set to use</returns>
        public override Unity_MapTileMap GetTileSet(Context context)
        {
            // Get the file name
            var filename = GetTileSetFilePath(context.Settings);

            // Read the file
            var tileSet = FileFactory.Read <ObjectArray <ARGB1555Color> >(filename, context, (s, x) => x.Length = s.CurrentLength / 2);

            // Return the tile set
            return(new Unity_MapTileMap(tileSet.Value, TileSetWidth, Settings.CellSize));
        }
コード例 #16
0
ファイル: R1_Kit_Manager.cs プロジェクト: PluMGMK/Ray1Map
        /// <summary>
        /// Gets the ETA file name for the current index in the current context
        /// </summary>
        /// <param name="context">The context</param>
        /// <param name="etaIndex">The ETA index</param>
        /// <returns>The file name</returns>
        public string GetETAFileName(Context context, int etaIndex)
        {
            // Read the world data
            var worldData = FileFactory.Read <R1_PC_WorldFile>(GetWorldFilePath(context.Settings), context);

            // Get file names
            var etaNames = worldData.ETAFileNames ?? new string[0];

            // Return the name
            return(etaNames.ElementAtOrDefault(etaIndex) ?? $"ETA_{etaIndex}");
        }
コード例 #17
0
ファイル: R1_Kit_Manager.cs プロジェクト: PluMGMK/Ray1Map
        /// <summary>
        /// Gets the DES file name for the current index in the current context
        /// </summary>
        /// <param name="context">The context</param>
        /// <param name="desIndex">The DES index</param>
        /// <returns>The file name</returns>
        public string GetDESFileName(Context context, int desIndex)
        {
            // Read the world data
            var worldData = FileFactory.Read <R1_PC_WorldFile>(GetWorldFilePath(context.Settings), context);

            // Get file names
            var desNames = worldData.DESFileNames ?? new string[0];

            // Return the name
            return(desNames.ElementAtOrDefault(desIndex) ?? $"DES_{desIndex}");
        }
コード例 #18
0
        protected override async UniTask <IReadOnlyDictionary <string, string[]> > LoadLocalizationAsync(Context context)
        {
            var filePath = GetLanguageFilePath("US");

            await FileSystem.PrepareFile(context.BasePath + filePath);

            // Create the dictionary
            return(new Dictionary <string, string[]>()
            {
                ["English"] = FileFactory.ReadText <R1_TextLocFile>(filePath, context).Strings
            });
        }
コード例 #19
0
        /// <summary>
        /// Loads the specified level for the editor
        /// </summary>
        /// <param name="context">The serialization context</param>
        /// <param name="loadTextures">Indicates if textures should be loaded</param>
        /// <returns>The level</returns>
        public override async UniTask <Unity_Level> LoadAsync(Context context, bool loadTextures)
        {
            // Get the file paths
            var mapPath   = GetMapFilePath(context.Settings);
            var levelPath = GetLevelFilePath(context.Settings);

            // Read the files
            var map   = FileFactory.Read <MapData>(mapPath, context);
            var level = FileFactory.Read <R1_PS1JPDemo_LevFile>(levelPath, context);

            // Load the level
            return(await LoadAsync(context, map, level.Events, level.EventLinkTable.Select(x => (ushort)x).ToArray(), loadTextures));
        }
コード例 #20
0
        public async UniTask ExportSpritesAsync(GameSettings settings, string outputDir)
        {
            using (var context = new Context(settings))
            {
                // Load rom
                await LoadFilesAsync(context);

                var rom = FileFactory.Read <SNES_Proto_ROM>(GetROMFilePath, context);

                var graphicsGroups = GetGraphicsGroups(rom);

                foreach (var graphicsGroup in graphicsGroups)
                {
                    // Export every sprite
                    for (int i = 0; i < graphicsGroup.Sprites.Length; i++)
                    {
                        var spriteIndex   = i % graphicsGroup.ImageDescriptors.Length;
                        var vramConfig    = i / graphicsGroup.ImageDescriptors.Length;
                        var imgDescriptor = graphicsGroup.ImageDescriptors[spriteIndex];
                        var sprite        = graphicsGroup.Sprites[i];
                        if (sprite == null)
                        {
                            continue;
                        }

                        var xPos = imgDescriptor.TileIndex % 16;
                        var yPos = (imgDescriptor.TileIndex - xPos) / 16;

                        var width  = (int)sprite.rect.width;
                        var height = (int)sprite.rect.height;

                        var newTex = TextureHelpers.CreateTexture2D(width, height);

                        var flipX = false;
                        var flipY = true;

                        for (int y = 0; y < height; y++)
                        {
                            for (int x = 0; x < width; x++)
                            {
                                newTex.SetPixel(flipX ? width - x - 1 : x, (!flipY) ? height - y - 1 : y, sprite.texture.GetPixel((int)sprite.rect.x + x, (int)sprite.rect.y + y));
                            }
                        }

                        newTex.Apply();

                        Util.ByteArrayToFile(Path.Combine(outputDir, graphicsGroup.Name, $"{spriteIndex} - {vramConfig}.png"), newTex.EncodeToPNG());
                    }
                }
            }
        }
コード例 #21
0
        public override async UniTask ExportMenuSpritesAsync(GameSettings settings, string outputPath, bool exportAnimFrames)
        {
            using (var menuContext = new Context(settings))
            {
                using (var bigRayContext = new Context(settings))
                {
                    await LoadFilesAsync(menuContext);
                    await LoadFilesAsync(bigRayContext);

                    // Read the allfix & font files for the menu
                    await LoadExtraFile(menuContext, GetAllfixFilePath(menuContext.Settings), false);

                    var fix = FileFactory.Read <R1_PS1_AllfixFile>(GetAllfixFilePath(menuContext.Settings), menuContext);
                    await LoadExtraFile(menuContext, GetFontFilePath(menuContext.Settings), false);

                    // Correct font palette
                    if (settings.EngineVersion == EngineVersion.R1_PS1_JP)
                    {
                        foreach (R1_PS1_FontData font in fix.AllfixData.FontData)
                        {
                            foreach (R1_ImageDescriptor imgDescr in font.ImageDescriptors)
                            {
                                var paletteInfo = imgDescr.PaletteInfo;
                                paletteInfo          = (ushort)BitHelpers.SetBits(paletteInfo, 509, 10, 6);
                                imgDescr.PaletteInfo = paletteInfo;
                            }
                        }
                    }
                    else
                    {
                        foreach (R1_PS1_FontData font in fix.AllfixData.FontData)
                        {
                            foreach (R1_ImageDescriptor imgDescr in font.ImageDescriptors)
                            {
                                var paletteInfo = imgDescr.PaletteInfo;
                                paletteInfo          = (ushort)BitHelpers.SetBits(paletteInfo, 492, 10, 6);
                                imgDescr.PaletteInfo = paletteInfo;
                            }
                        }
                    }

                    // Read the BigRay file
                    await LoadExtraFile(bigRayContext, GetBigRayFilePath(bigRayContext.Settings), false);

                    var br = bigRayContext.FileExists(GetBigRayFilePath(bigRayContext.Settings)) ? FileFactory.Read <R1_PS1_BigRayFile>(GetBigRayFilePath(bigRayContext.Settings), bigRayContext) : null;

                    // Export
                    await ExportMenuSpritesAsync(menuContext, bigRayContext, outputPath, exportAnimFrames, fix.AllfixData.FontData, fix.AllfixData.WldObj, br?.BigRayData);
                }
            }
        }
コード例 #22
0
ファイル: R1_Saturn_Manager.cs プロジェクト: PluMGMK/Ray1Map
        public override Dictionary <Unity_ObjectManager_R1.WldObjType, R1_EventData> GetEventTemplates(Context context)
        {
            var allfix = FileFactory.Read <R1_PS1_AllfixBlock>(GetAllfixFilePath(), context, onPreSerialize: (s, o) => o.Length = s.CurrentLength);
            var wldObj = allfix.WldObj;

            return(new Dictionary <Unity_ObjectManager_R1.WldObjType, R1_EventData>()
            {
                [Unity_ObjectManager_R1.WldObjType.Ray] = wldObj[0],
                [Unity_ObjectManager_R1.WldObjType.RayLittle] = wldObj[1],
                [Unity_ObjectManager_R1.WldObjType.ClockObj] = wldObj[2],
                [Unity_ObjectManager_R1.WldObjType.DivObj] = wldObj[3],
                [Unity_ObjectManager_R1.WldObjType.MapObj] = wldObj[4],
            });
        }
コード例 #23
0
        public UniTask <Unity_Level> LoadAsync(Context context, bool loadTextures)
        {
            // Read the rom
            var rom = FileFactory.Read <GBAIsometric_ROM>(GetROMFilePath, context);

            var levelInfo = rom.LevelInfos[context.Settings.Level];
            var levelData = levelInfo.LevelDataPointer.Value;

            var maps = levelData.MapLayers.Select(x =>
            {
                var width  = (ushort)(x.DataPointer.Value.Width * (64 / CellSize));
                var height = (ushort)(x.DataPointer.Value.Height * (64 / CellSize));

                return(new Unity_Map
                {
                    Width = width,
                    Height = height,
                    TileSetWidth = 1,
                    TileSet = new Unity_MapTileMap[]
                    {
                        new Unity_MapTileMap(CellSize),
                    },
                    MapTiles = Enumerable.Repeat(new Unity_Tile(new MapTile()), width * height).ToArray(),
                });
            }).ToArray();

            var objManager = new Unity_ObjectManager_GBAIsometric(context, rom.ObjectTypes, levelData.ObjectsCount);

            var allObjects = new List <Unity_Object>();

            // Add normal objects
            allObjects.AddRange(levelData.Objects.Select(x => (Unity_Object) new Unity_Object_GBAIsometric(x, objManager)));

            // Add waypoints
            allObjects.AddRange(levelData.Waypoints.Select(x => (Unity_Object) new Unity_Object_GBAIsometricWaypoint(x, objManager)));

            // Add localization
            var loc = rom.Localization.Localization.Select((x, i) => new
            {
                key     = rom.Localization.Localization[0][i],
                strings = x
            }).ToDictionary(x => x.key, x => x.strings);

            return(UniTask.FromResult(new Unity_Level(
                                          maps: maps,
                                          objManager: objManager,
                                          eventData: allObjects,
                                          cellSize: CellSize,
                                          localization: loc)));
        }
コード例 #24
0
        public override Dictionary <Unity_ObjectManager_R1.WldObjType, R1_EventData> GetEventTemplates(Context context)
        {
            var allfix = FileFactory.Read <R1_PS1_AllfixFile>(GetAllfixFilePath(context.Settings), context).AllfixData;
            var wldObj = allfix.WldObj;

            return(new Dictionary <Unity_ObjectManager_R1.WldObjType, R1_EventData>()
            {
                [Unity_ObjectManager_R1.WldObjType.Ray] = wldObj[0],
                [Unity_ObjectManager_R1.WldObjType.RayLittle] = wldObj[1],
                [Unity_ObjectManager_R1.WldObjType.ClockObj] = wldObj[2],
                [Unity_ObjectManager_R1.WldObjType.DivObj] = wldObj[3],
                [Unity_ObjectManager_R1.WldObjType.MapObj] = wldObj[4],
            });
        }
コード例 #25
0
ファイル: R1_PS1_Manager.cs プロジェクト: PluMGMK/Ray1Map
        /// <summary>
        /// Gets the tile set to use
        /// </summary>
        /// <param name="context">The context</param>
        /// <returns>The tile set to use</returns>
        public override Unity_MapTileMap GetTileSet(Context context)
        {
            if (context.Settings.R1_World == R1_World.Menu)
            {
                return(new Unity_MapTileMap(Settings.CellSize));
            }

            // Get the file name
            var filename = GetWorldFilePath(context.Settings);

            // Read the file
            var worldFile = FileFactory.Read <R1_PS1_WorldFile>(filename, context);

            int tileCount = worldFile.TilePaletteIndexTable.Length;
            int width     = TileSetWidth * Settings.CellSize;
            int height    = (worldFile.PalettedTiles.Length) / width;

            var pixels = new ARGB1555Color[width * height];

            int tile = 0;

            for (int yB = 0; yB < height; yB += Settings.CellSize)
            {
                for (int xB = 0; xB < width; xB += Settings.CellSize, tile++)
                {
                    for (int y = 0; y < Settings.CellSize; y++)
                    {
                        for (int x = 0; x < Settings.CellSize; x++)
                        {
                            int pixel = x + xB + (y + yB) * width;

                            if (tile >= tileCount)
                            {
                                // Set dummy data
                                pixels[pixel] = new ARGB1555Color();
                            }
                            else
                            {
                                byte tileIndex1 = worldFile.TilePaletteIndexTable[tile];
                                byte tileIndex2 = worldFile.PalettedTiles[pixel];
                                pixels[pixel] = worldFile.TilePalettes[tileIndex1][tileIndex2];
                            }
                        }
                    }
                }
            }

            return(new Unity_MapTileMap(pixels, TileSetWidth, Settings.CellSize));
        }
コード例 #26
0
        public async UniTask ExportRootTileKitsAsync(GameSettings settings, string outputDir)
        {
            using (var context = new Context(settings))
            {
                await LoadFilesAsync(context);

                var s   = context.Deserializer;
                var rom = FileFactory.Read <GBC_ROM>(GetROMFilePath, context);

                for (int i = 0; i < rom.ReferencesCount; i++)
                {
                    // Get the reference
                    var reference = rom.References[i];

                    if (reference.BlockHeader.Type == GBC_BlockType.TileKit)
                    {
                        var tileKit = s.DoAt(reference.Pointer.GetPointer(), () => s.SerializeObject <GBC_TileKit>(default, name: $"TileKit[{i}]"));
コード例 #27
0
        /// <summary>
        /// Loads the specified level for the editor
        /// </summary>
        /// <param name="context">The serialization context</param>
        /// <param name="loadTextures">Indicates if textures should be loaded</param>
        /// <returns>The level</returns>
        public override async UniTask <Unity_Level> LoadAsync(Context context, bool loadTextures)
        {
            Controller.DetailedState = $"Loading allfix";

            // Read the allfix file
            await LoadExtraFile(context, GetAllfixFilePath(context.Settings), false);

            FileFactory.Read <R1_PS1_AllfixFile>(GetAllfixFilePath(context.Settings), context);

            R1_PS1_EventBlock eventBlock = null;
            MapData           mapData;

            if (context.Settings.R1_World != R1_World.Menu)
            {
                Controller.DetailedState = $"Loading world file";

                await Controller.WaitIfNecessary();

                // Read the world file
                await LoadExtraFile(context, GetWorldFilePath(context.Settings), false);

                FileFactory.Read <R1_PS1_WorldFile>(GetWorldFilePath(context.Settings), context);

                Controller.DetailedState = $"Loading map data";

                // Read the level data
                await LoadExtraFile(context, GetLevelFilePath(context.Settings), true);

                var level = FileFactory.Read <R1_PS1_LevFile>(GetLevelFilePath(context.Settings), context);

                eventBlock = level.EventData;
                mapData    = level.MapData;

                // Load special tile set file
                await LoadExtraFile(context, GetSpecialTileSetPath(context.Settings), true);
            }
            else
            {
                await LoadExtraFile(context, GetFontFilePath(context.Settings), false);

                mapData = MapData.GetEmptyMapData(384 / Settings.CellSize, 288 / Settings.CellSize);
            }

            // Load the level
            return(await LoadAsync(context, mapData, eventBlock?.Events, eventBlock?.EventLinkingTable.Select(x => (ushort)x).ToArray(), loadTextures));
        }
コード例 #28
0
        protected override async UniTask <IReadOnlyDictionary <string, string[]> > LoadLocalizationAsync(Context context)
        {
            var lngPath = GetLanguageFilePath();

            await AddFile(context, lngPath);

            // Read the language file
            var lng = FileFactory.ReadText <R1_PC_LNGFile>(lngPath, context);

            // Set the common localization
            return(new Dictionary <string, string[]>()
            {
                ["English1"] = lng.Strings[0],
                ["English2"] = lng.Strings[1],
                ["English3"] = lng.Strings[2],
                ["French"] = lng.Strings[3],
                ["German"] = lng.Strings[4],
            });
        }
コード例 #29
0
        /// <summary>
        /// Gets the tile set colors to use
        /// </summary>
        /// <param name="context">The context</param>
        /// <returns>The tile set colors to use</returns>
        public IList <BaseColor> GetTileSetColors(Context context)
        {
            var levelTileSetFileName = GetSpecialTileSetPath(context.Settings);

            if (FileSystem.FileExists(context.BasePath + levelTileSetFileName))
            {
                ObjectArray <RGBA5551Color> cols = FileFactory.Read <ObjectArray <RGBA5551Color> >(levelTileSetFileName, context, onPreSerialize: (s, x) => x.Length = s.CurrentLength / 2);
                return(cols.Value);
            }

            // Get the file name
            var filename = GetWorldFilePath(context.Settings);

            // Read the file
            var worldJPFile = FileFactory.Read <R1_PS1_WorldFile>(filename, context);

            // Return the tile set
            return(worldJPFile.RawTiles);
        }
コード例 #30
0
        public override async UniTask ExportMenuSpritesAsync(GameSettings settings, string outputPath, bool exportAnimFrames)
        {
            using (var context = new Context(settings))
            {
                // Load files
                await LoadFilesAsync(context);

                // Read level file
                var level = FileFactory.Read <R1_PS1JPDemo_LevFile>(GetLevelFilePath(context.Settings), context);

                // Export
                await ExportMenuSpritesAsync(context, null, outputPath, exportAnimFrames, new R1_PS1_FontData[]
                {
                    level.FontData
                }, new R1_EventData[]
                {
                    level.RaymanEvent
                }, null);
            }
        }