Skip to content

Commit

Permalink
Add ImpostorHack to Host-Only
Browse files Browse the repository at this point in the history
  • Loading branch information
scp222thj committed Dec 27, 2023
1 parent 4ee5091 commit 5365837
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/HostOnly/HostOnlyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,53 @@ public static bool Prefix(byte srcPlayerId, byte suspectPlayerId, MeetingHud __i
//If no cheat is enabled, original MeetingHud.CastVote is ran
return true;
}
}

[HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.LateUpdate))]
public static class HostOnly_ImpostorHackPostfix
{
public static int lastRole;
public static bool isActive;

//Postfix patch of PlayerPhysics.LateUpdate that turns player into an impostor
//when CheatSettings.impostorHack is enabled
public static void Postfix(PlayerPhysics __instance)
{
//try-catch to prevent errors when role is null
try{

if (!PlayerControl.LocalPlayer.Data.Role.IsImpostor){ //Only works if the player is not already an impostor

lastRole = (int)PlayerControl.LocalPlayer.Data.RoleType; //Saves role before the modification

if (CheatSettings.impostorHack){
isActive = true;

//Prevents accidental revival of dead players when turning into impostor
if (PlayerControl.LocalPlayer.Data.IsDead){

DestroyableSingleton<RoleManager>.Instance.SetRole(PlayerControl.LocalPlayer, AmongUs.GameOptions.RoleTypes.ImpostorGhost);

} else {

DestroyableSingleton<RoleManager>.Instance.SetRole(PlayerControl.LocalPlayer, AmongUs.GameOptions.RoleTypes.Impostor);

}
}

}else{

//If the cheat toggle is disabled but the hack is still active
//Disable the hack by resetting to lastRole
if(!CheatSettings.impostorHack && isActive){

isActive = false;
DestroyableSingleton<RoleManager>.Instance.SetRole(PlayerControl.LocalPlayer, (AmongUs.GameOptions.RoleTypes)lastRole);

}
}

}catch{};

}
}
3 changes: 2 additions & 1 deletion src/UI/MenuUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private void Start()
}));

groups.Add(new GroupInfo("Host-Only", false, new List<ToggleInfo>() {
new ToggleInfo(" ImpostorHack", () => CheatSettings.impostorHack, x => CheatSettings.impostorHack = x),
new ToggleInfo(" Godmode", () => CheatSettings.godMode, x => CheatSettings.godMode = x),
new ToggleInfo(" EvilVote", () => CheatSettings.evilVote, x => CheatSettings.evilVote = x),
new ToggleInfo(" VoteImmune", () => CheatSettings.voteImmune, x => CheatSettings.voteImmune = x)
Expand Down Expand Up @@ -103,7 +104,7 @@ private void Update(){

//Host-only cheats are turned off if LocalPlayer is not the game's host
if(!isHostCheck.isHost){
CheatSettings.voteImmune = CheatSettings.godMode = CheatSettings.evilVote = false;
CheatSettings.voteImmune = CheatSettings.godMode = CheatSettings.impostorHack = CheatSettings.evilVote = false;
}

//Some cheats only work if the ship is present, so they are turned off if it is not
Expand Down

0 comments on commit 5365837

Please sign in to comment.