public StaticObject(Reader reader, bool PrintDebugInfo = false) { Debug = PrintDebugInfo; int[] TmpData = new int[reader.BaseStream.Length]; DataPos = 0; string filename = System.IO.Path.GetFileName(reader.GetFilename()); if (!reader.ReadBytes(4).SequenceEqual(MAGIC)) //"OBJ" Header { throw new Exception("Invalid config file header magic"); } if (Debug) { Console.WriteLine("Viewing Info for " + filename); } int MemPos = 0; // I think? while (!reader.IsEof) { int DataType = reader.ReadByte(); int ArraySize = reader.ReadInt32(); if ((DataType & 0x80) != 0) { uint DataSize = reader.ReadUInt32(); DataType &= 0x7F; ArrayInfo array = new ArrayInfo(); array.Type = (byte)DataType; array.Size = (int)DataSize; array.Data = new int[(int)DataSize]; switch (DataType) { //INT8 case (int)AttributeTypes.UINT8: if (Debug) { Console.WriteLine(); Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")"); Console.WriteLine("Array Size: " + DataSize); Console.WriteLine("Array Type: UINT8"); } for (int i = 0; i < DataSize; i++) { TmpData[DataPos++] = reader.ReadByte(); array.Data[i] = TmpData[DataPos - 1]; if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT8 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 1) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 1).ToString("X")); } } MemPos += ArraySize; break; case (int)AttributeTypes.INT8: if (Debug) { Console.WriteLine(); Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")"); Console.WriteLine("Array Size: " + DataSize); Console.WriteLine("Array Type: INT8"); } for (int i = 0; i < DataSize; i++) { TmpData[DataPos++] = reader.ReadSByte(); array.Data[i] = TmpData[DataPos - 1]; if (Debug) { Console.WriteLine("Value Info: Value: Type:" + AttributeTypes.INT8 + ", " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 1) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 1).ToString("X")); } } MemPos += ArraySize; break; //IN16 case (int)AttributeTypes.UINT16: int TmpDataOffset = (int)((MemPos & 0xFFFFFFFE) + 2); if ((MemPos & 0xFFFFFFFE) >= MemPos) { TmpDataOffset = MemPos; } MemPos = TmpDataOffset; if (Debug) { Console.WriteLine(); Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")"); Console.WriteLine("Array Size: " + DataSize); Console.WriteLine("Array Type: UINT16"); } for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); ushort Value = (ushort)(valA + (valB << 8)); TmpData[DataPos++] = Value; array.Data[i] = Value; if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT16 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 2) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 2).ToString("X")); } } MemPos += 2 * ArraySize; break; case (int)AttributeTypes.INT16: TmpDataOffset = (int)((MemPos & 0xFFFFFFFE) + 2); if ((MemPos & 0xFFFFFFFE) >= MemPos) { TmpDataOffset = MemPos; } MemPos = TmpDataOffset; if (Debug) { Console.WriteLine(); Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")"); Console.WriteLine("Array Size: " + DataSize); Console.WriteLine("Array Type: INT16"); } for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); short Value = (short)(valA + (valB << 8)); TmpData[DataPos++] = Value; array.Data[i] = Value; if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.INT16 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 2) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 2).ToString("X")); } } MemPos += 2 * ArraySize; break; //INT32 case (int)AttributeTypes.UINT32: TmpDataOffset = (int)((MemPos & 0xFFFFFFFC) + 4); if ((MemPos & 0xFFFFFFFC) >= MemPos) { TmpDataOffset = MemPos; } MemPos = TmpDataOffset; if (Debug) { Console.WriteLine(); Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")"); Console.WriteLine("Array Size: " + DataSize); Console.WriteLine("Array Type: UINT32"); } for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); byte valC = reader.ReadByte(); byte valD = reader.ReadByte(); uint Value = (uint)(valA + (valB << 8) + (valC << 16) + (valD << 24)); TmpData[DataPos++] = (int)Value; array.Data[i] = (int)Value; if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT32 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X")); } } MemPos += 4 * ArraySize; break; case (int)AttributeTypes.INT32: TmpDataOffset = (int)((MemPos & 0xFFFFFFFC) + 4); if ((MemPos & 0xFFFFFFFC) >= MemPos) { TmpDataOffset = MemPos; } MemPos = TmpDataOffset; if (Debug) { Console.WriteLine(); Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")"); Console.WriteLine("Array Size: " + DataSize); Console.WriteLine("Array Type: INT32"); } for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); byte valC = reader.ReadByte(); byte valD = reader.ReadByte(); int Value = valA + (valB << 8) + (valC << 16) + (valD << 24); TmpData[DataPos++] = Value; array.Data[i] = Value; if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.INT32 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X")); } } MemPos += 4 * ArraySize; break; case (int)AttributeTypes.ENUM: TmpDataOffset = (int)((MemPos & 0xFFFFFFFC) + 4); if ((MemPos & 0xFFFFFFFC) >= MemPos) { TmpDataOffset = MemPos; } MemPos = TmpDataOffset; if (Debug) { Console.WriteLine(); Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")"); Console.WriteLine("Array Size: " + DataSize); Console.WriteLine("Array Type: VAR"); } for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); byte valC = reader.ReadByte(); byte valD = reader.ReadByte(); int Value = (valA + (valB << 8) + (valC << 16) + (valD << 24)); TmpData[DataPos++] = (int)Value; array.Data[i] = Value; if (Debug) { Console.WriteLine("Value Info: Value: Type:" + AttributeTypes.ENUM + ", " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X")); } } MemPos += 4 * ArraySize; break; } } else { int Buffer = 0; switch (DataType) { //INT8 case (int)AttributeTypes.UINT8: case (int)AttributeTypes.INT8: MemPos += ArraySize; break; //IN16 case (int)AttributeTypes.UINT16: case (int)AttributeTypes.INT16: Buffer = (int)((MemPos & 0xFFFFFFFE) + 2); if ((MemPos & 0xFFFFFFFE) >= MemPos) { Buffer = MemPos; } MemPos = Buffer + 2 * ArraySize; break; //INT32 case (int)AttributeTypes.UINT32: case (int)AttributeTypes.INT32: case (int)AttributeTypes.ENUM: case (int)AttributeTypes.BOOL: Buffer = (int)((MemPos & 0xFFFFFFFC) + 4); if ((MemPos & 0xFFFFFFFC) >= MemPos) { Buffer = MemPos; } MemPos = Buffer + 4 * ArraySize; break; case (int)AttributeTypes.STRING: case (int)AttributeTypes.VECTOR2: Buffer = (int)((MemPos & 0xFFFFFFFC) + 4); if ((MemPos & 0xFFFFFFFC) >= MemPos) { Buffer = MemPos; } MemPos = Buffer + 8 * ArraySize; break; case (int)AttributeTypes.VECTOR3: Buffer = (int)((MemPos & 0xFFFFFFFC) + 4); if ((MemPos & 0xFFFFFFFC) >= MemPos) { Buffer = MemPos; } MemPos = Buffer + 24 * ArraySize; break; case (int)AttributeTypes.COLOR: Buffer = (int)((MemPos & 0xFFFFFFFE) + 2); if ((MemPos & 0xFFFFFFFE) >= MemPos) { Buffer = MemPos; } MemPos = Buffer + 8 * ArraySize; break; default: break; } } } reader.Close(); Data = new int[DataPos]; for (int i = 0; i < DataPos; i++) { Data[i] = TmpData[i]; } if (Debug) { Console.WriteLine(filename + " Has " + Data.Length + " Values"); } }
public StaticObject(Reader reader) { int[] TmpData = new int[reader.BaseStream.Length]; DataPos = 0; string filename = System.IO.Path.GetFileName(reader.GetFilename()); if (!reader.ReadBytes(4).SequenceEqual(MAGIC)) //"OBJ" Header { throw new Exception("Invalid config file header magic"); } if (Debug) { Console.WriteLine("Viewing Info for " + filename); } while (!reader.IsEof) { int DataType = reader.ReadByte(); uint Unknown = reader.ReadUInt32(); //Unknown if ((DataType & 0x80) != 0) { uint DataSize = reader.ReadUInt32(); DataType &= 0x7F; switch (DataType) { //INT8 case (int)AttributeTypes.UINT8: for (int i = 0; i < DataSize; i++) { TmpData[DataPos++] = reader.ReadByte(); if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT8 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 1) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 1).ToString("X")); } } break; case (int)AttributeTypes.INT8: for (int i = 0; i < DataSize; i++) { TmpData[DataPos++] = reader.ReadSByte(); if (Debug) { Console.WriteLine("Value Info: Value: Type:" + AttributeTypes.INT8 + ", " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 1) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 1).ToString("X")); } } break; //IN16 case (int)AttributeTypes.UINT16: for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); ushort Value = (ushort)(valA + (valB << 8)); TmpData[DataPos++] = Value; if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT16 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 2) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 2).ToString("X")); } } break; case (int)AttributeTypes.INT16: for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); short Value = (short)(valA + (valB << 8)); TmpData[DataPos++] = Value; if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.INT16 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 2) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 2).ToString("X")); } } break; //INT32 case (int)AttributeTypes.UINT32: for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); byte valC = reader.ReadByte(); byte valD = reader.ReadByte(); uint Value = (uint)(valA + (valB << 8) + (valC << 16) + (valD << 24)); TmpData[DataPos++] = (int)Value; if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT32 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X")); } } break; case (int)AttributeTypes.INT32: for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); byte valC = reader.ReadByte(); byte valD = reader.ReadByte(); int Value = valA + (valB << 8) + (valC << 16) + (valD << 24); TmpData[DataPos++] = Value; if (Debug) { Console.WriteLine("Value Info: Type:" + AttributeTypes.INT32 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X")); } } break; case (int)AttributeTypes.ENUM: for (int i = 0; i < DataSize; i++) { byte valA = reader.ReadByte(); byte valB = reader.ReadByte(); byte valC = reader.ReadByte(); byte valD = reader.ReadByte(); uint Value = (uint)(valA + (valB << 8) + (valC << 16) + (valD << 24)); TmpData[DataPos++] = (int)Value; if (Debug) { Console.WriteLine("Value Info: Value: Type:" + AttributeTypes.ENUM + ", " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X")); } } break; } } } reader.Close(); Data = new int[DataPos]; for (int i = 0; i < DataPos; i++) { Data[i] = TmpData[i]; } if (Debug) { Console.WriteLine(filename + " Has " + Data.Length + " Values"); } }