public static H3D Open(MemoryStream MS) { //Please note that data should be on Memory when opening because addresses are relocated. //Otherwise the original file would be corrupted! BinaryDeserializer Deserializer = new BinaryDeserializer(MS, GetSerializationOptions()); H3DHeader Header = Deserializer.Deserialize <H3DHeader>(); new H3DRelocator(MS, Header).ToAbsolute(); H3D Scene = Deserializer.Deserialize <H3D>(); Scene.BackwardCompatibility = Header.BackwardCompatibility; Scene.ForwardCompatibility = Header.ForwardCompatibility; Scene.ConverterVersion = Header.ConverterVersion; Scene.Flags = Header.Flags; /*Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(Scene, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings() * { * ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore * }));*/ Scene.SourceData.Add(Scene); return(Scene); }
public H3DRelocator(Stream BaseStream, H3DHeader Header) { this.BaseStream = BaseStream; this.Header = Header; Reader = new BinaryReader(BaseStream); Writer = new BinaryWriter(BaseStream); }
public static H3D Open(MemoryStream MS) { //Please note that data should be on Memory when opening because addresses are relocated. //Otherwise the original file would be corrupted! BinaryDeserializer Deserializer = new BinaryDeserializer(MS, GetSerializationOptions()); H3DHeader Header = Deserializer.Deserialize <H3DHeader>(); Console.Write("H3DHeader printout:\n{0}\n", Header); PrintProperties(Header); Console.Write("H3DHeader printout end\n\n\n\n\n"); new H3DRelocator(MS, Header).ToAbsolute(); H3D Scene = Deserializer.Deserialize <H3D>(); Console.Write("H3DScene printout:\n{0}\n", Scene); foreach (var field in Scene.GetType().GetFields()) { PrintProperties(field); } //PrintProperties(Scene); Scene.BackwardCompatibility = Header.BackwardCompatibility; Scene.ForwardCompatibility = Header.ForwardCompatibility; Scene.ConverterVersion = Header.ConverterVersion; Scene.Flags = Header.Flags; foreach (var thingy in Scene.Textures) { bool thing = false; //thing = true; if (thing) { string test = (new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location)).Directory + "\\" + thingy.Name + ".bin"; var bw = new BinaryWriter(File.OpenWrite(test)); bw.Write(thingy.RawBuffer); bw.Close(); } } return(Scene); }
public static H3D Open(MemoryStream MS) { //Please note that data should be on Memory when opening because addresses are relocated. //Otherwise the original file would be corrupted! BinaryDeserializer Deserializer = new BinaryDeserializer(MS, GetSerializationOptions()); H3DHeader Header = Deserializer.Deserialize <H3DHeader>(); new H3DRelocator(MS, Header).ToAbsolute(); H3D Scene = Deserializer.Deserialize <H3D>(); Scene.BackwardCompatibility = Header.BackwardCompatibility; Scene.ForwardCompatibility = Header.ForwardCompatibility; Scene.ConverterVersion = Header.ConverterVersion; Scene.Flags = Header.Flags; return(Scene); }
public static void Save(string FileName, H3D Scene) { using (FileStream FS = new FileStream(FileName, FileMode.Create)) { H3DHeader Header = new H3DHeader(); H3DRelocator Relocator = new H3DRelocator(FS, Header); BinarySerializer Serializer = new BinarySerializer(FS, GetSerializationOptions()); Section Contents = Serializer.Sections[(uint)H3DSectionId.Contents]; Contents.Header = Header; /* * Those comparisons are used to sort Strings and data buffers. * Strings are sorted in alphabetical order (like on the original file), * while buffers places textures first, and then vertex/index data after. * It's unknown why textures needs to come first, but placing the textures * at the end or at random order causes issues on the game. * It's most likely an alignment issue. */ Comparison <RefValue> CompStr = H3DComparers.GetComparisonStr(); Comparison <RefValue> CompRaw = H3DComparers.GetComparisonRaw(); Section Strings = new Section(0x10, CompStr); Section Commands = new Section(0x80); Section RawData = new Section(0x80, CompRaw); Section RawExt = new Section(0x80, CompRaw); Section Relocation = new Section(); Serializer.AddSection((uint)H3DSectionId.Strings, Strings, typeof(string)); Serializer.AddSection((uint)H3DSectionId.Strings, Strings, typeof(H3DStringUtf16)); Serializer.AddSection((uint)H3DSectionId.Commands, Commands, typeof(uint[])); Serializer.AddSection((uint)H3DSectionId.RawData, RawData); Serializer.AddSection((uint)H3DSectionId.RawExt, RawExt); Serializer.AddSection((uint)H3DSectionId.Relocation, Relocation); Header.BackwardCompatibility = Scene.BackwardCompatibility; Header.ForwardCompatibility = Scene.ForwardCompatibility; Header.ConverterVersion = Scene.ConverterVersion; Header.Flags = Scene.Flags; Serializer.Serialize(Scene); Header.AddressCount = (ushort)RawData.Values.Count; Header.AddressCount += (ushort)RawExt.Values.Count; Header.UnInitDataLength = Header.AddressCount * 4; Header.ContentsAddress = Contents.Position; Header.StringsAddress = Strings.Position; Header.CommandsAddress = Commands.Position; Header.RawDataAddress = RawData.Position; Header.RawExtAddress = RawExt.Position; Header.RelocationAddress = Relocation.Position; Header.ContentsLength = Contents.Length; Header.StringsLength = Strings.Length; Header.CommandsLength = Commands.Length; Header.RawDataLength = RawData.Length; Header.RawExtLength = RawExt.Length; Relocator.ToRelative(Serializer); FS.Seek(0, SeekOrigin.Begin); Serializer.WriteValue(Header); } }
public static H3D Open(MemoryStream MS) { //Please note that data should be on Memory when opening because addresses are relocated. //Otherwise the original file would be corrupted! BinaryDeserializer Deserializer = new BinaryDeserializer(MS, GetSerializationOptions()); H3DHeader Header = Deserializer.Deserialize <H3DHeader>(); new H3DRelocator(MS, Header).ToAbsolute(); H3D Scene = Deserializer.Deserialize <H3D>(); Scene.BackwardCompatibility = Header.BackwardCompatibility; Scene.ForwardCompatibility = Header.ForwardCompatibility; Scene.ConverterVersion = Header.ConverterVersion; Scene.Flags = Header.Flags; /*Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(Scene, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings() * { * ReferenceLoopHandling = ReferenceLoopHandling.Ignore * }));*/ if (Scene.Models.Count > 0) { foreach (H3DMaterial mat in Scene.Models[0].Materials) { /* mat.MaterialParams.StencilTest.Reference = 255; * mat.MaterialParams.MetaData[mat.MaterialParams.MetaData.Find("$EdgeID")].Values[0] = 255; * //mat.MaterialParams.MetaData[mat.MaterialParams.MetaData.Find("$EdgeType")].Values[0] = 0; * //mat.MaterialParams.MetaData.Clear(); * //mat.MaterialParams.VtxShaderUniforms.Clear(); * mat.MaterialParams.FragmentFlags = H3DFragmentFlags.IsLUTReflectionEnabled; * mat.MaterialParams.LUTInputSelection.ReflecR = PICALUTInput.CosNormalView; * mat.MaterialParams.LUTInputSelection.ReflecG = PICALUTInput.CosNormalView; * mat.MaterialParams.LUTInputSelection.ReflecB = PICALUTInput.CosNormalView; * mat.MaterialParams.LUTReflecRSamplerName = null; * mat.MaterialParams.LUTReflecRTableName = null; * mat.MaterialParams.LUTReflecGSamplerName = null; * mat.MaterialParams.LUTReflecGTableName = null; * mat.MaterialParams.LUTReflecBSamplerName = null; * mat.MaterialParams.LUTReflecBTableName = null;*/ /*mat.MaterialParams.TextureCoords[0].Flags = H3DTextureCoordFlags.IsDirty; * mat.MaterialParams.TextureCoords[1].Flags = H3DTextureCoordFlags.IsDirty; * mat.MaterialParams.TextureCoords[2].Flags = H3DTextureCoordFlags.IsDirty; * mat.MaterialParams.TextureCoords[0].ReferenceCameraIndex = 0; * mat.MaterialParams.TextureCoords[1].ReferenceCameraIndex = 0; * mat.MaterialParams.TextureCoords[2].ReferenceCameraIndex = 0;*/ } /*Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(Scene.Models[0], Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings() * { * ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore * }));*/ } /*RGBA DesiredOuterFireColor = new RGBA(0, 255, 0, 255); //Change this to whatever color you want the fire to be * RGBA DesiredInnerFireColor = new RGBA(0, 128, 0, 255); //Change these to whatever color you want the fire to be * * foreach (H3DModel Model in Scene.Models) * { * foreach (H3DMaterial Material in Model.Materials) * { * if (Material.Name.Equals("FireStenA")) * { * SetConstantColor(Material.MaterialParams.GetConstantIndex(0), Material.MaterialParams, DesiredOuterFireColor); * SetConstantColor(Material.MaterialParams.GetConstantIndex(1), Material.MaterialParams, DesiredInnerFireColor); * } * } * }*/ return(Scene); }