From 78a16850d0a7a0e054d1c28a424fc16c0d14b5c9 Mon Sep 17 00:00:00 2001 From: Pietrodjaowjao Date: Wed, 14 Aug 2024 22:49:02 -0300 Subject: [PATCH 01/60] 8.13 initial support --- MiraAPI/MiraAPI.csproj | 4 ++-- MiraAPI/Patches/Options/RoleSettingMenuPatches.cs | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/MiraAPI/MiraAPI.csproj b/MiraAPI/MiraAPI.csproj index e74fa8c..e038faf 100644 --- a/MiraAPI/MiraAPI.csproj +++ b/MiraAPI/MiraAPI.csproj @@ -32,10 +32,10 @@ - + - + diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index dbd9c8d..2d3314d 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -65,7 +65,7 @@ namespace MiraAPI.Patches.Options num3++; } - num -= 0.4f; + num -= 0.8f; CategoryHeaderEditRole categoryHeaderEditRole3 = Object.Instantiate(__instance.categoryHeaderEditRoleOrigin, Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform); categoryHeaderEditRole3.SetHeader(StringNames.None, 20); categoryHeaderEditRole3.Title.text = "Neutral Roles"; @@ -193,9 +193,8 @@ namespace MiraAPI.Patches.Options PassiveButton newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform); newButton.name = "ConfigButton"; newButton.transform.localPosition = new Vector3(0.2419f, -0.2582f, -2f); - newButton.transform.FindChild("Plus_TMP").gameObject.DestroyImmediate(); - newButton.transform.FindChild("InactiveSprite").GetComponent().sprite = MiraAssets.Cog.LoadAsset(); - newButton.transform.FindChild("ActiveSprite").GetComponent().sprite = MiraAssets.CogActive.LoadAsset(); + newButton.transform.GetComponentInChildren().gameObject.DestroyImmediate(); + newButton.transform.FindChild("ButtonSprite").GetComponent().sprite = MiraAssets.CogActive.LoadAsset(); PassiveButton passiveButton = newButton.GetComponent(); passiveButton.OnClick = new ButtonClickedEvent(); From 9a9367f2b9172a24cef9d2479b297beb88fdf764 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 11:05:59 -0400 Subject: [PATCH 02/60] make role configs save to mod, not to mira --- .../Patches/Options/RoleSettingMenuPatches.cs | 21 ++++++++++++------- .../Roles/RoleOptionsCollectionPatch.cs | 5 ++--- MiraAPI/PluginLoading/MiraPluginManager.cs | 3 ++- MiraAPI/Roles/CustomRoleManager.cs | 14 ++++++------- MiraAPI/Roles/ICustomRole.cs | 12 ++++++----- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 2350801..ff62645 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -106,11 +106,18 @@ public static class RoleSettingMenuPatches var role = roleSetting.Role as ICustomRole; if (role is null or { HideSettings: true }) return; - PluginSingleton.Instance.Config.TryGetEntry(role.NumConfigDefinition, out var numEntry); - numEntry.Value = roleSetting.RoleMaxCount; + try + { + role.ParentMod.PluginConfig.TryGetEntry(role.NumConfigDefinition, out var numEntry); + numEntry.Value = roleSetting.RoleMaxCount; - PluginSingleton.Instance.Config.TryGetEntry(role.ChanceConfigDefinition, out var chanceEntry); - chanceEntry.Value = roleSetting.RoleChance; + role.ParentMod.PluginConfig.TryGetEntry(role.ChanceConfigDefinition, out var chanceEntry); + chanceEntry.Value = roleSetting.RoleChance; + } + catch (Exception e) + { + Logger.Warning(e); + } roleSetting.UpdateValuesAndText(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions); DestroyableSingleton.Instance.Notifier.AddRoleSettingsChangeMessage(roleSetting.Role.StringName, roleSetting.RoleMaxCount, roleSetting.RoleChance, roleSetting.Role.TeamType, false); @@ -156,14 +163,14 @@ public static class RoleSettingMenuPatches newOpt.Initialize(); } - __instance.scrollBar.CalculateAndSetYBounds((float)(__instance.advancedSettingChildren.Count + 3), 1f, 6f, 0.45f); + __instance.scrollBar.CalculateAndSetYBounds(__instance.advancedSettingChildren.Count + 3, 1f, 6f, 0.45f); } private static void ChangeTab(RoleBehaviour role, RolesSettingsMenu __instance) { ICustomRole customRole = role as ICustomRole; __instance.roleDescriptionText.text = customRole.RoleLongDescription; - __instance.roleTitleText.text = DestroyableSingleton.Instance.GetString(role.StringName, Array.Empty()); - __instance.roleScreenshot.sprite = Sprite.Create(role.RoleScreenshot.texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100); + __instance.roleTitleText.text = DestroyableSingleton.Instance.GetString(role.StringName, []); + __instance.roleScreenshot.sprite = Sprite.Create(customRole.OptionsScreenshot.LoadAsset().texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100); __instance.roleScreenshot.drawMode = SpriteDrawMode.Sliced; __instance.roleHeaderSprite.color = customRole.RoleColor; __instance.roleHeaderText.color = customRole.RoleColor.DarkenColor(); diff --git a/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs b/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs index e49c432..60a4794 100644 --- a/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs +++ b/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs @@ -1,7 +1,6 @@ using AmongUs.GameOptions; using HarmonyLib; using MiraAPI.Roles; -using Reactor.Utilities; namespace MiraAPI.Patches.Roles; @@ -22,7 +21,7 @@ public static class RoleOptionsCollectionPatch return false; } - PluginSingleton.Instance.Config.TryGetEntry(customRole.ChanceConfigDefinition, out var entry); + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.ChanceConfigDefinition, out var entry); __result = entry.Value; return false; } @@ -44,7 +43,7 @@ public static class RoleOptionsCollectionPatch return false; } - PluginSingleton.Instance.Config.TryGetEntry(customRole.NumConfigDefinition, out var entry); + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.NumConfigDefinition, out var entry); __result = entry.Value; return false; } diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index a96fbf8..6ac174e 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -84,6 +84,7 @@ public class MiraPluginManager if (typeof(IModdedOption).IsAssignableFrom(property.PropertyType)) { IModdedOption option = (IModdedOption)property.GetValue(group); + group.Options.Add(option); option.Group = group; option.AdvancedRole = group.AdvancedRole; } @@ -101,7 +102,7 @@ public class MiraPluginManager ClassInjector.RegisterTypeInIl2Cpp(type); - var role = CustomRoleManager.RegisterRole(type, attribute.RoleId); + var role = CustomRoleManager.RegisterRole(type, attribute.RoleId, pluginInfo); try { diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 1d1f3c2..27cf965 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -36,7 +36,7 @@ public static class CustomRoleManager RoleManager.Instance.AllRoles = RoleManager.Instance.AllRoles.Concat(CustomRoles.Values).ToArray(); } - internal static RoleBehaviour RegisterRole(Type roleType, ushort roleId) + internal static RoleBehaviour RegisterRole(Type roleType, ushort roleId, MiraPluginInfo parentMod) { if (!(typeof(RoleBehaviour).IsAssignableFrom(roleType) && typeof(ICustomRole).IsAssignableFrom(roleType))) { @@ -79,7 +79,7 @@ public static class CustomRoleManager return roleBehaviour; } - var config = PluginSingleton.Instance.Config; + var config = parentMod.PluginConfig; config.Bind(customRole.NumConfigDefinition, 1); config.Bind(customRole.ChanceConfigDefinition, 100); @@ -88,7 +88,7 @@ public static class CustomRoleManager public static MiraPluginInfo FindParentMod(ICustomRole role) { - return MiraPluginManager.Instance.RegisteredPlugins.First(plugin => plugin.Value.CustomRoles.Values.Contains(role as RoleBehaviour)).Value; + return MiraPluginManager.Instance.RegisteredPlugins.First(plugin => plugin.Value.CustomRoles.ContainsValue(role as RoleBehaviour)).Value; } public static bool GetCustomRoleBehaviour(RoleTypes roleType, out ICustomRole result) @@ -150,8 +150,8 @@ public static class CustomRoleManager continue; } - PluginSingleton.Instance.Config.TryGetEntry(customRole.NumConfigDefinition, out var numEntry); - PluginSingleton.Instance.Config.TryGetEntry(customRole.ChanceConfigDefinition, out var chanceEntry); + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.NumConfigDefinition, out var numEntry); + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.ChanceConfigDefinition, out var chanceEntry); var netData = new NetData((uint)role.Role, BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); @@ -186,8 +186,8 @@ public static class CustomRoleManager var num = BitConverter.ToInt32(netData.Data, 0); var chance = BitConverter.ToInt32(netData.Data, 4); - PluginSingleton.Instance.Config.TryGetEntry(customRole.NumConfigDefinition, out var numEntry); - PluginSingleton.Instance.Config.TryGetEntry(customRole.ChanceConfigDefinition, out var chanceEntry); + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.NumConfigDefinition, out var numEntry); + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.ChanceConfigDefinition, out var chanceEntry); numEntry.Value = num; chanceEntry.Value = chance; diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 67e6506..15807e6 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -6,7 +6,7 @@ using MiraAPI.Utilities.Assets; using System.Text; using HarmonyLib; using MiraAPI.Networking; -using Reactor.Utilities; +using MiraAPI.PluginLoading; using UnityEngine; namespace MiraAPI.Roles; @@ -22,8 +22,8 @@ public interface ICustomRole Color RoleColor { get; } ModdedRoleTeams Team { get; } - - LoadableAsset OptionsScreenshot { get; } + + LoadableAsset OptionsScreenshot => MiraAssets.Empty; LoadableAsset Icon => MiraAssets.Empty; @@ -53,6 +53,8 @@ public interface ICustomRole RoleTypes GhostRole => Team == ModdedRoleTeams.Crewmate ? RoleTypes.CrewmateGhost : RoleTypes.ImpostorGhost; + MiraPluginInfo ParentMod => CustomRoleManager.FindParentMod(this); + void CreateOptions() { } void PlayerControlFixedUpdate(PlayerControl playerControl) { } @@ -72,8 +74,8 @@ public interface ICustomRole NetData GetNetData(RoleBehaviour roleBehaviour) { - PluginSingleton.Instance.Config.TryGetEntry(NumConfigDefinition, out var numEntry); - PluginSingleton.Instance.Config.TryGetEntry(ChanceConfigDefinition, out var chanceEntry); + ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out var numEntry); + ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out var chanceEntry); return new NetData((uint)roleBehaviour.Role, BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); } From c15ba69533cd191f2b956452d37c465ce58bcaa8 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:37:10 -0400 Subject: [PATCH 03/60] Options management cleanup + fixes --- MiraAPI/GameOptions/IModdedOption.cs | 2 +- MiraAPI/GameOptions/ModdedOptionsManager.cs | 23 +++--- .../GameOptions/OptionTypes/ModdedOption.cs | 8 +-- MiraAPI/MiraAPI.csproj | 1 + .../Patches/Options/GameOptionsMenuPatch.cs | 67 +++++++++++------- .../Patches/Options/RoleSettingMenuPatches.cs | 4 +- MiraAPI/Patches/Roles/NameTagPatch.cs | 2 - MiraAPI/PluginLoading/MiraPluginManager.cs | 12 +++- MiraAPI/Resources/Empty.png | Bin 0 -> 6349 bytes MiraAPI/Utilities/Assets/MiraAssets.cs | 2 +- MiraAPI/Utilities/Extensions.cs | 2 +- 11 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 MiraAPI/Resources/Empty.png diff --git a/MiraAPI/GameOptions/IModdedOption.cs b/MiraAPI/GameOptions/IModdedOption.cs index 232cf5a..a041cc7 100644 --- a/MiraAPI/GameOptions/IModdedOption.cs +++ b/MiraAPI/GameOptions/IModdedOption.cs @@ -9,7 +9,7 @@ public interface IModdedOption { public uint Id { get; } public BaseGameSetting Data { get; } - public IModdedOptionGroup Group { get; set; } + public bool HasGroup { get; set; } public IMiraPlugin ParentMod { get; set; } public Type AdvancedRole { get; set; } public OptionBehaviour OptionBehaviour { get; protected set; } diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index 0d8e15f..88228a7 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -12,12 +12,16 @@ namespace MiraAPI.GameOptions; public class ModdedOptionsManager { - public static readonly Dictionary ModdedOptions = new(); - public static readonly List Options = []; - public static readonly List Groups = []; private static readonly Dictionary OptionAttributes = new(); - public static readonly Dictionary OriginalTypes = new(); - public static uint NextId = 1; + + public static readonly Dictionary ModdedOptions = new(); + public static readonly Dictionary> GroupedOptions = new(); + + public static readonly List Groups = []; + public static readonly Dictionary TypeToGroup = new(); + + public static uint NextId => _nextId++; + private static uint _nextId = 1; public static IModdedOption RegisterOption(Type type, ModdedOptionAttribute attribute, PropertyInfo property) { @@ -50,11 +54,12 @@ public class ModdedOptionsManager OptionAttributes.Add(property, attribute); - if (OriginalTypes.ContainsKey(type)) + if (TypeToGroup.ContainsKey(type)) { - Logger.Error($"Grouping {attribute.Title} with {OriginalTypes[type].GroupName}"); - result.Group = OriginalTypes[type]; - result.AdvancedRole = OriginalTypes[type].AdvancedRole; + Logger.Error($"Grouping {attribute.Title} with {TypeToGroup[type].GroupName}"); + GroupedOptions[TypeToGroup[type]].Add(result); + result.HasGroup = true; + result.AdvancedRole = TypeToGroup[type].AdvancedRole; } } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index 386cc7c..3021cd1 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -4,7 +4,6 @@ using Reactor.Localization.Utilities; using System; using MiraAPI.Networking; using Reactor.Networking.Rpc; -using Reactor.Utilities; using UnityEngine; namespace MiraAPI.GameOptions.OptionTypes; @@ -13,6 +12,8 @@ public abstract class ModdedOption : IModdedOption { public uint Id { get; } public BaseGameSetting Data { get; protected init; } + public bool HasGroup { get; set; } = false; + public IMiraPlugin ParentMod { get; set; } = null; public T Value { get; protected set; } public T DefaultValue { get; init; } public Action ChangedEvent { get; set; } @@ -21,8 +22,6 @@ public abstract class ModdedOption : IModdedOption public Func Visible { get; set; } public Type AdvancedRole { get; set; } public OptionBehaviour OptionBehaviour { get; set; } - public IModdedOptionGroup Group { get; set; } = null; - public IMiraPlugin ParentMod { get; set; } = null; protected ModdedOption(string title, T defaultValue, Type roleType) : this() { @@ -40,8 +39,7 @@ public abstract class ModdedOption : IModdedOption private ModdedOption() { - Id = ModdedOptionsManager.NextId++; - ModdedOptionsManager.Options.Add(this); + Id = ModdedOptionsManager.NextId; ModdedOptionsManager.ModdedOptions.Add(Id, this); } diff --git a/MiraAPI/MiraAPI.csproj b/MiraAPI/MiraAPI.csproj index aad0751..0de367f 100644 --- a/MiraAPI/MiraAPI.csproj +++ b/MiraAPI/MiraAPI.csproj @@ -22,6 +22,7 @@ + diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index 20e1d96..580add3 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -22,7 +22,10 @@ public static class GameOptionsMenuPatch __instance.MapPicker.gameObject.SetActive(false); float num = 2.1f; - foreach (IModdedOptionGroup group in GameSettingMenuPatches.SelectedMod.OptionGroups) + + var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.AdvancedRole is null); + + foreach (IModdedOptionGroup group in filteredGroups) { CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer); categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20); @@ -35,7 +38,7 @@ public static class GameOptionsMenuPatch categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f); num -= 0.63f; - foreach (var opt in ModdedOptionsManager.Options.Where(opt => opt.Group is not null && opt.AdvancedRole is null && opt.Group.GroupName == group.GroupName)) + foreach (var opt in ModdedOptionsManager.GroupedOptions[group]) { OptionBehaviour newOpt = opt.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.settingsContainer); newOpt.transform.localPosition = new Vector3(0.952f, num, -2f); @@ -62,36 +65,46 @@ public static class GameOptionsMenuPatch } } - CategoryHeaderMasked ungroupedHeader = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer); - ungroupedHeader.SetHeader(CustomStringName.CreateAndRegister("Ungrouped Options"), 20); - ungroupedHeader.transform.localScale = Vector3.one * 0.63f; - ungroupedHeader.transform.localPosition = new Vector3(-0.903f, num, -2f); + var filteredOptions = GameSettingMenuPatches.SelectedMod.Options.Where(x => x.AdvancedRole is null && !x.HasGroup).ToList(); - num -= 0.63f; - - foreach (var opt in ModdedOptionsManager.Options.Where(opt => opt.Group is null && opt.AdvancedRole is null)) + if (filteredOptions.Count > 0) { - OptionBehaviour newOpt = opt.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.settingsContainer); - newOpt.transform.localPosition = new Vector3(0.952f, num, -2f); - newOpt.SetClickMask(__instance.ButtonClickMask); - newOpt.SetUpFromData(newOpt.data, 20); - SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren(true); - for (int i = 0; i < componentsInChildren.Length; i++) + CategoryHeaderMasked ungroupedHeader = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, + Quaternion.identity, __instance.settingsContainer); + ungroupedHeader.SetHeader(CustomStringName.CreateAndRegister("Ungrouped Options"), 20); + ungroupedHeader.transform.localScale = Vector3.one * 0.63f; + ungroupedHeader.transform.localPosition = new Vector3(-0.903f, num, -2f); + + num -= 0.63f; + + + foreach (var opt in filteredOptions) { - componentsInChildren[i].material.SetInt(PlayerMaterial.MaskLayer, 20); + OptionBehaviour newOpt = opt.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, + __instance.stringOptionOrigin, __instance.settingsContainer); + newOpt.transform.localPosition = new Vector3(0.952f, num, -2f); + newOpt.SetClickMask(__instance.ButtonClickMask); + newOpt.SetUpFromData(newOpt.data, 20); + + SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren(true); + for (int i = 0; i < componentsInChildren.Length; i++) + { + componentsInChildren[i].material.SetInt(PlayerMaterial.MaskLayer, 20); + } + + foreach (TextMeshPro textMeshPro in newOpt.GetComponentsInChildren(true)) + { + textMeshPro.fontMaterial.SetFloat(ShaderID.StencilComp, 3f); + textMeshPro.fontMaterial.SetFloat(ShaderID.Stencil, 20); + } + + __instance.Children.Add(newOpt); + + num -= 0.45f; + + newOpt.Initialize(); } - foreach (TextMeshPro textMeshPro in newOpt.GetComponentsInChildren(true)) - { - textMeshPro.fontMaterial.SetFloat(ShaderID.StencilComp, 3f); - textMeshPro.fontMaterial.SetFloat(ShaderID.Stencil, 20); - } - - __instance.Children.Add(newOpt); - - num -= 0.45f; - - newOpt.Initialize(); } __instance.scrollBar.SetYBoundsMax(-num - 1.65f); diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index ff62645..4bd63e7 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -139,8 +139,10 @@ public static class RoleSettingMenuPatches __instance.advancedSettingChildren.Clear(); float num = -0.872f; - foreach (var option in GameSettingMenuPatches.SelectedMod.Options.Where(option => option.AdvancedRole != null && option.AdvancedRole == role.GetType())) + foreach (var option in GameSettingMenuPatches.SelectedMod.Options) { + if (option.AdvancedRole is not null && option.AdvancedRole != role.GetType()) continue; + OptionBehaviour 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); diff --git a/MiraAPI/Patches/Roles/NameTagPatch.cs b/MiraAPI/Patches/Roles/NameTagPatch.cs index 3566416..929ccaf 100644 --- a/MiraAPI/Patches/Roles/NameTagPatch.cs +++ b/MiraAPI/Patches/Roles/NameTagPatch.cs @@ -1,6 +1,4 @@ using HarmonyLib; -using MiraAPI.GameModes; -using MiraAPI.GameOptions; using UnityEngine; namespace MiraAPI.Patches.Roles; diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index 6ac174e..17235bd 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -74,9 +74,11 @@ public class MiraPluginManager if (typeof(IModdedOptionGroup).IsAssignableFrom(type)) { IModdedOptionGroup group = (IModdedOptionGroup)Activator.CreateInstance(type); + if (group == null) continue; ModdedOptionsManager.Groups.Add(group); - ModdedOptionsManager.OriginalTypes.Add(type, group); + ModdedOptionsManager.TypeToGroup.Add(type, group); + ModdedOptionsManager.GroupedOptions.Add(group, []); pluginInfo.OptionGroups.Add(group); foreach (var property in type.GetProperties()) @@ -84,9 +86,13 @@ public class MiraPluginManager if (typeof(IModdedOption).IsAssignableFrom(property.PropertyType)) { IModdedOption option = (IModdedOption)property.GetValue(group); - group.Options.Add(option); - option.Group = group; + if (option == null) continue; + + option.HasGroup = true; option.AdvancedRole = group.AdvancedRole; + + ModdedOptionsManager.GroupedOptions[group].Add(option); + pluginInfo.Options.Add(option); } } } diff --git a/MiraAPI/Resources/Empty.png b/MiraAPI/Resources/Empty.png new file mode 100644 index 0000000000000000000000000000000000000000..478b531a69b64666a507ee45a95312a2369cba6c GIT binary patch literal 6349 zcmeHIe@qi+7(Nshgs|Y;gt)~Whr%+_-nIPf*^`vE+D_V3TBXPUukE!xZF}9_RSFTu z*u?BdqUZ!6n30V|+}w=QC2TM!*_?|bCc4ExbO~FGbJ0d2+t`K%_uUmrS%=x*p>MNl?ug_s8T5d3>nuH;K{Hoz~u@qqCRvK z=Va+1Pcs2n@JTwD5KkZoz~R}*{K1&>05_98&;bpTK~y2f(0Fpt%kT{6Wfm}r!3l;` zn4ZgF-ZcV}K<8=q0(1dMpaZQg&HuBZjL4cD?1$x}M82t|5r)OcCdNg(oBorm!V3j5 z9?u5l;UanR|L|ji;{rPx6e!I{Ml@%mWqb?^f&)1eiowo7My=MuGH%)jFs^E21#Hx7 zOBAY-5}8u25V^v;;TAef`RqE{PX#zoV+5kW%A$GC!8HrQ;{8_8Uf`0bQ{i=Sqo4Fp z)wGNE#`&8=Dye`c5fa|X7ZM76OMnJ1s}zG2t?Y9cfs`uIxT|UsAfa_&wOCNNf#!II zZ4!^7{bZ$HiteIYA1yW#42$K2lTP7&0tvE=E99hHVhF%p6y+E<-$=5Q#seyeKs0VQ z4I*uVEkaMhN?0kMl{RM5=%s+Wf4yd0$)Gc#p+axZ#->ISqF0NAxM2Y7qGw>pfN6!s z#ueDa1|AgvrNn}9cK+lkD+DFILW816ClQgqdLV9kZTfu`fD4`pW&dAa(L$iuO-w^%S4j zyXoMTAD`I&)pgaG_P#rh_f&sJd>G*-lSfQ{e^6Ui_F9r^?CfNE*DcS3V_mJo;JdUe zXsF>JD1C*nlAxa6YzSIDYSd|L;oitdQWBuF9+*CPH&yuXNk2&eNdZX#NdZX#NdZX# zNdZX#NdZX#NdZX#Nr6SJK opt.OptionBehaviour && opt.OptionBehaviour.Equals(optionBehaviour)); + return ModdedOptionsManager.ModdedOptions.Values.Any(opt => opt.OptionBehaviour && opt.OptionBehaviour.Equals(optionBehaviour)); } public static Color DarkenColor(this Color color) From 742ad44d10391c797164086989ceb44b541fbcc2 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:46:38 -0400 Subject: [PATCH 04/60] some more options error fixes --- MiraAPI/GameModes/CustomGameModeManager.cs | 2 +- MiraAPI/Patches/Options/GameOptionsMenuPatch.cs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/MiraAPI/GameModes/CustomGameModeManager.cs b/MiraAPI/GameModes/CustomGameModeManager.cs index bec9d84..9a5da49 100644 --- a/MiraAPI/GameModes/CustomGameModeManager.cs +++ b/MiraAPI/GameModes/CustomGameModeManager.cs @@ -24,7 +24,7 @@ public static class CustomGameModeManager /// /// Current gamemode /// - public static CustomGameMode? ActiveMode; + public static CustomGameMode? ActiveMode = new DefaultMode(); /// /// Set current gamemode diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index 580add3..f01a38c 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -23,7 +23,7 @@ public static class GameOptionsMenuPatch float num = 2.1f; - var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.AdvancedRole is null); + var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.GroupVisible.Invoke() && x.AdvancedRole is null); foreach (IModdedOptionGroup group in filteredGroups) { @@ -38,7 +38,9 @@ public static class GameOptionsMenuPatch categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f); num -= 0.63f; - foreach (var opt in ModdedOptionsManager.GroupedOptions[group]) + var filteredOpts = ModdedOptionsManager.GroupedOptions[group].Where(x=>x.Visible.Invoke()).ToList(); + + foreach (var opt in filteredOpts) { OptionBehaviour newOpt = opt.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.settingsContainer); newOpt.transform.localPosition = new Vector3(0.952f, num, -2f); From 65e533c2685e55f33b2848d966094ab0413f7a43 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:22:21 -0400 Subject: [PATCH 05/60] temp disable gamemodes --- MiraAPI/GameModes/CustomGameModeManager.cs | 2 +- .../GameModes/RegisterGameModeAttribute.cs | 2 +- MiraAPI/Patches/GameModes/ConsolePatches.cs | 4 +- MiraAPI/Patches/GameModes/DeadBodyPatch.cs | 16 ++++++ MiraAPI/Patches/GameModes/GameLogicPatches.cs | 3 +- .../Patches/GameModes/ImpostorTargetPatch.cs | 3 +- .../Patches/GameModes/MapBehaviourPatch.cs | 5 +- MiraAPI/Patches/GameModes/OnDeathPatch.cs | 16 ++++++ MiraAPI/Patches/GameModes/VentPatches.cs | 57 +++++++++++++++++++ MiraAPI/Patches/HudManagerPatches.cs | 10 ++-- MiraAPI/Patches/IntroCutscenePatches.cs | 6 +- .../Patches/Options/RoleSettingMenuPatches.cs | 5 +- MiraAPI/Patches/PlayerControlPatches.cs | 6 ++ MiraAPI/Patches/Roles/EjectionPatches.cs | 26 +++++++++ MiraAPI/Roles/ICustomRole.cs | 2 - 15 files changed, 146 insertions(+), 17 deletions(-) create mode 100644 MiraAPI/Patches/GameModes/DeadBodyPatch.cs create mode 100644 MiraAPI/Patches/GameModes/OnDeathPatch.cs create mode 100644 MiraAPI/Patches/GameModes/VentPatches.cs create mode 100644 MiraAPI/Patches/Roles/EjectionPatches.cs diff --git a/MiraAPI/GameModes/CustomGameModeManager.cs b/MiraAPI/GameModes/CustomGameModeManager.cs index 9a5da49..9426a2b 100644 --- a/MiraAPI/GameModes/CustomGameModeManager.cs +++ b/MiraAPI/GameModes/CustomGameModeManager.cs @@ -45,7 +45,7 @@ public static class CustomGameModeManager /// Register gamemode from type /// /// Type of gamemode class, should inherit from - public static void RegisterGameMode(Type gameModeType) + internal static void RegisterGameMode(Type gameModeType) { if (!typeof(CustomGameMode).IsAssignableFrom(gameModeType)) { diff --git a/MiraAPI/GameModes/RegisterGameModeAttribute.cs b/MiraAPI/GameModes/RegisterGameModeAttribute.cs index 455e6cd..2e7e9e3 100644 --- a/MiraAPI/GameModes/RegisterGameModeAttribute.cs +++ b/MiraAPI/GameModes/RegisterGameModeAttribute.cs @@ -9,7 +9,7 @@ public class RegisterGameModeAttribute : Attribute { private static readonly HashSet RegisteredAssemblies = []; - public static void Register(Assembly assembly) + internal static void Register(Assembly assembly) { if (!RegisteredAssemblies.Add(assembly)) return; diff --git a/MiraAPI/Patches/GameModes/ConsolePatches.cs b/MiraAPI/Patches/GameModes/ConsolePatches.cs index d37f940..c19a554 100644 --- a/MiraAPI/Patches/GameModes/ConsolePatches.cs +++ b/MiraAPI/Patches/GameModes/ConsolePatches.cs @@ -3,7 +3,7 @@ using InnerNet; using MiraAPI.GameModes; namespace MiraAPI.Patches.GameModes; - +/* [HarmonyPatch] public static class ConsolePatches { @@ -73,4 +73,4 @@ public static class ConsolePatches canUse = couldUse = true; return true; } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/MiraAPI/Patches/GameModes/DeadBodyPatch.cs b/MiraAPI/Patches/GameModes/DeadBodyPatch.cs new file mode 100644 index 0000000..e61a52c --- /dev/null +++ b/MiraAPI/Patches/GameModes/DeadBodyPatch.cs @@ -0,0 +1,16 @@ +using HarmonyLib; +using MiraAPI.GameModes; + +namespace MiraAPI.Patches.GameModes; + +/* +[HarmonyPatch(typeof(DeadBody))] +public static class DeadBodyPatch +{ + [HarmonyPrefix] + [HarmonyPatch(nameof(DeadBody.OnClick))] + public static bool OnClickPatch(DeadBody __instance) + { + return CustomGameModeManager.ActiveMode == null || CustomGameModeManager.ActiveMode.CanReport(__instance); + } +}*/ \ No newline at end of file diff --git a/MiraAPI/Patches/GameModes/GameLogicPatches.cs b/MiraAPI/Patches/GameModes/GameLogicPatches.cs index d60a70d..fee4cc4 100644 --- a/MiraAPI/Patches/GameModes/GameLogicPatches.cs +++ b/MiraAPI/Patches/GameModes/GameLogicPatches.cs @@ -3,6 +3,7 @@ using MiraAPI.GameModes; namespace MiraAPI.Patches.GameModes; +/* [HarmonyPatch] public static class GameLogicPatches { @@ -21,4 +22,4 @@ public static class GameLogicPatches CustomGameModeManager.ActiveMode?.AssignRoles(out runOriginal, __instance); return runOriginal; } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/MiraAPI/Patches/GameModes/ImpostorTargetPatch.cs b/MiraAPI/Patches/GameModes/ImpostorTargetPatch.cs index 899006d..7657fde 100644 --- a/MiraAPI/Patches/GameModes/ImpostorTargetPatch.cs +++ b/MiraAPI/Patches/GameModes/ImpostorTargetPatch.cs @@ -3,6 +3,7 @@ using MiraAPI.GameModes; namespace MiraAPI.Patches.GameModes; +/* /// /// Allow Impostors to kill each other if can kill is enabled in gamemode or friendly fire is toggled on /// @@ -25,4 +26,4 @@ public static class ImpostorTargetPatch return false; } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/MiraAPI/Patches/GameModes/MapBehaviourPatch.cs b/MiraAPI/Patches/GameModes/MapBehaviourPatch.cs index e7629ef..07512ec 100644 --- a/MiraAPI/Patches/GameModes/MapBehaviourPatch.cs +++ b/MiraAPI/Patches/GameModes/MapBehaviourPatch.cs @@ -3,8 +3,9 @@ using MiraAPI.GameModes; namespace MiraAPI.Patches.GameModes; +/* [HarmonyPatch(typeof(MapBehaviour))] -public class MapBehaviourPatch +public static class MapBehaviourPatch { [HarmonyPrefix] [HarmonyPatch(nameof(MapBehaviour.ShowSabotageMap))] @@ -19,4 +20,4 @@ public class MapBehaviourPatch return true; } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/MiraAPI/Patches/GameModes/OnDeathPatch.cs b/MiraAPI/Patches/GameModes/OnDeathPatch.cs new file mode 100644 index 0000000..e7589dd --- /dev/null +++ b/MiraAPI/Patches/GameModes/OnDeathPatch.cs @@ -0,0 +1,16 @@ +using HarmonyLib; +using MiraAPI.GameModes; + +namespace MiraAPI.Patches.GameModes; + +/* +[HarmonyPatch(typeof(KillAnimation))] +public static class OnDeathPatch +{ + [HarmonyPostfix] + [HarmonyPatch(nameof(KillAnimation.CoPerformKill))] + public static void OnDeathPostfix([HarmonyArgument(0)] PlayerControl source, [HarmonyArgument(1)] PlayerControl target) + { + CustomGameModeManager.ActiveMode?.OnDeath(target); + } +}*/ \ No newline at end of file diff --git a/MiraAPI/Patches/GameModes/VentPatches.cs b/MiraAPI/Patches/GameModes/VentPatches.cs new file mode 100644 index 0000000..7e53b98 --- /dev/null +++ b/MiraAPI/Patches/GameModes/VentPatches.cs @@ -0,0 +1,57 @@ +using HarmonyLib; +using MiraAPI.GameModes; +using MiraAPI.Roles; +using MiraAPI.Utilities; +using UnityEngine; + +namespace MiraAPI.Patches.GameModes; + +/* +[HarmonyPatch(typeof(Vent))] +public static class VentPatches +{ + + [HarmonyPrefix] + [HarmonyPatch(nameof(Vent.CanUse))] + public static bool CanUseVentPatch(Vent __instance, ref float __result, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] ref bool canUse, [HarmonyArgument(2)] ref bool couldUse) + { + if (CustomGameModeManager.ActiveMode?.CanVent(__instance, pc) == false) + { + return couldUse = canUse = false; + } + + if (pc.Role is not ICustomRole role) + { + return couldUse = canUse = true; + } + + var num = float.MaxValue; + var @object = pc.Object; + var customRoleUsable = role.CanUseVent; + + canUse = couldUse = customRoleUsable && !pc.IsDead && (@object.CanMove || @object.inVent); + 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; + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(Vent.SetOutline))] + public static bool SetOutlinePatch(Vent __instance, [HarmonyArgument(0)] bool on, [HarmonyArgument(1)] bool mainTarget) + { + var color = PlayerControl.LocalPlayer.Data.Role is ICustomRole role + ? role.RoleColor : PlayerControl.LocalPlayer.Data.Role.IsImpostor ? Palette.ImpostorRed : Palette.CrewmateBlue; + __instance.myRend.material.SetFloat(ShaderID.Outline, on ? 1 : 0); + __instance.myRend.material.SetColor(ShaderID.OutlineColor, color); + __instance.myRend.material.SetColor(ShaderID.AddColor, mainTarget ? color : Color.clear); + + return false; + } + +}*/ \ No newline at end of file diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 019ebd9..9a1c56d 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -27,10 +27,11 @@ public static class HudManagerPatches { return; } + + //CustomGameModeManager.ActiveMode?.HudUpdate(__instance); - //CustomGameModeManager.ActiveMode.HudUpdate(__instance); - if (local is null || local.Data is null || local.Data.Role is null) return; - + if (local?.Data?.Role is null) return; + if (local.Data.Role is ICustomRole customRole) { customRole.HudUpdate(__instance); @@ -57,6 +58,7 @@ public static class HudManagerPatches } } + /* /// /// Trigger hudstart on current custom gamemode /// @@ -65,7 +67,7 @@ public static class HudManagerPatches public static void GameStartPatch(HudManager __instance) { CustomGameModeManager.ActiveMode?.HudStart(__instance); - } + }*/ /// /// Create custom buttons parent diff --git a/MiraAPI/Patches/IntroCutscenePatches.cs b/MiraAPI/Patches/IntroCutscenePatches.cs index 1af8acf..7b395a5 100644 --- a/MiraAPI/Patches/IntroCutscenePatches.cs +++ b/MiraAPI/Patches/IntroCutscenePatches.cs @@ -9,6 +9,7 @@ namespace MiraAPI.Patches; [HarmonyPatch(typeof(IntroCutscene))] public static class IntroCutscenePatches { + /* [HarmonyPostfix] [HarmonyPatch(nameof(IntroCutscene.BeginImpostor))] public static void BeginImpostorPatch(IntroCutscene __instance) @@ -18,7 +19,7 @@ public static class IntroCutscenePatches var mode = CustomGameModeManager.ActiveMode; __instance.TeamTitle.text = $"{mode.Name}\n{mode.Description}"; } - } + }*/ [HarmonyPrefix] [HarmonyPatch(nameof(IntroCutscene.BeginCrewmate))] @@ -48,10 +49,11 @@ public static class IntroCutscenePatches return true; } + /* [HarmonyPostfix] [HarmonyPatch(nameof(IntroCutscene.OnDestroy))] public static void GameBeginPatch() { CustomGameModeManager.ActiveMode?.Initialize(); - } + }*/ } \ No newline at end of file diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 4bd63e7..cc0e1fc 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -139,7 +139,10 @@ public static class RoleSettingMenuPatches __instance.advancedSettingChildren.Clear(); float num = -0.872f; - foreach (var option in GameSettingMenuPatches.SelectedMod.Options) + + var filteredOptions = GameSettingMenuPatches.SelectedMod.Options.Where(x => x.AdvancedRole == role.GetType()); + + foreach (var option in filteredOptions) { if (option.AdvancedRole is not null && option.AdvancedRole != role.GetType()) continue; diff --git a/MiraAPI/Patches/PlayerControlPatches.cs b/MiraAPI/Patches/PlayerControlPatches.cs index 68bd25e..41ae0a9 100644 --- a/MiraAPI/Patches/PlayerControlPatches.cs +++ b/MiraAPI/Patches/PlayerControlPatches.cs @@ -1,5 +1,6 @@ using HarmonyLib; using MiraAPI.Hud; +using MiraAPI.Roles; namespace MiraAPI.Patches; @@ -13,6 +14,11 @@ public static class PlayerControlPatches { if (!__instance.AmOwner) return; + if (__instance.Data?.Role is ICustomRole customRole) + { + customRole.PlayerControlFixedUpdate(__instance); + } + foreach (var button in CustomButtonManager.CustomButtons) { if (!button.Enabled(__instance.Data.Role)) diff --git a/MiraAPI/Patches/Roles/EjectionPatches.cs b/MiraAPI/Patches/Roles/EjectionPatches.cs new file mode 100644 index 0000000..f6ca0e1 --- /dev/null +++ b/MiraAPI/Patches/Roles/EjectionPatches.cs @@ -0,0 +1,26 @@ +using HarmonyLib; +using MiraAPI.Roles; + +namespace MiraAPI.Patches.Roles; + +[HarmonyPatch(typeof(ExileController))] +public static class EjectionPatches +{ + + [HarmonyPostfix] + [HarmonyPatch(nameof(ExileController.Begin))] + public static void Begin(ExileController __instance) + { + if (!__instance.exiled?.Role || __instance.exiled.Role is not ICustomRole role) + { + return; + } + + if (role.GetCustomEjectionMessage(__instance.exiled) == null) + { + return; + } + + __instance.completeString = role.GetCustomEjectionMessage(__instance.exiled); + } +} \ No newline at end of file diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 15807e6..fcb7cca 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -55,8 +55,6 @@ public interface ICustomRole MiraPluginInfo ParentMod => CustomRoleManager.FindParentMod(this); - void CreateOptions() { } - void PlayerControlFixedUpdate(PlayerControl playerControl) { } void HudUpdate(HudManager hudManager) { } From 8b55463fa02fa8ea1aab0da1d2f321f34b919e91 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:27:45 -0400 Subject: [PATCH 06/60] getting rid of IDE warnings --- MiraAPI.Example/CustomRole.cs | 2 +- MiraAPI.Example/CustomRole2.cs | 2 +- MiraAPI.Example/CustomRoleSettings.cs | 6 +++--- MiraAPI.Example/ExampleOptions.cs | 10 +++++----- MiraAPI.Example/SomeRandomNonGroupClass.cs | 4 ++-- MiraAPI/GameModes/CustomGameModeManager.cs | 2 +- MiraAPI/Patches/GameModes/ConsolePatches.cs | 6 +----- MiraAPI/Patches/GameModes/DeadBodyPatch.cs | 5 +---- MiraAPI/Patches/GameModes/GameLogicPatches.cs | 5 +---- MiraAPI/Patches/GameModes/ImpostorTargetPatch.cs | 5 +---- MiraAPI/Patches/GameModes/MapBehaviourPatch.cs | 5 +---- MiraAPI/Patches/GameModes/OnDeathPatch.cs | 5 +---- MiraAPI/Patches/GameModes/VentPatches.cs | 8 +------- MiraAPI/Patches/HudManagerPatches.cs | 1 - MiraAPI/Patches/IntroCutscenePatches.cs | 1 - MiraAPI/Patches/PlayerControlPatches.cs | 2 +- MiraAPI/Patches/Roles/TaskAdderPatch.cs | 8 ++++---- 17 files changed, 25 insertions(+), 52 deletions(-) diff --git a/MiraAPI.Example/CustomRole.cs b/MiraAPI.Example/CustomRole.cs index 47b361b..84c9274 100644 --- a/MiraAPI.Example/CustomRole.cs +++ b/MiraAPI.Example/CustomRole.cs @@ -15,6 +15,6 @@ public class CustomRole : ImpostorRole, ICustomRole public ModdedRoleTeams Team => ModdedRoleTeams.Impostor; public LoadableAsset OptionsScreenshot => MiraAssets.Banner; - [ModdedNumberOption("Testing level", min: 3, max: 9, roleType: typeof(CustomRole))] public float testingLevel { get; set; } = 4; + [ModdedNumberOption("Testing level", min: 3, max: 9, roleType: typeof(CustomRole))] public float TestingLevel { get; set; } = 4; } \ No newline at end of file diff --git a/MiraAPI.Example/CustomRole2.cs b/MiraAPI.Example/CustomRole2.cs index 3033a12..e03e057 100644 --- a/MiraAPI.Example/CustomRole2.cs +++ b/MiraAPI.Example/CustomRole2.cs @@ -15,6 +15,6 @@ public class CustomRole2 : CrewmateRole, ICustomRole public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; public LoadableAsset OptionsScreenshot => MiraAssets.Banner; - [ModdedToggleOption("Teleportation ability", roleType: typeof(CustomRole2))] public bool teleport { get; set; } = true; + [ModdedToggleOption("Teleportation ability", roleType: typeof(CustomRole2))] public bool Teleport { get; set; } = true; } \ No newline at end of file diff --git a/MiraAPI.Example/CustomRoleSettings.cs b/MiraAPI.Example/CustomRoleSettings.cs index 34cb47a..d8f6d7c 100644 --- a/MiraAPI.Example/CustomRoleSettings.cs +++ b/MiraAPI.Example/CustomRoleSettings.cs @@ -11,9 +11,9 @@ public class CustomRoleSettings : IModdedOptionGroup public Type AdvancedRole => typeof(CustomRole); - [ModdedNumberOption("amogus", min: 3, max: 9)] public float amogus { get; set; } = 1; + [ModdedNumberOption("amogus", min: 3, max: 9)] public float Amogus { get; set; } = 1; - [ModdedEnumOption("dwayne the rock johnson", typeof(TestEnum))] public TestEnum dwayneTheRockJohnson { get; set; } = TestEnum.Hello; + [ModdedEnumOption("dwayne the rock johnson", typeof(TestEnum))] public TestEnum DwayneTheRockJohnson { get; set; } = TestEnum.Hello; - public ModdedToggleOption testToggle { get; } = new ("test toggle", false); + public ModdedToggleOption TestToggle { get; } = new ("test toggle", false); } \ No newline at end of file diff --git a/MiraAPI.Example/ExampleOptions.cs b/MiraAPI.Example/ExampleOptions.cs index 4160189..0cbb0e3 100644 --- a/MiraAPI.Example/ExampleOptions.cs +++ b/MiraAPI.Example/ExampleOptions.cs @@ -10,19 +10,19 @@ public class ExampleOptions : IModdedOptionGroup public Color GroupColor => Color.red; [ModdedToggleOption("Use Thing")] - public bool useThing { get; set; } = false; + public bool UseThing { get; set; } = false; [ModdedToggleOption("Use another thing")] - public bool useAnotherThing { get; set; } = true; + public bool UseAnotherThing { get; set; } = true; [ModdedNumberOption("Sussy level", min: 0, max: 10)] - public float sussyLevel { get; set; } = 4f; + public float SussyLevel { get; set; } = 4f; [ModdedStringOption("Sus choices", ["hello", "hello 2", "hello 3"])] - public int susChoices { get; set; } = 2; + public int SusChoices { get; set; } = 2; [ModdedEnumOption("Enum test", typeof(TestEnum))] - public TestEnum enumTest { get; set; } = TestEnum.Bye; + public TestEnum EnumTest { get; set; } = TestEnum.Bye; } public enum TestEnum diff --git a/MiraAPI.Example/SomeRandomNonGroupClass.cs b/MiraAPI.Example/SomeRandomNonGroupClass.cs index 7e57075..b931ef6 100644 --- a/MiraAPI.Example/SomeRandomNonGroupClass.cs +++ b/MiraAPI.Example/SomeRandomNonGroupClass.cs @@ -4,6 +4,6 @@ namespace MiraAPI.Example; public class SomeRandomNonGroupClass { - [ModdedStringOption("Yeah, idk", ["Idk 1", "idk 2", "idk 3", "idk 4"])] public static int yeaIdk { get; set; } = 3; - [ModdedNumberOption("Aw man", min: 45, max: 95)] public float sussyLevel { get; set; } = 63; + [ModdedStringOption("Yeah, idk", ["Idk 1", "idk 2", "idk 3", "idk 4"])] public static int YeaIdk { get; set; } = 3; + [ModdedNumberOption("Aw man", min: 45, max: 95)] public float SussyLevel { get; set; } = 63; } \ No newline at end of file diff --git a/MiraAPI/GameModes/CustomGameModeManager.cs b/MiraAPI/GameModes/CustomGameModeManager.cs index 9426a2b..9fe2ce2 100644 --- a/MiraAPI/GameModes/CustomGameModeManager.cs +++ b/MiraAPI/GameModes/CustomGameModeManager.cs @@ -49,7 +49,7 @@ public static class CustomGameModeManager { if (!typeof(CustomGameMode).IsAssignableFrom(gameModeType)) { - Logger.Warning($"{gameModeType?.Name} does not inherit CustomGameMode!"); + Logger.Warning($"{gameModeType.Name} does not inherit CustomGameMode!"); return; } diff --git a/MiraAPI/Patches/GameModes/ConsolePatches.cs b/MiraAPI/Patches/GameModes/ConsolePatches.cs index c19a554..50248e7 100644 --- a/MiraAPI/Patches/GameModes/ConsolePatches.cs +++ b/MiraAPI/Patches/GameModes/ConsolePatches.cs @@ -1,8 +1,4 @@ -using HarmonyLib; -using InnerNet; -using MiraAPI.GameModes; - -namespace MiraAPI.Patches.GameModes; + /* [HarmonyPatch] public static class ConsolePatches diff --git a/MiraAPI/Patches/GameModes/DeadBodyPatch.cs b/MiraAPI/Patches/GameModes/DeadBodyPatch.cs index e61a52c..edd4e58 100644 --- a/MiraAPI/Patches/GameModes/DeadBodyPatch.cs +++ b/MiraAPI/Patches/GameModes/DeadBodyPatch.cs @@ -1,7 +1,4 @@ -using HarmonyLib; -using MiraAPI.GameModes; - -namespace MiraAPI.Patches.GameModes; + /* [HarmonyPatch(typeof(DeadBody))] diff --git a/MiraAPI/Patches/GameModes/GameLogicPatches.cs b/MiraAPI/Patches/GameModes/GameLogicPatches.cs index fee4cc4..77eca63 100644 --- a/MiraAPI/Patches/GameModes/GameLogicPatches.cs +++ b/MiraAPI/Patches/GameModes/GameLogicPatches.cs @@ -1,7 +1,4 @@ -using HarmonyLib; -using MiraAPI.GameModes; - -namespace MiraAPI.Patches.GameModes; + /* [HarmonyPatch] diff --git a/MiraAPI/Patches/GameModes/ImpostorTargetPatch.cs b/MiraAPI/Patches/GameModes/ImpostorTargetPatch.cs index 7657fde..58f1187 100644 --- a/MiraAPI/Patches/GameModes/ImpostorTargetPatch.cs +++ b/MiraAPI/Patches/GameModes/ImpostorTargetPatch.cs @@ -1,7 +1,4 @@ -using HarmonyLib; -using MiraAPI.GameModes; - -namespace MiraAPI.Patches.GameModes; + /* /// diff --git a/MiraAPI/Patches/GameModes/MapBehaviourPatch.cs b/MiraAPI/Patches/GameModes/MapBehaviourPatch.cs index 07512ec..8f17b99 100644 --- a/MiraAPI/Patches/GameModes/MapBehaviourPatch.cs +++ b/MiraAPI/Patches/GameModes/MapBehaviourPatch.cs @@ -1,7 +1,4 @@ -using HarmonyLib; -using MiraAPI.GameModes; - -namespace MiraAPI.Patches.GameModes; + /* [HarmonyPatch(typeof(MapBehaviour))] diff --git a/MiraAPI/Patches/GameModes/OnDeathPatch.cs b/MiraAPI/Patches/GameModes/OnDeathPatch.cs index e7589dd..275321d 100644 --- a/MiraAPI/Patches/GameModes/OnDeathPatch.cs +++ b/MiraAPI/Patches/GameModes/OnDeathPatch.cs @@ -1,7 +1,4 @@ -using HarmonyLib; -using MiraAPI.GameModes; - -namespace MiraAPI.Patches.GameModes; + /* [HarmonyPatch(typeof(KillAnimation))] diff --git a/MiraAPI/Patches/GameModes/VentPatches.cs b/MiraAPI/Patches/GameModes/VentPatches.cs index 7e53b98..a86aa46 100644 --- a/MiraAPI/Patches/GameModes/VentPatches.cs +++ b/MiraAPI/Patches/GameModes/VentPatches.cs @@ -1,10 +1,4 @@ -using HarmonyLib; -using MiraAPI.GameModes; -using MiraAPI.Roles; -using MiraAPI.Utilities; -using UnityEngine; - -namespace MiraAPI.Patches.GameModes; + /* [HarmonyPatch(typeof(Vent))] diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 9a1c56d..45cd890 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -1,6 +1,5 @@ using HarmonyLib; using InnerNet; -using MiraAPI.GameModes; using MiraAPI.Hud; using MiraAPI.Roles; using Reactor.Utilities.Extensions; diff --git a/MiraAPI/Patches/IntroCutscenePatches.cs b/MiraAPI/Patches/IntroCutscenePatches.cs index 7b395a5..9d95896 100644 --- a/MiraAPI/Patches/IntroCutscenePatches.cs +++ b/MiraAPI/Patches/IntroCutscenePatches.cs @@ -1,5 +1,4 @@ using HarmonyLib; -using MiraAPI.GameModes; using MiraAPI.Roles; using MiraAPI.Utilities; using UnityEngine; diff --git a/MiraAPI/Patches/PlayerControlPatches.cs b/MiraAPI/Patches/PlayerControlPatches.cs index 41ae0a9..cf67604 100644 --- a/MiraAPI/Patches/PlayerControlPatches.cs +++ b/MiraAPI/Patches/PlayerControlPatches.cs @@ -21,7 +21,7 @@ public static class PlayerControlPatches foreach (var button in CustomButtonManager.CustomButtons) { - if (!button.Enabled(__instance.Data.Role)) + if (!button.Enabled(__instance.Data?.Role)) { continue; } diff --git a/MiraAPI/Patches/Roles/TaskAdderPatch.cs b/MiraAPI/Patches/Roles/TaskAdderPatch.cs index cba0b73..fc32e14 100644 --- a/MiraAPI/Patches/Roles/TaskAdderPatch.cs +++ b/MiraAPI/Patches/Roles/TaskAdderPatch.cs @@ -160,23 +160,23 @@ public static class TaskAdderPatch RoleBehaviour roleBehaviour = DestroyableSingleton.Instance.AllRoles[m]; if (roleBehaviour.Role != RoleTypes.ImpostorGhost && roleBehaviour.Role != RoleTypes.CrewmateGhost && !CustomRoleManager.CustomRoles.ContainsKey((ushort)roleBehaviour.Role)) { - TaskAddButton taskAddButton2 = Object.Instantiate(__instance.RoleButton); + TaskAddButton 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); taskAddButton2.Role = roleBehaviour; if (taskAddButton2 != null && taskAddButton2.Button != null) { - ControllerManager.Instance.AddSelectableUiElement(taskAddButton2.Button, false); + ControllerManager.Instance.AddSelectableUiElement(taskAddButton2.Button); if (m == 0 && __instance.restorePreviousSelectionFound != null) { - ControllerManager.Instance.SetDefaultSelection(__instance.restorePreviousSelectionFound, null); + ControllerManager.Instance.SetDefaultSelection(__instance.restorePreviousSelectionFound); __instance.restorePreviousSelectionByFolderName = string.Empty; __instance.restorePreviousSelectionFound = null; } else if (m == 0) { - ControllerManager.Instance.SetDefaultSelection(taskAddButton2.Button, null); + ControllerManager.Instance.SetDefaultSelection(taskAddButton2.Button); } } } From 819588046492003fef0ae31ceed4acac45e6df2e Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:35:35 -0400 Subject: [PATCH 07/60] internalize --- .../Attributes/ModdedEnumOptionAttribute.cs | 3 +-- .../Attributes/ModdedNumberOptionAttribute.cs | 2 +- .../GameOptions/Attributes/ModdedOptionAttribute.cs | 4 ++-- .../Attributes/ModdedStringOptionAttribute.cs | 2 +- .../Attributes/ModdedToggleOptionAttribute.cs | 2 +- MiraAPI/GameOptions/ModdedOptionsManager.cs | 10 +++++----- MiraAPI/Hud/CustomButtonManager.cs | 4 ++-- MiraAPI/MiraApiPlugin.cs | 3 ++- MiraAPI/PluginLoading/MiraPluginManager.cs | 6 +++--- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/MiraAPI/GameOptions/Attributes/ModdedEnumOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedEnumOptionAttribute.cs index 898f45c..7a0878f 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedEnumOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedEnumOptionAttribute.cs @@ -7,8 +7,7 @@ namespace MiraAPI.GameOptions.Attributes; public class ModdedEnumOptionAttribute(string title, Type enumType, Type roleType = null) : ModdedOptionAttribute(title, roleType) { - - public override IModdedOption CreateOption(object value, PropertyInfo property) + internal override IModdedOption CreateOption(object value, PropertyInfo property) { var opt = new ModdedEnumOption(Title, (int)value, enumType, RoleType); return opt; diff --git a/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs index 2caf6c6..12aa255 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs @@ -14,7 +14,7 @@ public class ModdedNumberOptionAttribute( Type roleType = null) : ModdedOptionAttribute(title, roleType) { - public override IModdedOption CreateOption(object value, PropertyInfo property) + internal override IModdedOption CreateOption(object value, PropertyInfo property) { var toggleOpt = new ModdedNumberOption(Title, (float)value, min, max, increment, suffixType, zeroInfinity, RoleType); return toggleOpt; diff --git a/MiraAPI/GameOptions/Attributes/ModdedOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedOptionAttribute.cs index 9ea511a..09e686e 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedOptionAttribute.cs @@ -15,6 +15,6 @@ public abstract class ModdedOptionAttribute(string title, Type roleType = null) public abstract void SetValue(object val); public abstract object GetValue(); - - public abstract IModdedOption CreateOption(object value, PropertyInfo property); + + internal abstract IModdedOption CreateOption(object value, PropertyInfo property); } \ No newline at end of file diff --git a/MiraAPI/GameOptions/Attributes/ModdedStringOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedStringOptionAttribute.cs index 3148e29..1117bc7 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedStringOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedStringOptionAttribute.cs @@ -7,7 +7,7 @@ namespace MiraAPI.GameOptions.Attributes; public class ModdedStringOptionAttribute(string title, string[] values, Type roleType = null) : ModdedOptionAttribute(title, roleType) { - public override IModdedOption CreateOption(object value, PropertyInfo property) + internal override IModdedOption CreateOption(object value, PropertyInfo property) { var opt = new ModdedStringOption(Title, (int)value, values, RoleType); return opt; diff --git a/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs index a03470a..6a0ede2 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs @@ -6,7 +6,7 @@ namespace MiraAPI.GameOptions.Attributes; public class ModdedToggleOptionAttribute(string title, Type roleType = null) : ModdedOptionAttribute(title, roleType) { - public override IModdedOption CreateOption(object value, PropertyInfo property) + internal override IModdedOption CreateOption(object value, PropertyInfo property) { var toggleOpt = new ModdedToggleOption(Title, (bool)value, RoleType); return toggleOpt; diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index 88228a7..9433202 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -23,7 +23,7 @@ public class ModdedOptionsManager public static uint NextId => _nextId++; private static uint _nextId = 1; - public static IModdedOption RegisterOption(Type type, ModdedOptionAttribute attribute, PropertyInfo property) + internal static IModdedOption RegisterOption(Type type, ModdedOptionAttribute attribute, PropertyInfo property) { if (OptionAttributes.ContainsKey(property)) return null; object newObj = Activator.CreateInstance(type); @@ -66,7 +66,7 @@ public class ModdedOptionsManager return result; } - public static void SyncAllOptions(int targetId=-1) + internal static void SyncAllOptions(int targetId=-1) { List data = []; int count = 0; @@ -88,9 +88,9 @@ public class ModdedOptionsManager Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, data.ToArray()); } } - - - public static void HandleSyncOptions(NetData[] data) + + + internal static void HandleSyncOptions(NetData[] data) { foreach (var netData in data) { diff --git a/MiraAPI/Hud/CustomButtonManager.cs b/MiraAPI/Hud/CustomButtonManager.cs index 14fbf3b..2b09d7b 100644 --- a/MiraAPI/Hud/CustomButtonManager.cs +++ b/MiraAPI/Hud/CustomButtonManager.cs @@ -7,8 +7,8 @@ namespace MiraAPI.Hud; public static class CustomButtonManager { public static readonly List CustomButtons = []; - - public static void RegisterButton(Type buttonType) + + internal static void RegisterButton(Type buttonType) { if (!typeof(CustomActionButton).IsAssignableFrom(buttonType)) { diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index 9faf789..dd41045 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -19,7 +19,8 @@ namespace MiraAPI; public partial class MiraApiPlugin : BasePlugin { public Harmony Harmony { get; } = new(Id); - public static MiraPluginManager PluginManager { get; private set; } + private static MiraPluginManager PluginManager { get; set; } + public static Color MiraColor = new Color32(238, 154, 112, 255); public override void Load() diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index 17235bd..e736610 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -13,7 +13,7 @@ using MiraAPI.Hud; namespace MiraAPI.PluginLoading; -public class MiraPluginManager +internal class MiraPluginManager { public readonly Dictionary RegisteredPlugins = []; @@ -24,7 +24,7 @@ public class MiraPluginManager private set => _instance = value; } - public void Initialize() + internal void Initialize() { Instance = this; IL2CPPChainloader.Instance.PluginLoad += (_, assembly, plugin) => @@ -127,7 +127,7 @@ public class MiraPluginManager } } } - + private static void RegisterButtonAttribute(Assembly assembly) { foreach (var type in assembly.GetTypes()) From 205b89fd25538be1622aff20517e1322616f462e Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:35:55 -0400 Subject: [PATCH 08/60] try catch to fix file error with multi instance --- MiraAPI/Roles/CustomRoleManager.cs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 27cf965..d9ffa75 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -182,15 +182,25 @@ public static class CustomRoleManager { continue; } - - var num = BitConverter.ToInt32(netData.Data, 0); - var chance = BitConverter.ToInt32(netData.Data, 4); - - customRole.ParentMod.PluginConfig.TryGetEntry(customRole.NumConfigDefinition, out var numEntry); - customRole.ParentMod.PluginConfig.TryGetEntry(customRole.ChanceConfigDefinition, out var chanceEntry); - - numEntry.Value = num; - chanceEntry.Value = chance; + + try + { + + var num = BitConverter.ToInt32(netData.Data, 0); + var chance = BitConverter.ToInt32(netData.Data, 4); + + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.NumConfigDefinition, + out var numEntry); + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.ChanceConfigDefinition, + out var chanceEntry); + + numEntry.Value = num; + chanceEntry.Value = chance; + } + catch (Exception e) + { + Logger.Error(e); + } } } } From 1eff857989796dc1fb7aea4415583cd6a43ef261 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:47:09 -0400 Subject: [PATCH 09/60] braces for formatting --- .../GameModes/RegisterGameModeAttribute.cs | 5 ++- MiraAPI/GameOptions/ModdedGroupSingleton.cs | 6 ++- MiraAPI/GameOptions/ModdedOptionsManager.cs | 6 ++- .../OptionTypes/ModdedEnumOption.cs | 5 ++- .../OptionTypes/ModdedNumberOption.cs | 5 ++- .../OptionTypes/ModdedStringOption.cs | 5 ++- .../OptionTypes/ModdedToggleOption.cs | 5 ++- MiraAPI/Hud/CustomButtonSingleton.cs | 12 ++++- MiraAPI/Patches/HudManagerPatches.cs | 7 ++- .../Patches/Options/GameOptionsMenuPatch.cs | 22 +++++++-- .../Patches/Options/GameSettingMenuPatches.cs | 21 ++++++--- MiraAPI/Patches/Options/OptionsPatches.cs | 18 ++++++-- .../Patches/Options/RoleSettingMenuPatches.cs | 12 +++-- MiraAPI/Patches/PlayerControlPatches.cs | 7 ++- MiraAPI/PluginLoading/MiraPluginManager.cs | 22 ++++++--- MiraAPI/Roles/CustomRoleManager.cs | 45 ++++++++++--------- 16 files changed, 147 insertions(+), 56 deletions(-) diff --git a/MiraAPI/GameModes/RegisterGameModeAttribute.cs b/MiraAPI/GameModes/RegisterGameModeAttribute.cs index 2e7e9e3..b329d53 100644 --- a/MiraAPI/GameModes/RegisterGameModeAttribute.cs +++ b/MiraAPI/GameModes/RegisterGameModeAttribute.cs @@ -11,7 +11,10 @@ public class RegisterGameModeAttribute : Attribute internal static void Register(Assembly assembly) { - if (!RegisteredAssemblies.Add(assembly)) return; + if (!RegisteredAssemblies.Add(assembly)) + { + return; + } foreach (var type in assembly.GetTypes()) { diff --git a/MiraAPI/GameOptions/ModdedGroupSingleton.cs b/MiraAPI/GameOptions/ModdedGroupSingleton.cs index 8019537..637d00d 100644 --- a/MiraAPI/GameOptions/ModdedGroupSingleton.cs +++ b/MiraAPI/GameOptions/ModdedGroupSingleton.cs @@ -12,7 +12,11 @@ public class ModdedGroupSingleton where T : IModdedOptionGroup get => _instance ??= ModdedOptionsManager.Groups.OfType().Single(); set { - if (_instance != null) throw new InvalidOperationException($"Instance for {typeof(T)} is already set"); + if (_instance != null) + { + throw new InvalidOperationException($"Instance for {typeof(T)} is already set"); + } + _instance = value; } } diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index 9433202..9af63ea 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -25,7 +25,11 @@ public class ModdedOptionsManager internal static IModdedOption RegisterOption(Type type, ModdedOptionAttribute attribute, PropertyInfo property) { - if (OptionAttributes.ContainsKey(property)) return null; + if (OptionAttributes.ContainsKey(property)) + { + return null; + } + object newObj = Activator.CreateInstance(type); IModdedOption result; diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs index fabfb7e..96499b5 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs @@ -63,7 +63,10 @@ public class ModdedEnumOption : ModdedOption public override void OnValueChanged(int newValue) { DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false); - if (OptionBehaviour is null) return; + if (OptionBehaviour is null) + { + return; + } var opt = OptionBehaviour as StringOption; if (opt) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index 6a3a357..42c0d0c 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -90,7 +90,10 @@ public class ModdedNumberOption : ModdedOption Value = Mathf.Clamp(newValue, Min, Max); DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(Value), false); - if (OptionBehaviour is null) return; + if (OptionBehaviour is null) + { + return; + } var opt = OptionBehaviour as NumberOption; if (opt) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs index 2630a86..be6e2d1 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs @@ -63,7 +63,10 @@ public class ModdedStringOption : ModdedOption public override void OnValueChanged(int newValue) { DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false); - if (OptionBehaviour is null) return; + if (OptionBehaviour is null) + { + return; + } var opt = OptionBehaviour as StringOption; if (opt) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs index a859a1c..60683ed 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs @@ -55,7 +55,10 @@ public class ModdedToggleOption : ModdedOption public override void OnValueChanged(bool newValue) { DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false); - if (OptionBehaviour is null) return; + if (OptionBehaviour is null) + { + return; + } var toggleOpt = OptionBehaviour as ToggleOption; if (toggleOpt) diff --git a/MiraAPI/Hud/CustomButtonSingleton.cs b/MiraAPI/Hud/CustomButtonSingleton.cs index 0879802..9c609e3 100644 --- a/MiraAPI/Hud/CustomButtonSingleton.cs +++ b/MiraAPI/Hud/CustomButtonSingleton.cs @@ -17,8 +17,16 @@ public class CustomButtonSingleton where T : CustomActionButton get => _instance ??= CustomButtonManager.CustomButtons.OfType().Single(); set { - if (_instance == value) return; - if (_instance != null) throw new InvalidOperationException($"Instance for {typeof(T)} is already set"); + if (_instance == value) + { + return; + } + + if (_instance != null) + { + throw new InvalidOperationException($"Instance for {typeof(T)} is already set"); + } + _instance = value; } } diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 45cd890..1b60a8c 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -29,8 +29,11 @@ public static class HudManagerPatches //CustomGameModeManager.ActiveMode?.HudUpdate(__instance); - if (local?.Data?.Role is null) return; - + if (local?.Data?.Role is null) + { + return; + } + if (local.Data.Role is ICustomRole customRole) { customRole.HudUpdate(__instance); diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index f01a38c..66f0431 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -17,7 +17,10 @@ public static class GameOptionsMenuPatch [HarmonyPatch(nameof(GameOptionsMenu.CreateSettings))] public static bool SettingsPatch(GameOptionsMenu __instance) { - if (GameSettingMenuPatches.CurrentSelectedMod == 0) return true; + if (GameSettingMenuPatches.CurrentSelectedMod == 0) + { + return true; + } __instance.MapPicker.gameObject.SetActive(false); @@ -49,13 +52,21 @@ public static class GameOptionsMenuPatch SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren(true); for (int i = 0; i < componentsInChildren.Length; i++) { - if (group.GroupColor != Color.clear) componentsInChildren[i].color = group.GroupColor; + if (group.GroupColor != Color.clear) + { + componentsInChildren[i].color = group.GroupColor; + } + componentsInChildren[i].material.SetInt(PlayerMaterial.MaskLayer, 20); } foreach (TextMeshPro textMeshPro in newOpt.GetComponentsInChildren(true)) { - if (group.GroupColor != Color.clear) textMeshPro.color = group.GroupColor.DarkenColor(); + if (group.GroupColor != Color.clear) + { + textMeshPro.color = group.GroupColor.DarkenColor(); + } + textMeshPro.fontMaterial.SetFloat(ShaderID.StencilComp, 3f); textMeshPro.fontMaterial.SetFloat(ShaderID.Stencil, 20); } @@ -135,7 +146,10 @@ public static class GameOptionsMenuPatch optionBehaviour.SetAsPlayer(); } - if (optionBehaviour.IsCustom()) continue; + if (optionBehaviour.IsCustom()) + { + continue; + } optionBehaviour.OnValueChanged = new System.Action(__instance.ValueChanged); } diff --git a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs index fb153d1..47e002a 100644 --- a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs @@ -73,7 +73,7 @@ public static class GameSettingMenuPatches })); } - public static void UpdateText(GameOptionsMenu settings, RolesSettingsMenu roles) + private static void UpdateText(GameOptionsMenu settings, RolesSettingsMenu roles) { if (CurrentSelectedMod == 0) { @@ -90,11 +90,11 @@ public static class GameSettingMenuPatches UpdateText(settings, roles); } - string name = SelectedMod.PluginInfo.Metadata.Name; - _text.text = name.Substring(0, Math.Min(name.Length, 15)); + string name = SelectedMod?.PluginInfo.Metadata.Name; + _text.text = name?[..Math.Min(name.Length, 15)]; } - if (roles is not null && roles.roleChances is not null) + if (roles?.roleChances != null) { if (roles.advancedSettingChildren is not null) { @@ -124,12 +124,19 @@ public static class GameSettingMenuPatches roles.SetQuotaTab(); } - if (settings is not null && settings.Children is not null) + if (settings?.Children != null) { foreach (var child in settings.Children) { - if (child.TryCast()) continue; - if (child.gameObject is null) continue; + if (child.TryCast()) + { + continue; + } + + if (!child.gameObject) + { + continue; + } child.gameObject.DestroyImmediate(); } diff --git a/MiraAPI/Patches/Options/OptionsPatches.cs b/MiraAPI/Patches/Options/OptionsPatches.cs index 78009f5..de7da75 100644 --- a/MiraAPI/Patches/Options/OptionsPatches.cs +++ b/MiraAPI/Patches/Options/OptionsPatches.cs @@ -11,7 +11,11 @@ public static class OptionsPatches [HarmonyPatch(typeof(ToggleOption), nameof(ToggleOption.Initialize))] public static bool ToggleInit(ToggleOption __instance) { - if (!__instance.IsCustom()) return true; + if (!__instance.IsCustom()) + { + return true; + } + __instance.TitleText.text = DestroyableSingleton.Instance.GetString(__instance.Title, Array.Empty()); return false; @@ -28,7 +32,11 @@ public static class OptionsPatches [HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Initialize))] public static bool NumberInit(NumberOption __instance) { - if (!__instance.IsCustom()) return true; + if (!__instance.IsCustom()) + { + return true; + } + __instance.TitleText.text = DestroyableSingleton.Instance.GetString(__instance.Title, Array.Empty()); return false; @@ -45,7 +53,11 @@ public static class OptionsPatches [HarmonyPatch(typeof(StringOption), nameof(StringOption.Initialize))] public static bool StringInit(StringOption __instance) { - if (!__instance.IsCustom()) return true; + if (!__instance.IsCustom()) + { + return true; + } + __instance.TitleText.text = DestroyableSingleton.Instance.GetString(__instance.Title, Array.Empty()); __instance.ValueText.text = DestroyableSingleton.Instance.GetString(__instance.Values[__instance.Value], Array.Empty()); diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index cc0e1fc..33e76fb 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -104,7 +104,10 @@ public static class RoleSettingMenuPatches { var roleSetting = obj.Cast(); var role = roleSetting.Role as ICustomRole; - if (role is null or { HideSettings: true }) return; + if (role is null or { HideSettings: true }) + { + return; + } try { @@ -144,8 +147,11 @@ public static class RoleSettingMenuPatches foreach (var option in filteredOptions) { - if (option.AdvancedRole is not null && option.AdvancedRole != role.GetType()) continue; - + if (option.AdvancedRole is not null && option.AdvancedRole != role.GetType()) + { + continue; + } + OptionBehaviour 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); diff --git a/MiraAPI/Patches/PlayerControlPatches.cs b/MiraAPI/Patches/PlayerControlPatches.cs index cf67604..bf42041 100644 --- a/MiraAPI/Patches/PlayerControlPatches.cs +++ b/MiraAPI/Patches/PlayerControlPatches.cs @@ -12,8 +12,11 @@ public static class PlayerControlPatches [HarmonyPatch(nameof(PlayerControl.FixedUpdate))] public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance) { - if (!__instance.AmOwner) return; - + if (!__instance.AmOwner) + { + return; + } + if (__instance.Data?.Role is ICustomRole customRole) { customRole.PlayerControlFixedUpdate(__instance); diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index e736610..c42691b 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -29,7 +29,10 @@ internal class MiraPluginManager Instance = this; IL2CPPChainloader.Instance.PluginLoad += (_, assembly, plugin) => { - if (!plugin.GetType().GetInterfaces().Contains(typeof(IMiraPlugin))) return; + if (!plugin.GetType().GetInterfaces().Contains(typeof(IMiraPlugin))) + { + return; + } var id = MetadataHelper.GetMetadata(plugin.GetType()).GUID; var info = new MiraPluginInfo(id, plugin as IMiraPlugin, IL2CPPChainloader.Instance.Plugins[id]); @@ -74,7 +77,10 @@ internal class MiraPluginManager if (typeof(IModdedOptionGroup).IsAssignableFrom(type)) { IModdedOptionGroup group = (IModdedOptionGroup)Activator.CreateInstance(type); - if (group == null) continue; + if (group == null) + { + continue; + } ModdedOptionsManager.Groups.Add(group); ModdedOptionsManager.TypeToGroup.Add(type, group); @@ -86,8 +92,11 @@ internal class MiraPluginManager if (typeof(IModdedOption).IsAssignableFrom(property.PropertyType)) { IModdedOption option = (IModdedOption)property.GetValue(group); - if (option == null) continue; - + if (option == null) + { + continue; + } + option.HasGroup = true; option.AdvancedRole = group.AdvancedRole; @@ -104,7 +113,10 @@ internal class MiraPluginManager foreach (var type in assembly.GetTypes()) { var attribute = type.GetCustomAttribute(); - if (attribute == null) continue; + if (attribute == null) + { + continue; + } ClassInjector.RegisterTypeInIl2Cpp(type); diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index d9ffa75..329b3c6 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -175,32 +175,35 @@ public static class CustomRoleManager { foreach (var netData in data) { - if (CustomRoles.TryGetValue((ushort)netData.Id, out var role)) + if (!CustomRoles.TryGetValue((ushort)netData.Id, out var role)) { - var customRole = role as ICustomRole; - if (customRole is null or { HideSettings: true }) - { - continue; - } + continue; + } - try - { + var customRole = role as ICustomRole; + if (customRole is null or { HideSettings: true }) + { + continue; + } - var num = BitConverter.ToInt32(netData.Data, 0); - var chance = BitConverter.ToInt32(netData.Data, 4); + var num = BitConverter.ToInt32(netData.Data, 0); + var chance = BitConverter.ToInt32(netData.Data, 4); + + DestroyableSingleton.Instance.Notifier.AddRoleSettingsChangeMessage(role.StringName, num, chance, role.TeamType, false); - customRole.ParentMod.PluginConfig.TryGetEntry(customRole.NumConfigDefinition, - out var numEntry); - customRole.ParentMod.PluginConfig.TryGetEntry(customRole.ChanceConfigDefinition, - out var chanceEntry); + try + { + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.NumConfigDefinition, + out var numEntry); + customRole.ParentMod.PluginConfig.TryGetEntry(customRole.ChanceConfigDefinition, + out var chanceEntry); - numEntry.Value = num; - chanceEntry.Value = chance; - } - catch (Exception e) - { - Logger.Error(e); - } + numEntry.Value = num; + chanceEntry.Value = chance; + } + catch (Exception e) + { + Logger.Error(e); } } } From 5affd9f6f180f9d7a70b85c02942e02e47f6ac2e Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:49:59 -0400 Subject: [PATCH 10/60] fix hidden roles showing in settings --- .../Patches/Options/RoleSettingMenuPatches.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 33e76fb..6c88150 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -51,8 +51,13 @@ public static class RoleSettingMenuPatches categoryHeaderEditRole.transform.localPosition = new Vector3(4.986f, num, -2f); num -= 0.522f; int num3 = 0; + + var crewRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values + .OfType() + .Where(role => role.Team == ModdedRoleTeams.Crewmate && !role.HideSettings) + .ToList(); - foreach (var role in GameSettingMenuPatches.SelectedMod.CustomRoles.Values.OfType().Where(role => role.Team == ModdedRoleTeams.Crewmate)) + foreach (var role in crewRoles) { CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); num3++; @@ -64,8 +69,12 @@ public static class RoleSettingMenuPatches categoryHeaderEditRole2.transform.localPosition = new Vector3(4.986f, num, -2f); num -= 0.522f; + var impRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values + .OfType() + .Where(role => role.Team == ModdedRoleTeams.Impostor && !role.HideSettings) + .ToList(); - foreach (var role in GameSettingMenuPatches.SelectedMod.CustomRoles.Values.OfType().Where(role => role.Team == ModdedRoleTeams.Impostor)) + foreach (var role in impRoles) { CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); num3++; @@ -77,9 +86,13 @@ public static class RoleSettingMenuPatches categoryHeaderEditRole3.Title.text = "Neutral Roles"; categoryHeaderEditRole3.transform.localPosition = new Vector3(4.986f, num, -2f); num -= 0.522f; - - - foreach (var role in GameSettingMenuPatches.SelectedMod.CustomRoles.Values.OfType().Where(role => role.Team == ModdedRoleTeams.Neutral)) + + var neutRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values + .OfType() + .Where(role => role.Team == ModdedRoleTeams.Neutral && !role.HideSettings) + .ToList(); + + foreach (var role in neutRoles) { CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); num3++; From 119911b6296c48410022356a7c4220a5d67205f5 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:51:31 -0400 Subject: [PATCH 11/60] shift view pane buttons and text --- MiraAPI/Patches/Options/LobbyViewPanePatches.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index 7a69c3c..011b421 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -14,14 +14,12 @@ public static class LobbyViewPanePatches [HarmonyPatch(nameof(LobbyViewSettingsPane.Awake))] public static void AwakePatch(LobbyViewSettingsPane __instance) { - __instance.gameModeText.transform.localPosition = new Vector3(-4.3f, 2.4f, -2); - __instance.gameModeText.horizontalAlignment = HorizontalAlignmentOptions.Center; - __instance.gameModeText.fontSizeMax = 10f; - __instance.gameModeText.margin = new Vector4(1,0,1,0); + __instance.gameModeText.transform.localPosition = new Vector3(-2.3f, 2.4f, -2); // Create the next button GameObject nextButton = Object.Instantiate(__instance.BackButton, __instance.BackButton.transform.parent).gameObject; - nextButton.transform.localPosition = new Vector3(-2.3f, 2.4f, -2f); + nextButton.GetComponent().size = new Vector2(0.2f, 0.3f); + nextButton.transform.localPosition = new Vector3(-5.4f, 2.4f, -2f); nextButton.transform.localScale = new Vector3(3, 3, 2); nextButton.name = "RightArrowButton"; From f9a587257bbc9069cdc74e5442a146391b3c8126 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:03:27 -0400 Subject: [PATCH 12/60] fix format strings for options --- MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index 42c0d0c..a959313 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -37,7 +37,7 @@ public class ModdedNumberOption : ModdedOption data.Value = Value; data.Increment = Increment; data.ValidRange = new FloatRange(Min, Max); - data.FormatString = Increment % 1 == 0 ? "0" : "0.0"; + data.FormatString = Increment % 1 == 0 && Value % 1 == 0 && Min % 1 == 0 && Max % 1 == 0 ? "0" : "0.0"; data.ZeroIsInfinity = ZeroInfinity; data.SuffixType = SuffixType; data.OptionName = FloatOptionNames.Invalid; @@ -54,7 +54,7 @@ public class ModdedNumberOption : ModdedOption numberOption.Value = Value; numberOption.Increment = Increment; numberOption.ValidRange = new FloatRange(Min, Max); - numberOption.FormatString = "0"; + numberOption.FormatString = ((FloatGameSetting)Data).FormatString; numberOption.ZeroIsInfinity = ZeroInfinity; numberOption.SuffixType = SuffixType; numberOption.floatOptionName = FloatOptionNames.Invalid; From 382fabb4bbb2b42c7c192030c68492b951e04289 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:08:05 -0400 Subject: [PATCH 13/60] Change options system to force all options into groups --- .../{ => Buttons}/ExampleButton.cs | 2 +- MiraAPI.Example/CustomRoleSettings.cs | 19 --- .../{ => Options}/ExampleOptions.cs | 2 +- .../{ => Options}/ExampleOptions2.cs | 2 +- .../Options/Roles/CustomRole2Settings.cs | 17 ++ .../Options/Roles/CustomRoleSettings.cs | 17 ++ MiraAPI.Example/{ => Roles}/CustomRole.cs | 9 +- MiraAPI.Example/{ => Roles}/CustomRole2.cs | 9 +- MiraAPI.Example/{ => Roles}/CustomRole3.cs | 2 +- MiraAPI.Example/SomeRandomNonGroupClass.cs | 9 - MiraAPI/GameOptions/IModdedOption.cs | 1 - MiraAPI/GameOptions/ModdedGroupSingleton.cs | 2 +- MiraAPI/GameOptions/ModdedOptionsManager.cs | 154 +++++++++++------- .../GameOptions/OptionTypes/ModdedOption.cs | 1 - .../Patches/Options/GameOptionsMenuPatch.cs | 44 +---- MiraAPI/PluginLoading/MiraPluginManager.cs | 63 +++---- 16 files changed, 163 insertions(+), 190 deletions(-) rename MiraAPI.Example/{ => Buttons}/ExampleButton.cs (95%) delete mode 100644 MiraAPI.Example/CustomRoleSettings.cs rename MiraAPI.Example/{ => Options}/ExampleOptions.cs (95%) rename MiraAPI.Example/{ => Options}/ExampleOptions2.cs (95%) create mode 100644 MiraAPI.Example/Options/Roles/CustomRole2Settings.cs create mode 100644 MiraAPI.Example/Options/Roles/CustomRoleSettings.cs rename MiraAPI.Example/{ => Roles}/CustomRole.cs (71%) rename MiraAPI.Example/{ => Roles}/CustomRole2.cs (71%) rename MiraAPI.Example/{ => Roles}/CustomRole3.cs (94%) delete mode 100644 MiraAPI.Example/SomeRandomNonGroupClass.cs diff --git a/MiraAPI.Example/ExampleButton.cs b/MiraAPI.Example/Buttons/ExampleButton.cs similarity index 95% rename from MiraAPI.Example/ExampleButton.cs rename to MiraAPI.Example/Buttons/ExampleButton.cs index d7058bc..a7aa9fb 100644 --- a/MiraAPI.Example/ExampleButton.cs +++ b/MiraAPI.Example/Buttons/ExampleButton.cs @@ -3,7 +3,7 @@ using MiraAPI.Utilities.Assets; using Reactor.Utilities; using UnityEngine; -namespace MiraAPI.Example; +namespace MiraAPI.Example.Buttons; [RegisterButton] public class ExampleButton : CustomActionButton diff --git a/MiraAPI.Example/CustomRoleSettings.cs b/MiraAPI.Example/CustomRoleSettings.cs deleted file mode 100644 index d8f6d7c..0000000 --- a/MiraAPI.Example/CustomRoleSettings.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using MiraAPI.GameOptions; -using MiraAPI.GameOptions.Attributes; -using MiraAPI.GameOptions.OptionTypes; - -namespace MiraAPI.Example; - -public class CustomRoleSettings : IModdedOptionGroup -{ - public string GroupName => "Custom Role"; - - public Type AdvancedRole => typeof(CustomRole); - - [ModdedNumberOption("amogus", min: 3, max: 9)] public float Amogus { get; set; } = 1; - - [ModdedEnumOption("dwayne the rock johnson", typeof(TestEnum))] public TestEnum DwayneTheRockJohnson { get; set; } = TestEnum.Hello; - - public ModdedToggleOption TestToggle { get; } = new ("test toggle", false); -} \ No newline at end of file diff --git a/MiraAPI.Example/ExampleOptions.cs b/MiraAPI.Example/Options/ExampleOptions.cs similarity index 95% rename from MiraAPI.Example/ExampleOptions.cs rename to MiraAPI.Example/Options/ExampleOptions.cs index 0cbb0e3..6c674a6 100644 --- a/MiraAPI.Example/ExampleOptions.cs +++ b/MiraAPI.Example/Options/ExampleOptions.cs @@ -2,7 +2,7 @@ using MiraAPI.GameOptions.Attributes; using UnityEngine; -namespace MiraAPI.Example; +namespace MiraAPI.Example.Options; public class ExampleOptions : IModdedOptionGroup { diff --git a/MiraAPI.Example/ExampleOptions2.cs b/MiraAPI.Example/Options/ExampleOptions2.cs similarity index 95% rename from MiraAPI.Example/ExampleOptions2.cs rename to MiraAPI.Example/Options/ExampleOptions2.cs index e6b8fb6..42c316f 100644 --- a/MiraAPI.Example/ExampleOptions2.cs +++ b/MiraAPI.Example/Options/ExampleOptions2.cs @@ -1,7 +1,7 @@ using MiraAPI.GameOptions; using MiraAPI.GameOptions.OptionTypes; -namespace MiraAPI.Example; +namespace MiraAPI.Example.Options; public class ExampleOptions2 : IModdedOptionGroup { diff --git a/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs b/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs new file mode 100644 index 0000000..9712dcd --- /dev/null +++ b/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs @@ -0,0 +1,17 @@ +using System; +using MiraAPI.Example.Roles; +using MiraAPI.GameOptions; +using MiraAPI.GameOptions.Attributes; +using MiraAPI.GameOptions.OptionTypes; + +namespace MiraAPI.Example.Options.Roles; + +public class CustomRole2Settings : IModdedOptionGroup +{ + public string GroupName => "Custom Role"; + + public Type AdvancedRole => typeof(CustomRole2); + + [ModdedToggleOption("Teleportation ability")] public bool Teleport { get; set; } = true; + +} \ No newline at end of file diff --git a/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs b/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs new file mode 100644 index 0000000..484ad6f --- /dev/null +++ b/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs @@ -0,0 +1,17 @@ +using System; +using MiraAPI.Example.Roles; +using MiraAPI.GameOptions; +using MiraAPI.GameOptions.Attributes; +using MiraAPI.GameOptions.OptionTypes; + +namespace MiraAPI.Example.Options.Roles; + +public class CustomRoleSettings : IModdedOptionGroup +{ + public string GroupName => "Custom Role"; + + public Type AdvancedRole => typeof(CustomRole); + + [ModdedNumberOption("Testing level", min: 3, max: 9)] public float TestingLevel { get; set; } = 4; + +} \ No newline at end of file diff --git a/MiraAPI.Example/CustomRole.cs b/MiraAPI.Example/Roles/CustomRole.cs similarity index 71% rename from MiraAPI.Example/CustomRole.cs rename to MiraAPI.Example/Roles/CustomRole.cs index 84c9274..44dfbe8 100644 --- a/MiraAPI.Example/CustomRole.cs +++ b/MiraAPI.Example/Roles/CustomRole.cs @@ -1,9 +1,8 @@ -using MiraAPI.GameOptions.Attributes; -using MiraAPI.Roles; +using MiraAPI.Roles; using MiraAPI.Utilities.Assets; using UnityEngine; -namespace MiraAPI.Example; +namespace MiraAPI.Example.Roles; [RegisterCustomRole] public class CustomRole : ImpostorRole, ICustomRole @@ -14,7 +13,5 @@ public class CustomRole : ImpostorRole, ICustomRole public Color RoleColor => Palette.Orange; public ModdedRoleTeams Team => ModdedRoleTeams.Impostor; public LoadableAsset OptionsScreenshot => MiraAssets.Banner; - - [ModdedNumberOption("Testing level", min: 3, max: 9, roleType: typeof(CustomRole))] public float TestingLevel { get; set; } = 4; - + } \ No newline at end of file diff --git a/MiraAPI.Example/CustomRole2.cs b/MiraAPI.Example/Roles/CustomRole2.cs similarity index 71% rename from MiraAPI.Example/CustomRole2.cs rename to MiraAPI.Example/Roles/CustomRole2.cs index e03e057..b5bbe48 100644 --- a/MiraAPI.Example/CustomRole2.cs +++ b/MiraAPI.Example/Roles/CustomRole2.cs @@ -1,9 +1,8 @@ -using MiraAPI.GameOptions.Attributes; -using MiraAPI.Roles; +using MiraAPI.Roles; using MiraAPI.Utilities.Assets; using UnityEngine; -namespace MiraAPI.Example; +namespace MiraAPI.Example.Roles; [RegisterCustomRole] public class CustomRole2 : CrewmateRole, ICustomRole @@ -14,7 +13,5 @@ public class CustomRole2 : CrewmateRole, ICustomRole public Color RoleColor => Palette.AcceptedGreen; public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; public LoadableAsset OptionsScreenshot => MiraAssets.Banner; - - [ModdedToggleOption("Teleportation ability", roleType: typeof(CustomRole2))] public bool Teleport { get; set; } = true; - + } \ No newline at end of file diff --git a/MiraAPI.Example/CustomRole3.cs b/MiraAPI.Example/Roles/CustomRole3.cs similarity index 94% rename from MiraAPI.Example/CustomRole3.cs rename to MiraAPI.Example/Roles/CustomRole3.cs index bf309d8..a97f9df 100644 --- a/MiraAPI.Example/CustomRole3.cs +++ b/MiraAPI.Example/Roles/CustomRole3.cs @@ -2,7 +2,7 @@ using MiraAPI.Utilities.Assets; using UnityEngine; -namespace MiraAPI.Example; +namespace MiraAPI.Example.Roles; [RegisterCustomRole] public class CustomRole3 : CrewmateRole, ICustomRole diff --git a/MiraAPI.Example/SomeRandomNonGroupClass.cs b/MiraAPI.Example/SomeRandomNonGroupClass.cs deleted file mode 100644 index b931ef6..0000000 --- a/MiraAPI.Example/SomeRandomNonGroupClass.cs +++ /dev/null @@ -1,9 +0,0 @@ -using MiraAPI.GameOptions.Attributes; - -namespace MiraAPI.Example; - -public class SomeRandomNonGroupClass -{ - [ModdedStringOption("Yeah, idk", ["Idk 1", "idk 2", "idk 3", "idk 4"])] public static int YeaIdk { get; set; } = 3; - [ModdedNumberOption("Aw man", min: 45, max: 95)] public float SussyLevel { get; set; } = 63; -} \ No newline at end of file diff --git a/MiraAPI/GameOptions/IModdedOption.cs b/MiraAPI/GameOptions/IModdedOption.cs index a041cc7..eaa7add 100644 --- a/MiraAPI/GameOptions/IModdedOption.cs +++ b/MiraAPI/GameOptions/IModdedOption.cs @@ -9,7 +9,6 @@ public interface IModdedOption { public uint Id { get; } public BaseGameSetting Data { get; } - public bool HasGroup { get; set; } public IMiraPlugin ParentMod { get; set; } public Type AdvancedRole { get; set; } public OptionBehaviour OptionBehaviour { get; protected set; } diff --git a/MiraAPI/GameOptions/ModdedGroupSingleton.cs b/MiraAPI/GameOptions/ModdedGroupSingleton.cs index 637d00d..265cc2a 100644 --- a/MiraAPI/GameOptions/ModdedGroupSingleton.cs +++ b/MiraAPI/GameOptions/ModdedGroupSingleton.cs @@ -9,7 +9,7 @@ public class ModdedGroupSingleton where T : IModdedOptionGroup public static T Instance { - get => _instance ??= ModdedOptionsManager.Groups.OfType().Single(); + get => _instance ??= ModdedOptionsManager.Groups.Keys.OfType().Single(); set { if (_instance != null) diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index 9af63ea..f61556c 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using MiraAPI.Networking; +using MiraAPI.PluginLoading; using Reactor.Networking.Rpc; namespace MiraAPI.GameOptions; @@ -13,80 +14,121 @@ namespace MiraAPI.GameOptions; public class ModdedOptionsManager { private static readonly Dictionary OptionAttributes = new(); + private static readonly Dictionary TypeToGroup = new(); public static readonly Dictionary ModdedOptions = new(); - public static readonly Dictionary> GroupedOptions = new(); + public static readonly Dictionary> Groups = new(); - public static readonly List Groups = []; - public static readonly Dictionary TypeToGroup = new(); public static uint NextId => _nextId++; private static uint _nextId = 1; + + internal static bool RegisterGroup(Type type, MiraPluginInfo pluginInfo) + { + var group = (IModdedOptionGroup)Activator.CreateInstance(type); + + if (group == null) + { + Logger.Error($"Failed to create group from {type.Name}"); + return false; + } - internal static IModdedOption RegisterOption(Type type, ModdedOptionAttribute attribute, PropertyInfo property) + if (TypeToGroup.ContainsKey(type)) + { + Logger.Error($"Group {type.Name} already exists."); + return false; + } + + Groups.Add(group, []); + TypeToGroup.Add(type, group); + pluginInfo.OptionGroups.Add(group); + + return true; + } + + internal static void RegisterPropertyOption(Type type, PropertyInfo property, MiraPluginInfo pluginInfo) + { + if (!TypeToGroup.TryGetValue(type, out var group)) + { + Logger.Error($"Failed to get group for {type.Name}"); + return; + } + + var option = (IModdedOption) property.GetValue(group); + + if (option == null) + { + Logger.Error($"Failed to get option for {property.Name}"); + return; + } + + option.ParentMod = pluginInfo.MiraPlugin; + option.AdvancedRole = group.AdvancedRole; + pluginInfo.Options.Add(option); + + Groups[group].Add(option); + } + + internal static void RegisterAttributeOption(Type type, ModdedOptionAttribute attribute, PropertyInfo property, MiraPluginInfo pluginInfo) { if (OptionAttributes.ContainsKey(property)) { - return null; + Logger.Error($"Property {property.Name} already has an attribute registered."); + return; } - object newObj = Activator.CreateInstance(type); - - IModdedOption result; - - try - { - result = attribute.CreateOption(property.GetValue(newObj), property); - } - catch (Exception e) + if (!TypeToGroup.TryGetValue(type, out var group)) { - Logger.Error(e); - return null; + Logger.Error($"Failed to get group for {type.Name}"); + return; } - if (result != null) + var option = attribute.CreateOption(property.GetValue(group), property); + + if (option == null) { - var setterOriginal = property.GetSetMethod(); - var setterPatch = typeof(ModdedOptionsManager).GetMethod(nameof(PropertySetterPatch)); - PluginSingleton.Instance.Harmony.Patch(setterOriginal, postfix: new HarmonyMethod(setterPatch)); - - var getterOriginal = property.GetGetMethod(); - var getterPatch = typeof(ModdedOptionsManager).GetMethod(nameof(PropertyGetterPatch)); - PluginSingleton.Instance.Harmony.Patch(getterOriginal, prefix: new HarmonyMethod(getterPatch)); - - attribute.HolderOption = result; - - OptionAttributes.Add(property, attribute); - - if (TypeToGroup.ContainsKey(type)) - { - Logger.Error($"Grouping {attribute.Title} with {TypeToGroup[type].GroupName}"); - GroupedOptions[TypeToGroup[type]].Add(result); - result.HasGroup = true; - result.AdvancedRole = TypeToGroup[type].AdvancedRole; - } + Logger.Error($"Failed to get option for {property.Name}"); + return; } + + var setterOriginal = property.GetSetMethod(); + var setterPatch = typeof(ModdedOptionsManager).GetMethod(nameof(PropertySetterPatch)); + PluginSingleton.Instance.Harmony.Patch(setterOriginal, postfix: new HarmonyMethod(setterPatch)); - return result; + var getterOriginal = property.GetGetMethod(); + var getterPatch = typeof(ModdedOptionsManager).GetMethod(nameof(PropertyGetterPatch)); + PluginSingleton.Instance.Harmony.Patch(getterOriginal, prefix: new HarmonyMethod(getterPatch)); + + OptionAttributes.Add(property, attribute); + attribute.HolderOption = option; + + option.ParentMod = pluginInfo.MiraPlugin; + option.AdvancedRole = group.AdvancedRole; + pluginInfo.Options.Add(option); + + Groups[group].Add(option); } internal static void SyncAllOptions(int targetId=-1) { List data = []; - int count = 0; - foreach (var option in ModdedOptions.Values) + + var count = 0; + foreach (var netData in ModdedOptions.Values.Select(option => option.GetNetData())) { - var netData = option.GetNetData(); data.Add(netData); count += netData.GetLength(); - - if (count > 1000) + + if (count <= 1000) { - Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, data.ToArray()); - data.Clear(); - count = 0; + continue; } + + Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, data.ToArray()); + data.Clear(); + count = 0; } + if (data.Count > 0) { Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, data.ToArray()); @@ -98,11 +140,13 @@ public class ModdedOptionsManager { foreach (var netData in data) { - if (ModdedOptions.TryGetValue(netData.Id, out var option)) + if (!ModdedOptions.TryGetValue(netData.Id, out var option)) { - Logger.Error("Handling option " + option.Title); - option.HandleNetData(netData.Data); + continue; } + + Logger.Error("Handling option " + option.Title); + option.HandleNetData(netData.Data); } } @@ -111,21 +155,19 @@ public class ModdedOptionsManager { ModdedOptionAttribute attribute = OptionAttributes.First(pair => pair.Key.GetSetMethod().Equals(__originalMethod)).Value; - if (attribute != null) - { - attribute.SetValue(value); - } + attribute?.SetValue(value); } public static bool PropertyGetterPatch(MethodBase __originalMethod, ref object __result) { ModdedOptionAttribute attribute = OptionAttributes.First(pair => pair.Key.GetGetMethod().Equals(__originalMethod)).Value; - if (attribute != null) + if (attribute == null) { - __result = attribute.GetValue(); - return false; + return true; } - return true; + + __result = attribute.GetValue(); + return false; } } \ No newline at end of file diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index 3021cd1..5bd07cb 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -12,7 +12,6 @@ public abstract class ModdedOption : IModdedOption { public uint Id { get; } public BaseGameSetting Data { get; protected init; } - public bool HasGroup { get; set; } = false; public IMiraPlugin ParentMod { get; set; } = null; public T Value { get; protected set; } public T DefaultValue { get; init; } diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index 66f0431..ea622cb 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -41,7 +41,7 @@ public static class GameOptionsMenuPatch categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f); num -= 0.63f; - var filteredOpts = ModdedOptionsManager.GroupedOptions[group].Where(x=>x.Visible.Invoke()).ToList(); + var filteredOpts = ModdedOptionsManager.Groups[group].Where(x=>x.Visible.Invoke()).ToList(); foreach (var opt in filteredOpts) { @@ -78,48 +78,6 @@ public static class GameOptionsMenuPatch } } - var filteredOptions = GameSettingMenuPatches.SelectedMod.Options.Where(x => x.AdvancedRole is null && !x.HasGroup).ToList(); - - if (filteredOptions.Count > 0) - { - - CategoryHeaderMasked ungroupedHeader = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, - Quaternion.identity, __instance.settingsContainer); - ungroupedHeader.SetHeader(CustomStringName.CreateAndRegister("Ungrouped Options"), 20); - ungroupedHeader.transform.localScale = Vector3.one * 0.63f; - ungroupedHeader.transform.localPosition = new Vector3(-0.903f, num, -2f); - - num -= 0.63f; - - - foreach (var opt in filteredOptions) - { - OptionBehaviour newOpt = opt.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, - __instance.stringOptionOrigin, __instance.settingsContainer); - newOpt.transform.localPosition = new Vector3(0.952f, num, -2f); - newOpt.SetClickMask(__instance.ButtonClickMask); - newOpt.SetUpFromData(newOpt.data, 20); - - SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren(true); - for (int i = 0; i < componentsInChildren.Length; i++) - { - componentsInChildren[i].material.SetInt(PlayerMaterial.MaskLayer, 20); - } - - foreach (TextMeshPro textMeshPro in newOpt.GetComponentsInChildren(true)) - { - textMeshPro.fontMaterial.SetFloat(ShaderID.StencilComp, 3f); - textMeshPro.fontMaterial.SetFloat(ShaderID.Stencil, 20); - } - - __instance.Children.Add(newOpt); - - num -= 0.45f; - - newOpt.Initialize(); - } - } - __instance.scrollBar.SetYBoundsMax(-num - 1.65f); return false; diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index c42691b..45dccb2 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -37,8 +37,8 @@ internal class MiraPluginManager var id = MetadataHelper.GetMetadata(plugin.GetType()).GUID; var info = new MiraPluginInfo(id, plugin as IMiraPlugin, IL2CPPChainloader.Instance.Plugins[id]); - RegisterOptionsGroups(assembly, info); - RegisterOptionsAttributes(assembly, info); + RegisterAllOptions(assembly, info); + RegisterRoleAttribute(assembly, info); RegisterButtonAttribute(assembly); @@ -53,57 +53,32 @@ internal class MiraPluginManager return RegisteredPlugins.Values.First(plugin => plugin.PluginId == guid); } - private static void RegisterOptionsAttributes(Assembly assembly, MiraPluginInfo pluginInfo) + private static void RegisterAllOptions(Assembly assembly, MiraPluginInfo pluginInfo) { - foreach (var type in assembly.GetTypes()) + var filteredTypes = assembly.GetTypes().Where(type => type.IsAssignableTo(typeof(IModdedOptionGroup))); + + foreach (var type in filteredTypes) { - foreach (PropertyInfo property in type.GetProperties()) + if (!ModdedOptionsManager.RegisterGroup(type, pluginInfo)) { - foreach (var attribute in property.GetCustomAttributes()) - { - if (attribute.GetType().BaseType == typeof(ModdedOptionAttribute)) - { - pluginInfo.Options.Add(ModdedOptionsManager.RegisterOption(type, (ModdedOptionAttribute)attribute, property)); - } - } + continue; } - } - } - - private static void RegisterOptionsGroups(Assembly assembly, MiraPluginInfo pluginInfo) - { - foreach (var type in assembly.GetTypes()) - { - if (typeof(IModdedOptionGroup).IsAssignableFrom(type)) + + foreach (var property in type.GetProperties()) { - IModdedOptionGroup group = (IModdedOptionGroup)Activator.CreateInstance(type); - if (group == null) + if (property.PropertyType.IsAssignableTo(typeof(IModdedOption))) + { + ModdedOptionsManager.RegisterPropertyOption(type, property, pluginInfo); + continue; + } + + var attribute = property.GetCustomAttribute(); + if (attribute == null) { continue; } - ModdedOptionsManager.Groups.Add(group); - ModdedOptionsManager.TypeToGroup.Add(type, group); - ModdedOptionsManager.GroupedOptions.Add(group, []); - pluginInfo.OptionGroups.Add(group); - - foreach (var property in type.GetProperties()) - { - if (typeof(IModdedOption).IsAssignableFrom(property.PropertyType)) - { - IModdedOption option = (IModdedOption)property.GetValue(group); - if (option == null) - { - continue; - } - - option.HasGroup = true; - option.AdvancedRole = group.AdvancedRole; - - ModdedOptionsManager.GroupedOptions[group].Add(option); - pluginInfo.Options.Add(option); - } - } + ModdedOptionsManager.RegisterAttributeOption(type, attribute, property, pluginInfo); } } } From 22be3c24f3895a1227fc585b8494d753c1746026 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:11:16 -0400 Subject: [PATCH 14/60] make sure only options picked up by Manager get registered into list --- MiraAPI/GameOptions/ModdedOptionsManager.cs | 14 ++++++++------ MiraAPI/GameOptions/OptionTypes/ModdedOption.cs | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index f61556c..39a8532 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -62,11 +62,7 @@ public class ModdedOptionsManager return; } - option.ParentMod = pluginInfo.MiraPlugin; - option.AdvancedRole = group.AdvancedRole; - pluginInfo.Options.Add(option); - - Groups[group].Add(option); + RegisterOption(option, group, pluginInfo); } internal static void RegisterAttributeOption(Type type, ModdedOptionAttribute attribute, PropertyInfo property, MiraPluginInfo pluginInfo) @@ -102,13 +98,19 @@ public class ModdedOptionsManager OptionAttributes.Add(property, attribute); attribute.HolderOption = option; + RegisterOption(option, group, pluginInfo); + } + + private static void RegisterOption(IModdedOption option, IModdedOptionGroup group, MiraPluginInfo pluginInfo) + { option.ParentMod = pluginInfo.MiraPlugin; option.AdvancedRole = group.AdvancedRole; pluginInfo.Options.Add(option); + ModdedOptions.Add(option.Id, option); Groups[group].Add(option); } - + internal static void SyncAllOptions(int targetId=-1) { List data = []; diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index 5bd07cb..f34754d 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -39,7 +39,6 @@ public abstract class ModdedOption : IModdedOption private ModdedOption() { Id = ModdedOptionsManager.NextId; - ModdedOptionsManager.ModdedOptions.Add(Id, this); } public void ValueChanged(OptionBehaviour optionBehaviour) From 612df4bb3c1e2b20504d57c16491b2943c467ea4 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:41:48 -0400 Subject: [PATCH 15/60] update example --- .../Options/Roles/CustomRole2Settings.cs | 1 - .../Options/Roles/CustomRoleSettings.cs | 1 - MiraAPI/GameOptions/IModdedOptionGroup.cs | 15 +++++++++++++++ MiraAPI/Patches/Options/LobbyViewPanePatches.cs | 1 - 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs b/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs index 9712dcd..e0e9d1a 100644 --- a/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs +++ b/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs @@ -2,7 +2,6 @@ using MiraAPI.Example.Roles; using MiraAPI.GameOptions; using MiraAPI.GameOptions.Attributes; -using MiraAPI.GameOptions.OptionTypes; namespace MiraAPI.Example.Options.Roles; diff --git a/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs b/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs index 484ad6f..98882ae 100644 --- a/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs +++ b/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs @@ -2,7 +2,6 @@ using MiraAPI.Example.Roles; using MiraAPI.GameOptions; using MiraAPI.GameOptions.Attributes; -using MiraAPI.GameOptions.OptionTypes; namespace MiraAPI.Example.Options.Roles; diff --git a/MiraAPI/GameOptions/IModdedOptionGroup.cs b/MiraAPI/GameOptions/IModdedOptionGroup.cs index d5d23fa..6297011 100644 --- a/MiraAPI/GameOptions/IModdedOptionGroup.cs +++ b/MiraAPI/GameOptions/IModdedOptionGroup.cs @@ -5,8 +5,23 @@ namespace MiraAPI.GameOptions; public interface IModdedOptionGroup { + /// + /// The name of the group. Visible in options menu. + /// public string GroupName { get; } + + /// + /// A function that returns whether the group should be visible or not. + /// public Func GroupVisible => () => true; + + /// + /// The group color. This is used to color the group in the options menu. + /// public Color GroupColor => Color.clear; + + /// + /// The role the group is associated with. This is used for the advanced role options menu. + /// public Type AdvancedRole => null; } \ No newline at end of file diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index 011b421..0f2fc49 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -1,6 +1,5 @@ using HarmonyLib; using MiraAPI.Utilities.Assets; -using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; From c11fe14fd219e4797a9dcc7d400ee1afe6a5cd79 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:17:45 -0400 Subject: [PATCH 16/60] Update README.md --- README.md | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0033b63..fbf2979 100644 --- a/README.md +++ b/README.md @@ -32,28 +32,43 @@ See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Ex ## Options Options are also very simple in Mira API. Options are split up into Groups and Options. Every Option needs to be in a Group. -To create a group, you need to create a class that implements the `IModdedOptionGroup` interface. Groups contain two properties, the `GroupName` and `GroupColor`. +To create a group, you need to create a class that implements the `IModdedOptionGroup` interface. Groups contain 4 properties, `GroupName`, `GroupColor`, `GroupVisible`, and `AdvancedRole`. Only the `GroupName` is required. -The easiest way to create an option within this group is to make a property within a class and assign one of the various Options Attributes listed below: +You can access any group class using the `ModdedGroupSingleton` class like this: +``` +// MyOptionsGroup is a class that implements IModdedOptionGroup +var myGroup = ModdedGroupSingleton.Instance; +``` + +There are two ways to make options inside a group: +- Use an Option Attribute with a property. +- Create a ModdedOption property. + +This is an example of using an Option Attribute on a property: +```csharp +// The first parameter is always the name of the option. The rest are dependent on the type of option. +[ModdedNumberOption("Sussy level", min: 0, max: 10)] +public float SussyLevel { get; set; } = 4f; // You can set a default value here. +``` + +And this is an example of a ModdedOption property: +```csharp +public ModdedToggleOption YeezusAbility { get; } = new ModdedToggleOption("Yeezus Ability", false); +``` + +Here is a full list of ModdedOption classes you can use: - `ModdedEnumOption` - `ModdedNumberOption` - `ModdedStringOption` - `ModdedToggleOption` -They are used like this: -```csharp -// The first parameter is always the name of the option. The rest are dependent on the type of option. -[ModdedNumberOption("Sussy level", min: 0, max: 10)] -public float sussyLevel { get; set; } = 4f; // You can set a default value here. -``` - -To see a full example, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExampleOptions.cs). +To see a full example of an options class, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExampleOptions.cs). ### Role Options -Options can also be used within a Role class to show up in that Role's settings. To do this, simply add your option property to the Role class and specify the `roleType` parameter in the Option attribute. +Options can also be used within a Role class to show up in that Role's settings. To set the role for an entire group, set the `AdvancedRole` property on that group. To set the role for individual options, specify the `roleType` parameter in the option. -An example can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/CustomRole2.cs). +An example can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs). ## Buttons From 49ac51f0396598c09ac2978c1bf5dff0bc6ebb4f Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:48:54 -0400 Subject: [PATCH 17/60] fix sprite tools assembly issues --- MiraAPI/Utilities/Assets/LoadableResourceAsset.cs | 7 +++++-- MiraAPI/Utilities/Assets/SpriteTools.cs | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/MiraAPI/Utilities/Assets/LoadableResourceAsset.cs b/MiraAPI/Utilities/Assets/LoadableResourceAsset.cs index 2111e1d..70f20ef 100644 --- a/MiraAPI/Utilities/Assets/LoadableResourceAsset.cs +++ b/MiraAPI/Utilities/Assets/LoadableResourceAsset.cs @@ -1,9 +1,12 @@ -using UnityEngine; +using System.Reflection; +using UnityEngine; namespace MiraAPI.Utilities.Assets; public class LoadableResourceAsset(string path) : LoadableAsset { + private readonly Assembly _assembly = Assembly.GetCallingAssembly(); + public override Sprite LoadAsset() { if (LoadedAsset != null) @@ -13,7 +16,7 @@ public class LoadableResourceAsset(string path) : LoadableAsset try { - return LoadedAsset = SpriteTools.LoadSpriteFromPath(path); + return LoadedAsset = SpriteTools.LoadSpriteFromPath(path, _assembly); } catch { diff --git a/MiraAPI/Utilities/Assets/SpriteTools.cs b/MiraAPI/Utilities/Assets/SpriteTools.cs index cfb04aa..a3fde44 100644 --- a/MiraAPI/Utilities/Assets/SpriteTools.cs +++ b/MiraAPI/Utilities/Assets/SpriteTools.cs @@ -32,10 +32,9 @@ public static class SpriteTools /// The path to the resource. /// A sprite made from the resource /// The resource cannot be found. - public static Sprite LoadSpriteFromPath(string resourcePath) + public static Sprite LoadSpriteFromPath(string resourcePath, Assembly assembly) { var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false); - var assembly = Assembly.GetExecutingAssembly(); var myStream = assembly.GetManifestResourceStream(resourcePath); if (myStream != null) { From 1ac28d21639ea6caaa3c4e44d7df9f5d1049b37f Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:57:58 -0400 Subject: [PATCH 18/60] only show groups if there is options in them --- .../Patches/Options/GameOptionsMenuPatch.cs | 8 +- .../Patches/Options/RoleSettingMenuPatches.cs | 76 +++++++++++-------- 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index ea622cb..ddd0e4b 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -30,6 +30,12 @@ public static class GameOptionsMenuPatch foreach (IModdedOptionGroup group in filteredGroups) { + var filteredOpts = ModdedOptionsManager.Groups[group].Where(x=>x.Visible.Invoke()).ToList(); + if (filteredOpts.Count == 0) + { + continue; + } + CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer); categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20); if (group.GroupColor != Color.clear) @@ -40,8 +46,6 @@ public static class GameOptionsMenuPatch categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f; categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f); num -= 0.63f; - - var filteredOpts = ModdedOptionsManager.Groups[group].Where(x=>x.Visible.Invoke()).ToList(); foreach (var opt in filteredOpts) { diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 6c88150..6e06d71 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -45,57 +45,71 @@ public static class RoleSettingMenuPatches __instance.scrollBar.transform.localPosition = new Vector3(-1.4957f, 1.5261f, -4); maskBg.localPosition = new Vector3(1.5353f, -1.0607f, -.1f); maskBg.localScale = new Vector3(6.6811f, 4.1563f, 0.5598f); - - CategoryHeaderEditRole 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; - int num3 = 0; + int num3 = 0; + var crewRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values .OfType() .Where(role => role.Team == ModdedRoleTeams.Crewmate && !role.HideSettings) .ToList(); - - foreach (var role in crewRoles) + + if (crewRoles.Count > 0) { - CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); - num3++; + + CategoryHeaderEditRole 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; + + foreach (var role in crewRoles) + { + CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); + num3++; + } } - - num -= 0.4f; - CategoryHeaderEditRole 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; - + var impRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values .OfType() .Where(role => role.Team == ModdedRoleTeams.Impostor && !role.HideSettings) .ToList(); - foreach (var role in impRoles) + if (impRoles.Count > 0) { - CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); - num3++; - } + num -= 0.4f; + CategoryHeaderEditRole 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; - num -= 0.8f; - CategoryHeaderEditRole categoryHeaderEditRole3 = Object.Instantiate(__instance.categoryHeaderEditRoleOrigin, Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform); - categoryHeaderEditRole3.SetHeader(StringNames.None, 20); - categoryHeaderEditRole3.Title.text = "Neutral Roles"; - categoryHeaderEditRole3.transform.localPosition = new Vector3(4.986f, num, -2f); - num -= 0.522f; + + foreach (var role in impRoles) + { + CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); + num3++; + } + } var neutRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values .OfType() .Where(role => role.Team == ModdedRoleTeams.Neutral && !role.HideSettings) .ToList(); - - foreach (var role in neutRoles) + + if (neutRoles.Count > 0) { - CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); - num3++; + num -= 0.8f; + CategoryHeaderEditRole categoryHeaderEditRole3 = Object.Instantiate(__instance.categoryHeaderEditRoleOrigin, + Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform); + categoryHeaderEditRole3.SetHeader(StringNames.None, 20); + categoryHeaderEditRole3.Title.text = "Neutral Roles"; + categoryHeaderEditRole3.transform.localPosition = new Vector3(4.986f, num, -2f); + num -= 0.522f; + + foreach (var role in neutRoles) + { + CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); + num3++; + } } return false; From 826e172a3af1d040cd3e7365ced4a263c7e6b655 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:27:59 -0400 Subject: [PATCH 19/60] fix for 8.13 --- MiraAPI/MiraAPI.csproj | 9 ++------- MiraAPI/Patches/Roles/EjectionPatches.cs | 6 +++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/MiraAPI/MiraAPI.csproj b/MiraAPI/MiraAPI.csproj index d15783e..e4dad34 100644 --- a/MiraAPI/MiraAPI.csproj +++ b/MiraAPI/MiraAPI.csproj @@ -9,12 +9,7 @@ Simple and easy to use Among Us modding API. Angxl, XtraCube - - - Steam - 2024.8.13 - - + @@ -29,7 +24,7 @@ - + diff --git a/MiraAPI/Patches/Roles/EjectionPatches.cs b/MiraAPI/Patches/Roles/EjectionPatches.cs index f6ca0e1..60c0dfe 100644 --- a/MiraAPI/Patches/Roles/EjectionPatches.cs +++ b/MiraAPI/Patches/Roles/EjectionPatches.cs @@ -11,16 +11,16 @@ public static class EjectionPatches [HarmonyPatch(nameof(ExileController.Begin))] public static void Begin(ExileController __instance) { - if (!__instance.exiled?.Role || __instance.exiled.Role is not ICustomRole role) + if (!__instance.initData.networkedPlayer.Role || __instance.initData.networkedPlayer.Role is not ICustomRole role) { return; } - if (role.GetCustomEjectionMessage(__instance.exiled) == null) + if (role.GetCustomEjectionMessage(__instance.initData.networkedPlayer) == null) { return; } - __instance.completeString = role.GetCustomEjectionMessage(__instance.exiled); + __instance.completeString = role.GetCustomEjectionMessage(__instance.initData.networkedPlayer); } } \ No newline at end of file From 62ec462e796fd83cecf064faceb3359a65f10669 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:55:11 -0400 Subject: [PATCH 20/60] readme updates --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fbf2979..de4f261 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,25 @@ Options are also very simple in Mira API. Options are split up into Groups and O To create a group, you need to create a class that implements the `IModdedOptionGroup` interface. Groups contain 4 properties, `GroupName`, `GroupColor`, `GroupVisible`, and `AdvancedRole`. Only the `GroupName` is required. +Here is an example of a group class: +```csharp +public class MyOptionsGroup : IModdedOptionGroup +{ + public string GroupName => "My Options"; // this is required + + [ModdedNumberOption("My Number Option", min: 0, max: 10)] + public float MyNumberOption { get; set; } = 5f; +} +``` + You can access any group class using the `ModdedGroupSingleton` class like this: ``` // MyOptionsGroup is a class that implements IModdedOptionGroup -var myGroup = ModdedGroupSingleton.Instance; +var myGroup = ModdedGroupSingleton.Instance; // gets the instance of the group +System.Out.Console.WriteLine(myGroup.MyNumberOption); // prints the value of the option to the console ``` -There are two ways to make options inside a group: +Once you have an options group, there are two ways to make the actual options: - Use an Option Attribute with a property. - Create a ModdedOption property. @@ -66,7 +78,32 @@ To see a full example of an options class, see [this file](https://github.com/Al ### Role Options -Options can also be used within a Role class to show up in that Role's settings. To set the role for an entire group, set the `AdvancedRole` property on that group. To set the role for individual options, specify the `roleType` parameter in the option. +Options can also be used within a Role class to show up in that Role's settings. + +To set the role for an entire group, set the `AdvancedRole` property on that group like this: +```csharp +public class MyOptionsGroup : IModdedOptionGroup +{ + public string GroupName => "My Options"; + public Type AdvancedRole => typeof(MyRole); // this is the role that will have these options + + [ModdedNumberOption("Ability Uses", min: 0, max: 10)] + public float AbilityUses { get; set; } = 5f; +} +``` + +To set the role for individual options, specify the `roleType` parameter in the option like this: +```csharp +// this group doesnt specify a role, so it will show up in the global settings +public class MyOptionsGroup : IModdedOptionGroup +{ + public string GroupName => "My Options"; + + // this option will only show up in the settings for MyRole + [ModdedNumberOption("Ability Uses", min: 0, max: 10, roleType: typeof(MyRole))] + public float AbilityUses { get; set; } = 5f; +} +``` An example can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs). From a0a2e9a6ab191db8cc304e71287e5e2a2978ef7f Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:48:38 -0400 Subject: [PATCH 21/60] sequential role IDs --- MiraAPI/PluginLoading/MiraPluginInfo.cs | 4 ++-- MiraAPI/PluginLoading/MiraPluginManager.cs | 16 +++++++++++----- MiraAPI/Roles/CustomRoleManager.cs | 20 ++++++++------------ MiraAPI/Roles/RegisterCustomRoleAttribute.cs | 14 +------------- MiraAPI/Roles/RoleId.cs | 17 +++++++++++++++++ 5 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 MiraAPI/Roles/RoleId.cs diff --git a/MiraAPI/PluginLoading/MiraPluginInfo.cs b/MiraAPI/PluginLoading/MiraPluginInfo.cs index 8214316..1947666 100644 --- a/MiraAPI/PluginLoading/MiraPluginInfo.cs +++ b/MiraAPI/PluginLoading/MiraPluginInfo.cs @@ -6,9 +6,9 @@ using System.Collections.Generic; namespace MiraAPI.PluginLoading; -public class MiraPluginInfo(string id, IMiraPlugin miraPlugin, PluginInfo info) +public class MiraPluginInfo(IMiraPlugin miraPlugin, PluginInfo info) { - public string PluginId { get; set; } = id; + public string PluginId { get; set; } = info.Metadata.GUID; public IMiraPlugin MiraPlugin { get; set; } = miraPlugin; public PluginInfo PluginInfo { get; set; } = info; public ConfigFile PluginConfig { get; set; } = miraPlugin.GetConfigFile(); diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index 45dccb2..a23e928 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using MiraAPI.Hud; +using Reactor.Networking; namespace MiraAPI.PluginLoading; @@ -27,15 +28,14 @@ internal class MiraPluginManager internal void Initialize() { Instance = this; - IL2CPPChainloader.Instance.PluginLoad += (_, assembly, plugin) => + IL2CPPChainloader.Instance.PluginLoad += (pluginInfo, assembly, plugin) => { if (!plugin.GetType().GetInterfaces().Contains(typeof(IMiraPlugin))) { return; } - var id = MetadataHelper.GetMetadata(plugin.GetType()).GUID; - var info = new MiraPluginInfo(id, plugin as IMiraPlugin, IL2CPPChainloader.Instance.Plugins[id]); + var info = new MiraPluginInfo(plugin as IMiraPlugin, pluginInfo); RegisterAllOptions(assembly, info); @@ -44,7 +44,7 @@ internal class MiraPluginManager RegisteredPlugins.Add(assembly, info); - Logger.Info($"Registering mod {id} with Mira API."); + Logger.Info($"Registering mod {pluginInfo.Metadata.GUID} with Mira API."); }; } @@ -92,10 +92,16 @@ internal class MiraPluginManager { continue; } + + if (!ModList.GetById(pluginInfo.PluginId).IsRequiredOnAllClients) + { + Logger.Error("Custom roles are only supported on all clients."); + return; + } ClassInjector.RegisterTypeInIl2Cpp(type); - var role = CustomRoleManager.RegisterRole(type, attribute.RoleId, pluginInfo); + var role = CustomRoleManager.RegisterRole(type, pluginInfo); try { diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 329b3c6..0c3ff2f 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -20,23 +20,19 @@ public static class CustomRoleManager { public static readonly Dictionary CustomRoles = new(); - private static int GetNextRoleId(ushort requestedId) + private static ushort _roleId = 100; + + private static ushort GetNextRoleId() { - while (CustomRoles.ContainsKey(requestedId) || requestedId <= Enum.GetNames().Length) - { - Logger.Error(requestedId + ", " + (requestedId+1)); - requestedId++; - } - - return requestedId; + return _roleId++; } - public static void RegisterInRoleManager() + internal static void RegisterInRoleManager() { RoleManager.Instance.AllRoles = RoleManager.Instance.AllRoles.Concat(CustomRoles.Values).ToArray(); } - internal static RoleBehaviour RegisterRole(Type roleType, ushort roleId, MiraPluginInfo parentMod) + internal static RoleBehaviour RegisterRole(Type roleType, MiraPluginInfo parentMod) { if (!(typeof(RoleBehaviour).IsAssignableFrom(roleType) && typeof(ICustomRole).IsAssignableFrom(roleType))) { @@ -52,7 +48,7 @@ public static class CustomRoleManager return null; } - roleBehaviour.Role = (RoleTypes)GetNextRoleId(roleId); + roleBehaviour.Role = (RoleTypes)GetNextRoleId(); roleBehaviour.TeamType = customRole.Team == ModdedRoleTeams.Neutral ? RoleTeamTypes.Crewmate : (RoleTeamTypes)customRole.Team; roleBehaviour.NameColor = customRole.RoleColor; roleBehaviour.StringName = CustomStringName.CreateAndRegister(customRole.RoleName); @@ -72,7 +68,7 @@ public static class CustomRoleManager RoleManager.GhostRoles.Add(roleBehaviour.Role); } - CustomRoles.Add(roleId, roleBehaviour); + CustomRoles.Add(_roleId, roleBehaviour); if (customRole.HideSettings) { diff --git a/MiraAPI/Roles/RegisterCustomRoleAttribute.cs b/MiraAPI/Roles/RegisterCustomRoleAttribute.cs index f32cdd7..db9a0e7 100644 --- a/MiraAPI/Roles/RegisterCustomRoleAttribute.cs +++ b/MiraAPI/Roles/RegisterCustomRoleAttribute.cs @@ -3,16 +3,4 @@ namespace MiraAPI.Roles; [AttributeUsage(AttributeTargets.Class)] -public class RegisterCustomRoleAttribute : Attribute -{ - public ushort RoleId { get; } - - public RegisterCustomRoleAttribute() - { - RoleId = (ushort)(20 + CustomRoleManager.CustomRoles.Count); - } - public RegisterCustomRoleAttribute(ushort roleId) - { - RoleId = roleId; - } -} \ No newline at end of file +public class RegisterCustomRoleAttribute : Attribute; \ No newline at end of file diff --git a/MiraAPI/Roles/RoleId.cs b/MiraAPI/Roles/RoleId.cs new file mode 100644 index 0000000..bb7b714 --- /dev/null +++ b/MiraAPI/Roles/RoleId.cs @@ -0,0 +1,17 @@ +using System; +using System.Linq; + +namespace MiraAPI.Roles; + +public class RoleId +{ + public static ushort Get() where T : RoleBehaviour + { + if (!CustomRoleManager.CustomRoles.Values.OfType().Any()) + { + throw new InvalidOperationException($"Role {typeof(T)} is not registered"); + } + + return (ushort)CustomRoleManager.CustomRoles.Values.OfType().Single().Role; + } +} \ No newline at end of file From 0098baa37c38c701f87a2a71f8a79ef55481d344 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 20:02:53 -0400 Subject: [PATCH 22/60] fix an error in docs --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index de4f261..21b6334 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,9 @@ To see a full example of an options class, see [this file](https://github.com/Al ### Role Options -Options can also be used within a Role class to show up in that Role's settings. +You can also specify a role type for an option or option group. -To set the role for an entire group, set the `AdvancedRole` property on that group like this: +To set the role type for an entire group, set the `AdvancedRole` property on that group like this: ```csharp public class MyOptionsGroup : IModdedOptionGroup { @@ -92,7 +92,7 @@ public class MyOptionsGroup : IModdedOptionGroup } ``` -To set the role for individual options, specify the `roleType` parameter in the option like this: +To set the role type for individual options, specify the `roleType` parameter in the option like this: ```csharp // this group doesnt specify a role, so it will show up in the global settings public class MyOptionsGroup : IModdedOptionGroup From e2e7749ec1938a84a46cfe688b6a0c90986dbf24 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:59:42 -0400 Subject: [PATCH 23/60] Create LICENSE --- LICENSE | 504 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 504 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8000a6f --- /dev/null +++ b/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! From cf5f91d66074e671ead215ce264b742d563fc04c Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:31:37 -0400 Subject: [PATCH 24/60] fix role setting menu --- MiraAPI/Patches/Options/RoleSettingMenuPatches.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 6e06d71..847678c 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -244,9 +244,8 @@ public static class RoleSettingMenuPatches PassiveButton newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform); newButton.name = "ConfigButton"; newButton.transform.localPosition = new Vector3(0.2419f, -0.2582f, -2f); - newButton.transform.FindChild("Plus_TMP").gameObject.DestroyImmediate(); - newButton.transform.FindChild("InactiveSprite").GetComponent().sprite = MiraAssets.Cog.LoadAsset(); - newButton.transform.FindChild("ActiveSprite").GetComponent().sprite = MiraAssets.CogActive.LoadAsset(); + newButton.transform.FindChild("Text_TMP").gameObject.DestroyImmediate(); + newButton.transform.FindChild("ButtonSprite").GetComponent().sprite = MiraAssets.Cog.LoadAsset(); PassiveButton passiveButton = newButton.GetComponent(); passiveButton.OnClick = new ButtonClickedEvent(); From 6604fb345afc8dfe46a63c673068061f9f380a1b Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 15:18:06 -0400 Subject: [PATCH 25/60] make null checks on unity objects better --- MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs | 2 +- MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs | 2 +- MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs | 2 +- MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs | 2 +- MiraAPI/Patches/HudManagerPatches.cs | 4 ++-- MiraAPI/Patches/Roles/NameTagPatch.cs | 2 +- MiraAPI/Patches/Roles/RoleManagerPatches.cs | 2 +- MiraAPI/Patches/Roles/TaskPanelPatch.cs | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs index 96499b5..30de265 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs @@ -63,7 +63,7 @@ public class ModdedEnumOption : ModdedOption public override void OnValueChanged(int newValue) { DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false); - if (OptionBehaviour is null) + if (!OptionBehaviour) { return; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index a959313..51e350e 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -90,7 +90,7 @@ public class ModdedNumberOption : ModdedOption Value = Mathf.Clamp(newValue, Min, Max); DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(Value), false); - if (OptionBehaviour is null) + if (!OptionBehaviour) { return; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs index be6e2d1..484126f 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs @@ -63,7 +63,7 @@ public class ModdedStringOption : ModdedOption public override void OnValueChanged(int newValue) { DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false); - if (OptionBehaviour is null) + if (!OptionBehaviour) { return; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs index 60683ed..a29e648 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs @@ -55,7 +55,7 @@ public class ModdedToggleOption : ModdedOption public override void OnValueChanged(bool newValue) { DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false); - if (OptionBehaviour is null) + if (!OptionBehaviour) { return; } diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 1b60a8c..7631523 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -40,7 +40,7 @@ public static class HudManagerPatches if (customRole.SetTabText() != null) { - if (_roleTab == null) + if (!_roleTab) { _roleTab = CustomRoleManager.CreateRoleTab(customRole); } @@ -114,7 +114,7 @@ public static class HudManagerPatches [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) + if (!player.Data) { return; } diff --git a/MiraAPI/Patches/Roles/NameTagPatch.cs b/MiraAPI/Patches/Roles/NameTagPatch.cs index 929ccaf..b427112 100644 --- a/MiraAPI/Patches/Roles/NameTagPatch.cs +++ b/MiraAPI/Patches/Roles/NameTagPatch.cs @@ -23,7 +23,7 @@ public static class NameTagPatch return true; } - if (PlayerControl.LocalPlayer == null || PlayerControl.LocalPlayer.Data == null || PlayerControl.LocalPlayer.Data.Role == null || otherPlayerRole == null) + if (!PlayerControl.LocalPlayer || !PlayerControl.LocalPlayer.Data || !PlayerControl.LocalPlayer.Data.Role || !otherPlayerRole) { __result = Color.white; } diff --git a/MiraAPI/Patches/Roles/RoleManagerPatches.cs b/MiraAPI/Patches/Roles/RoleManagerPatches.cs index a7cd867..e1139dd 100644 --- a/MiraAPI/Patches/Roles/RoleManagerPatches.cs +++ b/MiraAPI/Patches/Roles/RoleManagerPatches.cs @@ -12,7 +12,7 @@ public static class RoleManagerPatches [HarmonyPatch(nameof(RoleManager.AssignRoleOnDeath))] public static bool AssignRoleOnDeath(RoleManager __instance, [HarmonyArgument(0)] PlayerControl plr) { - if (plr == null || !plr.Data.IsDead) + if (!plr || !plr.Data.IsDead) { return false; } diff --git a/MiraAPI/Patches/Roles/TaskPanelPatch.cs b/MiraAPI/Patches/Roles/TaskPanelPatch.cs index 24c2a75..e93ab10 100644 --- a/MiraAPI/Patches/Roles/TaskPanelPatch.cs +++ b/MiraAPI/Patches/Roles/TaskPanelPatch.cs @@ -35,7 +35,7 @@ public static class TaskPanelPatch vector2.x += vector.x * 2f; __instance.tab.transform.localPosition = vector2; - if (GameManager.Instance == null) + if (!GameManager.Instance) { return false; } From 1933bb73bd361cb3467e92ca98018a18050f2fe7 Mon Sep 17 00:00:00 2001 From: ang-xd Date: Fri, 23 Aug 2024 22:12:25 -0400 Subject: [PATCH 26/60] Fix all scrolling issues (i think) --- .../Patches/Options/GameOptionsMenuPatch.cs | 11 ++++---- .../Patches/Options/GameSettingMenuPatches.cs | 7 +++-- .../Patches/Options/RoleSettingMenuPatches.cs | 26 +++++++++---------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index ddd0e4b..f0fb354 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -25,17 +25,17 @@ public static class GameOptionsMenuPatch __instance.MapPicker.gameObject.SetActive(false); float num = 2.1f; - + var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.GroupVisible.Invoke() && x.AdvancedRole is null); - + foreach (IModdedOptionGroup group in filteredGroups) { - var filteredOpts = ModdedOptionsManager.Groups[group].Where(x=>x.Visible.Invoke()).ToList(); + var filteredOpts = ModdedOptionsManager.Groups[group].Where(x => x.Visible.Invoke()).ToList(); if (filteredOpts.Count == 0) { continue; } - + CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer); categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20); if (group.GroupColor != Color.clear) @@ -46,7 +46,7 @@ public static class GameOptionsMenuPatch categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f; categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f); num -= 0.63f; - + foreach (var opt in filteredOpts) { OptionBehaviour newOpt = opt.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.settingsContainer); @@ -83,7 +83,6 @@ public static class GameOptionsMenuPatch } __instance.scrollBar.SetYBoundsMax(-num - 1.65f); - return false; } diff --git a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs index 47e002a..24f2a43 100644 --- a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs @@ -16,7 +16,7 @@ namespace MiraAPI.Patches.Options; public static class GameSettingMenuPatches { public static int CurrentSelectedMod { get; private set; } - + public static MiraPluginInfo SelectedMod { get; private set; } private static TextMeshPro _text; @@ -116,12 +116,14 @@ public static class GameSettingMenuPatches roleChance.gameObject.DestroyImmediate(); } - roles.roleChances.Clear(); roles.roleChances = null; roles.AdvancedRolesSettings.gameObject.SetActive(false); roles.RoleChancesSettings.gameObject.SetActive(true); roles.SetQuotaTab(); + + roles.scrollBar.CalculateAndSetYBounds(roles.roleChances.Count + 3, 1f, 6f, 0.43f); + roles.scrollBar.ScrollToTop(); } if (settings?.Children != null) @@ -150,6 +152,7 @@ public static class GameSettingMenuPatches settings.Children = null; settings.Initialize(); + settings.scrollBar.ScrollToTop(); } } } diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 847678c..7cf44a0 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -1,13 +1,13 @@ using HarmonyLib; +using MiraAPI.Networking; using MiraAPI.Roles; using MiraAPI.Utilities; using MiraAPI.Utilities.Assets; +using Reactor.Networking.Rpc; +using Reactor.Utilities; using Reactor.Utilities.Extensions; using System; using System.Linq; -using MiraAPI.Networking; -using Reactor.Networking.Rpc; -using Reactor.Utilities; using TMPro; using UnityEngine; using UnityEngine.Events; @@ -25,7 +25,7 @@ public static class RoleSettingMenuPatches { __instance.roleChances = new Il2CppSystem.Collections.Generic.List(); __instance.advancedSettingChildren = new Il2CppSystem.Collections.Generic.List(); - + var maskBg = __instance.scrollBar.transform.FindChild("MaskBg"); if (GameSettingMenuPatches.CurrentSelectedMod == 0) @@ -45,17 +45,17 @@ public static class RoleSettingMenuPatches __instance.scrollBar.transform.localPosition = new Vector3(-1.4957f, 1.5261f, -4); maskBg.localPosition = new Vector3(1.5353f, -1.0607f, -.1f); maskBg.localScale = new Vector3(6.6811f, 4.1563f, 0.5598f); - + int num3 = 0; var crewRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values .OfType() .Where(role => role.Team == ModdedRoleTeams.Crewmate && !role.HideSettings) .ToList(); - + if (crewRoles.Count > 0) { - + CategoryHeaderEditRole 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); @@ -67,7 +67,7 @@ public static class RoleSettingMenuPatches num3++; } } - + var impRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values .OfType() .Where(role => role.Team == ModdedRoleTeams.Impostor && !role.HideSettings) @@ -89,7 +89,7 @@ public static class RoleSettingMenuPatches num3++; } } - + var neutRoles = GameSettingMenuPatches.SelectedMod.CustomRoles.Values .OfType() .Where(role => role.Team == ModdedRoleTeams.Neutral && !role.HideSettings) @@ -104,7 +104,7 @@ public static class RoleSettingMenuPatches categoryHeaderEditRole3.Title.text = "Neutral Roles"; categoryHeaderEditRole3.transform.localPosition = new Vector3(4.986f, num, -2f); num -= 0.522f; - + foreach (var role in neutRoles) { CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3); @@ -161,7 +161,7 @@ public static class RoleSettingMenuPatches private static void CreateAdvancedSettings(RolesSettingsMenu __instance, RoleBehaviour role) { - foreach (var option in __instance.advancedSettingChildren) + foreach (var option in __instance.advancedSettingChildren) { Object.Destroy(option.gameObject); } @@ -171,7 +171,7 @@ public static class RoleSettingMenuPatches float num = -0.872f; var filteredOptions = GameSettingMenuPatches.SelectedMod.Options.Where(x => x.AdvancedRole == role.GetType()); - + foreach (var option in filteredOptions) { if (option.AdvancedRole is not null && option.AdvancedRole != role.GetType()) @@ -207,7 +207,7 @@ public static class RoleSettingMenuPatches { ICustomRole customRole = role as ICustomRole; __instance.roleDescriptionText.text = customRole.RoleLongDescription; - __instance.roleTitleText.text = DestroyableSingleton.Instance.GetString(role.StringName, []); + __instance.roleTitleText.text = DestroyableSingleton.Instance.GetString(role.StringName, Array.Empty()); __instance.roleScreenshot.sprite = Sprite.Create(customRole.OptionsScreenshot.LoadAsset().texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100); __instance.roleScreenshot.drawMode = SpriteDrawMode.Sliced; __instance.roleHeaderSprite.color = customRole.RoleColor; From 9a9b7e43e7d4a9e424b4fd658e6977a160e2f7a6 Mon Sep 17 00:00:00 2001 From: ang-xd Date: Fri, 23 Aug 2024 22:32:36 -0400 Subject: [PATCH 27/60] Stuff --- MiraAPI/Patches/Options/RoleSettingMenuPatches.cs | 11 +++++++++-- MiraAPI/Utilities/Assets/MiraAssets.cs | 1 - 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 7cf44a0..55b446c 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -243,12 +243,19 @@ public static class RoleSettingMenuPatches PassiveButton newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform); newButton.name = "ConfigButton"; - newButton.transform.localPosition = new Vector3(0.2419f, -0.2582f, -2f); + newButton.transform.localPosition = new Vector3(0.4473f, -0.3f, -2f); newButton.transform.FindChild("Text_TMP").gameObject.DestroyImmediate(); - newButton.transform.FindChild("ButtonSprite").GetComponent().sprite = MiraAssets.Cog.LoadAsset(); + newButton.activeSprites.Destroy(); + + SpriteRenderer btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent(); + btnRend.sprite = MiraAssets.Cog.LoadAsset(); + btnRend.color = customRole.RoleColor.DarkenColor(); PassiveButton passiveButton = newButton.GetComponent(); passiveButton.OnClick = new ButtonClickedEvent(); + passiveButton.disabledTextColor = customRole.RoleColor.DarkenColor(); + passiveButton.selectedTextColor = customRole.RoleColor.DarkenColor().DarkenColor(); + passiveButton.OnClick.AddListener((UnityAction)(() => { ChangeTab(role, __instance); diff --git a/MiraAPI/Utilities/Assets/MiraAssets.cs b/MiraAPI/Utilities/Assets/MiraAssets.cs index 12b0d4b..fa6ad54 100644 --- a/MiraAPI/Utilities/Assets/MiraAssets.cs +++ b/MiraAPI/Utilities/Assets/MiraAssets.cs @@ -7,6 +7,5 @@ public static class MiraAssets public static readonly LoadableResourceAsset NextButton = new("MiraAPI.Resources.NextButton.png"); public static readonly LoadableResourceAsset NextButtonActive = new("MiraAPI.Resources.NextButtonActive.png"); public static readonly LoadableResourceAsset Cog = new("MiraAPI.Resources.Cog.png"); - public static readonly LoadableResourceAsset CogActive = new("MiraAPI.Resources.CogActive.png"); public static readonly LoadableResourceAsset Banner = new("MiraAPI.Resources.FortniteBanner.jpeg"); } \ No newline at end of file From dcf6221671aa6d68cc989b6d0cd896a10fb35dc6 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 22:48:53 -0400 Subject: [PATCH 28/60] error check and more verbose error log --- MiraAPI/Hud/CustomButtonManager.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MiraAPI/Hud/CustomButtonManager.cs b/MiraAPI/Hud/CustomButtonManager.cs index 2b09d7b..e3adae5 100644 --- a/MiraAPI/Hud/CustomButtonManager.cs +++ b/MiraAPI/Hud/CustomButtonManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using Reactor.Utilities; namespace MiraAPI.Hud; @@ -12,10 +13,16 @@ public static class CustomButtonManager { if (!typeof(CustomActionButton).IsAssignableFrom(buttonType)) { + Logger.Error($"{buttonType?.Name} does not inherit from CustomActionButton."); return; } - var button = (CustomActionButton)Activator.CreateInstance(buttonType); + if (Activator.CreateInstance(buttonType) is not CustomActionButton button) + { + Logger.Error($"Failed to create button from {buttonType.Name}"); + return; + } + CustomButtons.Add(button); typeof(CustomButtonSingleton<>).MakeGenericType(buttonType) .GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)! From a1219f06569716789b8f27ef174c62e0db5a67a3 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:22:29 -0400 Subject: [PATCH 29/60] change IModdedOptionGroup to AbstractOptionGroup, update group singleton class, save options to config --- MiraAPI.Example/Options/ExampleOptions.cs | 6 ++-- MiraAPI.Example/Options/ExampleOptions2.cs | 4 +-- .../Options/Roles/CustomRole2Settings.cs | 6 ++-- .../Options/Roles/CustomRoleSettings.cs | 6 ++-- ...dOptionGroup.cs => AbstractOptionGroup.cs} | 13 +++++--- MiraAPI/GameOptions/IModdedOption.cs | 4 ++- MiraAPI/GameOptions/ModdedOptionsManager.cs | 22 ++++++------- ...upSingleton.cs => OptionGroupSingleton.cs} | 4 +-- .../GameOptions/OptionTypes/ModdedOption.cs | 31 ++++++++++++++----- .../Patches/Options/GameOptionsMenuPatch.cs | 4 +-- MiraAPI/PluginLoading/MiraPluginInfo.cs | 10 +++--- MiraAPI/PluginLoading/MiraPluginManager.cs | 2 +- 12 files changed, 64 insertions(+), 48 deletions(-) rename MiraAPI/GameOptions/{IModdedOptionGroup.cs => AbstractOptionGroup.cs} (61%) rename MiraAPI/GameOptions/{ModdedGroupSingleton.cs => OptionGroupSingleton.cs} (71%) diff --git a/MiraAPI.Example/Options/ExampleOptions.cs b/MiraAPI.Example/Options/ExampleOptions.cs index 6c674a6..09f615f 100644 --- a/MiraAPI.Example/Options/ExampleOptions.cs +++ b/MiraAPI.Example/Options/ExampleOptions.cs @@ -4,10 +4,10 @@ using UnityEngine; namespace MiraAPI.Example.Options; -public class ExampleOptions : IModdedOptionGroup +public class ExampleOptions : AbstractOptionGroup { - public string GroupName => "General Group"; - public Color GroupColor => Color.red; + public override string GroupName => "General Group"; + public override Color GroupColor => Color.red; [ModdedToggleOption("Use Thing")] public bool UseThing { get; set; } = false; diff --git a/MiraAPI.Example/Options/ExampleOptions2.cs b/MiraAPI.Example/Options/ExampleOptions2.cs index 42c316f..b17ff20 100644 --- a/MiraAPI.Example/Options/ExampleOptions2.cs +++ b/MiraAPI.Example/Options/ExampleOptions2.cs @@ -3,9 +3,9 @@ using MiraAPI.GameOptions.OptionTypes; namespace MiraAPI.Example.Options; -public class ExampleOptions2 : IModdedOptionGroup +public class ExampleOptions2 : AbstractOptionGroup { - public string GroupName => "Example 2"; + public override string GroupName => "Example 2"; public ModdedToggleOption UseThing { get; } = new("Use Thingy 5", false); diff --git a/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs b/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs index e0e9d1a..b925dcf 100644 --- a/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs +++ b/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs @@ -5,11 +5,11 @@ using MiraAPI.GameOptions.Attributes; namespace MiraAPI.Example.Options.Roles; -public class CustomRole2Settings : IModdedOptionGroup +public class CustomRole2Settings : AbstractOptionGroup { - public string GroupName => "Custom Role"; + public override string GroupName => "Custom Role"; - public Type AdvancedRole => typeof(CustomRole2); + public override Type AdvancedRole => typeof(CustomRole2); [ModdedToggleOption("Teleportation ability")] public bool Teleport { get; set; } = true; diff --git a/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs b/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs index 98882ae..26503c0 100644 --- a/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs +++ b/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs @@ -5,11 +5,11 @@ using MiraAPI.GameOptions.Attributes; namespace MiraAPI.Example.Options.Roles; -public class CustomRoleSettings : IModdedOptionGroup +public class CustomRoleSettings : AbstractOptionGroup { - public string GroupName => "Custom Role"; + public override string GroupName => "Custom Role"; - public Type AdvancedRole => typeof(CustomRole); + public override Type AdvancedRole => typeof(CustomRole); [ModdedNumberOption("Testing level", min: 3, max: 9)] public float TestingLevel { get; set; } = 4; diff --git a/MiraAPI/GameOptions/IModdedOptionGroup.cs b/MiraAPI/GameOptions/AbstractOptionGroup.cs similarity index 61% rename from MiraAPI/GameOptions/IModdedOptionGroup.cs rename to MiraAPI/GameOptions/AbstractOptionGroup.cs index 6297011..564bfa1 100644 --- a/MiraAPI/GameOptions/IModdedOptionGroup.cs +++ b/MiraAPI/GameOptions/AbstractOptionGroup.cs @@ -1,27 +1,30 @@ using System; +using System.Collections.Generic; using UnityEngine; namespace MiraAPI.GameOptions; -public interface IModdedOptionGroup +public abstract class AbstractOptionGroup { + public List Options { get; } = []; + /// /// The name of the group. Visible in options menu. /// - public string GroupName { get; } + public abstract string GroupName { get; } /// /// A function that returns whether the group should be visible or not. /// - public Func GroupVisible => () => true; + public virtual Func GroupVisible => () => true; /// /// The group color. This is used to color the group in the options menu. /// - public Color GroupColor => Color.clear; + public virtual Color GroupColor => Color.clear; /// /// The role the group is associated with. This is used for the advanced role options menu. /// - public Type AdvancedRole => null; + public virtual Type AdvancedRole => null; } \ No newline at end of file diff --git a/MiraAPI/GameOptions/IModdedOption.cs b/MiraAPI/GameOptions/IModdedOption.cs index eaa7add..b8f2227 100644 --- a/MiraAPI/GameOptions/IModdedOption.cs +++ b/MiraAPI/GameOptions/IModdedOption.cs @@ -1,5 +1,6 @@ using MiraAPI.PluginLoading; using System; +using BepInEx.Configuration; using MiraAPI.Networking; using UnityEngine; @@ -9,12 +10,13 @@ public interface IModdedOption { public uint Id { get; } public BaseGameSetting Data { get; } - public IMiraPlugin ParentMod { get; set; } + public IMiraPlugin ParentMod { get; init; } public Type AdvancedRole { get; set; } public OptionBehaviour OptionBehaviour { get; protected set; } public string Title { get; } public StringNames StringName { get; } public Func Visible { get; set; } + public ConfigDefinition ConfigDefinition { get; } public void ValueChanged(OptionBehaviour optionBehaviour); public OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container); public NetData GetNetData(); diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index 39a8532..0725fc6 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -14,20 +14,17 @@ namespace MiraAPI.GameOptions; public class ModdedOptionsManager { private static readonly Dictionary OptionAttributes = new(); - private static readonly Dictionary TypeToGroup = new(); + private static readonly Dictionary TypeToGroup = new(); public static readonly Dictionary ModdedOptions = new(); - public static readonly Dictionary> Groups = new(); - + public static readonly List Groups = []; public static uint NextId => _nextId++; private static uint _nextId = 1; internal static bool RegisterGroup(Type type, MiraPluginInfo pluginInfo) { - var group = (IModdedOptionGroup)Activator.CreateInstance(type); - - if (group == null) + if (Activator.CreateInstance(type) is not AbstractOptionGroup group) { Logger.Error($"Failed to create group from {type.Name}"); return false; @@ -39,7 +36,7 @@ public class ModdedOptionsManager return false; } - Groups.Add(group, []); + Groups.Add(group); TypeToGroup.Add(type, group); pluginInfo.OptionGroups.Add(group); @@ -53,10 +50,8 @@ public class ModdedOptionsManager Logger.Error($"Failed to get group for {type.Name}"); return; } - - var option = (IModdedOption) property.GetValue(group); - - if (option == null) + + if (property.GetValue(group) is not IModdedOption option) { Logger.Error($"Failed to get option for {property.Name}"); return; @@ -101,14 +96,15 @@ public class ModdedOptionsManager RegisterOption(option, group, pluginInfo); } - private static void RegisterOption(IModdedOption option, IModdedOptionGroup group, MiraPluginInfo pluginInfo) + private static void RegisterOption(IModdedOption option, AbstractOptionGroup group, MiraPluginInfo pluginInfo) { option.ParentMod = pluginInfo.MiraPlugin; option.AdvancedRole = group.AdvancedRole; + pluginInfo.Options.Add(option); ModdedOptions.Add(option.Id, option); - Groups[group].Add(option); + group.Options.Add(option); } internal static void SyncAllOptions(int targetId=-1) diff --git a/MiraAPI/GameOptions/ModdedGroupSingleton.cs b/MiraAPI/GameOptions/OptionGroupSingleton.cs similarity index 71% rename from MiraAPI/GameOptions/ModdedGroupSingleton.cs rename to MiraAPI/GameOptions/OptionGroupSingleton.cs index 265cc2a..d7678c6 100644 --- a/MiraAPI/GameOptions/ModdedGroupSingleton.cs +++ b/MiraAPI/GameOptions/OptionGroupSingleton.cs @@ -3,13 +3,13 @@ using System.Linq; namespace MiraAPI.GameOptions; -public class ModdedGroupSingleton where T : IModdedOptionGroup +public class OptionGroupSingleton where T : AbstractOptionGroup { private static T _instance; public static T Instance { - get => _instance ??= ModdedOptionsManager.Groups.Keys.OfType().Single(); + get => _instance ??= ModdedOptionsManager.Groups.OfType().Single(); set { if (_instance != null) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index f34754d..8d28277 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -2,6 +2,7 @@ using MiraAPI.Roles; using Reactor.Localization.Utilities; using System; +using BepInEx.Configuration; using MiraAPI.Networking; using Reactor.Networking.Rpc; using UnityEngine; @@ -10,9 +11,20 @@ namespace MiraAPI.GameOptions.OptionTypes; public abstract class ModdedOption : IModdedOption { + private readonly IMiraPlugin _parentMod; + public uint Id { get; } public BaseGameSetting Data { get; protected init; } - public IMiraPlugin ParentMod { get; set; } = null; + public IMiraPlugin ParentMod + { + get => _parentMod; + init + { + _parentMod = value; + var entry = _parentMod.GetConfigFile().Bind(ConfigDefinition, DefaultValue); + Value = entry.Value; + } + } public T Value { get; protected set; } public T DefaultValue { get; init; } public Action ChangedEvent { get; set; } @@ -21,9 +33,11 @@ public abstract class ModdedOption : IModdedOption public Func Visible { get; set; } public Type AdvancedRole { get; set; } public OptionBehaviour OptionBehaviour { get; set; } + public ConfigDefinition ConfigDefinition => new ("Options", Title); - protected ModdedOption(string title, T defaultValue, Type roleType) : this() + protected ModdedOption(string title, T defaultValue, Type roleType) { + Id = ModdedOptionsManager.NextId; Title = title; DefaultValue = defaultValue; Value = defaultValue; @@ -36,11 +50,6 @@ public abstract class ModdedOption : IModdedOption } } - private ModdedOption() - { - Id = ModdedOptionsManager.NextId; - } - public void ValueChanged(OptionBehaviour optionBehaviour) { SetValue(GetValueFromOptionBehaviour(optionBehaviour)); @@ -59,7 +68,13 @@ public abstract class ModdedOption : IModdedOption { Rpc.Instance.Send(PlayerControl.LocalPlayer, [GetNetData()], true); } - + + if (ParentMod is not null && + ParentMod.GetConfigFile().TryGetEntry(ConfigDefinition, out var entry)) + { + entry.Value = Value; + } + OnValueChanged(newValue); } diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index f0fb354..06b46e1 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -28,9 +28,9 @@ public static class GameOptionsMenuPatch var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.GroupVisible.Invoke() && x.AdvancedRole is null); - foreach (IModdedOptionGroup group in filteredGroups) + foreach (AbstractOptionGroup group in filteredGroups) { - var filteredOpts = ModdedOptionsManager.Groups[group].Where(x => x.Visible.Invoke()).ToList(); + var filteredOpts = group.Options.Where(x => x.Visible.Invoke()).ToList(); if (filteredOpts.Count == 0) { continue; diff --git a/MiraAPI/PluginLoading/MiraPluginInfo.cs b/MiraAPI/PluginLoading/MiraPluginInfo.cs index 8214316..2b58165 100644 --- a/MiraAPI/PluginLoading/MiraPluginInfo.cs +++ b/MiraAPI/PluginLoading/MiraPluginInfo.cs @@ -8,12 +8,12 @@ namespace MiraAPI.PluginLoading; public class MiraPluginInfo(string id, IMiraPlugin miraPlugin, PluginInfo info) { - public string PluginId { get; set; } = id; - public IMiraPlugin MiraPlugin { get; set; } = miraPlugin; - public PluginInfo PluginInfo { get; set; } = info; - public ConfigFile PluginConfig { get; set; } = miraPlugin.GetConfigFile(); + public string PluginId { get; } = id; + public IMiraPlugin MiraPlugin { get; } = miraPlugin; + public PluginInfo PluginInfo { get; } = info; + public ConfigFile PluginConfig { get; } = miraPlugin.GetConfigFile(); - public readonly List OptionGroups = []; + public readonly List OptionGroups = []; public readonly List Options = []; public readonly Dictionary CustomRoles = []; diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index 45dccb2..1124be9 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -55,7 +55,7 @@ internal class MiraPluginManager private static void RegisterAllOptions(Assembly assembly, MiraPluginInfo pluginInfo) { - var filteredTypes = assembly.GetTypes().Where(type => type.IsAssignableTo(typeof(IModdedOptionGroup))); + var filteredTypes = assembly.GetTypes().Where(type => type.IsAssignableTo(typeof(AbstractOptionGroup))); foreach (var type in filteredTypes) { From a77e5ef12d0cf3f59fe6ab31c7ce3b13b3f28448 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:24:25 -0400 Subject: [PATCH 30/60] oops messed up one thing --- MiraAPI/GameOptions/IModdedOption.cs | 2 +- MiraAPI/GameOptions/OptionTypes/ModdedOption.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MiraAPI/GameOptions/IModdedOption.cs b/MiraAPI/GameOptions/IModdedOption.cs index b8f2227..bd8a6f3 100644 --- a/MiraAPI/GameOptions/IModdedOption.cs +++ b/MiraAPI/GameOptions/IModdedOption.cs @@ -10,7 +10,7 @@ public interface IModdedOption { public uint Id { get; } public BaseGameSetting Data { get; } - public IMiraPlugin ParentMod { get; init; } + public IMiraPlugin ParentMod { get; set; } public Type AdvancedRole { get; set; } public OptionBehaviour OptionBehaviour { get; protected set; } public string Title { get; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index 8d28277..9cd3e97 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -11,14 +11,14 @@ namespace MiraAPI.GameOptions.OptionTypes; public abstract class ModdedOption : IModdedOption { - private readonly IMiraPlugin _parentMod; + private IMiraPlugin _parentMod; public uint Id { get; } public BaseGameSetting Data { get; protected init; } public IMiraPlugin ParentMod { get => _parentMod; - init + set { _parentMod = value; var entry = _parentMod.GetConfigFile().Bind(ConfigDefinition, DefaultValue); From a9fde0cf7fc6bdff38f5b8247a95eb6d4e7887f6 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:43:48 -0400 Subject: [PATCH 31/60] update example mod csproj --- MiraAPI.Example/MiraAPI.Example.csproj | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/MiraAPI.Example/MiraAPI.Example.csproj b/MiraAPI.Example/MiraAPI.Example.csproj index 193a9ed..bafb3f3 100644 --- a/MiraAPI.Example/MiraAPI.Example.csproj +++ b/MiraAPI.Example/MiraAPI.Example.csproj @@ -6,20 +6,15 @@ 1.0.0 dev - Simple and easy to use Among Us modding API. + Example mod for Mira API Angxl, XtraCube - - - Steam - 2024.6.18 - - + - + @@ -32,6 +27,6 @@ - + From 2fb9d426c70816e167b00e3ee55cb3be3464b49f Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:57:01 -0400 Subject: [PATCH 32/60] some more scrollbar fixes --- .../Patches/Options/GameSettingMenuPatches.cs | 2 +- .../Patches/Options/RoleSettingMenuPatches.cs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs index 24f2a43..6e10fbe 100644 --- a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs @@ -122,7 +122,7 @@ public static class GameSettingMenuPatches roles.RoleChancesSettings.gameObject.SetActive(true); roles.SetQuotaTab(); - roles.scrollBar.CalculateAndSetYBounds(roles.roleChances.Count + 3, 1f, 6f, 0.43f); + roles.scrollBar.CalculateAndSetYBounds(roles.roleChances.Count + 5, 1f, 6f, 0.43f); roles.scrollBar.ScrollToTop(); } diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 55b446c..cd25881 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -27,6 +27,7 @@ public static class RoleSettingMenuPatches __instance.advancedSettingChildren = new Il2CppSystem.Collections.Generic.List(); var maskBg = __instance.scrollBar.transform.FindChild("MaskBg"); + var hitbox = __instance.scrollBar.transform.FindChild("Hitbox"); if (GameSettingMenuPatches.CurrentSelectedMod == 0) { @@ -35,6 +36,8 @@ public static class RoleSettingMenuPatches __instance.scrollBar.transform.localPosition = new Vector3(-1.4957f, 0.657f, -4); maskBg.localPosition = new Vector3(1.5353f, -.5734f, -.1f); maskBg.localScale = new Vector3(6.6811f, 3.3563f, 0.5598f); + hitbox.localPosition = new Vector3(0.3297f, -.2333f, 4f); + hitbox.localScale = new Vector3(1, 1, 1); return true; } @@ -45,6 +48,8 @@ public static class RoleSettingMenuPatches __instance.scrollBar.transform.localPosition = new Vector3(-1.4957f, 1.5261f, -4); maskBg.localPosition = new Vector3(1.5353f, -1.0607f, -.1f); 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); int num3 = 0; @@ -97,7 +102,7 @@ public static class RoleSettingMenuPatches if (neutRoles.Count > 0) { - num -= 0.8f; + num -= 0.4f; CategoryHeaderEditRole categoryHeaderEditRole3 = Object.Instantiate(__instance.categoryHeaderEditRoleOrigin, Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform); categoryHeaderEditRole3.SetHeader(StringNames.None, 20); @@ -126,7 +131,15 @@ public static class RoleSettingMenuPatches return false; } - + + [HarmonyPostfix] + [HarmonyPatch(nameof(RolesSettingsMenu.OpenChancesTab))] + public static void OpenChancesTabPostfix(RolesSettingsMenu __instance) + { + __instance.scrollBar.CalculateAndSetYBounds(__instance.roleChances.Count + 5, 1f, 6f, 0.43f); + __instance.scrollBar.ScrollToTop(); + } + private static void ValueChanged(OptionBehaviour obj) { var roleSetting = obj.Cast(); @@ -202,6 +215,7 @@ public static class RoleSettingMenuPatches } __instance.scrollBar.CalculateAndSetYBounds(__instance.advancedSettingChildren.Count + 3, 1f, 6f, 0.45f); + __instance.scrollBar.ScrollToTop(); } private static void ChangeTab(RoleBehaviour role, RolesSettingsMenu __instance) { From d8ed4f387dc316c5520bcda4ec89d05c2e7c8532 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sat, 24 Aug 2024 11:27:37 -0400 Subject: [PATCH 33/60] fix examples and readme --- MiraAPI.Example/Buttons/ExampleButton.cs | 2 +- MiraAPI.Example/ExampleAssets.cs | 9 ++++++ MiraAPI.Example/MiraAPI.Example.csproj | 7 +++- MiraAPI.Example/Resources/ExampleButton.png | Bin 0 -> 20657 bytes .../Resources/FortniteBanner.jpeg | Bin MiraAPI.Example/Roles/CustomRole.cs | 2 +- MiraAPI.Example/Roles/CustomRole2.cs | 2 +- MiraAPI.Example/Roles/CustomRole3.cs | 2 +- MiraAPI/MiraAPI.csproj | 2 -- MiraAPI/Resources/ExampleButton.png | Bin 16568 -> 0 bytes MiraAPI/Utilities/Assets/MiraAssets.cs | 1 - README.md | 30 ++++++++++-------- 12 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 MiraAPI.Example/ExampleAssets.cs create mode 100644 MiraAPI.Example/Resources/ExampleButton.png rename {MiraAPI => MiraAPI.Example}/Resources/FortniteBanner.jpeg (100%) delete mode 100644 MiraAPI/Resources/ExampleButton.png diff --git a/MiraAPI.Example/Buttons/ExampleButton.cs b/MiraAPI.Example/Buttons/ExampleButton.cs index a7aa9fb..336896e 100644 --- a/MiraAPI.Example/Buttons/ExampleButton.cs +++ b/MiraAPI.Example/Buttons/ExampleButton.cs @@ -12,7 +12,7 @@ public class ExampleButton : CustomActionButton public override float Cooldown => 5f; public override float EffectDuration => 0f; public override int MaxUses => 5; - public override LoadableAsset Sprite { get; } = new LoadableResourceAsset("MiraAPI.Resources.ExampleButton.png"); + public override LoadableAsset Sprite { get; } = ExampleAssets.ExampleButton; protected override void OnClick() { diff --git a/MiraAPI.Example/ExampleAssets.cs b/MiraAPI.Example/ExampleAssets.cs new file mode 100644 index 0000000..b4abb94 --- /dev/null +++ b/MiraAPI.Example/ExampleAssets.cs @@ -0,0 +1,9 @@ +using MiraAPI.Utilities.Assets; + +namespace MiraAPI.Example; + +public static class ExampleAssets +{ + public static LoadableResourceAsset ExampleButton { get; } = new("MiraAPI.Example.Resources.ExampleButton.png"); + public static LoadableResourceAsset Banner { get; } = new("MiraAPI.Example.Resources.FortniteBanner.png"); +} \ No newline at end of file diff --git a/MiraAPI.Example/MiraAPI.Example.csproj b/MiraAPI.Example/MiraAPI.Example.csproj index bafb3f3..6c406ee 100644 --- a/MiraAPI.Example/MiraAPI.Example.csproj +++ b/MiraAPI.Example/MiraAPI.Example.csproj @@ -23,7 +23,12 @@ - + + + + + + diff --git a/MiraAPI.Example/Resources/ExampleButton.png b/MiraAPI.Example/Resources/ExampleButton.png new file mode 100644 index 0000000000000000000000000000000000000000..2052930cb7a58653b031c8dae5521e81ccb418a5 GIT binary patch literal 20657 zcma&OcOcdM`#*k;bDU!w9Qz!5X6M+Ob8H!@kjUQ3iV6wGv9h-$Bco6XQIt3wGqWh8 zWEN!|BaV4~r|$c6zrTO}{&*S3@jBP@+SlW{uGc+F3nK49 zlM*A2$^p-Er}x6*-v_0NrBJgP4ytPVheNOa z{XADBV=~Mc3&3c?bz+4lNzeu<5RjCo)_j4wRU~gkOrH>qUQAt77I6) zxNz=KQ;#i9iDQ}P+nryBx>s!2x_<_J!*VpAsBYc{YXblB?iVeZpKB|xFJ?9>!b|nm zE`spc&mO_ZtKJp3cxWE~!m0hDJG1!5ZqY7ePHrv&#=wBM?ze_`_Usu_L=-bb2MeTs z0N=adE>Zj6nW>(f3MLhi$>gY29hT7jjT!P!g~w!-*QleBzCIHFbX7SrFE8(upPzp} zYA0`q+#Ycdv&M!{-KYG=4u-ppOjh`ZC0sR`{0Ef#@Yh+M?ktax zJ$ohWDO2Q^bq!=MPfzNB3t7g}GBT(9>LG9~=Bp=Ua{Ejv?FgBS{O5k-`C5!IXn33s zYTk=O6ZB;Iy}dJi?>65T|3zjRfkab)o>|H?vtPug%dPo?W=fm0#dw8`TIUqZwbZ7) znfbf;V4ZYhaPGzhNkJP47dF;dU|ahg+lj#jl)1vS_sC z@Q*=*K6#<)*l=jhThYqzNRbK;WGIP*L?8AbD+ zpBYNh&hdaiIKjkvzc0%1(a`{+03%N{E1-hp>FMHzk%D@bkd;>@BH{N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;{(OqtDC|k8D!!aZs-uw0Dt?ya^c&!1L3^7ezn5| zo&-6AH80t`&Tm%5pxU+T_0j1E9;3^iy(S?7p>CFnregGng$gOkCcpdV>!%(B|vd5qR1Y@@0t1>)vP;vnA0Ae20apX(M zzJSpJvA2(N9&PR}|F2oanz)QB;Rssabl% zbiB_vWW)+Q4SR|Q+-GsgQezp}$=zLk-M%BMLrTwbb|xX{LH-DmvW_jB{SkBxjT07e zmVmw5lYXV(^&(79)UFyd@+K5O;(N|?-)}I11xYlBrE z$(u7ZjWh+HD7l*G+D4`TFOr%6&UJh>yx)zg1ZgSXC;!${v-1Bf-obs1j9|R)wu@+c z4)Bmy4|l5pMKuU}{Dwd4O1>Y&O6(Ot0S0lud(orkZmbpcc11JQX~1BXUY@lK*lfmY zj~6&p*4*bIp{vc1+=K!MKvmll2_3<7Fa&<9li*_+=TKP9+>=Wj$DcWCBd4#DkFt=J zcAiB0Lm=w`%Ebs_{~5dXyywpws0qwG-pO9>&@1?vzt9!PGoAdEP3>I7_k#HUXo3F& b6$Amq6$eEAEBAYU7nT2yfj*bK!g&7ydnOHn literal 0 HcmV?d00001 diff --git a/MiraAPI/Resources/FortniteBanner.jpeg b/MiraAPI.Example/Resources/FortniteBanner.jpeg similarity index 100% rename from MiraAPI/Resources/FortniteBanner.jpeg rename to MiraAPI.Example/Resources/FortniteBanner.jpeg diff --git a/MiraAPI.Example/Roles/CustomRole.cs b/MiraAPI.Example/Roles/CustomRole.cs index 44dfbe8..4e3c9a4 100644 --- a/MiraAPI.Example/Roles/CustomRole.cs +++ b/MiraAPI.Example/Roles/CustomRole.cs @@ -12,6 +12,6 @@ public class CustomRole : ImpostorRole, ICustomRole public string RoleDescription => RoleLongDescription; public Color RoleColor => Palette.Orange; public ModdedRoleTeams Team => ModdedRoleTeams.Impostor; - public LoadableAsset OptionsScreenshot => MiraAssets.Banner; + public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; } \ No newline at end of file diff --git a/MiraAPI.Example/Roles/CustomRole2.cs b/MiraAPI.Example/Roles/CustomRole2.cs index b5bbe48..019c891 100644 --- a/MiraAPI.Example/Roles/CustomRole2.cs +++ b/MiraAPI.Example/Roles/CustomRole2.cs @@ -12,6 +12,6 @@ public class CustomRole2 : CrewmateRole, ICustomRole public string RoleDescription => RoleLongDescription; public Color RoleColor => Palette.AcceptedGreen; public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; - public LoadableAsset OptionsScreenshot => MiraAssets.Banner; + public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; } \ No newline at end of file diff --git a/MiraAPI.Example/Roles/CustomRole3.cs b/MiraAPI.Example/Roles/CustomRole3.cs index a97f9df..111aa83 100644 --- a/MiraAPI.Example/Roles/CustomRole3.cs +++ b/MiraAPI.Example/Roles/CustomRole3.cs @@ -12,6 +12,6 @@ public class CustomRole3 : CrewmateRole, ICustomRole public string RoleDescription => RoleLongDescription; public Color RoleColor => Palette.Brown; public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; - public LoadableAsset OptionsScreenshot => MiraAssets.Banner; + public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; } \ No newline at end of file diff --git a/MiraAPI/MiraAPI.csproj b/MiraAPI/MiraAPI.csproj index e4dad34..fbc3e66 100644 --- a/MiraAPI/MiraAPI.csproj +++ b/MiraAPI/MiraAPI.csproj @@ -13,10 +13,8 @@ - - diff --git a/MiraAPI/Resources/ExampleButton.png b/MiraAPI/Resources/ExampleButton.png deleted file mode 100644 index c1680cceb2c80a294ddcd38385d6a37bf5a370c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16568 zcmZ8}cRbZ^|Nr|8=QtdD6AmI$*&`$87?DyZ5n0(}6H(SV4l*-Bh#aCME0mpMMKVqz zGO|b6qmXfar~7l?_4)q(cps0);eB1NJ+ABd5{QCJ7hZaWt zY&~c50RT|I1#OH`K$a~xjR?22v^4b>0EII4v4;+g1+=Hue%-KX-ft2VRSKNbznYvH zFZ)66r5xLn?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4s(Vm!`45o)%G&~V2EsOkvlwVLLxh;MLdo>Bl573R6YOan1xtZ75?89w< zyBdNJ8iq1Fl<2-qeAt4~Y9sTZF}Pxo(7$F^sWT@4==P!xtQ1MUs!s0YaxUhtx&W5H zbaB<5>5coB#nHO^VBCr{I9tup(GhlTm+o6)6d%=bX~@l}iWb_xo<#Lw97xHTE>ejO zt#ei!gfpx4UmXLPu%M7G@?or9*blXB0NE5Mv_XE447(>>K6R5^i*}aF3#4{*pQ#h- z-CpLo!%FX9W7|Em7Yks_Z*&F<<5iQR zRC08Dw%K25{|pS~mIcd<7}hpM#x>#IOp2n4Hh9i`%Yc zOw3MxKE(kC6}kK~CB6v7A<>_#Gs#D%omF`X$LO`M1K&%Vd4nb;O(+MTN*lh@7;gEm z=&m=OE+DKW18+6FmL-K76R(IJ;z*%IvoK{&;6%a4oQ|Ce6X=1fq|*34RTwmZ*!{~v ze&0M0_lx&5!S{~a|Z zTVDYdas2l#BDj1FKz!TpSOpf1Dy2u#4b`hRG2^#_w751$C;`;9NyYjlAb6LAo(>m<`0R_cw;Q#;t diff --git a/MiraAPI/Utilities/Assets/MiraAssets.cs b/MiraAPI/Utilities/Assets/MiraAssets.cs index fa6ad54..0ed16b0 100644 --- a/MiraAPI/Utilities/Assets/MiraAssets.cs +++ b/MiraAPI/Utilities/Assets/MiraAssets.cs @@ -7,5 +7,4 @@ public static class MiraAssets public static readonly LoadableResourceAsset NextButton = new("MiraAPI.Resources.NextButton.png"); public static readonly LoadableResourceAsset NextButtonActive = new("MiraAPI.Resources.NextButtonActive.png"); public static readonly LoadableResourceAsset Cog = new("MiraAPI.Resources.Cog.png"); - public static readonly LoadableResourceAsset Banner = new("MiraAPI.Resources.FortniteBanner.jpeg"); } \ No newline at end of file diff --git a/README.md b/README.md index 21b6334..b978c28 100644 --- a/README.md +++ b/README.md @@ -27,28 +27,28 @@ Roles are very simple in Mira API. There are 3 things you need to do to create a 2. Implement the `ICustomRole` interface from Mira API. 3. Add the `[RegisterCustomRole]` attribute to the class. -See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/CustomRole.cs) for a code example. +See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Roles/CustomRole.cs) for a code example. ## Options Options are also very simple in Mira API. Options are split up into Groups and Options. Every Option needs to be in a Group. -To create a group, you need to create a class that implements the `IModdedOptionGroup` interface. Groups contain 4 properties, `GroupName`, `GroupColor`, `GroupVisible`, and `AdvancedRole`. Only the `GroupName` is required. +To create a group, you need to create a class that inherits from the `AbstractOptionGroup` abstract class. Groups contain 4 properties, `GroupName`, `GroupColor`, `GroupVisible`, and `AdvancedRole`. Only the `GroupName` is required. Here is an example of a group class: ```csharp -public class MyOptionsGroup : IModdedOptionGroup +public class MyOptionsGroup : AbstractOptionGroup { - public string GroupName => "My Options"; // this is required + public override string GroupName => "My Options"; // this is required [ModdedNumberOption("My Number Option", min: 0, max: 10)] public float MyNumberOption { get; set; } = 5f; } ``` -You can access any group class using the `ModdedGroupSingleton` class like this: +You can access any group class using the `OptionGroupSingleton` class like this: ``` -// MyOptionsGroup is a class that implements IModdedOptionGroup -var myGroup = ModdedGroupSingleton.Instance; // gets the instance of the group +// MyOptionsGroup is a class that inherits from AbstractOptionGroup +var myGroup = OptionGroupSingleton.Instance; // gets the instance of the group System.Out.Console.WriteLine(myGroup.MyNumberOption); // prints the value of the option to the console ``` @@ -74,7 +74,7 @@ Here is a full list of ModdedOption classes you can use: - `ModdedStringOption` - `ModdedToggleOption` -To see a full example of an options class, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExampleOptions.cs). +To see a full example of an options class, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Options/ExampleOptions.cs). ### Role Options @@ -82,10 +82,10 @@ You can also specify a role type for an option or option group. To set the role type for an entire group, set the `AdvancedRole` property on that group like this: ```csharp -public class MyOptionsGroup : IModdedOptionGroup +public class MyOptionsGroup : AbstractOptionGroup { - public string GroupName => "My Options"; - public Type AdvancedRole => typeof(MyRole); // this is the role that will have these options + public override string GroupName => "My Options"; + public override Type AdvancedRole => typeof(MyRole); // this is the role that will have these options [ModdedNumberOption("Ability Uses", min: 0, max: 10)] public float AbilityUses { get; set; } = 5f; @@ -95,9 +95,9 @@ public class MyOptionsGroup : IModdedOptionGroup To set the role type for individual options, specify the `roleType` parameter in the option like this: ```csharp // this group doesnt specify a role, so it will show up in the global settings -public class MyOptionsGroup : IModdedOptionGroup +public class MyOptionsGroup : AbstractOptionGroup { - public string GroupName => "My Options"; + public override string GroupName => "My Options"; // this option will only show up in the settings for MyRole [ModdedNumberOption("Ability Uses", min: 0, max: 10, roleType: typeof(MyRole))] @@ -115,7 +115,7 @@ Mira API provides a simple interface for adding ability buttons to the game. The The button API is simple, but provides a lot of flexibility. There are various methods you can override to customize the behaviour of your button. See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI/Hud/CustomActionButton.cs) for a full list of methods you can override. -An example button can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExampleButton.cs). +An example button can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Buttons/ExampleButton.cs). ## Assets @@ -138,6 +138,8 @@ LoadableAsset buttonAsset = new LoadableResourceAsset("ExampleMod.Resour Sprite button = buttonSpriteAsset.LoadAsset(); ``` +You can view an example file [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExampleAssets.cs). + You can create your own asset loaders by inheriting from `LoadableAsset` and implementing the `LoadAsset` method. # Disclaimer From 7480217d6ca6c1574304809cbd1f661b12c956eb Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sat, 24 Aug 2024 11:30:14 -0400 Subject: [PATCH 34/60] wrong file type in example assets oops --- MiraAPI.Example/ExampleAssets.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MiraAPI.Example/ExampleAssets.cs b/MiraAPI.Example/ExampleAssets.cs index b4abb94..005d106 100644 --- a/MiraAPI.Example/ExampleAssets.cs +++ b/MiraAPI.Example/ExampleAssets.cs @@ -5,5 +5,5 @@ namespace MiraAPI.Example; public static class ExampleAssets { public static LoadableResourceAsset ExampleButton { get; } = new("MiraAPI.Example.Resources.ExampleButton.png"); - public static LoadableResourceAsset Banner { get; } = new("MiraAPI.Example.Resources.FortniteBanner.png"); + public static LoadableResourceAsset Banner { get; } = new("MiraAPI.Example.Resources.FortniteBanner.jpeg"); } \ No newline at end of file From 3a14a95e3bc03dc938d47ba996b219d31a8b0779 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sat, 24 Aug 2024 11:31:37 -0400 Subject: [PATCH 35/60] updates to readme (formatting, info, etc) --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b978c28..504c2cb 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,15 @@ # Mira API -A thorough, but simple, Among Us modding API that covers: +A thorough, but simple, Among Us modding API and utility library that covers: - Roles - Options -- Gamemodes +- Modifiers +- Game Modes - Assets - HUD Elements - Compatibility - + Mira API strives to be simple and easy to use, while also using as many base game elements as possible. The result is a less intrusive, better modding API that covers general use cases. # Usage @@ -46,7 +47,7 @@ public class MyOptionsGroup : AbstractOptionGroup ``` You can access any group class using the `OptionGroupSingleton` class like this: -``` +```csharp // MyOptionsGroup is a class that inherits from AbstractOptionGroup var myGroup = OptionGroupSingleton.Instance; // gets the instance of the group System.Out.Console.WriteLine(myGroup.MyNumberOption); // prints the value of the option to the console From 4db75aa4a94d2117e4e40fb2dd0577903f95eccf Mon Sep 17 00:00:00 2001 From: ang-xd Date: Sat, 24 Aug 2024 11:38:58 -0400 Subject: [PATCH 36/60] WIP Colors & Config button fix --- MiraAPI.Example/Roles/CustomRole.cs | 4 +- .../OptionTypes/ModdedToggleOption.cs | 6 +-- .../Patches/Options/GameOptionsMenuPatch.cs | 11 +++-- .../Patches/Options/RoleSettingMenuPatches.cs | 19 ++++---- MiraAPI/Patches/Roles/EjectionPatches.cs | 6 +-- MiraAPI/PluginLoading/MiraPluginManager.cs | 43 ++++++++++++++----- MiraAPI/Utilities/Colors/CustomColor.cs | 30 +++++++++++++ .../Colors/RegisterColorAttribute.cs | 6 +++ MiraAPI/Utilities/Extensions.cs | 15 +++++++ 9 files changed, 110 insertions(+), 30 deletions(-) create mode 100644 MiraAPI/Utilities/Colors/CustomColor.cs create mode 100644 MiraAPI/Utilities/Colors/RegisterColorAttribute.cs diff --git a/MiraAPI.Example/Roles/CustomRole.cs b/MiraAPI.Example/Roles/CustomRole.cs index 44dfbe8..9226020 100644 --- a/MiraAPI.Example/Roles/CustomRole.cs +++ b/MiraAPI.Example/Roles/CustomRole.cs @@ -10,8 +10,8 @@ public class CustomRole : ImpostorRole, ICustomRole public string RoleName => "fortnite killer"; public string RoleLongDescription => "ok so your objective is to eliminate everyone with your fortnite tactical shotgun, good luck"; public string RoleDescription => RoleLongDescription; - public Color RoleColor => Palette.Orange; + public Color RoleColor => Palette.Black; public ModdedRoleTeams Team => ModdedRoleTeams.Impostor; public LoadableAsset OptionsScreenshot => MiraAssets.Banner; - + } \ No newline at end of file diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs index a29e648..15b920e 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs @@ -1,5 +1,5 @@ -using System; -using MiraAPI.Networking; +using MiraAPI.Networking; +using System; using UnityEngine; using Object = UnityEngine.Object; @@ -7,7 +7,7 @@ namespace MiraAPI.GameOptions.OptionTypes; public class ModdedToggleOption : ModdedOption { - public ModdedToggleOption(string title, bool defaultValue, Type roleType=null) : base(title, defaultValue, roleType) + public ModdedToggleOption(string title, bool defaultValue, Type roleType = null) : base(title, defaultValue, roleType) { Data = ScriptableObject.CreateInstance(); diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index 06b46e1..d446f8e 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -41,7 +41,7 @@ public static class GameOptionsMenuPatch if (group.GroupColor != Color.clear) { categoryHeaderMasked.Background.color = group.GroupColor; - categoryHeaderMasked.Title.color = group.GroupColor.DarkenColor(); + categoryHeaderMasked.Title.color = group.GroupColor.GetAlternateColor(); } categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f; categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f); @@ -58,7 +58,12 @@ public static class GameOptionsMenuPatch { if (group.GroupColor != Color.clear) { - componentsInChildren[i].color = group.GroupColor; + componentsInChildren[i].color = group.GroupColor.GetAlternateColor(); + if (componentsInChildren[i].transform.parent.TryGetComponent(out var btn)) + { + btn.interactableColor = group.GroupColor.GetAlternateColor(); + btn.interactableHoveredColor = Color.white; + } } componentsInChildren[i].material.SetInt(PlayerMaterial.MaskLayer, 20); @@ -68,7 +73,7 @@ public static class GameOptionsMenuPatch { if (group.GroupColor != Color.clear) { - textMeshPro.color = group.GroupColor.DarkenColor(); + textMeshPro.color = group.GroupColor; } textMeshPro.fontMaterial.SetFloat(ShaderID.StencilComp, 3f); diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index cd25881..81c9522 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -131,7 +131,7 @@ public static class RoleSettingMenuPatches return false; } - + [HarmonyPostfix] [HarmonyPatch(nameof(RolesSettingsMenu.OpenChancesTab))] public static void OpenChancesTabPostfix(RolesSettingsMenu __instance) @@ -139,7 +139,7 @@ public static class RoleSettingMenuPatches __instance.scrollBar.CalculateAndSetYBounds(__instance.roleChances.Count + 5, 1f, 6f, 0.43f); __instance.scrollBar.ScrollToTop(); } - + private static void ValueChanged(OptionBehaviour obj) { var roleSetting = obj.Cast(); @@ -225,7 +225,7 @@ public static class RoleSettingMenuPatches __instance.roleScreenshot.sprite = Sprite.Create(customRole.OptionsScreenshot.LoadAsset().texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100); __instance.roleScreenshot.drawMode = SpriteDrawMode.Sliced; __instance.roleHeaderSprite.color = customRole.RoleColor; - __instance.roleHeaderText.color = customRole.RoleColor.DarkenColor(); + __instance.roleHeaderText.color = customRole.RoleColor.GetAlternateColor(); CreateAdvancedSettings(__instance, role); @@ -249,12 +249,14 @@ public static class RoleSettingMenuPatches roleOptionSetting.transform.localPosition = new Vector3(-0.15f, yPos, -2f); roleOptionSetting.SetRole(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions, role, 20); roleOptionSetting.labelSprite.color = customRole.RoleColor; - roleOptionSetting.titleText.color = customRole.RoleColor.DarkenColor(); roleOptionSetting.OnValueChanged = new Action(ValueChanged); - roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left; roleOptionSetting.SetClickMask(__instance.ButtonClickMask); __instance.roleChances.Add(roleOptionSetting); + roleOptionSetting.titleText.transform.localPosition = new Vector3(-0.5376f, -0.2923f, 0f); + roleOptionSetting.titleText.color = customRole.RoleColor.GetAlternateColor(); + roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left; + PassiveButton newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform); newButton.name = "ConfigButton"; newButton.transform.localPosition = new Vector3(0.4473f, -0.3f, -2f); @@ -263,12 +265,11 @@ public static class RoleSettingMenuPatches SpriteRenderer btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent(); btnRend.sprite = MiraAssets.Cog.LoadAsset(); - btnRend.color = customRole.RoleColor.DarkenColor(); - PassiveButton passiveButton = newButton.GetComponent(); + GameOptionButton passiveButton = newButton.GetComponent(); passiveButton.OnClick = new ButtonClickedEvent(); - passiveButton.disabledTextColor = customRole.RoleColor.DarkenColor(); - passiveButton.selectedTextColor = customRole.RoleColor.DarkenColor().DarkenColor(); + passiveButton.interactableColor = btnRend.color = customRole.RoleColor.GetAlternateColor(); + passiveButton.interactableHoveredColor = Color.white; passiveButton.OnClick.AddListener((UnityAction)(() => { diff --git a/MiraAPI/Patches/Roles/EjectionPatches.cs b/MiraAPI/Patches/Roles/EjectionPatches.cs index 60c0dfe..bbea1e8 100644 --- a/MiraAPI/Patches/Roles/EjectionPatches.cs +++ b/MiraAPI/Patches/Roles/EjectionPatches.cs @@ -6,12 +6,12 @@ namespace MiraAPI.Patches.Roles; [HarmonyPatch(typeof(ExileController))] public static class EjectionPatches { - + [HarmonyPostfix] [HarmonyPatch(nameof(ExileController.Begin))] public static void Begin(ExileController __instance) { - if (!__instance.initData.networkedPlayer.Role || __instance.initData.networkedPlayer.Role is not ICustomRole role) + if (!__instance.initData.networkedPlayer || !__instance.initData.networkedPlayer.Role || __instance.initData.networkedPlayer.Role is not ICustomRole role) { return; } @@ -20,7 +20,7 @@ public static class EjectionPatches { return; } - + __instance.completeString = role.GetCustomEjectionMessage(__instance.initData.networkedPlayer); } } \ No newline at end of file diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index 1124be9..f4075e8 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -3,25 +3,27 @@ using BepInEx.Unity.IL2CPP; using Il2CppInterop.Runtime.Injection; using MiraAPI.GameOptions; using MiraAPI.GameOptions.Attributes; +using MiraAPI.Hud; using MiraAPI.Roles; +using MiraAPI.Utilities.Colors; using Reactor.Utilities; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using MiraAPI.Hud; namespace MiraAPI.PluginLoading; internal class MiraPluginManager { public readonly Dictionary RegisteredPlugins = []; - + private static MiraPluginManager _instance; - - public static MiraPluginManager Instance { + + public static MiraPluginManager Instance + { get => _instance ??= new MiraPluginManager(); - private set => _instance = value; + private set => _instance = value; } internal void Initialize() @@ -38,10 +40,12 @@ internal class MiraPluginManager var info = new MiraPluginInfo(id, plugin as IMiraPlugin, IL2CPPChainloader.Instance.Plugins[id]); RegisterAllOptions(assembly, info); - + RegisterRoleAttribute(assembly, info); RegisterButtonAttribute(assembly); + RegisterAllColors(assembly); + RegisteredPlugins.Add(assembly, info); Logger.Info($"Registering mod {id} with Mira API."); @@ -56,14 +60,14 @@ internal class MiraPluginManager private static void RegisterAllOptions(Assembly assembly, MiraPluginInfo pluginInfo) { var filteredTypes = assembly.GetTypes().Where(type => type.IsAssignableTo(typeof(AbstractOptionGroup))); - + foreach (var type in filteredTypes) { if (!ModdedOptionsManager.RegisterGroup(type, pluginInfo)) { continue; } - + foreach (var property in type.GetProperties()) { if (property.PropertyType.IsAssignableTo(typeof(IModdedOption))) @@ -71,7 +75,7 @@ internal class MiraPluginManager ModdedOptionsManager.RegisterPropertyOption(type, property, pluginInfo); continue; } - + var attribute = property.GetCustomAttribute(); if (attribute == null) { @@ -109,12 +113,31 @@ internal class MiraPluginManager { Logger.Error($"{k}: {v}"); } - + Logger.Error(e); } } } + private static void RegisterAllColors(Assembly assembly) + { + foreach (var type in assembly.GetTypes()) + { + foreach (FieldInfo field in type.GetFields()) + { + foreach (var attribute in field.GetCustomAttributes()) + { + if (attribute.GetType().BaseType == typeof(RegisterColorAttribute)) + { + /* Palette.PlayerColors = Palette.PlayerColors.ToArray().AddToArray(); + Palette.ShadowColors = Palette.ShadowColors.ToArray().AddToArray(); + Palette.ColorNames = Palette.ColorNames.ToArray().AddToArray();*/ + } + } + } + } + } + private static void RegisterButtonAttribute(Assembly assembly) { foreach (var type in assembly.GetTypes()) diff --git a/MiraAPI/Utilities/Colors/CustomColor.cs b/MiraAPI/Utilities/Colors/CustomColor.cs new file mode 100644 index 0000000..99ebbdb --- /dev/null +++ b/MiraAPI/Utilities/Colors/CustomColor.cs @@ -0,0 +1,30 @@ +using UnityEngine; + +namespace MiraAPI.Utilities; +public class CustomColor +{ + public CustomColor(Color32 mainColor, StringNames name) + { + MainColor = mainColor; + ShadowColor = GetShadowColor(mainColor, 60); + Name = name; + } + + public CustomColor(Color32 mainColor, Color32 shadowColor, StringNames name) + { + MainColor = mainColor; + ShadowColor = shadowColor; + Name = name; + } + + public Color32 MainColor { get; } + public Color32 ShadowColor { get; } + public StringNames Name { get; } + + public static Color32 GetShadowColor(Color32 c, byte darknessAmount) + { + return + new Color32((byte)Mathf.Clamp(c.r - darknessAmount, 0, 255), (byte)Mathf.Clamp(c.g - darknessAmount, 0, 255), + (byte)Mathf.Clamp(c.b - darknessAmount, 0, 255), byte.MaxValue); + } +} \ No newline at end of file diff --git a/MiraAPI/Utilities/Colors/RegisterColorAttribute.cs b/MiraAPI/Utilities/Colors/RegisterColorAttribute.cs new file mode 100644 index 0000000..f80a7f2 --- /dev/null +++ b/MiraAPI/Utilities/Colors/RegisterColorAttribute.cs @@ -0,0 +1,6 @@ +using System; + +namespace MiraAPI.Utilities.Colors; + +[AttributeUsage(AttributeTargets.Field)] +public class RegisterColorAttribute : Attribute; \ No newline at end of file diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index e80e0b2..3ee4b85 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -17,6 +17,21 @@ public static class Extensions { return new Color(color.r - 0.3f, color.g - 0.3f, color.b - 0.3f); } + public static Color GetAlternateColor(this Color color) + { + return color.IsColorDark() ? LightenColor(color) : DarkenColor(color); + } + + public static Color LightenColor(this Color color) + { + return new Color(color.r + 0.3f, color.g + 0.3f, color.b + 0.3f); + } + + public static bool IsColorDark(this Color color) + { + return color.r < 0.5f && color.g < 0.5f && color.b < 0.5f; + } + public static void UpdateBodies(this PlayerControl playerControl, Color outlineColor, ref DeadBody target) { foreach (var body in Object.FindObjectsOfType()) From 3226d9fea50091f3fde0aaaf696bf6518f618599 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:52:20 -0400 Subject: [PATCH 37/60] small fixes --- MiraAPI/GameOptions/ModdedOptionsManager.cs | 24 +----- .../GameOptions/OptionTypes/ModdedOption.cs | 3 +- MiraAPI/Networking/NetData.cs | 6 +- .../Patches/Options/RoleSettingMenuPatches.cs | 2 +- MiraAPI/Patches/PlayerControlPatches.cs | 10 +-- MiraAPI/Roles/CustomRoleManager.cs | 46 ++++-------- MiraAPI/Roles/ICustomRole.cs | 17 +++-- MiraAPI/Utilities/Extensions.cs | 73 +++++++++++-------- 8 files changed, 79 insertions(+), 102 deletions(-) diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index 0725fc6..1836eb1 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Reflection; using MiraAPI.Networking; using MiraAPI.PluginLoading; +using MiraAPI.Utilities; using Reactor.Networking.Rpc; namespace MiraAPI.GameOptions; @@ -109,31 +110,14 @@ public class ModdedOptionsManager internal static void SyncAllOptions(int targetId=-1) { - List data = []; + var chunks = ModdedOptions.Values.Select(option => option.GetNetData()).ChunkNetData(1000); - var count = 0; - foreach (var netData in ModdedOptions.Values.Select(option => option.GetNetData())) + while (chunks.Count > 0) { - data.Add(netData); - count += netData.GetLength(); - - if (count <= 1000) - { - continue; - } - - Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, data.ToArray()); - data.Clear(); - count = 0; - } - - if (data.Count > 0) - { - Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, data.ToArray()); + Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, chunks.Dequeue()); } } - internal static void HandleSyncOptions(NetData[] data) { foreach (var netData in data) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index 9cd3e97..e06ca88 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -69,8 +69,7 @@ public abstract class ModdedOption : IModdedOption Rpc.Instance.Send(PlayerControl.LocalPlayer, [GetNetData()], true); } - if (ParentMod is not null && - ParentMod.GetConfigFile().TryGetEntry(ConfigDefinition, out var entry)) + if (ParentMod?.GetConfigFile().TryGetEntry(ConfigDefinition, out var entry) == true) { entry.Value = Value; } diff --git a/MiraAPI/Networking/NetData.cs b/MiraAPI/Networking/NetData.cs index a0d66d5..083a9d2 100644 --- a/MiraAPI/Networking/NetData.cs +++ b/MiraAPI/Networking/NetData.cs @@ -1,10 +1,8 @@ -using System; - -namespace MiraAPI.Networking; +namespace MiraAPI.Networking; public readonly struct NetData(uint id, byte[] data) { public uint Id { get; } = id; public byte[] Data { get; } = data; - public int GetLength() => BitConverter.GetBytes(Id).Length + Data.Length; + public int GetLength() => 4 + Data.Length; } \ No newline at end of file diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 81c9522..6e24a53 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -167,7 +167,7 @@ public static class RoleSettingMenuPatches if (AmongUsClient.Instance.AmHost) { - Rpc.Instance.Send(PlayerControl.LocalPlayer, [role.GetNetData(roleSetting.Role)], true); + Rpc.Instance.Send(PlayerControl.LocalPlayer, [role.GetNetData()], true); } GameOptionsManager.Instance.GameHostOptions = GameOptionsManager.Instance.CurrentGameOptions; } diff --git a/MiraAPI/Patches/PlayerControlPatches.cs b/MiraAPI/Patches/PlayerControlPatches.cs index bf42041..89060e0 100644 --- a/MiraAPI/Patches/PlayerControlPatches.cs +++ b/MiraAPI/Patches/PlayerControlPatches.cs @@ -12,16 +12,16 @@ public static class PlayerControlPatches [HarmonyPatch(nameof(PlayerControl.FixedUpdate))] public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance) { - if (!__instance.AmOwner) - { - return; - } - if (__instance.Data?.Role is ICustomRole customRole) { customRole.PlayerControlFixedUpdate(__instance); } + if (!__instance.AmOwner) + { + return; + } + foreach (var button in CustomButtonManager.CustomButtons) { if (!button.Enabled(__instance.Data?.Role)) diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 329b3c6..feb4e4f 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -9,7 +9,7 @@ using Reactor.Utilities.Extensions; using System; using System.Collections.Generic; using System.Linq; -using HarmonyLib; +using MiraAPI.Utilities; using TMPro; using UnityEngine; using Object = UnityEngine.Object; @@ -94,7 +94,7 @@ public static class CustomRoleManager public static bool GetCustomRoleBehaviour(RoleTypes roleType, out ICustomRole result) { CustomRoles.TryGetValue((ushort)roleType, out var temp); - if (temp != null) + if (temp) { result = temp as ICustomRole; return true; @@ -104,7 +104,7 @@ public static class CustomRoleManager return false; } - public static TaskPanelBehaviour CreateRoleTab(ICustomRole role) + internal static TaskPanelBehaviour CreateRoleTab(ICustomRole role) { var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").gameObject.GetComponent(); var clonePanel = Object.Instantiate(ogPanel.gameObject, ogPanel.transform.parent); @@ -122,7 +122,7 @@ public static class CustomRoleManager return newPanel; } - public static void UpdateRoleTab(TaskPanelBehaviour panel, ICustomRole role) + internal static void UpdateRoleTab(TaskPanelBehaviour panel, ICustomRole role) { var tabText = panel.tab.gameObject.GetComponentInChildren(); var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").gameObject.GetComponent(); @@ -138,40 +138,20 @@ public static class CustomRoleManager panel.SetTaskText(role.SetTabText().ToString()); } - public static void SyncAllRoleSettings(int targetId=-1) + internal static void SyncAllRoleSettings(int targetId=-1) { - List data = []; - int count = 0; - foreach (var role in CustomRoles.Values) + var data = CustomRoles.Values + .Where(x => x is ICustomRole { HideSettings: false }) + .Select(x => ((ICustomRole)x).GetNetData()) + .ChunkNetData(1000); + + while (data.Count > 0) { - ICustomRole customRole = role as ICustomRole; - if (customRole is null or { HideSettings: true }) - { - continue; - } - - customRole.ParentMod.PluginConfig.TryGetEntry(customRole.NumConfigDefinition, out var numEntry); - customRole.ParentMod.PluginConfig.TryGetEntry(customRole.ChanceConfigDefinition, out var chanceEntry); - - var netData = new NetData((uint)role.Role, BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); - - data.Add(netData); - count += netData.GetLength(); - - if (count > 1000) - { - Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, data.ToArray()); - data.Clear(); - count = 0; - } - } - if (data.Count > 0) - { - Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, data.ToArray()); + Rpc.Instance.SendTo(PlayerControl.LocalPlayer, targetId, data.Dequeue()); } } - public static void HandleSyncRoleOptions(NetData[] data) + internal static void HandleSyncRoleOptions(NetData[] data) { foreach (var netData in data) { diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index fcb7cca..4a630f4 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -45,8 +45,6 @@ public interface ICustomRole bool IsGhostRole => false; - bool TargetsBodies => false; - bool CreateCustomTab => true; bool HideSettings => IsGhostRole; @@ -55,8 +53,16 @@ public interface ICustomRole MiraPluginInfo ParentMod => CustomRoleManager.FindParentMod(this); + /// + /// Runs on the PlayerControl FixedUpdate method for any player with this role + /// + /// The PlayerControl that has this role void PlayerControlFixedUpdate(PlayerControl playerControl) { } + /// + /// Only runs for local player on HudManager Update method + /// + /// Reference to HudManager instance void HudUpdate(HudManager hudManager) { } string GetCustomEjectionMessage(NetworkedPlayerInfo player) @@ -70,11 +76,12 @@ public interface ICustomRole return taskStringBuilder; } - NetData GetNetData(RoleBehaviour roleBehaviour) + NetData GetNetData() { ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out var numEntry); ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out var chanceEntry); - - return new NetData((uint)roleBehaviour.Role, BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); + + // TODO: use the RoleID class when that branch is merged + return new NetData((uint)((RoleBehaviour)this).Role, BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); } } \ No newline at end of file diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 3ee4b85..a747e59 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -1,13 +1,49 @@ -using MiraAPI.GameOptions; -using MiraAPI.Roles; -using Reactor.Utilities.Extensions; +using System.Collections.Generic; +using MiraAPI.GameOptions; using System.Linq; +using MiraAPI.Networking; +using Reactor.Utilities; using UnityEngine; namespace MiraAPI.Utilities; public static class Extensions { + public static Queue ChunkNetData(this IEnumerable dataCollection, int chunkSize) + { + Queue chunks = []; + List current = []; + + var count = 0; + foreach (var netData in dataCollection) + { + var length = netData.GetLength(); + + if (length > chunkSize) + { + Logger.Error($"NetData length is greater than chunk size: {length} > {chunkSize}"); + continue; + } + + if (count + length > chunkSize) + { + chunks.Enqueue(current.ToArray()); + current.Clear(); + count = 0; + } + + current.Add(netData); + } + + if (current.Count > 0) + { + chunks.Enqueue(current.ToArray()); + } + + return chunks; + } + + public static bool IsCustom(this OptionBehaviour optionBehaviour) { return ModdedOptionsManager.ModdedOptions.Values.Any(opt => opt.OptionBehaviour && opt.OptionBehaviour.Equals(optionBehaviour)); @@ -32,37 +68,10 @@ public static class Extensions return color.r < 0.5f && color.g < 0.5f && color.b < 0.5f; } - public static void UpdateBodies(this PlayerControl playerControl, Color outlineColor, ref DeadBody target) - { - foreach (var body in Object.FindObjectsOfType()) - { - foreach (var bodyRenderer in body.bodyRenderers) - { - bodyRenderer.SetOutline(null); - } - } - - if (playerControl.Data.Role is not ICustomRole { TargetsBodies: true }) - { - return; - } - - target = playerControl.NearestDeadBody(); - if (!target) - { - return; - } - - foreach (var renderer in target.bodyRenderers) - { - renderer.SetOutline(outlineColor); - } - } - - public static DeadBody NearestDeadBody(this PlayerControl playerControl) + public static DeadBody NearestDeadBody(this PlayerControl playerControl, float radius) { var results = new Il2CppSystem.Collections.Generic.List(); - Physics2D.OverlapCircle(playerControl.GetTruePosition(), playerControl.MaxReportDistance / 4f, Helpers.Filter, results); + Physics2D.OverlapCircle(playerControl.GetTruePosition(), radius, Helpers.Filter, results); return results.ToArray() .Where(collider2D => collider2D.CompareTag("DeadBody")) .Select(collider2D => collider2D.GetComponent()) From 2eb2567db9098431b5d6f08a8c80b2e208e69b06 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sat, 24 Aug 2024 23:22:21 -0400 Subject: [PATCH 38/60] update to 2.3.1 and use ReactorCredits --- MiraAPI.Example/MiraAPI.Example.csproj | 3 +-- MiraAPI/MiraAPI.csproj | 3 +-- MiraAPI/MiraApiPlugin.cs | 19 +++---------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/MiraAPI.Example/MiraAPI.Example.csproj b/MiraAPI.Example/MiraAPI.Example.csproj index 6c406ee..87e735a 100644 --- a/MiraAPI.Example/MiraAPI.Example.csproj +++ b/MiraAPI.Example/MiraAPI.Example.csproj @@ -11,9 +11,8 @@ - + - diff --git a/MiraAPI/MiraAPI.csproj b/MiraAPI/MiraAPI.csproj index fbc3e66..b2e8122 100644 --- a/MiraAPI/MiraAPI.csproj +++ b/MiraAPI/MiraAPI.csproj @@ -19,9 +19,8 @@ - + - diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index dd41045..ad1fa11 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -8,6 +8,7 @@ using System; using System.Text; using Reactor.Networking; using Reactor.Networking.Attributes; +using Reactor.Utilities; using UnityEngine; namespace MiraAPI; @@ -26,24 +27,10 @@ public partial class MiraApiPlugin : BasePlugin public override void Load() { Harmony.PatchAll(); + + ReactorCredits.Register("Mira API", Version[..15], true, ReactorCredits.AlwaysShow); PluginManager = new MiraPluginManager(); PluginManager.Initialize(); - - ReactorVersionShower.TextUpdated += text => - { - text.text = new StringBuilder($"{MiraColor.ToTextColor()}Mira API ") - .Append(GetShortHashVersion(Version)) - .Append('\n') - .Append(text.text) - .ToString(); - }; - } - - private static string GetShortHashVersion(string version) - { - var index = version.IndexOf("+", StringComparison.Ordinal); - - return index < 0 ? version : version[..(index + 3)]; } } From 70320d7c191c26fdee3fba49053025e75d85a732 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sun, 25 Aug 2024 09:45:57 -0400 Subject: [PATCH 39/60] fixing a possible version not having commit hash attached to it case --- MiraAPI/MiraApiPlugin.cs | 3 ++- MiraAPI/Utilities/Extensions.cs | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index ad1fa11..83eea5a 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -6,6 +6,7 @@ using Reactor; using Reactor.Patches; using System; using System.Text; +using MiraAPI.Utilities; using Reactor.Networking; using Reactor.Networking.Attributes; using Reactor.Utilities; @@ -28,7 +29,7 @@ public partial class MiraApiPlugin : BasePlugin { Harmony.PatchAll(); - ReactorCredits.Register("Mira API", Version[..15], true, ReactorCredits.AlwaysShow); + ReactorCredits.Register("Mira API", Version.Truncate(15, "") ?? Version, true, ReactorCredits.AlwaysShow); PluginManager = new MiraPluginManager(); PluginManager.Initialize(); diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index a747e59..63b812d 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#nullable enable +using System.Collections.Generic; using MiraAPI.GameOptions; using System.Linq; using MiraAPI.Networking; @@ -9,6 +10,13 @@ namespace MiraAPI.Utilities; public static class Extensions { + public static string? Truncate(this string? value, int maxLength, string truncationSuffix = "…") + { + return value?.Length > maxLength + ? value.Substring(0, maxLength) + truncationSuffix + : value; + } + public static Queue ChunkNetData(this IEnumerable dataCollection, int chunkSize) { Queue chunks = []; @@ -68,7 +76,7 @@ public static class Extensions return color.r < 0.5f && color.g < 0.5f && color.b < 0.5f; } - public static DeadBody NearestDeadBody(this PlayerControl playerControl, float radius) + public static DeadBody? NearestDeadBody(this PlayerControl playerControl, float radius) { var results = new Il2CppSystem.Collections.Generic.List(); Physics2D.OverlapCircle(playerControl.GetTruePosition(), radius, Helpers.Filter, results); @@ -78,9 +86,9 @@ public static class Extensions .FirstOrDefault(component => component && !component.Reported); } - public static PlayerControl GetClosestPlayer(this PlayerControl playerControl, bool includeImpostors, float distance) + public static PlayerControl? GetClosestPlayer(this PlayerControl playerControl, bool includeImpostors, float distance) { - PlayerControl result = null; + PlayerControl? result = null; if (!ShipStatus.Instance) { return null; From b62d1b656573b6bca10a7c297d9050cdfcb14a19 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sun, 25 Aug 2024 21:51:22 -0400 Subject: [PATCH 40/60] targeting action button --- .../Buttons/ExampleTargetButton.cs | 40 ++++++++++++ MiraAPI/Hud/CustomActionButton.cs | 63 +++++++++++++++---- MiraAPI/MiraApiPlugin.cs | 3 - MiraAPI/Utilities/Extensions.cs | 33 +++++++--- 4 files changed, 116 insertions(+), 23 deletions(-) create mode 100644 MiraAPI.Example/Buttons/ExampleTargetButton.cs diff --git a/MiraAPI.Example/Buttons/ExampleTargetButton.cs b/MiraAPI.Example/Buttons/ExampleTargetButton.cs new file mode 100644 index 0000000..3fcdb33 --- /dev/null +++ b/MiraAPI.Example/Buttons/ExampleTargetButton.cs @@ -0,0 +1,40 @@ +using MiraAPI.Hud; +using MiraAPI.Utilities.Assets; +using UnityEngine; + +namespace MiraAPI.Example.Buttons; + +public class ExampleTargetButton : CustomActionButton +{ + public override string Name => "Shoot"; + public override float Cooldown => 0f; + public override float EffectDuration => 0f; + public override int MaxUses => 0; + public override LoadableAsset Sprite => ExampleAssets.ExampleButton; + + protected override void OnClick() + { + PlayerControl.LocalPlayer.CmdCheckMurder(Target); + } + + public override PlayerControl GetTarget() + { + return PlayerControl.LocalPlayer.Data.Role.FindClosestTarget(); + } + + public override void SetOutline(bool active) + { + Target?.cosmetics.SetOutline(active, new Il2CppSystem.Nullable(Color.red)); + } + + public override bool IsTargetValid(PlayerControl target) + { + return PlayerControl.LocalPlayer.Data.Role.IsValidTarget(target.Data); + } + + public override bool Enabled(RoleBehaviour role) + { + return role.IsImpostor; + } + +} \ No newline at end of file diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index 4acef2b..5e0fa4d 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -1,4 +1,6 @@ -using MiraAPI.Utilities.Assets; +#nullable enable +using MiraAPI.Utilities; +using MiraAPI.Utilities.Assets; using UnityEngine; using UnityEngine.Events; @@ -59,7 +61,7 @@ public abstract class CustomActionButton /// /// The button object in game. This is created by Mira API automatically. /// - protected ActionButton Button { get; private set; } + protected ActionButton? Button { get; private set; } internal void CreateButton(Transform parent) { @@ -109,7 +111,10 @@ public abstract class CustomActionButton /// The new sprite to override with public void OverrideSprite(Sprite sprite) { - Button.graphic.sprite = sprite; + if (Button != null) + { + Button.graphic.sprite = sprite; + } } /// @@ -118,7 +123,7 @@ public abstract class CustomActionButton /// The new name to override with public void OverrideName(string name) { - Button.OverrideText(name); + Button?.OverrideText(name); } /// @@ -164,7 +169,7 @@ public abstract class CustomActionButton /// Passed in from HudManager.SetHudActive, the current role of the player. public virtual void SetActive(bool visible, RoleBehaviour role) { - Button.ToggleVisible(visible && Enabled(role)); + Button?.ToggleVisible(visible && Enabled(role)); } /// @@ -172,7 +177,7 @@ public abstract class CustomActionButton /// This method takes into account cooldowns, effects, and uses, before calling the method. /// It can be overridden for custom behavior. /// - public virtual void ClickHandler() + protected virtual void ClickHandler() { if (!CanUse()) { @@ -182,11 +187,11 @@ public abstract class CustomActionButton if (LimitedUses) { UsesLeft--; - Button.SetUsesRemaining(UsesLeft); + Button?.SetUsesRemaining(UsesLeft); } OnClick(); - Button.SetDisabled(); + Button?.SetDisabled(); if (HasEffect) { EffectActive = true; @@ -219,15 +224,51 @@ public abstract class CustomActionButton if (CanUse()) { - Button.SetEnabled(); + Button?.SetEnabled(); } else { - Button.SetDisabled(); + Button?.SetDisabled(); } - Button.SetCoolDown(Timer, EffectActive ? EffectDuration : Cooldown); + Button?.SetCoolDown(Timer, EffectActive ? EffectDuration : Cooldown); FixedUpdate(playerControl); } +} + + +public abstract class CustomActionButton : CustomActionButton where T : MonoBehaviour +{ + public T? Target { get; private set; } + + public virtual float Distance => PlayerControl.LocalPlayer.Data.Role.GetAbilityDistance(); + + public virtual string ColliderTag => null; + + public virtual bool IsTargetValid(T target) + { + return target; + } + + public virtual T? GetTarget() + { + return PlayerControl.LocalPlayer.GetNearestObjectOfType(Distance, ColliderTag, IsTargetValid); + } + + public abstract void SetOutline(bool active); + + public override bool CanUse() + { + var newTarget = GetTarget(); + if (newTarget != Target) + { + SetOutline(false); + } + + Target = newTarget; + SetOutline(true); + + return base.CanUse() && Target; + } } \ No newline at end of file diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index 83eea5a..6dadbcd 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -3,9 +3,6 @@ using BepInEx.Unity.IL2CPP; using HarmonyLib; using MiraAPI.PluginLoading; using Reactor; -using Reactor.Patches; -using System; -using System.Text; using MiraAPI.Utilities; using Reactor.Networking; using Reactor.Networking.Attributes; diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 63b812d..7551865 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using System.Collections.Generic; using MiraAPI.GameOptions; using System.Linq; @@ -10,10 +11,16 @@ namespace MiraAPI.Utilities; public static class Extensions { + public static void SetOutline(this SpriteRenderer spriteRenderer, bool active, Color color) + { + spriteRenderer.material.SetFloat(ShaderID.Outline, active ? 1f : 0f); + spriteRenderer.material.SetColor(ShaderID.OutlineColor, color); + } + public static string? Truncate(this string? value, int maxLength, string truncationSuffix = "…") { return value?.Length > maxLength - ? value.Substring(0, maxLength) + truncationSuffix + ? value[..maxLength] + truncationSuffix : value; } @@ -73,7 +80,7 @@ public static class Extensions public static bool IsColorDark(this Color color) { - return color.r < 0.5f && color.g < 0.5f && color.b < 0.5f; + return color.r < 0.5f && color is { g: < 0.5f, b: < 0.5f }; } public static DeadBody? NearestDeadBody(this PlayerControl playerControl, float radius) @@ -86,6 +93,16 @@ public static class Extensions .FirstOrDefault(component => component && !component.Reported); } + public static T? GetNearestObjectOfType(this PlayerControl playerControl, float radius, string? colliderTag=null, Func? predicate=null) where T : Component + { + var results = new Il2CppSystem.Collections.Generic.List(); + Physics2D.OverlapCircle(playerControl.GetTruePosition(), radius, Helpers.Filter, results); + return results.ToArray() + .Where(collider2D => colliderTag == null || collider2D.CompareTag(colliderTag)) + .Select(collider2D => collider2D.GetComponent()) + .FirstOrDefault(predicate ?? (component => component)); + } + public static PlayerControl? GetClosestPlayer(this PlayerControl playerControl, bool includeImpostors, float distance) { PlayerControl? result = null; @@ -96,14 +113,12 @@ public static class Extensions var truePosition = playerControl.GetTruePosition(); - foreach (var playerInfo in GameData.Instance.AllPlayers) + var filteredPlayers = GameData.Instance.AllPlayers.ToArray() + .Where(playerInfo => !playerInfo.Disconnected && playerInfo.PlayerId != playerControl.PlayerId && !playerInfo.IsDead && + (includeImpostors || !playerInfo.Role.IsImpostor)); + + foreach (var playerInfo in filteredPlayers) { - if (playerInfo.Disconnected || playerInfo.PlayerId == playerControl.PlayerId || - playerInfo.IsDead || !includeImpostors && playerInfo.Role.IsImpostor) - { - continue; - } - var @object = playerInfo.Object; if (!@object) { From 0e39612325a715e11ab32a17a8a9d4f3f46c737a Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Mon, 26 Aug 2024 09:57:35 -0400 Subject: [PATCH 41/60] add docs to target button --- MiraAPI/Hud/CustomActionButton.cs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index 5e0fa4d..c2bf906 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -6,6 +6,9 @@ using UnityEngine.Events; namespace MiraAPI.Hud; +/// +/// Class for making custom action buttons. More customizable than the default Action/Ability buttons in the base game +/// public abstract class CustomActionButton { /// @@ -237,27 +240,50 @@ public abstract class CustomActionButton } } - +/// +/// Custom action button that has a target object. +/// +/// The type of the target object. public abstract class CustomActionButton : CustomActionButton where T : MonoBehaviour { + /// + /// The target object of the button. + /// public T? Target { get; private set; } + /// + /// The distance the player must be from the target object to use the button. + /// public virtual float Distance => PlayerControl.LocalPlayer.Data.Role.GetAbilityDistance(); - public virtual string ColliderTag => null; + /// + /// An optional collider tag to filter the target object by. + /// + public virtual string? ColliderTag => null; + /// + /// Determines if the target object is valid. + /// public virtual bool IsTargetValid(T target) { return target; } + /// + /// The method used to get the target object. + /// public virtual T? GetTarget() { return PlayerControl.LocalPlayer.GetNearestObjectOfType(Distance, ColliderTag, IsTargetValid); } + /// + /// Sets the outline of the target object. + /// + /// Should the outline be active public abstract void SetOutline(bool active); + public override bool CanUse() { var newTarget = GetTarget(); From 6de53fb7611603780fb634f94877df09a807676f Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Mon, 26 Aug 2024 09:57:46 -0400 Subject: [PATCH 42/60] custom colors API stuff --- MiraAPI/PluginLoading/MiraPluginManager.cs | 33 ++++++++++++++----- MiraAPI/Utilities/Colors/CustomColor.cs | 13 ++------ MiraAPI/Utilities/Colors/PaletteManager.cs | 21 ++++++++++++ .../Colors/RegisterColorAttribute.cs | 6 ---- .../Colors/RegisterColorsAttribute.cs | 6 ++++ MiraAPI/Utilities/Extensions.cs | 12 +++++++ 6 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 MiraAPI/Utilities/Colors/PaletteManager.cs delete mode 100644 MiraAPI/Utilities/Colors/RegisterColorAttribute.cs create mode 100644 MiraAPI/Utilities/Colors/RegisterColorsAttribute.cs diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index f4075e8..c132ffb 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using MiraAPI.Utilities; namespace MiraAPI.PluginLoading; @@ -123,19 +124,35 @@ internal class MiraPluginManager { foreach (var type in assembly.GetTypes()) { - foreach (FieldInfo field in type.GetFields()) + if (type.GetCustomAttribute() == null) { - foreach (var attribute in field.GetCustomAttributes()) + continue; + } + + if (!type.IsStatic()) + { + Logger.Error($"Color class {type.Name} must be static."); + continue; + } + + foreach (var property in type.GetProperties()) + { + if (property.PropertyType != typeof(CustomColor)) { - if (attribute.GetType().BaseType == typeof(RegisterColorAttribute)) - { - /* Palette.PlayerColors = Palette.PlayerColors.ToArray().AddToArray(); - Palette.ShadowColors = Palette.ShadowColors.ToArray().AddToArray(); - Palette.ColorNames = Palette.ColorNames.ToArray().AddToArray();*/ - } + continue; } + + var color = (CustomColor)property.GetValue(null); + if (color == null) + { + Logger.Error($"Color property {property.Name} in {type.Name} is null."); + continue; + } + + PaletteManager.CustomColors.Add(color); } } + PaletteManager.RegisterAllColors(); } private static void RegisterButtonAttribute(Assembly assembly) diff --git a/MiraAPI/Utilities/Colors/CustomColor.cs b/MiraAPI/Utilities/Colors/CustomColor.cs index 99ebbdb..9b261ef 100644 --- a/MiraAPI/Utilities/Colors/CustomColor.cs +++ b/MiraAPI/Utilities/Colors/CustomColor.cs @@ -1,12 +1,12 @@ using UnityEngine; -namespace MiraAPI.Utilities; -public class CustomColor +namespace MiraAPI.Utilities.Colors; +public sealed class CustomColor { public CustomColor(Color32 mainColor, StringNames name) { MainColor = mainColor; - ShadowColor = GetShadowColor(mainColor, 60); + ShadowColor = mainColor.GetShadowColor(60); Name = name; } @@ -20,11 +20,4 @@ public class CustomColor public Color32 MainColor { get; } public Color32 ShadowColor { get; } public StringNames Name { get; } - - public static Color32 GetShadowColor(Color32 c, byte darknessAmount) - { - return - new Color32((byte)Mathf.Clamp(c.r - darknessAmount, 0, 255), (byte)Mathf.Clamp(c.g - darknessAmount, 0, 255), - (byte)Mathf.Clamp(c.b - darknessAmount, 0, 255), byte.MaxValue); - } } \ No newline at end of file diff --git a/MiraAPI/Utilities/Colors/PaletteManager.cs b/MiraAPI/Utilities/Colors/PaletteManager.cs new file mode 100644 index 0000000..682a186 --- /dev/null +++ b/MiraAPI/Utilities/Colors/PaletteManager.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Linq; +using HarmonyLib; + +namespace MiraAPI.Utilities.Colors; + +internal static class PaletteManager +{ + public static readonly List CustomColors = []; + + public static void RegisterAllColors() + { + var colors = CustomColors.Select(x => x.MainColor); + var shadowColors = CustomColors.Select(x => x.ShadowColor); + var stringNames = CustomColors.Select(x => x.Name); + + Palette.PlayerColors = Palette.PlayerColors.ToArray().AddRangeToArray(colors.ToArray()); + Palette.ShadowColors = Palette.ShadowColors.ToArray().AddRangeToArray(shadowColors.ToArray()); + Palette.ColorNames = Palette.ColorNames.ToArray().AddRangeToArray(stringNames.ToArray()); + } +} \ No newline at end of file diff --git a/MiraAPI/Utilities/Colors/RegisterColorAttribute.cs b/MiraAPI/Utilities/Colors/RegisterColorAttribute.cs deleted file mode 100644 index f80a7f2..0000000 --- a/MiraAPI/Utilities/Colors/RegisterColorAttribute.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System; - -namespace MiraAPI.Utilities.Colors; - -[AttributeUsage(AttributeTargets.Field)] -public class RegisterColorAttribute : Attribute; \ No newline at end of file diff --git a/MiraAPI/Utilities/Colors/RegisterColorsAttribute.cs b/MiraAPI/Utilities/Colors/RegisterColorsAttribute.cs new file mode 100644 index 0000000..ef8a1cb --- /dev/null +++ b/MiraAPI/Utilities/Colors/RegisterColorsAttribute.cs @@ -0,0 +1,6 @@ +using System; + +namespace MiraAPI.Utilities.Colors; + +[AttributeUsage(AttributeTargets.Class)] +public class RegisterColorsAttribute : Attribute; \ No newline at end of file diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 7551865..7811b75 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -11,6 +11,18 @@ namespace MiraAPI.Utilities; public static class Extensions { + public static bool IsStatic(this Type type) + { + return type is { IsClass: true, IsAbstract: true, IsSealed: true }; + } + + public static Color32 GetShadowColor(this Color32 color, byte darknessAmount) + { + return + new Color32((byte)Mathf.Clamp(color.r - darknessAmount, 0, 255), (byte)Mathf.Clamp(color.g - darknessAmount, 0, 255), + (byte)Mathf.Clamp(color.b - darknessAmount, 0, 255), byte.MaxValue); + } + public static void SetOutline(this SpriteRenderer spriteRenderer, bool active, Color color) { spriteRenderer.material.SetFloat(ShaderID.Outline, active ? 1f : 0f); From d0bbb191c5d282ceca536621a5ecd013da4e8547 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Mon, 26 Aug 2024 10:38:35 -0400 Subject: [PATCH 43/60] rename to palette --- MiraAPI/PluginLoading/MiraPluginManager.cs | 2 +- MiraAPI/Utilities/Colors/CustomColor.cs | 8 ++++---- .../{RegisterColorsAttribute.cs => RegisterPalette.cs} | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename MiraAPI/Utilities/Colors/{RegisterColorsAttribute.cs => RegisterPalette.cs} (66%) diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index c132ffb..bfd9af7 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -124,7 +124,7 @@ internal class MiraPluginManager { foreach (var type in assembly.GetTypes()) { - if (type.GetCustomAttribute() == null) + if (type.GetCustomAttribute() == null) { continue; } diff --git a/MiraAPI/Utilities/Colors/CustomColor.cs b/MiraAPI/Utilities/Colors/CustomColor.cs index 9b261ef..93ee653 100644 --- a/MiraAPI/Utilities/Colors/CustomColor.cs +++ b/MiraAPI/Utilities/Colors/CustomColor.cs @@ -3,6 +3,10 @@ namespace MiraAPI.Utilities.Colors; public sealed class CustomColor { + public Color32 MainColor { get; } + public Color32 ShadowColor { get; } + public StringNames Name { get; } + public CustomColor(Color32 mainColor, StringNames name) { MainColor = mainColor; @@ -16,8 +20,4 @@ public sealed class CustomColor ShadowColor = shadowColor; Name = name; } - - public Color32 MainColor { get; } - public Color32 ShadowColor { get; } - public StringNames Name { get; } } \ No newline at end of file diff --git a/MiraAPI/Utilities/Colors/RegisterColorsAttribute.cs b/MiraAPI/Utilities/Colors/RegisterPalette.cs similarity index 66% rename from MiraAPI/Utilities/Colors/RegisterColorsAttribute.cs rename to MiraAPI/Utilities/Colors/RegisterPalette.cs index ef8a1cb..d3b0811 100644 --- a/MiraAPI/Utilities/Colors/RegisterColorsAttribute.cs +++ b/MiraAPI/Utilities/Colors/RegisterPalette.cs @@ -3,4 +3,4 @@ namespace MiraAPI.Utilities.Colors; [AttributeUsage(AttributeTargets.Class)] -public class RegisterColorsAttribute : Attribute; \ No newline at end of file +public class RegisterPalette : Attribute; \ No newline at end of file From e4e3a10ed8028d26f4831739ef1ead99d89966d7 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Mon, 26 Aug 2024 10:41:36 -0400 Subject: [PATCH 44/60] . --- MiraAPI/PluginLoading/MiraPluginManager.cs | 2 +- MiraAPI/Utilities/Colors/CustomColor.cs | 27 +++++++++---------- ...te.cs => RegisterCustomColorsAttribute.cs} | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) rename MiraAPI/Utilities/Colors/{RegisterPalette.cs => RegisterCustomColorsAttribute.cs} (63%) diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index bfd9af7..5fcaafd 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -124,7 +124,7 @@ internal class MiraPluginManager { foreach (var type in assembly.GetTypes()) { - if (type.GetCustomAttribute() == null) + if (type.GetCustomAttribute() == null) { continue; } diff --git a/MiraAPI/Utilities/Colors/CustomColor.cs b/MiraAPI/Utilities/Colors/CustomColor.cs index 93ee653..389335b 100644 --- a/MiraAPI/Utilities/Colors/CustomColor.cs +++ b/MiraAPI/Utilities/Colors/CustomColor.cs @@ -1,23 +1,22 @@ -using UnityEngine; +using Reactor.Localization.Utilities; +using UnityEngine; namespace MiraAPI.Utilities.Colors; -public sealed class CustomColor +public sealed class CustomColor(Color32 mainColor, Color32 shadowColor, StringNames name) { - public Color32 MainColor { get; } - public Color32 ShadowColor { get; } - public StringNames Name { get; } - - public CustomColor(Color32 mainColor, StringNames name) + public Color32 MainColor { get; } = mainColor; + public Color32 ShadowColor { get; } = shadowColor; + public StringNames Name { get; } = name; + + public CustomColor(Color32 mainColor, StringNames name) : this(mainColor, mainColor.GetShadowColor(60), name) { - MainColor = mainColor; - ShadowColor = mainColor.GetShadowColor(60); - Name = name; } - public CustomColor(Color32 mainColor, Color32 shadowColor, StringNames name) + public CustomColor(Color32 mainColor, string name) : this(mainColor, mainColor.GetShadowColor(60), name) + { + } + + public CustomColor(Color32 mainColor, Color32 shadowColor, string name) : this(mainColor, shadowColor, CustomStringName.CreateAndRegister(name)) { - MainColor = mainColor; - ShadowColor = shadowColor; - Name = name; } } \ No newline at end of file diff --git a/MiraAPI/Utilities/Colors/RegisterPalette.cs b/MiraAPI/Utilities/Colors/RegisterCustomColorsAttribute.cs similarity index 63% rename from MiraAPI/Utilities/Colors/RegisterPalette.cs rename to MiraAPI/Utilities/Colors/RegisterCustomColorsAttribute.cs index d3b0811..ca2063b 100644 --- a/MiraAPI/Utilities/Colors/RegisterPalette.cs +++ b/MiraAPI/Utilities/Colors/RegisterCustomColorsAttribute.cs @@ -3,4 +3,4 @@ namespace MiraAPI.Utilities.Colors; [AttributeUsage(AttributeTargets.Class)] -public class RegisterPalette : Attribute; \ No newline at end of file +public class RegisterCustomColorsAttribute : Attribute; \ No newline at end of file From af471f02324c83dafb9b5d906e8e6dc75bb6c562 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Mon, 26 Aug 2024 10:45:42 -0400 Subject: [PATCH 45/60] xd --- MiraAPI/Utilities/Extensions.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 7811b75..31e729e 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -23,12 +23,6 @@ public static class Extensions (byte)Mathf.Clamp(color.b - darknessAmount, 0, 255), byte.MaxValue); } - public static void SetOutline(this SpriteRenderer spriteRenderer, bool active, Color color) - { - spriteRenderer.material.SetFloat(ShaderID.Outline, active ? 1f : 0f); - spriteRenderer.material.SetColor(ShaderID.OutlineColor, color); - } - public static string? Truncate(this string? value, int maxLength, string truncationSuffix = "…") { return value?.Length > maxLength From 55b7174be2bf7557956579dc084044013136f114 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:10:39 -0400 Subject: [PATCH 46/60] fix palette manager --- MiraAPI/Patches/Roles/GameStartupPatch.cs | 2 ++ MiraAPI/PluginLoading/MiraPluginManager.cs | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/MiraAPI/Patches/Roles/GameStartupPatch.cs b/MiraAPI/Patches/Roles/GameStartupPatch.cs index 13ea698..e45a4eb 100644 --- a/MiraAPI/Patches/Roles/GameStartupPatch.cs +++ b/MiraAPI/Patches/Roles/GameStartupPatch.cs @@ -1,5 +1,6 @@ using HarmonyLib; using MiraAPI.Roles; +using MiraAPI.Utilities.Colors; namespace MiraAPI.Patches.Roles; @@ -22,5 +23,6 @@ public static class GameStartupPatch _runOnce = true; CustomRoleManager.RegisterInRoleManager(); + PaletteManager.RegisterAllColors(); } } \ No newline at end of file diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index 5fcaafd..01d4e4a 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -45,7 +45,7 @@ internal class MiraPluginManager RegisterRoleAttribute(assembly, info); RegisterButtonAttribute(assembly); - RegisterAllColors(assembly); + RegisterColorClasses(assembly); RegisteredPlugins.Add(assembly, info); @@ -120,7 +120,7 @@ internal class MiraPluginManager } } - private static void RegisterAllColors(Assembly assembly) + private static void RegisterColorClasses(Assembly assembly) { foreach (var type in assembly.GetTypes()) { @@ -152,7 +152,6 @@ internal class MiraPluginManager PaletteManager.CustomColors.Add(color); } } - PaletteManager.RegisterAllColors(); } private static void RegisterButtonAttribute(Assembly assembly) From c77664936f14c49e7373dc95aae142317f6fcce1 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:17:53 -0400 Subject: [PATCH 47/60] add button location property --- MiraAPI.Example/Buttons/ExampleButton.cs | 5 +++-- MiraAPI/Hud/ButtonLocation.cs | 7 +++++++ MiraAPI/Hud/CustomActionButton.cs | 5 +++++ MiraAPI/Patches/HudManagerPatches.cs | 19 +++++++++++++++---- 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 MiraAPI/Hud/ButtonLocation.cs diff --git a/MiraAPI.Example/Buttons/ExampleButton.cs b/MiraAPI.Example/Buttons/ExampleButton.cs index 336896e..3a06661 100644 --- a/MiraAPI.Example/Buttons/ExampleButton.cs +++ b/MiraAPI.Example/Buttons/ExampleButton.cs @@ -12,8 +12,9 @@ public class ExampleButton : CustomActionButton public override float Cooldown => 5f; public override float EffectDuration => 0f; public override int MaxUses => 5; - public override LoadableAsset Sprite { get; } = ExampleAssets.ExampleButton; - + public override LoadableAsset Sprite => ExampleAssets.ExampleButton; + public override ButtonLocation Location => ButtonLocation.BottomRight; + protected override void OnClick() { Logger.Info("Example button clicked!"); diff --git a/MiraAPI/Hud/ButtonLocation.cs b/MiraAPI/Hud/ButtonLocation.cs new file mode 100644 index 0000000..e08c9d2 --- /dev/null +++ b/MiraAPI/Hud/ButtonLocation.cs @@ -0,0 +1,7 @@ +namespace MiraAPI.Hud; + +public enum ButtonLocation +{ + BottomLeft, + BottomRight +} \ No newline at end of file diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index c2bf906..bdb4e5b 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -36,6 +36,11 @@ public abstract class CustomActionButton /// public abstract LoadableAsset Sprite { get; } + /// + /// The location of the button on the screen + /// + public virtual ButtonLocation Location => ButtonLocation.BottomLeft; + /// /// Returns true if the button has an effect ability. /// diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 7631523..b30a0ca 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -1,9 +1,11 @@ -using HarmonyLib; +using System; +using HarmonyLib; using InnerNet; using MiraAPI.Hud; using MiraAPI.Roles; using Reactor.Utilities.Extensions; using UnityEngine; +using Object = UnityEngine.Object; namespace MiraAPI.Patches; @@ -78,10 +80,12 @@ public static class HudManagerPatches [HarmonyPatch(nameof(HudManager.Start))] public static void StartPostfix(HudManager __instance) { + var buttons = __instance.transform.Find("Buttons"); + var bottomRight = buttons.Find("BottomRight"); + if (!_bottomLeft) { - var buttons = __instance.transform.Find("Buttons"); - _bottomLeft = Object.Instantiate(buttons.Find("BottomRight").gameObject, buttons); + _bottomLeft = Object.Instantiate(bottomRight.gameObject, buttons); } foreach (var t in _bottomLeft.GetComponentsInChildren(true)) @@ -98,7 +102,14 @@ public static class HudManagerPatches foreach (var button in CustomButtonManager.CustomButtons) { - button.CreateButton(_bottomLeft.transform); + Transform location = button.Location switch + { + ButtonLocation.BottomLeft => _bottomLeft.transform, + ButtonLocation.BottomRight => bottomRight, + _ => throw new ArgumentOutOfRangeException() + }; + + button.CreateButton(location); } gridArrange.Start(); From f4f2cf9182a82f6f57e73407d193bc66dcbd4458 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:27:00 -0400 Subject: [PATCH 48/60] braces --- MiraAPI/Patches/HudManagerPatches.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index b30a0ca..d1f6549 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -136,7 +136,9 @@ public static class HudManagerPatches } foreach (var button in CustomButtonManager.CustomButtons) + { button.SetActive(isActive, roleBehaviour); + } if (roleBehaviour is ICustomRole role) { From a2b1e9ddbfbdfe8e3e1130008ff5570c8acdae56 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:44:28 -0400 Subject: [PATCH 49/60] increase contrast on AlternateColors --- MiraAPI/Utilities/Extensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 31e729e..47f516d 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -72,7 +72,7 @@ public static class Extensions public static Color DarkenColor(this Color color) { - return new Color(color.r - 0.3f, color.g - 0.3f, color.b - 0.3f); + return new Color(color.r - 0.45f, color.g - 0.45f, color.b - 0.45f); } public static Color GetAlternateColor(this Color color) { @@ -81,7 +81,7 @@ public static class Extensions public static Color LightenColor(this Color color) { - return new Color(color.r + 0.3f, color.g + 0.3f, color.b + 0.3f); + return new Color(color.r + 0.45f, color.g + 0.45f, color.b + 0.45f); } public static bool IsColorDark(this Color color) From d96b146e591c567200e3584a6fa7528a919fd809 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:44:41 -0400 Subject: [PATCH 50/60] set neutral header color for uniformity --- MiraAPI/Patches/Options/RoleSettingMenuPatches.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 6e24a53..b7b46cd 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -107,6 +107,8 @@ public static class RoleSettingMenuPatches Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform); categoryHeaderEditRole3.SetHeader(StringNames.None, 20); categoryHeaderEditRole3.Title.text = "Neutral Roles"; + categoryHeaderEditRole3.Background.color = Color.gray; + categoryHeaderEditRole3.Title.color = Color.white; categoryHeaderEditRole3.transform.localPosition = new Vector3(4.986f, num, -2f); num -= 0.522f; From 5e9c592aabe225dc7d6a8a7ad3235314ad8fd30a Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:44:53 -0400 Subject: [PATCH 51/60] prep for view pane --- MiraAPI/GameOptions/IModdedOption.cs | 1 + MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs | 7 ++++++- MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs | 5 +++++ MiraAPI/GameOptions/OptionTypes/ModdedOption.cs | 2 ++ MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs | 5 +++++ MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs | 5 +++++ 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/MiraAPI/GameOptions/IModdedOption.cs b/MiraAPI/GameOptions/IModdedOption.cs index bd8a6f3..c4b88c1 100644 --- a/MiraAPI/GameOptions/IModdedOption.cs +++ b/MiraAPI/GameOptions/IModdedOption.cs @@ -19,6 +19,7 @@ public interface IModdedOption public ConfigDefinition ConfigDefinition { get; } public void ValueChanged(OptionBehaviour optionBehaviour); public OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container); + public abstract float GetFloatData(); public NetData GetNetData(); public void HandleNetData(byte[] data); } \ No newline at end of file diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs index 30de265..1e43a2b 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs @@ -39,7 +39,12 @@ public class ModdedEnumOption : ModdedOption return stringOption; } - + + public override float GetFloatData() + { + return Value; + } + public override NetData GetNetData() { return new NetData(Id, BitConverter.GetBytes(Value)); diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index 51e350e..b10926c 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -65,6 +65,11 @@ public class ModdedNumberOption : ModdedOption return numberOption; } + public override float GetFloatData() + { + return Value; + } + public override NetData GetNetData() { return new NetData(Id, BitConverter.GetBytes(Value)); diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index e06ca88..33a066c 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -77,6 +77,8 @@ public abstract class ModdedOption : IModdedOption OnValueChanged(newValue); } + public abstract float GetFloatData(); + public abstract NetData GetNetData(); public abstract void HandleNetData(byte[] data); diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs index 484126f..6b878b9 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs @@ -40,6 +40,11 @@ public class ModdedStringOption : ModdedOption return stringOption; } + public override float GetFloatData() + { + return Value; + } + public override NetData GetNetData() { return new NetData(Id, BitConverter.GetBytes(Value)); diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs index 15b920e..f90f83f 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs @@ -32,6 +32,11 @@ public class ModdedToggleOption : ModdedOption return toggleOption; } + public override float GetFloatData() + { + return Value ? 1 : 0; + } + public override NetData GetNetData() { return new NetData(Id, BitConverter.GetBytes(Value)); From 564f524dd6359b52238f0d18862f786fb3e1bad2 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:45:22 -0400 Subject: [PATCH 52/60] lobby view pane almost done --- .../Patches/Options/LobbyViewPanePatches.cs | 275 +++++++++++++++++- 1 file changed, 270 insertions(+), 5 deletions(-) diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index 0f2fc49..f2cf6d5 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -1,14 +1,28 @@ -using HarmonyLib; +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using HarmonyLib; +using MiraAPI.PluginLoading; +using MiraAPI.Roles; +using MiraAPI.Utilities; using MiraAPI.Utilities.Assets; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; +using Object = UnityEngine.Object; namespace MiraAPI.Patches.Options; [HarmonyPatch(typeof(LobbyViewSettingsPane))] public static class LobbyViewPanePatches { + + public static int CurrentSelectedMod { get; private set; } + + public static MiraPluginInfo? SelectedMod => CurrentSelectedMod == 0 ? null : MiraPluginManager.Instance.RegisteredPlugins.ElementAt(CurrentSelectedMod-1).Value; + + [HarmonyPostfix] [HarmonyPatch(nameof(LobbyViewSettingsPane.Awake))] public static void AwakePatch(LobbyViewSettingsPane __instance) @@ -16,7 +30,7 @@ public static class LobbyViewPanePatches __instance.gameModeText.transform.localPosition = new Vector3(-2.3f, 2.4f, -2); // Create the next button - GameObject nextButton = Object.Instantiate(__instance.BackButton, __instance.BackButton.transform.parent).gameObject; + var nextButton = Object.Instantiate(__instance.BackButton, __instance.BackButton.transform.parent).gameObject; nextButton.GetComponent().size = new Vector2(0.2f, 0.3f); nextButton.transform.localPosition = new Vector3(-5.4f, 2.4f, -2f); nextButton.transform.localScale = new Vector3(3, 3, 2); @@ -30,24 +44,275 @@ public static class LobbyViewPanePatches hover.transform.localPosition = new Vector3(0, 0f, 0.3f); hover.sprite = MiraAssets.NextButtonActive.LoadAsset(); - PassiveButton passiveButton = nextButton.gameObject.GetComponent(); + var passiveButton = nextButton.gameObject.GetComponent(); passiveButton.OnClick = new Button.ButtonClickedEvent(); passiveButton.OnClick.AddListener((UnityAction)(() => { + CurrentSelectedMod += 1; + if (CurrentSelectedMod > MiraPluginManager.Instance.RegisteredPlugins.Count) + { + CurrentSelectedMod = 0; + } + __instance.RefreshTab(); })); // Create the back button - 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(-6.3f, 2.4f, -2f); backButton.name = "LeftArrowButton"; backButton.transform.FindChild("Normal").gameObject.GetComponentInChildren().flipX = backButton.transform.FindChild("Hover").gameObject.GetComponentInChildren().flipX = true; - PassiveButton passiveButton2 = backButton.gameObject.GetComponent(); + var passiveButton2 = backButton.gameObject.GetComponent(); passiveButton2.OnClick = new Button.ButtonClickedEvent(); passiveButton2.OnClick.AddListener((UnityAction)(() => { + CurrentSelectedMod -= 1; + if (CurrentSelectedMod < 0) + { + CurrentSelectedMod = MiraPluginManager.Instance.RegisteredPlugins.Count; + } + __instance.RefreshTab(); })); } + + [HarmonyPostfix] + [HarmonyPatch(nameof(LobbyViewSettingsPane.Update))] + public static void UpdatePatch(LobbyViewSettingsPane __instance) + { + __instance.gameModeText.text = SelectedMod?.PluginInfo.Metadata.Name ?? "Default"; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(LobbyViewSettingsPane.DrawNormalTab))] + public static bool DrawNormalTabPatch(LobbyViewSettingsPane __instance) + { + if (CurrentSelectedMod == 0) + { + return true; + } + + DrawOptionsTab(__instance); + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(LobbyViewSettingsPane.DrawRolesTab))] + public static bool DrawRolesTabPatch(LobbyViewSettingsPane __instance) + { + if (CurrentSelectedMod == 0) + { + return true; + } + + DrawRolesTab(__instance); + return false; + } + + private static void DrawOptionsTab(LobbyViewSettingsPane instance) + { + if (SelectedMod == null) + { + return; + } + + var num = 1.44f; + + var filteredGroups = SelectedMod.OptionGroups.Where(x => x.GroupVisible.Invoke() && x.AdvancedRole is null); + + foreach (var group in filteredGroups) + { + if (group.Options.Count == 0) + { + continue; + } + + var categoryHeaderMasked = Object.Instantiate(instance.categoryHeaderOrigin, instance.settingsContainer, true); + categoryHeaderMasked.SetHeader(StringNames.Name, 61); + categoryHeaderMasked.Title.text = group.GroupName; + categoryHeaderMasked.transform.localScale = Vector3.one; + categoryHeaderMasked.transform.localPosition = new Vector3(-9.77f, num, -2f); + instance.settingsInfo.Add(categoryHeaderMasked.gameObject); + num -= 0.85f; + + var i = 0; + + foreach (var option in group.Options) + { + if (!option.Visible.Invoke()) + { + continue; + } + + var viewSettingsInfoPanel = Object.Instantiate(instance.infoPanelOrigin, instance.settingsContainer, true); + viewSettingsInfoPanel.transform.localScale = Vector3.one; + float num2; + if (i % 2 == 0) + { + num2 = -8.95f; + if (i > 0) + { + num -= 0.59f; + } + } + else + { + num2 = -3f; + } + viewSettingsInfoPanel.transform.localPosition = new Vector3(num2, num, -2f); + + var data = option.Data; + + if (data.Type == OptionTypes.Checkbox) + { + viewSettingsInfoPanel.SetInfoCheckbox(data.Title, 61, Mathf.Approximately(option.GetFloatData(), 1)); + } + else + { + viewSettingsInfoPanel.SetInfo(data.Title, data.GetValueString(option.GetFloatData()), 61); + } + + instance.settingsInfo.Add(viewSettingsInfoPanel.gameObject); + i++; + } + + num -= 0.59f; + } + instance.scrollBar.CalculateAndSetYBounds(instance.settingsInfo.Count + 10, 2f, 6f, 0.59f); + } + + private static void DrawRolesTab(LobbyViewSettingsPane instance) + { + if (SelectedMod == null) + { + return; + } + + var num = 0.95f; + var num2 = -6.53f; + var categoryHeaderMasked = + Object.Instantiate(instance.categoryHeaderOrigin, instance.settingsContainer, true); + categoryHeaderMasked.SetHeader(StringNames.RoleQuotaLabel, 61); + categoryHeaderMasked.transform.localScale = Vector3.one; + categoryHeaderMasked.transform.localPosition = new Vector3(-9.77f, 1.26f, -2f); + instance.settingsInfo.Add(categoryHeaderMasked.gameObject); + + var list = new List(); + + foreach (var team in Enum.GetValues()) + { + var categoryHeaderRoleVariant = + Object.Instantiate(instance.categoryHeaderRoleOrigin, instance.settingsContainer, true); + + switch (team) + { + case ModdedRoleTeams.Crewmate: + categoryHeaderRoleVariant.SetHeader(StringNames.CrewmateRolesHeader, 61); + break; + case ModdedRoleTeams.Impostor: + categoryHeaderRoleVariant.SetHeader(StringNames.ImpostorRolesHeader, 61); + break; + case ModdedRoleTeams.Neutral: + default: + categoryHeaderRoleVariant.SetHeader(StringNames.CrewmateRolesHeader, 61); + categoryHeaderRoleVariant.Title.text = team + " Roles"; + categoryHeaderRoleVariant.Background.color = Color.gray; + categoryHeaderRoleVariant.Title.color = Color.white; + break; + } + + categoryHeaderRoleVariant.transform.localScale = Vector3.one; + categoryHeaderRoleVariant.transform.localPosition = new Vector3(0.09f, num, -2f); + instance.settingsInfo.Add(categoryHeaderRoleVariant.gameObject); + num -= 0.696f; + + var filteredRoles = SelectedMod.CustomRoles.Values + .OfType() + .Where(x => !x.HideSettings && x.Team == team); + + foreach (var role in filteredRoles) + { + var roleBehaviour = role as RoleBehaviour; + if (roleBehaviour == null) + { + continue; + } + + var chancePerGame = + GameOptionsManager.Instance.CurrentGameOptions.RoleOptions.GetChancePerGame(roleBehaviour.Role); + var numPerGame = + GameOptionsManager.Instance.CurrentGameOptions.RoleOptions.GetNumPerGame(roleBehaviour.Role); + + var flag = numPerGame == 0; + + var viewSettingsInfoPanelRoleVariant = + Object.Instantiate( + instance.infoPanelRoleOrigin, instance.settingsContainer, true); + viewSettingsInfoPanelRoleVariant.transform.localScale = Vector3.one; + viewSettingsInfoPanelRoleVariant.transform.localPosition = new Vector3(num2, num, -2f); + + if (!flag) + { + //list.Add(role.GetType()); + } + + viewSettingsInfoPanelRoleVariant.SetInfo(roleBehaviour.NiceName, numPerGame, chancePerGame, + 61, role.RoleColor, role.Icon.LoadAsset(), true); + + viewSettingsInfoPanelRoleVariant.titleText.color = + viewSettingsInfoPanelRoleVariant.chanceTitle.color = + viewSettingsInfoPanelRoleVariant.chanceBackground.color = + viewSettingsInfoPanelRoleVariant.background.color = + role.RoleColor.GetAlternateColor(); + instance.settingsInfo.Add(viewSettingsInfoPanelRoleVariant.gameObject); + num -= 0.664f; + } + + + } + + if (list.Count > 0) + { + var categoryHeaderMasked2 = + Object.Instantiate(instance.categoryHeaderOrigin, instance.settingsContainer, true); + categoryHeaderMasked2.SetHeader(StringNames.RoleSettingsLabel, 61); + categoryHeaderMasked2.transform.localScale = Vector3.one; + categoryHeaderMasked2.transform.localPosition = new Vector3(-9.77f, num, -2f); + instance.settingsInfo.Add(categoryHeaderMasked2.gameObject); + num -= 1.7f; + var num3 = 0f; + for (var k = 0; k < list.Count; k++) + { + float num4; + if (k % 2 == 0) + { + num4 = -5.8f; + if (k > 0) + { + num -= num3 + 0.59f; + num3 = 0f; + } + } + else + { + num4 = 0.14999962f; + } + + var advancedRoleViewPanel = + Object.Instantiate(instance.advancedRolePanelOrigin, instance.settingsContainer, true); + advancedRoleViewPanel.transform.localScale = Vector3.one; + advancedRoleViewPanel.transform.localPosition = new Vector3(num4, num, -2f); + var num5 = advancedRoleViewPanel.SetUp(list[k], 0.59f, 61); + if (num5 > num3) + { + num3 = num5; + } + + instance.settingsInfo.Add(advancedRoleViewPanel.gameObject); + } + } + + instance.scrollBar.SetYBoundsMax(-num); + } } \ No newline at end of file From cd1529b4bf1e997ca2cf69c3c8d10e6cd913f645 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:51:00 -0400 Subject: [PATCH 53/60] QOL in view tab --- MiraAPI/Patches/Options/LobbyViewPanePatches.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index f2cf6d5..44b02bb 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -54,6 +54,7 @@ public static class LobbyViewPanePatches CurrentSelectedMod = 0; } __instance.RefreshTab(); + __instance.scrollBar.ScrollToTop(); })); // Create the back button @@ -74,6 +75,7 @@ public static class LobbyViewPanePatches CurrentSelectedMod = MiraPluginManager.Instance.RegisteredPlugins.Count; } __instance.RefreshTab(); + __instance.scrollBar.ScrollToTop(); })); } @@ -202,6 +204,15 @@ public static class LobbyViewPanePatches foreach (var team in Enum.GetValues()) { + var filteredRoles = SelectedMod.CustomRoles.Values + .OfType() + .Where(x => !x.HideSettings && x.Team == team).ToList(); + + if (filteredRoles.Count == 0) + { + continue; + } + var categoryHeaderRoleVariant = Object.Instantiate(instance.categoryHeaderRoleOrigin, instance.settingsContainer, true); @@ -227,10 +238,6 @@ public static class LobbyViewPanePatches instance.settingsInfo.Add(categoryHeaderRoleVariant.gameObject); num -= 0.696f; - var filteredRoles = SelectedMod.CustomRoles.Values - .OfType() - .Where(x => !x.HideSettings && x.Team == team); - foreach (var role in filteredRoles) { var roleBehaviour = role as RoleBehaviour; From 4cd8aa0bd7f0effa7846031b33cc158247f10b6b Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:18:38 -0400 Subject: [PATCH 54/60] advanced role settings in view tab --- .../Patches/Options/LobbyViewPanePatches.cs | 74 +++++++++++++++++-- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index 44b02bb..187265c 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -200,7 +200,7 @@ public static class LobbyViewPanePatches categoryHeaderMasked.transform.localPosition = new Vector3(-9.77f, 1.26f, -2f); instance.settingsInfo.Add(categoryHeaderMasked.gameObject); - var list = new List(); + var list = new List(); foreach (var team in Enum.GetValues()) { @@ -238,9 +238,9 @@ public static class LobbyViewPanePatches instance.settingsInfo.Add(categoryHeaderRoleVariant.gameObject); num -= 0.696f; - foreach (var role in filteredRoles) + foreach (var customRole in filteredRoles) { - var roleBehaviour = role as RoleBehaviour; + var roleBehaviour = customRole as RoleBehaviour; if (roleBehaviour == null) { continue; @@ -259,19 +259,23 @@ public static class LobbyViewPanePatches viewSettingsInfoPanelRoleVariant.transform.localScale = Vector3.one; viewSettingsInfoPanelRoleVariant.transform.localPosition = new Vector3(num2, num, -2f); - if (!flag) + var advancedRoleOptions = SelectedMod.Options + .Where(x => x.AdvancedRole == customRole.GetType()) + .ToList(); + + if (!flag && advancedRoleOptions.Count > 0) { - //list.Add(role.GetType()); + list.Add(customRole.GetType()); } viewSettingsInfoPanelRoleVariant.SetInfo(roleBehaviour.NiceName, numPerGame, chancePerGame, - 61, role.RoleColor, role.Icon.LoadAsset(), true); + 61, customRole.RoleColor, customRole.Icon.LoadAsset(), true); viewSettingsInfoPanelRoleVariant.titleText.color = viewSettingsInfoPanelRoleVariant.chanceTitle.color = viewSettingsInfoPanelRoleVariant.chanceBackground.color = viewSettingsInfoPanelRoleVariant.background.color = - role.RoleColor.GetAlternateColor(); + customRole.RoleColor.GetAlternateColor(); instance.settingsInfo.Add(viewSettingsInfoPanelRoleVariant.gameObject); num -= 0.664f; } @@ -310,7 +314,8 @@ public static class LobbyViewPanePatches Object.Instantiate(instance.advancedRolePanelOrigin, instance.settingsContainer, true); advancedRoleViewPanel.transform.localScale = Vector3.one; advancedRoleViewPanel.transform.localPosition = new Vector3(num4, num, -2f); - var num5 = advancedRoleViewPanel.SetUp(list[k], 0.59f, 61); + var num5 = SetUpAdvancedRoleViewPanel(advancedRoleViewPanel, list[k], 0.59f, 61); + if (num5 > num3) { num3 = num5; @@ -322,4 +327,57 @@ public static class LobbyViewPanePatches instance.scrollBar.SetYBoundsMax(-num); } + + private static float SetUpAdvancedRoleViewPanel(AdvancedRoleViewPanel viewPanel, Type roleType, float spacingY, int maskLayer) + { + if (SelectedMod == null) + { + return 0; + } + + var role = SelectedMod.CustomRoles.Values.FirstOrDefault(x => x.GetType() == roleType); + + if (role == null) + { + return 0; + } + + var customRole = role as ICustomRole; + + viewPanel.header.SetHeader(role.StringName, maskLayer, role.TeamType == RoleTeamTypes.Crewmate, customRole.Icon.LoadAsset()); + viewPanel.divider.material.SetInt(PlayerMaterial.MaskLayer, maskLayer); + + var num = viewPanel.yPosStart; + var num2 = 1.08f; + + var filteredOptions = SelectedMod.Options + .Where(x => x.AdvancedRole == roleType) + .ToList(); + + for (var i = 0; i < filteredOptions.Count; i++) + { + var option = filteredOptions[i]; + BaseGameSetting 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); + + var value = option.GetFloatData(); + + if (baseGameSetting.Type == OptionTypes.Checkbox) + { + viewSettingsInfoPanel.SetInfoCheckbox(baseGameSetting.Title, maskLayer, value > 0f); + } + else + { + viewSettingsInfoPanel.SetInfo(baseGameSetting.Title, baseGameSetting.GetValueString(value), maskLayer); + } + num -= spacingY; + if (i > 0) + { + num2 += 0.8f; + } + } + return num2; + } } \ No newline at end of file From f39580e8588578ddf3f97816e0abee82055393d4 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:26:32 -0400 Subject: [PATCH 55/60] fixes --- MiraAPI/Patches/Options/LobbyViewPanePatches.cs | 5 ++++- MiraAPI/PluginLoading/MiraPluginManager.cs | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index 187265c..74c0fd0 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -342,7 +342,10 @@ public static class LobbyViewPanePatches return 0; } - var customRole = role as ICustomRole; + if (role is not ICustomRole customRole) + { + return 0; + } viewPanel.header.SetHeader(role.StringName, maskLayer, role.TeamType == RoleTeamTypes.Crewmate, customRole.Icon.LoadAsset()); viewPanel.divider.material.SetInt(PlayerMaterial.MaskLayer, maskLayer); diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index c65a7c9..8a48e38 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -1,5 +1,4 @@ -using BepInEx; -using BepInEx.Unity.IL2CPP; +using BepInEx.Unity.IL2CPP; using Il2CppInterop.Runtime.Injection; using MiraAPI.GameOptions; using MiraAPI.GameOptions.Attributes; @@ -12,7 +11,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using MiraAPI.Utilities; -using MiraAPI.Hud; using Reactor.Networking; namespace MiraAPI.PluginLoading; From 37aee8712ec52dc77c3e786ccded50bf7543fcc8 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:54:40 -0400 Subject: [PATCH 56/60] readme update --- README.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 504c2cb..e7ce157 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,16 @@ A thorough, but simple, Among Us modding API and utility library that covers: - Roles - Options -- Modifiers -- Game Modes +- Buttons - Assets -- HUD Elements - Compatibility +- ~~Modifiers~~ (coming soon) +- ~~Game Modes~~ (coming soon) Mira API strives to be simple and easy to use, while also using as many base game elements as possible. The result is a less intrusive, better modding API that covers general use cases. +**Join the [Discord](https://discord.gg/all-of-us-launchpad-794950428756410429) for support and to stay updated on the latest releases** + # Usage To start using Mira API, you need to: @@ -22,16 +24,46 @@ To start using Mira API, you need to: For a full example, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExamplePlugin.cs). +## Recommended Project Structure +It is highly recommended to follow this project structure when using Mira API in order to keep your code clean and organized. You can also view the Example Mod in this repository for some guidance. +``` +MyMiraMod/ +├── Buttons/ +│ └── MyCoolButton.cs +├── Options/ +│ ├── Roles/ +│ │ └── CoolCustomRoleOptions.cs +│ └── MainOptionGroup.cs +├── Patches/ +│ ├── Roles/ +│ │ └── CoolCustomRole/ +│ │ ├── PlayerControlPatches.cs +│ │ └── ExileControllerPatches.cs +│ └── General/ +│ └── HudManagerPatches.cs +├── Resources/ +│ ├── CoolButton.png +│ └── myAssets-win-x86.bundle +├── Roles/ +│ └── CoolCustomRole.cs +├── MyMiraModPlugin.cs +└── MyModAssets.cs +``` + ## Roles Roles are very simple in Mira API. There are 3 things you need to do to create a custom role: -1. Create a class that inherits from a base game role (like `RoleBehaviour`, `CrewmateRole`, `ImpostorRole`, etc). +1. Create a class that inherits from a base game role (like `CrewmateRole`, `ImpostorRole`, etc) 2. Implement the `ICustomRole` interface from Mira API. 3. Add the `[RegisterCustomRole]` attribute to the class. +Note: For step 1, if you are making neutral roles, choose either `CrewmateRole` or `ImpostorRole` as the base depending on if it can kill or not! + +Mira API handles everything else, from adding the proper options to the settings menu, to managing the role assignment at the start of the game. There are no extra steps on the developer's part. + See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Roles/CustomRole.cs) for a code example. ## Options -Options are also very simple in Mira API. Options are split up into Groups and Options. Every Option needs to be in a Group. +Options are also very simple in Mira API. Mira API handles all the hard work behind the scenes, so developers only have to follow a few steps to create their custom options. The Options API is split up into Groups and Options. Every Option needs to be in a Group. To create a group, you need to create a class that inherits from the `AbstractOptionGroup` abstract class. Groups contain 4 properties, `GroupName`, `GroupColor`, `GroupVisible`, and `AdvancedRole`. Only the `GroupName` is required. @@ -57,6 +89,8 @@ Once you have an options group, there are two ways to make the actual options: - Use an Option Attribute with a property. - Create a ModdedOption property. +### Option Attributes + This is an example of using an Option Attribute on a property: ```csharp // The first parameter is always the name of the option. The rest are dependent on the type of option. @@ -64,6 +98,26 @@ This is an example of using an Option Attribute on a property: public float SussyLevel { get; set; } = 4f; // You can set a default value here. ``` +Here are the available Option Attributes and their signatures: +```csharp +ModdedEnumOption(string name, Type enumType, Type roleType = null) + +ModdedNumberOption( + string name, + float min, + float max, + float increment=1 + NumberSuffixes suffixType = NumberSuffixes.None, + bool zeroInfinity = false, + Type roleType = null) + +ModdedStringOption(string title, string[] values, Type roleType = null) + +ModdedToggleOption(string name, Type roleType = null) +``` + +### ModdedOption Properties + And this is an example of a ModdedOption property: ```csharp public ModdedToggleOption YeezusAbility { get; } = new ModdedToggleOption("Yeezus Ability", false); @@ -114,6 +168,8 @@ Mira API provides a simple interface for adding ability buttons to the game. The 1. Create a class that inherits from the `CustomActionButton` class and implement the properties and methods. 2. Add the `[RegisterCustomButton]` attribute to the class. +All other tasks and logic required to add the button to the game are handled by Mira API. + The button API is simple, but provides a lot of flexibility. There are various methods you can override to customize the behaviour of your button. See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI/Hud/CustomActionButton.cs) for a full list of methods you can override. An example button can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Buttons/ExampleButton.cs). From 8a8fb7ced49b965d1ab1d9f88ae5ff63bac7691f Mon Sep 17 00:00:00 2001 From: ang-xd Date: Tue, 27 Aug 2024 13:57:38 -0400 Subject: [PATCH 57/60] Collapsible options, and fixes --- .../Buttons/ExampleTargetButton.cs | 2 +- MiraAPI.Example/ExamplePlugin.cs | 3 +- MiraAPI.Example/Options/ExampleOptions.cs | 30 ++--- MiraAPI.Example/Options/ExampleOptions2.cs | 32 ++--- .../Options/Roles/CustomRole2Settings.cs | 6 +- .../Options/Roles/CustomRoleSettings.cs | 8 +- MiraAPI.Example/Roles/CustomRole.cs | 6 +- MiraAPI.Example/Roles/CustomRole2.cs | 6 +- MiraAPI.Example/Roles/CustomRole3.cs | 17 --- MiraAPI/GameOptions/AbstractOptionGroup.cs | 11 +- .../GameOptions/OptionTypes/ModdedOption.cs | 18 +-- MiraAPI/MiraAPI.csproj | 7 ++ MiraAPI/MiraApiPlugin.cs | 6 +- .../Patches/Options/GameOptionsMenuPatch.cs | 114 +++++++++++++++--- .../Patches/Options/GameSettingMenuPatches.cs | 47 ++++++-- MiraAPI/PluginLoading/IMiraPlugin.cs | 1 + MiraAPI/Resources/CheckMarkBox.png | Bin 0 -> 347 bytes MiraAPI/Resources/Checkmark.png | Bin 0 -> 370 bytes MiraAPI/Utilities/Assets/MiraAssets.cs | 2 + 19 files changed, 209 insertions(+), 107 deletions(-) delete mode 100644 MiraAPI.Example/Roles/CustomRole3.cs create mode 100644 MiraAPI/Resources/CheckMarkBox.png create mode 100644 MiraAPI/Resources/Checkmark.png diff --git a/MiraAPI.Example/Buttons/ExampleTargetButton.cs b/MiraAPI.Example/Buttons/ExampleTargetButton.cs index 3fcdb33..aa36854 100644 --- a/MiraAPI.Example/Buttons/ExampleTargetButton.cs +++ b/MiraAPI.Example/Buttons/ExampleTargetButton.cs @@ -11,7 +11,7 @@ public class ExampleTargetButton : CustomActionButton public override float EffectDuration => 0f; public override int MaxUses => 0; public override LoadableAsset Sprite => ExampleAssets.ExampleButton; - + protected override void OnClick() { PlayerControl.LocalPlayer.CmdCheckMurder(Target); diff --git a/MiraAPI.Example/ExamplePlugin.cs b/MiraAPI.Example/ExamplePlugin.cs index 1f3ac7b..881242c 100644 --- a/MiraAPI.Example/ExamplePlugin.cs +++ b/MiraAPI.Example/ExamplePlugin.cs @@ -9,7 +9,7 @@ using Reactor.Networking.Attributes; namespace MiraAPI.Example; -[BepInAutoPlugin("mira.example", "MiraAPIExample")] +[BepInAutoPlugin("mira.example", "MiraExampleMod")] [BepInProcess("Among Us.exe")] [BepInDependency(ReactorPlugin.Id)] [BepInDependency(MiraApiPlugin.Id)] @@ -17,6 +17,7 @@ namespace MiraAPI.Example; public partial class ExamplePlugin : BasePlugin, IMiraPlugin { public Harmony Harmony { get; } = new(Id); + public string OptionsTitleText => "Mira API\nExample Mod"; public ConfigFile GetConfigFile() => Config; public override void Load() { diff --git a/MiraAPI.Example/Options/ExampleOptions.cs b/MiraAPI.Example/Options/ExampleOptions.cs index 09f615f..e124d91 100644 --- a/MiraAPI.Example/Options/ExampleOptions.cs +++ b/MiraAPI.Example/Options/ExampleOptions.cs @@ -6,28 +6,28 @@ namespace MiraAPI.Example.Options; public class ExampleOptions : AbstractOptionGroup { - public override string GroupName => "General Group"; - public override Color GroupColor => Color.red; + public override string GroupName => "Example Options 1"; + public override Color GroupColor => Color.green; - [ModdedToggleOption("Use Thing")] - public bool UseThing { get; set; } = false; + [ModdedToggleOption("Toggle Opt 1")] + public bool ToggleOpt { get; set; } = false; - [ModdedToggleOption("Use another thing")] - public bool UseAnotherThing { get; set; } = true; + [ModdedToggleOption("Toggle Opt 2")] + public bool ToggleOpt2 { get; set; } = true; - [ModdedNumberOption("Sussy level", min: 0, max: 10)] - public float SussyLevel { get; set; } = 4f; + [ModdedNumberOption("Number Opt", min: 0, max: 10)] + public float NumberOpt { get; set; } = 4f; - [ModdedStringOption("Sus choices", ["hello", "hello 2", "hello 3"])] - public int SusChoices { get; set; } = 2; + [ModdedStringOption("String Opt", ["Hello", "Hey", "Bye"])] + public int StringOpt { get; set; } = 2; - [ModdedEnumOption("Enum test", typeof(TestEnum))] - public TestEnum EnumTest { get; set; } = TestEnum.Bye; + [ModdedEnumOption("Enum Opt", typeof(TestEnum))] + public TestEnum EnumOpt { get; set; } = TestEnum.Mira; } public enum TestEnum { - Hello, - Hi, - Bye + Welcome, + To, + Mira } \ No newline at end of file diff --git a/MiraAPI.Example/Options/ExampleOptions2.cs b/MiraAPI.Example/Options/ExampleOptions2.cs index b17ff20..594bb36 100644 --- a/MiraAPI.Example/Options/ExampleOptions2.cs +++ b/MiraAPI.Example/Options/ExampleOptions2.cs @@ -5,23 +5,23 @@ namespace MiraAPI.Example.Options; public class ExampleOptions2 : AbstractOptionGroup { - public override string GroupName => "Example 2"; - - public ModdedToggleOption UseThing { get; } = new("Use Thingy 5", false); - - public ModdedToggleOption UseThing2 { get; } = new("Use Thingy 6", false); - - public ModdedStringOption Sussy { get; } = new("Sussy", 0, ["Sussy 1", "Sussy 2", "Sussy 3"]); - - public ModdedEnumOption SussyEnum { get; } = new("Sussy Enum", 0, typeof(SussyEnum)); - - public ModdedNumberOption YeezyLevel { get; } = new("Yeezy Level", 50, 0, 100, 25, NumberSuffixes.Multiplier); + public override string GroupName => "Example Options 2"; + + public ModdedToggleOption ToggleOpt1 { get; } = new("Toggle Option 1", false); + + public ModdedToggleOption ToggleOpt2 { get; } = new("Toggle Option 2", false) + { + Visible = () => OptionGroupSingleton.Instance.ToggleOpt1.Value + }; + + public ModdedStringOption StringOpt { get; } = new("String Opt", 0, ["Choice 1", "Choice 2", "Choice 3"]); + + public ModdedEnumOption EnumOpt { get; } = new("Enum Opt", 0, typeof(TestingEnum)); } -public enum SussyEnum +public enum TestingEnum { - Sussy, - Baka, - Imposter, - Kanye + Happy, + Sad, + Neutral } \ No newline at end of file diff --git a/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs b/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs index b925dcf..9745035 100644 --- a/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs +++ b/MiraAPI.Example/Options/Roles/CustomRole2Settings.cs @@ -1,7 +1,7 @@ -using System; -using MiraAPI.Example.Roles; +using MiraAPI.Example.Roles; using MiraAPI.GameOptions; using MiraAPI.GameOptions.Attributes; +using System; namespace MiraAPI.Example.Options.Roles; @@ -10,7 +10,7 @@ public class CustomRole2Settings : AbstractOptionGroup public override string GroupName => "Custom Role"; public override Type AdvancedRole => typeof(CustomRole2); - + [ModdedToggleOption("Teleportation ability")] public bool Teleport { get; set; } = true; } \ No newline at end of file diff --git a/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs b/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs index 26503c0..e2ca4a6 100644 --- a/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs +++ b/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs @@ -1,7 +1,7 @@ -using System; -using MiraAPI.Example.Roles; +using MiraAPI.Example.Roles; using MiraAPI.GameOptions; using MiraAPI.GameOptions.Attributes; +using System; namespace MiraAPI.Example.Options.Roles; @@ -10,7 +10,7 @@ public class CustomRoleSettings : AbstractOptionGroup public override string GroupName => "Custom Role"; public override Type AdvancedRole => typeof(CustomRole); - - [ModdedNumberOption("Testing level", min: 3, max: 9)] public float TestingLevel { get; set; } = 4; + + [ModdedNumberOption("Number Opt", min: 3, max: 9)] public float NumberOpt { get; set; } = 4; } \ No newline at end of file diff --git a/MiraAPI.Example/Roles/CustomRole.cs b/MiraAPI.Example/Roles/CustomRole.cs index bf656c8..7a04283 100644 --- a/MiraAPI.Example/Roles/CustomRole.cs +++ b/MiraAPI.Example/Roles/CustomRole.cs @@ -7,11 +7,11 @@ namespace MiraAPI.Example.Roles; [RegisterCustomRole] public class CustomRole : ImpostorRole, ICustomRole { - public string RoleName => "fortnite killer"; - public string RoleLongDescription => "ok so your objective is to eliminate everyone with your fortnite tactical shotgun, good luck"; + public string RoleName => "Custom Role"; + public string RoleLongDescription => "Eliminate everyone with your special ability!"; public string RoleDescription => RoleLongDescription; public Color RoleColor => Palette.Black; public ModdedRoleTeams Team => ModdedRoleTeams.Impostor; public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; - + } \ No newline at end of file diff --git a/MiraAPI.Example/Roles/CustomRole2.cs b/MiraAPI.Example/Roles/CustomRole2.cs index 019c891..ce0650d 100644 --- a/MiraAPI.Example/Roles/CustomRole2.cs +++ b/MiraAPI.Example/Roles/CustomRole2.cs @@ -7,11 +7,11 @@ namespace MiraAPI.Example.Roles; [RegisterCustomRole] public class CustomRole2 : CrewmateRole, ICustomRole { - public string RoleName => "fortnite defender"; - public string RoleLongDescription => "ok so your objective is to save everyone from the fortnite killer"; + public string RoleName => "Custom Role 2"; + public string RoleLongDescription => "Save everyone from dying!"; public string RoleDescription => RoleLongDescription; public Color RoleColor => Palette.AcceptedGreen; public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; - + } \ No newline at end of file diff --git a/MiraAPI.Example/Roles/CustomRole3.cs b/MiraAPI.Example/Roles/CustomRole3.cs deleted file mode 100644 index 111aa83..0000000 --- a/MiraAPI.Example/Roles/CustomRole3.cs +++ /dev/null @@ -1,17 +0,0 @@ -using MiraAPI.Roles; -using MiraAPI.Utilities.Assets; -using UnityEngine; - -namespace MiraAPI.Example.Roles; - -[RegisterCustomRole] -public class CustomRole3 : CrewmateRole, ICustomRole -{ - public string RoleName => "fortnite helper"; - public string RoleLongDescription => "ok so your objective is to help"; - public string RoleDescription => RoleLongDescription; - public Color RoleColor => Palette.Brown; - public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; - public LoadableAsset OptionsScreenshot => ExampleAssets.Banner; - -} \ No newline at end of file diff --git a/MiraAPI/GameOptions/AbstractOptionGroup.cs b/MiraAPI/GameOptions/AbstractOptionGroup.cs index 564bfa1..df924ab 100644 --- a/MiraAPI/GameOptions/AbstractOptionGroup.cs +++ b/MiraAPI/GameOptions/AbstractOptionGroup.cs @@ -7,24 +7,27 @@ namespace MiraAPI.GameOptions; public abstract class AbstractOptionGroup { public List Options { get; } = []; - + /// /// The name of the group. Visible in options menu. /// public abstract string GroupName { get; } - + /// /// A function that returns whether the group should be visible or not. /// public virtual Func GroupVisible => () => true; - + /// /// The group color. This is used to color the group in the options menu. /// public virtual Color GroupColor => Color.clear; - + /// /// The role the group is associated with. This is used for the advanced role options menu. /// public virtual Type AdvancedRole => null; + + internal bool AllOptionsHidden = true; + internal CategoryHeaderMasked Header; } \ No newline at end of file diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index e06ca88..d7be9b5 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -1,10 +1,10 @@ -using MiraAPI.PluginLoading; +using BepInEx.Configuration; +using MiraAPI.Networking; +using MiraAPI.PluginLoading; using MiraAPI.Roles; using Reactor.Localization.Utilities; -using System; -using BepInEx.Configuration; -using MiraAPI.Networking; using Reactor.Networking.Rpc; +using System; using UnityEngine; namespace MiraAPI.GameOptions.OptionTypes; @@ -12,7 +12,7 @@ namespace MiraAPI.GameOptions.OptionTypes; public abstract class ModdedOption : IModdedOption { private IMiraPlugin _parentMod; - + public uint Id { get; } public BaseGameSetting Data { get; protected init; } public IMiraPlugin ParentMod @@ -33,7 +33,7 @@ public abstract class ModdedOption : IModdedOption public Func Visible { get; set; } public Type AdvancedRole { get; set; } public OptionBehaviour OptionBehaviour { get; set; } - public ConfigDefinition ConfigDefinition => new ("Options", Title); + public ConfigDefinition ConfigDefinition => new("Options", Title); protected ModdedOption(string title, T defaultValue, Type roleType) { @@ -68,17 +68,17 @@ public abstract class ModdedOption : IModdedOption { Rpc.Instance.Send(PlayerControl.LocalPlayer, [GetNetData()], true); } - + if (ParentMod?.GetConfigFile().TryGetEntry(ConfigDefinition, out var entry) == true) { entry.Value = Value; } - + OnValueChanged(newValue); } public abstract NetData GetNetData(); - + public abstract void HandleNetData(byte[] data); public abstract void OnValueChanged(T newValue); diff --git a/MiraAPI/MiraAPI.csproj b/MiraAPI/MiraAPI.csproj index b2e8122..fe4ce8b 100644 --- a/MiraAPI/MiraAPI.csproj +++ b/MiraAPI/MiraAPI.csproj @@ -9,8 +9,15 @@ Simple and easy to use Among Us modding API. Angxl, XtraCube + + + + + + + diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index 6dadbcd..e64399c 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -2,8 +2,8 @@ using BepInEx.Unity.IL2CPP; using HarmonyLib; using MiraAPI.PluginLoading; -using Reactor; using MiraAPI.Utilities; +using Reactor; using Reactor.Networking; using Reactor.Networking.Attributes; using Reactor.Utilities; @@ -19,13 +19,13 @@ public partial class MiraApiPlugin : BasePlugin { public Harmony Harmony { get; } = new(Id); private static MiraPluginManager PluginManager { get; set; } - + public static Color MiraColor = new Color32(238, 154, 112, 255); public override void Load() { Harmony.PatchAll(); - + ReactorCredits.Register("Mira API", Version.Truncate(15, "") ?? Version, true, ReactorCredits.AlwaysShow); PluginManager = new MiraPluginManager(); diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index d446f8e..7f30b85 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -1,11 +1,14 @@ using HarmonyLib; -using Il2CppSystem.Collections.Generic; using MiraAPI.GameOptions; using MiraAPI.Utilities; +using MiraAPI.Utilities.Assets; using Reactor.Localization.Utilities; +using Reactor.Utilities.Extensions; +using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; +using UnityEngine.Events; namespace MiraAPI.Patches.Options; @@ -13,6 +16,59 @@ namespace MiraAPI.Patches.Options; [HarmonyPatch(typeof(GameOptionsMenu))] public static class GameOptionsMenuPatch { + [HarmonyPostfix] + [HarmonyPatch(nameof(GameOptionsMenu.Update))] + public static void UpdatePatch(GameOptionsMenu __instance) + { + if (GameSettingMenuPatches.CurrentSelectedMod == 0) + { + return; + } + + float num = 2.1f; + var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.GroupVisible.Invoke() && x.AdvancedRole is null); + + foreach (AbstractOptionGroup group in filteredGroups) + { + var filteredOpts = group.Options.Where(x => x.Visible.Invoke()).ToList(); + if (filteredOpts.Count == 0) + { + continue; + } + + group.Header.gameObject.SetActive(true); + group.Header.transform.localScale = Vector3.one * 0.63f; + group.Header.transform.localPosition = new Vector3(-0.903f, num, -2f); + + num -= 0.58f; + + foreach (var opt in group.Options) + { + OptionBehaviour newOpt = opt.OptionBehaviour; + + if (opt.Visible.Invoke() == false) + { + newOpt.gameObject.SetActive(false); + continue; + } + + if (!group.AllOptionsHidden) + { + newOpt.gameObject.SetActive(true); + newOpt.transform.localPosition = new Vector3(0.952f, num, -2f); + num -= 0.45f; + } + else + { + newOpt.gameObject.SetActive(false); + } + } + } + + __instance.scrollBar.SetYBoundsMax(-num - 1.65f); + + } + [HarmonyPrefix] [HarmonyPatch(nameof(GameOptionsMenu.CreateSettings))] public static bool SettingsPatch(GameOptionsMenu __instance) @@ -24,33 +80,31 @@ public static class GameOptionsMenuPatch __instance.MapPicker.gameObject.SetActive(false); - float num = 2.1f; - - var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.GroupVisible.Invoke() && x.AdvancedRole is null); + var filteredGroups = GameSettingMenuPatches.SelectedMod.OptionGroups.Where(x => x.AdvancedRole is null); foreach (AbstractOptionGroup group in filteredGroups) { - var filteredOpts = group.Options.Where(x => x.Visible.Invoke()).ToList(); - if (filteredOpts.Count == 0) - { - continue; - } - CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer); categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20); if (group.GroupColor != Color.clear) { categoryHeaderMasked.Background.color = group.GroupColor; + categoryHeaderMasked.Divider.color = group.GroupColor; categoryHeaderMasked.Title.color = group.GroupColor.GetAlternateColor(); } - categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f; - categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f); - num -= 0.63f; + categoryHeaderMasked.Background.size = new Vector2(categoryHeaderMasked.Background.size.x + 1.5f, categoryHeaderMasked.Background.size.y); + categoryHeaderMasked.gameObject.SetActive(false); + group.Header = categoryHeaderMasked; - foreach (var opt in filteredOpts) + TextMeshPro newText = GameObject.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform); + newText.text = $"(Click to open)"; + newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f); + newText.gameObject.GetComponent().Destroy(); + + List newOpts = new(); + foreach (var opt in group.Options) { OptionBehaviour newOpt = opt.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.settingsContainer); - newOpt.transform.localPosition = new Vector3(0.952f, num, -2f); newOpt.SetClickMask(__instance.ButtonClickMask); SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren(true); @@ -80,14 +134,38 @@ public static class GameOptionsMenuPatch textMeshPro.fontMaterial.SetFloat(ShaderID.Stencil, 20); } + if (newOpt is ToggleOption toggle) + { + toggle.CheckMark.sprite = MiraAssets.Checkmark.LoadAsset(); + + SpriteRenderer rend = toggle.CheckMark.transform.parent.FindChild("ActiveSprite").GetComponent(); + rend.sprite = MiraAssets.CheckmarkBox.LoadAsset(); + rend.color = group.GroupColor; + } + __instance.Children.Add(newOpt); - num -= 0.45f; newOpt.Initialize(); + newOpts.Add(newOpt); + newOpt.gameObject.SetActive(false); } + + BoxCollider2D boxCol = categoryHeaderMasked.gameObject.AddComponent(); + boxCol.size = new Vector2(7, 0.7f); + boxCol.offset = new Vector2(1.5f, -0.3f); + + PassiveButton headerBtn = categoryHeaderMasked.gameObject.AddComponent(); + headerBtn.ClickSound = __instance.BackButton.GetComponent().ClickSound; + headerBtn.OnMouseOver = new UnityEvent(); + headerBtn.OnMouseOut = new UnityEvent(); + headerBtn.OnClick.AddListener((UnityAction)(() => + { + group.AllOptionsHidden = !group.AllOptionsHidden; + newText.text = group.AllOptionsHidden ? "(Click to open)" : "(Click to close)"; + })); + headerBtn.SetButtonEnableState(true); } - __instance.scrollBar.SetYBoundsMax(-num - 1.65f); return false; } @@ -101,7 +179,7 @@ public static class GameOptionsMenuPatch __instance.MapPicker.Initialize(20); BaseGameSetting mapNameSetting = GameManager.Instance.GameSettingsList.MapNameSetting; __instance.MapPicker.SetUpFromData(mapNameSetting, 20); - __instance.Children = new List(); + __instance.Children = new Il2CppSystem.Collections.Generic.List(); __instance.Children.Add(__instance.MapPicker); __instance.CreateSettings(); __instance.cachedData = GameOptionsManager.Instance.CurrentGameOptions; diff --git a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs index 6e10fbe..aa479c1 100644 --- a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs @@ -21,10 +21,13 @@ public static class GameSettingMenuPatches private static TextMeshPro _text; + private static Vector3 _roleBtnOgPos; + [HarmonyPrefix] [HarmonyPatch(nameof(GameSettingMenu.Start))] public static void StartPrefix(GameSettingMenu __instance) { + _roleBtnOgPos = __instance.RoleSettingsButton.transform.localPosition; __instance.transform.FindChild("GameSettingsLabel").gameObject.SetActive(false); Transform helpThing = __instance.transform.FindChild("What Is This?"); @@ -36,7 +39,9 @@ public static class GameSettingMenuPatches _text = tmpText.GetComponent(); _text.fontSizeMax = 3.2f; - UpdateText(__instance.GameSettingsTab, __instance.RoleSettingsTab); + _text.overflowMode = TextOverflowModes.Overflow; + + UpdateText(__instance, __instance.GameSettingsTab, __instance.RoleSettingsTab); _text.alignment = TextAlignmentOptions.Center; @@ -54,7 +59,7 @@ public static class GameSettingMenuPatches if (CurrentSelectedMod != MiraPluginManager.Instance.RegisteredPlugins.Count) { CurrentSelectedMod += 1; - UpdateText(__instance.GameSettingsTab, __instance.RoleSettingsTab); + UpdateText(__instance, __instance.GameSettingsTab, __instance.RoleSettingsTab); } })); @@ -68,12 +73,12 @@ public static class GameSettingMenuPatches if (CurrentSelectedMod != 0) { CurrentSelectedMod -= 1; - UpdateText(__instance.GameSettingsTab, __instance.RoleSettingsTab); + UpdateText(__instance, __instance.GameSettingsTab, __instance.RoleSettingsTab); } })); } - private static void UpdateText(GameOptionsMenu settings, RolesSettingsMenu roles) + private static void UpdateText(GameSettingMenu menu, GameOptionsMenu settings, RolesSettingsMenu roles) { if (CurrentSelectedMod == 0) { @@ -82,19 +87,41 @@ public static class GameSettingMenuPatches } else { - _text.fontSizeMax = 2f; + _text.fontSizeMax = 2.3f; SelectedMod = MiraPluginManager.Instance.RegisteredPlugins.ElementAt(CurrentSelectedMod - 1).Value; if (SelectedMod == null) { CurrentSelectedMod = 0; - UpdateText(settings, roles); + UpdateText(menu, settings, roles); } - string name = SelectedMod?.PluginInfo.Metadata.Name; - _text.text = name?[..Math.Min(name.Length, 15)]; + string name = SelectedMod?.MiraPlugin.OptionsTitleText; + _text.text = name?[..Math.Min(name.Length, 25)]; } - if (roles?.roleChances != null) + menu.RoleSettingsButton.transform.localPosition = _roleBtnOgPos; + menu.GameSettingsButton.gameObject.SetActive(true); + menu.RoleSettingsButton.gameObject.SetActive(true); + + if (CurrentSelectedMod != 0) + { + if (SelectedMod.OptionGroups.Count == 0) + { + menu.GameSettingsButton.gameObject.SetActive(false); + } + + if (SelectedMod.CustomRoles.Count == 0) + { + menu.RoleSettingsButton.gameObject.SetActive(false); + } + + if (!menu.GameSettingsButton.gameObject.active && menu.RoleSettingsButton.gameObject.active) + { + menu.RoleSettingsButton.transform.localPosition = menu.GameSettingsButton.transform.localPosition; + } + } + + if (roles?.roleChances != null && SelectedMod != null && SelectedMod.CustomRoles.Count != 0) { if (roles.advancedSettingChildren is not null) { @@ -126,7 +153,7 @@ public static class GameSettingMenuPatches roles.scrollBar.ScrollToTop(); } - if (settings?.Children != null) + if (settings?.Children != null && SelectedMod.OptionGroups.Count != 0) { foreach (var child in settings.Children) { diff --git a/MiraAPI/PluginLoading/IMiraPlugin.cs b/MiraAPI/PluginLoading/IMiraPlugin.cs index fb48f68..9a71645 100644 --- a/MiraAPI/PluginLoading/IMiraPlugin.cs +++ b/MiraAPI/PluginLoading/IMiraPlugin.cs @@ -4,5 +4,6 @@ namespace MiraAPI.PluginLoading; public interface IMiraPlugin { + string OptionsTitleText { get; } public ConfigFile GetConfigFile(); } \ No newline at end of file diff --git a/MiraAPI/Resources/CheckMarkBox.png b/MiraAPI/Resources/CheckMarkBox.png new file mode 100644 index 0000000000000000000000000000000000000000..1190f47dacbd63aac462870d85897a14efbd204b GIT binary patch literal 347 zcmeAS@N?(olHy`uVBq!ia0vp^6(G#Q3?xr`X+H!~jKx9jPK-BC>eK@{oCO|{#S9F5 zM?jcysy3fAP*69(C&U#<|NsAAA}&ZkLP9`9Kq56tF*iy;KtM=HNFv%tKuAD9P(UIv zNFq8&Kt$sBn&(G>8u&|s{DMK+kigU4dCP!OYdl>XLn`LHy=lmG$U(sE;mkt~9TO^S zXIBXKC-FVv6)EDIUBRH5#@zMxOuWm(-2WSQ2cIi8{(S3E`X2v)BbwP}XLfkrTx45a zSh=Gi_rsUf-0NZw{On$ydA{O0i~YOl{Bg32f~#}-^JBIq*1Vg3{Pnw=$3Ik9Hy%td zklSNf0(~+g?V+NZvOREy${zbOt6h&nfR$&tZvB@m7{vPn{`9j)ptgI R*95wo!PC{xWt~$(699Nqi0uFX literal 0 HcmV?d00001 diff --git a/MiraAPI/Resources/Checkmark.png b/MiraAPI/Resources/Checkmark.png new file mode 100644 index 0000000000000000000000000000000000000000..802819a9b789f8583ac6e1e881ee0f2e2dbaae42 GIT binary patch literal 370 zcmeAS@N?(olHy`uVBq!ia0vp^c0g>z$P8kg{Z#{`7>k44ofvPP)Tsw@I14-?iy0XB zj({-ZRBb+Kpded-Plzj!{{R2~(wp<|0$EHYL4Lsu|Dz`=Z3Xhad%8G=RLqGzZkeLWRpJ0Ha6Rq3PXx!k{ic(-mi5fEoSfn}bEn?XyJE96kNO_+iTAeK7JsH<<*t9dk{s;e zXEdILr-}6YryZE7aK@p_czc}J2aAi>6DDNXnw;MK>8X-|Gkb&NqK^q}E3D26@EAIO zurY4=H#hvlo(QcBw~IN!&ZQ@Kj&3k{;+$E~errNb?H Date: Tue, 27 Aug 2024 14:05:04 -0400 Subject: [PATCH 58/60] more readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7ce157..d57449c 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ You can access any group class using the `OptionGroupSingleton` class like this: ```csharp // MyOptionsGroup is a class that inherits from AbstractOptionGroup var myGroup = OptionGroupSingleton.Instance; // gets the instance of the group -System.Out.Console.WriteLine(myGroup.MyNumberOption); // prints the value of the option to the console +Logger.Info(myGroup.MyNumberOption); // prints the value of the option to the console ``` Once you have an options group, there are two ways to make the actual options: @@ -170,6 +170,11 @@ Mira API provides a simple interface for adding ability buttons to the game. The All other tasks and logic required to add the button to the game are handled by Mira API. +In case you need to access your `CustomActionButton` instance from another class, you can use the `CustomButtonSingleton` class like this: +```csharp +var myButton = CustomButtonSingleton.Instance; +``` + The button API is simple, but provides a lot of flexibility. There are various methods you can override to customize the behaviour of your button. See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI/Hud/CustomActionButton.cs) for a full list of methods you can override. An example button can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Buttons/ExampleButton.cs). From 74592b2558cebd00a92c0c238eb1a013fe1f19bb Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:29:06 -0400 Subject: [PATCH 59/60] oops role ID had issues --- .../Patches/Options/GameOptionsMenuPatch.cs | 4 +-- .../Patches/Options/GameSettingMenuPatches.cs | 4 +-- MiraAPI/PluginLoading/MiraPluginManager.cs | 31 +++++++---------- MiraAPI/Roles/CustomRoleManager.cs | 33 ++++++++++++++++--- MiraAPI/Roles/RoleId.cs | 6 ++-- 5 files changed, 46 insertions(+), 32 deletions(-) diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index 7f30b85..0a488ff 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -96,12 +96,12 @@ public static class GameOptionsMenuPatch categoryHeaderMasked.gameObject.SetActive(false); group.Header = categoryHeaderMasked; - TextMeshPro newText = GameObject.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform); + TextMeshPro newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform); newText.text = $"(Click to open)"; newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f); newText.gameObject.GetComponent().Destroy(); - List newOpts = new(); + List newOpts = []; foreach (var opt in group.Options) { OptionBehaviour newOpt = opt.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.settingsContainer); diff --git a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs index aa479c1..6da7827 100644 --- a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs @@ -95,7 +95,7 @@ public static class GameSettingMenuPatches UpdateText(menu, settings, roles); } - string name = SelectedMod?.MiraPlugin.OptionsTitleText; + var name = SelectedMod?.MiraPlugin.OptionsTitleText; _text.text = name?[..Math.Min(name.Length, 25)]; } @@ -105,7 +105,7 @@ public static class GameSettingMenuPatches if (CurrentSelectedMod != 0) { - if (SelectedMod.OptionGroups.Count == 0) + if (SelectedMod.Options.Where(x=>x.AdvancedRole==null).ToList().Count == 0) { menu.GameSettingsButton.gameObject.SetActive(false); } diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index 8a48e38..13c9c37 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -89,6 +89,7 @@ internal class MiraPluginManager private static void RegisterRoleAttribute(Assembly assembly, MiraPluginInfo pluginInfo) { + List roles = []; foreach (var type in assembly.GetTypes()) { var attribute = type.GetCustomAttribute(); @@ -97,32 +98,22 @@ internal class MiraPluginManager continue; } + if (!(typeof(RoleBehaviour).IsAssignableFrom(type) && typeof(ICustomRole).IsAssignableFrom(type))) + { + Logger.Error($"{type.Name} does not inherit from RoleBehaviour or ICustomRole."); + continue; + } + if (!ModList.GetById(pluginInfo.PluginId).IsRequiredOnAllClients) { Logger.Error("Custom roles are only supported on all clients."); return; } - - ClassInjector.RegisterTypeInIl2Cpp(type); - - var role = CustomRoleManager.RegisterRole(type, pluginInfo); - - try - { - pluginInfo.CustomRoles.Add((ushort)role.Role, role); - } - catch (Exception e) - { - Logger.Error("Failed to register role: " + type.Name); - - foreach (var (k, v) in pluginInfo.CustomRoles) - { - Logger.Error($"{k}: {v}"); - } - - Logger.Error(e); - } + + roles.Add(type); } + + CustomRoleManager.RegisterRoleTypes(roles, pluginInfo); } private static void RegisterColorClasses(Assembly assembly) diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 0cbd453..74e0bcf 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -9,6 +9,7 @@ using Reactor.Utilities.Extensions; using System; using System.Collections.Generic; using System.Linq; +using Il2CppInterop.Runtime.Injection; using MiraAPI.Utilities; using TMPro; using UnityEngine; @@ -19,7 +20,9 @@ namespace MiraAPI.Roles; public static class CustomRoleManager { public static readonly Dictionary CustomRoles = new(); - + + public static readonly Dictionary RoleIds = new(); + private static ushort _roleId = 100; private static ushort GetNextRoleId() @@ -32,7 +35,25 @@ public static class CustomRoleManager RoleManager.Instance.AllRoles = RoleManager.Instance.AllRoles.Concat(CustomRoles.Values).ToArray(); } - internal static RoleBehaviour RegisterRole(Type roleType, MiraPluginInfo parentMod) + public static void RegisterRoleTypes(List roles, MiraPluginInfo pluginInfo) + { + roles.ForEach(x=>RoleIds.Add(x, GetNextRoleId())); + + foreach (var roleType in roles) + { + ClassInjector.RegisterTypeInIl2Cpp(roleType); + + var role = RegisterRole(roleType, pluginInfo); + if (role is null) + { + continue; + } + + pluginInfo.CustomRoles.Add((ushort)role.Role, role); + } + } + + private static RoleBehaviour RegisterRole(Type roleType, MiraPluginInfo parentMod) { if (!(typeof(RoleBehaviour).IsAssignableFrom(roleType) && typeof(ICustomRole).IsAssignableFrom(roleType))) { @@ -47,8 +68,10 @@ public static class CustomRoleManager roleBehaviour.gameObject.Destroy(); return null; } + + var roleId = RoleIds[roleType]; - roleBehaviour.Role = (RoleTypes)GetNextRoleId(); + roleBehaviour.Role = (RoleTypes)roleId; roleBehaviour.TeamType = customRole.Team == ModdedRoleTeams.Neutral ? RoleTeamTypes.Crewmate : (RoleTeamTypes)customRole.Team; roleBehaviour.NameColor = customRole.RoleColor; roleBehaviour.StringName = CustomStringName.CreateAndRegister(customRole.RoleName); @@ -68,7 +91,7 @@ public static class CustomRoleManager RoleManager.GhostRoles.Add(roleBehaviour.Role); } - CustomRoles.Add(_roleId, roleBehaviour); + CustomRoles.Add(roleId, roleBehaviour); if (customRole.HideSettings) { @@ -78,7 +101,7 @@ public static class CustomRoleManager var config = parentMod.PluginConfig; config.Bind(customRole.NumConfigDefinition, 1); config.Bind(customRole.ChanceConfigDefinition, 100); - + return roleBehaviour; } diff --git a/MiraAPI/Roles/RoleId.cs b/MiraAPI/Roles/RoleId.cs index bb7b714..f9d30c0 100644 --- a/MiraAPI/Roles/RoleId.cs +++ b/MiraAPI/Roles/RoleId.cs @@ -7,11 +7,11 @@ public class RoleId { public static ushort Get() where T : RoleBehaviour { - if (!CustomRoleManager.CustomRoles.Values.OfType().Any()) + if (!CustomRoleManager.RoleIds.TryGetValue(typeof(T), out var roleId)) { throw new InvalidOperationException($"Role {typeof(T)} is not registered"); } - - return (ushort)CustomRoleManager.CustomRoles.Values.OfType().Single().Role; + + return roleId; } } \ No newline at end of file From 2dadf08df469f975603679f3888112bb7f4b667a Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:30:27 -0400 Subject: [PATCH 60/60] a todo --- MiraAPI/Roles/ICustomRole.cs | 3 +-- MiraAPI/Roles/RoleId.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 4a630f4..42cc91c 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -81,7 +81,6 @@ public interface ICustomRole ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out var numEntry); ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out var chanceEntry); - // TODO: use the RoleID class when that branch is merged - return new NetData((uint)((RoleBehaviour)this).Role, BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); + return new NetData(RoleId.Get(GetType()), BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); } } \ No newline at end of file diff --git a/MiraAPI/Roles/RoleId.cs b/MiraAPI/Roles/RoleId.cs index f9d30c0..d1174f6 100644 --- a/MiraAPI/Roles/RoleId.cs +++ b/MiraAPI/Roles/RoleId.cs @@ -14,4 +14,14 @@ public class RoleId return roleId; } + + public static ushort Get(Type type) + { + if (!CustomRoleManager.RoleIds.TryGetValue(type, out var roleId)) + { + throw new InvalidOperationException($"Role {type} is not registered"); + } + + return roleId; + } } \ No newline at end of file