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 authored Jan 18, 2025
1 parent 352c4de commit afed1c2
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions addons/core/scripts/Game/ACE_Core/Global/ACE_EntityIdHelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,38 @@ 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;

array<int> bits = ACE_HexTools.HexStringToInt(str);
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);
// Fixed by LRRP, reported upstream: https://github.com/acemod/ACE-Anvil/issues/152
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 afed1c2

Please sign in to comment.