From dcfe22ade78872abcff919d2515497b584c63943 Mon Sep 17 00:00:00 2001 From: dexy Date: Fri, 13 Mar 2020 01:05:59 +1100 Subject: [PATCH] Fragments group names reading/writing/packing improvements --- CodeWalker.Core/GameFiles/Resources/Frag.cs | 122 ++++++++++-- .../GameFiles/Resources/ResourceBaseTypes.cs | 175 ------------------ 2 files changed, 106 insertions(+), 191 deletions(-) diff --git a/CodeWalker.Core/GameFiles/Resources/Frag.cs b/CodeWalker.Core/GameFiles/Resources/Frag.cs index f31170e..ce47509 100644 --- a/CodeWalker.Core/GameFiles/Resources/Frag.cs +++ b/CodeWalker.Core/GameFiles/Resources/Frag.cs @@ -2178,7 +2178,7 @@ namespace CodeWalker.GameFiles // reference data public FragPhysArticulatedBodyType ArticulatedBodyType { get; set; } public float[] ChildrenUnkFloats { get; set; } - public ResourcePointerArray64_s GroupNames { get; set; } + public FragPhysGroupNamesBlock GroupNames { get; set; } public ResourcePointerArray64 Groups { get; set; } public ResourcePointerArray64 Children { get; set; } public FragPhysArchetype Archetype1 { get; set; } @@ -2253,8 +2253,8 @@ namespace CodeWalker.GameFiles // read reference data this.ArticulatedBodyType = reader.ReadBlockAt(this.ArticulatedBodyTypePointer); this.ChildrenUnkFloats = reader.ReadFloatsAt(this.ChildrenUnkFloatsPointer, this.ChildrenCount); - this.GroupNames = reader.ReadBlockAt>(this.GroupNamesPointer, this.GroupsCount); this.Groups = reader.ReadBlockAt>(this.GroupsPointer, this.GroupsCount); + this.GroupNames = reader.ReadBlockAt(this.GroupNamesPointer, this.GroupsCount, this.Groups?.data_items); this.Children = reader.ReadBlockAt>(this.ChildrenPointer, this.ChildrenCount); this.Archetype1 = reader.ReadBlockAt(this.Archetype1Pointer); this.Archetype2 = reader.ReadBlockAt(this.Archetype2Pointer); @@ -2377,8 +2377,6 @@ namespace CodeWalker.GameFiles } public override void Write(ResourceDataWriter writer, params object[] parameters) { - BuildGroupsData(); - // update structure data this.ArticulatedBodyTypePointer = (ulong)(this.ArticulatedBodyType != null ? this.ArticulatedBodyType.FilePosition : 0); this.ChildrenUnkFloatsPointer = (ulong)(this.ChildrenUnkFloatsBlock != null ? this.ChildrenUnkFloatsBlock.FilePosition : 0); @@ -2400,16 +2398,6 @@ namespace CodeWalker.GameFiles this.ChildrenCount = (byte)(this.Children != null ? this.Children.Count : 0); this.ChildrenCount2 = this.ChildrenCount; - if ((Groups?.data_items != null) && (GroupNames != null)) - { - var gnplist = new List(); - foreach (var grp in Groups?.data_items) - { - gnplist.Add((ulong)grp.FilePosition + 128);//manually write group names pointers as offsets to the groups - } - GroupNames.data_pointers = gnplist.ToArray(); - } - // write structure data writer.Write(this.VFT); @@ -2664,8 +2652,9 @@ namespace CodeWalker.GameFiles if (grpnames.Count > 0) { - if (GroupNames == null) GroupNames = new ResourcePointerArray64_s(); + if (GroupNames == null) GroupNames = new FragPhysGroupNamesBlock(); GroupNames.data_items = grpnames.ToArray(); + GroupNames.Groups = Groups?.data_items; } else { @@ -2712,7 +2701,6 @@ namespace CodeWalker.GameFiles } if (GroupNames != null) { - GroupNames.ManualPointerOverride = (Groups != null); //we'll just write a set of pointers into the Groups list.Add(GroupNames); } return list.ToArray(); @@ -4200,6 +4188,108 @@ namespace CodeWalker.GameFiles } + [TypeConverter(typeof(ExpandableObjectConverter))] public class FragPhysGroupNamesBlock : ResourceSystemBlock + { + + public override long BlockLength + { + get { return (data_items?.Length ?? 0) * 8 + 8; } + } + + + public ulong[] data_pointers { get; set; } + public FragPhysNameStruct_s[] data_items { get; set; } + + public uint UnkVFT { get; set; } = 1095046985; + public uint UnkUint1 { get; set; } = 1; + + + public FragPhysTypeGroup[] Groups;//for writing purposes + + + + public override void Read(ResourceDataReader reader, params object[] parameters) + { + int numElements = Convert.ToInt32(parameters[0]); + Groups = parameters[1] as FragPhysTypeGroup[]; + + data_pointers = new ulong[numElements]; + for (int i = 0; i < numElements; i++) + { + data_pointers[i] = reader.ReadUInt64(); + } + + UnkVFT = reader.ReadUInt32(); + UnkUint1 = reader.ReadUInt32(); + + //switch (UnkVFT) + //{ + // case 1095030569: + // case 1080035264: + // case 1080043424: + // case 1080043456: + // case 1079473328: + // case 1079970608: + // case 1079970704: + // case 1079985584: + // case 1079976016: + // case 1080043488: + // case 1079992976: + // case 1095046985: + // case 1095046905: + // break; + // default: + // break;//no hit + //} + //switch (UnkUint1) + //{ + // case 1: + // break; + // default: + // break;//no hit + //} + + data_items = new FragPhysNameStruct_s[numElements]; + for (int i = 0; i < numElements; i++) + { + data_items[i] = reader.ReadStructAt((long)data_pointers[i]); + } + + } + + public override void Write(ResourceDataWriter writer, params object[] parameters) + { + + + var gnplist = new List(); + foreach (var grp in Groups) + { + gnplist.Add((ulong)grp.FilePosition + 128);//manually write group names pointers as offsets to the groups + } + data_pointers = gnplist.ToArray(); + + + + foreach (var x in data_pointers) + { + writer.Write(x); + } + + writer.Write(UnkVFT); + writer.Write(UnkUint1); + + } + + + + + public override string ToString() + { + return "(Count: " + ((data_items != null) ? data_items.Length : 0).ToString() + ")"; + } + + } + [TypeConverter(typeof(ExpandableObjectConverter))] public struct FragPhysNameStruct_s { // structure data diff --git a/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs b/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs index aed3b11..35f9aa8 100644 --- a/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs +++ b/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs @@ -1542,181 +1542,6 @@ namespace CodeWalker.GameFiles - public override string ToString() - { - return "(Count: " + ((data_items != null) ? data_items.Length : 0).ToString() + ")"; - } - - } - [TypeConverter(typeof(ExpandableObjectConverter))] public class ResourcePointerArray64_s : ResourceSystemBlock, IList where T : struct - { - - public override long BlockLength - { - get { return (data_items != null) ? 8 * data_items.Length : 0; } - } - - - public ulong[] data_pointers { get; set; } - public T[] data_items { get; set; } - - public bool ManualPointerOverride = false;//use this to manually write data_pointers - - private ResourceSystemStructBlock[] data_blocks = null; - - - public ResourcePointerArray64_s() - { - } - - public override void Read(ResourceDataReader reader, params object[] parameters) - { - int numElements = Convert.ToInt32(parameters[0]); - - data_pointers = reader.ReadUlongsAt((ulong)reader.Position, (uint)numElements); - - data_items = new T[numElements]; - for (int i = 0; i < numElements; i++) - { - data_items[i] = reader.ReadStructAt((long)data_pointers[i]); - } - - } - - public override void Write(ResourceDataWriter writer, params object[] parameters) - { - // update... - if (ManualPointerOverride == false) - { - var list = new List(); - if (data_blocks != null) - { - foreach (var x in data_blocks) - { - list.Add((ulong)x.FilePosition); - } - } - //foreach (var x in data_items) - // if (x != null) - // data_pointers.Add((uint)x.Position); - // else - // data_pointers.Add((uint)0); - data_pointers = list.ToArray(); - } - - // write... - foreach (var x in data_pointers) - writer.Write(x); - } - - - public override IResourceBlock[] GetReferences() - { - var list = new List(); - - if (ManualPointerOverride == false) - { - var blocks = new List>(); - if (data_items != null) - { - foreach (var x in data_items) - { - var block = new ResourceSystemStructBlock(new[] { x }); - blocks.Add(block); - list.Add(block); - } - } - data_blocks = blocks.ToArray(); - //foreach (var x in data_items) - // list.Add(x); - } - - return list.ToArray(); - } - - - - - - public int IndexOf(T item) - { - throw new NotImplementedException(); - } - - public void Insert(int index, T item) - { - throw new NotImplementedException(); - } - - public void RemoveAt(int index) - { - //data_items.RemoveAt(index); - throw new NotImplementedException(); - } - - public T this[int index] - { - get - { - return data_items[index]; - } - set - { - throw new NotImplementedException(); - } - } - - public void Add(T item) - { - //data_items.Add(item); - throw new NotImplementedException(); - } - - public void Clear() - { - throw new NotImplementedException(); - } - - public bool Contains(T item) - { - throw new NotImplementedException(); - } - - public void CopyTo(T[] array, int arrayIndex) - { - throw new NotImplementedException(); - } - - public int Count - { - //get { return data_items.Count; } - get { return (data_items != null) ? data_items.Length : 0; } - } - - public bool IsReadOnly - { - get { return false; } - } - - public bool Remove(T item) - { - //return data_items.Remove(item); - throw new NotImplementedException(); - } - - public IEnumerator GetEnumerator() - { - //return data_items.GetEnumerator(); - throw new NotImplementedException(); - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } - - - public override string ToString() { return "(Count: " + ((data_items != null) ? data_items.Length : 0).ToString() + ")";