Cstrike: Do some more cleanup

This commit is contained in:
Arkshine 2015-07-04 15:51:16 +02:00
parent f13461caee
commit 2de1f9a33b
10 changed files with 219 additions and 170 deletions

View File

@ -16,6 +16,9 @@
#include "amxxmodule.h"
/**
* Weapon Ids for use with CS_OnBuyAttempt(), CS_OnBuy().
*/
#define CSI_P228 CSW_P228
#define CSI_SCOUT CSW_SCOUT
#define CSI_HEGRENADE CSW_HEGRENADE
@ -55,7 +58,9 @@
#define BITS_PISTOLS (1<<CSI_GLOCK18 | 1<<CSI_USP | 1<<CSI_P228 | 1<<CSI_DEAGLE | 1<<CSI_ELITE | 1<<CSI_FIVESEVEN)
// Ids of weapons in CS
/**
* Weapons Ids.
*/
#define CSW_P228 1
#define CSW_SCOUT 3
#define CSW_HEGRENADE 4
@ -89,7 +94,9 @@
#define CSW_VESTHELM 32 // Brand new invention!
#define CSW_SHIELDGUN 99
// These are used with armoury_entity:s.
/**
* Armoury entity ids for use with cs_get/set_armoury_type().
*/
#define CSA_MP5NAVY 0
#define CSA_TMP 1
#define CSA_P90 2
@ -110,6 +117,9 @@
#define CSA_VESTHELM 17
#define CSA_SMOKEGRENADE 18
/**
* Weapon states of the following weapons: usp, elite, glock18, famas and m4a1.
*/
enum WeaponState
{
WPNSTATE_USP_SILENCED = (1 << 0),
@ -120,6 +130,9 @@ enum WeaponState
WPNSTATE_SHIELD_DRAWN = (1 << 5),
};
/**
* M4A1 animations
*/
enum m4a1_e
{
M4A1_IDLE,
@ -138,6 +151,9 @@ enum m4a1_e
M4A1_DETACH_SILENCER
};
/**
* USP animations
*/
enum usp_e
{
USP_IDLE,
@ -158,6 +174,9 @@ enum usp_e
USP_DETACH_SILENCER
};
/**
* States of gameplay zones.
*/
enum SignalState
{
SIGNAL_BUY = (1 << 0),
@ -167,48 +186,48 @@ enum SignalState
SIGNAL_VIPSAFETY = (1 << 4),
};
/**
* Default team indexes.
*/
#define TEAM_UNASSIGNED 0
#define TEAM_T 1
#define TEAM_CT 2
#define TEAM_SPECTATOR 3
/**
* Default color of defuser HUD icon.
*/
#define DEFUSER_COLOUR_R 0
#define DEFUSER_COLOUR_G 160
#define DEFUSER_COLOUR_B 0
/**
* Values for use with ScoreAttrib message.
*/
#define SCOREATTRIB_NOTHING 0
#define SCOREATTRIB_DEAD 1
#define SCOREATTRIB_BOMB 2 // t only
#define SCOREATTRIB_VIP 4 // ct only
#define AMD64_STATIONARY_NO 2
#define AMD64_STATIONARY_YES 3
/**
* Armor types for use with cs_get/Set_user_armor().
*/
#define CS_ARMOR_NONE 0
#define CS_ARMOR_KEVLAR 1
#define CS_ARMOR_ASSAULTSUIT 2
/**
* Default FOV values.
*/
#define CS_FIRST_ZOOM 40
#define CS_SECOND_AWP_ZOOM 10
#define CS_SECOND_NONAWP_ZOOM 15
#define CS_AUGSG552_ZOOM 55
#define CS_NO_ZOOM 90
enum CS_Internal_Models {
CS_DONTCHANGE = 0,
CS_CT_URBAN = 1,
CS_T_TERROR = 2,
CS_T_LEET = 3,
CS_T_ARCTIC = 4,
CS_CT_GSG9 = 5,
CS_CT_GIGN = 6,
CS_CT_SAS = 7,
CS_T_GUERILLA = 8,
CS_CT_VIP = 9,
CZ_T_MILITIA = 10,
CZ_CT_SPETSNAZ = 11
};
/**
* Zoom value for use with cs_get/set_user_zoom().
*/
enum
{
CS_RESET_ZOOM = 0,
@ -216,8 +235,31 @@ enum
CS_SET_FIRST_ZOOM,
CS_SET_SECOND_ZOOM,
CS_SET_AUGSG552_ZOOM,
};
/**
* Player's model types.
*/
enum CS_Internal_Models
{
CS_DONTCHANGE = 0,
CS_CT_URBAN = 1,
CS_T_TERROR = 2,
CS_T_LEET = 3,
CS_T_ARCTIC = 4,
CS_CT_GSG9 = 5,
CS_CT_GIGN = 6,
CS_CT_SAS = 7,
CS_T_GUERILLA = 8,
CS_CT_VIP = 9,
CZ_T_MILITIA = 10,
CZ_CT_SPETSNAZ = 11
};
/**
* Menu states.
*/
typedef enum
{
Menu_OFF,
@ -238,7 +280,4 @@ typedef enum
} Menu;
typedef edict_t* (*CreateNamedEntityFunc)(string_t iszClassname);
typedef void* (*UTIL_FindEntityByStringFunc)(void* pStartEntity, const char *szKeyword, const char *szValue);
#endif // CSTRIKE_DATA_H

