Skip to content

Added instance_property support to entity managers. #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ srv_check = False
offset_windows = 372


[instance_attribute]
[instance_property]


# from memory import alloc
Expand All @@ -74,8 +74,8 @@ srv_check = False
# break
# print('Offset of Player.assists is:', offset)
[[assists]]
offset_windows = 4024
offset_linux = 4048
base = m_iFrags
offset = 4
type = INT


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ srv_check = False
on_rescue_zone_touch = OnRescueZoneTouch


[instance_attribute]
[instance_property]

[[mvps]]
offset_windows = 12272
offset_linux = 12296
base = m_bIsHoldingLookAtWeapon
offset = 11
type = INT

[[score]]
offset_windows = 12312
offset_linux = 12336
base = m_bIsHoldingLookAtWeapon
offset = 51
type = INT

[[clan_tag]]
offset_windows = 10240
offset_linux = 10264
base = m_flGroundAccelLinearFracLastTime
offset = 140
type = STRING_ARRAY


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@
on_rescue_zone_touch = OnRescueZoneTouch


[instance_attribute]
[instance_property]

[[mvps]]
offset_windows = 6384
offset_linux = 6404
base = cslocaldata.m_bPlayerDominatingMe.065
offset = 4
type = INT

[[clan_tag]]
offset_windows = 5628
offset_linux = 5648
base = m_flFlashDuration
offset = -28
type = STRING_ARRAY


Expand Down
24 changes: 23 additions & 1 deletion addons/source-python/packages/source-python/entities/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from memory import DataType
from memory import get_object_pointer
from memory import make_object
from memory.helpers import Key
from memory.helpers import Type
from memory.manager import CustomType
from memory.manager import TypeManager
Expand Down Expand Up @@ -332,6 +333,26 @@ def _get_server_class(self, class_name, datamap):
instance, name, offset, property_contents,
_supported_descriptor_types[desc.type])

# Loop through all instance properties
for name, data in manager_contents.get(
'instance_property', {}).items():

# Register the property
setattr(instance, name, getattr(
self, data.get('method', 'instance_attribute')
)(
Key.as_attribute_type(self, data['type']),
instance.properties[
data.get('base_' + PLATFORM, data.get('base'))
].offset + Key.as_int(
self, data.get(
'offset_' + PLATFORM, data.get('offset', 0)
)
),
data.get('doc', None)
)
)

# Get a list of all properties for the current server class
properties = list(instance.properties)

Expand Down Expand Up @@ -485,7 +506,8 @@ def _add_property(
value = self.instance_attribute(prop_type, offset)

# Add the property to the properties dictionary
instance.properties[name] = EntityProperty(value, prop_type, networked)
instance.properties[name] = EntityProperty(
value, prop_type, networked, offset)

# Is the property not a named property?
if name not in contents:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ class TypeDescriptionFlags(IntFlag):
class EntityProperty(object):
"""Class used to store property information for verification."""

def __init__(self, instance, prop_type, networked):
def __init__(self, instance, prop_type, networked, offset):
"""Store the base attributes on instantiation."""
self._instance = instance
self._prop_type = prop_type
self._networked = networked
self._offset = offset

@property
def instance(self):
Expand All @@ -123,3 +124,9 @@ def prop_type(self):
def networked(self):
"""Return whether the property is networked."""
return self._networked

@property
def offset(self):
"""Returns the offset of the property."""
return self._offset