mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Merge remote-tracking branch 'origin/6.18' into 6.18
This commit is contained in:
commit
f351431eaa
12 files changed
+103
-202
No files matched your search
@@ -9,11 +9,20 @@ namespace MiraAPI.Example
|
||||
public string GroupName => "General Group";
|
||||
public Color GroupColor => Color.red;
|
||||
|
||||
[ModdedToggleOption("Use Thing")] public bool useThing { get; set; } = false;
|
||||
[ModdedToggleOption("Use another thing")] public bool useAnotherThing { get; set; } = true;
|
||||
[ModdedNumberOption("Sussy level", min: 0, max: 10)] public float sussyLevel { get; set; } = 4f;
|
||||
[ModdedStringOption("Sus choices", ["hello", "hello 2", "hello 3"])] public int susChoices { get; set; } = 2;
|
||||
[ModdedEnumOption("Enum test", typeof(TestEnum))] public TestEnum enumTest { get; set; } = TestEnum.Bye;
|
||||
[ModdedToggleOption("Use Thing")]
|
||||
public bool useThing { get; set; } = false;
|
||||
|
||||
[ModdedToggleOption("Use another thing")]
|
||||
public bool useAnotherThing { get; set; } = true;
|
||||
|
||||
[ModdedNumberOption("Sussy level", min: 0, max: 10)]
|
||||
public float sussyLevel { get; set; } = 4f;
|
||||
|
||||
[ModdedStringOption("Sus choices", ["hello", "hello 2", "hello 3"])]
|
||||
public int susChoices { get; set; } = 2;
|
||||
|
||||
[ModdedEnumOption("Enum test", typeof(TestEnum))]
|
||||
public TestEnum enumTest { get; set; } = TestEnum.Bye;
|
||||
}
|
||||
|
||||
public enum TestEnum
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.PluginLoading;
|
||||
@@ -15,6 +16,7 @@ namespace MiraAPI.Example;
|
||||
public partial class ExamplePlugin : BasePlugin, IMiraPlugin
|
||||
{
|
||||
public Harmony Harmony { get; } = new(Id);
|
||||
public ConfigFile GetConfigFile() => Config;
|
||||
public override void Load()
|
||||
{
|
||||
Harmony.PatchAll();
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace MiraAPI.GameOptions
|
||||
{
|
||||
public string GroupName { get; }
|
||||
public Func<bool> GroupVisible => () => true;
|
||||
public Color GroupColor => Color.white;
|
||||
public Color GroupColor => Color.clear;
|
||||
public Type AdvancedRole => null;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,11 @@ public static class GameOptionsMenuPatch
|
||||
{
|
||||
CategoryHeaderMasked categoryHeaderMasked = UnityEngine.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.Title.color = group.GroupColor.DarkenColor();
|
||||
}
|
||||
categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f;
|
||||
categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
||||
num -= 0.63f;
|
||||
@@ -38,10 +43,13 @@ public static class GameOptionsMenuPatch
|
||||
SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
for (int i = 0; i < componentsInChildren.Length; i++)
|
||||
{
|
||||
if (group.GroupColor != Color.clear) componentsInChildren[i].color = group.GroupColor;
|
||||
componentsInChildren[i].material.SetInt(PlayerMaterial.MaskLayer, 20);
|
||||
}
|
||||
|
||||
foreach (TextMeshPro textMeshPro in newOpt.GetComponentsInChildren<TextMeshPro>(true))
|
||||
{
|
||||
if (group.GroupColor != Color.clear) textMeshPro.color = group.GroupColor.DarkenColor();
|
||||
textMeshPro.fontMaterial.SetFloat("_StencilComp", 3f);
|
||||
textMeshPro.fontMaterial.SetFloat("_Stencil", 20);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public static class GameSettingMenuPatches
|
||||
|
||||
text = tmpText.GetComponent<TextMeshPro>();
|
||||
text.fontSizeMax = 3.2f;
|
||||
UpdateText(__instance.GameSettingsTab);
|
||||
UpdateText(__instance.GameSettingsTab, __instance.RoleSettingsTab);
|
||||
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
|
||||
@@ -51,8 +51,8 @@ public static class GameSettingMenuPatches
|
||||
if (currentSelectedMod != MiraPluginManager.Instance.RegisteredPlugins.Count)
|
||||
{
|
||||
currentSelectedMod += 1;
|
||||
UpdateText(__instance.GameSettingsTab, __instance.RoleSettingsTab);
|
||||
}
|
||||
UpdateText(__instance.GameSettingsTab);
|
||||
}));
|
||||
|
||||
GameObject backButton = GameObject.Instantiate(nextButton, __instance.BackButton.transform.parent).gameObject;
|
||||
@@ -65,12 +65,12 @@ public static class GameSettingMenuPatches
|
||||
if (currentSelectedMod != 0)
|
||||
{
|
||||
currentSelectedMod -= 1;
|
||||
UpdateText(__instance.GameSettingsTab, __instance.RoleSettingsTab);
|
||||
}
|
||||
UpdateText(__instance.GameSettingsTab);
|
||||
}));
|
||||
}
|
||||
|
||||
public static void UpdateText(GameOptionsMenu settings)
|
||||
public static void UpdateText(GameOptionsMenu settings, RolesSettingsMenu roles)
|
||||
{
|
||||
if (currentSelectedMod == 0)
|
||||
{
|
||||
@@ -84,31 +84,62 @@ public static class GameSettingMenuPatches
|
||||
if (selectedMod == null)
|
||||
{
|
||||
currentSelectedMod = 0;
|
||||
UpdateText(settings);
|
||||
UpdateText(settings, roles);
|
||||
}
|
||||
|
||||
string name = selectedMod.PluginInfo.Metadata.Name;
|
||||
text.text = name.Substring(0, Math.Min(name.Length, 15));
|
||||
}
|
||||
|
||||
if (settings.Children is null || settings is null) return;
|
||||
|
||||
foreach (var child in settings.Children)
|
||||
if (roles is not null && roles.roleChances is not null)
|
||||
{
|
||||
if (child.TryCast<GameOptionsMapPicker>()) continue;
|
||||
if (child.gameObject is null) continue;
|
||||
if (roles.advancedSettingChildren is not null)
|
||||
{
|
||||
foreach (var child in roles.advancedSettingChildren)
|
||||
{
|
||||
child.gameObject.DestroyImmediate();
|
||||
}
|
||||
roles.advancedSettingChildren.Clear();
|
||||
roles.advancedSettingChildren = null;
|
||||
}
|
||||
|
||||
child.gameObject.DestroyImmediate();
|
||||
foreach (var header in roles.RoleChancesSettings.transform.GetComponentsInChildren<CategoryHeaderEditRole>())
|
||||
{
|
||||
header.gameObject.DestroyImmediate();
|
||||
}
|
||||
|
||||
foreach (var roleChance in roles.roleChances)
|
||||
{
|
||||
roleChance.gameObject.DestroyImmediate();
|
||||
}
|
||||
|
||||
|
||||
roles.roleChances.Clear();
|
||||
roles.roleChances = null;
|
||||
roles.AdvancedRolesSettings.gameObject.SetActive(false);
|
||||
roles.RoleChancesSettings.gameObject.SetActive(true);
|
||||
roles.SetQuotaTab();
|
||||
}
|
||||
|
||||
foreach (var header in settings.settingsContainer.GetComponentsInChildren<CategoryHeaderMasked>())
|
||||
if (settings is not null && settings.Children is not null)
|
||||
{
|
||||
header.gameObject.DestroyImmediate();
|
||||
foreach (var child in settings.Children)
|
||||
{
|
||||
if (child.TryCast<GameOptionsMapPicker>()) continue;
|
||||
if (child.gameObject is null) continue;
|
||||
|
||||
child.gameObject.DestroyImmediate();
|
||||
}
|
||||
|
||||
foreach (var header in settings.settingsContainer.GetComponentsInChildren<CategoryHeaderMasked>())
|
||||
{
|
||||
header.gameObject.DestroyImmediate();
|
||||
}
|
||||
|
||||
settings.Children.Clear();
|
||||
settings.Children = null;
|
||||
|
||||
settings.Initialize();
|
||||
}
|
||||
|
||||
settings.Children.Clear();
|
||||
settings.Children = null;
|
||||
|
||||
settings.Initialize();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
@@ -18,8 +19,13 @@ namespace MiraAPI.Patches.Options
|
||||
[HarmonyPrefix, HarmonyPatch(nameof(RolesSettingsMenu.SetQuotaTab))]
|
||||
public static bool PatchStart(RolesSettingsMenu __instance)
|
||||
{
|
||||
__instance.roleChances = new Il2CppSystem.Collections.Generic.List<RoleOptionSetting>();
|
||||
__instance.advancedSettingChildren = new Il2CppSystem.Collections.Generic.List<OptionBehaviour>();
|
||||
|
||||
if (GameSettingMenuPatches.currentSelectedMod == 0)
|
||||
{
|
||||
__instance.AllButton.transform.parent.gameObject.SetActive(true);
|
||||
__instance.AllButton.gameObject.SetActive(true);
|
||||
__instance.scrollBar.transform.localPosition = new Vector3(-1.4957f, 0.657f, -4);
|
||||
return true;
|
||||
}
|
||||
@@ -134,7 +140,7 @@ namespace MiraAPI.Patches.Options
|
||||
__instance.roleScreenshot.sprite = Sprite.Create(role.RoleScreenshot.texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100);
|
||||
__instance.roleScreenshot.drawMode = SpriteDrawMode.Sliced;
|
||||
__instance.roleHeaderSprite.color = customRole.RoleColor;
|
||||
__instance.roleHeaderText.color = new Color(customRole.RoleColor.r - 0.3f, customRole.RoleColor.g - 0.3f, customRole.RoleColor.b - 0.3f);
|
||||
__instance.roleHeaderText.color = customRole.RoleColor.DarkenColor();
|
||||
|
||||
CreateAdvancedSettings(__instance, role);
|
||||
|
||||
@@ -153,10 +159,12 @@ namespace MiraAPI.Patches.Options
|
||||
|
||||
public static void CreateQuotaOption(RolesSettingsMenu __instance, RoleBehaviour role, ref float yPos, int index)
|
||||
{
|
||||
ICustomRole customRole = role as ICustomRole;
|
||||
RoleOptionSetting roleOptionSetting = Object.Instantiate(__instance.roleOptionSettingOrigin, Vector3.zero, Quaternion.identity, __instance.RoleChancesSettings.transform);
|
||||
roleOptionSetting.transform.localPosition = new Vector3(-0.15f, yPos, -2f);
|
||||
roleOptionSetting.SetRole(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions, role, 20);
|
||||
roleOptionSetting.labelSprite.color = (role as ICustomRole).RoleColor;
|
||||
roleOptionSetting.labelSprite.color = customRole.RoleColor;
|
||||
roleOptionSetting.titleText.color = customRole.RoleColor.DarkenColor();
|
||||
roleOptionSetting.OnValueChanged = new Action<OptionBehaviour>(ValueChanged);
|
||||
roleOptionSetting.titleText.horizontalAlignment = TMPro.HorizontalAlignmentOptions.Left;
|
||||
roleOptionSetting.SetClickMask(__instance.ButtonClickMask);
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Roles;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
/*
|
||||
[HarmonyPatch(typeof(RoleOptionSetting))]
|
||||
public static class RoleOptionSettingPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Update the role details screen in role settings for Launchpad roles
|
||||
/// </summary>
|
||||
[HarmonyPrefix, HarmonyPatch("ShowRoleDetails")]
|
||||
public static bool ShowRoleDetailsPrefix(RoleOptionSetting __instance)
|
||||
{
|
||||
if (__instance.Role is ICustomRole customRole)
|
||||
{
|
||||
GameSettingMenu.Instance.RoleName.text = __instance.Role.NiceName;
|
||||
GameSettingMenu.Instance.RoleBlurb.text = __instance.Role.BlurbLong;
|
||||
GameSettingMenu.Instance.RoleIcon.sprite = customRole.Icon.LoadAsset();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
@@ -1,148 +0,0 @@
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System.Linq;
|
||||
using MiraAPI.Networking;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
/*
|
||||
[HarmonyPatch(typeof(RolesSettingsMenu))]
|
||||
public static class RolesSettingsMenuPatches
|
||||
{
|
||||
/// <summary>
|
||||
/// Create role buttons and advanced role settings menu for every custom Launchpad role
|
||||
/// </summary>
|
||||
[HarmonyPrefix, HarmonyPatch("OnEnable")]
|
||||
public static void OnEnablePrefix(RolesSettingsMenu __instance)
|
||||
{
|
||||
var tabPrefab = __instance.AllAdvancedSettingTabs.ToArray()[1].Tab;
|
||||
foreach (var (key, role) in CustomRoleManager.CustomRoles)
|
||||
{
|
||||
if (__instance.AllAdvancedSettingTabs.ToArray().Any(x => (ushort)x.Type == key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (role is ICustomRole { HideSettings: true })
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var numChanceOption = Object.Instantiate(__instance.SettingPrefab, __instance.ItemParent);
|
||||
numChanceOption.transform.localPosition = new Vector3(0.044f, 0, 0);
|
||||
numChanceOption.name = role.NiceName;
|
||||
numChanceOption.Role = role;
|
||||
__instance.AllRoleSettings.Add(numChanceOption);
|
||||
|
||||
|
||||
var newTab = Object.Instantiate(tabPrefab, __instance.AdvancedRolesSettings.transform);
|
||||
newTab.name = role.NiceName + " Settings";
|
||||
var toggleSet = Object.Instantiate(newTab.GetComponentInChildren<ToggleOption>(true));
|
||||
var numberSet = Object.Instantiate(newTab.GetComponentInChildren<NumberOption>(true));
|
||||
|
||||
foreach (var option in newTab.GetComponentsInChildren<OptionBehaviour>())
|
||||
{
|
||||
option.gameObject.Destroy();
|
||||
}
|
||||
|
||||
var startOffset = 0.5f;
|
||||
|
||||
/* foreach (var customOption in CustomOptionsManager.CustomOptions)
|
||||
{
|
||||
if (customOption.AdvancedRole is not null && customOption.AdvancedRole == role.GetType())
|
||||
{
|
||||
startOffset -= 0.5f;
|
||||
|
||||
switch (customOption)
|
||||
{
|
||||
case CustomNumberOption numberOption:
|
||||
var numOpt = numberOption.CreateNumberOption(numberSet, newTab.transform);
|
||||
numOpt.transform.localPosition = new Vector3(-1.25f, startOffset, 0);
|
||||
break;
|
||||
|
||||
case CustomToggleOption toggleOption:
|
||||
var togOpt = toggleOption.CreateToggleOption(toggleSet, newTab.transform);
|
||||
togOpt.transform.localPosition = new Vector3(-1.25f, startOffset, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*\/
|
||||
|
||||
var tmp = newTab.GetComponentInChildren<TextTranslatorTMP>();
|
||||
tmp.defaultStr = role.NiceName;
|
||||
tmp.TargetText = role.StringName;
|
||||
|
||||
var newAdvSet = new AdvancedRoleSettingsButton
|
||||
{
|
||||
Tab = newTab,
|
||||
Type = (RoleTypes)key
|
||||
};
|
||||
|
||||
__instance.AllAdvancedSettingTabs.Add(newAdvSet);
|
||||
|
||||
toggleSet.gameObject.Destroy();
|
||||
numberSet.gameObject.Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set custom role options OnValueChanged and re-enable the role settings menu scrolling
|
||||
/// </summary>
|
||||
[HarmonyPostfix, HarmonyPatch("Start")]
|
||||
public static void StartPostfix(RolesSettingsMenu __instance)
|
||||
{
|
||||
/* foreach (var customOption in CustomOptionsManager.CustomOptions)
|
||||
{
|
||||
if (customOption.AdvancedRole is not null)
|
||||
{
|
||||
customOption.OptionBehaviour.OnValueChanged = (Action<OptionBehaviour>)customOption.ValueChanged;
|
||||
}
|
||||
}*\/
|
||||
|
||||
var scroll = __instance.GetComponentInChildren<Scroller>();
|
||||
scroll.active = true;
|
||||
scroll.ContentYBounds.max = 2 * __instance.AllRoleSettings.Count / 10f;
|
||||
|
||||
scroll.transform.FindChild("UI_Scrollbar").gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update config when value changed
|
||||
/// </summary>
|
||||
[HarmonyPrefix, HarmonyPatch("ValueChanged")]
|
||||
public static bool ValueChangedPrefix(RolesSettingsMenu __instance, [HarmonyArgument(0)] OptionBehaviour obj)
|
||||
{
|
||||
if (obj.GetIl2CppType() != Il2CppType.Of<RoleOptionSetting>())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var roleSetting = obj.Cast<RoleOptionSetting>();
|
||||
|
||||
if (roleSetting.Role is not ICustomRole role || role.HideSettings)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
MiraAPIPlugin.Instance.Config.TryGetEntry<int>(role.NumConfigDefinition, out var numEntry);
|
||||
numEntry.Value = roleSetting.RoleMaxCount;
|
||||
|
||||
MiraAPIPlugin.Instance.Config.TryGetEntry<int>(role.ChanceConfigDefinition, out var chanceEntry);
|
||||
chanceEntry.Value = roleSetting.RoleChance;
|
||||
|
||||
roleSetting.UpdateValuesAndText(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions);
|
||||
|
||||
if (AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
Rpc<SyncRoleOptionsRpc>.Instance.Send(new SyncRoleOptionsRpc.Data((ushort)roleSetting.Role.Role, numEntry.Value, chanceEntry.Value));
|
||||
}
|
||||
GameOptionsManager.Instance.GameHostOptions = GameOptionsManager.Instance.CurrentGameOptions;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace MiraAPI.PluginLoading
|
||||
using BepInEx.Configuration;
|
||||
|
||||
namespace MiraAPI.PluginLoading
|
||||
{
|
||||
public interface IMiraPlugin
|
||||
{
|
||||
public ConfigFile GetConfigFile();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using System.Collections.Generic;
|
||||
@@ -8,8 +9,9 @@ namespace MiraAPI.PluginLoading;
|
||||
public class MiraPluginInfo
|
||||
{
|
||||
public string PluginId { get; set; }
|
||||
public IMiraPlugin Config { get; set; }
|
||||
public IMiraPlugin MiraPlugin { get; set; }
|
||||
public PluginInfo PluginInfo { get; set; }
|
||||
public ConfigFile PluginConfig { get; set; }
|
||||
|
||||
public readonly List<IModdedOptionGroup> OptionGroups = [];
|
||||
public readonly List<IModdedOption> Options = [];
|
||||
@@ -17,11 +19,12 @@ public class MiraPluginInfo
|
||||
public readonly Dictionary<ushort, RoleBehaviour> CustomRoles = [];
|
||||
public readonly Dictionary<int, CustomGameMode> GameModes = [];
|
||||
|
||||
public MiraPluginInfo(string id, IMiraPlugin config, PluginInfo info)
|
||||
public MiraPluginInfo(string id, IMiraPlugin miraPlugin, PluginInfo info)
|
||||
{
|
||||
PluginId = id;
|
||||
Config = config;
|
||||
MiraPlugin = miraPlugin;
|
||||
PluginInfo = info;
|
||||
PluginConfig = miraPlugin.GetConfigFile();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using AmongUs.GameOptions;
|
||||
using Il2CppInterop.Runtime;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.PluginLoading;
|
||||
using Reactor.Localization.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
@@ -83,6 +84,10 @@ public static class CustomRoleManager
|
||||
return roleBehaviour;
|
||||
}
|
||||
|
||||
public static MiraPluginInfo FindParentMod(ICustomRole role)
|
||||
{
|
||||
return MiraPluginManager.Instance.RegisteredPlugins.First(plugin => plugin.Value.CustomRoles.Values.Contains(role as RoleBehaviour)).Value;
|
||||
}
|
||||
|
||||
public static bool GetCustomRoleBehaviour(RoleTypes roleType, out ICustomRole result)
|
||||
{
|
||||
|
||||
@@ -15,6 +15,10 @@ namespace MiraAPI.Utilities
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Color DarkenColor(this Color color)
|
||||
{
|
||||
return new Color(color.r - 0.3f, color.g - 0.3f, color.b - 0.3f);
|
||||
}
|
||||
public static void UpdateBodies(this PlayerControl playerControl, Color outlineColor, ref DeadBody target)
|
||||
{
|
||||
foreach (var body in Object.FindObjectsOfType<DeadBody>())
|
||||
|
||||
Reference in new issue
Block a user