From 7712807c36b490ad0595709e0b51ba9507a2c134 Mon Sep 17 00:00:00 2001 From: dexy Date: Fri, 13 Mar 2020 04:21:30 +1100 Subject: [PATCH] ResourceAnalyzer improvements --- .../GameFiles/FileTypes/YbnFile.cs | 8 +++++ CodeWalker.Core/GameFiles/GameFileCache.cs | 4 +-- CodeWalker.Core/GameFiles/Resources/Bounds.cs | 33 ++++++++++++------- .../GameFiles/Resources/ResourceBaseTypes.cs | 5 ++- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/YbnFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YbnFile.cs index 5797d66..ac487cd 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YbnFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YbnFile.cs @@ -18,6 +18,10 @@ namespace CodeWalker.GameFiles //used by the editor: public bool HasChanged { get; set; } = false; +#if DEBUG + public ResourceAnalyzer Analyzer { get; set; } +#endif + public YbnFile() : base(null, GameFileType.Ybn) { @@ -55,6 +59,10 @@ namespace CodeWalker.GameFiles Bounds.OwnerYbn = this; Bounds.OwnerName = entry.Name; +#if DEBUG + Analyzer = new ResourceAnalyzer(rd); +#endif + Loaded = true; } diff --git a/CodeWalker.Core/GameFiles/GameFileCache.cs b/CodeWalker.Core/GameFiles/GameFileCache.cs index 254a7c7..d61fc05 100644 --- a/CodeWalker.Core/GameFiles/GameFileCache.cs +++ b/CodeWalker.Core/GameFiles/GameFileCache.cs @@ -3654,7 +3654,7 @@ namespace CodeWalker.GameFiles } public void TestYbns() { - bool xmltest = true; + bool xmltest = false; bool savetest = false; bool reloadtest = false; var errorfiles = new List(); @@ -3878,7 +3878,7 @@ namespace CodeWalker.GameFiles //} } } - if (errorfiles.Count > 0) + if (errorfiles.Count != 13) { } } public void TestYdds() diff --git a/CodeWalker.Core/GameFiles/Resources/Bounds.cs b/CodeWalker.Core/GameFiles/Resources/Bounds.cs index 1050730..eaf657a 100644 --- a/CodeWalker.Core/GameFiles/Resources/Bounds.cs +++ b/CodeWalker.Core/GameFiles/Resources/Bounds.cs @@ -2141,6 +2141,19 @@ namespace CodeWalker.GameFiles this.BVH = reader.ReadBlockAt( this.BvhPointer // offset ); + + //var cap = BVH.Nodes.EntriesCount;//how to calc this? + //var diff = BVH.Nodes.EntriesCapacity - cap; + //switch (diff) + //{ + // case 0: + // case 1: + // case 2: + // break; + // default: + // break;//no hit + //} + } else { @@ -2453,23 +2466,21 @@ namespace CodeWalker.GameFiles this.BVHPointer = reader.ReadUInt64(); // read reference data - this.Children = reader.ReadBlockAt>( - this.ChildrenPointer, // offset - this.ChildrenCount1 - ); - + this.Children = reader.ReadBlockAt>(this.ChildrenPointer, this.ChildrenCount1); this.ChildrenTransformation1 = reader.ReadStructsAt(this.ChildrenTransformation1Pointer, this.ChildrenCount1); this.ChildrenTransformation2 = reader.ReadStructsAt(this.ChildrenTransformation2Pointer, this.ChildrenCount1); this.ChildrenBoundingBoxes = reader.ReadStructsAt(this.ChildrenBoundingBoxesPointer, this.ChildrenCount1); this.ChildrenFlags1 = reader.ReadStructsAt(this.ChildrenFlags1Pointer, this.ChildrenCount1); this.ChildrenFlags2 = reader.ReadStructsAt(this.ChildrenFlags2Pointer, this.ChildrenCount1); + this.BVH = reader.ReadBlockAt(this.BVHPointer); - this.BVH = reader.ReadBlockAt( - this.BVHPointer // offset - ); - - - + //if (BVH != null) + //{ + // var cap = Math.Max(BVH.Nodes.EntriesCount + 2, ChildrenCount1 * 2 + 1); + // var diff = BVH.Nodes.EntriesCapacity - cap; + // if (diff != 0) + // { }//no hit + //} var childTransforms = ChildrenTransformation1 ?? ChildrenTransformation2; if ((Children != null) && (Children.data_items != null)) diff --git a/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs b/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs index 35f9aa8..de9fba2 100644 --- a/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs +++ b/CodeWalker.Core/GameFiles/Resources/ResourceBaseTypes.cs @@ -847,6 +847,9 @@ namespace CodeWalker.GameFiles //TODO: NEEDS TO BE TESTED!!! data_items = reader.ReadStructsAt(EntriesPointer, EntriesCount); + + if (EntriesCount != EntriesCapacity) + { } } /// @@ -926,7 +929,7 @@ namespace CodeWalker.GameFiles // read reference data //TODO: NEEDS TO BE TESTED!!! - data_items = reader.ReadStructsAt(EntriesPointer, EntriesCount); + data_items = reader.ReadStructsAt(EntriesPointer, EntriesCapacity); } ///