Junior Member
|
03-13-2017
, 04:33
[DHooks] Vtable offset
|
#1
|
i trying to update plugin which changes clip size and ReserveMax.
Plugin (CS:GO)
Code:
#include <icpack/load>
#include <dhooks>
public Plugin:myinfo = {name = "[InkCore] AmmoManager CSGO", author = "inklesspen", version = "1.4"}
// #define _DEBUG
new Handle:dGetMaxClip1 = INVALID_HANDLE
new Handle:dGetReserveAmmoMax = INVALID_HANDLE
new Handle:pEntityFirstAmmoFinished = INVALID_HANDLE
new iAmmoMax[2][2049]
public OnPluginStart()
{
dGetMaxClip1 = DHookCreate(CSGOCheckLinux ? 353 : 347, HookType_Entity, ReturnType_Int, ThisPointer_CBaseEntity, DHOnGetMaxClip1);
dGetReserveAmmoMax = DHookCreate(CSGOCheckLinux ? 357 : 351, HookType_Entity, ReturnType_Int, ThisPointer_CBaseEntity, DHOnGetReserveAmmoMax);
pEntityFirstAmmoFinished = CreateGlobalForward("ICAM_EntityFirstAmmoFinished", ET_Ignore, Param_Cell)
RegConsoleCmd("sm_getclassindex", GCI)
}
public Action GCI(client,args)
{
decl String:arg[32]
new weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon")
GetEntityClassname(weapon, arg, 32)
PrintToChat(client, "%i %s", GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex"), arg)
}
public SpawnWeapon(entity)
{
SDKUnhook(entity, SDKHook_SpawnPost, SpawnWeapon)
decl String:classname2[64]
GetEntityClassname(entity, classname2, 64)
// #if defined _DEBUG
// PrintToChatAll("FoundEntity: %s %i", classname2, entity)
// #endif
if(strncmp(classname2, "weapon_", 7)==0)
{
new Handle:kv = CreateKeyValues("classnames")
FileToKeyValues(kv, "addons/sourcemod/configs/ic_ammomanager/classnames.ini")
KvRewind(kv)
decl String:index2[8]
FormatEx(index2, 8, "%i", GetEntProp(entity, Prop_Send, "m_iItemDefinitionIndex"))
if(KvJumpToKey(kv, index2, false))
{
KvGetString(kv, "name", classname2, 64, classname2)
}
CloseHandle(kv)
kv = CreateKeyValues("weapons")
FileToKeyValues(kv, "addons/sourcemod/configs/ic_ammomanager/ignore.ini")
KvRewind(kv)
if(KvJumpToKey(kv, classname2, false))
{
if(bool:KvGetNum(kv, "disable", 0))
{
CloseHandle(kv)
return;
}
}
CloseHandle(kv)
kv = CreateKeyValues("weapons")
FileToKeyValues(kv, "addons/sourcemod/configs/ic_ammomanager/originalammo.ini")
KvRewind(kv)
if(KvJumpToKey(kv, classname2, false))
{
iAmmoMax[0][entity]=KvGetNum(kv, "clip", 0)
iAmmoMax[1][entity]=KvGetNum(kv, "reserve", 0)
Forward_FinishSetAmmoFirst(entity)
DHookEntity(dGetMaxClip1, false, entity)
DHookEntity(dGetReserveAmmoMax, false, entity)
}
else
{
LogError("%s not found", classname2)
}
CloseHandle(kv)
#if defined _DEBUG
PrintToChatAll("Found: %s %i", classname2, entity)
#endif
}
}
public OnEntityCreated(entity, const String:classname[])
{
if(entity<1||entity>2048)
return;
// SDKUnhook(entity, SDKHook_SpawnPost, SpawnWeapon)
SDKHook(entity, SDKHook_SpawnPost, SpawnWeapon)
}
public APLRes AskPluginLoad2(Handle pMyself, bool sLate, char[] sError, int iErrorMax)
{
CreateNative("ICAM_SetWeaponClipSize", ICAM_SetWeaponClipSize_Native)
CreateNative("ICAM_SetWeaponReserveSize", ICAM_SetWeaponReserveSize_Native)
CreateNative("ICAM_GetWeaponClipSize", ICAM_GetWeaponClipSize_Native)
CreateNative("ICAM_GetWeaponReserveSize", ICAM_GetWeaponReserveSize_Native)
return APLRes_Success;
}
public int ICAM_SetWeaponReserveSize_Native(Handle:plugin, num)
{
new weapon = GetNativeCell(1)
if(!YesEntityMe(weapon))
{
ThrowNativeError(0, "Weapon#%i is not valid", weapon)
return 0
}
iAmmoMax[1][weapon]=GetNativeCell(2)
return 0
}
public int ICAM_GetWeaponReserveSize_Native(Handle:plugin, num)
{
new weapon = GetNativeCell(1)
if(!YesEntityMe(weapon))
{
ThrowNativeError(0, "Weapon#%i is not valid", weapon)
return 0
}
return iAmmoMax[1][weapon]
}
public int ICAM_SetWeaponClipSize_Native(Handle:plugin, num)
{
new weapon = GetNativeCell(1)
if(!YesEntityMe(weapon))
{
ThrowNativeError(0, "Weapon#%i is not valid", weapon)
return 0
}
iAmmoMax[0][weapon] = GetNativeCell(2)
return 0
}
public int ICAM_GetWeaponClipSize_Native(Handle:plugin, num)
{
new weapon = GetNativeCell(1)
if(!YesEntityMe(weapon))
{
ThrowNativeError(0, "Weapon#%i is not valid", weapon)
return 0
}
return iAmmoMax[0][weapon]
}
public MRESReturn:DHOnGetMaxClip1(entity, Handle:hReturn)
{
// #if defined _DEBUG
// PrintToChatAll("HookMaxClip1: %i", entity)
// #endif
if(!YesEntityMe(entity))
return MRES_Ignored;
if(iAmmoMax[0][entity]==0)
{
return MRES_Ignored
}
else
{
DHookSetReturn(hReturn, iAmmoMax[0][entity])
return MRES_Override
}
}
public MRESReturn:DHOnGetReserveAmmoMax(entity, Handle:hReturn)
{
if(!YesEntityMe(entity))
return MRES_Ignored;
if(iAmmoMax[1][entity]==0)
{
return MRES_Ignored
}
else
{
DHookSetReturn(hReturn, iAmmoMax[1][entity])
return MRES_Override
}
}
Forward_FinishSetAmmoFirst(int entity)
{
Call_StartForward(pEntityFirstAmmoFinished)
Call_PushCell(entity)
Call_Finish()
}
bool CSGOCheckLinux()
{
StartPrepSDKCall(SDKCall_Player);
PrepSDKCall_SetSignature(SDKLibrary_Server, "@_ZNK9CCSPlayer17GetActiveCSWeaponEv", 32);
PrepSDKCall_SetReturnInfo(SDKType_CBaseEntity, SDKPass_Pointer);
if(EndPrepSDKCall()!=INVALID_HANDLE)
return false
return true
}
In IDA i open server_i486.so, find GetMaxClip1 void -> double click -> ctrl+x -> first entry -> Dump CBaseCombatWeapon using linux_vtable_dump.idc got 248 offset = wont work
For testing
Code:
public OnEntityCreated(entity, const String:classname[])
{
if(entity<1||entity>2048)
return;
// SDKUnhook(entity, SDKHook_SpawnPost, SpawnWeapon)
SDKHook(entity, SDKHook_SpawnPost, SpawnWeapon)
}
public SpawnWeapon(entity)
{
SDKUnhook(entity, SDKHook_SpawnPost, SpawnWeapon)
decl String:classname2[64]
GetEntityClassname(entity, classname2, 64)
// #if defined _DEBUG
PrintToChatAll("FoundEntity: %s %i", classname2, entity)
// #endif
if(strncmp(classname2, "weapon_", 7)==0)
{
if (StrEqual("weapon_deagle", classname2, false))
{
PrintToChatAll("Foo")
DHookEntity(dGetMaxClip1, false, entity);
//DHookEntity(dGetReserveAmmoMax, false, entity)
}
}
}
public MRESReturn:DHOnGetMaxClip1(entity, Handle:hReturn)
{
PrintToChatAll("bar");
DHookSetReturn(hReturn, 1)
return MRES_Override
}
Please tell how to properly get offset
|
|