use nameof instead of strings

This commit is contained in:
XtraCube committed 2024-06-20 13:42:11 -04:00
1 parent 4c4d0ea1ca
commit 18853329f4
14 files changed
+79 -98

No files matched your search

+3 -1
View File
@@ -7,6 +7,8 @@ using UnityEngine.Events;
using Object = UnityEngine.Object;
namespace MiraAPI.GameOptions.UI;
/*
public static class ModdedOptionsTab
{
public static readonly List<GameObject> CustomTabs = [];
@@ -151,4 +153,4 @@ public static class ModdedOptionsTab
return newSettings;
}
}
}*/
+6 -3
View File
@@ -18,7 +18,8 @@ namespace MiraAPI.Patches
/// Custom role tab
private static TaskPanelBehaviour _roleTab;
[HarmonyPostfix, HarmonyPatch("Update")]
[HarmonyPostfix]
[HarmonyPatch(nameof(HudManager.Update))]
public static void UpdatePostfix(HudManager __instance)
{
var local = PlayerControl.LocalPlayer;
@@ -69,7 +70,8 @@ namespace MiraAPI.Patches
/// <summary>
/// Create custom buttons parent
/// </summary>
[HarmonyPostfix, HarmonyPatch("Start")]
[HarmonyPostfix]
[HarmonyPatch(nameof(HudManager.Start))]
public static void StartPostfix(HudManager __instance)
{
if (!_bottomLeft)
@@ -104,7 +106,8 @@ namespace MiraAPI.Patches
/// <summary>
/// Make sure all launchpad hud elements are inactive/active when appropriate
/// </summary>
[HarmonyPostfix, HarmonyPatch("SetHudActive", typeof(PlayerControl), typeof(RoleBehaviour), typeof(bool))]
[HarmonyPostfix]
[HarmonyPatch(nameof(HudManager.SetHudActive), typeof(PlayerControl), typeof(RoleBehaviour), typeof(bool))]
public static void SetHudActivePostfix(HudManager __instance, [HarmonyArgument(0)] PlayerControl player, [HarmonyArgument(1)] RoleBehaviour roleBehaviour, [HarmonyArgument(2)] bool isActive)
{
if (player.Data == null)
+12 -12
View File
@@ -7,13 +7,14 @@ using Object = UnityEngine.Object;
namespace MiraAPI.Patches.Options;
/*
[HarmonyPatch(typeof(GameOptionsMenu))]
public static class GameOptionsMenuPatch
{
/// <summary>
/// Change the OnValueChanged action for all custom game options
/// </summary>
[HarmonyPostfix, HarmonyPatch("Start")]
[HarmonyPostfix, HarmonyPatch(nameof(GameOptionsMenu.Start))]
public static void StartPostfix(GameOptionsMenu __instance)
{
foreach (var customOption in ModdedOptionsManager.Options)
@@ -26,26 +27,25 @@ public static class GameOptionsMenuPatch
customOption.OptionBehaviour.OnValueChanged = (Action<OptionBehaviour>)customOption.ValueChanged;
}
}
private static GameSettingMenu menu;
/// <summary>
/// Set the position and offset of all custom game options
/// </summary>
[HarmonyPostfix, HarmonyPatch("Update")]
[HarmonyPostfix, HarmonyPatch(nameof(GameOptionsMenu.Update))]
public static void UpdatePostfix(GameOptionsMenu __instance)
{
if (!menu)
{
menu = Object.FindObjectsOfType<GameSettingMenu>().First();
}
if (menu.RegularGameSettings.active || menu.RolesSettings.gameObject.active || menu.HideNSeekSettings.active)
if (!GameSettingMenu.Instance)
{
return;
}
if (GameSettingMenu.Instance.GameSettingsTab.gameObject.active || GameSettingMenu.Instance.RoleSettingsTab.gameObject.active)
{
return;
}
var startOffset = 2.5f;
__instance.GetComponentInParent<Scroller>().ContentYBounds.max = startOffset + __instance.Children.Count * 0.5f;
@@ -106,4 +106,4 @@ public static class GameOptionsMenuPatch
}
}
}
}
}*/
@@ -0,0 +1,37 @@
using HarmonyLib;
using MiraAPI.GameOptions;
using Reactor.Utilities;
using Reactor.Utilities.Extensions;
using System.Collections.Generic;
using System.Linq;
using MiraAPI.GameOptions.UI;
using UnityEngine;
namespace MiraAPI.Patches.Options;
[HarmonyPatch(typeof(GameSettingMenu))]
public static class GameSettingMenuPatches
{
[HarmonyPrefix]
[HarmonyPatch(nameof(GameSettingMenu.Start))]
public static void StartPrefix(GameSettingMenu __instance)
{
__instance.MenuDescriptionText.transform.parent.gameObject.SetActive(false);
}
/*public static void CreateOptionsFor(GameSettingMenu __instance, ToggleOption togglePrefab, NumberOption numberPrefab, StringOption stringPrefab, Transform container,
List<IModdedOption> options)
{
foreach (IModdedOption option in options)
{
if (option.AdvancedRole is not null || option.OptionBehaviour)
{
continue;
}
OptionBehaviour newOption = option.CreateOption(togglePrefab, numberPrefab, stringPrefab, container);
__instance.AllItems = __instance.AllItems.AddItem(newOption.transform).ToArray();
}
}*/
}
@@ -1,68 +0,0 @@
using HarmonyLib;
using MiraAPI.GameOptions;
using Reactor.Utilities;
using Reactor.Utilities.Extensions;
using System.Collections.Generic;
using System.Linq;
using MiraAPI.GameOptions.UI;
using UnityEngine;
using Object = UnityEngine.Object;
namespace MiraAPI.Patches.Options;
[HarmonyPatch(typeof(GameSettingMenu))]
public static class GameSettingsMenuPatches
{
private static GameObject _gameBtn;
private static GameObject _roleBtn;
[HarmonyPrefix, HarmonyPatch("Start")]
public static void StartPrefix(GameSettingMenu __instance)
{
foreach (var tab in ModdedOptionsTab.CustomTabs) tab.gameObject.Destroy();
foreach (var screen in ModdedOptionsTab.CustomScreens) screen.gameObject.Destroy();
ModdedOptionsTab.CustomScreens.Clear();
ModdedOptionsTab.CustomTabs.Clear();
_gameBtn = __instance.transform.FindChild("Header/Tabs/GameTab").gameObject;
_roleBtn = __instance.transform.FindChild("Header/Tabs/RoleTab").gameObject;
var numberOpt = __instance.RegularGameSettings.GetComponentInChildren<NumberOption>();
var toggleOpt = Object.FindObjectOfType<ToggleOption>();
var stringOpt = __instance.RegularGameSettings.GetComponentInChildren<StringOption>();
foreach (var pair in ModdedOptionsManager.RegisteredMods)
{
var container = ModdedOptionsTab.InitializeForMod(pair.Value, __instance).transform;
foreach (var group in ModdedOptionsManager.Groups.Where(group => group.AdvancedRole == null && group.ParentMod == pair.Value))
{
group.Header = ModdedOptionsTab.CreateHeader(toggleOpt, container, group.GroupName, group.GroupColor);
CreateOptionsFor(__instance, toggleOpt, numberOpt, stringOpt, container, ModdedOptionsManager.Options.Where(x => x.Group == group).ToList());
}
CreateOptionsFor(__instance, toggleOpt, numberOpt, stringOpt, container, ModdedOptionsManager.Options.Where(x => x.Group is null).ToList());
}
if (!numberOpt || !toggleOpt || !stringOpt)
{
Logger<MiraAPIPlugin>.Error("OPTION PREFABS MISSING");
}
}
public static void CreateOptionsFor(GameSettingMenu __instance, ToggleOption togglePrefab, NumberOption numberPrefab, StringOption stringPrefab, Transform container,
List<IModdedOption> options)
{
foreach (IModdedOption option in options)
{
if (option.AdvancedRole is not null || option.OptionBehaviour)
{
continue;
}
OptionBehaviour newOption = option.CreateOption(togglePrefab, numberPrefab, stringPrefab, container);
__instance.AllItems = __instance.AllItems.AddItem(newOption.transform).ToArray();
}
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ public static class GameStartupPatch
/// This is used for registering roles when the game opens, might be a janky solution, but it works
/// </summary>
[HarmonyPostfix]
[HarmonyPatch("Start")]
[HarmonyPatch(nameof(MainMenuManager.Start))]
public static void StartPostfix()
{
if (_runOnce)
+2 -1
View File
@@ -9,7 +9,8 @@ namespace MiraAPI.Patches.Roles;
[HarmonyPatch(typeof(PlayerNameColor))]
public static class NameTagPatch
{
[HarmonyPrefix, HarmonyPatch("Get", typeof(RoleBehaviour))]
[HarmonyPrefix]
[HarmonyPatch(nameof(PlayerNameColor.Get), typeof(RoleBehaviour))]
public static bool GetPatch([HarmonyArgument(0)] RoleBehaviour otherPlayerRole, ref Color __result)
{
if (PlayerControl.LocalPlayer.Data.IsDead)
@@ -10,7 +10,8 @@ public static class RoleBehaviourPatches
/// <summary>
/// Update TeamColor text for Launchpad roles
/// </summary>
[HarmonyPrefix, HarmonyPatch("TeamColor", MethodType.Getter)]
[HarmonyPrefix]
[HarmonyPatch(nameof(RoleBehaviour.TeamColor), MethodType.Getter)]
public static bool PrefixTeamColorGetter(RoleBehaviour __instance, ref Color __result)
{
if (__instance is not ICustomRole behaviour)
+2 -1
View File
@@ -8,7 +8,8 @@ namespace MiraAPI.Patches.Roles;
[HarmonyPatch(typeof(RoleManager))]
public static class RoleManagerPatches
{
[HarmonyPrefix, HarmonyPatch("AssignRoleOnDeath")]
[HarmonyPrefix]
[HarmonyPatch(nameof(RoleManager.AssignRoleOnDeath))]
public static bool AssignRoleOnDeath(RoleManager __instance, [HarmonyArgument(0)] PlayerControl plr)
{
if (plr == null || !plr.Data.IsDead)
@@ -2,7 +2,7 @@
using MiraAPI.Roles;
namespace MiraAPI.Patches.Roles;
/*
[HarmonyPatch(typeof(RoleOptionSetting))]
public static class RoleOptionSettingPatch
{
@@ -21,4 +21,4 @@ public static class RoleOptionSettingPatch
}
return true;
}
}
}*/
@@ -5,13 +5,14 @@ using Reactor.Utilities;
namespace MiraAPI.Patches.Roles;
[HarmonyPatch(typeof(RoleOptionsCollectionV07))]
[HarmonyPatch(typeof(RoleOptionsCollectionV08))]
public static class RoleOptionsCollectionPatch
{
/// <summary>
/// Set the role chance for custom Launchpad roles based on config
/// </summary>
[HarmonyPrefix, HarmonyPatch("GetChancePerGame")]
[HarmonyPrefix]
[HarmonyPatch(nameof(RoleOptionsCollectionV08.GetChancePerGame))]
public static bool GetChancePrefix([HarmonyArgument(0)] RoleTypes roleType, ref int __result)
{
if (CustomRoleManager.GetCustomRoleBehaviour(roleType, out var customRole))
@@ -32,7 +33,8 @@ public static class RoleOptionsCollectionPatch
/// <summary>
/// Set the amount for custom Launchpad roles based on config
/// </summary>
[HarmonyPrefix, HarmonyPatch("GetNumPerGame")]
[HarmonyPrefix]
[HarmonyPatch(nameof(RoleOptionsCollectionV08.GetNumPerGame))]
public static bool GetNumPrefix([HarmonyArgument(0)] RoleTypes roleType, ref int __result)
{
if (CustomRoleManager.GetCustomRoleBehaviour(roleType, out var customRole))
@@ -10,7 +10,7 @@ using UnityEngine;
using Object = UnityEngine.Object;
namespace MiraAPI.Patches.Roles;
/*
[HarmonyPatch(typeof(RolesSettingsMenu))]
public static class RolesSettingsMenuPatches
{
@@ -71,7 +71,7 @@ public static class RolesSettingsMenuPatches
break;
}
}
}*/
}*\/
var tmp = newTab.GetComponentInChildren<TextTranslatorTMP>();
tmp.defaultStr = role.NiceName;
@@ -102,7 +102,7 @@ public static class RolesSettingsMenuPatches
{
customOption.OptionBehaviour.OnValueChanged = (Action<OptionBehaviour>)customOption.ValueChanged;
}
}*/
}*\/
var scroll = __instance.GetComponentInChildren<Scroller>();
scroll.active = true;
@@ -144,4 +144,5 @@ public static class RolesSettingsMenuPatches
GameOptionsManager.Instance.GameHostOptions = GameOptionsManager.Instance.CurrentGameOptions;
return false;
}
}
}
*/
+2 -1
View File
@@ -56,7 +56,8 @@ public static class TaskAdderPatch
}
// yes it might be crazy patching the entire method, but i tried so many other methods and only this works :cry:
[HarmonyPrefix, HarmonyPatch(typeof(TaskAdderGame), nameof(TaskAdderGame.ShowFolder))]
[HarmonyPrefix]
[HarmonyPatch(typeof(TaskAdderGame), nameof(TaskAdderGame.ShowFolder))]
public static bool ShowPatch(TaskAdderGame __instance, [HarmonyArgument(0)] TaskFolder taskFolder)
{
var stringBuilder = new StringBuilder(64);
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB