mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 11:39:45 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0aa4a82d48 |
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.10.14" PrivateAssets="all" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2025.4.15" 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.3.3</VersionPrefix>
|
||||
<VersionPrefix>0.2.1</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Example.GameOver;
|
||||
using MiraAPI.Example.GameOver;
|
||||
using MiraAPI.GameEnd;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
@@ -23,7 +22,6 @@ public class NeutralKillerRole : ImpostorRole, ICustomRole
|
||||
|
||||
public RoleOptionsGroup RoleOptionsGroup { get; } = new("Outcast", Color.gray);
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public TeamIntroConfiguration? IntroConfiguration { get; } = new(
|
||||
Color.gray,
|
||||
"OUTCAST",
|
||||
|
||||
@@ -34,7 +34,7 @@ public static class MiraEventManager
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Error($"Error invoking event handler for {typeof(T).Name}: {ex.ToString()}");
|
||||
Logger<MiraApiPlugin>.Error($"Error invoking event handler for {typeof(T).Name}: {ex.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public static class MiraEventManager
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Error($"Error invoking event handler for {type.Name}: {ex.ToString()}");
|
||||
Logger<MiraApiPlugin>.Error($"Error invoking event handler for {type.Name}: {ex.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ public static class GameOverManager
|
||||
|
||||
if (gameOverType.IsAbstract)
|
||||
{
|
||||
Error("The type must not be abstract.");
|
||||
Logger<MiraApiPlugin>.Error("The type must not be abstract.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gameOverType.GetConstructor(Type.EmptyTypes) == null)
|
||||
{
|
||||
Error("The type must have a parameterless constructor.");
|
||||
Logger<MiraApiPlugin>.Error("The type must have a parameterless constructor.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public static class CustomGameModeManager
|
||||
return;
|
||||
}
|
||||
|
||||
Error($"No gamemode with id {id} found!");
|
||||
Logger<MiraApiPlugin>.Error($"No gamemode with id {id} found!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -48,7 +48,7 @@ public static class CustomGameModeManager
|
||||
{
|
||||
if (!typeof(CustomGameMode).IsAssignableFrom(gameModeType))
|
||||
{
|
||||
Warning($"{gameModeType.Name} does not inherit CustomGameMode!");
|
||||
Logger<MiraApiPlugin>.Warning($"{gameModeType.Name} does not inherit CustomGameMode!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,13 +56,13 @@ public static class CustomGameModeManager
|
||||
|
||||
if (modeObj is not CustomGameMode gameMode)
|
||||
{
|
||||
Error($"Failed to create instance of {gameModeType.Name}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create instance of {gameModeType.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameModes.Any(x => x.Key == gameMode.Id))
|
||||
{
|
||||
Error($"ID for gamemode {gameMode.Name} already exists!");
|
||||
Logger<MiraApiPlugin>.Error($"ID for gamemode {gameMode.Name} already exists!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public static class ModdedOptionsManager
|
||||
|
||||
if (TypeToGroup.ContainsKey(type))
|
||||
{
|
||||
Error($"Group {type.Name} already exists.");
|
||||
Logger<MiraApiPlugin>.Error($"Group {type.Name} already exists.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -60,13 +60,13 @@ public static class ModdedOptionsManager
|
||||
{
|
||||
if (!TypeToGroup.TryGetValue(type, out var group))
|
||||
{
|
||||
Error($"Failed to get group for {type.Name}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to get group for {type.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (property.GetValue(group) is not IModdedOption option)
|
||||
{
|
||||
Error($"Failed to get option for {property.Name}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to get option for {property.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,13 +81,13 @@ public static class ModdedOptionsManager
|
||||
{
|
||||
if (OptionAttributes.ContainsKey(property))
|
||||
{
|
||||
Error($"Property {property.Name} already has an attribute registered.");
|
||||
Logger<MiraApiPlugin>.Error($"Property {property.Name} already has an attribute registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TypeToGroup.TryGetValue(type, out var group))
|
||||
{
|
||||
Error($"Failed to get group for {type.Name}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to get group for {type.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public static class ModdedOptionsManager
|
||||
|
||||
if (option == null)
|
||||
{
|
||||
Error($"Failed to get option for {property.Name}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to get option for {property.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
{
|
||||
if (ConfigDefinition is null)
|
||||
{
|
||||
Error($"Attempted to save {Title} to preset, but ConfigDefinition is null.");
|
||||
Logger<MiraApiPlugin>.Error($"Attempted to save {Title} to preset, but ConfigDefinition is null.");
|
||||
return;
|
||||
}
|
||||
Bind(presetConfig);
|
||||
@@ -147,7 +147,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
}
|
||||
else
|
||||
{
|
||||
Error($"Attempted to load {Title} from preset, but ConfigDefinition is not found in preset.");
|
||||
Logger<MiraApiPlugin>.Error($"Attempted to load {Title} from preset, but ConfigDefinition is not found in preset.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ public abstract class CustomActionButton
|
||||
return;
|
||||
}
|
||||
|
||||
Location = location;
|
||||
this.Location = location;
|
||||
|
||||
if (!moveButton)
|
||||
{
|
||||
|
||||
@@ -26,11 +26,11 @@ public static class KeybindManager
|
||||
try
|
||||
{
|
||||
var instance = KeybindUtils.RewiredInputManager!;
|
||||
foreach (var keybind in Keybinds)
|
||||
foreach (var keybind in KeybindManager.Keybinds)
|
||||
{
|
||||
if (instance.userData.actions.ToArray().Any(x => x.name == keybind.Id))
|
||||
{
|
||||
Warning($"Keybind of id {keybind.Id} already exists. Skipping it");
|
||||
Logger<MiraApiPlugin>.Warning($"Keybind of id {keybind.Id} already exists. Skipping it");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public static class KeybindManager
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Error while registering keybinds in Rewired: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Error while registering keybinds in Rewired: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class LocalEnumSettingAttribute(
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override LocalEnumSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
internal 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/>
|
||||
public override LocalNumberSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
internal 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>
|
||||
public abstract ILocalSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase);
|
||||
internal abstract ILocalSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class LocalSliderSettingAttribute(
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override LocalSliderSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
internal 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/>
|
||||
public override LocalToggleSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
internal override LocalToggleSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalToggleSetting(tab, configEntryBase, _name, _description);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public static class LocalSettingsManager
|
||||
|
||||
if (TypeToTab.ContainsKey(type))
|
||||
{
|
||||
Error($"Local settings tab {type.Name} already exists.");
|
||||
Logger<MiraApiPlugin>.Error($"Local settings tab {type.Name} already exists.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,6 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
{
|
||||
CreateLabel(generalLabel, Scroller.Inner, pair.Key, ref contentOffset);
|
||||
contentOrder = 1;
|
||||
contentIndex = 1;
|
||||
}
|
||||
|
||||
foreach (var setting in pair.Value)
|
||||
@@ -246,7 +245,6 @@ 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 modifying tab appearance.
|
||||
/// Struct for modyfing tab apparance.
|
||||
/// Defines how the settings look.
|
||||
/// </summary>
|
||||
public record struct LocalSettingTabAppearance()
|
||||
@@ -24,11 +24,6 @@ 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>
|
||||
@@ -83,7 +78,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,10 +20,7 @@ public abstract class LocalSettingBase<T> : ILocalSetting
|
||||
/// <inheritdoc />
|
||||
public ConfigEntryBase ConfigEntry { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tab of the local setting.
|
||||
/// </summary>
|
||||
public LocalSettingsTab? Tab => LocalSettingsManager.Tabs.FirstOrDefault(x => x.Settings.Contains(this));
|
||||
internal LocalSettingsTab? Tab => LocalSettingsManager.Tabs.FirstOrDefault(x => x.Settings.Contains(this));
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalSettingBase{T}"/> class.
|
||||
@@ -56,7 +53,7 @@ public abstract class LocalSettingBase<T> : ILocalSetting
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the config entry, cast to the setting type.
|
||||
/// Gets the value of the config entry, casted to the setting type.
|
||||
/// </summary>
|
||||
/// <returns>The value.</returns>
|
||||
public virtual T GetValue()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
global using static Reactor.Utilities.Logger<MiraAPI.MiraApiPlugin>;
|
||||
using BepInEx;
|
||||
using BepInEx;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.PluginLoading;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.LocalSettings.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
|
||||
namespace MiraAPI;
|
||||
@@ -18,7 +19,6 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
{
|
||||
TabButtonHoverColor = MiraApiPlugin.MiraColor,
|
||||
TabIcon = MiraAssets.SettingsIcon,
|
||||
HideIconOnHover = false,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -27,14 +27,26 @@ 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);
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
_player = GetComponent<PlayerControl>();
|
||||
if (_player == null)
|
||||
{
|
||||
Error("ModifierComponent could not find PlayerControl on the same GameObject.");
|
||||
Logger<MiraApiPlugin>.Error("ModifierComponent could not find PlayerControl on the same GameObject.");
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Error while deactivating modifier {modifier.ModifierName}: {e.ToString()}");
|
||||
Logger<MiraApiPlugin>.Error($"Error while deactivating modifier {modifier.ModifierName}: {e.ToString()}");
|
||||
}
|
||||
|
||||
Modifiers.Remove(modifier);
|
||||
@@ -95,7 +95,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Error while activating modifier {modifier.ModifierName}: {e.ToString()}");
|
||||
Logger<MiraApiPlugin>.Error($"Error while activating modifier {modifier.ModifierName}: {e.ToString()}");
|
||||
}
|
||||
|
||||
if (modifier is TimedModifier { AutoStart: true } timer)
|
||||
@@ -122,7 +122,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Error while (fixed) updating modifier {modifier.ModifierName}: {e.ToString()}");
|
||||
Logger<MiraApiPlugin>.Error($"Error while (fixed) updating modifier {modifier.ModifierName}: {e.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Error while updating modifier {modifier.ModifierName}: {e.ToString()}");
|
||||
Logger<MiraApiPlugin>.Error($"Error while updating modifier {modifier.ModifierName}: {e.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,7 +336,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
var modifier = modifiers.FirstOrDefault();
|
||||
if (modifier is null)
|
||||
{
|
||||
Error($"Cannot remove modifier {type.Name} because it is not active.");
|
||||
Logger<MiraApiPlugin>.Error($"Cannot remove modifier {type.Name} because it is not active.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
if (!ActiveModifiers.Contains(modifier))
|
||||
{
|
||||
Error($"Cannot remove modifier {modifier.ModifierName} because it is not active on this player.");
|
||||
Logger<MiraApiPlugin>.Error($"Cannot remove modifier {modifier.ModifierName} because it is not active on this player.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
var modifier = GetModifier(uniqueId);
|
||||
if (modifier == null)
|
||||
{
|
||||
Error($"Cannot remove modifier with unique id {uniqueId} because it is not active.");
|
||||
Logger<MiraApiPlugin>.Error($"Cannot remove modifier with unique id {uniqueId} because it is not active.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -412,19 +412,19 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
// TODO: Make a proper synchronization system.
|
||||
if (LobbyBehaviour.Instance)
|
||||
{
|
||||
Warning($"Modifiers added in the lobby won't sync to new players!");
|
||||
Logger<MiraApiPlugin>.Warning($"Modifiers added in the lobby won't sync to new players!");
|
||||
}
|
||||
|
||||
var id = modifier.TypeId;
|
||||
if (modifier.Unique && ActiveModifiers.Find(x => x.TypeId == id) != null)
|
||||
{
|
||||
Error($"Player already has modifier with id {id}!");
|
||||
Logger<MiraApiPlugin>.Error($"Player already has modifier with id {id}!");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ActiveModifiers.Contains(modifier))
|
||||
{
|
||||
Error($"Player already has this modifier!");
|
||||
Logger<MiraApiPlugin>.Error($"Player already has this modifier!");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ public static class ModifierExtensions
|
||||
var modifier = target.GetModifier(typeId, predicate);
|
||||
if (modifier is null)
|
||||
{
|
||||
Error($"Player {target.PlayerId} does not have modifier with type ID {typeId}.");
|
||||
Logger<MiraApiPlugin>.Error($"Player {target.PlayerId} does not have modifier with type ID {typeId}.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public static class ModifierManager
|
||||
|
||||
if (modifierType.GetConstructor(Type.EmptyTypes) == null)
|
||||
{
|
||||
Error($"Game Modifier {modifierType.FullName} does not have a parameterless constructor!");
|
||||
Logger<MiraApiPlugin>.Error($"Game Modifier {modifierType.FullName} does not have a parameterless constructor!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public static class ModifierManager
|
||||
var validPlayers = plrs.Where(x => IsGameModifierValid(x, modifier, modifier.TypeId)).ToList();
|
||||
if (validPlayers.Count == 0)
|
||||
{
|
||||
Warning($"No valid players for modifier {modifier.ModifierName}");
|
||||
Logger<MiraApiPlugin>.Warning($"No valid players for modifier {modifier.ModifierName}");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public static class ModifierManager
|
||||
|
||||
if (candidates.Count == 0)
|
||||
{
|
||||
Warning(
|
||||
Logger<MiraApiPlugin>.Warning(
|
||||
$"No available players for modifier {modifier.ModifierName} at assignment {i + 1}");
|
||||
break;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public static class ModifierManager
|
||||
var plr = candidates.Random();
|
||||
if (plr == null)
|
||||
{
|
||||
Warning($"Valid player for modifier {modifier.ModifierName} disappeared");
|
||||
Logger<MiraApiPlugin>.Warning($"Valid player for modifier {modifier.ModifierName} disappeared");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public abstract class TimedModifier : BaseModifier
|
||||
{
|
||||
if (TimerActive)
|
||||
{
|
||||
Error("Can't start a timer that has already been started.");
|
||||
Logger<MiraApiPlugin>.Error("Can't start a timer that has already been started.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class CustomGameOverRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<
|
||||
{
|
||||
if (!gameOver.VerifyCondition(innerNetObject, [.. data.Winners]))
|
||||
{
|
||||
Info($"Game over condition not met for {gameOver.GetType().Name}");
|
||||
Logger<MiraApiPlugin>.Info($"Game over condition not met for {gameOver.GetType().Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class CustomGameOverRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<
|
||||
else
|
||||
{
|
||||
CustomGameOver.Instance = null;
|
||||
Error($"Unknown game over reason: {data.Reason}");
|
||||
Logger<MiraApiPlugin>.Error($"Unknown game over reason: {data.Reason}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using AmongUs.Data;
|
||||
using AmongUs.GameOptions;
|
||||
@@ -10,10 +8,8 @@ using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Networking;
|
||||
|
||||
@@ -173,14 +169,7 @@ public static class CustomMurderRpc
|
||||
|
||||
if (showKillAnim)
|
||||
{
|
||||
try
|
||||
{
|
||||
HudManager.Instance.KillOverlay.ShowMiraKillAnimation(source.Data, data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Error with kill animation: {e.ToString()}");
|
||||
}
|
||||
HudManager.Instance.KillOverlay.ShowKillAnimation(source.Data, data);
|
||||
}
|
||||
|
||||
target.cosmetics.SetNameMask(false);
|
||||
@@ -213,7 +202,7 @@ public static class CustomMurderRpc
|
||||
bool teleportMurderer = true)
|
||||
{
|
||||
var cam = Camera.main?.GetComponent<FollowerCamera>();
|
||||
var isParticipant = source.AmOwner || target.AmOwner;
|
||||
var isParticipant = PlayerControl.LocalPlayer == source || PlayerControl.LocalPlayer == target;
|
||||
var sourcePhys = source.MyPhysics;
|
||||
|
||||
if (teleportMurderer)
|
||||
@@ -233,7 +222,7 @@ public static class CustomMurderRpc
|
||||
|
||||
if (createDeadBody)
|
||||
{
|
||||
deadBody = Object.Instantiate(GameManager.Instance.GetDeadBody(source.Data.Role));
|
||||
deadBody = Object.Instantiate(GameManager.Instance.DeadBodyPrefab);
|
||||
deadBody.enabled = false;
|
||||
deadBody.ParentId = target.PlayerId;
|
||||
deadBody.bodyRenderers.ToList().ForEach(target.SetPlayerMaterialColors);
|
||||
@@ -244,13 +233,6 @@ public static class CustomMurderRpc
|
||||
deadBody.transform.position = vector;
|
||||
}
|
||||
|
||||
source.Data.Role.KillAnimSpecialSetup(deadBody, source, target);
|
||||
target.Data.Role.KillAnimSpecialSetup(deadBody, source, target);
|
||||
|
||||
// no idea if this causes bugs, but innersloth is brain-dead
|
||||
// I HATE INNERSCUFF I HATE INNERSCUFF I HATE INNERSCUFF I HATE INNERSCUFF I HATE INNERSCUFF I HATE INNERSCUFF
|
||||
PlayerControl.LocalPlayer.Data.Role.KillAnimSpecialSetup(deadBody, source, target);
|
||||
|
||||
if (isParticipant)
|
||||
{
|
||||
if (cam != null)
|
||||
@@ -298,68 +280,4 @@ public static class CustomMurderRpc
|
||||
PlayerControl.LocalPlayer.isKilling = false;
|
||||
source.isKilling = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reimplementation of vanilla's kill animation screen.
|
||||
/// </summary>
|
||||
/// <param name="killOverlay">The kill overlay from the Hud Manager.</param>
|
||||
/// <param name="killer">The murderer's network information.</param>
|
||||
/// <param name="victim">The murdered player's network information.</param>
|
||||
public static void ShowMiraKillAnimation(this KillOverlay killOverlay, NetworkedPlayerInfo killer, NetworkedPlayerInfo victim)
|
||||
{
|
||||
List<OverlayKillAnimation> self = killOverlay.KillAnims.ToList();
|
||||
OverlayKillAnimation killAnimation;
|
||||
if (killer.Object)
|
||||
{
|
||||
OverlayKillAnimation[] killAnimations = killer.Object.MyPhysics.Animations.GetKillAnimations();
|
||||
if (GameOptionsManager.Instance.CurrentGameOptions.GameMode == AmongUs.GameOptions.GameModes.HideNSeek && AprilFoolsMode.ShouldHorseAround())
|
||||
{
|
||||
self = killOverlay.HorseWrangleAnims.ToList();
|
||||
}
|
||||
else if (killAnimations.Length != 0)
|
||||
{
|
||||
self = killAnimations.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
SkinViewData skin = ShipStatus.Instance.CosmeticsCache.GetSkin(killer.Object.CurrentOutfit.SkinId);
|
||||
if (skin && skin.CustomKillAnimID > 0)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(skin.HatID_KillAnim) && skin.HatID_KillAnim != killer.Object.CurrentOutfit.HatId)
|
||||
{
|
||||
if (killer.Role.CustomKillAnimations.Length != 0)
|
||||
{
|
||||
self = killer.Role.CustomKillAnimations.ToList();
|
||||
}
|
||||
killAnimation = self.Random();
|
||||
killOverlay.ShowKillAnimation(killAnimation, killer, victim);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(skin.VisorID_KillAnim) && skin.VisorID_KillAnim != killer.Object.CurrentOutfit.VisorId)
|
||||
{
|
||||
if (killer.Role.CustomKillAnimations.Length != 0)
|
||||
{
|
||||
self = killer.Role.CustomKillAnimations.ToList();
|
||||
}
|
||||
killAnimation = self.Random();
|
||||
killOverlay.ShowKillAnimation(killAnimation, killer, victim);
|
||||
return;
|
||||
}
|
||||
self = new List<OverlayKillAnimation>
|
||||
{
|
||||
killOverlay.CustomKillAnimations[skin.CustomKillAnimID - 1],
|
||||
};
|
||||
killAnimation = self.Random();
|
||||
killOverlay.ShowKillAnimation(killAnimation, killer, victim);
|
||||
return;
|
||||
}
|
||||
else if (killer.Role.CustomKillAnimations.Length != 0)
|
||||
{
|
||||
self = killer.Role.CustomKillAnimations.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
killAnimation = self.Random();
|
||||
killOverlay.ShowKillAnimation(killAnimation, killer, victim);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
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.SetImpostorPopup))]
|
||||
public static class DetectiveNotesMinigamePatch
|
||||
{
|
||||
public static void Prefix(DetectiveNotesMinigame __instance, bool active)
|
||||
{
|
||||
__instance.impostorTypePopup.gameObject.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, __instance.impostorTypePopup, __instance.ImpostorIconControllerSelectables[0], __instance.ImpostorIconControllerSelectables, false);
|
||||
return;
|
||||
}
|
||||
__instance.impostorButton = new List<GameObject>();
|
||||
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;
|
||||
var gameObject = Object.Instantiate(__instance.impostorTypePrefab, __instance.impostorTypeParent);
|
||||
__instance.impostorButton.Add(gameObject);
|
||||
gameObject.GetComponent<DetectiveImpostorType>().Initialize(__instance, role);
|
||||
__instance.ImpostorIconControllerSelectables.Add(gameObject.GetComponent<PassiveButton>());
|
||||
}
|
||||
ControllerManager.Instance.OpenOverlayMenu(__instance.ImpostorOverlay, __instance.impostorTypePopup, __instance.ImpostorIconControllerSelectables[0], __instance.ImpostorIconControllerSelectables, false);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Patches.Events;
|
||||
internal static class EndGamePatches
|
||||
{
|
||||
[HarmonyPatch(typeof(GameManager), nameof(GameManager.RpcEndGame))]
|
||||
public static class GameManagerRpcEndGamePatch
|
||||
public static class GameManagerPatches
|
||||
{
|
||||
public static bool Prefix(GameOverReason endReason)
|
||||
{
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
[HarmonyPatch]
|
||||
[HarmonyPatch(typeof(TutorialManager._RunTutorial_d__3), nameof(TutorialManager._RunTutorial_d__3.MoveNext))]
|
||||
public static class FreeplayRoundStartPatch
|
||||
{
|
||||
public static MethodBase TargetMethod()
|
||||
{
|
||||
return Helpers.GetStateMachineMoveNext<TutorialManager>(nameof(TutorialManager.RunTutorial))!;
|
||||
}
|
||||
|
||||
public static void Postfix(ref bool __result)
|
||||
public static void Postfix(TutorialManager._RunTutorial_d__3 __instance, ref bool __result)
|
||||
{
|
||||
if (!__result)
|
||||
{
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Patch to invoke AfterMurderEvent after a kill animation is performed.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class KillAnimationMurderEventPatch
|
||||
{
|
||||
public static MethodBase TargetMethod()
|
||||
{
|
||||
return Helpers.GetStateMachineMoveNext<KillAnimation>(nameof(KillAnimation.CoPerformKill))!;
|
||||
}
|
||||
|
||||
public static void Postfix(Il2CppObjectBase __instance)
|
||||
{
|
||||
var wrapper = new StateMachineWrapper<KillAnimation>(__instance);
|
||||
if (wrapper.GetState() != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var source = wrapper.GetParameter<PlayerControl>("source");
|
||||
var target = wrapper.GetParameter<PlayerControl>("target");
|
||||
|
||||
var afterMurderEvent = new AfterMurderEvent(source, target, Helpers.GetBodyById(target.PlayerId));
|
||||
MiraEventManager.InvokeEvent(afterMurderEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
/// <summary>
|
||||
/// General patches for the KillAnimation class.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class KillAnimationPatches
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to trigger the <see cref="AfterMurderEvent"/>.
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(KillAnimation._CoPerformKill_d__2), nameof(KillAnimation._CoPerformKill_d__2.MoveNext))]
|
||||
public static void KillAnimPostfix(KillAnimation._CoPerformKill_d__2 __instance)
|
||||
{
|
||||
// Checking if state is -1 to wait for the end of coroutine.
|
||||
if (__instance.__1__state != -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var afterMurderEvent = new AfterMurderEvent(__instance.source, __instance.target, Helpers.GetBodyById(__instance.target.PlayerId));
|
||||
MiraEventManager.InvokeEvent(afterMurderEvent);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public static class ReportBodyEventPatch
|
||||
var source = AmongUsClient.Instance.FindObjectByNetId<PlayerControl>(reportBodyMessage.rpcObjectNetId);
|
||||
if (source == null)
|
||||
{
|
||||
Error("Failed to find source player for RpcReportDeadBodyMessage with NetId: " + reportBodyMessage.rpcObjectNetId);
|
||||
Logger<MiraApiPlugin>.Error("Failed to find source player for RpcReportDeadBodyMessage with NetId: " + reportBodyMessage.rpcObjectNetId);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Freeplay;
|
||||
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
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 Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
@@ -24,8 +21,6 @@ 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)
|
||||
@@ -65,168 +60,46 @@ 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 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 rolesFolder = Object.Instantiate(__instance.RootFolderPrefab, _scroller.Inner);
|
||||
rolesFolder.gameObject.SetActive(false);
|
||||
rolesFolder.FolderName = "Roles";
|
||||
rolesFolder.name = "RolesFolder";
|
||||
|
||||
folders.Clear();
|
||||
folders.Add(crewmateFolder.FolderName, crewmateFolder);
|
||||
folders.Add(impostorFolder.FolderName, impostorFolder);
|
||||
//folders.Add("Neutrals", neutralFolder);
|
||||
folders.Add("Modifiers", modifiersFolder);
|
||||
var modifiersFolder = Object.Instantiate(__instance.RootFolderPrefab, _scroller.Inner);
|
||||
modifiersFolder.gameObject.SetActive(false);
|
||||
modifiersFolder.FolderName = "Modifiers";
|
||||
modifiersFolder.name = "ModifiersFolder";
|
||||
|
||||
int folderIdx = 2;
|
||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins)
|
||||
{
|
||||
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))
|
||||
if (plugin.InternalRoles.Any(x => x.Value is ICustomRole { Configuration.ShowInFreeplay: true }))
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
if (plugin.InternalModifiers.Exists(x => x.ShowInFreeplay))
|
||||
{
|
||||
__instance.CreateFolder(plugin.PluginInfo.Metadata.Name, modifiersFolder)
|
||||
.gameObject.name = plugin.PluginId;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Modifier folder at the end
|
||||
__instance.Root.SubFolders.Insert(folderIdx, modifiersFolder);
|
||||
__instance.Root.SubFolders.Add(rolesFolder);
|
||||
__instance.Root.SubFolders.Add(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,
|
||||
@@ -249,46 +122,40 @@ 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)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder(64);
|
||||
var stringBuilder = new Il2CppSystem.Text.StringBuilder(64);
|
||||
__instance.Hierarchy.Add(taskFolder);
|
||||
foreach (var t in __instance.Hierarchy)
|
||||
for (var i = 0; i < __instance.Hierarchy.Count; i++)
|
||||
{
|
||||
stringBuilder.Append(t.FolderName);
|
||||
stringBuilder.Append('\\');
|
||||
stringBuilder.Append(__instance.Hierarchy.ToArray()[i].FolderName);
|
||||
stringBuilder.Append("\\");
|
||||
}
|
||||
|
||||
__instance.PathText.text = stringBuilder.ToString();
|
||||
var prettyEnabled = LocalSettingsTabSingleton<MiraApiSettings>.Instance.PrettyTaskAdder.Value;
|
||||
if (prettyEnabled)
|
||||
for (var j = 0; j < __instance.ActiveItems.Count; j++)
|
||||
{
|
||||
__instance.PathText.fontSizeMin = 3;
|
||||
__instance.PathText.fontSizeMax = 3;
|
||||
__instance.transform.FindChild("TitleText_TMP")?.gameObject.DestroyImmediate();
|
||||
Object.Destroy(__instance.ActiveItems.ToArray()[j].gameObject);
|
||||
}
|
||||
|
||||
__instance.ActiveItems.ToArray().Do(x => x.gameObject.Destroy());
|
||||
__instance.ActiveItems.Clear();
|
||||
|
||||
float num = 0f;
|
||||
float num2 = 0f;
|
||||
float num3 = 0f;
|
||||
foreach (var t in taskFolder.SubFolders)
|
||||
var num = 0f;
|
||||
var num2 = 0f;
|
||||
var num3 = 0f;
|
||||
for (var k = 0; k < taskFolder.SubFolders.Count; k++)
|
||||
{
|
||||
TaskFolder taskFolder2 = Object.Instantiate(t, __instance.TaskParent);
|
||||
var taskFolder2 = Object.Instantiate(taskFolder.SubFolders.ToArray()[k], __instance.TaskParent);
|
||||
var folderTransform = taskFolder2.transform;
|
||||
|
||||
taskFolder2.gameObject.SetActive(true);
|
||||
taskFolder2.Parent = __instance;
|
||||
taskFolder2.transform.localPosition = new Vector3(num, num2, 0f);
|
||||
taskFolder2.transform.localScale = Vector3.one;
|
||||
num3 = Mathf.Max(num3, taskFolder2.Text.bounds.size.y + 1.1f);
|
||||
|
||||
folderTransform.localPosition = new Vector3(num, num2, 0f);
|
||||
folderTransform.localScale = Vector3.one;
|
||||
num3 = Mathf.Max(num3, taskFolder2.Text.bounds.size.y + 1.3f);
|
||||
num += __instance.folderWidth;
|
||||
if (num > __instance.lineWidth)
|
||||
{
|
||||
@@ -297,204 +164,141 @@ internal static class TaskAdderPatches
|
||||
num3 = 0f;
|
||||
}
|
||||
|
||||
__instance.ActiveItems.Add(taskFolder2.transform);
|
||||
if (taskFolder2 != null && taskFolder2.Button != null)
|
||||
__instance.ActiveItems.Add(folderTransform);
|
||||
if (!taskFolder2 || !taskFolder2.Button)
|
||||
{
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskFolder2.Button);
|
||||
continue;
|
||||
}
|
||||
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskFolder2.Button);
|
||||
if (!string.IsNullOrEmpty(__instance.restorePreviousSelectionByFolderName) &&
|
||||
taskFolder2.FolderName.Equals(__instance.restorePreviousSelectionByFolderName, StringComparison.Ordinal))
|
||||
{
|
||||
__instance.restorePreviousSelectionFound = taskFolder2.Button;
|
||||
}
|
||||
}
|
||||
|
||||
var list = taskFolder.TaskChildren
|
||||
.ToArray()
|
||||
.OrderBy(x => x.TaskType)
|
||||
.ToArray();
|
||||
foreach (var task in list)
|
||||
var flag = false;
|
||||
var list = taskFolder.Children.ToArray().OrderBy(t => t.TaskType).ToList();
|
||||
|
||||
for (var l = 0; l < list.Count; l++)
|
||||
{
|
||||
TaskAddButton taskAddButton = Object.Instantiate(__instance.TaskPrefab);
|
||||
taskAddButton.MyTask = task;
|
||||
switch (task.TaskType)
|
||||
var taskAddButton = Object.Instantiate(__instance.TaskPrefab);
|
||||
taskAddButton.MyTask = list.ToArray()[l];
|
||||
switch (taskAddButton.MyTask.TaskType)
|
||||
{
|
||||
case TaskTypes.DivertPower:
|
||||
{
|
||||
var targetSystem = task.Cast<DivertPowerTask>().TargetSystem;
|
||||
taskAddButton.Text.text = TranslationController.Instance.GetString(
|
||||
StringNames.DivertPowerTo,
|
||||
TranslationController.Instance.GetString(targetSystem));
|
||||
break;
|
||||
}
|
||||
{
|
||||
var targetSystem = taskAddButton.MyTask.Cast<DivertPowerTask>().TargetSystem;
|
||||
taskAddButton.Text.text = TranslationController.Instance.GetString(
|
||||
StringNames.DivertPowerTo,
|
||||
TranslationController.Instance.GetString(targetSystem));
|
||||
break;
|
||||
}
|
||||
case TaskTypes.FixWeatherNode:
|
||||
{
|
||||
var nodeId = task.Cast<WeatherNodeTask>().NodeId;
|
||||
taskAddButton.Text.text =
|
||||
TranslationController.Instance.GetString(
|
||||
StringNames.FixWeatherNode) + " " +
|
||||
TranslationController.Instance.GetString(
|
||||
WeatherSwitchGame.ControlNames[nodeId]);
|
||||
break;
|
||||
}
|
||||
{
|
||||
var nodeId = taskAddButton.MyTask.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(task.TaskType);
|
||||
TranslationController.Instance.GetString(taskAddButton.MyTask.TaskType);
|
||||
break;
|
||||
}
|
||||
|
||||
__instance.AddFileAsChildCustom(taskAddButton, ref num, ref num2, ref num3);
|
||||
if (taskAddButton != null && taskAddButton.Button != null)
|
||||
if (taskAddButton.Button == null)
|
||||
{
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskAddButton.Button, false);
|
||||
}
|
||||
}
|
||||
|
||||
var roleChildren = taskFolder.RoleChildren
|
||||
.ToArray()
|
||||
.Where(x => x is not ICustomRole)
|
||||
.ToArray();
|
||||
foreach (var role in roleChildren)
|
||||
{
|
||||
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)
|
||||
{
|
||||
roleAddButton.Text.fontSizeMin = 1;
|
||||
roleAddButton.FileImage.sprite = role.IsImpostor
|
||||
? MiraAssets.ImpostorFile.LoadAsset()
|
||||
: MiraAssets.CrewmateFile.LoadAsset();
|
||||
continue;
|
||||
}
|
||||
|
||||
__instance.AddFileAsChildCustom(roleAddButton, ref num, ref num2, ref num3);
|
||||
if (roleAddButton != null && roleAddButton.Button != null)
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskAddButton.Button);
|
||||
if (__instance.Hierarchy.Count == 1 || flag)
|
||||
{
|
||||
ControllerManager.Instance.AddSelectableUiElement(roleAddButton.Button);
|
||||
continue;
|
||||
}
|
||||
|
||||
var component =
|
||||
ControllerManager.Instance.CurrentUiState.CurrentSelection.GetComponent<TaskFolder>();
|
||||
if (component != null)
|
||||
{
|
||||
__instance.restorePreviousSelectionByFolderName = component.FolderName;
|
||||
}
|
||||
|
||||
ControllerManager.Instance.SetDefaultSelection(taskAddButton.Button);
|
||||
flag = true;
|
||||
}
|
||||
|
||||
string[] split = [];
|
||||
try
|
||||
if (taskFolder.FolderName == "Roles")
|
||||
{
|
||||
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)
|
||||
for (var m = 0; m < RoleManager.Instance.AllRoles.Length; m++)
|
||||
{
|
||||
foreach (var role in plugin.InternalRoles)
|
||||
var roleBehaviour = RoleManager.Instance.AllRoles[m];
|
||||
if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost ||
|
||||
CustomRoleManager.CustomRoles.ContainsKey((ushort)roleBehaviour.Role))
|
||||
{
|
||||
var roleBehaviour = role.Value;
|
||||
if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost ||
|
||||
roleBehaviour is ICustomRole { Configuration.ShowInFreeplay: false })
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var crewLocale = TranslationController.Instance.GetString(StringNames.Crewmate);
|
||||
var impLocale = TranslationController.Instance.GetString(StringNames.Impostor);
|
||||
continue;
|
||||
}
|
||||
|
||||
var teamFolder = roleBehaviour.IsImpostor ? impLocale : crewLocale;
|
||||
if (roleBehaviour is ICustomRole cs)
|
||||
{
|
||||
teamFolder = cs.Configuration.FreeplayFolder;
|
||||
}
|
||||
if (split[1] != teamFolder)
|
||||
{
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
if (taskAddButton2.Button == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
__instance.AddFileAsChildCustom(roleAddButton, ref num, ref num2, ref num3);
|
||||
ControllerManager.Instance.AddSelectableUiElement(roleAddButton.Button);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (folders.TryGetValue("Modifiers", out var modifiersFolder) && taskFolder.IsChildOf(modifiersFolder))
|
||||
if (taskFolder)
|
||||
{
|
||||
var plugin = MiraPluginManager.GetPluginByGuid(taskFolder.name.Replace("(Clone)", string.Empty));
|
||||
if (plugin != null)
|
||||
var split = taskFolder.name.Split(':');
|
||||
if (split.Length == 2)
|
||||
{
|
||||
foreach (var modifier in plugin.InternalModifiers)
|
||||
var pluginId = split[0];
|
||||
var folderName = split[1];
|
||||
|
||||
if (MiraPluginManager.GetPluginByGuid(pluginId) is { } plugin)
|
||||
{
|
||||
if (!modifier.ShowInFreeplay)
|
||||
if (folderName == "Roles(Clone)")
|
||||
{
|
||||
continue;
|
||||
PluginRoles(__instance, plugin, ref num, ref num2, ref num3);
|
||||
}
|
||||
|
||||
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)
|
||||
else if (folderName == "Modifiers(Clone)")
|
||||
{
|
||||
taskAddButton.FileImage.sprite = MiraAssets.TimedModifierFile.LoadAsset();
|
||||
taskAddButton.Text.text += $" ({timed.Duration}s)";
|
||||
PluginModifiers(__instance, plugin, ref num, ref num2, ref num3);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var chip in __instance.ActiveItems)
|
||||
{
|
||||
chip.GetComponentInChildren<TextMeshPro>().EnableStencilMasking();
|
||||
chip.GetComponent<SpriteRenderer>().maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
}
|
||||
|
||||
if (_scroller)
|
||||
{
|
||||
_scroller.CalculateAndSetYBounds(__instance.ActiveItems.Count, 6, 4.5f, 1.65f);
|
||||
@@ -502,11 +306,129 @@ internal static class TaskAdderPatches
|
||||
_scroller.ScrollToTop();
|
||||
}
|
||||
|
||||
ControllerManager.Instance.SetBackButton(__instance.Hierarchy.Count == 1
|
||||
? __instance.BackButton
|
||||
: __instance.FolderBackButton);
|
||||
if (__instance.Hierarchy.Count == 1)
|
||||
{
|
||||
ControllerManager.Instance.SetBackButton(__instance.BackButton);
|
||||
return false;
|
||||
}
|
||||
|
||||
__instance.SetPreviousControllerSelection(taskFolder.FolderName);
|
||||
ControllerManager.Instance.SetBackButton(__instance.FolderBackButton);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public static class ButtonResetPatches
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Error($"Error resetting cooldown and effect for button {customActionButton.GetType().Name}: {ex}");
|
||||
Logger<MiraApiPlugin>.Error($"Error resetting cooldown and effect for button {customActionButton.GetType().Name}: {ex}");
|
||||
}
|
||||
|
||||
if (customActionButton.UsesMode == ButtonUsesMode.PerRound)
|
||||
|
||||
@@ -73,22 +73,6 @@ public static class HudManagerPatches
|
||||
gridArrange.Alignment = GridArrange.StartAlign.Right;
|
||||
aspectPosition.Alignment = AspectPosition.EdgeAlignments.LeftBottom;
|
||||
|
||||
if (Constants.GetPlatformType() is Platforms.Android or Platforms.IPhone)
|
||||
{
|
||||
var fakeButton = Object.Instantiate(__instance.AbilityButton, BottomLeft.transform);
|
||||
foreach (var renderer in fakeButton.GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
renderer.enabled = false;
|
||||
}
|
||||
|
||||
fakeButton.buttonLabelText.Destroy();
|
||||
fakeButton.cooldownTimerText.Destroy();
|
||||
fakeButton.usesRemainingText.Destroy();
|
||||
fakeButton.GetComponent<PassiveButton>().Destroy();
|
||||
fakeButton.ToggleVisible(true);
|
||||
fakeButton.Destroy();
|
||||
}
|
||||
|
||||
foreach (var button in CustomButtonManager.CustomButtons)
|
||||
{
|
||||
var location = button.Location switch
|
||||
@@ -109,7 +93,7 @@ public static class HudManagerPatches
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Error($"Failed to create custom button {button.GetType().Name}: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create custom button {button.GetType().Name}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +155,7 @@ public static class HudManagerPatches
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Error($"Failed to set custom button {button.GetType().Name} active: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to set custom button {button.GetType().Name} active: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,10 +182,12 @@ public static class HudManagerPatches
|
||||
entry.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var entry in KeybindManager.VanillaKeybinds.Values.Where(x => player.GetButtonDown(x.Id)))
|
||||
foreach (var entry in KeybindManager.VanillaKeybinds.Values)
|
||||
{
|
||||
entry.Invoke();
|
||||
if (player.GetButtonDown(entry.Id))
|
||||
{
|
||||
entry.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
@@ -33,29 +29,14 @@ public static class IntroCutscenePatches
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class IntroCutsceneShowRolePatch
|
||||
[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)
|
||||
{
|
||||
public static MethodBase TargetMethod()
|
||||
{
|
||||
return Helpers.GetStateMachineMoveNext<IntroCutscene>(nameof(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;
|
||||
|
||||
Info("IntroCutscene ShowRole reached");
|
||||
var @event = new IntroRoleRevealEvent(introCutscene);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
var realInstance = __instance.__4__this;
|
||||
var @event = new IntroRoleRevealEvent(realInstance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
@@ -85,54 +66,16 @@ public static class IntroCutscenePatches
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class IntroCutsceneDestroyPatch
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.OnDestroy))]
|
||||
public static void GameBeginPatch(IntroCutscene __instance)
|
||||
{
|
||||
private static bool _usedFallback;
|
||||
MiraEventManager.InvokeEvent(new IntroEndEvent(__instance));
|
||||
|
||||
public static MethodBase TargetMethod()
|
||||
{
|
||||
var onDestroy = AccessTools.Method(typeof(IntroCutscene), "OnDestroy");
|
||||
if (onDestroy != null)
|
||||
{
|
||||
_usedFallback = false;
|
||||
Info("Using OnDestroy for IntroCutsceneDestroyPatch");
|
||||
return onDestroy;
|
||||
}
|
||||
var @event = new BeforeRoundStartEvent(true);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
_usedFallback = true;
|
||||
return Helpers.GetStateMachineMoveNext<IntroCutscene>(nameof(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>();
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
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,13 +6,10 @@ 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;
|
||||
@@ -23,20 +20,6 @@ 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)
|
||||
@@ -55,8 +38,6 @@ public static class HatsTabPatches
|
||||
}
|
||||
}
|
||||
|
||||
InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage);
|
||||
|
||||
GenerateHats(__instance, currentPage);
|
||||
|
||||
return false;
|
||||
@@ -64,17 +45,22 @@ 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))
|
||||
{
|
||||
PreviousPage(__instance);
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? sortedHats.Count - 1 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
NextPage(__instance);
|
||||
currentPage++;
|
||||
currentPage = currentPage > sortedHats.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,10 +84,10 @@ public static class HatsTabPatches
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedHats.Count})";
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedHats.Count})\nPress Ctrl or Tab to cycle pages";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 5f;
|
||||
text.fontSizeMax = 5f;
|
||||
text.fontSize = 3f;
|
||||
text.fontSizeMax = 3f;
|
||||
text.fontSizeMin = 0f;
|
||||
var xLerp = __instance.XRange.Lerp(0.5f);
|
||||
var yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
@@ -139,17 +125,9 @@ public static class HatsTabPatches
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = hat.ProductId;
|
||||
if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard)
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip);
|
||||
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectHat(hat)));
|
||||
colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectHat(HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat))));
|
||||
}
|
||||
else
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectHat(hat)));
|
||||
}
|
||||
|
||||
colorChip.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))));
|
||||
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);
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Patches.Menu;
|
||||
|
||||
public static class InventoryUtility
|
||||
{
|
||||
public static void CreateNextBackButtons<T>(T tab, Action<T> previousPage, Action<T> nextPage) where T : InventoryTab
|
||||
{
|
||||
var title = tab.transform.FindChild("Text");
|
||||
title.localPosition = new Vector3(.9123f, -.23f, -55);
|
||||
title.GetComponent<TextMeshPro>().alignment = TextAlignmentOptions.Center;
|
||||
|
||||
tab.scroller.Hitbox.transform.localScale -= new Vector3(0, 0.1f, 0);
|
||||
tab.scroller.Hitbox.transform.localPosition -= new Vector3(0, 0.1f, 0);
|
||||
|
||||
var leftButtonElement = Object.Instantiate(PlayerCustomizationMenu.Instance.BackButton.gameObject, tab.transform);
|
||||
var leftSpriteRenderer = leftButtonElement.GetComponent<SpriteRenderer>();
|
||||
var leftButton = leftButtonElement.GetComponent<PassiveButton>();
|
||||
|
||||
leftButtonElement.transform.localPosition = new Vector3(-1.1f, -0.2f, -55);
|
||||
leftSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset();
|
||||
leftSpriteRenderer.flipX = true;
|
||||
|
||||
leftButton.OnMouseOver = new UnityEvent();
|
||||
leftButton.OnMouseOver.AddListener((Action)(() => leftSpriteRenderer.sprite = MiraAssets.NextButtonActive.LoadAsset()));
|
||||
leftButton.OnMouseOut = new UnityEvent();
|
||||
leftButton.OnMouseOut.AddListener((Action)(() => leftSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset()));
|
||||
|
||||
leftButton.OnClick = new Button.ButtonClickedEvent();
|
||||
leftButton.OnClick.AddListener((Action)(() => previousPage(tab)));
|
||||
|
||||
var rightButtonElement = Object.Instantiate(leftButtonElement, tab.transform);
|
||||
var rightSpriteRenderer = rightButtonElement.GetComponent<SpriteRenderer>();
|
||||
var rightButton = rightButtonElement.GetComponent<PassiveButton>();
|
||||
|
||||
rightButtonElement.transform.localPosition = new Vector3(2.8f, -0.2f, -55);
|
||||
rightSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset();
|
||||
rightSpriteRenderer.flipX = false;
|
||||
|
||||
rightButton.OnMouseOver = new UnityEvent();
|
||||
rightButton.OnMouseOver.AddListener((Action)(() => rightSpriteRenderer.sprite = MiraAssets.NextButtonActive.LoadAsset()));
|
||||
rightButton.OnMouseOut = new UnityEvent();
|
||||
rightButton.OnMouseOut.AddListener((Action)(() => rightSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset()));
|
||||
|
||||
rightButton.OnClick = new Button.ButtonClickedEvent();
|
||||
rightButton.OnClick.AddListener((Action)(() => nextPage(tab)));
|
||||
}
|
||||
}
|
||||
@@ -26,20 +26,6 @@ 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)
|
||||
@@ -47,9 +33,6 @@ 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;
|
||||
@@ -62,11 +45,15 @@ public static class NameplatesTabPatches
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
PreviousPage(__instance);
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? SortedNameplates.Count - 1 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
NextPage(__instance);
|
||||
currentPage++;
|
||||
currentPage = currentPage > SortedNameplates.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,10 +73,10 @@ public static class NameplatesTabPatches
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedNameplates.Count})";
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedNameplates.Count})\nPress Ctrl or Tab to cycle pages";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 5f;
|
||||
text.fontSizeMax = 5f;
|
||||
text.fontSize = 3f;
|
||||
text.fontSizeMax = 3f;
|
||||
text.fontSizeMin = 0f;
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
@@ -112,20 +99,9 @@ public static class NameplatesTabPatches
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = namePlate.ProductId;
|
||||
|
||||
if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard)
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip);
|
||||
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectNameplate(namePlate)));
|
||||
colorChip.Button.OnMouseOut.AddListener(
|
||||
(Action)(() => __instance.SelectNameplate(
|
||||
HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.NamePlate))));
|
||||
}
|
||||
else
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectNameplate(namePlate)));
|
||||
}
|
||||
|
||||
colorChip.Button.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))));
|
||||
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||
colorChip.ProductId = namePlate.ProdId;
|
||||
|
||||
|
||||
@@ -18,20 +18,6 @@ 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)
|
||||
@@ -50,8 +36,6 @@ public static class SkinsTabPatches
|
||||
}
|
||||
}
|
||||
|
||||
InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage);
|
||||
|
||||
GenerateHats(__instance, currentPage);
|
||||
|
||||
return false;
|
||||
@@ -64,11 +48,15 @@ public static class SkinsTabPatches
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
PreviousPage(__instance);
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? sortedSkins.Count - 1 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
NextPage(__instance);
|
||||
currentPage++;
|
||||
currentPage = currentPage > sortedSkins.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,10 +76,10 @@ public static class SkinsTabPatches
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedSkins.Count})";
|
||||
text.text = $"{groupName} ({currentPage + 1}/{sortedSkins.Count})\nPress Ctrl or Tab to cycle pages";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 5f;
|
||||
text.fontSizeMax = 5f;
|
||||
text.fontSize = 3f;
|
||||
text.fontSizeMax = 3f;
|
||||
text.fontSizeMin = 0f;
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
@@ -114,18 +102,9 @@ public static class SkinsTabPatches
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = skin.ProductId;
|
||||
if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard)
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip);
|
||||
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectSkin(skin)));
|
||||
colorChip.Button.OnMouseOut.AddListener(
|
||||
(Action)(() =>
|
||||
__instance.SelectSkin(HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin))));
|
||||
}
|
||||
else
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectSkin(skin)));
|
||||
}
|
||||
colorChip.Button.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))));
|
||||
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||
colorChip.ProductId = skin.ProductId;
|
||||
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||
|
||||
@@ -25,21 +25,6 @@ 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)
|
||||
@@ -47,9 +32,6 @@ 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;
|
||||
@@ -62,11 +44,15 @@ public static class VisorsTabPatches
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
PreviousPage(__instance);
|
||||
currentPage--;
|
||||
currentPage = currentPage < 0 ? SortedVisors.Count - 1 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
NextPage(__instance);
|
||||
currentPage++;
|
||||
currentPage = currentPage > SortedVisors.Count - 1 ? 0 : currentPage;
|
||||
GenerateHats(__instance, currentPage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,10 +72,10 @@ public static class VisorsTabPatches
|
||||
text.gameObject.transform.localScale = Vector3.one;
|
||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
text.EnableStencilMasking();
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedVisors.Count})";
|
||||
text.text = $"{groupName} ({currentPage + 1}/{SortedVisors.Count})\nPress Ctrl or Tab to cycle pages";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.fontSize = 5f;
|
||||
text.fontSizeMax = 5f;
|
||||
text.fontSize = 3f;
|
||||
text.fontSizeMax = 3f;
|
||||
text.fontSizeMin = 0f;
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||
@@ -112,20 +98,9 @@ public static class VisorsTabPatches
|
||||
{
|
||||
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
colorChip.gameObject.name = visor.ProductId;
|
||||
|
||||
if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard)
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip);
|
||||
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectVisor(visor)));
|
||||
colorChip.Button.OnMouseOut.AddListener(
|
||||
(Action)(() =>
|
||||
__instance.SelectVisor(HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor))));
|
||||
}
|
||||
else
|
||||
{
|
||||
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectVisor(visor)));
|
||||
}
|
||||
|
||||
colorChip.Button.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))));
|
||||
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||
colorChip.ProductId = visor.ProductId;
|
||||
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||
|
||||
@@ -117,7 +117,7 @@ internal static class GamePresetsTabPatches
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static void Postfix()
|
||||
{
|
||||
Error("OnDisable called");
|
||||
Logger<MiraApiPlugin>.Error("OnDisable called");
|
||||
|
||||
if (_saveButton)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ internal static class GamePresetsTabPatches
|
||||
var prefab = GameSettingMenu.Instance.GameSettingsButton;
|
||||
if (prefab == null)
|
||||
{
|
||||
Error("GameSettingsButton prefab is null");
|
||||
Logger<MiraApiPlugin>.Error("GameSettingsButton prefab is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -318,10 +318,10 @@ internal static class GamePresetsTabPatches
|
||||
|
||||
private static void Refresh()
|
||||
{
|
||||
Error("Refreshing presets");
|
||||
Logger<MiraApiPlugin>.Error("Refreshing presets");
|
||||
if (GameSettingMenuPatches.SelectedMod == null)
|
||||
{
|
||||
Error("Selected mod is null, cannot refresh presets");
|
||||
Logger<MiraApiPlugin>.Error("Selected mod is null, cannot refresh presets");
|
||||
return;
|
||||
}
|
||||
lock (Lock)
|
||||
|
||||
@@ -344,7 +344,7 @@ public static class LobbyViewPanePatches
|
||||
}
|
||||
|
||||
viewSettingsInfoPanelRoleVariant.SetInfo(
|
||||
roleBehaviour.GetRoleName(),
|
||||
roleBehaviour.NiceName,
|
||||
numPerGame,
|
||||
chancePerGame,
|
||||
61,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.GameOptions;
|
||||
@@ -58,7 +57,6 @@ 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)
|
||||
{
|
||||
@@ -69,64 +67,7 @@ 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);
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
|
||||
ScrollerNum = 0.522f;
|
||||
@@ -138,16 +79,15 @@ 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 num4 = 0;
|
||||
var num3 = 0;
|
||||
|
||||
var roleGroups = GameSettingMenuPatches.SelectedMod?.InternalRoles.Values.OfType<ICustomRole>()
|
||||
.ToLookup(x => x.RoleOptionsGroup);
|
||||
|
||||
if (roleGroups is null)
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// sort the groups by priority
|
||||
@@ -257,11 +197,11 @@ public static class RoleSettingMenuPatches
|
||||
continue;
|
||||
}
|
||||
|
||||
var option = CreateQuotaOption(__instance, roleBehaviour, num4);
|
||||
var option = CreateQuotaOption(__instance, roleBehaviour, num3);
|
||||
if (option is not null)
|
||||
{
|
||||
RoleOptionSettings.Add(option);
|
||||
num4++;
|
||||
num3++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -392,7 +332,7 @@ public static class RoleSettingMenuPatches
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Warning(e);
|
||||
Logger<MiraApiPlugin>.Warning(e);
|
||||
}
|
||||
|
||||
roleSetting.UpdateValuesAndText(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions);
|
||||
@@ -466,14 +406,16 @@ public static class RoleSettingMenuPatches
|
||||
{
|
||||
if (role is not ICustomRole customRole)
|
||||
{
|
||||
Error($"Role {role.NiceName} is not a custom role.");
|
||||
Logger<MiraApiPlugin>.Error($"Role {role.NiceName} is not a custom role.");
|
||||
return;
|
||||
}
|
||||
|
||||
RolePositions[GameSettingMenuPatches.SelectedModIdx] = __instance.scrollBar.Inner.localPosition;
|
||||
|
||||
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
||||
__instance.roleTitleText.text = role.GetRoleName();
|
||||
__instance.roleTitleText.text = TranslationController.Instance.GetString(
|
||||
role.StringName,
|
||||
new Il2CppReferenceArray<Il2CppSystem.Object>(0));
|
||||
|
||||
var imgBg = __instance.AdvancedRolesSettings.transform.FindChild("Imagebackground");
|
||||
var labelBg = __instance.AdvancedRolesSettings.transform.FindChild("InfoLabelBackground");
|
||||
@@ -560,7 +502,7 @@ public static class RoleSettingMenuPatches
|
||||
{
|
||||
if (role is not ICustomRole customRole)
|
||||
{
|
||||
Error($"Role {role.NiceName} is not a custom role.");
|
||||
Logger<MiraApiPlugin>.Error($"Role {role.NiceName} is not a custom role.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -577,7 +519,6 @@ public static class RoleSettingMenuPatches
|
||||
roleOptionSetting.transform.localPosition = new Vector3(-0.1f, ScrollerNum, -2f);
|
||||
|
||||
roleOptionSetting.SetRole(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions, role, 20);
|
||||
roleOptionSetting.titleText.text = role.GetRoleName();
|
||||
roleOptionSetting.labelSprite.color = customRole.OptionsMenuColor;
|
||||
roleOptionSetting.OnValueChanged = new Action<OptionBehaviour>(ValueChanged);
|
||||
roleOptionSetting.SetClickMask(__instance.ButtonClickMask);
|
||||
@@ -591,19 +532,6 @@ 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())))
|
||||
@@ -623,6 +551,18 @@ 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,5 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
@@ -68,53 +67,15 @@ internal static class PlayerControlPatches
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(PlayerControl.CheckMurder))]
|
||||
public static void PlayerControlCheckMurderPrefix(PlayerControl __instance, PlayerControl target, ref bool __runOriginal)
|
||||
[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)
|
||||
{
|
||||
__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);
|
||||
|
||||
if (beforeMurderEvent.IsCancelled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
__instance.isKilling = true;
|
||||
__instance.RpcMurderPlayer(target, true);
|
||||
didSucceed = beforeMurderEvent.IsCancelled;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
@@ -145,7 +106,7 @@ internal static class PlayerControlPatches
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Error($"Failed to update custom button {button.GetType().Name}: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to update custom button {button.GetType().Name}: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ internal static class EjectionPatches
|
||||
__instance.completeString = role.GetCustomEjectionMessage(__instance.initData.networkedPlayer);
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ExileController), nameof(ExileController.ReEnableGameplay))]
|
||||
public static class ReEnableGameplayPatch
|
||||
[HarmonyPatch(typeof(ExileController), nameof(ExileController.WrapUp))]
|
||||
public static class WrapUpPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Patches the haunt menu to show the actual role name rather than team.
|
||||
/// Patches the haunt menu to show the actual role name rather then team.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(HauntMenuMinigame), nameof(HauntMenuMinigame.SetHauntTarget))]
|
||||
// SetFilterText was INLINED
|
||||
@@ -23,7 +22,7 @@ public static class HauntMenuMinigamePatch
|
||||
var role = __instance.HauntTarget.Data.Role;
|
||||
var color = role is ICustomRole custom ? custom.RoleColor : role.TeamColor;
|
||||
|
||||
__instance.FilterText.text = role.GetRoleName();
|
||||
__instance.FilterText.text = role.NiceName;
|
||||
__instance.FilterText.color = color;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
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,11 +58,6 @@ public static class KillButtonPatches
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerControl.LocalPlayer.RpcCustomMurder(__instance.currentTarget);
|
||||
__instance.SetTarget(null);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public static class RoleManagerPatches
|
||||
var data = targetPlayer.Data;
|
||||
if (data == null)
|
||||
{
|
||||
Error("It shouldn't be possible, but " + targetPlayer.name + " still doesn't have PlayerData during role selection.");
|
||||
Debug.LogError("It shouldn't be possible, but " + targetPlayer.name + " still doesn't have PlayerData during role selection.");
|
||||
return false;
|
||||
}
|
||||
if (data.Role)
|
||||
@@ -33,7 +33,7 @@ public static class RoleManagerPatches
|
||||
data.Role.Deinitialize(targetPlayer);
|
||||
Object.Destroy(data.Role.gameObject);
|
||||
}
|
||||
var roleBehaviour = Object.Instantiate<RoleBehaviour>(__instance.AllRoles.ToArray().First(r => r.Role == roleType), data.gameObject.transform);
|
||||
var roleBehaviour = Object.Instantiate<RoleBehaviour>(__instance.AllRoles.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(RoleOptionsCollectionV10))]
|
||||
[HarmonyPatch(typeof(RoleOptionsCollectionV09))]
|
||||
public static class RoleOptionsCollectionPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// This patch fixes GetNumPerGame being inlined (2025.9.9) in the original code.
|
||||
/// This patch fixes GetNumPerGame being inlined (2025.5.20) in the original code.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV10.AnyRolesEnabled))]
|
||||
public static bool AnyRolesEnabledPrefix(RoleOptionsCollectionV10 __instance, ref bool __result)
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV09.AnyRolesEnabled))]
|
||||
public static bool AnyRolesEnabledPrefix(RoleOptionsCollectionV09 __instance, ref bool __result)
|
||||
{
|
||||
foreach (KeyValuePair<RoleTypes, RoleDataV10> keyValuePair in __instance.roles)
|
||||
foreach (KeyValuePair<RoleTypes, RoleDataV09> 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(RoleOptionsCollectionV10.GetChancePerGame))]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV09.GetChancePerGame))]
|
||||
public static bool GetChancePrefix(RoleTypes role, ref int __result)
|
||||
{
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(role, out var customRole) || customRole == null)
|
||||
@@ -51,7 +51,7 @@ public static class RoleOptionsCollectionPatch
|
||||
var chance = customRole.GetChance();
|
||||
if (chance == null)
|
||||
{
|
||||
Error($"Chance is null, defaulting to zero.");
|
||||
Logger<MiraApiPlugin>.Error($"Chance is null, defaulting to zero.");
|
||||
chance = 0;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public static class RoleOptionsCollectionPatch
|
||||
/// </summary>
|
||||
/// <returns>Return false to skip original method, true to not.</returns>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV10.GetNumPerGame))]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV09.GetNumPerGame))]
|
||||
public static bool GetNumPrefix(RoleTypes role, ref int __result)
|
||||
{
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(role, out var customRole) || customRole == null)
|
||||
@@ -81,7 +81,7 @@ public static class RoleOptionsCollectionPatch
|
||||
var count = customRole.GetCount();
|
||||
if (count == null)
|
||||
{
|
||||
Error($"Count is null, defaulting to zero.");
|
||||
Logger<MiraApiPlugin>.Error($"Count is null, defaulting to zero.");
|
||||
count = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Reactor.Utilities;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -10,29 +8,20 @@ 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 ServerManager.Instance.AvailableRegions)
|
||||
foreach (var regionInfo in DestroyableSingleton<ServerManager>.Instance.AvailableRegions)
|
||||
{
|
||||
var findingGame = SceneManager.GetActiveScene().name is "FindAGame";
|
||||
|
||||
if (ServerManager.Instance.CurrentRegion.RegionEquals(regionInfo))
|
||||
if (DestroyableSingleton<ServerManager>.Instance.CurrentRegion.Equals(regionInfo))
|
||||
{
|
||||
__instance.defaultButtonSelected = __instance.firstOption;
|
||||
__instance.firstOption.ChangeButtonText(
|
||||
TranslationController.Instance.GetStringWithDefault(
|
||||
DestroyableSingleton<TranslationController>.Instance.GetStringWithDefault(
|
||||
regionInfo.TranslateName,
|
||||
regionInfo.Name));
|
||||
}
|
||||
@@ -45,11 +34,11 @@ public static class ServerDropdownPatch
|
||||
{
|
||||
x += 2;
|
||||
}
|
||||
var y = -0.55f * (num / 2f);
|
||||
var y = -0.55f * (num / 2);
|
||||
serverListButton.transform.localPosition = new Vector3(x, __instance.y_posButton + y, -1f);
|
||||
serverListButton.transform.localScale = Vector3.one;
|
||||
serverListButton.Text.text =
|
||||
TranslationController.Instance.GetStringWithDefault(
|
||||
DestroyableSingleton<TranslationController>.Instance.GetStringWithDefault(
|
||||
regionInfo.TranslateName,
|
||||
regionInfo.Name);
|
||||
serverListButton.Text.ForceMeshUpdate();
|
||||
@@ -58,9 +47,9 @@ public static class ServerDropdownPatch
|
||||
__instance.controllerSelectable.Add(serverListButton.Button);
|
||||
__instance.background.transform.localPosition = new Vector3(
|
||||
findingGame ? 2f : 0f,
|
||||
__instance.initialYPos + -0.3f * (num / 2f),
|
||||
__instance.initialYPos + (-0.3f * (num / 2)),
|
||||
0f);
|
||||
__instance.background.size = new Vector2(__instance.background.size.x, 1.2f + 0.6f * (num / 2f));
|
||||
__instance.background.size = new Vector2(__instance.background.size.x, 1.2f + (0.6f * (num / 2)));
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using HarmonyLib;
|
||||
using Hazel;
|
||||
using Il2CppSystem.Text;
|
||||
|
||||
namespace MiraAPI.Patches.Stubs;
|
||||
@@ -230,76 +229,4 @@ 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
|
||||
}
|
||||
}
|
||||
@@ -70,14 +70,14 @@ public sealed class MiraPluginManager
|
||||
|
||||
if (!method.IsStatic)
|
||||
{
|
||||
Error($"Event method {method.Name} in {type.Name} must be static.");
|
||||
Logger<MiraApiPlugin>.Error($"Event method {method.Name} in {type.Name} must be static.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var parameters = method.GetParameters();
|
||||
if (parameters.Length != 1 || !parameters[0].ParameterType.IsSubclassOf(typeof(MiraEvent)))
|
||||
{
|
||||
Error($"Invalid event registration method {method.Name} in {type.Name}");
|
||||
Logger<MiraApiPlugin>.Error($"Invalid event registration method {method.Name} in {type.Name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public sealed class MiraPluginManager
|
||||
info.SavePublicCollections();
|
||||
PresetManager.CreateDefaultPreset(info);
|
||||
PresetManager.LoadPresets(info);
|
||||
Info($"Registering mod {pluginInfo.Metadata.GUID} with Mira API.");
|
||||
Logger<MiraApiPlugin>.Info($"Registering mod {pluginInfo.Metadata.GUID} with Mira API.");
|
||||
};
|
||||
IL2CPPChainloader.Instance.Finished += PaletteManager.RegisterAllColors;
|
||||
IL2CPPChainloader.Instance.Finished += () =>
|
||||
@@ -167,7 +167,7 @@ public sealed class MiraPluginManager
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Failed to register game over {type.Name}: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to register game over {type.Name}: {e}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public sealed class MiraPluginManager
|
||||
{
|
||||
if (property.GetMethod?.IsStatic == true)
|
||||
{
|
||||
Error($"Option property {property.Name} in {type.Name} must not be static.");
|
||||
Logger<MiraApiPlugin>.Error($"Option property {property.Name} in {type.Name} must not be static.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -211,14 +211,14 @@ public sealed class MiraPluginManager
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(IModdedOption))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for options.");
|
||||
Logger<MiraApiPlugin>.Error($"{field.Name} is a field, not a property. Use properties for options.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Failed to register options for {type.Name}: {e.ToString()}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to register options for {type.Name}: {e.ToString()}");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -235,7 +235,7 @@ public sealed class MiraPluginManager
|
||||
|
||||
if (!ModList.GetById(pluginInfo.PluginId).IsRequiredOnAllClients)
|
||||
{
|
||||
Error("Custom roles are only supported on all clients.");
|
||||
Logger<MiraApiPlugin>.Error("Custom roles are only supported on all clients.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ public sealed class MiraPluginManager
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Failed to register role for {type.Name}: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to register role for {type.Name}: {e}");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -260,7 +260,7 @@ public sealed class MiraPluginManager
|
||||
|
||||
if (!type.IsStatic())
|
||||
{
|
||||
Error($"Color class {type.Name} must be static.");
|
||||
Logger<MiraApiPlugin>.Error($"Color class {type.Name} must be static.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ public sealed class MiraPluginManager
|
||||
|
||||
if (property.GetValue(null) is not CustomColor color)
|
||||
{
|
||||
Error($"Color property {property.Name} in {type.Name} is not a CustomColor.");
|
||||
Logger<MiraApiPlugin>.Error($"Color property {property.Name} in {type.Name} is not a CustomColor.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -282,12 +282,12 @@ public sealed class MiraPluginManager
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(CustomColor))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for colors.");
|
||||
Logger<MiraApiPlugin>.Error($"{field.Name} is a field, not a property. Use properties for colors.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Failed to register color class {type.Name}: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to register color class {type.Name}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ public sealed class MiraPluginManager
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Failed to register modifier {type.Name}: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to register modifier {type.Name}: {e}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -312,7 +312,7 @@ public sealed class MiraPluginManager
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Failed to register button {type.Name}: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to register button {type.Name}: {e}");
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -355,13 +355,13 @@ public sealed class MiraPluginManager
|
||||
|
||||
if (property.GetMethod?.IsStatic == true)
|
||||
{
|
||||
Error($"Option property {property.Name} in {type.Name} must not be static.");
|
||||
Logger<MiraApiPlugin>.Error($"Option property {property.Name} in {type.Name} must not be static.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property.GetValue(tabInstance) is not ConfigEntryBase configEntry)
|
||||
{
|
||||
Error($"Option property {property.Name} in {type.Name} has to be a config entry.");
|
||||
Logger<MiraApiPlugin>.Error($"Option property {property.Name} in {type.Name} has to be a config entry.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -376,14 +376,14 @@ public sealed class MiraPluginManager
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(ConfigEntryBase)) && f.GetCustomAttribute<LocalSettingAttribute>() != null))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for local settings.");
|
||||
Logger<MiraApiPlugin>.Error($"{field.Name} is a field, not a property. Use properties for local settings.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Failed to register options for {type.Name}: {e.ToString()}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to register options for {type.Name}: {e.ToString()}");
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -400,7 +400,7 @@ public sealed class MiraPluginManager
|
||||
|
||||
if (!type.IsStatic())
|
||||
{
|
||||
Error($"Keybinds class {type.Name} must be static.");
|
||||
Logger<MiraApiPlugin>.Error($"Keybinds class {type.Name} must be static.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ public sealed class MiraPluginManager
|
||||
|
||||
if (property.GetValue(null) is not MiraKeybind keybind)
|
||||
{
|
||||
Error($"Keybind property {property.Name} in {type.Name} is not a MiraKeybind.");
|
||||
Logger<MiraApiPlugin>.Error($"Keybind property {property.Name} in {type.Name} is not a MiraKeybind.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -430,12 +430,12 @@ public sealed class MiraPluginManager
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(MiraKeybind))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for keybinds.");
|
||||
Logger<MiraApiPlugin>.Error($"{field.Name} is a field, not a property. Use properties for keybinds.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Failed to register keybind class {type.Name}: {e}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to register keybind class {type.Name}: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public static class PresetManager
|
||||
foreach (var file in Directory.GetFiles(pluginPresetPath, "*.cfg"))
|
||||
{
|
||||
var fileName = Path.GetFileName(file);
|
||||
Info($"Loading preset file {fileName}");
|
||||
Logger<MiraApiPlugin>.Info($"Loading preset file {fileName}");
|
||||
var presetName = Path.GetFileNameWithoutExtension(file);
|
||||
var presetConfig = new ConfigFile(file, false)
|
||||
{
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
@@ -32,12 +32,6 @@ 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;
|
||||
@@ -118,11 +112,6 @@ 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>
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using Il2CppInterop.Runtime;
|
||||
using Il2CppInterop.Runtime.Injection;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities;
|
||||
@@ -36,11 +35,6 @@ 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>
|
||||
@@ -54,9 +48,6 @@ public static class CustomRoleManager
|
||||
internal static readonly Dictionary<ushort, RoleBehaviour> CustomRoles = [];
|
||||
internal static readonly Dictionary<Type, ushort> RoleIds = [];
|
||||
|
||||
private static Il2CppSystem.Collections.Generic.List<BaseGameSetting>? _emptySettings;
|
||||
private static Il2CppReferenceArray<OverlayKillAnimation>? _emptyKillAnimations;
|
||||
|
||||
private static ushort _roleId = 100;
|
||||
|
||||
private static ushort GetNextRoleId()
|
||||
@@ -66,10 +57,7 @@ public static class CustomRoleManager
|
||||
|
||||
internal static void RegisterInRoleManager()
|
||||
{
|
||||
foreach (var role in CustomRoles.Values)
|
||||
{
|
||||
RoleManager.Instance.AllRoles.Add(role);
|
||||
}
|
||||
RoleManager.Instance.AllRoles = RoleManager.Instance.AllRoles.Concat(CustomRoles.Values).ToArray();
|
||||
|
||||
foreach (var role in CustomRoles.Values.Where(x => x.IsDead))
|
||||
{
|
||||
@@ -108,7 +96,7 @@ public static class CustomRoleManager
|
||||
{
|
||||
if (!(typeof(RoleBehaviour).IsAssignableFrom(roleType) && typeof(ICustomRole).IsAssignableFrom(roleType)))
|
||||
{
|
||||
Error($"{roleType.Name} does not inherit from RoleBehaviour or ICustomRole.");
|
||||
Logger<MiraApiPlugin>.Error($"{roleType.Name} does not inherit from RoleBehaviour or ICustomRole.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -137,12 +125,6 @@ public static class CustomRoleManager
|
||||
roleBehaviour.MaxCount = customRole.Configuration.MaxRoleCount;
|
||||
roleBehaviour.RoleScreenshot = customRole.Configuration.OptionsScreenshot?.LoadAsset();
|
||||
|
||||
_emptySettings ??= new(0);
|
||||
_emptyKillAnimations ??= new(0);
|
||||
|
||||
roleBehaviour.AllGameSettings = _emptySettings;
|
||||
roleBehaviour.CustomKillAnimations = _emptyKillAnimations;
|
||||
|
||||
if (customRole.Configuration.Icon != null)
|
||||
{
|
||||
var asset = customRole.Configuration.Icon.LoadAsset();
|
||||
@@ -168,7 +150,7 @@ public static class CustomRoleManager
|
||||
|
||||
if (useTaskHint && !overridesTaskText)
|
||||
{
|
||||
Error($"Role {customRole.RoleName} is using RoleHintType.TaskHint but does not override SpawnTaskHeader!");
|
||||
Logger<MiraApiPlugin>.Error($"Role {customRole.RoleName} is using RoleHintType.TaskHint but does not override SpawnTaskHeader!");
|
||||
}
|
||||
|
||||
CustomRoles.Add(roleId, roleBehaviour);
|
||||
@@ -298,7 +280,7 @@ public static class CustomRoleManager
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error(e);
|
||||
Logger<MiraApiPlugin>.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Roles;
|
||||
@@ -55,7 +56,7 @@ public static class CustomRoleUtils
|
||||
/// <returns>The intro sound.</returns>
|
||||
public static LoadableAsset<AudioClip>? GetIntroSound(RoleTypes roleType)
|
||||
{
|
||||
var role = CustomRoleManager.AllRoles.FirstOrDefault(role => role.Role == roleType);
|
||||
var role = RoleManager.Instance.AllRoles.FirstOrDefault(role => role.Role == roleType);
|
||||
if (role is ICustomRole customRole)
|
||||
{
|
||||
return customRole.Configuration.IntroSound;
|
||||
|
||||
@@ -156,7 +156,7 @@ public interface ICustomRole : IOptionable
|
||||
{
|
||||
if (!Configuration.CanModifyChance)
|
||||
{
|
||||
Error($"Cannot modify chance for role: {RoleName}");
|
||||
Logger<MiraApiPlugin>.Error($"Cannot modify chance for role: {RoleName}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ public interface ICustomRole : IOptionable
|
||||
return;
|
||||
}
|
||||
|
||||
Error($"Error getting chance configuration for role: {RoleName}");
|
||||
Logger<MiraApiPlugin>.Error($"Error getting chance configuration for role: {RoleName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -181,7 +181,7 @@ public interface ICustomRole : IOptionable
|
||||
return;
|
||||
}
|
||||
|
||||
Error($"Error getting count configuration for role: {RoleName}");
|
||||
Logger<MiraApiPlugin>.Error($"Error getting count configuration for role: {RoleName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -33,7 +33,7 @@ public static class AddressablesLoader
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more catalogs.");
|
||||
Logger<MiraApiPlugin>.Error("AddressablesLoader has already been initialized, cannot register more catalogs.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public static class AddressablesLoader
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more keys for hats.");
|
||||
Logger<MiraApiPlugin>.Error("AddressablesLoader has already been initialized, cannot register more keys for hats.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public static class AddressablesLoader
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more keys for skins.");
|
||||
Logger<MiraApiPlugin>.Error("AddressablesLoader has already been initialized, cannot register more keys for skins.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public static class AddressablesLoader
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more keys for nameplates.");
|
||||
Logger<MiraApiPlugin>.Error("AddressablesLoader has already been initialized, cannot register more keys for nameplates.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public static class AddressablesLoader
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized, cannot register more keys for visors.");
|
||||
Logger<MiraApiPlugin>.Error("AddressablesLoader has already been initialized, cannot register more keys for visors.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public static class AddressablesLoader
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
Error("AddressablesLoader has already been initialized.");
|
||||
Logger<MiraApiPlugin>.Error("AddressablesLoader has already been initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -129,10 +129,10 @@ public static class AddressablesLoader
|
||||
// Check for errors
|
||||
if (catalogOperation.Status != AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Error($"Failed to load catalog {location}.");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to load catalog {location}.");
|
||||
}
|
||||
|
||||
Info($"Loaded addressables {location}.");
|
||||
Logger<MiraApiPlugin>.Info($"Loaded addressables {location}.");
|
||||
LoadedLocations.Add(location);
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public static class AddressablesLoader
|
||||
}
|
||||
catch
|
||||
{
|
||||
Error($"Failed to find tag {tag}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to find tag {tag}");
|
||||
}
|
||||
}
|
||||
return behaviours;
|
||||
@@ -214,7 +214,7 @@ public static class AddressablesLoader
|
||||
}
|
||||
catch
|
||||
{
|
||||
Error($"Failed to find tag {tag}");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to find tag {tag}");
|
||||
}
|
||||
}
|
||||
return behaviours;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class LoadableAddressableAsset<T>(string uid) : LoadableAsset<T> where T
|
||||
|
||||
var remoteReference = new AssetReference(uid);
|
||||
|
||||
if (!GC.TryStartNoGCRegion(4096, true)) Error("Could not start NoGCRegion of size 4kb, there is the possibility of injected unmanaged classes being garbage collected as per BepInEx/Il2CppInterop/issues/40");
|
||||
if (!GC.TryStartNoGCRegion(4096, true)) Logger<MiraApiPlugin>.Error("Could not start NoGCRegion of size 4kb, there is the possibility of injected unmanaged classes being garbage collected as per BepInEx/Il2CppInterop/issues/40");
|
||||
|
||||
LoadedAsset = remoteReference.LoadAssetAsync<T>().WaitForCompletion();
|
||||
if (LoadedAsset == null)
|
||||
|
||||
@@ -45,7 +45,7 @@ public class LoadableAddressableAssets<T>(string key) where T : UnityEngine.Obje
|
||||
|
||||
var locations = Addressables.LoadResourceLocationsAsync(key).WaitForCompletion();
|
||||
|
||||
if (!GC.TryStartNoGCRegion(4096, true)) Error("Could not start NoGCRegion of size 4kb, there is the possibility of injected unmanaged classes being garbage collected as per BepInEx/Il2CppInterop/issues/40");
|
||||
if (!GC.TryStartNoGCRegion(4096, true)) Logger<MiraApiPlugin>.Error("Could not start NoGCRegion of size 4kb, there is the possibility of injected unmanaged classes being garbage collected as per BepInEx/Il2CppInterop/issues/40");
|
||||
|
||||
var assetsIList = Addressables.LoadAssetsAsync<T>(locations, null, false).WaitForCompletion();
|
||||
if (assetsIList == null)
|
||||
|
||||
@@ -12,7 +12,7 @@ public static class MiraAssets
|
||||
{
|
||||
var boxTex = SpriteTools.LoadTextureFromResourcePath(
|
||||
"MiraAPI.Resources.RoundedBox.png",
|
||||
System.Reflection.Assembly.GetExecutingAssembly());
|
||||
System.Reflection.Assembly.GetCallingAssembly());
|
||||
var boxSprite = Sprite.Create(
|
||||
boxTex,
|
||||
new Rect(0, 0, boxTex.width, boxTex.height),
|
||||
@@ -105,26 +105,6 @@ 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>
|
||||
|
||||
@@ -19,10 +19,7 @@ public static class SpriteTools
|
||||
/// <exception cref="ArgumentException">Thrown when the resource cannot be found in the specified assembly.</exception>
|
||||
public static Texture2D LoadTextureFromResourcePath(string resourcePath, Assembly assembly)
|
||||
{
|
||||
var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false)
|
||||
{
|
||||
wrapMode = TextureWrapMode.Clamp,
|
||||
};
|
||||
var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
|
||||
var myStream = assembly.GetManifestResourceStream(resourcePath);
|
||||
if (myStream != null)
|
||||
{
|
||||
|
||||
@@ -29,13 +29,13 @@ public static class Extensions
|
||||
|
||||
if (count == null)
|
||||
{
|
||||
Error("Couldn't get role count for NetData, defaulting to zero.");
|
||||
Logger<MiraApiPlugin>.Error("Couldn't get role count for NetData, defaulting to zero.");
|
||||
count = 0;
|
||||
}
|
||||
|
||||
if (chance == null)
|
||||
{
|
||||
Error("Couldn't get role chance for NetData, defaulting to zero.");
|
||||
Logger<MiraApiPlugin>.Error("Couldn't get role chance for NetData, defaulting to zero.");
|
||||
chance = 0;
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ public static class Extensions
|
||||
|
||||
if (length > chunkSize)
|
||||
{
|
||||
Info($"NetData length is greater than chunk size: {length} > {chunkSize}");
|
||||
Logger<MiraApiPlugin>.Info($"NetData length is greater than chunk size: {length} > {chunkSize}");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Keybinds;
|
||||
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;
|
||||
@@ -39,31 +37,6 @@ 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)
|
||||
{
|
||||
Error($"Failed to find {methodName} state machine for {typeName}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var moveNext = AccessTools.Method(showRoleStateMachine, "MoveNext");
|
||||
if (moveNext == null)
|
||||
{
|
||||
Error($"Failed to find MoveNext method for {typeName}.{methodName}");
|
||||
return null;
|
||||
}
|
||||
|
||||
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>
|
||||
@@ -139,7 +112,7 @@ public static class Helpers
|
||||
return true;
|
||||
default:
|
||||
{
|
||||
var num = Random.RandomRangeInt(1, 101);
|
||||
var num = UnityEngine.Random.RandomRangeInt(1, 101);
|
||||
return num <= probability;
|
||||
}
|
||||
}
|
||||
@@ -500,7 +473,7 @@ public static class Helpers
|
||||
public static string RandomString(int length, string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
{
|
||||
return new string(Enumerable.Repeat(chars, length)
|
||||
.Select(s => s[Random.RandomRangeInt(0, s.Length)]).ToArray());
|
||||
.Select(s => s[UnityEngine.Random.RandomRangeInt(0, s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -522,18 +495,4 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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;
|
||||
|
||||
// normally it is fields, but IL2CPP turns them into properties
|
||||
private readonly PropertyInfo _thisProperty;
|
||||
private readonly PropertyInfo _stateProperty;
|
||||
private readonly Dictionary<string, PropertyInfo> _propertyCache;
|
||||
|
||||
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");
|
||||
|
||||
if (_thisProperty == null || _stateProperty == null)
|
||||
{
|
||||
throw new MissingMemberException($"Could not find required properties in type '{type}'.");
|
||||
}
|
||||
|
||||
_propertyCache = [];
|
||||
}
|
||||
|
||||
/// <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)!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a parameter from the state machine by its name.
|
||||
/// </summary>
|
||||
/// <param name="parameterName">The name of the parameter to retrieve.</param>
|
||||
/// <typeparam name="TField">The type of the parameter to retrieve.</typeparam>
|
||||
/// <returns>>The value of the specified parameter.</returns>
|
||||
/// <exception cref="MissingFieldException">Thrown if the specified parameter does not exist.</exception>
|
||||
public TField GetParameter<TField>(string parameterName)
|
||||
{
|
||||
if (_propertyCache.TryGetValue(parameterName, out var property))
|
||||
{
|
||||
return (TField)property.GetValue(_stateMachine)!;
|
||||
}
|
||||
|
||||
property = AccessTools.Property(_stateMachine.GetType(), parameterName)
|
||||
?? throw new MissingFieldException($"Could not find parameter '{parameterName}' in state machine of type '{_stateMachine.GetType()}'.");
|
||||
|
||||
_propertyCache[parameterName] = property;
|
||||
return (TField)property.GetValue(_stateMachine)!;
|
||||
}
|
||||
}
|
||||
@@ -224,7 +224,7 @@ public static class VotingUtils
|
||||
var playerById = GameData.Instance.GetPlayerById(vote.Voter);
|
||||
if (playerById == null)
|
||||
{
|
||||
Error($"Couldn't find player info for voter: {vote.Voter}");
|
||||
Logger<MiraApiPlugin>.Error($"Couldn't find player info for voter: {vote.Voter}");
|
||||
}
|
||||
else if (i == 0 && vote.Suspect == SkipVoteId)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,5 @@
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
<add key="Reactor" value="https://nuget.reactor.gg/v3/index.json" />
|
||||
<add key="Samboy063" value="https://nuget.samboy.dev/v3/index.json" />
|
||||
<add key="local" value="./packages" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
Binary file not shown.
@@ -1,3 +0,0 @@
|
||||
here to ensure git doesn't delete empty folders
|
||||
|
||||
local packages are stored in this directory
|
||||
Reference in new issue
Block a user