AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   AddEntityHasValue mod func (https://forums.alliedmods.net/showthread.php?t=251409)

HamletEagle 11-12-2014 11:18

AddEntityHasValue mod func
 
As you may already know custom entities(created by amxx) are not taken into account by the dll, because it cache the ent list. So, if you create a weaponbox ent during a round and you want it to be deleted by the game it won't.

A solution my be to redo the WeaponBoxKill function, and to do the things as the game:
PHP Code:

void CWeaponBox::Killvoid )
{
    
CBasePlayerItem *pWeapon;
    
int i;

    
// destroy the weapons
    
for ( MAX_ITEM_TYPES i++ )
    {
        
pWeapon m_rgpPlayerItems];

        while ( 
pWeapon )
        {
            
pWeapon->SetThink(&CBasePlayerItem::SUB_Remove);
            
pWeapon->pev->nextthink gpGlobals->time 0.1;
            
pWeapon pWeapon->m_pNext;
        }
    }

    
// remove the box
    
UTIL_Removethis );


Source: https://github.com/alliedmodders/hls...ls/weapons.cpp

But I don't like to reinvent the wheel and by searching a bit I found that we can call with okapi/orpheu AddEntityHasValue for our custom entity so the game will take it into account.

From here the problem starts, I think that this function use some unsuported param by okapi/orpheu.

Here is my code:
Code:
#include <amxmodx> #include <okapi> new funcAddEntityHasValue public plugin_init() {     new okapiHandleFunc     new const AddEntityHasValueSymbol[ ] = "AddEntityHashValue__FP9entvars_sPCc12hash_types_e"     new const AddEntityHasValueSignature[ ] = {0x56,0x57,0xDEF,0xDEF,0xDEF,0xDEF,0x57,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x8B,0xF0,0x83}     if     (         (okapiHandleFunc = okapi_mod_get_symbol_ptr(AddEntityHasValueSymbol)) ||         (okapiHandleFunc = okapi_mod_find_sig(AddEntityHasValueSignature, charsmax(AddEntityHasValueSignature)))     )     {         funcAddEntityHasValue = okapi_build_function(okapiHandleFunc, arg_entvars, arg_string,  .... )              } }

The function header is:
Code:

AddEntityHashValue(entvars_s *,char const *,hash_types_e)
In okapi_const I didn't found an argument for hash_types_e so I think it's not suported. Correct me if I'm wrong. I also think if the windows signature is correct, can't test until my code is ready.

My question is: it's possible to register that function with okapi/orpheu so I can call it on my custom entity and solve the problem ? If not, do you have another alternative( without re-doing the c++ code ), which is here if anyone needs it:

Code:
if(!pev_valid(wpnBoxEnt))     {         return     }         new iWpnIndex     for(new Iter; Iter < MAX_ITEM_TYPES; Iter++)     {         iWpnIndex = get_pdata_cbase(wpnBoxEnt, m_rgpPlayerItems[Iter], XO_CWEAPONBOX)         if(pev_valid(iWpnIndex))         {             set_pev(iWpnIndex, pev_flags, FL_KILLME)         }     }         //Maybe better to call think on this weaponbox ?     set_pev(wpnBoxEnt, pev_flags, FL_KILLME)

Arkshine 11-12-2014 11:56

Re: AddEntityHasValue mod func
 
Yeah, you're right, each new entity created, you see a hash is created from its class name, for performance reason.
About the entity creation, I'm talking about pfnCreateNamedEntity, but in the mod, it basically uses a custom function, which calls pfnCreateNamedEntity and AddEntityHashValue, that's why, using AMXX it doesn't work because it calls directly the engine function.

Also, the game is using a custom function UTIL_FindEntityByString to find an entity, which basically loops over the hash table.
Right now it supports only the classname. "hash_types_e" is just an enum (has only one item defined for classname and it's 0 as value), so you can replace by "int". The same.

You can actually see the actual hash map using the server command print_ent.
And you can see the difference in performance using without and with hash using this command : perf_test

You can use arg_int for last param for okapi.
You could also use CREATE_NAMED_ENTITY() from the mod, the custom function I'm talking about.

This could be a good idea to add it to cstrike module since specific to CS, maybe either cs_create_entity or natives to add/remove hash item, don't know.

HamletEagle 11-12-2014 12:00

Re: AddEntityHasValue mod func
 
Code:

Time in old search loop 3.8373
Time in new search loop 0.9554

Impressive...

I've already looked at CreateNamedEntity and I saw exactly what you wrote, that it calls AddEntityHasValue. Thx for the info, will try to replace it by arg_int. One more thing, can you please check if the windows signature is correct ?

Yes, it would be very good to a native for alterating hash items. So, another way is to create the weaponbox with CREATE_NAMED_ENTITY ?

Arkshine 11-12-2014 12:12

Re: AddEntityHasValue mod func
 
This seems the wrong signature, mine is:

Code:

8B ? ? ? 83 ? ? 85 ? 53 55 56 57 0F ? ? ? ? ? 8B

HamletEagle 11-12-2014 12:23

Re: AddEntityHasValue mod func
 
Can you tell me how you find it ? AddEntityHasValue doesn't have strings so we can't search in the swds.dll by strings, I'm a bit confused.

Arkshine 11-12-2014 12:31

Re: AddEntityHasValue mod func
 
It's used in several places, just picked up one randomly. Here ServerActivate, it contains a reference to AddEntityHashValue and a string "Can't instance %s\n".

Code:

                if (pClass && !(pClass->pev->flags & FL_DORMANT))
                {
                        AddEntityHashValue(&pEdictList[i].v, STRING(pEdictList[i].v.classname), CLASSNAME);
                        pClass->Activate();
                }
                else
                        ALERT(at_console, "Can't instance %s\n", STRING(pEdictList[i].v.classname));


HamletEagle 11-12-2014 12:35

Re: AddEntityHasValue mod func
 
Thx for all the info. Some suggestion for amxx, idc where to post them, since I can't create the c++ code:
1. Add the native for hash values.
2. Add a forward that will catch all cvar changes, this is very useful, we won't need to cache cvars on new round or so. Like cvar index( the one returned by register_cvar ), old value, new value.
3. Add a native so we can calculate the velocity considering punch angle and view angle, this is very used and it's becoming annoing to see the same code in 50% of the plugins.

meTaLiCroSS 11-12-2014 17:10

Re: AddEntityHasValue mod func
 
So, instead of hooking AddEntityHashValue, just hook CREATE_NAMED_ENTITY and that would be enough


All times are GMT -4. The time now is 17:34.

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