Raised This Month: $ Target: $400
 0% 

Create_named_entity()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-12-2014 , 13:35   Create_named_entity()
Reply With Quote #1

I'm trying to create entites by calling CREATE_NAMED_ENTITY, due to the old story with dll optimizations and the hash list not being updated when creating an entity with amxx.

So, I managed to properly hook(orpheu config shows "FOUND") that function:
Code:
new OrpheuFunction: CreateNamedEntityHook public plugin_precache() {     CreateNamedEntityHook =  OrpheuGetFunction("CREATE_NAMED_ENTITY")     if(!CreateNamedEntityHook)     {         set_fail_state("Failed to hook CREATE_NAMED_ENTITY")     } } //Later OrpheuCall(CreateNamedEntityHook, EntityClassName)
The problem is that everytime I call that function it returns an invalid entity(0). I'm sure that EntityClassName is a valid string, I've tried with info_target

I'm a bit confused because in IDA I see that this function has a singe param and that's an int, but the classname should be a string.

Also the game code didn't solved my questions:
Code:
edict_t *CREATE_NAMED_ENTITY(string_t iClass) {     edict_t *named = g_engfuncs.pfnCreateNamedEntity(iClass);     if (named)     {         AddEntityHashValue(&named->v, STRING(iClass), CLASSNAME);     }     return named; }
__________________

Last edited by HamletEagle; 12-12-2014 at 15:52.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-12-2014 , 15:51   Re: Create_named_entity()
Reply With Quote #2

It doesn't expect a string, but an integer, which is basically a kind of offset.
You have to call EngFunc_AllocString on the concerned string and use its return in CREATE_NAMED_ENTITY.
To get a string from such kind of offset you can use EngFunc_SzFromIndex or glb_pStringBase.

Note: on constants strings, game does such trick, code copied from HLDSK:
Code:
// Use this instead of ALLOC_STRING on constant strings
#define STRING(offset)		((const char *)(gpGlobals->pStringBase + (unsigned int)(offset)))
#define MAKE_STRING(str)	((uint64)(str) - (uint64)(STRING(0)))
But in a plugin I guess you have no choice to allocate, so it might be a good idea to do it one time.
__________________

Last edited by Arkshine; 12-12-2014 at 15:58.
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-12-2014 , 15:57   Re: Create_named_entity()
Reply With Quote #3

Oh, I was thinking about that because I saw it needs an integer but was too lazy to actually try it. Thx Arkshine, you save the day again.
__________________

Last edited by HamletEagle; 12-12-2014 at 15:57.
HamletEagle is offline
Reply


Thread Tools
Display Modes

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 15:28.


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