public override void SerializeOffsetData(SerializerObject s) { // Parse level block data if (OffsetTable.Offsets[Index_PlayField] != -1) { PlayField = s.DoAt(OffsetTable.GetPointer(Index_PlayField), () => s.SerializeObject <GBA_PlayField>(PlayField, name: nameof(PlayField))); } // Parse actor data var actors = GetAllActors(s.GameSettings).ToArray(); for (var i = 0; i < actors.Length; i++) { if (actors[i].Type == GBA_Actor.ActorType.Captor) { actors[i].CaptorData = s.DoAt(OffsetTable.GetPointer(actors[i].Index_CaptorData, isRelativeOffset: IsGCNBlock), () => s.SerializeObject <GBA_CaptorData>(actors[i].CaptorData, onPreSerialize: bab => { bab.IsGCNBlock = IsGCNBlock; bab.Length = actors[i].LinkedActorsCount; }, name: $"{nameof(GBA_Actor.CaptorData)}[{i}]")); } else if (actors[i].Type != GBA_Actor.ActorType.Waypoint && actors[i].Type != GBA_Actor.ActorType.Unk && actors[i].Index_ActorModel < OffsetTable.OffsetsCount) { actors[i].ActorModel = s.DoAt(OffsetTable.GetPointer(actors[i].Index_ActorModel), () => s.SerializeObject <GBA_ActorModel>(actors[i].ActorModel, name: $"{nameof(GBA_Actor.ActorModel)}[{i}]")); } } }
public override void SerializeOffsetData(SerializerObject s) { // Parse level block data if (OffsetTable.Offsets[PlayFieldIndex] != -1) { PlayField = s.DoAt(OffsetTable.GetPointer(PlayFieldIndex), () => s.SerializeObject <GBA_PlayField>(PlayField, name: nameof(PlayField))); } // Parse actor data var actors = GetAllActors(s.GameSettings).ToArray(); for (var i = 0; i < actors.Length; i++) { if (actors[i].Type == GBA_Actor.ActorType.BoxTrigger) { actors[i].BoxActorBlock = s.DoAt(OffsetTable.GetPointer(actors[i].BoxActorBlockOffsetIndex, isRelativeOffset: IsGCNBlock), () => s.SerializeObject <GBA_BoxTriggerActorDataBlock>(actors[i].BoxActorBlock, onPreSerialize: bab => { bab.IsGCNBlock = IsGCNBlock; bab.Length = actors[i].LinkedActorsCount; }, name: $"{nameof(GBA_Actor.BoxActorBlock)}[{i}]")); } else if (actors[i].Type != GBA_Actor.ActorType.Trigger && actors[i].Type != GBA_Actor.ActorType.Unk && actors[i].GraphicsDataIndex < OffsetTable.OffsetsCount) { actors[i].GraphicData = s.DoAt(OffsetTable.GetPointer(actors[i].GraphicsDataIndex), () => s.SerializeObject <GBA_ActorGraphicData>(actors[i].GraphicData, name: $"{nameof(GBA_Actor.GraphicData)}[{i}]")); } } }
public override void SerializeImpl(SerializerObject s) { Offsets = s.SerializePointerArray <Array <ushort> >(Offsets, 6, resolve: true, onPreSerialize: x => x.Length = 690, name: nameof(Offsets)); LocTables = s.SerializePointerArray(LocTables, 6, name: nameof(LocTables)); if (Localization == null) { Localization = new string[Offsets.Length][]; for (int i = 0; i < Localization.Length; i++) { Localization[i] = new string[Offsets[i].Value.Length]; s.DoAt(LocTables[i], () => { s.DoEncoded(new RHREncoder(), () => { Pointer basePtr = s.CurrentPointer; for (int j = 0; j < Offsets[i].Value.Length; j++) { s.DoAt(basePtr + Offsets[i].Value.Value[j], () => { Localization[i][j] = s.SerializeString(Localization[i][j], encoding: Encoding.GetEncoding(1252), name: $"{nameof(Localization)}[{i}][{j}]"); }); } // Go to end s.Goto(s.CurrentPointer + s.CurrentLength); }); }); } } }
} // References to some of the states in the normal state array public override void SerializeImpl(SerializerObject s) { UnknownStatesPointer = s.SerializeObject <SNES_Pointer>(UnknownStatesPointer, onPreSerialize: x => x.MemoryBankOverride = 4, name: nameof(UnknownStatesPointer)); ImageDescriptorsPointer = s.SerializeObject <SNES_Pointer>(ImageDescriptorsPointer, onPreSerialize: x => x.MemoryBankOverride = 4, name: nameof(ImageDescriptorsPointer)); Ushort_04 = s.Serialize <ushort>(Ushort_04, name: nameof(Ushort_04)); XPosition = s.Serialize <short>(XPosition, name: nameof(XPosition)); YPosition = s.Serialize <short>(YPosition, name: nameof(YPosition)); Bytes_0A = s.SerializeArray <byte>(Bytes_0A, 6, name: nameof(Bytes_0A)); StatesPointer = s.SerializeObject <SNES_Pointer>(StatesPointer, onPreSerialize: x => x.MemoryBankOverride = 4, name: nameof(StatesPointer)); if (!s.FullSerialize) { return; } // Serialize data from pointers States = s.DoAt(StatesPointer.GetPointer(), () => s.SerializeObjectArray <SNES_Proto_State>(States, 5 * 0x15, name: nameof(States))); ImageDescriptors = s.DoAt(ImageDescriptorsPointer.GetPointer(), () => s.SerializeObjectArray <SNES_Proto_ImageDescriptor>(ImageDescriptors, States.Max(state => state.Animation?.Layers.Max(layer => layer.ImageIndex + 1) ?? 0), name: nameof(ImageDescriptors))); UnknownStatesPointers = s.DoAt(UnknownStatesPointer.GetPointer(), () => s.SerializeObjectArray <SNES_Pointer>(UnknownStatesPointers, 16, onPreSerialize: x => x.MemoryBankOverride = 4, name: nameof(UnknownStatesPointers))); if (UnknownStates == null) { UnknownStates = new SNES_Proto_State[UnknownStatesPointers.Length]; } for (int i = 0; i < UnknownStates.Length; i++) { UnknownStates[i] = s.DoAt(UnknownStatesPointers[i].GetPointer(), () => s.SerializeObject <SNES_Proto_State>(UnknownStates[i], name: $"{nameof(UnknownStates)}[{i}]")); } }
public override void SerializeOffsetData(SerializerObject s) { if (s.GameSettings.EngineVersion > EngineVersion.GBA_R3_MadTrax) { // Serialize tile palette if (Palettes == null) { Palettes = new GBA_Palette[PaletteCount]; } for (int p = 0; p < Palettes.Length; p++) { Palettes[p] = s.DoAt(OffsetTable.GetPointer(PaletteIndices[p]), () => s.SerializeObject <GBA_Palette>(Palettes[p], name: $"{nameof(Palettes)}[{p}]")); } // Serialize tile animations if (AnimatedTileKitManagerIndex != 0xFF) { AnimatedTileKitManager = s.DoAt(OffsetTable.GetPointer(AnimatedTileKitManagerIndex), () => s.SerializeObject <GBA_AnimatedTileKitManager>(AnimatedTileKitManager, name: nameof(AnimatedTileKitManager))); if (AnimatedTileKits == null) { AnimatedTileKits = new GBA_AnimatedTileKit[AnimatedTileKitManager.Length]; } for (int i = 0; i < AnimatedTileKits.Length; i++) { AnimatedTileKits[i] = s.DoAt(OffsetTable.GetPointer(AnimatedTileKitManager.TileKitBlocks[i]), () => s.SerializeObject <GBA_AnimatedTileKit>(AnimatedTileKits[i], name: $"{nameof(AnimatedTileKits)}[{i}]")); } Debug.Log("Level " + s.GameSettings.Level + " (" + s.GameSettings.World + ") has " + AnimatedTileKits.Length + " animated tilekits."); } } }
/// <summary> /// Handles the data serialization /// </summary> /// <param name="s">The serializer object</param> public override void SerializeImpl(SerializerObject s) { // Serialize header EventsPointer = s.SerializePointer(EventsPointer, name: nameof(EventsPointer)); EventCount = s.Serialize <byte>(EventCount, name: nameof(EventCount)); s.SerializeArray <byte>(new byte[3], 3, name: "Padding"); EventLinksPointer = s.SerializePointer(EventLinksPointer, name: nameof(EventLinksPointer)); EventLinkCount = s.Serialize <byte>(EventLinkCount, name: nameof(EventLinkCount)); s.SerializeArray <byte>(new byte[3], 3, name: "Padding"); if (EventCount != EventLinkCount) { Debug.LogError("Event counts don't match"); } s.DoAt(EventsPointer, (() => { // Serialize every event Events = s.SerializeObjectArray <R1_EventData>(Events, EventCount, name: nameof(Events)); })); s.DoAt(EventLinksPointer, (() => { // Serialize the event linking table EventLinkingTable = s.SerializeArray <byte>(EventLinkingTable, EventLinkCount, name: nameof(EventLinkingTable)); })); }
public override void SerializeBlock(SerializerObject s) { UShort_00 = s.Serialize <ushort>(UShort_00, name: nameof(UShort_00)); PatternOffsetsOffset = s.Serialize <ushort>(PatternOffsetsOffset, name: nameof(PatternOffsetsOffset)); Byte_04 = s.Serialize <byte>(Byte_04, name: nameof(Byte_04)); PatternCount = s.Serialize <byte>(PatternCount, name: nameof(PatternCount)); UInt_06 = s.Serialize <uint>(UInt_06, name: nameof(UInt_06)); s.DoAt(BlockStartPointer + PatternOffsetsOffset, () => { PatternOffsets = s.SerializeArray <ushort>(PatternOffsets, PatternCount, name: nameof(PatternOffsets)); }); if (Patterns == null) { Patterns = new Pattern[PatternCount]; } for (int i = 0; i < PatternCount; i++) { Patterns[i] = s.DoAt(BlockStartPointer + PatternOffsets[i], () => { return(s.SerializeObject <Pattern>(Patterns[i], name: $"{nameof(Patterns)}[{i}]")); }); } if (Patterns.Length > 0) { s.Goto(Patterns[Patterns.Length - 1].Offset + Patterns[Patterns.Length - 1].Size); } }
/// <summary> /// Handles the data serialization /// </summary> /// <param name="s">The serializer object</param> public override void SerializeImpl(SerializerObject s) { // Get offsets var offsetTableOffset = s.GameSettings.EngineVersion != EngineVersion.R1Jaguar_Proto ? Offset + 0x1208 : new R1Jaguar_Proto_Manager().GetDataPointer(s.Context, R1Jaguar_Proto_References.test_offlist); var eventTableOffset = s.GameSettings.EngineVersion != EngineVersion.R1Jaguar_Proto ? Offset + 0x1608 : new R1Jaguar_Proto_Manager().GetDataPointer(s.Context, R1Jaguar_Proto_References.test_event); MapEvents = s.SerializeObject <R1Jaguar_MapEvents>(MapEvents, name: nameof(MapEvents)); // Serialize next data block, skipping the padding s.DoAt(offsetTableOffset, () => EventOffsetTable = s.SerializeArray <ushort>(EventOffsetTable, MapEvents.EventIndexMap.Max(), name: nameof(EventOffsetTable))); if (EventData == null) { EventData = new R1Jaguar_EventInstance[EventOffsetTable.Length][]; } // Serialize the events based on the offsets for (int i = 0; i < EventData.Length; i++) { s.DoAt(eventTableOffset + EventOffsetTable[i], () => { if (EventData[i] == null) { var temp = new List <R1Jaguar_EventInstance>(); var index = 0; while (temp.LastOrDefault()?.Unk_00 != 0) { temp.Add(s.SerializeObject <R1Jaguar_EventInstance>(default, name: $"{nameof(EventData)}[{i}][{index}]"));
public override void SerializeImpl(SerializerObject s) { TileSetPointer = s.SerializePointer <GBAIsometric_RHR_TileSet>(TileSetPointer, resolve: true, name: nameof(TileSetPointer)); StructType = s.Serialize <MapLayerType>(StructType, name: nameof(StructType)); Width = s.Serialize <ushort>(Width, name: nameof(Width)); Height = s.Serialize <ushort>(Height, name: nameof(Height)); Ushort_0A = s.Serialize <ushort>(Ushort_0A, name: nameof(Ushort_0A)); MapDataPointer = s.SerializePointer(MapDataPointer, name: nameof(MapDataPointer)); MapPalettePointer = s.SerializePointer(MapPalettePointer, name: nameof(MapPalettePointer)); MapPalette = s.DoAt(MapPalettePointer, () => s.SerializeObjectArray <RGBA5551Color>(MapPalette, 256, name: nameof(MapPalette))); s.DoAt(MapDataPointer, () => { s.DoEncoded(new RHREncoder(), () => MapData = s.SerializeArray <ushort>(MapData, Width * Height, name: nameof(MapData))); }); // Debug tilemaps //ushort[] fullMap = CreateFullMap(MapData); //string logString = $"{Offset}: Max Tilemap Value - {fullMap.Max()}"; //UnityEngine.Debug.Log(logString); //s.Log(logString); //byte[] result = new byte[fullMap.Length * sizeof(ushort)]; //Buffer.BlockCopy(fullMap, 0, result, 0, result.Length); //Util.ByteArrayToFile(s.Context.BasePath + "full_tilemap/" + Offset.StringAbsoluteOffset + ".bin", result); }
/// <summary> /// Handles the data serialization /// </summary> /// <param name="s">The serializer object</param> public override void SerializeImpl(SerializerObject s) { // Serialize ROM header base.SerializeImpl(s); var manager = ((GBA_Manager)s.Context.Settings.GetGameManager); // Get the pointer table var pointerTable = PointerTables.GBA_PointerTable(s.Context, Offset.file); var lvlType = manager.GetLevelType(s.Context); // Serialize the offset table if (lvlType != GBA_Manager.LevelType.R3SinglePak) { s.DoAt(pointerTable[GBA_Pointer.UiOffsetTable], () => Data = s.SerializeObject <GBA_Data>(Data, name: nameof(Data))); } // Serialize level info if (pointerTable.ContainsKey(GBA_Pointer.LevelInfo)) { LevelInfo = s.DoAt(pointerTable[GBA_Pointer.LevelInfo], () => s.SerializeObjectArray <GBA_R3_SceneInfo>(LevelInfo, manager.LevelCount, name: nameof(LevelInfo))); } // Serialize localization if (pointerTable.ContainsKey(GBA_Pointer.Localization)) { if (s.GameSettings.GBA_IsMilan) { s.DoAt(pointerTable[GBA_Pointer.Localization], () => Milan_Localization = s.SerializeObject <GBA_Milan_LocTable>(Milan_Localization, name: nameof(Milan_Localization))); } else { s.DoAt(pointerTable[GBA_Pointer.Localization], () => Localization = s.SerializeObject <GBA_LocLanguageTable>(Localization, name: nameof(Localization))); } } // Serialize actor type data if (pointerTable.ContainsKey(GBA_Pointer.ActorTypeTable)) { ActorTypeTable = s.DoAt(pointerTable[GBA_Pointer.ActorTypeTable], () => s.SerializeObjectArray <GBA_ActorTypeTableEntry>(ActorTypeTable, manager.ActorTypeTableLength, name: nameof(ActorTypeTable))); } if (lvlType == GBA_Manager.LevelType.R3SinglePak) { R3SinglePak_OffsetTable = s.DoAt(pointerTable[GBA_Pointer.R3SinglePak_OffsetTable], () => s.SerializeObject <GBA_OffsetTable>(R3SinglePak_OffsetTable, name: nameof(R3SinglePak_OffsetTable))); R3SinglePak_Palette = s.DoAt(pointerTable[GBA_Pointer.R3SinglePak_Palette], () => s.SerializeObjectArray <RGBA5551Color>(R3SinglePak_Palette, 256, name: nameof(R3SinglePak_Palette))); R3SinglePak_TileMap = s.DoAt(pointerTable[GBA_Pointer.R3SinglePak_TileMap], () => s.SerializeArray <ushort>(R3SinglePak_TileMap, 0x400, name: nameof(R3SinglePak_TileMap))); R3SinglePak_TileSet = s.DoAt(pointerTable[GBA_Pointer.R3SinglePak_TileSet], () => s.SerializeArray <byte>(R3SinglePak_TileSet, (R3SinglePak_TileMap.Max() + 1) * 0x40, name: nameof(R3SinglePak_TileSet))); if (R3SinglePak_Puppets == null) { R3SinglePak_Puppets = new GBA_Puppet[R3SinglePak_OffsetTable.OffsetsCount]; } for (int i = 0; i < R3SinglePak_Puppets.Length; i++) { R3SinglePak_Puppets[i] = s.DoAt(R3SinglePak_OffsetTable.GetPointer(i), () => s.SerializeObject <GBA_Puppet>(R3SinglePak_Puppets[i], name: $"{nameof(R3SinglePak_Puppets)}[{i}]")); } } }
public override void SerializeImpl(SerializerObject s) { // Get the language count for the current game var langCount = ((GBAIsometric_Spyro_Manager)s.GameSettings.GetGameManager).GetLanguages.Count(); var pointerTable = PointerTables.GBAIsometric_Spyro_PointerTable(s.GameSettings.GameModeSelection, Offset.file); if (s.GameSettings.EngineVersion == EngineVersion.GBAIsometric_Spyro3) { // Parse loc tables LocalizationBlockIndices = s.DoAt(pointerTable.TryGetItem(GBAIsometric_Spyro_Pointer.LocalizationBlockIndices), () => s.SerializeObjectArray <GBAIsometric_Spyro_DataBlockIndex>(LocalizationBlockIndices, langCount, x => x.HasPadding = true, name: nameof(LocalizationBlockIndices))); LocalizationDecompressionBlockIndices = s.DoAt(pointerTable.TryGetItem(GBAIsometric_Spyro_Pointer.LocalizationDecompressionBlockIndices), () => s.SerializeObjectArray <GBAIsometric_Spyro_DataBlockIndex>(LocalizationDecompressionBlockIndices, langCount, x => x.HasPadding = true, name: nameof(LocalizationDecompressionBlockIndices))); LocTables = s.DoAt(pointerTable.TryGetItem(GBAIsometric_Spyro_Pointer.LocTables), () => s.SerializeObjectArray <GBAIsometric_Spyro_LocTable>(LocTables, 38, name: nameof(LocTables))); // Parse block data if (LocDecompressHelpers == null) { LocDecompressHelpers = new GBAIsometric_Spyro_LocDecompress[langCount][]; } for (int i = 0; i < LocDecompressHelpers.Length; i++) { LocDecompressHelpers[i] = LocalizationDecompressionBlockIndices[i].DoAtBlock(size => s.SerializeObjectArray <GBAIsometric_Spyro_LocDecompress>(LocDecompressHelpers[i], size / 3, name: $"{nameof(LocDecompressHelpers)}[{i}]")); } if (LocBlocks == null) { LocBlocks = new GBAIsometric_Spyro_LocBlock[langCount]; } for (int i = 0; i < LocBlocks.Length; i++) { LocBlocks[i] = LocalizationBlockIndices[i].DoAtBlock(size => s.SerializeObject <GBAIsometric_Spyro_LocBlock>(LocBlocks[i], onPreSerialize: lb => { lb.Length = LocTables.Max(lt => lt.StartIndex + lt.NumEntries); lb.DecompressHelpers = LocDecompressHelpers[i]; }, name: $"{nameof(LocBlocks)}[{i}]")); } } else { LocalizationPointers = s.DoAt(pointerTable.TryGetItem(GBAIsometric_Spyro_Pointer.LocalizationPointers), () => s.SerializePointerArray(LocalizationPointers, langCount, name: nameof(LocalizationPointers))); if (LocBlocks == null) { LocBlocks = new GBAIsometric_Spyro_LocBlock[langCount]; } for (int i = 0; i < LocBlocks.Length; i++) { LocBlocks[i] = s.DoAt(LocalizationPointers[i], () => s.SerializeObject <GBAIsometric_Spyro_LocBlock>(LocBlocks[i], name: $"{nameof(LocBlocks)}[{i}]")); } } // Store the localization tables so we can access them to get the strings s.Context.StoreObject("Loc", LocBlocks.Select(x => x.Strings).ToArray()); }
public override void SerializeImpl(SerializerObject s) { PalettePointer = s.SerializePointer(PalettePointer, name: nameof(PalettePointer)); TileSetPointer = s.SerializePointer(TileSetPointer, name: nameof(TileSetPointer)); Palette = s.DoAt(PalettePointer, () => s.SerializeObject <GBAVV_WorldMap_Palette>(Palette, name: nameof(Palette))); TileSet = s.DoAt(TileSetPointer, () => s.SerializeObject <GBAVV_Map2D_TileSet>(TileSet, name: nameof(TileSet))); }
/// <summary> /// Handles the data serialization /// </summary> /// <param name="s">The serializer object</param> public override void SerializeImpl(SerializerObject s) { // Get info var pointerTable = s.GameSettings.EngineVersion != EngineVersion.R1Jaguar_Proto ? PointerTables.JaguarR1_PointerTable(s.GameSettings.EngineVersion, this.Offset.file) : null; var manager = (R1Jaguar_Manager)s.GameSettings.GetGameManager; var levels = manager.GetNumLevels; // Serialize the references for the prototype if (s.GameSettings.EngineVersion == EngineVersion.R1Jaguar_Proto) { s.DoAt(new Pointer(0x8BB6A8, Offset.file), () => { References = s.SerializeObjectArray <R1Jaguar_ReferenceEntry>(References, 1676, onPreSerialize: (x => x.StringBase = new Pointer(0x8C0538, Offset.file)), name: nameof(References)); // Unknown initial 4 bytes, part of the string table UnkReferenceValue = s.Serialize <uint>(UnkReferenceValue, name: nameof(UnkReferenceValue)); }); } // Serialize event definition data if (s.GameSettings.EngineVersion == EngineVersion.R1Jaguar) { if (!s.Context.FileExists("RAM_EventDefinitions")) { // Copied to 0x001f9000 in memory. All pointers to 0x001Fxxxx likely point to an entry in this table s.DoAt(pointerTable[JaguarR1_Pointer.EventDefinitions], () => { byte[] EventDefsDataBytes = s.SerializeArray <byte>(null, manager.EventCount * 0x28, name: nameof(EventDefsDataBytes)); var file = new MemoryMappedByteArrayFile("RAM_EventDefinitions", EventDefsDataBytes, s.Context, 0x001f9000) { Endianness = BinaryFile.Endian.Big }; s.Context.AddFile(file); s.DoAt(file.StartPointer, () => EventDefinitions = s.SerializeObjectArray <R1Jaguar_EventDefinition>(EventDefinitions, manager.EventCount, name: nameof(EventDefinitions))); }); } } else { var offset = s.GameSettings.EngineVersion == EngineVersion.R1Jaguar_Proto ? GetProtoDataPointer(R1Jaguar_Proto_References.MS_rayman) : pointerTable[JaguarR1_Pointer.EventDefinitions]; // Pointers all point to the ROM, not RAM s.DoAt(offset, () => EventDefinitions = s.SerializeObjectArray <R1Jaguar_EventDefinition>(EventDefinitions, manager.EventCount, name: nameof(EventDefinitions))); } if (AdditionalEventDefinitions == null) { if (s.GameSettings.EngineVersion != EngineVersion.R1Jaguar_Proto) { AdditionalEventDefinitions = manager.AdditionalEventDefinitionPointers.Select(p => { return(s.DoAt(new Pointer(p, pointerTable[JaguarR1_Pointer.EventDefinitions].file), () => s.SerializeObject <R1Jaguar_EventDefinition>(default, name: nameof(AdditionalEventDefinitions))));
public override void SerializeImpl(SerializerObject s) { GraphicsDataPointer = s.SerializePointer <GBAIsometric_RHR_GraphicsData>(GraphicsDataPointer, resolve: true, name: nameof(GraphicsDataPointer)); PaletteIndexTablePointer = s.SerializePointer <GBAIsometric_RHR_PaletteIndexTable>(PaletteIndexTablePointer, resolve: true, onPreSerialize: pit => pit.Length = GraphicsDataPointer.Value.CompressionLookupBufferLength, name: nameof(PaletteIndexTablePointer)); CombinedTileDataPointer = s.SerializePointer(CombinedTileDataPointer, name: nameof(CombinedTileDataPointer)); CombinedTileOffsetsPointer = s.SerializePointer(CombinedTileOffsetsPointer, name: nameof(CombinedTileOffsetsPointer)); for (int i = 0; i < 4; i++) { AssembleData[i] = s.SerializeObject <GBAIsometric_RHR_TileAssemble>(AssembleData[i], onPreSerialize: ad => ad.TileCompression = (GBAIsometric_RHR_TileAssemble.Compression)i, name: $"{nameof(AssembleData)}[{i}]"); } PalettesPointer = s.SerializePointer(PalettesPointer, name: nameof(PalettesPointer)); // Todo: Read these in a less hacky way s.DoAt(CombinedTileDataPointer, () => { CombinedTileData = s.SerializeArray <ushort>(CombinedTileData, (CombinedTileOffsetsPointer - CombinedTileDataPointer) / 2, name: nameof(CombinedTileData)); }); s.DoAt(CombinedTileOffsetsPointer, () => { if (CombinedTileDataPointer == CombinedTileOffsetsPointer) { CombinedTileOffsets = new ushort[0]; } else { uint length = 0; s.DoAt(CombinedTileOffsetsPointer, () => { ushort CombinedTileOffsetsLengthHack = 0; while (CombinedTileOffsetsLengthHack < CombinedTileData.Length) { CombinedTileOffsetsLengthHack = s.Serialize <ushort>(CombinedTileOffsetsLengthHack, name: nameof(CombinedTileOffsetsLengthHack)); } length = (uint)((s.CurrentPointer - CombinedTileOffsetsPointer) / 2); }); CombinedTileOffsets = s.SerializeArray <ushort>(CombinedTileOffsets, length, name: nameof(CombinedTileOffsets)); } }); s.DoAt(PalettesPointer, () => { if (Palettes == null) { Palettes = new RGBA5551Color[PaletteIndexTablePointer.Value.GetMaxPaletteIndex() + 1][]; } for (int i = 0; i < Palettes.Length; i++) { Palettes[i] = s.SerializeObjectArray <RGBA5551Color>(Palettes[i], 16, name: $"{nameof(Palettes)}[i]"); } }); s.DoEncoded(new RHR_SpriteEncoder(false, GraphicsDataPointer.Value.CompressionLookupBuffer, GraphicsDataPointer.Value.CompressedDataPointer), () => { byte[] fullSheet = s.SerializeArray <byte>(default, s.CurrentLength, name: nameof(fullSheet));
public override void SerializeImpl(SerializerObject s) { ID = s.Serialize <byte>(ID, name: nameof(ID)); NumEntries = s.Serialize <ushort>(NumEntries, name: nameof(NumEntries)); Pos = s.Serialize <ushort>(Pos, name: nameof(Pos)); Padding = s.Serialize <ushort>(Padding, name: nameof(Padding)); s.DoAt(new Pointer(Pos, Offset.file), () => { Entries = s.SerializeObjectArray <Entry>(Entries, NumEntries, name: nameof(Entries)); }); Strings = new string[NumEntries]; for (int i = 0; i < Entries.Length; i++) { s.DoAt(new Pointer(Entries[i].Pos, Offset.file), () => { s.DoEncoded(new Eclipse_StringEncoder(HuffTable, Entries[i]), () => { var bytes = s.SerializeArray <byte>(default, s.CurrentLength, "bytes[" + i + "]");
public override void SerializeImpl(SerializerObject s) { MapTilesPointer = s.SerializePointer(MapTilesPointer, name: nameof(MapTilesPointer)); TileMapPointer = s.SerializePointer(TileMapPointer, name: nameof(TileMapPointer)); LayerPrio = s.Serialize <uint>(LayerPrio, name: nameof(LayerPrio)); ScrollX = s.Serialize <uint>(ScrollX, name: nameof(ScrollX)); ScrollY = s.Serialize <uint>(ScrollY, name: nameof(ScrollY)); Uint_14 = s.Serialize <uint>(Uint_14, name: nameof(Uint_14)); Uint_18 = s.Serialize <uint>(Uint_18, name: nameof(Uint_18)); TileMap = s.DoAt(TileMapPointer, () => s.SerializeObject <GBAVV_Isometric_MapLayer>(TileMap, x => x.IsWorldMap = true, name: nameof(TileMap))); var mapTilesLength = TileMap.TileMapRows.SelectMany(x => x.Commands).Select(x => x.Params?.Max() ?? x.Param).Max() + 1; MapTiles = s.DoAt(MapTilesPointer, () => s.SerializeObjectArray <MapTile>(MapTiles, mapTilesLength * 4, x => x.GBAVV_IsWorldMap8bpp = Is8bpp, name: nameof(MapTiles))); }
public void DecryptSaveFiles(GameSettings settings) { using (var context = new Context(settings)) { foreach (var save in Directory.GetFiles(settings.GameDirectory, "*.sav", SearchOption.TopDirectoryOnly).Select(Path.GetFileName)) { LinearSerializedFile f = new LinearSerializedFile(context) { filePath = save }; context.AddFile(f); SerializerObject s = context.Deserializer; byte[] saveData = null; s.DoAt(f.StartPointer, () => { s.DoEncoded(new PC_R1_SaveEncoder(), () => { saveData = s.SerializeArray <byte>(saveData, s.CurrentLength, name: "SaveData"); Util.ByteArrayToFile(context.BasePath + save + ".dec", saveData); }); }); /*LinearSerializedFile f2 = new LinearSerializedFile(context) { * filePath = save + ".recompressed" * }; * context.AddFile(f2); * s = context.Serializer; * s.DoAt(f2.StartPointer, () => { * s.DoEncoded(new R1PCSaveEncoder(), () => { * saveData = s.SerializeArray<byte>(saveData, saveData.Length, name: "SaveData"); * }); * });*/ } } }
public override void SerializeImpl(SerializerObject s) { AnimSetsPointer = s.SerializePointer(AnimSetsPointer, name: nameof(AnimSetsPointer)); TileSetPointer = s.SerializePointer(TileSetPointer, name: nameof(TileSetPointer)); PalettesPointer = s.SerializePointer(PalettesPointer, name: nameof(PalettesPointer)); AnimSetsCount = s.Serialize <ushort>(AnimSetsCount, name: nameof(AnimSetsCount)); PalettesCount = s.Serialize <ushort>(PalettesCount, name: nameof(PalettesCount)); AnimSets = s.DoAt(AnimSetsPointer, () => s.SerializeObjectArray <GBAVV_Map2D_AnimSet>(AnimSets, AnimSetsCount, name: nameof(AnimSets))); var tileSetLength = AnimSets.SelectMany(x => x.AnimationFrames).Select(x => x.TileOffset + (x.TileShapes.Select(t => (GBAVV_Map2D_AnimSet.TileShapes[t.ShapeIndex].x * GBAVV_Map2D_AnimSet.TileShapes[t.ShapeIndex].y) / 2).Sum())).Max(); TileSet = s.DoAt(TileSetPointer, () => s.SerializeArray <byte>(TileSet, tileSetLength, name: nameof(TileSet))); Palettes = s.DoAt(PalettesPointer, () => s.SerializeObjectArray <GBAVV_Map2D_ObjPal>(Palettes, PalettesCount, name: nameof(Palettes))); }
public override void SerializeBlock(SerializerObject s) { if (s.GameSettings.GBA_IsMilan && s.GameSettings.EngineVersion != EngineVersion.GBA_TomClancysRainbowSixRogueSpear) { // Copied from function at 0x080087e4 in The Mummy (US) // Serialize header s.DoAt(ShanghaiOffsetTable.GetPointer(0), () => { Milan_Ushort_00 = s.Serialize <ushort>(Milan_Ushort_00, name: nameof(Milan_Ushort_00)); Milan_Ushort_02 = s.Serialize <ushort>(Milan_Ushort_02, name: nameof(Milan_Ushort_02)); }); // Go to palette data s.Goto(ShanghaiOffsetTable.GetPointer(1)); if (Milan_Palettes == null) { Milan_Palettes = new Dictionary <int, RGBA5551Color[]>(); if (Milan_Ushort_00 == 0) { var palIndex = 0; do { if (BitHelpers.ExtractBits(Milan_Ushort_02, 1, palIndex) == 1) { var pal = s.SerializeObjectArray <RGBA5551Color>(default, 0x10, name: $"Palette[{palIndex}]");
public override void SerializeBlock(SerializerObject s) { if (DependencyTable.DependenciesCount > 0) { if (Vignettes == null) { Vignettes = new GBC_Vignette[DependencyTable.DependenciesCount]; } for (int i = 0; i < Vignettes.Length; i++) { Vignettes[i] = s.DoAt(DependencyTable.GetPointer(i), () => s.SerializeObject <GBC_Vignette>(Vignettes[i], name: $"{nameof(Vignettes)}[{i}]")); } } else { // Serialize data Width = s.Serialize <byte>(Width, name: nameof(Width)); Height = s.Serialize <byte>(Height, name: nameof(Height)); UnkData = s.SerializeArray <byte>(UnkData, 14, name: nameof(UnkData)); Palette = s.SerializeObjectArray <RGBA5551Color>(Palette, 4 * 8, name: nameof(Palette)); TileSet = s.SerializeArray <byte>(TileSet, Width * Height * 0x10, name: nameof(TileSet)); PalIndices = s.SerializeArray <byte>(PalIndices, Width * Height, name: nameof(PalIndices)); } }
public override void SerializeImpl(SerializerObject s) { if (SerializeValues) { Index = s.Serialize <uint>(Index, name: nameof(Index)); AnimationsPointer = s.SerializePointer(AnimationsPointer, name: nameof(AnimationsPointer)); FrameOffsetsPointer = s.SerializePointer(FrameOffsetsPointer, name: nameof(FrameOffsetsPointer)); PaletteIndex = s.Serialize <uint>(PaletteIndex, name: nameof(PaletteIndex)); Uint_10 = s.Serialize <uint>(Uint_10, name: nameof(Uint_10)); Short_14 = s.Serialize <short>(Short_14, name: nameof(Short_14)); Short_16 = s.Serialize <short>(Short_16, name: nameof(Short_16)); Short_18 = s.Serialize <short>(Short_18, name: nameof(Short_18)); Short_1A = s.Serialize <short>(Short_1A, name: nameof(Short_1A)); Short_1C = s.Serialize <short>(Short_1C, name: nameof(Short_1C)); Bytes_1E = s.SerializeArray <byte>(Bytes_1E, 10, name: nameof(Bytes_1E)); } s.DoAt(AnimationsPointer, () => { if (Animations == null) { // Since there is no count we read until we get to an invalid animation var anims = new List <GBAVV_Mode7_Animation>(); var currentFrameIndex = 0; var index = 0; while (true) { var anim = s.SerializeObject <GBAVV_Mode7_Animation>(default, name: $"{nameof(Animations)}[{index}]");
public override void SerializeImpl(SerializerObject s) { var animLength = Animations?.Length ?? -1; if (animLength == -1) { var firstAnim = s.DoAt(s.CurrentPointer, () => s.SerializeObject <GBAIsometric_Spyro_Animation>(default, name: $"{nameof(Animations)}[0]"));
public override void SerializeImpl(SerializerObject s) { PointersPointer = s.SerializePointer <GBAIsometric_LevelDataLayerDataPointers>(PointersPointer, resolve: true, name: nameof(PointersPointer)); StructType = s.Serialize <MapLayerType>(StructType, name: nameof(StructType)); Width = s.Serialize <ushort>(Width, name: nameof(Width)); Height = s.Serialize <ushort>(Height, name: nameof(Height)); Ushort_0A = s.Serialize <ushort>(Ushort_0A, name: nameof(Ushort_0A)); MapDataPointer = s.SerializePointer(MapDataPointer, name: nameof(MapDataPointer)); Pointer_20 = s.SerializePointer(Pointer_20, name: nameof(Pointer_20)); if (StructType == MapLayerType.Map) { Palette = s.SerializeObjectArray <ARGB1555Color>(Palette, 256, name: nameof(Palette)); RemainingData = s.SerializeArray <byte>(RemainingData, 44, name: nameof(RemainingData)); } // TODO: Remove try/catch try { s.DoAt(MapDataPointer, () => { s.DoEncoded(new RHREncoder(), () => { MapData = s.SerializeArray <ushort>(MapData, Width * Height, name: nameof(MapData)); }); }); } catch (Exception ex) { Debug.LogWarning($"Failed to decompress {MapDataPointer}: {ex.Message}\n{ex.InnerException?.StackTrace}"); } }
public override void SerializeBlock(SerializerObject s) { Data = s.SerializeArray <byte>(Data, BlockSize, name: nameof(Data)); // Serialize sub-blocks if (SubBlocks == null) { SubBlocks = new GBC_DummyBlock[DependencyTable.DependenciesCount]; } // Get all root pointers var rootBlock = ((GBC_BaseManager)s.GameSettings.GetGameManager).GetLevelList(s.Context); var rootTable = rootBlock.DependencyTable; var rootPointers = Enumerable.Range(0, rootTable.Dependencies.Length).Select(x => rootTable.GetPointer(x)).ToArray(); for (int i = 0; i < DependencyTable.Dependencies.Length; i++) { var p = DependencyTable.GetPointer(i); if (rootPointers.Contains(p) && Offset != rootBlock.Offset) { continue; } SubBlocks[i] = s.DoAt(p, () => s.SerializeObject <GBC_DummyBlock>(SubBlocks[i], name: $"{nameof(SubBlocks)}[{i}]")); } }
public override void SerializeBlock(SerializerObject s) { if (s.GameSettings.EngineVersion >= EngineVersion.GBA_SplinterCell) { MatrixOffsets = s.SerializeArray <ushort>(MatrixOffsets, FrameCount, name: nameof(MatrixOffsets)); s.Align(4); if (Matrices == null) { Matrices = new GBA_AffineMatrix[FrameCount][]; } for (int i = 0; i < Matrices.Length; i++) { ushort offset = MatrixOffsets[i]; uint count = (uint)Math.Min((BlockSize - offset) / 8, 32); s.DoAt(Offset + offset, () => { Matrices[i] = s.SerializeObjectArray <GBA_AffineMatrix>(Matrices[i], count, name: $"{nameof(Matrices)}[{i}]"); }); } s.Goto(Offset + BlockSize); } else { if (Matrices == null) { Matrices = new GBA_AffineMatrix[1][]; } Matrices[0] = s.SerializeObjectArray <GBA_AffineMatrix>(Matrices[0], BlockSize / 8, name: $"{nameof(Matrices)}[{0}]"); } }
} // Set before serializing public override void SerializeBlock(SerializerObject s) { var baseOffset = s.CurrentPointer; for (var animSetIndex = 0; animSetIndex < AnimSets.Length; animSetIndex++) { var animSet = AnimSets[animSetIndex]; if (animSet.FrameOffsets == null) { animSet.ObjFrames = new GBAVV_Mode7_ObjFrame[0]; continue; } if (animSet.ObjFrames == null) { var frames = new List <GBAVV_Mode7_ObjFrame>(); for (var frameIndex = 0; frameIndex < animSet.FrameOffsets.Length; frameIndex++) { var offset = animSet.FrameOffsets[frameIndex]; var pointer = offset > 0x08000000 ? new Pointer(offset, Offset.file) : baseOffset + offset; var frame = s.DoAt(pointer, () => s.SerializeObject <GBAVV_Mode7_ObjFrame>(default, name: $"{nameof(AnimSets)}[{animSetIndex}].{nameof(animSet.ObjFrames)}[{frameIndex}]"));
public override void SerializeImpl(SerializerObject s) { bool determineTileSize = false; if (Count == 0) { Headers = s.SerializeObjectArray <Header>(Headers, 2, name: nameof(Headers)); if (Headers[0].TileOffset % 4 != 0 || Headers[0].ExtraBytes >= 4 || (Headers[0].TileOffset / 4) < 2) { return; // Invalid } Count = (uint)(Headers[0].TileOffset / 4) - 1; determineTileSize = true; s.Goto(Offset); } Headers = s.SerializeObjectArray <Header>(Headers, Count + 1, name: nameof(Headers)); if (TileData == null) { TileData = new byte[Count][]; for (int i = 0; i < Count; i++) { s.DoAt(Offset + Headers[i].TileOffset, () => { int length = (Headers[i + 1].TileOffset - Headers[i].TileOffset - Headers[i].ExtraBytes); if (determineTileSize && i == 0) { if (Math.Sqrt(length * 2) % 1 == 0) { int val = Mathf.RoundToInt(Mathf.Sqrt(length * 2)); if ((val != 0) && ((val & (val - 1)) == 0)) { TileSize = (uint)val; } } } if (length != TileSize * TileSize / 2) { s.DoEncoded(new LZSSEncoder((uint)length, hasHeader: false), () => { TileData[i] = s.SerializeArray <byte>(TileData[i], s.CurrentLength, name: $"{nameof(TileData)}[{i}]"); }); } else { TileData[i] = s.SerializeArray <byte>(TileData[i], length, name: $"{nameof(TileData)}[{i}]"); } if (determineTileSize && i == 0) { int len = TileData[i].Length; if (Math.Sqrt(len * 2) % 1 == 0) { TileSize = (uint)Mathf.RoundToInt(Mathf.Sqrt(len * 2)); } } }); } } }
public override void SerializeImpl(SerializerObject s) { // Serialize the header if (HasHeader) { s.DoAt(s.CurrentPointer, () => s.SerializeBitValues <uint>(bitFunc => { bitFunc(default, 4, name: "Padding");
public override void SerializeImpl(SerializerObject s) { PaletteIndicesPointer = s.SerializePointer(PaletteIndicesPointer, name: nameof(PaletteIndicesPointer)); SecondaryPaletteIndicesPointer = s.SerializePointer(SecondaryPaletteIndicesPointer, name: nameof(SecondaryPaletteIndicesPointer)); SecondaryPaletteTileIndicesPointer = s.SerializePointer(SecondaryPaletteTileIndicesPointer, name: nameof(SecondaryPaletteTileIndicesPointer)); s.DoAt(PaletteIndicesPointer, () => { PaletteIndices = s.SerializeArray <byte>(PaletteIndices, Length, name: nameof(PaletteIndices)); }); s.DoAt(SecondaryPaletteIndicesPointer, () => { long length = SecondaryPaletteTileIndicesPointer - SecondaryPaletteIndicesPointer; // hack SecondaryPaletteIndices = s.SerializeArray <byte>(SecondaryPaletteIndices, length, name: nameof(SecondaryPaletteIndices)); }); s.DoAt(SecondaryPaletteTileIndicesPointer, () => { SecondaryTileIndices = s.SerializeArray <ushort>(SecondaryTileIndices, SecondaryPaletteIndices.Length, name: nameof(SecondaryTileIndices)); }); }
public override void SerializeOffsetData(SerializerObject s) { Palette = s.DoAt(OffsetTable.GetPointer(Index_Palette), () => s.SerializeObject <GBA_SpritePalette>(Palette, name: nameof(Palette))); if (!s.GameSettings.GBA_IsMilan) { TileSet = s.DoAt(OffsetTable.GetPointer(Index_TileSet), () => s.SerializeObject <GBA_SpriteTileSet>(TileSet, onPreSerialize: x => { if (s.GameSettings.EngineVersion == EngineVersion.GBA_Sabrina) { x.IsDataCompressed = BitHelpers.ExtractBits(Byte_04, 1, 5) == 0; } }, name: nameof(TileSet))); } else { Milan_TileKit = s.DoAt(OffsetTable.GetPointer(Index_TileSet), () => s.SerializeObject <GBA_TileKit>(Milan_TileKit, name: nameof(Milan_TileKit))); } if (Animations == null) { Animations = new GBA_Animation[AnimationsCount]; } for (int i = 0; i < Animations.Length; i++) { Animations[i] = s.DoAt(OffsetTable.GetPointer(AnimationIndexTable[i]), () => s.SerializeObject <GBA_Animation>(Animations[i], name: $"{nameof(Animations)}[{i}]")); } for (int i = 0; i < Animations.Length; i++) { if (Animations[i] == null) { continue; } int matrixIndex = Animations[i].AffineMatricesIndex; if (matrixIndex != 0) { Matrices[matrixIndex] = s.DoAt(OffsetTable.GetPointer(matrixIndex), () => s.SerializeObject <GBA_AffineMatrixList>( Matrices.ContainsKey(matrixIndex) ? Matrices[matrixIndex] : null, onPreSerialize: ml => ml.FrameCount = Animations[i].FrameCount, name: $"{nameof(Matrices)}[{matrixIndex}]")); } } }