// Methods public void Read(BINAReader reader) { // Read the data uint lineType = reader.ReadUInt32(); uint padding1 = reader.ReadUInt32(); ulong nameOffset = reader.ReadUInt64(); ulong padding2 = reader.ReadUInt64(); UnknownFloat1 = reader.ReadSingle(); byte firstCharacter = reader.ReadByte(); byte firstAnim = reader.ReadByte(); byte secondCharacter = reader.ReadByte(); byte secondAnim = reader.ReadByte(); TalkingCharacter = reader.ReadUInt64(); // Parse it if (nameOffset != 0) { Name = reader.GetString((uint)nameOffset + reader.Offset); } LineType = (LineTypes)lineType; FirstCharacter = (CharacterTypes)firstCharacter; FirstCharAnimation = (AnimationTypes)firstAnim; SecondCharacter = (CharacterTypes)secondCharacter; SecondCharAnimation = (AnimationTypes)secondAnim; }
// Methods public void Read(BINAReader reader, bool readStageID = false) { // Stage Index StageIndex = reader.ReadByte(); byte unknown2 = reader.ReadByte(); byte unknown3 = reader.ReadByte(); byte unknown4 = reader.ReadByte(); // Time Bonus TimeBasis = reader.ReadUInt32(); TimeDown = reader.ReadUInt32(); // Miss Bonuses NoMissBonus = reader.ReadUInt32(); OneMissBonus = reader.ReadUInt32(); TwoMissBonus = reader.ReadUInt32(); ThreeMissBonus = reader.ReadUInt32(); FourMissBonus = reader.ReadUInt32(); FivePlusMissBonus = reader.ReadUInt32(); // Rank Scores SRankScore = reader.ReadUInt32(); ARankScore = reader.ReadUInt32(); BRankScore = reader.ReadUInt32(); uint CRankScore = reader.ReadUInt32(); // Not really used uint DRankScore = reader.ReadUInt32(); // Unused // Stage ID stageIDOffset = reader.ReadUInt64(); ulong unknown5 = reader.ReadUInt64(); if (readStageID) { StageID = reader.GetString((uint)stageIDOffset); } // Padding/Unknown Value Checks if (unknown2 != 0) { Console.WriteLine($"WARNING: Unknown2 != 0! ({unknown2})"); } if (unknown3 != 0) { Console.WriteLine($"WARNING: Unknown3 != 0! ({unknown3})"); } if (unknown4 != 0) { Console.WriteLine($"WARNING: Unknown4 != 0! ({unknown4})"); } if (unknown5 != 0) { Console.WriteLine($"WARNING: Unknown5 != 0! ({unknown5})"); } }
// Methods public override void Load(Stream fileStream) { // BINA Header var reader = new BINAReader(fileStream); Header = reader.ReadHeader(); string sig = reader.ReadSignature(4); if (sig != Signature) { throw new InvalidSignatureException(Signature, sig); } var unknown1 = reader.ReadUInt32(); //Might be part of the Header according to Skyth's spec? if (unknown1 != 1) { Console.WriteLine($"Unknown1 does not equal 1 in this file! It's actually set to {unknown1}"); } var shapeCount = reader.ReadInt64(); var unknown2 = reader.ReadUInt64(); if (unknown2 != 24) { Console.WriteLine($"Unknown1 does not equal 24 in this file! It's actually set to {unknown1}"); } Console.WriteLine(unknown2); for (int i = 0; i < shapeCount; i++) { SvShape shape = new SvShape(); var shapeNameOffset = reader.ReadInt64(); long pos = reader.BaseStream.Position; reader.JumpTo(shapeNameOffset, false); shape.Name = reader.ReadNullTerminatedString(); reader.JumpTo(pos, true); shape.Unknown1 = reader.ReadUInt32(); shape.Size = reader.ReadVector3(); shape.Position = reader.ReadVector3(); shape.Rotation = reader.ReadQuaternion(); shape.BoundingBox.Minimum = reader.ReadVector3(); shape.BoundingBox.Maximum = reader.ReadVector3(); shape.Unknown2 = reader.ReadUInt32(); var sectorCount = reader.ReadInt64(); var sectorListOffset = reader.ReadInt64(); pos = reader.BaseStream.Position; reader.JumpTo(sectorListOffset, false); for (int s = 0; s < sectorCount; s++) { SvSector sector = new SvSector(); sector.SectorIndex = reader.Read(); sector.Visible = reader.ReadBoolean(); shape.Sectors.Add(sector); } reader.JumpTo(pos, true); SvShapes.Add(shape); } }
// Methods public override void Read(BINAReader reader, BINAHeader header = null) { // Slots Unknown1 = new Slot(reader); // gadget_database? CustomizeBody = new Slot(reader); CustomizeHead = new Slot(reader); CustomizeGlass = new Slot(reader); Unknown2 = new Slot(reader); // customize_face? CustomizeGlove = new Slot(reader); CustomizeShoes = new Slot(reader); CustomizePattern = new Slot(reader); EventMovie = new Slot(reader); GameScore = new Slot(reader); StageScore = new Slot(reader); Unknown3 = new Slot(reader); // idk (padding?) // Paths ulong miscPACOffset = reader.ReadUInt64(); ulong unknownPath1Offset = reader.ReadUInt64(); ulong stgMissionLUAOffset = reader.ReadUInt64(); ulong unknownPath2Offset = reader.ReadUInt64(); MiscPAC = ReadPath(miscPACOffset); UnknownPath1 = ReadPath(unknownPath1Offset); StgMissionLUA = ReadPath(stgMissionLUAOffset); UnknownPath2 = ReadPath(unknownPath2Offset); // Sub-Methods string ReadPath(ulong offset) { if (offset == 0) { return(null); } reader.JumpTo((long)offset, false); return(reader.ReadNullTerminatedString()); } }
// Methods public void Read(BINAReader reader) { uint id = reader.ReadUInt32(); long dataSize = reader.ReadInt64(); reader.JumpAhead(4); DataOffset = reader.ReadInt64(); reader.JumpAhead(8); ExtensionOffset = reader.ReadInt64(); DataType = (DataEntryTypes)reader.ReadUInt64(); if (DataType != DataEntryTypes.NotHere) { Data = new byte[dataSize]; } }
// Methods public void Read(BINAReader reader) { ulong nameOffset = reader.ReadUInt64(); ulong padding1 = reader.ReadUInt64(); ulong startOffset = reader.ReadUInt64(); ulong padding2 = reader.ReadUInt64(); ulong endOffset = reader.ReadUInt64(); ulong padding3 = reader.ReadUInt64(); // Read strings if (nameOffset != 0) { Name = reader.GetString((uint)nameOffset + reader.Offset); } if (startOffset != 0) { StageStartCaptionParam = reader.GetString((uint)startOffset + reader.Offset); } if (endOffset != 0) { StageEndCaptionParam = reader.GetString((uint)endOffset + reader.Offset); } // Padding Checks if (padding1 != 0) { Console.WriteLine("WARNING: Padding1 != 0! ({0:X})", padding1); } if (padding2 != 0) { Console.WriteLine("WARNING: Padding2 != 0! ({0:X})", padding2); } if (padding3 != 0) { Console.WriteLine("WARNING: Padding3 != 0! ({0:X})", padding3); } }
public override void Load(Stream fileStream) { // PACx Header var reader = new BINAReader(fileStream); Header.Read(reader); // Type Names var typeTree = ReadNodeTree(reader); var names = new string[typeTree.Nodes.Count]; for (int i = 0; i < typeTree.Nodes.Count; ++i) { var typeNode = typeTree.Nodes[i]; if (typeNode.ChildCount < 1) { continue; } int nameIndex = -1; if (typeNode.ChildIDTableOffset > 0) { reader.JumpTo(typeNode.ChildIDTableOffset); nameIndex = reader.ReadInt32(); } if (typeNode.NameOffset > 0) { reader.JumpTo(typeNode.NameOffset); names[i] = reader.ReadNullTerminatedString(); } } // Types foreach (var type in typeTree.Nodes) { if (!type.HasData) { continue; } string name = string.Empty; var n = type; while (n.ParentIndex >= 0) { name = $"{names[n.ParentIndex]}{name}"; n = typeTree.Nodes[n.ParentIndex]; } reader.JumpTo(type.DataOffset); var fileTree = ReadNodeTree(reader); // File Names var fileNames = new string[fileTree.Nodes.Count]; for (int i = 0; i < fileTree.Nodes.Count; ++i) { var fileNode = fileTree.Nodes[i]; if (fileNode.ChildCount < 1) { continue; } int nameIndex = -1; if (fileNode.ChildIDTableOffset > 0) { reader.JumpTo(fileNode.ChildIDTableOffset); nameIndex = reader.ReadInt32(); } if (fileNode.NameOffset > 0) { reader.JumpTo(fileNode.NameOffset); fileNames[i] = reader.ReadNullTerminatedString(); } } // File Nodes foreach (var file in fileTree.Nodes) { if (!file.HasData) { continue; } name = string.Empty; n = file; while (n.ParentIndex >= 0) { name = $"{fileNames[n.ParentIndex]}{name}"; n = fileTree.Nodes[n.ParentIndex]; } // File Entries reader.JumpTo(file.DataOffset); uint pacID = reader.ReadUInt32(); if (pacID != Header.ID) { Console.WriteLine( $"WARNING: Skipped file {name} as its pac ID was missing"); continue; } ulong fileSize = reader.ReadUInt64(); uint padding1 = reader.ReadUInt32(); long fileDataOffset = reader.ReadInt64(); ulong padding2 = reader.ReadUInt64(); long extensionOffset = reader.ReadInt64(); uint pacType = reader.ReadUInt32(); uint padding3 = reader.ReadUInt32(); if (fileDataOffset <= 0 || pacType == 1) { continue; } // File Extension reader.JumpTo(extensionOffset); name += $".{reader.ReadNullTerminatedString()}"; // File Data reader.JumpTo(fileDataOffset); var data = reader.ReadBytes((int)fileSize); // BINA Check // TODO: Remove this check if (data[0] == 0x42 && data[1] == 0x49 && data[2] == 0x4E && data[3] == 0x41) { if (pacType != 2) { Console.WriteLine( $"WARNING: FileType ({pacType}) != 2 when file carries BINA Header!"); } } else { if (pacType == 2) { Console.WriteLine( $"WARNING: FileType ({pacType}) == 2 when file has no BINA Header!"); } } Data.Add(new ArchiveFile(name, data)); } } }
public const uint Signature = 0x4658434F; // FXCO in ASCII // Methods public override void Load(Stream fileStream) { // Header var reader = new BINAReader(fileStream); Header = reader.ReadHeader(); uint sig = reader.ReadUInt32(); if (sig != Signature) { throw new InvalidSignatureException("FXCO", Encoding.ASCII.GetString(BitConverter.GetBytes(sig))); } uint unknown1 = reader.ReadUInt32(); // Version number? ulong instanceCount = reader.ReadUInt64(); ulong instancesOffset = reader.ReadUInt64(); ulong shapesCount = reader.ReadUInt64(); ulong shapesOffset = reader.ReadUInt64(); ulong unknownCount = reader.ReadUInt64(); ulong unknownOffset = reader.ReadUInt64(); // Instances reader.JumpTo((long)instancesOffset, false); for (uint i = 0; i < instanceCount; ++i) { reader.FixPadding(8); ulong nameOffset = reader.ReadUInt64(); byte unknownFlag1 = reader.ReadByte(); byte unknownFlag2 = reader.ReadByte(); byte unknownFlag3 = reader.ReadByte(); byte unknownFlag4 = reader.ReadByte(); var vect1 = reader.ReadVector3(); // Position or size? ulong instPadding1 = reader.ReadUInt64(); uint instPadding2 = reader.ReadUInt32(); uint instUnknown1 = reader.ReadUInt32(); ulong instPadding3 = reader.ReadUInt64(); ulong instPadding4 = reader.ReadUInt64(); ulong instPadding5 = reader.ReadUInt64(); ulong instPadding6 = reader.ReadUInt64(); ulong unknownString1 = reader.ReadUInt64(); // Always "none"? var vect2 = reader.ReadVector3(); // Position or size? uint instUnknown2 = reader.ReadUInt32(); // Always 0x00000080? uint instPadding7 = reader.ReadUInt32(); uint instUnknown3 = reader.ReadUInt32(); // Always 0x00000080? float instUnknown4 = reader.ReadSingle(); // Always 1? } // Unknown reader.JumpTo((long)unknownOffset, false); for (uint i = 0; i < unknownCount; ++i) { ulong uk1 = reader.ReadUInt64(); // Maybe 8 indices? } // Shapes reader.JumpTo((long)shapesOffset, false); for (uint i = 0; i < shapesCount; ++i) { uint shapeUnknown1 = reader.ReadUInt32(); uint shapeUnknown2 = reader.ReadUInt32(); var shapeUnknown3 = reader.ReadVector3(); var shapeUnknown4 = reader.ReadVector3(); } }
// Methods public override void Load(Stream fileStream) { // BINA Header var reader = new BINAReader(fileStream); Header = reader.ReadHeader(); // Header byte unknown1 = reader.ReadByte(); // Always 3? byte sheetCount = reader.ReadByte(); // ? byte unknown2 = reader.ReadByte(); // Always 0? byte unknown3 = reader.ReadByte(); // Always 0? uint unknown4 = reader.ReadUInt32(); long sheetsOffset = reader.ReadInt64(); // Sheets reader.JumpTo(sheetsOffset, false); for (uint i = 0; i < sheetCount; ++i) { Sheets.Add(new Sheet() { NameOffset = reader.ReadInt64(), CellCount = reader.ReadUInt64(), CellsOffset = reader.ReadInt64() }); } // Cells for (int i = 0; i < sheetCount; ++i) { var sheet = Sheets[i]; reader.JumpTo(sheet.CellsOffset, false); for (uint i2 = 0; i2 < sheet.CellCount; ++i2) { sheet.Cells.Add(new Cell() { UUID = reader.ReadUInt64(), NameOffset = reader.ReadInt64(), SecondEntryOffset = reader.ReadInt64(), DataOffset = reader.ReadInt64() }); } } // Data foreach (var sheet in Sheets) { for (int i = 0; i < sheet.Cells.Count; ++i) { var cell = sheet.Cells[i]; reader.JumpTo(cell.DataOffset.Value, false); var chars = new List <byte>(); bool isReadingButton = false; // Read Unicode strings do { byte b1 = reader.ReadByte(); byte b2 = reader.ReadByte(); if (b1 != 0 && ((b2 & 0xE0) == 0xE0)) { isReadingButton = true; } if (b1 == 0 && b2 == 0) { if (isReadingButton) { isReadingButton = false; chars.Add(0x57); // NullReplaceChar byte1 chars.Add(0x2B); // NullReplaceChar byte2 continue; } else { break; } } chars.Add(b1); chars.Add(b2); }while (fileStream.Position < fileStream.Length); cell.Data = Encoding.Unicode.GetString(chars.ToArray()); } } // Second Entries var typeOffsets = new Dictionary <long, string>(); foreach (var sheet in Sheets) { for (int i = 0; i < sheet.Cells.Count; ++i) { var cell = sheet.Cells[i]; reader.JumpTo(cell.SecondEntryOffset.Value, false); long nameOffset = reader.ReadInt64(); long typeOffset = reader.ReadInt64(); cell.LayoutOffset = reader.ReadInt64(); if (nameOffset != cell.NameOffset) { Console.WriteLine( "WARNING: Second name offset ({0:X}) != first ({1:X})!", nameOffset, cell.NameOffset); } // Caption Type if (typeOffsets.ContainsKey(typeOffset)) { cell.TypeName = typeOffsets[typeOffset]; continue; } var type = new CellType(); reader.JumpTo(typeOffset, false); long typeNameOffset = reader.ReadInt64(); long typeNamespaceOffset = reader.ReadInt64(); long unknownFloat1Offset = reader.ReadInt64(); long unknownFloat2Offset = reader.ReadInt64(); long unknownFloat3Offset = reader.ReadInt64(); long unknownInt1Offset = reader.ReadInt64(); long unknownInt2Offset = reader.ReadInt64(); long unknownOffset1 = reader.ReadInt64(); long unknownULong2Offset = reader.ReadInt64(); long unknownOffset2 = reader.ReadInt64(); long unknownOffset3 = reader.ReadInt64(); long unknownOffset4 = reader.ReadInt64(); long unknownULong1Offset = reader.ReadInt64(); long unknownOffset5 = reader.ReadInt64(); // UnknownFloat1 if (unknownFloat1Offset > 0) { reader.JumpTo(unknownFloat1Offset, false); type.UnknownFloat1 = reader.ReadSingle(); uint padding1 = reader.ReadUInt32(); if (padding1 != 0) { Console.WriteLine("WARNING: Type Padding1 != 0 (0x{0:X})", padding1); } } // UnknownFloat2 if (unknownFloat2Offset > 0) { reader.JumpTo(unknownFloat2Offset, false); type.UnknownFloat2 = reader.ReadSingle(); uint padding2 = reader.ReadUInt32(); if (padding2 != 0) { Console.WriteLine("WARNING: Type Padding2 != 0 (0x{0:X})", padding2); } } // UnknownFloat3 if (unknownFloat3Offset > 0) { reader.JumpTo(unknownFloat3Offset, false); type.UnknownFloat3 = reader.ReadSingle(); uint padding3 = reader.ReadUInt32(); if (padding3 != 0) { Console.WriteLine("WARNING: Type Padding3 != 0 (0x{0:X})", padding3); } } // UnknownInt1 if (unknownInt1Offset > 0) { reader.JumpTo(unknownInt1Offset, false); type.UnknownInt1 = reader.ReadInt32(); uint padding4 = reader.ReadUInt32(); if (padding4 != 0) { Console.WriteLine("WARNING: Type Padding4 != 0 (0x{0:X})", padding4); } } // UnknownInt2 if (unknownInt2Offset > 0) { reader.JumpTo(unknownInt2Offset, false); type.UnknownInt2 = reader.ReadInt32(); uint padding5 = reader.ReadUInt32(); if (padding5 != 0) { Console.WriteLine("WARNING: Type Padding5 != 0 (0x{0:X})", padding5); } } if (unknownOffset1 != 0) { Console.WriteLine("WARNING: Type ukOff1 != 0 (0x{0:X})", unknownOffset1); } // UnknownULong2Offset if (unknownULong2Offset > 0) { reader.JumpTo(unknownULong2Offset, false); type.UnknownULong2 = reader.ReadUInt64(); } if (unknownOffset2 != 0) { Console.WriteLine("WARNING: Type ukOff2 != 0 (0x{0:X})", unknownOffset2); } if (unknownOffset3 != 0) { Console.WriteLine("WARNING: Type ukOff3 != 0 (0x{0:X})", unknownOffset3); } if (unknownOffset4 != 0) { Console.WriteLine("WARNING: Type ukOff4 != 0 (0x{0:X})", unknownOffset4); } // UnknownULong1Offset if (unknownULong1Offset > 0) { reader.JumpTo(unknownULong1Offset, false); type.UnknownULong1 = reader.ReadUInt64(); } if (unknownOffset5 != 0) { Console.WriteLine("WARNING: Type ukOff5 != 0 (0x{0:X})", unknownOffset5); } // Strings reader.JumpTo(typeNameOffset, false); string typeName = reader.ReadNullTerminatedString(); reader.JumpTo(typeNamespaceOffset, false); type.Namespace = reader.ReadNullTerminatedString(); cell.TypeName = typeName; typeOffsets.Add(typeOffset, typeName); Types.Add(typeName, type); } } // Layouts var layoutOffsets = new List <long>(); foreach (var sheet in Sheets) { foreach (var cell in sheet.Cells) { if (!layoutOffsets.Contains(cell.LayoutOffset.Value)) { var layout = new Layout(); reader.JumpTo(cell.LayoutOffset.Value, false); long layoutNameOffset = reader.ReadInt64(); long unknownData1Offset = reader.ReadInt64(); long unknownData2Offset = reader.ReadInt64(); long unknownData3Offset = reader.ReadInt64(); long unknownData4Offset = reader.ReadInt64(); long unknownData5Offset = reader.ReadInt64(); long unknownData6Offset = reader.ReadInt64(); long unknownData7Offset = reader.ReadInt64(); layout.UnknownData8 = reader.ReadInt64(); // Always 0? if (layout.UnknownData8 != 0) { Console.WriteLine( "WARNING: Layout UnknownData8 != 0! ({0:X})", layout.UnknownData8); } // Unknown Data 1 if (unknownData1Offset > 0) { reader.JumpTo(unknownData1Offset, false); layout.UnknownData1 = reader.ReadInt32(); // Always 1? } // Unknown Data 2 if (unknownData2Offset > 0) { reader.JumpTo(unknownData2Offset, false); layout.UnknownData2 = reader.ReadSingle(); uint padding = reader.ReadUInt32(); if (padding != 0) { Console.WriteLine( "WARNING: Layout UnknownData2 Padding != 0! ({0:X})", padding); } } // Unknown Data 3 if (unknownData3Offset > 0) { reader.JumpTo(unknownData3Offset, false); layout.UnknownData3 = reader.ReadSingle(); uint padding = reader.ReadUInt32(); if (padding != 0) { Console.WriteLine( "WARNING: Layout UnknownData3 Padding != 0! ({0:X})", padding); } } // Unknown Data 4 if (unknownData4Offset > 0) { reader.JumpTo(unknownData4Offset, false); layout.UnknownData4 = reader.ReadInt32(); // Always 0? } // Unknown Data 5 if (unknownData5Offset > 0) { reader.JumpTo(unknownData5Offset, false); layout.UnknownData5 = reader.ReadInt32(); } // Unknown Data 6 if (unknownData6Offset > 0) { reader.JumpTo(unknownData6Offset, false); layout.UnknownData6 = reader.ReadInt32(); // Always 1? } // Unknown Data 7 if (unknownData7Offset > 0) { reader.JumpTo(unknownData7Offset, false); layout.UnknownData7 = reader.ReadInt32(); // Always 2? } // Layout Name reader.JumpTo(layoutNameOffset, false); layout.Name = reader.ReadNullTerminatedString(); layout.Offset = cell.LayoutOffset; cell.LayoutIndex = layoutOffsets.Count; layoutOffsets.Add(cell.LayoutOffset.Value); Layouts.Add(layout); } else { cell.LayoutIndex = layoutOffsets.IndexOf( cell.LayoutOffset.Value); } } } // Names foreach (var sheet in Sheets) { reader.JumpTo(sheet.NameOffset, false); sheet.Name = reader.ReadNullTerminatedString(); for (int i = 0; i < sheet.Cells.Count; ++i) { var cell = sheet.Cells[i]; reader.JumpTo(cell.NameOffset.Value, false); cell.Name = reader.ReadNullTerminatedString(); } } }
protected SetObject ReadObject(BINAReader reader, Dictionary <string, SetObjectType> objectTemplates) { var obj = new SetObject(); ulong padding1 = reader.ReadUInt64(); long objTypeOffset = reader.ReadInt64(); long objNameOffset = reader.ReadInt64(); ushort id = reader.ReadUInt16(); ushort groupID = reader.ReadUInt16(); ushort parentID = reader.ReadUInt16(); ushort parentGroupID = reader.ReadUInt16(); obj.CustomData.Add("ParentID", new SetObjectParam( typeof(ushort), parentID)); obj.CustomData.Add("ParentGroupID", new SetObjectParam( typeof(ushort), parentGroupID)); obj.ObjectID = id; obj.CustomData.Add("GroupID", new SetObjectParam( typeof(ushort), groupID)); var pos = reader.ReadVector3(); var rot = reader.ReadVector3(); var childPosOffset = reader.ReadVector3(); var childRotOffset = reader.ReadVector3(); obj.CustomData.Add("ChildPosOffset", new SetObjectParam( typeof(Vector3), childPosOffset)); obj.CustomData.Add("ChildRotOffset", new SetObjectParam( typeof(Vector3), childRotOffset)); obj.Transform.Position = pos; obj.Transform.Rotation = new Quaternion(rot, true); long extraParamsOffset = reader.ReadInt64(); ulong unknownCount1 = reader.ReadUInt64(); ulong unknownCount2 = reader.ReadUInt64(); ulong padding3 = reader.ReadUInt64(); long objParamsOffset = reader.ReadInt64(); // Unknown Count Checks if (unknownCount1 != unknownCount2) { Console.WriteLine( "WARNING: UnknownCount1 ({0}) != UnknownCount2 ({1})", unknownCount1, unknownCount2); } if (unknownCount1 > 1) { Console.WriteLine( "WARNING: UnknownCount1 > 1 ({0})", unknownCount1); } // Extra Parameter Offsets var extraParamOffsets = new long[unknownCount1]; reader.JumpTo(extraParamsOffset, false); for (uint i = 0; i < unknownCount1; ++i) { extraParamOffsets[i] = reader.ReadInt64(); ulong padding5 = reader.ReadUInt64(); // TODO: Make sure this is correct } // Extra Parameters for (uint i = 0; i < unknownCount1; ++i) { reader.JumpTo(extraParamOffsets[i], false); ulong padding6 = reader.ReadUInt64(); long extraParamNameOffset = reader.ReadInt64(); ulong extraParamLength = reader.ReadUInt64(); long extraParamDataOffset = reader.ReadInt64(); // Extra Parameter Data reader.JumpTo(extraParamDataOffset, false); var data = reader.ReadBytes((int)extraParamLength); // Extra Parameter Name reader.JumpTo(extraParamNameOffset, false); string name = reader.ReadNullTerminatedString(); // Parse Data switch (name) { case "RangeSpawning": { obj.CustomData.Add("RangeIn", new SetObjectParam( typeof(float), BitConverter.ToSingle(data, 0))); obj.CustomData.Add("RangeOut", new SetObjectParam( typeof(float), BitConverter.ToSingle(data, 4))); continue; } } Console.WriteLine($"WARNING: Unknown extra parameter type {name}"); obj.CustomData.Add(name, new SetObjectParam( data.GetType(), data)); } // Object Name reader.JumpTo(objNameOffset, false); string objName = reader.ReadNullTerminatedString(); obj.CustomData.Add("Name", new SetObjectParam(typeof(string), objName)); // Object Type reader.JumpTo(objTypeOffset, false); string objType = reader.ReadNullTerminatedString(); obj.ObjectType = objType; if (!objectTemplates.ContainsKey(objType)) { Console.WriteLine( "WARNING: Skipped {0} because there is no template for type {1}!", objName, objType); Console.WriteLine("Params at: {0:X}", objParamsOffset + reader.Offset); return(null); } //Console.WriteLine("\"{1}\" Params at: {0:X}", // objParamsOffset + reader.Offset, objName); var template = objectTemplates[objType]; // Object Parameters reader.JumpTo(objParamsOffset, false); foreach (var param in template.Parameters) { obj.Parameters.Add(ReadParameter(reader, param)); } // Additional Padding var rawDataLenExtra = template.GetExtra("RawByteLength"); if (uint.TryParse(rawDataLenExtra?.Value, out var rawLength)) { uint paramLen = (uint)(reader.BaseStream.Position - objParamsOffset - reader.Offset); if (paramLen != rawLength) { obj.CustomData.Add("RawByteLength", new SetObjectParam( typeof(uint), rawLength)); } } // Padding Checks if (padding1 != 0) { Console.WriteLine($"WARNING: Obj Padding1 != 0 ({padding1})"); } if (padding3 != 0) { Console.WriteLine($"WARNING: Obj Padding3 != 0 ({padding3})"); } return(obj); }
protected SetObjectParam ReadParameter(BINAReader reader, SetObjectTypeParam param) { FixPadding(reader, param.DataType); // Special Param Types if (param is SetObjectTypeParamGroup group) { var g = new SetObjectParamGroup(group.Padding); var groupParams = g.Parameters; foreach (var p in group.Parameters) { groupParams.Add(ReadParameter(reader, p)); } reader.FixPadding(group.Padding ?? 16); return(g); } else if (param.DataType == typeof(ObjectReference[])) { long arrOffset = reader.ReadInt64(); ulong arrLength = reader.ReadUInt64(); ulong arrLength2 = reader.ReadUInt64(); long curPos = reader.BaseStream.Position; if (arrLength != arrLength2) { Console.WriteLine( "WARNING: ArrLength ({0}) != ArrLength2 ({1})", arrLength, arrLength2); } var arr = new ObjectReference[arrLength]; if (arrLength > 0 && arrOffset > 0) { reader.JumpTo(arrOffset, false); for (uint i = 0; i < arrLength; ++i) { arr[i] = new ObjectReference(reader); } reader.JumpTo(curPos); } return(new SetObjectParam(param.DataType, arr)); } else if (param.DataType == typeof(ObjectReference)) { return(new SetObjectParam(typeof(ObjectReference), new ObjectReference(reader))); } else if (param.DataType == typeof(string)) { var stringParam = new SetObjectParam(typeof(string), string.Empty); long offset = reader.ReadInt64(); long stringPadding = reader.ReadInt64(); if (offset > 0) { long curPos = reader.BaseStream.Position; reader.JumpTo(offset, false); stringParam.Data = reader.ReadNullTerminatedString(); reader.JumpTo(curPos); } if (stringPadding != 0) { Console.WriteLine("WARNING: String Padding != 0 ({0:X})!!", stringPadding); } //reader.FixPadding(16); return(stringParam); } // Data var objParam = new SetObjectParam(param.DataType, reader.ReadByType(param.DataType)); // Post-Param Padding if (param.DataType == typeof(Vector3)) { uint vecPadding = reader.ReadUInt32(); if (vecPadding != 0) { Console.WriteLine("WARNING: Vector Padding != 0 ({0:X})!!", vecPadding); } } return(objParam); }
// Methods public override void Load(Stream fileStream, Dictionary <string, SetObjectType> objectTemplates) { if (objectTemplates == null) { throw new ArgumentNullException("objectTemplates", "Cannot load Forces set data without object templates."); } // BINA Header var reader = new BINAReader(fileStream); Header = reader.ReadHeader(); // Set Data Header ulong padding1 = reader.ReadUInt64(); ulong padding2 = reader.ReadUInt64(); long objectTableOffset = reader.ReadInt64(); ulong objectCount = reader.ReadUInt64(); ulong objectCount2 = reader.ReadUInt64(); ulong padding3 = reader.ReadUInt64(); // Padding/Unknown Value Checks if (padding1 != 0) { Console.WriteLine($"WARNING: Padding1 != 0 ({padding1})"); } if (padding2 != 0) { Console.WriteLine($"WARNING: Padding2 != 0 ({padding2})"); } if (padding3 != 0) { Console.WriteLine($"WARNING: Padding3 != 0 ({padding3})"); } if (objectCount != objectCount2) { Console.WriteLine( "WARNING: ObjectCount ({0}) != ObjectCount2 ({1})", objectCount, objectCount2); } // Object Offsets var objectOffsets = new long[objectCount]; reader.JumpTo(objectTableOffset, false); for (uint i = 0; i < objectCount; ++i) { objectOffsets[i] = reader.ReadInt64(); } // Objects for (uint i = 0; i < objectCount; ++i) { reader.JumpTo(objectOffsets[i], false); var obj = ReadObject(reader, objectTemplates); if (obj == null) { continue; } Objects.Add(obj); } }