AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Getting ammo type (particularly grenades) (https://forums.alliedmods.net/showthread.php?t=300574)

Kailo 08-21-2017 17:32

Getting ammo type (particularly grenades)
 
As CreateEntityByName has broken, this my way to get ammo type.
(Ammo type needs for me to check/give/remove grenades from player inventory)
I use engine basic function for it CAmmoDef::Index(const char *).
For call this function we need CAmmoDef object that we can get with GetAmmoDef() function.

PHP Code:

Handle g_hGameConf;
int g_HEGrenadeOffset;
int g_FlashbangOffset;
int g_SmokegrenadeOffset;
int g_MolotovOffset;
int g_DecoyOffset;

public 
void OnPluginStart()
{
    
g_hGameConf LoadGameConfigFile("gamedata");

    
g_HEGrenadeOffset CAmmoDef_Index("AMMO_TYPE_HEGRENADE");
    
g_FlashbangOffset CAmmoDef_Index("AMMO_TYPE_FLASHBANG");
    
g_SmokegrenadeOffset CAmmoDef_Index("AMMO_TYPE_SMOKEGRENADE");
    
g_MolotovOffset CAmmoDef_Index("AMMO_TYPE_MOLOTOV");
    
g_DecoyOffset CAmmoDef_Index("AMMO_TYPE_DECOY");
}

int CAmmoDef_Index(const char[] type)
{
    static 
Handle call null;
    if (
call == null) {
        
StartPrepSDKCall(SDKCall_Raw);
        
PrepSDKCall_SetFromConf(g_hGameConfSDKConf_Signature"CAmmoDef_Index");
        
PrepSDKCall_SetReturnInfo(SDKType_PlainOldDataSDKPass_Plain);
        
PrepSDKCall_AddParameter(SDKType_StringSDKPass_Pointer);
        
call EndPrepSDKCall();
        if (!
call)
            
SetFailState("Can't load function call.");
    }
    static 
any AmmoDef 0;
    if (
AmmoDef == 0)
        
AmmoDef GetAmmoDef();
    return 
SDKCall(callAmmoDeftype);
}

any GetAmmoDef()
{
    static 
Handle call null;
    if (
call == null) {
        
StartPrepSDKCall(SDKCall_Static);
        
PrepSDKCall_SetFromConf(g_hGameConfSDKConf_Signature"GetAmmoDef");
        
PrepSDKCall_SetReturnInfo(SDKType_PlainOldDataSDKPass_Plain);
        
// No args
        
call EndPrepSDKCall();
        if (!
call)
            
SetFailState("Can't load function call.");
    }
    return 
SDKCall(call);


gamedata:
Code:

"Games"
{
        "csgo"
        {
                "Signatures"
                {
                        "GetAmmoDef"
                        {
                                "library"                "server"
                                "windows"                "\x80\x3D\x2A\x2A\x2A\x2A\x00\x0F\x85\x2A\x2A\x2A\x2A\x6A\x0E"
                                "linux"                        "\x55\x89\xE5\x83\xEC\x38\x80\x3D\x2A\x2A\x2A\x2A\x00\x0F\x85\x2A\x2A\x2A\x2A"
                        }
                        "CAmmoDef_Index"
                        {
                                "library"                "server"
                                "windows"                "\x55\x8B\xEC\x8B\x45\x08\x85\xC0\x75\x2A\x83\xC8\xFF"
                                "linux"                        "\x55\x89\xE5\x57\x56\x53\xBB\xFF\xFF\xFF\xFF\x83\xEC\x1C\x8B\x45\x0C"
                        }
                }
        }
}


Dr!fter 08-21-2017 18:00

Re: Getting ammo type (particularly grenades)
 
Why not just use gamedata to read the index's? Like 2 function calls for numbers that havent changed in forever seems a bit much. https://bitbucket.org/Drifter321/wea...#natives.sp-16

Kailo 08-21-2017 18:26

Re: Getting ammo type (particularly grenades)
 
@Dr!fter, Justly. But current situation is not good. If offsets changed (I remember 4 changes): Every plugin what used it must be rewriten by plugin creator and updated on all servers where it used by servers' heads.
Can we use cstrike extention gamedata for it somehow? Offsets changed -> autoupdater update game data for all plugin on all servers.
Or use way 2 with offsets (without signatures)?

P.S. Updated snippet: We can get AmmoDef only once and save it.

CamerDisco 08-21-2017 18:39

Re: Getting ammo type (particularly grenades)
 
Thanks, it will be usefull!

Dr!fter 08-21-2017 19:58

Re: Getting ammo type (particularly grenades)
 
Quote:

Originally Posted by Kailo (Post 2543417)
@Dr!fter, Justly. But current situation is not good. If offsets changed (I remember 4 changes): Every plugin what used it must be rewriten by plugin creator and updated on all servers where it used by servers' heads.
Can we use cstrike extention gamedata for it somehow? Offsets changed -> autoupdater update game data for all plugin on all servers.
Or use way 2 with offsets (without signatures)?

P.S. Updated snippet: We can get AmmoDef only once and save it.

When were the 4 changes? I remember one where there was changes and that was in 2013 (at least for grenades). Server operators will need to update gamedata anyway when the sig breaks which is way more likely then the offset changing. Im not sure how I feel about adding it to the cstrike extension but if it was to be added the offsets would be stored in gamedata and read into the variables on load.

Kailo 08-21-2017 20:24

Re: Getting ammo type (particularly grenades)
 
@Dr!fter, Probably less 4. According to github commits: 29 Dec 2014, 30 Jan 2015.
Don't know if will more because i changed system 4 Apr 2015 to auto getting prop from grenade entities.

Michauux 08-22-2017 10:11

Re: Getting ammo type (particularly grenades)
 
L 08/22/2017 - 16:05:34: [SM] Error parsing gameconfig file "/home/csgo/27015/serverfiles/csgo/addons/sourcemod/gamedata/sm-cstrike.games/game.csgo.txt":
L 08/22/2017 - 16:05:34: [SM] Error 11 on line 12, col 9: A property was declared outside of a section

Michauux 08-22-2017 10:19

Re: Getting ammo type (particularly grenades)
 
Kailo, who exactly edited the file and tossed these two lines of your gamedata?

Kailo 08-22-2017 10:36

Re: Getting ammo type (particularly grenades)
 
Michauux, what are you speaking about?
I didn't do anything other than this thread.

Michauux 08-22-2017 10:38

Re: Getting ammo type (particularly grenades)
 
Put those files that are needed to the gamedata


All times are GMT -4. The time now is 13:03.

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