Skip to content

Commit 0214278

Browse files
committed
Fixed Sticky Modifier issues, Fixed Overload button creation issue, Fixed chat issue, Fixed an issue where Visionary warning shows if Visionary isn’t enabled, decreased all modifiers' default amount from 6 to 2
1 parent 1917ce0 commit 0214278

14 files changed

Lines changed: 145 additions & 68 deletions

File tree

NewMod/Buttons/Overload/OverloadButton.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class OverloadButton : CustomActionButton
8282
/// <summary>
8383
/// The icon displayed on the button.
8484
/// </summary>
85-
public override LoadableAsset<Sprite> Sprite => absorbedSprite;
85+
public override LoadableAsset<Sprite> Sprite => MiraAssets.Empty;
8686

8787
/// <summary>
8888
/// Copies functionality and appearance from another role's button.

NewMod/CustomRPC.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public enum CustomRPC
1515
WitnessTrap,
1616
NotifyChampion,
1717
SummonNPC,
18+
RequestSummon,
1819
BeaconPulse,
1920
DeployZone
2021
}

NewMod/ModCompatibility.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,5 @@ public static void DisableRole(string roleName, string pluginGuid)
5252
}
5353
}
5454
}
55-
public static bool IsRoleActive(string roleName)
56-
{
57-
foreach (var roles in RoleManager.Instance.AllRoles)
58-
{
59-
CustomRoleManager.GetCustomRoleBehaviour(roles.Role, out var customRole);
60-
61-
if (customRole != null && customRole.RoleName.Equals(roleName, StringComparison.OrdinalIgnoreCase))
62-
{
63-
return customRole.GetChance() > 0 && customRole.GetCount() > 0;
64-
}
65-
}
66-
return false;
67-
}
6855
}
6956
}

NewMod/Modifiers/StickyModifier.cs

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System.Collections;
22
using System.Collections.Generic;
3+
using MiraAPI.Events;
4+
using MiraAPI.Events.Vanilla.Gameplay;
35
using MiraAPI.GameOptions;
6+
using MiraAPI.Modifiers;
47
using MiraAPI.Modifiers.Types;
58
using NewMod.Options;
69
using NewMod.Options.Modifiers;
@@ -15,6 +18,7 @@ public class StickyModifier : GameModifier
1518
public override bool HideOnUi => false;
1619
public override bool ShowInFreeplay => true;
1720
public static List<PlayerControl> linkedPlayers = [];
21+
public static bool _IsActive = false;
1822
public override int GetAmountPerGame()
1923
{
2024
return (int)OptionGroupSingleton<ModifiersOptions>.Instance.StickyAmount;
@@ -29,62 +33,74 @@ public override int GetAssignmentChance()
2933
}
3034
public override string GetDescription()
3135
{
32-
float distance = OptionGroupSingleton<StickyModifierOptions>.Instance.StickyDistance.Value;
33-
float duration = OptionGroupSingleton<StickyModifierOptions>.Instance.StickyDuration.Value;
36+
float distance = (int)OptionGroupSingleton<StickyModifierOptions>.Instance.StickyDistance;
37+
float duration = (int)OptionGroupSingleton<StickyModifierOptions>.Instance.StickyDuration;
3438

3539
return $"{ModifierName}: Pulls nearby players within {distance} units for {duration} seconds.";
3640
}
3741
public override void FixedUpdate()
3842
{
3943
base.FixedUpdate();
4044

41-
if (!Player.CanMove) return;
45+
if (_IsActive) return;
46+
47+
if (!Player.CanMove || Player.Data.IsDead) return;
4248

4349
foreach (var player in PlayerControl.AllPlayerControls)
4450
{
45-
if (player == Player || linkedPlayers.Contains(player)) continue;
51+
if (player == Player) continue;
4652

47-
float distance = OptionGroupSingleton<StickyModifierOptions>.Instance.StickyDistance.Value;
53+
float distance = (int)OptionGroupSingleton<StickyModifierOptions>.Instance.StickyDistance;
4854

4955
if (Vector2.Distance(player.GetTruePosition(), Player.GetTruePosition()) < distance)
5056
{
57+
_IsActive = true;
5158
linkedPlayers.Add(player);
5259
Coroutines.Start(CoFollowStickyPlayer(player));
60+
break;
5361
}
5462
}
5563
}
5664
public IEnumerator CoFollowStickyPlayer(PlayerControl player)
5765
{
58-
var info = new StickyState
66+
float duration = (int)OptionGroupSingleton<StickyModifierOptions>.Instance.StickyDuration;
67+
float timer = 0f;
68+
float pullStrength = (int)OptionGroupSingleton<StickyModifierOptions>.Instance.PullStrength;
69+
float stopDistance = 1f;
70+
71+
while (timer < duration)
5972
{
60-
StickyOwner = Player,
61-
LinkedPlayer = player,
62-
velocity = Vector3.zero,
63-
};
73+
if (player.Data.IsDead || player.Data.Disconnected) break;
6474

65-
yield return HudManager.Instance.StartCoroutine(
66-
Effects.Overlerp(0.5f, new System.Action<float>((t) =>
67-
{
68-
Vector3 targetPos = info.LinkedPlayer.transform.position;
69-
Vector3 currentPos = info.StickyOwner.transform.position;
75+
timer += Time.deltaTime;
7076

71-
info.LinkedPlayer.transform.position = Vector3.SmoothDamp(
72-
targetPos,
73-
currentPos,
74-
ref info.velocity,
75-
t
76-
);
77-
})
78-
));
77+
var ownerPos = Player.transform.position;
78+
var targetPos = player.transform.position;
7979

80+
float distance = Vector3.Distance(ownerPos, targetPos);
81+
82+
if (distance > stopDistance)
83+
{
84+
Vector3 direction = (ownerPos - targetPos).normalized;
85+
Vector3 leashPoint = ownerPos - (direction * stopDistance);
86+
87+
player.transform.position = Vector3.Lerp(targetPos, leashPoint, Time.deltaTime * pullStrength);
88+
}
89+
yield return null;
90+
}
8091
linkedPlayers.Remove(player);
81-
}
82-
}
8392

