mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-22 15:41:08 +00:00
Compare commits
190
Commits
0.4.1
...
dev-update
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e901abfc60 | ||
|
|
853a94681a | ||
|
|
f230cff5e5 | ||
|
|
7c7d184d1f | ||
|
|
6b923cfe01 | ||
|
|
247c765176 | ||
|
|
a3668b3150 | ||
|
|
aa4dd24ac3 | ||
|
|
cb0afe3095 | ||
|
|
883222be82 | ||
|
|
6b774500dd | ||
|
|
f96f75cea1 | ||
|
|
75662a6c25 | ||
|
|
73e4506016 | ||
|
|
a491592669 | ||
|
|
01fef0f747 | ||
|
|
e22f4daf3e | ||
|
|
b83cb5cc29 | ||
|
|
fb164a54e3 | ||
|
|
b6475161f1 | ||
|
|
c7f3f9d5da | ||
|
|
5d54a0c2d3 | ||
|
|
cf1a75f5ea | ||
|
|
721bd20d2b | ||
|
|
0e3b6be5be | ||
|
|
411340d9e9 | ||
|
|
57d2a6a9b5 | ||
|
|
6f61a75bb7 | ||
|
|
06c746c632 | ||
|
|
95819cf83a | ||
|
|
d1d11e2bec | ||
|
|
b4ed14f7f2 | ||
|
|
951af42358 | ||
|
|
27e14488af | ||
|
|
9ab87955bb | ||
|
|
0141dfdea4 | ||
|
|
cd97fab3a2 | ||
|
|
3cd8db1f04 | ||
|
|
535967475d | ||
|
|
6fd5993959 | ||
|
|
b713599c13 | ||
|
|
f44ec15804 | ||
|
|
847a4dd287 | ||
|
|
83d55d409b | ||
|
|
7a00ea9174 | ||
|
|
22716b29ab | ||
|
|
43291bda50 | ||
|
|
d4a675f2a9 | ||
|
|
00c5c5c4ff | ||
|
|
abb6f3d161 | ||
|
|
eef098317e | ||
|
|
1c097b47df | ||
|
|
6fe2750545 | ||
|
|
a57f40fa79 | ||
|
|
54bfd3002b | ||
|
|
4c38189444 | ||
|
|
14ce020208 | ||
|
|
877fc15aec | ||
|
|
2160d1d823 | ||
|
|
4d187f3f79 | ||
|
|
4e37f8b3d4 | ||
|
|
015d175aa0 | ||
|
|
ca7da0c343 | ||
|
|
72fa908cb0 | ||
|
|
58067d9f21 | ||
|
|
b8b85e2bc3 | ||
|
|
043845ee11 | ||
|
|
df7c182abb | ||
|
|
2a4d16e65e | ||
|
|
9606871cbe | ||
|
|
ae45c506cb | ||
|
|
fd01273635 | ||
|
|
840761787f | ||
|
|
615d527c86 | ||
|
|
7628a41d86 | ||
|
|
121baeb178 | ||
|
|
0cf4954eaf | ||
|
|
8f403f5408 | ||
|
|
2f5c382ece | ||
|
|
1ab0c3f4a7 | ||
|
|
0230d98642 | ||
|
|
04b7a9905d | ||
|
|
317e0b6ea9 | ||
|
|
cbe44a40d0 | ||
|
|
d5c3905684 | ||
|
|
49d16b707c | ||
|
|
3eb5bfae01 | ||
|
|
b1293081fc | ||
|
|
83751a25a9 | ||
|
|
bd58fca7bd | ||
|
|
63d1003b2b | ||
|
|
0645c32cca | ||
|
|
8beabb20a2 | ||
|
|
3f28d70308 | ||
|
|
b919c55ef1 | ||
|
|
55a2161876 | ||
|
|
4ca2249fbd | ||
|
|
fc94c8e67e | ||
|
|
83e550c1f2 | ||
|
|
edee889ffe | ||
|
|
119d4c5152 | ||
|
|
c99f468abf | ||
|
|
adde6db1d0 | ||
|
|
0012fe8cd6 | ||
|
|
9148a1e8da | ||
|
|
8c5aee4beb | ||
|
|
30a39fa223 | ||
|
|
228ed9711a | ||
|
|
7c085b1072 | ||
|
|
8750e5c894 | ||
|
|
1b40b1c5e4 | ||
|
|
0a0ad74419 | ||
|
|
992bdbcbf8 | ||
|
|
f9721a8d69 | ||
|
|
e541840da9 | ||
|
|
eb18d82d8e | ||
|
|
7afd899e56 | ||
|
|
5cccc192b1 | ||
|
|
9d7e41a3c9 | ||
|
|
662b52f78d | ||
|
|
dac1d82d5c | ||
|
|
1b718092ee | ||
|
|
3eb0a4fdb3 | ||
|
|
850e82155c | ||
|
|
ff30d5fdd6 | ||
|
|
2eecba2e51 | ||
|
|
84321f290e | ||
|
|
25a55b1b60 | ||
|
|
af2cc9a3c1 | ||
|
|
e9730f018d | ||
|
|
1d316bb02f | ||
|
|
2eac3d04f1 | ||
|
|
154b50fd76 | ||
|
|
390e4c1157 | ||
|
|
35b444854a | ||
|
|
8e5028c236 | ||
|
|
ad113a47ab | ||
|
|
59b8e92c48 | ||
|
|
d313089521 | ||
|
|
0852f769ae | ||
|
|
ae4b4d872b | ||
|
|
b33a66cbd9 | ||
|
|
ac87003d0a | ||
|
|
f7de7f127d | ||
|
|
e095e2da6a | ||
|
|
50cb8ffc3d | ||
|
|
4f4b880ad4 | ||
|
|
b627006ba1 | ||
|
|
b0ceb129a4 | ||
|
|
bf7c800613 | ||
|
|
990bac4c06 | ||
|
|
08c6883a0d | ||
|
|
3066720e6e | ||
|
|
af363000c7 | ||
|
|
77c13bebdc | ||
|
|
00eaa2601c | ||
|
|
ba2deb66f1 | ||
|
|
bb5c212e97 | ||
|
|
f59e0af7e8 | ||
|
|
8f3a137877 | ||
|
|
44415019cc | ||
|
|
7125374cda | ||
|
|
cff46ebd19 | ||
|
|
8b19271e34 | ||
|
|
c29e882d7e | ||
|
|
fdfb876b44 | ||
|
|
205eee96b2 | ||
|
|
8774c9da70 | ||
|
|
51c7e248f9 | ||
|
|
02f9c20804 | ||
|
|
7890ec9456 | ||
|
|
8bb191270f | ||
|
|
65cd177551 | ||
|
|
7801f81052 | ||
|
|
2d59b29c15 | ||
|
|
a62c75a13b | ||
|
|
c85cf7ef2f | ||
|
|
ead28339b0 | ||
|
|
9177d5b456 | ||
|
|
284a0f58b1 | ||
|
|
47dfa63423 | ||
|
|
1b261d7287 | ||
|
|
fa8ea9dbab | ||
|
|
9c15ca4d06 | ||
|
|
a4b1868690 | ||
|
|
409503a261 | ||
|
|
edca42247d | ||
|
|
b6ba8f59bd | ||
|
|
f9f7898277 | ||
|
|
dbacd044eb |
No files matched your search
+2
-2
@@ -2,7 +2,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Reactor" Version="2.5.0-ci.371" />
|
||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.735" Private="false" ExcludeAssets="runtime;native" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2026.3.31" PrivateAssets="all" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2026.8.18" PrivateAssets="all" />
|
||||
|
||||
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
|
||||
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.1.0-rc.1" PrivateAssets="all" ExcludeAssets="runtime" />
|
||||
@@ -11,4 +11,4 @@
|
||||
<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
|
||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUs)/BepInEx/plugins/" UseSymboliclinksIfPossible="true" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
|
||||
<VersionPrefix>0.4.1</VersionPrefix>
|
||||
<VersionPrefix>0.4.3</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
using System.Linq;
|
||||
using BepInEx;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor;
|
||||
using Reactor.Networking;
|
||||
using Reactor.Networking.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
|
||||
@@ -19,6 +20,7 @@ public partial class ExamplePlugin : BasePlugin, IMiraPlugin
|
||||
{
|
||||
public Harmony Harmony { get; } = new(Id);
|
||||
public string OptionsTitleText => "Mira API\nExample Mod";
|
||||
public string CustomOptionMenuNameTwo => "angxl's Options";
|
||||
public ConfigFile GetConfigFile() => Config;
|
||||
public override void Load()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.GameModes;
|
||||
|
||||
public class ExampleMode : AbstractGameMode
|
||||
{
|
||||
public override string Name => "Example Mode";
|
||||
public override string Description => "An example gamemode.";
|
||||
public override LoadableAsset<Sprite>? Icon => ExampleAssets.ExampleButton;
|
||||
public override Color Color => Color.red;
|
||||
}
|
||||
@@ -10,6 +10,8 @@ public class ExampleOptions2 : AbstractOptionGroup
|
||||
|
||||
public override uint GroupPriority => 0; // This group will be displayed first. The default value is uint.MaxValue.
|
||||
|
||||
public override MenuCategory ParentMenu => MenuCategory.CustomTwo;
|
||||
|
||||
public ModdedPlayerOption PlayerOption2 { get; } = new("YOU MUST CHOSE A PLAYER", false);
|
||||
public ModdedPlayerOption PlayerOption { get; } = new("Eh whatever");
|
||||
public ModdedToggleOption ToggleOpt1 { get; } = new("Toggle Option 1", false);
|
||||
|
||||
@@ -9,7 +9,7 @@ public class GeneralModifierOptions : AbstractOptionGroup
|
||||
|
||||
public override uint GroupPriority => 0;
|
||||
|
||||
public override bool ShowInModifiersMenu => true;
|
||||
public override MenuCategory ParentMenu => MenuCategory.Modifiers;
|
||||
|
||||
[ModdedToggleOption("Some Boolean Option")]
|
||||
public bool SomeBooleanOption { get; set; } = true;
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
|
||||
namespace MiraAPI.Example.Options.Roles;
|
||||
|
||||
public class FreezerRoleSettings : AbstractOptionGroup<FreezerRole>
|
||||
{
|
||||
public override OptionNotifConfiguration Configuration => new(
|
||||
Palette.Blue,
|
||||
TmpSpriteUtils.CreateSpriteAsset(
|
||||
MiraAssets.ImpostorFile.LoadAsset(),
|
||||
"ApiExample.Role.Impostor.FreezerRole"));
|
||||
public override string GroupName => "Custom Role";
|
||||
|
||||
[ModdedNumberOption("Freeze Duration", 1, 15, 1, MiraNumberSuffixes.Seconds)]
|
||||
|
||||
@@ -6,7 +6,7 @@ using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Example.Options.Roles;
|
||||
|
||||
public class TeleporterOptions : AbstractOptionGroup<TeleporterRole>
|
||||
public class TeleporterOptions : AbstractRoleOptionGroup<TeleporterRole>
|
||||
{
|
||||
public override string GroupName => "Teleporter";
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Patches.Stubs;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -20,6 +21,8 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
public CustomRoleConfiguration Configuration => new(this)
|
||||
{
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
Icon = MiraAssets.CrewmateFile,
|
||||
IconTmp = TmpSpriteUtils.CreateSpriteAsset(MiraAssets.CrewmateFile.LoadAsset(), "ApiExample.Role.Impostor.ChameleonRole"),
|
||||
IntroSound = CustomRoleUtils.GetIntroSound(RoleTypes.Shapeshifter),
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
@@ -13,6 +14,8 @@ public class FreezerRole : ImpostorRole, ICustomRole
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
{
|
||||
Icon = MiraAssets.ImpostorFile,
|
||||
IconTmp = TmpSpriteUtils.CreateSpriteAsset(MiraAssets.ImpostorFile.LoadAsset(), "ApiExample.Role.Impostor.FreezerRole"),
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
MaxRoleCount = 2,
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace MiraAPI.Events.Mira;
|
||||
/// Button click event for <see cref="CustomActionButton"/>s only. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The <see cref="CustomActionButton"/> type.</typeparam>
|
||||
public sealed class MiraButtonClickEvent<T> : MiraCancelableEvent where T : CustomActionButton
|
||||
public class MiraButtonClickEvent<T> : MiraCancelableEvent where T : CustomActionButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CustomActionButton"/> that was clicked.
|
||||
@@ -33,7 +33,7 @@ public sealed class MiraButtonClickEvent<T> : MiraCancelableEvent where T : Cust
|
||||
/// <summary>
|
||||
/// Button click event for <see cref="CustomActionButton"/>s only. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </summary>
|
||||
public sealed class MiraButtonClickEvent : MiraCancelableEvent
|
||||
public class MiraButtonClickEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CustomActionButton"/> that was clicked.
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
namespace MiraAPI.Events;
|
||||
using MiraAPI.PluginLoading;
|
||||
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Abstract class for Mira Events that can be cancelled.
|
||||
/// </summary>
|
||||
[MiraIgnore]
|
||||
public abstract class MiraCancelableEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace MiraAPI.Events;
|
||||
using MiraAPI.PluginLoading;
|
||||
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Abstract class for Mira Events.
|
||||
/// </summary>
|
||||
[MiraIgnore]
|
||||
public abstract class MiraEvent;
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
|
||||
@@ -16,20 +16,76 @@ public class AfterMurderEvent : MiraEvent
|
||||
public PlayerControl Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Target"/>'s <see cref="global::DeadBody"/>, if it exists.
|
||||
/// Gets the <see cref="PlayerControl"/> that was framed, if any.
|
||||
/// </summary>
|
||||
public PlayerControl? Framed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the murder was done indirectly.
|
||||
/// This is commonly used to prevent the <see cref="Source"/> <see cref="PlayerControl"/> from being killed.
|
||||
/// </summary>
|
||||
public bool IsIndirectAttack { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the murder was able to bypass protective roles or general defense, such as <see cref="GuardianAngelRole"/>.
|
||||
/// </summary>
|
||||
public bool IgnoreDefense { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Target"/>'s <see cref="DeadBody"/>, if it exists.
|
||||
/// </summary>
|
||||
public DeadBody? DeadBody { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AfterMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The killed <see cref="PlayerControl"/>.</param>
|
||||
/// <param name="deadBody">The <paramref name="target"/>'s <see cref="global::DeadBody"/>, if it exists.</param>
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that killed the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that was killed.</param>
|
||||
/// <param name="deadBody">The <paramref name="target"/>'s <see cref="DeadBody"/>, if it exists.</param>
|
||||
/// <param name="isIndirect">Whether the murder was caused indirectly.</param>
|
||||
/// <param name="ignoreDefense">Whether the murder ignored protection.</param>
|
||||
public AfterMurderEvent(PlayerControl source, PlayerControl target, DeadBody? deadBody, bool isIndirect, bool ignoreDefense = false)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
Framed = null;
|
||||
DeadBody = deadBody;
|
||||
IsIndirectAttack = isIndirect;
|
||||
IgnoreDefense = ignoreDefense;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AfterMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that killed the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that was killed.</param>
|
||||
/// <param name="framed">The <see cref="PlayerControl"/> that was framed.</param>
|
||||
/// <param name="deadBody">The <paramref name="target"/>'s <see cref="DeadBody"/>, if it exists.</param>
|
||||
/// <param name="isIndirect">Whether the murder was caused indirectly.</param>
|
||||
/// <param name="ignoreDefense">Whether the murder ignored protection.</param>
|
||||
public AfterMurderEvent(PlayerControl source, PlayerControl target, PlayerControl framed, DeadBody? deadBody, bool isIndirect = true, bool ignoreDefense = false)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
Framed = framed;
|
||||
DeadBody = deadBody;
|
||||
IsIndirectAttack = isIndirect;
|
||||
IgnoreDefense = ignoreDefense;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AfterMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that killed the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that was killed.</param>
|
||||
/// <param name="deadBody">The <paramref name="target"/>'s <see cref="DeadBody"/>, if it exists.</param>
|
||||
public AfterMurderEvent(PlayerControl source, PlayerControl target, DeadBody? deadBody)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
Framed = null;
|
||||
DeadBody = deadBody;
|
||||
IsIndirectAttack = false;
|
||||
IgnoreDefense = false;
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,64 @@ public sealed class BeforeMurderEvent : MiraCancelableEvent
|
||||
/// </summary>
|
||||
public PlayerControl Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PlayerControl"/> that is being framed, if any.
|
||||
/// </summary>
|
||||
public PlayerControl? Framed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the murder is done indirectly.
|
||||
/// This is commonly used to prevent the <see cref="Source"/> <see cref="PlayerControl"/> from being killed.
|
||||
/// </summary>
|
||||
public bool IsIndirectAttack { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the murder should bypass protective roles or general defense, such as <see cref="GuardianAngelRole"/>.
|
||||
/// </summary>
|
||||
public bool IgnoreDefense { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the murder was meant to be done in a meeting, via an enum.
|
||||
/// </summary>
|
||||
public MeetingCheck InMeeting { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that is killing the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that is being killed.</param>
|
||||
/// <param name="isIndirect">Whether the murder is caused indirectly.</param>
|
||||
/// <param name="ignoreDefense">Whether the murder should ignore protection.</param>
|
||||
/// <param name="inMeeting">Whether the murder is intended to be triggered in a meeting.</param>
|
||||
public BeforeMurderEvent(PlayerControl source, PlayerControl target, bool isIndirect, bool ignoreDefense = false, MeetingCheck inMeeting = MeetingCheck.Ignore)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
Framed = null;
|
||||
IsIndirectAttack = isIndirect;
|
||||
IgnoreDefense = ignoreDefense;
|
||||
InMeeting = inMeeting;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that is killing the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that is being killed.</param>
|
||||
/// <param name="framed">The <see cref="PlayerControl"/> that is being framed.</param>
|
||||
/// <param name="isIndirect">Whether the murder is caused indirectly.</param>
|
||||
/// <param name="ignoreDefense">Whether the murder should ignore protection.</param>
|
||||
/// <param name="inMeeting">Whether the murder is intended to be triggered in a meeting.</param>
|
||||
public BeforeMurderEvent(PlayerControl source, PlayerControl target, PlayerControl framed, bool isIndirect = true, bool ignoreDefense = false, MeetingCheck inMeeting = MeetingCheck.Ignore)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
Framed = framed;
|
||||
IsIndirectAttack = isIndirect;
|
||||
IgnoreDefense = ignoreDefense;
|
||||
InMeeting = inMeeting;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeMurderEvent"/> class.
|
||||
/// </summary>
|
||||
@@ -32,6 +85,9 @@ public sealed class BeforeMurderEvent : MiraCancelableEvent
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
Framed = null;
|
||||
IsIndirectAttack = false;
|
||||
IgnoreDefense = false;
|
||||
InMeeting = inMeeting;
|
||||
}
|
||||
|
||||
@@ -44,6 +100,9 @@ public sealed class BeforeMurderEvent : MiraCancelableEvent
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
Framed = null;
|
||||
IsIndirectAttack = false;
|
||||
IgnoreDefense = false;
|
||||
InMeeting = MeetingCheck.Ignore;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using MiraAPI.Voting;
|
||||
|
||||
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked after the local player successfully votes a player or skips. This event is not cancelable.
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using MiraAPI.Voting;
|
||||
|
||||
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked before the local player confirms a vote on a player or when skipping. This event is cancelable.
|
||||
|
||||
@@ -25,15 +25,20 @@ public class HandleVoteEvent : MiraCancelableEvent
|
||||
public byte TargetId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether to prevent the vote from commencing.
|
||||
/// Gets or sets a value indicating whether to prevent the vote from commencing.
|
||||
/// </summary>
|
||||
public bool PreventVote { get; }
|
||||
public bool PreventVote { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="NetworkedPlayerInfo"/> of the target.
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo TargetPlayerInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the vote event is an Overrule caused by a Judge.
|
||||
/// </summary>
|
||||
public bool IsOverruling { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HandleVoteEvent"/> class.
|
||||
/// </summary>
|
||||
@@ -47,4 +52,20 @@ public class HandleVoteEvent : MiraCancelableEvent
|
||||
PreventVote = false;
|
||||
TargetPlayerInfo = GameData.Instance.GetPlayerById(targetId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HandleVoteEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteData">The voter's <see cref="PlayerVoteData"/>.</param>
|
||||
/// <param name="targetId">The target's playerId.</param>
|
||||
/// <param name="isOverruling">Whether the vote is actually for a Judge.</param>
|
||||
public HandleVoteEvent(PlayerVoteData playerVoteData, byte targetId, bool isOverruling)
|
||||
{
|
||||
VoteData = playerVoteData;
|
||||
Player = playerVoteData.Owner;
|
||||
TargetId = targetId;
|
||||
PreventVote = false;
|
||||
IsOverruling = isOverruling;
|
||||
TargetPlayerInfo = GameData.Instance.GetPlayerById(targetId);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,16 @@ public class ProcessVotesEvent(List<CustomVote> votes, NetworkedPlayerInfo? exil
|
||||
/// </summary>
|
||||
public List<CustomVote> Votes { get; } = votes;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether an overruling was done. Normally set by judge but can be overwritten.
|
||||
/// </summary>
|
||||
public bool OverruledVote { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value specifically to determine which Judge (if any) caused the overruling. Normally set by judge but can be overwritten.
|
||||
/// </summary>
|
||||
public ushort OverruledNonce { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the player to be exiled. Will be <see langword="null"/> if no player is to be exiled.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.GameEnd;
|
||||
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for custom gamemodes.
|
||||
/// </summary>
|
||||
[MiraIgnore]
|
||||
public abstract class AbstractGameMode : IOptionable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the game mode name.
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the mode is visible in the menu. Only checked at startup.
|
||||
/// </summary>
|
||||
public virtual bool HideMode => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game mode description.
|
||||
/// </summary>
|
||||
public abstract string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game mode description.
|
||||
/// </summary>
|
||||
public virtual Color Color { get; } = Color.white;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the icon of the gamemode. Will be shown in options menu underneath the gamemode option.
|
||||
/// </summary>
|
||||
public virtual LoadableAsset<Sprite>? Icon => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the icon of the gamemode for use on the options pop-up.
|
||||
/// </summary>
|
||||
public TMP_SpriteAsset TmpIcon { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the colored game mode name, using the color and name properties.
|
||||
/// </summary>
|
||||
public string ColoredName => $"<color=#{this.Color.ToHtmlStringRGBA()}>{this.Name}</color>";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game mode id.
|
||||
/// </summary>
|
||||
public uint ID { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a specific body type is used by the game mode.
|
||||
/// </summary>
|
||||
public virtual bool GameModeBodyTypeOverride => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the gamemode removes the normal game settings.
|
||||
/// </summary>
|
||||
public virtual bool ShowNormalGameSettings => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the gamemode removes the normal role settings.
|
||||
/// </summary>
|
||||
public virtual bool ShowNormalRoleSettings => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating the default kill cooldown for impostors in this mode.
|
||||
/// </summary>
|
||||
public virtual float DefaultImpostorKillCooldown => GameOptionsManager.Instance.CurrentGameOptions.GetFloat(FloatOptionNames.KillCooldown);
|
||||
|
||||
/// <summary>
|
||||
/// Called on GameManager.GetBodyType().
|
||||
/// </summary>
|
||||
/// <param name="player">Player to get body type from.</param>
|
||||
/// <returns>Resulting body type.</returns>
|
||||
public virtual PlayerBodyTypes GetBodyType(PlayerControl player)
|
||||
{
|
||||
if (AprilFoolsMode.ShouldHorseAround())
|
||||
{
|
||||
return PlayerBodyTypes.Horse;
|
||||
}
|
||||
if (AprilFoolsMode.ShouldLongAround())
|
||||
{
|
||||
return PlayerBodyTypes.Long;
|
||||
}
|
||||
return PlayerBodyTypes.Normal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a custom intro sequence is implemented by the game mode.
|
||||
/// </summary>
|
||||
public virtual bool ShowGameModeIntroCutscene => false;
|
||||
|
||||
/// <summary>
|
||||
/// Called when Intro Cutscene is destroyed.
|
||||
/// </summary>
|
||||
public virtual void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on HudManager.Start().
|
||||
/// </summary>
|
||||
/// <param name="instance">Instance of HudManager.</param>
|
||||
public virtual void HudStart(HudManager instance)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame on HudManager.Update().
|
||||
/// </summary>
|
||||
/// <param name="instance">Instance of HudManager.</param>
|
||||
public virtual void HudUpdate(HudManager instance)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a player is killed.
|
||||
/// </summary>
|
||||
/// <param name="player">PlayerControl that was killed.</param>
|
||||
/// <param name="assignGhostRole">Determines whether to assign a ghost role on the player.</param>
|
||||
public virtual void OnPlayerDeath(PlayerControl player, bool assignGhostRole)
|
||||
{
|
||||
GameManager.Instance.LogicRoleSelection.OnPlayerDeath(player, assignGhostRole);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate Game End logic.
|
||||
/// </summary>
|
||||
/// <param name="runOriginal">Should original game end logic be used.</param>
|
||||
/// <param name="instance">Instance of LogicGameFlowNormal.</param>
|
||||
public virtual void CheckGameEnd(out bool runOriginal, LogicGameFlowNormal instance)
|
||||
{
|
||||
runOriginal = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom role assignment.
|
||||
/// </summary>
|
||||
/// <param name="runOriginal">Should original role assignment be used.</param>
|
||||
/// <param name="instance">Instance of LogicRoleSelection.</param>
|
||||
public virtual void AssignRoles(out bool runOriginal, LogicRoleSelectionNormal instance)
|
||||
{
|
||||
runOriginal = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom role assignment to run after all roles are handed out.
|
||||
/// </summary>
|
||||
/// <param name="instance">Instance of LogicRoleSelection.</param>
|
||||
public virtual void PostAssignRoles(LogicRoleSelectionNormal instance)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom murder logic.
|
||||
/// </summary>
|
||||
/// <param name="runOriginal">Should the original murder logic be used.</param>
|
||||
/// <param name="result">Result of custom murder logic.</param>
|
||||
/// <param name="target">Target player for murder.</param>
|
||||
public virtual void CanKill(out bool runOriginal, out bool result, PlayerControl target)
|
||||
{
|
||||
result = false;
|
||||
runOriginal = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom winner selection.
|
||||
/// </summary>
|
||||
/// <returns>List of winners or null.</returns>
|
||||
public virtual List<NetworkedPlayerInfo>? CalculateWinners() => null;
|
||||
|
||||
/// <summary>
|
||||
/// The IEnumerator that plays the intro cutscene for this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="__instance">An instance of IntroCutscene.</param>
|
||||
/// <returns>An IEnumerator to run the intro cutscene instead of the base game one.</returns>
|
||||
public virtual IEnumerator IntroCutscene(IntroCutscene __instance)
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can Admin be used in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">Admin Console.</param>
|
||||
/// <returns>True if Admin console is enabled.</returns>
|
||||
public virtual bool CanUseMapConsole(MapConsole console) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can a body be reported in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="body">Target body for reporting.</param>
|
||||
/// <returns>True if dead bodies can be reported.</returns>
|
||||
public virtual bool CanReport(DeadBody body) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can system consoles be used in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">System Console.</param>
|
||||
/// <returns>True if system consoles are enabled in this mode.</returns>
|
||||
public virtual bool CanUseSystemConsole(SystemConsole console) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can tasks be interacted with in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">Task console.</param>
|
||||
/// <returns>True if tasks are enabled in this mode.</returns>
|
||||
public virtual bool CanUseTasks(Console console) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Should the sabotage map be used when attempting to open sabotage overlay.
|
||||
/// </summary>
|
||||
/// <param name="map">MapBehaviour object.</param>
|
||||
/// <returns>True if the sabotage map should be shown.</returns>
|
||||
public virtual bool ShouldShowSabotageMap(MapBehaviour map) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="MapOptions"/> to display on the map.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="MapOptions"/> for the gamemode.</returns>
|
||||
public virtual MapOptions GetMapOptions()
|
||||
{
|
||||
return new MapOptions
|
||||
{
|
||||
Mode = PlayerControl.LocalPlayer.Data.Role.IsImpostor && !MeetingHud.Instance
|
||||
? MapOptions.Modes.Sabotage
|
||||
: MapOptions.Modes.Normal,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can a player vent in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="vent">Target vent.</param>
|
||||
/// <param name="playerInfo">Player attempting to vent.</param>
|
||||
/// <returns>True if venting is enabled in this mode.</returns>
|
||||
public virtual bool CanVent(Vent vent, NetworkedPlayerInfo playerInfo) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Does the task bar appear in the gamemode.
|
||||
/// </summary>
|
||||
/// <returns>True if the task bar is enabled in this mode.</returns>
|
||||
public virtual bool ShowTaskBar => true;
|
||||
|
||||
public virtual void UpdateTaskPanel(TaskPanelBehaviour instance)
|
||||
{
|
||||
instance.background.transform.localScale = (instance.taskText.textBounds.size.x > 0f)
|
||||
? new Vector3(instance.taskText.textBounds.size.x + 0.2f, instance.taskText.textBounds.size.y + 0.2f, 1f)
|
||||
: Vector3.zero;
|
||||
Vector3 vector = instance.background.sprite.bounds.extents;
|
||||
vector.y = -vector.y;
|
||||
vector = vector.Mul(instance.background.transform.localScale);
|
||||
instance.background.transform.localPosition = vector;
|
||||
Vector3 vector2 = instance.tab.sprite.bounds.extents;
|
||||
vector2 = vector2.Mul(instance.tab.transform.localScale);
|
||||
vector2.y = -vector2.y;
|
||||
vector2.x += vector.x * 2f;
|
||||
instance.tab.transform.localPosition = vector2;
|
||||
if (GameManager.Instance == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var yPos = 0.6f;
|
||||
var xPos = -instance.background.sprite.bounds.size.x * instance.background.transform.localScale.x;
|
||||
instance.closedPosition = new Vector3(xPos, yPos, instance.closedPosition.z);
|
||||
instance.openPosition = new Vector3(instance.openPosition.x, yPos, instance.openPosition.z);
|
||||
if (instance.open)
|
||||
{
|
||||
instance.timer = Mathf.Min(1f, instance.timer + Time.deltaTime / instance.animationTimeSeconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.timer = Mathf.Max(0f, instance.timer - Time.deltaTime / instance.animationTimeSeconds);
|
||||
}
|
||||
|
||||
Vector3 relativePos = new(
|
||||
Mathf.SmoothStep(instance.closedPosition.x, instance.openPosition.x, instance.timer),
|
||||
yPos,
|
||||
instance.openPosition.z);
|
||||
instance.transform.localPosition =
|
||||
AspectPosition.ComputePosition(AspectPosition.EdgeAlignments.LeftTop, relativePos);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// The classic game mode.
|
||||
/// </summary>
|
||||
[MiraIgnore]
|
||||
public class ClassicMode : AbstractGameMode
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override string Name => "Classic";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string Description => "The classic Among Us experience!\nFind the Impostors or deceive the Crew.";
|
||||
|
||||
public override LoadableAsset<Sprite>? Icon => MiraAssets.ClassicGamemodeIcon;
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for custom gamemodes.
|
||||
/// </summary>
|
||||
public abstract class CustomGameMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the game mode name.
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game mode description.
|
||||
/// </summary>
|
||||
public abstract string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game mode ID.
|
||||
/// </summary>
|
||||
public abstract int Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when <see cref="IntroCutscene"/> is destroyed.
|
||||
/// </summary>
|
||||
public virtual void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on <see cref="HudManager.Start"/>.
|
||||
/// </summary>
|
||||
/// <param name="instance">Instance of <see cref="HudManager"/>.</param>
|
||||
public virtual void HudStart(HudManager instance)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame on <see cref="HudManager.Update"/>.
|
||||
/// </summary>
|
||||
/// <param name="instance">Instance of <see cref="HudManager"/>.</param>
|
||||
public virtual void HudUpdate(HudManager instance)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a player is killed.
|
||||
/// </summary>
|
||||
/// <param name="player"><see cref="PlayerControl"/> that was killed.</param>
|
||||
public virtual void OnDeath(PlayerControl player)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate Game End logic.
|
||||
/// </summary>
|
||||
/// <param name="runOriginal">Should original game end logic be used.</param>
|
||||
/// <param name="instance">Instance of <see cref="LogicGameFlowNormal"/>.</param>
|
||||
public virtual void CheckGameEnd(out bool runOriginal, LogicGameFlowNormal instance)
|
||||
{
|
||||
runOriginal = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom role assignment.
|
||||
/// </summary>
|
||||
/// <param name="runOriginal">Should original role assignment be used.</param>
|
||||
/// <param name="instance">Instance of <see cref="LogicRoleSelection"/>.</param>
|
||||
public virtual void AssignRoles(out bool runOriginal, LogicRoleSelectionNormal instance)
|
||||
{
|
||||
runOriginal = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom murder logic.
|
||||
/// </summary>
|
||||
/// <param name="runOriginal">Should the original murder logic be used.</param>
|
||||
/// <param name="result">Result of custom murder logic.</param>
|
||||
/// <param name="target">Target <see cref="PlayerControl"/> for murder.</param>
|
||||
public virtual void CanKill(out bool runOriginal, out bool result, PlayerControl target)
|
||||
{
|
||||
result = false;
|
||||
runOriginal = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should Roles Settings be available when this gamemode is selected.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if Role Settings are enabled in this game mode.</returns>
|
||||
public virtual bool AreRoleSettingsEnabled() => true;
|
||||
|
||||
/// <summary>
|
||||
/// Should Game Settings be available when this gamemode is selected.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if Game Settings are enabled in this mode.</returns>
|
||||
public virtual bool AreGameSettingsEnabled() => true;
|
||||
|
||||
/// <summary>
|
||||
/// Custom winner selection.
|
||||
/// </summary>
|
||||
/// <returns>List of winners or <see langword="null"/>.</returns>
|
||||
public virtual List<NetworkedPlayerInfo>? CalculateWinners() => null;
|
||||
|
||||
/// <summary>
|
||||
/// Show gamemode in <see cref="IntroCutscene"/>.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if the game mode should be shown in the intro cutscene.</returns>
|
||||
public virtual bool ShowGameModeIntroCutscene() => false;
|
||||
|
||||
/// <summary>
|
||||
/// Can Admin be used in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">Admin Console.</param>
|
||||
/// <returns><see langword="true"/> if Admin console is enabled.</returns>
|
||||
public virtual bool CanUseMapConsole(MapConsole console) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can a <see cref="DeadBody"/> be reported in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="body">Target <see cref="DeadBody"/> for reporting.</param>
|
||||
/// <returns><see langword="true"/> if <see cref="DeadBody"/>s can be reported.</returns>
|
||||
public virtual bool CanReport(DeadBody body) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can <see cref="SystemConsole"/>s be used in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">System Console.</param>
|
||||
/// <returns><see langword="true"/> if <see cref="SystemConsole"/>s are enabled in this mode.</returns>
|
||||
public virtual bool CanUseSystemConsole(SystemConsole console) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can tasks be interacted with in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">Task console.</param>
|
||||
/// <returns><see langword="true"/> if tasks are enabled in this mode.</returns>
|
||||
public virtual bool CanUseTasks(Console console) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Should the sabotage map be used when attempting to open sabotage overlay.
|
||||
/// </summary>
|
||||
/// <param name="map"><see cref="MapBehaviour"/> object.</param>
|
||||
/// <returns><see langword="true"/> if the sabotage map should be shown.</returns>
|
||||
public virtual bool ShouldShowSabotageMap(MapBehaviour map) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can a player vent in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="vent">Target vent.</param>
|
||||
/// <param name="playerInfo">Player attempting to vent.</param>
|
||||
/// <returns><see langword="true"/> if venting is enabled in this mode.</returns>
|
||||
public virtual bool CanVent(Vent vent, NetworkedPlayerInfo playerInfo) => true;
|
||||
}
|
||||
@@ -1,71 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MiraAPI.PluginLoading;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// Manages <see cref="CustomGameMode"/>s.
|
||||
/// Manages custom gamemodes.
|
||||
/// </summary>
|
||||
public static class CustomGameModeManager
|
||||
{
|
||||
/// <summary>
|
||||
/// List of registered <see cref="CustomGameMode"/>.
|
||||
/// </summary>
|
||||
internal static readonly Dictionary<int, CustomGameMode> GameModes = [];
|
||||
internal static readonly Dictionary<uint, AbstractGameMode> IdToModeMap = [];
|
||||
|
||||
public static bool IsDefault()
|
||||
private static uint GetNextId() => ++LastId;
|
||||
|
||||
private static uint LastId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Register gamemode from type.
|
||||
/// </summary>
|
||||
/// <param name="gameModeType">Type of gamemode class, should inherit from <see cref="AbstractGameMode"/>.</param>
|
||||
/// <param name="pluginInfo">The custom plugin info of the mod.</param>
|
||||
/// <returns>Whether the gamemode was successfully registered.</returns>
|
||||
internal static bool RegisterGameMode(Type gameModeType, MiraPluginInfo pluginInfo)
|
||||
{
|
||||
return ActiveMode?.Id == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current <see cref="CustomGameMode"/>.
|
||||
/// </summary>
|
||||
public static CustomGameMode? ActiveMode { get; internal set; } = new DefaultMode();
|
||||
|
||||
/// <summary>
|
||||
/// Set current <see cref="CustomGameMode"/>.
|
||||
/// </summary>
|
||||
/// <param name="id"><see cref="CustomGameMode"/> ID.</param>
|
||||
public static void SetGameMode(int id)
|
||||
{
|
||||
if (GameModes.TryGetValue(id, out var gameMode))
|
||||
{
|
||||
ActiveMode = gameMode;
|
||||
return;
|
||||
}
|
||||
|
||||
Error($"No gamemode with id {id} found!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register <see cref="CustomGameMode"/> from type.
|
||||
/// </summary>
|
||||
/// <param name="gameModeType">Type of <see cref="CustomGameMode"/>, should inherit from <see cref="CustomGameMode"/>.</param>
|
||||
internal static void RegisterGameMode(Type gameModeType)
|
||||
{
|
||||
if (!typeof(CustomGameMode).IsAssignableFrom(gameModeType))
|
||||
if (!typeof(AbstractGameMode).IsAssignableFrom(gameModeType))
|
||||
{
|
||||
Warning($"{gameModeType.Name} does not inherit CustomGameMode!");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
var modeObj = Activator.CreateInstance(gameModeType);
|
||||
var instance = Activator.CreateInstance(gameModeType);
|
||||
|
||||
if (modeObj is not CustomGameMode gameMode)
|
||||
if (instance is not AbstractGameMode mode)
|
||||
{
|
||||
Error($"Failed to create instance of {gameModeType.Name}");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GameModes.Any(x => x.Key == gameMode.Id))
|
||||
if (!mode.HideMode)
|
||||
{
|
||||
Error($"ID for gamemode {gameMode.Name} already exists!");
|
||||
IdToModeMap.Add(GetNextId(), mode);
|
||||
pluginInfo.GameModes.Add(LastId, mode);
|
||||
mode.ID = LastId;
|
||||
GameModeOption.AddOption(mode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the current game mode is an instance of the classic mode.
|
||||
/// </summary>
|
||||
/// <returns>True if the classic mode is the current one.</returns>
|
||||
public static bool IsClassic() => ActiveMode != null && ActiveMode.GetType().IsAssignableTo(typeof(ClassicMode));
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the current game mode is an instance of the HNS mode.
|
||||
/// </summary>
|
||||
/// <returns>True if the Hide & Seek mode is the current one.</returns>
|
||||
public static bool IsHideNSeek() => ActiveMode != null && ActiveMode.GetType().IsAssignableTo(typeof(HideAndSeekMode));
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a provided GameMode is the current active one.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The AbstractGameMode subclass being checked.</typeparam>
|
||||
/// <returns>Whether the provided mode is the current active one.</returns>
|
||||
public static bool IsActiveGameMode<T>() where T : AbstractGameMode => ActiveMode is T;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current gamemode.
|
||||
/// </summary>
|
||||
public static AbstractGameMode? ActiveMode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a gamemode from an ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the gamemode to fetch.</param>
|
||||
/// <returns>The gamemode matching that ID.</returns>
|
||||
public static AbstractGameMode GetMode(uint id) => IdToModeMap[id];
|
||||
|
||||
/// <summary>
|
||||
/// Finds the parent mod of a custom gamemode.
|
||||
/// </summary>
|
||||
/// <param name="gameMode">The <see cref="AbstractGameMode"/> object.</param>
|
||||
/// <returns>A <see cref="MiraPluginInfo"/> object representing the parent mod of the gamemode.</returns>
|
||||
public static MiraPluginInfo? FindParentMod(AbstractGameMode gameMode)
|
||||
{
|
||||
return MiraPluginManager.Instance.RegisteredPlugins.FirstOrDefault(plugin => plugin.GameModes.ContainsValue(gameMode));
|
||||
}
|
||||
|
||||
internal static void RegisterDefaultMode()
|
||||
{
|
||||
var defaultMode = new ClassicMode();
|
||||
IdToModeMap.Add(0, defaultMode);
|
||||
// no need to add to game mode option as it already contains it
|
||||
// because we cannot have the option be created with no values
|
||||
defaultMode.ID = 0;
|
||||
var hnsMode = new HideAndSeekMode();
|
||||
if (!hnsMode.HideMode)
|
||||
{
|
||||
IdToModeMap.Add(1, hnsMode);
|
||||
hnsMode.ID = 1;
|
||||
GameModeOption.AddOption(hnsMode);
|
||||
LastId++;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void GetAndSetGameMode()
|
||||
{
|
||||
var id = (uint)GameModeOption.Value;
|
||||
|
||||
if (IdToModeMap.TryGetValue(id, out var mode))
|
||||
{
|
||||
ActiveMode = mode;
|
||||
return;
|
||||
}
|
||||
|
||||
GameModes.Add(gameMode.Id, gameMode);
|
||||
ActiveMode = IdToModeMap[0];
|
||||
Logger<MiraApiPlugin>.Warning($"Unable to find game mode of id {id}!");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
public class DefaultMode : CustomGameMode
|
||||
{
|
||||
public override string Name => "Default";
|
||||
public override string Description => "Default Among Us GameMode";
|
||||
public override int Id => 0;
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Patches.GameModes;
|
||||
using MiraAPI.Patches.Options;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Localization.Utilities;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.ProBuilder;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// The game mode option.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class GameModeOption
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the current index of the Game Mode Option
|
||||
/// For the value as an <see cref="AbstractGameMode"/>, see <see cref="CustomGameModeManager.ActiveMode"/>.
|
||||
/// </summary>
|
||||
public static int Value
|
||||
{
|
||||
get =>
|
||||
OptionBehaviour != null
|
||||
? OptionBehaviour.GetInt()
|
||||
: _lastValue;
|
||||
private set
|
||||
{
|
||||
_lastValue = value;
|
||||
if (OptionBehaviour == null)
|
||||
return;
|
||||
OptionBehaviour.Value = value;
|
||||
OptionBehaviour.UpdateValue();
|
||||
_lastValue = value;
|
||||
}
|
||||
}
|
||||
internal static StringOption OptionBehaviour { get; set; } = null!;
|
||||
|
||||
internal static int _lastValue;
|
||||
internal static readonly StringNames GamemodeName = CustomStringName.CreateAndRegister("Gamemode");
|
||||
internal static readonly StringNames CustomName = CustomStringName.CreateAndRegister("Custom");
|
||||
internal static readonly Dictionary<uint, StringNames> Values = new()
|
||||
{
|
||||
[0] = CustomStringName.CreateAndRegister("Classic"),
|
||||
};
|
||||
|
||||
internal static void AddOption(AbstractGameMode mode)
|
||||
{
|
||||
if (!Values.ContainsKey(mode.ID))
|
||||
Values.Add(mode.ID, CustomStringName.CreateAndRegister(mode.ColoredName));
|
||||
}
|
||||
/*[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.CreateSettings))]
|
||||
[HarmonyPostfix]
|
||||
private static void CreateSettingsPatch(GameOptionsMenu __instance)
|
||||
{
|
||||
if (MenuState.Instance.CurrentModIdx != 0 || GameManager.Instance.IsHideAndSeek() || CustomGameModeManager.ActiveMode == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var num = 0.713f;
|
||||
|
||||
foreach (var category in __instance.settingsContainer.GetComponentsInChildren<CategoryHeaderMasked>())
|
||||
{
|
||||
if (category)
|
||||
category.gameObject.transform.localPosition -= new Vector3(0, 1.3f, 0);
|
||||
}
|
||||
CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer);
|
||||
categoryHeaderMasked.SetHeader(CustomName, 20);
|
||||
categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f;
|
||||
categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
||||
OptionBehaviour = Object.Instantiate(
|
||||
__instance.stringOptionOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
__instance.settingsContainer);
|
||||
num -= 0.63f;
|
||||
OptionBehaviour.transform.localPosition = new Vector3(0.952f, num, -2f);
|
||||
OptionBehaviour.SetClickMask(__instance.ButtonClickMask);
|
||||
StringGameSetting setting = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
setting.Type = OptionTypes.MultipleChoice;
|
||||
setting.Title = GamemodeName;
|
||||
setting.Index = _lastValue;
|
||||
setting.Values = new Il2CppStructArray<StringNames>([Values[0]]);
|
||||
OptionBehaviour.SetUpFromData(setting, 20);
|
||||
Set(_lastValue);
|
||||
OptionBehaviour.TitleText.fontSize = 3;
|
||||
foreach (var optionBehaviour in __instance.Children.ToArray().Skip(1))
|
||||
{
|
||||
optionBehaviour.gameObject.transform.localPosition -= new Vector3(0, 1.3f, 0);
|
||||
}
|
||||
__instance.Children.Add(OptionBehaviour);
|
||||
for (var i = 1; i < Values.Count; i++)
|
||||
OptionBehaviour.Values = (Il2CppStructArray<StringNames>)OptionBehaviour.Values.Add(Values.ElementAt(i).Value);
|
||||
__instance.scrollBar.SetYBoundsMax(__instance.scrollBar.GetYBounds().max + 1);
|
||||
}*/
|
||||
|
||||
internal static void Set(int val)
|
||||
{
|
||||
Value = val;
|
||||
var previousMode = CustomGameModeManager.ActiveMode;
|
||||
CustomGameModeManager.GetAndSetGameMode();
|
||||
HudPatches.SetGameModeText(CustomGameModeManager.GetMode(Values.ElementAt(_lastValue).Key).ColoredName);
|
||||
var gm = CustomGameModeManager.ActiveMode!;
|
||||
if (gm != previousMode)
|
||||
{
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
GamemodeName,
|
||||
gm.ColoredName,
|
||||
new Color(0.7333f, 0.7333f, 0.7333f, 1),
|
||||
gm.TmpIcon,
|
||||
true);
|
||||
if (MenuState.Instance)
|
||||
{
|
||||
// should force reset roles for gamemodes properly
|
||||
foreach (var roleMenu in MenuState.Instance.QueuedRoleMenuRefresh)
|
||||
{
|
||||
MenuState.Instance.QueuedRoleMenuRefresh[roleMenu.Key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// could make Values a dict of AbstractGameMode too
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.ValueChanged))]
|
||||
[HarmonyPrefix]
|
||||
private static bool ValueChanged(GameOptionsMenu __instance, OptionBehaviour option)
|
||||
{
|
||||
if (OptionBehaviour.Equals(option))
|
||||
{
|
||||
Info($"Game mode changed to {option.GetInt()}");
|
||||
RpcSyncGamemode(PlayerControl.LocalPlayer, option.GetInt());
|
||||
if (GameSettingMenu.Instance && CustomGameModeManager.ActiveMode != null)
|
||||
{
|
||||
GameOptionsMenuPatch.ToggleGamemodeOptions(CustomGameModeManager.ActiveMode, __instance);
|
||||
GameSettingMenu.Instance.RoleSettingsButton.gameObject.SetActive(CustomGameModeManager.ActiveMode.ShowNormalRoleSettings);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[MethodRpc((uint) MiraRpc.SyncGamemodeOption)]
|
||||
internal static void RpcSyncGamemode(PlayerControl host, int data)
|
||||
{
|
||||
Set(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,534 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AmongUs.Data;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using InnerNet;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.HnsReimplemented;
|
||||
using MiraAPI.HnsReimplemented.Options;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using PowerTools;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// The vanilla Hide and Seek game mode, ported to Mira.
|
||||
/// </summary>
|
||||
[MiraIgnore]
|
||||
public class HideAndSeekMode : AbstractGameMode
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override string Name => "Hide n Seek";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string Description => "You can run, but you can't hide!\nOutlive the timer or eliminate the crew.";
|
||||
|
||||
// TODO: Once the Hide n Seek port is ready for release, we will remove this.
|
||||
public override bool HideMode => !MiraApiPlugin.IsDevBuild;
|
||||
|
||||
public override Color Color { get; } = new Color32(255, 88, 90, 255);
|
||||
public override LoadableAsset<Sprite>? Icon => MiraAssets.HnSGamemodeIcon;
|
||||
public override bool CanReport(DeadBody body) => false;
|
||||
public override bool ShouldShowSabotageMap(MapBehaviour map) => false;
|
||||
public override bool ShowGameModeIntroCutscene => true;
|
||||
public override bool GameModeBodyTypeOverride => true;
|
||||
public override bool ShowNormalGameSettings => false;
|
||||
public override bool ShowNormalRoleSettings => false;
|
||||
public override float DefaultImpostorKillCooldown => 1f;
|
||||
|
||||
public override bool ShowTaskBar => false;
|
||||
public static int ImpostorPlayerID()
|
||||
{
|
||||
return OptionGroupSingleton<HnsImpostorOptions>.Instance.SelectedSeeker.Value;
|
||||
}
|
||||
|
||||
public static bool HasImpostorPlayerID()
|
||||
{
|
||||
return ImpostorPlayerID() > -1;
|
||||
}
|
||||
|
||||
public static bool ValidateImpostorPlayerID(List<NetworkedPlayerInfo> players)
|
||||
{
|
||||
return HasImpostorPlayerID() && players.Find((NetworkedPlayerInfo p) => (int)p.PlayerId == ImpostorPlayerID()) != null;
|
||||
}
|
||||
|
||||
public override void AssignRoles(out bool runOriginal, LogicRoleSelectionNormal instance)
|
||||
{
|
||||
runOriginal = false;
|
||||
Il2CppSystem.Collections.Generic.List<ClientData> list = new();
|
||||
AmongUsClient.Instance.GetAllClients(list);
|
||||
List<NetworkedPlayerInfo> list2 = list.ToArray()
|
||||
.Where(c => c.Character != null && c.Character.Data != null && !c.Character.Data.Disconnected &&
|
||||
!c.Character.Data.IsDead).OrderBy(c => c.Id).Select(c => c.Character.Data)
|
||||
.ToList();
|
||||
|
||||
foreach (NetworkedPlayerInfo networkedPlayerInfo in GameData.Instance.AllPlayers)
|
||||
{
|
||||
if (networkedPlayerInfo.Object != null && networkedPlayerInfo.Object.isDummy)
|
||||
{
|
||||
list2.Add(networkedPlayerInfo);
|
||||
}
|
||||
}
|
||||
IGameOptions currentGameOptions = GameOptionsManager.Instance.CurrentGameOptions;
|
||||
int adjustedNumImpostors = GameOptionsManager.Instance.CurrentGameOptions.GetAdjustedNumImpostors(list2.Count);
|
||||
AssignRolesForTeam(list2, currentGameOptions, RoleTeamTypes.Impostor, Math.Max(adjustedNumImpostors, 1), RoleTypes.Impostor);
|
||||
AssignRolesForTeam(list2, currentGameOptions, RoleTeamTypes.Crewmate, int.MaxValue, RoleTypes.Engineer);
|
||||
}
|
||||
|
||||
public static void AssignRolesForTeam(
|
||||
List<NetworkedPlayerInfo> players,
|
||||
IGameOptions opts,
|
||||
RoleTeamTypes team,
|
||||
int teamMax,
|
||||
RoleTypes defaultRole)
|
||||
{
|
||||
Error($"Hide And Seek Mode - AssignRolesForTeam: Team: {team}, Max: {teamMax}, Players: {players.Count}, DefaultRole: {defaultRole}");
|
||||
int num = 0;
|
||||
IRoleOptionsCollection roleOptions = opts.RoleOptions;
|
||||
var source = RoleManager.Instance.AllRoles.ToArray()
|
||||
.Where(role => role.TeamType == team && !RoleManager.IsGhostRole(role.Role) &&
|
||||
CustomRoleUtils.CanSpawnOnCurrentMode(role));
|
||||
var assignmentData = source.Where(x => !x.IsDead).Select(role =>
|
||||
new RoleManager.RoleAssignmentData(
|
||||
role,
|
||||
roleOptions.GetNumPerGame(role.Role),
|
||||
roleOptions.GetChancePerGame(role.Role))).ToList();
|
||||
var source2 = CustomRoleUtils.GetPossibleRoles(assignmentData, x => x.Chance == 100);
|
||||
var guaranteedRoles = source.Where(x => source2.Contains(((ushort)x.Role, 100)));
|
||||
List<RoleTypes> list = new List<RoleTypes>();
|
||||
if (team == RoleTeamTypes.Crewmate)
|
||||
{
|
||||
Error($"MiraAPI.Patches.Roles.LogicRoleSelectionHnsPatch - AssignRolesForTeam: Before Guaranteed Assignment");
|
||||
foreach (RoleManager.RoleAssignmentData roleAssignmentData in guaranteedRoles.Select((x) =>
|
||||
new RoleManager.RoleAssignmentData(x, roleOptions.GetNumPerGame(x.Role), 100)))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
RoleManager.RoleAssignmentData roleAssignmentData2 = roleAssignmentData;
|
||||
int count = roleAssignmentData2.Count;
|
||||
roleAssignmentData2.Count = count - 1;
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
list.Add(roleAssignmentData.Role.Role);
|
||||
}
|
||||
}
|
||||
Error($"MiraAPI.Patches.Roles.LogicRoleSelectionHnsPatch - AssignRolesForTeam: After Guaranteed Assignment");
|
||||
AssignRolesFromList(players, teamMax, list, ref num);
|
||||
|
||||
var list2 = source.Where(x => !x.IsDead).Select(role =>
|
||||
new RoleManager.RoleAssignmentData(
|
||||
role,
|
||||
roleOptions.GetNumPerGame(role.Role),
|
||||
roleOptions.GetChancePerGame(role.Role))).ToList();
|
||||
|
||||
list.Clear();
|
||||
foreach (RoleManager.RoleAssignmentData roleAssignmentData3 in list2)
|
||||
{
|
||||
for (int i = 0; i < roleAssignmentData3.Count; i++)
|
||||
{
|
||||
if (HashRandom.Next(101) < roleAssignmentData3.Chance)
|
||||
{
|
||||
list.Add(roleAssignmentData3.Role.Role);
|
||||
}
|
||||
}
|
||||
}
|
||||
Error($"MiraAPI.Patches.Roles.LogicRoleSelectionHnsPatch - AssignRolesForTeam: After Potential Assignment");
|
||||
|
||||
AssignRolesFromList(players, teamMax, list, ref num);
|
||||
var basicRole = RoleTypes.Engineer;
|
||||
while (list.Count < players.Count && list.Count + num < teamMax)
|
||||
{
|
||||
list.Add(basicRole);
|
||||
}
|
||||
|
||||
AssignRolesFromList(players, teamMax, list, ref num);
|
||||
Error($"MiraAPI.Patches.Roles.LogicRoleSelectionHnsPatch - AssignRolesForTeam: After Fallback Assignment");
|
||||
}
|
||||
else if (team == RoleTeamTypes.Impostor)
|
||||
{
|
||||
Error($"MiraAPI.Patches.Roles.LogicRoleSelectionHnsPatch - AssignRolesForTeam: Before Guaranteed Assignment");
|
||||
var newImpostors = new List<NetworkedPlayerInfo>();
|
||||
// Specified Seeker
|
||||
if (HasImpostorPlayerID() &&
|
||||
ValidateImpostorPlayerID(players) &&
|
||||
!AmongUsClient.Instance.IsGamePublic)
|
||||
{
|
||||
NetworkedPlayerInfo networkedPlayerInfo = players.ToArray()
|
||||
.First(p => p.PlayerId == ImpostorPlayerID());
|
||||
players.Remove(networkedPlayerInfo);
|
||||
newImpostors.Add(networkedPlayerInfo);
|
||||
Error($"MiraAPI.Patches.Roles.LogicRoleSelectionHnsPatch - AssignRolesForTeam: Seeker is {networkedPlayerInfo.PlayerName}, ID: {networkedPlayerInfo.PlayerId}");
|
||||
}
|
||||
// Random Seeker
|
||||
else
|
||||
{
|
||||
int num2 = 0;
|
||||
while (num2 < teamMax && players.Count > 0)
|
||||
{
|
||||
PseudoRandomList<NetworkedPlayerInfo> pseudoRandomList = new PseudoRandomList<NetworkedPlayerInfo>(AmongUsClient.Instance.GameId);
|
||||
players.Do(x => pseudoRandomList.Add(x));
|
||||
for (int i = 0; i < GameData.RoundsPlayedInSession; i++)
|
||||
{
|
||||
pseudoRandomList.PickRandom();
|
||||
}
|
||||
NetworkedPlayerInfo networkedPlayerInfo = pseudoRandomList.PickRandom();
|
||||
players.Remove(networkedPlayerInfo);
|
||||
newImpostors.Add(networkedPlayerInfo);
|
||||
num2++;
|
||||
Error($"MiraAPI.Patches.Roles.LogicRoleSelectionHnsPatch - AssignRolesForTeam: Seeker is {networkedPlayerInfo.PlayerName}, ID: {networkedPlayerInfo.PlayerId}");
|
||||
}
|
||||
}
|
||||
Error($"MiraAPI.Patches.Roles.LogicRoleSelectionHnsPatch - AssignRolesForTeam: After Guaranteed Assignment");
|
||||
foreach (RoleManager.RoleAssignmentData roleAssignmentData in guaranteedRoles.Select((x) =>
|
||||
new RoleManager.RoleAssignmentData(x, roleOptions.GetNumPerGame(x.Role), 100)))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
RoleManager.RoleAssignmentData roleAssignmentData2 = roleAssignmentData;
|
||||
int count = roleAssignmentData2.Count;
|
||||
roleAssignmentData2.Count = count - 1;
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
list.Add(roleAssignmentData.Role.Role);
|
||||
}
|
||||
}
|
||||
AssignRolesFromList(newImpostors, teamMax, list, ref num);
|
||||
|
||||
var list2 = source.Where(x => !x.IsDead).Select(role =>
|
||||
new RoleManager.RoleAssignmentData(
|
||||
role,
|
||||
roleOptions.GetNumPerGame(role.Role),
|
||||
roleOptions.GetChancePerGame(role.Role))).ToList();
|
||||
|
||||
list.Clear();
|
||||
foreach (RoleManager.RoleAssignmentData roleAssignmentData3 in list2)
|
||||
{
|
||||
for (int i = 0; i < roleAssignmentData3.Count; i++)
|
||||
{
|
||||
if (HashRandom.Next(101) < roleAssignmentData3.Chance)
|
||||
{
|
||||
list.Add(roleAssignmentData3.Role.Role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AssignRolesFromList(newImpostors, teamMax, list, ref num);
|
||||
var basicRole = RoleTypes.Impostor;
|
||||
while (list.Count < newImpostors.Count && list.Count + num < teamMax)
|
||||
{
|
||||
list.Add(basicRole);
|
||||
}
|
||||
|
||||
AssignRolesFromList(newImpostors, teamMax, list, ref num);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AssignRolesFromList(List<NetworkedPlayerInfo> players, int teamMax, List<RoleTypes> roleList, ref int rolesAssigned)
|
||||
{
|
||||
while (roleList.Count > 0 && players.Count > 0 && rolesAssigned < teamMax)
|
||||
{
|
||||
int index = HashRandom.FastNext(roleList.Count);
|
||||
RoleTypes roleType = roleList[index];
|
||||
roleList.RemoveAt(index);
|
||||
int index2 = HashRandom.FastNext(players.Count);
|
||||
players[index2].Object.RpcSetRole(roleType, false);
|
||||
players.RemoveAt(index2);
|
||||
rolesAssigned++;
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator IntroCutscene(IntroCutscene __instance)
|
||||
{
|
||||
SoundManager.Instance.PlaySound(__instance.IntroStinger, false, 1f, null);
|
||||
Logger.GlobalInstance.Info("IntroCutscene :: CoBegin() :: Game Mode: Hide and Seek (MiraAPI)", null);
|
||||
__instance.LogPlayerRoleData();
|
||||
__instance.HideAndSeekPanels.SetActive(true);
|
||||
if (PlayerControl.LocalPlayer.Data.Role.IsImpostor)
|
||||
{
|
||||
__instance.CrewmateRules.SetActive(false);
|
||||
__instance.ImpostorRules.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.CrewmateRules.SetActive(true);
|
||||
__instance.ImpostorRules.SetActive(false);
|
||||
}
|
||||
|
||||
__instance.ImpostorName.gameObject.SetActive(true);
|
||||
__instance.ImpostorTitle.gameObject.SetActive(true);
|
||||
__instance.BackgroundBar.enabled = false;
|
||||
__instance.TeamTitle.gameObject.SetActive(false);
|
||||
var impostor = PlayerControl.AllPlayerControls.ToArray().FirstOrDefault(x => x.Data.Role.IsImpostor);
|
||||
if (impostor == null)
|
||||
{
|
||||
Logger.GlobalInstance.Error("IntroCutscene :: CoBegin() :: impostor is NULL", null);
|
||||
}
|
||||
|
||||
GameManager.Instance.SetSpecialCosmetics(impostor);
|
||||
if (impostor != null)
|
||||
{
|
||||
__instance.ImpostorName.text = impostor.Data.PlayerName;
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.ImpostorName.text = "???";
|
||||
}
|
||||
|
||||
yield return new WaitForSecondsRealtime(0.1f);
|
||||
if (impostor != null)
|
||||
{
|
||||
__instance.ImpostorTitle.text = impostor.Data.Role.GetRoleName();
|
||||
}
|
||||
PoolablePlayer playerSlot = null;
|
||||
if (impostor != null)
|
||||
{
|
||||
playerSlot = __instance.CreatePlayer(1, 1, impostor.Data, false);
|
||||
playerSlot.SetBodyType(PlayerBodyTypes.Normal);
|
||||
playerSlot.SetFlipX(false);
|
||||
playerSlot.transform.localPosition = __instance.impostorPos;
|
||||
playerSlot.transform.localScale = Vector3.one * __instance.impostorScale;
|
||||
}
|
||||
|
||||
yield return ShipStatus.Instance.CosmeticsCache.PopulateFromPlayers();
|
||||
yield return new WaitForSecondsRealtime(6f);
|
||||
if (playerSlot != null)
|
||||
{
|
||||
playerSlot.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
__instance.HideAndSeekPanels.SetActive(false);
|
||||
__instance.CrewmateRules.SetActive(false);
|
||||
__instance.ImpostorRules.SetActive(false);
|
||||
HnsMusicHandler.Instance.StartMusicWithIntro();
|
||||
var hideTimer = 10f;
|
||||
|
||||
if (PlayerControl.LocalPlayer.Data.Role.IsImpostor)
|
||||
{
|
||||
__instance.HideAndSeekTimerText.gameObject.SetActive(true);
|
||||
PoolablePlayer poolablePlayer;
|
||||
AnimationClip anim;
|
||||
if (AprilFoolsMode.ShouldHorseAround())
|
||||
{
|
||||
poolablePlayer = __instance.HorseWrangleVisualSuit;
|
||||
poolablePlayer.gameObject.SetActive(true);
|
||||
poolablePlayer.SetBodyType(PlayerBodyTypes.Seeker);
|
||||
anim = __instance.HnSSeekerSpawnHorseAnim;
|
||||
__instance.HorseWrangleVisualPlayer.SetBodyType(PlayerBodyTypes.Normal);
|
||||
__instance.HorseWrangleVisualPlayer.UpdateFromPlayerData(
|
||||
PlayerControl.LocalPlayer.Data,
|
||||
PlayerControl.LocalPlayer.CurrentOutfitType,
|
||||
PlayerMaterial.MaskType.None,
|
||||
false,
|
||||
null,
|
||||
false);
|
||||
}
|
||||
else if (AprilFoolsMode.ShouldLongAround())
|
||||
{
|
||||
poolablePlayer = __instance.HideAndSeekPlayerVisual;
|
||||
poolablePlayer.gameObject.SetActive(true);
|
||||
poolablePlayer.SetBodyType(PlayerBodyTypes.LongSeeker);
|
||||
anim = __instance.HnSSeekerSpawnLongAnim;
|
||||
}
|
||||
else
|
||||
{
|
||||
poolablePlayer = __instance.HideAndSeekPlayerVisual;
|
||||
poolablePlayer.gameObject.SetActive(true);
|
||||
poolablePlayer.SetBodyType(PlayerBodyTypes.Seeker);
|
||||
anim = __instance.HnSSeekerSpawnAnim;
|
||||
}
|
||||
|
||||
poolablePlayer.SetBodyCosmeticsVisible(false);
|
||||
poolablePlayer.UpdateFromPlayerData(
|
||||
PlayerControl.LocalPlayer.Data,
|
||||
PlayerControl.LocalPlayer.CurrentOutfitType,
|
||||
PlayerMaterial.MaskType.None,
|
||||
false,
|
||||
null,
|
||||
false);
|
||||
SpriteAnim component = poolablePlayer.GetComponent<SpriteAnim>();
|
||||
poolablePlayer.gameObject.SetActive(true);
|
||||
poolablePlayer.ToggleName(false);
|
||||
component.Play(anim, 1f);
|
||||
while (hideTimer > 0f)
|
||||
{
|
||||
__instance.HideAndSeekTimerText.text = Mathf.RoundToInt(hideTimer).ToString();
|
||||
hideTimer -= Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HideAndSeekHudHelper.Instance.HideCountdown = hideTimer;
|
||||
if (AprilFoolsMode.ShouldHorseAround())
|
||||
{
|
||||
if (impostor != null)
|
||||
{
|
||||
impostor.AnimateCustom(__instance.HnSSeekerSpawnHorseInGameAnim);
|
||||
}
|
||||
}
|
||||
else if (AprilFoolsMode.ShouldLongAround())
|
||||
{
|
||||
if (impostor != null)
|
||||
{
|
||||
impostor.AnimateCustom(__instance.HnSSeekerSpawnLongInGameAnim);
|
||||
}
|
||||
}
|
||||
else if (impostor != null)
|
||||
{
|
||||
impostor.AnimateCustom(__instance.HnSSeekerSpawnAnim);
|
||||
impostor.cosmetics.SetBodyCosmeticsVisible(false);
|
||||
}
|
||||
}
|
||||
ShipStatus.Instance.StartSFX();
|
||||
HnsMusicHandler.Instance.OnGameStart();
|
||||
HnsDangerMeter.Instance.OnGameStart();
|
||||
UnityEngine.Object.Destroy(__instance.gameObject);
|
||||
}
|
||||
public override void Initialize()
|
||||
{
|
||||
deadPlayerCount = 0;
|
||||
ShipStatus.Instance.BreakEmergencyButton();
|
||||
PlayerControl.LocalPlayer.SetKillTimer(0.01f);
|
||||
if (HudManager.InstanceExists)
|
||||
{
|
||||
HudManager.Instance.gameObject.AddComponent<HnsMusicHandler>();
|
||||
HudManager.Instance.gameObject.AddComponent<HideAndSeekHudHelper>();
|
||||
HudManager.Instance.gameObject.AddComponent<HnsDangerMeter>();
|
||||
}
|
||||
}
|
||||
public override MapOptions GetMapOptions()
|
||||
{
|
||||
MapOptions mapOptions = new MapOptions
|
||||
{
|
||||
Mode = MapOptions.Modes.Normal,
|
||||
};
|
||||
if (PlayerControl.LocalPlayer.Data.Role.IsImpostor && HideAndSeekHudHelper.Instance.SeekerAdminMapEnabled(PlayerControl.LocalPlayer))
|
||||
{
|
||||
mapOptions.Mode = MapOptions.Modes.CountOverlay;
|
||||
mapOptions.AllowMovementWhileMapOpen = true;
|
||||
mapOptions.IncludeDeadBodies = false;
|
||||
mapOptions.ShowLivePlayerPosition = false;
|
||||
}
|
||||
return mapOptions;
|
||||
}
|
||||
|
||||
public override void CheckGameEnd(out bool runOriginal, LogicGameFlowNormal instance)
|
||||
{
|
||||
runOriginal = false;
|
||||
if (Helpers.GetAlivePlayers().Count(x => x.Data.Role.IsImpostor) == 0)
|
||||
{
|
||||
instance.Manager.RpcEndGame(GameOverReason.ImpostorDisconnect, !DataManager.Player.Ads.HasPurchasedAdRemoval);
|
||||
}
|
||||
if (Helpers.GetAlivePlayers().Count(x => !x.Data.Role.IsImpostor) != 0)
|
||||
{
|
||||
if (HideAndSeekHudHelper.Instance.AllTimersExpired())
|
||||
{
|
||||
instance.Manager.RpcEndGame(GameOverReason.HideAndSeek_CrewmatesByTimer, !DataManager.Player.Ads.HasPurchasedAdRemoval);
|
||||
}
|
||||
return;
|
||||
}
|
||||
instance.Manager.RpcEndGame(GameOverReason.HideAndSeek_ImpostorsByKills, !DataManager.Player.Ads.HasPurchasedAdRemoval);
|
||||
}
|
||||
|
||||
public override PlayerBodyTypes GetBodyType(PlayerControl player)
|
||||
{
|
||||
if (player == null || player.Data == null || player.Data.Role == null)
|
||||
{
|
||||
if (AprilFoolsMode.ShouldHorseAround())
|
||||
{
|
||||
return PlayerBodyTypes.Horse;
|
||||
}
|
||||
if (AprilFoolsMode.ShouldLongAround())
|
||||
{
|
||||
return PlayerBodyTypes.Long;
|
||||
}
|
||||
return PlayerBodyTypes.Normal;
|
||||
}
|
||||
else if (AprilFoolsMode.ShouldHorseAround())
|
||||
{
|
||||
if (player.Data.Role.IsImpostor)
|
||||
{
|
||||
return PlayerBodyTypes.Normal;
|
||||
}
|
||||
return PlayerBodyTypes.Horse;
|
||||
}
|
||||
else if (AprilFoolsMode.ShouldLongAround())
|
||||
{
|
||||
if (player.Data.Role.IsImpostor)
|
||||
{
|
||||
return PlayerBodyTypes.LongSeeker;
|
||||
}
|
||||
return PlayerBodyTypes.Long;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.Data.Role.IsImpostor)
|
||||
{
|
||||
return PlayerBodyTypes.Seeker;
|
||||
}
|
||||
return PlayerBodyTypes.Normal;
|
||||
}
|
||||
}
|
||||
public override void UpdateTaskPanel(TaskPanelBehaviour instance)
|
||||
{
|
||||
instance.background.transform.localScale = (instance.taskText.textBounds.size.x > 0f)
|
||||
? new Vector3(instance.taskText.textBounds.size.x + 0.2f, instance.taskText.textBounds.size.y + 0.2f, 1f)
|
||||
: Vector3.zero;
|
||||
Vector3 vector = instance.background.sprite.bounds.extents;
|
||||
vector.y = -vector.y;
|
||||
vector = vector.Mul(instance.background.transform.localScale);
|
||||
instance.background.transform.localPosition = vector;
|
||||
Vector3 vector2 = instance.tab.sprite.bounds.extents;
|
||||
vector2 = vector2.Mul(instance.tab.transform.localScale);
|
||||
vector2.y = -vector2.y;
|
||||
vector2.x += vector.x * 2f;
|
||||
instance.tab.transform.localPosition = vector2;
|
||||
if (GameManager.Instance == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var yPos = 1.6f;
|
||||
var xPos = -instance.background.sprite.bounds.size.x * instance.background.transform.localScale.x;
|
||||
instance.closedPosition = new Vector3(xPos, yPos, instance.closedPosition.z);
|
||||
instance.openPosition = new Vector3(instance.openPosition.x, yPos, instance.openPosition.z);
|
||||
if (instance.open)
|
||||
{
|
||||
instance.timer = Mathf.Min(1f, instance.timer + Time.deltaTime / instance.animationTimeSeconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.timer = Mathf.Max(0f, instance.timer - Time.deltaTime / instance.animationTimeSeconds);
|
||||
}
|
||||
|
||||
Vector3 relativePos = new(
|
||||
Mathf.SmoothStep(instance.closedPosition.x, instance.openPosition.x, instance.timer),
|
||||
yPos,
|
||||
instance.openPosition.z);
|
||||
instance.transform.localPosition =
|
||||
AspectPosition.ComputePosition(AspectPosition.EdgeAlignments.LeftTop, relativePos);
|
||||
}
|
||||
private int deadPlayerCount;
|
||||
public override void OnPlayerDeath(PlayerControl player, bool assignGhostRole)
|
||||
{
|
||||
base.OnPlayerDeath(player, assignGhostRole);
|
||||
HudManager.Instance.NotifyOfDeath();
|
||||
var popup = GameManagerCreator.Instance.HideAndSeekManagerPrefab.DeathPopupPrefab;
|
||||
deadPlayerCount++;
|
||||
var item = UnityEngine.Object.Instantiate(popup, HudManager.Instance.transform.parent);
|
||||
item.Show(player, deadPlayerCount);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
@@ -40,7 +42,7 @@ public abstract class AbstractOptionGroup
|
||||
/// <summary>
|
||||
/// Gets a value indicating which menu the group is in.
|
||||
/// </summary>
|
||||
public virtual MenuCategory ParentMenu => MenuCategory.Roles;
|
||||
public virtual MenuCategory ParentMenu => MenuCategory.Game;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the function that determines whether the group should be visible or not.
|
||||
@@ -58,9 +60,16 @@ public abstract class AbstractOptionGroup
|
||||
/// </summary>
|
||||
public virtual uint GroupPriority => uint.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default notification settings for the group.
|
||||
/// </summary>
|
||||
public virtual OptionNotifConfiguration Configuration => new(new Color(0.7333f, 0.7333f, 0.7333f, 1));
|
||||
|
||||
internal bool AllOptionsHidden { get; set; }
|
||||
|
||||
internal CategoryHeaderMasked? Header { get; set; }
|
||||
|
||||
internal bool Ready { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -72,9 +81,7 @@ public abstract class AbstractOptionGroup<T> : AbstractOptionGroup where T : IOp
|
||||
/// <inheritdoc />
|
||||
public override Type OptionableType => typeof(T);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating which menu the group is in.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override MenuCategory ParentMenu
|
||||
{
|
||||
get
|
||||
@@ -93,11 +100,43 @@ public abstract class AbstractOptionGroup<T> : AbstractOptionGroup where T : IOp
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base class for option groups. An option group is a collection of options that are displayed together in the options menu.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The custom role that the group is for.</typeparam>
|
||||
public abstract class AbstractRoleOptionGroup<T>() : AbstractOptionGroup<T> where T : ICustomRole
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Type OptionableType => typeof(T);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override MenuCategory ParentMenu => MenuCategory.Roles;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionNotifConfiguration Configuration
|
||||
{
|
||||
get
|
||||
{
|
||||
var role = CustomRoleManager.CustomMiraRoles.FirstOrDefault(x => x.GetType() == OptionableType);
|
||||
if (role == null)
|
||||
{
|
||||
return new(new Color(0.7333f, 0.7333f, 0.7333f, 1));
|
||||
}
|
||||
return new(role.RoleColor, role.Configuration.IconTmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Menu categories for option groups.
|
||||
/// </summary>
|
||||
public enum MenuCategory
|
||||
{
|
||||
/// <summary>
|
||||
/// Placeholder for indexing purposes. Options don't exist in the presset tab.
|
||||
/// </summary>
|
||||
Preset,
|
||||
|
||||
/// <summary>
|
||||
/// Determines the option group is in the game settings tab.
|
||||
/// </summary>
|
||||
|
||||
@@ -8,8 +8,9 @@ namespace MiraAPI.GameOptions.Attributes;
|
||||
/// </summary>
|
||||
/// <param name="title">The option title.</param>
|
||||
/// <param name="roleType">Optional parameter to specify a role Type.</param>
|
||||
/// <param name="modeType">Optional parameter to specify a game mode Type.</param>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public abstract class ModdedOptionAttribute(string title, Type? roleType = null) : Attribute
|
||||
public abstract class ModdedOptionAttribute(string title, Type? roleType = null, Type? modeType = null) : Attribute
|
||||
{
|
||||
internal IModdedOption? HolderOption { get; set; }
|
||||
|
||||
@@ -23,6 +24,11 @@ public abstract class ModdedOptionAttribute(string title, Type? roleType = null)
|
||||
/// </summary>
|
||||
protected Type? RoleType { get; private set; } = roleType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game mode type of the option.
|
||||
/// </summary>
|
||||
protected Type? ModeType { get; private set; } = modeType;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of the option.
|
||||
/// </summary>
|
||||
|
||||
@@ -21,6 +21,16 @@ public interface IModdedOption
|
||||
/// </summary>
|
||||
string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the parent <see cref="AbstractOptionGroup"/> of the option.
|
||||
/// </summary>
|
||||
AbstractOptionGroup ParentGroup { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the notification settings for the option.
|
||||
/// </summary>
|
||||
OptionNotifConfiguration Configuration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="StringNames"/> for the option, used for localization.
|
||||
/// </summary>
|
||||
|
||||
@@ -5,6 +5,8 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.Injection;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Networking;
|
||||
@@ -12,6 +14,8 @@ using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
@@ -24,12 +28,67 @@ public static class ModdedOptionsManager
|
||||
private static readonly Dictionary<Type, AbstractOptionGroup> TypeToGroup = [];
|
||||
|
||||
internal static readonly Dictionary<OptionBehaviour, ModdedPlayerOption> CreatedPlayerOptions = [];
|
||||
internal static readonly Dictionary<OptionBehaviour, ModdedStringOption> CreatedStringOptions = [];
|
||||
internal static readonly Dictionary<Type, List<AbstractOptionGroup>> GameModeOptionGroups = [];
|
||||
internal static readonly Dictionary<uint, IModdedOption> ModdedOptions = [];
|
||||
internal static readonly List<AbstractOptionGroup> Groups = [];
|
||||
|
||||
internal static uint NextId => _nextId++;
|
||||
private static uint _nextId = 1;
|
||||
|
||||
public static void AddSettingsChangeMessage(NotificationPopper notif, StringNames key, string value, Color textColor, TMP_SpriteAsset? sprite, bool playSound = true)
|
||||
{
|
||||
string item;
|
||||
var text = textColor.ToTextColor();
|
||||
if (sprite != null)
|
||||
{
|
||||
item = TranslationController.Instance.GetString(
|
||||
StringNames.LobbyChangeSettingNotification,
|
||||
string.Concat(
|
||||
"<sprite name=\"",
|
||||
sprite.name,
|
||||
"\"><font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">",
|
||||
text,
|
||||
TranslationController.Instance.GetString(key),
|
||||
"</color></font>"),
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + value + "</font>"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = TranslationController.Instance.GetString(
|
||||
StringNames.LobbyChangeSettingNotification,
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" +
|
||||
text +
|
||||
TranslationController.Instance.GetString(key) + "</color></font>",
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + value + "</font>");
|
||||
}
|
||||
notif.SettingsChangeMessageLogic(key, item, playSound);
|
||||
}
|
||||
|
||||
internal static bool RegisterGroup(Type type)
|
||||
{
|
||||
if (Activator.CreateInstance(type) is not AbstractOptionGroup group)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TypeToGroup.ContainsKey(type))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Group {type.Name} already exists.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Groups.Add(group);
|
||||
TypeToGroup.Add(type, group);
|
||||
|
||||
typeof(OptionGroupSingleton<>).MakeGenericType(type)
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
|
||||
.SetValue(null, group);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static bool RegisterGroup(Type type, MiraPluginInfo pluginInfo)
|
||||
{
|
||||
if (Activator.CreateInstance(type) is not AbstractOptionGroup group)
|
||||
@@ -45,6 +104,17 @@ public static class ModdedOptionsManager
|
||||
|
||||
Groups.Add(group);
|
||||
TypeToGroup.Add(type, group);
|
||||
if (group.OptionableType?.IsAssignableTo(typeof(AbstractGameMode)) == true)
|
||||
{
|
||||
if (GameModeOptionGroups.TryGetValue(group.OptionableType, out var oldList))
|
||||
{
|
||||
oldList.Add(group);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameModeOptionGroups.Add(group.OptionableType, new List<AbstractOptionGroup>() { group });
|
||||
}
|
||||
}
|
||||
pluginInfo.InternalOptionGroups.Add(group);
|
||||
|
||||
typeof(OptionGroupSingleton<>).MakeGenericType(type)
|
||||
@@ -123,6 +193,7 @@ public static class ModdedOptionsManager
|
||||
|
||||
option.ConfigDefinition = new ConfigDefinition(groupName, propertyName);
|
||||
|
||||
option.ParentGroup = group;
|
||||
option.ParentMod = pluginInfo.MiraPlugin;
|
||||
pluginInfo.InternalOptions.Add(option);
|
||||
ModdedOptions.Add(option.Id, option);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Linq;
|
||||
using MiraAPI.PluginLoading;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
#pragma warning disable CA1852
|
||||
[MiraIgnore]
|
||||
internal class ModifierOptionGroup : AbstractOptionGroup
|
||||
#pragma warning restore CA1852
|
||||
{
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Used to configure the specific visuals for option notifications.
|
||||
/// </summary>
|
||||
public record struct OptionNotifConfiguration
|
||||
{
|
||||
#pragma warning disable S1133
|
||||
[Obsolete("Default constructor is not supported")]
|
||||
#pragma warning restore S1133
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
public OptionNotifConfiguration()
|
||||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
||||
{
|
||||
throw new NotImplementedException("Default constructor is not supported.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OptionNotifConfiguration"/> struct based on a group.
|
||||
/// </summary>
|
||||
/// <param name="group">The <see cref="AbstractOptionGroup"/> in which you are configuring.</param>
|
||||
public OptionNotifConfiguration(AbstractOptionGroup group)
|
||||
{
|
||||
PopUpIconTmp = group.Configuration.PopUpIconTmp;
|
||||
PopUpTextColor = group.Configuration.PopUpTextColor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OptionNotifConfiguration"/> struct from scratch.
|
||||
/// </summary>
|
||||
/// <param name="color">The text <see cref="Color"/> for the configuration.</param>
|
||||
/// <param name="asset">The <see cref="TMP_SpriteAsset"/> icon for the configuration.</param>
|
||||
public OptionNotifConfiguration(Color color, TMP_SpriteAsset asset = null!)
|
||||
{
|
||||
PopUpIconTmp = asset;
|
||||
PopUpTextColor = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="TMP_SpriteAsset"/> for the icon on the options pop-up.
|
||||
/// </summary>
|
||||
public TMP_SpriteAsset PopUpIconTmp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="Color"/> for the text on the options pop-up.
|
||||
/// </summary>
|
||||
[HideFromIl2Cpp]
|
||||
public Color PopUpTextColor { get; set; }
|
||||
}
|
||||
@@ -90,7 +90,13 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(int newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false);
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
Data.GetValueString(newValue),
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
@@ -183,7 +189,13 @@ public class ModdedEnumOption<T> : ModdedOption<T> where T : Enum
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(T newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(Convert.ToInt32(newValue, NumberFormatInfo.InvariantInfo)), false);
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
Data.GetValueString(Convert.ToInt32(newValue, NumberFormatInfo.InvariantInfo)),
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -225,9 +225,12 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
protected override void OnValueChanged(float newValue)
|
||||
{
|
||||
Value = Mathf.Clamp(newValue, Min, Max);
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
Data.GetValueString(Value),
|
||||
Data.GetValueString(newValue),
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
|
||||
if (OptionBehaviour is NumberOption opt)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.PluginLoading;
|
||||
using Reactor.Localization.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions.OptionTypes;
|
||||
@@ -190,4 +189,10 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
{
|
||||
return option.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public AbstractOptionGroup ParentGroup { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual OptionNotifConfiguration Configuration => new(ParentGroup);
|
||||
}
|
||||
@@ -126,7 +126,13 @@ public class ModdedPlayerOption : ModdedOption<int>
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(int newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false);
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
Data.GetValueString(newValue),
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Networking;
|
||||
using Reactor.Localization.Utilities;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
/// <summary>
|
||||
/// An option for selecting an enum value.
|
||||
/// </summary>
|
||||
public class ModdedStringOption : ModdedOption<string>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the string values of the option.
|
||||
/// </summary>
|
||||
public string[] Values { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the String Name values of the option.
|
||||
/// </summary>
|
||||
public StringNames[] StringNameValues { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string's index.
|
||||
/// </summary>
|
||||
/// <param name="value">The option's string value.</param>
|
||||
/// <returns>The option's value in the index.</returns>
|
||||
public int GetIndex(string value, int location)
|
||||
{
|
||||
if (Values.Contains(value))
|
||||
{
|
||||
return Values.ToList().IndexOf(value);
|
||||
}
|
||||
Info($"Cannot find a valid index for {value} in {location}. Returning 0 instead. Values: {string.Join(", ", Values)}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a value to the option.
|
||||
/// </summary>
|
||||
/// <param name="value">The option's string value.</param>
|
||||
/// <param name="index">The additional value's index on the list.</param>
|
||||
public void RegisterExtraValue(string value, int index = -1)
|
||||
{
|
||||
if (!Values.Contains(value))
|
||||
{
|
||||
if (index <= -1)
|
||||
index = Values.Length;
|
||||
|
||||
var newVals = Values.ToList();
|
||||
newVals.Insert(index, value);
|
||||
Values = newVals.ToArray();
|
||||
var newStrVals = StringNameValues.ToList();
|
||||
newStrVals.Insert(index, CustomStringName.CreateAndRegister(value));
|
||||
StringNameValues = newStrVals.ToArray();
|
||||
}
|
||||
|
||||
if (Data != null)
|
||||
{
|
||||
var data = (StringGameSetting)Data;
|
||||
data.Values = StringNameValues;
|
||||
|
||||
data.Index = GetIndex(Value, 1);
|
||||
if (OptionBehaviour != null)
|
||||
{
|
||||
var strOpt = OptionBehaviour.TryCast<StringOption>();
|
||||
if (strOpt != null)
|
||||
{
|
||||
strOpt.Values = StringNameValues;
|
||||
strOpt.Value = GetIndex(Value, 2);
|
||||
Warning("StringOption is valid");
|
||||
}
|
||||
else
|
||||
{
|
||||
Error("StringOption is null.");
|
||||
}
|
||||
Warning("OptionBehaviour is valid");
|
||||
}
|
||||
else
|
||||
{
|
||||
Error("OptionBehaviour is null.");
|
||||
}
|
||||
Warning("Data is valid");
|
||||
}
|
||||
else
|
||||
{
|
||||
Error("Data is null.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedStringOption"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="defaultValue">The default value as a string.</param>
|
||||
/// <param name="values">An option list of string values to use.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedStringOption(string title, string defaultValue, string[] values, bool includeInPreset=true) : base(title, defaultValue, includeInPreset)
|
||||
{
|
||||
Values = values;
|
||||
Data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
var data = (StringGameSetting)Data;
|
||||
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
StringNameValues = values.Select(CustomStringName.CreateAndRegister).ToArray();
|
||||
data.Values = StringNameValues;
|
||||
|
||||
data.Index = GetIndex(Value, 3);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container)
|
||||
{
|
||||
var stringOption = Object.Instantiate(stringOpt, container);
|
||||
stringOption.name =
|
||||
$"{ParentMod!.OptionsTitleText}.StringOption.{TranslationController.Instance.GetString(StringName)}";
|
||||
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
// SetUpFromData method doesnt work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Values = (Data as StringGameSetting)?.Values ?? new Il2CppStructArray<StringNames>(0);
|
||||
stringOption.Value = GetIndex(Value, 4);
|
||||
|
||||
OptionBehaviour = stringOption;
|
||||
ModdedOptionsManager.CreatedStringOptions.TryAdd(stringOption, this);
|
||||
|
||||
return stringOption;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float GetFloatData()
|
||||
{
|
||||
return Array.IndexOf(Values, Value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override NetData GetNetData()
|
||||
{
|
||||
return new NetData(Id, Encoding.Unicode.GetBytes(Convert.ToString(Value, NumberFormatInfo.InvariantInfo)));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void HandleNetData(byte[] data)
|
||||
{
|
||||
SetValue(Encoding.Unicode.GetString(data));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
|
||||
{
|
||||
return Values[optionBehaviour.GetInt()];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(string newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(GetIndex(newValue, 5)), false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OptionBehaviour is StringOption opt)
|
||||
{
|
||||
opt.Value = GetIndex(newValue, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,13 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(bool newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false);
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
newValue ? "On" : "Off",
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.HnsReimplemented.Options;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.HnsReimplemented;
|
||||
|
||||
[RegisterInIl2Cpp]
|
||||
public sealed class HideAndSeekHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
public static HideAndSeekHudHelper Instance { get; private set; }
|
||||
|
||||
public AudioClip FinalHideAlertSfx;
|
||||
|
||||
public AudioClip FinalHideCountdownSfx;
|
||||
|
||||
private AudioClip TaskFinishedSound;
|
||||
|
||||
private const int SECONDS_TO_BEEP = 10;
|
||||
|
||||
private const float SECONDS_TO_SET_DIRTY = 1f;
|
||||
|
||||
private HideAndSeekTimerBar timerBar;
|
||||
|
||||
private float totalHideTime = float.MaxValue;
|
||||
|
||||
private float currentHideTime = float.MaxValue;
|
||||
|
||||
private float totalFinalHideTime = float.MaxValue;
|
||||
|
||||
private float currentFinalHideTime = float.MaxValue;
|
||||
|
||||
private float secondsSinceLastSetDirty;
|
||||
private Coroutine beepCoroutine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public bool IsFinalCountdown
|
||||
{
|
||||
get { return currentHideTime <= 0f; }
|
||||
}
|
||||
|
||||
public bool SeekerAdminMapEnabled(PlayerControl player)
|
||||
{
|
||||
int item = Helpers.GetAlivePlayers().Count(x => !x.Data.Role.IsImpostor);
|
||||
return !player.inVent && player.Data != null && player.Data.Role != null &&
|
||||
((!player.inVent && player.Data.Role.IsImpostor && IsFinalCountdown &&
|
||||
OptionGroupSingleton<HnsFinalHideOptions>.Instance.FinalHideSeekMap.Value) ||
|
||||
(player.Data.Role.IsImpostor &&
|
||||
item <=
|
||||
(GameData.Instance.PlayerCount - 1) / 3));
|
||||
}
|
||||
|
||||
public void OnTaskComplete(float timeDeduction)
|
||||
{
|
||||
if (timerBar != null)
|
||||
{
|
||||
timerBar.TaskComplete();
|
||||
}
|
||||
|
||||
AdjustEscapeTimer(timeDeduction, true);
|
||||
}
|
||||
|
||||
public float GetTotalRoundTime()
|
||||
{
|
||||
float escapeTime = OptionGroupSingleton<HnsCrewmateOptions>.Instance.HidingTime.Value;
|
||||
float finalCountdownTime = OptionGroupSingleton<HnsFinalHideOptions>.Instance.FinalHideTime.Value;
|
||||
return escapeTime + finalCountdownTime;
|
||||
}
|
||||
|
||||
public float GetTotalTimeRemaining()
|
||||
{
|
||||
return currentHideTime + currentFinalHideTime;
|
||||
}
|
||||
|
||||
public float GetRoundTimeElapsed()
|
||||
{
|
||||
return GetTotalRoundTime() - GetTotalTimeRemaining();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
totalHideTime = OptionGroupSingleton<HnsCrewmateOptions>.Instance.HidingTime.Value;
|
||||
currentHideTime = totalHideTime;
|
||||
totalFinalHideTime = OptionGroupSingleton<HnsFinalHideOptions>.Instance.FinalHideTime.Value;
|
||||
currentFinalHideTime = totalFinalHideTime;
|
||||
if (timerBar != null)
|
||||
{
|
||||
Object.Destroy(timerBar);
|
||||
}
|
||||
|
||||
FinalHideAlertSfx = GameManagerCreator.Instance.HideAndSeekManagerPrefab.FinalHideAlertSFX;
|
||||
FinalHideCountdownSfx = GameManagerCreator.Instance.HideAndSeekManagerPrefab.FinalHideCountdownSFX;
|
||||
TaskFinishedSound = GameManagerCreator.Instance.HideAndSeekManagerPrefab.TaskFinishedSound;
|
||||
timerBar = Object.Instantiate<HideAndSeekTimerBar>(
|
||||
GameManagerCreator.Instance.HideAndSeekManagerPrefab.TimerBarPrefab,
|
||||
HudManager.Instance.transform.parent);
|
||||
}
|
||||
|
||||
public void OnGameEnd()
|
||||
{
|
||||
if (timerBar != null)
|
||||
{
|
||||
Object.Destroy(timerBar.gameObject);
|
||||
}
|
||||
|
||||
if (beepCoroutine != null)
|
||||
{
|
||||
StopCoroutine(beepCoroutine);
|
||||
}
|
||||
|
||||
beepCoroutine = null!;
|
||||
}
|
||||
private float taskDirtyTimer;
|
||||
public float HideCountdown { get; set; }
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
if (!HudManager.InstanceExists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (HideCountdown > 0f && taskDirtyTimer > 0.25f)
|
||||
{
|
||||
float num = taskDirtyTimer;
|
||||
taskDirtyTimer = 0f;
|
||||
if (!PlayerControl.LocalPlayer)
|
||||
{
|
||||
HudManager.Instance.TaskPanel.SetTaskText(string.Empty);
|
||||
return;
|
||||
}
|
||||
NetworkedPlayerInfo data = PlayerControl.LocalPlayer.Data;
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool flag = data.Role != null && data.Role.IsImpostor;
|
||||
HudManager.Instance.tasksString.Clear();
|
||||
if (PlayerControl.LocalPlayer.myTasks == null || PlayerControl.LocalPlayer.myTasks.Count == 0)
|
||||
{
|
||||
HudManager.Instance.tasksString.Append("None");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < PlayerControl.LocalPlayer.myTasks.Count; i++)
|
||||
{
|
||||
PlayerTask playerTask = PlayerControl.LocalPlayer.myTasks[i];
|
||||
if (playerTask)
|
||||
{
|
||||
if (playerTask.TaskType == TaskTypes.FixComms && !flag)
|
||||
{
|
||||
HudManager.Instance.tasksString.Clear();
|
||||
playerTask.AppendTaskText(HudManager.Instance.tasksString);
|
||||
break;
|
||||
}
|
||||
playerTask.AppendTaskText(HudManager.Instance.tasksString);
|
||||
}
|
||||
}
|
||||
if (data.Role != null)
|
||||
{
|
||||
data.Role.AppendTaskHint(HudManager.Instance.tasksString);
|
||||
}
|
||||
if (HideCountdown > 0f)
|
||||
{
|
||||
HideCountdown -= num;
|
||||
HudManager.Instance.tasksString.Append("\n\n" + ((int)HideCountdown));
|
||||
}
|
||||
HudManager.Instance.tasksString.TrimEnd();
|
||||
}
|
||||
HudManager.Instance.TaskPanel.SetTaskText(HudManager.Instance.tasksString.ToString());
|
||||
}
|
||||
}
|
||||
public void FixedUpdate()
|
||||
{
|
||||
secondsSinceLastSetDirty += Time.fixedDeltaTime;
|
||||
if (IsFinalCountdown)
|
||||
{
|
||||
AdjustFinalEscapeTimer(Time.fixedDeltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
AdjustEscapeTimer(Time.fixedDeltaTime, false);
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (timerBar != null)
|
||||
{
|
||||
Object.Destroy(timerBar);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFinalCountdownTriggered()
|
||||
{
|
||||
foreach (PlayerControl playerControl in PlayerControl.AllPlayerControls)
|
||||
{
|
||||
if (!playerControl.Data.Role.IsImpostor && !playerControl.Data.IsDead)
|
||||
{
|
||||
playerControl.ClearTasks();
|
||||
PlayerTask.GetOrCreateTask<ImportantTextTask>(playerControl, 0).Text =
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(StringNames.HideActionButton);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PlayerControl.LocalPlayer.Data.IsDead && Minigame.Instance != null)
|
||||
{
|
||||
Minigame instance = Minigame.Instance;
|
||||
if (instance != null)
|
||||
{
|
||||
instance.ForceClose();
|
||||
}
|
||||
}
|
||||
|
||||
timerBar.StartFinalHide();
|
||||
SoundManager.Instance.PlaySound(FinalHideAlertSfx, false, 1f, null);
|
||||
DestroyableSingleton<HudManager>.Instance.SetAlertOverlay(true);
|
||||
}
|
||||
|
||||
private void AdjustEscapeTimer(float timeDeduction, bool forceDirty)
|
||||
{
|
||||
float num = currentHideTime;
|
||||
currentHideTime -= timeDeduction;
|
||||
currentHideTime = Mathf.Max(currentHideTime, 0f);
|
||||
if (currentHideTime <= 10f && beepCoroutine == null)
|
||||
{
|
||||
beepCoroutine = StartCoroutine(BeepAlmostEverySecond().WrapToIl2Cpp());
|
||||
}
|
||||
|
||||
if (num > 0f && currentHideTime <= 0f)
|
||||
{
|
||||
OnFinalCountdownTriggered();
|
||||
}
|
||||
|
||||
timerBar.UpdateTimer(currentHideTime, totalHideTime);
|
||||
if (forceDirty || secondsSinceLastSetDirty > 1f)
|
||||
{
|
||||
secondsSinceLastSetDirty = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator BeepAlmostEverySecond()
|
||||
{
|
||||
while (!IsFinalCountdown)
|
||||
{
|
||||
float num = currentHideTime / 10f;
|
||||
float pitch = 1.5f - num / 2f;
|
||||
SoundManager.Instance.PlaySoundImmediate(FinalHideCountdownSfx, false, 1f, pitch, null);
|
||||
yield return new WaitForSeconds(1f);
|
||||
}
|
||||
|
||||
yield return Effects.Wait(currentFinalHideTime - 10f);
|
||||
while (currentFinalHideTime > 0f)
|
||||
{
|
||||
float num2 = currentFinalHideTime / 10f;
|
||||
float pitch2 = 1.5f - num2 / 2f;
|
||||
SoundManager.Instance.PlaySoundImmediate(FinalHideCountdownSfx, false, 1f, pitch2, null);
|
||||
yield return new WaitForSeconds(1f);
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
private void AdjustFinalEscapeTimer(float timeDeduction)
|
||||
{
|
||||
currentFinalHideTime -= timeDeduction;
|
||||
currentFinalHideTime = Mathf.Max(currentFinalHideTime, 0f);
|
||||
timerBar.UpdateTimer(currentFinalHideTime, totalFinalHideTime);
|
||||
if (secondsSinceLastSetDirty > 1f)
|
||||
{
|
||||
secondsSinceLastSetDirty = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public bool AllTimersExpired()
|
||||
{
|
||||
return currentHideTime <= 0f && currentFinalHideTime <= 0f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.HnsReimplemented.Options;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.HnsReimplemented;
|
||||
|
||||
[RegisterInIl2Cpp]
|
||||
public sealed class HnsDangerMeter(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
public static HnsDangerMeter Instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private DangerMeter dangerMeter;
|
||||
|
||||
private List<PlayerControl> impostors = [];
|
||||
|
||||
private float scaryMusicDistance;
|
||||
|
||||
private float veryScaryMusicDistance;
|
||||
|
||||
private float dangerLevel1;
|
||||
|
||||
private float dangerLevel2;
|
||||
|
||||
private bool firstMusicActivation;
|
||||
|
||||
private float firstCrossfadeCountdown;
|
||||
|
||||
public void FixedUpdate()
|
||||
{
|
||||
PlayerControl localPlayer = PlayerControl.LocalPlayer;
|
||||
if (impostors == null || localPlayer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (impostors.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float num = float.MaxValue;
|
||||
foreach (PlayerControl playerControl in impostors)
|
||||
{
|
||||
if (!(playerControl == null))
|
||||
{
|
||||
float sqrMagnitude = (playerControl.transform.position - localPlayer.transform.position).sqrMagnitude;
|
||||
if (sqrMagnitude < scaryMusicDistance && num > sqrMagnitude)
|
||||
{
|
||||
num = sqrMagnitude;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (HideAndSeekHudHelper.Instance.HideCountdown > 0f)
|
||||
{
|
||||
dangerLevel1 = 0f;
|
||||
dangerLevel2 = 0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (firstMusicActivation)
|
||||
{
|
||||
firstMusicActivation = false;
|
||||
firstCrossfadeCountdown = 3f;
|
||||
HnsMusicHandler.Instance.SetMusicCrossfadeSpeed(0.6f);
|
||||
}
|
||||
|
||||
if (firstCrossfadeCountdown > 0f)
|
||||
{
|
||||
firstCrossfadeCountdown -= Time.deltaTime;
|
||||
if (firstCrossfadeCountdown <= 0f)
|
||||
{
|
||||
HnsMusicHandler.Instance.SetMusicCrossfadeSpeed(5f);
|
||||
}
|
||||
}
|
||||
|
||||
dangerLevel1 = Mathf.Clamp01(
|
||||
(scaryMusicDistance - num) / (scaryMusicDistance - veryScaryMusicDistance));
|
||||
dangerLevel2 = Mathf.Clamp01((veryScaryMusicDistance - num) / veryScaryMusicDistance);
|
||||
}
|
||||
|
||||
UpdateDangerMeter();
|
||||
UpdateDangerMusic();
|
||||
}
|
||||
|
||||
private void UpdateDangerMusic()
|
||||
{
|
||||
PlayerControl localPlayer = PlayerControl.LocalPlayer;
|
||||
if (localPlayer != null && localPlayer.Data != null && localPlayer.Data.IsDead)
|
||||
{
|
||||
HnsMusicHandler.Instance.SetTaskState(false);
|
||||
HnsMusicHandler.Instance.ResetMusic();
|
||||
return;
|
||||
}
|
||||
|
||||
HnsMusicHandler.Instance.SetMusicValues(dangerLevel1, dangerLevel2);
|
||||
}
|
||||
|
||||
private void UpdateDangerMeter()
|
||||
{
|
||||
if (dangerMeter == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
dangerMeter.SetDangerValue(dangerLevel1, dangerLevel2);
|
||||
}
|
||||
|
||||
public void OnGameStart()
|
||||
{
|
||||
firstMusicActivation = true;
|
||||
if (!PlayerControl.LocalPlayer.Data.Role.IsImpostor)
|
||||
{
|
||||
dangerMeter = HudManager.Instance.DangerMeter;
|
||||
dangerMeter.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
impostors = Helpers.GetAlivePlayers().Where(x => x.Data.Role.IsImpostor).ToList();
|
||||
|
||||
var baseSpeed = OptionGroupSingleton<HnsCrewmateOptions>.Instance.PlayerSpeed.Value;
|
||||
scaryMusicDistance = 55f *
|
||||
baseSpeed;
|
||||
veryScaryMusicDistance = 15f *
|
||||
baseSpeed;
|
||||
if (scaryMusicDistance < veryScaryMusicDistance)
|
||||
{
|
||||
float num = veryScaryMusicDistance;
|
||||
float num2 = scaryMusicDistance;
|
||||
scaryMusicDistance = num;
|
||||
veryScaryMusicDistance = num2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
using System.Collections.Generic;
|
||||
using Amongus.GameModes.HideAndSeek;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.HnsReimplemented.Options;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.HnsReimplemented;
|
||||
|
||||
[RegisterInIl2Cpp]
|
||||
public sealed class HnsMusicHandler(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
public static HnsMusicHandler Instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private HideAndSeekMusicCollection musicCollection;
|
||||
|
||||
private float lastMusicSyncTime;
|
||||
|
||||
private bool isDoingTask;
|
||||
|
||||
private float normalVolume;
|
||||
|
||||
private float taskVolume;
|
||||
|
||||
private float dangerLevel1Volume;
|
||||
|
||||
private float dangerLevel2Volume;
|
||||
|
||||
private AudioSource normalSource;
|
||||
|
||||
private AudioSource taskSource;
|
||||
|
||||
private AudioSource dangerLevel1Source;
|
||||
|
||||
private AudioSource dangerLevel2Source;
|
||||
|
||||
private float musicLerpSpeed = 5f;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
musicCollection = GameManagerCreator.Instance.HideAndSeekManagerPrefab.MusicCollection;
|
||||
}
|
||||
|
||||
public void OnGameStart()
|
||||
{
|
||||
InitMusic();
|
||||
ResetMusic();
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
ResetMusic();
|
||||
}
|
||||
|
||||
private void InitMusic()
|
||||
{
|
||||
if (normalSource == null)
|
||||
{
|
||||
normalSource =
|
||||
SoundManager.Instance.GetNamedSfxSource(musicNames[LogicHnSMusic.HideAndSeekMusicTrack.Normal]);
|
||||
}
|
||||
|
||||
normalSource.outputAudioMixerGroup = SoundManager.Instance.MusicChannel;
|
||||
normalSource.clip = musicCollection.NormalMusic;
|
||||
normalSource.loop = true;
|
||||
if (taskSource == null)
|
||||
{
|
||||
taskSource =
|
||||
SoundManager.Instance.GetNamedSfxSource(musicNames[LogicHnSMusic.HideAndSeekMusicTrack.Task]);
|
||||
}
|
||||
|
||||
taskSource.outputAudioMixerGroup = SoundManager.Instance.MusicChannel;
|
||||
taskSource.volume = 0f;
|
||||
taskSource.clip = musicCollection.TaskMusic;
|
||||
taskSource.loop = true;
|
||||
if (dangerLevel1Source == null)
|
||||
{
|
||||
dangerLevel1Source =
|
||||
SoundManager.Instance.GetNamedSfxSource(
|
||||
musicNames[LogicHnSMusic.HideAndSeekMusicTrack.DangerLevel1]);
|
||||
}
|
||||
|
||||
dangerLevel1Source.outputAudioMixerGroup = SoundManager.Instance.MusicChannel;
|
||||
dangerLevel1Source.volume = 0f;
|
||||
dangerLevel1Source.clip = musicCollection.DangerLevel1Music;
|
||||
dangerLevel1Source.loop = true;
|
||||
if (dangerLevel2Source == null)
|
||||
{
|
||||
dangerLevel2Source =
|
||||
SoundManager.Instance.GetNamedSfxSource(
|
||||
musicNames[LogicHnSMusic.HideAndSeekMusicTrack.DangerLevel2]);
|
||||
}
|
||||
|
||||
dangerLevel2Source.outputAudioMixerGroup = SoundManager.Instance.MusicChannel;
|
||||
dangerLevel2Source.volume = 0f;
|
||||
dangerLevel2Source.clip = musicCollection.DangerLevel2Music;
|
||||
dangerLevel2Source.loop = true;
|
||||
normalSource.Play();
|
||||
taskSource.Play();
|
||||
dangerLevel1Source.Play();
|
||||
dangerLevel2Source.Play();
|
||||
SyncMusic();
|
||||
}
|
||||
|
||||
public void StartMusicWithIntro()
|
||||
{
|
||||
if (PlayerControl.LocalPlayer.Data.Role.IsImpostor)
|
||||
{
|
||||
AudioClip clip = OptionGroupSingleton<HnsCrewmateOptions>.Instance.HidingTime.Value <= 180f
|
||||
? musicCollection.ImpostorShortMusic
|
||||
: musicCollection.ImpostorLongMusic;
|
||||
if (AprilFoolsMode.ShouldHorseAround())
|
||||
{
|
||||
clip = musicCollection.ImpostorRanchMusic;
|
||||
}
|
||||
|
||||
SoundManager.Instance.PlaySound(clip, true, 1f, SoundManager.Instance.MusicChannel);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTaskState(bool isDoingTask)
|
||||
{
|
||||
isDoingTask = isDoingTask;
|
||||
}
|
||||
|
||||
public void FixedUpdate()
|
||||
{
|
||||
if (normalSource == null || taskSource == null || dangerLevel1Source == null ||
|
||||
dangerLevel2Source == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.unscaledTime > lastMusicSyncTime + 1f)
|
||||
{
|
||||
SyncMusic();
|
||||
}
|
||||
|
||||
normalSource.volume = Mathf.Lerp(
|
||||
normalSource.volume,
|
||||
normalVolume,
|
||||
Time.fixedDeltaTime * musicLerpSpeed);
|
||||
taskSource.volume = Mathf.Lerp(
|
||||
taskSource.volume,
|
||||
taskVolume,
|
||||
Time.fixedDeltaTime * musicLerpSpeed);
|
||||
dangerLevel1Source.volume = Mathf.Lerp(
|
||||
dangerLevel1Source.volume,
|
||||
dangerLevel1Volume,
|
||||
Time.fixedDeltaTime * musicLerpSpeed);
|
||||
dangerLevel2Source.volume = Mathf.Lerp(
|
||||
dangerLevel2Source.volume,
|
||||
dangerLevel2Volume,
|
||||
Time.fixedDeltaTime * musicLerpSpeed);
|
||||
}
|
||||
|
||||
private void SyncMusic()
|
||||
{
|
||||
taskSource.timeSamples = normalSource.timeSamples;
|
||||
dangerLevel1Source.timeSamples = normalSource.timeSamples;
|
||||
dangerLevel2Source.timeSamples = normalSource.timeSamples;
|
||||
lastMusicSyncTime = Time.unscaledTime;
|
||||
}
|
||||
|
||||
public void ResetMusic()
|
||||
{
|
||||
SetMusicValues(0f, 0f);
|
||||
}
|
||||
|
||||
public void SetMusicCrossfadeSpeed(float lerpSpeed)
|
||||
{
|
||||
musicLerpSpeed = lerpSpeed;
|
||||
}
|
||||
|
||||
public void SetMusicValues(float dangerLevel1, float dangerLevel2)
|
||||
{
|
||||
if (PlayerControl.LocalPlayer != null && PlayerControl.LocalPlayer.Data.Role.IsImpostor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (normalSource == null || taskSource == null || dangerLevel1Source == null ||
|
||||
dangerLevel2Source == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
normalVolume = (isDoingTask ? 0f : 1f);
|
||||
taskVolume = (isDoingTask ? 1f : 0f);
|
||||
dangerLevel1Volume = 0f;
|
||||
dangerLevel2Volume = 0f;
|
||||
if (dangerLevel1 > 0f)
|
||||
{
|
||||
dangerLevel1Volume = dangerLevel1;
|
||||
if (isDoingTask)
|
||||
{
|
||||
taskVolume = 1f - dangerLevel1;
|
||||
}
|
||||
else
|
||||
{
|
||||
normalVolume = 1f - dangerLevel1;
|
||||
}
|
||||
}
|
||||
|
||||
if (dangerLevel2 > 0f)
|
||||
{
|
||||
dangerLevel2Volume = dangerLevel2;
|
||||
dangerLevel1Volume = 1f - dangerLevel2;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<LogicHnSMusic.HideAndSeekMusicTrack, string> musicNames =
|
||||
new Dictionary<LogicHnSMusic.HideAndSeekMusicTrack, string>
|
||||
{
|
||||
{
|
||||
LogicHnSMusic.HideAndSeekMusicTrack.Normal,
|
||||
"HnS_Music_Normal"
|
||||
},
|
||||
{
|
||||
LogicHnSMusic.HideAndSeekMusicTrack.Task,
|
||||
"HnS_Music_Task"
|
||||
},
|
||||
{
|
||||
LogicHnSMusic.HideAndSeekMusicTrack.DangerLevel1,
|
||||
"HnS_Music_DangerLevel1"
|
||||
},
|
||||
{
|
||||
LogicHnSMusic.HideAndSeekMusicTrack.DangerLevel2,
|
||||
"HnS_Music_DangerLevel2"
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.HnsReimplemented.Options;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class HnsCrewmateOptions : AbstractOptionGroup<HideAndSeekMode>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string GroupName => "Crewmates";
|
||||
|
||||
public ModdedNumberOption PlayerSpeed { get; set; } = new(
|
||||
"Player Speed",
|
||||
1f,
|
||||
0.5f,
|
||||
3f,
|
||||
0.25f,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Multiplier,
|
||||
"0.00");
|
||||
|
||||
public ModdedNumberOption HidingTime { get; set; } = new(
|
||||
"Hiding Time",
|
||||
200,
|
||||
160,
|
||||
300,
|
||||
20,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Seconds);
|
||||
|
||||
public ModdedNumberOption CrewmateVision { get; set; } = new(
|
||||
"Crewmate Vision",
|
||||
0.6f,
|
||||
0.25f,
|
||||
1,
|
||||
0.05f,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Multiplier,
|
||||
"0.00");
|
||||
|
||||
public ModdedNumberOption MaxVentUses { get; set; } = new(
|
||||
"Max Vent Uses",
|
||||
1,
|
||||
0,
|
||||
5,
|
||||
1,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.None);
|
||||
|
||||
public ModdedNumberOption MaxTimeInVent { get; set; } = new(
|
||||
"Max Time in Vent",
|
||||
3,
|
||||
1,
|
||||
10,
|
||||
1,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Seconds)
|
||||
{
|
||||
Visible = () => (int)OptionGroupSingleton<HnsCrewmateOptions>.Instance.MaxVentUses.Value > 0,
|
||||
};
|
||||
|
||||
public ModdedToggleOption FlashlightMode { get; set; } = new(
|
||||
"Flashlight Mode",
|
||||
true);
|
||||
|
||||
public ModdedNumberOption CrewmateFlashlightSize { get; set; } = new(
|
||||
"Crewmate Flashlight Size",
|
||||
0.35f,
|
||||
0.1f,
|
||||
0.5f,
|
||||
0.05f,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Multiplier)
|
||||
{
|
||||
Visible = () => OptionGroupSingleton<HnsCrewmateOptions>.Instance.FlashlightMode.Value,
|
||||
};
|
||||
|
||||
public ModdedToggleOption ShowNames { get; set; } = new(
|
||||
"Show Names",
|
||||
false);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.HnsReimplemented.Options;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class HnsFinalHideOptions : AbstractOptionGroup<HideAndSeekMode>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string GroupName => "Final Hide";
|
||||
|
||||
public ModdedNumberOption FinalHideTime { get; set; } = new(
|
||||
"Hiding Time",
|
||||
50,
|
||||
30,
|
||||
120,
|
||||
5,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Seconds);
|
||||
|
||||
public ModdedToggleOption FinalHidePings { get; set; } = new(
|
||||
"Final Hide Pings",
|
||||
true);
|
||||
|
||||
public ModdedNumberOption FinalHideImpostorSpeed { get; set; } = new(
|
||||
"Final Hide Impostor Speed",
|
||||
1.2f,
|
||||
1f,
|
||||
3,
|
||||
0.05f,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Multiplier,
|
||||
"0.00");
|
||||
|
||||
public ModdedNumberOption PingInterval { get; set; } = new(
|
||||
"Ping Interval",
|
||||
6,
|
||||
3,
|
||||
10,
|
||||
5,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Seconds);
|
||||
|
||||
public ModdedToggleOption FinalHideSeekMap { get; set; } = new(
|
||||
"Final Hide Seek Map",
|
||||
true);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.HnsReimplemented.Options;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class HnsImpostorOptions : AbstractOptionGroup<HideAndSeekMode>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string GroupName => "Impostors";
|
||||
|
||||
public ModdedPlayerOption SelectedSeeker { get; set; } = new(
|
||||
"Forced Impostor");
|
||||
|
||||
public ModdedNumberOption ImpostorVision { get; set; } = new(
|
||||
"Impostor Vision",
|
||||
0.6f,
|
||||
0.25f,
|
||||
1,
|
||||
0.05f,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Multiplier,
|
||||
"0.00");
|
||||
|
||||
public ModdedNumberOption ImpostorFlashlightSize { get; set; } = new(
|
||||
"Impostor Flashlight Size",
|
||||
0.35f,
|
||||
0.1f,
|
||||
0.5f,
|
||||
0.05f,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.Multiplier)
|
||||
{
|
||||
Visible = () => OptionGroupSingleton<HnsCrewmateOptions>.Instance.FlashlightMode.Value,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.HnsReimplemented.Options;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class HnsTaskOptions : AbstractOptionGroup<HideAndSeekMode>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string GroupName => "Tasks";
|
||||
|
||||
public ModdedNumberOption CommonTasks { get; set; } = new(
|
||||
"# Common Tasks",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
1,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.None);
|
||||
|
||||
public ModdedNumberOption LongTasks { get; set; } = new(
|
||||
"# Long Tasks",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
1,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.None);
|
||||
|
||||
public ModdedNumberOption ShortTasks { get; set; } = new(
|
||||
"# Short Tasks",
|
||||
2,
|
||||
0,
|
||||
8,
|
||||
1,
|
||||
"#",
|
||||
"#",
|
||||
MiraNumberSuffixes.None);
|
||||
}
|
||||
@@ -7,7 +7,6 @@ using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Patches;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using Rewired;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Collections.ObjectModel;
|
||||
using System.Reflection;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.PluginLoading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
@@ -18,6 +17,20 @@ public static class CustomButtonManager
|
||||
/// </summary>
|
||||
public static ReadOnlyCollection<CustomActionButton> Buttons { get; internal set; } = new([]);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all registered button-specific <see cref="MiraButtonClickEvent"/>s.
|
||||
/// </summary>
|
||||
public static ReadOnlyDictionary<Type, Type> EventTypes { get; internal set; } = new(
|
||||
new Dictionary<Type, Type>
|
||||
{ });
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all registered button-specific <see cref="MiraButtonCancelledEvent"/>s.
|
||||
/// </summary>
|
||||
public static ReadOnlyDictionary<Type, Type> CancelledEventTypes { get; internal set; } = new(
|
||||
new Dictionary<Type, Type>
|
||||
{ });
|
||||
|
||||
internal static readonly List<CustomActionButton> CustomButtons = [];
|
||||
internal static readonly Dictionary<Type, Type> ButtonEventTypes = [];
|
||||
internal static readonly Dictionary<Type, Type> ButtonCancelledEventTypes = [];
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using InnerNet;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Modifiers.ModifierDisplay;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
[RegisterInIl2Cpp]
|
||||
public sealed class MiraHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
public static MiraHudHelper Instance { get; private set; }
|
||||
public static GameObject ModifierDisplayObject;
|
||||
public static GameObject VanillaMatchInfoButton;
|
||||
public static bool ModifierDisplayOnRight;
|
||||
public static GameObject ClonedChatButton;
|
||||
public static GameObject ExtraUiTopRight;
|
||||
public static GridArrange ExtraUiGrid;
|
||||
public static AspectPosition ExtraUiAspectPos;
|
||||
public static GameObject UiTopRight;
|
||||
public static GridArrange UiGrid;
|
||||
public static AspectPosition UiAspectPos;
|
||||
public static GameObject SubmergedFloorButton;
|
||||
public static SpriteRenderer SubmergedFloorButtonRenderer;
|
||||
public static SpriteRenderer SubmergedFloorButtonRendererHover;
|
||||
public void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
MiraApiSettings.OldButtonScaleFactor =
|
||||
LocalSettingsTabSingleton<MiraApiSettings>.Instance.TopRightButtonsFactorSlider.Value;
|
||||
StartCoroutine(MiraApiSettings.CoResizeSettingsUI().WrapToIl2Cpp());
|
||||
}
|
||||
#pragma warning disable S2325
|
||||
#pragma warning disable CA1822
|
||||
public void FixedUpdate()
|
||||
{
|
||||
if (!HudManager.InstanceExists || !PlayerControl.LocalPlayer || !PlayerControl.LocalPlayer.Data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var instance = HudManager.Instance;
|
||||
|
||||
CreateUiRow(instance);
|
||||
CreateNewUiRow(instance);
|
||||
AdjustModifierTab();
|
||||
|
||||
if (!PlayerControl.LocalPlayer || !PlayerControl.LocalPlayer.Data || !PlayerControl.LocalPlayer.Data.Role ||
|
||||
!ShipStatus.Instance ||
|
||||
(AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started &&
|
||||
!TutorialManager.InstanceExists))
|
||||
{
|
||||
return;
|
||||
}
|
||||
UpdateSubmergedButtons(instance);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
#pragma warning restore S2325
|
||||
|
||||
public static Vector3 BelowOptionPos = new(0.435f, 1.25f, 0f);
|
||||
public static Vector3 FullTopPos = new(0.435f, 0.475f, 0f);
|
||||
public static void CreateUiRow(HudManager instance)
|
||||
{
|
||||
if (!UiTopRight)
|
||||
{
|
||||
UiTopRight = instance.MapButton.transform.parent.gameObject;
|
||||
|
||||
UiGrid = UiTopRight.AddComponent<GridArrange>();
|
||||
UiAspectPos = UiTopRight.AddComponent<AspectPosition>();
|
||||
|
||||
UiGrid.Alignment = GridArrange.StartAlign.Left;
|
||||
UiGrid.CellSize = new Vector2(0.85f, 0.85f);
|
||||
UiGrid.MaxColumns = 6;
|
||||
UiAspectPos.Alignment = AspectPosition.EdgeAlignments.RightTop;
|
||||
UiGrid.Start();
|
||||
UiAspectPos.DistanceFromEdge = FullTopPos;
|
||||
var mapButton = instance.MapButton.gameObject;
|
||||
mapButton.GetComponent<AspectPosition>().Destroy();
|
||||
var settingsButton = instance.SettingsButton;
|
||||
settingsButton.GetComponent<AspectPosition>().Destroy();
|
||||
VanillaMatchInfoButton = instance.MatchInfoButton.gameObject;
|
||||
VanillaMatchInfoButton.GetComponent<AspectPosition>().Destroy();
|
||||
var oldPos = settingsButton.transform.localPosition;
|
||||
settingsButton.transform.localPosition = new Vector3(oldPos.x, oldPos.y, -100);
|
||||
var chatButton = instance.Chat.chatButton.gameObject;
|
||||
ClonedChatButton = Object.Instantiate(chatButton, chatButton.transform.parent);
|
||||
ClonedChatButton.SetActive(false);
|
||||
instance.Chat.chatButtonAspectPosition = ClonedChatButton.GetComponent<AspectPosition>();
|
||||
chatButton.GetComponent<AspectPosition>().Destroy();
|
||||
var inactivePos = settingsButton.transform.GetChild(1).transform.localPosition;
|
||||
var bg = settingsButton.transform.GetChild(2).gameObject;
|
||||
var bgPos = bg.transform.localPosition;
|
||||
var bgSprite = bg.GetComponent<SpriteRenderer>().sprite;
|
||||
var activePos = settingsButton.transform.GetChild(3).transform.localPosition;
|
||||
var selectedPos = settingsButton.transform.GetChild(4).transform.localPosition;
|
||||
chatButton.transform.GetChild(2).transform.localPosition = inactivePos;
|
||||
var chatBg = chatButton.transform.GetChild(3);
|
||||
chatBg.transform.localPosition = bgPos;
|
||||
chatBg.GetComponent<SpriteRenderer>().sprite = bgSprite;
|
||||
chatButton.transform.GetChild(4).transform.localPosition = activePos;
|
||||
chatButton.transform.GetChild(5).transform.localPosition = selectedPos;
|
||||
var collider = chatButton.GetComponent<BoxCollider2D>();
|
||||
collider.size = new Vector2(0.4354f, 0.4003f);
|
||||
collider.offset = new Vector2(0.0025f, 0.0254f);
|
||||
if (FriendsListManager.InstanceExists && !TutorialManager.InstanceExists)
|
||||
{
|
||||
var listButton = FriendsListManager.Instance.FriendsListButton.transform.GetChild(0);
|
||||
listButton.transform.SetParent(UiTopRight.transform, false);
|
||||
FriendsListManager.Instance.FriendsListButton = listButton.GetComponent<FriendsListButton>();
|
||||
listButton.GetComponent<AspectPosition>().Destroy();
|
||||
listButton.localPosition = new Vector3(0, 0, 0);
|
||||
}
|
||||
settingsButton.transform.SetAsLastSibling();
|
||||
chatButton.transform.SetParent(UiTopRight.transform, false);
|
||||
instance.Chat.chatButton = chatButton.GetComponent<PassiveButton>();
|
||||
var iconContainer = new GameObject("iconContainer")
|
||||
{
|
||||
layer = LayerMask.NameToLayer("UI"),
|
||||
};
|
||||
iconContainer.transform.SetParent(chatButton.transform, false);
|
||||
iconContainer.transform.localPosition = new Vector3(0.1f, -0.1f, 0);
|
||||
instance.Chat.chatNotifyDot.transform.SetParent(iconContainer.transform, false);
|
||||
instance.Chat.chatNotifyDot = iconContainer.transform.GetChild(0).GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
if (UiTopRight && UiGrid)
|
||||
{
|
||||
var isChatButtonVisible = HudManager.Instance.Chat.isActiveAndEnabled;
|
||||
instance.Chat.chatButton.gameObject.SetActive(isChatButtonVisible);
|
||||
if (VanillaMatchInfoButton)
|
||||
{
|
||||
VanillaMatchInfoButton.SetActive(!GameSettingMenu.Instance && !Minigame.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void UpdateSubmergedButtons(HudManager instance)
|
||||
{
|
||||
if (ModCompatibility.IsSubmerged() && !SubmergedFloorButton && ExtraUiTopRight)
|
||||
{
|
||||
if (!SubmergedFloorButton && ExtraUiTopRight)
|
||||
{
|
||||
var transform = instance.MapButton.transform.parent.Find(instance.MapButton.name + "(Clone)");
|
||||
if (transform != null)
|
||||
{
|
||||
SubmergedFloorButton = transform.gameObject;
|
||||
SubmergedFloorButton.transform.SetParent(ExtraUiTopRight.transform, false);
|
||||
|
||||
SubmergedFloorButtonRenderer =
|
||||
SubmergedFloorButton.transform.Find("Inactive").GetComponent<SpriteRenderer>();
|
||||
SubmergedFloorButtonRendererHover =
|
||||
SubmergedFloorButton.transform.Find("Active").GetComponent<SpriteRenderer>();
|
||||
|
||||
MiraApiSettings.SetUpButtonPositions();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AdjustModifierTab()
|
||||
{
|
||||
if (!ModifierDisplayObject && UiTopRight && ExtraUiTopRight && ModifierDisplayComponent.Instance)
|
||||
{
|
||||
ModifierDisplayObject = ModifierDisplayComponent.Instance?.gameObject ?? null!;
|
||||
ModifierDisplayOnRight = !LocalSettingsTabSingleton<MiraApiSettings>.Instance.ModifiersHudLeftSide.Value;
|
||||
if (ModifierDisplayOnRight)
|
||||
{
|
||||
ModifierDisplayObject.transform.SetParent(ExtraUiTopRight.transform, false);
|
||||
ModifierDisplayObject.GetComponent<AspectPosition>().Destroy();
|
||||
var oldPos = ModifierDisplayObject.transform.GetChild(0).localPosition;
|
||||
ModifierDisplayObject.transform.GetChild(0).localPosition = new Vector3(-1.1757f, -2.1633f, oldPos.z);
|
||||
oldPos = ModifierDisplayObject.transform.GetChild(1).localPosition;
|
||||
ModifierDisplayObject.transform.GetChild(1).localPosition = new Vector3(-0.45f, 0.3f, oldPos.z);
|
||||
}
|
||||
MiraApiSettings.SetUpButtonPositions();
|
||||
}
|
||||
}
|
||||
public static void CreateNewUiRow(HudManager instance)
|
||||
{
|
||||
if (!ExtraUiTopRight && UiTopRight)
|
||||
{
|
||||
ExtraUiTopRight = new GameObject("ExtraUiTopRight")
|
||||
{
|
||||
layer = UiTopRight.layer
|
||||
};
|
||||
ExtraUiTopRight.transform.SetParent(instance.MapButton.transform.parent.parent, false);
|
||||
|
||||
ExtraUiGrid = ExtraUiTopRight.AddComponent<GridArrange>();
|
||||
ExtraUiAspectPos = ExtraUiTopRight.AddComponent<AspectPosition>();
|
||||
|
||||
ExtraUiGrid.Alignment = GridArrange.StartAlign.Left;
|
||||
ExtraUiGrid.CellSize = new Vector2(0.85f, 0.85f);
|
||||
ExtraUiAspectPos.Alignment = AspectPosition.EdgeAlignments.RightTop;
|
||||
ExtraUiAspectPos.DistanceFromEdge = BelowOptionPos;
|
||||
ExtraUiGrid.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Globalization;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
|
||||
namespace MiraAPI.LocalSettings.Attributes;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Localization.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using MiraAPI.GameOptions;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.LocalSettings;
|
||||
|
||||
@@ -14,6 +12,7 @@ public static class LocalSettingsManager
|
||||
{
|
||||
internal static readonly Dictionary<Type, LocalSettingsTab> TypeToTab = [];
|
||||
internal static readonly List<LocalSettingsTab> Tabs = [];
|
||||
internal static readonly List<LocalSettingsTab> AvailableTabs = [];
|
||||
|
||||
internal static bool RegisterTab(Type type, BasePlugin pluginInfo)
|
||||
{
|
||||
@@ -29,6 +28,10 @@ public static class LocalSettingsManager
|
||||
}
|
||||
|
||||
Tabs.Add(tab);
|
||||
if (tab.ShouldCreateButton)
|
||||
{
|
||||
AvailableTabs.Add(tab);
|
||||
}
|
||||
TypeToTab.Add(type, tab);
|
||||
|
||||
typeof(LocalSettingsTabSingleton<>).MakeGenericType(type)
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.PluginLoading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.LocalSettings.SettingTypes;
|
||||
|
||||
/// <inheritdoc />
|
||||
[MiraIgnore]
|
||||
public abstract class LocalSettingBase<T> : ILocalSetting
|
||||
{
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
global using static Reactor.Utilities.Logger<MiraAPI.MiraApiPlugin>;
|
||||
using System;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.VanillaEvents;
|
||||
using Reactor;
|
||||
using Reactor.Networking;
|
||||
using Reactor.Networking.Attributes;
|
||||
@@ -18,10 +20,21 @@ namespace MiraAPI;
|
||||
[BepInAutoPlugin("mira.api", "MiraAPI")]
|
||||
[BepInProcess("Among Us.exe")]
|
||||
[BepInDependency(ReactorPlugin.Id)]
|
||||
[BepInDependency(ModCompatibility.SubmergedId, BepInDependency.DependencyFlags.SoftDependency)]
|
||||
[ReactorModFlags(ModFlags.RequireOnAllClients)]
|
||||
public partial class MiraApiPlugin : BasePlugin
|
||||
public partial class MiraApiPlugin : BasePlugin, IMiraPlugin
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public ConfigFile GetConfigFile()
|
||||
{
|
||||
return Config;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string OptionsTitleText => "MiraAPI";
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool DisplayOnOptionsMenu => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current device is running Starlight (on mobile).
|
||||
/// </summary>
|
||||
@@ -49,10 +62,15 @@ public partial class MiraApiPlugin : BasePlugin
|
||||
public override void Load()
|
||||
{
|
||||
Harmony.PatchAll();
|
||||
JudgeEvents.Initialize();
|
||||
|
||||
ReactorCredits.Register("Mira API", Version, IsDevBuild, ReactorCredits.AlwaysShow);
|
||||
|
||||
PluginManager = new MiraPluginManager();
|
||||
PluginManager.Initialize();
|
||||
PluginManager.Initialize(this, this);
|
||||
|
||||
IL2CPPChainloader.Instance.Finished +=
|
||||
ModCompatibility
|
||||
.Initialize; // Initialise AFTER the mods are loaded to ensure maximum parity (no need for the soft dependency either then)
|
||||
}
|
||||
}
|
||||
+163
-3
@@ -1,4 +1,6 @@
|
||||
using BepInEx.Configuration;
|
||||
using System.Collections;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.LocalSettings.Attributes;
|
||||
using MiraAPI.Patches;
|
||||
@@ -25,15 +27,21 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value stored for scaling buttons properly.
|
||||
/// Gets or sets the value stored for scaling ability buttons properly.
|
||||
/// </summary>
|
||||
public static float OldButtonScaleFactor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value stored for scaling UI buttons properly.
|
||||
/// </summary>
|
||||
public static float OldUiButtonScaleFactor { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Open()
|
||||
{
|
||||
base.Open();
|
||||
OldButtonScaleFactor = ButtonUIFactorSlider.Value;
|
||||
OldUiButtonScaleFactor = TopRightButtonsFactorSlider.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -49,12 +57,153 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
}
|
||||
OldButtonScaleFactor = ButtonUIFactorSlider.Value;
|
||||
}
|
||||
else if (configEntry == TopRightButtonsFactorSlider)
|
||||
{
|
||||
if (MiraHudHelper.Instance)
|
||||
{
|
||||
ResizeUI(TopRightButtonsFactorSlider.Value);
|
||||
}
|
||||
OldUiButtonScaleFactor = TopRightButtonsFactorSlider.Value;
|
||||
}
|
||||
else if (configEntry == WikiOnBottomRow)
|
||||
{
|
||||
SetUpButtonPositions();
|
||||
}
|
||||
else if (configEntry == SetFpsSlider)
|
||||
{
|
||||
Application.targetFrameRate = (int)SetFpsSlider.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetUpButtonPositions()
|
||||
{
|
||||
var topUi = MiraHudHelper.UiTopRight;
|
||||
var extraTopUi = MiraHudHelper.ExtraUiTopRight;
|
||||
var wikiButton = MiraHudHelper.VanillaMatchInfoButton;
|
||||
var subButton = MiraHudHelper.SubmergedFloorButton;
|
||||
var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!;
|
||||
ResetButtonPositions();
|
||||
if (topUi && extraTopUi)
|
||||
{
|
||||
var opts = LocalSettingsTabSingleton<MiraApiSettings>.Instance;
|
||||
if (wikiButton)
|
||||
{
|
||||
wikiButton.transform.SetParent(opts.WikiOnBottomRow.Value ? extraTopUi.transform : topUi.transform);
|
||||
}
|
||||
if (subButton)
|
||||
{
|
||||
subButton.transform.SetParent(extraTopUi.transform);
|
||||
}
|
||||
if (modDisplay)
|
||||
{
|
||||
modDisplay.transform.SetParent(extraTopUi.transform);
|
||||
}
|
||||
MiraHudHelper.UiGrid.ArrangeChilds();
|
||||
MiraHudHelper.ExtraUiGrid.ArrangeChilds();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetButtonPositions()
|
||||
{
|
||||
var topUi = MiraHudHelper.UiTopRight;
|
||||
var extraTopUi = MiraHudHelper.ExtraUiTopRight;
|
||||
var subButton = MiraHudHelper.SubmergedFloorButton;
|
||||
var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!;
|
||||
if (topUi && extraTopUi)
|
||||
{
|
||||
var wikiButton = MiraHudHelper.VanillaMatchInfoButton;
|
||||
if (wikiButton)
|
||||
{
|
||||
wikiButton.transform.SetParent(null);
|
||||
}
|
||||
if (subButton)
|
||||
{
|
||||
subButton.transform.SetParent(null);
|
||||
}
|
||||
if (modDisplay)
|
||||
{
|
||||
modDisplay.transform.SetParent(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerator CoResizeSettingsUI()
|
||||
{
|
||||
while (!HudManager.Instance || !MiraHudHelper.UiGrid || !MiraHudHelper.ExtraUiGrid)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(0.01f);
|
||||
ResizeUI(LocalSettingsTabSingleton<MiraApiSettings>.Instance.TopRightButtonsFactorSlider.Value);
|
||||
}
|
||||
|
||||
public static void ResizeUI(float scaleFactor)
|
||||
{
|
||||
var alteredScale = scaleFactor * 0.85f;
|
||||
var actualScaleVal = scaleFactor * 1.176470588235294f;
|
||||
var actualScale = new Vector3(actualScaleVal, actualScaleVal, 1);
|
||||
var baseAspect = MiraHudHelper.UiAspectPos;
|
||||
var baseGrid = MiraHudHelper.UiGrid;
|
||||
var baseUi = MiraHudHelper.UiTopRight;
|
||||
if (baseUi && baseAspect && baseGrid)
|
||||
{
|
||||
baseAspect.DistanceFromEdge = new Vector2(0.435f * scaleFactor, 0.475f * scaleFactor);
|
||||
|
||||
foreach (var button in baseUi.GetComponentsInChildren<PassiveButton>(true))
|
||||
{
|
||||
if (button.gameObject == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (button.transform.name.Contains("Friends List Button"))
|
||||
{
|
||||
button.gameObject.transform.localScale = new Vector3(0.2675f * actualScaleVal, 0.2675f * actualScaleVal, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
button.gameObject.transform.localScale = actualScale;
|
||||
}
|
||||
|
||||
baseGrid.CellSize = new Vector2(alteredScale, alteredScale);
|
||||
if (baseGrid.gameObject.transform.childCount != 0)
|
||||
{
|
||||
baseGrid.ArrangeChilds();
|
||||
}
|
||||
baseAspect.AdjustPosition();
|
||||
}
|
||||
|
||||
var extraAspect = MiraHudHelper.ExtraUiAspectPos;
|
||||
var extraGrid = MiraHudHelper.ExtraUiGrid;
|
||||
var extraUi = MiraHudHelper.ExtraUiTopRight;
|
||||
if (extraUi && extraAspect && extraGrid)
|
||||
{
|
||||
extraAspect.DistanceFromEdge = new Vector3(0.435f * scaleFactor, 1.25f * scaleFactor, 0f);
|
||||
|
||||
foreach (var button in extraUi.GetAllChildren())
|
||||
{
|
||||
if (button.gameObject == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (button.transform.name.Contains("Modifiers"))
|
||||
{
|
||||
button.gameObject.transform.localScale = new Vector3(0.65f * scaleFactor, 0.65f * scaleFactor, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
button.gameObject.transform.localScale = actualScale;
|
||||
}
|
||||
|
||||
extraGrid.CellSize = new Vector2(alteredScale, alteredScale);
|
||||
if (extraGrid.gameObject.transform.childCount != 0)
|
||||
{
|
||||
extraGrid.ArrangeChilds();
|
||||
}
|
||||
extraAspect.AdjustPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the modifiers hud should be on the left side of the screen (under roles/task tab). Recommended for streamers.
|
||||
/// </summary>
|
||||
@@ -68,12 +217,19 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
public ConfigEntry<bool> ShowKeybinds { get; private set; } = config.Bind("Visuals/UI", "Show Keybinds on Buttons", true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scale of the buttons.
|
||||
/// Gets the scale of the ability buttons.
|
||||
/// </summary>
|
||||
[LocalSliderSetting(min: 0.5f, max: 1.5f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
||||
public ConfigEntry<float> ButtonUIFactorSlider { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Button Scale Factor", 0.75f);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scale of the UI buttons.
|
||||
/// </summary>
|
||||
[LocalSliderSetting(min: 0.3f, max: 2f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
||||
public ConfigEntry<float> TopRightButtonsFactorSlider { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Top-Right UI Scale Factor", 1f);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fps specified by the player.
|
||||
/// </summary>
|
||||
@@ -81,6 +237,10 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
public ConfigEntry<float> SetFpsSlider { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Max FPS", 120f);
|
||||
|
||||
[LocalToggleSetting]
|
||||
public ConfigEntry<bool> WikiOnBottomRow { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Display Wiki on Bottom Row", true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to apply cosmetic changes to the TaskAdder.
|
||||
/// </summary>
|
||||
|
||||
+32
-11
@@ -1,6 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using SemanticVersioning;
|
||||
|
||||
namespace MiraAPI;
|
||||
|
||||
@@ -14,15 +14,36 @@ public static class ModCompatibility
|
||||
/// </summary>
|
||||
public const string SubmergedId = "Submerged";
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the Submerged mod is loaded.
|
||||
/// </summary>
|
||||
/// <param name="submergedAssembly">Submerged mod assembly if loaded, <see langword="null"/> otherwise.</param>
|
||||
/// <returns><see langword="true"/> if the Submerged mod is loaded, <see langword="false"/> otherwise.</returns>
|
||||
public static bool SubmergedLoaded([NotNullWhen(true)] out Assembly? submergedAssembly)
|
||||
public static Version SubVersion { get; private set; }
|
||||
public static bool SubLoaded { get; private set; }
|
||||
public static BasePlugin SubPlugin { get; private set; }
|
||||
public static Assembly SubAssembly { get; private set; }
|
||||
|
||||
public const ShipStatus.MapType SubmergedMapType = (ShipStatus.MapType)6;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
var result = IL2CPPChainloader.Instance.Plugins.TryGetValue(SubmergedId, out var plugin);
|
||||
submergedAssembly = result ? plugin?.Instance.GetType().Assembly : null;
|
||||
return result;
|
||||
InitSubmerged();
|
||||
}
|
||||
|
||||
public static void InitSubmerged()
|
||||
{
|
||||
if (!IL2CPPChainloader.Instance.Plugins.TryGetValue(SubmergedId, out var plugin))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SubPlugin = (plugin!.Instance as BasePlugin)!;
|
||||
SubVersion = plugin.Metadata.Version;
|
||||
|
||||
SubAssembly = SubPlugin.GetType().Assembly;
|
||||
|
||||
SubLoaded = true;
|
||||
Message("Submerged was detected");
|
||||
}
|
||||
|
||||
public static bool IsSubmerged()
|
||||
{
|
||||
return SubLoaded && ShipStatus.Instance && ShipStatus.Instance.Type == SubmergedMapType;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Modifiers.ModifierDisplay;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
using MiraAPI.Patches.Roles;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.Extensions;
|
||||
@@ -138,7 +137,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
internal void DestroyComponent(ModifierUiComponent component)
|
||||
{
|
||||
_modifiers.Remove(component.Modifier!);
|
||||
component.gameObject.DeepDestroy();
|
||||
component.gameObject.Destroy();
|
||||
RefreshModifiers();
|
||||
}
|
||||
|
||||
@@ -208,7 +207,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
continue;
|
||||
}
|
||||
|
||||
mod.Value.gameObject.DeepDestroy();
|
||||
mod.Value.gameObject.Destroy();
|
||||
_modifiers.Remove(mod.Key);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ using MiraAPI.Networking;
|
||||
using MiraAPI.Networking.Modifiers;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Modifiers;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ using MiraAPI.Modifiers.Types;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using Random = System.Random;
|
||||
|
||||
@@ -137,7 +136,10 @@ public static class ModifierManager
|
||||
var validPlayers = plrs.Where(x => IsGameModifierValid(x, modifier, modifier.TypeId)).ToList();
|
||||
if (validPlayers.Count == 0)
|
||||
{
|
||||
Warning($"No valid players for modifier {modifier.ModifierName}");
|
||||
if (MiraApiPlugin.IsDevBuild)
|
||||
{
|
||||
Warning($"No valid players for modifier {modifier.ModifierName}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -153,20 +155,28 @@ public static class ModifierManager
|
||||
}
|
||||
|
||||
var candidates = availablePlayers
|
||||
.Where(x => IsGameModifierValid(x, modifier, modifier.TypeId))
|
||||
.Where(x => IsGameModifierPostCheck(x, modifier, modifier.TypeId))
|
||||
.ToList();
|
||||
|
||||
if (candidates.Count == 0)
|
||||
{
|
||||
Warning(
|
||||
$"No available players for modifier {modifier.ModifierName} at assignment {i + 1}");
|
||||
if (MiraApiPlugin.IsDevBuild)
|
||||
{
|
||||
Warning(
|
||||
$"No available players for modifier {modifier.ModifierName} at assignment {i + 1}");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
var plr = candidates.Random();
|
||||
if (plr == null)
|
||||
{
|
||||
Warning($"Valid player for modifier {modifier.ModifierName} disappeared");
|
||||
if (MiraApiPlugin.IsDevBuild)
|
||||
{
|
||||
Warning($"Valid player for modifier {modifier.ModifierName} disappeared");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -179,7 +189,12 @@ public static class ModifierManager
|
||||
private static bool IsGameModifierValid(PlayerControl player, GameModifier modifier, uint modifierId)
|
||||
{
|
||||
return (player.Data.Role is not ICustomRole role || role.IsModifierApplicable(modifier)) &&
|
||||
modifier.IsModifierValidOn(player.Data.Role) && !player.HasModifier(modifierId) &&
|
||||
!player.HasModifier(modifierId) && modifier.IsModifierValidOn(player.Data.Role) &&
|
||||
modifier.CanSpawnOnCurrentMode();
|
||||
}
|
||||
private static bool IsGameModifierPostCheck(PlayerControl player, GameModifier modifier, uint modifierId)
|
||||
{
|
||||
return (player.Data.Role is not ICustomRole role || role.IsModifierApplicable(modifier)) &&
|
||||
!player.HasModifier(modifierId) && modifier.IsModifierValidOnPostCheck(player.Data.Role);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
namespace MiraAPI.Modifiers.Types;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.PluginLoading;
|
||||
|
||||
namespace MiraAPI.Modifiers.Types;
|
||||
|
||||
/// <summary>
|
||||
/// The base class for a game modifier. Game modifiers are applied at the start of the game on top of the player's role.
|
||||
/// </summary>
|
||||
[MiraIgnore]
|
||||
public abstract class GameModifier : BaseModifier
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -33,6 +37,13 @@ public abstract class GameModifier : BaseModifier
|
||||
/// <returns><see langword="true"/> if the modifier is valid on the role, otherwise <see langword="false"/>.</returns>
|
||||
public virtual bool IsModifierValidOn(RoleBehaviour role) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the modifier is valid on a role, which runs after players are determined but before the modifiers are given.
|
||||
/// </summary>
|
||||
/// <param name="role">The role to be checked.</param>
|
||||
/// <returns><see langword="true"/> if the modifier is valid on the role, otherwise <see langword="false"/>.</returns>
|
||||
public virtual bool IsModifierValidOnPostCheck(RoleBehaviour role) => IsModifierValidOn(role);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the player won the game with this modifier. The modifier with the highest priority will override other modifiers.
|
||||
/// </summary>
|
||||
@@ -44,5 +55,5 @@ public abstract class GameModifier : BaseModifier
|
||||
/// Determines whether the modifier can spawn in general, accounting for gamemodes and everything else.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if the modifier is able to spawn, otherwise <see langword="false"/>.</returns>
|
||||
public virtual bool CanSpawnOnCurrentMode() => !GameManager.Instance.IsHideAndSeek();
|
||||
public virtual bool CanSpawnOnCurrentMode() => CustomGameModeManager.IsClassic() && !GameManager.Instance.IsHideAndSeek();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using MiraAPI.PluginLoading;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -7,6 +8,7 @@ namespace MiraAPI.Modifiers.Types;
|
||||
/// <summary>
|
||||
/// The base class for all timed modifiers. Timed modifiers have a duration and can be started and stopped.
|
||||
/// </summary>
|
||||
[MiraIgnore]
|
||||
public abstract class TimedModifier : BaseModifier
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -4,7 +4,6 @@ using InnerNet;
|
||||
using MiraAPI.GameEnd;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Networking;
|
||||
|
||||
|
||||
@@ -7,12 +7,10 @@ using Assets.CoreScripts;
|
||||
using BepInEx.Unity.IL2CPP.Utils;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using Rewired;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -87,13 +85,15 @@ public static class CustomMurderRpc
|
||||
|
||||
var beforeMurderEvent = new BeforeMurderEvent(source, target, inMeeting);
|
||||
MiraEventManager.InvokeEvent(beforeMurderEvent);
|
||||
var defenseFlag = beforeMurderEvent.IgnoreDefense;
|
||||
var indirectFlag = beforeMurderEvent.IsIndirectAttack;
|
||||
var isMeetingActive = MeetingHud.Instance != null || ExileController.Instance != null;
|
||||
if ((inMeeting is MeetingCheck.ForMeeting && !isMeetingActive) || (inMeeting is MeetingCheck.OutsideMeeting && isMeetingActive))
|
||||
{
|
||||
beforeMurderEvent.Cancel();
|
||||
}
|
||||
|
||||
if (target.ProtectedByGa())
|
||||
if (!defenseFlag && target.ProtectedByGa())
|
||||
{
|
||||
beforeMurderEvent.Cancel();
|
||||
murderResultFlags = MurderResultFlags.FailedProtected;
|
||||
@@ -117,6 +117,8 @@ public static class CustomMurderRpc
|
||||
PlayerControl.LocalPlayer,
|
||||
source,
|
||||
target,
|
||||
indirectFlag,
|
||||
defenseFlag,
|
||||
murderResultFlags,
|
||||
resetKillTimer,
|
||||
createDeadBody,
|
||||
@@ -131,6 +133,8 @@ public static class CustomMurderRpc
|
||||
/// <param name="host">The game host.</param>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
/// <param name="isIndirect">Should the kill be indirect.</param>
|
||||
/// <param name="ignoreDefense">Should the kill ignore defense.</param>
|
||||
/// <param name="murderResultFlags">End result for the murder.</param>
|
||||
/// <param name="resetKillTimer">Should the kill timer be reset.</param>
|
||||
/// <param name="createDeadBody">Should a dead body be created.</param>
|
||||
@@ -142,6 +146,149 @@ public static class CustomMurderRpc
|
||||
this PlayerControl host,
|
||||
PlayerControl source,
|
||||
PlayerControl target,
|
||||
bool isIndirect,
|
||||
bool ignoreDefense,
|
||||
MurderResultFlags murderResultFlags,
|
||||
bool resetKillTimer = true,
|
||||
bool createDeadBody = true,
|
||||
bool teleportMurderer = true,
|
||||
bool showKillAnim = true,
|
||||
bool playKillSound = true)
|
||||
{
|
||||
if (LobbyBehaviour.Instance || !host.IsHost() || target.Data.IsDead || target.Data.Disconnected)
|
||||
{
|
||||
source.isKilling = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var murderResultFlags2 = MurderResultFlags.DecisionByHost | murderResultFlags;
|
||||
|
||||
if (isIndirect || ignoreDefense)
|
||||
{
|
||||
source.CustomMurder(
|
||||
target,
|
||||
null,
|
||||
isIndirect,
|
||||
ignoreDefense,
|
||||
murderResultFlags2,
|
||||
resetKillTimer,
|
||||
createDeadBody,
|
||||
teleportMurderer,
|
||||
showKillAnim,
|
||||
playKillSound);
|
||||
}
|
||||
else
|
||||
{
|
||||
source.CustomMurder(
|
||||
target,
|
||||
murderResultFlags2,
|
||||
resetKillTimer,
|
||||
createDeadBody,
|
||||
teleportMurderer,
|
||||
showKillAnim,
|
||||
playKillSound);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Networked Custom Murder method, which checks for meetings as well, ran by clients for the host to confirm kills.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
/// <param name="inMeeting">Whether the murder is intended to be triggered in a meeting.</param>
|
||||
/// <param name="isIndirect">Should the kill be indirect.</param>
|
||||
/// <param name="ignoreDefense">Should the kill ignore defense.</param>
|
||||
/// <param name="didSucceed">Whether the murder was successful or not.</param>
|
||||
/// <param name="resetKillTimer">Should the kill timer be reset.</param>
|
||||
/// <param name="createDeadBody">Should a dead body be created.</param>
|
||||
/// <param name="teleportMurderer">Should the killer be snapped to the dead player.</param>
|
||||
/// <param name="showKillAnim">Should the kill animation be shown.</param>
|
||||
/// <param name="playKillSound">Should the kill sound be played.</param>
|
||||
[MethodRpc((uint)MiraRpc.AdvancedCustomMurder, LocalHandling = RpcLocalHandling.Before)]
|
||||
public static void RpcAdvancedCustomMurder(
|
||||
this PlayerControl source,
|
||||
PlayerControl target,
|
||||
MeetingCheck inMeeting,
|
||||
bool isIndirect,
|
||||
bool ignoreDefense = false,
|
||||
bool didSucceed = true,
|
||||
bool resetKillTimer = true,
|
||||
bool createDeadBody = true,
|
||||
bool teleportMurderer = true,
|
||||
bool showKillAnim = true,
|
||||
bool playKillSound = true)
|
||||
{
|
||||
if (LobbyBehaviour.Instance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var murderResultFlags = didSucceed ? MurderResultFlags.Succeeded : MurderResultFlags.FailedError;
|
||||
|
||||
var beforeMurderEvent = new BeforeMurderEvent(source, target, isIndirect, ignoreDefense, inMeeting);
|
||||
MiraEventManager.InvokeEvent(beforeMurderEvent);
|
||||
var defenseFlag = beforeMurderEvent.IgnoreDefense;
|
||||
var indirectFlag = beforeMurderEvent.IsIndirectAttack;
|
||||
var isMeetingActive = MeetingHud.Instance != null || ExileController.Instance != null;
|
||||
if ((inMeeting is MeetingCheck.ForMeeting && !isMeetingActive) || (inMeeting is MeetingCheck.OutsideMeeting && isMeetingActive))
|
||||
{
|
||||
beforeMurderEvent.Cancel();
|
||||
}
|
||||
|
||||
if (!defenseFlag && target.ProtectedByGa())
|
||||
{
|
||||
beforeMurderEvent.Cancel();
|
||||
murderResultFlags = MurderResultFlags.FailedProtected;
|
||||
}
|
||||
else if (beforeMurderEvent.IsCancelled)
|
||||
{
|
||||
murderResultFlags = MurderResultFlags.FailedError;
|
||||
}
|
||||
|
||||
if (beforeMurderEvent.IsCancelled && source.AmOwner)
|
||||
{
|
||||
source.isKilling = true;
|
||||
}
|
||||
|
||||
if (!PlayerControl.LocalPlayer.IsHost())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RpcConfirmAdvancedCustomMurder(
|
||||
PlayerControl.LocalPlayer,
|
||||
source,
|
||||
target,
|
||||
indirectFlag,
|
||||
defenseFlag,
|
||||
murderResultFlags,
|
||||
resetKillTimer,
|
||||
createDeadBody,
|
||||
teleportMurderer,
|
||||
showKillAnim,
|
||||
playKillSound);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Networked Custom Murder method, which checks for meetings as well, ran by clients for the host to confirm kills.
|
||||
/// </summary>
|
||||
/// <param name="host">The game host.</param>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
/// <param name="isIndirect">Should the kill be indirect.</param>
|
||||
/// <param name="ignoreDefense">Should the kill ignore defense.</param>
|
||||
/// <param name="murderResultFlags">End result for the murder.</param>
|
||||
/// <param name="resetKillTimer">Should the kill timer be reset.</param>
|
||||
/// <param name="createDeadBody">Should a dead body be created.</param>
|
||||
/// <param name="teleportMurderer">Should the killer be snapped to the dead player.</param>
|
||||
/// <param name="showKillAnim">Should the kill animation be shown.</param>
|
||||
/// <param name="playKillSound">Should the kill sound be played.</param>
|
||||
[MethodRpc((uint)MiraRpc.ConfirmAdvancedCustomMurder, LocalHandling = RpcLocalHandling.After)]
|
||||
public static void RpcConfirmAdvancedCustomMurder(
|
||||
this PlayerControl host,
|
||||
PlayerControl source,
|
||||
PlayerControl target,
|
||||
bool isIndirect,
|
||||
bool ignoreDefense,
|
||||
MurderResultFlags murderResultFlags,
|
||||
bool resetKillTimer = true,
|
||||
bool createDeadBody = true,
|
||||
@@ -159,6 +306,9 @@ public static class CustomMurderRpc
|
||||
|
||||
source.CustomMurder(
|
||||
target,
|
||||
null,
|
||||
isIndirect,
|
||||
ignoreDefense,
|
||||
murderResultFlags2,
|
||||
resetKillTimer,
|
||||
createDeadBody,
|
||||
@@ -168,10 +318,145 @@ public static class CustomMurderRpc
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom Murder method without networking. If you need a networked version, use <see cref="RpcCustomMurder(PlayerControl, PlayerControl, bool, bool, bool, bool, bool, bool)"/>.
|
||||
/// Networked Custom Murder method, which checks for meetings as well, ran by clients for the host to confirm kills.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
/// <param name="framed">The player to frame.</param>
|
||||
/// <param name="inMeeting">Whether the murder is intended to be triggered in a meeting.</param>
|
||||
/// <param name="isIndirect">Should the kill be indirect.</param>
|
||||
/// <param name="ignoreDefense">Should the kill ignore defense.</param>
|
||||
/// <param name="didSucceed">Whether the murder was successful or not.</param>
|
||||
/// <param name="resetKillTimer">Should the kill timer be reset.</param>
|
||||
/// <param name="createDeadBody">Should a dead body be created.</param>
|
||||
/// <param name="teleportMurderer">Should the framed player be snapped to the dead player.</param>
|
||||
/// <param name="showKillAnim">Should the kill animation be shown.</param>
|
||||
/// <param name="playKillSound">Should the kill sound be played.</param>
|
||||
[MethodRpc((uint)MiraRpc.FramedCustomMurder, LocalHandling = RpcLocalHandling.Before)]
|
||||
public static void RpcFramedCustomMurder(
|
||||
this PlayerControl source,
|
||||
PlayerControl target,
|
||||
PlayerControl framed,
|
||||
MeetingCheck inMeeting,
|
||||
bool isIndirect = true,
|
||||
bool ignoreDefense = false,
|
||||
bool didSucceed = true,
|
||||
bool resetKillTimer = true,
|
||||
bool createDeadBody = true,
|
||||
bool teleportMurderer = true,
|
||||
bool showKillAnim = true,
|
||||
bool playKillSound = true)
|
||||
{
|
||||
if (LobbyBehaviour.Instance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var murderResultFlags = didSucceed ? MurderResultFlags.Succeeded : MurderResultFlags.FailedError;
|
||||
|
||||
var beforeMurderEvent = new BeforeMurderEvent(source, target, framed, isIndirect, ignoreDefense, inMeeting);
|
||||
MiraEventManager.InvokeEvent(beforeMurderEvent);
|
||||
var defenseFlag = beforeMurderEvent.IgnoreDefense;
|
||||
var indirectFlag = beforeMurderEvent.IsIndirectAttack;
|
||||
var isMeetingActive = MeetingHud.Instance != null || ExileController.Instance != null;
|
||||
if ((inMeeting is MeetingCheck.ForMeeting && !isMeetingActive) || (inMeeting is MeetingCheck.OutsideMeeting && isMeetingActive))
|
||||
{
|
||||
beforeMurderEvent.Cancel();
|
||||
}
|
||||
|
||||
if (!defenseFlag && target.ProtectedByGa())
|
||||
{
|
||||
beforeMurderEvent.Cancel();
|
||||
murderResultFlags = MurderResultFlags.FailedProtected;
|
||||
}
|
||||
else if (beforeMurderEvent.IsCancelled)
|
||||
{
|
||||
murderResultFlags = MurderResultFlags.FailedError;
|
||||
}
|
||||
|
||||
if (beforeMurderEvent.IsCancelled && source.AmOwner)
|
||||
{
|
||||
source.isKilling = true;
|
||||
}
|
||||
|
||||
if (!PlayerControl.LocalPlayer.IsHost())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RpcConfirmFramedCustomMurder(
|
||||
PlayerControl.LocalPlayer,
|
||||
source,
|
||||
target,
|
||||
framed,
|
||||
indirectFlag,
|
||||
defenseFlag,
|
||||
murderResultFlags,
|
||||
resetKillTimer,
|
||||
createDeadBody,
|
||||
teleportMurderer,
|
||||
showKillAnim,
|
||||
playKillSound);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Networked Custom Murder method, which checks for meetings as well, ran by clients for the host to confirm kills.
|
||||
/// </summary>
|
||||
/// <param name="host">The game host.</param>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
/// <param name="framed">The player to frame.</param>
|
||||
/// <param name="isIndirect">Should the kill be indirect.</param>
|
||||
/// <param name="ignoreDefense">Should the kill ignore defense.</param>
|
||||
/// <param name="murderResultFlags">End result for the murder.</param>
|
||||
/// <param name="resetKillTimer">Should the kill timer be reset.</param>
|
||||
/// <param name="createDeadBody">Should a dead body be created.</param>
|
||||
/// <param name="teleportMurderer">Should the framed player be snapped to the dead player.</param>
|
||||
/// <param name="showKillAnim">Should the kill animation be shown.</param>
|
||||
/// <param name="playKillSound">Should the kill sound be played.</param>
|
||||
[MethodRpc((uint)MiraRpc.ConfirmFramedCustomMurder, LocalHandling = RpcLocalHandling.After)]
|
||||
public static void RpcConfirmFramedCustomMurder(
|
||||
this PlayerControl host,
|
||||
PlayerControl source,
|
||||
PlayerControl target,
|
||||
PlayerControl framed,
|
||||
bool isIndirect,
|
||||
bool ignoreDefense,
|
||||
MurderResultFlags murderResultFlags,
|
||||
bool resetKillTimer = true,
|
||||
bool createDeadBody = true,
|
||||
bool teleportMurderer = true,
|
||||
bool showKillAnim = true,
|
||||
bool playKillSound = true)
|
||||
{
|
||||
if (LobbyBehaviour.Instance || !host.IsHost() || target.Data.IsDead || target.Data.Disconnected)
|
||||
{
|
||||
source.isKilling = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var murderResultFlags2 = MurderResultFlags.DecisionByHost | murderResultFlags;
|
||||
|
||||
source.CustomMurder(
|
||||
target,
|
||||
framed,
|
||||
isIndirect,
|
||||
ignoreDefense,
|
||||
murderResultFlags2,
|
||||
resetKillTimer,
|
||||
createDeadBody,
|
||||
teleportMurderer,
|
||||
showKillAnim,
|
||||
playKillSound);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom Murder method without networking. If you need a networked version, use <see cref="RpcFramedCustomMurder"/> or <see cref="RpcAdvancedCustomMurder"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
/// <param name="framed">The player to frame, if any.</param>
|
||||
/// <param name="isIndirect">Should the kill be indirect.</param>
|
||||
/// <param name="ignoreDefense">Should the kill ignore defense.</param>
|
||||
/// <param name="resultFlags">Murder result flags.</param>
|
||||
/// <param name="resetKillTimer">Should the kill timer be reset.</param>
|
||||
/// <param name="createDeadBody">Should a dead body be created.</param>
|
||||
@@ -181,6 +466,9 @@ public static class CustomMurderRpc
|
||||
public static void CustomMurder(
|
||||
this PlayerControl source,
|
||||
PlayerControl target,
|
||||
PlayerControl? framed,
|
||||
bool isIndirect,
|
||||
bool ignoreDefense,
|
||||
MurderResultFlags resultFlags,
|
||||
bool resetKillTimer = true,
|
||||
bool createDeadBody = true,
|
||||
@@ -194,8 +482,9 @@ public static class CustomMurderRpc
|
||||
return;
|
||||
}
|
||||
|
||||
if (resultFlags.HasFlag(MurderResultFlags.FailedProtected) ||
|
||||
(resultFlags.HasFlag(MurderResultFlags.DecisionByHost) && target.protectedByGuardianId > -1))
|
||||
if (!ignoreDefense && (resultFlags.HasFlag(MurderResultFlags.FailedProtected) ||
|
||||
(resultFlags.HasFlag(MurderResultFlags.DecisionByHost) &&
|
||||
target.protectedByGuardianId > -1)))
|
||||
{
|
||||
target.protectedByGuardianThisRound = true;
|
||||
var flag = PlayerControl.LocalPlayer.Data.Role.Role == RoleTypes.GuardianAngel;
|
||||
@@ -293,7 +582,141 @@ public static class CustomMurderRpc
|
||||
source.CurrentOutfitType == PlayerOutfitType.Shapeshifted,
|
||||
source.shapeshiftTargetPlayerId,
|
||||
target.PlayerId);
|
||||
source.MyPhysics.StartCoroutine(source.KillAnimations.RandomSnapshot().CoPerformCustomKill(source, target, createDeadBody, teleportMurderer));
|
||||
source.MyPhysics.StartCoroutine(source.KillAnimations.RandomSnapshot().CoPerformCustomKill(source, target, framed, isIndirect, ignoreDefense, createDeadBody, teleportMurderer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom Murder method without networking. If you need a networked version, use <see cref="RpcCustomMurder(PlayerControl, PlayerControl, bool, bool, bool, bool, bool, bool)"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The player to murder.</param>
|
||||
/// <param name="resultFlags">Murder result flags.</param>
|
||||
/// <param name="resetKillTimer">Should the kill timer be reset.</param>
|
||||
/// <param name="createDeadBody">Should a dead body be created.</param>
|
||||
/// <param name="teleportMurderer">Should the killer be snapped to the dead player.</param>
|
||||
/// <param name="showKillAnim">Should the kill animation be shown.</param>
|
||||
/// <param name="playKillSound">Should the kill sound be played.</param>
|
||||
public static void CustomMurder(
|
||||
this PlayerControl source,
|
||||
PlayerControl target,
|
||||
MurderResultFlags resultFlags,
|
||||
bool resetKillTimer = true,
|
||||
bool createDeadBody = true,
|
||||
bool teleportMurderer = true,
|
||||
bool showKillAnim = true,
|
||||
bool playKillSound = true)
|
||||
{
|
||||
source.isKilling = false;
|
||||
if (resultFlags.HasFlag(MurderResultFlags.FailedError) || LobbyBehaviour.Instance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (resultFlags.HasFlag(MurderResultFlags.FailedProtected) ||
|
||||
(resultFlags.HasFlag(MurderResultFlags.DecisionByHost) && target.protectedByGuardianId > -1))
|
||||
{
|
||||
target.protectedByGuardianThisRound = true;
|
||||
var flag = PlayerControl.LocalPlayer.Data.Role.Role == RoleTypes.GuardianAngel;
|
||||
if (flag && PlayerControl.LocalPlayer.Data.PlayerId == target.protectedByGuardianId)
|
||||
{
|
||||
DataManager.Player.Stats.IncrementStat(StatID.Role_GuardianAngel_CrewmatesProtected);
|
||||
AchievementManager.Instance.OnProtectACrewmate();
|
||||
}
|
||||
|
||||
if (source.AmOwner || flag)
|
||||
{
|
||||
target.ShowFailedMurder();
|
||||
|
||||
if (resetKillTimer)
|
||||
{
|
||||
source.SetKillTimer(
|
||||
CustomGameModeManager.ActiveMode != null
|
||||
? CustomGameModeManager.ActiveMode.DefaultImpostorKillCooldown / 2f
|
||||
: GameOptionsManager.Instance.CurrentGameOptions.GetFloat(FloatOptionNames.KillCooldown) /
|
||||
2f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
target.RemoveProtection();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resultFlags.HasFlag(MurderResultFlags.Succeeded) &&
|
||||
!resultFlags.HasFlag(MurderResultFlags.DecisionByHost))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DebugAnalytics.Instance.Analytics.Kill(target.Data, source.Data);
|
||||
if (source.AmOwner)
|
||||
{
|
||||
DataManager.Player.Stats.IncrementStat(
|
||||
GameManager.Instance.IsHideAndSeek()
|
||||
? StatID.HideAndSeek_ImpostorKills
|
||||
: StatID.ImpostorKills);
|
||||
|
||||
if (source.CurrentOutfitType == PlayerOutfitType.Shapeshifted)
|
||||
{
|
||||
DataManager.Player.Stats.IncrementStat(StatID.Role_Shapeshifter_ShiftedKills);
|
||||
}
|
||||
|
||||
if (Constants.ShouldPlaySfx() && playKillSound)
|
||||
{
|
||||
SoundManager.Instance.PlaySound(source.KillSfx, false, 0.8f);
|
||||
}
|
||||
|
||||
if (resetKillTimer)
|
||||
{
|
||||
source.SetKillTimer(CustomGameModeManager.ActiveMode != null
|
||||
? CustomGameModeManager.ActiveMode.DefaultImpostorKillCooldown
|
||||
: GameOptionsManager.Instance.CurrentGameOptions.GetFloat(FloatOptionNames.KillCooldown));
|
||||
}
|
||||
}
|
||||
|
||||
UnityTelemetry.Instance.WriteMurder();
|
||||
target.gameObject.layer = LayerMask.NameToLayer("Ghost");
|
||||
if (target.AmOwner)
|
||||
{
|
||||
DataManager.Player.Stats.IncrementStat(StatID.TimesMurdered);
|
||||
if (Minigame.Instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
Minigame.Instance.Close();
|
||||
Minigame.Instance.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
if (showKillAnim)
|
||||
{
|
||||
try
|
||||
{
|
||||
HudManager.Instance.KillOverlay.ShowKillAnimation(source.Data, target.Data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Error with kill animation: {e.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
target.cosmetics.SetNameMask(false);
|
||||
target.RpcSetScanner(false);
|
||||
}
|
||||
|
||||
AchievementManager.Instance.OnMurder(
|
||||
source.AmOwner,
|
||||
target.AmOwner,
|
||||
source.CurrentOutfitType == PlayerOutfitType.Shapeshifted,
|
||||
source.shapeshiftTargetPlayerId,
|
||||
target.PlayerId);
|
||||
source.MyPhysics.StartCoroutine(source.KillAnimations.RandomSnapshot().CoPerformCustomKill(source, target, null, false, false, createDeadBody, teleportMurderer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -302,6 +725,9 @@ public static class CustomMurderRpc
|
||||
/// <param name="anim">The kill animation.</param>
|
||||
/// <param name="source">The murderer.</param>
|
||||
/// <param name="target">The murdered player.</param>
|
||||
/// <param name="framed">The framed player, if any.</param>
|
||||
/// <param name="isIndirect">Was the kill indirect.</param>
|
||||
/// <param name="ignoreDefense">Would the kill ignore defense.</param>
|
||||
/// <param name="createDeadBody">Should a dead body be created.</param>
|
||||
/// <param name="teleportMurderer">Should the murder be teleported.</param>
|
||||
/// <returns>Coroutine.</returns>
|
||||
@@ -309,6 +735,9 @@ public static class CustomMurderRpc
|
||||
this KillAnimation anim,
|
||||
PlayerControl source,
|
||||
PlayerControl target,
|
||||
PlayerControl? framed,
|
||||
bool isIndirect,
|
||||
bool ignoreDefense,
|
||||
bool createDeadBody = true,
|
||||
bool teleportMurderer = true)
|
||||
{
|
||||
@@ -317,12 +746,13 @@ public static class CustomMurderRpc
|
||||
yield break;
|
||||
}
|
||||
var cam = Camera.main?.GetComponent<FollowerCamera>();
|
||||
var isParticipant = source.AmOwner || target.AmOwner;
|
||||
var sourcePhys = source.MyPhysics;
|
||||
var playerToLunge = framed ?? source;
|
||||
var isParticipant = playerToLunge.AmOwner || target.AmOwner;
|
||||
var sourcePhys = playerToLunge.MyPhysics;
|
||||
|
||||
if (teleportMurderer)
|
||||
{
|
||||
KillAnimation.SetMovement(source, false);
|
||||
KillAnimation.SetMovement(playerToLunge, false);
|
||||
}
|
||||
|
||||
KillAnimation.SetMovement(target, false);
|
||||
@@ -376,7 +806,7 @@ public static class CustomMurderRpc
|
||||
yield return source.MyPhysics.Animations.CoPlayCustomAnimation(anim.BlurAnim);
|
||||
sourcePhys.Animations.PlayIdleAnimation();
|
||||
source.NetTransform.SnapTo(target.transform.position);
|
||||
KillAnimation.SetMovement(source, true);
|
||||
KillAnimation.SetMovement(playerToLunge, true);
|
||||
}
|
||||
|
||||
KillAnimation.SetMovement(target, true);
|
||||
@@ -386,7 +816,7 @@ public static class CustomMurderRpc
|
||||
deadBody.enabled = true;
|
||||
}
|
||||
|
||||
var afterMurderEvent = new AfterMurderEvent(source, target, deadBody);
|
||||
var afterMurderEvent = framed != null ? new AfterMurderEvent(source, target, framed, deadBody, isIndirect, ignoreDefense) : new AfterMurderEvent(source, target, deadBody, isIndirect, ignoreDefense);
|
||||
MiraEventManager.InvokeEvent(afterMurderEvent);
|
||||
|
||||
if (!isParticipant)
|
||||
|
||||
@@ -40,6 +40,26 @@ public enum MiraRpc : uint
|
||||
/// </summary>
|
||||
ConfirmCustomMurder,
|
||||
|
||||
/// <summary>
|
||||
/// Advanced Custom Murder RPC.
|
||||
/// </summary>
|
||||
AdvancedCustomMurder,
|
||||
|
||||
/// <summary>
|
||||
/// Advanced Custom Murder RPC Confirmation.
|
||||
/// </summary>
|
||||
ConfirmAdvancedCustomMurder,
|
||||
|
||||
/// <summary>
|
||||
/// Framed Custom Murder RPC.
|
||||
/// </summary>
|
||||
FramedCustomMurder,
|
||||
|
||||
/// <summary>
|
||||
/// Framed Custom Murder RPC Confirmation.
|
||||
/// </summary>
|
||||
ConfirmFramedCustomMurder,
|
||||
|
||||
/// <summary>
|
||||
/// Custom Game Over RPC.
|
||||
/// </summary>
|
||||
@@ -54,4 +74,14 @@ public enum MiraRpc : uint
|
||||
/// Custom RPC to replace Among Us CastVote.
|
||||
/// </summary>
|
||||
CastVote,
|
||||
|
||||
/// <summary>
|
||||
/// Custom RPC to replace Among Us QueueOverruleVotes.
|
||||
/// </summary>
|
||||
QueueOverruleVotes,
|
||||
|
||||
/// <summary>
|
||||
/// Custom RPC to sync the Gamemode option.
|
||||
/// </summary>
|
||||
SyncGamemodeOption,
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using InnerNet;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Player;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Roles;
|
||||
|
||||
@@ -32,6 +33,7 @@ internal static class AmongUsClientSyncPatch
|
||||
|
||||
ModdedOptionsManager.SyncAllOptions(clientData.Id);
|
||||
CustomRoleManager.SyncAllRoleSettings(clientData.Id);
|
||||
GameModeOption.RpcSyncGamemode(PlayerControl.LocalPlayer, GameModeOption.Value);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
|
||||
@@ -4,7 +4,6 @@ using InnerNet;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Meeting;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Events.Vanilla.Usables;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
|
||||
@@ -278,7 +278,6 @@ public static class TaskAdderPatches
|
||||
|
||||
__instance.ActiveItems.ToArray().Do(x => x.gameObject.DeepDestroy(false));
|
||||
__instance.ActiveItems.Clear();
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
|
||||
float num = 0f;
|
||||
float num2 = 0f;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(IntroCutscene), nameof(IntroCutscene.CoBegin))]
|
||||
internal static class BodyTypePatch
|
||||
{
|
||||
public static bool Prefix(IntroCutscene __instance, ref Il2CppSystem.Collections.IEnumerator __result)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode?.ShowGameModeIntroCutscene == true)
|
||||
{
|
||||
__result = CustomGameModeManager.ActiveMode.IntroCutscene(__instance).WrapToIl2Cpp();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,18 @@
|
||||
/*
|
||||
using HarmonyLib;
|
||||
using InnerNet;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class ConsolePatches
|
||||
internal static class ConsolePatches
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(Console), nameof(Console.CanUse))]
|
||||
[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))
|
||||
if (CustomGameModeManager.ActiveMode == null || CustomGameModeManager.ActiveMode.CanUseTasks(__instance))
|
||||
{
|
||||
var task = __instance.FindTask(pc.Object);
|
||||
|
||||
@@ -31,15 +35,15 @@ public static class ConsolePatches
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(SystemConsole), nameof(SystemConsole.CanUse))]
|
||||
[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))
|
||||
if (CustomGameModeManager.ActiveMode == null || CustomGameModeManager.ActiveMode.CanUseSystemConsole(__instance))
|
||||
{
|
||||
return canUse = couldUse = true;
|
||||
canUse = couldUse = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
canUse = couldUse = false;
|
||||
@@ -50,15 +54,15 @@ public static class ConsolePatches
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(MapConsole), nameof(MapConsole.CanUse))]
|
||||
[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))
|
||||
if (CustomGameModeManager.ActiveMode == null || CustomGameModeManager.ActiveMode.CanUseMapConsole(__instance))
|
||||
{
|
||||
return canUse = couldUse = true;
|
||||
canUse = couldUse = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
canUse = couldUse = false;
|
||||
@@ -68,4 +72,40 @@ public static class ConsolePatches
|
||||
canUse = couldUse = true;
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(MapConsole), nameof(MapConsole.Use))]
|
||||
public static bool MapUsePatch(MapConsole __instance)
|
||||
{
|
||||
if (AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started && ShipStatus.Instance)
|
||||
{
|
||||
return CustomGameModeManager.ActiveMode == null ||
|
||||
CustomGameModeManager.ActiveMode.CanUseMapConsole(__instance);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(SystemConsole), nameof(SystemConsole.Use))]
|
||||
public static bool SystemUsePatch(SystemConsole __instance)
|
||||
{
|
||||
if (AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started && ShipStatus.Instance)
|
||||
{
|
||||
return CustomGameModeManager.ActiveMode == null ||
|
||||
CustomGameModeManager.ActiveMode.CanUseSystemConsole(__instance);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(Console), nameof(Console.Use))]
|
||||
public static bool ConsoleUsePatch(Console __instance)
|
||||
{
|
||||
if (AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started && ShipStatus.Instance)
|
||||
{
|
||||
return CustomGameModeManager.ActiveMode == null ||
|
||||
CustomGameModeManager.ActiveMode.CanUseTasks(__instance);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using HarmonyLib;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.SetGameMode))]
|
||||
internal static class CreateOptionsPatch
|
||||
{
|
||||
public static bool Prefix(CreateOptionsPicker __instance, AmongUs.GameOptions.GameModes mode)
|
||||
{
|
||||
if (mode <= AmongUs.GameOptions.GameModes.SeekFools)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: finish this
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
/*
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(DeadBody))]
|
||||
public static class DeadBodyPatch
|
||||
internal static class DeadBodyPatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(DeadBody.OnClick))]
|
||||
[HarmonyPrefix, HarmonyPatch(nameof(DeadBody.OnClick))]
|
||||
public static bool OnClickPatch(DeadBody __instance)
|
||||
{
|
||||
return CustomGameModeManager.ActiveMode == null || CustomGameModeManager.ActiveMode.CanReport(__instance);
|
||||
return CustomGameModeManager.ActiveMode?.CanReport(__instance) == true;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -1,20 +1,78 @@
|
||||
/*
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class GameLogicPatches
|
||||
internal static class GameLogicPatches
|
||||
{
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(LogicGameFlowNormal), nameof(LogicGameFlowNormal.CheckEndCriteria))]
|
||||
public static bool EndCritPatch(LogicGameFlowNormal __instance)
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(GameManager), nameof(GameManager.DidHumansWin))]
|
||||
public static bool DidHumansWin(GameOverReason reason, ref bool __result)
|
||||
{
|
||||
var runOriginal = true;
|
||||
CustomGameModeManager.ActiveMode?.CheckGameEnd(out runOriginal, __instance);
|
||||
return runOriginal;
|
||||
__result = reason == GameOverReason.CrewmatesByTask || reason == GameOverReason.CrewmatesByVote ||
|
||||
reason == GameOverReason.ImpostorDisconnect || reason == GameOverReason.HideAndSeek_CrewmatesByTimer;
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(LogicRoleSelectionNormal), nameof(LogicRoleSelectionNormal.AssignRolesFromList))]
|
||||
public static bool AssignRolesPatch(LogicRoleSelectionNormal __instance)
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(GameManager), nameof(GameManager.DidImpostorsWin))]
|
||||
public static bool DidImpostorsWin(GameOverReason reason, ref bool __result)
|
||||
{
|
||||
var runOriginal = true;
|
||||
CustomGameModeManager.ActiveMode?.AssignRoles(out runOriginal, __instance);
|
||||
return runOriginal;
|
||||
__result = reason == GameOverReason.ImpostorsByKill || reason == GameOverReason.ImpostorsBySabotage ||
|
||||
reason == GameOverReason.ImpostorsByVote || reason == GameOverReason.HideAndSeek_ImpostorsByKills ||
|
||||
reason == GameOverReason.CrewmateDisconnect;
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
[HarmonyPrefix, HarmonyPatch(typeof(NormalGameManager), nameof(NormalGameManager.GetBodyType))]
|
||||
public static bool BodyTypePatch(NormalGameManager __instance, PlayerControl player, ref PlayerBodyTypes __result)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode == null || !CustomGameModeManager.ActiveMode.GameModeBodyTypeOverride)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
__result = CustomGameModeManager.ActiveMode.GetBodyType(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(LogicGameFlowNormal), nameof(LogicGameFlowNormal.CheckEndCriteria))]
|
||||
public static bool EndGamePatch(LogicGameFlowNormal __instance)
|
||||
{
|
||||
if (TutorialManager.InstanceExists)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GameData.Instance)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CustomGameModeManager.ActiveMode != null)
|
||||
{
|
||||
CustomGameModeManager.ActiveMode.CheckGameEnd(out var runOriginal, __instance);
|
||||
|
||||
if (!runOriginal)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(LogicGameFlowNormal), nameof(LogicGameFlowNormal.IsGameOverDueToDeath))]
|
||||
public static void IsGameOverDueToDeathPatch(LogicGameFlowNormal __instance, ref bool __result)
|
||||
{
|
||||
if (CustomGameModeManager.IsActiveGameMode<HideAndSeekMode>())
|
||||
{
|
||||
__result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(GameManager))]
|
||||
internal static class GameManagerPatches
|
||||
{
|
||||
[HarmonyPrefix, HarmonyPatch(nameof(GameManager.OnPlayerDeath))]
|
||||
public static bool OnDeathPrefix([HarmonyArgument(0)] PlayerControl player, [HarmonyArgument(1)] bool assignGhostRole)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode != null)
|
||||
{
|
||||
CustomGameModeManager.ActiveMode.OnPlayerDeath(player, assignGhostRole);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
[HarmonyPrefix, HarmonyPatch(nameof(GameManager.ShowCrewmatesKilled))]
|
||||
public static bool ShowCrewmatesKilledPrefix(ref bool __result)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode != null)
|
||||
{
|
||||
__result = CustomGameModeManager.ActiveMode is HideAndSeekMode;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
[HarmonyPatch(typeof(NormalGameManager), nameof(NormalGameManager.GetMapOptions))]
|
||||
[HarmonyPrefix]
|
||||
public static bool GetMapOptions(ref MapOptions __result)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
__result = CustomGameModeManager.ActiveMode.GetMapOptions();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(GameStartManager))]
|
||||
internal static class GameStartManagerPatches
|
||||
{
|
||||
[HarmonyPrefix, HarmonyPatch(nameof(GameStartManager.Start))]
|
||||
public static void StartPatch(GameStartManager __instance)
|
||||
{
|
||||
if (MiraApiPlugin.IsDevBuild)
|
||||
{
|
||||
__instance.MinPlayers = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using HarmonyLib;
|
||||
using Il2CppSystem;
|
||||
using MiraAPI.GameModes;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(HudManager))]
|
||||
internal static class HudPatches
|
||||
{
|
||||
[HarmonyPostfix, HarmonyPatch(nameof(HudManager.Update))]
|
||||
public static void HudUpdatePatch(HudManager __instance)
|
||||
{
|
||||
if (GameManager.Instance != null && GameManager.Instance.GameHasStarted &&
|
||||
CustomGameModeManager.ActiveMode != null)
|
||||
{
|
||||
CustomGameModeManager.ActiveMode.HudUpdate(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Start))]
|
||||
[HarmonyPostfix]
|
||||
public static void PostHudStart(HudManager __instance)
|
||||
{
|
||||
Coroutines.Start(CoPostHudStart(__instance));
|
||||
}
|
||||
|
||||
private static IEnumerator CoPostHudStart(HudManager instance)
|
||||
{
|
||||
yield return new WaitUntil((Func<bool>)(() => GameManager.Instance != null));
|
||||
if (GameManager.Instance.IsHideAndSeek())
|
||||
yield return null;
|
||||
var infoPane = instance.gameObject.transform.FindChild("LobbyInfoPane");
|
||||
var aspect = infoPane.gameObject.transform.Find("AspectSize");
|
||||
var modeLabel = aspect!.Find("ModeLabel");
|
||||
var modeValue = aspect.Find("ModeValue");
|
||||
var modelText = modeLabel!.Find("Text_TMP").gameObject;
|
||||
var modelTextClone = Object.Instantiate(modelText, modeLabel);
|
||||
Object.Destroy(modelTextClone.GetComponent<TextTranslatorTMP>());
|
||||
modelTextClone.GetComponent<TextMeshPro>().text = "Gamemode";
|
||||
var gmText = modeValue!.Find("GameModeText").gameObject;
|
||||
var gmTextClone = Object.Instantiate(gmText, modeValue);
|
||||
gmText.SetActive(false);
|
||||
modelText.SetActive(false);
|
||||
_text = gmTextClone.GetComponent<TextMeshPro>();
|
||||
_text.text = CustomGameModeManager.ActiveMode != null ? $"<color=#{CustomGameModeManager.ActiveMode.Color.ToHtmlStringRGBA()}>{CustomGameModeManager.ActiveMode.Name}</color>" : "Classic";
|
||||
CustomGameModeManager.ActiveMode?.HudStart(instance);
|
||||
}
|
||||
|
||||
private static TextMeshPro? _text;
|
||||
internal static void SetGameModeText(string text)
|
||||
{
|
||||
if (_text != null)
|
||||
_text.text = text;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
/*
|
||||
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
|
||||
/// 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
|
||||
internal static class ImpostorTargetPatch
|
||||
{
|
||||
public static bool Prefix(ImpostorRole __instance, [HarmonyArgument(0)] NetworkedPlayerInfo target, ref bool __result)
|
||||
{
|
||||
@@ -16,9 +20,8 @@ public static class ImpostorTargetPatch
|
||||
}
|
||||
|
||||
__result = target is { Disconnected: false, IsDead: false } &&
|
||||
target.PlayerId != __instance.Player.PlayerId && !(target.Role == null) &&
|
||||
!(target.Object == null) && !target.Object.inVent && !target.Object.inMovingPlat;
|
||||
target.PlayerId != __instance.Player.PlayerId && target.Role != null &&
|
||||
target.Object != null && !target.Object.inVent && !target.Object.inMovingPlat;
|
||||
return false;
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(IntroCutscene), nameof(IntroCutscene.CoBegin))]
|
||||
internal static class IntroCutscenePatch
|
||||
{
|
||||
public static bool Prefix(IntroCutscene __instance, ref Il2CppSystem.Collections.IEnumerator __result)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode?.ShowGameModeIntroCutscene == true)
|
||||
{
|
||||
__result = CustomGameModeManager.ActiveMode.IntroCutscene(__instance).WrapToIl2Cpp();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
/*
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(MapBehaviour))]
|
||||
public static class MapBehaviourPatch
|
||||
internal static class MapBehaviourPatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(MapBehaviour.ShowSabotageMap))]
|
||||
[HarmonyPrefix, HarmonyPatch(nameof(MapBehaviour.ShowSabotageMap))]
|
||||
public static bool ShowSabotagePatch(MapBehaviour __instance)
|
||||
{
|
||||
var shouldShow = CustomGameModeManager.ActiveMode?.ShouldShowSabotageMap(__instance);
|
||||
@@ -15,4 +18,4 @@ public static class MapBehaviourPatch
|
||||
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(NormalGameManager))]
|
||||
internal static class NormalGameManagerPatches
|
||||
{
|
||||
[HarmonyPrefix, HarmonyPatch(nameof(NormalGameManager.IsNormal))]
|
||||
public static void IsNormal(ref bool __result)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode != null)
|
||||
{
|
||||
__result = !CustomGameModeManager.ActiveMode.IsHideAndSeek;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,11 +0,0 @@
|
||||
/*
|
||||
[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);
|
||||
}
|
||||
}*/
|
||||
@@ -0,0 +1,17 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
[HarmonyPatch(typeof(ProgressTracker), nameof(ProgressTracker.Start))]
|
||||
internal static class ProgressTrackerPatch
|
||||
{
|
||||
public static bool Prefix(ProgressTracker __instance)
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode != null && !CustomGameModeManager.ActiveMode.ShowTaskBar)
|
||||
{
|
||||
__instance.gameObject.SetActive(false);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
[HarmonyPatch(typeof(TaskPanelBehaviour), nameof(TaskPanelBehaviour.Update))]
|
||||
internal static class TaskPanelPatch
|
||||
{
|
||||
public static bool Prefix(TaskPanelBehaviour __instance)
|
||||
{
|
||||
if (__instance != Roles.HudManagerPatches.RoleTab && CustomGameModeManager.ActiveMode != null)
|
||||
{
|
||||
CustomGameModeManager.ActiveMode.UpdateTaskPanel(__instance);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
[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;
|
||||
}
|
||||
}*/
|
||||
@@ -0,0 +1,27 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
|
||||
namespace MiraAPI.Patches.GameModes;
|
||||
|
||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnGameEnd))]
|
||||
internal static class WinnersPatch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void ShowWinningScreen()
|
||||
{
|
||||
if (CustomGameModeManager.ActiveMode is null or ClassicMode)
|
||||
return;
|
||||
|
||||
var winners = CustomGameModeManager.ActiveMode.CalculateWinners();
|
||||
|
||||
if (winners is null)
|
||||
return;
|
||||
|
||||
EndGameResult.CachedWinners.Clear();
|
||||
|
||||
foreach (var data in winners)
|
||||
{
|
||||
EndGameResult.CachedWinners.Add(new(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches.Hud;
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
@@ -123,6 +125,47 @@ public static class HudManagerPatches
|
||||
CustomGameModeManager.ActiveMode?.HudStart(__instance);
|
||||
}*/
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(FriendsListManager), nameof(FriendsListManager.SetFriendButtonColor))]
|
||||
public static bool SetFriendButtonColor(FriendsListManager __instance, bool isGrayedOut)
|
||||
{
|
||||
__instance.FriendsListButton?.SetGlyphColor(isGrayedOut);
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.Toggle))]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.Close))]
|
||||
public static void TogglePrefix(ChatController __instance)
|
||||
{
|
||||
if (!MiraHudHelper.ClonedChatButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
__instance.chatButton.transform.localPosition = MiraHudHelper.ClonedChatButton.transform.localPosition + new Vector3(-0.3f, 0);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.Toggle))]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.Close))]
|
||||
public static void TogglePostfix(ChatController __instance)
|
||||
{
|
||||
MiraHudHelper.UiGrid.ArrangeChilds();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.AddChatNote))]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.AddChat))]
|
||||
[HarmonyPatch(typeof(ChatController), nameof(ChatController.AddChatWarning))]
|
||||
public static void ChatBubbleUpdatePrefix(ChatController __instance)
|
||||
{
|
||||
__instance.chatNotifyDot.transform.localPosition = new Vector3(-0.34f, 0.373f, -1f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create custom buttons and arrange them on the hud.
|
||||
/// </summary>
|
||||
@@ -131,6 +174,7 @@ public static class HudManagerPatches
|
||||
[HarmonyPatch(nameof(HudManager.Start))]
|
||||
public static void StartPostfix(HudManager __instance)
|
||||
{
|
||||
__instance.gameObject.AddComponent<MiraHudHelper>();
|
||||
if (Buttons == null)
|
||||
{
|
||||
Buttons = __instance.transform.Find("Buttons");
|
||||
@@ -148,9 +192,8 @@ public static class HudManagerPatches
|
||||
|
||||
foreach (var t in BottomLeft.GetComponentsInChildren<ActionButton>(true))
|
||||
{
|
||||
t.gameObject.DeepDestroy(false);
|
||||
t.gameObject.Destroy();
|
||||
}
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
|
||||
var gridArrange = BottomLeft.GetComponent<GridArrange>();
|
||||
var aspectPosition = BottomLeft.GetComponent<AspectPosition>();
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
@@ -31,6 +30,11 @@ public static class IntroCutscenePatches
|
||||
{
|
||||
var @event = new IntroBeginEvent(__instance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (CustomGameModeManager.ActiveMode != null)
|
||||
{
|
||||
CustomGameModeManager.ActiveMode.Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
@@ -123,8 +127,6 @@ public static class IntroCutscenePatches
|
||||
introCutscene = __instance.Cast<IntroCutscene>();
|
||||
}
|
||||
|
||||
Info("IntroCutscene ended");
|
||||
|
||||
MiraEventManager.InvokeEvent(new IntroEndEvent(introCutscene));
|
||||
|
||||
var @event = new BeforeRoundStartEvent(true);
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.LocalSettings;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using Rewired.UI.ControlMapper;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace MiraAPI.Patches.Keybinds;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Keybinds;
|
||||
using MonoMod.Utils;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Patches.Keybinds;
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -70,7 +69,7 @@ public static class OptionsMenuPatches
|
||||
int i = 0;
|
||||
int tabIdx = 0;
|
||||
int page = 1;
|
||||
foreach (var settings in LocalSettingsManager.Tabs)
|
||||
foreach (var settings in LocalSettingsManager.AvailableTabs)
|
||||
{
|
||||
var tab = settings.CreateTab(__instance);
|
||||
if (settings.ShouldCreateButton)
|
||||
@@ -165,12 +164,12 @@ public static class OptionsMenuPatches
|
||||
public static bool OpenTabGroupPrefix(OptionsMenuBehaviour __instance, ref int index)
|
||||
{
|
||||
__instance.Tabs.ToList().ForEach(x => x.Close()); // Close all vanilla tabs
|
||||
LocalSettingsManager.Tabs.ForEach(CustomClose); // Close all mod tabs
|
||||
LocalSettingsManager.AvailableTabs.ForEach(CustomClose); // Close all mod tabs
|
||||
|
||||
// Tabs with index 10 and above are the mod settings tabs
|
||||
if (index >= 10)
|
||||
{
|
||||
CustomOpen(LocalSettingsManager.Tabs[index - 10]);
|
||||
CustomOpen(LocalSettingsManager.AvailableTabs[index - 10]);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -184,7 +183,7 @@ public static class OptionsMenuPatches
|
||||
[HarmonyPatch(nameof(OptionsMenuBehaviour.Open))]
|
||||
public static void OpenPostfix(OptionsMenuBehaviour __instance)
|
||||
{
|
||||
LocalSettingsManager.Tabs.ForEach(CustomClose);
|
||||
LocalSettingsManager.AvailableTabs.ForEach(CustomClose);
|
||||
currentPage = 1;
|
||||
UpdatePages();
|
||||
}
|
||||
|
||||
@@ -100,10 +100,9 @@ public static class HatsTabPatches
|
||||
if (loadRoutine != null) Coroutines.Stop(loadRoutine);
|
||||
|
||||
hatIndex = 0;
|
||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
|
||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
var group = sortedHats.Where(x => x.Key == storeNames[page]);
|
||||
|
||||
@@ -7,6 +7,8 @@ using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -81,10 +83,9 @@ public static class NameplatesTabPatches
|
||||
|
||||
private static void GenerateHats(NameplatesTab __instance, int page)
|
||||
{
|
||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
|
||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
|
||||
|
||||
@@ -83,10 +83,9 @@ public static class SkinsTabPatches
|
||||
|
||||
private static void GenerateHats(SkinsTab __instance, int page)
|
||||
{
|
||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
|
||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
|
||||
|
||||
@@ -80,10 +80,9 @@ public static class VisorsTabPatches
|
||||
|
||||
private static void GenerateHats(VisorsTab __instance, int page)
|
||||
{
|
||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
|
||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using Il2CppSystem.Collections.Generic;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Presets;
|
||||
@@ -13,6 +16,7 @@ using Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.ProBuilder;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -21,6 +25,366 @@ namespace MiraAPI.Patches.Options;
|
||||
[HarmonyPatch(typeof(GameOptionsMenu))]
|
||||
internal static class GameOptionsMenuPatch
|
||||
{
|
||||
private static List<CategoryHeaderMasked> _vanillaHeaders = new();
|
||||
private static List<OptionBehaviour> _vanillaOptions = new();
|
||||
private static List<OptionBehaviour> _mainOptions = new();
|
||||
private static System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<AbstractOptionGroup>> _gameModeGroups = new();
|
||||
private static System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<OptionBehaviour>> _gameModeOptions = new();
|
||||
private static System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<CategoryHeaderMasked>> _gameModeHeaders = new();
|
||||
private static TextMeshPro _gamemodeDescription = null!;
|
||||
private static SpriteRenderer _modIcon = null!;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GameOptionsMenu.Initialize))]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static bool InitPatch(GameOptionsMenu __instance)
|
||||
{
|
||||
__instance.Children ??= new Il2CppSystem.Collections.Generic.List<OptionBehaviour>();
|
||||
__instance.Children.Clear();
|
||||
|
||||
if (MenuState.Instance.CurrentModIdx == 0)
|
||||
{
|
||||
__instance.MapPicker.gameObject.SetActive(true);
|
||||
__instance.cachedData = GameOptionsManager.Instance.CurrentGameOptions;
|
||||
var container = MenuState.Instance.CurrentContainer.transform;
|
||||
|
||||
if (container.childCount == 1)
|
||||
{
|
||||
__instance.MapPicker.Initialize(20);
|
||||
var mapNameSetting = GameManager.Instance.GameSettingsList.MapNameSetting;
|
||||
__instance.MapPicker.SetUpFromData(mapNameSetting, 20);
|
||||
__instance.Children.Add(__instance.MapPicker);
|
||||
CreateSettings(__instance, container);
|
||||
if (CustomGameModeManager.ActiveMode != null)
|
||||
{
|
||||
ToggleGamemodeOptions(CustomGameModeManager.ActiveMode, __instance);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var child in container.GetComponentsInChildren<OptionBehaviour>(true))
|
||||
{
|
||||
__instance.Children.Add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.MapPicker.gameObject.SetActive(false);
|
||||
CustomCreateSettings(__instance);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static float AdditionalVanillaScrollNum;
|
||||
internal static void ToggleGamemodeOptions(AbstractGameMode gameMode, GameOptionsMenu instance)
|
||||
{
|
||||
float num = -1.217f;
|
||||
instance.Children.Clear();
|
||||
foreach (var opt in _mainOptions)
|
||||
{
|
||||
instance.Children.Add(opt);
|
||||
}
|
||||
|
||||
var icon = gameMode.Icon;
|
||||
if (icon != null)
|
||||
{
|
||||
_modIcon.gameObject.SetActive(true);
|
||||
_gamemodeDescription.transform.localPosition = new Vector3(0.3f, 0, -0.01f);
|
||||
_gamemodeDescription.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
||||
var texture = icon.LoadAsset().texture;
|
||||
var scale = Mathf.Min(128f / texture.width, 128f / texture.height);
|
||||
|
||||
var newSprite = Sprite.Create(
|
||||
texture,
|
||||
new Rect(0, 0, texture.width, texture.height),
|
||||
Vector2.one / 2,
|
||||
100f / scale
|
||||
);
|
||||
|
||||
_modIcon.sprite = newSprite;
|
||||
_modIcon.drawMode = SpriteDrawMode.Simple;
|
||||
}
|
||||
else
|
||||
{
|
||||
_gamemodeDescription.transform.localPosition = new Vector3(0f, 0, -0.01f);
|
||||
_gamemodeDescription.horizontalAlignment = HorizontalAlignmentOptions.Center;
|
||||
_modIcon.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
_gamemodeDescription.text = gameMode.Description;
|
||||
if (gameMode.ShowNormalGameSettings)
|
||||
{
|
||||
foreach (var opt in _vanillaHeaders)
|
||||
{
|
||||
num -= 0.63f;
|
||||
opt.gameObject.SetActive(true);
|
||||
}
|
||||
foreach (var opt in _vanillaOptions)
|
||||
{
|
||||
opt.gameObject.SetActive(true);
|
||||
instance.Children.Add(opt);
|
||||
num -= 0.45f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var opt in _vanillaHeaders)
|
||||
{
|
||||
opt.gameObject.SetActive(false);
|
||||
}
|
||||
foreach (var opt in _vanillaOptions)
|
||||
{
|
||||
opt.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var pair in _gameModeGroups)
|
||||
{
|
||||
if (pair.Value.Count != 0)
|
||||
{
|
||||
if (gameMode == pair.Key)
|
||||
{
|
||||
foreach (var opt in _gameModeHeaders[gameMode])
|
||||
{
|
||||
num -= 0.63f;
|
||||
opt.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
foreach (var opt in _gameModeOptions[gameMode])
|
||||
{
|
||||
opt.gameObject.SetActive(true);
|
||||
instance.Children.Add(opt);
|
||||
num -= 0.45f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var opt in _gameModeHeaders[pair.Key])
|
||||
{
|
||||
opt.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
foreach (var opt in _gameModeOptions[pair.Key])
|
||||
{
|
||||
opt.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
instance.ControllerSelectable.Clear();
|
||||
foreach (var obj in instance.scrollBar.GetComponentsInChildren<UiElement>())
|
||||
{
|
||||
if (obj.gameObject.activeSelf)
|
||||
{
|
||||
instance.ControllerSelectable.Add(obj);
|
||||
}
|
||||
}
|
||||
instance.scrollBar.SetYBoundsMax(-num - 1.65f);
|
||||
}
|
||||
|
||||
|
||||
private static void CreateSettings(GameOptionsMenu instance, Transform container)
|
||||
{
|
||||
float num = 0.713f;
|
||||
_vanillaHeaders.Clear();
|
||||
_vanillaOptions.Clear();
|
||||
_mainOptions.Clear();
|
||||
_gameModeHeaders.Clear();
|
||||
_gameModeOptions.Clear();
|
||||
_gameModeGroups.Clear();
|
||||
|
||||
CategoryHeaderMasked gmCategory = Object.Instantiate(instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, container);
|
||||
gmCategory.SetHeader(GameModeOption.CustomName, 20);
|
||||
gmCategory.transform.localScale = Vector3.one * 0.63f;
|
||||
gmCategory.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
||||
GameModeOption.OptionBehaviour = Object.Instantiate(
|
||||
instance.stringOptionOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
container);
|
||||
num -= 0.63f;
|
||||
GameModeOption.OptionBehaviour.transform.localPosition = new Vector3(0.952f, num, -2f);
|
||||
GameModeOption.OptionBehaviour.SetClickMask(instance.ButtonClickMask);
|
||||
StringGameSetting setting = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
setting.Type = OptionTypes.MultipleChoice;
|
||||
setting.Title = GameModeOption.GamemodeName;
|
||||
setting.Index = GameModeOption._lastValue;
|
||||
setting.Values = new Il2CppStructArray<StringNames>([GameModeOption.Values[0]]);
|
||||
GameModeOption.OptionBehaviour.SetUpFromData(setting, 20);
|
||||
GameModeOption.Set(GameModeOption._lastValue);
|
||||
GameModeOption.OptionBehaviour.TitleText.fontSize = 3;
|
||||
instance.Children.Add(GameModeOption.OptionBehaviour);
|
||||
foreach (var optionBehaviour in instance.Children)
|
||||
{
|
||||
_mainOptions.Add(optionBehaviour);
|
||||
}
|
||||
for (var i = 1; i < GameModeOption.Values.Count; i++)
|
||||
{
|
||||
GameModeOption.OptionBehaviour.Values =
|
||||
(Il2CppStructArray<StringNames>)GameModeOption.OptionBehaviour.Values.Add(
|
||||
GameModeOption.Values.ElementAt(i).Value);
|
||||
}
|
||||
|
||||
var modeInfoHolder = new GameObject("GamemodeInfo")
|
||||
{
|
||||
transform =
|
||||
{
|
||||
parent = container,
|
||||
localPosition = new Vector3(1.2f, -0.675f, 1),
|
||||
localScale = Vector3.one,
|
||||
},
|
||||
layer = container.gameObject.layer,
|
||||
}.transform;
|
||||
|
||||
var gamemodeBg = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(0).gameObject, Vector3.zero, Quaternion.identity, modeInfoHolder);
|
||||
gamemodeBg.transform.localPosition = Vector3.zero;
|
||||
gamemodeBg.transform.localScale = new Vector3(1.35f, 0.85f, 1);
|
||||
gamemodeBg.name = "Background";
|
||||
|
||||
var modIconObj = new GameObject("ModIcon")
|
||||
{
|
||||
transform =
|
||||
{
|
||||
parent = modeInfoHolder,
|
||||
localPosition = new Vector3(-1.75f, 0, -0.1f),
|
||||
localScale = new Vector3(0.45f, 0.45f, 1),
|
||||
},
|
||||
layer = gamemodeBg.layer,
|
||||
};
|
||||
_modIcon = modIconObj.AddComponent<SpriteRenderer>();
|
||||
_modIcon.sprite = MiraAssets.BlankSprite.LoadAsset();
|
||||
_modIcon.material = gamemodeBg.gameObject.GetComponent<SpriteRenderer>().material;
|
||||
|
||||
var gamemodeTextObj = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(1).gameObject, Vector3.zero, Quaternion.identity, modeInfoHolder);
|
||||
gamemodeTextObj.transform.localPosition = new Vector3(0.3f, 0, -0.01f);
|
||||
gamemodeTextObj.transform.localScale = new Vector3(2.12f, 2.12f, 1);
|
||||
_gamemodeDescription = gamemodeTextObj.GetComponentInChildren<TextMeshPro>();
|
||||
_gamemodeDescription.fontSizeMin = 0.65f;
|
||||
_gamemodeDescription.fontSizeMax = 0.9f;
|
||||
_gamemodeDescription.alignment = TextAlignmentOptions.Left;
|
||||
|
||||
num -= 1.3f;
|
||||
AdditionalVanillaScrollNum = 0f;
|
||||
foreach (RulesCategory rulesCategory in GameManager.Instance.GameSettingsList.AllCategories)
|
||||
{
|
||||
CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate<CategoryHeaderMasked>(
|
||||
instance.categoryHeaderOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
container);
|
||||
categoryHeaderMasked.SetHeader(rulesCategory.CategoryName, 20);
|
||||
categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f;
|
||||
categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
||||
_vanillaHeaders.Add(categoryHeaderMasked);
|
||||
num -= 0.63f;
|
||||
AdditionalVanillaScrollNum -= 0.63f;
|
||||
foreach (BaseGameSetting baseGameSetting in rulesCategory.AllGameSettings)
|
||||
{
|
||||
switch (baseGameSetting.Type)
|
||||
{
|
||||
case OptionTypes.Checkbox:
|
||||
{
|
||||
OptionBehaviour optionBehaviour = Object.Instantiate<ToggleOption>(
|
||||
instance.checkboxOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
container);
|
||||
optionBehaviour.transform.localPosition = new Vector3(0.952f, num, -2f);
|
||||
optionBehaviour.SetClickMask(instance.ButtonClickMask);
|
||||
optionBehaviour.SetUpFromData(baseGameSetting, 20);
|
||||
_vanillaOptions.Add(optionBehaviour);
|
||||
break;
|
||||
}
|
||||
case OptionTypes.String:
|
||||
{
|
||||
OptionBehaviour optionBehaviour = Object.Instantiate<StringOption>(
|
||||
instance.stringOptionOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
container);
|
||||
optionBehaviour.transform.localPosition = new Vector3(0.952f, num, -2f);
|
||||
optionBehaviour.SetClickMask(instance.ButtonClickMask);
|
||||
optionBehaviour.SetUpFromData(baseGameSetting, 20);
|
||||
_vanillaOptions.Add(optionBehaviour);
|
||||
break;
|
||||
}
|
||||
case OptionTypes.Float:
|
||||
case OptionTypes.Int:
|
||||
{
|
||||
OptionBehaviour optionBehaviour = Object.Instantiate<NumberOption>(
|
||||
instance.numberOptionOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
container);
|
||||
optionBehaviour.transform.localPosition = new Vector3(0.952f, num, -2f);
|
||||
optionBehaviour.SetClickMask(instance.ButtonClickMask);
|
||||
optionBehaviour.SetUpFromData(baseGameSetting, 20);
|
||||
_vanillaOptions.Add(optionBehaviour);
|
||||
break;
|
||||
}
|
||||
case OptionTypes.Player:
|
||||
{
|
||||
OptionBehaviour optionBehaviour = Object.Instantiate<PlayerOption>(
|
||||
instance.playerOptionOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
container);
|
||||
optionBehaviour.transform.localPosition = new Vector3(0.952f, num, -2f);
|
||||
optionBehaviour.SetClickMask(instance.ButtonClickMask);
|
||||
optionBehaviour.SetUpFromData(baseGameSetting, 20);
|
||||
_vanillaOptions.Add(optionBehaviour);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
num -= 0.45f;
|
||||
AdditionalVanillaScrollNum -= 0.45f;
|
||||
}
|
||||
}
|
||||
foreach (var optionBehaviour in _vanillaOptions)
|
||||
{
|
||||
if (AmongUsClient.Instance && !AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
optionBehaviour.SetAsPlayer();
|
||||
}
|
||||
instance.Children.Add(optionBehaviour);
|
||||
}
|
||||
|
||||
foreach (var optionBehaviour in instance.Children)
|
||||
{
|
||||
optionBehaviour.OnValueChanged = new Action<OptionBehaviour>(instance.ValueChanged);
|
||||
}
|
||||
|
||||
foreach (var mode in CustomGameModeManager.IdToModeMap.Values)
|
||||
{
|
||||
var filteredGroups =
|
||||
ModdedOptionsManager.GameModeOptionGroups
|
||||
.Where(x => x.Key == mode.GetType()).Select(y => y.Value).SelectMany(y => y) ?? [];
|
||||
_gameModeGroups.Add(mode, filteredGroups.ToList());
|
||||
|
||||
var optionBehaviours = new System.Collections.Generic.List<OptionBehaviour>();
|
||||
var categoryHeaders = new System.Collections.Generic.List<CategoryHeaderMasked>();
|
||||
var newNum = mode.ShowNormalGameSettings ? num : num - AdditionalVanillaScrollNum;
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
CreateGroup(instance, group, container, ref newNum, ref optionBehaviours, ref categoryHeaders);
|
||||
group.Ready = true;
|
||||
}
|
||||
_gameModeHeaders.Add(mode, categoryHeaders);
|
||||
_gameModeOptions.Add(mode, optionBehaviours);
|
||||
}
|
||||
|
||||
instance.ControllerSelectable.Clear();
|
||||
foreach (var obj in instance.scrollBar.GetComponentsInChildren<UiElement>())
|
||||
{
|
||||
instance.ControllerSelectable.Add(obj);
|
||||
}
|
||||
instance.scrollBar.SetYBoundsMax(-num - 1.65f);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(GameOptionsMenu.OnEnable))]
|
||||
public static void OpenPatch(GameOptionsMenu __instance)
|
||||
@@ -40,61 +404,165 @@ internal static class GameOptionsMenuPatch
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static void UpdatePatch(GameOptionsMenu __instance)
|
||||
{
|
||||
if (GameSettingMenuPatches.SelectedModIdx == 0)
|
||||
if (MenuState.Instance.CurrentModIdx == 0 && _gameModeGroups.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var num = 2.1f;
|
||||
if (__instance.name == "MODIFIERS TAB")
|
||||
{
|
||||
ModifiersUpdate(ref num);
|
||||
}
|
||||
else if (__instance.name == "CUSTOM TAB 1")
|
||||
{
|
||||
CustomMenuOneUpdate(ref num);
|
||||
}
|
||||
else if (__instance.name == "CUSTOM TAB 2")
|
||||
{
|
||||
CustomMenuTwoUpdate(ref num);
|
||||
}
|
||||
else
|
||||
{
|
||||
var filteredGroups =
|
||||
GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
|
||||
.Where(x => x.OptionableType == null &&
|
||||
x.ParentMenu == MenuCategory.Roles) ?? [];
|
||||
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
UpdateGroup(group, ref num);
|
||||
}
|
||||
switch (MenuState.Instance.CurrentMenu)
|
||||
{
|
||||
case MenuCategory.Modifiers:
|
||||
ModifiersUpdate(ref num);
|
||||
break;
|
||||
case MenuCategory.CustomOne:
|
||||
CustomMenuOneUpdate(ref num);
|
||||
break;
|
||||
case MenuCategory.CustomTwo:
|
||||
CustomMenuTwoUpdate(ref num);
|
||||
break;
|
||||
default:
|
||||
if (MenuState.Instance.CurrentModIdx == 0)
|
||||
{
|
||||
num = -1.217f;
|
||||
GamemodeOptionsUpdate(ref num);
|
||||
break;
|
||||
}
|
||||
var filteredGroups =
|
||||
MenuState.Instance.CurrentMod.InternalOptionGroups
|
||||
.Where(x => (x.OptionableType == null || CustomGameModeManager.ActiveMode!.GetType().IsAssignableTo(x.OptionableType)) &&
|
||||
x.ParentMenu == MenuCategory.Game) ?? [];
|
||||
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
UpdateGroup(group, ref num);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
__instance.scrollBar.SetYBoundsMax(-num - 1.65f);
|
||||
}
|
||||
|
||||
private static void UpdateGroup(AbstractOptionGroup group, ref float num)
|
||||
private static void CreateGroup(GameOptionsMenu menu, AbstractOptionGroup group, Transform container, ref float num, ref System.Collections.Generic.List<OptionBehaviour> optionBehaviours, ref System.Collections.Generic.List<CategoryHeaderMasked> categoryHeaders)
|
||||
{
|
||||
if (group.Options.Count == 0 || group.Header is null)
|
||||
var categoryHeaderMasked = Object.Instantiate(
|
||||
menu.categoryHeaderOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
container);
|
||||
categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num + 1, -2f);
|
||||
categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f;
|
||||
categoryHeaders.Add(categoryHeaderMasked);
|
||||
|
||||
num -= 0.58f;
|
||||
|
||||
categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20);
|
||||
categoryHeaderMasked.Background.color = group.GroupColor;
|
||||
categoryHeaderMasked.Divider.color = group.GroupColor;
|
||||
categoryHeaderMasked.Title.color = group.GroupColor.Equals(MiraApiPlugin.DefaultHeaderColor)
|
||||
? Color.white
|
||||
: group.GroupColor.FindAlternateColor();
|
||||
|
||||
categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset();
|
||||
categoryHeaderMasked.Background.sprite.texture.filterMode = FilterMode.Bilinear;
|
||||
categoryHeaderMasked.Background.sprite.texture.wrapMode = TextureWrapMode.Clamp;
|
||||
|
||||
categoryHeaderMasked.Background.transform.localPosition = new Vector3(0.5f, -0.1833f, 0);
|
||||
categoryHeaderMasked.Background.size = new Vector2(
|
||||
categoryHeaderMasked.Background.size.x + 1.5f,
|
||||
categoryHeaderMasked.Background.size.y);
|
||||
|
||||
categoryHeaderMasked.gameObject.SetActive(true);
|
||||
group.Header = categoryHeaderMasked;
|
||||
categoryHeaderMasked.transform.localPosition += Vector3.down;
|
||||
|
||||
var options = group.Options.Select(opt => opt.CreateOption(
|
||||
menu.checkboxOrigin,
|
||||
menu.numberOptionOrigin,
|
||||
menu.stringOptionOrigin,
|
||||
menu.playerOptionOrigin,
|
||||
container));
|
||||
|
||||
foreach (var newOpt in options)
|
||||
{
|
||||
newOpt.SetClickMask(menu.ButtonClickMask);
|
||||
SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
foreach (var renderer in componentsInChildren)
|
||||
{
|
||||
if (group.GroupColor != MiraApiPlugin.DefaultHeaderColor)
|
||||
{
|
||||
renderer.color = group.GroupColor.FindAlternateColor();
|
||||
if (renderer.transform.parent.TryGetComponent<GameOptionButton>(out var btn))
|
||||
{
|
||||
btn.interactableColor = group.GroupColor.FindAlternateColor();
|
||||
btn.interactableHoveredColor = Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
renderer.material.SetInt(PlayerMaterial.MaskLayer, 20);
|
||||
}
|
||||
|
||||
foreach (var textMeshPro in newOpt.GetComponentsInChildren<TextMeshPro>(true))
|
||||
{
|
||||
if (group.GroupColor != MiraApiPlugin.DefaultHeaderColor)
|
||||
{
|
||||
textMeshPro.color = group.GroupColor;
|
||||
}
|
||||
|
||||
textMeshPro.fontMaterial.SetFloat(ShaderID.StencilComp, 3f);
|
||||
textMeshPro.fontMaterial.SetFloat(ShaderID.Stencil, 20);
|
||||
}
|
||||
|
||||
if (newOpt is ToggleOption toggle)
|
||||
{
|
||||
toggle.CheckMark.sprite = MiraAssets.Checkmark.LoadAsset();
|
||||
toggle.CheckMark.color = group.GroupColor != MiraApiPlugin.DefaultHeaderColor
|
||||
? group.GroupColor
|
||||
: MiraAssets.AcceptedTeal;
|
||||
var rend = toggle.CheckMark.transform.parent.FindChild("ActiveSprite")
|
||||
.GetComponent<SpriteRenderer>();
|
||||
rend.sprite = MiraAssets.CheckmarkBox.LoadAsset();
|
||||
rend.color = group.GroupColor != MiraApiPlugin.DefaultHeaderColor
|
||||
? group.GroupColor
|
||||
: MiraAssets.AcceptedTeal;
|
||||
}
|
||||
|
||||
optionBehaviours.Add(newOpt);
|
||||
newOpt.transform.localPosition = new Vector3(0.952f, num, -2f);
|
||||
num -= 0.45f;
|
||||
|
||||
newOpt.Initialize();
|
||||
newOpt.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpdateGroup(AbstractOptionGroup? group, ref float num)
|
||||
{
|
||||
if (group is null || !group.Ready || group.Options.Count == 0 || group.Header is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!group.GroupVisible.Invoke())
|
||||
{
|
||||
group.Header.gameObject.SetActive(false);
|
||||
if (group.Header != null && group.Header.gameObject != null)
|
||||
group.Header.gameObject.SetActive(false);
|
||||
foreach (var option in group.Options)
|
||||
{
|
||||
option.OptionBehaviour?.gameObject.SetActive(false);
|
||||
if (option.OptionBehaviour != null && option.OptionBehaviour.gameObject != null)
|
||||
option.OptionBehaviour?.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
group.Header.gameObject.SetActive(true);
|
||||
group.Header.transform.localScale = Vector3.one * 0.63f;
|
||||
group.Header.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
||||
if (group.Header != null)
|
||||
{
|
||||
if (group.Header.gameObject != null)
|
||||
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;
|
||||
|
||||
@@ -102,7 +570,7 @@ internal static class GameOptionsMenuPatch
|
||||
{
|
||||
var newOpt = opt.OptionBehaviour;
|
||||
|
||||
if (newOpt is null)
|
||||
if (!newOpt || newOpt == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -126,10 +594,30 @@ internal static class GameOptionsMenuPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static void GamemodeOptionsUpdate(ref float num)
|
||||
{
|
||||
var mode = CustomGameModeManager.ActiveMode;
|
||||
if (mode == null) return;
|
||||
|
||||
if (mode.ShowNormalGameSettings)
|
||||
{
|
||||
num += AdditionalVanillaScrollNum;
|
||||
}
|
||||
|
||||
if (!_gameModeGroups.TryGetValue(mode, out var groups) || groups.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var group in groups)
|
||||
{
|
||||
UpdateGroup(group, ref num);
|
||||
}
|
||||
}
|
||||
private static void CustomMenuOneUpdate(ref float num)
|
||||
{
|
||||
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
|
||||
.Where(x => x.ParentMenu == MenuCategory.CustomOne) ?? [];
|
||||
var groups = MenuState.Instance.CurrentMod.InternalOptionGroups
|
||||
.Where(x => x.ParentMenu == MenuCategory.CustomOne);
|
||||
|
||||
foreach (var modGroup in groups)
|
||||
{
|
||||
@@ -137,20 +625,10 @@ internal static class GameOptionsMenuPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static void CustomMenuOneCreate(GameOptionsMenu menu)
|
||||
{
|
||||
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
|
||||
.Where(x => x.ParentMenu == MenuCategory.CustomOne) ?? [];
|
||||
foreach (var group in groups)
|
||||
{
|
||||
CreateGroup(menu, group);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CustomMenuTwoUpdate(ref float num)
|
||||
{
|
||||
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
|
||||
.Where(x => x.ParentMenu == MenuCategory.CustomTwo) ?? [];
|
||||
var groups = MenuState.Instance.CurrentMod.InternalOptionGroups
|
||||
.Where(x => x.ParentMenu == MenuCategory.CustomTwo);
|
||||
|
||||
foreach (var modGroup in groups)
|
||||
{
|
||||
@@ -158,20 +636,11 @@ internal static class GameOptionsMenuPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static void CustomMenuTwoCreate(GameOptionsMenu menu)
|
||||
{
|
||||
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
|
||||
.Where(x => x.ParentMenu == MenuCategory.CustomTwo) ?? [];
|
||||
foreach (var group in groups)
|
||||
{
|
||||
CreateGroup(menu, group);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ModifiersUpdate(ref float num)
|
||||
{
|
||||
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
|
||||
.Where(x => x.ParentMenu is MenuCategory.Modifiers || x.OptionableType?.IsAssignableTo(typeof(BaseModifier)) == true) ?? [];
|
||||
var groups = MenuState.Instance.CurrentMod.InternalOptionGroups
|
||||
.Where(x => x.ParentMenu is MenuCategory.Modifiers ||
|
||||
x.OptionableType?.IsAssignableTo(typeof(BaseModifier)) == true);
|
||||
|
||||
foreach (var modGroup in groups)
|
||||
{
|
||||
@@ -179,139 +648,114 @@ internal static class GameOptionsMenuPatch
|
||||
}
|
||||
}
|
||||
|
||||
private static void ModifiersCreate(GameOptionsMenu menu)
|
||||
private static Coroutine? _creationCoroutine;
|
||||
|
||||
public static void CustomCreateSettings(GameOptionsMenu menu)
|
||||
{
|
||||
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
|
||||
.Where(x => x.ParentMenu is MenuCategory.Modifiers || x.OptionableType?.IsAssignableTo(typeof(BaseModifier)) == true) ?? [];
|
||||
foreach (var group in groups)
|
||||
{
|
||||
CreateGroup(menu, group);
|
||||
}
|
||||
}
|
||||
menu.MapPicker.gameObject.SetActive(false);
|
||||
var mod = MenuState.Instance.CurrentMod;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GameOptionsMenu.CreateSettings))]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static bool SettingsPatch(GameOptionsMenu __instance)
|
||||
{
|
||||
if (GameSettingMenuPatches.SelectedModIdx == 0)
|
||||
var filteredGroups = MenuState.Instance.CurrentMenu switch
|
||||
{
|
||||
return true;
|
||||
MenuCategory.Game => mod.InternalOptionGroups.Where(x =>
|
||||
x.OptionableType == null && x.ParentMenu == MenuCategory.Game),
|
||||
MenuCategory.Modifiers => mod.InternalOptionGroups.Where(x =>
|
||||
x.ParentMenu is MenuCategory.Modifiers ||
|
||||
x.OptionableType?.IsAssignableTo(typeof(BaseModifier)) == true),
|
||||
MenuCategory.CustomOne => mod.InternalOptionGroups.Where(x => x.ParentMenu == MenuCategory.CustomOne),
|
||||
MenuCategory.CustomTwo => mod.InternalOptionGroups.Where(x => x.ParentMenu == MenuCategory.CustomTwo),
|
||||
_ => [],
|
||||
};
|
||||
|
||||
if (_creationCoroutine != null)
|
||||
{
|
||||
GameSettingMenu.Instance.StopCoroutine(_creationCoroutine);
|
||||
}
|
||||
|
||||
__instance.MapPicker.gameObject.SetActive(false);
|
||||
_creationCoroutine = GameSettingMenu.Instance.StartCoroutine(CreateGroups().WrapToIl2Cpp());
|
||||
|
||||
if (__instance.name == "MODIFIERS TAB")
|
||||
IEnumerator CreateGroups()
|
||||
{
|
||||
ModifiersCreate(__instance);
|
||||
return false;
|
||||
}
|
||||
else if (__instance.name == "CUSTOM TAB 1")
|
||||
{
|
||||
CustomMenuOneCreate(__instance);
|
||||
return false;
|
||||
}
|
||||
else if (__instance.name == "CUSTOM TAB 2")
|
||||
{
|
||||
CustomMenuTwoCreate(__instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
var filteredGroups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
|
||||
.Where(x => x.OptionableType == null && x.ParentMenu == MenuCategory.Roles) ?? [];
|
||||
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
CreateGroup(__instance, group);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GameOptionsMenu.Initialize))]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static bool InitPatch(GameOptionsMenu __instance)
|
||||
{
|
||||
if (__instance.Children != null && __instance.Children.Count != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
__instance.MapPicker.gameObject.SetActive(true);
|
||||
__instance.MapPicker.Initialize(20);
|
||||
var mapNameSetting = GameManager.Instance.GameSettingsList.MapNameSetting;
|
||||
__instance.MapPicker.SetUpFromData(mapNameSetting, 20);
|
||||
__instance.Children = new Il2CppSystem.Collections.Generic.List<OptionBehaviour>();
|
||||
__instance.Children.Add(__instance.MapPicker);
|
||||
__instance.CreateSettings();
|
||||
__instance.cachedData = GameOptionsManager.Instance.CurrentGameOptions;
|
||||
foreach (var optionBehaviour in __instance.Children)
|
||||
{
|
||||
if (AmongUsClient.Instance && !AmongUsClient.Instance.AmHost)
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
optionBehaviour.SetAsPlayer();
|
||||
yield return CoCreateGroup(menu, group);
|
||||
}
|
||||
|
||||
if (optionBehaviour.IsCustom())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
optionBehaviour.OnValueChanged = new Action<OptionBehaviour>(__instance.ValueChanged);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void CreateGroup(GameOptionsMenu menu, AbstractOptionGroup group)
|
||||
private static IEnumerator CoCreateGroup(GameOptionsMenu menu, AbstractOptionGroup group)
|
||||
{
|
||||
var categoryHeaderMasked = Object.Instantiate(
|
||||
menu.categoryHeaderOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
menu.settingsContainer);
|
||||
var container = MenuState.Instance.CurrentContainer.transform;
|
||||
|
||||
categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20);
|
||||
categoryHeaderMasked.Background.color = group.GroupColor;
|
||||
categoryHeaderMasked.Divider.color = group.GroupColor;
|
||||
categoryHeaderMasked.Title.color = group.GroupColor.Equals(MiraApiPlugin.DefaultHeaderColor)
|
||||
? Color.white
|
||||
: group.GroupColor.FindAlternateColor();
|
||||
group.Ready = false;
|
||||
if (group.Header == null || !group.Header)
|
||||
{
|
||||
var categoryHeaderMasked = Object.Instantiate(
|
||||
menu.categoryHeaderOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
container);
|
||||
|
||||
categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset();
|
||||
categoryHeaderMasked.Background.sprite.texture.filterMode = FilterMode.Bilinear;
|
||||
categoryHeaderMasked.Background.sprite.texture.wrapMode = TextureWrapMode.Clamp;
|
||||
categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20);
|
||||
categoryHeaderMasked.Background.color = group.GroupColor;
|
||||
categoryHeaderMasked.Divider.color = group.GroupColor;
|
||||
categoryHeaderMasked.Title.color = group.GroupColor.Equals(MiraApiPlugin.DefaultHeaderColor)
|
||||
? Color.white
|
||||
: group.GroupColor.FindAlternateColor();
|
||||
|
||||
categoryHeaderMasked.Background.transform.localPosition = new Vector3(0.5f, -0.1833f, 0);
|
||||
categoryHeaderMasked.Background.size = new Vector2(
|
||||
categoryHeaderMasked.Background.size.x + 1.5f,
|
||||
categoryHeaderMasked.Background.size.y);
|
||||
categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset();
|
||||
categoryHeaderMasked.Background.sprite.texture.filterMode = FilterMode.Bilinear;
|
||||
categoryHeaderMasked.Background.sprite.texture.wrapMode = TextureWrapMode.Clamp;
|
||||
|
||||
categoryHeaderMasked.gameObject.SetActive(false);
|
||||
group.Header = categoryHeaderMasked;
|
||||
categoryHeaderMasked.Background.transform.localPosition = new Vector3(0.5f, -0.1833f, 0);
|
||||
categoryHeaderMasked.Background.size = new Vector2(
|
||||
categoryHeaderMasked.Background.size.x + 1.5f,
|
||||
categoryHeaderMasked.Background.size.y);
|
||||
|
||||
var newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform);
|
||||
newText.text = "<size=70%>(Click to close)</size>";
|
||||
newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f);
|
||||
newText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
categoryHeaderMasked.gameObject.SetActive(false);
|
||||
|
||||
var options = group.Options.Select(opt => opt.CreateOption(
|
||||
var newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform);
|
||||
newText.text = "<size=70%>(Click to close)</size>";
|
||||
newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f);
|
||||
newText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
|
||||
var boxCol = categoryHeaderMasked.gameObject.AddComponent<BoxCollider2D>();
|
||||
boxCol.size = new Vector2(7, 0.7f);
|
||||
boxCol.offset = new Vector2(1.5f, -0.3f);
|
||||
|
||||
var headerBtn = categoryHeaderMasked.gameObject.AddComponent<PassiveButton>();
|
||||
headerBtn.ClickSound = menu.BackButton.GetComponent<PassiveButton>().ClickSound;
|
||||
headerBtn.OnMouseOver = new UnityEvent();
|
||||
headerBtn.OnMouseOut = new UnityEvent();
|
||||
headerBtn.OnClick.AddListener(
|
||||
(UnityAction)(() =>
|
||||
{
|
||||
group.AllOptionsHidden = !group.AllOptionsHidden;
|
||||
newText.text = group.AllOptionsHidden
|
||||
? "<size=70%>(Click to open)</size>"
|
||||
: "<size=70%>(Click to close)</size>";
|
||||
}));
|
||||
headerBtn.SetButtonEnableState(true);
|
||||
|
||||
group.Header = categoryHeaderMasked;
|
||||
}
|
||||
|
||||
var options = group.Options.Where(opt => opt.OptionBehaviour == null || !opt.OptionBehaviour
|
||||
).Select(opt => opt.CreateOption(
|
||||
menu.checkboxOrigin,
|
||||
menu.numberOptionOrigin,
|
||||
menu.stringOptionOrigin,
|
||||
menu.playerOptionOrigin,
|
||||
menu.settingsContainer));
|
||||
container)
|
||||
);
|
||||
|
||||
OptionPreset? defaultPreset = null;
|
||||
if (GameSettingMenuPatches.SelectedMod != null && PresetManager.DefaultPresets.TryGetValue(
|
||||
GameSettingMenuPatches.SelectedMod,
|
||||
out var preset))
|
||||
if (PresetManager.DefaultPresets.TryGetValue(MenuState.Instance.CurrentMod, out var preset))
|
||||
{
|
||||
defaultPreset = preset;
|
||||
}
|
||||
|
||||
foreach (var newOpt in options)
|
||||
yield return options.CoLoopWithBudget(newOpt =>
|
||||
{
|
||||
newOpt.SetClickMask(menu.ButtonClickMask);
|
||||
|
||||
@@ -414,6 +858,7 @@ internal static class GameOptionsMenuPatch
|
||||
defaultPreset!.ResetOption(strOpt);
|
||||
}));
|
||||
}
|
||||
|
||||
if (!defaultPreset!.IsOptionInPreset(newOpt))
|
||||
{
|
||||
resetBtn.Destroy();
|
||||
@@ -421,24 +866,12 @@ internal static class GameOptionsMenuPatch
|
||||
|
||||
newOpt.Initialize();
|
||||
newOpt.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
var boxCol = categoryHeaderMasked.gameObject.AddComponent<BoxCollider2D>();
|
||||
boxCol.size = new Vector2(7, 0.7f);
|
||||
boxCol.offset = new Vector2(1.5f, -0.3f);
|
||||
|
||||
var headerBtn = categoryHeaderMasked.gameObject.AddComponent<PassiveButton>();
|
||||
headerBtn.ClickSound = menu.BackButton.GetComponent<PassiveButton>().ClickSound;
|
||||
headerBtn.OnMouseOver = new UnityEvent();
|
||||
headerBtn.OnMouseOut = new UnityEvent();
|
||||
headerBtn.OnClick.AddListener(
|
||||
(UnityAction)(() =>
|
||||
if (AmongUsClient.Instance && !AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
group.AllOptionsHidden = !group.AllOptionsHidden;
|
||||
newText.text = group.AllOptionsHidden
|
||||
? "<size=70%>(Click to open)</size>"
|
||||
: "<size=70%>(Click to close)</size>";
|
||||
}));
|
||||
headerBtn.SetButtonEnableState(true);
|
||||
newOpt.SetAsPlayer();
|
||||
}
|
||||
}).WrapToIl2Cpp();
|
||||
group.Ready = true;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 148 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user