Raised This Month: $29 Target: $400
 7% 

[FRAMEWORK] CEntity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pRED*
Join Date: Dec 2006
Old 03-12-2009 , 20:45   [FRAMEWORK] CEntity
Reply With Quote #1

CEntity Entity Handling Framework version 2.x by Matt 'pRED*' Woodrow

This is a framework for C++ developers and requires a decent understanding of C++ and the SDK to be of use.

Source Code

Example Usage
SideWinder (CEntity 1.x)
TFDodgeball (CEntity 2.x)

Credits
  • This is largely (or entirely) based on a concept by voogru - http://voogru.com/
  • The virtual function hooking is powered by the SourceHook library by Pavol "PM OnoTo" Marko.
  • Contains code contributed by Brett "Brutal" Powell.
  • Contains code contributed by Asher "asherkin" Baker.
About
  • CEntity is (and its derived classes are) designed to emulate the CBaseEntity class from the HL2 SDK.
  • Valve code (like entire class definitions and CBaseEntity functions) from the SDK should almost just work when copied into this.
    • References to CBaseEntity need to be changed to CEntity.
    • Sendprops and datamaps are pointers to the actual values so references to these need to be dereferenced.
    • Code that uses unexposed data members won't work - Though you could reimplement these manually.
  • Virtual functions handle identically to ones in a real derived class.
    • Calls from valve code to a virtual in CEntity (with no derived versions) fall back directly to the valve code.
    • Calls from valve code to a virtual (with a derived version) will call that code, and the valve code can be optionally run using BaseClass::Function().
    • Calls from your code to a virtual in CEntity (with no derived versions) will make a call to the valve code.
    • Calls from your code to a virtual (with a derived version) will call that code, and that derived handler can run the valve code optionally using BaseClass::Function().
Notes
  • If you inherit Init() or Destroy() in a derived class, I would highly recommend calling the BaseClass equivalent.

TODO (in no particular order)
  • Add handling of custom keyvalues commands
    • Add datamapping to class values so keyvalues can parse to them
  • Include more CEntity virtuals and props/datamaps
  • Create more derived classes
  • Include more Think/Touch etc handlers
    • Valve code now has lists of thinks, can we access this?
  • Forcibly deleting entities? - Implemented AcceptInput("Kill"...), UTIL_Remove sig scan would be cleaner.
  • Support mods other than TF2 (CPlayer should only contain CBasePlayer sdk stuff and create optional CTFPlayer/CCSPlayer derives)
Change log
  • 1.0
    • Initial import of basic CEntity and CPlayer
  • 2.x
    • Improved LINK_ENTITY_TO_CLASS to use DLL Classnames. tf_projectile_rocket changed to CTFProjectile_Rocket for example.
    • Added the ability to handle entity Inputs/Outputs.
    • Cleaned up Macros used for almost everything.
    • Added many new hooks and props for CEntity and CPlayer.
    • Support for custom classnames with LINK_ENTITY_TO_CUSTOM_CLASS.
    • Added support for detours, needs CDetours folder in the parent directory.
    • Added a helpers class that makes common functions easy (from CrimsonGT).
    • CScriptCreatedItem and CScriptCreatedAttribute (from TF2Items).
    • A new 'tracker', designed to get a generic pointer from a sig in a gamedata file.
    • A lot of CPlayer defines, including PLAYERCONDs, WEAPONSLOTs and LOADOUTSLOTs.
    • Added CAnimating with StudioFrameAdvance and Dissolve.
    • Changed CPlayer to inherit from CAnimating.

Last edited by asherkin; 01-24-2011 at 05:45.
pRED* is offline
pRED*
Join Date: Dec 2006
Old 03-12-2009 , 20:46   Re: [FRAMEWORK] CEntity
Reply With Quote #2

As an aside (and to reserve the second post slot), If anyone wants private paid plugins of a similar nature to sidewinder, feel free to PM me.

I quite enjoy writing gameplay hacks that like.
pRED* is offline
Cooltad
Veteran Member
Join Date: Apr 2008
Old 03-12-2009 , 21:45   Re: [FRAMEWORK] CEntity
Reply With Quote #3

Quote:
Originally Posted by pRED* View Post
As an aside (and to reserve the second post slot), If anyone wants private paid plugins of a similar nature to sidewinder, feel free to PM me.

I quite enjoy writing gameplay hacks that like.
Cost? Like, what if it's a simple, small one? What if it's large and even requires a new extension?
__________________
Please, give me some rep if you found what I posted useful. :]
Cooltad is offline
pRED*
Join Date: Dec 2006
Old 03-12-2009 , 22:05   Re: [FRAMEWORK] CEntity
Reply With Quote #4

