mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2025-04-22 05:35:43 +00:00
Clean up gsc functions with additional checks
This commit is contained in:
parent
e9a877bd74
commit
286481cbcd
@ -49,6 +49,7 @@ namespace command
|
|||||||
if (i > index) result.append(" ");
|
if (i > index) result.append(" ");
|
||||||
result.append(this->get(i));
|
result.append(this->get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +97,6 @@ namespace command
|
|||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void post_unpack() override
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -402,8 +402,13 @@ namespace gsc
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto client = ent.entnum;
|
const auto client = ent.entnum;
|
||||||
const auto message = args[0].as<std::string>();
|
|
||||||
|
|
||||||
|
if (game::g_entities[client].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto message = args[0].as<std::string>();
|
||||||
game::SV_GameSendServerCommand(client, 0, utils::string::va("%c \"%s\"", 84, message.data()));
|
game::SV_GameSendServerCommand(client, 0, utils::string::va("%c \"%s\"", 84, message.data()));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@ -416,16 +421,18 @@ namespace gsc
|
|||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto num = ent.entnum;
|
const auto client = ent.entnum;
|
||||||
|
|
||||||
|
if (game::g_entities[client].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
const auto toggle = args[0].as<int>();
|
const auto toggle = args[0].as<int>();
|
||||||
|
auto flags = game::g_entities[client].client->ps.perks[0];
|
||||||
|
|
||||||
auto g_client = game::g_entities[num].client;
|
game::g_entities[client].client->ps.perks[0] = toggle
|
||||||
auto playerState = &g_client->ps;
|
? flags | 0x4000u : flags & ~0x4000u;
|
||||||
auto flags = playerState->perks[0];
|
|
||||||
|
|
||||||
playerState->perks[0] = toggle
|
|
||||||
? flags | 0x4000u
|
|
||||||
: flags & ~0x4000u;
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
@ -438,9 +445,10 @@ namespace gsc
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto client = ent.entnum;
|
const auto client = ent.entnum;
|
||||||
|
|
||||||
if (game::g_entities[client].client == nullptr)
|
if (game::g_entities[client].client == nullptr)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("entity is not a player");
|
throw std::runtime_error("Not a player entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
return game::svs_clients[client].bIsTestClient;
|
return game::svs_clients[client].bIsTestClient;
|
||||||
|
@ -14,7 +14,13 @@ namespace notifies
|
|||||||
|
|
||||||
void client_command_stub(int clientNum)
|
void client_command_stub(int clientNum)
|
||||||
{
|
{
|
||||||
char cmd[1024] = { 0 };
|
char cmd[1024] = {0};
|
||||||
|
const auto* entity = &game::g_entities[clientNum];
|
||||||
|
|
||||||
|
if (entity->client == nullptr)
|
||||||
|
{
|
||||||
|
return; // Client is not fully in game yet
|
||||||
|
}
|
||||||
|
|
||||||
game::SV_Cmd_ArgvBuffer(0, cmd, 1024);
|
game::SV_Cmd_ArgvBuffer(0, cmd, 1024);
|
||||||
|
|
||||||
|
@ -92,13 +92,18 @@ namespace userinfo
|
|||||||
|
|
||||||
gsc::method::add("setname", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("setname", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
const auto name = args[0].as<std::string>();
|
if (ent.classnum != 0)
|
||||||
|
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto name = args[0].as<std::string>();
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum]["name"] = name;
|
userinfo_overrides[ent.entnum]["name"] = name;
|
||||||
game::ClientUserinfoChanged(ent.entnum);
|
game::ClientUserinfoChanged(ent.entnum);
|
||||||
|
|
||||||
@ -107,11 +112,16 @@ namespace userinfo
|
|||||||
|
|
||||||
gsc::method::add("resetname", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("resetname", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
if (ent.classnum != 0)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum].erase("name");
|
userinfo_overrides[ent.entnum].erase("name");
|
||||||
game::ClientUserinfoChanged(ent.entnum);
|
game::ClientUserinfoChanged(ent.entnum);
|
||||||
|
|
||||||
@ -120,13 +130,18 @@ namespace userinfo
|
|||||||
|
|
||||||
gsc::method::add("setclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("setclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
const auto name = args[0].as<std::string>();
|
if (ent.classnum != 0)
|
||||||
|
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto name = args[0].as<std::string>();
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum]["clantag"] = name;
|
userinfo_overrides[ent.entnum]["clantag"] = name;
|
||||||
userinfo_overrides[ent.entnum]["ec_TagText"] = name;
|
userinfo_overrides[ent.entnum]["ec_TagText"] = name;
|
||||||
userinfo_overrides[ent.entnum]["ec_usingTag"] = "1";
|
userinfo_overrides[ent.entnum]["ec_usingTag"] = "1";
|
||||||
@ -137,11 +152,16 @@ namespace userinfo
|
|||||||
|
|
||||||
gsc::method::add("resetclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("resetclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
if (ent.classnum != 0)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum].erase("clantag");
|
userinfo_overrides[ent.entnum].erase("clantag");
|
||||||
userinfo_overrides[ent.entnum].erase("ec_TagText");
|
userinfo_overrides[ent.entnum].erase("ec_TagText");
|
||||||
userinfo_overrides[ent.entnum].erase("ec_usingTag");
|
userinfo_overrides[ent.entnum].erase("ec_usingTag");
|
||||||
@ -152,11 +172,16 @@ namespace userinfo
|
|||||||
|
|
||||||
gsc::method::add("removeclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("removeclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
if (ent.classnum != 0)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum]["clantag"] = "";
|
userinfo_overrides[ent.entnum]["clantag"] = "";
|
||||||
userinfo_overrides[ent.entnum]["ec_TagText"] = "";
|
userinfo_overrides[ent.entnum]["ec_TagText"] = "";
|
||||||
userinfo_overrides[ent.entnum]["ec_usingTag"] = "0";
|
userinfo_overrides[ent.entnum]["ec_usingTag"] = "0";
|
||||||
|
@ -26,20 +26,35 @@ namespace game
|
|||||||
const char** argv[8];
|
const char** argv[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum netsrc_t
|
||||||
|
{
|
||||||
|
NS_CLIENT1 = 0x0,
|
||||||
|
NS_CLIENT2 = 0x1,
|
||||||
|
NS_CLIENT3 = 0x2,
|
||||||
|
NS_CLIENT4 = 0x3,
|
||||||
|
NS_MAXCLIENTS = 0x4,
|
||||||
|
NS_SERVER = 0x4,
|
||||||
|
NS_PACKET = 0x5,
|
||||||
|
NS_INVALID_NETSRC = 0x6
|
||||||
|
};
|
||||||
|
|
||||||
struct msg_t
|
struct msg_t
|
||||||
{
|
{
|
||||||
int overflowed;
|
int overflowed;
|
||||||
int readOnly;
|
int readOnly;
|
||||||
char* data;
|
unsigned char* data;
|
||||||
char* splitData;
|
unsigned char* splitData;
|
||||||
int maxsize;
|
int maxsize;
|
||||||
int cursize;
|
int cursize;
|
||||||
int splitSize;
|
int splitSize;
|
||||||
int readcount;
|
int readcount;
|
||||||
int bit;
|
int bit;
|
||||||
int lastEntityRef;
|
int lastEntityRef;
|
||||||
|
netsrc_t targetLocalNetID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(msg_t) == 0x2C);
|
||||||
|
|
||||||
struct XZoneInfo
|
struct XZoneInfo
|
||||||
{
|
{
|
||||||
const char* name;
|
const char* name;
|
||||||
@ -328,18 +343,6 @@ namespace game
|
|||||||
char __pad2[0xEC];
|
char __pad2[0xEC];
|
||||||
};
|
};
|
||||||
|
|
||||||
enum netsrc_t
|
|
||||||
{
|
|
||||||
NS_CLIENT1 = 0x0,
|
|
||||||
NS_CLIENT2 = 0x1,
|
|
||||||
NS_CLIENT3 = 0x2,
|
|
||||||
NS_CLIENT4 = 0x3,
|
|
||||||
NS_MAXCLIENTS = 0x4,
|
|
||||||
NS_SERVER = 0x4,
|
|
||||||
NS_PACKET = 0x5,
|
|
||||||
NS_INVALID_NETSRC = 0x6
|
|
||||||
};
|
|
||||||
|
|
||||||
enum netadrtype_t
|
enum netadrtype_t
|
||||||
{
|
{
|
||||||
NA_BOT = 0x0,
|
NA_BOT = 0x0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user