This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Accessing entity information in MetaMod:Source


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ManuHeel
New Member
Join Date: May 2024
Location: France
Old 05-27-2024 , 16:07   Accessing entity information in MetaMod:Source
Reply With Quote #1

Hi!

MetaMod:Source beginner here, with just a little bit of experience coding in C++ and coding within the Source engine.

I'm currently porting code I made for a Source engine modification, where I was overriding the client.dll and server.dll, to a Metamod:Source plugin as I'd like my addons to be more portable and compatible with different mods overriding these DLLs.

I managed to compile everything from the samples, adapt them into my plugins, code some stuff, link external DLLs and libs, all right, however I'm stuck at interacting with entities (CBaseEntity and such) and edicts (edict_t). I'm used to be in the engine and having access to CBase, CBaseEntity, and most importantly the global gEntList variable which is quite useful, but it seems I cannot do it the same way with a plugin.

I had code like this snippet right there to find NPCs in the map and do something with it (only read data though) :


CBaseEntity *pNPC = nullptr;
while ((pNPC = gEntList.FindEntityByClassname(pNPC, "npc_*")) != nullptr) {
auto *pAI = dynamic_cast<CAI_BaseNPC *>(pNPC);
if (pAI) {
int relationToPlayer = pAI->IRelationType(pPlayer); // I already had a pointer to my player
// something something
}
}

This code is probably written like shit but it worked, I had access to cbase.h so with baseentity.h, so with gEntList and the base classes like CBaseEntity, but now in Metamod I don't.
I tried including the cbase.h header, of course, but I can't find a way to link it, and I'm almost certain that's not the way plugins work, they probably don't know what the hell is happening in the engine and maybe I'm not at all permitted to include cbase.h.
I get this kind of linker error which is expected, even if I link every public/*.lib file in the sdk's source :
error LNK2019: unresolved external symbol "public: class CBaseEntity * __thiscall CGlobalEntityList::FindEntityByClassname(clas s CBaseEntity *,char const *)" (?FindEntityByClassname@CGlobalEntityList@@QA EPAVCBaseEntity@@PAV2@PBD@Z) referenced in function [...]

How can I then find data about what entities are currently in the game? How can I access this data, and use the methods of basic classes like CBaseEntity? Can I even known which entities are in the game with like gEntList?

Navigating through the Source engine's doc, I found info on those edict_t objects, which I found in some plugins' methods' signature (so I guess Metamod deals with them), I can get some info from them (like the player's position with pEdict->GetCollideable()->GetCollisionOrigin()) but I can't get more info from it. The doc says I can do think kind of stuff to get an entity from my edict, but it does not work, and I can't compile with CBaseEntity stuff in any case:
pEdit->GetUnknown()->GetBaseEntity()

ex:

void MyPlugin::Hook_ClientPutInServer(edict_t *pEntity, char const *playername) {
Vector position = pEdict->GetCollideable()->GetCollisionOrigin(); // this works
float health = pEdit->GetUnknown()->GetBaseEntity()->GetHealth(); // this returns me 0.0f in any case, and I can't debug from GetBaseEntity() as I get this result in the immediate window : Function IServerUnknown::GetBaseEntity has no address, possibly due to compiler optimizations.
}

Am I missing something? Is there any explicit doc about how to handle CBaseEntity and/or edicts and their data with Metamod:Source?

Thanks a lot.
Manu.
ManuHeel is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-02-2024 , 18:55   Re: Accessing entity information in MetaMod:Source
Reply With Quote #2

Depending on the game you're dealing with, you can probably use the IServerTools Valve interface to help with this.
__________________
asherkin is offline
ManuHeel
New Member
Join Date: May 2024
Location: France
Old 06-03-2024 , 01:13   Re: Accessing entity information in MetaMod:Source
Reply With Quote #3

Hi asherkin, thanks for you help.

I'm modding HL2/HL2 Update through the hl2sdk-sdk2013 engine version.

Thank you for the insight! I'll take a look into the IServerTools interface to see if I can hook it up to one of my classes and find some more info, but it looks promising.

If you have resources or code snippet about implementing the IServerTools interface, I'm up for it.
Quickly searching on Google, I found this kind of similar approach here (https://www.codereversing.com/archives/512). This is Aimbot-related but that's not my goal, I'm not even searching for coding a multiplayer plugin, however it could help me implementing the interface.
ManuHeel is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-03-2024 , 04:53   Re: Accessing entity information in MetaMod:Source
Reply With Quote #4

The stub_mm/sample_mm plugins both have examples of getting IServerGameDLL from the serverFactory - it’s exactly the same but with IServerTools as the type and VSERVERTOOLS_INTERFACE_VERSION as the name.

The problem with reading health is probably the mod’s class layout is different from the SDK and GetHealth isn’t where the header says it should be. Reverse engineering the entire SDK per-game is silly work, so it’s generally just got the core engine stuff and plugins like SM abstract things like virtual function offsets to configuration. Try instead reading the m_iHealth property with https://wiki.alliedmods.net/Entity_Properties (your game might have a different name, check it against a property dump from SM).
__________________
asherkin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode