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 1 commit
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
Prev Previous commit
Renamed instance_property to based_attribute.
Polished the code.
Added old offsets back to the data files.
  • Loading branch information
jordanbriere committed Dec 14, 2020
commit 668891b82203bfb3ecb30e70d80fcf8dc7935911
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ srv_check = False
offset_windows = 372


[instance_property]
# TODO: Remove when outdated.
[instance_attribute]

[[assists]]
offset_windows = 4024
offset_linux = 4048
type = INT


[based_attribute]

# from memory import alloc
# from players.entity import Player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,26 @@ srv_check = False
on_rescue_zone_touch = OnRescueZoneTouch


[instance_property]
# TODO: Remove when outdated.
[instance_attribute]

[[mvps]]
offset_windows = 12272
offset_linux = 12296
type = INT

[[score]]
offset_windows = 12312
offset_linux = 12336
type = INT

[[clan_tag]]
offset_windows = 10240
offset_linux = 10264
type = STRING_ARRAY


[based_attribute]

[[mvps]]
base = m_bIsHoldingLookAtWeapon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@
on_rescue_zone_touch = OnRescueZoneTouch


[instance_property]
# TODO: Remove when outdated.
[instance_attribute]

[[mvps]]
offset_windows = 6384
offset_linux = 6404
type = INT

[[clan_tag]]
offset_windows = 5628
offset_linux = 5648
type = STRING_ARRAY


[based_attribute]

[[mvps]]
base = cslocaldata.m_bPlayerDominatingMe.065
Expand Down
46 changes: 29 additions & 17 deletions addons/source-python/packages/source-python/entities/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,26 +333,38 @@ 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)
# Loop through all based attributes
for name, data in manager_contents.get('based_attribute', {}).items():

# Resolve the method to register this attribute
method = getattr(self, data.get('method', 'instance_attribute'))

# Resolve the offset of this attribute
offset = Key.as_int(
self,
data.get('offset_' + PLATFORM, data.get('offset', 0))
)

# Resolve the base offset of this attribute
base = data.get('base_' + PLATFORM, data.get('base'))
try:
offset += instance.properties[base].offset
except KeyError:
raise NameError(
f'"{base}" is not a valid property ' +
f'for attribute "{class_name}.{name}".'
)

# Generate the attribute
attribute = method(
Key.as_attribute_type(self, data['type']),
offset,
data.get('doc')
)

# Assign the attribute to the instance
setattr(instance, name, attribute)

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

Expand Down