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

Commit bd088b1

Browse files
authored
[BugFix] Fix role assign issues (#568)
* [BugFix] Fix role assign issues * Addition Reset some values to avoid further bugs. * Sometimes this check fails * fuck skidder
1 parent 37fe7e4 commit bd088b1

File tree

6 files changed

+65
-12
lines changed

6 files changed

+65
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This project is no longer in active development by the BitCrackers team. Therefo
88
</p>
99

1010
## Disclaimer
11+
我知道有人在拿这个分支的码子搞事情。原则上分支主人不能干涉他人的使用和编译行为,但我仍希望你不要故意到处搞破坏。请你至少考虑维护AU的生态环境。
1112
This project is for Educational Use only. We do not condone this software being used to gain an advantage against other people. I made this project for my university project to show how cheating software works and how it is possible to block these manipulations in the future.
1213

1314
## Compile (Configurations)

gui/tabs/host_tab.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,32 @@ namespace HostTab {
4242
State.scientists_amount = (int)GetRoleCount(RoleType::Scientist);
4343
State.shapeshifters_amount = (int)GetRoleCount(RoleType::Shapeshifter);
4444
State.impostors_amount = (int)GetRoleCount(RoleType::Impostor);
45+
State.crewmates_amount = (int)GetRoleCount(RoleType::Crewmate);
46+
4547
if (State.impostors_amount + State.shapeshifters_amount > maxImposterAmount)
4648
{
4749
if(State.assignedRoles[index] == RoleType::Shapeshifter)
48-
State.assignedRoles[index] = RoleType::Engineer;
50+
State.assignedRoles[index] = RoleType::Random; //Set to random to avoid bugs.
4951
else if(State.assignedRoles[index] == RoleType::Impostor)
5052
State.assignedRoles[index] = RoleType::Random;
51-
State.shapeshifters_amount = (int)GetRoleCount(RoleType::Shapeshifter);
52-
State.impostors_amount = (int)GetRoleCount(RoleType::Impostor);
5353
}
5454

55+
if (State.assignedRoles[index] == RoleType::Engineer || State.assignedRoles[index] == RoleType::Scientist || State.assignedRoles[index] == RoleType::Crewmate) {
56+
if (State.engineers_amount + State.scientists_amount + State.crewmates_amount >= (int)playerAmount)
57+
State.assignedRoles[index] = RoleType::Random;
58+
} //Some may set all players to non imps. This hangs the game on beginning. Leave space to Random so we have imps.
59+
60+
if (options.GetGameMode() == GameModes__Enum::HideNSeek)
61+
{
62+
if (State.assignedRoles[index] == RoleType::Shapeshifter)
63+
State.assignedRoles[index] = RoleType::Random;
64+
else if (State.assignedRoles[index] == RoleType::Scientist)
65+
State.assignedRoles[index] = RoleType::Engineer;
66+
else if (State.assignedRoles[index] == RoleType::Crewmate)
67+
State.assignedRoles[index] = RoleType::Engineer;
68+
} //Assign other roles in hidenseek causes game bug.
69+
//These are organized. Do not change the order unless you find it necessary.
70+
5571
if (!IsInGame()) {
5672
SetRoleAmount(RoleTypes__Enum::Engineer, State.engineers_amount);
5773
SetRoleAmount(RoleTypes__Enum::Scientist, State.scientists_amount);

hooks/InnerNetClient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "profiler.h"
1010
#include <sstream>
1111
#include "esp.hpp"
12+
#include <algorithm>
1213

1314
void dInnerNetClient_Update(InnerNetClient* __this, MethodInfo* method)
1415
{
@@ -218,6 +219,12 @@ static void onGameEnd() {
218219
Replay::Reset();
219220
State.aumUsers.clear();
220221
State.chatMessages.clear();
222+
std::fill(State.assignedRoles.begin(), State.assignedRoles.end(), RoleType::Random); //Clear Pre assigned roles to avoid bugs.
223+
State.engineers_amount = 0;
224+
State.scientists_amount = 0;
225+
State.shapeshifters_amount = 0;
226+
State.impostors_amount = 0;
227+
State.crewmates_amount = 0; //We need to reset these. Or if the host doesn't turn on host tab ,these value won't update.
221228
State.MatchEnd = std::chrono::system_clock::now();
222229

223230
drawing_t& instance = Esp::GetDrawing();

hooks/RoleManager.cpp

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ void dRoleManager_SelectRoles(RoleManager* __this, MethodInfo* method) {
1313
auto roleRates = RoleRates(options, (int)allPlayers.size());
1414

1515
AssignPreChosenRoles(roleRates, assignedPlayers);
16-
AssignRoles(roleRates, roleRates.ShapeshifterChance, RoleTypes__Enum::Shapeshifter, allPlayers, assignedPlayers);
17-
AssignRoles(roleRates, 100, RoleTypes__Enum::Impostor, allPlayers, assignedPlayers);
18-
AssignRoles(roleRates, roleRates.ScientistChance, RoleTypes__Enum::Scientist, allPlayers, assignedPlayers);
19-
AssignRoles(roleRates, roleRates.EngineerChance, RoleTypes__Enum::Engineer, allPlayers, assignedPlayers);
20-
AssignRoles(roleRates, 100, RoleTypes__Enum::Crewmate, allPlayers, assignedPlayers);
16+
17+
if (options.GetGameMode() != GameModes__Enum::HideNSeek) {
18+
AssignRoles(roleRates, roleRates.ShapeshifterChance, RoleTypes__Enum::Shapeshifter, allPlayers, assignedPlayers);
19+
AssignRoles(roleRates, 100, RoleTypes__Enum::Impostor, allPlayers, assignedPlayers);
20+
AssignRoles(roleRates, roleRates.ScientistChance, RoleTypes__Enum::Scientist, allPlayers, assignedPlayers);
21+
AssignRoles(roleRates, roleRates.EngineerChance, RoleTypes__Enum::Engineer, allPlayers, assignedPlayers);
22+
AssignRoles(roleRates, 100, RoleTypes__Enum::Crewmate, allPlayers, assignedPlayers);
23+
} //Assign normal roles
24+
else {
25+
AssignRoles(roleRates, 100, RoleTypes__Enum::Impostor, allPlayers, assignedPlayers);
26+
AssignRoles(roleRates, 100, RoleTypes__Enum::Engineer, allPlayers, assignedPlayers);
27+
AssignRoles(roleRates, 100, RoleTypes__Enum::Crewmate, allPlayers, assignedPlayers); //In case we do not assign everyone.
28+
}//Assign hidenseek roles
2129
}
2230

2331
/*void dRoleManager_AssignRolesForTeam(List_1_GameData_PlayerInfo_* players, RoleOptionsData* opts, RoleTeamTypes__Enum team, int32_t teamMax, Nullable_1_RoleTypes_ defaultRole, MethodInfo* method) {
@@ -47,12 +55,29 @@ void AssignPreChosenRoles(RoleRates& roleRates, std::vector<uint8_t>& assignedPl
4755

4856
void AssignRoles(RoleRates& roleRates, int roleChance, RoleTypes__Enum role, il2cpp::List<List_1_PlayerControl_>& allPlayers, std::vector<uint8_t>& assignedPlayers)
4957
{
58+
GameOptions options;
5059
auto roleCount = roleRates.GetRoleCount(role);
60+
auto playerAmount = allPlayers.size();
61+
auto maxImposterAmount = GetMaxImposterAmount((int)playerAmount);
62+
63+
//if (role == RoleTypes__Enum::Shapeshifter || role == RoleTypes__Enum::Impostor) {
64+
// if (State.shapeshifters_amount + State.impostors_amount >= maxImposterAmount)
65+
// return; //Skip assigns when pre assigned enough imps.
66+
//}
67+
68+
if (options.GetGameMode() == GameModes__Enum::HideNSeek) {
69+
if (role == RoleTypes__Enum::Impostor)
70+
roleCount = 1; //Sometime the game would accidently make imp amount > 1.
71+
if (role == RoleTypes__Enum::Engineer)
72+
roleCount = playerAmount - 1; //For unknown reason Game simply set engineer amount in hidenseek to 0.
73+
}
74+
75+
if (role == RoleTypes__Enum::Shapeshifter && roleCount >= maxImposterAmount)
76+
roleCount = maxImposterAmount; //In previous version, aum would assign more imps than MaxImposterAmount based on shapeshifter amount.
77+
5178
if (roleCount < 1)
5279
return;
5380

54-
auto playerAmount = allPlayers.size();
55-
5681
for (auto i = 0; i < roleCount; i++)
5782
{
5883
if(assignedPlayers.size() >= playerAmount)

user/state.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class Settings {
132132
int shapeshifters_amount = 0;
133133
int engineers_amount = 0;
134134
int scientists_amount = 0;
135+
int crewmates_amount = 0;
135136

136137
bool Wallhack = false;
137138
bool FreeCam = false;

user/utility.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ void RoleRates::SubtractRole(RoleTypes__Enum role) {
9494

9595
int GetMaxImposterAmount(int playerAmount)
9696
{
97-
if(playerAmount >= 9)
97+
GameOptions options;
98+
if (options.GetGameMode() == GameModes__Enum::HideNSeek)
99+
return 1;
100+
if (playerAmount >= 9)
98101
return 3;
99-
if(playerAmount >= 7)
102+
if (playerAmount >= 7)
100103
return 2;
101104
return 1;
102105
}

0 commit comments

Comments
 (0)