Dealing with hooks in a binary Module

Does anyone know how to get the Player object passed to the intitial spawn hook in binary module?
I have hooked the hook with



ILuaObject* hookModule =Lua()->GetGlobal("hook");
	ILuaObject* addFunction = hookModule->GetMember("Add");

	addFunction->Push();
	Lua()->Push("PlayerSpawn");
	Lua()->Push("DeRP:PlayerInitialSpawn");
	Lua()->Push(DeRP_Player_FirstSpawn);

	Lua()->Call(3);

	addFunction->UnReference();
	hookModule->UnReference();


but this does not seem to work



LUA_FUNCTION(DeRP_Player_FirstSpawn)
{
	isr=new DeRPPlayerInitSpawnRequest(GetDatabase(),Lua(),finishedspawn);
	ILuaObject* ply=Lua()->GetObject(1);
	ILuaObject* SteamID=ply->GetMember("SteamID");
	Lua()->Push(SteamID);
	Lua()->Call(0,1);
	const char* steam_id=Lua()->GetReturn(0)->GetString();
	Lua()->Msg("[DeRP]Checking that this is steam ID: %s",steam_id);
	finishedspawn();
	return 0;
}


It errors out saying calling a nill value, then the message says [DeRP]Checking that this is steam ID: nill

You need to convert it to a CBaseHandle and push it to Lua. All you need to know to do that is right here: http://code.google.com/p/chrisaster/source/browse/trunk/gmsv_luamd5/gmsv_luamd5/gmsv_luamd5.cpp . Remember to include that sigscan for IEntityList else you will error.

This reminds me why I sometimes hate C++, I can not see how the two things match.

[editline]04:56PM[/editline]

Oh wait, now I think I see it, greeeeeeat, why can;t this be simple?

[editline]05:02PM[/editline]

Whats with the sig scanning for entity list? it is not used anywhere else even o.o

That’s because your module wasn’t compiled with Garry’s Mod at the start. You don’t have direct access to the entity list unless you use some other method to find it.

But the module you show does not even use the entity list once it has found it

It’s used indirectly in the SDK.

well that failed ,




Warning	1	warning C4800: 'CBaseHandle *' : forcing value to bool 'true' or 'false' (performance warning)	C:\DeRP\gmsv_DeRP\gmsv_DeRP\DeRPPlayer.cpp	21	1	gmsv_DeRP



A warning doesn’t mean a failure, it just points out a possible flaw. In this case you should compare the handle to 0 or NULL instead of forcing it into a boolean.

also when I run the thing? I get this error :



kat.swales suicided!
bad argument #1 to '?' (Entity expected, got boolean)
[DeRP]Checking that this is steam ID: (null)


the line it warned about?



Lua()->Push(ply);


[editline]06:52PM[/editline]

the function is currently now:




LUA_FUNCTION(DeRP_Player_FirstSpawn)
{
	//Lua()->CheckType(1,GLua::TYPE_TABLE);
	isr=new DeRPPlayerInitSpawnRequest(GetDatabase(),Lua(),finishedspawn);
	CBaseHandle* ply=(CBaseHandle *)Lua()->GetObject(1);
	if(!ply)
		Lua()->Error("This did not worl");
	ILuaObject* SteamIDIndex=Lua()->GetMetaTable("Player", GLua::TYPE_ENTITY)->GetMember("SteamID");
	Lua()->Push(SteamIDIndex);
	Lua()->Push(ply);
	Lua()->Call(1,1);
	const char* steam_id=Lua()->GetReturn(0)->GetString();
	Lua()->Msg("[DeRP]Checking that this is steam ID: %s",steam_id);
	finishedspawn();
	return 0;
}



You cant push entities, i havent found a way to properly do it yet atleast, its forcing it to a bolean becuse thats the only overload that works

Yeah I can see that, just wondering why Gbps said to do that then.as looking at the code, no way it would work

seems this however, DOES work :



LUA_FUNCTION(DeRP_Player_FirstSpawn)
{
	//Lua()->CheckType(1,GLua::TYPE_TABLE);
	isr=new DeRPPlayerInitSpawnRequest(GetDatabase(),Lua(),finishedspawn);
	ILuaObject* ply=Lua()->GetObject(1);
	if(!ply)
		Lua()->Error("This did not work");
	ILuaObject* SteamIDIndex=Lua()->GetMetaTable("Player", GLua::TYPE_ENTITY)->GetMember("SteamID");
	Lua()->Push(SteamIDIndex);
	Lua()->Push(ply);
	Lua()->Call(1,1);
	const char* steam_id=Lua()->GetReturn(0)->GetString();
	Lua()->Msg("[DeRP]Checking that this is steam ID: %s",steam_id);
	finishedspawn();
	return 0;
}


without all that sigscanning nonsence.

Pass the entity index rather than the SteamID. More efficient.

Edit: nevermind, read the code wrong.

It does, but it’s not “correct” I guess.

And sigscanning is?:raise:

not correct in what way? rather then what you told me, that does not even come close to working thanks to the fact you can NOT push a CBaseHandle onto Lua.

[editline]10:47PM[/editline]

Gbps was claiming would need to use some sigscanning, which is basically searching memory for the address of a function.

Let me rephrase that:
And sigscanning is the “correct” way?

You push CBaseHandle* to Lua with the metatable GLua::TYPE_ENTITY. That’s what an entity is.

[editline]04:57PM[/editline]

The “correct” way is using the IBaseEntityList to use and give CBaseHandle to/from Lua.

the most convoluted way possible is not the correct way, note that this does it without any fuss, and bother with that, and I have found it in several releases in the release section, whereas I have not found the use of CBaseHandle, which none of the lua functions even accept at all (I can say that after just double checking by searching through the headers).

CBaseHandle is used to get CBaseEntity which is the most useful entity class in the Source engine.