Skip to content

Commit

Permalink
Update ACE_EntityIdHelper to support low IDs entity IDs
Browse files Browse the repository at this point in the history
Map entities such as trees and bushes do not have a high ID. This results in the game engine returning `0x0x` prefixes when ToString is called.

ToInt and FromString have also been updated to use a high ID of 0 when the array only contains a single element.
  • Loading branch information
gnif committed Jan 18, 2025
1 parent 352c4de commit 9ecaa25
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions addons/core/scripts/Game/ACE_Core/Global/ACE_EntityIdHelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,36 @@ class ACE_EntityIdHelper
//------------------------------------------------------------------------------------------------
static array<int> ToInt(EntityID id)
{
return ACE_HexTools.HexStringToInt(ToString(id));
array<int> bits = ACE_HexTools.HexStringToInt(ToString(id));
if (bits.Count() == 1)
bits.InsertAt(0, 0);

return bits;
}

//------------------------------------------------------------------------------------------------
static EntityID FromString(string str)
{
array<int> bits = ACE_HexTools.HexStringToInt(str);
if (bits.Count() < 2)
return EntityID.INVALID;
if (bits.Count() == 1)
bits.InsertAt(0, 0);
else
if (bits.Count() > 2)
return EntityID.INVALID;

return EntityID.FromInt(bits[0], bits[1]);
}

//------------------------------------------------------------------------------------------------
static string ToString(EntityID id)
{
// Drop the last three characters, which are " {}"
return id.ToString().Substring(0, 18);
string str = id.ToString();

// Low id items such as trees/bushes end up with this odd format, fix it
if (str.StartsWith("0x0x"))
return str.Substring(2, str.Length() - 5);
else
return str.Substring(0, str.Length() - 3);
}
}

0 comments on commit 9ecaa25

Please sign in to comment.