mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
136 lines
4.7 KiB
C#
136 lines
4.7 KiB
C#
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
|
using BetterAmongUs.Helpers;
|
|
using BetterAmongUs.Items.Enums;
|
|
using BetterAmongUs.Items.OptionItems;
|
|
using BetterAmongUs.Managers;
|
|
using BetterAmongUs.Mono;
|
|
using HarmonyLib;
|
|
using System.Collections;
|
|
|
|
namespace BetterAmongUs.Patches.Gameplay.Player;
|
|
|
|
[HarmonyPatch(typeof(PlayerControl))]
|
|
internal static class PlayerControlPatch
|
|
{
|
|
[HarmonyPatch(nameof(PlayerControl.Start))]
|
|
[HarmonyPostfix]
|
|
private static void Start_Postfix(PlayerControl __instance, ref Il2CppSystem.Collections.IEnumerator __result)
|
|
{
|
|
BAUPlugin.AllPlayerControls.Add(__instance);
|
|
OptionPlayerItem.UpdateAllValues();
|
|
|
|
__result = Effects.Sequence(__result, CoSetFavoriteColor(__instance).WrapToIl2Cpp());
|
|
}
|
|
|
|
private static IEnumerator CoSetFavoriteColor(PlayerControl player)
|
|
{
|
|
if (player.AmOwner)
|
|
{
|
|
if (BAUPlugin.FavoriteColor.Value >= 0 && player.cosmetics.ColorId != (byte)BAUPlugin.FavoriteColor.Value)
|
|
{
|
|
player.CmdCheckColor((byte)BAUPlugin.FavoriteColor.Value);
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerControl.OnDestroy))]
|
|
[HarmonyPostfix]
|
|
private static void OnDestroy_Postfix(PlayerControl __instance)
|
|
{
|
|
BAUPlugin.AllPlayerControls.Remove(__instance);
|
|
OptionPlayerItem.UpdateAllValues();
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerControl.MurderPlayer))]
|
|
[HarmonyPostfix]
|
|
private static void MurderPlayer_Postfix(PlayerControl __instance, PlayerControl target)
|
|
{
|
|
if (target == null) return;
|
|
|
|
Logger.LogPrivate($"{__instance.Data.PlayerName} Has killed {target.Data.PlayerName} as {__instance.Data.RoleType.GetRoleName()}", "EventLog");
|
|
|
|
__instance.BetterData().RoleInfo.Kills += 1;
|
|
|
|
HostManager.SyncNames(NameSyncType.Gameplay);
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerControl.Shapeshift))]
|
|
[HarmonyPostfix]
|
|
private static void Shapeshift_Postfix(PlayerControl __instance, PlayerControl targetPlayer, bool animate)
|
|
{
|
|
if (targetPlayer == null) return;
|
|
|
|
if (__instance != targetPlayer)
|
|
Logger.LogPrivate($"{__instance.Data.PlayerName} Has Shapeshifted into {targetPlayer.Data.PlayerName}, did animate: {animate}", "EventLog");
|
|
else
|
|
Logger.LogPrivate($"{__instance.Data.PlayerName} Has Un-Shapeshifted, did animate: {animate}", "EventLog");
|
|
|
|
HostManager.SyncNames(NameSyncType.Gameplay, 0.2f, 30);
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerControl.CompleteTask))]
|
|
[HarmonyPostfix]
|
|
private static void CompleteTask_Postfix(PlayerControl __instance)
|
|
{
|
|
HostManager.SyncNames(NameSyncType.Gameplay);
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerControl.StartMeeting))]
|
|
[HarmonyPrefix]
|
|
private static void StartMeeting_Prefix(PlayerControl __instance)
|
|
{
|
|
HostManager.SyncNames(NameSyncType.Meeting);
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerControl.SetRoleInvisibility))]
|
|
[HarmonyPostfix]
|
|
private static void SetRoleInvisibility_Postfix(PlayerControl __instance, bool isActive, bool shouldAnimate)
|
|
{
|
|
|
|
if (isActive)
|
|
Logger.LogPrivate($"{__instance.Data.PlayerName} Has Vanished as Phantom, did animate: {shouldAnimate}", "EventLog");
|
|
else
|
|
Logger.LogPrivate($"{__instance.Data.PlayerName} Has Appeared as Phantom, did animate: {shouldAnimate}", "EventLog");
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerControl.SetName))]
|
|
[HarmonyPostfix]
|
|
private static void SetName_Postfix(PlayerControl __instance, string playerName)
|
|
{
|
|
__instance.BetterDataWait(data =>
|
|
{
|
|
data.NameSetAsLast = playerName;
|
|
});
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(PlayerPhysics))]
|
|
internal static class PlayerPhysicsPatch
|
|
{
|
|
[HarmonyPatch(nameof(PlayerPhysics.BootFromVent))]
|
|
[HarmonyPostfix]
|
|
private static void BootFromVent_Postfix(PlayerPhysics __instance, int ventId)
|
|
{
|
|
|
|
Logger.LogPrivate($"{__instance.myPlayer.Data.PlayerName} Has been booted from vent: {ventId}, as {__instance.myPlayer.Data.RoleType.GetRoleName()}", "EventLog");
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerPhysics.CoEnterVent))]
|
|
[HarmonyPostfix]
|
|
private static void CoEnterVent_Postfix(PlayerPhysics __instance, int id)
|
|
{
|
|
|
|
Logger.LogPrivate($"{__instance.myPlayer.Data.PlayerName} Has entered vent: {id}, as {__instance.myPlayer.Data.RoleType.GetRoleName()}", "EventLog");
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerPhysics.CoExitVent))]
|
|
[HarmonyPostfix]
|
|
private static void CoExitVent_Postfix(PlayerPhysics __instance, int id)
|
|
{
|
|
|
|
Logger.LogPrivate($"{__instance.myPlayer.Data.PlayerName} Has exit vent: {id}, as {__instance.myPlayer.Data.RoleType.GetRoleName()}", "EventLog");
|
|
}
|
|
}
|