PDA

View Full Version : Using CBaseEntity::Create from a server plugin (mini-tut)


vancelorgin
12-12-2004, 23:04
I also posted this on HL2Coding.com, but originally from this IRC channel. This is for those who missed it.

Well (as we all know), Valve's server plugin interface sucks. Rather than bitch I'm being proactive and trying to make it suck less. I'm putting together a set of mod-independant server plugin interface extensions which give access to server.dll functions and singletons that you really shouldn't have access to. Here is a little preview - how to use CBaseEntity::Create. That function, obviously, creates an entity :P It isn't, however, exported by server.dll in any way, and hence usually cannot be used by anything but server.dll itself. Fuck that. The function is in memory, so you can call it. Here is how (on a windows hl2dm box, dedicated or server, as of 12/12/04):


typedef CBaseEntity* (__cdecl* CBaseEntity_CreateFunc)( const char *szName, const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner );
CBaseEntity_CreateFunc CBaseEntity_Create = (CBaseEntity_CreateFunc)0x22227F00;


Yeah - hacked, but works flawlessly. My code auto-derives this address based on a signature scan, but I don't feel like pasting it, and it needs polishing. I'll probably release it soon. As an example of how to use it, try this down in ClientCommand:


if(FStrEq(pcmd, "wtfhelp")){
CBaseEntity* e = pEntity->GetUnknown()->GetBaseEntity();
CBaseEntity_Create("item_healthvial", e->GetAbsOrigin(), e->GetAbsAngles(), NULL);
return PLUGIN_STOP;
}


That spawns a little health vial on whoever types "wtfhelp" into their console. This is just the beginning guys: I'm working on hooking server messages, total ent control, ent class func overrides, and so, so much more. For the time being, play around with this :)

Dygear
12-12-2004, 23:07
0x22227F00

*Runs away with tail between legs* Yikes, I did not know the SDK went down to that level.

vancelorgin
12-12-2004, 23:10
Well it gets compiled, so it goes down that low level. You can only do really cool stuff from a server plugin *if* you yourself go down that low, but Valve never intended for us to :P

BAILOPAN
12-12-2004, 23:16
Good job lancevorigin.

This should be message to valve - that if you don't provide the interfaces, people will extract them anyway ;]

Johnny got his gun
12-13-2004, 07:20
Obviously this isn't the way to go. Valve just has to make something better.

Fruchtzwerg
12-13-2004, 08:31
You cant use the baseentity class in the future if it get changed, Valve warns about this in the hlcoders mailing list. MOD authors can easly change this class, but you will never get new header files for this.

PM
12-13-2004, 14:52
You cant use the baseentity class in the future if it get changed, Valve warns about this in the hlcoders mailing list. MOD authors can easly change this class, but you will never get new header files for this.

Valve can warn, but we have been doing stuff mod dependent, with offsets and unpredictable messages and such for a long time at AMX / AMXX. It works well if you have someone interested enough to update the offsets :)

I think we will have to do it the same way here until they give us something better (or we will write our metamod!!111yams 0xBA1L style)

vancelorgin
12-13-2004, 15:14
Whilst yes, CBaseEntity can change, we can compensate (as he pointed out).

And, Johnny: I hope all of this will be wasted time soon, but it probably will be ages before we see a decent plugin interface, and I want to see and do some dev in the mean time. Again, I hope to be wrong here.

Please note I've done this shit for years and years now. I didn't just start doing this weird shit yesterday :P

Eradicator
12-13-2004, 15:51
I get a use of undefined type error even though I defined the type using your code above o_O

BAILOPAN
12-13-2004, 16:32
don;t use his code unless you know what you are doing

Eradicator
12-13-2004, 17:17
Umm... right. If it crashes I guess I'll have to go home and cry to my mother o_O Anyway, can someone offer real help so that I can ->learn<- (I know its strange to ask that of people on a... coding forum)?

vancelorgin
12-14-2004, 07:45
It'd be easier to help on IRC :P I'm on gamesurge, #sourcemod. If I don't respond, I'm asleep.