Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
v2.0.0 code
Browse files Browse the repository at this point in the history
  • Loading branch information
slushiegoose committed Apr 9, 2021
1 parent 9024eed commit 27b3bc4
Show file tree
Hide file tree
Showing 156 changed files with 2,375 additions and 948 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ An Among Us mod that adds a bunch of roles, modifiers and game settings
- [Child](#child)
- [Spy](#spy)
- [Snitch](#snitch)
- Altruist (description coming soon)

**Neutral Roles**
- [Jester](#jester)
Expand All @@ -43,6 +44,8 @@ An Among Us mod that adds a bunch of roles, modifiers and game settings
- [Flash](#flash)
- [Tiebreaker](#tiebreaker)
- [Drunk](#drunk)
- Giant (description coming soon)
- Button Barry (description coming soon)



Expand All @@ -60,6 +63,18 @@ An Among Us mod that adds a bunch of roles, modifiers and game settings
<details>
<summary> Changelog </summary>

<details>
<summary> v2.0.0 </summary>
<ul>
<li> Airship support! </li>
<li> New role - Altruist </li>
<li> New modifiers - Giant & Button Barry </li>
<li> Airship comms fix built-in </li>
<li> Bug fixes with Lovers, Time Lord etc. </li>
<li> New hats based on streamers! </li>
<li> Investigator cannot spawn on airship due to too much lag with handling footprints </li>
</ul>
</details>

<details>
<summary> v1.2.0 </summary>
Expand All @@ -72,8 +87,8 @@ An Among Us mod that adds a bunch of roles, modifiers and game settings
<li> Option for dead to see the roles of everyone </li>
<li> Custom colours now work! </li>
</ul>
</details>
<details>
</details>
<details>
<summary> v1.1.0 </summary>
<ul>
<li> New roles (see above)</a>
Expand Down
119 changes: 119 additions & 0 deletions source/Patches/AltruistMod/Coroutine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TownOfUs.Roles;
using UnityEngine;
using Object = UnityEngine.Object;


namespace TownOfUs.AltruistMod
{
public class Coroutine
{
public static ArrowBehaviour Arrow;
public static PlayerControl Target;
public static Sprite Sprite => TownOfUs.Arrow;

public static IEnumerator AltruistRevive(DeadBody target, Altruist role)
{
var parentId = target.ParentId;
var position = target.TruePosition;

var revived = new List<PlayerControl>();


Utils.MurderPlayer(role.Player, role.Player);

if (CustomGameOptions.AltruistTargetBody)
{
if(target != null) Object.Destroy(target.gameObject);
}

var startTime = DateTime.UtcNow;
while (true)
{
var now = DateTime.UtcNow;
var seconds = (now - startTime).TotalSeconds;
if (seconds < CustomGameOptions.ReviveDuration)
{
yield return null;
}
else break;

if (MeetingHud.Instance) yield break;

}

var altruistBody = Object.FindObjectsOfType<DeadBody>().FirstOrDefault(b => b.ParentId == role.Player.PlayerId);
if (altruistBody != null)
{
Object.Destroy(altruistBody.gameObject);
}

var player = Utils.PlayerById(parentId);


player.Revive();
MedicMod.Murder.KilledPlayers.Remove(
MedicMod.Murder.KilledPlayers.FirstOrDefault(x => x.PlayerId == player.PlayerId));
revived.Add(player);
player.NetTransform.SnapTo(position);

if (target != null)
{

Object.Destroy(target.gameObject);
}

if (player.isLover())
{
var lover = Roles.Role.GetRole<Lover>(player).OtherLover.Player;

lover.Revive();
MedicMod.Murder.KilledPlayers.Remove(
MedicMod.Murder.KilledPlayers.FirstOrDefault(x => x.PlayerId == lover.PlayerId));
revived.Add(lover);

var loverBody = Object.FindObjectsOfType<DeadBody>().FirstOrDefault(b => b.ParentId == lover.PlayerId);

if (loverBody != null)
{
lover.NetTransform.SnapTo(loverBody.TruePosition);
Object.Destroy(loverBody.gameObject);
}

}

if (revived.Any(x => x.AmOwner))
{
try
{
Minigame.Instance.Close();
Minigame.Instance.Close();
}
catch
{
}
}


if (PlayerControl.LocalPlayer.Data.IsImpostor)
{
var gameObj = new GameObject();
Arrow = gameObj.AddComponent<ArrowBehaviour>();
gameObj.transform.parent = PlayerControl.LocalPlayer.gameObject.transform;
var renderer = gameObj.AddComponent<SpriteRenderer>();
renderer.sprite = Sprite;
Arrow.image = renderer;
gameObj.layer = 5;
Target = player;
yield return Utils.FlashCoroutine(role.Color, 1f, 0.5f);
}




}
}
}
62 changes: 62 additions & 0 deletions source/Patches/AltruistMod/HudManagerUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using HarmonyLib;
using UnityEngine;

namespace TownOfUs.AltruistMod
{
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))]
public class HudManagerUpdate
{
public 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.Is(RoleEnum.Altruist)) return;

var role = Roles.Role.GetRole<Roles.Altruist>(PlayerControl.LocalPlayer);

var data = PlayerControl.LocalPlayer.Data;
var isDead = data.IsDead;
var truePosition = PlayerControl.LocalPlayer.GetTruePosition();
var maxDistance = GameOptionsData.KillDistances[PlayerControl.GameOptions.KillDistance];
var flag = (PlayerControl.GameOptions.GhostsDoTasks || !data.IsDead) &&
(!AmongUsClient.Instance || !AmongUsClient.Instance.IsGameOver) && PlayerControl.LocalPlayer.CanMove;
var allocs = Physics2D.OverlapCircleAll(truePosition, maxDistance,
LayerMask.GetMask(new [] {"Players", "Ghost"}));
var killButton = __instance.KillButton;
DeadBody closestBody = null;
var closestDistance = float.MaxValue;

foreach (var collider2D in allocs)
{
if (!flag || isDead || collider2D.tag != "DeadBody") continue;
var component = collider2D.GetComponent<DeadBody>();


if (!(Vector2.Distance(truePosition, component.TruePosition) <=
maxDistance)) continue;

var distance = Vector2.Distance(truePosition, component.TruePosition);
if (!(distance < closestDistance)) continue;
closestBody = component;
closestDistance = distance;

}

if (isDead)
{
killButton.gameObject.SetActive(false);
killButton.isActive = false;
}
else
{
killButton.gameObject.SetActive(!MeetingHud.Instance);
killButton.isActive = !MeetingHud.Instance;
}

KillButtonTarget.SetTarget(killButton, closestBody, role);
__instance.KillButton.SetCoolDown(0f, 1f);
}

}
}
40 changes: 40 additions & 0 deletions source/Patches/AltruistMod/KillButtonTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using HarmonyLib;
using UnityEngine;

namespace TownOfUs.AltruistMod
{
[HarmonyPatch(typeof(KillButtonManager), nameof(KillButtonManager.SetTarget))]
public class KillButtonTarget
{

public static byte DontRevive = byte.MaxValue;
public static bool Prefix(KillButtonManager __instance)
{
return !PlayerControl.LocalPlayer.Is(RoleEnum.Altruist);
}

public static void SetTarget(KillButtonManager __instance, DeadBody target, Roles.Altruist role)
{
if (role.CurrentTarget && role.CurrentTarget != target)
{
role.CurrentTarget.GetComponent<SpriteRenderer>().material.SetFloat("_Outline", 0f);
}


if (target != null && target.ParentId == DontRevive) target = null;
role.CurrentTarget = target;
if (role.CurrentTarget && __instance.enabled)
{
var component = role.CurrentTarget.GetComponent<SpriteRenderer>();
component.material.SetFloat("_Outline", 1f);
component.material.SetColor("_OutlineColor", Color.red);
__instance.renderer.color = Palette.EnabledColor;
__instance.renderer.material.SetFloat("_Desat", 0f);
return;
}

__instance.renderer.color = Palette.DisabledClear;
__instance.renderer.material.SetFloat("_Desat", 1f);
}
}
}
39 changes: 39 additions & 0 deletions source/Patches/AltruistMod/PerformKillButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using HarmonyLib;
using Hazel;
using Reactor;
using TownOfUs.Roles;
using UnityEngine;

namespace TownOfUs.AltruistMod
{
[HarmonyPatch(typeof(KillButtonManager), nameof(KillButtonManager.PerformKill))]
public class PerformKillButton
{
public static bool Prefix(KillButtonManager __instance)
{
if (__instance != DestroyableSingleton<HudManager>.Instance.KillButton) return true;
var flag = PlayerControl.LocalPlayer.Is(RoleEnum.Altruist);
if (!flag) return true;
if (!PlayerControl.LocalPlayer.CanMove) return false;
if (PlayerControl.LocalPlayer.Data.IsDead) return false;
var role = Roles.Role.GetRole<Altruist>(PlayerControl.LocalPlayer);

var flag2 = __instance.isCoolingDown;
if (flag2) return false;
if (!__instance.enabled) return false;
var maxDistance = GameOptionsData.KillDistances[PlayerControl.GameOptions.KillDistance];
if (Vector2.Distance(role.CurrentTarget.TruePosition,
PlayerControl.LocalPlayer.GetTruePosition()) > maxDistance) return false;
var playerId = role.CurrentTarget.ParentId;

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

Coroutines.Start(Coroutine.AltruistRevive(role.CurrentTarget, role));
return false;
}
}
}
27 changes: 27 additions & 0 deletions source/Patches/AltruistMod/UpdateArrows.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using HarmonyLib;
using Reactor.Extensions;

namespace TownOfUs.AltruistMod
{
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.FixedUpdate))]
public class UpdateArrows
{
public static void Postfix(PlayerControl __instance)
{
if (Coroutine.Arrow != null)
{
if (LobbyBehaviour.Instance || MeetingHud.Instance || PlayerControl.LocalPlayer.Data.IsDead ||
Coroutine.Target.Data.IsDead)
{
Coroutine.Arrow.gameObject.Destroy();
Coroutine.Target = null;
return;
}

Coroutine.Arrow.target = Coroutine.Target.transform.position;

}
}

}
}
2 changes: 1 addition & 1 deletion source/Patches/AmongUsClient_OnGameEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Postfix(AmongUsClient __instance, [HarmonyArgument(0)] GameOv
}
}

