Michael:

I'm doing that exact same thing right now, for a module for a plugin
manager that shall remain nameless :P

Your plugin is loaded before any ents are created, obviously, but
after all the factories are initialized and the class maps prettied up
and whatnot - a very good time for loading. Hooking CreateEdict is
nice, but it won't tell you what type of entity is being created.

So I went on to hooking EntityFactoryDictionary, which I've become
quite fond of :D A windows only way of getting the EFD ptr is in my
sigscanner thread on the forums of that place (nasty, I know, but hey
it works - haven't had to update it since I made it) - the linux way
is a ton easier. Using my vfunc hook thing again from those forums
heres a way to hook the creation of any ent, and do with it what you
will (too lazy to make my vtbl hook work on lin atm, but I'll be
forced to soon - again it's a ton easier)

class CEntityFactoryDictionary  : public IEntityFactoryDictionary {
public:
        CEntityFactoryDictionary();

        void InstallFactory( IEntityFactory *pFactory, const char *pClassName );
        IServerNetworkable *Create( const char *pClassName );
        void Destroy( const char *pClassName, IServerNetworkable *pNetworkable 
);

public:
        IEntityFactory *FindFactory( const char *pClassName );

        CUtlDict< IEntityFactory *, unsigned short > m_Factories;
};

CEntityFactoryDictionary* pEntityFactoryDictionary = NULL;

CSigScanner SigEntityFactoryDictionary("SigEntityFactoryDictionary",
SIGRANGESERVERDLL, &pEntityFactoryDictionary,
"xx????xxxxxxxxxxx????xx????x????x????x????xxxx????x",
"\x8A\x0D\x58\x16\x5A\x22\xB0\x01\x84\xC8\x75\x21\x8A\xD1\x0A\xD0\xB9\x08\x16\x5A\x22\x88\x15\x58\x16\x5A\x22\xE8\x60\x00\x00\x00\x68\x30\xD9\x3A\x22\xE8\x2F\x99\x01\x00\x83\xC4\x04\xB8\x08\x16\x5A\x22\xC3",
17, false, 2); //lol

DEFVFUNC(EntityFactoryDictionary_Create, CBaseEntity*,
(CEntityFactoryDictionary*, const char* lpcClassName));

CBaseEntity* VFUNC myEFD_Create(CEntityFactoryDictionary* pEFD, const
char* lpcClassName){
        CBaseEntity* pEntity = EntityFactoryDictionary_Create(pEFD, 
lpcClassName);

        LOG("Made ent: [%s] %x", lpcClassName, pEntity);

        return pEntity;
}

.... init ....

        HOOKVFUNC(pEntityFactoryDictionary, 1,
EntityFactoryDictionary_Create, myEFD_Create);

Regarding modifying those entities, hook their vtbls - you can do
anything you want ot them. If you want a single instance only hook
then swap out the ent's vtable ptr (which I've had no luck with,
honestly), or hook all ents of that type by just modifying it's vtable
directly (which I've had luck with).

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to