diff --git a/gui/tabs/host_tab.cpp b/gui/tabs/host_tab.cpp index 4f67b99d..ccacc15f 100644 --- a/gui/tabs/host_tab.cpp +++ b/gui/tabs/host_tab.cpp @@ -42,16 +42,32 @@ namespace HostTab { State.scientists_amount = (int)GetRoleCount(RoleType::Scientist); State.shapeshifters_amount = (int)GetRoleCount(RoleType::Shapeshifter); State.impostors_amount = (int)GetRoleCount(RoleType::Impostor); + State.crewmates_amount = (int)GetRoleCount(RoleType::Crewmate); + if (State.impostors_amount + State.shapeshifters_amount > maxImposterAmount) { if(State.assignedRoles[index] == RoleType::Shapeshifter) - State.assignedRoles[index] = RoleType::Engineer; + State.assignedRoles[index] = RoleType::Random; //Set to random to avoid bugs. else if(State.assignedRoles[index] == RoleType::Impostor) State.assignedRoles[index] = RoleType::Random; - State.shapeshifters_amount = (int)GetRoleCount(RoleType::Shapeshifter); - State.impostors_amount = (int)GetRoleCount(RoleType::Impostor); } + if (State.assignedRoles[index] == RoleType::Engineer || State.assignedRoles[index] == RoleType::Scientist || State.assignedRoles[index] == RoleType::Crewmate) { + if (State.engineers_amount + State.scientists_amount + State.crewmates_amount >= (int)playerAmount) + State.assignedRoles[index] = RoleType::Random; + } //Some may set all players to non imps. This hangs the game on beginning. Leave space to Random so we have imps. + + if (options.GetGameMode() == GameModes__Enum::HideNSeek) + { + if (State.assignedRoles[index] == RoleType::Shapeshifter) + State.assignedRoles[index] = RoleType::Random; + else if (State.assignedRoles[index] == RoleType::Scientist) + State.assignedRoles[index] = RoleType::Engineer; + else if (State.assignedRoles[index] == RoleType::Crewmate) + State.assignedRoles[index] = RoleType::Engineer; + } //Assign other roles in hidenseek causes game bug. + //These are organized. Do not change the order unless you find it necessary. + if (!IsInGame()) { SetRoleAmount(RoleTypes__Enum::Engineer, State.engineers_amount); SetRoleAmount(RoleTypes__Enum::Scientist, State.scientists_amount); diff --git a/hooks/InnerNetClient.cpp b/hooks/InnerNetClient.cpp index 15196bce..e43954bd 100644 --- a/hooks/InnerNetClient.cpp +++ b/hooks/InnerNetClient.cpp @@ -9,6 +9,7 @@ #include "profiler.h" #include #include "esp.hpp" +#include void dInnerNetClient_Update(InnerNetClient* __this, MethodInfo* method) { @@ -222,6 +223,12 @@ static void onGameEnd() { Replay::Reset(); State.aumUsers.clear(); State.chatMessages.clear(); + std::fill(State.assignedRoles.begin(), State.assignedRoles.end(), RoleType::Random); //Clear Pre assigned roles to avoid bugs. + State.engineers_amount = 0; + State.scientists_amount = 0; + State.shapeshifters_amount = 0; + State.impostors_amount = 0; + State.crewmates_amount = 0; //We need to reset these. Or if the host doesn't turn on host tab ,these value won't update. State.MatchEnd = std::chrono::system_clock::now(); drawing_t& instance = Esp::GetDrawing(); diff --git a/hooks/RoleManager.cpp b/hooks/RoleManager.cpp index 0ceda18e..4ff989ea 100644 --- a/hooks/RoleManager.cpp +++ b/hooks/RoleManager.cpp @@ -13,19 +13,19 @@ void dRoleManager_SelectRoles(RoleManager* __this, MethodInfo* method) { auto roleRates = RoleRates(options, (int)allPlayers.size()); AssignPreChosenRoles(roleRates, assignedPlayers); - if (options.GetGameMode() != GameModes__Enum::HideNSeek) - { - AssignRoles(roleRates, roleRates.ShapeshifterChance, RoleTypes__Enum::Shapeshifter, allPlayers, assignedPlayers); - AssignRoles(roleRates, 100, RoleTypes__Enum::Impostor, allPlayers, assignedPlayers); - AssignRoles(roleRates, roleRates.ScientistChance, RoleTypes__Enum::Scientist, allPlayers, assignedPlayers); - AssignRoles(roleRates, roleRates.EngineerChance, RoleTypes__Enum::Engineer, allPlayers, assignedPlayers); - AssignRoles(roleRates, 100, RoleTypes__Enum::Crewmate, allPlayers, assignedPlayers); - } - else - { - AssignRoles(roleRates, 100, RoleTypes__Enum::Impostor, allPlayers, assignedPlayers); - AssignRoles(roleRates, 100, RoleTypes__Enum::Engineer, allPlayers, assignedPlayers); - } + + if (options.GetGameMode() != GameModes__Enum::HideNSeek) { + AssignRoles(roleRates, roleRates.ShapeshifterChance, RoleTypes__Enum::Shapeshifter, allPlayers, assignedPlayers); + AssignRoles(roleRates, 100, RoleTypes__Enum::Impostor, allPlayers, assignedPlayers); + AssignRoles(roleRates, roleRates.ScientistChance, RoleTypes__Enum::Scientist, allPlayers, assignedPlayers); + AssignRoles(roleRates, roleRates.EngineerChance, RoleTypes__Enum::Engineer, allPlayers, assignedPlayers); + AssignRoles(roleRates, 100, RoleTypes__Enum::Crewmate, allPlayers, assignedPlayers); + } //Assign normal roles + else { + AssignRoles(roleRates, 100, RoleTypes__Enum::Impostor, allPlayers, assignedPlayers); + AssignRoles(roleRates, 100, RoleTypes__Enum::Engineer, allPlayers, assignedPlayers); + AssignRoles(roleRates, 100, RoleTypes__Enum::Crewmate, allPlayers, assignedPlayers); //In case we do not assign everyone. + }//Assign hidenseek roles } /*void dRoleManager_AssignRolesForTeam(List_1_GameData_PlayerInfo_* players, RoleOptionsData* opts, RoleTeamTypes__Enum team, int32_t teamMax, Nullable_1_RoleTypes_ defaultRole, MethodInfo* method) { @@ -57,14 +57,27 @@ void AssignRoles(RoleRates& roleRates, int roleChance, RoleTypes__Enum role, il2 { GameOptions options; auto roleCount = roleRates.GetRoleCount(role); - if (role == RoleTypes__Enum::Engineer && options.GetGameMode() == GameModes__Enum::HideNSeek) - roleCount = allPlayers.size() - 1; + auto playerAmount = allPlayers.size(); + auto maxImposterAmount = GetMaxImposterAmount((int)playerAmount); + + //if (role == RoleTypes__Enum::Shapeshifter || role == RoleTypes__Enum::Impostor) { + // if (State.shapeshifters_amount + State.impostors_amount >= maxImposterAmount) + // return; //Skip assigns when pre assigned enough imps. + //} + + if (options.GetGameMode() == GameModes__Enum::HideNSeek) { + if (role == RoleTypes__Enum::Impostor) + roleCount = 1; //Sometime the game would accidently make imp amount > 1. + if (role == RoleTypes__Enum::Engineer) + roleCount = playerAmount - 1; //For unknown reason Game simply set engineer amount in hidenseek to 0. + } + + if (role == RoleTypes__Enum::Shapeshifter && roleCount >= maxImposterAmount) + roleCount = maxImposterAmount; //In previous version, aum would assign more imps than MaxImposterAmount based on shapeshifter amount. if (roleCount < 1) return; - auto playerAmount = allPlayers.size(); - for (auto i = 0; i < roleCount; i++) { if(assignedPlayers.size() >= playerAmount) diff --git a/user/state.hpp b/user/state.hpp index 2fa05cc0..caea00f0 100644 --- a/user/state.hpp +++ b/user/state.hpp @@ -141,6 +141,7 @@ class Settings { int shapeshifters_amount = 0; int engineers_amount = 0; int scientists_amount = 0; + int crewmates_amount = 0; bool Wallhack = false; bool FreeCam = false;