From cb1b462045b8585d8e3c4dbe6cfaf778d3bb208f Mon Sep 17 00:00:00 2001 From: kotae4 <83557652+kotae4@users.noreply.github.com> Date: Sun, 21 Nov 2021 18:23:00 -0500 Subject: [PATCH] fixed crash & added role under name --- appdata/il2cpp-functions.h | 1 + gui/radar.cpp | 2 +- hooks/PlayerControl.cpp | 4 ++++ user/gitparams.h | 2 +- user/utility.cpp | 8 ++++++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/appdata/il2cpp-functions.h b/appdata/il2cpp-functions.h index d5c825dc..160c3805 100644 --- a/appdata/il2cpp-functions.h +++ b/appdata/il2cpp-functions.h @@ -180,6 +180,7 @@ DO_APP_FUNC(bool, EOSManager_IsFreechatAllowed, (EOSManager* __this, MethodInfo* DO_APP_FUNC(void, TextMeshPro_SetFaceColor, (TextMeshPro* __this, Color32 color, MethodInfo* method), "Unity.TextMeshPro, System.Void TMPro.TextMeshPro::SetFaceColor(UnityEngine.Color32)"); DO_APP_FUNC(void, TextMeshPro_SetOutlineColor, (TextMeshPro* __this, Color32 color, MethodInfo* method), "Unity.TextMeshPro, System.Void TMPro.TextMeshPro::SetOutlineColor(UnityEngine.Color32)"); +DO_APP_FUNC(void, TMP_Text_set_text, (TMP_Text* __this, String* value, MethodInfo* method), "Unity.TextMeshPro, System.Void TMPro.TMP_Text::set_text(System.String)"); DO_APP_FUNC(Color32, Color32_op_Implicit, (Color c, MethodInfo* method), "UnityEngine.CoreModule, UnityEngine.Color32 UnityEngine.Color32::op_Implicit(UnityEngine.Color)"); 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, RoleOptionsData, RoleTeamTypes, System.Int32, System.Nullable)"); diff --git a/gui/radar.cpp b/gui/radar.cpp index a33e579e..d61f797e 100644 --- a/gui/radar.cpp +++ b/gui/radar.cpp @@ -13,7 +13,7 @@ namespace Radar { ImU32 GetRadarPlayerColorStatus(GameData_PlayerInfo* playerData) { if (playerData->fields.IsDead) return ImGui::ColorConvertFloat4ToU32(AmongUsColorToImVec4(app::Palette__TypeInfo->static_fields->HalfWhite)); - else if (State.RevealRoles && playerData->fields.Role->fields.StringName != StringNames__Enum::Crewmate) + else if (State.RevealRoles && playerData->fields.Role != nullptr && playerData->fields.Role->fields.StringName != StringNames__Enum::Crewmate) return ImGui::ColorConvertFloat4ToU32(AmongUsColorToImVec4(GetRoleColor(playerData->fields.Role))); else return ImGui::ColorConvertFloat4ToU32(ImVec4(0, 0, 0, 0)); diff --git a/hooks/PlayerControl.cpp b/hooks/PlayerControl.cpp index 7bda75a8..ecb7f024 100644 --- a/hooks/PlayerControl.cpp +++ b/hooks/PlayerControl.cpp @@ -47,6 +47,10 @@ void dPlayerControl_FixedUpdate(PlayerControl* __this, MethodInfo* method) { if (State.RevealRoles || PlayerIsImpostor(localData)) { Color32 c = app::Color32_op_Implicit(GetRoleColor(playerData->fields.Role), NULL); + std::string playerName = convert_from_string(GetPlayerOutfit(playerData)->fields._playerName); + playerName += "\n(" + GetRoleName(playerData->fields.Role) + ")"; + String* playerNameStr = convert_to_string(playerName); + app::TMP_Text_set_text((app::TMP_Text*)nameTextTMP, playerNameStr, NULL); app::TextMeshPro_SetFaceColor(nameTextTMP, c, NULL); app::TextMeshPro_SetOutlineColor(nameTextTMP, faceColor, NULL); diff --git a/user/gitparams.h b/user/gitparams.h index fad8a142..d1872b34 100644 --- a/user/gitparams.h +++ b/user/gitparams.h @@ -1,2 +1,2 @@ -#define GIT_CUR_COMMIT 6e947b3dd8cd233548f0f53125783fc89e91dd47 +#define GIT_CUR_COMMIT f461e3dc6034da2d0e8179086ec67e01f31a7579 #define GIT_BRANCH 2021.11.9.5e diff --git a/user/utility.cpp b/user/utility.cpp index ef770ab1..6b86f66f 100644 --- a/user/utility.cpp +++ b/user/utility.cpp @@ -605,12 +605,18 @@ GameData_PlayerOutfit* GetPlayerOutfit(GameData_PlayerInfo* player) { } bool PlayerIsImpostor(GameData_PlayerInfo* player) { + + if (player->fields.Role == nullptr) return false; + RoleBehaviour* role = player->fields.Role; return role->fields.Role == RoleTypes__Enum::Impostor; } Color GetRoleColor(RoleBehaviour* roleBehaviour) { + + if (roleBehaviour == nullptr) return Palette__TypeInfo->static_fields->White; + app::Color c; switch (roleBehaviour->fields.Role) { case RoleTypes__Enum::Engineer: @@ -638,6 +644,8 @@ Color GetRoleColor(RoleBehaviour* roleBehaviour) { std::string GetRoleName(RoleBehaviour* roleBehaviour) { + if (roleBehaviour == nullptr) return "Unknown"; + switch (roleBehaviour->fields.Role) { case RoleTypes__Enum::Engineer: