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

Virtual Offsets


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 05-27-2009 , 21:36   Virtual Offsets
Reply With Quote #1

Since the spy/sniper update to TF2 I have been made aware of Offsets, since they are something new to me I thought I would have a go at finding some myself and using them. A quick search of the forums for an old plugin with few offets gave me this from MikeJS:
PHP Code:
#pragma semicolon 1 
#include <sourcemod> 
#include <sdktools> 
#include <tf2_stocks> 
new Handle:gameConf
new 
Handle:giveNamedItem
new 
Handle:weaponEquip
new 
Handle:g_hEnabled INVALID_HANDLE
new 
bool:g_bEnabled true
public 
OnPluginStart() { 
    
gameConf LoadGameConfigFile("sandman.games"); 
    
StartPrepSDKCall(SDKCall_Player); 
    
PrepSDKCall_SetFromConf(gameConfSDKConf_Virtual"GiveNamedItem"); 
    
PrepSDKCall_AddParameter(SDKType_StringSDKPass_Pointer); 
    
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain); 
    
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain); 
    
PrepSDKCall_SetReturnInfo(SDKType_CBaseEntitySDKPass_Plain); 
    
giveNamedItem EndPrepSDKCall(); 
    
StartPrepSDKCall(SDKCall_Player); 
    
PrepSDKCall_SetFromConf(gameConfSDKConf_Virtual"WeaponEquip"); 
    
PrepSDKCall_AddParameter(SDKType_CBaseEntitySDKPass_Pointer); 
    
weaponEquip EndPrepSDKCall(); 
    
g_hEnabled CreateConVar("sm_nosandman""1""Enable no sandman"FCVAR_PLUGIN|FCVAR_NOTIFY); 
    
HookConVarChange(g_hEnabledCvar_enabled); 