View File

@ -17,16 +17,16 @@ HL_TypeConversion G_HL_TypeConversion;
void OffsetHandler::search_pev()
{
edict_t* edict = INDEXENT(0);
entvars_t* entvars = &edict->v;
edict_t *pEdict = INDEXENT(0);
entvars_t *pev = VARS(pEdict);
byte* private_c = (byte*)edict->pvPrivateData;
byte *privateData = reinterpret_cast<byte*>(pEdict->pvPrivateData);
for (int i = 0; i < 0xFFF; i++)
{
uintptr_t val = *((uintptr_t*)(private_c + i));
entvars_t *val = *(reinterpret_cast<entvars_t**>(privateData + i));
if (val == (uintptr_t)entvars)
if (val == pev)
{
this->pev = i;
return;
@ -82,7 +82,8 @@ void* HL_TypeConversion::id_to_cbase(int index)
entvars_t* HL_TypeConversion::id_to_entvar(int index)
{
return &(INDEXENT2(index)->v);
edict_t *pEdict = INDEXENT2(index);
return pEdict ? VARS(pEdict) : nullptr;
}
entvars_t* HL_TypeConversion::cbase_to_entvar(void* cbase)
@ -92,7 +93,7 @@ entvars_t* HL_TypeConversion::cbase_to_entvar(void* cbase)
return nullptr;
}
return *(entvars_t **)((char *)(cbase) + G_OffsetHandler->pev);
return *reinterpret_cast<entvars_t**>(reinterpret_cast<int8*>(cbase) + G_OffsetHandler->pev);
}
int HL_TypeConversion::cbase_to_id(void *cbase)
@ -102,7 +103,7 @@ int HL_TypeConversion::cbase_to_id(void *cbase)
return -1;
}
entvars_t* pev = this->cbase_to_entvar(cbase);
entvars_t *pev = this->cbase_to_entvar(cbase);
if (!pev)
{

View File

@ -13,45 +13,47 @@
#include "CstrikeDatas.h"
#include "CstrikeUtils.h"
#include "CDetour/detours.h"
#include "CstrikeHacks.h"
#include <sm_stringhashmap.h>
#include "CstrikeHLTypeConversion.h"
void CtrlDetours_ClientCommand(bool set);
void CtrlDetours_BuyCommands(bool set);
void CtrlDetours_Natives(bool set);
int ForwardInternalCommand = -1;
int ForwardOnBuy = -1;
int ForwardOnBuyAttempt = -1;
int ForwardOnBuy = -1;
int ForwardOnBuyAttempt = -1;
int *UseBotArgs = NULL;
const char **BotArgs = NULL;
int *UseBotArgs;
const char **BotArgs;
CDetour *ClientCommandDetour = NULL;
CDetour *GiveShieldDetour = NULL;
CDetour *GiveNamedItemDetour = NULL;
CDetour *AddAccountDetour = NULL;
CDetour *ClientCommandDetour;
CDetour *GiveShieldDetour;
CDetour *GiveNamedItemDetour;
CDetour *AddAccountDetour;
CDetour *GiveDefaultItemsDetour;
int CurrentItemId = 0;
CreateNamedEntityFunc CS_CreateNamedEntity;
UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString;
int CurrentItemId;
StringHashMap<int> ItemAliasList;
int TeamOffset = 0;
int MenuOffset = 0;
extern enginefuncs_t *g_pengfuncsTable;
int TeamOffset;
int MenuOffset;
void InitializeHacks()
{
#if defined AMD64
#error UNSUPPORTED
#endif
CtrlDetours_ClientCommand(true);
CtrlDetours_BuyCommands(true);
CtrlDetours_Natives(true);
}
void ShutdownHacks()
{
CtrlDetours_ClientCommand(false);
CtrlDetours_BuyCommands(false);
CtrlDetours_Natives(false);
}
#undef CMD_ARGV
@ -65,7 +67,7 @@ const char *CMD_ARGV(int i)
return BotArgs[i];
}
return NULL;
return nullptr;
}
return g_engfuncs.pfnCmd_Argv(i);
@ -76,7 +78,7 @@ void OnEmitSound(edict_t *entity, int channel, const char *sample, float volume,
// If shield is blocked with CS_OnBuy, we need to block the pickup sound ("items/gunpickup2.wav")
// as well played right after. Why this sound is not contained in GiveShield()?
g_pengfuncsTable->pfnEmitSound = NULL;
g_pengfuncsTable->pfnEmitSound = nullptr;
RETURN_META(MRES_SUPERCEDE);
}
@ -177,7 +179,7 @@ DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlay
// If the current item id is not null, this means player has triggers a buy command.
if (CurrentItemId)
{
int client = PrivateToIndex(this);
int client = G_HL_TypeConversion.cbase_to_id(this);
if (MF_IsPlayerAlive(client) && MF_ExecuteForward(ForwardOnBuy, static_cast<cell>(client), static_cast<cell>(CurrentItemId)) > 0)
{
@ -198,7 +200,7 @@ DETOUR_DECL_MEMBER1(GiveShield, void, bool, bRetire) // void CBasePlayer::GiveSh
// Special case for shield. Game doesn't use GiveNamedItem() to give a shield.
if (CurrentItemId == CSI_SHIELDGUN)
{
int client = PrivateToIndex(this);
int client = G_HL_TypeConversion.cbase_to_id(this);
if (MF_IsPlayerAlive(client) && MF_ExecuteForward(ForwardOnBuy, static_cast<cell>(client), CSI_SHIELDGUN) > 0)
{
@ -244,12 +246,12 @@ void CtrlDetours_ClientCommand(bool set)
int offset = 0;
if (MainConfig->GetOffset("UseBotArgs", &offset) && offset)
if (MainConfig->GetOffset("UseBotArgs", &offset))
{
UseBotArgs = get_pdata<int*>(base, offset);
}
if (MainConfig->GetOffset("BotArgs", &offset) && offset)
if (MainConfig->GetOffset("BotArgs", &offset))
{
BotArgs = get_pdata<const char**>(base, offset);
}
@ -258,12 +260,12 @@ void CtrlDetours_ClientCommand(bool set)
void *address = nullptr;
if (MainConfig->GetMemSig("UseBotArgs", &address) && address)
if (MainConfig->GetMemSig("UseBotArgs", &address))
{
UseBotArgs = reinterpret_cast<int *>(address);
}
if (MainConfig->GetMemSig("BotArgs", &address) && address)
if (MainConfig->GetMemSig("BotArgs", &address))
{
BotArgs = reinterpret_cast<const char **>(address);
}
@ -336,10 +338,10 @@ void ToggleDetour_ClientCommands(bool enable)
{ "nvgs" , CSI_NVGS }, { "shield" , CSI_SHIELDGUN },
{ "buyammo1" , CSI_PRIMAMMO }, { "primammo" , CSI_PRIMAMMO },
{ "buyammo2" , CSI_SECAMMO }, { "secammo" , CSI_SECAMMO },
{ NULL , 0 }
{ nullptr , 0 }
};
for (size_t i = 0; aliasToId[i].alias != NULL; ++i)
for (size_t i = 0; aliasToId[i].alias != nullptr; ++i)
{
ItemAliasList.insert(aliasToId[i].alias, aliasToId[i].id);
}
@ -357,15 +359,21 @@ void CtrlDetours_BuyCommands(bool set)
{
void *address = nullptr;
MainConfig->GetMemSig("GiveShield", &address);
GiveShieldDetour = DETOUR_CREATE_MEMBER_FIXED(GiveShield, address); address = nullptr;
if (MainConfig->GetMemSig("GiveShield", &address))
{
GiveShieldDetour = DETOUR_CREATE_MEMBER_FIXED(GiveShield, address);
}
MainConfig->GetMemSig("GiveNamedItem", &address);
GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, address); address = nullptr;
MainConfig->GetMemSig("AddAccount", &address);
AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, address); address = nullptr;
if (MainConfig->GetMemSig("GiveNamedItem", &address))
{
GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, address);
}
if (MainConfig->GetMemSig("AddAccount", &address))
{
AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, address);
}
if (!GiveShieldDetour || !GiveNamedItemDetour || !AddAccountDetour)
{
if (!GiveShieldDetour)
@ -424,3 +432,31 @@ void ToggleDetour_BuyCommands(bool enable)
(enable) ? AddAccountDetour->EnableDetour() : AddAccountDetour->DisableDetour();
}
}
void CtrlDetours_Natives(bool set)
{
if (set)
{
void *address = nullptr;
if (MainConfig->GetMemSig("CreateNamedEntity", &address)) // cs_create_entity()
{
CS_CreateNamedEntity = reinterpret_cast<CreateNamedEntityFunc>(address);
}
if (MainConfig->GetMemSig("FindEntityByString", &address)) // cs_find_ent_by_class()
{
CS_UTIL_FindEntityByString = reinterpret_cast<UTIL_FindEntityByStringFunc>(address);
}
if (!CS_CreateNamedEntity)
{
MF_Log("CREATE_NAMED_ENITTY is not available - native cs_create_entity() has been disabled");
}
if (!CS_UTIL_FindEntityByString)
{
MF_Log("UTIL_FindEntByString is not available - native cs_find_ent_by_class() has been disabled");
}
}
}

