forked from ValveSoftware/source-sdk-2013
-
Notifications
You must be signed in to change notification settings - Fork 6
/
_gamerules.py
127 lines (101 loc) · 4.99 KB
/
_gamerules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from srcpy.module_generators import SemiSharedModuleGenerator
from pyplusplus.module_builder import call_policies
from pygccxml.declarations import matchers
class GameRules(SemiSharedModuleGenerator):
module_name = '_gamerules'
split = True
required_files = [
'$SRCDIR\game\shared\python\srcpy_gamerules.cpp',
'$SRCDIR\game\shared\python\srcpy_gamerules.h',
]
module_symbols = ['SRCPY_MOD_GAMERULES']
@property
def files(self):
files = [
'cbase.h',
'gamerules.h',
'multiplay_gamerules.h',
'singleplay_gamerules.h',
'teamplay_gamerules.h',
'srcpy_gamerules.h',
'ammodef.h',
'#items.h',
'$takedamageinfo.h',
]
if 'HL2MP' in self.symbols:
files.extend([
'#hl2mp/hl2mp_player.h',
'hl2mp/hl2mp_gamerules.h',
])
return files
def Parse(self, mb):
# Exclude everything by default
mb.decls().exclude()
gamerules = [
('CGameRules', 'C_GameRules', True),
('CMultiplayRules', 'C_MultiplayRules', True),
('CSingleplayRules', 'C_SingleplayRules', True),
('CTeamplayRules', 'C_TeamplayRules', False),
]
if 'HL2MP' in self.symbols:
gamerules.append(('CHL2MPRules', 'C_HL2MPRules', False))
for gamerulename, clientgamerulename, baseonly in gamerules:
cls_name = gamerulename if self.isserver else clientgamerulename
cls = mb.class_(cls_name)
cls.include()
if not baseonly:
# Used internally
cls.member_functions('GetPySelf', allow_empty=True).exclude()
cls.add_wrapper_code(
'virtual PyObject *GetPySelf() const { return boost::python::detail::wrapper_base_::get_owner(*this); }'
)
else:
cls.no_init = True
# Always use server class name
cls.rename(gamerulename)
mb.member_functions('ShouldCollide').virtuality = 'not virtual'
mb.member_functions('GetAmmoDamage').virtuality = 'not virtual' # Just modify the ammo table when needed...
mb.member_functions('NetworkStateChanged').exclude()
if self.isserver:
if self.settings.branch == 'source2013':
mb.member_function('TacticalMissionManagerFactory').exclude()
if self.settings.branch == 'swarm':
mb.member_functions('DoFindClientInPVS').exclude()
mb.member_functions('IsTopDown').virtuality = 'not virtual'
mb.member_functions('ForceSplitScreenPlayersOnToSameTeam').virtuality = 'not virtual'
# Excludes
mb.member_functions('VoiceCommand').exclude()
# Remove virtuality from or include some unneeded functions (would just slow down things)
mb.member_functions('FrameUpdatePostEntityThink').virtuality = 'not virtual' # Calls Think
mb.member_functions('EndGameFrame').virtuality = 'not virtual'
mb.member_functions('FAllowFlashlight', lambda d: d.virtuality == 'virtual').virtuality = 'not virtual'
if 'HL2MP' in self.symbols:
mb.member_functions('GetHL2MPViewVectors').exclude()
if self.isclient:
mb.member_functions('RestartGame').exclude()
mb.member_functions('CheckAllPlayersReady').exclude()
mb.member_functions('CheckRestartGame').exclude()
mb.member_functions('CleanUpMap').exclude()
# Temp excludes
mb.member_functions('GetEncryptionKey').exclude()
mb.member_functions('GetViewVectors').exclude()
# Call policies
mb.member_functions('GetNextBestWeapon').call_policies = call_policies.return_value_policy(call_policies.return_by_value)
# Rename PyGameRules to just GameRules
mb.free_function('PyGameRules').include()
mb.free_function('PyGameRules').rename('GameRules')
# Installing the gamerules
mb.free_function('PyInstallGameRules').include()
mb.free_function('PyInstallGameRules').rename('InstallGameRules')
# CAmmoDef
cls = mb.class_('CAmmoDef')
cls.include()
cls.member_function('GetAmmoOfIndex').exclude()
cls.variable('m_AmmoType').exclude()
cls.variable('m_nAmmoIndex').rename('ammoindex')
mb.free_function('GetAmmoDef').include()
mb.free_function('GetAmmoDef').call_policies = call_policies.return_value_policy(call_policies.reference_existing_object)
# Remove any protected function
mb.calldefs( matchers.access_type_matcher_t('protected') ).exclude()
# Finally apply common rules to all includes functions and classes, etc.
self.ApplyCommonRules(mb)