public 
OnMapStart() { 
    
CreateTimer(5.0WpnCheck); 

public 
OnConfigsExecuted() { 
    
g_bEnabled GetConVarBool(g_hEnabled); 

public 
Cvar_enabled(Handle:convar, const String:oldValue[], const String:newValue[]) { 
    
g_bEnabled GetConVarBool(g_hEnabled); 
    if(
g_bEnabled) { 
        
WpnCheck(INVALID_HANDLE); 
    } 

public 
Action:WpnCheck(Handle:timer) { 
    new 
ent
    
decl String:wpn[64]; 
    for(new 
i=1;i<=MaxClients;i++) { 
        if(
IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i)) { 
            if((
ent GetPlayerWeaponSlot(i2))!=-1) { 
                
GetEdictClassname(entwpnsizeof(wpn)); 
                if(
StrEqual(wpn"tf_weapon_bat_wood")) { 
                    
TF2_RemoveWeaponSlot(i2); 
                    new 
entity SDKCall(giveNamedItemi"tf_weapon_bat"00); 
                    
SDKCall(weaponEquipientity); 
                    
PrintToChat(i"Your sandman has been removed."); 
                } 
            } 
        } 
    } 
    if(
g_bEnabled) { 
        
CreateTimer(5.0WpnCheck); 
    } 

It only has 2 offsets (GiveNamedItem and WeaponEquip) so I thought I would have a go at finding the new ones. I followed the steps exactly from http://wiki.alliedmods.net/Finding_Virtual_Offsets and I managed to get a file (attached as dump2.txt). I used this to edit sandman.games.txt to the new Windows offset and then I added 1 for each Linux offset (attached).

Obviously, since I am writing this post, it does not work. I suspect my offsets to be wrong but I dont know where I went wrong, did I do something wrong in IDA Dissembler or are my Linux offsets wrong (if so, how do I find the correct ones)? Any information on how to find the correct offsets would be greatly appreciated.


Note: In the offsets WeaponEquip is called Weapon_Equip, however it seems that it was called Weapon_Equip back when MikeJS wrote this plugin, which is the correct name?


EDIT: I should of said, I am testing on a remote linux server.
Attached Files
File Type: txt dump2.txt (14.7 KB, 267 views)
File Type: txt sandman.games.txt (201 Bytes, 101 views)

Last edited by Wazz; 05-28-2009 at 07:34.
Wazz is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 05-28-2009 , 07:33   Re: Virtual Offsets
Reply With Quote #2

Ok, so I tested on a local windows server and I am getting errors to do with bad index of edict. Does that mean even the windows offsets are wrong?
Wazz is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-28-2009 , 07:38   Re: Virtual Offsets
Reply With Quote #3

Sometimes the windows offset wont be perfect, it actually gets the linux offsets, and assumes the windows offsets are 1 less (which sometimes they arent, but in most cases they are)

In the case of givenameditem, the offsets for windows have never been correct in the print out, and we generally have to try + or - 5 or so from it until it works.

Bad index of edict sounds like your trying to use it on an edict that does not exist. I wrote that article on how to find them a long time ago, so I should probably update it with some warnings about windows offsets.
__________________
CrimsonGT is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 05-28-2009 , 08:09   Re: Virtual Offsets
Reply With Quote #4

Alright cheers, I'll have a play later on and post back here with how I get on.
Wazz is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 05-28-2009 , 09:51   Re: Virtual Offsets
Reply With Quote #5

GetPlayerWeaponSlot(client, slot); is causing the crash, any ideas why?

EDIT: Confusing sentence removed.

Last edited by Wazz; 05-28-2009 at 10:05.
Wazz is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-28-2009 , 09:56   Re: Virtual Offsets
Reply With Quote #6

I dont understand anything you just said, copy paste the code.
__________________
CrimsonGT is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 05-28-2009 , 10:07   Re: Virtual Offsets
Reply With Quote #7

Yea, thats what I get for rushing a post. This is what I am using at the moment.
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <tf2_stocks>
new Handle:gameConf;
new 
Handle:giveNamedItem;
new 
Handle:weaponEquip;
new 
Handle:g_hEnabled INVALID_HANDLE;
new 
bool:g_bEnabled true;
public 
OnPluginStart() {
    
gameConf LoadGameConfigFile("sandman.games");
    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetFromConf(gameConfSDKConf_Virtual"GiveNamedItem");
    
PrepSDKCall_AddParameter(SDKType_StringSDKPass_Pointer);
    
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain);
    
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain);
    
PrepSDKCall_SetReturnInfo(SDKType_CBaseEntitySDKPass_Plain);
    
giveNamedItem EndPrepSDKCall();
    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetFromConf(gameConfSDKConf_Virtual"Weapon_Equip");
    
PrepSDKCall_AddParameter(SDKType_CBaseEntitySDKPass_Pointer);
    
weaponEquip EndPrepSDKCall();
    
g_hEnabled CreateConVar("sm_nosandman""1""Enable no sandman"FCVAR_PLUGIN|FCVAR_NOTIFY);
    
HookConVarChange(g_hEnabledCvar_enabled);
    
}

public 
OnMapStart() {
    
CreateTimer(5.0WpnCheck);
}

public 
OnConfigsExecuted() {
    
g_bEnabled GetConVarBool(g_hEnabled);
}

public 
Cvar_enabled(Handle:convar, const String:oldValue[], const String:newValue[]) {
    
g_bEnabled GetConVarBool(g_hEnabled);
    if(
g_bEnabled) {
        
WpnCheck(INVALID_HANDLE);
    }
}

public 
Action:WpnCheck(Handle:timer) {
    new 
ent;
    
decl String:wpn[64];
    for(new 
i=1i<=MaxClientsi++) {
        if(
IsClientInGame(i) && IsPlayerAlive(i)) {
            
ent GetPlayerWeaponSlot(i2);  /// ent = entity index
                
PrintToChat(i"Ent: %i"ent);
/*
            if(ent != -1) {
                GetEdictClassname(ent, wpn, sizeof(wpn));
                PrintToChat(i, "Classname: %s", wpn);
                if(StrEqual(wpn, "tf_weapon_bat_wood")) {
                    // TF2_RemoveWeaponSlot(i, 2);
                    // new entity = SDKCall(giveNamedItem, i, "tf_weapon_bat", 0, 0);
                    // SDKCall(weaponEquip, i, entity);
                        PrintToChat(i, "Your sandman has been removed.");
                }
            }*/
        
}
    }
    
    if(
g_bEnabled) {
        
CreateTimer(5.0WpnCheck);
    }

As you see I commented out the if statement.
In that state the server crashes. If you were to comment out the line with GetPlayerWeaponSlot, the server does not crash. 'i' is a valid client index so I am guessing it is the second parameter thats wrong but I do not know why.

Last edited by Wazz; 05-28-2009 at 10:11.
Wazz is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-28-2009 , 10:29   Re: Virtual Offsets
Reply With Quote #8

That doesnt sound like a code problem, try updating your SM to the latest 1.3 snapshot. Your offsets for GetWeaponSlot are out of date.
__________________
CrimsonGT is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 05-28-2009 , 10:38   Re: Virtual Offsets
Reply With Quote #9

Many thanks, thats looking alot more hopeful. Just a pity I spent ages last night going through possible offset values for GivePlayerItem and WeaponEquip when it wasnt those offsets causing the crash
Wazz is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 05-28-2009 , 14:42   Re: Virtual Offsets
Reply With Quote #10

Working well, thanks a lot for your time CrimsonGT.
Wazz 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 22:28.


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