Skip to content

Commit

Permalink
v4.0.6 Source Code
Browse files Browse the repository at this point in the history
  • Loading branch information
eDonnes124 committed May 31, 2023
1 parent 1da29f6 commit 4528c3f
Show file tree
Hide file tree
Showing 52 changed files with 1,092 additions and 693 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Join our [Discord](https://discord.gg/ugyc4EVUYZ) if you have any problems or wa
# Releases
| Among Us - Version| Mod Version | Link |
|----------|-------------|-----------------|
| 2023.3.28s & 2023.3.28e | v4.0.6 | [Download](https://github.com/eDonnes124/Town-Of-Us/releases/download/v4.0.6/ToU.v4.0.6.zip) |
| 2023.3.28s & 2023.3.28e | v4.0.5 | [Download](https://github.com/eDonnes124/Town-Of-Us/releases/download/v4.0.5/ToU.v4.0.5.zip) |
| 2023.3.28s & 2023.3.28e | v4.0.4 | [Download](https://github.com/eDonnes124/Town-Of-Us/releases/download/v4.0.4/ToU.v4.0.4.zip) |
| 2023.2.28s & 2023.2.28e | v4.0.3 | [Download](https://github.com/eDonnes124/Town-Of-Us/releases/download/v4.0.3/ToU.v4.0.3.zip) |
Expand Down Expand Up @@ -133,6 +134,10 @@ Join our [Discord](https://discord.gg/ugyc4EVUYZ) if you have any problems or wa
<details>
<summary> Changelog </summary>
<details>
<summary> v4.0.6 </summary>
<ul> <li>Bug Fix: Reverted alot of the changes from the last few patches...</li> </ul>
</details>
<details>
<summary> v4.0.5 </summary>
<ul> <li>Bug Fix: Exile Functions now work when someone disconnects right after being assassinated</li> </ul>
</details>
Expand Down
46 changes: 46 additions & 0 deletions source/Patches/AddHauntPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using HarmonyLib;
using System.Collections.Generic;
using UnityEngine;
using System;
using Object = UnityEngine.Object;
using TownOfUs.NeutralRoles.PhantomMod;
using TownOfUs.CrewmateRoles.HaunterMod;

namespace TownOfUs.Patches
{
[HarmonyPatch(typeof(AirshipExileController), nameof(AirshipExileController.WrapUpAndSpawn))]
public static class AirshipAddHauntPatch
{
public static void Postfix(AirshipExileController __instance) => AddHauntPatch.ExileControllerPostfix(__instance);
}

[HarmonyPatch(typeof(ExileController), nameof(ExileController.WrapUp))]
[HarmonyPriority(Priority.First)]
class AddHauntPatch
{
public static List<PlayerControl> AssassinatedPlayers = new List<PlayerControl>();

public static void ExileControllerPostfix(ExileController __instance)
{
foreach (var player in AssassinatedPlayers)
{
try
{
if (SetPhantom.WillBePhantom != player && SetHaunter.WillBeHaunter != player
&& !player.Data.Disconnected) player.Exiled();
}
catch { }
}
AssassinatedPlayers.Clear();
}

public static void Postfix(ExileController __instance) => ExileControllerPostfix(__instance);

[HarmonyPatch(typeof(Object), nameof(Object.Destroy), new Type[] { typeof(GameObject) })]
public static void Prefix(GameObject obj)
{
if (!SubmergedCompatibility.Loaded || GameOptionsManager.Instance.currentNormalGameOptions.MapId != 5) return;
if (obj.name.Contains("ExileCutscene")) ExileControllerPostfix(ExileControllerPatch.lastExiled);
}
}
}
55 changes: 0 additions & 55 deletions source/Patches/CrewmateRoles/AltruistMod/Coroutine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
using Object = UnityEngine.Object;
using TownOfUs.Roles.Modifiers;
using AmongUs.GameOptions;
using TownOfUs.Patches;
using Hazel;

namespace TownOfUs.CrewmateRoles.AltruistMod
{
Expand Down Expand Up @@ -100,59 +98,6 @@ public static IEnumerator AltruistRevive(DeadBody target, Altruist role)
{
}

ExilePatch.CheckTraitorSpawn(null);
if (AmongUsClient.Instance.AmHost)
{
if (ExilePatch.WillBeHaunter == player)
{
var toChooseFrom = PlayerControl.AllPlayerControls.ToArray().Where(x => x.Is(Faction.Crewmates) && !x.Is(ModifierEnum.Lover) && x.Data.IsDead && !x.Data.Disconnected && x != player).ToList();
if (toChooseFrom.Count == 0)
{
ExilePatch.WillBeHaunter = null;
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.SetHaunter, SendOption.Reliable, -1);
writer.Write(byte.MaxValue);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
else
{
var rand = UnityEngine.Random.RandomRangeInt(0, toChooseFrom.Count);
var pc = toChooseFrom[rand];

ExilePatch.WillBeHaunter = pc;

var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.SetHaunter, SendOption.Reliable, -1);
writer.Write(pc.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
}
if (ExilePatch.WillBePhantom == player)
{
var toChooseFrom = PlayerControl.AllPlayerControls.ToArray().Where(x => (x.Is(Faction.NeutralOther) || x.Is(Faction.NeutralKilling)) && !x.Is(ModifierEnum.Lover) && x.Data.IsDead && !x.Data.Disconnected && x != player).ToList();
if (toChooseFrom.Count == 0)
{
ExilePatch.WillBePhantom = null;
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.SetPhantom, SendOption.Reliable, -1);
writer.Write(byte.MaxValue);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
else
{
var rand = UnityEngine.Random.RandomRangeInt(0, toChooseFrom.Count);
var pc = toChooseFrom[rand];

ExilePatch.WillBePhantom = pc;

var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.SetPhantom, SendOption.Reliable, -1);
writer.Write(pc.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
}
}

if (PlayerControl.LocalPlayer.Data.IsImpostor() || PlayerControl.LocalPlayer.Is(RoleEnum.Glitch) || PlayerControl.LocalPlayer.Is(RoleEnum.Juggernaut)
|| PlayerControl.LocalPlayer.Is(RoleEnum.Arsonist) || PlayerControl.LocalPlayer.Is(RoleEnum.Werewolf)
|| PlayerControl.LocalPlayer.Is(RoleEnum.Plaguebearer) || PlayerControl.LocalPlayer.Is(RoleEnum.Pestilence))
Expand Down
32 changes: 32 additions & 0 deletions source/Patches/CrewmateRoles/HaunterMod/RepickHaunter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using HarmonyLib;
using System.Linq;
using Hazel;
using UnityEngine;

namespace TownOfUs.CrewmateRoles.HaunterMod
{
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))]
public class RepickHaunter
{
private static void Postfix(HudManager __instance)
{
if (PlayerControl.AllPlayerControls.Count <= 1) return;
if (PlayerControl.LocalPlayer == null) return;
if (PlayerControl.LocalPlayer.Data == null) return;
if (PlayerControl.LocalPlayer != SetHaunter.WillBeHaunter) return;
if (PlayerControl.LocalPlayer.Data.IsDead) return;
var toChooseFrom = PlayerControl.AllPlayerControls.ToArray().Where(x => x.Is(Faction.Crewmates) && !x.Is(ModifierEnum.Lover) && x.Data.IsDead && !x.Data.Disconnected).ToList();
if (toChooseFrom.Count == 0) return;
var rand = Random.RandomRangeInt(0, toChooseFrom.Count);
var pc = toChooseFrom[rand];

SetHaunter.WillBeHaunter = pc;

var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.SetHaunter, SendOption.Reliable, -1);
writer.Write(pc.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
return;
}
}
}
89 changes: 89 additions & 0 deletions source/Patches/CrewmateRoles/HaunterMod/SetHaunter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using HarmonyLib;
using Hazel;
using TownOfUs.Roles;
using UnityEngine;
using Object = UnityEngine.Object;
using Random = UnityEngine.Random;
using TownOfUs.Patches;

namespace TownOfUs.CrewmateRoles.HaunterMod
{
[HarmonyPatch(typeof(AirshipExileController), nameof(AirshipExileController.WrapUpAndSpawn))]
public static class AirshipExileController_WrapUpAndSpawn
{
public static void Postfix(AirshipExileController __instance) => SetHaunter.ExileControllerPostfix(__instance);
}

[HarmonyPatch(typeof(ExileController), nameof(ExileController.WrapUp))]
public class SetHaunter
{
public static PlayerControl WillBeHaunter;
public static Vector2 StartPosition;

public static void ExileControllerPostfix(ExileController __instance)
{
if (WillBeHaunter == null) return;
var exiled = __instance.exiled?.Object;
if (!WillBeHaunter.Data.IsDead && exiled.Is(Faction.Crewmates) && !exiled.IsLover()) WillBeHaunter = exiled;
if (WillBeHaunter.Data.Disconnected) return;
if (!WillBeHaunter.Data.IsDead && WillBeHaunter != exiled) return;

if (!WillBeHaunter.Is(RoleEnum.Haunter))
{
var oldRole = Role.GetRole(WillBeHaunter);
var killsList = (oldRole.CorrectKills, oldRole.IncorrectKills, oldRole.CorrectAssassinKills, oldRole.IncorrectAssassinKills);
Role.RoleDictionary.Remove(WillBeHaunter.PlayerId);
if (PlayerControl.LocalPlayer == WillBeHaunter)
{
var role = new Haunter(PlayerControl.LocalPlayer);
role.formerRole = oldRole.RoleType;
role.CorrectKills = killsList.CorrectKills;
role.IncorrectKills = killsList.IncorrectKills;
role.CorrectAssassinKills = killsList.CorrectAssassinKills;
role.IncorrectAssassinKills = killsList.IncorrectAssassinKills;
role.RegenTask();
}
else
{
var role = new Haunter(WillBeHaunter);
role.formerRole = oldRole.RoleType;
role.CorrectKills = killsList.CorrectKills;
role.IncorrectKills = killsList.IncorrectKills;
role.CorrectAssassinKills = killsList.CorrectAssassinKills;
role.IncorrectAssassinKills = killsList.IncorrectAssassinKills;
}

Utils.RemoveTasks(WillBeHaunter);
if (!PlayerControl.LocalPlayer.Is(RoleEnum.Phantom)) WillBeHaunter.MyPhysics.ResetMoveState();

WillBeHaunter.gameObject.layer = LayerMask.NameToLayer("Players");
}

if (PlayerControl.LocalPlayer != WillBeHaunter) return;

if (Role.GetRole<Haunter>(PlayerControl.LocalPlayer).Caught) return;
var startingVent =
ShipStatus.Instance.AllVents[Random.RandomRangeInt(0, ShipStatus.Instance.AllVents.Count)];

var writer2 = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.SetPos, SendOption.Reliable, -1);
writer2.Write(PlayerControl.LocalPlayer.PlayerId);
writer2.Write(startingVent.transform.position.x);
writer2.Write(startingVent.transform.position.y + 0.3636f);
AmongUsClient.Instance.FinishRpcImmediately(writer2);

PlayerControl.LocalPlayer.NetTransform.RpcSnapTo(new Vector2(startingVent.transform.position.x, startingVent.transform.position.y + 0.3636f));
PlayerControl.LocalPlayer.MyPhysics.RpcEnterVent(startingVent.Id);
}

public static void Postfix(ExileController __instance) => ExileControllerPostfix(__instance);

[HarmonyPatch(typeof(Object), nameof(Object.Destroy), new Type[] { typeof(GameObject) })]
public static void Prefix(GameObject obj)
{
if (!SubmergedCompatibility.Loaded || GameOptionsManager.Instance.currentNormalGameOptions.MapId != 5) return;
if (obj.name.Contains("ExileCutscene")) ExileControllerPostfix(ExileControllerPatch.lastExiled);
}
}
}
19 changes: 16 additions & 3 deletions source/Patches/CrewmateRoles/SpyMod/Admin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,41 @@ public static void UpdateBlips(CounterArea area, List<int> colorMapping, bool is
public static void UpdateBlips(MapCountOverlay __instance, bool isSpy)
{
var rooms = ShipStatus.Instance.FastRooms;
var colorMapDuplicate = new List<int>();
foreach (var area in __instance.CountAreas)
{
if (!rooms.ContainsKey(area.RoomType)) continue;
var room = rooms[area.RoomType];
if (room.roomArea == null) continue;
var objectsInRoom = room.roomArea.OverlapCollider(__instance.filter, __instance.buffer);
var colorMap = new List<int>();
for (var i = 0;i < objectsInRoom;i++)
for (var i = 0; i < objectsInRoom; i++)
{
var collider = __instance.buffer[i];
var player = collider.GetComponent<PlayerControl>();
var data = player?.Data;
if (collider.tag == "DeadBody" &&
(isSpy && CustomGameOptions.WhoSeesDead == AdminDeadPlayers.Spy ||
(isSpy && CustomGameOptions.WhoSeesDead == AdminDeadPlayers.Spy ||
!isSpy && CustomGameOptions.WhoSeesDead == AdminDeadPlayers.EveryoneButSpy ||
CustomGameOptions.WhoSeesDead == AdminDeadPlayers.Everyone))
{
var playerId = collider.GetComponent<DeadBody>().ParentId;
colorMap.Add(GameData.Instance.GetPlayerById(playerId).DefaultOutfit.ColorId);
colorMapDuplicate.Add(GameData.Instance.GetPlayerById(playerId).DefaultOutfit.ColorId);
continue;
}
if (data != null && !data.Disconnected && !data.IsDead && !colorMap.Contains(data.DefaultOutfit.ColorId)) colorMap.Add(data.DefaultOutfit.ColorId);
else
{
PlayerControl component = collider.GetComponent<PlayerControl>();
if (component && component.Data != null && !component.Data.Disconnected && !component.Data.IsDead && (__instance.showLivePlayerPosition || !component.AmOwner))
{
if (!colorMapDuplicate.Contains(data.DefaultOutfit.ColorId))
{
colorMap.Add(data.DefaultOutfit.ColorId);
colorMapDuplicate.Add(data.DefaultOutfit.ColorId);
}
}
}
}
UpdateBlips(area, colorMap, isSpy);
}
Expand Down
24 changes: 0 additions & 24 deletions source/Patches/CrewmateRoles/SwapperMod/NoButtons.cs

This file was deleted.

1 change: 0 additions & 1 deletion source/Patches/CrewmateRoles/SwapperMod/ShowHideButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using HarmonyLib;
using Hazel;
using Reactor.Utilities;
using TownOfUs.CrewmateRoles.MayorMod;
using TownOfUs.Extensions;
using TownOfUs.Roles;
Expand Down
1 change: 0 additions & 1 deletion source/Patches/CrewmateRoles/VeteranMod/PerformKill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public static bool Prefix(KillButton __instance)
if (role.AlertTimer() != 0) return false;
role.TimeRemaining = CustomGameOptions.AlertDuration;
role.UsesLeft--;
role.RegenTask();
role.Alert();
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.Alert, SendOption.Reliable, -1);
Expand Down
27 changes: 1 addition & 26 deletions source/Patches/CrewmateRoles/VigilanteMod/VigilanteKill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,35 +212,10 @@ public static void VigiKillCount(PlayerControl player, PlayerControl vigilante)
}
}

if (ExilePatch.HaunterOn && ExilePatch.WillBeHaunter == null)
{
if (player.Is(Faction.Crewmates) && !player.Is(ModifierEnum.Lover))
{
ExilePatch.WillBeHaunter = player;
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.SetHaunter, SendOption.Reliable, -1);
writer.Write(player.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
}

if (ExilePatch.PhantomOn && ExilePatch.WillBePhantom == null)
{
if ((player.Is(Faction.NeutralOther) || player.Is(Faction.NeutralKilling)) && !player.Is(ModifierEnum.Lover))
{
ExilePatch.WillBePhantom = player;
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.SetPhantom, SendOption.Reliable, -1);
writer.Write(player.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
}

meetingHud.CheckForEndVoting();
}

ExilePatch.AssassinatedPlayers.Add(player);
ExilePatch.CheckTraitorSpawn(player);
AddHauntPatch.AssassinatedPlayers.Add(player);
}
}
}
1 change: 0 additions & 1 deletion source/Patches/CultistRoles/ChameleonMod/PerformKill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static bool Prefix(KillButton __instance)
if (!__instance.isActiveAndEnabled) return false;
if (role.SwoopTimer() != 0) return false;
role.TimeRemaining = CustomGameOptions.SwoopDuration;
role.RegenTask();
role.Swoop();
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.ChameleonSwoop, SendOption.Reliable, -1);
Expand Down

0 comments on commit 4528c3f

Please sign in to comment.