Raised This Month: $12 Target: $400
 3% 

CBaseEntity class nonexistant


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-12-2012 , 16:10   CBaseEntity class nonexistant
Reply With Quote #1

I have this bit of code:
PHP Code:
void BaseExt::Hook_SomeHook() 
{
    
CBaseEntitypEnt META_IFACEPTR(CBaseEntity);
    
pEnt-> // nothing shows up

When I try to use the arrow on the pointer class, the compiler simply says "pointer to incomplete class type not allowed". Then I tried deriving my own version of it just to test:

PHP Code:
class CBaseEntityHook : public CBaseEntity
{
public:
    
bool IsHookedcharmodel;
    
CBaseEntityHook() { IsHooked falsemodel NULL; }
};

void BaseExt::Hook_SomeHook()
{
    
CBaseEntitybaseEnt META_IFACEPTR(CBaseEntity);
    
CBaseEntityHookpEnt static_cast<CBaseEntityHook*>(baseEnt); // error

But now it says static_cast: invalid type conversion. Any ideas?
ajr1234 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-12-2012 , 16:49   Re: CBaseEntity class nonexistant
Reply With Quote #2

CBaseEntity is an abstract class, therefore it's no surprise that META_IFACEPTR doesn't work properly on it.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-12-2012 , 17:44   Re: CBaseEntity class nonexistant
Reply With Quote #3

They do a similar thing in the SDK Hooks extension with META_IFACEPTR and CBaseEntity.

It can't be THAT hard to get the model name of an entity when it spawns. Maybe I can use IEntityListener, but I don't have a class by that name anywhere.

Last edited by ajr1234; 06-12-2012 at 20:27.
ajr1234 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-12-2012 , 22:56   Re: CBaseEntity class nonexistant
Reply With Quote #4

CBaseEntity is not abstract, but you still cannot (or at least should not) inherit from it as it includes a huge amount of unnecessary code from the sdk, half of which will be broken on most games.

Just make a forward declaration for CBaseEntity.

Code:
class CBaseEntity;
psychonic is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-13-2012 , 00:48   Re: CBaseEntity class nonexistant
Reply With Quote #5

Code:
CBaseEntity* baseEnt = META_IFACEPTR(CBaseEntity);
string modelName = baseEnt->model;
There was an extension in the Extensions category that did something similar to the above. VC++ 2010 compiler throws an error saying it's an incomplete class... whatever that means. Google searches tell me that class doesn't exist, which doesn't make sense either.

In other words, finding the model name of a spawned entity is harder than I thought -_-
ajr1234 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-13-2012 , 07:17   Re: CBaseEntity class nonexistant
Reply With Quote #6

Quote:
Originally Posted by ajr1234 View Post
Code:
CBaseEntity* baseEnt = META_IFACEPTR(CBaseEntity);
string modelName = baseEnt->model;
There was an extension in the Extensions category that did something similar to the above. VC++ 2010 compiler throws an error saying it's an incomplete class... whatever that means. Google searches tell me that class doesn't exist, which doesn't make sense either.

In other words, finding the model name of a spawned entity is harder than I thought -_-
Right, it's just for naming purposes. You don't have the whole class, and cannot call member functions on it.

What you can do are call any public functions that take an entity, ones from SM or the SDK.

For example, to get modelName like you have there, you can get hold of the IServerTools interface like this, http://hg.nicholashastings.com/sdkho...ff=1&diff=diff

Then you can do:
Code:
char modelName[256]; servertools->GetKeyValue( baseEnt, "model", modelName, sizeof(modelName) );
psychonic is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-13-2012 , 12:05   Re: CBaseEntity class nonexistant
Reply With Quote #7

Psychonic saves the day again!

I never knew about the SDK tools repo. Now I see what you meant by IEntityListener being a good method to check for spawns. In order to get that method working, all I need to do is copy the IEntityListener class and derive it in my SDK class?

Last edited by ajr1234; 06-13-2012 at 12:12.
ajr1234 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-13-2012 , 14:21   Re: CBaseEntity class nonexistant
Reply With Quote #8

Quote:
Originally Posted by ajr1234 View Post
In order to get that method working, all I need to do is copy the IEntityListener class and derive it in my SDK class?
That, plus you also need to add your class to the list of entity listeners. SDK Hooks does this by asking SM for the pointer to the global entity list (IGameHelpers::GetGlobalEntityList()), and then uses an offset in gamedata to the CUtlVector of entity listeners on the list. Add yourself to it on Load and remove on Unload.
psychonic is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-14-2012 , 00:44   Re: CBaseEntity class nonexistant
Reply With Quote #9

EDIT: Thanks psychonic for helping me fix the entity create hook. The model name having "????" characters in them still remains, but I temporarily fixed it by creating a native and having a plugin find it (which seems to be the long way around).

Last question- can we pass a variable number of arguments via a forward?

EDIT 2: Nevermind, found another way.

Last edited by ajr1234; 06-16-2012 at 11:16.
ajr1234 is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 06-18-2012 , 12:03   Re: CBaseEntity class nonexistant
Reply With Quote #10

Sorry to bump this thread again. How can we use functions like GetEntPropEnt in a c++ extension? I looked everywhere, so sorry if this has already been answered before.

EDIT: Nevermind. I found the wiki page

Last edited by ajr1234; 06-18-2012 at 12:10.
ajr1234 is offline
Reply



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 19:29.


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