84-
class StickyState
85-
{
86-
public PlayerControl StickyOwner;
87-
public PlayerControl LinkedPlayer;
88-
public Vector3 velocity;
93+
_IsActive = true;
94+
95+
if (Player.AmOwner)
96+
{
97+
PlayerControl.LocalPlayer.RpcRemoveModifier<StickyModifier>();
98+
}
99+
}
100+
[RegisterEvent]
101+
public static void OnRoundStart(RoundStartEvent evt)
102+
{
103+
linkedPlayers.Clear();
104+
}
89105
}
90106
}

NewMod/NewMod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override void Load()
4747
{
4848
Instance = this;
4949
AddComponent<DebugWindow>();
50-
ReactorCredits.Register("NewMod", "v1.2.9 Hotfix 1", true, ReactorCredits.AlwaysShow);
50+
ReactorCredits.Register("NewMod", "v1.2.9 Hotfix 2", true, ReactorCredits.AlwaysShow);
5151
Harmony.PatchAll();
5252
NewModEventHandler.RegisterEventsLogs();
5353

NewMod/Options/Modifiers/StickyModifierOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,14 @@ public class StickyModifierOptions : AbstractOptionGroup<StickyModifier>
2626
increment: 0.5f,
2727
suffixType: MiraNumberSuffixes.None
2828
);
29+
public ModdedNumberOption PullStrength { get; } =
30+
new(
31+
"Pull Strength",
32+
1f,
33+
min: 1f,
34+
max: 5f,
35+
increment: 1f,
36+
suffixType: MiraNumberSuffixes.None
37+
);
2938
}
3039
}

NewMod/Options/ModifiersOptions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ public class ModifiersOptions : AbstractOptionGroup
1212
public override Color GroupColor => Color.blue;
1313
public override bool ShowInModifiersMenu => true;
1414

15-
[ModdedNumberOption("Sticky Amount", min:0f, max:6)]
16-
public float StickyAmount { get; set; } = 10f;
15+
[ModdedNumberOption("Sticky Amount", min:0f, max:2f)]
16+
public float StickyAmount { get; set; } = 1f;
1717

1818
public ModdedNumberOption StickyChance { get; } = new("Sticky Chance", 50f, 0, 100f, 10f, MiraNumberSuffixes.Percent)
1919
{
2020
Visible = () => OptionGroupSingleton<ModifiersOptions>.Instance.StickyAmount > 0
2121
};
2222

23-
[ModdedNumberOption("Drowsy Amount", min:0f, max:6f)]
24-
public float DrowsyAmount { get; set; } = 10f;
23+
[ModdedNumberOption("Drowsy Amount", min:0f, max:2f)]
24+
public float DrowsyAmount { get; set; } = 1f;
2525

2626
public ModdedNumberOption DrowsyChance { get; } =new("Drowsy Chance", 50f, 0, 100f, 10f, MiraNumberSuffixes.Percent)
2727
{
2828
Visible = () => OptionGroupSingleton<ModifiersOptions>.Instance.DrowsyAmount > 0f
2929
};
3030

