demoinfocs-golang icon indicating copy to clipboard operation
demoinfocs-golang copied to clipboard

CS2: Entity.Properties() does not include second level properties of composite types

Open esbengc opened this issue 2 years ago • 1 comments
trafficstars

Describe the bug When parsing Source 2 demos and calling Entity.Properties(), the return value will not include properties such as a.b if both a and b are both composite types (i.e. arrays or record types). For example CCSPlayerPawn.m_pWeaponServices.m_hMyWeapons, which is an array type, will not be returned. Similarly, CCSPlayerPawn.m_attributes (which is an array of records) is not listed at all.

To Reproduce Parse any CS2 demo, and at any point where a player pawn entity is available, call entity.Properties and print the names of the returned properties. m_pWeaponServices.m_hMyWeapons is absent

Expected behavior See above

Library version v4.0.0-beta2

Additional context Problem seems to come from method sendtables2.field.getFieldPaths. When resolving a composite property, it calls state.get(fp) on the current state using the root-relative fp. For top level properties, this works fine as state will be the top-level state of the entity. For nested properties, however, it's going to be a problem. Take CCSPlayerPawn.m_pWeaponServices.m_hMyWeapons as an example: Here, state will be the value of m_pWeaponServices, which consists of 7 inner properties, while fp will be the root-relative path [86, 0]. So it starts by looking up value at index 86 on an object with only 7 properties, which fails.

esbengc avatar Oct 13 '23 12:10 esbengc

thanks for filing this issue - that's indeed a bug.

in the meantime ServerClass.String() could be useful - I think this should include the props with a.b. (on the latest master anyway, not on -beta.2)

markus-wa avatar Oct 14 '23 15:10 markus-wa