diff --git a/README.md b/README.md index 77e69a3..3f8a6b0 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ GSC Entity fields: - `self.noclip = ` - toggles noclip - `self.ufo = ` - toggles ufomode - `self.entityflags = ` - gentity flags e.g. `1` is godmode +- `self.forwardmove ` - **Read-Only** Player's forward/backward movement input (-127 = full backward, 127 = full forward, 0 = no input) +- `self.rightmove ` - **Read-Only** Player's left/right movement input (-127 = full left, 127 = full right, 0 = no input) GSC Functions: @@ -71,12 +73,27 @@ GSC Functions: GSC Methods: -- `HoldBreathButtonPressed` -- `JumpButtonPressed` -- `NightVisionButtonPressed` -- `SetVelocity` - Changes current player velocity. `self setVelocity((0, 0, 300)); // Go up.` -- `CloneBrushModelToScriptModel` -- **HOST ONLY** `ButtonPressed` e.g. `self ButtonPressed("DPAD_DOWN")` - See **keynames** below for valid button identifiers. +- `ButtonPressed` - **HOST ONLY** - Check if a specific button is pressed. + - Usage: `self ButtonPressed("DPAD_DOWN")` + - See **keynames** below for valid button identifiers. +- `SprintBreathButtonPressed` - Check if the sprint button is pressed. +- `LeanLeftButtonPressed` - Check if the lean left button is pressed. +- `LeanRightButtonPressed` - Check if the lean right button is pressed. +- `JumpButtonPressed` - Check if the jump button is pressed. +- `HoldBreathButtonPressed` - Check if the hold breath button is pressed. +- `NightVisionButtonPressed` - Check if the night vision button is pressed. +- `ForwardButtonPressed` - Check if the player is moving forward (left stick up). +- `BackButtonPressed` - Check if the player is moving backward (left stick down). +- `LeftButtonPressed` - Check if the player is moving left (left stick left). +- `RightButtonPressed` - Check if the player is moving right (left stick right). +- `SetVelocity` - Changes current player velocity. + + - Usage: `self setVelocity((0, 0, 300)); // Go up.` + +- `CloneBrushModelToScriptModel` - Clones a brush model's geometry to a script model entity. + - Usage: `scriptModel CloneBrushModelToScriptModel(brushEntity);` +- `SetBrushModel` - Sets an entity's brush model by index. + - Usage: `entity SetBrushModel(index);`
keynames 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..a9d1e3b --- /dev/null +++ b/src/game/iw3/mp/components/gsc_methods.cpp @@ -0,0 +1,201 @@ +// 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(