Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
[BugFix] Fix role assign issues (BitCrackers#568)
Browse files Browse the repository at this point in the history
* [BugFix] Fix role assign issues

* Addition

Reset some values to avoid further bugs.

* Sometimes this check fails

* fuck skidder
  • Loading branch information
NikoCat233 authored and GDjkhp committed Oct 29, 2023
1 parent 212ac7b commit dc7858d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
22 changes: 19 additions & 3 deletions gui/tabs/host_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions hooks/InnerNetClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "profiler.h"
#include <sstream>
#include "esp.hpp"
#include <algorithm>

void dInnerNetClient_Update(InnerNetClient* __this, MethodInfo* method)
{
Expand Down Expand Up @@ -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();
Expand Down
47 changes: 30 additions & 17 deletions hooks/RoleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions user/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dc7858d

Please sign in to comment.