Skip to content

Commit d9b7b6b

Browse files
committed
Changed Player's base classes order to correct the MRO
1 parent 8506e1f commit d9b7b6b

7 files changed

Lines changed: 438 additions & 4 deletions

File tree

addons/source-python/data/source-python/entities/csgo/CBaseCombatWeapon.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@ srv_check = False
1818

1919
primary_ammo_count = m_iPrimaryReserveAmmoCount
2020
secondary_ammo_count = m_iSecondaryReserveAmmoCount
21-
ammoprop = m_iPrimaryAmmoType
22-
secondary_fire_ammoprop = m_iSecondaryAmmoType

addons/source-python/packages/source-python/players/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
# =============================================================================
7575
# >> CLASSES
7676
# =============================================================================
77-
class Player(Entity, PlayerMixin):
77+
class Player(PlayerMixin, Entity):
7878
"""Class used to interact directly with players."""
7979

8080
def __init__(self, index):

addons/source-python/packages/source-python/weapons/_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Entities
1010
from entities.entity import Entity
1111
# Weapons
12+
from _weapons._entity import WeaponMixin
1213
from weapons.manager import weapon_manager
1314

1415

@@ -23,7 +24,7 @@
2324
# =============================================================================
2425
# >> CLASSES
2526
# =============================================================================
26-
class Weapon(Entity):
27+
class Weapon(WeaponMixin, Entity):
2728
"""Allows easy usage of the weapon's attributes."""
2829