Depends entirely on how much work it is.

Feel free to make an offer via PM and we can discuss it.
pRED* is offline
voogru
Inspector Javert
Join Date: Oct 2004
Old 03-15-2009 , 15:02   Re: [FRAMEWORK] CEntity
Reply With Quote #5

OMG COPYCAT, first homing sentry rockets, and now this!

When does it stop?!

:p

It's surprising how much of it actually looks like copy and paste from my interface.

I'm implementing the VP hooks, and after looking at your code there is a flaw that I've discovered:

Code:
if (pNetworkable != NULL)
	{
		const char *serverName = pNetworkable->GetServerClass()->GetName();
		edict_t *pEdict = pNetworkable->GetEdict();
		CBaseEntity *pEnt = pNetworkable->GetBaseEntity();

		if (!pEdict || !pEnt)
		{
			return NULL;
		}

		if (pHookedTrie.retrieve(serverName))
		{
			pFactory->Create(pEdict, pEnt, false);
		}
		else
		{
			pFactory->Create(pEdict, pEnt, true);
			pHookedTrie.insert(serverName, true);
		}
	}

You are assuming that GetServerClass()->GetName() is going to be unique for every vtable, this isn't the case. There are several
entities where this will show up as "CBaseEntity", but they are seperate vtables.

For example, look at "info_target" and "soundent", completely different vtables, but same ServerClass "CBaseEntity".

I'd suggest using the classname of the entity instead, or some alternative method of detecting unique vtables because classname isn't perfect either.
voogru is offline
voogru
Inspector Javert
Join Date: Oct 2004
Old 03-15-2009 , 15:21   Re: [FRAMEWORK] CEntity
Reply With Quote #6

typeid(*BaseEntity()).name()+6 (skip "class ")

Run time type information for the win.
voogru is offline
pRED*
Join Date: Dec 2006
Old 03-15-2009 , 16:17   Re: [FRAMEWORK] CEntity
Reply With Quote #7

RTTI will only exist in the windows binary. Great for you, but i'm aiming for cross platform support.

Anyway are you sure? For "info_target" and "soundent" to have different vtables, they must be linked to separate classes. So why would ServerClass->GetName() return CBaseEntity if they are actually a CBaseInfoTargetOrWhatever. Sense, this picture makes none.

Better solution imo would be track the vtable void*.
pRED* is offline
voogru
Inspector Javert
Join Date: Oct 2004
Old 03-15-2009 , 18:49   Re: [FRAMEWORK] CEntity
Reply With Quote #8

Quote:
Originally Posted by pRED* View Post
RTTI will only exist in the windows binary. Great for you, but i'm aiming for cross platform support.

Anyway are you sure? For "info_target" and "soundent" to have different vtables, they must be linked to separate classes. So why would ServerClass->GetName() return CBaseEntity if they are actually a CBaseInfoTargetOrWhatever. Sense, this picture makes none.

Better solution imo would be track the vtable void*.
Wow, didn't know RTTI would only be in windows binary. Thought linux had that ability too? Doesn't the SDK use RTTI?

Code:
Find all "dynamic_cast", Subfolders, Keep modified files open, Find Results 1, "C:\removed", "*.c;*.cpp;*.cxx;*.cc;*.tli;*.tlh;*.h;*.hpp;*.hxx;*.hh;*.inl;*.rc;*.resx;*.idl;*.asm;*.inc"

game\server\ai_basehumanoid.cpp(142):			 !dynamic_cast<CBasePropDoor *>(pBlocker) &&
game\server\ai_basehumanoid.cpp(154):			CPhysicsProp *pProp = dynamic_cast<CPhysicsProp*>( pBlocker );
game\server\ai_basenpc.cpp(773):			CAI_BaseNPC *pAttacker = dynamic_cast<CAI_BaseNPC *>( info.GetAttacker() );
...

  Matching lines: 783    Matching files: 266    Total files searched: 2800

Last edited by voogru; 03-15-2009 at 18:57.
voogru is offline
pRED*
Join Date: Dec 2006
Old 03-15-2009 , 22:05   Re: [FRAMEWORK] CEntity
Reply With Quote #9

Hum.
pRED* is offline
1nsane
SourceMod Donor
Join Date: Sep 2005
Old 03-16-2009 , 01:04   Re: [FRAMEWORK] CEntity
Reply With Quote #10

This is relevant to my interests.
1nsane 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 06:32.


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