Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ GSC Entity fields:

- `self.noclip = <bool>` - toggles noclip
- `self.ufo = <bool>` - toggles ufomode
- `self.god = <bool>` - toggles godmode
- `self.entityflags = <int>` - gentity flags e.g. `1` is godmode

GSC Functions:

Expand All @@ -76,6 +76,35 @@ GSC Methods:
- `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.

<details>
<summary>keynames</summary>

```
BUTTON_A
BUTTON_B
BUTTON_X
BUTTON_Y
BUTTON_LSHLDR
BUTTON_RSHLDR
BUTTON_START
BUTTON_BACK
BUTTON_LSTICK
BUTTON_RSTICK
BUTTON_RTRIG
BUTTON_LTRIG
DPAD_UP
DPAD_DOWN
DPAD_LEFT
DPAD_RIGHT
APAD_UP
APAD_DOWN
APAD_LEFT
APAD_RIGHT
```

</details>

### Loading single-player maps

Expand Down
28 changes: 28 additions & 0 deletions src/game/iw3/mp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,33 @@ void PlayerCmd_GetRightMove(scr_entref_t entref)
Scr_AddInt(cl->lastUsercmd.rightmove);
}

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: <client> buttonPressed(<button name>)");

// toupper
for (char *p = button; *p; p++)
if (*p >= 'a' && *p <= 'z')
*p -= 32;

const int keypressed = CL_IsKeyPressed(0, button);
return Scr_AddInt(keypressed);
}

void PlayerCmd_SetVelocity(scr_entref_t entref)
{
if (entref.classnum != 0)
Expand Down Expand Up @@ -1596,6 +1623,7 @@ IW3_MP_Plugin::IW3_MP_Plugin()
Scr_AddMethod("getrightmove", PlayerCmd_GetRightMove, 0);
Scr_AddMethod("setvelocity", PlayerCmd_SetVelocity, 0);
Scr_AddMethod("nightvisionbuttonpressed", PlayerCmd_NightVisionButtonPressed, 0);
Scr_AddMethod("buttonpressed", PlayerCmd_ButtonPressed, 0);

SV_ClientThinkDetour = Detour(SV_ClientThink, SV_ClientThinkHook);
SV_ClientThinkDetour.Install();
Expand Down
35 changes: 35 additions & 0 deletions src/game/iw3/mp/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2674,6 +2674,41 @@ static_assert(sizeof(cgs_t) == 15972, "");
#define YAW 1
#define ROLL 2

struct field_t
{
int cursor;
int scroll;
int drawWidth;
int widthInPixels;
float charHeight;
int fixedSize;
char buffer[256];
};

struct KeyState
{
int down;
int repeats;
const char *binding;
};

enum LocSelInputState : __int32
{
LOC_SEL_INPUT_NONE = 0x0,
LOC_SEL_INPUT_CONFIRM = 0x1,
LOC_SEL_INPUT_CANCEL = 0x2,
};

struct PlayerKeyState
{
field_t chatField;
int chat_team;
int overstrikeMode;
int anyKeyDown;
KeyState keys[256];
LocSelInputState locSelInputState;
};

} // namespace mp
} // namespace iw3

Expand Down
5 changes: 5 additions & 0 deletions src/game/iw3/mp/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ static auto Scr_AddSourceBuffer =
reinterpret_cast<char *(*)(const char *filename, const char *extFilename, const char *codePos, bool archive)>(
0x822212C0);

typedef int (*Key_StringToKeynum_t)(const char *str);
static Key_StringToKeynum_t Key_StringToKeynum = reinterpret_cast<Key_StringToKeynum_t>(0x822D69A8);

static PlayerKeyState *playerKeys = reinterpret_cast<PlayerKeyState *>(0x8242AB38);

// Variables
static auto cgArray = reinterpret_cast<cg_s **>(0x823F28A0);
static auto cgsArray = reinterpret_cast<cgs_t *>(0x823F2890);
Expand Down