View File

@ -0,0 +1,54 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// Counter-Strike Module
//
#ifndef CSTRIKE_HACKS_H
#define CSTRIKE_HACKS_H
#include <amxxmodule.h>
#include <IGameConfigs.h>
#include <CDetour/detours.h>
void InitializeHacks();
void ShutdownHacks();
void ToggleDetour_ClientCommands(bool enable);
void ToggleDetour_BuyCommands(bool enable);
extern int MessageIdArmorType;
extern int MessageIdMoney;
extern int MessageIdResetHUD;
extern int MessageIdScoreAttrib;
extern int MessageIdScoreInfo;
extern int MessageIdStatusIcon;
extern int MessageIdTeamInfo;
extern int MessageIdTextMsg;
extern AMX_NATIVE_INFO CstrikeNatives[];
extern IGameConfig *MainConfig;
extern IGameConfig *OffsetConfig;
extern int ForwardInternalCommand;
extern int ForwardOnBuy;
extern int ForwardOnBuyAttempt;
typedef edict_t* (*CreateNamedEntityFunc)(string_t iszClassname);
typedef void* (*UTIL_FindEntityByStringFunc)(void* pStartEntity, const char *szKeyword, const char *szValue);
extern CreateNamedEntityFunc CS_CreateNamedEntity;
extern UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString;
extern CDetour *GiveDefaultItemsDetour;
extern enginefuncs_t *g_pengfuncsTable;
extern bool NoKifesMode;
#endif // CSTRIKE_HACKS_H

