mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 11:39:45 +00:00
Compare commits
49
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9096b6160 | ||
|
|
8bf101534f | ||
|
|
479323acdd | ||
|
|
50c5899f4d | ||
|
|
fd719ae42f | ||
|
|
e050b043cb | ||
|
|
e78c456636 | ||
|
|
7e8d07672c | ||
|
|
77ae01c66a | ||
|
|
ce824f05fa | ||
|
|
b5fe3c7afd | ||
|
|
1750cd3db9 | ||
|
|
4dd2554b38 | ||
|
|
e5cfd8a2fc | ||
|
|
6d387cae96 | ||
|
|
59f3058685 | ||
|
|
9dfb40d7bf | ||
|
|
ffca13e6e6 | ||
|
|
c1d2868e77 | ||
|
|
18c52e0138 | ||
|
|
b64bf7c9de | ||
|
|
e98c16b9f5 | ||
|
|
e166efa666 | ||
|
|
8da80be027 | ||
|
|
af75cc3606 | ||
|
|
0f1962394a | ||
|
|
36991f34ee | ||
|
|
ae5f3783b4 | ||
|
|
12a1908c3e | ||
|
|
8246e05da6 | ||
|
|
c75e039141 | ||
|
|
ac66e0d62b | ||
|
|
c4cbf0b18d | ||
|
|
f3175990d3 | ||
|
|
790d868759 | ||
|
|
9f11874189 | ||
|
|
1b6a2c4eb3 | ||
|
|
81887c34d9 | ||
|
|
810fd54e10 | ||
|
|
5492c2b3cc | ||
|
|
f7a515882a | ||
|
|
89eb774501 | ||
|
|
5fd57633ff | ||
|
|
834d1d878e | ||
|
|
790b37e8d3 | ||
|
|
dfa8b29710 | ||
|
|
2c0042e6a8 | ||
|
|
70f63f8b16 | ||
|
|
03a3733966 |
No files matched your search
+2
-2
@@ -2,12 +2,12 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Reactor" Version="2.3.1" />
|
||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.735" Private="false" ExcludeAssets="runtime;native" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2025.4.15" PrivateAssets="all" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2025.9.9" 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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
|
||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUs)/BepInEx/plugins/" UseSymboliclinksIfPossible="true" />
|
||||
</Target>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
|
||||
<VersionPrefix>0.2.1</VersionPrefix>
|
||||
<VersionPrefix>0.3.1</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MiraAPI.Example.GameOver;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Example.GameOver;
|
||||
using MiraAPI.GameEnd;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
@@ -22,6 +23,7 @@ public class NeutralKillerRole : ImpostorRole, ICustomRole
|
||||
|
||||
public RoleOptionsGroup RoleOptionsGroup { get; } = new("Outcast", Color.gray);
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public TeamIntroConfiguration? IntroConfiguration { get; } = new(
|
||||
Color.gray,
|
||||
"OUTCAST",
|
||||
|
||||
@@ -20,7 +20,7 @@ public class LocalEnumSettingAttribute(
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override LocalEnumSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
public override LocalEnumSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalEnumSetting(tab, configEntryBase, configEntryBase.SettingType, _name, _description, names);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class LocalNumberSettingAttribute(
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override LocalNumberSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
public override LocalNumberSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalNumberSetting(tab, configEntryBase, _name, _description, new FloatRange(min, max), increment, suffixType, formatString);
|
||||
}
|
||||
|
||||
@@ -20,5 +20,5 @@ public abstract class LocalSettingAttribute(
|
||||
/// <param name="tab">Gets the tab where the setting is located.</param>
|
||||
/// <param name="configEntryBase">Gets the config entry the setting is attached to.</param>
|
||||
/// <returns>The created class.</returns>
|
||||
internal abstract ILocalSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase);
|
||||
public abstract ILocalSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class LocalSliderSettingAttribute(
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override LocalSliderSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
public override LocalSliderSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalSliderSetting(tab, configEntryBase, _name, _description, new FloatRange(min, max), displayValue, suffixType, formatString, roundValue);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class LocalToggleSettingAttribute(
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override LocalToggleSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
public override LocalToggleSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalToggleSetting(tab, configEntryBase, _name, _description);
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
{
|
||||
CreateLabel(generalLabel, Scroller.Inner, pair.Key, ref contentOffset);
|
||||
contentOrder = 1;
|
||||
contentIndex = 1;
|
||||
}
|
||||
|
||||
foreach (var setting in pair.Value)
|
||||
@@ -245,6 +246,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
tabButtonText.maxVisibleCharacters = int.MaxValue;
|
||||
tabButtonText.text = TabName;
|
||||
tabButtonText.alignment = TextAlignmentOptions.Left;
|
||||
tabButtonRend?.gameObject.SetActive(!TabAppearance.HideIconOnHover);
|
||||
}));
|
||||
tabButton.OnMouseOut.AddListener((UnityAction)(() =>
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
namespace MiraAPI.LocalSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Struct for modyfing tab apparance.
|
||||
/// Struct for modifying tab appearance.
|
||||
/// Defines how the settings look.
|
||||
/// </summary>
|
||||
public record struct LocalSettingTabAppearance()
|
||||
@@ -24,6 +24,11 @@ public record struct LocalSettingTabAppearance()
|
||||
/// </summary>
|
||||
public Color TabButtonColor { get; set; } = Color.white;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the icon should be hidden when tab button is hovered.
|
||||
/// </summary>
|
||||
public bool HideIconOnHover { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets hover color of the tab button.
|
||||
/// </summary>
|
||||
@@ -78,7 +83,7 @@ public record struct LocalSettingTabAppearance()
|
||||
/// Gets or sets hover color of enum buttons.
|
||||
/// </summary>
|
||||
public Color EnumHoverColor { get; set; } = Palette.AcceptedGreen;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets color of buttons.
|
||||
/// </summary>
|
||||
|
||||
@@ -20,7 +20,10 @@ public abstract class LocalSettingBase<T> : ILocalSetting
|
||||
/// <inheritdoc />
|
||||
public ConfigEntryBase ConfigEntry { get; }
|
||||
|
||||
internal LocalSettingsTab? Tab => LocalSettingsManager.Tabs.FirstOrDefault(x => x.Settings.Contains(this));
|
||||
/// <summary>
|
||||
/// Gets the tab of the local setting.
|
||||
/// </summary>
|
||||
public LocalSettingsTab? Tab => LocalSettingsManager.Tabs.FirstOrDefault(x => x.Settings.Contains(this));
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalSettingBase{T}"/> class.
|
||||
@@ -53,7 +56,7 @@ public abstract class LocalSettingBase<T> : ILocalSetting
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the config entry, casted to the setting type.
|
||||
/// Gets the value of the config entry, cast to the setting type.
|
||||
/// </summary>
|
||||
/// <returns>The value.</returns>
|
||||
public virtual T GetValue()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.LocalSettings.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
|
||||
namespace MiraAPI;
|
||||
@@ -19,6 +18,7 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
{
|
||||
TabButtonHoverColor = MiraApiPlugin.MiraColor,
|
||||
TabIcon = MiraAssets.SettingsIcon,
|
||||
HideIconOnHover = false,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -27,26 +27,14 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
[LocalToggleSetting]
|
||||
public ConfigEntry<bool> ModifiersHudLeftSide { get; private set; } = config.Bind("Displays", "Show Modifiers HUD on Left Side", false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether vents and their connections appear on the map.
|
||||
/// </summary>
|
||||
[LocalToggleSetting]
|
||||
public ConfigEntry<bool> ShowVentsOnMap { get; private set; } = config.Bind("Displays", "Show Vent Layout on Map", true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether cooldowns for buttons below 10 seconds appear with decimals.
|
||||
/// </summary>
|
||||
[LocalToggleSetting]
|
||||
public ConfigEntry<bool> PreciseCooldowns { get; private set; } = config.Bind("Buttons", "Precise Button Cooldowns Under 10s", false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of ability buttons in-game.
|
||||
/// </summary>
|
||||
[LocalSliderSetting(min: 0.5f, max: 1.5f, displayValue: true, formatString: "0.00", suffixType: MiraNumberSuffixes.Multiplier)]
|
||||
public ConfigEntry<float> ButtonUiScale { get; private set; } = config.Bind("Buttons", "Button Scale Factor", 0.8f);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to show keybinds in the control mapper.
|
||||
/// </summary>
|
||||
public ConfigEntry<bool> ShowKeybinds { get; private set; } = config.Bind("Keybinds", "Show Keybinds in Control Mapper", true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to apply cosmetic changes to the TaskAdder.
|
||||
/// </summary>
|
||||
[LocalToggleSetting]
|
||||
public ConfigEntry<bool> PrettyTaskAdder { get; private set; } = config.Bind("Freeplay", "Pretty Task Laptop", true);
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public static class CustomMurderRpc
|
||||
|
||||
if (createDeadBody)
|
||||
{
|
||||
deadBody = Object.Instantiate(GameManager.Instance.DeadBodyPrefab);
|
||||
deadBody = Object.Instantiate(GameManager.Instance.deadBodyPrefab[0]);
|
||||
deadBody.enabled = false;
|
||||
deadBody.ParentId = target.PlayerId;
|
||||
deadBody.bodyRenderers.ToList().ForEach(target.SetPlayerMaterialColors);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using Il2CppSystem.Collections.Generic;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(DetectiveNotesMinigame), nameof(DetectiveNotesMinigame.OpenBodyPopup))]
|
||||
public static class DetectiveNotesMinigamePatch
|
||||
{
|
||||
public static void Prefix(DetectiveNotesMinigame __instance, bool active)
|
||||
{
|
||||
__instance.impostorTypePopup.SetActive(active);
|
||||
if (!active)
|
||||
{
|
||||
ControllerManager.Instance.CloseOverlayMenu(__instance.ImpostorOverlay);
|
||||
ControllerManager.Instance.SetUpSelectables(ControllerManager.Instance.CurrentUiState, __instance.ControllerSelectable[0], __instance.ControllerSelectable);
|
||||
ControllerManager.Instance.SetCurrentSelected(__instance.ControllerSelectable[2]);
|
||||
return;
|
||||
}
|
||||
if (__instance.impostorButton != null)
|
||||
{
|
||||
ControllerManager.Instance.OpenOverlayMenu(__instance.ImpostorOverlay, null, __instance.ImpostorIconControllerSelectables[0], __instance.ImpostorIconControllerSelectables, false);
|
||||
return;
|
||||
}
|
||||
__instance.impostorButton = new List<GameObject>();
|
||||
int num = 0;
|
||||
var allRoles = DestroyableSingleton<RoleManager>.Instance.AllRoles;
|
||||
var customRoles = CustomRoleManager.CustomRoleBehaviours;
|
||||
foreach (var role in allRoles)
|
||||
{
|
||||
if (role.TeamType != RoleTeamTypes.Impostor || role.Role == RoleTypes.ImpostorGhost || customRoles.Contains(role) )
|
||||
continue;
|
||||
GameObject gameObject = Object.Instantiate<GameObject>(__instance.impostorTypePrefab, __instance.impostorTypeParent);
|
||||
__instance.impostorButton.Add(gameObject);
|
||||
gameObject.GetComponent<DetectiveImpostorType>().Initialize(__instance, role);
|
||||
num++;
|
||||
__instance.ImpostorIconControllerSelectables.Add(gameObject.GetComponent<PassiveButton>());
|
||||
}
|
||||
ControllerManager.Instance.OpenOverlayMenu(__instance.ImpostorOverlay, null, __instance.ImpostorIconControllerSelectables[0], __instance.ImpostorIconControllerSelectables, false);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,17 @@ namespace MiraAPI.Patches.Events;
|
||||
|
||||
internal static class EndGamePatches
|
||||
{
|
||||
[HarmonyPatch(typeof(GameManager), nameof(GameManager.Awake))]
|
||||
public static class GameManagerAwakePatch
|
||||
{
|
||||
public static void Postfix(GameManager __instance)
|
||||
{
|
||||
__instance.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(GameManager), nameof(GameManager.RpcEndGame))]
|
||||
public static class GameManagerPatches
|
||||
public static class GameManagerRpcEndGamePatch
|
||||
{
|
||||
public static bool Prefix(GameOverReason endReason)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Freeplay;
|
||||
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using TMPro;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
@@ -21,6 +24,8 @@ namespace MiraAPI.Patches.Freeplay;
|
||||
internal static class TaskAdderPatches
|
||||
{
|
||||
private static Scroller _scroller = null!;
|
||||
private static Dictionary<string, TaskFolder> folders = new();
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(TaskAdderGame.Begin))]
|
||||
public static void AddRolesFolder(TaskAdderGame __instance)
|
||||
@@ -60,46 +65,168 @@ internal static class TaskAdderPatches
|
||||
__instance.RoleButton.GetComponent<PassiveButton>().ClickMask = collider;
|
||||
__instance.RootFolderPrefab.GetComponent<PassiveButton>().ClickMask = collider;
|
||||
__instance.RootFolderPrefab.gameObject.SetActive(false);
|
||||
|
||||
__instance.TaskParent = inner.transform;
|
||||
var crewLocale = TranslationController.Instance.GetString(StringNames.Crewmate);
|
||||
var impLocale = TranslationController.Instance.GetString(StringNames.Impostor);
|
||||
|
||||
var rolesFolder = Object.Instantiate(__instance.RootFolderPrefab, _scroller.Inner);
|
||||
rolesFolder.gameObject.SetActive(false);
|
||||
rolesFolder.FolderName = "Roles";
|
||||
rolesFolder.name = "RolesFolder";
|
||||
var crewmateFolder = __instance.Root.SubFolders.ToArray().FirstOrDefault(x => x.FolderName == crewLocale)!;
|
||||
var impostorFolder = __instance.Root.SubFolders.ToArray().FirstOrDefault(x => x.FolderName == impLocale)!;
|
||||
//var neutralFolder = __instance.CreateFolder("Neutral", __instance.Root, 2, Color.gray);
|
||||
var modifiersFolder = __instance.CreateFolder("Modifiers", __instance.Root, 0, Color.blue);
|
||||
|
||||
var modifiersFolder = Object.Instantiate(__instance.RootFolderPrefab, _scroller.Inner);
|
||||
modifiersFolder.gameObject.SetActive(false);
|
||||
modifiersFolder.FolderName = "Modifiers";
|
||||
modifiersFolder.name = "ModifiersFolder";
|
||||
folders.Clear();
|
||||
folders.Add(crewmateFolder.FolderName, crewmateFolder);
|
||||
folders.Add(impostorFolder.FolderName, impostorFolder);
|
||||
//folders.Add("Neutrals", neutralFolder);
|
||||
folders.Add("Modifiers", modifiersFolder);
|
||||
|
||||
int folderIdx = 2;
|
||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins)
|
||||
{
|
||||
if (plugin.InternalRoles.Any(x => x.Value is ICustomRole { Configuration.ShowInFreeplay: true }))
|
||||
var pluginFolders = new Dictionary<string, TaskFolder>();
|
||||
|
||||
foreach (var role in plugin.InternalRoles
|
||||
.Where(x => x.Value is ICustomRole { Configuration.ShowInFreeplay: true })
|
||||
.Select(x => x.Value))
|
||||
{
|
||||
var newFolder = Object.Instantiate(__instance.RootFolderPrefab, _scroller.Inner);
|
||||
newFolder.name = plugin.PluginId+":Roles";
|
||||
newFolder.FolderName = plugin.PluginInfo.Metadata.Name;
|
||||
newFolder.gameObject.SetActive(false);
|
||||
rolesFolder.SubFolders.Add(newFolder);
|
||||
var customRole = role as ICustomRole;
|
||||
var folderName = customRole!.Configuration.FreeplayFolder;
|
||||
if (!folders.TryGetValue(folderName, out var teamFolder))
|
||||
{
|
||||
teamFolder = __instance.CreateFolder(folderName, __instance.Root, folderIdx++, customRole.IntroConfiguration?.IntroTeamColor ?? Color.gray);
|
||||
folders.Add(folderName, teamFolder);
|
||||
}
|
||||
|
||||
if (!pluginFolders.TryGetValue(folderName, out var pluginFolder))
|
||||
{
|
||||
pluginFolder = __instance.CreateFolder(plugin.PluginInfo.Metadata.Name, teamFolder);
|
||||
pluginFolder.name = $"Roles:{folderName}:{plugin.PluginId}";
|
||||
pluginFolders.Add(folderName, teamFolder);
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.InternalModifiers.Exists(x => x.ShowInFreeplay))
|
||||
{
|
||||
var newFolder = Object.Instantiate(__instance.RootFolderPrefab, _scroller.Inner);
|
||||
newFolder.name = plugin.PluginId+":Modifiers";
|
||||
newFolder.FolderName = plugin.PluginInfo.Metadata.Name;
|
||||
newFolder.gameObject.SetActive(false);
|
||||
modifiersFolder.SubFolders.Add(newFolder);
|
||||
__instance.CreateFolder(plugin.PluginInfo.Metadata.Name, modifiersFolder)
|
||||
.gameObject.name = plugin.PluginId;
|
||||
}
|
||||
}
|
||||
|
||||
__instance.Root.SubFolders.Add(rolesFolder);
|
||||
__instance.Root.SubFolders.Add(modifiersFolder);
|
||||
// Modifier folder at the end
|
||||
__instance.Root.SubFolders.Insert(folderIdx, modifiersFolder);
|
||||
|
||||
__instance.GoToRoot();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(TaskAdderGame.PopulateRoot))]
|
||||
private static bool PopulateRootPrefix(TaskAdderGame __instance, TaskAdderGame.FolderType folderType, TaskFolder rootFolder, Il2CppSystem.Collections.Generic.Dictionary<string, TaskFolder> folders, Il2CppReferenceArray<NormalPlayerTask> taskList)
|
||||
{
|
||||
if (folderType != TaskAdderGame.FolderType.Tasks)
|
||||
{
|
||||
if (folderType != TaskAdderGame.FolderType.Roles)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TaskFolder crewFolder = folders["Crewmates"] =
|
||||
Object.Instantiate(__instance.RootFolderPrefab, __instance.transform);
|
||||
crewFolder.gameObject.SetActive(false);
|
||||
crewFolder.SetFolderColor(TaskFolder.FolderColor.Blue);
|
||||
TaskFolder impFolder = folders["Impostors"] =
|
||||
Object.Instantiate(__instance.RootFolderPrefab, __instance.transform);
|
||||
impFolder.gameObject.SetActive(false);
|
||||
impFolder.SetFolderColor(TaskFolder.FolderColor.Red);
|
||||
crewFolder.FolderName = TranslationController.Instance.GetString(StringNames.Crewmate);
|
||||
impFolder.FolderName = TranslationController.Instance.GetString(StringNames.Impostor);
|
||||
rootFolder.SubFolders.Insert(0, crewFolder);
|
||||
rootFolder.SubFolders.Insert(0, impFolder);
|
||||
Il2CppSystem.Collections.Generic.List<RoleBehaviour> impRoles = new();
|
||||
Il2CppSystem.Collections.Generic.List<RoleBehaviour> crewRoles = new();
|
||||
foreach (var role in RoleManager.Instance.AllRoles)
|
||||
{
|
||||
if (role.Role != RoleTypes.ImpostorGhost && role.Role != RoleTypes.CrewmateGhost && !role.IsCustomRole())
|
||||
{
|
||||
if (role.TeamType == RoleTeamTypes.Crewmate)
|
||||
{
|
||||
crewRoles.Add(role);
|
||||
}
|
||||
else
|
||||
{
|
||||
impRoles.Add(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
crewFolder.RoleChildren = crewRoles;
|
||||
impFolder.RoleChildren = impRoles;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (taskList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (NormalPlayerTask normalPlayerTask in taskList)
|
||||
{
|
||||
SystemTypes systemTypes = normalPlayerTask.StartAt;
|
||||
if (normalPlayerTask is DivertPowerTask task)
|
||||
{
|
||||
systemTypes = task.TargetSystem;
|
||||
}
|
||||
|
||||
if (systemTypes == SystemTypes.LowerEngine)
|
||||
{
|
||||
systemTypes = SystemTypes.UpperEngine;
|
||||
}
|
||||
|
||||
if (!folders.TryGetValue(systemTypes.ToString(), out var taskFolder3))
|
||||
{
|
||||
taskFolder3 = folders[systemTypes.ToString()] = Object.Instantiate(__instance.RootFolderPrefab, __instance.transform);
|
||||
taskFolder3.SetFolderColor(TaskFolder.FolderColor.Tan);
|
||||
taskFolder3.gameObject.SetActive(false);
|
||||
if (systemTypes == SystemTypes.UpperEngine)
|
||||
{
|
||||
taskFolder3.FolderName = TranslationController.Instance.GetString(StringNames.Engines);
|
||||
}
|
||||
else
|
||||
{
|
||||
taskFolder3.FolderName = TranslationController.Instance.GetString(systemTypes);
|
||||
}
|
||||
|
||||
rootFolder.SubFolders.Add(taskFolder3);
|
||||
}
|
||||
|
||||
taskFolder3.TaskChildren.Add(normalPlayerTask);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static TaskFolder CreateFolder(this TaskAdderGame instance, string name, TaskFolder parent, int idx = -1, Color? color = null)
|
||||
{
|
||||
var folder = Object.Instantiate(instance.RootFolderPrefab, instance.transform);
|
||||
folder.gameObject.SetActive(false);
|
||||
folder.FolderName = name;
|
||||
folder.SetCustomColor(color ?? new Color(0.937f, 0.811f, 0.592f));
|
||||
folder.name = name + "Folder";
|
||||
if (idx == -1)
|
||||
parent.SubFolders.Add(folder);
|
||||
else if (idx > 0)
|
||||
parent.SubFolders.Insert(idx, folder);
|
||||
return folder;
|
||||
}
|
||||
|
||||
private static void SetCustomColor(this TaskFolder folder, Color color)
|
||||
{
|
||||
folder.currentFolderColor = color;
|
||||
folder.folderSpriteRenderer.color = color;
|
||||
folder.buttonRolloverHandler.OutColor = color;
|
||||
folder.buttonRolloverHandler.UnselectedColor = color;
|
||||
}
|
||||
|
||||
private static void AddFileAsChildCustom(
|
||||
this TaskAdderGame instance,
|
||||
TaskAddButton item,
|
||||
@@ -122,40 +249,46 @@ internal static class TaskAdderPatches
|
||||
instance.ActiveItems.Add(item.transform);
|
||||
}
|
||||
|
||||
private static bool IsChildOf(this TaskFolder child, TaskFolder parent) => parent.SubFolders
|
||||
.ToArray()
|
||||
.Any(x => x.FolderName == child.FolderName);
|
||||
|
||||
// yes it might be crazy patching the entire method, but i tried so many other methods and only this works :cry:
|
||||
// true -chip
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(TaskAdderGame.ShowFolder))]
|
||||
public static bool ShowPatch(TaskAdderGame __instance, TaskFolder taskFolder)
|
||||
{
|
||||
var stringBuilder = new Il2CppSystem.Text.StringBuilder(64);
|
||||
StringBuilder stringBuilder = new StringBuilder(64);
|
||||
__instance.Hierarchy.Add(taskFolder);
|
||||
for (var i = 0; i < __instance.Hierarchy.Count; i++)
|
||||
foreach (var t in __instance.Hierarchy)
|
||||
{
|
||||
stringBuilder.Append(__instance.Hierarchy.ToArray()[i].FolderName);
|
||||
stringBuilder.Append("\\");
|
||||
stringBuilder.Append(t.FolderName);
|
||||
stringBuilder.Append('\\');
|
||||
}
|
||||
|
||||
__instance.PathText.text = stringBuilder.ToString();
|
||||
for (var j = 0; j < __instance.ActiveItems.Count; j++)
|
||||
var prettyEnabled = LocalSettingsTabSingleton<MiraApiSettings>.Instance.PrettyTaskAdder.Value;
|
||||
if (prettyEnabled)
|
||||
{
|
||||
Object.Destroy(__instance.ActiveItems.ToArray()[j].gameObject);
|
||||
__instance.PathText.fontSizeMin = 3;
|
||||
__instance.PathText.fontSizeMax = 3;
|
||||
__instance.transform.FindChild("TitleText_TMP")?.gameObject.DestroyImmediate();
|
||||
}
|
||||
|
||||
__instance.ActiveItems.ToArray().Do(x => x.gameObject.Destroy());
|
||||
__instance.ActiveItems.Clear();
|
||||
var num = 0f;
|
||||
var num2 = 0f;
|
||||
var num3 = 0f;
|
||||
for (var k = 0; k < taskFolder.SubFolders.Count; k++)
|
||||
{
|
||||
var taskFolder2 = Object.Instantiate(taskFolder.SubFolders.ToArray()[k], __instance.TaskParent);
|
||||
var folderTransform = taskFolder2.transform;
|
||||
|
||||
float num = 0f;
|
||||
float num2 = 0f;
|
||||
float num3 = 0f;
|
||||
foreach (var t in taskFolder.SubFolders)
|
||||
{
|
||||
TaskFolder taskFolder2 = Object.Instantiate(t, __instance.TaskParent);
|
||||
taskFolder2.gameObject.SetActive(true);
|
||||
taskFolder2.Parent = __instance;
|
||||
|
||||
folderTransform.localPosition = new Vector3(num, num2, 0f);
|
||||
folderTransform.localScale = Vector3.one;
|
||||
num3 = Mathf.Max(num3, taskFolder2.Text.bounds.size.y + 1.3f);
|
||||
taskFolder2.transform.localPosition = new Vector3(num, num2, 0f);
|
||||
taskFolder2.transform.localScale = Vector3.one;
|
||||
num3 = Mathf.Max(num3, taskFolder2.Text.bounds.size.y + 1.1f);
|
||||
num += __instance.folderWidth;
|
||||
if (num > __instance.lineWidth)
|
||||
{
|
||||
@@ -164,139 +297,202 @@ internal static class TaskAdderPatches
|
||||
num3 = 0f;
|
||||
}
|
||||
|
||||
__instance.ActiveItems.Add(folderTransform);
|
||||
if (!taskFolder2 || !taskFolder2.Button)
|
||||
__instance.ActiveItems.Add(taskFolder2.transform);
|
||||
if (taskFolder2 != null && taskFolder2.Button != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskFolder2.Button);
|
||||
if (!string.IsNullOrEmpty(__instance.restorePreviousSelectionByFolderName) &&
|
||||
taskFolder2.FolderName.Equals(__instance.restorePreviousSelectionByFolderName, StringComparison.Ordinal))
|
||||
{
|
||||
__instance.restorePreviousSelectionFound = taskFolder2.Button;
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskFolder2.Button);
|
||||
}
|
||||
}
|
||||
|
||||
var flag = false;
|
||||
var list = taskFolder.Children.ToArray().OrderBy(t => t.TaskType).ToList();
|
||||
|
||||
for (var l = 0; l < list.Count; l++)
|
||||
var list = taskFolder.TaskChildren
|
||||
.ToArray()
|
||||
.OrderBy(x => x.TaskType)
|
||||
.ToArray();
|
||||
foreach (var task in list)
|
||||
{
|
||||
var taskAddButton = Object.Instantiate(__instance.TaskPrefab);
|
||||
taskAddButton.MyTask = list.ToArray()[l];
|
||||
switch (taskAddButton.MyTask.TaskType)
|
||||
TaskAddButton taskAddButton = Object.Instantiate(__instance.TaskPrefab);
|
||||
taskAddButton.MyTask = task;
|
||||
switch (task.TaskType)
|
||||
{
|
||||
case TaskTypes.DivertPower:
|
||||
{
|
||||
var targetSystem = taskAddButton.MyTask.Cast<DivertPowerTask>().TargetSystem;
|
||||
taskAddButton.Text.text = TranslationController.Instance.GetString(
|
||||
StringNames.DivertPowerTo,
|
||||
TranslationController.Instance.GetString(targetSystem));
|
||||
break;
|
||||
}
|
||||
{
|
||||
var targetSystem = task.Cast<DivertPowerTask>().TargetSystem;
|
||||
taskAddButton.Text.text = TranslationController.Instance.GetString(
|
||||
StringNames.DivertPowerTo,
|
||||
TranslationController.Instance.GetString(targetSystem));
|
||||
break;
|
||||
}
|
||||
case TaskTypes.FixWeatherNode:
|
||||
{
|
||||
var nodeId = taskAddButton.MyTask.Cast<WeatherNodeTask>().NodeId;
|
||||
taskAddButton.Text.text =
|
||||
TranslationController.Instance.GetString(
|
||||
StringNames.FixWeatherNode) + " " +
|
||||
TranslationController.Instance.GetString(
|
||||
WeatherSwitchGame.ControlNames[nodeId]);
|
||||
break;
|
||||
}
|
||||
{
|
||||
var nodeId = task.Cast<WeatherNodeTask>().NodeId;
|
||||
taskAddButton.Text.text =
|
||||
TranslationController.Instance.GetString(
|
||||
StringNames.FixWeatherNode) + " " +
|
||||
TranslationController.Instance.GetString(
|
||||
WeatherSwitchGame.ControlNames[nodeId]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
taskAddButton.Text.text =
|
||||
TranslationController.Instance.GetString(taskAddButton.MyTask.TaskType);
|
||||
TranslationController.Instance.GetString(task.TaskType);
|
||||
break;
|
||||
}
|
||||
|
||||
__instance.AddFileAsChildCustom(taskAddButton, ref num, ref num2, ref num3);
|
||||
if (taskAddButton.Button == null)
|
||||
if (taskAddButton != null && taskAddButton.Button != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskAddButton.Button);
|
||||
if (__instance.Hierarchy.Count == 1 || flag)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var component =
|
||||
ControllerManager.Instance.CurrentUiState.CurrentSelection.GetComponent<TaskFolder>();
|
||||
if (component != null)
|
||||
{
|
||||
__instance.restorePreviousSelectionByFolderName = component.FolderName;
|
||||
}
|
||||
|
||||
ControllerManager.Instance.SetDefaultSelection(taskAddButton.Button);
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (taskFolder.FolderName == "Roles")
|
||||
{
|
||||
for (var m = 0; m < RoleManager.Instance.AllRoles.Length; m++)
|
||||
{
|
||||
var roleBehaviour = RoleManager.Instance.AllRoles[m];
|
||||
if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost ||
|
||||
CustomRoleManager.CustomRoles.ContainsKey((ushort)roleBehaviour.Role))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var taskAddButton2 = Object.Instantiate(__instance.RoleButton);
|
||||
taskAddButton2.SafePositionWorld = __instance.SafePositionWorld;
|
||||
taskAddButton2.Text.text = "Be_" + roleBehaviour.NiceName + ".exe";
|
||||
__instance.AddFileAsChildCustom(taskAddButton2, ref num, ref num2, ref num3);
|
||||
taskAddButton2.Role = roleBehaviour;
|
||||
|
||||
if (taskAddButton2.Button == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskAddButton2.Button);
|
||||
switch (m)
|
||||
{
|
||||
case 0 when __instance.restorePreviousSelectionFound != null:
|
||||
ControllerManager.Instance.SetDefaultSelection(__instance.restorePreviousSelectionFound);
|
||||
__instance.restorePreviousSelectionByFolderName = string.Empty;
|
||||
__instance.restorePreviousSelectionFound = null;
|
||||
break;
|
||||
case 0:
|
||||
ControllerManager.Instance.SetDefaultSelection(taskAddButton2.Button);
|
||||
break;
|
||||
}
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskAddButton.Button, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (taskFolder)
|
||||
var roleChildren = taskFolder.RoleChildren
|
||||
.ToArray()
|
||||
.Where(x => x is not ICustomRole)
|
||||
.ToArray();
|
||||
foreach (var role in roleChildren)
|
||||
{
|
||||
var split = taskFolder.name.Split(':');
|
||||
if (split.Length == 2)
|
||||
TaskAddButton roleAddButton = Object.Instantiate(__instance.RoleButton);
|
||||
roleAddButton.SafePositionWorld = __instance.SafePositionWorld;
|
||||
roleAddButton.Text.text = prettyEnabled ? role.GetRoleName() : "Be_" + role.GetRoleName() + ".exe";
|
||||
roleAddButton.Role = role;
|
||||
if (prettyEnabled)
|
||||
{
|
||||
var pluginId = split[0];
|
||||
var folderName = split[1];
|
||||
roleAddButton.Text.fontSizeMin = 1;
|
||||
roleAddButton.FileImage.sprite = role.IsImpostor
|
||||
? MiraAssets.ImpostorFile.LoadAsset()
|
||||
: MiraAssets.CrewmateFile.LoadAsset();
|
||||
}
|
||||
|
||||
if (MiraPluginManager.GetPluginByGuid(pluginId) is { } plugin)
|
||||
__instance.AddFileAsChildCustom(roleAddButton, ref num, ref num2, ref num3);
|
||||
if (roleAddButton != null && roleAddButton.Button != null)
|
||||
{
|
||||
ControllerManager.Instance.AddSelectableUiElement(roleAddButton.Button);
|
||||
}
|
||||
}
|
||||
|
||||
string[] split = [];
|
||||
try
|
||||
{
|
||||
split = taskFolder.name.Replace("(Clone)", string.Empty).Split(':');
|
||||
}
|
||||
catch
|
||||
{
|
||||
// I hate you
|
||||
}
|
||||
if (split is ["Roles", _, _] && folders.Any(x => taskFolder.IsChildOf(x.Value)))
|
||||
{
|
||||
var plugin = MiraPluginManager.GetPluginByGuid(split[2]);
|
||||
if (plugin != null)
|
||||
{
|
||||
foreach (var role in plugin.InternalRoles)
|
||||
{
|
||||
if (folderName == "Roles(Clone)")
|
||||
var roleBehaviour = role.Value;
|
||||
if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost ||
|
||||
roleBehaviour is ICustomRole { Configuration.ShowInFreeplay: false })
|
||||
{
|
||||
PluginRoles(__instance, plugin, ref num, ref num2, ref num3);
|
||||
continue;
|
||||
}
|
||||
else if (folderName == "Modifiers(Clone)")
|
||||
var crewLocale = TranslationController.Instance.GetString(StringNames.Crewmate);
|
||||
var impLocale = TranslationController.Instance.GetString(StringNames.Impostor);
|
||||
|
||||
var teamFolder = roleBehaviour.IsImpostor ? impLocale : crewLocale;
|
||||
if (roleBehaviour is ICustomRole cs)
|
||||
{
|
||||
PluginModifiers(__instance, plugin, ref num, ref num2, ref num3);
|
||||
teamFolder = cs.Configuration.FreeplayFolder;
|
||||
}
|
||||
if (split[1] != teamFolder)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var roleAddButton = Object.Instantiate(__instance.RoleButton);
|
||||
roleAddButton.MyTask = null;
|
||||
roleAddButton.SafePositionWorld = __instance.SafePositionWorld;
|
||||
roleAddButton.Text.text = prettyEnabled ? roleBehaviour.GetRoleName() : "Be_" + roleBehaviour.GetRoleName() + ".exe";
|
||||
roleAddButton.Text.EnableMasking();
|
||||
roleAddButton.role = roleBehaviour;
|
||||
if (prettyEnabled)
|
||||
{
|
||||
roleAddButton.Text.fontSizeMin = 1;
|
||||
roleAddButton.FileImage.sprite = roleBehaviour.IsImpostor
|
||||
? MiraAssets.ImpostorFile.LoadAsset()
|
||||
: MiraAssets.CrewmateFile.LoadAsset();
|
||||
}
|
||||
if (roleBehaviour is ICustomRole custom)
|
||||
{
|
||||
if (prettyEnabled && custom.Team == ModdedRoleTeams.Custom) roleAddButton.FileImage.sprite = MiraAssets.CustomTeamFile.LoadAsset();
|
||||
var customColor = custom.IntroConfiguration?.IntroTeamColor ?? Color.gray;
|
||||
if (custom.Team is ModdedRoleTeams.Crewmate)
|
||||
{
|
||||
customColor = Palette.CrewmateBlue;
|
||||
}
|
||||
else if (custom.Team is ModdedRoleTeams.Impostor)
|
||||
{
|
||||
customColor = Palette.ImpostorRed;
|
||||
}
|
||||
roleAddButton.FileImage.color = customColor;
|
||||
roleAddButton.RolloverHandler.OutColor = customColor;
|
||||
}
|
||||
|
||||
__instance.AddFileAsChildCustom(roleAddButton, ref num, ref num2, ref num3);
|
||||
ControllerManager.Instance.AddSelectableUiElement(roleAddButton.Button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var chip in __instance.ActiveItems)
|
||||
if (folders.TryGetValue("Modifiers", out var modifiersFolder) && taskFolder.IsChildOf(modifiersFolder))
|
||||
{
|
||||
chip.GetComponentInChildren<TextMeshPro>().EnableStencilMasking();
|
||||
chip.GetComponent<SpriteRenderer>().maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
var plugin = MiraPluginManager.GetPluginByGuid(taskFolder.name.Replace("(Clone)", string.Empty));
|
||||
if (plugin != null)
|
||||
{
|
||||
foreach (var modifier in plugin.InternalModifiers)
|
||||
{
|
||||
if (!modifier.ShowInFreeplay)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var taskAddButton = Object.Instantiate(__instance.RoleButton);
|
||||
taskAddButton.name = modifier.TypeId.ToString(NumberFormatInfo.InvariantInfo);
|
||||
taskAddButton.role = null;
|
||||
taskAddButton.MyTask = null;
|
||||
taskAddButton.SafePositionWorld = __instance.SafePositionWorld;
|
||||
taskAddButton.Text.text = modifier.ModifierName;
|
||||
taskAddButton.Text.fontSizeMin = 1;
|
||||
taskAddButton.Text.EnableMasking();
|
||||
taskAddButton.FileImage.color = modifier.FreeplayFileColor;
|
||||
taskAddButton.RolloverHandler.OutColor = modifier.FreeplayFileColor;
|
||||
if (modifier is TimedModifier timed)
|
||||
{
|
||||
taskAddButton.FileImage.sprite = MiraAssets.TimedModifierFile.LoadAsset();
|
||||
taskAddButton.Text.text += $" ({timed.Duration}s)";
|
||||
}
|
||||
else
|
||||
{
|
||||
taskAddButton.FileImage.sprite = MiraAssets.ModifierFile.LoadAsset();
|
||||
}
|
||||
|
||||
taskAddButton.Button.OnClick = new Button.ButtonClickedEvent();
|
||||
var m = modifier;
|
||||
taskAddButton.Button.OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
var id = m.TypeId;
|
||||
if (PlayerControl.LocalPlayer.HasModifier(id))
|
||||
{
|
||||
PlayerControl.LocalPlayer.RemoveModifier(id);
|
||||
taskAddButton.Overlay.enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerControl.LocalPlayer.AddModifier(id);
|
||||
taskAddButton.Overlay.enabled = true;
|
||||
}
|
||||
}));
|
||||
|
||||
__instance.AddFileAsChildCustom(taskAddButton, ref num, ref num2, ref num3);
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskAddButton.Button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_scroller)
|
||||
@@ -306,129 +502,11 @@ internal static class TaskAdderPatches
|
||||
_scroller.ScrollToTop();
|
||||
}
|
||||
|
||||
if (__instance.Hierarchy.Count == 1)
|
||||
{
|
||||
ControllerManager.Instance.SetBackButton(__instance.BackButton);
|
||||
return false;
|
||||
}
|
||||
ControllerManager.Instance.SetBackButton(__instance.Hierarchy.Count == 1
|
||||
? __instance.BackButton
|
||||
: __instance.FolderBackButton);
|
||||
|
||||
ControllerManager.Instance.SetBackButton(__instance.FolderBackButton);
|
||||
__instance.SetPreviousControllerSelection(taskFolder.FolderName);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void PluginModifiers(
|
||||
TaskAdderGame instance,
|
||||
MiraPluginInfo plugin,
|
||||
ref float num,
|
||||
ref float num2,
|
||||
ref float num3)
|
||||
{
|
||||
for (var m = 0; m < plugin.InternalModifiers.Count; m++)
|
||||
{
|
||||
var modifier = plugin.InternalModifiers[m];
|
||||
if (!modifier.ShowInFreeplay)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var taskAddButton = Object.Instantiate(instance.RoleButton);
|
||||
taskAddButton.name = modifier.TypeId.ToString(NumberFormatInfo.InvariantInfo);
|
||||
taskAddButton.role = null;
|
||||
taskAddButton.MyTask = null;
|
||||
taskAddButton.SafePositionWorld = instance.SafePositionWorld;
|
||||
taskAddButton.Text.text = modifier.ModifierName;
|
||||
taskAddButton.Text.fontSizeMin = 1;
|
||||
taskAddButton.Text.EnableMasking();
|
||||
taskAddButton.FileImage.color = modifier.FreeplayFileColor;
|
||||
taskAddButton.RolloverHandler.OutColor = modifier.FreeplayFileColor;
|
||||
taskAddButton.Button.OnClick = new Button.ButtonClickedEvent();
|
||||
taskAddButton.Button.OnClick.AddListener((UnityEngine.Events.UnityAction)(() =>
|
||||
{
|
||||
var id = modifier.TypeId;
|
||||
if (PlayerControl.LocalPlayer.HasModifier(id))
|
||||
{
|
||||
PlayerControl.LocalPlayer.RemoveModifier(id);
|
||||
taskAddButton.Overlay.enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerControl.LocalPlayer.AddModifier(id);
|
||||
taskAddButton.Overlay.enabled = true;
|
||||
}
|
||||
}));
|
||||
|
||||
if (modifier is TimedModifier timed)
|
||||
{
|
||||
taskAddButton.FileImage.sprite = MiraAssets.TimedModifierFile.LoadAsset();
|
||||
taskAddButton.Text.text += $"({timed.Duration}s)";
|
||||
}
|
||||
|
||||
instance.AddFileAsChildCustom(taskAddButton, ref num, ref num2, ref num3);
|
||||
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskAddButton.Button);
|
||||
switch (m)
|
||||
{
|
||||
case 0 when instance.restorePreviousSelectionFound != null:
|
||||
ControllerManager.Instance.SetDefaultSelection(instance.restorePreviousSelectionFound);
|
||||
instance.restorePreviousSelectionByFolderName = string.Empty;
|
||||
instance.restorePreviousSelectionFound = null;
|
||||
break;
|
||||
case 0:
|
||||
ControllerManager.Instance.SetDefaultSelection(taskAddButton.Button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void PluginRoles(TaskAdderGame instance, MiraPluginInfo plugin, ref float num, ref float num2, ref float num3)
|
||||
{
|
||||
for (var m = 0; m < plugin.InternalRoles.Count; m++)
|
||||
{
|
||||
var roleBehaviour = plugin.InternalRoles.ElementAt(m).Value;
|
||||
if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost ||
|
||||
roleBehaviour is ICustomRole { Configuration.ShowInFreeplay: false })
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var taskAddButton2 = Object.Instantiate(instance.RoleButton);
|
||||
taskAddButton2.SafePositionWorld = instance.SafePositionWorld;
|
||||
taskAddButton2.Text.text = "Be_" + roleBehaviour.NiceName + ".exe";
|
||||
taskAddButton2.Text.EnableMasking();
|
||||
|
||||
instance.AddFileAsChildCustom(taskAddButton2, ref num, ref num2, ref num3);
|
||||
taskAddButton2.Role = roleBehaviour;
|
||||
if (roleBehaviour is ICustomRole custom)
|
||||
{
|
||||
var customColor = custom.IntroConfiguration?.IntroTeamColor ?? Color.gray;
|
||||
if (custom.Team is ModdedRoleTeams.Crewmate)
|
||||
{
|
||||
customColor = Palette.CrewmateBlue;
|
||||
}
|
||||
else if (custom.Team is ModdedRoleTeams.Impostor)
|
||||
{
|
||||
customColor = Palette.ImpostorRed;
|
||||
}
|
||||
taskAddButton2.FileImage.color = customColor;
|
||||
taskAddButton2.RolloverHandler.OutColor = customColor;
|
||||
}
|
||||
if (taskAddButton2.Button == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskAddButton2.Button);
|
||||
switch (m)
|
||||
{
|
||||
case 0 when instance.restorePreviousSelectionFound != null:
|
||||
ControllerManager.Instance.SetDefaultSelection(instance.restorePreviousSelectionFound);
|
||||
instance.restorePreviousSelectionByFolderName = string.Empty;
|
||||
instance.restorePreviousSelectionFound = null;
|
||||
break;
|
||||
case 0:
|
||||
ControllerManager.Instance.SetDefaultSelection(taskAddButton2.Button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,12 +182,10 @@ public static class HudManagerPatches
|
||||
entry.Invoke();
|
||||
}
|
||||
}
|
||||
foreach (var entry in KeybindManager.VanillaKeybinds.Values)
|
||||
|
||||
foreach (var entry in KeybindManager.VanillaKeybinds.Values.Where(x => player.GetButtonDown(x.Id)))
|
||||
{
|
||||
if (player.GetButtonDown(entry.Id))
|
||||
{
|
||||
entry.Invoke();
|
||||
}
|
||||
entry.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
using HarmonyLib;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
@@ -29,14 +33,29 @@ public static class IntroCutscenePatches
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(IntroCutscene._ShowRole_d__41), nameof(IntroCutscene._ShowRole_d__41.MoveNext))]
|
||||
[HarmonyPriority(Priority.Last)]
|
||||
public static void ShowRolePatch(IntroCutscene._ShowRole_d__41 __instance)
|
||||
[HarmonyPatch]
|
||||
public static class IntroCutsceneShowRolePatch
|
||||
{
|
||||
var realInstance = __instance.__4__this;
|
||||
var @event = new IntroRoleRevealEvent(realInstance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
public static MethodBase TargetMethod()
|
||||
{
|
||||
return Helpers.GetStateMachineMoveNext<IntroCutscene>("ShowRole")!;
|
||||
}
|
||||
|
||||
public static void Postfix(Il2CppObjectBase __instance)
|
||||
{
|
||||
var wrapper = new StateMachineWrapper<IntroCutscene>(__instance);
|
||||
// run before the first yield
|
||||
if (wrapper.GetState() != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var introCutscene = wrapper.Instance;
|
||||
|
||||
Logger<MiraApiPlugin>.Info("IntroCutscene ShowRole reached");
|
||||
var @event = new IntroRoleRevealEvent(introCutscene);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
@@ -66,16 +85,54 @@ public static class IntroCutscenePatches
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.OnDestroy))]
|
||||
public static void GameBeginPatch(IntroCutscene __instance)
|
||||
[HarmonyPatch]
|
||||
public static class IntroCutsceneDestroyPatch
|
||||
{
|
||||
MiraEventManager.InvokeEvent(new IntroEndEvent(__instance));
|
||||
private static bool _usedFallback;
|
||||
|
||||
var @event = new BeforeRoundStartEvent(true);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
public static MethodBase TargetMethod()
|
||||
{
|
||||
var onDestroy = AccessTools.Method(typeof(IntroCutscene), "OnDestroy");
|
||||
if (onDestroy != null)
|
||||
{
|
||||
_usedFallback = false;
|
||||
Logger<MiraApiPlugin>.Info("Using OnDestroy for IntroCutsceneDestroyPatch");
|
||||
return onDestroy;
|
||||
}
|
||||
|
||||
if (@event.IsCancelled) return;
|
||||
MiraEventManager.InvokeEvent(new RoundStartEvent(true));
|
||||
_usedFallback = true;
|
||||
return Helpers.GetStateMachineMoveNext<IntroCutscene>("CoBegin")!;
|
||||
}
|
||||
|
||||
public static void Postfix(Il2CppObjectBase __instance)
|
||||
{
|
||||
IntroCutscene introCutscene;
|
||||
|
||||
if (_usedFallback)
|
||||
{
|
||||
var wrapper = new StateMachineWrapper<IntroCutscene>(__instance);
|
||||
// run after the final yield
|
||||
if (wrapper.GetState() != -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
introCutscene = wrapper.Instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
introCutscene = __instance.Cast<IntroCutscene>();
|
||||
}
|
||||
|
||||
|
||||
Logger<MiraApiPlugin>.Info("IntroCutscene ended");
|
||||
|
||||
MiraEventManager.InvokeEvent(new IntroEndEvent(introCutscene));
|
||||
|
||||
var @event = new BeforeRoundStartEvent(true);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (@event.IsCancelled) return;
|
||||
MiraEventManager.InvokeEvent(new RoundStartEvent(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public static class OptionsMenuPatches
|
||||
private static Dictionary<int, List<GameObject>> tabButtons = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates the tabs and their content
|
||||
/// Creates the tabs and their content.
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(OptionsMenuBehaviour.Start))]
|
||||
|
||||
@@ -8,7 +8,7 @@ public static class ToggleBehaviourPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// ResetText was inlined ofc.
|
||||
/// Skill issue
|
||||
/// Skill issue.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(ToggleButtonBehaviour.UpdateText))]
|
||||
|
||||
@@ -6,10 +6,13 @@ 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;
|
||||
@@ -20,6 +23,20 @@ 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)
|
||||
@@ -38,6 +55,8 @@ public static class HatsTabPatches
|
||||
}
|
||||
}
|
||||
|
||||
InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage);
|
||||
|
||||
GenerateHats(__instance, currentPage);
|
||||
|
||||
return false;
|
||||
@@ -45,22 +64,17 @@ public static class HatsTabPatches
|
||||
|
||||
[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))
|
||||
{
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? sortedHats.Count - 1 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
PreviousPage(__instance);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
currentPage++;
|
||||
currentPage = currentPage > sortedHats.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
NextPage(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,10 +98,10 @@ public static class HatsTabPatches
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedHats.Count})\nPress Ctrl or Tab to cycle pages";
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedHats.Count})";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 3f;
|
||||
text.fontSizeMax = 3f;
|
||||
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;
|
||||
@@ -125,9 +139,17 @@ public static class HatsTabPatches
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = hat.ProductId;
|
||||
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))));
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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)));
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,20 @@ public static class NameplatesTabPatches
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -33,6 +47,9 @@ public static class NameplatesTabPatches
|
||||
__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;
|
||||
@@ -45,15 +62,11 @@ public static class NameplatesTabPatches
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? SortedNameplates.Count - 1 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
PreviousPage(__instance);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
currentPage++;
|
||||
currentPage = currentPage > SortedNameplates.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
NextPage(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,10 +86,10 @@ public static class NameplatesTabPatches
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedNameplates.Count})\nPress Ctrl or Tab to cycle pages";
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedNameplates.Count})";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 3f;
|
||||
text.fontSizeMax = 3f;
|
||||
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;
|
||||
@@ -99,9 +112,20 @@ public static class NameplatesTabPatches
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = namePlate.ProductId;
|
||||
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))));
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -18,6 +18,20 @@ 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)
|
||||
@@ -36,6 +50,8 @@ public static class SkinsTabPatches
|
||||
}
|
||||
}
|
||||
|
||||
InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage);
|
||||
|
||||
GenerateHats(__instance, currentPage);
|
||||
|
||||
return false;
|
||||
@@ -48,15 +64,11 @@ public static class SkinsTabPatches
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? sortedSkins.Count - 1 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
PreviousPage(__instance);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
currentPage++;
|
||||
currentPage = currentPage > sortedSkins.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
NextPage(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +88,10 @@ public static class SkinsTabPatches
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedSkins.Count})\nPress Ctrl or Tab to cycle pages";
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedSkins.Count})";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 3f;
|
||||
text.fontSizeMax = 3f;
|
||||
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;
|
||||
@@ -102,9 +114,18 @@ public static class SkinsTabPatches
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = skin.ProductId;
|
||||
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))));
|
||||
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);
|
||||
|
||||
@@ -25,6 +25,21 @@ public static class VisorsTabPatches
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -32,6 +47,9 @@ public static class VisorsTabPatches
|
||||
__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;
|
||||
@@ -44,15 +62,11 @@ public static class VisorsTabPatches
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? SortedVisors.Count - 1 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
PreviousPage(__instance);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
currentPage++;
|
||||
currentPage = currentPage > SortedVisors.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
NextPage(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +86,10 @@ public static class VisorsTabPatches
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedVisors.Count})\nPress Ctrl or Tab to cycle pages";
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedVisors.Count})";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 3f;
|
||||
text.fontSizeMax = 3f;
|
||||
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;
|
||||
@@ -98,9 +112,20 @@ public static class VisorsTabPatches
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = visor.ProductId;
|
||||
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))));
|
||||
|
||||
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);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.GameOptions;
|
||||
@@ -57,6 +58,7 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
var maskBg = __instance.scrollBar.transform.FindChild("MaskBg");
|
||||
var hitbox = __instance.scrollBar.transform.FindChild("Hitbox");
|
||||
var dividerImage = __instance.transform.FindChild("HeaderButtons/DividerImage");
|
||||
|
||||
if (GameSettingMenuPatches.SelectedModIdx == 0)
|
||||
{
|
||||
@@ -67,7 +69,64 @@ public static class RoleSettingMenuPatches
|
||||
maskBg.localScale = new Vector3(6.6811f, 3.3563f, 0.5598f);
|
||||
hitbox.localPosition = new Vector3(0.3297f, -.2333f, 4f);
|
||||
hitbox.localScale = new Vector3(1, 1, 1);
|
||||
return true;
|
||||
dividerImage.gameObject.SetActive(true);
|
||||
|
||||
var num = 0.662f;
|
||||
|
||||
var list = CustomRoleManager.AllRoles.Where(
|
||||
r => !r.IsCustomRole() && r.TeamType == RoleTeamTypes.Crewmate && r.Role != RoleTypes.Crewmate &&
|
||||
r.Role != RoleTypes.CrewmateGhost).ToList();
|
||||
var list2 = CustomRoleManager.AllRoles.Where(
|
||||
r => !r.IsCustomRole() && r.TeamType == RoleTeamTypes.Impostor && r.Role != RoleTypes.Impostor &&
|
||||
r.Role != RoleTypes.ImpostorGhost).ToList();
|
||||
|
||||
if (__instance.roleTabs == null || __instance.roleTabs.Count == 0)
|
||||
{
|
||||
var num2 = -1.928f;
|
||||
__instance.roleTabs = new();
|
||||
__instance.roleTabs.Add(__instance.AllButton);
|
||||
foreach (var t in list)
|
||||
{
|
||||
__instance.AddRoleTab(t, ref num2);
|
||||
}
|
||||
|
||||
foreach (var t in list2)
|
||||
{
|
||||
__instance.AddRoleTab(t, ref num2);
|
||||
}
|
||||
}
|
||||
|
||||
var categoryHeaderEditRole = Object.Instantiate(
|
||||
__instance.categoryHeaderEditRoleOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
__instance.RoleChancesSettings.transform);
|
||||
categoryHeaderEditRole.SetHeader(StringNames.CrewmateRolesHeader, 20);
|
||||
categoryHeaderEditRole.transform.localPosition = new Vector3(4.986f, num, -2f);
|
||||
num -= 0.522f;
|
||||
var num3 = 0;
|
||||
foreach (var t in list)
|
||||
{
|
||||
__instance.CreateQuotaOption(t, ref num, num3);
|
||||
num3++;
|
||||
}
|
||||
|
||||
num -= 0.22f;
|
||||
var categoryHeaderEditRole2 = Object.Instantiate(
|
||||
__instance.categoryHeaderEditRoleOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
__instance.RoleChancesSettings.transform);
|
||||
categoryHeaderEditRole2.SetHeader(StringNames.ImpostorRolesHeader, 20);
|
||||
categoryHeaderEditRole2.transform.localPosition = new Vector3(4.986f, num, -2f);
|
||||
num -= 0.522f;
|
||||
foreach (var t in list2)
|
||||
{
|
||||
__instance.CreateQuotaOption(t, ref num, num3);
|
||||
num3++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ScrollerNum = 0.522f;
|
||||
@@ -79,15 +138,16 @@ public static class RoleSettingMenuPatches
|
||||
maskBg.localScale = new Vector3(6.6811f, 4.1563f, 0.5598f);
|
||||
hitbox.localPosition = new Vector3(0.3297f, -.6333f, 4f);
|
||||
hitbox.localScale = new Vector3(1, 1.2f, 1);
|
||||
dividerImage.gameObject.SetActive(false);
|
||||
|
||||
var num3 = 0;
|
||||
var num4 = 0;
|
||||
|
||||
var roleGroups = GameSettingMenuPatches.SelectedMod?.InternalRoles.Values.OfType<ICustomRole>()
|
||||
.ToLookup(x => x.RoleOptionsGroup);
|
||||
|
||||
if (roleGroups is null)
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// sort the groups by priority
|
||||
@@ -197,11 +257,11 @@ public static class RoleSettingMenuPatches
|
||||
continue;
|
||||
}
|
||||
|
||||
var option = CreateQuotaOption(__instance, roleBehaviour, num3);
|
||||
var option = CreateQuotaOption(__instance, roleBehaviour, num4);
|
||||
if (option is not null)
|
||||
{
|
||||
RoleOptionSettings.Add(option);
|
||||
num3++;
|
||||
num4++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -532,6 +592,19 @@ public static class RoleSettingMenuPatches
|
||||
roleOptionSetting.titleText.color = customRole.OptionsMenuColor.FindAlternateColor();
|
||||
roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
||||
|
||||
if (customRole.Configuration.Icon != null)
|
||||
{
|
||||
var roleIcon = new GameObject("RoleIcon");
|
||||
roleIcon.transform.parent = roleOptionSetting.transform;
|
||||
roleIcon.transform.localScale = new(.25f, .25f, 1);
|
||||
roleIcon.layer = LayerMask.NameToLayer("UI");
|
||||
roleIcon.transform.localPosition = new Vector3(-1.3f, -0.3f, -2f);
|
||||
var rend = roleIcon.AddComponent<SpriteRenderer>();
|
||||
rend.sprite = customRole.Configuration.Icon.LoadAsset();
|
||||
|
||||
rend.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
}
|
||||
|
||||
if (GameSettingMenuPatches.SelectedMod is null ||
|
||||
GameSettingMenuPatches.SelectedMod.InternalOptionGroups
|
||||
.Exists(x => x.GroupVisible() && x.OptionableType == role.GetType() && x.Options.Any(y => y.Visible())))
|
||||
@@ -551,18 +624,6 @@ public static class RoleSettingMenuPatches
|
||||
passiveButton.interactableHoveredColor = Color.white;
|
||||
|
||||
passiveButton.OnClick.AddListener((UnityAction)(() => { ChangeTab(role, __instance); }));
|
||||
|
||||
if (customRole.Configuration.Icon != null)
|
||||
{
|
||||
var roleIcon = new GameObject("RoleIcon");
|
||||
roleIcon.transform.parent = roleOptionSetting.transform;
|
||||
roleIcon.transform.localScale = new(.25f, .25f, 1);
|
||||
roleIcon.layer = LayerMask.NameToLayer("UI");
|
||||
roleIcon.transform.localPosition = new Vector3(-1.3f, -0.3f, -2f);
|
||||
var rend = roleIcon.AddComponent<SpriteRenderer>();
|
||||
rend.sprite = customRole.Configuration.Icon.LoadAsset();
|
||||
rend.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
}
|
||||
}
|
||||
|
||||
if (customRole.Configuration is { MaxRoleCount: 0 })
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
@@ -67,15 +68,53 @@ internal static class PlayerControlPatches
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(PlayerControl.RpcMurderPlayer))]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
// Note: This method is partially inlined in 2025.5.20 but we already use custom murder RPCs.
|
||||
public static void PlayerControlMurderPrefix(PlayerControl __instance, PlayerControl target, ref bool didSucceed)
|
||||
[HarmonyPatch(nameof(PlayerControl.CheckMurder))]
|
||||
public static void PlayerControlCheckMurderPrefix(PlayerControl __instance, PlayerControl target, ref bool __runOriginal)
|
||||
{
|
||||
__runOriginal = false;
|
||||
|
||||
__instance.logger.Debug($"Checking if {__instance.PlayerId} murdered {(target == null ? "null player" : target.PlayerId.ToString(NumberFormatInfo.InvariantInfo))}");
|
||||
|
||||
__instance.isKilling = false;
|
||||
if (AmongUsClient.Instance.IsGameOver || !AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!target || __instance.Data.IsDead || !__instance.Data.Role.IsImpostor || __instance.Data.Disconnected)
|
||||
{
|
||||
int num = target ? target!.PlayerId : -1;
|
||||
__instance.logger.Warning($"Bad kill from {__instance.PlayerId} to {num}");
|
||||
__instance.RpcMurderPlayer(target, false);
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkedPlayerInfo data = target!.Data;
|
||||
if (data == null || data.IsDead || target.inVent || target.MyPhysics.Animations.IsPlayingEnterVentAnimation() ||
|
||||
target.MyPhysics.Animations.IsPlayingAnyLadderAnimation() || target.inMovingPlat)
|
||||
{
|
||||
__instance.logger.Warning("Invalid target data for kill");
|
||||
__instance.RpcMurderPlayer(target, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (MeetingHud.Instance)
|
||||
{
|
||||
__instance.logger.Warning("Tried to kill while a meeting was starting");
|
||||
__instance.RpcMurderPlayer(target, false);
|
||||
return;
|
||||
}
|
||||
|
||||
var beforeMurderEvent = new BeforeMurderEvent(__instance, target);
|
||||
MiraEventManager.InvokeEvent(beforeMurderEvent);
|
||||
|
||||
didSucceed = beforeMurderEvent.IsCancelled;
|
||||
if (beforeMurderEvent.IsCancelled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
__instance.isKilling = true;
|
||||
__instance.RpcMurderPlayer(target, true);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
|
||||
@@ -33,8 +33,8 @@ internal static class EjectionPatches
|
||||
__instance.completeString = role.GetCustomEjectionMessage(__instance.initData.networkedPlayer);
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ExileController), nameof(ExileController.WrapUp))]
|
||||
public static class WrapUpPatch
|
||||
[HarmonyPatch(typeof(ExileController), nameof(ExileController.ReEnableGameplay))]
|
||||
public static class ReEnableGameplayPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
[HarmonyPatch(typeof(HowToPlayScene), nameof(HowToPlayScene.OpenRolesSelectionMenu))]
|
||||
internal static class HowToPlayPatch
|
||||
{
|
||||
// yes i patched the entire method
|
||||
private static void Prefix(HowToPlayScene __instance)
|
||||
{
|
||||
__instance.sceneIndex = 0;
|
||||
__instance.category = HowToPlayScene.HowToPlayCategory.RolesSelection;
|
||||
__instance.startPage.SetActive(false);
|
||||
if (__instance.roleButtonsParent.childCount == 0)
|
||||
{
|
||||
using (IEnumerator<RoleBehaviour> enumerator = RoleManager.Instance.AllRoles.ToArray().Where(x => !x.IsCustomRole()).GetEnumerator())
|
||||
{
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
RoleBehaviour role = enumerator.Current;
|
||||
if (!role.IsSimpleRole && role.Role != RoleTypes.CrewmateGhost && role.Role != RoleTypes.ImpostorGhost)
|
||||
{
|
||||
HowToPlayRoleButton component = Object.Instantiate(__instance.roleButtonPrefab, __instance.roleButtonsParent).GetComponent<HowToPlayRoleButton>();
|
||||
Sprite roleIcon = __instance.rolesScenes.ToArray().First(r => r.role == role.Role).roleIcon;
|
||||
component.SetRoleInfo(role, roleIcon);
|
||||
component.SetButtonAction((Il2CppSystem.Action)(() =>
|
||||
{
|
||||
__instance.OpenRolePage(role.Role);
|
||||
}));
|
||||
__instance.controllerSelectables.Add(component.GetComponent<PassiveButton>());
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (UiElement uiElement in __instance.controllerSelectables)
|
||||
{
|
||||
uiElement.ReceiveMouseOut();
|
||||
}
|
||||
ControllerManager.Instance.NewScene(__instance.name, __instance.closeButton, __instance.defaultButtonSelected, __instance.controllerSelectables, false);
|
||||
}
|
||||
__instance.DisableAllScenes();
|
||||
__instance.roleSelectionScene.SetActive(true);
|
||||
ControllerManager.Instance.SetDefaultSelection(__instance.defaultButtonSelected, null);
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,11 @@ public static class KillButtonPatches
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerControl.LocalPlayer.RpcCustomMurder(__instance.currentTarget);
|
||||
__instance.SetTarget(null);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public static class RoleManagerPatches
|
||||
data.Role.Deinitialize(targetPlayer);
|
||||
Object.Destroy(data.Role.gameObject);
|
||||
}
|
||||
var roleBehaviour = Object.Instantiate<RoleBehaviour>(__instance.AllRoles.First(r => r.Role == roleType), data.gameObject.transform);
|
||||
var roleBehaviour = Object.Instantiate<RoleBehaviour>(__instance.AllRoles.ToArray().First(r => r.Role == roleType), data.gameObject.transform);
|
||||
roleBehaviour.Initialize(targetPlayer);
|
||||
targetPlayer.Data.Role = roleBehaviour;
|
||||
targetPlayer.Data.RoleType = roleType;
|
||||
|
||||
@@ -9,17 +9,17 @@ namespace MiraAPI.Patches.Roles;
|
||||
/// <summary>
|
||||
/// Patches to return the correct role counts.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(RoleOptionsCollectionV09))]
|
||||
[HarmonyPatch(typeof(RoleOptionsCollectionV10))]
|
||||
public static class RoleOptionsCollectionPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// This patch fixes GetNumPerGame being inlined (2025.5.20) in the original code.
|
||||
/// This patch fixes GetNumPerGame being inlined (2025.9.9) in the original code.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV09.AnyRolesEnabled))]
|
||||
public static bool AnyRolesEnabledPrefix(RoleOptionsCollectionV09 __instance, ref bool __result)
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV10.AnyRolesEnabled))]
|
||||
public static bool AnyRolesEnabledPrefix(RoleOptionsCollectionV10 __instance, ref bool __result)
|
||||
{
|
||||
foreach (KeyValuePair<RoleTypes, RoleDataV09> keyValuePair in __instance.roles)
|
||||
foreach (KeyValuePair<RoleTypes, RoleDataV10> keyValuePair in __instance.roles)
|
||||
{
|
||||
if (__instance.GetNumPerGame(keyValuePair.Key) > 0)
|
||||
{
|
||||
@@ -34,7 +34,7 @@ public static class RoleOptionsCollectionPatch
|
||||
/// </summary>
|
||||
/// <returns>Return false to skip original method, true to not.</returns>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV09.GetChancePerGame))]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV10.GetChancePerGame))]
|
||||
public static bool GetChancePrefix(RoleTypes role, ref int __result)
|
||||
{
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(role, out var customRole) || customRole == null)
|
||||
@@ -64,7 +64,7 @@ public static class RoleOptionsCollectionPatch
|
||||
/// </summary>
|
||||
/// <returns>Return false to skip original method, true to not.</returns>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV09.GetNumPerGame))]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV10.GetNumPerGame))]
|
||||
public static bool GetNumPrefix(RoleTypes role, ref int __result)
|
||||
{
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(role, out var customRole) || customRole == null)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -8,20 +10,29 @@ namespace MiraAPI.Patches;
|
||||
[HarmonyPatch(typeof(ServerDropdown), nameof(ServerDropdown.FillServerOptions))]
|
||||
public static class ServerDropdownPatch
|
||||
{
|
||||
public static bool RegionEquals(this IRegionInfo region, IRegionInfo other)
|
||||
{
|
||||
return region.Name == other.Name &&
|
||||
region.TranslateName == other.TranslateName &&
|
||||
region.PingServer == other.PingServer &&
|
||||
region.TargetServer == other.TargetServer &&
|
||||
region.Servers.All(s=>other.Servers.Any(x=>x.Equals(s)));
|
||||
}
|
||||
|
||||
public static bool Prefix(ServerDropdown __instance)
|
||||
{
|
||||
var num = 0;
|
||||
__instance.background.size = new Vector2(8.4f, 4.8f);
|
||||
|
||||
foreach (var regionInfo in DestroyableSingleton<ServerManager>.Instance.AvailableRegions)
|
||||
foreach (var regionInfo in ServerManager.Instance.AvailableRegions)
|
||||
{
|
||||
var findingGame = SceneManager.GetActiveScene().name is "FindAGame";
|
||||
|
||||
if (DestroyableSingleton<ServerManager>.Instance.CurrentRegion.Equals(regionInfo))
|
||||
if (ServerManager.Instance.CurrentRegion.RegionEquals(regionInfo))
|
||||
{
|
||||
__instance.defaultButtonSelected = __instance.firstOption;
|
||||
__instance.firstOption.ChangeButtonText(
|
||||
DestroyableSingleton<TranslationController>.Instance.GetStringWithDefault(
|
||||
TranslationController.Instance.GetStringWithDefault(
|
||||
regionInfo.TranslateName,
|
||||
regionInfo.Name));
|
||||
}
|
||||
@@ -34,11 +45,11 @@ public static class ServerDropdownPatch
|
||||
{
|
||||
x += 2;
|
||||
}
|
||||
var y = -0.55f * (num / 2);
|
||||
var y = -0.55f * (num / 2f);
|
||||
serverListButton.transform.localPosition = new Vector3(x, __instance.y_posButton + y, -1f);
|
||||
serverListButton.transform.localScale = Vector3.one;
|
||||
serverListButton.Text.text =
|
||||
DestroyableSingleton<TranslationController>.Instance.GetStringWithDefault(
|
||||
TranslationController.Instance.GetStringWithDefault(
|
||||
regionInfo.TranslateName,
|
||||
regionInfo.Name);
|
||||
serverListButton.Text.ForceMeshUpdate();
|
||||
@@ -47,9 +58,9 @@ public static class ServerDropdownPatch
|
||||
__instance.controllerSelectable.Add(serverListButton.Button);
|
||||
__instance.background.transform.localPosition = new Vector3(
|
||||
findingGame ? 2f : 0f,
|
||||
__instance.initialYPos + (-0.3f * (num / 2)),
|
||||
__instance.initialYPos + -0.3f * (num / 2f),
|
||||
0f);
|
||||
__instance.background.size = new Vector2(__instance.background.size.x, 1.2f + (0.6f * (num / 2)));
|
||||
__instance.background.size = new Vector2(__instance.background.size.x, 1.2f + 0.6f * (num / 2f));
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using HarmonyLib;
|
||||
using Hazel;
|
||||
using Il2CppSystem.Text;
|
||||
|
||||
namespace MiraAPI.Patches.Stubs;
|
||||
@@ -229,4 +230,76 @@ public static class RoleBehaviourStubs
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.UseSecondaryAbility.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.UseSecondaryAbility))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void UseSecondaryAbility(RoleBehaviour instance)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.OnRoleSet.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.OnRoleSet))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void OnRoleSet(RoleBehaviour instance)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.InitializeMeetingAbilityButton.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.InitializeMeetingAbilityButton))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void InitializeMeetingAbilityButton(RoleBehaviour instance)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.FindClosestBody.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.FindClosestBody))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static DeadBody FindClosestBody(RoleBehaviour instance)
|
||||
{
|
||||
return null!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.HandleRoleRpc.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.HandleRoleRpc))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void HandleRoleRpc(RoleBehaviour instance, byte callId, MessageReader reader)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.KillAnimSpecialSetup.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.KillAnimSpecialSetup))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void KillAnimSpecialSetup(RoleBehaviour instance, DeadBody deadBody, PlayerControl killer, PlayerControl victim)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
@@ -32,6 +32,12 @@ public record struct CustomRoleConfiguration
|
||||
TasksCountForProgress = role.Team is ModdedRoleTeams.Crewmate;
|
||||
HideSettings = roleBehaviour?.IsDead == true;
|
||||
ShowInFreeplay = roleBehaviour?.IsDead == false;
|
||||
FreeplayFolder = role.Team switch
|
||||
{
|
||||
ModdedRoleTeams.Crewmate => TranslationController.Instance.GetString(StringNames.Crewmate),
|
||||
ModdedRoleTeams.Impostor => TranslationController.Instance.GetString(StringNames.Impostor),
|
||||
_ => "Neutral",
|
||||
};
|
||||
IntroSound = role.Team is ModdedRoleTeams.Crewmate
|
||||
? CustomRoleManager.CrewmateIntroSound
|
||||
: CustomRoleManager.ImpostorIntroSound;
|
||||
@@ -112,6 +118,11 @@ public record struct CustomRoleConfiguration
|
||||
/// </summary>
|
||||
public bool ShowInFreeplay { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a freeplay folder this role belongs to. Defaults to team folder.
|
||||
/// </summary>
|
||||
public string FreeplayFolder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the outline color for the KillButton if <see cref="UseVanillaKillButton"/> is true.
|
||||
/// </summary>
|
||||
|
||||
@@ -35,6 +35,11 @@ public static class CustomRoleManager
|
||||
public static readonly LoadableAsset<AudioClip> ImpostorIntroSound =
|
||||
CustomRoleUtils.GetIntroSound(RoleTypes.Impostor)!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of all roles from vanilla RoleManager.
|
||||
/// </summary>
|
||||
public static RoleBehaviour[] AllRoles => RoleManager.Instance.AllRoles.ToArray();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of custom roles as RoleBehaviour objects.
|
||||
/// </summary>
|
||||
@@ -57,7 +62,10 @@ public static class CustomRoleManager
|
||||
|
||||
internal static void RegisterInRoleManager()
|
||||
{
|
||||
RoleManager.Instance.AllRoles = RoleManager.Instance.AllRoles.Concat(CustomRoles.Values).ToArray();
|
||||
foreach (var role in CustomRoles.Values)
|
||||
{
|
||||
RoleManager.Instance.AllRoles.Add(role);
|
||||
}
|
||||
|
||||
foreach (var role in CustomRoles.Values.Where(x => x.IsDead))
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Roles;
|
||||
@@ -56,7 +55,7 @@ public static class CustomRoleUtils
|
||||
/// <returns>The intro sound.</returns>
|
||||
public static LoadableAsset<AudioClip>? GetIntroSound(RoleTypes roleType)
|
||||
{
|
||||
var role = RoleManager.Instance.AllRoles.FirstOrDefault(role => role.Role == roleType);
|
||||
var role = CustomRoleManager.AllRoles.FirstOrDefault(role => role.Role == roleType);
|
||||
if (role is ICustomRole customRole)
|
||||
{
|
||||
return customRole.Configuration.IntroSound;
|
||||
|
||||
@@ -12,7 +12,7 @@ public static class MiraAssets
|
||||
{
|
||||
var boxTex = SpriteTools.LoadTextureFromResourcePath(
|
||||
"MiraAPI.Resources.RoundedBox.png",
|
||||
System.Reflection.Assembly.GetCallingAssembly());
|
||||
System.Reflection.Assembly.GetExecutingAssembly());
|
||||
var boxSprite = Sprite.Create(
|
||||
boxTex,
|
||||
new Rect(0, 0, boxTex.width, boxTex.height),
|
||||
@@ -105,6 +105,26 @@ public static class MiraAssets
|
||||
/// </summary>
|
||||
public static LoadableResourceAsset KeybindButton { get; } = new("MiraAPI.Resources.KeybindButton.png");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite used for crewmate role files in TaskAdderGame.
|
||||
/// </summary>
|
||||
public static LoadableResourceAsset CrewmateFile { get; } = new("MiraAPI.Resources.CrewmateFile.png");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite used for impostor role files in TaskAdderGame.
|
||||
/// </summary>
|
||||
public static LoadableResourceAsset ImpostorFile { get; } = new("MiraAPI.Resources.ImpostorFile.png");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite used for custom team role files in TaskAdderGame.
|
||||
/// </summary>
|
||||
public static LoadableResourceAsset CustomTeamFile { get; } = new("MiraAPI.Resources.CustomFile.png");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite used for modifier file in TaskAdderGame.
|
||||
/// </summary>
|
||||
public static LoadableResourceAsset ModifierFile { get; } = new("MiraAPI.Resources.ModifierFile.png");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite used for timed modifier file in TaskAdderGame.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using Rewired;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using MethodBase = System.Reflection.MethodBase;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Utilities;
|
||||
@@ -37,6 +39,31 @@ public static class Helpers
|
||||
return keybindIcon;
|
||||
}
|
||||
|
||||
public static MethodBase? GetStateMachineMoveNext<T>(string methodName)
|
||||
{
|
||||
var typeName = typeof(T).FullName;
|
||||
var showRoleStateMachine =
|
||||
typeof(T)
|
||||
.GetNestedTypes()
|
||||
.FirstOrDefault(x=>x.Name.Contains(methodName));
|
||||
|
||||
if (showRoleStateMachine == null)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to find {methodName} state machine for {typeName}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var moveNext = AccessTools.Method(showRoleStateMachine, "MoveNext");
|
||||
if (moveNext == null)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to find MoveNext method for {typeName}.{methodName}");
|
||||
return null;
|
||||
}
|
||||
|
||||
Logger<MiraApiPlugin>.Info($"Found {methodName}.MoveNext");
|
||||
return moveNext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a draggable scroller. Add items into the scroller.Inner transform. This does not automatically position children.
|
||||
/// </summary>
|
||||
@@ -495,4 +522,18 @@ public static class Helpers
|
||||
(Il2CppSystem.Object[])[value.ToString(formatString, CultureInfo.InvariantCulture)]),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the string of a role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role to find.</param>
|
||||
/// <returns>The role name.</returns>
|
||||
public static string GetRoleName(this RoleBehaviour role)
|
||||
{
|
||||
if (role is ICustomRole custom)
|
||||
{
|
||||
return custom.RoleName;
|
||||
}
|
||||
return role.NiceName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
|
||||
namespace MiraAPI.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// A wrapper for state machine objects to access their parent instance and state.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the parent class that owns the state machine.</typeparam>
|
||||
public class StateMachineWrapper<T> where T : Il2CppObjectBase
|
||||
{
|
||||
private readonly Il2CppObjectBase _stateMachine;
|
||||
private readonly PropertyInfo _thisProperty;
|
||||
private readonly PropertyInfo _stateProperty;
|
||||
|
||||
private T? _parentInstance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the parent class that owns the state machine.
|
||||
/// </summary>
|
||||
public T Instance => _parentInstance ??= (T)_thisProperty.GetValue(_stateMachine)!;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StateMachineWrapper{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="stateMachine">The state machine instance to wrap.</param>
|
||||
public StateMachineWrapper(Il2CppObjectBase stateMachine)
|
||||
{
|
||||
_stateMachine = stateMachine;
|
||||
|
||||
var type = _stateMachine.GetType();
|
||||
_thisProperty = AccessTools.Property(type, "__4__this");
|
||||
_stateProperty = AccessTools.Property(type, "__1__state");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current state of the state machine.
|
||||
/// </summary>
|
||||
/// <returns>The current state as an integer.</returns>
|
||||
public int GetState() => (int)_stateProperty.GetValue(_stateMachine)!;
|
||||
}
|
||||
Reference in new issue
Block a user