31-
[ModdedNumberOption("Adrenaline Amount", min:0f, max:6f)]
32-
public float AdrenalineAmount { get; set; } = 10f;
31+
[ModdedNumberOption("Adrenaline Amount", min:0f, max:2f)]
32+
public float AdrenalineAmount { get; set; } = 1f;
3333

3434
public ModdedNumberOption AdrenalineChance { get; } =new("Adrenaline Chance", 50f, 0, 100f, 10f, MiraNumberSuffixes.Percent)
3535
{

NewMod/Patches/ChatPatch.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using AmongUs.Data;
2+
using HarmonyLib;
3+
using InnerNet;
4+
5+
namespace NewMod.Patches
6+
{
7+
[HarmonyPatch(typeof(ChatController), nameof(ChatController.SendChat))]
8+
public static class ChatPatch
9+
{
10+
public static bool Prefix(ChatController __instance)
11+
{
12+
__instance.timeSinceLastMessage = 0f;
13+
14+
if (__instance.quickChatMenu.CanSend)
15+
{
16+
__instance.SendQuickChat();
17+
}
18+
else
19+
{
20+
if (__instance.quickChatMenu.IsOpen || string.IsNullOrWhiteSpace(__instance.freeChatField.Text) || DataManager.Settings.Multiplayer.ChatMode != QuickChatModes.FreeChatOrQuickChat)
21+
{
22+
return false;
23+
}
24+
__instance.SendFreeChat();
25+
}
26+
27+
__instance.timeSinceLastMessage = 0f;
28+
__instance.freeChatField.Clear();
29+
__instance.quickChatMenu.Clear();
30+
__instance.quickChatField.Clear();
31+
__instance.UpdateChatMode();
32+
33+
return false;
34+
}
35+
[HarmonyPatch(typeof(TextBoxTMP), nameof(TextBoxTMP.Start))]
36+
[HarmonyPostfix]
37+
public static void StartPostfix(TextBoxTMP __instance)
38+
{
39+
__instance.AllowSymbols = true;
40+
__instance.allowAllCharacters = true;
41+
}
42+
}
43+
}

NewMod/Patches/Compatibility/StartGamePatch.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using HarmonyLib;
22
using MiraAPI.GameOptions;
33
using NewMod.Options;
4+
using NewMod.Utilities;
45

56
namespace NewMod.Patches.Compatibility
67
{
@@ -15,8 +16,8 @@ public static bool Prefix(AmongUsClient __instance)
1516

1617
if (!settings.AllowRevenantHitmanCombo)
1718
{
18-
var hitman = ModCompatibility.IsRoleActive("Hitman");
19-
var revenant = ModCompatibility.IsRoleActive("Revenant");
19+
var hitman = Utils.IsRoleActive("Hitman");
20+
var revenant = Utils.IsRoleActive("Revenant");
2021

2122
if (hitman && revenant)
2223
{

NewMod/Patches/Roles/MeetingHudPatch.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
using System;
2-
using UnityEngine;
3-
using Object = UnityEngine.Object;
4-
using UnityEngine.Events;
51
using System.Collections.Generic;
62
using HarmonyLib;
73
using NewMod.Utilities;
8-
using MiraAPI.Roles;
9-
using MiraAPI.Hud;
10-
using Reactor.Utilities;
114
using System.Linq;
125
using Il2CppInterop.Runtime.InteropTypes.Arrays;
136
using AmongUs.GameOptions;
14-
using NewMod.Roles.NeutralRoles;
157

168
namespace NewMod.Patches.Roles
179
{
@@ -30,6 +22,8 @@ public static class MeetingHud_CoIntro_Patch
3022
{
3123
public static bool Prefix(ref Il2CppReferenceArray<NetworkedPlayerInfo> deadBodies)
3224
{
25+
if (!Utils.IsRoleActive("Prankster")) return true;
26+
3327
List<DeadBody> pranksterBodies = PranksterUtilities.FindAllPranksterBodies();
3428
deadBodies = new Il2CppReferenceArray<NetworkedPlayerInfo>(
3529
deadBodies
@@ -44,6 +38,8 @@ public static class MeetingHud_PopulateButtons_Patch
4438
{
4539
public static bool Prefix(MeetingHud __instance, byte reporter)
4640
{
41+
if (!Utils.IsRoleActive("Prankster")) return true;
42+
4743
var fakeBodies = PranksterUtilities.FindAllPranksterBodies();
4844
var realPlayers = GameData.Instance.AllPlayers
4945
.ToArray()

0 commit comments

Comments
 (0)