mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 11:39:45 +00:00
Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8b8e7d7be | ||
|
|
90bf402cbc | ||
|
|
50d7111c49 | ||
|
|
fed3abafb2 | ||
|
|
925d47a275 | ||
|
|
45a3597ab2 | ||
|
|
faeb39d3de | ||
|
|
6b46cffe5e | ||
|
|
00a60bb7ad | ||
|
|
d89bce6956 | ||
|
|
7f92e94293 | ||
|
|
6199e55110 | ||
|
|
eac442443b | ||
|
|
6321753ec0 | ||
|
|
e66d45bd21 | ||
|
|
1e00181220 | ||
|
|
fcd7856571 | ||
|
|
5680d27db1 | ||
|
|
49d77fcf40 | ||
|
|
dcb4a3876f | ||
|
|
9270de408d | ||
|
|
8940de76bb | ||
|
|
1813fe5a84 | ||
|
|
272b14f0e0 | ||
|
|
6cc1d4b762 |
No files matched your search
+2
-2
@@ -1,8 +1,8 @@
|
||||
<Project>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Reactor" Version="2.3.1" />
|
||||
<PackageReference Include="Reactor" Version="2.5.0-ci.371" />
|
||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.735" Private="false" ExcludeAssets="runtime;native" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2025.10.14" PrivateAssets="all" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2026.3.31" PrivateAssets="all" />
|
||||
|
||||
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
|
||||
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.1.0-rc.1" PrivateAssets="all" ExcludeAssets="runtime" />
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
|
||||
<VersionPrefix>0.3.8</VersionPrefix>
|
||||
<VersionPrefix>0.4.0</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||
|
||||
@@ -7,10 +7,12 @@ using Assets.CoreScripts;
|
||||
using BepInEx.Unity.IL2CPP.Utils;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using Rewired;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -22,7 +24,7 @@ namespace MiraAPI.Networking;
|
||||
public static class CustomMurderRpc
|
||||
{
|
||||
/// <summary>
|
||||
/// Networked Custom Murder method.
|
||||
/// Networked Custom Murder method, ran by clients for the host to confirm kills.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
@@ -54,7 +56,7 @@ public static class CustomMurderRpc
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Networked Custom Murder method, which checks for meetings as well.
|
||||
/// Networked Custom Murder method, which checks for meetings as well, ran by clients for the host to confirm kills.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
@@ -91,11 +93,68 @@ public static class CustomMurderRpc
|
||||
beforeMurderEvent.Cancel();
|
||||
}
|
||||
|
||||
if (beforeMurderEvent.IsCancelled)
|
||||
if (target.ProtectedByGa())
|
||||
{
|
||||
beforeMurderEvent.Cancel();
|
||||
murderResultFlags = MurderResultFlags.FailedProtected;
|
||||
}
|
||||
else if (beforeMurderEvent.IsCancelled)
|
||||
{
|
||||
murderResultFlags = MurderResultFlags.FailedError;
|
||||
}
|
||||
|
||||
if (beforeMurderEvent.IsCancelled && source.AmOwner)
|
||||
{
|
||||
source.isKilling = true;
|
||||
}
|
||||
|
||||
if (!PlayerControl.LocalPlayer.IsHost())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RpcConfirmCustomMurder(
|
||||
PlayerControl.LocalPlayer,
|
||||
source,
|
||||
target,
|
||||
murderResultFlags,
|
||||
resetKillTimer,
|
||||
createDeadBody,
|
||||
teleportMurderer,
|
||||
showKillAnim,
|
||||
playKillSound);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Networked Custom Murder method, which checks for meetings as well, ran by clients for the host to confirm kills.
|
||||
/// </summary>
|
||||
/// <param name="host">The game host.</param>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
/// <param name="murderResultFlags">End result for the murder.</param>
|
||||
/// <param name="resetKillTimer">Should the kill timer be reset.</param>
|
||||
/// <param name="createDeadBody">Should a dead body be created.</param>
|
||||
/// <param name="teleportMurderer">Should the killer be snapped to the dead player.</param>
|
||||
/// <param name="showKillAnim">Should the kill animation be shown.</param>
|
||||
/// <param name="playKillSound">Should the kill sound be played.</param>
|
||||
[MethodRpc((uint)MiraRpc.ConfirmCustomMurder, LocalHandling = RpcLocalHandling.After)]
|
||||
public static void RpcConfirmCustomMurder(
|
||||
this PlayerControl host,
|
||||
PlayerControl source,
|
||||
PlayerControl target,
|
||||
MurderResultFlags murderResultFlags,
|
||||
bool resetKillTimer = true,
|
||||
bool createDeadBody = true,
|
||||
bool teleportMurderer = true,
|
||||
bool showKillAnim = true,
|
||||
bool playKillSound = true)
|
||||
{
|
||||
if (LobbyBehaviour.Instance || !host.IsHost() || target.Data.IsDead || target.Data.Disconnected)
|
||||
{
|
||||
source.isKilling = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var murderResultFlags2 = MurderResultFlags.DecisionByHost | murderResultFlags;
|
||||
|
||||
source.CustomMurder(
|
||||
@@ -234,7 +293,7 @@ public static class CustomMurderRpc
|
||||
source.CurrentOutfitType == PlayerOutfitType.Shapeshifted,
|
||||
source.shapeshiftTargetPlayerId,
|
||||
target.PlayerId);
|
||||
source.MyPhysics.StartCoroutine(source.KillAnimations.Random()?.CoPerformCustomKill(source, target, createDeadBody, teleportMurderer));
|
||||
source.MyPhysics.StartCoroutine(source.KillAnimations.RandomSnapshot().CoPerformCustomKill(source, target, createDeadBody, teleportMurderer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -35,6 +35,11 @@ public enum MiraRpc : uint
|
||||
/// </summary>
|
||||
CustomMurder,
|
||||
|
||||
/// <summary>
|
||||
/// Custom Murder RPC Confirmation.
|
||||
/// </summary>
|
||||
ConfirmCustomMurder,
|
||||
|
||||
/// <summary>
|
||||
/// Custom Game Over RPC.
|
||||
/// </summary>
|
||||
|
||||
@@ -52,12 +52,7 @@ public static class HudManagerPatches
|
||||
continue;
|
||||
}
|
||||
|
||||
if (aspect.gameObject.transform.parent.name == "TopRight")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (aspect.gameObject.transform.parent.transform.parent.name == "TopRight")
|
||||
if (aspect.gameObject.name.Contains("TopRight"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -89,6 +84,11 @@ public static class HudManagerPatches
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arrange.gameObject.name.Contains("TopRight"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
arrange.gameObject.SetActive(!arrange.isActiveAndEnabled);
|
||||
arrange.CellSize = new Vector2(scaleFactor, scaleFactor);
|
||||
arrange.gameObject.SetActive(!arrange.isActiveAndEnabled);
|
||||
|
||||
@@ -16,8 +16,15 @@ public static class OptionsMenuBehaviourPatch
|
||||
private static void OpenPostfix(OptionsMenuBehaviour __instance)
|
||||
{
|
||||
_remap_rollover = GameObject.Find("Remap Controls")?.GetComponent<ButtonRolloverHandler>()!;
|
||||
_remap_background = _remap_rollover.transform.FindChild("Background").GetComponent<SpriteRenderer>();
|
||||
_remap_background.color = _conflicts ? Color.red : Color.white;
|
||||
try
|
||||
{
|
||||
_remap_background = _remap_rollover.transform.FindChild("Background").GetComponent<SpriteRenderer>();
|
||||
_remap_background.color = _conflicts ? Color.red : Color.white;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored, this normally breaks when on mobile since there's no remap button screen.
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using AmongUs.Data;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Patches.Menu;
|
||||
|
||||
[HarmonyPatch(typeof(HatsTab))]
|
||||
public static class HatsTabPatches
|
||||
{
|
||||
private static SortedList<string, List<HatData>> sortedHats = [];
|
||||
private static int currentPage;
|
||||
|
||||
private static void PreviousPage(HatsTab hatsTab)
|
||||
{
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? sortedHats.Count - 1 : currentPage;
|
||||
GenerateHats(hatsTab, currentPage);
|
||||
}
|
||||
|
||||
private static void NextPage(HatsTab hatsTab)
|
||||
{
|
||||
currentPage++;
|
||||
currentPage = currentPage > sortedHats.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(hatsTab, currentPage);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(HatsTab.OnEnable))]
|
||||
[HarmonyPrefix]
|
||||
public static bool OnEnablePrefix(HatsTab __instance)
|
||||
{
|
||||
__instance.currentHat = HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat);
|
||||
var allHats = HatManager.Instance.GetUnlockedHats().ToImmutableList();
|
||||
|
||||
if (sortedHats.Count == 0)
|
||||
{
|
||||
var comparer = new ControllableComparer<string>(["vanilla"], [], StringComparer.InvariantCulture);
|
||||
sortedHats = new SortedList<string, List<HatData>>(comparer);
|
||||
foreach (var hat in allHats)
|
||||
{
|
||||
if (!sortedHats.ContainsKey(hat.StoreName)) sortedHats[hat.StoreName] = [];
|
||||
sortedHats[hat.StoreName].Add(hat);
|
||||
}
|
||||
}
|
||||
|
||||
InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage);
|
||||
|
||||
GenerateHats(__instance, currentPage);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(HatsTab), nameof(HatsTab.Update))]
|
||||
[HarmonyPrefix]
|
||||
public static void UpdatePrefix(HatsTab __instance)
|
||||
{
|
||||
if (sortedHats.Count == 0) return;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
PreviousPage(__instance);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
NextPage(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerator? loadRoutine;
|
||||
private static int hatIndex;
|
||||
|
||||
private static void GenerateHats(HatsTab __instance, int page)
|
||||
{
|
||||
if (loadRoutine != null) Coroutines.Stop(loadRoutine);
|
||||
|
||||
hatIndex = 0;
|
||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
||||
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
|
||||
var (groupName, hats) = sortedHats.ToArray()[page];
|
||||
var text = Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||
text.enabled = true;
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedHats.Count})";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 5f;
|
||||
text.fontSizeMax = 5f;
|
||||
text.fontSizeMin = 0f;
|
||||
var xLerp = __instance.XRange.Lerp(0.5f);
|
||||
var yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||
|
||||
hatIndex += 5;
|
||||
loadRoutine = Coroutines.Start(CoGenerateChips(__instance, hats));
|
||||
}
|
||||
|
||||
private static IEnumerator CoGenerateChips(HatsTab __instance, List<HatData> hats)
|
||||
{
|
||||
__instance.scroller.ScrollToTop();
|
||||
var batchSize = 5;
|
||||
for (var i = 0; i < hats.Count; i += batchSize)
|
||||
{
|
||||
var batch = hats.Skip(i).Take(batchSize).ToList();
|
||||
|
||||
foreach (var hat in batch.OrderBy(HatManager.Instance.allHats.IndexOf))
|
||||
{
|
||||
var hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||
var hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), hat);
|
||||
hatIndex += 1;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
__instance.SetScrollerBounds();
|
||||
yield return new WaitForSeconds(0.01f);
|
||||
}
|
||||
__instance.currentHatIsEquipped = true;
|
||||
loadRoutine = null;
|
||||
}
|
||||
|
||||
private static void GenerateColorChip(HatsTab __instance, Vector2 position, HatData hat)
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = hat.ProductId;
|
||||
if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard)
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip);
|
||||
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectHat(hat)));
|
||||
colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectHat(HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat))));
|
||||
}
|
||||
else
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectHat(hat)));
|
||||
}
|
||||
|
||||
colorChip.Inner.SetHat(hat, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color);
|
||||
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||
__instance.UpdateMaterials(colorChip.Inner.FrontLayer, hat);
|
||||
colorChip.Inner.SetMaskType(PlayerMaterial.MaskType.SimpleUI);
|
||||
colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f);
|
||||
colorChip.Inner.transform.localPosition = hat.ChipOffset + new Vector2(0f, -0.3f);
|
||||
colorChip.Tag = hat;
|
||||
__instance.ColorChips.Add(colorChip);
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Patches.Menu;
|
||||
|
||||
public static class InventoryUtility
|
||||
{
|
||||
public static void CreateNextBackButtons<T>(T tab, Action<T> previousPage, Action<T> nextPage) where T : InventoryTab
|
||||
{
|
||||
var title = tab.transform.FindChild("Text");
|
||||
title.localPosition = new Vector3(.9123f, -.23f, -55);
|
||||
title.GetComponent<TextMeshPro>().alignment = TextAlignmentOptions.Center;
|
||||
|
||||
tab.scroller.Hitbox.transform.localScale -= new Vector3(0, 0.1f, 0);
|
||||
tab.scroller.Hitbox.transform.localPosition -= new Vector3(0, 0.1f, 0);
|
||||
|
||||
var leftButtonElement = Object.Instantiate(PlayerCustomizationMenu.Instance.BackButton.gameObject, tab.transform);
|
||||
var leftSpriteRenderer = leftButtonElement.GetComponent<SpriteRenderer>();
|
||||
var leftButton = leftButtonElement.GetComponent<PassiveButton>();
|
||||
|
||||
leftButtonElement.transform.localPosition = new Vector3(-1.1f, -0.2f, -55);
|
||||
leftSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset();
|
||||
leftSpriteRenderer.flipX = true;
|
||||
|
||||
leftButton.OnMouseOver = new UnityEvent();
|
||||
leftButton.OnMouseOver.AddListener((Action)(() => leftSpriteRenderer.sprite = MiraAssets.NextButtonActive.LoadAsset()));
|
||||
leftButton.OnMouseOut = new UnityEvent();
|
||||
leftButton.OnMouseOut.AddListener((Action)(() => leftSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset()));
|
||||
|
||||
leftButton.OnClick = new Button.ButtonClickedEvent();
|
||||
leftButton.OnClick.AddListener((Action)(() => previousPage(tab)));
|
||||
|
||||
var rightButtonElement = Object.Instantiate(leftButtonElement, tab.transform);
|
||||
var rightSpriteRenderer = rightButtonElement.GetComponent<SpriteRenderer>();
|
||||
var rightButton = rightButtonElement.GetComponent<PassiveButton>();
|
||||
|
||||
rightButtonElement.transform.localPosition = new Vector3(2.8f, -0.2f, -55);
|
||||
rightSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset();
|
||||
rightSpriteRenderer.flipX = false;
|
||||
|
||||
rightButton.OnMouseOver = new UnityEvent();
|
||||
rightButton.OnMouseOver.AddListener((Action)(() => rightSpriteRenderer.sprite = MiraAssets.NextButtonActive.LoadAsset()));
|
||||
rightButton.OnMouseOut = new UnityEvent();
|
||||
rightButton.OnMouseOut.AddListener((Action)(() => rightSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset()));
|
||||
|
||||
rightButton.OnClick = new Button.ButtonClickedEvent();
|
||||
rightButton.OnClick.AddListener((Action)(() => nextPage(tab)));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using HarmonyLib;
|
||||
using System.Collections;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Menu;
|
||||
@@ -18,7 +20,14 @@ public static class MainMenuManagerPatches
|
||||
[HarmonyPostfix]
|
||||
public static void AwakePostfix()
|
||||
{
|
||||
AddressablesLoader.LoadAll();
|
||||
Coroutines.Start(SetFps());
|
||||
}
|
||||
|
||||
private static IEnumerator SetFps()
|
||||
{
|
||||
Application.targetFrameRate = (int)LocalSettingsTabSingleton<MiraApiSettings>.Instance.SetFpsSlider.Value;
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
Application.targetFrameRate = (int)LocalSettingsTabSingleton<MiraApiSettings>.Instance.SetFpsSlider.Value;
|
||||
}
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
using AmongUs.Data;
|
||||
using HarmonyLib;
|
||||
using Innersloth.Assets;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Patches.Menu;
|
||||
|
||||
[HarmonyPatch(typeof(NameplatesTab))]
|
||||
public static class NameplatesTabPatches
|
||||
{
|
||||
private static readonly SortedList<string, List<NamePlateData>> SortedNameplates = new(new ControllableComparer<string>(["vanilla"], [], StringComparer.InvariantCulture));
|
||||
private static int currentPage;
|
||||
internal static void AddRange(IEnumerable<(string Key, NamePlateData Visor)> data)
|
||||
{
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (!SortedNameplates.ContainsKey(item.Key)) SortedNameplates.Add(item.Key, []);
|
||||
SortedNameplates[item.Key].Add(item.Visor);
|
||||
}
|
||||
}
|
||||
|
||||
private static void PreviousPage(NameplatesTab tab)
|
||||
{
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? SortedNameplates.Count - 1 : currentPage;
|
||||
GenerateHats(tab, currentPage);
|
||||
}
|
||||
|
||||
private static void NextPage(NameplatesTab tab)
|
||||
{
|
||||
currentPage++;
|
||||
currentPage = currentPage > SortedNameplates.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(tab, currentPage);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(NameplatesTab.OnEnable))]
|
||||
[HarmonyPrefix]
|
||||
public static bool OnEnablePrefix(NameplatesTab __instance)
|
||||
{
|
||||
__instance.plateId = HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.namePlate).ProdId;
|
||||
|
||||
if (!SortedNameplates.ContainsKey("Vanilla")) AddRange(DestroyableSingleton<HatManager>.Instance.GetUnlockedNamePlates().Select(x => ("Vanilla", x)));
|
||||
|
||||
InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage);
|
||||
|
||||
GenerateHats(__instance, currentPage);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(NameplatesTab), nameof(NameplatesTab.Update))]
|
||||
[HarmonyPrefix]
|
||||
|
||||
public static void UpdatePrefix(NameplatesTab __instance)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
PreviousPage(__instance);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
NextPage(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateHats(NameplatesTab __instance, int page)
|
||||
{
|
||||
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
||||
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
|
||||
int hatIndex = 0;
|
||||
|
||||
var (groupName, nameplates) = SortedNameplates.ToArray()[page];
|
||||
var text = Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||
text.enabled = true;
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedNameplates.Count})";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 5f;
|
||||
text.fontSizeMax = 5f;
|
||||
text.fontSizeMin = 0f;
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||
|
||||
hatIndex += 2;
|
||||
foreach (var visor in nameplates.OrderBy(HatManager.Instance.allNamePlates.IndexOf))
|
||||
{
|
||||
float hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||
float hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), visor);
|
||||
hatIndex += 1;
|
||||
}
|
||||
|
||||
__instance.SetScrollerBounds();
|
||||
__instance.currentNameplateIsEquipped = true;
|
||||
}
|
||||
|
||||
private static void GenerateColorChip(NameplatesTab __instance, Vector2 position, NamePlateData namePlate)
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = namePlate.ProductId;
|
||||
|
||||
if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard)
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip);
|
||||
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectNameplate(namePlate)));
|
||||
colorChip.Button.OnMouseOut.AddListener(
|
||||
(Action)(() => __instance.SelectNameplate(
|
||||
HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.NamePlate))));
|
||||
}
|
||||
else
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectNameplate(namePlate)));
|
||||
}
|
||||
|
||||
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||
colorChip.ProductId = namePlate.ProdId;
|
||||
|
||||
var x = (NamePlateViewData viewdata) =>
|
||||
{
|
||||
colorChip.transform.GetChild(1).GetComponent<SpriteRenderer>().sprite = viewdata?.Image;
|
||||
// (colorChip as NameplateChip).image.sprite = viewdata?.Image;
|
||||
};
|
||||
__instance.StartCoroutine(AddressableAssetExtensions.CoLoadAssetAsync<NamePlateViewData>(__instance, namePlate.GetAssetReference(), x));
|
||||
colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f);
|
||||
colorChip.Tag = namePlate;
|
||||
__instance.ColorChips.Add(colorChip);
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
using AmongUs.Data;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Patches.Menu;
|
||||
|
||||
[HarmonyPatch(typeof(SkinsTab))]
|
||||
public static class SkinsTabPatches
|
||||
{
|
||||
private static SortedList<string, List<SkinData>> sortedSkins = [];
|
||||
private static int currentPage;
|
||||
|
||||
private static void PreviousPage(SkinsTab tab)
|
||||
{
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? sortedSkins.Count - 1 : currentPage;
|
||||
GenerateHats(tab, currentPage);
|
||||
}
|
||||
|
||||
private static void NextPage(SkinsTab tab)
|
||||
{
|
||||
currentPage++;
|
||||
currentPage = currentPage > sortedSkins.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(tab, currentPage);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(SkinsTab.OnEnable))]
|
||||
[HarmonyPrefix]
|
||||
public static bool OnEnablePrefix(SkinsTab __instance)
|
||||
{
|
||||
__instance.skinId = HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin).ProdId;
|
||||
var allSkins = HatManager.Instance.GetUnlockedSkins().ToImmutableList();
|
||||
|
||||
if (sortedSkins.Count == 0)
|
||||
{
|
||||
var comparer = new ControllableComparer<string>(["vanilla"], [], StringComparer.InvariantCulture);
|
||||
sortedSkins = new SortedList<string, List<SkinData>>(comparer);
|
||||
foreach (var skin in allSkins)
|
||||
{
|
||||
if (!sortedSkins.ContainsKey(skin.StoreName)) sortedSkins[skin.StoreName] = [];
|
||||
sortedSkins[skin.StoreName].Add(skin);
|
||||
}
|
||||
}
|
||||
|
||||
InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage);
|
||||
|
||||
GenerateHats(__instance, currentPage);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(SkinsTab), nameof(SkinsTab.Update))]
|
||||
[HarmonyPrefix]
|
||||
|
||||
public static void UpdatePrefix(SkinsTab __instance)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
PreviousPage(__instance);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
NextPage(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateHats(SkinsTab __instance, int page)
|
||||
{
|
||||
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
||||
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
|
||||
int hatIndex = 0;
|
||||
|
||||
var (groupName, skins) = sortedSkins.ToArray()[page];
|
||||
var text = Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||
text.enabled = true;
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedSkins.Count})";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 5f;
|
||||
text.fontSizeMax = 5f;
|
||||
text.fontSizeMin = 0f;
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||
|
||||
hatIndex += 5;
|
||||
foreach (var skin in skins.OrderBy(HatManager.Instance.allSkins.IndexOf))
|
||||
{
|
||||
float hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||
float hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), skin);
|
||||
hatIndex += 1;
|
||||
}
|
||||
|
||||
__instance.SetScrollerBounds();
|
||||
__instance.currentSkinIsEquipped = true;
|
||||
}
|
||||
|
||||
private static void GenerateColorChip(SkinsTab __instance, Vector2 position, SkinData skin)
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = skin.ProductId;
|
||||
if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard)
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip);
|
||||
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectSkin(skin)));
|
||||
colorChip.Button.OnMouseOut.AddListener(
|
||||
(Action)(() =>
|
||||
__instance.SelectSkin(HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin))));
|
||||
}
|
||||
else
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectSkin(skin)));
|
||||
}
|
||||
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||
colorChip.ProductId = skin.ProductId;
|
||||
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||
__instance.UpdateMaterials(colorChip.Inner.FrontLayer, skin);
|
||||
skin.SetPreview(colorChip.Inner.FrontLayer, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color);
|
||||
colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f);
|
||||
colorChip.Inner.transform.localPosition = skin.ChipOffset + new Vector2(0f, -0.3f);
|
||||
colorChip.Tag = skin;
|
||||
__instance.ColorChips.Add(colorChip);
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
using AmongUs.Data;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Patches.Menu;
|
||||
|
||||
[HarmonyPatch(typeof(VisorsTab))]
|
||||
public static class VisorsTabPatches
|
||||
{
|
||||
private static readonly SortedList<string, List<VisorData>> SortedVisors = new(new ControllableComparer<string>(["vanilla"], [], StringComparer.InvariantCulture));
|
||||
private static int currentPage;
|
||||
internal static void AddRange(IEnumerable<(string Key, VisorData Visor)> data)
|
||||
{
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (!SortedVisors.ContainsKey(item.Key)) SortedVisors.Add(item.Key, []);
|
||||
SortedVisors[item.Key].Add(item.Visor);
|
||||
}
|
||||
}
|
||||
|
||||
private static void PreviousPage(VisorsTab tab)
|
||||
{
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? SortedVisors.Count - 1 : currentPage;
|
||||
GenerateHats(tab, currentPage);
|
||||
}
|
||||
|
||||
private static void NextPage(VisorsTab tab)
|
||||
{
|
||||
currentPage++;
|
||||
currentPage = currentPage > SortedVisors.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(tab, currentPage);
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPatch(nameof(VisorsTab.OnEnable))]
|
||||
[HarmonyPrefix]
|
||||
public static bool OnEnablePrefix(VisorsTab __instance)
|
||||
{
|
||||
__instance.visorId = HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor).ProdId;
|
||||
|
||||
if (!SortedVisors.ContainsKey("Vanilla")) AddRange(DestroyableSingleton<HatManager>.Instance.GetUnlockedVisors().Select(x => ("Vanilla", x)));
|
||||
|
||||
InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage);
|
||||
|
||||
GenerateHats(__instance, currentPage);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(VisorsTab), nameof(VisorsTab.Update))]
|
||||
[HarmonyPrefix]
|
||||
|
||||
public static void UpdatePrefix(VisorsTab __instance)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
PreviousPage(__instance);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
NextPage(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateHats(VisorsTab __instance, int page)
|
||||
{
|
||||
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
||||
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
|
||||
int hatIndex = 0;
|
||||
|
||||
var (groupName, visors) = SortedVisors.ToArray()[page];
|
||||
var text = Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||
text.enabled = true;
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedVisors.Count})";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 5f;
|
||||
text.fontSizeMax = 5f;
|
||||
text.fontSizeMin = 0f;
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||
|
||||
hatIndex += 5;
|
||||
foreach (var visor in visors.OrderBy(HatManager.Instance.allVisors.IndexOf))
|
||||
{
|
||||
float hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||
float hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), visor);
|
||||
hatIndex += 1;
|
||||
}
|
||||
|
||||
__instance.SetScrollerBounds();
|
||||
__instance.currentVisorIsEquipped = true;
|
||||
}
|
||||
|
||||
private static void GenerateColorChip(VisorsTab __instance, Vector2 position, VisorData visor)
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = visor.ProductId;
|
||||
|
||||
if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard)
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip);
|
||||
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectVisor(visor)));
|
||||
colorChip.Button.OnMouseOut.AddListener(
|
||||
(Action)(() =>
|
||||
__instance.SelectVisor(HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor))));
|
||||
}
|
||||
else
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectVisor(visor)));
|
||||
}
|
||||
|
||||
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||
colorChip.ProductId = visor.ProductId;
|
||||
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||
__instance.UpdateMaterials(colorChip.Inner.FrontLayer, visor);
|
||||
visor.SetPreview(colorChip.Inner.FrontLayer, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color);
|
||||
colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f);
|
||||
colorChip.Inner.transform.localPosition = visor.ChipOffset + new Vector2(0f, -0.3f);
|
||||
colorChip.Tag = visor;
|
||||
__instance.ColorChips.Add(colorChip);
|
||||
}
|
||||
}
|
||||
@@ -210,12 +210,19 @@ public static class LobbyViewPanePatches
|
||||
list.Add(roleBehaviour);
|
||||
}
|
||||
|
||||
var color = (i == 0) ? Palette.CrewmateRoleBlue : Palette.ImpostorRoleRed;
|
||||
if (roleBehaviour is ICustomRole custom && (custom.Team is not ModdedRoleTeams.Crewmate &&
|
||||
custom.Team is not ModdedRoleTeams.Impostor))
|
||||
{
|
||||
color = Color.grey;
|
||||
}
|
||||
|
||||
viewSettingsInfoPanelRoleVariant.SetInfo(
|
||||
roleBehaviour.NiceName,
|
||||
numPerGame,
|
||||
chancePerGame,
|
||||
61,
|
||||
(i == 0) ? Palette.CrewmateRoleBlue : Palette.ImpostorRoleRed,
|
||||
color,
|
||||
roleBehaviour.RoleIconSolid,
|
||||
i == 0,
|
||||
flag);
|
||||
@@ -513,6 +520,34 @@ public static class LobbyViewPanePatches
|
||||
instance.scrollBar.SetYBoundsMax(-num);
|
||||
}
|
||||
|
||||
public static void SetModdedHeader(this CategoryHeaderRoleVariant header, StringNames roleName, int maskLayer, ModdedRoleTeams team, Sprite? roleIcon = null)
|
||||
{
|
||||
header.SetHeader(roleName, maskLayer);
|
||||
if (team is ModdedRoleTeams.Crewmate)
|
||||
{
|
||||
header.Background.color = Palette.CrewmateRoleHeaderBlue;
|
||||
header.Divider.color = Palette.CrewmateRoleHeaderBlue;
|
||||
header.Title.color = Palette.CrewmateRoleHeaderTextBlue;
|
||||
}
|
||||
else if (team is ModdedRoleTeams.Impostor)
|
||||
{
|
||||
header.Background.color = Palette.ImpostorRoleHeaderRed;
|
||||
header.Divider.color = Palette.ImpostorRoleHeaderRed;
|
||||
header.Title.color = Palette.ImpostorRoleHeaderTextRed;
|
||||
}
|
||||
else
|
||||
{
|
||||
header.Background.color = Color.grey;
|
||||
header.Divider.color = Color.grey;
|
||||
header.Title.color = new Color32(50, 50, 50, 255);
|
||||
}
|
||||
if (roleIcon != null && header.icon != null)
|
||||
{
|
||||
header.icon.material.SetInt(PlayerMaterial.MaskLayer, maskLayer);
|
||||
header.icon.sprite = roleIcon;
|
||||
}
|
||||
}
|
||||
|
||||
private static float SetUpAdvancedRoleViewPanel(
|
||||
AdvancedRoleViewPanel viewPanel,
|
||||
Type roleType,
|
||||
@@ -536,10 +571,10 @@ public static class LobbyViewPanePatches
|
||||
return 0;
|
||||
}
|
||||
|
||||
viewPanel.header.SetHeader(
|
||||
viewPanel.header.SetModdedHeader(
|
||||
role.StringName,
|
||||
maskLayer,
|
||||
role.TeamType == RoleTeamTypes.Crewmate,
|
||||
customRole.Team,
|
||||
customRole.Configuration.Icon != null ? customRole.Configuration.Icon.LoadAsset() : MiraAssets.Empty.LoadAsset());
|
||||
viewPanel.header.icon.transform.localScale = new Vector3(0.465f, 0.465f, 1f);
|
||||
viewPanel.divider.material.SetInt(PlayerMaterial.MaskLayer, maskLayer);
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Colors;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.GameEnd;
|
||||
@@ -21,7 +22,6 @@ using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Networking;
|
||||
using Reactor.Utilities;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
|
||||
@@ -60,7 +60,7 @@ public sealed class MiraPluginManager
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var method in type.GetMethods())
|
||||
foreach (var method in AccessTools.GetDeclaredMethods(type))
|
||||
{
|
||||
var eventAttribute = method.GetCustomAttribute<RegisterEventAttribute>();
|
||||
if (eventAttribute == null)
|
||||
|
||||
@@ -10,20 +10,10 @@ using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
namespace MiraAPI.Utilities.Assets;
|
||||
|
||||
/// <summary>
|
||||
/// The component for loading Addressables, and cosmetics.
|
||||
/// The component for loading Addressables, and cosmetics. This is deprecated in favor of Corsac Cosmetics.
|
||||
/// </summary>
|
||||
public static class AddressablesLoader
|
||||
{
|
||||
private static bool _isInitialized;
|
||||
|
||||
private static readonly List<(string Location, string ProviderSuffix)> CatalogLocations = [];
|
||||
private static readonly List<string> LoadedLocations = [];
|
||||
|
||||
private static readonly List<string> RegisteredHatKeys = [];
|
||||
private static readonly List<(string, string)> RegisteredVisorKeys = [];
|
||||
private static readonly List<(string, string)> RegisteredNameplateKeys = [];
|
||||
private static readonly List<string> RegisteredSkinKeys = [];
|
||||
|
||||
/// <summary>
|
||||
/// Registers a specific addressables package to load asynchronously at the start of the game, when possible.
|
||||
/// </summary>
|
||||
@@ -31,13 +21,7 @@ public static class AddressablesLoader
|
||||
/// <param name="providerSuffix">The suffix of the provider for an addressables package.</param>
|
||||
public static void RegisterCatalog(string location, string providerSuffix = "")
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more catalogs.");
|
||||
return;
|
||||
}
|
||||
|
||||
CatalogLocations.Add((location, providerSuffix));
|
||||
Error("Catalogs are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,13 +30,7 @@ public static class AddressablesLoader
|
||||
/// <param name="addressablesKey">The key/label/group for a List <see cref="HatData"/>.</param>
|
||||
public static void RegisterHats(string addressablesKey)
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more keys for hats.");
|
||||
return;
|
||||
}
|
||||
|
||||
RegisteredHatKeys.Add(addressablesKey);
|
||||
Error("Hats are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,13 +39,7 @@ public static class AddressablesLoader
|
||||
/// <param name="addressablesKey">The key/label/group for a List <see cref="SkinData"/>.</param>
|
||||
public static void RegisterSkins(string addressablesKey)
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more keys for skins.");
|
||||
return;
|
||||
}
|
||||
|
||||
RegisteredSkinKeys.Add(addressablesKey);
|
||||
Error("Skins are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,13 +49,7 @@ public static class AddressablesLoader
|
||||
/// /// <param name="groupTitle">The title of the group for visors.</param>
|
||||
public static void RegisterNameplates(string addressablesKey, string groupTitle)
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more keys for nameplates.");
|
||||
return;
|
||||
}
|
||||
|
||||
RegisteredNameplateKeys.Add((addressablesKey, groupTitle));
|
||||
Error("Nameplates are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -93,130 +59,6 @@ public static class AddressablesLoader
|
||||
/// <param name="groupTitle">The title of the group for visors.</param>
|
||||
public static void RegisterVisors(string addressablesKey, string groupTitle)
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more keys for visors.");
|
||||
return;
|
||||
}
|
||||
|
||||
RegisteredVisorKeys.Add((addressablesKey, groupTitle));
|
||||
}
|
||||
|
||||
internal static void LoadAll()
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
_isInitialized = true;
|
||||
foreach (var (location, providerSuffix) in CatalogLocations)
|
||||
{
|
||||
Coroutines.Start(CoLoadAddressables(location, providerSuffix));
|
||||
}
|
||||
|
||||
Coroutines.Start(LoadCosmetics());
|
||||
}
|
||||
|
||||
internal static IEnumerator CoLoadAddressables(string location, string suffix = "")
|
||||
{
|
||||
while (!AmongUsClient.Instance) yield return null;
|
||||
// Load the local/remote content catalog
|
||||
var catalogOperation = Addressables.LoadContentCatalog(location, suffix);
|
||||
yield return catalogOperation;
|
||||
|
||||
// Check for errors
|
||||
if (catalogOperation.Status != AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Error($"Failed to load catalog {location}.");
|
||||
}
|
||||
|
||||
Info($"Loaded addressables {location}.");
|
||||
LoadedLocations.Add(location);
|
||||
}
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
internal static IEnumerator LoadCosmetics()
|
||||
{
|
||||
while (!AmongUsClient.Instance || CatalogLocations.Select(x=>x.Location).Any(x=>!LoadedLocations.Contains(x))) yield return null;
|
||||
|
||||
var hatBehaviours = DiscoverData<HatData>(RegisteredHatKeys);
|
||||
var skinBehaviours = DiscoverData<SkinData>(RegisteredSkinKeys);
|
||||
var namePlateBehaviours = DiscoverAndReportData<NamePlateData>(RegisteredNameplateKeys);
|
||||
var visorBehaviours = DiscoverAndReportData<VisorData>(RegisteredVisorKeys);
|
||||
|
||||
var hatData = new List<HatData>();
|
||||
hatData.AddRange(DestroyableSingleton<HatManager>.Instance.allHats);
|
||||
hatData.ForEach(x => x.StoreName = "Vanilla");
|
||||
DestroyableSingleton<HatManager>.Instance.allHats = PrepareArray(hatData, hatBehaviours);
|
||||
|
||||
var skinData = new List<SkinData>();
|
||||
skinData.AddRange(DestroyableSingleton<HatManager>.Instance.allSkins);
|
||||
skinData.ForEach(x => x.StoreName = "Vanilla");
|
||||
DestroyableSingleton<HatManager>.Instance.allSkins = PrepareArray(skinData, skinBehaviours);
|
||||
|
||||
var visorData = new List<VisorData>();
|
||||
visorData.AddRange(DestroyableSingleton<HatManager>.Instance.allVisors);
|
||||
VisorsTabPatches.AddRange(visorBehaviours);
|
||||
DestroyableSingleton<HatManager>.Instance.allVisors = PrepareArray(visorData, visorBehaviours.Select(x=>x.Data).ToList());
|
||||
|
||||
var namePlateData = new List<NamePlateData>();
|
||||
namePlateData.AddRange(DestroyableSingleton<HatManager>.Instance.allNamePlates);
|
||||
NameplatesTabPatches.AddRange(namePlateBehaviours);
|
||||
DestroyableSingleton<HatManager>.Instance.allNamePlates = PrepareArray(namePlateData, namePlateBehaviours.Select(x => x.Data).ToList());
|
||||
}
|
||||
|
||||
private static T[] PrepareArray<T>(List<T> data, List<T> behaviours) where T : CosmeticData
|
||||
{
|
||||
var count = data.Count;
|
||||
for (int i = 0; i < behaviours.Count; i++)
|
||||
{
|
||||
behaviours[i].displayOrder = count + i;
|
||||
data.Add(behaviours[i]);
|
||||
}
|
||||
return data.ToArray();
|
||||
}
|
||||
|
||||
private static List<T> DiscoverData<T>(List<string> tags)
|
||||
{
|
||||
var behaviours = new List<T>();
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
try
|
||||
{
|
||||
var allLocations = Addressables.LoadResourceLocationsAsync(tag).WaitForCompletion();
|
||||
var assets = Addressables.LoadAssetsAsync<T>(allLocations, null, false).WaitForCompletion();
|
||||
var array = new Il2CppSystem.Collections.Generic.List<T>(assets.Pointer);
|
||||
behaviours.AddRange(array.ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
Error($"Failed to find tag {tag}");
|
||||
}
|
||||
}
|
||||
return behaviours;
|
||||
}
|
||||
|
||||
private static List<(string Category, T Data)> DiscoverAndReportData<T>(List<(string Tag, string Category)> tags)
|
||||
{
|
||||
var behaviours = new List<(string, T)>();
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
try
|
||||
{
|
||||
var allLocations = Addressables.LoadResourceLocationsAsync(tag.Tag).WaitForCompletion();
|
||||
var assets = Addressables.LoadAssetsAsync<T>(allLocations, null, false).WaitForCompletion();
|
||||
var array = new Il2CppSystem.Collections.Generic.List<T>(assets.Pointer);
|
||||
behaviours.AddRange(array.ToArray().Select(x => (tag.Category, x)));
|
||||
}
|
||||
catch
|
||||
{
|
||||
Error($"Failed to find tag {tag}");
|
||||
}
|
||||
}
|
||||
return behaviours;
|
||||
Error("Visors are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead.");
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,31 @@ public static class Extensions
|
||||
button.SetCooldownFill(num);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a random element from the specified sequence.
|
||||
/// </summary>
|
||||
/// <param name="input">
|
||||
/// The sequence to select an element from.
|
||||
/// </param>
|
||||
/// <typeparam name="T">
|
||||
/// The type of elements in the sequence.
|
||||
/// </typeparam>
|
||||
/// <returns>
|
||||
/// A randomly selected element from <paramref name="input"/>.
|
||||
/// </returns>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown when <paramref name="input"/> is empty.
|
||||
/// </exception>
|
||||
public static T RandomSnapshot<T>(this IEnumerable<T> input)
|
||||
{
|
||||
var list = input.ToList();
|
||||
|
||||
if (list.Count == 0)
|
||||
throw new InvalidOperationException("Cannot get random element from an empty collection.");
|
||||
|
||||
return list[UnityEngine.Random.Range(0, list.Count)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a PlayerControl from their PlayerVoteArea in a meeting.
|
||||
/// </summary>
|
||||
@@ -156,6 +181,16 @@ public static class Extensions
|
||||
return TutorialManager.InstanceExists || AmongUsClient.Instance.HostId == playerControl.OwnerId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a PlayerControl is protected by a Guardian Angel.
|
||||
/// </summary>
|
||||
/// <param name="playerControl">The player you're checking for.</param>
|
||||
/// <returns>If the player is protected, true, else false.</returns>
|
||||
public static bool ProtectedByGa(this PlayerControl playerControl)
|
||||
{
|
||||
return playerControl.protectedByGuardianId > -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to convert a System.Collections.Generic.List to Il2cppSystem.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using Object = Il2CppSystem.Object;
|
||||
|
||||
namespace MiraAPI.Utilities;
|
||||
|
||||
@@ -17,6 +18,7 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
|
||||
// normally it is fields, but IL2CPP turns them into properties
|
||||
private readonly PropertyInfo _thisProperty;
|
||||
private readonly PropertyInfo _stateProperty;
|
||||
private readonly PropertyInfo _currentProperty;
|
||||
private readonly Dictionary<string, PropertyInfo> _propertyCache;
|
||||
|
||||
private T? _parentInstance;
|
||||
@@ -37,8 +39,9 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
|
||||
var type = _stateMachine.GetType();
|
||||
_thisProperty = AccessTools.Property(type, "__4__this");
|
||||
_stateProperty = AccessTools.Property(type, "__1__state");
|
||||
_currentProperty = AccessTools.Property(type, "__2__current");
|
||||
|
||||
if (_thisProperty == null || _stateProperty == null)
|
||||
if (_thisProperty == null || _stateProperty == null || _currentProperty == null)
|
||||
{
|
||||
throw new MissingMemberException($"Could not find required properties in type '{type}'.");
|
||||
}
|
||||
@@ -52,6 +55,18 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
|
||||
/// <returns>The current state as an integer.</returns>
|
||||
public int GetState() => (int)_stateProperty.GetValue(_stateMachine)!;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current state of the state machine.
|
||||
/// </summary>
|
||||
/// <param name="newState">The new state to use.</param>
|
||||
public void SetState(int newState) => _stateProperty.SetValue(_stateMachine, newState);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the newest yield return of the state machine.
|
||||
/// </summary>
|
||||
/// <param name="newReturn">The new return to use.</param>
|
||||
public void SetRecentReturn(Object newReturn) => _currentProperty.SetValue(_stateMachine, newReturn);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a parameter from the state machine by its name.
|
||||
/// </summary>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# Mira API
|
||||
|
||||
A thorough, but simple, Among Us modding API and utility library that covers:
|
||||
|
||||
- Roles
|
||||
- Options
|
||||
- Modifiers
|
||||
@@ -13,6 +14,9 @@ A thorough, but simple, Among Us modding API and utility library that covers:
|
||||
- Events
|
||||
- Voting
|
||||
- Assets
|
||||
- Keybinds
|
||||
- Local Settings
|
||||
- Custom Game Over Conditions
|
||||
- Compatibility
|
||||
- ~~Game Modes~~ (coming soon)
|
||||
|
||||
@@ -24,9 +28,10 @@ The result is a less intrusive, better modding API that covers general use cases
|
||||
# Usage
|
||||
|
||||
To start using Mira API, you need to:
|
||||
|
||||
1. Add a reference to Mira API either through a [DLL](https://github.com/All-Of-Us-Mods/MiraAPI/releases), project reference, or [NuGet package](https://www.nuget.org/packages/AllOfUs.MiraAPI).
|
||||
2. Add a BepInDependency on your plugin class like this: `[BepInDependency(MiraApiPlugin.Id)]`
|
||||
3. Implement the IMiraPlugin interface in your plugin class.
|
||||
3. Implement the `IMiraPlugin` interface on your plugin class.
|
||||
|
||||
Mira API also depends on [Reactor](https://github.com/NuclearPowered/Reactor) to function properly!
|
||||
Remember to include it as a reference and `BepInDependency`!
|
||||
@@ -34,8 +39,10 @@ Remember to include it as a reference and `BepInDependency`!
|
||||
For a full example, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExamplePlugin.cs).
|
||||
|
||||
## Recommended Project Structure
|
||||
|
||||
It is highly recommended to follow this project structure when using Mira API to keep your code clean and organized.
|
||||
You can also view the Example Mod in this repository for some guidance.
|
||||
|
||||
```
|
||||
MyMiraMod/
|
||||
├── Buttons/
|
||||
@@ -60,220 +67,21 @@ MyMiraMod/
|
||||
└── MyModAssets.cs
|
||||
```
|
||||
|
||||
## Roles
|
||||
Roles are straightforward in Mira API. There are two things you need to do to create a custom role:
|
||||
1. Create a class that inherits from a base game role (like `CrewmateRole`, `ImpostorRole`, etc.)
|
||||
2. Implement the `ICustomRole` interface from Mira API.
|
||||
# Documentation
|
||||
|
||||
**Disclaimer: Make sure your plugin class has the following attribute `[ReactorModFlags(ModFlags.RequireOnAllClients)]` or else your roles will not register correctly.**
|
||||
Full documentation for every Mira API feature is available on the **[wiki](https://github.com/All-Of-Us-Mods/MiraAPI/wiki)**:
|
||||
|
||||
Note: For step 1, if you are making neutral roles,
|
||||
you can choose either `CrewmateRole` or `ImpostorRole`,
|
||||
or even `RoleBehaviour` if you are okay with starting from scratch.
|
||||
|
||||
Mira API handles everything else, from adding the proper options to the settings menu,
|
||||
to managing the role assignment at the start of the game.
|
||||
There are no extra steps on the developer's part.
|
||||
|
||||
See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Roles/CustomRole.cs) for a code example.
|
||||
|
||||
## Modifiers
|
||||
Mira API uses a different definition of 'modifiers' than other Among Us mods.
|
||||
For example, in Town Of Us, a modifier is an extra "ability" that is applied on top of the base role.
|
||||
However, in Mira API, modifiers are very flexible.
|
||||
A modifier is anything that "modifiers" a player's abilities or interactions.
|
||||
|
||||
Mira provides three classes for working with modifiers:
|
||||
- `BaseModifier`: The base for every modifier. You MUST add and remove this modifier from a player manually!
|
||||
- `TimedModifier`: A modifier that has a time limit. This modifier has to be added manually, but will automatically remove itself after the time limit.
|
||||
- `GameModifier`: This works like the typical TOU modifier, where it is automatically applied at the beginning of the game, then removed at the end.
|
||||
|
||||
Modifiers provide various overridable functions and properties for custom behavior.
|
||||
They can also be used for "tagging" a player.
|
||||
You can check if a player has a modifier through the extension method `HasModifier` on a `PlayerControl` object.
|
||||
|
||||
To start using a modifier, pick one of the base classes above and create a class that inherits from it. Implement the properties and methods you would like, then add the `[RegisterModifier]` attribute to the class.
|
||||
|
||||
An example Game modifier can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Modifiers/GameModifierExample.cs).
|
||||
An example Timer modifier can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Modifiers/ModifierTimerExample.cs).
|
||||
|
||||
## Options
|
||||
Options are also simple in Mira API.
|
||||
Mira API handles all the hard work behind the scenes,
|
||||
so developers only have to follow a few steps to create their custom options.
|
||||
The Options API is split up into Groups and Options.
|
||||
Every Option needs to be in a Group.
|
||||
|
||||
To create a group, you need to create a class that inherits from the `AbstractOptionGroup` abstract class.
|
||||
Groups contain some properties for developers to control,
|
||||
including `GroupName`, `GroupColor`, `GroupVisible`, and `OptionableType`.
|
||||
The full list of properties can be found in the `AbstractOptionGroup` class.
|
||||
Only the `GroupName` is required.
|
||||
|
||||
Here is an example of a group class:
|
||||
```csharp
|
||||
public class MyOptionsGroup : AbstractOptionGroup
|
||||
{
|
||||
public override string GroupName => "My Options"; // this is required
|
||||
|
||||
[ModdedNumberOption("My Number Option", min: 0, max: 10)]
|
||||
public float MyNumberOption { get; set; } = 5f;
|
||||
}
|
||||
```
|
||||
|
||||
You can access any group class using the `OptionGroupSingleton` class like this:
|
||||
```csharp
|
||||
// MyOptionsGroup is a class that inherits from AbstractOptionGroup
|
||||
var myGroup = OptionGroupSingleton<MyOptionsGroup>.Instance; // gets the instance of the group
|
||||
Logger<MyPlugin>.Info(myGroup.MyNumberOption); // prints the value of the option to the console
|
||||
```
|
||||
|
||||
Once you have an options group, there are two ways to make the actual options:
|
||||
- Use an Option Attribute with a property.
|
||||
- Create a ModdedOption property.
|
||||
|
||||
### Option Attributes
|
||||
|
||||
This is an example of using an Option Attribute on a property:
|
||||
```csharp
|
||||
// The first parameter is always the name of the option. The rest are dependent on the type of option.
|
||||
[ModdedNumberOption("Sussy level", min: 0, max: 10)]
|
||||
public float SussyLevel { get; set; } = 4f; // You can set a default value here.
|
||||
```
|
||||
|
||||
Here are the available Option Attributes and their signatures:
|
||||
```csharp
|
||||
ModdedEnumOption(string name, Type enumType, string[]? values = null, Type? roleType = null)
|
||||
|
||||
ModdedNumberOption(
|
||||
string name,
|
||||
float min,
|
||||
float max,
|
||||
float increment=1
|
||||
NumberSuffixes suffixType = NumberSuffixes.None,
|
||||
bool zeroInfinity = false,
|
||||
Type? roleType = null)
|
||||
|
||||
ModdedToggleOption(string name, Type? roleType = null)
|
||||
```
|
||||
|
||||
### ModdedOption Properties
|
||||
|
||||
And this is an example of a ModdedOption property:
|
||||
```csharp
|
||||
public ModdedToggleOption YeezusAbility { get; } = new ModdedToggleOption("Yeezus Ability", false);
|
||||
```
|
||||
|
||||
There are currently three types of ModdedOptions you can create:
|
||||
- `ModdedEnumOption`
|
||||
- `ModdedNumberOption`
|
||||
- `ModdedToggleOption`
|
||||
|
||||
To see a full example of an option class,
|
||||
see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Options/ExampleOptions.cs).
|
||||
|
||||
### Role Options
|
||||
|
||||
You can also specify a role type for an option or option group.
|
||||
|
||||
To set the role type for an entire group, set the `OptionableType` property on that group like this:
|
||||
```csharp
|
||||
public class MyOptionsGroup : AbstractOptionGroup
|
||||
{
|
||||
public override string GroupName => "My Options";
|
||||
public override Type? OptionableType => typeof(MyRole); // this is the role that will have these options
|
||||
|
||||
[ModdedNumberOption("Ability Uses", min: 0, max: 10)]
|
||||
public float AbilityUses { get; set; } = 5f;
|
||||
}
|
||||
```
|
||||
|
||||
You can also use a modifier type for the `OptionableType` property.
|
||||
This will associate that option group with the specified modifier type
|
||||
and display it in the modifier options menu.
|
||||
|
||||
An example can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs).
|
||||
|
||||
## Custom Murders
|
||||
Mira API provides its own implementation for murders.
|
||||
Our implementation allows for more customization on kills, and helps bypass server checks.
|
||||
You can use `PlayerControl.RpcCustomMurder` to perform a networked custom murder, or `PlayerControl.CustomMurder` to normally perform a custom murder.
|
||||
For example:
|
||||
```cs
|
||||
PlayerControl.LocalPlayer.RpcCustomMurder(Target, createDeadBody: false, teleportMurderer: false, playKillSound: false, resetKillTimer: false, showKillAnim: false);
|
||||
```
|
||||
This will kill a player without creating a dead body and without teleporting the murderer.
|
||||
|
||||
## Buttons
|
||||
|
||||
Mira API provides a simple interface for adding ability buttons to the game.
|
||||
|
||||
The only thing you need to do is create a class
|
||||
that inherits from the `CustomActionButton` class and implement the properties and methods.
|
||||
|
||||
Mira API handles all other tasks and logic required to add the button to the game.
|
||||
|
||||
In case you need to access your `CustomActionButton` instance from another class,
|
||||
you can use the `CustomButtonSingleton` class like this:
|
||||
```csharp
|
||||
var myButton = CustomButtonSingleton<MyCoolButton>.Instance;
|
||||
```
|
||||
|
||||
The button API is straightforward, but provides a lot of flexibility.
|
||||
There are various methods you can override to customize the behavior of your button.
|
||||
See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI/Hud/CustomActionButton.cs)
|
||||
for a full list of methods you can override.
|
||||
|
||||
An example button can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Buttons/ExampleButton.cs).
|
||||
|
||||
## Custom Colors
|
||||
|
||||
Mira provides a simple Custom Color API that allows you to add custom player colors to the game.
|
||||
|
||||
Creating custom colors isn't difficult, but there are some requirements for Mira to register your colors.
|
||||
|
||||
1. Create a ***STATIC*** class to house all your `CustomColor` objects.
|
||||
2. Inside this class, create a `CustomColor` property for each color you intend to add.
|
||||
3. Add the `[RegisterCustomColors]` attribute to the class.
|
||||
|
||||
Here is an example of a custom color class:
|
||||
```csharp
|
||||
[RegisterCustomColors]
|
||||
public static class MyCustomColors
|
||||
{
|
||||
public static CustomColor Cerulean { get; } = new CustomColor("Cerulean", new Color(0.0f, 0.48f, 0.65f));
|
||||
|
||||
public static CustomColor Rose { get; } = new CustomColor("Rose", new Color(0.98f, 0.26f, 0.62f));
|
||||
|
||||
public static CustomColor Gold { get; } = new CustomColor("Gold", new Color(1.0f, 0.84f, 0.0f));
|
||||
}
|
||||
```
|
||||
|
||||
## Assets
|
||||
|
||||
Mira API provides a simple, but expandable asset system.
|
||||
The core of the system is the `LoadableAsset<T>` class.
|
||||
This is a generic abstract class that provides a pattern for loading assets.
|
||||
|
||||
Mira API comes with a few asset loaders:
|
||||
1. `LoadableBundleAsset<T>`: This is used for loading assets from AssetBundles.
|
||||
2. `LoadableAddressableAsset<T>`: This is used for loading assets from Addressables.
|
||||
3. `LoadableResourceAsset`: This is used for loading **only sprites** from the Embedded Resources within a mod.
|
||||
4. `LoadableAudioResourceAsset`: This is used for loading **only audio clips** from the Embedded Resources within a mod.
|
||||
|
||||
The code below shows how to use an asset loaders:
|
||||
```csharp
|
||||
// Load a sprite from an AssetBundle
|
||||
AssetBundle bundle = AssetBundleManager.Load("MyBundle"); // AssetBundleManager is a utility provided by Reactor
|
||||
LoadableAsset<Sprite> mySpriteAsset = new LoadableBundleAsset<Sprite>("MySprite", bundle);
|
||||
Sprite sprite = mySpriteAsset.LoadAsset();
|
||||
|
||||
// Load a sprite from an Embedded Resource
|
||||
// Make sure to set the Build Action of your image to Embedded Resource!
|
||||
LoadableAsset<Sprite> buttonAsset = new LoadableResourceAsset("ExampleMod.Resources.MyButton.png");
|
||||
Sprite button = buttonSpriteAsset.LoadAsset();
|
||||
```
|
||||
|
||||
You can view an example file [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExampleAssets.cs).
|
||||
|
||||
You can create your own asset loaders by inheriting from `LoadableAsset<T>` and implementing the `LoadAsset` method.
|
||||
- [Get Started / IMiraPlugin](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Home)
|
||||
- [Custom Roles](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Custom-Roles)
|
||||
- [Options](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Options)
|
||||
- [Modifiers](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Modifiers)
|
||||
- [Custom Buttons](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Custom-Buttons)
|
||||
- [Custom Colors](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Colors)
|
||||
- [Events](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Events)
|
||||
- [Meetings and Voting](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Meetings-and-Voting)
|
||||
- [Assets](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Assets)
|
||||
- [Keybinds](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Keybinds)
|
||||
- [Local Settings](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Local-Settings)
|
||||
- [Game Modes](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Game-Modes)
|
||||
- [Custom Game Over](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Game-Over)
|
||||
- [Utilities](https://github.com/All-Of-Us-Mods/MiraAPI/wiki/Utilities)
|
||||
Binary file not shown.
Reference in new issue
Block a user