Skip to content

Commit

Permalink
Resolve reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
NikoCat233 committed Jul 7, 2024
1 parent d5d4188 commit 2ac71b3
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 76 deletions.
14 changes: 9 additions & 5 deletions src/CrowdedMod/Components/MeetingHudPagingBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Il2CppInterop.Runtime.Attributes;
using Reactor.Utilities.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using Il2CppInterop.Runtime.Attributes;
using Reactor.Utilities.Attributes;
using UnityEngine;

namespace CrowdedMod.Components;
Expand Down Expand Up @@ -36,8 +36,10 @@ public override void OnPageChanged()
{
var i = 0;

foreach (var button in Targets) {
if (i >= PageIndex * MaxPerPage && i < (PageIndex + 1) * MaxPerPage) {
foreach (var button in Targets)
{
if (i >= PageIndex * MaxPerPage && i < (PageIndex + 1) * MaxPerPage)
{
button.gameObject.SetActive(true);

var relativeIndex = i % MaxPerPage;
Expand All @@ -50,7 +52,9 @@ public override void OnPageChanged()
meetingHud.VoteButtonOffsets.y * row,
buttonTransform.localPosition.z
);
} else {
}
else
{
button.gameObject.SetActive(false);
}
i++;
Expand Down
13 changes: 8 additions & 5 deletions src/CrowdedMod/Components/ShapeShifterPagingBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using Il2CppInterop.Runtime.Attributes;
using Reactor.Utilities.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using Il2CppInterop.Runtime.Attributes;
using Reactor.Utilities.Attributes;
using TMPro;
using UnityEngine;

Expand Down Expand Up @@ -40,7 +40,8 @@ public override void OnPageChanged()

foreach (var panel in Targets)
{
if (i >= PageIndex * MaxPerPage && i < (PageIndex + 1) * MaxPerPage) {
if (i >= PageIndex * MaxPerPage && i < (PageIndex + 1) * MaxPerPage)
{
panel.gameObject.SetActive(true);

var relativeIndex = i % MaxPerPage;
Expand All @@ -52,7 +53,9 @@ public override void OnPageChanged()
shapeshifterMinigame.YStart + shapeshifterMinigame.YOffset * row,
buttonTransform.localPosition.z
);
} else {
}
else
{
panel.gameObject.SetActive(false);
}

Expand Down
6 changes: 3 additions & 3 deletions src/CrowdedMod/Components/VitalsPagingBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Il2CppInterop.Runtime.Attributes;
using Reactor.Utilities.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using Il2CppInterop.Runtime.Attributes;
using TMPro;
using Reactor.Utilities.Attributes;
using UnityEngine;

namespace CrowdedMod.Components;

[RegisterInIl2Cpp]
public class VitalsPagingBehaviour : AbstractPagingBehaviour
{
public VitalsPagingBehaviour(IntPtr ptr) : base(ptr) {}
public VitalsPagingBehaviour(IntPtr ptr) : base(ptr) { }

public VitalsMinigame vitalsMinigame = null!;

Expand Down
5 changes: 1 addition & 4 deletions src/CrowdedMod/CrowdedMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>
<PropertyGroup>
<GamePlatform Condition="'$(GamePlatform)' == ''">Steam</GamePlatform>
<GameVersion>2023.3.28</GameVersion>
<GameVersion>2024.6.18</GameVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Reactor" Version="2.1.0" />
Expand All @@ -21,9 +21,6 @@
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.0.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="AmongUs.GameLibs.Steam" Version="2024.6.18" />
</ItemGroup>

<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUs)/BepInEx/plugins/" UseSymboliclinksIfPossible="true" />
Expand Down
10 changes: 5 additions & 5 deletions src/CrowdedMod/CrowdedModPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Linq;
using AmongUs.GameOptions;
using AmongUs.GameOptions;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Reactor;
using Reactor.Networking;
using Reactor.Networking.Attributes;
using System.Linq;

namespace CrowdedMod;

Expand All @@ -19,12 +19,12 @@ public partial class CrowdedModPlugin : BasePlugin
public const int MaxPlayers = 127;
public const int MaxImpostors = 127 / 2;

private Harmony Harmony { get; } = new (Id);
private Harmony Harmony { get; } = new(Id);

public override void Load()
{
NormalGameOptionsV07.RecommendedImpostors = NormalGameOptionsV07.MaxImpostors = Enumerable.Repeat(127, 127).ToArray();
NormalGameOptionsV07.MinPlayers = Enumerable.Repeat(4, 127).ToArray();
NormalGameOptionsV08.RecommendedImpostors = NormalGameOptionsV08.MaxImpostors = Enumerable.Repeat(127, 127).ToArray();
NormalGameOptionsV08.MinPlayers = Enumerable.Repeat(4, 127).ToArray();

Harmony.PatchAll();
}
Expand Down
2 changes: 1 addition & 1 deletion src/CrowdedMod/Net/SetColorRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Reactor.Networking.Rpc;
namespace CrowdedMod.Net;

[RegisterCustomRpc((uint) CustomRpcCalls.SetColor)]
[RegisterCustomRpc((uint)CustomRpcCalls.SetColor)]
public class SetColorRpc : PlayerCustomRpc<CrowdedModPlugin, byte>
{
public SetColorRpc(CrowdedModPlugin plugin, uint id) : base(plugin, id)
Expand Down
44 changes: 7 additions & 37 deletions src/CrowdedMod/Patches/CreateGameOptionsPatches.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using AmongUs.GameOptions;
using AmongUs.GameOptions;
using HarmonyLib;
using Reactor.Utilities.Extensions;
using System;
using TMPro;
using UnityEngine;

Expand Down Expand Up @@ -98,7 +98,8 @@ public static void Postfix(CreateOptionsPicker __instance)

var firstPassiveButton = firstButton.PassiveButton;
firstPassiveButton.OnClick.RemoveAllListeners();
firstPassiveButton.OnClick.AddListener((Action)(() => {
firstPassiveButton.OnClick.AddListener((Action)(() =>
{
var newVal = Mathf.Clamp(
byte.Parse(secondButtonText.text) - 1,
1,
Expand All @@ -114,7 +115,8 @@ public static void Postfix(CreateOptionsPicker __instance)

var thirdPassiveButton = thirdButton.PassiveButton;
thirdPassiveButton.OnClick.RemoveAllListeners();
thirdPassiveButton.OnClick.AddListener((Action)(() => {
thirdPassiveButton.OnClick.AddListener((Action)(() =>
{
var newVal = Mathf.Clamp(
byte.Parse(secondButtonText.text) + 1,
1,
Expand Down Expand Up @@ -155,37 +157,5 @@ public static bool Prefix()
return false;
}
}

[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.SetImpostorButtons))]
public static class CreateOptionsPicker_SetImpostorButtons
{
public static bool Prefix(CreateOptionsPicker __instance, int numImpostors)
{
IGameOptions targetOptions = __instance.GetTargetOptions();
targetOptions.SetInt(Int32OptionNames.NumImpostors, numImpostors);
__instance.SetTargetOptions(targetOptions);
__instance.UpdateImpostorsButtons(numImpostors);

return false;
}
}

[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.SetMaxPlayersButtons))]
public static class CreateOptionsPicker_SetMaxPlayersButtons
{
public static bool Prefix(CreateOptionsPicker __instance, int maxPlayers)
{
if (DestroyableSingleton<FindAGameManager>.InstanceExists)
{
return true;
}

IGameOptions targetOptions = __instance.GetTargetOptions();
targetOptions.SetInt(Int32OptionNames.MaxPlayers, maxPlayers);
__instance.SetTargetOptions(targetOptions);
__instance.UpdateMaxPlayersButtons(targetOptions);

return false;
}
}
}

32 changes: 18 additions & 14 deletions src/CrowdedMod/Patches/GenericPatches.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
using System.Linq;
using AmongUs.GameOptions;
using CrowdedMod.Net;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Reactor.Networking.Rpc;
using UnityEngine;
using System.Linq;

namespace CrowdedMod.Patches;

internal static class GenericPatches {
internal static class GenericPatches
{
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.CmdCheckColor))]
public static class PlayerControlCmdCheckColorPatch {
public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] byte colorId) {
public static class PlayerControlCmdCheckColorPatch
{
public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] byte colorId)
{
Rpc<SetColorRpc>.Instance.Send(__instance, colorId);
return false;
}
}

[HarmonyPatch(typeof(PlayerTab), nameof(PlayerTab.Update))]
public static class PlayerTabIsSelectedItemEquippedPatch {
public static class PlayerTabIsSelectedItemEquippedPatch
{
public static void Postfix(PlayerTab __instance)
{
__instance.currentColorIsEquipped = false;
Expand All @@ -33,7 +35,7 @@ public static bool Prefix(PlayerTab __instance)
__instance.AvailableColors.Clear();
for (var i = 0; i < Palette.PlayerColors.Count; i++)
{
if(!PlayerControl.LocalPlayer || PlayerControl.LocalPlayer.CurrentOutfit.ColorId != i)
if (!PlayerControl.LocalPlayer || PlayerControl.LocalPlayer.CurrentOutfit.ColorId != i)
{
__instance.AvailableColors.Add(i);
}
Expand Down Expand Up @@ -72,7 +74,8 @@ public static void Prefix(GameStartManager __instance)
if (__instance.LastPlayerCount > __instance.MinPlayers)
{
fixDummyCounterColor = "<color=#00FF00FF>";
} else if (__instance.LastPlayerCount == __instance.MinPlayers)
}
else if (__instance.LastPlayerCount == __instance.MinPlayers)
{
fixDummyCounterColor = "<color=#FFFF00FF>";
}
Expand All @@ -88,7 +91,7 @@ public static void Postfix(GameStartManager __instance)
{
return;
}

__instance.PlayerCounter.text = $"{fixDummyCounterColor}{GameData.Instance.PlayerCount}/{GameManager.Instance.LogicOptions.MaxPlayers}";
fixDummyCounterColor = null;
}
Expand Down Expand Up @@ -157,11 +160,12 @@ public static void Postfix(GameOptionsMenu __instance)
{
var numberOptions = __instance.GetComponentsInChildren<NumberOption>();

if (numberOptions.Any(o => o.Title == StringNames.GameNumImpostors))
var impostorsOption = numberOptions.FirstOrDefault(o => o.Title == StringNames.GameNumImpostors);
if (impostorsOption != null)
{
numberOptions.First(o => o.Title == StringNames.GameNumImpostors)
.ValidRange = new FloatRange(1, CrowdedModPlugin.MaxImpostors);
impostorsOption.ValidRange = new FloatRange(1, CrowdedModPlugin.MaxImpostors);
}

}
}
}
}
4 changes: 2 additions & 2 deletions src/CrowdedMod/Patches/PagingPatches.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HarmonyLib;
using CrowdedMod.Components;
using CrowdedMod.Components;
using HarmonyLib;

namespace CrowdedMod.Patches;

Expand Down

0 comments on commit 2ac71b3

Please sign in to comment.