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

Commit

Permalink
Fix instant win if no roles were selected / present (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkPenguin24 authored Mar 1, 2022
1 parent aeb0563 commit 869ef3c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion hooks/RoleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
void dRoleManager_SelectRoles(RoleManager* __this, MethodInfo* method) {
std::vector<uint8_t> assignedPlayers;
auto allPlayers = GetAllPlayerControl();
auto roleRates = RoleRates((*Game::pGameOptionsData)->fields.RoleOptions);
auto roleRates = RoleRates((*Game::pGameOptionsData)->fields);

AssignPreChosenRoles(roleRates, assignedPlayers);
AssignRoles(roleRates.ShapeshifterCount, roleRates.ShapeshifterChance, RoleTypes__Enum::Shapeshifter, allPlayers, assignedPlayers);
Expand Down Expand Up @@ -45,12 +45,14 @@ void AssignPreChosenRoles(RoleRates& roleRates, std::vector<uint8_t>& assignedPl
if (roleRates.ShapeshifterCount == 0)
continue;
roleRates.ShapeshifterCount--;
roleRates.ImposterCount--;
}
else if (trueRole == RoleTypes__Enum::Impostor)
{
if (roleRates.ImposterCount == 0)
continue;
roleRates.ImposterCount--;
roleRates.ShapeshifterCount--;
}
else if (trueRole == RoleTypes__Enum::Scientist)
{
Expand Down
5 changes: 3 additions & 2 deletions user/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ int randi(int lo, int hi) {
return lo + i;
}

RoleRates::RoleRates(RoleOptionsData* roleOptions) {
auto roleRates = roleOptions->fields.roleRates;
RoleRates::RoleRates(GameOptionsData__Fields gameOptionsDataFields) {
this->ImposterCount = gameOptionsDataFields.NumImpostors;
auto roleRates = gameOptionsDataFields.RoleOptions->fields.roleRates;
if (roleRates->fields.count != 0) {
auto vectors = roleRates->fields.entries[0].vector;
for (auto iVector = 0; iVector < 32; iVector++)
Expand Down
2 changes: 1 addition & 1 deletion user/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RoleRates {
int EngineerCount = 0;
int EngineerChance = 0;
int MaxCrewmates = 15;
RoleRates(RoleOptionsData* roleOptions);
RoleRates(GameOptionsData__Fields gameOptionsDataFields);
};

class PlayerSelection {
Expand Down

0 comments on commit 869ef3c

Please sign in to comment.