/// <summary> /// Reads in a D3DTX file from the disk. /// </summary> /// <param name="filePath"></param> public void Read_D3DTX_File(string filePath) { //read meta version of the file string metaVersion = Read_D3DTX_File_MetaVersionOnly(filePath); //read the d3dtx version of the file int d3dtxVersion = Read_D3DTX_File_D3DTXVersionOnly(filePath); using (BinaryReader reader = new BinaryReader(File.OpenRead(filePath))) { //read meta header switch (metaVersion) { case "6VSM": msv6 = new(reader); break; case "5VSM": msv5 = new(reader); break; case "ERTM": mtre = new(reader); break; default: ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Red); Console.WriteLine("ERROR! '{0}' meta stream version is not supported!", metaVersion); ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White); return; } if (d3dtxVersion == 5 || d3dtxVersion == 6 || d3dtxVersion == 7 || d3dtxVersion == 8) { ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Yellow); Console.WriteLine("Warning! '{0}' version is not fully complete/tested! There may be some issues with converting.", d3dtxVersion); ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White); } //read d3dtx header switch (d3dtxVersion) { case 4: d3dtx4 = new(reader, true); break; case 5: d3dtx5 = new(reader, true); break; case 6: d3dtx6 = new(reader, true); break; case 7: d3dtx7 = new(reader, true); break; case 8: d3dtx8 = new(reader, true); break; case 9: d3dtx9 = new(reader, true); break; default: ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Red); Console.WriteLine("ERROR! '{0}' d3dtx version is not supported!", d3dtxVersion); ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White); break; } } }
/// <summary> /// Reads a json file and serializes it into the appropriate d3dtx version that was serialized in the json file. /// </summary> /// <param name="filePath"></param> public void Read_D3DTX_JSON(string filePath) { //read the data from the json file string jsonText = File.ReadAllText(filePath); //parse the data into a json array JArray jarray = JArray.Parse(jsonText); //meta object JObject metaObject = jarray[0] as JObject; //parsed meta stream version from the json document string metaStreamVersion = ""; //loop through each property to get the value of the variable 'mMetaStreamVersion' to determine what version of the meta header to parse. foreach (JProperty property in metaObject.Properties()) { string name = property.Name; if (name.Equals("mMetaStreamVersion")) { metaStreamVersion = (string)property.Value; break; } } //deserialize the appropriate json object if (metaStreamVersion.Equals("6VSM")) { msv6 = metaObject.ToObject <MSV6>(); } else if (metaStreamVersion.Equals("5VSM")) { msv5 = metaObject.ToObject <MSV5>(); } else if (metaStreamVersion.Equals("ERTM")) { mtre = metaObject.ToObject <MTRE>(); } //d3dtx object JObject d3dtxObject = jarray[1] as JObject; //d3dtx version value int d3dtxVersion = 0; //loop through each property to get the value of the variable 'mVersion' to determine what version of the d3dtx header to parse. foreach (JProperty property in d3dtxObject.Properties()) { string name = property.Name; if (name.Equals("mVersion")) { d3dtxVersion = (int)property.Value; break; } } //deserialize the appropriate json object switch (d3dtxVersion) { case 4: d3dtx4 = d3dtxObject.ToObject <D3DTX_V4>(); break; case 5: d3dtx5 = d3dtxObject.ToObject <D3DTX_V5>(); break; case 6: d3dtx6 = d3dtxObject.ToObject <D3DTX_V6>(); break; case 7: d3dtx7 = d3dtxObject.ToObject <D3DTX_V7>(); break; case 8: d3dtx8 = d3dtxObject.ToObject <D3DTX_V8>(); break; case 9: d3dtx9 = d3dtxObject.ToObject <D3DTX_V9>(); break; default: d3dtxOLD = d3dtxObject.ToObject <D3DTX_V_OLD>(); break; } }