mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-24 06:46:46 +00:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e901abfc60 | ||
|
|
853a94681a | ||
|
|
f230cff5e5 | ||
|
|
7c7d184d1f | ||
|
|
6b923cfe01 | ||
|
|
247c765176 | ||
|
|
a3668b3150 | ||
|
|
aa4dd24ac3 | ||
|
|
cb0afe3095 |
No files matched your search
@@ -0,0 +1,203 @@
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using InnerNet;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Modifiers.ModifierDisplay;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
[RegisterInIl2Cpp]
|
||||
public sealed class MiraHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
public static MiraHudHelper Instance { get; private set; }
|
||||
public static GameObject ModifierDisplayObject;
|
||||
public static GameObject VanillaMatchInfoButton;
|
||||
public static bool ModifierDisplayOnRight;
|
||||
public static GameObject ClonedChatButton;
|
||||
public static GameObject ExtraUiTopRight;
|
||||
public static GridArrange ExtraUiGrid;
|
||||
public static AspectPosition ExtraUiAspectPos;
|
||||
public static GameObject UiTopRight;
|
||||
public static GridArrange UiGrid;
|
||||
public static AspectPosition UiAspectPos;
|
||||
public static GameObject SubmergedFloorButton;
|
||||
public static SpriteRenderer SubmergedFloorButtonRenderer;
|
||||
public static SpriteRenderer SubmergedFloorButtonRendererHover;
|
||||
public void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
MiraApiSettings.OldButtonScaleFactor =
|
||||
LocalSettingsTabSingleton<MiraApiSettings>.Instance.TopRightButtonsFactorSlider.Value;
|
||||
StartCoroutine(MiraApiSettings.CoResizeSettingsUI().WrapToIl2Cpp());
|
||||
}
|
||||
#pragma warning disable S2325
|
||||
#pragma warning disable CA1822
|
||||
public void FixedUpdate()
|
||||
{
|
||||
if (!HudManager.InstanceExists || !PlayerControl.LocalPlayer || !PlayerControl.LocalPlayer.Data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var instance = HudManager.Instance;
|
||||
|
||||
CreateUiRow(instance);
|
||||
CreateNewUiRow(instance);
|
||||
AdjustModifierTab();
|
||||
|
||||
if (!PlayerControl.LocalPlayer || !PlayerControl.LocalPlayer.Data || !PlayerControl.LocalPlayer.Data.Role ||
|
||||
!ShipStatus.Instance ||
|
||||
(AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started &&
|
||||
!TutorialManager.InstanceExists))
|
||||
{
|
||||
return;
|
||||
}
|
||||
UpdateSubmergedButtons(instance);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
#pragma warning restore S2325
|
||||
|
||||
public static Vector3 BelowOptionPos = new(0.435f, 1.25f, 0f);
|
||||
public static Vector3 FullTopPos = new(0.435f, 0.475f, 0f);
|
||||
public static void CreateUiRow(HudManager instance)
|
||||
{
|
||||
if (!UiTopRight)
|
||||
{
|
||||
UiTopRight = instance.MapButton.transform.parent.gameObject;
|
||||
|
||||
UiGrid = UiTopRight.AddComponent<GridArrange>();
|
||||
UiAspectPos = UiTopRight.AddComponent<AspectPosition>();
|
||||
|
||||
UiGrid.Alignment = GridArrange.StartAlign.Left;
|
||||
UiGrid.CellSize = new Vector2(0.85f, 0.85f);
|
||||
UiGrid.MaxColumns = 6;
|
||||
UiAspectPos.Alignment = AspectPosition.EdgeAlignments.RightTop;
|
||||
UiGrid.Start();
|
||||
UiAspectPos.DistanceFromEdge = FullTopPos;
|
||||
var mapButton = instance.MapButton.gameObject;
|
||||
mapButton.GetComponent<AspectPosition>().Destroy();
|
||||
var settingsButton = instance.SettingsButton;
|
||||
settingsButton.GetComponent<AspectPosition>().Destroy();
|
||||
VanillaMatchInfoButton = instance.MatchInfoButton.gameObject;
|
||||
VanillaMatchInfoButton.GetComponent<AspectPosition>().Destroy();
|
||||
var oldPos = settingsButton.transform.localPosition;
|
||||
settingsButton.transform.localPosition = new Vector3(oldPos.x, oldPos.y, -100);
|
||||
var chatButton = instance.Chat.chatButton.gameObject;
|
||||
ClonedChatButton = Object.Instantiate(chatButton, chatButton.transform.parent);
|
||||
ClonedChatButton.SetActive(false);
|
||||
instance.Chat.chatButtonAspectPosition = ClonedChatButton.GetComponent<AspectPosition>();
|
||||
chatButton.GetComponent<AspectPosition>().Destroy();
|
||||
var inactivePos = settingsButton.transform.GetChild(1).transform.localPosition;
|
||||
var bg = settingsButton.transform.GetChild(2).gameObject;
|
||||
var bgPos = bg.transform.localPosition;
|
||||
var bgSprite = bg.GetComponent<SpriteRenderer>().sprite;
|
||||
var activePos = settingsButton.transform.GetChild(3).transform.localPosition;
|
||||
var selectedPos = settingsButton.transform.GetChild(4).transform.localPosition;
|
||||
chatButton.transform.GetChild(2).transform.localPosition = inactivePos;
|
||||
var chatBg = chatButton.transform.GetChild(3);
|
||||
chatBg.transform.localPosition = bgPos;
|
||||
chatBg.GetComponent<SpriteRenderer>().sprite = bgSprite;
|
||||
chatButton.transform.GetChild(4).transform.localPosition = activePos;
|
||||
chatButton.transform.GetChild(5).transform.localPosition = selectedPos;
|
||||
var collider = chatButton.GetComponent<BoxCollider2D>();
|
||||
collider.size = new Vector2(0.4354f, 0.4003f);
|
||||
collider.offset = new Vector2(0.0025f, 0.0254f);
|
||||
if (FriendsListManager.InstanceExists && !TutorialManager.InstanceExists)
|
||||
{
|
||||
var listButton = FriendsListManager.Instance.FriendsListButton.transform.GetChild(0);
|
||||
listButton.transform.SetParent(UiTopRight.transform, false);
|
||||
FriendsListManager.Instance.FriendsListButton = listButton.GetComponent<FriendsListButton>();
|
||||
listButton.GetComponent<AspectPosition>().Destroy();
|
||||
listButton.localPosition = new Vector3(0, 0, 0);
|
||||
}
|
||||
settingsButton.transform.SetAsLastSibling();
|
||||
chatButton.transform.SetParent(UiTopRight.transform, false);
|
||||
instance.Chat.chatButton = chatButton.GetComponent<PassiveButton>();
|
||||
var iconContainer = new GameObject("iconContainer")
|
||||
{
|
||||
layer = LayerMask.NameToLayer("UI"),
|
||||
};
|
||||
iconContainer.transform.SetParent(chatButton.transform, false);
|
||||
iconContainer.transform.localPosition = new Vector3(0.1f, -0.1f, 0);
|
||||
instance.Chat.chatNotifyDot.transform.SetParent(iconContainer.transform, false);
|
||||
instance.Chat.chatNotifyDot = iconContainer.transform.GetChild(0).GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
if (UiTopRight && UiGrid)
|
||||
{
|
||||
var isChatButtonVisible = HudManager.Instance.Chat.isActiveAndEnabled;
|
||||
instance.Chat.chatButton.gameObject.SetActive(isChatButtonVisible);
|
||||
if (VanillaMatchInfoButton)
|
||||
{
|
||||
VanillaMatchInfoButton.SetActive(!GameSettingMenu.Instance && !Minigame.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void UpdateSubmergedButtons(HudManager instance)
|
||||
{
|
||||
if (ModCompatibility.IsSubmerged() && !SubmergedFloorButton && ExtraUiTopRight)
|
||||
{
|
||||
if (!SubmergedFloorButton && ExtraUiTopRight)
|
||||
{
|
||||
var transform = instance.MapButton.transform.parent.Find(instance.MapButton.name + "(Clone)");
|
||||
if (transform != null)
|
||||
{
|
||||
SubmergedFloorButton = transform.gameObject;
|
||||
SubmergedFloorButton.transform.SetParent(ExtraUiTopRight.transform, false);
|
||||
|
||||
SubmergedFloorButtonRenderer =
|
||||
SubmergedFloorButton.transform.Find("Inactive").GetComponent<SpriteRenderer>();
|
||||
SubmergedFloorButtonRendererHover =
|
||||
SubmergedFloorButton.transform.Find("Active").GetComponent<SpriteRenderer>();
|
||||
|
||||
MiraApiSettings.SetUpButtonPositions();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AdjustModifierTab()
|
||||
{
|
||||
if (!ModifierDisplayObject && UiTopRight && ExtraUiTopRight && ModifierDisplayComponent.Instance)
|
||||
{
|
||||
ModifierDisplayObject = ModifierDisplayComponent.Instance?.gameObject ?? null!;
|
||||
ModifierDisplayOnRight = !LocalSettingsTabSingleton<MiraApiSettings>.Instance.ModifiersHudLeftSide.Value;
|
||||
if (ModifierDisplayOnRight)
|
||||
{
|
||||
ModifierDisplayObject.transform.SetParent(ExtraUiTopRight.transform, false);
|
||||
ModifierDisplayObject.GetComponent<AspectPosition>().Destroy();
|
||||
var oldPos = ModifierDisplayObject.transform.GetChild(0).localPosition;
|
||||
ModifierDisplayObject.transform.GetChild(0).localPosition = new Vector3(-1.1757f, -2.1633f, oldPos.z);
|
||||
oldPos = ModifierDisplayObject.transform.GetChild(1).localPosition;
|
||||
ModifierDisplayObject.transform.GetChild(1).localPosition = new Vector3(-0.45f, 0.3f, oldPos.z);
|
||||
}
|
||||
MiraApiSettings.SetUpButtonPositions();
|
||||
}
|
||||
}
|
||||
public static void CreateNewUiRow(HudManager instance)
|
||||
{
|
||||
if (!ExtraUiTopRight && UiTopRight)
|
||||
{
|
||||
ExtraUiTopRight = new GameObject("ExtraUiTopRight")
|
||||
{
|
||||
layer = UiTopRight.layer
|
||||
};
|
||||
ExtraUiTopRight.transform.SetParent(instance.MapButton.transform.parent.parent, false);
|
||||
|
||||
ExtraUiGrid = ExtraUiTopRight.AddComponent<GridArrange>();
|
||||
ExtraUiAspectPos = ExtraUiTopRight.AddComponent<AspectPosition>();
|
||||
|
||||
ExtraUiGrid.Alignment = GridArrange.StartAlign.Left;
|
||||
ExtraUiGrid.CellSize = new Vector2(0.85f, 0.85f);
|
||||
ExtraUiAspectPos.Alignment = AspectPosition.EdgeAlignments.RightTop;
|
||||
ExtraUiAspectPos.DistanceFromEdge = BelowOptionPos;
|
||||
ExtraUiGrid.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ namespace MiraAPI;
|
||||
[BepInAutoPlugin("mira.api", "MiraAPI")]
|
||||
[BepInProcess("Among Us.exe")]
|
||||
[BepInDependency(ReactorPlugin.Id)]
|
||||
[BepInDependency(ModCompatibility.SubmergedId, BepInDependency.DependencyFlags.SoftDependency)]
|
||||
[ReactorModFlags(ModFlags.RequireOnAllClients)]
|
||||
public partial class MiraApiPlugin : BasePlugin, IMiraPlugin
|
||||
{
|
||||
@@ -69,5 +68,9 @@ public partial class MiraApiPlugin : BasePlugin, IMiraPlugin
|
||||
|
||||
PluginManager = new MiraPluginManager();
|
||||
PluginManager.Initialize(this, this);
|
||||
|
||||
IL2CPPChainloader.Instance.Finished +=
|
||||
ModCompatibility
|
||||
.Initialize; // Initialise AFTER the mods are loaded to ensure maximum parity (no need for the soft dependency either then)
|
||||
}
|
||||
}
|
||||
+163
-3
@@ -1,4 +1,6 @@
|
||||
using BepInEx.Configuration;
|
||||
using System.Collections;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.LocalSettings.Attributes;
|
||||
using MiraAPI.Patches;
|
||||
@@ -25,15 +27,21 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value stored for scaling buttons properly.
|
||||
/// Gets or sets the value stored for scaling ability buttons properly.
|
||||
/// </summary>
|
||||
public static float OldButtonScaleFactor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value stored for scaling UI buttons properly.
|
||||
/// </summary>
|
||||
public static float OldUiButtonScaleFactor { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Open()
|
||||
{
|
||||
base.Open();
|
||||
OldButtonScaleFactor = ButtonUIFactorSlider.Value;
|
||||
OldUiButtonScaleFactor = TopRightButtonsFactorSlider.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -49,12 +57,153 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
}
|
||||
OldButtonScaleFactor = ButtonUIFactorSlider.Value;
|
||||
}
|
||||
else if (configEntry == TopRightButtonsFactorSlider)
|
||||
{
|
||||
if (MiraHudHelper.Instance)
|
||||
{
|
||||
ResizeUI(TopRightButtonsFactorSlider.Value);
|
||||
}
|
||||
OldUiButtonScaleFactor = TopRightButtonsFactorSlider.Value;
|
||||
}
|
||||
else if (configEntry == WikiOnBottomRow)
|
||||
{
|
||||
SetUpButtonPositions();
|
||||
}
|
||||
else if (configEntry == SetFpsSlider)
|
||||
{
|
||||
Application.targetFrameRate = (int)SetFpsSlider.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetUpButtonPositions()
|
||||
{
|
||||
var topUi = MiraHudHelper.UiTopRight;
|
||||
var extraTopUi = MiraHudHelper.ExtraUiTopRight;
|
||||
var wikiButton = MiraHudHelper.VanillaMatchInfoButton;
|
||||
var subButton = MiraHudHelper.SubmergedFloorButton;
|
||||
var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!;
|
||||
ResetButtonPositions();
|
||||
if (topUi && extraTopUi)
|
||||
{
|
||||
var opts = LocalSettingsTabSingleton<MiraApiSettings>.Instance;
|
||||
if (wikiButton)
|
||||
{
|
||||
wikiButton.transform.SetParent(opts.WikiOnBottomRow.Value ? extraTopUi.transform : topUi.transform);
|
||||
}
|
||||
if (subButton)
|
||||
{
|
||||
subButton.transform.SetParent(extraTopUi.transform);
|
||||
}
|
||||
if (modDisplay)
|
||||
{
|
||||
modDisplay.transform.SetParent(extraTopUi.transform);
|
||||
}
|
||||
MiraHudHelper.UiGrid.ArrangeChilds();
|
||||
MiraHudHelper.ExtraUiGrid.ArrangeChilds();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetButtonPositions()
|
||||
{
|
||||
var topUi = MiraHudHelper.UiTopRight;
|
||||
var extraTopUi = MiraHudHelper.ExtraUiTopRight;
|
||||
var subButton = MiraHudHelper.SubmergedFloorButton;
|
||||
var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!;
|
||||
if (topUi && extraTopUi)
|
||||
{
|
||||
var wikiButton = MiraHudHelper.VanillaMatchInfoButton;
|
||||
if (wikiButton)
|
||||
{
|
||||
wikiButton.transform.SetParent(null);
|
||||
}
|
||||
if (subButton)
|
||||
{
|
||||
subButton.transform.SetParent(null);
|
||||
}
|
||||
if (modDisplay)
|
||||
{
|
||||
modDisplay.transform.SetParent(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerator CoResizeSettingsUI()
|
||||
{
|
||||
while (!HudManager.Instance || !MiraHudHelper.UiGrid || !MiraHudHelper.ExtraUiGrid)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(0.01f);
|
||||
ResizeUI(LocalSettingsTabSingleton<MiraApiSettings>.Instance.TopRightButtonsFactorSlider.Value);
|
||||
}
|
||||
|
||||
public static void ResizeUI(float scaleFactor)
|
||||
{
|
||||
var alteredScale = scaleFactor * 0.85f;
|
||||
var actualScaleVal = scaleFactor * 1.176470588235294f;
|
||||
var actualScale = new Vector3(actualScaleVal, actualScaleVal, 1);
|
||||
var baseAspect = MiraHudHelper.UiAspectPos;
|
||||
var baseGrid = MiraHudHelper.UiGrid;
|
||||
var baseUi = MiraHudHelper.UiTopRight;
|
||||
if (baseUi && baseAspect && baseGrid)
|
||||
{
|
||||
baseAspect.DistanceFromEdge = new Vector2(0.435f * scaleFactor, 0.475f * scaleFactor);
|
||||
|
||||
foreach (var button in baseUi.GetComponentsInChildren<PassiveButton>(true))
|
||||
{
|
||||
if (button.gameObject == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (button.transform.name.Contains("Friends List Button"))
|
||||
{
|
||||
button.gameObject.transform.localScale = new Vector3(0.2675f * actualScaleVal, 0.2675f * actualScaleVal, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
button.gameObject.transform.localScale = actualScale;
|
||||
}
|
||||
|
||||
baseGrid.CellSize = new Vector2(alteredScale, alteredScale);
|
||||
if (baseGrid.gameObject.transform.childCount != 0)
|
||||
{
|
||||
baseGrid.ArrangeChilds();
|
||||
}
|
||||
baseAspect.AdjustPosition();
|
||||
}
|
||||
|
||||
var extraAspect = MiraHudHelper.ExtraUiAspectPos;
|
||||
var extraGrid = MiraHudHelper.ExtraUiGrid;
|
||||
var extraUi = MiraHudHelper.ExtraUiTopRight;
|
||||
if (extraUi && extraAspect && extraGrid)
|
||||
{
|
||||
extraAspect.DistanceFromEdge = new Vector3(0.435f * scaleFactor, 1.25f * scaleFactor, 0f);
|
||||
|
||||
foreach (var button in extraUi.GetAllChildren())
|
||||
{
|
||||
if (button.gameObject == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (button.transform.name.Contains("Modifiers"))
|
||||
{
|
||||
button.gameObject.transform.localScale = new Vector3(0.65f * scaleFactor, 0.65f * scaleFactor, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
button.gameObject.transform.localScale = actualScale;
|
||||
}
|
||||
|
||||
extraGrid.CellSize = new Vector2(alteredScale, alteredScale);
|
||||
if (extraGrid.gameObject.transform.childCount != 0)
|
||||
{
|
||||
extraGrid.ArrangeChilds();
|
||||
}
|
||||
extraAspect.AdjustPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the modifiers hud should be on the left side of the screen (under roles/task tab). Recommended for streamers.
|
||||
/// </summary>
|
||||
@@ -68,12 +217,19 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
public ConfigEntry<bool> ShowKeybinds { get; private set; } = config.Bind("Visuals/UI", "Show Keybinds on Buttons", true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scale of the buttons.
|
||||
/// Gets the scale of the ability buttons.
|
||||
/// </summary>
|
||||
[LocalSliderSetting(min: 0.5f, max: 1.5f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
||||
public ConfigEntry<float> ButtonUIFactorSlider { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Button Scale Factor", 0.75f);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scale of the UI buttons.
|
||||
/// </summary>
|
||||
[LocalSliderSetting(min: 0.3f, max: 2f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
||||
public ConfigEntry<float> TopRightButtonsFactorSlider { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Top-Right UI Scale Factor", 1f);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fps specified by the player.
|
||||
/// </summary>
|
||||
@@ -81,6 +237,10 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
public ConfigEntry<float> SetFpsSlider { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Max FPS", 120f);
|
||||
|
||||
[LocalToggleSetting]
|
||||
public ConfigEntry<bool> WikiOnBottomRow { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Display Wiki on Bottom Row", true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to apply cosmetic changes to the TaskAdder.
|
||||
/// </summary>
|
||||
|
||||
+32
-11
@@ -1,6 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using SemanticVersioning;
|
||||
|
||||
namespace MiraAPI;
|
||||
|
||||
@@ -14,15 +14,36 @@ public static class ModCompatibility
|
||||
/// </summary>
|
||||
public const string SubmergedId = "Submerged";
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the Submerged mod is loaded.
|
||||
/// </summary>
|
||||
/// <param name="submergedAssembly">Submerged mod assembly if loaded, <see langword="null"/> otherwise.</param>
|
||||
/// <returns><see langword="true"/> if the Submerged mod is loaded, <see langword="false"/> otherwise.</returns>
|
||||
public static bool SubmergedLoaded([NotNullWhen(true)] out Assembly? submergedAssembly)
|
||||
public static Version SubVersion { get; private set; }
|
||||
public static bool SubLoaded { get; private set; }
|
||||
public static BasePlugin SubPlugin { get; private set; }
|
||||
public static Assembly SubAssembly { get; private set; }
|
||||
|
||||
public const ShipStatus.MapType SubmergedMapType = (ShipStatus.MapType)6;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
var result = IL2CPPChainloader.Instance.Plugins.TryGetValue(SubmergedId, out var plugin);
|
||||
submergedAssembly = result ? plugin?.Instance.GetType().Assembly : null;
|
||||
return result;
|
||||
InitSubmerged();
|
||||
}
|
||||
|
||||
public static void InitSubmerged()
|
||||
{
|
||||
if (!IL2CPPChainloader.Instance.Plugins.TryGetValue(SubmergedId, out var plugin))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SubPlugin = (plugin!.Instance as BasePlugin)!;
|
||||
SubVersion = plugin.Metadata.Version;
|
||||
|
||||
SubAssembly = SubPlugin.GetType().Assembly;
|
||||
|
||||
SubLoaded = true;
|
||||
Message("Submerged was detected");
|
||||
}
|
||||
|
||||
public static bool IsSubmerged()
|
||||
{
|
||||
return SubLoaded && ShipStatus.Instance && ShipStatus.Instance.Type == SubmergedMapType;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
@@ -112,6 +114,58 @@ public static class HudManagerPatches
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// Trigger hudstart on current custom gamemode
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(HudManager.OnGameStart))]
|
||||
public static void GameStartPatch(HudManager __instance)
|
||||
{
|
||||
CustomGameModeManager.ActiveMode?.HudStart(__instance);
|
||||
}*/
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(FriendsListManager), nameof(FriendsListManager.SetFriendButtonColor))]
|
||||
public static bool SetFriendButtonColor(FriendsListManager __instance, bool isGrayedOut)
|
||||
{
|
||||
__instance.FriendsListButton?.SetGlyphColor(isGrayedOut);
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.Toggle))]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.Close))]
|
||||
public static void TogglePrefix(ChatController __instance)
|
||||
{
|
||||
if (!MiraHudHelper.ClonedChatButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
__instance.chatButton.transform.localPosition = MiraHudHelper.ClonedChatButton.transform.localPosition + new Vector3(-0.3f, 0);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.Toggle))]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.Close))]
|
||||
public static void TogglePostfix(ChatController __instance)
|
||||
{
|
||||
MiraHudHelper.UiGrid.ArrangeChilds();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.AddChatNote))]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.AddChat))]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.AddChatWarning))]
|
||||
public static void ChatBubbleUpdatePrefix(ChatController __instance)
|
||||
{
|
||||
__instance.chatNotifyDot.transform.localPosition = new Vector3(-0.34f, 0.373f, -1f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create custom buttons and arrange them on the hud.
|
||||
/// </summary>
|
||||
@@ -120,6 +174,7 @@ public static class HudManagerPatches
|
||||
[HarmonyPatch(nameof(HudManager.Start))]
|
||||
public static void StartPostfix(HudManager __instance)
|
||||
{
|
||||
__instance.gameObject.AddComponent<MiraHudHelper>();
|
||||
if (Buttons == null)
|
||||
{
|
||||
Buttons = __instance.transform.Find("Buttons");
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Innersloth.Assets;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class RoleGuidePatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.CreateNormalModeSettings))]
|
||||
[HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.CreateHnSModeSettings))]
|
||||
public static void CreateNormalModeSettings(MatchInfoGuide __instance)
|
||||
{
|
||||
__instance.MatchInfoRoleMaskArea.transform.localPosition = new Vector3(-0.0184f, 0.15f, -0.1f);
|
||||
|
||||
__instance.matchInfoPlayersMaskArea.transform.localPosition =
|
||||
__instance.matchInfoSettingsMaskArea.transform.localPosition = new Vector3(1.22f, -0.335f, -0.1f);
|
||||
|
||||
__instance.matchInfoPlayersMaskArea.size =
|
||||
__instance.matchInfoSettingsMaskArea.size =
|
||||
__instance.MatchInfoRoleMaskArea.size = new Vector2(-6, 1.8f);
|
||||
|
||||
__instance.matchInfoPlayersMaskArea.transform.parent.GetAllChildren().First(x => x.name.Contains("BG_Gradient"))
|
||||
.GetComponent<SpriteRenderer>()
|
||||
.maskInteraction =
|
||||
__instance.matchInfoSettingsMaskArea.transform.parent.GetAllChildren()
|
||||
.First(x => x.name.Contains("BG_Gradient")).GetComponent<SpriteRenderer>()
|
||||
.maskInteraction =
|
||||
__instance.MatchInfoRoleMaskArea.transform.parent.GetAllChildren()
|
||||
.First(x => x.name.Contains("BG_Gradient")).GetComponent<SpriteRenderer>()
|
||||
.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.Awake))]
|
||||
public static void Awake(MatchInfoGuide __instance)
|
||||
{
|
||||
__instance.transitionOpen.targetSize = 1.3f;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.Open))]
|
||||
public static bool Open(MatchInfoGuide __instance)
|
||||
{
|
||||
if (HudManager.Instance.GameMenu.IsOpen || HudManager.Instance.Chat.IsOpenOrOpening)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Minigame.Instance != null)
|
||||
{
|
||||
Minigame.Instance.Close();
|
||||
}
|
||||
if (MapBehaviour.Instance)
|
||||
{
|
||||
MapBehaviour.Instance.Close();
|
||||
}
|
||||
if (HudManager.InstanceExists)
|
||||
{
|
||||
ConsoleJoystick.SetMode_MenuAdditive();
|
||||
}
|
||||
ControllerManager.Instance.OpenOverlayMenu("MatchInfoGuide", __instance.closeButton);
|
||||
bool enabled = ActiveInputManager.currentControlType == ActiveInputManager.InputType.Joystick;
|
||||
__instance.glyphL.enabled = enabled;
|
||||
__instance.glyphR.enabled = enabled;
|
||||
if (GameManager.Instance.TryCast<NormalGameManager>() != null)
|
||||
{
|
||||
if (__instance.NormalModeSettings.Count == 0)
|
||||
{
|
||||
__instance.numOfTabs = 3;
|
||||
__instance.TabButtons[0].SelectButton(true);
|
||||
__instance.CreateNormalModeSettings();
|
||||
}
|
||||
}
|
||||
else if (__instance.HnSModeSettings.Count == 0)
|
||||
{
|
||||
__instance.numOfTabs = 2;
|
||||
__instance.TabButtons[0].SelectButton(true);
|
||||
__instance.CreateHnSModeSettings();
|
||||
}
|
||||
PlayerControl.LocalPlayer.NetTransform.Halt();
|
||||
__instance.MatchInfoParent.SetActive(true);
|
||||
ControllerManager instance = ControllerManager.Instance;
|
||||
ControllerUiElementsState currentUiState = ControllerManager.Instance.CurrentUiState;
|
||||
Il2CppSystem.Collections.Generic.List<UiElement> controllerSelectable = __instance.ControllerSelectable;
|
||||
instance.SetUpSelectables(currentUiState, controllerSelectable[controllerSelectable.Count - 1], __instance.ControllerSelectable);
|
||||
ControllerManager instance2 = ControllerManager.Instance;
|
||||
Il2CppSystem.Collections.Generic.List<UiElement> controllerSelectable2 = __instance.ControllerSelectable;
|
||||
instance2.SetCurrentSelected(controllerSelectable2[controllerSelectable2.Count - 1]);
|
||||
__instance.SetActiveTab(0);
|
||||
return false;
|
||||
}
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.CreatePlayerEntries))]
|
||||
private static bool CreatePlayerEntries(MatchInfoGuide __instance)
|
||||
{
|
||||
__instance.PlayerPool.ReclaimAll();
|
||||
int num = 51;
|
||||
foreach (NetworkedPlayerInfo networkedPlayerInfo in GameData.Instance.AllPlayers)
|
||||
{
|
||||
PlayerIdentifierButton component =
|
||||
__instance.PlayerPool.Get<PoolableBehavior>().GetComponent<PlayerIdentifierButton>();
|
||||
component.transform.localPosition = new Vector3(0f, 0f, -1f);
|
||||
component.Populate(networkedPlayerInfo);
|
||||
__instance.ControllerSelectable.Add(component.Button);
|
||||
component.SetTextStencil(num++);
|
||||
component.PlatformIdentifier.transform.localPosition = new Vector3(0.314f, 0.088f, -2.78f);
|
||||
component.NameText.transform.localPosition = new Vector3(0.3563f, 0, -2.98f);
|
||||
component.NameText.text += $"\n<size=75%>{networkedPlayerInfo.GetPlayerColorString()}</size>";
|
||||
var namePlate = HatManager.Instance.GetNamePlateById(networkedPlayerInfo.DefaultOutfit.NamePlateId);
|
||||
var x = (NamePlateViewData viewdata) =>
|
||||
{
|
||||
component.buttonSprite.sprite = viewdata?.Image;
|
||||
component.buttonSprite.transform.localScale = new Vector3(0.7f, 1.075f, 1);
|
||||
component.buttonSprite.transform.localPosition = new Vector3(-0.395f, 0, 0.1f);
|
||||
};
|
||||
__instance.StartCoroutine(
|
||||
AddressableAssetExtensions.CoLoadAssetAsync<NamePlateViewData>(
|
||||
__instance,
|
||||
namePlate.GetAssetReference(),
|
||||
x));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(MatchInfoRolePanel), nameof(MatchInfoRolePanel.SetPanel))]
|
||||
public static bool SetPanel(MatchInfoRolePanel __instance, RoleBehaviour role, int numPerGame, int chancePerGame)
|
||||
{
|
||||
__instance.roleCount.text = string.Format(CultureInfo.InvariantCulture, "{0} at {1}%", numPerGame.ToString(CultureInfo.InvariantCulture), chancePerGame);
|
||||
if (role is ICustomRole customRole)
|
||||
{
|
||||
__instance.roleName.text = customRole.RoleName;
|
||||
__instance.roleDescription.text = $"<size=60%>{customRole.RoleFactionTitle}</size>\n" + customRole.RoleMedDescription;
|
||||
__instance.roleIcon.sprite = customRole.Configuration.Icon?.LoadAsset();
|
||||
__instance.roleCount.text += $" ({customRole.ParentMod.MiraPlugin.GetAbbreviatedModName()})";
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.roleName.text = role.NiceName;
|
||||
__instance.roleDescription.text = $"<size=60%>{TranslationController.Instance.GetString(role.TeamType is RoleTeamTypes.Crewmate ? StringNames.Crewmate : StringNames.Impostor)}</size>\n" + role.BlurbMed;
|
||||
__instance.roleIcon.sprite = role.RoleIconColor;
|
||||
__instance.roleCount.text += " (AU)";
|
||||
}
|
||||
|
||||
__instance.roleIcon.SetSizeLimit(0.13f);
|
||||
__instance.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50);
|
||||
__instance.roleName.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f);
|
||||
__instance.roleDescription.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f);
|
||||
__instance.roleCount.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f);
|
||||
__instance.roleIcon.transform.localScale = new Vector3(4f, 4f, 1f);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,17 @@ namespace MiraAPI.Patches.Roles;
|
||||
/// <summary>
|
||||
/// Patches to return the correct role counts.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(RoleOptionsCollectionV10))]
|
||||
[HarmonyPatch(typeof(RoleOptionsCollectionV11))]
|
||||
public static class RoleOptionsCollectionPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// This patch fixes <see cref="RoleOptionsCollectionV10.GetNumPerGame(RoleTypes)"/> being inlined (2025.9.9) in the original code.
|
||||
/// This patch fixes <see cref="RoleOptionsCollectionV11.GetNumPerGame(RoleTypes)"/> being inlined (2025.9.9) in the original code.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV10.AnyRolesEnabled))]
|
||||
public static bool AnyRolesEnabledPrefix(RoleOptionsCollectionV10 __instance, ref bool __result)
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV11.AnyRolesEnabled))]
|
||||
public static bool AnyRolesEnabledPrefix(RoleOptionsCollectionV11 __instance, ref bool __result)
|
||||
{
|
||||
foreach (KeyValuePair<RoleTypes, RoleDataV10> keyValuePair in __instance.roles)
|
||||
foreach (KeyValuePair<RoleTypes, RoleDataV11> keyValuePair in __instance.roles)
|
||||
{
|
||||
if (__instance.GetNumPerGame(keyValuePair.Key) > 0)
|
||||
{
|
||||
@@ -33,7 +33,7 @@ public static class RoleOptionsCollectionPatch
|
||||
/// </summary>
|
||||
/// <returns>Return <see langword="false"/> to skip original method, <see langword="true"/> to not.</returns>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV10.GetChancePerGame))]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV11.GetChancePerGame))]
|
||||
public static bool GetChancePrefix(RoleTypes role, ref int __result)
|
||||
{
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(role, out var customRole) || customRole == null)
|
||||
@@ -63,7 +63,7 @@ public static class RoleOptionsCollectionPatch
|
||||
/// </summary>
|
||||
/// <returns>Return <see langword="false"/> to skip original method, <see langword="true"/> to not.</returns>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV10.GetNumPerGame))]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV11.GetNumPerGame))]
|
||||
public static bool GetNumPrefix(RoleTypes role, ref int __result)
|
||||
{
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(role, out var customRole) || customRole == null)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.1 KiB |
@@ -23,11 +23,27 @@ public interface ICustomRole : IOptionable
|
||||
/// </summary>
|
||||
string RoleDescription { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the medium description of the role. Used in the role guide.
|
||||
/// </summary>
|
||||
string RoleMedDescription => RoleDescription;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the long description of the role. Used in the Role Tab and Role Options.
|
||||
/// </summary>
|
||||
string RoleLongDescription { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the faction / alignment of the role. Used in the role guide.
|
||||
/// </summary>
|
||||
string RoleFactionTitle => Team switch
|
||||
{
|
||||
ModdedRoleTeams.Crewmate => TranslationController.Instance.GetString(StringNames.Crewmate),
|
||||
ModdedRoleTeams.Impostor => TranslationController.Instance.GetString(StringNames.Impostor),
|
||||
ModdedRoleTeams.Custom => "Neutral",
|
||||
_ => "Other",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Color"/> of the role.
|
||||
/// </summary>
|
||||
|
||||
@@ -145,5 +145,20 @@ public static class MiraAssets
|
||||
/// </summary>
|
||||
public static LoadableResourceAsset TimedModifierFile { get; } = new("MiraAPI.Resources.TimedModifierFile.png");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite used for the new chat button while hovering.
|
||||
/// </summary>
|
||||
public static LoadableResourceAsset ChatHoverSprite { get; } = new("MiraAPI.Resources.NormalChatHover.png");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite used for the new chat button while hovering.
|
||||
/// </summary>
|
||||
public static LoadableResourceAsset ChatIdleSprite { get; } = new("MiraAPI.Resources.NormalChatIdle.png");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite used for the new chat button while hovering.
|
||||
/// </summary>
|
||||
public static LoadableResourceAsset ChatOpenSprite { get; } = new("MiraAPI.Resources.NormalChatOpen.png");
|
||||
|
||||
internal static LoadableResourceAsset BlankSprite { get; } = new("MiraAPI.Resources.BlankSprite.png");
|
||||
}
|
||||
@@ -367,6 +367,71 @@ public static class Extensions
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all child objects in a parent object.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="IEnumerable"/> that contains <see cref="GameObject"/>s.</returns>
|
||||
public static IEnumerable<GameObject> GetAllChildren(this GameObject go)
|
||||
{
|
||||
for (var i = 0; i < go.transform.childCount; i++)
|
||||
{
|
||||
yield return go.transform.GetChild(i).gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all child objects in a parent Transform.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="IEnumerable"/> that contains <see cref="GameObject"/>s.</returns>
|
||||
public static IEnumerable<GameObject> GetAllChildren(this Transform go)
|
||||
{
|
||||
for (var i = 0; i < go.transform.childCount; i++)
|
||||
{
|
||||
yield return go.transform.GetChild(i).gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes a <see cref="SpriteRenderer"/> appropriate to the maximum pixel size without messing up ratios.
|
||||
/// </summary>
|
||||
/// <param name="sprite">The <see cref="SpriteRenderer"/> to adjust.</param>
|
||||
/// <param name="pixelSize">The scale for the sprite to be adjusted to.</param>
|
||||
public static void SetSizeLimit(this SpriteRenderer sprite, float pixelSize)
|
||||
{
|
||||
sprite.drawMode = SpriteDrawMode.Sliced;
|
||||
if (!sprite.sprite)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float spriteWidth = sprite.sprite.rect.width;
|
||||
float spriteHeight = sprite.sprite.rect.height;
|
||||
|
||||
if (spriteWidth < spriteHeight)
|
||||
{
|
||||
sprite.size = new Vector2(pixelSize * spriteWidth / spriteHeight, pixelSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.size = new Vector2(pixelSize, pixelSize * spriteHeight / spriteWidth);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes a <see cref="SpriteRenderer"/> appropriate to the maximum pixel size without messing up ratios.
|
||||
/// </summary>
|
||||
/// <param name="spriteObj">The <see cref="GameObject"/> to adjust.</param>
|
||||
/// <param name="pixelSize">The scale for the sprite to be adjusted to.</param>
|
||||
public static void SetSizeLimit(this GameObject spriteObj, float pixelSize)
|
||||
{
|
||||
if (!spriteObj.TryGetComponent<SpriteRenderer>(out var sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sprite.SetSizeLimit(pixelSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a cache of <see cref="PlayerControl"/>'s <see cref="PlayerVoteData"/> to improve performance.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user