Raised This Month: $32 Target: $400
 8% 

Getting ammo type (particularly grenades)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 08-21-2017 , 17:32   Getting ammo type (particularly grenades)
Reply With Quote #1

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"
			}
		}
	}
}

Last edited by Kailo; 08-21-2017 at 18:17.
Kailo is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 08-21-2017 , 18:00   Re: Getting ammo type (particularly grenades)
Reply With Quote #2

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

Last edited by Dr!fter; 08-21-2017 at 18:01.
Dr!fter is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 08-21-2017 , 18:26   Re: Getting ammo type (particularly grenades)
Reply With Quote #3

@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.

Last edited by Kailo; 08-21-2017 at 18:27.
Kailo is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 08-21-2017 , 18:39   Re: Getting ammo type (particularly grenades)
Reply With Quote #4

Thanks, it will be usefull!
__________________


Max-Play.pl - the best polish servers
CamerDisco is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 08-21-2017 , 19:58   Re: Getting ammo type (particularly grenades)
Reply With Quote #5

Quote:
Originally Posted by Kailo View Post
@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.
Dr!fter is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 08-21-2017 , 20:24   Re: Getting ammo type (particularly grenades)
Reply With Quote #6

@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.

Last edited by Kailo; 08-21-2017 at 20:44.
Kailo is offline
Michauux
Member
Join Date: Nov 2015
Old 08-22-2017 , 10:11   Re: Getting ammo type (particularly grenades)
Reply With Quote #7

L 08/22/2017 - 16:054: [SM] Error parsing gameconfig file "/home/csgo/27015/serverfiles/csgo/addons/sourcemod/gamedata/sm-cstrike.games/game.csgo.txt":
L 08/22/2017 - 16:054: [SM] Error 11 on line 12, col 9: A property was declared outside of a section
Michauux is offline
Michauux
Member
Join Date: Nov 2015
Old 08-22-2017 , 10:19   Re: Getting ammo type (particularly grenades)
Reply With Quote #8

Kailo, who exactly edited the file and tossed these two lines of your gamedata?
Michauux is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 08-22-2017 , 10:36   Re: Getting ammo type (particularly grenades)
Reply With Quote #9

Michauux, what are you speaking about?
I didn't do anything other than this thread.
Kailo is offline
Michauux
Member
Join Date: Nov 2015
Old 08-22-2017 , 10:38   Re: Getting ammo type (particularly grenades)
Reply With Quote #10

Put those files that are needed to the gamedata
Michauux 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 13:03.


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