alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
978 stars 424 forks source link

Latest TF2 update broke EntIndexToEntRef or EntRefToEntIndex #1871

Closed bottiger1 closed 1 year ago

bottiger1 commented 1 year ago

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: https://github.com/alliedmodders/sourcemod/commit/d1be0421 Build ID: 6920:d1be0421 http://www.sourcemod.net/

psychonic commented 1 year ago

This is fixed in 1.11.6921, by backporting https://github.com/alliedmodders/sourcemod/pull/1859 from master.

bottiger1 commented 1 year ago

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: https://github.com/alliedmodders/sourcemod/commit/99ec71ac Build ID: 6921:99ec71ac http://www.sourcemod.net/

voided commented 1 year ago

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).
bottiger1 commented 1 year ago

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.

https://github.com/alliedmodders/sourcemod/blob/e34e9b9869915bd2f82446cc64ddedf06586722d/core/HalfLife2.cpp#L1001

tf2 https://github.com/alliedmodders/hl2sdk/blob/tf2/public/const.h#L66

csgo https://github.com/alliedmodders/hl2sdk/blob/da376c88b01397ab0678183b796711dccedb4513/public/const.h#L73

psychonic commented 1 year ago

You're right. It's 8192 now. I'll get the SDK updated.

psychonic commented 1 year ago

This should be ok now.

https://github.com/alliedmodders/hl2sdk/commit/4209d924355ffce8ba5a7d9537d4fc94aabe713a

https://github.com/alliedmodders/sourcemod/commit/83a29cf82b5b2412f2ff265058dc8049e9c1330f

bottiger1 commented 1 year ago

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: https://github.com/alliedmodders/sourcemod/commit/f9765981 Build ID: 6922:f9765981 http://www.sourcemod.net/

fearts commented 1 year ago

Tested 1.11.0.6922 on Windows and I'm still getting issues as well.

bottiger1 commented 1 year ago

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.

zudsniper commented 1 year ago

thank you all you're all beautiful I wish i could buy you coffees <3

zudsniper commented 1 year ago

$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

sapphonie commented 1 year ago

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

bottiger1 commented 1 year ago

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.

asherkin commented 1 year ago

Try the latest build again please.

zudsniper commented 1 year ago

latest no work! and @sapphonie compiled some shared libraries for me that I tried to also no avail. also, beautiful
good chats

zudsniper commented 1 year ago

the compiled .so's just included this proposed quickfix / patch https://github.com/alliedmodders/sourcemod/issues/1871#issuecomment-1334755152

caxanga334 commented 1 year ago

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
asherkin commented 1 year ago

Excellent, thank you!