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

SourceMod FindEntityByClassname / SetEntProp extension equivalents?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-21-2012 , 17:23   SourceMod FindEntityByClassname / SetEntProp extension equivalents?
Reply With Quote #1

Hi guys,

I was wondering if there was an easy way in a SourceMod extension to find an entity by its classname and adjust its properties. This would be quite easy to do in a plugin, but unfortunately, the rest of my logic is already in an extension.

Incidentally, the entity class is vote_controller, and the properties I want to adjust are:
Code:
 -Member: m_iActiveIssueIndex (offset 796) (type integer) (bits 32)
 -Member: m_iOnlyTeamToVote (offset 800) (type integer) (bits 32)
  Sub-Class Table (2 Deep): m_nVoteOptionCount
  -Member: 000 (offset 0) (type integer) (bits 8)
  -Member: 001 (offset 4) (type integer) (bits 8)
  -Member: 002 (offset 8) (type integer) (bits 8)
  -Member: 003 (offset 12) (type integer) (bits 8)
  -Member: 004 (offset 16) (type integer) (bits 8)
 -Member: m_nPotentialVotes (offset 824) (type integer) (bits 32)
 -Member: m_bIsYesNoVote (offset 828) (type integer) (bits 1)
(yes, all of them)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-21-2012 at 17:24.
Powerlord is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-21-2012 , 20:11   Re: SourceMod FindEntityByClassname / SetEntProp extension equivalents?
Reply With Quote #2

Quote:
Originally Posted by Powerlord View Post
Hi guys,

I was wondering if there was an easy way in a SourceMod extension to find an entity by its classname and adjust its properties. This would be quite easy to do in a plugin, but unfortunately, the rest of my logic is already in an extension.

Incidentally, the entity class is vote_controller, and the properties I want to adjust are:
Code:
 -Member: m_iActiveIssueIndex (offset 796) (type integer) (bits 32)
 -Member: m_iOnlyTeamToVote (offset 800) (type integer) (bits 32)
  Sub-Class Table (2 Deep): m_nVoteOptionCount
  -Member: 000 (offset 0) (type integer) (bits 8)
  -Member: 001 (offset 4) (type integer) (bits 8)
  -Member: 002 (offset 8) (type integer) (bits 8)
  -Member: 003 (offset 12) (type integer) (bits 8)
  -Member: 004 (offset 16) (type integer) (bits 8)
 -Member: m_nPotentialVotes (offset 824) (type integer) (bits 32)
 -Member: m_bIsYesNoVote (offset 828) (type integer) (bits 1)
(yes, all of them)
For FEBC, you can copy the native implementation using IServerTools right out of SDK Tools.
http://hg.alliedmods.net/sourcemod-c...tives.cpp#l638

For finding datadesc property offsets and values, use GetDataMap and FindInDataMap on IGameHelpers.
PHP Code:
datamap_t *pMap gamehelpers->GetDataMap(pEntity);
typedescription_t *td gamehelpers->FindInDataMap(pMap"m_nVoteOptionCount");
uint32 nVoteOptionCount = *(uint32 *)((intptr_t)pEntity GetTypeDescOffs(td)); 
psychonic is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-21-2012 , 20:12   Re: SourceMod FindEntityByClassname / SetEntProp extension equivalents?
Reply With Quote #3

Quote:
Originally Posted by psychonic View Post
For FEBC, you can copy the native implementation using IServerTools right out of SDK Tools.
http://hg.alliedmods.net/sourcemod-c...tives.cpp#l638

For finding datadesc property offsets and values, use GetDataMap and FindInDataMap on IGameHelpers.
PHP Code:
datamap_t *pMap gamehelpers->GetDataMap(pEntity);
typedescription_t *td gamehelpers->FindInDataMap(pMap"m_nVoteOptionCount");
uint32 nVoteOptionCount = *(uint32 *)((intptr_t)pEntity GetTypeDescOffs(td)); 
These are Netprops by the way, would this still be the correct way to access them?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-21-2012 , 20:22   Re: SourceMod FindEntityByClassname / SetEntProp extension equivalents?
Reply With Quote #4

