Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
XtraCube committed Sep 5, 2024
2 parents c8c6ab1 + 400ad53 commit 76ddfa4
Show file tree
Hide file tree
Showing 83 changed files with 1,513 additions and 863 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{cs,vb}]
dotnet_diagnostic.CA1707.severity = none
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>

<VersionPrefix>0.1.4</VersionPrefix>
<VersionPrefix>0.1.5</VersionPrefix>
<VersionSuffix>dev</VersionSuffix>

<Authors>All Of Us, XtraCube, Angxl</Authors>
Expand Down
8 changes: 5 additions & 3 deletions MiraAPI.Example/Buttons/Freezer/FreezeButton.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using MiraAPI.Example.Modifiers.Freezer;
using MiraAPI.Example.Options.Roles;
using MiraAPI.Example.Roles;
using MiraAPI.GameOptions;
using MiraAPI.Hud;
using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
Expand All @@ -11,9 +13,9 @@ namespace MiraAPI.Example.Buttons.Freezer;
public class FreezeButton : CustomActionButton<PlayerControl>
{
public override string Name => "Freeze";
public override float Cooldown => 5f;
public override float Cooldown => OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeDuration;
public override float EffectDuration => 0f;
public override int MaxUses => 0;
public override int MaxUses => (int)OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeUses;
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;

protected override void OnClick()
Expand All @@ -23,7 +25,7 @@ protected override void OnClick()

public override PlayerControl? GetTarget()
{
return PlayerControl.LocalPlayer.GetClosestPlayer(true, Distance, false);
return PlayerControl.LocalPlayer.GetClosestPlayer(true, Distance);
}

public override void SetOutline(bool active)
Expand Down
4 changes: 2 additions & 2 deletions MiraAPI.Example/Buttons/Teleporter/TeleportButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TeleportButton : CustomActionButton
{
public override string Name => "Teleport";

public override float Cooldown => OptionGroupSingleton<TeleporterOptions>.Instance.TeleportCooldown;
public override float Cooldown => OptionGroupSingleton<TeleporterOptions>.Instance.TeleportCooldown.Value;

public override float EffectDuration => OptionGroupSingleton<TeleporterOptions>.Instance.TeleportDuration;

Expand All @@ -22,7 +22,7 @@ public class TeleportButton : CustomActionButton
public override LoadableAsset<Sprite> Sprite => ExampleAssets.TeleportButton;
public static bool IsZoom { get; private set; }

public override bool Enabled(RoleBehaviour role)
public override bool Enabled(RoleBehaviour? role)
{
return role is TeleporterRole;
}
Expand Down
4 changes: 2 additions & 2 deletions MiraAPI.Example/ExampleAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class ExampleAssets
{
public static LoadableResourceAsset ExampleButton { get; } = new("MiraAPI.Example.Resources.ExampleButton.png");

// Credit to EpicHorrors for the teleport button asset.
// Credit to EpicHorrors for the teleport button asset.
public static LoadableResourceAsset TeleportButton { get; } = new("MiraAPI.Example.Resources.TeleportButton.png");
public static LoadableResourceAsset Banner { get; } = new("MiraAPI.Example.Resources.FortniteBanner.jpeg");
}
}
6 changes: 3 additions & 3 deletions MiraAPI.Example/ExampleColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace MiraAPI.Example;
[RegisterCustomColors]
public static class ExampleColors
{
public static CustomColor Cerulean { get; } = new("Cerulean", new Color(0.0f, 0.48f, 0.65f));
public static CustomColor Cerulean { get; } = new("Cerulean", new Color(0.0f, 0.48f, 0.65f));

public static CustomColor Rose { get; } = new("Rose", new Color(0.98f, 0.26f, 0.62f));

public static CustomColor Gold { get; } = new("Gold", new Color(1.0f, 0.84f, 0.0f));
}
}
24 changes: 11 additions & 13 deletions MiraAPI.Example/MiraDebugWindow.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
using Reactor.Utilities.Attributes;
using System;
using Il2CppInterop.Runtime.Attributes;
using Reactor.Utilities.Attributes;
using Reactor.Utilities.ImGui;
using System;
using UnityEngine;

