Added bot methods

This commit is contained in:
ineedbots 2021-06-29 20:00:26 -06:00
parent 51dbee4712
commit a6417421dc
5 changed files with 121 additions and 26 deletions

View File

@ -1,5 +1,6 @@
#include "STDInclude.hpp"
#include "Bots.hpp"
#include "Script.hpp"
namespace Components
{
@ -9,7 +10,6 @@ namespace Components
{
{ "fire", KEY_FIRE },
{ "attack", KEY_FIRE },
{ "sprint", KEY_SPRINT },
{ "melee", KEY_MELEE },
{ "activate", KEY_USE },
{ "use", KEY_USE | KEY_USERELOAD },
@ -23,13 +23,11 @@ namespace Components
{ "ads", KEY_ADSMODE | KEY_ADS },
{ "toggleads_throw", KEY_ADSMODE },
{ "speed_throw", KEY_ADS },
{ "temp", KEY_TEMP },
{ "holdbreath", KEY_HOLDBREATH },
{ "frag", KEY_FRAG },
{ "smoke", KEY_SMOKE },
{ "unk", KEY_UNK },
{ "unk2", KEY_UNK2 },
{ "nightvision", KEY_NIGHTVISION },
{ "unk3", KEY_UNK3 },
{ "unk4", KEY_UNK4 },
{ "menu", KEY_MENU },
@ -42,7 +40,10 @@ namespace Components
{ "unk11", KEY_UNK11 },
{ "unk12", KEY_UNK12 },
{ "unk13", KEY_UNK13 },
{ "unk14", KEY_UNK14 }
{ "unk14", KEY_UNK14 },
{ "unk15", KEY_UNK15 },
{ "unk16", KEY_UNK16 },
{ "unk17", KEY_UNK17 }
};
std::vector<std::string> Bots::bot_names;
@ -155,6 +156,51 @@ namespace Components
Utils::Hook(0x51E2DC, G_SelectWeaponIndex_Stub, HOOK_CALL).install()->quick();
Utils::Hook(0x501E0D, G_SelectWeaponIndex_Stub, HOOK_CALL).install()->quick();
Utils::Hook(0x52B166, PlayerCmd_setSpawnWeapon_Stub, HOOK_JUMP).install()->quick();
Script::AddMethod("botaction", [](Game::scr_entref_t ent)
{
const char* action = Game::Scr_GetString(0);
for (size_t i = 0; i < sizeof(bot_actions) / sizeof(BotAction_t); ++i)
{
if (strcmp(&action[1], bot_actions[i].action))
{
continue;
}
if (action[0] == '+')
{
g_botai[ent].buttons |= bot_actions[i].key;
}
else
{
g_botai[ent].buttons &= ~(bot_actions[i].key);
}
return;
}
});
Script::AddMethod("botmovement", [](Game::scr_entref_t ent)
{
int forward = Game::Scr_GetInt(0);
int right = Game::Scr_GetInt(1);
forward = std::clamp(forward, -128, 127);
right = std::clamp(right, -128, 127);
g_botai[ent].forward = static_cast<char>(forward);
g_botai[ent].right = static_cast<char>(right);
});
Script::AddMethod("botstop", [](Game::scr_entref_t ent)
{
g_botai[ent].buttons = 0;
g_botai[ent].forward = 0;
g_botai[ent].right = 0;
g_botai[ent].weapon = 1;
});
}
Bots::~Bots()

View File

