Address review
This commit is contained in:
parent
7798532ad0
commit
c9d5306553
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
Game::dvar_t* Bots::TestClientsActivate;
|
||||
std::vector<std::string> Bots::BotNames;
|
||||
|
||||
struct BotMovementInfo
|
||||
@ -11,6 +10,7 @@ namespace Components
|
||||
int8_t forward;
|
||||
int8_t right;
|
||||
uint16_t weapon;
|
||||
bool active;
|
||||
};
|
||||
|
||||
static BotMovementInfo g_botai[18];
|
||||
@ -36,7 +36,8 @@ namespace Components
|
||||
{ "leanright", Game::usercmdButtonBits::CMD_BUTTON_LEAN_RIGHT },
|
||||
{ "ads", Game::usercmdButtonBits::CMD_BUTTON_ADS },
|
||||
{ "holdbreath", Game::usercmdButtonBits::CMD_BUTTON_BREATH },
|
||||
{ "use", Game::usercmdButtonBits::CMD_BUTTON_USE_RELOAD | Game::usercmdButtonBits::CMD_BUTTON_ACTIVATE },
|
||||
{ "usereload", Game::usercmdButtonBits::CMD_BUTTON_USE_RELOAD },
|
||||
{ "activate", Game::usercmdButtonBits::CMD_BUTTON_ACTIVATE },
|
||||
{ "0", Bots::NUM_0 },
|
||||
{ "1", Bots::NUM_1 },
|
||||
{ "2", Bots::NUM_2 },
|
||||
@ -51,7 +52,7 @@ namespace Components
|
||||
|
||||
int Bots::BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port)
|
||||
{
|
||||
static auto botId = 0;
|
||||
static size_t botId = 0;
|
||||
const char* botName;
|
||||
|
||||
if (Bots::BotNames.empty())
|
||||
@ -156,6 +157,7 @@ namespace Components
|
||||
|
||||
g_botai[entref.entnum] = {0};
|
||||
g_botai[entref.entnum].weapon = 1;
|
||||
g_botai[entref.entnum].active = false;
|
||||
});
|
||||
|
||||
Script::AddFunction("BotWeapon", [](Game::scr_entref_t entref) // Usage: <bot> BotWeapon(<str>);
|
||||
@ -179,6 +181,7 @@ namespace Components
|
||||
|
||||
const auto weapId = Game::G_GetWeaponIndexForName(weapon);
|
||||
g_botai[entref.entnum].weapon = static_cast<uint16_t>(weapId);
|
||||
g_botai[entref.entnum].active = true;
|
||||
});
|
||||
|
||||
Script::AddFunction("BotAction", [](Game::scr_entref_t entref) // Usage: <bot> BotAction(<str action>);
|
||||
@ -216,6 +219,7 @@ namespace Components
|
||||
else
|
||||
g_botai[entref.entnum].buttons &= ~(BotActions[i].key);
|
||||
|
||||
g_botai[entref.entnum].active = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -241,6 +245,7 @@ namespace Components
|
||||
|
||||
g_botai[entref.entnum].forward = static_cast<int8_t>(forwardInt);
|
||||
g_botai[entref.entnum].right = static_cast<int8_t>(rightInt);
|
||||
g_botai[entref.entnum].active = true;
|
||||
});
|
||||
}
|
||||
|
||||
@ -251,16 +256,23 @@ namespace Components
|
||||
|
||||
const auto entnum = cl->gentity->s.number;
|
||||
|
||||
Game::usercmd_s ucmd = {0};
|
||||
// Keep test client functionality
|
||||
if (!g_botai[entnum].active)
|
||||
{
|
||||
Game::SV_BotUserMove(cl);
|
||||
return;
|
||||
}
|
||||
|
||||
ucmd.serverTime = *Game::svs_time;
|
||||
Game::usercmd_s userCmd = {0};
|
||||
|
||||
ucmd.buttons = g_botai[entnum].buttons;
|
||||
ucmd.forwardmove = g_botai[entnum].forward;
|
||||
ucmd.rightmove = g_botai[entnum].right;
|
||||
ucmd.weapon = g_botai[entnum].weapon;
|
||||
userCmd.serverTime = *Game::svs_time;
|
||||
|
||||
Game::SV_ClientThink(cl, &ucmd);
|
||||
userCmd.buttons = g_botai[entnum].buttons;
|
||||
userCmd.forwardmove = g_botai[entnum].forward;
|
||||
userCmd.rightmove = g_botai[entnum].right;
|
||||
userCmd.weapon = g_botai[entnum].weapon;
|
||||
|
||||
Game::SV_ClientThink(cl, &userCmd);
|
||||
}
|
||||
|
||||
constexpr auto SV_BotUserMove = 0x626E50;
|
||||
@ -268,13 +280,6 @@ namespace Components
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push eax
|
||||
mov eax, Bots::TestClientsActivate
|
||||
cmp byte ptr [eax + 0x10], 0x1
|
||||
pop eax
|
||||
|
||||
jz enableBots
|
||||
|
||||
pushad
|
||||
|
||||
push edi
|
||||
@ -282,20 +287,42 @@ namespace Components
|
||||
add esp, 4
|
||||
|
||||
popad
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
enableBots:
|
||||
call SV_BotUserMove
|
||||
ret
|
||||
void Bots::G_SelectWeaponIndex(int clientNum, int iWeaponIndex)
|
||||
{
|
||||
if (g_botai[clientNum].active)
|
||||
{
|
||||
g_botai[clientNum].weapon = static_cast<uint16_t>(iWeaponIndex);
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(naked) void Bots::G_SelectWeaponIndex_Hk()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
pushad
|
||||
|
||||
push [esp + 0x20 + 0x8]
|
||||
push [esp + 0x20 + 0x8]
|
||||
call Bots::G_SelectWeaponIndex
|
||||
add esp, 0x8
|
||||
|
||||
popad
|
||||
|
||||
// Code skipped by hook
|
||||
mov eax, [esp + 0x8]
|
||||
push eax
|
||||
|
||||
push 0x441B85
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
Bots::Bots()
|
||||
{
|
||||
Bots::TestClientsActivate = Game::Dvar_RegisterBool("testClients_activate", true,
|
||||
Game::dvar_flag::DVAR_FLAG_NONE, "Testclients will retain their native functionality.");
|
||||
|
||||
// Replace connect string
|
||||
Utils::Hook::Set<const char*>(0x48ADA6, "connect bot%d \"\\cg_predictItems\\1\\cl_anonymous\\0\\color\\4\\head\\default\\model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\protocol\\%d\\checksum\\%d\\statver\\%d %u\\qport\\%d\"");
|
||||
|
||||
@ -305,6 +332,8 @@ namespace Components
|
||||
Utils::Hook(0x627021, Bots::SV_BotUserMove_Hk, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x627241, Bots::SV_BotUserMove_Hk, HOOK_CALL).install()->quick();
|
||||
|
||||
Utils::Hook(0x441B80, Bots::G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick();
|
||||
|
||||
// Zero the bot command array
|
||||
for (auto i = 0u; i < std::extent_v<decltype(g_botai)>; i++)
|
||||
{
|
||||
|
@ -22,7 +22,6 @@ namespace Components
|
||||
};
|
||||
|
||||
private:
|
||||
static Game::dvar_t* TestClientsActivate;
|
||||
static std::vector<std::string> BotNames;
|
||||
|
||||
static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port);
|
||||
@ -33,5 +32,8 @@ namespace Components
|
||||
|
||||
static void BotAiAction(Game::client_t* cl);
|
||||
static void SV_BotUserMove_Hk();
|
||||
|
||||
static void G_SelectWeaponIndex(int clientNum, int iWeaponIndex);
|
||||
static void G_SelectWeaponIndex_Hk();
|
||||
};
|
||||
}
|
||||
|
@ -385,7 +385,6 @@ namespace Components
|
||||
Utils::Hook(0x59386A, Dvar::DvarSetFromStringByNameStub, HOOK_CALL).install()->quick();
|
||||
|
||||
// If the game closed abruptly, the dvars would not have been restored
|
||||
|
||||
Dvar::OnInit([]
|
||||
{
|
||||
Dvar::ResetDvarsValue();
|
||||
|
@ -7,7 +7,6 @@ namespace Components
|
||||
void ScriptExtension::AddFunctions()
|
||||
{
|
||||
//File functions
|
||||
|
||||
Script::AddFunction("FileWrite", [](Game::scr_entref_t) // gsc: FileWrite(<filepath>, <string>, <mode>)
|
||||
{
|
||||
const auto* path = Game::Scr_GetString(0);
|
||||
@ -115,7 +114,7 @@ namespace Components
|
||||
{
|
||||
if (std::strstr(path, ScriptExtension::QueryStrings[i]) != nullptr)
|
||||
{
|
||||
Logger::Print("^1fileRemove: directory traversal is not allowed!\n");
|
||||
Logger::Print("^1FileRemove: directory traversal is not allowed!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -152,9 +151,35 @@ namespace Components
|
||||
});
|
||||
}
|
||||
|
||||
void ScriptExtension::Scr_TableLookupIStringByRow()
|
||||
{
|
||||
if (Game::Scr_GetNumParam() < 3)
|
||||
{
|
||||
Game::Scr_Error("USAGE: tableLookupIStringByRow( filename, rowNum, returnValueColumnNum )\n");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* fileName = Game::Scr_GetString(0);
|
||||
const auto rowNum = Game::Scr_GetInt(1);
|
||||
const auto returnValueColumnNum = Game::Scr_GetInt(2);
|
||||
|
||||
const auto* table = Game::DB_FindXAssetHeader(Game::ASSET_TYPE_STRINGTABLE, fileName).stringTable;
|
||||
|
||||
if (table == nullptr)
|
||||
{
|
||||
Game::Scr_ParamError(0, Utils::String::VA("%s does not exist\n", fileName));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* value = Game::StringTable_GetColumnValueForRow(table, rowNum, returnValueColumnNum);
|
||||
Game::Scr_AddIString(value);
|
||||
}
|
||||
|
||||
ScriptExtension::ScriptExtension()
|
||||
{
|
||||
ScriptExtension::AddFunctions();
|
||||
ScriptExtension::AddMethods();
|
||||
// Correct builtin function pointer
|
||||
Utils::Hook::Set<void(*)()>(0x79A90C, ScriptExtension::Scr_TableLookupIStringByRow);
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,6 @@ namespace Components
|
||||
|
||||
static void AddFunctions();
|
||||
static void AddMethods();
|
||||
static void Scr_TableLookupIStringByRow();
|
||||
};
|
||||
}
|
||||
|
@ -271,6 +271,7 @@ namespace Game
|
||||
|
||||
Scr_AddEntity_t Scr_AddEntity = Scr_AddEntity_t(0x4BFB40);
|
||||
Scr_AddString_t Scr_AddString = Scr_AddString_t(0x412310);
|
||||
Scr_AddIString_t Scr_AddIString = Scr_AddIString_t(0x455F20);
|
||||
Scr_AddInt_t Scr_AddInt = Scr_AddInt_t(0x41D7D0);
|
||||
Scr_AddFloat_t Scr_AddFloat = Scr_AddFloat_t(0x61E860);
|
||||
Scr_AddObject_t Scr_AddObject = Scr_AddObject_t(0x430F40);
|
||||
@ -320,6 +321,7 @@ namespace Game
|
||||
Steam_JoinLobby_t Steam_JoinLobby = Steam_JoinLobby_t(0x49CF70);
|
||||
|
||||
StringTable_Lookup_t StringTable_Lookup = StringTable_Lookup_t(0x42F0E0);
|
||||
StringTable_GetColumnValueForRow_t StringTable_GetColumnValueForRow = StringTable_GetColumnValueForRow_t(0x4F2C80);
|
||||
StringTable_HashString_t StringTable_HashString = StringTable_HashString_t(0x475EB0);
|
||||
|
||||
SV_AddTestClient_t SV_AddTestClient = SV_AddTestClient_t(0x48AD30);
|
||||
@ -1591,5 +1593,20 @@ namespace Game
|
||||
}
|
||||
}
|
||||
|
||||
constexpr auto SV_BotUserMove_Addr = 0x626E50;
|
||||
__declspec(naked) void SV_BotUserMove(client_t* /*client*/)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
pushad
|
||||
|
||||
mov edi, [esp + 0x20 + 0x4]
|
||||
call SV_BotUserMove_Addr
|
||||
|
||||
popad
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#pragma optimize("", on)
|
||||
}
|
||||
|
@ -639,12 +639,15 @@ namespace Game
|
||||
typedef void(__cdecl * RemoveRefToObject_t)(unsigned int id);
|
||||
extern RemoveRefToObject_t RemoveRefToObject;
|
||||
|
||||
typedef void(__cdecl * Scr_AddEntity_t)(gentity_s const*);
|
||||
typedef void(__cdecl * Scr_AddEntity_t)(const gentity_s* ent);
|
||||
extern Scr_AddEntity_t Scr_AddEntity;
|
||||
|
||||
typedef void(__cdecl * Scr_AddString_t)(const char* str);
|
||||
typedef void(__cdecl * Scr_AddString_t)(const char* value);
|
||||
extern Scr_AddString_t Scr_AddString;
|
||||
|
||||
typedef void(__cdecl * Scr_AddIString_t)(const char* value);
|
||||
extern Scr_AddIString_t Scr_AddIString;
|
||||
|
||||
typedef void(__cdecl * Scr_AddInt_t)(int num);
|
||||
extern Scr_AddInt_t Scr_AddInt;
|
||||
|
||||
@ -759,9 +762,12 @@ namespace Game
|
||||
typedef void(__cdecl * Steam_JoinLobby_t)(SteamID, char);
|
||||
extern Steam_JoinLobby_t Steam_JoinLobby;
|
||||
|
||||
typedef const char*(__cdecl * StringTable_Lookup_t)(StringTable *table, const int comparisonColumn, const char *value, const int valueColumn);
|
||||
typedef const char*(__cdecl * StringTable_Lookup_t)(const StringTable *table, const int comparisonColumn, const char *value, const int valueColumn);
|
||||
extern StringTable_Lookup_t StringTable_Lookup;
|
||||
|
||||
typedef const char* (__cdecl * StringTable_GetColumnValueForRow_t)(const StringTable* table, int, int column);
|
||||
extern StringTable_GetColumnValueForRow_t StringTable_GetColumnValueForRow;
|
||||
|
||||
typedef int(__cdecl * StringTable_HashString_t)(const char* string);
|
||||
extern StringTable_HashString_t StringTable_HashString;
|
||||
|
||||
@ -1108,6 +1114,7 @@ namespace Game
|
||||
|
||||
void SV_KickClient(client_t* client, const char* reason);
|
||||
void SV_KickClientError(client_t* client, const std::string& reason);
|
||||
void SV_BotUserMove(client_t* client);
|
||||
|
||||
void RuntimeErrorInternal(int channel, const char* codePos, unsigned int index, const char* msg);
|
||||
void IncInParam();
|
||||
|
Loading…
Reference in New Issue
Block a user