2930
def _validate_clip(self):

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,14 @@ Set(SOURCEPYTHON_STUDIO_MODULE_SOURCES
451451
Set(SOURCEPYTHON_WEAPONS_MODULE_HEADERS
452452
core/modules/weapons/${SOURCE_ENGINE}/weapons_constants_wrap.h
453453
core/modules/weapons/${SOURCE_ENGINE}/weapons_scripts_wrap.h
454+
core/modules/weapons/weapons_entity.h
454455
)
455456

456457
Set(SOURCEPYTHON_WEAPONS_MODULE_SOURCES
457458
core/modules/weapons/weapons_constants_wrap.cpp
458459
core/modules/weapons/weapons_scripts_wrap.cpp
460+
core/modules/weapons/weapons_entity.cpp
461+
core/modules/weapons/weapons_entity_wrap.cpp
459462
)
460463

461464
# ------------------------------------------------------------------
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/**
2+
* =============================================================================
3+
* Source Python
4+
* Copyright (C) 2012-2016 Source Python Development Team. All rights reserved.
5+
* =============================================================================
6+
*
7+
* This program is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, version 3.0, as published by the
9+
* Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* As a special exception, the Source Python Team gives you permission
20+
* to link the code of this program (as well as its derivative works) to
21+
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
22+
* by the Valve Corporation. You must obey the GNU General Public License in
23+
* all respects for all other code used. Additionally, the Source.Python
24+
* Development Team grants this exception to all derivative works.
25+
*/
26+
27+
// ============================================================================
28+
// >> INCLUDES
29+
// ============================================================================
30+
// Source.Python
31+
#include "weapons_entity.h"
32+
33+
34+
// ============================================================================
35+
// >> PlayerMixin
36+
// ============================================================================
37+
boost::shared_ptr<WeaponMixin> WeaponMixin::__init__(unsigned int uiEntityIndex)
38+
{
39+
CBaseEntityWrapper* pEntity = (CBaseEntityWrapper*) ExcBaseEntityFromIndex(uiEntityIndex);
40+
41+
// TODO
42+
//if (!pEntity->IsPlayer())
43+
// BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Index '%d' is not a valid weapon.", uiEntityIndex);
44+
45+
return WeaponMixin::wrap(pEntity->GetBaseEntity());
46+
}
47+
48+
boost::shared_ptr<WeaponMixin> WeaponMixin::wrap(CBaseEntity* pEntity)
49+
{
50+
return boost::shared_ptr<WeaponMixin>(
51+
(WeaponMixin *) pEntity,
52+
&NeverDeleteDeleter<WeaponMixin *>
53+
);
54+
}
55+
56+
57+
// CBaseCombatWeapon
58+
float WeaponMixin::GetNextAttack()
59+
{
60+
static int offset = FindNetworkPropertyOffset("LocalActiveWeaponData.m_flNextPrimaryAttack");
61+
return GetNetworkPropertyByOffset<float>(offset);
62+
}
63+
64+
void WeaponMixin::SetNextAttack(float value)
65+
{
66+
static int offset = FindNetworkPropertyOffset("LocalActiveWeaponData.m_flNextPrimaryAttack");
67+
SetNetworkPropertyByOffset<float>(offset, value);
68+
}
69+
70+
71+
float WeaponMixin::GetNextSecondaryFireAttack()
72+
{
73+
static int offset = FindNetworkPropertyOffset("LocalActiveWeaponData.m_flNextSecondaryAttack");
74+
return GetNetworkPropertyByOffset<float>(offset);
75+
}
76+
77+
void WeaponMixin::SetNextSecondaryFireAttack(float value)
78+
{
79+
static int offset = FindNetworkPropertyOffset("LocalActiveWeaponData.m_flNextSecondaryAttack");
80+
SetNetworkPropertyByOffset<float>(offset, value);
81+
}
82+
83+
84+
int WeaponMixin::GetAmmoProp()
85+
{
86+
static int offset = FindNetworkPropertyOffset("LocalWeaponData.m_iPrimaryAmmoType");
87+
return GetNetworkPropertyByOffset<int>(offset);
88+
}
89+
90+
void WeaponMixin::SetAmmoProp(int value)
91+
{
92+
static int offset = FindNetworkPropertyOffset("LocalWeaponData.m_iPrimaryAmmoType");
93+
SetNetworkPropertyByOffset<int>(offset, value);
94+
}
95+
96+
97+
int WeaponMixin::GetSecondaryFireAmmoProp()
98+
{
99+
static int offset = FindNetworkPropertyOffset("LocalWeaponData.m_iSecondaryAmmoType");
100+
return GetNetworkPropertyByOffset<int>(offset);
101+
}
102+
103+
void WeaponMixin::SetSecondaryFireAmmoProp(int value)
104+
{
105+
static int offset = FindNetworkPropertyOffset("LocalWeaponData.m_iSecondaryAmmoType");
106+
SetNetworkPropertyByOffset<int>(offset, value);
107+
}
108+
109+
110+
int WeaponMixin::GetOwnerHandle()
111+
{
112+
static int offset = FindNetworkPropertyOffset("m_hOwner");
113+
return GetNetworkPropertyByOffset<int>(offset);
114+
}
115+
116+
void WeaponMixin::SetOwnerHandle(int value)
117+
{
118+
static int offset = FindNetworkPropertyOffset("m_hOwner");
119+
SetNetworkPropertyByOffset<int>(offset, value);
120+
}
121+
122+
123+
int WeaponMixin::GetClip()
124+
{
125+
static int offset = FindDatamapPropertyOffset("m_iClip1");
126+
return GetNetworkPropertyByOffset<int>(offset);
127+
}
128+
129+
void WeaponMixin::SetClip(int value)
130+
{
131+
static int offset = FindDatamapPropertyOffset("m_iClip1");
132+
SetNetworkPropertyByOffset<int>(offset, value);
133+
}
134+
135+
136+
int WeaponMixin::GetSecondaryFireClip()
137+
{
138+
static int offset = FindDatamapPropertyOffset("m_iClip2");
139+
return GetNetworkPropertyByOffset<int>(offset);
140+
}
141+
142+
void WeaponMixin::SetSecondaryFireClip(int value)
143+
{
144+
static int offset = FindDatamapPropertyOffset("m_iClip2");
145+
SetNetworkPropertyByOffset<int>(offset, value);
146+
}
147+
148+
149+
int WeaponMixin::GetFlipViewModel()
150+
{
151+
static int offset = FindNetworkPropertyOffset("LocalWeaponData.m_bFlipViewModel");
152+
return GetNetworkPropertyByOffset<int>(offset);
153+
}
154+
155+
void WeaponMixin::SetFlipViewModel(int value)
156+
{
157+
static int offset = FindNetworkPropertyOffset("LocalWeaponData.m_bFlipViewModel");
158+
SetNetworkPropertyByOffset<int>(offset, value);
159+
}
160+
161+
162+
int WeaponMixin::GetWorldModelIndex()
163+
{
164+
static int offset = FindNetworkPropertyOffset("m_iWorldModelIndex");
165+
return GetNetworkPropertyByOffset<int>(offset);
166+
}
167+
168+
void WeaponMixin::SetWorldModelIndex(int value)
169+
{
170+
static int offset = FindNetworkPropertyOffset("m_iWorldModelIndex");
171+
SetNetworkPropertyByOffset<int>(offset, value);
172+
}
173+
174+
175+
// CS:GO
176+
int WeaponMixin::GetPrimaryAmmoCount()
177+
{
178+
static int offset = FindNetworkPropertyOffset("m_iPrimaryReserveAmmoCount");
179+
return GetNetworkPropertyByOffset<int>(offset);
180+
}
181+
182+
void WeaponMixin::SetPrimaryAmmoCount(int value)
183+
{
184+
static int offset = FindNetworkPropertyOffset("m_iPrimaryReserveAmmoCount");
185+
SetNetworkPropertyByOffset<int>(offset, value);
186+
}
187+
188+
189+
int WeaponMixin::GetSecondaryAmmoCount()
190+
{
191+
static int offset = FindNetworkPropertyOffset("m_iSecondaryReserveAmmoCount");
192+
return GetNetworkPropertyByOffset<int>(offset);
193+
}
194+
195+
void WeaponMixin::SetSecondaryAmmoCount(int value)
196+
{
197+
static int offset = FindNetworkPropertyOffset("m_iSecondaryReserveAmmoCount");
198+
SetNetworkPropertyByOffset<int>(offset, value);
199+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* =============================================================================
3+
* Source Python
4+
* Copyright (C) 2012-2015 Source Python Development Team. All rights reserved.
5+
* =============================================================================
6+
*
7+
* This program is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, version 3.0, as published by the
9+
* Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* As a special exception, the Source Python Team gives you permission
20+
* to link the code of this program (as well as its derivative works) to
21+
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
22+
* by the Valve Corporation. You must obey the GNU General Public License in
23+
* all respects for all other code used. Additionally, the Source.Python
24+
* Development Team grants this exception to all derivative works.
25+
*/
26+
27+
#ifndef _WEAPONS_ENTITY_H
28+
#define _WEAPONS_ENTITY_H
29+
30+
//-----------------------------------------------------------------------------
31+
// Includes.
32+
//-----------------------------------------------------------------------------
33+
#include "boost/python.hpp"
34+
using namespace boost::python;
35+
36+
#include "modules/entities/entities_entity.h"
37+
38+
39+
//-----------------------------------------------------------------------------
40+
// CBaseEntity extension class for players.
41+
//-----------------------------------------------------------------------------
42+
class WeaponMixin: public CBaseEntityWrapper
43+
{
44+
public:
45+
static boost::shared_ptr<WeaponMixin> __init__(unsigned int uiEntityIndex);
46+
static boost::shared_ptr<WeaponMixin> wrap(CBaseEntity* pEntity);
47+
48+
49+
float GetNextAttack();
50+
void SetNextAttack(float value);
51+
52+
float GetNextSecondaryFireAttack();
53+
void SetNextSecondaryFireAttack(float value);
54+
55+
int GetAmmoProp();
56+
void SetAmmoProp(int value);
57+
58+
int GetSecondaryFireAmmoProp();
59+
void SetSecondaryFireAmmoProp(int value);
60+
61+
int GetOwnerHandle();
62+
void SetOwnerHandle(int value);
63+
64+
int GetClip();
65+
void SetClip(int value);
66+
67+
int GetSecondaryFireClip();
68+
void SetSecondaryFireClip(int value);
69+
70+
int GetFlipViewModel();
71+
void SetFlipViewModel(int value);
72+
73+
int GetWorldModelIndex();
74+
void SetWorldModelIndex(int value);
75+
76+
// CS:GO
77+
int GetPrimaryAmmoCount();
78+
void SetPrimaryAmmoCount(int value);
79+
80+
int GetSecondaryAmmoCount();
81+
void SetSecondaryAmmoCount(int value);
82+
83+
};
84+
85+
86+
#endif // _WEAPONS_ENTITY_H

0 commit comments

Comments
 (0)