namespace MiraAPI.Example;

[RegisterInIl2Cpp]
public class MiraDebugWindow(IntPtr ptr) : MonoBehaviour(ptr)
public class MiraDebugWindow(IntPtr cppPtr) : MonoBehaviour(cppPtr)
{
public readonly DragWindow DebuggingWindow = new(new Rect(10, 10, 0, 0), "MIRA API DEBUGGING", () =>
{
if (GUILayout.Button("Test modifier"))
{
//PlayerControl.LocalPlayer.AddModifier<ModifierTimerExample>();
}
if (GUILayout.Button("Remove modifier"))
[HideFromIl2Cpp]
public DragWindow DebuggingWindow { get; } = new(
new Rect(10, 10, 0, 0),
"MIRA API DEBUGGING",
() =>
{
//PlayerControl.LocalPlayer.RemoveModifier<ModifierTimerExample>();
}
})
})
{
Enabled = true,
};
Expand Down
2 changes: 2 additions & 0 deletions MiraAPI.Example/Options/ExampleOptions2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class ExampleOptions2 : AbstractOptionGroup
{
public override string GroupName => "Example Options 2";

public override uint GroupPriority => 0; // This group will be displayed first. The default value is uint.MaxValue.

public ModdedToggleOption ToggleOpt1 { get; } = new("Toggle Option 1", false);

public ModdedToggleOption ToggleOpt2 { get; } = new("Toggle Option 2", false)
Expand Down
16 changes: 0 additions & 16 deletions MiraAPI.Example/Options/Roles/CustomRole2Settings.cs

This file was deleted.

20 changes: 20 additions & 0 deletions MiraAPI.Example/Options/Roles/FreezerRoleSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using MiraAPI.Example.Roles;
using MiraAPI.GameOptions;
using MiraAPI.GameOptions.Attributes;
using System;
using MiraAPI.Utilities;

namespace MiraAPI.Example.Options.Roles;

public class FreezerRoleSettings : AbstractOptionGroup
{
public override string GroupName => "Custom Role";

public override Type AdvancedRole => typeof(FreezerRole);

[ModdedNumberOption("Freeze Duration", 1, 15, 1, MiraNumberSuffixes.Seconds)]
public float FreezeDuration { get; set; } = 5;

[ModdedNumberOption("Freeze Uses", 1, 5)]
public float FreezeUses { get; set; } = 1;
}
8 changes: 4 additions & 4 deletions MiraAPI.Example/Options/Roles/TeleporterOptions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using MiraAPI.Example.Roles;
using System;
using MiraAPI.Example.Roles;
using MiraAPI.GameOptions;
using MiraAPI.GameOptions.Attributes;
using MiraAPI.GameOptions.OptionTypes;
using MiraAPI.Utilities;
using System;

namespace MiraAPI.Example.Options.Roles;

Expand All @@ -12,8 +13,7 @@ public class TeleporterOptions : AbstractOptionGroup

public override Type AdvancedRole => typeof(TeleporterRole);

[ModdedNumberOption("Teleport Cooldown", 5, 60, 2.5f, MiraNumberSuffixes.Seconds)]
public float TeleportCooldown { get; set; } = 5;
public ModdedNumberOption TeleportCooldown { get; set; } = new("Teleport Cooldown", 10, 5, 60, 2.5f, MiraNumberSuffixes.Seconds);

[ModdedNumberOption("Teleport Duration", 5, 25, 1, MiraNumberSuffixes.Seconds)]
public float TeleportDuration { get; set; } = 10;
Expand Down
46 changes: 46 additions & 0 deletions MiraAPI.Example/Roles/ChameleonRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using MiraAPI.Roles;
using MiraAPI.Utilities.Assets;
using TMPro;
using UnityEngine;

namespace MiraAPI.Example.Roles;

[RegisterCustomRole]
public class ChameloenRole : CrewmateRole, ICustomRole
{
public string RoleName => "Chamelon";
public string RoleLongDescription => "Stay invisible while not moving.";
public string RoleDescription => RoleLongDescription;
public Color RoleColor => Palette.AcceptedGreen;
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
public int MaxPlayers => 2;

public void PlayerControlFixedUpdate(PlayerControl playerControl)
{
if (playerControl.MyPhysics.Velocity.magnitude > 0)
{
SpriteRenderer rend = playerControl.cosmetics.currentBodySprite.BodySprite;
TextMeshPro tmp = playerControl.cosmetics.nameText;
tmp.color = Color.Lerp(tmp.color, new Color(tmp.color.r, tmp.color.g, tmp.color.b, 1), Time.deltaTime * 4f);
rend.color = Color.Lerp(rend.color, new Color(1, 1, 1, 1), Time.deltaTime * 4f);

foreach (var cosmetic in playerControl.cosmetics.transform.GetComponentsInChildren<SpriteRenderer>())
{
cosmetic.color = Color.Lerp(cosmetic.color, new Color(1, 1, 1, 1), Time.deltaTime * 4f);
}
}
else
{
SpriteRenderer rend = playerControl.cosmetics.currentBodySprite.BodySprite;
TextMeshPro tmp = playerControl.cosmetics.nameText;
tmp.color = Color.Lerp(tmp.color, new Color(tmp.color.r, tmp.color.g, tmp.color.b, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f);
rend.color = Color.Lerp(rend.color, new Color(1, 1, 1, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f);

foreach (var cosmetic in playerControl.cosmetics.transform.GetComponentsInChildren<SpriteRenderer>())
{
cosmetic.color = Color.Lerp(cosmetic.color, new Color(1, 1, 1, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f);
}
}
}
}
27 changes: 27 additions & 0 deletions MiraAPI.Example/Roles/NeutralKillerRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using MiraAPI.Roles;
using UnityEngine;

namespace MiraAPI.Example.Roles;

[RegisterCustomRole]
public class NeutralKillerRole : ImpostorRole, ICustomRole
{
public string RoleName => "Neutral Killer";
public string RoleDescription => "Neutral who can kill.";
public string RoleLongDescription => RoleDescription;
public Color RoleColor => Color.magenta;
public ModdedRoleTeams Team => ModdedRoleTeams.Neutral;
public bool UseVanillaKillButton => true;
public bool CanGetKilled => true;
public bool CanUseVent => true;

public override void SpawnTaskHeader(PlayerControl playerControl)
{
// remove existing task header.
}

public override bool DidWin(GameOverReason gameOverReason)
{
return GameManager.Instance.DidHumansWin(gameOverReason);
}
}
18 changes: 9 additions & 9 deletions MiraAPI/GameModes/CustomGameModeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
namespace MiraAPI.GameModes;

/// <summary>
/// Manages custom gamemodes
/// Manages custom gamemodes.
/// </summary>
public static class CustomGameModeManager
{
/// <summary>
/// List of registered gamemodes
/// List of registered gamemodes.
/// </summary>
internal static readonly Dictionary<int, CustomGameMode> GameModes = [];

Expand All @@ -21,14 +21,14 @@ public static bool IsDefault()
}

/// <summary>
/// Current gamemode
/// Current gamemode.
/// </summary>
public static CustomGameMode? ActiveMode { get; internal set; } = new DefaultMode();

/// <summary>
/// Set current gamemode
/// Set current gamemode.
/// </summary>
/// <param name="id">gamemode ID</param>
/// <param name="id">gamemode ID.</param>
public static void SetGameMode(int id)
{
if (GameModes.TryGetValue(id, out var gameMode))
Expand All @@ -41,9 +41,9 @@ public static void SetGameMode(int id)
}

/// <summary>
/// Register gamemode from type
/// Register gamemode from type.
/// </summary>
/// <param name="gameModeType">Type of gamemode class, should inherit from <see cref="CustomGameMode"/></param>
/// <param name="gameModeType">Type of gamemode class, should inherit from <see cref="CustomGameMode"/>.</param>
internal static void RegisterGameMode(Type gameModeType)
{
if (!typeof(CustomGameMode).IsAssignableFrom(gameModeType))
Expand All @@ -59,7 +59,7 @@ internal static void RegisterGameMode(Type gameModeType)
Logger<MiraApiPlugin>.Error($"Failed to create instance of {gameModeType.Name}");
return;
}

if (GameModes.Any(x => x.Key == gameMode.Id))
{
Logger<MiraApiPlugin>.Error($"ID for gamemode {gameMode.Name} already exists!");
Expand All @@ -68,4 +68,4 @@ internal static void RegisterGameMode(Type gameModeType)

GameModes.Add(gameMode.Id, gameMode);
}
}
}
2 changes: 1 addition & 1 deletion MiraAPI/GameModes/DefaultMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public class DefaultMode : CustomGameMode
public override string Name => "Default";

Check warning on line 6 in MiraAPI/GameModes/DefaultMode.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DefaultMode.Name'

Check warning on line 6 in MiraAPI/GameModes/DefaultMode.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DefaultMode.Name'
public override string Description => "Default Among Us GameMode";

Check warning on line 7 in MiraAPI/GameModes/DefaultMode.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DefaultMode.Description'

Check warning on line 7 in MiraAPI/GameModes/DefaultMode.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DefaultMode.Description'
public override int Id => 0;

Check warning on line 8 in MiraAPI/GameModes/DefaultMode.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DefaultMode.Id'

Check warning on line 8 in MiraAPI/GameModes/DefaultMode.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DefaultMode.Id'
}
}
2 changes: 1 addition & 1 deletion MiraAPI/GameModes/RegisterGameModeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ internal static void Register(Assembly assembly)
}
}
}
}
}
6 changes: 6 additions & 0 deletions MiraAPI/GameOptions/AbstractOptionGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public abstract class AbstractOptionGroup
/// </summary>
public virtual Color GroupColor => Color.clear;