[HarmonyPatch(typeof(EndGameManager), nameof(EndGameManager.SetEverythingUp))]
[HarmonyPatch(typeof(EndGameManager), nameof(EndGameManager.Start))]
public class EndGameManager_SetEverythingUp
{
public static void Prefix()
Expand Down
3 changes: 3 additions & 0 deletions source/Patches/ArsonistMod/EndGame.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using Hazel;
using TownOfUs.Roles;
using Reactor.Extensions;

namespace TownOfUs.ArsonistMod
{
Expand Down
9 changes: 5 additions & 4 deletions source/Patches/ArsonistMod/HUDClose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
namespace TownOfUs.ArsonistMod
{

[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Close))]
[HarmonyPatch(typeof(UnityEngine.Object), nameof(UnityEngine.Object.Destroy), new Type[] { typeof(UnityEngine.Object) })]
public static class HUDClose
{

public static void Postfix(MeetingHud __instance)
{

public static void Postfix(UnityEngine.Object obj)
{
if (ExileController.Instance == null || obj != ExileController.Instance.gameObject) return;
foreach (var role in Roles.Role.GetRoles(RoleEnum.Arsonist))
{
var arsonist = (Roles.Arsonist) role;
Expand Down
Loading

0 comments on commit 27b3bc4

Please sign in to comment.