From cedf2f73f6d8750ec07459e976d961da7d9d73c7 Mon Sep 17 00:00:00 2001 From: dexy Date: Mon, 27 Jan 2020 06:35:15 +1100 Subject: [PATCH] Resource types cleanup --- .../GameFiles/Resources/Particle.cs | 70 ++----- .../GameFiles/Resources/ResourceBaseTypes.cs | 171 ------------------ 2 files changed, 18 insertions(+), 223 deletions(-) diff --git a/CodeWalker.Core/GameFiles/Resources/Particle.cs b/CodeWalker.Core/GameFiles/Resources/Particle.cs index c2ec3a5..7db9b00 100644 --- a/CodeWalker.Core/GameFiles/Resources/Particle.cs +++ b/CodeWalker.Core/GameFiles/Resources/Particle.cs @@ -177,7 +177,7 @@ namespace CodeWalker.GameFiles public ulong Unknown_8h; // 0x0000000000000000 public ulong Unknown_10h; // 0x0000000000000000 public ulong Unknown_18h = 1; // 0x0000000000000001 - public ResourceSimpleList64 ParticleRuleNameHashes { get; set; } + public ResourceSimpleList64_s ParticleRuleNameHashes { get; set; } public ResourcePointerList64 ParticleRules { get; set; } @@ -189,7 +189,7 @@ namespace CodeWalker.GameFiles this.Unknown_8h = reader.ReadUInt64(); this.Unknown_10h = reader.ReadUInt64(); this.Unknown_18h = reader.ReadUInt64(); - this.ParticleRuleNameHashes = reader.ReadBlock>(); + this.ParticleRuleNameHashes = reader.ReadBlock>(); this.ParticleRules = reader.ReadBlock>(); //if (Unknown_4h != 1) @@ -203,6 +203,7 @@ namespace CodeWalker.GameFiles } public override void Write(ResourceDataWriter writer, params object[] parameters) { + // write structure data writer.Write(this.VFT); writer.Write(this.Unknown_4h); @@ -236,7 +237,7 @@ namespace CodeWalker.GameFiles public ulong Unknown_8h; // 0x0000000000000000 public ulong Unknown_10h; // 0x0000000000000000 public ulong Unknown_18h = 1; // 0x0000000000000001 - public ResourceSimpleList64 EffectRuleNameHashes { get; set; } + public ResourceSimpleList64_s EffectRuleNameHashes { get; set; } public ResourcePointerList64 EffectRules { get; set; } public override void Read(ResourceDataReader reader, params object[] parameters) @@ -247,7 +248,7 @@ namespace CodeWalker.GameFiles this.Unknown_8h = reader.ReadUInt64(); this.Unknown_10h = reader.ReadUInt64(); this.Unknown_18h = reader.ReadUInt64(); - this.EffectRuleNameHashes = reader.ReadBlock>(); + this.EffectRuleNameHashes = reader.ReadBlock>(); this.EffectRules = reader.ReadBlock>(); //if (Unknown_4h != 1) @@ -294,18 +295,9 @@ namespace CodeWalker.GameFiles public ulong Unknown_8h; // 0x0000000000000000 public ulong Unknown_10h; // 0x0000000000000000 public ulong Unknown_18h = 1; // 0x0000000000000001 - public ulong HashesPointer { get; set; } - public ushort HashesCount1 { get; set; } - public ushort HashesCount2 { get; set; } - public uint Unknown_2Ch; // 0x00000000 - public ulong EffectRulesPointer { get; set; } - public ushort EffectRulesCount1 { get; set; } - public ushort EffectRulesCount2 { get; set; } - public uint Unknown_3Ch; // 0x00000000 + public ResourceSimpleList64_s EmitterRuleNameHashes { get; set; } + public ResourcePointerList64 EmitterRules { get; set; } - // reference data - public ResourceSimpleArray Hashes { get; set; } - public ResourcePointerArray64 EmitterRules { get; set; } public override void Read(ResourceDataReader reader, params object[] parameters) { @@ -315,18 +307,9 @@ namespace CodeWalker.GameFiles this.Unknown_8h = reader.ReadUInt64(); this.Unknown_10h = reader.ReadUInt64(); this.Unknown_18h = reader.ReadUInt64(); - this.HashesPointer = reader.ReadUInt64(); - this.HashesCount1 = reader.ReadUInt16(); - this.HashesCount2 = reader.ReadUInt16(); - this.Unknown_2Ch = reader.ReadUInt32(); - this.EffectRulesPointer = reader.ReadUInt64(); - this.EffectRulesCount1 = reader.ReadUInt16(); - this.EffectRulesCount2 = reader.ReadUInt16(); - this.Unknown_3Ch = reader.ReadUInt32(); + this.EmitterRuleNameHashes = reader.ReadBlock>(); + this.EmitterRules = reader.ReadBlock>(); - // read reference data - this.Hashes = reader.ReadBlockAt>(this.HashesPointer, this.HashesCount1); - this.EmitterRules = reader.ReadBlockAt>(this.EffectRulesPointer, this.EffectRulesCount1); //if (Unknown_4h != 1) //{ }//no hit @@ -336,20 +319,9 @@ namespace CodeWalker.GameFiles //{ }//no hit //if (Unknown_18h != 1) //{ }//no hit - //if (Unknown_2Ch != 0) - //{ }//no hit - //if (Unknown_3Ch != 0) - //{ }//no hit } public override void Write(ResourceDataWriter writer, params object[] parameters) { - // update structure data - this.HashesPointer = (ulong)(this.Hashes != null ? this.Hashes.FilePosition : 0); - this.HashesCount1 = (ushort)(this.Hashes != null ? this.Hashes.Count : 0); - this.HashesCount2 = this.HashesCount1; - this.EffectRulesPointer = (ulong)(this.EmitterRules != null ? this.EmitterRules.FilePosition : 0); - this.EffectRulesCount1 = (ushort)(this.EmitterRules != null ? this.EmitterRules.Count : 0); - this.EffectRulesCount2 = this.EffectRulesCount1; // write structure data writer.Write(this.VFT); @@ -357,22 +329,16 @@ namespace CodeWalker.GameFiles writer.Write(this.Unknown_8h); writer.Write(this.Unknown_10h); writer.Write(this.Unknown_18h); - writer.Write(this.HashesPointer); - writer.Write(this.HashesCount1); - writer.Write(this.HashesCount2); - writer.Write(this.Unknown_2Ch); - writer.Write(this.EffectRulesPointer); - writer.Write(this.EffectRulesCount1); - writer.Write(this.EffectRulesCount2); - writer.Write(this.Unknown_3Ch); + writer.WriteBlock(this.EmitterRuleNameHashes); + writer.WriteBlock(this.EmitterRules); } - public override IResourceBlock[] GetReferences() + public override Tuple[] GetParts() { - var list = new List(); - if (Hashes != null) list.Add(Hashes); - if (EmitterRules != null) list.Add(EmitterRules); - return list.ToArray(); + return new Tuple[] { + new Tuple(0x20, EmitterRuleNameHashes), + new Tuple(0x30, EmitterRules) + }; } } @@ -887,7 +853,7 @@ namespace CodeWalker.GameFiles public ulong Unknown_28h; // 0x0000000000000000 public ulong Unknown_30h; // 0x0000000000000000 public ulong Unknown_38h; // 0x0000000000000000 - public ResourceSimpleList64 Unknown_40h { get; set; } + public ResourceSimpleList64_s Unknown_40h { get; set; } public uint Unknown_50h { get; set; } public uint Unknown_54h; // 0x00000000 @@ -899,7 +865,7 @@ namespace CodeWalker.GameFiles this.Unknown_28h = reader.ReadUInt64(); this.Unknown_30h = reader.ReadUInt64(); this.Unknown_38h = reader.ReadUInt64(); - this.Unknown_40h = reader.ReadBlock>(); + this.Unknown_40h = reader.ReadBlock>(); this.Unknown_50h = reader.ReadUInt32(); this.Unknown_54h = reader.ReadUInt32(); diff --git a/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs b/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs index 1949986..a6d3e89 100644 --- a/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs +++ b/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs @@ -36,45 +36,6 @@ namespace CodeWalker.GameFiles { - [TypeConverter(typeof(ExpandableObjectConverter))] public class uint_r : ResourceSystemBlock - { - // Represents a uint that can be referenced in a resource structure. - - /// - /// Gets the length of the uint. - /// - public override long BlockLength - { - get { return 4; } - } - - /// - /// Gets or sets the uint value. - /// - public uint Value { get; set; } - - public override void Read(ResourceDataReader reader, params object[] parameters) - { - Value = reader.ReadUInt32(); - } - - public override void Write(ResourceDataWriter writer, params object[] parameters) - { - writer.Write(Value); - } - - public static explicit operator uint(uint_r value) - { - return value.Value; - } - - public static explicit operator uint_r(uint value) - { - var x = new uint_r(); - x.Value = value; - return x; - } - } [TypeConverter(typeof(ExpandableObjectConverter))] public class string_r : ResourceSystemBlock { @@ -1917,138 +1878,6 @@ namespace CodeWalker.GameFiles } } - [TypeConverter(typeof(ExpandableObjectConverter))] public class ResourceSimpleArrayArray64 : ListBase> where T : IResourceSystemBlock, new() - { - /// - /// Gets the length of the data block. - /// - public override long BlockLength - { - get - { - long len = 8 * Data.Count; - //foreach (var f in Data) - // len += f.BlockLength; - return len; - } - } - - - public ResourceSimpleArrayArray64() - { - Data = new List>(); - } - - - - - public List ptr_list { get; private set; } - - - - /// - /// Reads the data block. - /// - public override void Read(ResourceDataReader reader, params object[] parameters) - { - if (parameters[1] is uint[]) - { - //version for raw arrays from dexy - - var numEl2 = (uint[])parameters[1]; - - ptr_list = new List(); - for (int i = 0; i < numEl2.Length; i++) - ptr_list.Add(reader.ReadUInt64()); - - for (int i = 0; i < numEl2.Length; i++) - { - var xarr = reader.ReadBlockAt>(ptr_list[i], numEl2[i]); - Data.Add(xarr); - } - - return; - } - - - - var numEl = (ResourceSimpleArray)parameters[1]; - - ptr_list = new List(); - for (int i = 0; i < numEl.Count; i++) - ptr_list.Add(reader.ReadUInt64()); - - for (int i = 0; i < numEl.Count; i++) - { - var xarr = reader.ReadBlockAt>(ptr_list[i], (uint)numEl[i]); - Data.Add(xarr); - } - - //int numElements = Convert.ToInt32(parameters[0]); - - //Data = new List(); - //for (int i = 0; i < numElements; i++) - //{ - // T item = reader.ReadBlock(); - // Data.Add(item); - //} - } - - /// - /// Writes the data block. - /// - public override void Write(ResourceDataWriter writer, params object[] parameters) - { - //foreach (var f in Data) - // f.Write(writer); - - - ptr_list = new List(); - foreach (var x in Data) - ptr_list.Add((ulong)x.FilePosition); - - foreach (var x in ptr_list) - writer.Write(x); - //foreach (var x in Data) - // x.Write(writer); - - } - - - - public override IResourceBlock[] GetReferences() - { - var children = new List(); - - if (Data != null) children.AddRange(Data); - - return children.ToArray(); - } - - public override Tuple[] GetParts() - { - var children = new List>(); - - //if (Data != null) - //{ - // long len = 8 * Data.Count; - // foreach (var f in Data) - // { - // children.Add(new Tuple(len, f)); - // len += f.BlockLength; - // } - //} - - return children.ToArray(); - } - - public override string ToString() - { - return "(Count: " + ((ptr_list != null) ? ptr_list.Count : 0).ToString() + ")"; - } - - } - [TypeConverter(typeof(ExpandableObjectConverter))] public class ResourceSimpleArray2 : ResourceSystemBlock where T : IResourceSystemBlock, new() where U : IResourceSystemBlock, new() { public ResourceSimpleArray Array1 { get; private set; }