Files
EndlessHostRoles/Patches/LobbyPatch.cs
T
TommyXL 7929a4b83e Optimization (Part 1?) (#589)
* Well lets try check this

* Some changes

* Change

* Well

* Change ControllerManager.Update

* Nothing

* Optimaze more?

* Fix error build

* Fix win check

* Change

* Fix

* Optimaze some roles in OnCheckPlayerPosition

* More optimaze

* Full optimaze roles in OnGlobalFixedUpdate

* Optimaze some add-ons

* ProgressText

* Change

* Optimaze NameNotifyManager

* Optimaze NotifyRoles and some roles

* Move the displayed version

* Some changes

* Optimaze OnFixedUpdate in some roles

* Fix bugs

* Optimaze IsActive & V4 version

* Optimaze MapRoom.DoorsUpdate

* Cache TryCatch in IsActive

* Change

* Fix

* More optimze TaskPanelBehaviour

* Cache GetRoleColor & ColorString & AllStringNames & Change RemoveHtmlTags

* Cache TryCast VentilationSystem & ICriticalSabotage & IUsable and more optimaze

* Fix CountAlivePlayers

* Fix exceptios

* Replace some CachedAllPlayerControls to EnumeratePlayerControls

* Replace some CachedAlivePlayerControls to EnumerateAlivePlayerControls

* Fixes

* Fix modded clients

* Fix errors

* Fix again

* Optimaze & add null check

* Fix crash in Starlight

* Use only Main.PluginVersion in LobbySharingAPI

* Optimaze code in FixedUpdate

* Fix

* Optimize GetProgressText for Roles

* Some changes in Translations

* Cache Enum.GetValues and StringBuilder

* Changes

* CustomRole.ColoredTextByRole()

* Optimaze Lobby & Meeting

* ColorStringPrefix => ColorPrefix

* Add null check

* Remove

* Fixes & optimaze

* Fixes

* Changes

* Fix

* Fix

* Fix

* Remove

* Fix

* Change

* Revert
2026-05-15 20:01:54 +02:00

104 lines
3.5 KiB
C#

using System;
using HarmonyLib;
using TMPro;
using UnityEngine;
namespace EHR;
//[HarmonyPatch(typeof(LobbyBehaviour), nameof(LobbyBehaviour.FixedUpdate))]
public static class LobbyFixedUpdatePatch
{
private static GameObject Paint;
private static SpriteRenderer LeftEngineSR;
private static SpriteRenderer RightEngineSR;
public static void Postfix()
{
try
{
if (!Paint)
{
GameObject leftBox = GameObject.Find("Leftbox");
if (leftBox)
{
Paint = Object.Instantiate(leftBox, leftBox.transform.parent.transform);
Paint.name = "Lobby Paint";
Paint.transform.localPosition = new(0.042f, -2.59f, -10.5f);
var renderer = Paint.GetComponent<SpriteRenderer>();
renderer.sprite = Utils.LoadSprite("EHR.Resources.Images.LobbyPaint.png", 290f);
}
}
if (!LeftEngineSR || !RightEngineSR)
{
var leftEngine = GameObject.Find("LeftEngine");
if (leftEngine) LeftEngineSR = leftEngine.GetComponent<SpriteRenderer>();
var rightEngine = GameObject.Find("RightEngine");
if (rightEngine) RightEngineSR = rightEngine.GetComponent<SpriteRenderer>();
}
else
{
LeftEngineSR.color = Color.cyan;
RightEngineSR.color = Color.cyan;
}
}
catch (Exception e) { Utils.ThrowException(e); }
}
}
[HarmonyPatch(typeof(HostInfoPanel), nameof(HostInfoPanel.SetUp))]
public static class HostInfoPanelSetUpPatch
{
private static TextMeshPro HostText;
public static bool Prefix(HostInfoPanel __instance)
{
return GameStates.IsLobby && __instance.player.ColorId != byte.MaxValue;
}
public static void Postfix(HostInfoPanel __instance)
{
try
{
if (!HostText) HostText = __instance.content.transform.FindChild("Name").GetComponent<TextMeshPro>();
string name = AmongUsClient.Instance.GetHost().PlayerName.Split('\n')[^1];
if (name == string.Empty) return;
string text = AmongUsClient.Instance.AmHost
? Translator.GetString("YouAreHostSuffix")
: name;
HostText.text = Utils.ColorString(Palette.PlayerColors[__instance.player.ColorId], text);
}
catch { }
}
}
// https://github.com/SuperNewRoles/SuperNewRoles/blob/master/SuperNewRoles/Patches/LobbyBehaviourPatch.cs
//[HarmonyPatch(typeof(LobbyBehaviour), nameof(LobbyBehaviour.Update))]
internal static class LobbyBehaviourUpdatePatch
{
private static Func<ISoundPlayer, bool> Lobbybgm;
private static ISoundPlayer MapThemeSound;
public static void Postfix(LobbyBehaviour __instance)
{
// ReSharper disable once ConvertToLocalFunction
Lobbybgm = x => x.Name.Equals("MapTheme");
MapThemeSound = SoundManager.Instance.soundPlayers.Find(Lobbybgm);
if (!Main.LobbyMusic.Value)
{
if (MapThemeSound == null) return;
SoundManager.Instance.StopNamedSound("MapTheme");
}
else
{
if (MapThemeSound != null) return;
SoundManager.Instance.CrossFadeSound("MapTheme", __instance.MapTheme, 0.5f);
}
}
}