View File

@ -14,23 +14,25 @@
#include "CstrikeDatas.h"
#include "CstrikePlayer.h"
#include "CstrikeUtils.h"
#include "CstrikeHacks.h"
#include "CstrikeHLTypeConversion.h"
#include <CDetour/detours.h>
CCstrikePlayer g_players[33];
int g_zooming[33] = {0};
bool g_precachedknife = false;
bool g_noknives = false;
extern CreateNamedEntityFunc CS_CreateNamedEntity;
extern UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString;
bool NoKifesMode = false;
extern int MessageIdMoney;
extern int MessageIdScoreInfo;
extern int MessageIdArmorType;
extern int MessageIdTeamInfo;
extern int MessageIdStatusIcon;
extern int MessageIdScoreAttrib;
extern int MessageIdResetHUD;
int MessageIdArmorType;
int MessageIdMoney;
int MessageIdResetHUD;
int MessageIdScoreAttrib;
int MessageIdScoreInfo;
int MessageIdStatusIcon;
int MessageIdTeamInfo;
int MessageIdTextMsg;
// native cs_set_user_money(index, money, flash = 1);
static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params)
@ -938,13 +940,13 @@ static cell AMX_NATIVE_CALL cs_get_user_hasprimary(AMX *amx, cell *params)
// native cs_get_no_knives();
static cell AMX_NATIVE_CALL cs_get_no_knives(AMX *amx, cell *params)
{
return g_noknives ? 1 : 0;
return NoKifesMode ? 1 : 0;
}
// native cs_set_no_knives(noknives = 0);
static cell AMX_NATIVE_CALL cs_set_no_knives(AMX *amx, cell *params)
{
g_noknives = params[1] != 0;
NoKifesMode = params[1] != 0;
return 1;
}

