Skip to content

Commit 32a5c08

Browse files
committed
tests/TestPlayerInputs.py
## buttons'n'bindings and stuff in here, lets see. ## Check and report button states on player_jump and the following python captures ## python capture 'OnClientCommand' but not as game event ## python capture 'OnClientAbility1' but not as game event ## python capture 'OnClientAbility2' but not as game event ## python capture 'OnClientUltimate' but not as game event
1 parent 90258c6 commit 32a5c08

File tree

9 files changed

+188
-56
lines changed

9 files changed

+188
-56
lines changed

PyPlugins/pyplugins.ini

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@
2323
## event 'OnPlayerSpawn'
2424
## event 'OnPlayerSpawn_post'
2525

26-
tests/TestPlayerJump.py
26+
#tests/TestPlayerJump.py
2727
## event 'OnPlayerJump'
2828
## event 'OnPlayerLand'
2929
## event 'OnPlayerAirborn'
3030

3131
tests/TestPlayerInputs.py
3232
## buttons'n'bindings and stuff in here, lets see.
33+
## Check and report button states on player_jump and the following python captures
34+
## python capture 'OnClientCommand' but not as game event
35+
## python capture 'OnClientAbility1' but not as game event
36+
## python capture 'OnClientAbility2' but not as game event
37+
## python capture 'OnClientUltimate' but not as game event
38+
39+
3340

3441
##junk below is old work to pull from while making
3542
##'good' working examples above
3643
#SampleEvents.py
3744
#ManyRaces/AdventureTest.py
3845

39-
adventure/adventure.py
46+
Adventure/Adventure.py

PyPlugins/tests/TestPlayerInputs.py

Lines changed: 82 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,95 @@ class TestPlayerInputs:
1919
def OnPluginLoad(self):
2020
alog("")
2121
pass
22-
23-
def OnGameFrame(self,
24-
simulating: bool,
25-
bFirstTick: bool,
26-
bLastTick: bool
27-
):
28-
#we will be only reporting button presses on frames where the state changed.
29-
pass
30-
def OnPlayer______(self,
31-
_slot: int
32-
):
33-
alog("START")
22+
def _checkButtonStates(self, _slot):
3423
try:
3524
alog("_slot: " + str(_slot))
3625
player = ADVPlayer(_slot)
3726
if (player.IsValid()):
38-
name = player.GetName()
39-
if (name):
40-
alog(name + " is airborn!")
41-
else:
42-
alog("name was invalid")
27+
bstates = player.GetButtonStates()
28+
29+
#incomplete list, missing weapon select 1,2,3,4 (eg)
30+
IN_ATTACK = 1 << 0
31+
alog(str(bstates & IN_ATTACK) + " IN_ATTACK")
32+
IN_JUMP = 1 << 1
33+
alog(str(bstates & IN_JUMP) + " IN_JUMP")
34+
IN_DUCK = 1 << 2
35+
alog(str(bstates & IN_DUCK) + " IN_DUCK")
36+
IN_FORWARD = 1 << 3
37+
alog(str(bstates & IN_FORWARD) + " IN_FORWARD")
38+
IN_BACKWARD = 1 << 4
39+
alog(str(bstates & IN_BACKWARD) + " IN_BACKWARD")
40+
IN_USE = 1 << 5
41+
alog(str(bstates & IN_USE) + " IN_USE")
42+
43+
#6
44+
#7
45+
#8
46+
47+
IN_MOVELEFT = 1 << 9
48+
alog(str(bstates & IN_MOVELEFT) + " IN_MOVELEFT")
49+
IN_MOVERIGHT = 1 << 10
50+
alog(str(bstates & IN_MOVERIGHT) + " IN_MOVERIGHT")
51+
IN_ATTACK2 = 1 << 11
52+
alog(str(bstates & IN_ATTACK2) + " IN_ATTACK2")
53+
54+
#12
55+
56+
IN_RELOAD = 1 << 13
57+
alog(str(bstates & IN_RELOAD) + " IN_RELOAD")
58+
59+
#14
60+
#15
61+
62+
IN_SPRINT = 1 << 16
63+
alog(str(bstates & IN_SPRINT) + " IN_SPRINT")
64+
65+
IN_SCORE = 0x200000000
66+
alog(str(bstates & IN_SCORE) + " IN_SCORE")
67+
IN_LOOK_AT_WEAPON = 0x800000000
68+
alog(str(bstates & IN_LOOK_AT_WEAPON) + " IN_LOOK_AT_WEAPON")
69+
4370
except Exception as e:
4471
alog(e)
45-
alog(traceback.format_exc())
72+
alog(traceback.format_exc())
73+
def OnClientCommand(self,
74+
_slot: int,
75+
_cmd: str):
76+
player = ADVPlayer(_slot)
77+
if (player.IsValid()):
78+
self._checkButtonStates(self, _slot)
79+
alog(player.GetName() + " used a ClientCommand: {0}".format(_cmd))
80+
pass
81+
def OnClientAbility1(self,
82+
_slot: int
83+
):
84+
player = ADVPlayer(_slot)
85+
if (player.IsValid()):
86+
self._checkButtonStates(self, _slot)
87+
alog(player.GetName() + " used Ability1!")
88+
pass
89+
def OnClientAbility2(self,
90+
_slot: int
91+
):
92+
player = ADVPlayer(_slot)
93+
if (player.IsValid()):
94+
self._checkButtonStates(self, _slot)
95+
alog(player.GetName() + " used Ability2!")
96+
pass
97+
def OnClientUltimate(self,
98+
_slot: int
99+
):
100+
player = ADVPlayer(_slot)
101+
if (player.IsValid()):
102+
self._checkButtonStates(self, _slot)
103+
alog(player.GetName() + " used Ultimate!")
104+
pass
105+
def OnPlayerJump(self,
106+
_slot: int
107+
):
108+
alog("START")
109+
self._checkButtonStates(self, _slot)
46110
alog("END")
47111
pass
48112

