Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ineed bots committed Dec 5, 2023
1 parent 9d4e08b commit e9debbd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
26 changes: 14 additions & 12 deletions src/Components/Modules/Bots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ namespace Components
return;
}

auto clientNum = cl - Game::svs_clients;

// Keep test client functionality
if (!g_botai[cl - Game::svs_clients].active)
if (!g_botai[clientNum].active)
{
Game::SV_BotUserMove(cl);
return;
Expand All @@ -313,11 +315,11 @@ namespace Components

userCmd.serverTime = *Game::svs_time;

userCmd.buttons = g_botai[cl - Game::svs_clients].buttons;
userCmd.forwardmove = g_botai[cl - Game::svs_clients].forward;
userCmd.rightmove = g_botai[cl - Game::svs_clients].right;
userCmd.weapon = g_botai[cl - Game::svs_clients].weapon;
userCmd.primaryWeaponForAltMode = g_botai[cl - Game::svs_clients].lastAltWeapon;
userCmd.buttons = g_botai[clientNum].buttons;
userCmd.forwardmove = g_botai[clientNum].forward;
userCmd.rightmove = g_botai[clientNum].right;
userCmd.weapon = g_botai[clientNum].weapon;
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[1] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[1] - cl->gentity->client->ps.delta_angles[1]));
Expand Down Expand Up @@ -350,21 +352,21 @@ namespace Components

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 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))
{
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;
}
Expand Down Expand Up @@ -523,7 +525,7 @@ namespace Components

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(0x459654, SV_GetClientPing_Hk, HOOK_CALL).install()->quick();
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Modules/GSC/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ namespace Components::GSC

// check if we need to append scriptdata folder, for backwards compat
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())
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Modules/GSC/ScriptStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ namespace Components::GSC

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();
{
FileSystem::File storageFile("scriptdata/scriptstorage.json");
FileSystem::File storageFile(Game::SCRIPTDATA_DIR + "/scriptstorage.json"s);
if (!storageFile.exists())
{
return;
Expand Down
2 changes: 2 additions & 0 deletions src/Game/Script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ namespace Game

constexpr auto LOCAL_VAR_STACK_SIZE = 64;

constexpr auto SCRIPTDATA_DIR = "scriptdata";

extern void IncInParam();

extern void Scr_AddBool(int value);
Expand Down

0 comments on commit e9debbd

Please sign in to comment.