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

Erase rf::local_player from g_player_additional_data_map upon leaving server. #317

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions game_patch/misc/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <patch_common/CodeInjection.h>
#include <patch_common/AsmWriter.h>

std::unordered_map<rf::Player*, PlayerAdditionalData> g_player_additional_data_map;
std::unordered_map<const rf::Player*, PlayerAdditionalData> g_player_additional_data_map;

void find_player(const StringMatcher& query, std::function<void(rf::Player*)> consumer)
{
Expand All @@ -30,6 +30,10 @@ void find_player(const StringMatcher& query, std::function<void(rf::Player*)> co
}
}

void reset_player_additional_data(const rf::Player* const player) {
g_player_additional_data_map.erase(player);
}

PlayerAdditionalData& get_player_additional_data(rf::Player* player)
{
return g_player_additional_data_map[player];
Expand All @@ -48,8 +52,8 @@ FunHook<void(rf::Player*)> player_destroy_hook{
0x004A35C0,
[](rf::Player* player) {
multi_spectate_on_destroy_player(player);
reset_player_additional_data(player);
player_destroy_hook.call_target(player);
g_player_additional_data_map.erase(player);
},
};

Expand Down
1 change: 1 addition & 0 deletions game_patch/misc/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ struct PlayerAdditionalData
};

void find_player(const StringMatcher& query, std::function<void(rf::Player*)> consumer);
void reset_player_additional_data(const rf::Player* player);
PlayerAdditionalData& get_player_additional_data(rf::Player* player);
3 changes: 3 additions & 0 deletions game_patch/multi/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,9 @@ FunHook<void()> multi_stop_hook{
// Clear server info when leaving
g_df_server_info.reset();
multi_stop_hook.call_target();
if (rf::local_player) {
reset_player_additional_data(rf::local_player);
}
},
};

Expand Down