Latest TF2 update broke EntIndexToEntRef or EntRefToEntIndex
bottiger1 opened this issue · 18 comments
EntIndexToEntRef seems to return some kind of number, but it can't be used anywhere, including EntRefToEntIndex.
public OnPluginStart()
{
int ent = FindEntityByClassname(-1, "vote_controller"); // 44
int ref = EntIndexToEntRef(ent); // -2047737812
int back = EntRefToEntIndex(ref); // -1
PrintToServer("original %i ref %i index %i", ent, ref, back);
char name[64];
GetEntPropString(ref, Prop_Data, "m_iName", name, sizeof(name)); // Exception reported: Entity -1 (-2047737812) is invalid
PrintToServer("name %s", name);
}
SourceMod Version Information:
SourceMod Version: 1.11.0.6920
SourcePawn Engine: 1.11.0.6920, jit-x86 (build 1.11.0.6920)
SourcePawn API: v1 = 5, v2 = 16
Compiled on: Dec 1 2022 16:38:10
Built from: d1be0421
Build ID: 6920:d1be0421
http://www.sourcemod.net/
I just tested this. The error is still occuring.
original 44 ref -2047737812 index -1
SourceMod Version Information:
SourceMod Version: 1.11.0.6921
SourcePawn Engine: 1.11.0.6921, jit-x86 (build 1.11.0.6921)
SourcePawn API: v1 = 5, v2 = 16
Compiled on: Dec 1 2022 18:52:49
Built from: 99ec71ac
Build ID: 6921:99ec71ac
http://www.sourcemod.net/
This repros for me as well on latest 1.12.
] sm_rcon sm plugins load crap
original 48 ref -1683816400 index -1
[SM] Plugin crap.smx failed to load: Error detected in plugin startup (see error logs).
My guess is that NUM_ENT_ENTRIES has changed, or something similar. I don't have sourcemod compile environment to test this hypothesis right now, but starting to set it up.
Line 1001 in e34e9b9
tf2
https://github.com/alliedmodders/hl2sdk/blob/tf2/public/const.h#L66
You're right. It's 8192 now. I'll get the SDK updated.
Unfortunately I just tested it with the snippet above and it still doesn't succeed.
original 44 ref -2047737812 index -1
SourceMod Version Information:
SourceMod Version: 1.11.0.6922
SourcePawn Engine: 1.11.0.6922, jit-x86 (build 1.11.0.6922)
SourcePawn API: v1 = 5, v2 = 16
Compiled on: Dec 1 2022 19:46:50
Built from: f9765981
Build ID: 6922:f9765981
http://www.sourcemod.net/
Tested 1.11.0.6922 on Windows and I'm still getting issues as well.
After doing some more investigation, I believe basehandle.h has been upgraded as well.
https://github.com/alliedmodders/hl2sdk/blob/tf2/public/basehandle.h
https://github.com/alliedmodders/hl2sdk/blob/csgo/public/basehandle.h
Specifically GetSerialNumber is no longer correct. I have verified with GDB that it should be shifted by 16 instead of the current 13.
inline int CBaseHandle::GetSerialNumber() const
{
return m_Index >> NUM_ENT_ENTRY_BITS; // in csgo this is NUM_SERIAL_NUM_SHIFT_BITS which is 16
}
However I do not know if it would be safe to just change this or copy over the entire file from csgo due to my limited understanding of the handle system.
thank you all you're all beautiful I wish i could buy you coffees <3
$10 to whoever gets it working!!
entirely serious DM me if you do eet & it work
can send $ in/with whatever is necessary
thank u all
After doing some more investigation, I believe basehandle.h has been upgraded as well.
https://github.com/alliedmodders/hl2sdk/blob/tf2/public/basehandle.h
https://github.com/alliedmodders/hl2sdk/blob/csgo/public/basehandle.h
Specifically GetSerialNumber is no longer correct. I have verified with GDB that it should be shifted by 16 instead of the current 13.
inline int CBaseHandle::GetSerialNumber() const { return m_Index >> NUM_ENT_ENTRY_BITS; // in csgo this is NUM_SERIAL_NUM_SHIFT_BITS which is 16 }
However I do not know if it would be safe to just change this or copy over the entire file from csgo due to my limited understanding of the handle system.
Do you know if CBaseHandle::Init is still correct
I do not know. I am hoping other people with more knowledge of the engine internals would be able to say for sure.
I would release a pull request but I don't want people to blame me for weird side effects because some other parts of basehandle.h were included or not included. I don't know how to test it for correctness.
Try the latest build again please.
latest no work! and @sapphonie compiled some shared libraries for me that I tried to also no avail.
also, beautiful
the compiled .so
's just included this proposed quickfix / patch
#1871 (comment)
Try the latest build again please.
Tested on Windows with 1.12.0.6943. Seems to be working fine now.
Test code.
#include <sourcemod>
#include <sdkhooks>
void OnEntityCreated(int entity, const char[] classname)
{
int ref = EntIndexToEntRef(entity);
int ent = EntRefToEntIndex(ref);
LogMessage("OnEntityCreated - %i#(%s) - %i/%i", entity, classname, ref, ent);
}
Output:
L 12/02/2022 - 07:28:16: [entref_test.smx] OnEntityCreated - 94#(item_healthkit_medium) - -1499856802/94
L 12/02/2022 - 07:28:16: [entref_test.smx] OnEntityCreated - 95#(item_ammopack_medium) - -632553377/95
L 12/02/2022 - 07:28:16: [entref_test.smx] OnEntityCreated - 96#(item_healthkit_small) - -633995168/96
L 12/02/2022 - 07:28:16: [entref_test.smx] OnEntityCreated - 97#(item_ammopack_medium) - -1364524959/97
L 12/02/2022 - 07:28:16: [entref_test.smx] OnEntityCreated - 98#(trigger_multiple) - -1565392798/98
L 12/02/2022 - 07:28:16: [entref_test.smx] OnEntityCreated - 99#(ambient_generic) - -117571485/99
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 100#(func_respawnroom) - -1807679388/100
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 101#(func_brush) - -759365531/101
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 102#(func_brush) - -1676345242/102
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 103#(func_door) - -1615986585/103
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 104#(func_door) - -873332632/104
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 105#(func_brush) - -595066775/105
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 106#(func_brush) - -1379008406/106
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 107#(func_respawnroomvisualizer) - -1464532885/107
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 108#(func_brush) - -1134886804/108
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 109#(func_door) - -1856962451/109
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 110#(func_door) - -1194000274/110
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 111#(trigger_multiple) - -251658129/111
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 112#(func_respawnroomvisualizer) - -1525809040/112
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 113#(func_door) - -1629159311/113
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 114#(logic_auto) - -1882718094/114
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 115#(env_tonemap_controller) - -69402509/115
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 116#(info_observer_point) - -2013855628/116
L 12/02/2022 - 07:28:17: [entref_test.smx] OnEntityCreated - 117#(prop_dynamic) - -861863819/117
Excellent, thank you!