49113

50-
'''button_flags =
51-
{
52-
"IN_NONE": 0x0,
53-
"IN_ALL": 0xffffffffffffffff,
54-
"IN_ATTACK": 0x1,
55-
"IN_JUMP": 0x2,
56-
"IN_DUCK": 0x4,
57-
"IN_FORWARD": 0x8,
58-
"IN_BACK": 0x10,
59-
"IN_USE": 0x20,
60-
"IN_TURNLEFT": 0x80,
61-
"IN_TURNRIGHT": 0x100,
62-
"IN_MOVELEFT": 0x200,
63-
"IN_MOVERIGHT": 0x400,
64-
"IN_ATTACK2": 0x800,
65-
"IN_RELOAD": 0x2000,
66-
"IN_SPEED": 0x10000,
67-
"IN_JOYAUTOSPRINT": 0x20000,
68-
69-
}'''
70-

cfg/cs2fixes/cs2fixes.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Feature cvars
2-
cs2f_commands_enable 0 // Whether to enable chat commands
2+
cs2f_commands_enable 1 // Whether to enable chat commands
33
cs2f_admin_commands_enable 0 // Whether to enable admin chat commands
44
cs2f_admin_immunity 0 // Mode for which admin immunity system targetting allows: 0 - strictly lower, 1 - equal to or lower, 2 - ignore immunity levels
55
cs2f_weapons_enable 0 // Whether to enable weapon commands

src/PyModule.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ PYBIND11_EMBEDDED_MODULE(Source2Py, m) {
118118
;
119119
}
120120

