mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
options fixes + start re implement custom game modes
This commit is contained in:
1 parent
05bc3561d9
commit
a37a8a8e1b
14 files changed
+268
-27
No files matched your search
@@ -0,0 +1,19 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Reactor.Utilities;
|
||||
#nullable enable
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -17,13 +18,13 @@ public static class CustomGameModeManager
|
||||
|
||||
public static bool IsDefault()
|
||||
{
|
||||
return ActiveMode.Id == 0;
|
||||
return ActiveMode?.Id == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current gamemode
|
||||
/// </summary>
|
||||
public static CustomGameMode ActiveMode;
|
||||
public static CustomGameMode? ActiveMode;
|
||||
|
||||
/// <summary>
|
||||
/// Set current gamemode
|
||||
@@ -52,17 +53,17 @@ public static class CustomGameModeManager
|
||||
return;
|
||||
}
|
||||
|
||||
var gameMode = (CustomGameMode)Activator.CreateInstance(gameModeType);
|
||||
var modeObj = Activator.CreateInstance(gameModeType);
|
||||
|
||||
if (GameModes.Any(x => x.Key == gameMode?.Id))
|
||||
if (modeObj is not CustomGameMode gameMode)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"ID for gamemode {gameMode?.Name} already exists!");
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create instance of {gameModeType.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameMode == null)
|
||||
|
||||
if (GameModes.Any(x => x.Key == gameMode.Id))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"GAMEMODE WITH TYPE {gameModeType.Name} IS NULL");
|
||||
Logger<MiraApiPlugin>.Error($"ID for gamemode {gameMode.Name} already exists!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public interface IModdedOption
|
||||
public BaseGameSetting Data { get; }
|
||||
public IModdedOptionGroup Group { get; set; }
|
||||
public IMiraPlugin ParentMod { get; set; }
|
||||
public Type AdvancedRole { get; }
|
||||
public Type AdvancedRole { get; set; }
|
||||
public OptionBehaviour OptionBehaviour { get; protected set; }
|
||||
public string Title { get; }
|
||||
public StringNames StringName { get; }
|
||||
|
||||
@@ -23,7 +23,18 @@ public class ModdedOptionsManager
|
||||
{
|
||||
if (OptionAttributes.ContainsKey(property)) return null;
|
||||
object newObj = Activator.CreateInstance(type);
|
||||
IModdedOption result = attribute.CreateOption(property.GetValue(newObj), property);
|
||||
|
||||
IModdedOption result;
|
||||
|
||||
try
|
||||
{
|
||||
result = attribute.CreateOption(property.GetValue(newObj), property);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
@@ -43,6 +54,7 @@ public class ModdedOptionsManager
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Grouping {attribute.Title} with {OriginalTypes[type].GroupName}");
|
||||
result.Group = OriginalTypes[type];
|
||||
result.AdvancedRole = OriginalTypes[type].AdvancedRole;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
public string Title { get; }
|
||||
public StringNames StringName { get; }
|
||||
public Func<bool> Visible { get; set; }
|
||||
public Type AdvancedRole { get; }
|
||||
public Type AdvancedRole { get; set; }
|
||||
public OptionBehaviour OptionBehaviour { get; set; }
|
||||
public IModdedOptionGroup Group { get; set; } = null;
|
||||
public IMiraPlugin ParentMod { get; set; } = null;
|
||||
@@ -40,7 +40,6 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
|
||||
private ModdedOption()
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error("created modded option");
|
||||
Id = ModdedOptionsManager.NextId++;
|
||||
ModdedOptionsManager.Options.Add(this);
|
||||
ModdedOptionsManager.ModdedOptions.Add(Id, this);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
using HarmonyLib;
|
||||
using InnerNet;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class ConsolePatches
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(Console), nameof(Console.CanUse))]
|
||||
public static bool CanUsePatch(Console __instance, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse)
|
||||
{
|
||||
if (AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started && ShipStatus.Instance)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode != null && CustomGameModeManager.ActiveMode.CanUseConsole(__instance))
|
||||
{
|
||||
var task = __instance.FindTask(pc.Object);
|
||||
|
||||
if (task && task.GetComponent<SabotageTask>())
|
||||
{
|
||||
canUse = couldUse = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
canUse = false;
|
||||
couldUse = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
canUse = couldUse = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
canUse = couldUse = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(SystemConsole), nameof(SystemConsole.CanUse))]
|
||||
public static bool SystemCanUsePatch(SystemConsole __instance, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse)
|
||||
{
|
||||
if (AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started && ShipStatus.Instance)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode != null && CustomGameModeManager.ActiveMode.CanUseSystemConsole(__instance))
|
||||
{
|
||||
return canUse = couldUse = true;
|
||||
}
|
||||
|
||||
canUse = couldUse = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
canUse = couldUse = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(MapConsole), nameof(MapConsole.CanUse))]
|
||||
public static bool MapCanUsePatch(MapConsole __instance, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse)
|
||||
{
|
||||
if (AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started && ShipStatus.Instance)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode != null && CustomGameModeManager.ActiveMode.CanUseMapConsole(__instance))
|
||||
{
|
||||
return canUse = couldUse = true;
|
||||
}
|
||||
|
||||
canUse = couldUse = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
canUse = couldUse = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class GameLogicPatches
|
||||
{
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(LogicGameFlowNormal), nameof(LogicGameFlowNormal.CheckEndCriteria))]
|
||||
public static bool EndCritPatch(LogicGameFlowNormal __instance)
|
||||
{
|
||||
var runOriginal = true;
|
||||
CustomGameModeManager.ActiveMode?.CheckGameEnd(out runOriginal, __instance);
|
||||
return runOriginal;
|
||||
}
|
||||
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(LogicRoleSelectionNormal), nameof(LogicRoleSelectionNormal.AssignRolesFromList))]
|
||||
public static bool AssignRolesPatch(LogicRoleSelectionNormal __instance)
|
||||
{
|
||||
var runOriginal = true;
|
||||
CustomGameModeManager.ActiveMode?.AssignRoles(out runOriginal, __instance);
|
||||
return runOriginal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// Allow Impostors to kill each other if can kill is enabled in gamemode or friendly fire is toggled on
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(ImpostorRole), "IsValidTarget")]
|
||||
public static class ImpostorTargetPatch
|
||||
{
|
||||
public static bool Prefix(ImpostorRole __instance, [HarmonyArgument(0)] NetworkedPlayerInfo target, ref bool __result)
|
||||
{
|
||||
var runOriginal = true;
|
||||
var result = false;
|
||||
CustomGameModeManager.ActiveMode?.CanKill(out runOriginal, out result, target.Object);
|
||||
if (runOriginal || !result)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
__result = target is { Disconnected: false, IsDead: false } &&
|
||||
target.PlayerId != __instance.Player.PlayerId && !(target.Role == null) &&
|
||||
!(target.Object == null) && !target.Object.inVent && !target.Object.inMovingPlat;
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(MapBehaviour))]
|
||||
public class MapBehaviourPatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(MapBehaviour.ShowSabotageMap))]
|
||||
public static bool ShowSabotagePatch(MapBehaviour __instance)
|
||||
{
|
||||
var shouldShow = CustomGameModeManager.ActiveMode?.ShouldShowSabotageMap(__instance);
|
||||
if (shouldShow.HasValue && !shouldShow.Value)
|
||||
{
|
||||
__instance.ShowNormalMap();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using InnerNet;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Utilities.Extensions;
|
||||
@@ -56,15 +57,15 @@ public static class HudManagerPatches
|
||||
}
|
||||
}
|
||||
|
||||
/* /// <summary>
|
||||
/// Trigger hudstart on current custom gamemode
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch("OnGameStart")]
|
||||
public static void GameStartPatch(HudManager __instance)
|
||||
{
|
||||
CustomGameModeManager.ActiveMode.HudStart(__instance);
|
||||
}*/
|
||||
/// <summary>
|
||||
/// Trigger hudstart on current custom gamemode
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(HudManager.OnGameStart))]
|
||||
public static void GameStartPatch(HudManager __instance)
|
||||
{
|
||||
CustomGameModeManager.ActiveMode?.HudStart(__instance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create custom buttons parent
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(IntroCutscene))]
|
||||
public static class IntroCutscenePatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.BeginImpostor))]
|
||||
public static void BeginImpostorPatch(IntroCutscene __instance)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode != null && CustomGameModeManager.ActiveMode.ShowCustomRoleScreen())
|
||||
{
|
||||
var mode = CustomGameModeManager.ActiveMode;
|
||||
__instance.TeamTitle.text = $"<size=70%>{mode.Name}</size>\n<size=20%>{mode.Description}</size>";
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.BeginCrewmate))]
|
||||
public static bool BeginCrewmatePatch(IntroCutscene __instance)
|
||||
{
|
||||
if (PlayerControl.LocalPlayer.Data.Role is ICustomRole customRole)
|
||||
{
|
||||
if (!customRole.IsNeutral)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var barTransform = __instance.BackgroundBar.transform;
|
||||
var position = barTransform.position;
|
||||
position.y -= 0.25f;
|
||||
barTransform.position = position;
|
||||
|
||||
__instance.BackgroundBar.material.SetColor(ShaderID.Color, Color.gray);
|
||||
__instance.TeamTitle.text = "OUTCAST";
|
||||
__instance.impostorScale = 1f;
|
||||
__instance.ImpostorText.text = "You are an Outcast. You do not have a team.";
|
||||
__instance.TeamTitle.color = Color.gray;
|
||||
|
||||
__instance.ourCrewmate = __instance.CreatePlayer(0, Mathf.CeilToInt(7.5f), PlayerControl.LocalPlayer.Data, false);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.OnDestroy))]
|
||||
public static void GameBeginPatch()
|
||||
{
|
||||
CustomGameModeManager.ActiveMode?.Initialize();
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public static class RoleSettingMenuPatches
|
||||
__instance.advancedSettingChildren.Clear();
|
||||
|
||||
float num = -0.872f;
|
||||
foreach (var option in GameSettingMenuPatches.SelectedMod.Options.Where(option => option.AdvancedRole == role.GetType()))
|
||||
foreach (var option in GameSettingMenuPatches.SelectedMod.Options.Where(option => option.AdvancedRole != null && option.AdvancedRole == role.GetType()))
|
||||
{
|
||||
OptionBehaviour newOpt = option.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.AdvancedRolesSettings.transform);
|
||||
newOpt.transform.localPosition = new Vector3(2.17f, num, -2f);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
@@ -13,13 +15,12 @@ public static class NameTagPatch
|
||||
[HarmonyPatch(nameof(PlayerNameColor.Get), typeof(RoleBehaviour))]
|
||||
public static bool GetPatch([HarmonyArgument(0)] RoleBehaviour otherPlayerRole, ref Color __result)
|
||||
{
|
||||
if (PlayerControl.LocalPlayer.Data.IsDead)
|
||||
if (PlayerControl.LocalPlayer.Data.Role.IsImpostor && otherPlayerRole.IsImpostor)
|
||||
{
|
||||
__result = otherPlayerRole.NameColor;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PlayerControl.LocalPlayer.Data.Role.IsImpostor && otherPlayerRole.IsImpostor)
|
||||
if (GameManager.Instance.IsHideAndSeek())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ public class MiraPluginManager
|
||||
{
|
||||
IModdedOption option = (IModdedOption)property.GetValue(group);
|
||||
option.Group = group;
|
||||
option.AdvancedRole = group.AdvancedRole;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user