From 44c71139f14e851e56f031dfd726c3a7e3494d2b Mon Sep 17 00:00:00 2001 From: Eugene Pogrebnyak Date: Thu, 3 Dec 2020 14:30:15 +0300 Subject: [PATCH 1/2] Changed entity hash generation method to real one used in RAGE --- .../GameFiles/FileTypes/YmapFile.cs | 25 ++++--------------- .../GameFiles/MetaTypes/Archetype.cs | 1 + 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs index 5c27028..4530878 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs @@ -1385,6 +1385,7 @@ namespace CodeWalker.GameFiles UpdateWidgetPosition(); UpdateWidgetOrientation(); + UpdateEntityHash(); } @@ -1515,26 +1516,10 @@ namespace CodeWalker.GameFiles public void UpdateEntityHash() { - unchecked - { - var ints = new int[4]; - var pv = Position; - ints[0] = (int)pv.X; - ints[1] = (int)pv.Y; - ints[2] = (int)pv.Z; - ints[3] = (int)_CEntityDef.archetypeName.Hash; - var bytes = new byte[16]; - for (int i = 0; i < 4; i++) - { - var ib = i * 4; - var b = BitConverter.GetBytes(ints[i]); - bytes[ib + 0] = b[0]; - bytes[ib + 1] = b[1]; - bytes[ib + 2] = b[2]; - bytes[ib + 3] = b[3]; - } - EntityHash = JenkHash.GenHash(bytes); - } + uint xhash = (uint)Math.Floor(Position.X * 100); + uint yhash = (uint)Math.Floor(Position.Y * 100); + uint zhash = (uint)Math.Floor(Position.Z * 100); + EntityHash = _CEntityDef.archetypeName.Hash ^ xhash ^ yhash ^ zhash & 0xffffffff; } public void SetOrientation(Quaternion ori, bool inverse = false) diff --git a/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs b/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs index 38c2618..1d8cd85 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs @@ -864,6 +864,7 @@ namespace CodeWalker.GameFiles e.Orientation = Quaternion.Multiply(Owner.Orientation, e.MloRefOrientation); e.UpdateWidgetPosition(); e.UpdateWidgetOrientation(); + e.UpdateEntityHash(); } public void AddEntity(YmapEntityDef e) From 3e05173d112d5d3442ef6178b945732775293b53 Mon Sep 17 00:00:00 2001 From: Eugene Pogrebnyak Date: Thu, 3 Dec 2020 23:47:39 +0300 Subject: [PATCH 2/2] Fixed hash generation to 100% fit RAGE one --- CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs index 4530878..be16759 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs @@ -1516,9 +1516,9 @@ namespace CodeWalker.GameFiles public void UpdateEntityHash() { - uint xhash = (uint)Math.Floor(Position.X * 100); - uint yhash = (uint)Math.Floor(Position.Y * 100); - uint zhash = (uint)Math.Floor(Position.Z * 100); + uint xhash = (uint)(Position.X * 100); + uint yhash = (uint)(Position.Y * 100); + uint zhash = (uint)(Position.Z * 100); EntityHash = _CEntityDef.archetypeName.Hash ^ xhash ^ yhash ^ zhash & 0xffffffff; }