View File

@ -12,11 +12,10 @@
//
#include "amxxmodule.h"
#include "MemoryUtils.h"
extern int MessageIdTextMsg;
bool UTIL_IsPlayer(edict_t *pPlayer)
bool UTIL_IsPlayer(edict_t *pPlayer)
{
return strcmp(STRING(pPlayer->v.classname), "player") == 0;
}
@ -36,7 +35,7 @@ bool UTIL_CheckForPublic(const char *publicname)
int i = 0;
char blah[64];
strncpy(blah, publicname, sizeof(blah)- 1);
strncpy(blah, publicname, sizeof(blah) - 1);
while ((amx = MF_GetScriptAmx(i++)))
{
@ -46,6 +45,5 @@ bool UTIL_CheckForPublic(const char *publicname)
}
}
return false;
return false;
}

View File

@ -14,16 +14,9 @@
#ifndef CSTRIKE_UTILS_H
#define CSTRIKE_UTILS_H
#include <IGameConfigs.h>
bool UTIL_IsPlayer(edict_t *pPlayer);
void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message);
void *UTIL_FindAddressFromEntry(const char *entry, bool isHidden = false, const char *library = "mod");
bool UTIL_CheckForPublic(const char *publicname);
char *UTIL_StringToLower(char *str);
extern IGameConfig *MainConfig;
extern IGameConfig *OffsetConfig;
#define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
#define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue)
@ -119,39 +112,6 @@ inline void set_pdata(void *pEntity, int offset, T value, int element = 0)
*reinterpret_cast<T*>(reinterpret_cast<int8*>(pEntity) + offset + element * sizeof(T)) = value;
}
inline edict_t *PrivateToEdict(const void *pdata)
{
if (!pdata)
{
return NULL;
}
char *ptr = (char*)pdata;
ptr += 4;
entvars_t *pev = *(entvars_t **)ptr;
if (!pev)
{
return NULL;
}
return pev->pContainingEntity;
};
inline int PrivateToIndex(const void *pdata)
{
edict_t *pEntity = PrivateToEdict(pdata);
if (!pEntity)
{
return -1;
}
return ENTINDEX(pEntity);
};
class EHANDLE
{
private:

View File

@ -14,36 +14,14 @@
#include "amxxmodule.h"
#include "CstrikeUtils.h"
#include "CstrikeDatas.h"
#include "CstrikeHacks.h"
#include "CstrikeHLTypeConversion.h"
#include <IGameConfigs.h>
extern AMX_NATIVE_INFO CstrikeNatives[];
extern int ForwardInternalCommand;
extern int ForwardOnBuy;
extern int ForwardOnBuyAttempt;
void InitializeHacks();
void ShutdownHacks();
void ToggleDetour_ClientCommands(bool enable);
void ToggleDetour_BuyCommands(bool enable);
CreateNamedEntityFunc CS_CreateNamedEntity = nullptr;
UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString = nullptr;
IGameConfig *MainConfig;
IGameConfig *OffsetConfig;
IGameConfigManager *ConfigManager;
int MessageIdArmorType;
int MessageIdMoney;
int MessageIdResetHUD;
int MessageIdScoreAttrib;
int MessageIdScoreInfo;
int MessageIdStatusIcon;
int MessageIdTeamInfo;
int MessageIdTextMsg;
struct UserMsg
{
const char* name;
@ -60,10 +38,9 @@ UserMsg MessagesList[] =
{ "StatusIcon" , &MessageIdStatusIcon },
{ "TeamInfo" , &MessageIdTeamInfo },
{ "TextMsg" , &MessageIdTextMsg },
{ nullptr , 0 }
{ nullptr , nullptr }
};
int AmxxCheckGame(const char *game)
{
if (strcasecmp(game, "cstrike") == 0 ||
@ -80,7 +57,7 @@ void OnAmxxAttach()
ConfigManager = MF_GetConfigManager();
char error[256];
char error[256];
error[0] = '\0';
if (!ConfigManager->LoadGameConfigFile("modules.games", &MainConfig, error, sizeof(error)) && error[0] != '\0')
@ -97,28 +74,6 @@ void OnAmxxAttach()
return;
}
void *address = nullptr;
if (MainConfig->GetMemSig("CreateNamedEntity", &address) && address) // cs_create_entity()
{
CS_CreateNamedEntity = reinterpret_cast<CreateNamedEntityFunc>(address);
}
if (MainConfig->GetMemSig("FindEntityByString", &address) && address) // cs_find_ent_by_class()
{
CS_UTIL_FindEntityByString = reinterpret_cast<UTIL_FindEntityByStringFunc>(address);
}
if (!CS_CreateNamedEntity)
{
MF_Log("CREATE_NAMED_ENITTY is not available - native cs_create_entity() has been disabled");
}
if (!CS_UTIL_FindEntityByString)
{
MF_Log("UTIL_FindEntByString is not available - native cs_find_ent_by_class() has been disabled");
}
InitializeHacks();
}

View File

@ -158,6 +158,7 @@
<ClInclude Include="..\..\..\..\public\memtools\CDetour\detours.h" />
<ClInclude Include="..\..\..\..\public\memtools\MemoryUtils.h" />
<ClInclude Include="..\CstrikeDatas.h" />
<ClInclude Include="..\CstrikeHacks.h" />
<ClInclude Include="..\CstrikePlayer.h" />
<ClInclude Include="..\moduleconfig.h" />
<ClInclude Include="..\..\..\..\public\sdk\amxxmodule.h" />

View File

@ -88,6 +88,9 @@
<ClInclude Include="..\moduleconfig.h">
<Filter>Module SDK</Filter>
</ClInclude>
<ClInclude Include="..\CstrikeHacks.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\..\plugins\include\cstrike.inc">