Skip to content

Commit 6d5ef61

Browse files
General improvements (#53)
General code improvements Minor fixes --------- Co-authored-by: Galster-dev <46283010+Galster-dev@users.noreply.github.com>
1 parent 7301421 commit 6d5ef61

13 files changed

Lines changed: 412 additions & 359 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,4 +352,7 @@ MigrationBackup/
352352
# Ionide (cross platform F# VS Code tools) working folder
353353
.ionide/
354354
Libs/*.dll
355-
RemovePlayerLimit/RemovePlayerLimit.csproj
355+
RemovePlayerLimit/RemovePlayerLimit.csproj
356+
357+
# VSC Stuff
358+
.vscode/

src/CrowdedMod/Components/AbstractPagingBehaviour.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ namespace CrowdedMod.Components;
55

66
// Interface until unhollower implements generic il2cpp (if it's possible)
77
/// <summary>
8-
/// This class is not actually abstract because unhollower does not support it <br/>
9-
/// You need to implement <see cref="OnPageChanged"/> and <see cref="MaxPageIndex"/>
8+
/// This class is not actually abstract because unhollower does not support it.<br/>
9+
/// You need to implement <see cref="OnPageChanged"/> and <see cref="MaxPageIndex"/>.
1010
/// </summary>
1111
public class AbstractPagingBehaviour : MonoBehaviour
1212
{
1313
public AbstractPagingBehaviour(IntPtr ptr) : base(ptr)
1414
{
1515
}
1616

17+
public const string PAGE_INDEX_GAME_OBJECT_NAME = "CrowdedMod_PageIndex";
18+
1719
private int _page;
1820

1921
public virtual int MaxPerPage => 15;
@@ -34,20 +36,23 @@ public virtual int PageIndex
3436

3537
public virtual void OnPageChanged() => throw new NotImplementedException();
3638

37-
public void Start()
39+
public virtual void Start() => OnPageChanged();
40+
41+
public virtual void Update()
3842
{
39-
OnPageChanged();
43+
if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.mouseScrollDelta.y > 0f)
44+
Cycle(false);
45+
else if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.RightArrow) || Input.mouseScrollDelta.y < 0f)
46+
Cycle(true);
4047
}
4148

42-
public virtual void Update()
49+
/// <summary>
50+
/// Loops around if you go over the limits.<br/>
51+
/// Attempting to go up a page while on the first page will take you to the last page and vice versa.
52+
/// </summary>
53+
public virtual void Cycle(bool increment)
4354
{
44-
if (Input.GetKeyDown(KeyCode.UpArrow) || Input.mouseScrollDelta.y > 0f)
45-
{
46-
PageIndex = Mathf.Clamp(PageIndex - 1, 0, MaxPageIndex);
47-
}
48-
else if (Input.GetKeyDown(KeyCode.DownArrow) || Input.mouseScrollDelta.y < 0f)
49-
{
50-
PageIndex = Mathf.Clamp(PageIndex + 1, 0, MaxPageIndex);
51-
}
55+
var change = increment ? 1 : -1;
56+
PageIndex = Mathf.Clamp(PageIndex + change, 0, MaxPageIndex);
5257
}
5358
}

src/CrowdedMod/Components/MeetingHudPagingBehaviour.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public MeetingHudPagingBehaviour(IntPtr ptr) : base(ptr)
2020
public IEnumerable<PlayerVoteArea> Targets => meetingHud.playerStates.OrderBy(p => p.AmDead);
2121
public override int MaxPageIndex => (Targets.Count() - 1) / MaxPerPage;
2222

23+
public override void Start() => OnPageChanged();
24+
2325
public override void Update()
2426
{
2527
base.Update();
2628

27-
if (meetingHud.state is MeetingHud.VoteStates.Animating or MeetingHud.VoteStates.Proceeding)
28-
{
29-
return; // TimerText does not update there
30-
}
31-
29+
if (meetingHud.state is MeetingHud.VoteStates.Animating or MeetingHud.VoteStates.Proceeding || meetingHud.TimerText.text.Contains($" ({PageIndex + 1}/{MaxPageIndex + 1})"))
30+
return; // TimerText does not update there ^ Sometimes the timer text is spammed with the page counter for some weird reason so this is just a band-aid fix for it
31+
3232
meetingHud.TimerText.text += $" ({PageIndex + 1}/{MaxPageIndex + 1})";
3333
}
3434

@@ -42,11 +42,12 @@ public override void OnPageChanged()
4242

4343
var relativeIndex = i % MaxPerPage;
4444
var row = relativeIndex / 3;
45+
var col = relativeIndex % 3;
4546
var buttonTransform = button.transform;
4647
buttonTransform.localPosition = meetingHud.VoteOrigin +
4748
new Vector3(
48-
meetingHud.VoteButtonOffsets.x * (relativeIndex % 3),
49-
meetingHud.VoteButtonOffsets.y * row,
49+
meetingHud.VoteButtonOffsets.x * col,
50+
meetingHud.VoteButtonOffsets.y * row,
5051
buttonTransform.localPosition.z
5152
);
5253
} else {

src/CrowdedMod/Components/ShapeShifterPagingBehaviour.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using Il2CppInterop.Runtime.Attributes;
55
using Reactor.Utilities.Attributes;
6+
using TMPro;
67
using UnityEngine;
78

89
namespace CrowdedMod.Components;
@@ -19,9 +20,22 @@ public ShapeShifterPagingBehaviour(IntPtr ptr) : base(ptr)
1920
public IEnumerable<ShapeshifterPanel> Targets => shapeshifterMinigame.potentialVictims.ToArray();
2021

2122
public override int MaxPageIndex => (Targets.Count() - 1) / MaxPerPage;
23+
private TextMeshPro PageText = null!;
24+
25+
public override void Start()
26+
{
27+
PageText = Instantiate(HudManager.Instance.KillButton.cooldownTimerText, shapeshifterMinigame.transform);
28+
PageText.name = PAGE_INDEX_GAME_OBJECT_NAME;
29+
PageText.enableWordWrapping = false;
30+
PageText.gameObject.SetActive(true);
31+
PageText.transform.localPosition = new Vector3(4.1f, -2.36f, -1f);
32+
PageText.transform.localScale *= 0.5f;
33+
OnPageChanged();
34+
}
2235

2336
public override void OnPageChanged()
2437
{
38+
PageText.text = $"({PageIndex + 1}/{MaxPageIndex + 1})";
2539
var i = 0;
2640

2741
foreach (var panel in Targets)
@@ -31,10 +45,11 @@ public override void OnPageChanged()
3145

3246
var relativeIndex = i % MaxPerPage;
3347
var row = relativeIndex / 3;
48+
var col = relativeIndex % 3;
3449
var buttonTransform = panel.transform;
3550
buttonTransform.localPosition = new Vector3(
36-
shapeshifterMinigame.XStart + shapeshifterMinigame.XOffset * (relativeIndex % 3),
37-
shapeshifterMinigame.YStart + shapeshifterMinigame.YOffset * row,
51+
shapeshifterMinigame.XStart + shapeshifterMinigame.XOffset * col,
52+
shapeshifterMinigame.YStart + shapeshifterMinigame.YOffset * row,
3853
buttonTransform.localPosition.z
3954
);
4055
} else {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Il2CppInterop.Runtime.Attributes;
5+
using TMPro;
6+
using Reactor.Utilities.Attributes;
7+
using UnityEngine;
8+
9+
namespace CrowdedMod.Components;
10+
11+
[RegisterInIl2Cpp]
12+
public class VitalsPagingBehaviour : AbstractPagingBehaviour
13+
{
14+
public VitalsPagingBehaviour(IntPtr ptr) : base(ptr) {}
15+
16+
public VitalsMinigame vitalsMinigame = null!;
17+
18+
[HideFromIl2Cpp]
19+
public IEnumerable<VitalsPanel> Targets => vitalsMinigame.vitals.ToArray();
20+
public override int MaxPageIndex => (Targets.Count() - 1) / MaxPerPage;
21+
private TextMeshPro PageText = null!;
22+
23+
public override void Start()
24+
{
25+
PageText = Instantiate(HudManager.Instance.KillButton.cooldownTimerText, vitalsMinigame.transform);
26+
PageText.name = PAGE_INDEX_GAME_OBJECT_NAME;
27+
PageText.enableWordWrapping = false;
28+
PageText.gameObject.SetActive(true);
29+
PageText.transform.localPosition = new Vector3(2.7f, -2f, -1f);
30+
PageText.transform.localScale *= 0.5f;
31+
OnPageChanged();
32+
}
33+
34+
public override void OnPageChanged()
35+
{
36+
if (PlayerTask.PlayerHasTaskOfType<HudOverrideTask>(PlayerControl.LocalPlayer))
37+
return;
38+
39+
PageText.text = $"({PageIndex + 1}/{MaxPageIndex + 1})";
40+
var i = 0;
41+
42+
foreach (var panel in Targets)
43+
{
44+
if (i >= PageIndex * MaxPerPage && i < (PageIndex + 1) * MaxPerPage)
45+
{
46+
panel.gameObject.SetActive(true);
47+
var relativeIndex = i % MaxPerPage;
48+
var row = relativeIndex / 3;
49+
var col = relativeIndex % 3;
50+
var panelTransform = panel.transform;
51+
panelTransform.localPosition = new Vector3(
52+
vitalsMinigame.XStart + vitalsMinigame.XOffset * col,
53+
vitalsMinigame.YStart + vitalsMinigame.YOffset * row,
54+
panelTransform.localPosition.z
55+
);
56+
}
57+
else
58+
panel.gameObject.SetActive(false);
59+
60+
i++;
61+
}
62+
}
63+
}

src/CrowdedMod/CrowdedMod.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<LangVersion>latest</LangVersion>
99
<DebugType>embedded</DebugType>
1010
<Nullable>enable</Nullable>
11+
<AmongUs>H:\amogus\latest idfk\Among Us</AmongUs>
1112
</PropertyGroup>
1213
<PropertyGroup>
1314
<GamePlatform Condition="'$(GamePlatform)' == ''">Steam</GamePlatform>

src/CrowdedMod/CrowdedModPlugin.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@
44
using BepInEx.Unity.IL2CPP;
55
using HarmonyLib;
66
using Reactor;
7+
using Reactor.Networking;
8+
using Reactor.Networking.Attributes;
79

8-
namespace CrowdedMod {
9-
[BepInAutoPlugin("xyz.crowdedmods.crowdedmod")]
10-
[BepInProcess("Among Us.exe")]
11-
[BepInDependency(ReactorPlugin.Id)]
12-
[BepInDependency("gg.reactor.debugger", BepInDependency.DependencyFlags.SoftDependency)] // fix debugger overwriting MinPlayers
13-
public partial class CrowdedModPlugin : BasePlugin
14-
{
15-
public const int MaxPlayers = 127;
16-
public const int MaxImpostors = 127 / 2;
17-
18-
private Harmony Harmony { get; } = new (Id);
10+
namespace CrowdedMod;
11+
12+
[BepInAutoPlugin("xyz.crowdedmods.crowdedmod")]
13+
[BepInProcess("Among Us.exe")]
14+
[BepInDependency(ReactorPlugin.Id)]
15+
[ReactorModFlags(ModFlags.RequireOnAllClients)]
16+
[BepInDependency("gg.reactor.debugger", BepInDependency.DependencyFlags.SoftDependency)] // fix debugger overwriting MinPlayers
17+
public partial class CrowdedModPlugin : BasePlugin
18+
{
19+
public const int MaxPlayers = 127;
20+
public const int MaxImpostors = 127 / 2;
1921

20-
public override void Load()
21-
{
22-
NormalGameOptionsV07.RecommendedImpostors = NormalGameOptionsV07.MaxImpostors = Enumerable.Repeat(127, 127).ToArray();
23-
NormalGameOptionsV07.MinPlayers = Enumerable.Repeat(4, 127).ToArray();
22+
private Harmony Harmony { get; } = new (Id);
2423

24+
public override void Load()
25+
{
26+
NormalGameOptionsV07.RecommendedImpostors = NormalGameOptionsV07.MaxImpostors = Enumerable.Repeat(127, 127).ToArray();
27+
NormalGameOptionsV07.MinPlayers = Enumerable.Repeat(4, 127).ToArray();
2528

26-
Harmony.PatchAll();
27-
}
29+
Harmony.PatchAll();
2830
}
29-
}
31+
}

src/CrowdedMod/Net/SetColorRpc.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using CrowdedMod;
2-
using Hazel;
1+
using Hazel;
32
using Reactor.Networking.Attributes;
43
using Reactor.Networking.Rpc;
54
namespace CrowdedMod.Net;

0 commit comments

Comments
 (0)