/// <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)); }
public void UpdateAndFillDataBlock(Pointer offset, R1_PS1_EventBlock originalBlock, R1_EventData[] events, byte[] eventLinkingTable, GameSettings settings) { long currentOffset = 0; Pointer getCurrentBlockPointer() { // Align by 4 if (currentOffset % 4 != 0) { currentOffset += 4 - currentOffset % 4; } return(offset + (1 * 4) + currentOffset); } originalBlock.EventCount = (byte)events.Length; originalBlock.EventsPointer = getCurrentBlockPointer(); originalBlock.Events = events; currentOffset += events.Length * 112; originalBlock.EventLinkCount = (byte)eventLinkingTable.Length; originalBlock.EventLinksPointer = getCurrentBlockPointer(); originalBlock.EventLinkingTable = eventLinkingTable; currentOffset += eventLinkingTable.Length; foreach (var e in events) { if (e.Commands != null) { e.CommandsPointer = getCurrentBlockPointer(); currentOffset += e.Commands.ToBytes(settings).Length; } else { e.CommandsPointer = null; } if (e.LabelOffsets != null) { e.LabelOffsetsPointer = getCurrentBlockPointer(); currentOffset += e.LabelOffsets.Length * 2; } else { e.LabelOffsetsPointer = null; } } }
/// <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)); }