private void readClassDefinition(int classId) { string className = reader.ReadUtf8(); string packageName = reader.ReadUtf8(); GameDataClassDefinition classDefinition = new GameDataClassDefinition(packageName, className); int fieldsCount = reader.ReadInt(); uint i = 0; while (i < fieldsCount) { classDefinition.AddField(reader); i++; } classDefinitions.Add(classId, classDefinition); }
private void readClassDefinition(int classId) { string className = reader.ReadUtf8(); string packageName = reader.ReadUtf8(); GameDataClassDefinition classDefinition = new GameDataClassDefinition(packageName, className); Console.WriteLine("ClassId: {0} ClassMemberName: {1} ClassPkgName {2}", classId, className, packageName); int fieldsCount = reader.ReadInt(); uint i = 0; while (i < fieldsCount) { classDefinition.AddField(reader); i++; } classDefinitions.Add(classId, classDefinition); }
int contentOffset = 0; //or uint? public App(string d2oFilePath) { objectPointerTable = new Dictionary <int, int>(); classDefinitions = new Dictionary <int, GameDataClassDefinition>(); using (FileStream d2oFile = File.Open(d2oFilePath, FileMode.Open)) using (reader = new D2OReader(d2oFile)) { string headerString = reader.ReadAscii(3); if (!headerString.Equals("D2O")) { reader.Pointer = 0; string headers = reader.ReadUtf8(); short formatVersion = reader.ReadShort(); int len = reader.ReadInt(); reader.Pointer = reader.Pointer + len; contentOffset = reader.Pointer; int streamStartIndex = (contentOffset + 7); //or uint? headers = reader.ReadAscii(3); if (!headers.Equals("D2O")) { throw new InvalidDataException("Header doesn't equal the string 'D2O' : Corrupted file"); } } readObjectPointerTable(); //printObjectPointerTable(); readClassTable(); printClassTable(); readGameDataProcessor(); //TODO: implement unpackObjectsAsJson(); writeJsonFile(true); //printAllObjects(); //call after unpackObjectsAsJson(); searchObjectById(); //call after unpackObjectsAsJson(); } }
private string getFieldValueBuilder(GameDataField field) { StringBuilder fieldValueBuilder = new StringBuilder(); switch (field.fieldType) { case GameDataTypeEnum.Vector: fieldValueBuilder.Append("["); int vectorLength = reader.ReadInt(); for (int i = 0; i < vectorLength; i++) { fieldValueBuilder .Append(getFieldValueBuilder(field.innerField)) .Append(writeCommaIfHasMore(vectorLength, i)); } fieldValueBuilder.Append("]"); break; case GameDataTypeEnum.Int: fieldValueBuilder.Append(reader.ReadInt()); break; case GameDataTypeEnum.UInt: fieldValueBuilder.Append(reader.ReadUInt()); break; case GameDataTypeEnum.I18N: fieldValueBuilder.Append(reader.ReadInt()); break; case GameDataTypeEnum.String: fieldValueBuilder.Append(JsonConvert.ToString(reader.ReadUtf8())); break; case GameDataTypeEnum.Bool: fieldValueBuilder.Append(JsonConvert.ToString(reader.ReadBool())); //in json bool is true/false not True/False break; case GameDataTypeEnum.Double: fieldValueBuilder.Append(JsonConvert.ToString(reader.ReadDouble())); //handling the "," vs "." problem of the culture specifics break; default: if (field.fieldType > 0) //if type is an object { int classId = reader.ReadInt(); if (classDefinitions.ContainsKey(classId)) { fieldValueBuilder.Append(getObjectBuilder(classId)); } } else { Console.WriteLine("Error: invalid type( {0} ) for field {1}", field.fieldType, field.fieldName); } break; } return(fieldValueBuilder.ToString()); }