mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
final touches and fixes
This commit is contained in:
1 parent
016d21075f
commit
76c39d9bdc
40 files changed
+241
-216
No files matched your search
@@ -7,25 +7,22 @@ using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
[RegisterInIl2Cpp]
|
||||
public class MiraDebugWindow : MonoBehaviour
|
||||
public class MiraDebugWindow(IntPtr ptr) : MonoBehaviour(ptr)
|
||||
{
|
||||
public DragWindow DebuggingWindow;
|
||||
public MiraDebugWindow(IntPtr ptr) : base(ptr)
|
||||
public readonly DragWindow DebuggingWindow = new(new Rect(10, 10, 0, 0), "MIRA API DEBUGGING", () =>
|
||||
{
|
||||
DebuggingWindow = new DragWindow(new Rect(10, 10, 0, 0), "MIRA API DEBUGGING", () =>
|
||||
if (GUILayout.Button("Test modifier"))
|
||||
{
|
||||
if (GUILayout.Button("Test modifier"))
|
||||
{
|
||||
PlayerControl.LocalPlayer.AddModifier<ModifierTimerExample>();
|
||||
}
|
||||
if (GUILayout.Button("Remove modifier"))
|
||||
{
|
||||
PlayerControl.LocalPlayer.RemoveModifier<ModifierTimerExample>();
|
||||
}
|
||||
});
|
||||
|
||||
DebuggingWindow.Enabled = true;
|
||||
}
|
||||
PlayerControl.LocalPlayer.AddModifier<ModifierTimerExample>();
|
||||
}
|
||||
if (GUILayout.Button("Remove modifier"))
|
||||
{
|
||||
PlayerControl.LocalPlayer.RemoveModifier<ModifierTimerExample>();
|
||||
}
|
||||
})
|
||||
{
|
||||
Enabled = true
|
||||
};
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ public class ModifierTimerExample : TimedModifier
|
||||
public override float Duration => 10f;
|
||||
public override bool AutoStart => true;
|
||||
|
||||
private System.Random _rand = new();
|
||||
private readonly System.Random _rand = new();
|
||||
|
||||
public override void OnTimerComplete()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using Reactor.Localization.Utilities;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Localization.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Utilities.Colors;
|
||||
namespace MiraAPI.Colors;
|
||||
public sealed class CustomColor(Color32 mainColor, Color32 shadowColor, StringNames name)
|
||||
{
|
||||
public Color32 MainColor { get; } = mainColor;
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace MiraAPI.Utilities.Colors;
|
||||
namespace MiraAPI.Colors;
|
||||
|
||||
internal static class PaletteManager
|
||||
{
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.Utilities.Colors;
|
||||
namespace MiraAPI.Colors;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegisterCustomColorsAttribute : Attribute;
|
||||
@@ -14,7 +14,7 @@ public static class CustomGameModeManager
|
||||
/// <summary>
|
||||
/// List of registered gamemodes
|
||||
/// </summary>
|
||||
public static readonly Dictionary<int, CustomGameMode> GameModes = [];
|
||||
internal static readonly Dictionary<int, CustomGameMode> GameModes = [];
|
||||
|
||||
public static bool IsDefault()
|
||||
{
|
||||
@@ -24,7 +24,7 @@ public static class CustomGameModeManager
|
||||
/// <summary>
|
||||
/// Current gamemode
|
||||
/// </summary>
|
||||
public static CustomGameMode? ActiveMode = new DefaultMode();
|
||||
public static CustomGameMode? ActiveMode { get; internal set; } = new DefaultMode();
|
||||
|
||||
/// <summary>
|
||||
/// Set current gamemode
|
||||
|
||||
@@ -28,6 +28,7 @@ public abstract class AbstractOptionGroup
|
||||
/// </summary>
|
||||
public virtual Type AdvancedRole => null;
|
||||
|
||||
internal bool AllOptionsHidden = true;
|
||||
internal CategoryHeaderMasked Header;
|
||||
internal bool AllOptionsHidden { get; set; }
|
||||
|
||||
internal CategoryHeaderMasked Header { get; set; }
|
||||
}
|
||||
@@ -15,13 +15,13 @@ public class ModdedEnumOptionAttribute(string title, Type enumType, Type roleTyp
|
||||
|
||||
public override void SetValue(object value)
|
||||
{
|
||||
ModdedEnumOption opt = HolderOption as ModdedEnumOption;
|
||||
var opt = HolderOption as ModdedEnumOption;
|
||||
opt.SetValue((int)value);
|
||||
}
|
||||
|
||||
public override object GetValue()
|
||||
{
|
||||
ModdedEnumOption opt = HolderOption as ModdedEnumOption;
|
||||
var opt = HolderOption as ModdedEnumOption;
|
||||
return Enum.ToObject(enumType, opt.Value);
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,13 @@ public class ModdedNumberOptionAttribute(
|
||||
|
||||
public override void SetValue(object value)
|
||||
{
|
||||
ModdedNumberOption toggleOpt = HolderOption as ModdedNumberOption;
|
||||
var toggleOpt = HolderOption as ModdedNumberOption;
|
||||
toggleOpt.SetValue((float)value);
|
||||
}
|
||||
|
||||
public override object GetValue()
|
||||
{
|
||||
ModdedNumberOption toggleOpt = HolderOption as ModdedNumberOption;
|
||||
var toggleOpt = HolderOption as ModdedNumberOption;
|
||||
return toggleOpt.Value;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace MiraAPI.GameOptions.Attributes;
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public abstract class ModdedOptionAttribute(string title, Type roleType = null) : Attribute
|
||||
{
|
||||
public IModdedOption HolderOption { get; set; }
|
||||
public IModdedOption HolderOption { get; internal set; }
|
||||
|
||||
public string Title { get; private set; } = title;
|
||||
|
||||
|
||||
@@ -15,13 +15,13 @@ public class ModdedStringOptionAttribute(string title, string[] values, Type rol
|
||||
|
||||
public override void SetValue(object value)
|
||||
{
|
||||
ModdedStringOption opt = HolderOption as ModdedStringOption;
|
||||
var opt = HolderOption as ModdedStringOption;
|
||||
opt.SetValue((int)value);
|
||||
}
|
||||
|
||||
public override object GetValue()
|
||||
{
|
||||
ModdedStringOption opt = HolderOption as ModdedStringOption;
|
||||
var opt = HolderOption as ModdedStringOption;
|
||||
return opt.Value;
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,13 @@ public class ModdedToggleOptionAttribute(string title, Type roleType = null) : M
|
||||
|
||||
public override void SetValue(object value)
|
||||
{
|
||||
ModdedToggleOption toggleOpt = HolderOption as ModdedToggleOption;
|
||||
var toggleOpt = HolderOption as ModdedToggleOption;
|
||||
toggleOpt.SetValue((bool)value);
|
||||
}
|
||||
|
||||
public override object GetValue()
|
||||
{
|
||||
ModdedToggleOption toggleOpt = HolderOption as ModdedToggleOption;
|
||||
var toggleOpt = HolderOption as ModdedToggleOption;
|
||||
return toggleOpt.Value;
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,10 @@ public static class ModdedOptionsManager
|
||||
private static readonly Dictionary<PropertyInfo, ModdedOptionAttribute> OptionAttributes = new();
|
||||
private static readonly Dictionary<Type, AbstractOptionGroup> TypeToGroup = new();
|
||||
|
||||
public static readonly Dictionary<uint, IModdedOption> ModdedOptions = new();
|
||||
public static readonly List<AbstractOptionGroup> Groups = [];
|
||||
internal static readonly Dictionary<uint, IModdedOption> ModdedOptions = new();
|
||||
internal static readonly List<AbstractOptionGroup> Groups = [];
|
||||
|
||||
public static uint NextId => _nextId++;
|
||||
internal static uint NextId => _nextId++;
|
||||
private static uint _nextId = 1;
|
||||
|
||||
internal static bool RegisterGroup(Type type, MiraPluginInfo pluginInfo)
|
||||
@@ -127,7 +127,6 @@ public static class ModdedOptionsManager
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger<MiraApiPlugin>.Error("Handling option " + option.Title);
|
||||
option.HandleNetData(netData.Data);
|
||||
}
|
||||
}
|
||||
@@ -135,14 +134,14 @@ public static class ModdedOptionsManager
|
||||
|
||||
public static void PropertySetterPatch(MethodBase __originalMethod, object value)
|
||||
{
|
||||
ModdedOptionAttribute attribute = OptionAttributes.First(pair => pair.Key.GetSetMethod().Equals(__originalMethod)).Value;
|
||||
var attribute = OptionAttributes.First(pair => pair.Key.GetSetMethod().Equals(__originalMethod)).Value;
|
||||
|
||||
attribute?.SetValue(value);
|
||||
}
|
||||
|
||||
public static bool PropertyGetterPatch(MethodBase __originalMethod, ref object __result)
|
||||
{
|
||||
ModdedOptionAttribute attribute = OptionAttributes.First(pair => pair.Key.GetGetMethod().Equals(__originalMethod)).Value;
|
||||
var attribute = OptionAttributes.First(pair => pair.Key.GetGetMethod().Equals(__originalMethod)).Value;
|
||||
|
||||
if (attribute == null)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
}
|
||||
}
|
||||
public T Value { get; protected set; }
|
||||
public T DefaultValue { get; init; }
|
||||
public T DefaultValue { get; }
|
||||
public Action<T> ChangedEvent { get; set; }
|
||||
public string Title { get; }
|
||||
public StringNames StringName { get; }
|
||||
|
||||
@@ -150,7 +150,7 @@ public abstract class CustomActionButton
|
||||
/// True means the button is active, false means the button is disabled.
|
||||
/// </summary>
|
||||
/// <param name="role">The role of the local player.</param>
|
||||
public abstract bool Enabled(RoleBehaviour role);
|
||||
public abstract bool Enabled(RoleBehaviour? role);
|
||||
|
||||
/// <summary>
|
||||
/// Given that there is an effect, this method that runs when the effect ends.
|
||||
|
||||
@@ -5,9 +5,9 @@ using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
public static class CustomButtonManager
|
||||
internal static class CustomButtonManager
|
||||
{
|
||||
public static readonly List<CustomActionButton> CustomButtons = [];
|
||||
internal static readonly List<CustomActionButton> CustomButtons = [];
|
||||
|
||||
internal static void RegisterButton(Type buttonType)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,10 @@ public class ModifierComponent(IntPtr ptr) : MonoBehaviour(ptr)
|
||||
player = GetComponent<PlayerControl>();
|
||||
ActiveModifiers = [];
|
||||
|
||||
if (!player.AmOwner) return;
|
||||
if (!player.AmOwner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_modifierText = Helpers.CreateTextLabel("ModifierText", HudManager.Instance.transform, AspectPosition.EdgeAlignments.RightTop, new Vector3(10.1f, 3.5f, 0), textAlignment: TextAlignmentOptions.Right);
|
||||
_modifierText.verticalAlignment = VerticalAlignmentOptions.Top;
|
||||
|
||||
@@ -23,7 +23,7 @@ public static class ModifierManager
|
||||
return _nextId;
|
||||
}
|
||||
|
||||
public static void RegisterModifier(Type modifierType)
|
||||
internal static void RegisterModifier(Type modifierType)
|
||||
{
|
||||
if (!typeof(BaseModifier).IsAssignableFrom(modifierType))
|
||||
{
|
||||
@@ -34,9 +34,9 @@ public static class ModifierManager
|
||||
TypeToIdModifiers.Add(modifierType, _nextId);
|
||||
}
|
||||
|
||||
public static void AssignModifiers(List<PlayerControl> plrs)
|
||||
internal static void AssignModifiers(List<PlayerControl> plrs)
|
||||
{
|
||||
Random rand = new Random();
|
||||
var rand = new Random();
|
||||
|
||||
List<uint> filteredModifiers = [];
|
||||
|
||||
@@ -46,9 +46,9 @@ public static class ModifierManager
|
||||
var num = mod.GetAmountPerGame();
|
||||
var chance = mod.GetAssignmentChance();
|
||||
|
||||
for (int i = 0; i < num; i++)
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
int randomNum = rand.Next(100);
|
||||
var randomNum = rand.Next(100);
|
||||
|
||||
if (randomNum < Math.Clamp(chance, 0, 100))
|
||||
{
|
||||
@@ -72,17 +72,23 @@ public static class ModifierManager
|
||||
|
||||
if (plr.Data.Role is ICustomRole modRole)
|
||||
{
|
||||
if (!modRole.IsModifierApplicable(mod)) continue;
|
||||
if (!modRole.IsModifierApplicable(mod))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (plr.HasModifier(id) || mod.IsModifierValidOn(plr.Data.Role)) continue;
|
||||
if (plr.HasModifier(id) || mod.IsModifierValidOn(plr.Data.Role))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
shuffledModifiers.RemoveAt(0);
|
||||
ModifierComponent.RpcAddModifier(plr, id);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SyncAllModifiers(int targetId = -1)
|
||||
internal static void SyncAllModifiers(int targetId = -1)
|
||||
{
|
||||
var data = new List<NetData>();
|
||||
|
||||
@@ -104,7 +110,7 @@ public static class ModifierManager
|
||||
Rpc<SyncModifiersRpc>.Instance.Send(PlayerControl.LocalPlayer, data.ToArray(), true);
|
||||
}
|
||||
|
||||
public static void HandleSyncModifiers(NetData[] data)
|
||||
internal static void HandleSyncModifiers(NetData[] data)
|
||||
{
|
||||
foreach (var netData in data)
|
||||
{
|
||||
|
||||
@@ -8,12 +8,16 @@ public abstract class TimedModifier : BaseModifier
|
||||
public virtual bool AutoStart => false;
|
||||
public abstract void OnTimerComplete();
|
||||
|
||||
public bool TimerActive = false;
|
||||
public float TimeRemaining;
|
||||
public bool TimerActive { get; protected set; }
|
||||
|
||||
public float TimeRemaining { get; protected set; }
|
||||
|
||||
public override void FixedUpdate()
|
||||
{
|
||||
if (!Player.AmOwner) return;
|
||||
if (!Player.AmOwner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeRemaining > 0 && TimerActive)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ using Reactor.Networking.Rpc;
|
||||
namespace MiraAPI.Networking;
|
||||
|
||||
[RegisterCustomRpc((uint)MiraRpc.SyncModifiers)]
|
||||
public class SyncModifiersRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<MiraApiPlugin, NetData[]>(plugin, id)
|
||||
internal class SyncModifiersRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<MiraApiPlugin, NetData[]>(plugin, id)
|
||||
{
|
||||
public override RpcLocalHandling LocalHandling => RpcLocalHandling.None;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace MiraAPI.Networking;
|
||||
|
||||
// METHOD RPC DOESNT WORK WITH THE ARRAYS AND STUFF SO THIS IS HOW WE WILL DO IT FOR NOW
|
||||
[RegisterCustomRpc((uint)MiraRpc.SyncGameOptions)]
|
||||
public class SyncOptionsRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<MiraApiPlugin, NetData[]>(plugin, id)
|
||||
internal class SyncOptionsRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<MiraApiPlugin, NetData[]>(plugin, id)
|
||||
{
|
||||
public override RpcLocalHandling LocalHandling => RpcLocalHandling.None;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using Reactor.Networking.Rpc;
|
||||
namespace MiraAPI.Networking;
|
||||
|
||||
[RegisterCustomRpc((uint)MiraRpc.SyncRoleOptions)]
|
||||
public class SyncRoleOptionsRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<MiraApiPlugin, NetData[]>(plugin, id)
|
||||
internal class SyncRoleOptionsRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<MiraApiPlugin, NetData[]>(plugin, id)
|
||||
{
|
||||
|
||||
public override RpcLocalHandling LocalHandling => RpcLocalHandling.None;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using HarmonyLib;
|
||||
using InnerNet;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
@@ -22,6 +23,6 @@ public static class AmongUsClientSyncPatch
|
||||
|
||||
ModdedOptionsManager.SyncAllOptions(clientData.Id);
|
||||
CustomRoleManager.SyncAllRoleSettings(clientData.Id);
|
||||
// ModifierManager.SyncAllModifiers(clientData.Id);
|
||||
ModifierManager.SyncAllModifiers(clientData.Id);
|
||||
}
|
||||
}
|
||||
@@ -102,13 +102,18 @@ public static class HudManagerPatches
|
||||
|
||||
foreach (var button in CustomButtonManager.CustomButtons)
|
||||
{
|
||||
Transform location = button.Location switch
|
||||
var location = button.Location switch
|
||||
{
|
||||
ButtonLocation.BottomLeft => _bottomLeft.transform,
|
||||
ButtonLocation.BottomRight => bottomRight,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (location is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
button.CreateButton(location);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Utilities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -17,30 +15,32 @@ public static class VentPatches
|
||||
var @object = pc.Object;
|
||||
var role = @object.Data.Role;
|
||||
|
||||
List<BaseModifier> modifiers = @object.GetModifierComponent().ActiveModifiers;
|
||||
if (modifiers.Count > 0)
|
||||
var modifiers = @object.GetModifierComponent()?.ActiveModifiers;
|
||||
if (modifiers is null || modifiers.Count <= 0)
|
||||
{
|
||||
if (role.CanVent && modifiers.Any(x => !x.CanVent()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (role.CanVent)
|
||||
{
|
||||
case true when modifiers.Any(x => !x.CanVent()):
|
||||
couldUse = canUse = false;
|
||||
return;
|
||||
}
|
||||
else if (!role.CanVent && modifiers.Any(x => x.CanVent()))
|
||||
{
|
||||
case false when modifiers.Any(x => x.CanVent()):
|
||||
couldUse = true;
|
||||
}
|
||||
|
||||
var num = float.MaxValue;
|
||||
|
||||
canUse = couldUse;
|
||||
if (canUse)
|
||||
{
|
||||
var center = @object.Collider.bounds.center;
|
||||
var position = __instance.transform.position;
|
||||
num = Vector2.Distance(center, position);
|
||||
canUse &= num <= __instance.UsableDistance && !PhysicsHelpers.AnythingBetween(@object.Collider, center, position, Constants.ShipOnlyMask, false);
|
||||
}
|
||||
__result = num;
|
||||
break;
|
||||
}
|
||||
|
||||
var num = float.MaxValue;
|
||||
|
||||
canUse = couldUse;
|
||||
if (canUse)
|
||||
{
|
||||
var center = @object.Collider.bounds.center;
|
||||
var position = __instance.transform.position;
|
||||
num = Vector2.Distance(center, position);
|
||||
canUse &= num <= __instance.UsableDistance && !PhysicsHelpers.AnythingBetween(@object.Collider, center, position, Constants.ShipOnlyMask, false);
|
||||
}
|
||||
__result = num;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Localization.Utilities;
|
||||
@@ -25,10 +24,10 @@ public static class GameOptionsMenuPatch
|
||||
return;
|
||||
}
|
||||
|
||||
float num = 2.1f;
|
||||
var num = 2.1f;
|
||||
var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.GroupVisible.Invoke() && x.AdvancedRole is null);
|
||||
|
||||
foreach (AbstractOptionGroup group in filteredGroups)
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
var filteredOpts = group.Options.Where(x => x.Visible.Invoke()).ToList();
|
||||
if (filteredOpts.Count == 0)
|
||||
@@ -44,7 +43,7 @@ public static class GameOptionsMenuPatch
|
||||
|
||||
foreach (var opt in group.Options)
|
||||
{
|
||||
OptionBehaviour newOpt = opt.OptionBehaviour;
|
||||
var newOpt = opt.OptionBehaviour;
|
||||
|
||||
if (opt.Visible.Invoke() == false)
|
||||
{
|
||||
@@ -82,9 +81,9 @@ public static class GameOptionsMenuPatch
|
||||
|
||||
var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.AdvancedRole is null);
|
||||
|
||||
foreach (AbstractOptionGroup group in filteredGroups)
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer);
|
||||
var categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer);
|
||||
categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20);
|
||||
if (group.GroupColor != Color.clear)
|
||||
{
|
||||
@@ -96,34 +95,35 @@ public static class GameOptionsMenuPatch
|
||||
categoryHeaderMasked.gameObject.SetActive(false);
|
||||
group.Header = categoryHeaderMasked;
|
||||
|
||||
TextMeshPro newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform);
|
||||
var newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform);
|
||||
newText.text = $"<size=70%>(Click to open)</size>";
|
||||
newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f);
|
||||
newText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
|
||||
List<OptionBehaviour> newOpts = [];
|
||||
foreach (var opt in group.Options)
|
||||
var options = group.Options.Select(opt => opt.CreateOption(__instance.checkboxOrigin,
|
||||
__instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.settingsContainer));
|
||||
|
||||
foreach (var newOpt in options)
|
||||
{
|
||||
OptionBehaviour newOpt = opt.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.settingsContainer);
|
||||
newOpt.SetClickMask(__instance.ButtonClickMask);
|
||||
|
||||
SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
for (int i = 0; i < componentsInChildren.Length; i++)
|
||||
foreach (var renderer in componentsInChildren)
|
||||
{
|
||||
if (group.GroupColor != Color.clear)
|
||||
{
|
||||
componentsInChildren[i].color = group.GroupColor.GetAlternateColor();
|
||||
if (componentsInChildren[i].transform.parent.TryGetComponent<GameOptionButton>(out var btn))
|
||||
renderer.color = group.GroupColor.GetAlternateColor();
|
||||
if (renderer.transform.parent.TryGetComponent<GameOptionButton>(out var btn))
|
||||
{
|
||||
btn.interactableColor = group.GroupColor.GetAlternateColor();
|
||||
btn.interactableHoveredColor = Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
componentsInChildren[i].material.SetInt(PlayerMaterial.MaskLayer, 20);
|
||||
renderer.material.SetInt(PlayerMaterial.MaskLayer, 20);
|
||||
}
|
||||
|
||||
foreach (TextMeshPro textMeshPro in newOpt.GetComponentsInChildren<TextMeshPro>(true))
|
||||
foreach (var textMeshPro in newOpt.GetComponentsInChildren<TextMeshPro>(true))
|
||||
{
|
||||
if (group.GroupColor != Color.clear)
|
||||
{
|
||||
@@ -138,7 +138,7 @@ public static class GameOptionsMenuPatch
|
||||
{
|
||||
toggle.CheckMark.sprite = MiraAssets.Checkmark.LoadAsset();
|
||||
|
||||
SpriteRenderer rend = toggle.CheckMark.transform.parent.FindChild("ActiveSprite").GetComponent<SpriteRenderer>();
|
||||
var rend = toggle.CheckMark.transform.parent.FindChild("ActiveSprite").GetComponent<SpriteRenderer>();
|
||||
rend.sprite = MiraAssets.CheckmarkBox.LoadAsset();
|
||||
rend.color = group.GroupColor;
|
||||
}
|
||||
@@ -146,15 +146,14 @@ public static class GameOptionsMenuPatch
|
||||
__instance.Children.Add(newOpt);
|
||||
|
||||
newOpt.Initialize();
|
||||
newOpts.Add(newOpt);
|
||||
newOpt.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
BoxCollider2D boxCol = categoryHeaderMasked.gameObject.AddComponent<BoxCollider2D>();
|
||||
var boxCol = categoryHeaderMasked.gameObject.AddComponent<BoxCollider2D>();
|
||||
boxCol.size = new Vector2(7, 0.7f);
|
||||
boxCol.offset = new Vector2(1.5f, -0.3f);
|
||||
|
||||
PassiveButton headerBtn = categoryHeaderMasked.gameObject.AddComponent<PassiveButton>();
|
||||
var headerBtn = categoryHeaderMasked.gameObject.AddComponent<PassiveButton>();
|
||||
headerBtn.ClickSound = __instance.BackButton.GetComponent<PassiveButton>().ClickSound;
|
||||
headerBtn.OnMouseOver = new UnityEvent();
|
||||
headerBtn.OnMouseOut = new UnityEvent();
|
||||
@@ -173,30 +172,32 @@ public static class GameOptionsMenuPatch
|
||||
[HarmonyPatch(nameof(GameOptionsMenu.Initialize))]
|
||||
public static bool InitPatch(GameOptionsMenu __instance)
|
||||
{
|
||||
if (__instance.Children == null || __instance.Children.Count == 0)
|
||||
if (__instance.Children != null && __instance.Children.Count != 0)
|
||||
{
|
||||
__instance.MapPicker.gameObject.SetActive(true);
|
||||
__instance.MapPicker.Initialize(20);
|
||||
BaseGameSetting mapNameSetting = GameManager.Instance.GameSettingsList.MapNameSetting;
|
||||
__instance.MapPicker.SetUpFromData(mapNameSetting, 20);
|
||||
__instance.Children = new Il2CppSystem.Collections.Generic.List<OptionBehaviour>();
|
||||
__instance.Children.Add(__instance.MapPicker);
|
||||
__instance.CreateSettings();
|
||||
__instance.cachedData = GameOptionsManager.Instance.CurrentGameOptions;
|
||||
foreach (var optionBehaviour in __instance.Children)
|
||||
return false;
|
||||
}
|
||||
|
||||
__instance.MapPicker.gameObject.SetActive(true);
|
||||
__instance.MapPicker.Initialize(20);
|
||||
var mapNameSetting = GameManager.Instance.GameSettingsList.MapNameSetting;
|
||||
__instance.MapPicker.SetUpFromData(mapNameSetting, 20);
|
||||
__instance.Children = new Il2CppSystem.Collections.Generic.List<OptionBehaviour>();
|
||||
__instance.Children.Add(__instance.MapPicker);
|
||||
__instance.CreateSettings();
|
||||
__instance.cachedData = GameOptionsManager.Instance.CurrentGameOptions;
|
||||
foreach (var optionBehaviour in __instance.Children)
|
||||
{
|
||||
if (AmongUsClient.Instance && !AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
if (AmongUsClient.Instance && !AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
optionBehaviour.SetAsPlayer();
|
||||
}
|
||||
|
||||
if (optionBehaviour.IsCustom())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
optionBehaviour.OnValueChanged = new System.Action<OptionBehaviour>(__instance.ValueChanged);
|
||||
optionBehaviour.SetAsPlayer();
|
||||
}
|
||||
|
||||
if (optionBehaviour.IsCustom())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
optionBehaviour.OnValueChanged = new System.Action<OptionBehaviour>(__instance.ValueChanged);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -30,8 +30,8 @@ public static class GameSettingMenuPatches
|
||||
_roleBtnOgPos = __instance.RoleSettingsButton.transform.localPosition;
|
||||
__instance.transform.FindChild("GameSettingsLabel").gameObject.SetActive(false);
|
||||
|
||||
Transform helpThing = __instance.transform.FindChild("What Is This?");
|
||||
GameObject tmpText = Object.Instantiate(helpThing.transform.FindChild("InfoText"), helpThing.parent).gameObject;
|
||||
var helpThing = __instance.transform.FindChild("What Is This?");
|
||||
var tmpText = Object.Instantiate(helpThing.transform.FindChild("InfoText"), helpThing.parent).gameObject;
|
||||
|
||||
tmpText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
tmpText.name = "SelectedMod";
|
||||
@@ -45,14 +45,14 @@ public static class GameSettingMenuPatches
|
||||
|
||||
_text.alignment = TextAlignmentOptions.Center;
|
||||
|
||||
GameObject nextButton = Object.Instantiate(__instance.BackButton, __instance.BackButton.transform.parent).gameObject;
|
||||
var nextButton = Object.Instantiate(__instance.BackButton, __instance.BackButton.transform.parent).gameObject;
|
||||
nextButton.transform.localPosition = new Vector3(-2.2663f, 1.5272f, -25f);
|
||||
nextButton.name = "RightArrowButton";
|
||||
nextButton.transform.FindChild("Inactive").gameObject.GetComponent<SpriteRenderer>().sprite = MiraAssets.NextButton.LoadAsset();
|
||||
nextButton.transform.FindChild("Active").gameObject.GetComponent<SpriteRenderer>().sprite = MiraAssets.NextButtonActive.LoadAsset();
|
||||
nextButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
||||
|
||||
PassiveButton passiveButton = nextButton.gameObject.GetComponent<PassiveButton>();
|
||||
var passiveButton = nextButton.gameObject.GetComponent<PassiveButton>();
|
||||
passiveButton.OnClick = new ButtonClickedEvent();
|
||||
passiveButton.OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
@@ -63,7 +63,7 @@ public static class GameSettingMenuPatches
|
||||
}
|
||||
}));
|
||||
|
||||
GameObject backButton = Object.Instantiate(nextButton, __instance.BackButton.transform.parent).gameObject;
|
||||
var backButton = Object.Instantiate(nextButton, __instance.BackButton.transform.parent).gameObject;
|
||||
backButton.transform.localPosition = new Vector3(-4.4209f, 1.5272f, -25f);
|
||||
backButton.name = "LeftArrowButton";
|
||||
backButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().Destroy();
|
||||
@@ -105,12 +105,12 @@ public static class GameSettingMenuPatches
|
||||
|
||||
if (CurrentSelectedMod != 0)
|
||||
{
|
||||
if (SelectedMod.Options.Where(x=>x.AdvancedRole==null).ToList().Count == 0)
|
||||
if (SelectedMod?.Options.Where(x=>x.AdvancedRole==null).ToList().Count == 0)
|
||||
{
|
||||
menu.GameSettingsButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (SelectedMod.CustomRoles.Count == 0)
|
||||
if (SelectedMod?.CustomRoles.Count == 0)
|
||||
{
|
||||
menu.RoleSettingsButton.gameObject.SetActive(false);
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public static class GameSettingMenuPatches
|
||||
roles.scrollBar.ScrollToTop();
|
||||
}
|
||||
|
||||
if (settings?.Children != null && SelectedMod.OptionGroups.Count != 0)
|
||||
if (settings?.Children != null && SelectedMod?.OptionGroups.Count != 0)
|
||||
{
|
||||
foreach (var child in settings.Children)
|
||||
{
|
||||
|
||||
@@ -360,7 +360,7 @@ public static class LobbyViewPanePatches
|
||||
for (var i = 0; i < filteredOptions.Count; i++)
|
||||
{
|
||||
var option = filteredOptions[i];
|
||||
BaseGameSetting baseGameSetting = option.Data;
|
||||
var baseGameSetting = option.Data;
|
||||
var viewSettingsInfoPanel = Object.Instantiate(viewPanel.infoPanelOrigin, viewPanel.transform, true);
|
||||
viewSettingsInfoPanel.transform.localScale = Vector3.one;
|
||||
viewSettingsInfoPanel.transform.localPosition = new Vector3(viewPanel.xPosStart, num, -2f);
|
||||
|
||||
@@ -41,7 +41,7 @@ public static class RoleSettingMenuPatches
|
||||
return true;
|
||||
}
|
||||
|
||||
float num = 0.522f;
|
||||
var num = 0.522f;
|
||||
|
||||
__instance.AllButton.transform.parent.gameObject.SetActive(false);
|
||||
__instance.AllButton.gameObject.SetActive(false);
|
||||
@@ -51,7 +51,7 @@ public static class RoleSettingMenuPatches
|
||||
hitbox.localPosition = new Vector3(0.3297f, -.6333f, 4f);
|
||||
hitbox.localScale = new Vector3(1, 1.2f, 1);
|
||||
|
||||
int num3 = 0;
|
||||
var num3 = 0;
|
||||
|
||||
var crewRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values
|
||||
.OfType<ICustomRole>()
|
||||
@@ -61,7 +61,7 @@ public static class RoleSettingMenuPatches
|
||||
if (crewRoles.Count > 0)
|
||||
{
|
||||
|
||||
CategoryHeaderEditRole categoryHeaderEditRole = Object.Instantiate(__instance.categoryHeaderEditRoleOrigin, Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform);
|
||||
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;
|
||||
@@ -81,7 +81,7 @@ public static class RoleSettingMenuPatches
|
||||
if (impRoles.Count > 0)
|
||||
{
|
||||
num -= 0.4f;
|
||||
CategoryHeaderEditRole categoryHeaderEditRole2 = Object.Instantiate(__instance.categoryHeaderEditRoleOrigin,
|
||||
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);
|
||||
@@ -103,7 +103,7 @@ public static class RoleSettingMenuPatches
|
||||
if (neutRoles.Count > 0)
|
||||
{
|
||||
num -= 0.4f;
|
||||
CategoryHeaderEditRole categoryHeaderEditRole3 = Object.Instantiate(__instance.categoryHeaderEditRoleOrigin,
|
||||
var categoryHeaderEditRole3 = Object.Instantiate(__instance.categoryHeaderEditRoleOrigin,
|
||||
Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform);
|
||||
categoryHeaderEditRole3.SetHeader(StringNames.None, 20);
|
||||
categoryHeaderEditRole3.Title.text = "Neutral Roles";
|
||||
@@ -126,12 +126,7 @@ public static class RoleSettingMenuPatches
|
||||
[HarmonyPatch(nameof(RolesSettingsMenu.Update))]
|
||||
public static bool UpdatePatch()
|
||||
{
|
||||
if (GameSettingMenuPatches.CurrentSelectedMod == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return GameSettingMenuPatches.CurrentSelectedMod == 0;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
@@ -183,7 +178,7 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
__instance.advancedSettingChildren.Clear();
|
||||
|
||||
float num = -0.872f;
|
||||
var num = -0.872f;
|
||||
|
||||
var filteredOptions = GameSettingMenuPatches.SelectedMod.Options.Where(x => x.AdvancedRole == role.GetType());
|
||||
|
||||
@@ -194,16 +189,16 @@ public static class RoleSettingMenuPatches
|
||||
continue;
|
||||
}
|
||||
|
||||
OptionBehaviour newOpt = option.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.AdvancedRolesSettings.transform);
|
||||
var newOpt = option.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.AdvancedRolesSettings.transform);
|
||||
newOpt.transform.localPosition = new Vector3(2.17f, num, -2f);
|
||||
newOpt.SetClickMask(__instance.ButtonClickMask);
|
||||
|
||||
SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
for (int i = 0; i < componentsInChildren.Length; i++)
|
||||
foreach (var renderer in componentsInChildren)
|
||||
{
|
||||
componentsInChildren[i].material.SetInt(PlayerMaterial.MaskLayer, 20);
|
||||
renderer.material.SetInt(PlayerMaterial.MaskLayer, 20);
|
||||
}
|
||||
foreach (TextMeshPro textMeshPro in newOpt.GetComponentsInChildren<TextMeshPro>(true))
|
||||
foreach (var textMeshPro in newOpt.GetComponentsInChildren<TextMeshPro>(true))
|
||||
{
|
||||
textMeshPro.fontMaterial.SetFloat(ShaderID.StencilComp, 3f);
|
||||
textMeshPro.fontMaterial.SetFloat(ShaderID.Stencil, 20);
|
||||
@@ -221,7 +216,7 @@ public static class RoleSettingMenuPatches
|
||||
}
|
||||
private static void ChangeTab(RoleBehaviour role, RolesSettingsMenu __instance)
|
||||
{
|
||||
ICustomRole customRole = role as ICustomRole;
|
||||
var customRole = role as ICustomRole;
|
||||
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
||||
__instance.roleTitleText.text = DestroyableSingleton<TranslationController>.Instance.GetString(role.StringName, []);
|
||||
__instance.roleScreenshot.sprite = Sprite.Create(customRole.OptionsScreenshot.LoadAsset().texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100);
|
||||
@@ -246,8 +241,8 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
public static void CreateQuotaOption(RolesSettingsMenu __instance, RoleBehaviour role, ref float yPos, int index)
|
||||
{
|
||||
ICustomRole customRole = role as ICustomRole;
|
||||
RoleOptionSetting roleOptionSetting = Object.Instantiate(__instance.roleOptionSettingOrigin, Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform);
|
||||
var customRole = role as ICustomRole;
|
||||
var roleOptionSetting = Object.Instantiate(__instance.roleOptionSettingOrigin, Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform);
|
||||
roleOptionSetting.transform.localPosition = new Vector3(-0.15f, yPos, -2f);
|
||||
roleOptionSetting.SetRole(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions, role, 20);
|
||||
roleOptionSetting.labelSprite.color = customRole.RoleColor;
|
||||
@@ -259,16 +254,16 @@ public static class RoleSettingMenuPatches
|
||||
roleOptionSetting.titleText.color = customRole.RoleColor.GetAlternateColor();
|
||||
roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
||||
|
||||
PassiveButton newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform);
|
||||
var newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform);
|
||||
newButton.name = "ConfigButton";
|
||||
newButton.transform.localPosition = new Vector3(0.4473f, -0.3f, -2f);
|
||||
newButton.transform.FindChild("Text_TMP").gameObject.DestroyImmediate();
|
||||
newButton.activeSprites.Destroy();
|
||||
|
||||
SpriteRenderer btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent<SpriteRenderer>();
|
||||
var btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent<SpriteRenderer>();
|
||||
btnRend.sprite = MiraAssets.Cog.LoadAsset();
|
||||
|
||||
GameOptionButton passiveButton = newButton.GetComponent<GameOptionButton>();
|
||||
var passiveButton = newButton.GetComponent<GameOptionButton>();
|
||||
passiveButton.OnClick = new ButtonClickedEvent();
|
||||
passiveButton.interactableColor = btnRend.color = customRole.RoleColor.GetAlternateColor();
|
||||
passiveButton.interactableHoveredColor = Color.white;
|
||||
|
||||
@@ -13,7 +13,10 @@ public static class PlayerControlPatches
|
||||
[HarmonyPatch(nameof(PlayerControl.Start))]
|
||||
public static void PlayerControlStartPostfix(PlayerControl __instance)
|
||||
{
|
||||
if (__instance.gameObject.TryGetComponent<ModifierComponent>(out var comp)) comp.DestroyImmediate();
|
||||
if (__instance.gameObject.TryGetComponent<ModifierComponent>(out var comp))
|
||||
{
|
||||
comp.DestroyImmediate();
|
||||
}
|
||||
|
||||
__instance.gameObject.AddComponent<ModifierComponent>();
|
||||
}
|
||||
@@ -34,6 +37,11 @@ public static class PlayerControlPatches
|
||||
|
||||
foreach (var button in CustomButtonManager.CustomButtons)
|
||||
{
|
||||
if (__instance.Data?.Role != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!button.Enabled(__instance.Data?.Role))
|
||||
{
|
||||
continue;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Colors;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Colors;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
|
||||
@@ -14,7 +14,10 @@ public static class RoleManagerPatches
|
||||
[HarmonyPatch(nameof(RoleManager.SelectRoles))]
|
||||
public static void ModifierSelectionPatches(RoleManager __instance)
|
||||
{
|
||||
if (!AmongUsClient.Instance.AmHost) return;
|
||||
if (!AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ModifierManager.AssignModifiers(PlayerControl.AllPlayerControls.ToArray().Where(plr => !plr.Data.IsDead && !plr.Data.Disconnected).ToList());
|
||||
}
|
||||
@@ -28,16 +31,18 @@ public static class RoleManagerPatches
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plr.Data.Role is ICustomRole role)
|
||||
if (plr.Data.Role is not ICustomRole role)
|
||||
{
|
||||
Debug.Log(role.RoleName);
|
||||
if (role.GhostRole != RoleTypes.CrewmateGhost && role.GhostRole != RoleTypes.ImpostorGhost)
|
||||
{
|
||||
plr.RpcSetRole(role.GhostRole);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
if (role.GhostRole is RoleTypes.CrewmateGhost or RoleTypes.ImpostorGhost)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
plr.RpcSetRole(role.GhostRole);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,19 +14,20 @@ public static class RoleOptionsCollectionPatch
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV08.GetChancePerGame))]
|
||||
public static bool GetChancePrefix([HarmonyArgument(0)] RoleTypes roleType, ref int __result)
|
||||
{
|
||||
if (CustomRoleManager.GetCustomRoleBehaviour(roleType, out var customRole))
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(roleType, out var customRole))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (customRole.HideSettings)
|
||||
{
|
||||
if (customRole.HideSettings)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
customRole.ParentMod.PluginConfig.TryGetEntry<int>(customRole.ChanceConfigDefinition, out var entry);
|
||||
__result = entry.Value;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
customRole.ParentMod.PluginConfig.TryGetEntry<int>(customRole.ChanceConfigDefinition, out var entry);
|
||||
__result = entry.Value;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -36,18 +37,18 @@ public static class RoleOptionsCollectionPatch
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV08.GetNumPerGame))]
|
||||
public static bool GetNumPrefix([HarmonyArgument(0)] RoleTypes roleType, ref int __result)
|
||||
{
|
||||
if (CustomRoleManager.GetCustomRoleBehaviour(roleType, out var customRole))
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(roleType, out var customRole))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (customRole.HideSettings)
|
||||
{
|
||||
if (customRole.HideSettings)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
customRole.ParentMod.PluginConfig.TryGetEntry<int>(customRole.NumConfigDefinition, out var entry);
|
||||
__result = entry.Value;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
customRole.ParentMod.PluginConfig.TryGetEntry<int>(customRole.NumConfigDefinition, out var entry);
|
||||
__result = entry.Value;
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,23 +14,23 @@ namespace MiraAPI.Patches.Roles;
|
||||
[HarmonyPatch]
|
||||
public static class TaskAdderPatch
|
||||
{
|
||||
public static TaskFolder RolesFolder;
|
||||
public static System.Collections.Generic.Dictionary<string, string> ModsFolders = new System.Collections.Generic.Dictionary<string, string>();
|
||||
private static TaskFolder _rolesFolder;
|
||||
private static readonly System.Collections.Generic.Dictionary<string, string> ModsFolders = new();
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(TaskAdderGame), nameof(TaskAdderGame.Begin))]
|
||||
public static void AddRolesFolder(TaskAdderGame __instance)
|
||||
{
|
||||
RolesFolder = Object.Instantiate(__instance.RootFolderPrefab, __instance.transform);
|
||||
RolesFolder.gameObject.SetActive(false);
|
||||
RolesFolder.FolderName = "Roles";
|
||||
RolesFolder.name = "RolesFolder";
|
||||
_rolesFolder = Object.Instantiate(__instance.RootFolderPrefab, __instance.transform);
|
||||
_rolesFolder.gameObject.SetActive(false);
|
||||
_rolesFolder.FolderName = "Roles";
|
||||
_rolesFolder.name = "RolesFolder";
|
||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins.Values)
|
||||
{
|
||||
var newFolder = Object.Instantiate(__instance.RootFolderPrefab, __instance.transform);
|
||||
newFolder.FolderName = newFolder.name = plugin.PluginInfo.Metadata.Name;
|
||||
newFolder.gameObject.SetActive(false);
|
||||
RolesFolder.SubFolders.Add(newFolder);
|
||||
_rolesFolder.SubFolders.Add(newFolder);
|
||||
|
||||
if (!ModsFolders.ContainsKey(plugin.PluginInfo.Metadata.Name))
|
||||
{
|
||||
@@ -38,7 +38,7 @@ public static class TaskAdderPatch
|
||||
}
|
||||
}
|
||||
|
||||
__instance.Root.SubFolders.Add(RolesFolder);
|
||||
__instance.Root.SubFolders.Add(_rolesFolder);
|
||||
|
||||
__instance.GoToRoot();
|
||||
}
|
||||
@@ -47,12 +47,9 @@ public static class TaskAdderPatch
|
||||
[HarmonyPatch(typeof(TaskAddButton), "Role", MethodType.Setter)]
|
||||
public static void RoleGetterPatch(TaskAddButton __instance)
|
||||
{
|
||||
if (__instance.role is ICustomRole lpRole)
|
||||
if (__instance.role is ICustomRole { IsNeutral: true })
|
||||
{
|
||||
if (lpRole.IsNeutral)
|
||||
{
|
||||
__instance.FileImage.color = Color.gray;
|
||||
}
|
||||
__instance.FileImage.color = Color.gray;
|
||||
}
|
||||
|
||||
__instance.RolloverHandler.OutColor = __instance.FileImage.color;
|
||||
@@ -155,15 +152,15 @@ public static class TaskAdderPatch
|
||||
}
|
||||
if (taskFolder.FolderName == "Roles")
|
||||
{
|
||||
for (int m = 0; m < DestroyableSingleton<RoleManager>.Instance.AllRoles.Length; m++)
|
||||
for (var m = 0; m < DestroyableSingleton<RoleManager>.Instance.AllRoles.Length; m++)
|
||||
{
|
||||
RoleBehaviour roleBehaviour = DestroyableSingleton<RoleManager>.Instance.AllRoles[m];
|
||||
var roleBehaviour = DestroyableSingleton<RoleManager>.Instance.AllRoles[m];
|
||||
if (roleBehaviour.Role != RoleTypes.ImpostorGhost && roleBehaviour.Role != RoleTypes.CrewmateGhost && !CustomRoleManager.CustomRoles.ContainsKey((ushort)roleBehaviour.Role))
|
||||
{
|
||||
TaskAddButton taskAddButton2 = Object.Instantiate(__instance.RoleButton);
|
||||
var taskAddButton2 = Object.Instantiate(__instance.RoleButton);
|
||||
taskAddButton2.SafePositionWorld = __instance.SafePositionWorld;
|
||||
taskAddButton2.Text.text = "Be_" + roleBehaviour.NiceName + ".exe";
|
||||
__instance.AddFileAsChild(RolesFolder, taskAddButton2, ref num, ref num2, ref num3);
|
||||
__instance.AddFileAsChild(_rolesFolder, taskAddButton2, ref num, ref num2, ref num3);
|
||||
taskAddButton2.Role = roleBehaviour;
|
||||
if (taskAddButton2 != null && taskAddButton2.Button != null)
|
||||
{
|
||||
@@ -183,9 +180,9 @@ public static class TaskAdderPatch
|
||||
}
|
||||
}
|
||||
|
||||
if (ModsFolders.TryGetValue(taskFolder.FolderName, out string guid))
|
||||
if (ModsFolders.TryGetValue(taskFolder.FolderName, out var guid))
|
||||
{
|
||||
MiraPluginInfo plugin = MiraPluginManager.Instance.GetPluginByGuid(guid);
|
||||
var plugin = MiraPluginManager.Instance.GetPluginByGuid(guid);
|
||||
for (var m = 0; m < plugin.CustomRoles.Count; m++)
|
||||
{
|
||||
var roleBehaviour = plugin.CustomRoles.ElementAt(m).Value;
|
||||
@@ -194,7 +191,7 @@ public static class TaskAdderPatch
|
||||
var taskAddButton2 = Object.Instantiate(__instance.RoleButton);
|
||||
taskAddButton2.SafePositionWorld = __instance.SafePositionWorld;
|
||||
taskAddButton2.Text.text = "Be_" + roleBehaviour.NiceName + ".exe";
|
||||
__instance.AddFileAsChild(RolesFolder, taskAddButton2, ref num, ref num2, ref num3);
|
||||
__instance.AddFileAsChild(_rolesFolder, taskAddButton2, ref num, ref num2, ref num3);
|
||||
taskAddButton2.Role = roleBehaviour;
|
||||
if (taskAddButton2 != null && taskAddButton2.Button != null)
|
||||
{
|
||||
|
||||
@@ -17,5 +17,5 @@ public class MiraPluginInfo(IMiraPlugin miraPlugin, PluginInfo info)
|
||||
public readonly List<IModdedOption> Options = [];
|
||||
|
||||
public readonly Dictionary<ushort, RoleBehaviour> CustomRoles = [];
|
||||
public readonly Dictionary<int, CustomGameMode> GameModes = [];
|
||||
internal readonly Dictionary<int, CustomGameMode> GameModes = [];
|
||||
}
|
||||
@@ -4,12 +4,12 @@ using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Colors;
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MiraAPI.Colors;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Networking;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace MiraAPI.Roles;
|
||||
|
||||
public class RoleId
|
||||
public static class RoleId
|
||||
{
|
||||
public static ushort Get<T>() where T : RoleBehaviour
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Utilities.Assets;
|
||||
@@ -9,7 +10,7 @@ public class LoadableResourceAsset(string path) : LoadableAsset<Sprite>
|
||||
|
||||
public override Sprite LoadAsset()
|
||||
{
|
||||
if (LoadedAsset != null)
|
||||
if (LoadedAsset)
|
||||
{
|
||||
return LoadedAsset;
|
||||
}
|
||||
@@ -20,7 +21,7 @@ public class LoadableResourceAsset(string path) : LoadableAsset<Sprite>
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.LogError($"Not loading, invalid asset: {path}");
|
||||
Logger<MiraApiPlugin>.Error($"Not loading, invalid asset: {path}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,17 @@ namespace MiraAPI.Utilities.Assets;
|
||||
/// </summary>
|
||||
public static class SpriteTools
|
||||
{
|
||||
private delegate bool DLoadImage(IntPtr tex, IntPtr data, bool markNonReadable);
|
||||
public delegate bool DLoadImage(IntPtr tex, IntPtr data, bool markNonReadable);
|
||||
|
||||
private static DLoadImage _iCallLoadImage;
|
||||
public static DLoadImage ICallLoadImage;
|
||||
|
||||
private static bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable)
|
||||
public static bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable)
|
||||
{
|
||||
_iCallLoadImage ??= IL2CPP.ResolveICall<DLoadImage>("UnityEngine.ImageConversion::LoadImage");
|
||||
ICallLoadImage ??= IL2CPP.ResolveICall<DLoadImage>("UnityEngine.ImageConversion::LoadImage");
|
||||
|
||||
var il2CPPArray = (Il2CppStructArray<byte>)data;
|
||||
|
||||
return _iCallLoadImage.Invoke(tex.Pointer, il2CPPArray.Pointer, markNonReadable);
|
||||
return ICallLoadImage.Invoke(tex.Pointer, il2CPPArray.Pointer, markNonReadable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -82,7 +82,7 @@ public static class Extensions
|
||||
System.Random rnd = new();
|
||||
while (list.Count > 0)
|
||||
{
|
||||
int index = rnd.Next(0, list.Count);
|
||||
var index = rnd.Next(0, list.Count);
|
||||
randomizedList.Add(list[index]);
|
||||
list.RemoveAt(index);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user