@ -12,7 +12,7 @@ namespace Components
typedef enum button_mask : unsigned int
{
KEY_FIRE = 1 << 0,
KEY_SPRINT = 1 << 1,
KEY_UNK = 1 << 1,
KEY_MELEE = 1 << 2,
KEY_USE = 1 << 3,
KEY_RELOAD = 1 << 4,
@ -22,28 +22,28 @@ namespace Components
KEY_PRONE = 1 << 8,
KEY_CROUCH = 1 << 9,
KEY_GOSTAND = 1 << 10,
KEY_ADSMODE = 1 << 11,
KEY_TEMP = 1 << 12,
KEY_HOLDBREATH = 1 << 13,
KEY_FRAG = 1 << 14,
KEY_SMOKE = 1 << 15,
KEY_UNK = 1 << 16,
KEY_UNK2 = 1 << 17,
KEY_NIGHTVISION = 1 << 18,
KEY_UNK2 = 1 << 11,
KEY_ADSMODE = 1 << 12,
KEY_UNK3 = 1 << 13,
KEY_UNK4 = 1 << 14,
KEY_HOLDBREATH = 1 << 15,
KEY_FRAG = 1 << 16,
KEY_SMOKE = 1 << 17,
KEY_UNK5 = 1 << 18,
KEY_ADS = 1 << 19,
KEY_UNK3 = 1 << 20,
KEY_UNK4 = 1 << 21,
KEY_UNK7 = 1 << 20,
KEY_UNK8 = 1 << 21,
KEY_MENU = 1 << 22,
KEY_UNK5 = 1 << 23,
KEY_UNK6 = 1 << 24,
KEY_UNK7 = 1 << 25,
KEY_UNK8 = 1 << 25,
KEY_UNK9 = 1 << 26,
KEY_UNK10 = 1 << 27,
KEY_UNK11 = 1 << 28,
KEY_UNK12 = 1 << 29,
KEY_UNK13 = 1 << 30,
KEY_UNK14 = 2147483648
KEY_UNK10 = 1 << 23,
KEY_UNK11 = 1 << 24,
KEY_UNK12 = 1 << 25,
KEY_UNK13 = 1 << 25,
KEY_UNK14 = 1 << 26,
KEY_UNK15 = 1 << 27,
KEY_UNK16 = 1 << 28,
KEY_UNK17 = 1 << 29,
KEY_UNK9 = 1 << 30,
KEY_UNK6 = 2147483648
} button_mask;
struct BotAction_t

View File

@ -65,7 +65,6 @@ namespace Components
// load custom scripts
Utils::Hook(0x4FC75F, G_LoadStructs_Hook, HOOK_CALL).install()->quick();
Utils::Hook(0x5043FA, GScr_LoadGameTypeScript_Hook, HOOK_CALL).install()->quick();
}
Script::~Script()

View File

@ -37,6 +37,8 @@ namespace Game
Com_Printf_t* Com_Printf;
Com_DedicatedModified_t* Com_DedicatedModified;
Dvar_RegisterBool_t* Dvar_RegisterBool;
Cmd_AddCommand_t* Cmd_AddCommand;
Cmd_FindCommand_t* Cmd_FindCommand;
char* isDvarSystemActive;
@ -57,6 +59,8 @@ namespace Game
Com_Printf = ASSIGN(Com_Printf_t*, 0x431EE0);
Com_DedicatedModified = ASSIGN(Com_DedicatedModified_t*, 0x434DC0);
Dvar_RegisterBool = ASSIGN(Dvar_RegisterBool_t*, 0x438040);
Cmd_AddCommand = ASSIGN(Cmd_AddCommand_t*, 0x4212F0);
Cmd_FindCommand = ASSIGN(Cmd_FindCommand_t*, 0x421290);
isDvarSystemActive = ASSIGN(char*, 0xC5C5C8);
@ -131,6 +135,36 @@ namespace Game
}
}
const char* Scr_GetString(unsigned int slot)
{
int func_loc = 0x482FF0;
const char* answer;
__asm
{
mov eax, slot;
call func_loc;
mov answer, eax;
}
return answer;
}
int Scr_GetInt(unsigned int slot)
{
int func_loc = 0x482B80;
int answer;
__asm
{
mov eax, slot;
call func_loc;
mov answer, eax;
}
return answer;
}
void G_SelectWeaponIndex(int wpIdx, int clNum)
{
int func_loc = 0x5282E0;

View File

@ -67,6 +67,22 @@ namespace Game
typedef Game::xfunction_t (Scr_GetFunction_t)(const char**, int*);
extern Scr_GetFunction_t* Scr_GetFunction;
typedef void (Cmd_AddCommand_t)(const char*, Game::xcommand_t);
extern Cmd_AddCommand_t* Cmd_AddCommand;
typedef void (Cmd_FindCommand_t)(const char*);
extern Cmd_FindCommand_t* Cmd_FindCommand;
//VariableValue *__cdecl sub_483580(union VariableUnion a1) addint
//int __usercall sub_483770@<eax>(char *a2@<esi>) addstring
//VariableValue *__cdecl sub_4835D0(float a1) addfloat
//_DWORD *__usercall Scr_AddVector@<eax>(_DWORD *a2@<esi>) 4838B0
//double __usercall sub_482DB0@<st0>(unsigned int a1@<eax>) getfloat
//char __usercall sub_483160@<al>(unsigned int a1@<eax>, _DWORD *a2@<edx>) get vector
extern const char* Scr_GetString(unsigned int);
extern int Scr_GetInt(unsigned int);
extern void G_SelectWeaponIndex(int, int);
extern void SV_ClientThink(Game::usercmd_s*, Game::client_t*);
extern void SV_DropClient(Game::client_t*, const char*);