121+
/*
122+
//CCommand
123+
{
124+
//went another route and not using.
125+
py::class_<CCommand>(m, "CCommand")
126+
.def("GetArgCount", &CCommand::ArgC, "() -> int")
127+
.def("GetMaxCommandLength", &CCommand::MaxCommandLength, "() -> int")
128+
.def("GetArgS", &CCommand::ArgS, "() -> const char*")
129+
.def("GetCommandString", &CCommand::GetCommandString, "() -> const char*")
130+
131+
.def("GetArg", &CCommand::Arg, "(int index) -> const char*")
132+
133+
.def("FindArg", &CCommand::FindArg, "(const char* pName) -> int")
134+
.def("FindArgInt", &CCommand::FindArgInt, "(const char* pName, int nDefaultVal) -> int")
135+
136+
.def("__getitem__", &CCommand::operator[])
137+
//.def("GetArgV", &CCommand::ArgV) //idk what this one is atm.
138+
;
139+
}
140+
*/
141+
121142
//ADVAPI
122143
{
123144
py::class_<ADVAPI>(m, "ADVPlayer")
@@ -134,7 +155,7 @@ PYBIND11_EMBEDDED_MODULE(Source2Py, m) {
134155
.def("GetIndex", &ADVAPI::GetIndex)
135156
.def("IsOnGround", &ADVAPI::IsOnGround)
136157
.def("IsOnLadder", &ADVAPI::IsOnLadder)
137-
.def("GetButtons", &ADVAPI::GetButtonStates)
158+
.def("GetButtonStates", &ADVAPI::GetButtonStates)
138159
.def("test",
139160
[](ADVAPI& self) -> int
140161
//Tristen, don't delete this, you'll eventually forget again.

src/PyPlugin.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace Source2Py {
7171
PyRuntime::ExecuteObjectMethod(m_PluginObject, "OnClientSettingsChanged", playerSlot);
7272
}
7373

74-
void PyPlugin::PyOnClientConnected(
74+
void PyPlugin::PyClientConnected(
7575
int playerSlot,
7676
const char* name,
7777
uint64_t xuid,
@@ -132,4 +132,23 @@ namespace Source2Py {
132132
PyRuntime::ExecuteObjectMethod(m_PluginObject, "OnPlayerAirborn", playerSlot);
133133
}
134134

135+
void PyPlugin::PyClientCommand(int playerSlot, const char* command)
136+
{
137+
PyRuntime::ExecuteObjectMethod(m_PluginObject, "OnClientCommand", playerSlot, command);
138+
}
139+
140+
void PyPlugin::PyClientAbility1(int playerSlot)
141+
{
142+
PyRuntime::ExecuteObjectMethod(m_PluginObject, "OnClientAbility1", playerSlot);
143+
}
144+
145+
void PyPlugin::PyClientAbility2(int playerSlot)
146+
{
147+
PyRuntime::ExecuteObjectMethod(m_PluginObject, "OnClientAbility2", playerSlot);
148+
}
149+
150+
void PyPlugin::PyClientUltimate(int playerSlot)
151+
{
152+
PyRuntime::ExecuteObjectMethod(m_PluginObject, "OnClientUltimate", playerSlot);
153+
}
135154
} // namespace Source2Py

src/PyPlugin.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "PyRuntime.h"
4+
#include "convar.h"
45

56
#include <igameevents.h>
67

@@ -18,23 +19,31 @@ namespace Source2Py {
1819
void Unload();
1920

2021
// Python plugin hooks
21-
void PyGameFrame(bool simulating, bool firstTick, bool lastTick);
2222
void PyClientActive(int playerSlot, bool loadGame, const char* name, uint64_t xuid);
2323
void PyClientDisconnect(int playerSlot, int reason, const char* name, uint64_t xuid, const char* networkID);
24+
void PyClientConnected(int playerSlot, const char* name, uint64_t xuid, const char* networkID, const char* address, bool fakePlayer);
2425
void PyClientPutInServer(int playerSlot, char const* name, int type, uint64_t xuid);
2526
void PyClientSettingsChanged(int playerSlot);
26-
void PyOnClientConnected(int playerSlot, const char* name, uint64_t xuid, const char* networkID, const char* address, bool fakePlayer);
27-
//void ClientCommand(int playerSlot, const CCommand& _cmd); (todo: port CCommand)
2827
void PyFireGameEvent(IGameEvent* event);
28+
void PyGameFrame(bool simulating, bool firstTick, bool lastTick);
29+
void PyPlayerActivate(int playerSlot);
30+
31+
void PyClientCommand(int playerSlot, const char* command);
32+
void PyClientAbility1(int playerSlot);
33+
void PyClientAbility2(int playerSlot);
34+
void PyClientUltimate(int playerSlot);
35+
2936
void PyPlayerHurt(IGameEvent* event);
3037
void PyPlayerDeath(IGameEvent* event);
38+
39+
void PyPlayerJump(int playerSlot);
40+
void PyPlayerAirborn(int playerSlot);
41+
void PyPlayerLand(int playerSlot);
42+
3143
void PyPlayerSpawn(int playerSlot);
3244
void PyPlayerSpawn_post(int playerSlot);
3345
void PyPlayerSpawned(int playerSlot);
34-
void PyPlayerActivate(int playerSlot);
35-
void PyPlayerJump(int playerSlot);
36-
void PyPlayerLand(int playerSlot);
37-
void PyPlayerAirborn(int playerSlot);
46+
3847

3948
bool IsValid() const { return m_Valid; }
4049

src/adventuremod.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "adventuremod.h"
22

3+
#include "commands.h"
4+
#include "cs2fixes.h"
5+
36
int ADVAPI::GetHealth()
47
{
58
CBaseEntity* pawn = GetPawn();
@@ -66,6 +69,28 @@ uint64* ADVAPI::GetButtonStates()
6669
CPlayer_MovementServices* ms = base->m_pMovementServices();
6770
// m_pButtonStates[0] is the mask of currently pressed buttons
6871
// m_pButtonStates[1] is the mask of buttons that changed in the current frame
69-
uint64* temp = ms->m_nButtons().m_pButtonStates();
70-
return temp;
71-
}
72+
73+
//uint64* temp = ms->m_nButtons().m_pButtonStates();
74+
//return temp;
75+
76+
return ms->m_nButtons().m_pButtonStates();
77+
}
78+
79+
CON_COMMAND_F(ability1, "Technique bound to ability1", FCVAR_NONE)
80+
{
81+
for (auto& plugin : g_CS2Fixes.m_Plugins)
82+
plugin.PyClientAbility1(context.GetPlayerSlot().Get());
83+
return;
84+
}
85+
CON_COMMAND_F(ability2, "Technique bound to ability2", FCVAR_NONE)
86+
{
87+
for (auto& plugin : g_CS2Fixes.m_Plugins)
88+
plugin.PyClientAbility2(context.GetPlayerSlot().Get());
89+
return;
90+
}
91+
CON_COMMAND_F(ultimate, "Technique bound to ultimate", FCVAR_NONE)
92+
{
93+
for (auto& plugin : g_CS2Fixes.m_Plugins)
94+
plugin.PyClientUltimate(context.GetPlayerSlot().Get());
95+
return;
96+
}

src/cs2fixes.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,10 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool
442442
});
443443

444444
// run our cfg
445-
g_pEngineServer2->ServerCommand("exec cs2fixes/cs2fixes");
445+
// remember for later, exec looks in ~/csgo/cfg/ for stuff.
446+
// ~/csgo/cfg/cs2fixes/cs2fixes.cfg <-- move to here
447+
// ~/csgo/addons/cs2fixes/cfg/cs2fixes/cs2fixes.cfg <-- from here
448+
g_pEngineServer2->ServerCommand("exec CS2Fixes/cs2fixes");
446449

447450
srand(time(0));
448451

@@ -820,6 +823,9 @@ void CS2Fixes::Hook_ClientCommand(CPlayerSlot slot, const CCommand& args)
820823
ZR_Hook_ClientCommand_JoinTeam(slot, args);
821824
RETURN_META(MRES_SUPERCEDE);
822825
}
826+
827+
for (auto& plugin : g_CS2Fixes.m_Plugins)
828+
plugin.PyClientCommand(slot.Get(), args.GetCommandString());
823829
}
824830

825831
void CS2Fixes::Hook_ClientSettingsChanged(CPlayerSlot slot)
@@ -1213,6 +1219,8 @@ void CS2Fixes::OnLevelInit(char const* pMapName,
12131219
g_iRoundNum = 0;
12141220

12151221
// run our cfg
1222+
//remember for later, this ~/game/csgo/cfg/cs2fixes/cs2fixes.cfg being executed.
1223+
//you'll need to move it from ~/addons/cs2fixes/cfg/cs2fixes/cs2fixes.cfg if you want it found.
12161224
g_pEngineServer2->ServerCommand("exec cs2fixes/cs2fixes");
12171225

12181226
// Run map cfg (if present)

src/playermanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ bool CPlayerManager::OnClientConnected(CPlayerSlot slot, uint64 xuid, const char
775775
name = pc->GetPlayerName();
776776

777777
for (auto& plugin : g_CS2Fixes.m_Plugins)
778-
plugin.PyOnClientConnected(
778+
plugin.PyClientConnected(
779779
slot.Get(),
780780
name,
781781
xuid,

0 commit comments

Comments
 (0)