/// <summary>
/// Gets the group priority. This is used to determine the order in which groups are displayed in the options menu.
/// Zero is the highest priority, and the default value is the max uint value.
/// </summary>
public virtual uint GroupPriority => uint.MaxValue;

/// <summary>
/// Gets the role the group is associated with. This is used for the advanced role options menu.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion MiraAPI/GameOptions/IModdedOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal interface IModdedOption
OptionBehaviour? OptionBehaviour { get; }
Func<bool> Visible { get; set; }
ConfigDefinition? ConfigDefinition { get; set; }
OptionBehaviour? CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container);
OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container);
float GetFloatData();
NetData GetNetData();
void HandleNetData(byte[] data);
Expand Down
6 changes: 3 additions & 3 deletions MiraAPI/GameOptions/ModdedOptionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace MiraAPI.GameOptions;
/// </summary>
public static class ModdedOptionsManager
{
private static readonly Dictionary<PropertyInfo, ModdedOptionAttribute> OptionAttributes = new();
private static readonly Dictionary<Type, AbstractOptionGroup> TypeToGroup = new();
private static readonly Dictionary<PropertyInfo, ModdedOptionAttribute> OptionAttributes = [];
private static readonly Dictionary<Type, AbstractOptionGroup> TypeToGroup = [];

internal static readonly Dictionary<uint, IModdedOption> ModdedOptions = new();
internal static readonly Dictionary<uint, IModdedOption> ModdedOptions = [];
internal static readonly List<AbstractOptionGroup> Groups = [];

internal static uint NextId => _nextId++;
Expand Down
8 changes: 4 additions & 4 deletions MiraAPI/GameOptions/OptionGroupSingleton.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System;
using System.Linq;
using System.Linq;

namespace MiraAPI.GameOptions;

/// <summary>
/// Singleton for option groups.
/// </summary>
/// <typeparam name="T">The option group type.</typeparam>
public class OptionGroupSingleton<T> where T : AbstractOptionGroup
public static class OptionGroupSingleton<T> where T : AbstractOptionGroup
{
private static T? _instance;

/// <summary>
/// Gets the instance of the option group.
/// </summary>
/// <exception cref="InvalidOperationException">Can't</exception>
#pragma warning disable CA1000
public static T Instance => _instance ??= ModdedOptionsManager.Groups.OfType<T>().Single();
#pragma warning restore CA1000
}
Loading

0 comments on commit 76ddfa4

Please sign in to comment.