Skip to content

Commit

Permalink
[Bugfix] Properly reset data on game end (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
cddjr committed Jun 4, 2022
1 parent dc98c1e commit c58d8e6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion appdata/il2cpp-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ DO_APP_FUNC(void, MessageWriter_EndMessage, (MessageWriter* __this, MethodInfo*
DO_APP_FUNC(void, AccountTab_Open, (AccountTab* __this, MethodInfo* method), "Assembly-CSharp, System.Void AccountTab::Open()");
DO_APP_FUNC(void, FullAccount_CanSetCustomName, (FullAccount* __this, bool canSetName, MethodInfo* method), "Assembly-CSharp, System.Void FullAccount::CanSetCustomName(System.Boolean)");
DO_APP_FUNC(void, FollowerCamera_Update, (FollowerCamera* __this, MethodInfo* method), "Assembly-CSharp, System.Void FollowerCamera::Update()");
DO_APP_FUNC(MessageWriter*, InnerNetClient_StartEndGame, (InnerNetClient* __this, MethodInfo* method), "Assembly-CSharp, Hazel.MessageWriter InnerNet.InnerNetClient::StartEndGame()");
DO_APP_FUNC(void, AmongUsClient_OnGameEnd, (AmongUsClient* __this, Object* endGameResult, MethodInfo* method), "Assembly-CSharp, System.Void AmongUsClient::OnGameEnd(EndGameResult)");

DO_APP_FUNC(void, Debug_Log, (Object* message, MethodInfo* method), "UnityEngine.CoreModule, System.Void UnityEngine.Debug::Log(System.Object)");
DO_APP_FUNC(void, Debug_LogError, (Object* message, MethodInfo* method), "UnityEngine.CoreModule, System.Void UnityEngine.Debug::LogError(System.Object)");
Expand All @@ -201,6 +201,7 @@ DO_APP_FUNC(void, RoleManager_SelectRoles, (RoleManager* __this, MethodInfo* met
DO_APP_FUNC(void, RoleManager_AssignRolesForTeam, (List_1_GameData_PlayerInfo_* players, RoleOptionsData* opts, RoleTeamTypes__Enum team, int32_t teamMax, Nullable_1_RoleTypes_ defaultRole, MethodInfo* method), "Assembly-CSharp, System.Void RoleManager::AssignRolesForTeam(System.Collections.Generic.List<GameData.PlayerInfo>, RoleOptionsData, RoleTeamTypes, System.Int32, System.Nullable<RoleTypes>)");
DO_APP_FUNC(void, RoleManager_AssignRolesFromList, (List_1_GameData_PlayerInfo_* players, int32_t teamMax, List_1_RoleTypes_* roleList, int32_t* rolesAssigned, MethodInfo* method), "Assembly-CSharp, System.Void RoleManager::AssignRolesFromList(System.Collections.Generic.List<GameData.PlayerInfo>, System.Int32, System.Collections.Generic.List<RoleTypes>, System.Int32&)");
DO_APP_FUNC(void, InnerNetClient_EnqueueDisconnect, (InnerNetClient* __this, DisconnectReasons__Enum reason, String* stringReason, MethodInfo* method), "Assembly-CSharp, System.Void InnerNet.InnerNetClient::EnqueueDisconnect(DisconnectReasons, System.String)");
DO_APP_FUNC(void, InnerNetClient_DisconnectInternal, (InnerNetClient* __this, DisconnectReasons__Enum reason, String* stringReason, MethodInfo* method), "Assembly-CSharp, System.Void InnerNet.InnerNetClient::DisconnectInternal(DisconnectReasons, System.String)");

DO_APP_FUNC(void, PlayerPhysics_FixedUpdate, (PlayerPhysics* __this, MethodInfo* method), "Assembly-CSharp, System.Void PlayerPhysics::FixedUpdate()");

Expand Down
23 changes: 17 additions & 6 deletions hooks/InnerNetClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,30 @@ void dCustomNetworkTransform_SnapTo(CustomNetworkTransform* __this, Vector2 posi
CustomNetworkTransform_SnapTo(__this, position, minSid, method);
}

void dInnerNetClient_StartEndGame(InnerNetClient* __this, MethodInfo* method) {
State.aumUsers.clear();

std::lock_guard<std::mutex> replayLock(Replay::replayEventMutex);
static void onGameEnd() {
LOG_DEBUG("Reset All");
Replay::Reset();

std::lock_guard<std::mutex> replayLock(Replay::replayEventMutex);
State.aumUsers.clear();
for (auto& e : State.rawEvents)
e.reset();
State.rawEvents.clear();

State.MatchEnd = std::chrono::system_clock::now();
}

InnerNetClient_StartEndGame(__this, method);
void dAmongUsClient_OnGameEnd(AmongUsClient* __this, Object* endGameResult, MethodInfo* method) {
onGameEnd();
AmongUsClient_OnGameEnd(__this, endGameResult, method);
}

void dInnerNetClient_DisconnectInternal(InnerNetClient* __this, DisconnectReasons__Enum reason, String* stringReason, MethodInfo* method) {
// IsInGame()
if (__this->fields.GameState == InnerNetClient_GameStates__Enum::Started
|| __this->fields.GameMode == GameModes__Enum::FreePlay) {
onGameEnd();
}
InnerNetClient_DisconnectInternal(__this, reason, stringReason, method);
}

void dInnerNetClient_EnqueueDisconnect(InnerNetClient* __this, DisconnectReasons__Enum reason, String* stringReason, MethodInfo* method) {
Expand Down
4 changes: 4 additions & 0 deletions hooks/_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ void DetourInitilization() {
HOOKFUNC(PlayerPhysics_FixedUpdate);
HOOKFUNC(SaveManager_GetPurchase);
HOOKFUNC(PlayerControl_TurnOnProtection);
HOOKFUNC(AmongUsClient_OnGameEnd);
HOOKFUNC(InnerNetClient_DisconnectInternal);


if (!HookFunction(&(PVOID&)oPresent, dPresent, "D3D_PRESENT_FUNCTION")) return;
Expand Down Expand Up @@ -236,6 +238,8 @@ void DetourUninitialization()
UNHOOKFUNC(ChatController_Update);
UNHOOKFUNC(InnerNetClient_EnqueueDisconnect);
UNHOOKFUNC(PlayerControl_TurnOnProtection);
UNHOOKFUNC(AmongUsClient_OnGameEnd);
UNHOOKFUNC(InnerNetClient_DisconnectInternal);

if (DetourDetach(&(PVOID&)oPresent, dPresent) != 0) return;

Expand Down
4 changes: 3 additions & 1 deletion hooks/_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ void dEOSManager_ReallyBeginFlow(EOSManager* __this, MethodInfo* method);
bool dEOSManager_IsFreechatAllowed(EOSManager* __this, MethodInfo* method);
void dChatController_Update(ChatController* __this, MethodInfo* method);
void dInnerNetClient_EnqueueDisconnect(InnerNetClient* __this, DisconnectReasons__Enum reason, String* stringReason, MethodInfo* method);
void dInnerNetClient_DisconnectInternal(InnerNetClient* __this, DisconnectReasons__Enum reason, String* stringReason, MethodInfo* method);
void dRoleManager_SelectRoles(RoleManager* __this, MethodInfo * method);
void dRoleManager_AssignRolesForTeam(List_1_GameData_PlayerInfo_* players, RoleOptionsData* opts, RoleTeamTypes__Enum team, int32_t teamMax, Nullable_1_RoleTypes_ defaultRole, MethodInfo* method);
void dRoleManager_AssignRolesFromList(List_1_GameData_PlayerInfo_* players, int32_t teamMax, List_1_RoleTypes_* roleList, int32_t* rolesAssigned, MethodInfo* method);
void dPlayerPhysics_FixedUpdate (PlayerPhysics* __this, MethodInfo* method);
bool dSaveManager_GetPurchase(String* itemKey, String* bundleKey, MethodInfo* method);
void dPlayerControl_TurnOnProtection(PlayerControl* __this, bool visible, int32_t colorId, MethodInfo* method);
void dPlayerControl_TurnOnProtection(PlayerControl* __this, bool visible, int32_t colorId, MethodInfo* method);
void dAmongUsClient_OnGameEnd(AmongUsClient* __this, Object* endGameResult, MethodInfo* method);

0 comments on commit c58d8e6

Please sign in to comment.