From f9cf85f7144044d48c42f6f164fbb40d455155b4 Mon Sep 17 00:00:00 2001 From: Michael Oliver Date: Mon, 22 Dec 2025 11:59:19 +0000 Subject: [PATCH 1/2] feat(IW3 MP): refactor GSC method set and expand API --- codxe.vcxproj | 6 +- ...lient_fields.cpp => gsc_client_fields.cpp} | 24 ++- .../iw3/mp/components/gsc_client_fields.h | 21 ++ src/game/iw3/mp/components/gsc_methods.cpp | 180 ++++++++++++++++++ .../{g_client_fields.h => gsc_methods.h} | 8 +- src/game/iw3/mp/main.cpp | 114 +---------- src/game/iw3/mp/symbols.h | 6 +- 7 files changed, 237 insertions(+), 122 deletions(-) rename src/game/iw3/mp/components/{g_client_fields.cpp => gsc_client_fields.cpp} (85%) create mode 100644 src/game/iw3/mp/components/gsc_client_fields.h create mode 100644 src/game/iw3/mp/components/gsc_methods.cpp rename src/game/iw3/mp/components/{g_client_fields.h => gsc_methods.h} (58%) diff --git a/codxe.vcxproj b/codxe.vcxproj index 567da16..c99d244 100644 --- a/codxe.vcxproj +++ b/codxe.vcxproj @@ -90,8 +90,9 @@ - + + @@ -189,8 +190,9 @@ - + + diff --git a/src/game/iw3/mp/components/g_client_fields.cpp b/src/game/iw3/mp/components/gsc_client_fields.cpp similarity index 85% rename from src/game/iw3/mp/components/g_client_fields.cpp rename to src/game/iw3/mp/components/gsc_client_fields.cpp index 4da3ac2..eebf989 100644 --- a/src/game/iw3/mp/components/g_client_fields.cpp +++ b/src/game/iw3/mp/components/gsc_client_fields.cpp @@ -1,5 +1,5 @@ #include "pch.h" -#include "g_client_fields.h" +#include "gsc_client_fields.h" const unsigned int CLIENT_FIELD_MASK = 0xC000; @@ -10,16 +10,28 @@ namespace mp void ClientScr_SetEntityFlags(gclient_s *pSelf, const client_fields_s *pField) { - gentity_s *ent = &g_entities[g_clients - pSelf]; + gentity_s *ent = &g_entities[pSelf - g_clients]; ent->flags = Scr_GetInt(0); } void ClientScr_GetEntityFlags(gclient_s *pSelf, const client_fields_s *field) { - const gentity_s *ent = &g_entities[g_clients - pSelf]; + const gentity_s *ent = &g_entities[pSelf - g_clients]; Scr_AddInt(ent->flags); } +void ClientScr_GetForwardMove(gclient_s *pSelf, const client_fields_s *field) +{ + const client_t *cl = &svsHeader->clients[pSelf - g_clients]; + Scr_AddInt(cl->lastUsercmd.rightmove); +} + +void ClientScr_GetRightMove(gclient_s *pSelf, const client_fields_s *field) +{ + const client_t *cl = &svsHeader->clients[pSelf - g_clients]; + Scr_AddInt(cl->lastUsercmd.forwardmove); +} + client_fields_s client_fields_extended[] = { // Original fields {"name", 0, F_LSTRING, ClientScr_ReadOnly, ClientScr_GetName}, @@ -44,6 +56,8 @@ client_fields_s client_fields_extended[] = { {"noclip", 12456, F_INT, nullptr, nullptr}, {"ufo", 12460, F_INT, nullptr, nullptr}, {"entityflags", NULL, F_INT, ClientScr_SetEntityFlags, ClientScr_GetEntityFlags}, + {"forwardmove", NULL, F_INT, ClientScr_ReadOnly, ClientScr_GetForwardMove}, + {"rightmove", NULL, F_INT, ClientScr_ReadOnly, ClientScr_GetRightMove}, {nullptr, 0, F_INT, nullptr, nullptr}}; @@ -133,7 +147,7 @@ void Scr_GetEntityField_Hook(int entnum, int offset) } } -g_client_fields::g_client_fields() +gsc_client_fields::gsc_client_fields() { GScr_AddFieldsForClient_Detour = Detour(GScr_AddFieldsForClient, GScr_AddFieldsForClient_Hook); GScr_AddFieldsForClient_Detour.Install(); @@ -145,7 +159,7 @@ g_client_fields::g_client_fields() Scr_SetEntityField_Detour.Install(); } -g_client_fields::~g_client_fields() +gsc_client_fields::~gsc_client_fields() { GScr_AddFieldsForClient_Detour.Remove(); Scr_GetEntityField_Detour.Remove(); diff --git a/src/game/iw3/mp/components/gsc_client_fields.h b/src/game/iw3/mp/components/gsc_client_fields.h new file mode 100644 index 0000000..0437b50 --- /dev/null +++ b/src/game/iw3/mp/components/gsc_client_fields.h @@ -0,0 +1,21 @@ +#pragma once + +#include "pch.h" + +namespace iw3 +{ +namespace mp +{ +class gsc_client_fields : public Module +{ + public: + gsc_client_fields(); + ~gsc_client_fields(); + + const char *get_name() override + { + return "gsc_client_fields"; + }; +}; +} // namespace mp +} // namespace iw3 diff --git a/src/game/iw3/mp/components/gsc_methods.cpp b/src/game/iw3/mp/components/gsc_methods.cpp new file mode 100644 index 0000000..2f4cb72 --- /dev/null +++ b/src/game/iw3/mp/components/gsc_methods.cpp @@ -0,0 +1,180 @@ +// cod4x + +#include "pch.h" +#include "g_scr_main.h" +#include "gsc_methods.h" + +namespace iw3 +{ +namespace mp +{ + +// #define KEY_MASK_FIRE 1 +#define KEY_MASK_SPRINT 2 +// #define KEY_MASK_MELEE 4 +// #define KEY_MASK_RELOAD 16 +#define KEY_MASK_LEANLEFT 64 +#define KEY_MASK_LEANRIGHT 128 +// #define KEY_MASK_PRONE 256 +// #define KEY_MASK_CROUCH 512 +#define KEY_MASK_JUMP 1024 +// #define KEY_MASK_ADS_MODE 2048 +// #define KEY_MASK_TEMP_ACTION 4096 +#define KEY_MASK_HOLDBREATH 8192 +// #define KEY_MASK_FRAG 16384 +// #define KEY_MASK_SMOKE 32768 +#define KEY_MASK_NIGHTVISION 262144 +// #define KEY_MASK_ADS 524288 +// #define KEY_MASK_USE 8 +// #define KEY_MASK_USERELOAD 0x20 +// #define BUTTON_ATTACK KEY_MASK_FIRE + +int CL_IsKeyPressed(const int localClientNum, const char *keyName) +{ + const int keynum = Key_StringToKeynum(keyName); + if (keynum >= 0) + return playerKeys[0].keys[keynum].down; + else + return 0; +} + +void PlayerCmd_ButtonPressed(scr_entref_t entref) +{ + if (entref.classnum != 0) + Scr_ObjectError("not an entity"); + + char *button = Scr_GetString(0); + if (!button || !*button) + Scr_Error("usage: buttonPressed(