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

[BugFix] Fix role assign issues #568

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</p>

## Disclaimer
我知道有人在拿这个分支的码子搞事情。原则上分支主人不能干涉他人的使用和编译行为,但我仍希望你不要故意到处搞破坏。请你至少考虑维护AU的生态环境。
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.

## Compile (Configurations)
Expand Down
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 @@ -218,6 +219,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
39 changes: 32 additions & 7 deletions hooks/RoleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ void dRoleManager_SelectRoles(RoleManager* __this, MethodInfo* method) {
auto roleRates = RoleRates(options, (int)allPlayers.size());

AssignPreChosenRoles(roleRates, assignedPlayers);
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);

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 @@ -47,12 +55,29 @@ void AssignPreChosenRoles(RoleRates& roleRates, std::vector<uint8_t>& assignedPl

void AssignRoles(RoleRates& roleRates, int roleChance, RoleTypes__Enum role, il2cpp::List<List_1_PlayerControl_>& allPlayers, std::vector<uint8_t>& assignedPlayers)
{
GameOptions options;
auto roleCount = roleRates.GetRoleCount(role);
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 @@ -132,6 +132,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
7 changes: 5 additions & 2 deletions user/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ void RoleRates::SubtractRole(RoleTypes__Enum role) {

int GetMaxImposterAmount(int playerAmount)
{
if(playerAmount >= 9)
GameOptions options;
if (options.GetGameMode() == GameModes__Enum::HideNSeek)
return 1;
if (playerAmount >= 9)
return 3;
if(playerAmount >= 7)
if (playerAmount >= 7)
return 2;
return 1;
}
Expand Down
Loading