Skip to content
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

Refactoring and bug fixes in ESP and spectators list handling #132

Merged
merged 11 commits into from
Apr 4, 2024

Conversation

PetrSeifert
Copy link
Contributor

The changes primarily focus on refactoring and fixing bugs in the handling of ESP and spectators list. 

In the observer.rs file, in the create function, the 'target_controller_entity_id', which represented 'EntityHandle.get_entity_index()', was replaced by 'target_entity_handle_index', which represents EntityHandle<C_BaseEntity>.value. This adjustment was made because observer_target can now also be C_PlantedC4
The check for matching target entities has been updated to use observer_target_handle.value. I am not sure that this is optimal, as I don't even know what the 'serial_number` represents, so I will be happy to hear your opinion.

In the player.rs file, the local player controller is now fetched directly using the get_local_player_controller function and is used to update local_team_id
The code for fetching the local player's pawn position has been removed. The distance calculation for each player now uses view_world_position instead of local_pos.

In the world.rs file, a new function get_view_world_position has been added to the ViewController structure. This function calculates the world position based on the view matrix.

@PetrSeifert PetrSeifert changed the title Refactoring and bug fixes in player and spectator handling Refactoring and bug fixes in ESP and spectators list handling Mar 14, 2024
@WolverinDEV
Copy link
Collaborator

WolverinDEV commented Mar 15, 2024

Hey, interesting PR.

In regards of naming schemes

Entity id, entity index and entity handle index are basically used synonymously throughout Valthrun.
Entities in CS2 are stored in a 2 dimensional array (CEntityIdentity[64][512]).

The CEntityIdentity class contains multiple fields including

  • A pointer to the instance of the entity
  • The index of the entity (index within the above described array)
  • A hash used for quick lookup

The EntityHandle

To refer to these identities/entities, a EntityHandle is used which is basically a 32 bit integer.
Such handles consist of two parts, the lower bits represent the entity index and the upper part some kind of serial number
used for caching within the source 2 engine itself (afaik).

Thoughts regards the SpectatorList changes

As far as I understand you repurposed the SpectatorList state to retrive a list of spectators from for a target entity instead of a certain controller.
This would allow to get the observers of any entity (including the C_PlantedC4). This sounds good to me.
The value check is incorrect tough as value includes the serial number. Only check for the entity index :)

Thoughts regards the LocalCameraControllerTarget changes

In regards to the LocalCameraControllerTarget state you'll have to update it's description as well.
I'm not quite understanding the implementation for player_controller.m_bPawnIsAlive()?. Why did ou use m_hOriginalControllerOfCurrentPawn to get a controller and then the pawn again? I would assume returning the player_controller pawns entity index would be a better approach.
PS: The .value this applies here as well.

Other notes

Can you help me out on the get_view_world_position function:
What does it do and why do you need it instead of taking the position of the currently observed entity?

I hope so far I caught everything in your PR.

@PetrSeifert
Copy link
Contributor Author

Entity comparison is now done only by entity_index.

LocalCameraTarget
Taking pawn from m_hOriginalControllerOfCurrentPawn was my mistake.

ViewController
I renamed get_view_world_position to get_camera_world_position.
As it states, the function calculates the camera position from the view matrix.
I then used the camera position instead of the target position to calculate the distance from the players.
I did that because when the observed entity is C_PlantedC4 then the entity position doesn't match the camera position. So I feel like the camera position should always produce expected results.

@WolverinDEV WolverinDEV merged commit 3f91668 into Valthrun:master Apr 4, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants