Address comments

This commit is contained in:
ineed bots 2023-12-05 17:34:33 -06:00
parent 9d4e08b1a3
commit e9debbd4f5
4 changed files with 20 additions and 16 deletions

View File

@ -301,8 +301,10 @@ namespace Components
return; return;
} }
auto clientNum = cl - Game::svs_clients;
// Keep test client functionality // Keep test client functionality
if (!g_botai[cl - Game::svs_clients].active) if (!g_botai[clientNum].active)
{ {
Game::SV_BotUserMove(cl); Game::SV_BotUserMove(cl);
return; return;
@ -313,11 +315,11 @@ namespace Components
userCmd.serverTime = *Game::svs_time; userCmd.serverTime = *Game::svs_time;
userCmd.buttons = g_botai[cl - Game::svs_clients].buttons; userCmd.buttons = g_botai[clientNum].buttons;
userCmd.forwardmove = g_botai[cl - Game::svs_clients].forward; userCmd.forwardmove = g_botai[clientNum].forward;
userCmd.rightmove = g_botai[cl - Game::svs_clients].right; userCmd.rightmove = g_botai[clientNum].right;
userCmd.weapon = g_botai[cl - Game::svs_clients].weapon; userCmd.weapon = g_botai[clientNum].weapon;
userCmd.primaryWeaponForAltMode = g_botai[cl - Game::svs_clients].lastAltWeapon; userCmd.primaryWeaponForAltMode = g_botai[clientNum].lastAltWeapon;
userCmd.angles[0] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[0] - cl->gentity->client->ps.delta_angles[0])); userCmd.angles[0] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[0] - cl->gentity->client->ps.delta_angles[0]));
userCmd.angles[1] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[1] - cl->gentity->client->ps.delta_angles[1])); userCmd.angles[1] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[1] - cl->gentity->client->ps.delta_angles[1]));
@ -350,21 +352,21 @@ namespace Components
auto* def = Game::BG_GetWeaponCompleteDef(iWeaponIndex); auto* def = Game::BG_GetWeaponCompleteDef(iWeaponIndex);
if (def->weapDef->inventoryType == Game::WEAPINVENTORY_ALTMODE) if (def && def->weapDef->inventoryType == Game::WEAPINVENTORY_ALTMODE)
{ {
auto* ps = &Game::g_entities[clientNum].client->ps; auto* ps = &Game::g_entities[clientNum].client->ps;
auto num_weaps = Game::BG_GetNumWeapons(); auto numWeaps = Game::BG_GetNumWeapons();
for (auto i = 1u; i < num_weaps; i++) for (auto i = 1u; i < numWeaps; i++)
{ {
if (!Game::BG_PlayerHasWeapon(ps, i)) if (!Game::BG_PlayerHasWeapon(ps, i))
{ {
continue; continue;
} }
auto* this_def = Game::BG_GetWeaponCompleteDef(i); auto* thisDef = Game::BG_GetWeaponCompleteDef(i);
if (this_def->altWeaponIndex != iWeaponIndex) if (!thisDef || thisDef->altWeaponIndex != iWeaponIndex)
{ {
continue; continue;
} }
@ -523,7 +525,7 @@ namespace Components
Utils::Hook(0x441B80, G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick(); Utils::Hook(0x441B80, G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick();
// fix bots using objects // fix bots using objects (SV_IsClientBot)
Utils::Hook(0x4D79C5, Player_UpdateActivate_stub, HOOK_CALL).install()->quick(); Utils::Hook(0x4D79C5, Player_UpdateActivate_stub, HOOK_CALL).install()->quick();
Utils::Hook(0x459654, SV_GetClientPing_Hk, HOOK_CALL).install()->quick(); Utils::Hook(0x459654, SV_GetClientPing_Hk, HOOK_CALL).install()->quick();

View File

@ -33,9 +33,9 @@ namespace Components::GSC
// check if we need to append scriptdata folder, for backwards compat // check if we need to append scriptdata folder, for backwards compat
std::string spath = path; std::string spath = path;
if (!spath.starts_with("scriptdata/") && !spath.starts_with("scriptdata\\")) if (!spath.starts_with(Game::SCRIPTDATA_DIR + "/"s) && !spath.starts_with(Game::SCRIPTDATA_DIR + "\\"s))
{ {
spath = "scriptdata/" + spath; spath = Game::SCRIPTDATA_DIR + "/"s + spath;
} }
if (!fsGame.empty()) if (!fsGame.empty())

View File

@ -84,12 +84,12 @@ namespace Components::GSC
const nlohmann::json json = Data; const nlohmann::json json = Data;
FileSystem::FileWriter("scriptdata/scriptstorage.json").write(json.dump()); FileSystem::FileWriter(Game::SCRIPTDATA_DIR + "/scriptstorage.json"s).write(json.dump());
}); });
Script::AddFunction("StorageLoad", [] // gsc: StorageLoad(); Script::AddFunction("StorageLoad", [] // gsc: StorageLoad();
{ {
FileSystem::File storageFile("scriptdata/scriptstorage.json"); FileSystem::File storageFile(Game::SCRIPTDATA_DIR + "/scriptstorage.json"s);
if (!storageFile.exists()) if (!storageFile.exists())
{ {
return; return;

View File

@ -221,6 +221,8 @@ namespace Game
constexpr auto LOCAL_VAR_STACK_SIZE = 64; constexpr auto LOCAL_VAR_STACK_SIZE = 64;
constexpr auto SCRIPTDATA_DIR = "scriptdata";
extern void IncInParam(); extern void IncInParam();
extern void Scr_AddBool(int value); extern void Scr_AddBool(int value);