Quote:
Originally Posted by Powerlord View Post
These are Netprops by the way, would this still be the correct way to access them?
Actually, they exist as both. I sillily search for vote_controller instead of CVoteController in the netprop dump, ofc didn't find it, and then looked in the datamap dump.

Netprops, specifically for integers are a little trickier due to the varying bit counts.

Look at SM's core/smn_entities.cpp and GetEntProp for an example.
psychonic is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-29-2016 , 15:52   Re: SourceMod FindEntityByClassname / SetEntProp extension equivalents?
Reply With Quote #5

Hey, sorry to bump this since I'm trying to do the same thing

can you tell me why this doesnt work ?
PHP Code:
CBaseEntity *UTIL_FindEntityByClassname(int start, const char *pEntityClassname)
{
    
CBaseEntity *pEntity;

    if (
start == -1)
    {
        
pEntity = (CBaseEntity *)g_pServerTools->FirstEntity();
    }
    else
    {
        
pEntity gamehelpers->ReferenceToEntity(start);

        if (
pEntity)
        {
            
pEntity = (CBaseEntity *)g_pServerTools->NextEntity(pEntity);
        }
    }

    if (
pEntity)
    {
        static 
int offset = -1;

        if (
offset == -1)
        {
            
sm_datatable_info_t info;

            if (
gamehelpers->FindDataMapInfo(gamehelpers->GetDataMap(pEntity), "m_iClassname", &info))
            {
                
offset info.actual_offset;
            }
        }

        const 
char *pClassname;
        
string_t str;

        
int lastLetter;

        while (
pEntity)
        {
            
str = *(string_t *)((uint8_t *)pEntity offset);

            if (
str == NULL_STRING)
            {
                
pEntity = (CBaseEntity *)g_pServerTools->NextEntity(pEntity);
                continue;
            }

            
pClassname STRING(str);

            
lastLetter strlen(pEntityClassname) - 1;

            if (
pEntityClassname[lastLetter] == '*' && !strncasecmp(pEntityClassnamepClassnamelastLetter))
            {
                return 
pEntity;
            }
            else if (!
strcasecmp(pEntityClassnamepClassname))
            {
                return 
pEntity;
            }

            
pEntity = (CBaseEntity *)g_pServerTools->NextEntity(pEntity);
        }
    }

    return 
pEntity;
}; 
Basically I'm trying to find the fov ("ent_fov_controller") and edit it also is there any equivalent to SetVariant* and AcceptEntityInput

PHP Code:
void OnServer_Activate(edict_t *pEdictint edictCountint clientMax)
{
    
engine->LightStyle(0MAP_LIGHT);

/*
    CBaseEntity *pFogEntity = UTIL_FindEntityByClassname(-1, "env_fog_controller");

    if (!pFogEntity)
    {
        g_pServerTools->DispatchSpawn(pFogEntity);
    }

    g_pServerTools->SetKeyValue(pFogEntity, "fogmaxdensity", 0.6);
    
    SetVariantInt(FogStartDist);
    AcceptEntityInput(FogControllerIndex, "SetStartDist");
        
    SetVariantInt(FogEndDist);
    AcceptEntityInput(FogControllerIndex, "SetEndDist");
    
    SetVariantInt(FogZPlane);
    AcceptEntityInput(FogControllerIndex, "SetFarZ");

    SetVariantString(FogColor);
    AcceptEntityInput(FogControllerIndex, "SetColor");

    SetVariantString(FogColor);
    AcceptEntityInput(FogControllerIndex, "SetColorSecondary");
    
    SET START DIST, END DIST, FARZ
*/

The lightning works fine, but others doesnt

Last edited by TheDS1337; 01-29-2016 at 15:53.
TheDS1337 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 00:19.


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