2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2022-07-06 11:48:40 -04:00
|
|
|
#include "GSC/Script.hpp"
|
2021-12-09 07:01:37 -05:00
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
2022-08-21 12:52:54 -04:00
|
|
|
std::unordered_map<std::string, std::function<void(Game::gentity_s*, const Command::ServerParams*)>> ClientCommand::HandlersSV;
|
2021-12-09 07:01:37 -05:00
|
|
|
|
|
|
|
bool ClientCommand::CheatsOk(const Game::gentity_s* ent)
|
|
|
|
{
|
2021-12-09 12:49:47 -05:00
|
|
|
const auto entNum = ent->s.number;
|
2021-12-09 07:01:37 -05:00
|
|
|
|
2022-08-10 17:03:26 -04:00
|
|
|
if (!(*Game::g_cheats)->current.enabled)
|
2021-12-09 07:01:37 -05:00
|
|
|
{
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Cheats are disabled!");
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"GAME_CHEATSNOTENABLED\"", 0x65));
|
2021-12-09 07:01:37 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ent->health < 1)
|
|
|
|
{
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Entity {} must be alive to use this command!", entNum);
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"GAME_MUSTBEALIVECOMMAND\"", 0x65));
|
2021-12-09 07:01:37 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-21 12:52:54 -04:00
|
|
|
void ClientCommand::Add(const char* name, const std::function<void(Game::gentity_s*, const Command::ServerParams*)>& callback)
|
2021-12-09 07:01:37 -05:00
|
|
|
{
|
|
|
|
const auto command = Utils::String::ToLower(name);
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
HandlersSV[command] = callback;
|
2021-12-09 07:01:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommand::ClientCommandStub(const int clientNum)
|
|
|
|
{
|
2022-04-12 08:34:51 -04:00
|
|
|
const auto ent = &Game::g_entities[clientNum];
|
2021-12-09 07:01:37 -05:00
|
|
|
|
2022-11-25 13:33:53 -05:00
|
|
|
if (!ent->client)
|
2021-12-09 07:01:37 -05:00
|
|
|
{
|
2022-11-25 13:33:53 -05:00
|
|
|
Logger::Debug("ClientCommand: client {} is not fully connected", clientNum);
|
2021-12-09 07:01:37 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:34:51 -04:00
|
|
|
Command::ServerParams params;
|
|
|
|
const auto command = Utils::String::ToLower(params.get(0));
|
2021-12-09 07:01:37 -05:00
|
|
|
|
2022-10-14 17:56:09 -04:00
|
|
|
if (const auto itr = HandlersSV.find(command); itr != HandlersSV.end())
|
2021-12-09 07:01:37 -05:00
|
|
|
{
|
2022-10-14 17:56:09 -04:00
|
|
|
itr->second(ent, ¶ms);
|
2022-04-12 08:34:51 -04:00
|
|
|
return;
|
2021-12-09 07:01:37 -05:00
|
|
|
}
|
2022-04-12 08:34:51 -04:00
|
|
|
|
2022-07-23 19:08:01 -04:00
|
|
|
Utils::Hook::Call<void(int)>(0x416790)(clientNum);
|
2021-12-09 07:01:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommand::AddCheatCommands()
|
|
|
|
{
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("noclip", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2021-12-09 07:01:37 -05:00
|
|
|
{
|
2022-09-01 10:54:28 -04:00
|
|
|
if (!CheatsOk(ent))
|
2021-12-09 07:01:37 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
ent->client->flags ^= Game::PLAYER_FLAG_NOCLIP;
|
|
|
|
|
2021-12-09 12:49:47 -05:00
|
|
|
const auto entNum = ent->s.number;
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Noclip toggled for entity {}", entNum);
|
2021-12-09 07:01:37 -05:00
|
|
|
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
2021-12-09 07:01:37 -05:00
|
|
|
(ent->client->flags & Game::PLAYER_FLAG_NOCLIP) ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF"));
|
|
|
|
});
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("ufo", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2021-12-09 07:01:37 -05:00
|
|
|
{
|
2022-09-01 10:54:28 -04:00
|
|
|
if (!CheatsOk(ent))
|
2021-12-09 07:01:37 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
ent->client->flags ^= Game::PLAYER_FLAG_UFO;
|
|
|
|
|
2021-12-09 12:49:47 -05:00
|
|
|
const auto entNum = ent->s.number;
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("UFO toggled for entity {}", entNum);
|
2021-12-09 07:01:37 -05:00
|
|
|
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
2021-12-09 07:01:37 -05:00
|
|
|
(ent->client->flags & Game::PLAYER_FLAG_UFO) ? "GAME_UFOON" : "GAME_UFOOFF"));
|
|
|
|
});
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("god", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2021-12-09 07:01:37 -05:00
|
|
|
{
|
2022-09-01 10:54:28 -04:00
|
|
|
if (!CheatsOk(ent))
|
2021-12-09 07:01:37 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
ent->flags ^= Game::FL_GODMODE;
|
|
|
|
|
2021-12-09 12:49:47 -05:00
|
|
|
const auto entNum = ent->s.number;
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("God toggled for entity {}", entNum);
|
2021-12-09 07:01:37 -05:00
|
|
|
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
2021-12-09 07:01:37 -05:00
|
|
|
(ent->flags & Game::FL_GODMODE) ? "GAME_GODMODE_ON" : "GAME_GODMODE_OFF"));
|
|
|
|
});
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("demigod", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2021-12-09 07:01:37 -05:00
|
|
|
{
|
2022-09-01 10:54:28 -04:00
|
|
|
if (!CheatsOk(ent))
|
2021-12-09 07:01:37 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
ent->flags ^= Game::FL_DEMI_GODMODE;
|
|
|
|
|
2021-12-09 12:49:47 -05:00
|
|
|
const auto entNum = ent->s.number;
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Demigod toggled for entity {}", entNum);
|
2021-12-09 07:01:37 -05:00
|
|
|
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
2021-12-09 07:01:37 -05:00
|
|
|
(ent->flags & Game::FL_DEMI_GODMODE) ? "GAME_DEMI_GODMODE_ON" : "GAME_DEMI_GODMODE_OFF"));
|
|
|
|
});
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("notarget", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2021-12-09 07:01:37 -05:00
|
|
|
{
|
2022-09-01 10:54:28 -04:00
|
|
|
if (!CheatsOk(ent))
|
2021-12-09 07:01:37 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
ent->flags ^= Game::FL_NOTARGET;
|
|
|
|
|
2021-12-09 12:49:47 -05:00
|
|
|
const auto entNum = ent->s.number;
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Notarget toggled for entity {}", entNum);
|
2021-12-09 07:01:37 -05:00
|
|
|
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
2021-12-09 07:01:37 -05:00
|
|
|
(ent->flags & Game::FL_NOTARGET) ? "GAME_NOTARGETON" : "GAME_NOTARGETOFF"));
|
|
|
|
});
|
2022-01-10 07:04:39 -05:00
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("setviewpos", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-01-10 07:04:39 -05:00
|
|
|
{
|
2022-11-25 13:33:53 -05:00
|
|
|
assert(ent);
|
2022-01-10 07:04:39 -05:00
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
if (!CheatsOk(ent))
|
2022-01-10 07:04:39 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
Game::vec3_t origin, angles{0.f, 0.f, 0.f};
|
|
|
|
|
2022-04-12 08:34:51 -04:00
|
|
|
if (params->size() < 4 || params->size() > 6)
|
2022-01-10 07:04:39 -05:00
|
|
|
{
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_CAN_IGNORE,
|
2022-01-11 13:53:20 -05:00
|
|
|
Utils::String::VA("%c \"GAME_USAGE\x15: setviewpos x y z [yaw] [pitch]\n\"", 0x65));
|
2022-01-10 07:04:39 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto i = 0; i < 3; i++)
|
|
|
|
{
|
2022-04-12 08:34:51 -04:00
|
|
|
origin[i] = std::strtof(params->get(i + 1), nullptr);
|
2022-01-10 07:04:39 -05:00
|
|
|
}
|
|
|
|
|
2022-04-12 08:34:51 -04:00
|
|
|
if (params->size() >= 5)
|
2022-01-10 07:04:39 -05:00
|
|
|
{
|
2022-04-12 08:34:51 -04:00
|
|
|
angles[1] = std::strtof(params->get(4), nullptr); // Yaw
|
2022-01-10 07:04:39 -05:00
|
|
|
}
|
|
|
|
|
2022-04-12 08:34:51 -04:00
|
|
|
if (params->size() == 6)
|
2022-01-10 07:04:39 -05:00
|
|
|
{
|
2022-04-12 08:34:51 -04:00
|
|
|
angles[0] = std::strtof(params->get(5), nullptr); // Pitch
|
2022-01-10 07:04:39 -05:00
|
|
|
}
|
|
|
|
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Teleported entity {} to {:f} {:f} {:f}\nviewpos {:f} {:f}", ent->s.number,
|
2022-06-12 17:07:53 -04:00
|
|
|
origin[0], origin[1], origin[2], angles[0], angles[2]);
|
2022-01-10 07:04:39 -05:00
|
|
|
Game::TeleportPlayer(ent, origin, angles);
|
|
|
|
});
|
2022-06-20 05:06:30 -04:00
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("give", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-06-20 05:06:30 -04:00
|
|
|
{
|
2022-09-01 10:54:28 -04:00
|
|
|
if (!CheatsOk(ent))
|
2022-06-20 05:06:30 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (params->size() < 2)
|
|
|
|
{
|
|
|
|
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_CAN_IGNORE,
|
|
|
|
Utils::String::VA("%c \"GAME_USAGE\x15: give <weapon name>\"", 0x65));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Game::level->initializing = 1;
|
|
|
|
const auto* weaponName = params->get(1);
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Giving weapon {} to entity {}", weaponName, ent->s.number);
|
2022-06-20 05:06:30 -04:00
|
|
|
const auto weaponIndex = Game::G_GetWeaponIndexForName(weaponName);
|
|
|
|
|
|
|
|
if (weaponIndex == 0)
|
|
|
|
{
|
|
|
|
Game::level->initializing = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Game::BG_GetWeaponDef(weaponIndex)->inventoryType == Game::weapInventoryType_t::WEAPINVENTORY_ALTMODE)
|
|
|
|
{
|
|
|
|
Logger::PrintError(Game::CON_CHANNEL_ERROR,
|
|
|
|
"You can't directly spawn the altfire weapon '{}'. Spawn a weapon that has this altmode instead.\n", weaponName);
|
|
|
|
Game::level->initializing = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* weapEnt = Game::G_Spawn();
|
2022-06-22 04:58:51 -04:00
|
|
|
std::memcpy(weapEnt->r.currentOrigin, ent->r.currentOrigin, sizeof(std::float_t[3]));
|
2022-06-20 05:06:30 -04:00
|
|
|
Game::G_GetItemClassname(static_cast<int>(weaponIndex), weapEnt);
|
|
|
|
Game::G_SpawnItem(weapEnt, static_cast<int>(weaponIndex));
|
|
|
|
|
|
|
|
weapEnt->active = 1;
|
|
|
|
const auto offHandClass = Game::BG_GetWeaponDef(weaponIndex)->offhandClass;
|
|
|
|
if (offHandClass != Game::OFFHAND_CLASS_NONE)
|
|
|
|
{
|
|
|
|
auto* client = ent->client;
|
|
|
|
if ((client->ps.weapCommon.offhandPrimary != offHandClass) && (client->ps.weapCommon.offhandSecondary != offHandClass))
|
|
|
|
{
|
|
|
|
switch (offHandClass)
|
|
|
|
{
|
|
|
|
case Game::OFFHAND_CLASS_FRAG_GRENADE:
|
|
|
|
case Game::OFFHAND_CLASS_THROWINGKNIFE:
|
|
|
|
case Game::OFFHAND_CLASS_OTHER:
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Setting offhandPrimary");
|
2022-06-20 05:06:30 -04:00
|
|
|
client->ps.weapCommon.offhandPrimary = offHandClass;
|
|
|
|
break;
|
|
|
|
default:
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Setting offhandSecondary");
|
2022-06-20 05:06:30 -04:00
|
|
|
client->ps.weapCommon.offhandSecondary = offHandClass;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Game::Touch_Item(weapEnt, ent, 0);
|
|
|
|
weapEnt->active = 0;
|
|
|
|
|
|
|
|
if (weapEnt->r.isInUse)
|
|
|
|
{
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Freeing up entity {}", weapEnt->s.number);
|
2022-06-20 05:06:30 -04:00
|
|
|
Game::G_FreeEntity(weapEnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Game::level->initializing = 0;
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < std::extent_v<decltype(Game::playerState_s::weaponsEquipped)>; ++i)
|
|
|
|
{
|
|
|
|
const auto index = ent->client->ps.weaponsEquipped[i];
|
2022-09-01 10:54:28 -04:00
|
|
|
if (index)
|
2022-06-20 05:06:30 -04:00
|
|
|
{
|
|
|
|
Game::Add_Ammo(ent, index, 0, 998, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-08-22 13:46:47 -04:00
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("kill", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-08-22 13:46:47 -04:00
|
|
|
{
|
2022-11-25 13:33:53 -05:00
|
|
|
assert(ent->client);
|
2022-08-22 13:46:47 -04:00
|
|
|
assert(ent->client->sess.connected != Game::CON_DISCONNECTED);
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
if (ent->client->sess.sessionState != Game::SESS_STATE_PLAYING || !CheatsOk(ent))
|
2022-08-22 13:46:47 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
Scheduler::Once([ent]
|
|
|
|
{
|
|
|
|
ent->flags &= ~(Game::FL_GODMODE | Game::FL_DEMI_GODMODE);
|
|
|
|
ent->health = 0;
|
|
|
|
ent->client->ps.stats[0] = 0;
|
2022-09-01 10:54:28 -04:00
|
|
|
Game::player_die(ent, ent, ent, 100000, Game::MOD_SUICIDE, 0, nullptr, Game::HITLOC_NONE, 0);
|
2022-08-22 13:46:47 -04:00
|
|
|
}, Scheduler::Pipeline::SERVER);
|
|
|
|
});
|
2021-12-09 07:01:37 -05:00
|
|
|
}
|
|
|
|
|
2022-04-12 08:34:51 -04:00
|
|
|
void ClientCommand::AddDevelopmentCommands()
|
|
|
|
{
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("dropallbots", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-04-12 08:34:51 -04:00
|
|
|
{
|
|
|
|
Game::SV_DropAllBots();
|
|
|
|
});
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("entitylist", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-04-12 08:34:51 -04:00
|
|
|
{
|
|
|
|
Game::Svcmd_EntityList_f();
|
|
|
|
});
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("printentities", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-04-12 08:34:51 -04:00
|
|
|
{
|
|
|
|
Game::G_PrintEntities();
|
|
|
|
});
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("entitycount", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-04-12 08:34:51 -04:00
|
|
|
{
|
2022-06-12 17:07:53 -04:00
|
|
|
Logger::Print("Entity count = {}\n", Game::level->num_entities);
|
2022-04-12 08:34:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Also known as: "vis"
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("visionsetnaked", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-04-12 08:34:51 -04:00
|
|
|
{
|
|
|
|
if (params->size() < 2)
|
|
|
|
{
|
|
|
|
Logger::Print("USAGE: visionSetNaked <name> <duration>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto duration = 1000;
|
|
|
|
if (params->size() > 2)
|
|
|
|
{
|
|
|
|
const auto input = std::strtof(params->get(2), nullptr);
|
|
|
|
duration = static_cast<int>(std::floorf(input * 1000.0f + 0.5f));
|
|
|
|
}
|
|
|
|
|
2022-11-25 13:33:53 -05:00
|
|
|
assert(ent->client);
|
2022-04-12 08:34:51 -04:00
|
|
|
|
|
|
|
constexpr auto visMode = Game::visionSetMode_t::VISIONSET_NORMAL;
|
|
|
|
const auto* name = params->get(1);
|
|
|
|
|
|
|
|
ent->client->visionDuration[visMode] = duration;
|
|
|
|
strncpy_s(ent->client->visionName[visMode],
|
|
|
|
sizeof(Game::gclient_t::visionName[0]) / sizeof(char), name, _TRUNCATE);
|
|
|
|
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_RELIABLE,
|
2022-04-12 08:34:51 -04:00
|
|
|
Utils::String::VA("%c \"%s\" %i", Game::MY_CMDS[visMode], name, duration));
|
|
|
|
});
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("visionsetnight", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-04-12 08:34:51 -04:00
|
|
|
{
|
|
|
|
if (params->size() < 2)
|
|
|
|
{
|
|
|
|
Logger::Print("USAGE: visionSetNight <name> <duration>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto duration = 1000;
|
|
|
|
if (params->size() > 2)
|
|
|
|
{
|
|
|
|
const auto input = std::strtof(params->get(2), nullptr);
|
|
|
|
duration = static_cast<int>(std::floorf(input * 1000.0f + 0.5f));
|
|
|
|
}
|
|
|
|
|
2022-11-25 13:33:53 -05:00
|
|
|
assert(ent->client);
|
2022-04-12 08:34:51 -04:00
|
|
|
|
|
|
|
constexpr auto visMode = Game::visionSetMode_t::VISIONSET_NIGHT;
|
|
|
|
const auto* name = params->get(1);
|
|
|
|
|
|
|
|
ent->client->visionDuration[visMode] = duration;
|
|
|
|
strncpy_s(ent->client->visionName[visMode],
|
|
|
|
sizeof(Game::gclient_t::visionName[0]) / sizeof(char), name, _TRUNCATE);
|
|
|
|
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_RELIABLE,
|
2022-04-12 08:34:51 -04:00
|
|
|
Utils::String::VA("%c \"%s\" %i", Game::MY_CMDS[visMode], name, duration));
|
|
|
|
});
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
Add("g_testCmd", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
2022-04-12 08:34:51 -04:00
|
|
|
{
|
2022-11-25 13:33:53 -05:00
|
|
|
assert(ent);
|
2022-06-12 17:07:53 -04:00
|
|
|
|
2022-04-15 06:16:12 -04:00
|
|
|
ent->client->ps.stunTime = 1000 + Game::level->time; // 1000 is the default test stun time
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("playerState_s.stunTime is {}", ent->client->ps.stunTime);
|
2022-04-12 08:34:51 -04:00
|
|
|
});
|
2022-09-01 10:54:28 -04:00
|
|
|
|
|
|
|
Add("dumpEntInfo", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
|
|
|
{
|
|
|
|
G_DumpEntityDebugInfoToConsole(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
Add("dumpEntInfoCSV", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
|
|
|
{
|
|
|
|
G_DumpEntityDebugInfoToCSV("");
|
|
|
|
});
|
2022-04-12 08:34:51 -04:00
|
|
|
}
|
|
|
|
|
2021-12-09 07:01:37 -05:00
|
|
|
void ClientCommand::AddScriptFunctions()
|
|
|
|
{
|
2022-07-23 17:22:58 -04:00
|
|
|
Script::AddFunction("DropAllBots", [] // gsc: DropAllBots();
|
2022-04-12 08:34:51 -04:00
|
|
|
{
|
|
|
|
Game::SV_DropAllBots();
|
|
|
|
});
|
2021-12-09 07:01:37 -05:00
|
|
|
}
|
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
const char* ClientCommand::EntInfoLine(const int entNum)
|
|
|
|
{
|
|
|
|
const auto* ent = &Game::g_entities[entNum];
|
|
|
|
|
|
|
|
Game::XModel* model = nullptr;
|
|
|
|
if (ent->model)
|
|
|
|
{
|
|
|
|
model = Game::G_GetModel(ent->model);
|
|
|
|
}
|
|
|
|
|
|
|
|
Game::vec3_t point, angles;
|
|
|
|
|
|
|
|
point[0] = ent->r.currentOrigin[0] - (*Game::viewposNow)->current.vector[0];
|
|
|
|
point[1] = ent->r.currentOrigin[1] - (*Game::viewposNow)->current.vector[1];
|
|
|
|
point[2] = ent->r.currentOrigin[2] - (*Game::viewposNow)->current.vector[2];
|
|
|
|
|
|
|
|
angles[0] = ent->r.currentAngles[0];
|
|
|
|
angles[1] = ent->r.currentAngles[1];
|
|
|
|
angles[2] = ent->r.currentAngles[2];
|
|
|
|
|
|
|
|
const auto distance = std::sqrtf(point[0] * point[0] + point[1] * point[1]
|
|
|
|
+ point[2] * point[2]);
|
|
|
|
|
|
|
|
const auto* team = (ent->client) ? Game::CG_GetTeamName(ent->client->sess.cs.team) : "";
|
|
|
|
|
|
|
|
const auto* scriptLinkName = (ent->script_linkName) ? Game::SL_ConvertToString(ent->script_linkName) : "";
|
|
|
|
|
|
|
|
const auto* target = (ent->target) ? Game::SL_ConvertToString(ent->target) : "";
|
|
|
|
|
|
|
|
const auto* targetName = (ent->targetname) ? Game::SL_ConvertToString(ent->targetname) : "";
|
|
|
|
|
|
|
|
const auto* codeClassname = (ent->script_classname) ? Game::SL_ConvertToString(ent->script_classname) : "";
|
|
|
|
|
|
|
|
const auto* classname = (ent->classname) ? Game::SL_ConvertToString(ent->classname) : "";
|
|
|
|
|
|
|
|
const auto* eventType = (ent->s.eType < Game::ET_EVENTS) ? Game::G_GetEntityTypeName(ent) : "";
|
|
|
|
|
|
|
|
// See description of the format string in the function G_DumpEntityDebugInfoToCSV
|
|
|
|
// If empty it means the item does not exist in the current version of the game or it was not possible to reverse it
|
|
|
|
return Utils::String::VA("%i,%s,%.0f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%.0f %.0f %.0f,%.0f %.0f %.0f,%i\n",
|
|
|
|
entNum, eventType, distance, classname, codeClassname, (model) ? model->name : "",
|
|
|
|
targetName, target, "", scriptLinkName, team, "",
|
|
|
|
point[0], point[1], point[2], angles[0], angles[1], angles[2], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommand::G_DumpEntityDebugInfoToConsole(bool logfileOnly)
|
|
|
|
{
|
|
|
|
const auto channel = logfileOnly ? Game::CON_CHANNEL_LOGFILEONLY : Game::CON_CHANNEL_SERVER;
|
|
|
|
|
|
|
|
Logger::Print(channel, "=====================================================================================\n");
|
|
|
|
Logger::Print(channel, "============(entity dump begin)\n");
|
|
|
|
Logger::Print(channel,
|
|
|
|
"Number,Type,Distance,Classname,Code Classname,Model,"
|
|
|
|
"Targetname,Target,Script Noteworthy,Script Linkname,Team,ParentNum,Origin,Angles,SentToClients\n");
|
|
|
|
|
|
|
|
for (auto i = 0; i < Game::MAX_GENTITIES; ++i)
|
|
|
|
{
|
|
|
|
if (&Game::g_entities[i] == nullptr)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto* line = EntInfoLine(i);
|
|
|
|
assert(line);
|
|
|
|
Logger::Print(channel, "%s", line);
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger::Print(channel, "(end entity dump)============\n");
|
|
|
|
Logger::Print(channel, "=====================================================================================\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommand::G_DumpEntityDebugInfoToCSV(const char* filenameSuffix)
|
|
|
|
{
|
|
|
|
assert(filenameSuffix);
|
|
|
|
|
|
|
|
const auto* fileName = Utils::String::VA("%s%s%s%s", "EntInfo", (*filenameSuffix) ? "_" : "", filenameSuffix, ".csv");
|
|
|
|
Logger::Print(Game::CON_CHANNEL_SERVER, "Opening file \"{}\" for writing.\n", fileName);
|
|
|
|
|
|
|
|
auto h = Game::FS_FOpenTextFileWrite(fileName);
|
|
|
|
if (!h)
|
|
|
|
{
|
|
|
|
Logger::PrintError(Game::CON_CHANNEL_SERVER, "Couldn't open file \"{}\" for writing.\n", fileName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Game::FS_Write("Number,Type,Distance,Classname,Code Classname,Model,Targetname,Target,Script Noteworthy,Script Linkname,Team,Paren"
|
|
|
|
"tNum,Origin,Angles,SentToClients\n", 147, h);
|
|
|
|
|
|
|
|
for (auto i = 0; i < Game::MAX_GENTITIES; ++i)
|
|
|
|
{
|
|
|
|
if (&Game::g_entities[i] == nullptr)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto* line = EntInfoLine(i);
|
|
|
|
const auto lineLen = std::strlen(line);
|
2022-11-25 13:33:53 -05:00
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
assert(line);
|
|
|
|
assert(lineLen);
|
2022-11-25 13:33:53 -05:00
|
|
|
|
|
|
|
Game::FS_Write(line, static_cast<int>(lineLen), h);
|
2022-09-01 10:54:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Game::FS_FCloseFile(h);
|
|
|
|
Logger::Print(Game::CON_CHANNEL_SERVER, "Done writing file.\n");
|
|
|
|
}
|
|
|
|
|
2021-12-09 07:01:37 -05:00
|
|
|
ClientCommand::ClientCommand()
|
|
|
|
{
|
2022-08-10 17:03:26 -04:00
|
|
|
AssertOffset(Game::playerState_s, stats, 0x150);
|
|
|
|
|
2021-12-09 12:49:47 -05:00
|
|
|
// Hook call to ClientCommand in SV_ExecuteClientCommand so we may add custom commands
|
2022-09-01 10:54:28 -04:00
|
|
|
Utils::Hook(0x6259FA, ClientCommandStub, HOOK_CALL).install()->quick();
|
2021-12-09 07:01:37 -05:00
|
|
|
|
2022-09-01 10:54:28 -04:00
|
|
|
AddCheatCommands();
|
|
|
|
AddScriptFunctions();
|
2022-04-12 08:34:51 -04:00
|
|
|
#ifdef _DEBUG
|
2022-09-01 10:54:28 -04:00
|
|
|
AddDevelopmentCommands();
|
2022-04-12 08:34:51 -04:00
|
|
|
#endif
|
2021-12-09 07:01:37 -05:00
|
|
|
}
|
|
|
|
}
|