public static Dictionary <string, dynamic> parseGameObj(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose) { Dictionary <string, dynamic> retVal = new Dictionary <string, dynamic>(); long fileContentBegin = reader.BaseStream.Position; retVal["tag"] = reader.ReadString(); retVal["layer"] = reader.ReadInt32(); retVal["enabled"] = reader.ReadBoolean(); int numProperties = reader.ReadInt32(); for (int i = 0; i < numProperties; i++) { bool isNull = reader.ReadBoolean(); if (!isNull) { string assemblyQualifiedName = reader.ReadString(); string propertyType = assemblyQualifiedName.Split(new char[] { ',' })[0]; string propertyName = i + "_" + propertyType; if (propertyType.Contains("[]")) { retVal[propertyName] = reader.readUnityArray(propertyType); } else { retVal[propertyName] = reader.readUnityObj(propertyType); } } } if ((reader.BaseStream.Position - fileContentBegin) != fileSize) { int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin)); reader.ReadBytes(bytesToRead); } string json = JsonConvert.SerializeObject(retVal, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()); if (verbose) { Console.WriteLine(json); } if (saveFile) { StreamWriter file = new StreamWriter(new FileStream(saveFileName + ".json", FileMode.Create)); file.Write(json); file.Close(); } return(retVal); }
public static Dictionary<string, dynamic> parseInfoGen(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose) { Dictionary<string, dynamic> retVal = new Dictionary<string, dynamic>(); long fileContentBegin = reader.BaseStream.Position; int numProperties = reader.ReadInt32(); for (int i = 0; i < numProperties; i++) { bool isNull = reader.ReadBoolean(); if (!isNull) { string assemblyQualifiedName = reader.ReadString(); string propertyType = assemblyQualifiedName.Split(new char[] { ',' })[0]; string propertyName = reader.ReadString(); if (propertyType.Contains("[]")) { retVal[propertyName] = reader.readUnityArray(propertyType); } else { retVal[propertyName] = reader.readUnityObj(propertyType); } } } if ((reader.BaseStream.Position - fileContentBegin) != fileSize) { int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin)); reader.ReadBytes(bytesToRead); } string json = JsonConvert.SerializeObject(retVal, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()); string fileName = saveFileName + ".json"; if (verbose) { Console.WriteLine("Read info file {0}", fileName); Console.WriteLine(json); } if (saveFile) { StreamWriter file = new StreamWriter(new FileStream(fileName, FileMode.Create)); file.Write(json); file.Close(); } return retVal; }
public static MagickImage parseImage(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose) { bool forceLinearFlag = reader.ReadBoolean(); uint imgLength = reader.ReadUInt32(); MagickImage retVal = parseImgFile(reader, imgLength); string fileName = saveFileName + ".png"; if (verbose) { Console.WriteLine("Read image file {0}", fileName); } if (saveFile) { retVal.Write(fileName); } return(retVal); }
public static MaterialStub parseMaterial(CrpReader reader, bool saveFile, string saveFileName, long fileSize, bool verbose) { long fileContentBegin = reader.BaseStream.Position; MaterialStub retVal = new MaterialStub(); retVal.shaderName = reader.ReadString(); retVal.numProperties = reader.ReadInt32(); for (int i = 0; i < retVal.numProperties; i++) { int propertyType = reader.ReadInt32(); string propertyName = reader.ReadString(); switch (propertyType) { case 0: retVal.colors[propertyName] = reader.singlarObjParser["UnityEngine.Color"](); break; case 1: retVal.vectors[propertyName] = reader.singlarObjParser["UnityEngine.Vector4"](); break; case 2: retVal.floats[propertyName] = reader.ReadSingle(); break; case 3: bool isNull = reader.ReadBoolean(); if (!isNull) { retVal.textures[propertyName] = reader.ReadString(); } else { retVal.textures[propertyName] = ""; } break; } } if ((reader.BaseStream.Position - fileContentBegin) != fileSize) { int bytesToRead = (int)(fileSize - (reader.BaseStream.Position - fileContentBegin)); reader.ReadBytes(bytesToRead); } string fileName = saveFileName + ".json"; string json = JsonConvert.SerializeObject(retVal, Formatting.Indented); if (verbose) { Console.WriteLine("Read info file {0}", fileName); Console.WriteLine(json); } if (saveFile) { StreamWriter file = new StreamWriter(new FileStream(saveFileName + ".json", FileMode.Create)); file.Write(json); file.Close(); } return(retVal); }