Skip to content

Commit 14f2c2e

Browse files
Merge pull request #6 from MyDragonBreath/v0.0.4
v0.0.4
2 parents 779c717 + 879118e commit 14f2c2e

File tree

13 files changed

+192
-117
lines changed

13 files changed

+192
-117
lines changed

.github/workflows/main.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@ on: [ "push", "pull_request" ]
44

55
jobs:
66
build:
7-
runs-on: ubuntu-20.04
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
dotnet-version: ['6.0']
811

912
steps:
10-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1114
with:
1215
submodules: true
1316

1417
- name: Setup .NET
15-
uses: actions/setup-dotnet@v1
18+
uses: actions/setup-dotnet@v3
1619
with:
17-
dotnet-version: 6.x
20+
dotnet-version: ${{ matrix.dotnet-version }}
1821

19-
- name: Run the Cake script
20-
uses: cake-build/cake-action@v1
21-
with:
22-
verbosity: Diagnostic
22+
- name: Install dependencies
23+
run: dotnet restore
24+
- name: Build
25+
run: dotnet build --configuration Release --no-restore
2326

24-
- uses: actions/upload-artifact@v2
27+
- uses: actions/upload-artifact@v3.1.2
2528
with:
2629
name: MCI.dll
27-
path: MCI/bin/Release/netstandard2.1/MCI.dll
30+
path: MCI/bin/Release/net6.0/MCI.dll

MCI/InstanceControl.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,53 @@ namespace MCI
77
{
88
public static class InstanceControl
99
{
10-
public static Dictionary<int, ClientData> clients = new Dictionary<int, ClientData>();
11-
public static Dictionary<byte, int> PlayerIdClientId = new Dictionary<byte, int>();
10+
public static Dictionary<int, ClientData> clients = new();
11+
12+
public static Dictionary<byte, int> PlayerIdClientId = new();
13+
1214
public const int MaxID = 100;
13-
public static int availableId()
15+
16+
public static int AvailableId()
1417
{
1518
for (int i = 2; i < MaxID; i++)
16-
if (!clients.ContainsKey(i))
17-
if (PlayerControl.LocalPlayer.OwnerId != i) return i;
19+
{
20+
if (!clients.ContainsKey(i) && PlayerControl.LocalPlayer.OwnerId != i)
21+
return i;
22+
}
1823
return -1;
1924
}
2025

21-
22-
23-
24-
25-
2626
public static PlayerControl CurrentPlayerInPower { get; private set; }
2727

2828
public static void SwitchTo(byte playerId)
2929
{
3030
PlayerControl.LocalPlayer.NetTransform.RpcSnapTo(PlayerControl.LocalPlayer.transform.position);
3131
PlayerControl.LocalPlayer.moveable = false;
3232

33-
Object.Destroy(PlayerControl.LocalPlayer.myLight);
34-
33+
Object.Destroy(PlayerControl.LocalPlayer.lightSource);
3534

3635
var newPlayer = Utils.PlayerById(playerId);
36+
37+
HudManager.Instance.KillButton.buttonLabelText.gameObject.SetActive(false);
38+
3739
PlayerControl.LocalPlayer = newPlayer;
3840
PlayerControl.LocalPlayer.moveable = true;
3941

4042
AmongUsClient.Instance.ClientId = PlayerControl.LocalPlayer.OwnerId;
4143
AmongUsClient.Instance.HostId = PlayerControl.LocalPlayer.OwnerId;
4244

43-
DestroyableSingleton<HudManager>.Instance.SetHudActive(true);
45+
HudManager.Instance.SetHudActive(true);
4446

4547
//hacky "fix" for twix and det
46-
DestroyableSingleton<HudManager>.Instance.KillButton.transform.parent.GetComponentsInChildren<Transform>().ToList().ForEach((x) => { if (x.gameObject.name == "KillButton(Clone)") Object.Destroy(x.gameObject); });
47-
DestroyableSingleton<HudManager>.Instance.transform.GetComponentsInChildren<Transform>().ToList().ForEach((x) => { if (x.gameObject.name == "KillButton(Clone)") Object.Destroy(x.gameObject); });
48+
49+
HudManager.Instance.KillButton.transform.parent.GetComponentsInChildren<Transform>().ToList().ForEach((x) => { if (x.gameObject.name == "KillButton(Clone)") Object.Destroy(x.gameObject); });
50+
HudManager.Instance.KillButton.transform.GetComponentsInChildren<Transform>().ToList().ForEach((x) => { if (x.gameObject.name == "KillTimer_TMP(Clone)") Object.Destroy(x.gameObject); });
51+
HudManager.Instance.transform.GetComponentsInChildren<Transform>().ToList().ForEach((x) => { if (x.gameObject.name == "KillButton(Clone)") Object.Destroy(x.gameObject); });
4852

49-
PlayerControl.LocalPlayer.myLight = UnityEngine.Object.Instantiate<LightSource>(PlayerControl.LocalPlayer.LightPrefab);
50-
PlayerControl.LocalPlayer.myLight.transform.SetParent(PlayerControl.LocalPlayer.transform);
51-
PlayerControl.LocalPlayer.myLight.transform.localPosition = PlayerControl.LocalPlayer.Collider.offset;
52-
PlayerControl.LocalPlayer.myLight.Initialize();
53+
PlayerControl.LocalPlayer.lightSource = Object.Instantiate(PlayerControl.LocalPlayer.LightPrefab);
54+
PlayerControl.LocalPlayer.lightSource.transform.SetParent(PlayerControl.LocalPlayer.transform);
55+
PlayerControl.LocalPlayer.lightSource.transform.localPosition = PlayerControl.LocalPlayer.Collider.offset;
56+
PlayerControl.LocalPlayer.lightSource.Initialize(PlayerControl.LocalPlayer.Collider.offset * 0.5f);
5357
Camera.main.GetComponent<FollowerCamera>().SetTarget(PlayerControl.LocalPlayer);
5458
PlayerControl.LocalPlayer.MyPhysics.ResetMoveState(true);
5559
KillAnimation.SetMovement(PlayerControl.LocalPlayer, true);
@@ -59,7 +63,7 @@ public static void SwitchTo(byte playerId)
5963

6064
public static void SwitchTo(int clientId)
6165
{
62-
byte? id = Enumerable.FirstOrDefault(InstanceControl.PlayerIdClientId.Keys, (byte x) => InstanceControl.PlayerIdClientId[x] == clientId);
66+
byte? id = PlayerIdClientId.Keys.FirstOrDefault((byte x) => PlayerIdClientId[x] == clientId);
6367
if (id != null) SwitchTo((byte)id);
6468
}
6569
}

MCI/MCI.csproj

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.1</TargetFramework>
3+
<TargetFramework>net6.0</TargetFramework>
44
<LangVersion>latest</LangVersion>
55
<DebugType>embedded</DebugType>
66

77
<VersionPrefix>1.0.0</VersionPrefix>
88
<VersionSuffix>dev</VersionSuffix>
99
<Description>MultiClientInstancing</Description>
10-
<!-- <Authors>your name</Authors> -->
10+
<Authors>MyDragonBreath, whichtwix</Authors>
1111
</PropertyGroup>
1212

1313
<PropertyGroup>
1414
<GamePlatform Condition="'$(GamePlatform)' == ''">Steam</GamePlatform>
15-
<GameVersion Condition="'$(GamePlatform)' == 'Steam'">2022.6.21</GameVersion>
16-
<GameVersion Condition="'$(GamePlatform)' == 'Itch'">2022.6.21</GameVersion>
15+
<GameVersion Condition="'$(GamePlatform)' == 'Steam'">2022.12.14</GameVersion>
16+
<GameVersion Condition="'$(GamePlatform)' == 'Itch'">2022.12.14</GameVersion>
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Reactor" Version="1.2.5" />
21-
<PackageReference Include="BepInEx.IL2CPP" Version="6.0.0-be.570" />
20+
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.664" />
2221
<PackageReference Include="AmongUs.GameLibs.$(GamePlatform)" Version="$(GameVersion)" PrivateAssets="all" />
2322

24-
<PackageReference Include="BepInEx.AutoPlugin" Version="1.0.1" PrivateAssets="all" />
25-
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="1.1.1" PrivateAssets="all" />
23+
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
24+
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.0.1" PrivateAssets="all" />
25+
26+
<PackageReference Include="System.Text.Json" Version="5.0.2" PrivateAssets="all" />
2627
</ItemGroup>
2728

2829
<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
2930
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUs)/BepInEx/plugins/" UseSymboliclinksIfPossible="true" />
3031
</Target>
31-
</Project>
32+
</Project>

MCI/MCIPlugin.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
using BepInEx;
2-
using BepInEx.IL2CPP;
2+
using BepInEx.Unity.IL2CPP;
33
using HarmonyLib;
4-
using Reactor;
54

65
namespace MCI
76
{
8-
9-
[BepInAutoPlugin]
7+
[BepInAutoPlugin("dragonbreath.au.mci", "MCI", VersionString)]
108
[BepInProcess("Among Us.exe")]
11-
[BepInDependency(ReactorPlugin.Id)]
129
public partial class MCIPlugin : BasePlugin
1310
{
11+
public const string VersionString = "0.0.4";
12+
public static System.Version vVersion = new(VersionString);
1413
public Harmony Harmony { get; } = new(Id);
1514
public override void Load()
1615
{
17-
1816
Harmony.PatchAll();
19-
20-
17+
UpdateChecker.checkForUpdate();
2118
}
22-
23-
2419
}
2520
}

MCI/Patches/KeyboardJoystick.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
using HarmonyLib;
22
using UnityEngine;
3-
using System.Linq;
43

54
namespace MCI.Patches
65
{
76
[HarmonyPatch(typeof(KeyboardJoystick), nameof(KeyboardJoystick.Update))]
8-
class Keyboard_Joystick
7+
public sealed class Keyboard_Joystick
98
{
10-
public static int controllingFigure = 0;
9+
private static int controllingFigure;
10+
1111
public static void Postfix()
1212
{
1313
if (Input.GetKeyDown(KeyCode.F5))
1414
{
1515
controllingFigure = PlayerControl.LocalPlayer.PlayerId;
16-
if (PlayerControl.AllPlayerControls.Count == 15) return; //remove this if your willing to suffer with the consequences.
16+
if (PlayerControl.AllPlayerControls.Count == 15 && !Input.GetKeyDown(KeyCode.F6)) return; //hold f6 and press f5 to bypass limit
1717
Utils.CleanUpLoad();
1818
Utils.CreatePlayerInstance("Robot");
1919
}
2020

2121
if (Input.GetKeyDown(KeyCode.F9))
2222
{
2323
controllingFigure++;
24-
controllingFigure = Mathf.Clamp(controllingFigure, 0, PlayerControl.AllPlayerControls.Count -1);
24+
controllingFigure = Mathf.Clamp(controllingFigure, 0, PlayerControl.AllPlayerControls.Count - 1);
2525
InstanceControl.SwitchTo((byte)controllingFigure);
2626
}
2727

2828
if (Input.GetKeyDown(KeyCode.F10))
2929
{
3030
controllingFigure--;
31-
controllingFigure = Mathf.Clamp(controllingFigure, 0, PlayerControl.AllPlayerControls.Count -1);
31+
controllingFigure = Mathf.Clamp(controllingFigure, 0, PlayerControl.AllPlayerControls.Count - 1);
3232
InstanceControl.SwitchTo((byte)controllingFigure);
3333
}
3434
}

MCI/Patches/LocalOnly.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
namespace MCI.Patches
55
{
66
[HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start))]
7-
class LocalOnly
7+
public sealed class LocalOnly
88
{
9-
static void Postfix(PingTracker __instance)
9+
public static void Postfix()
1010
{
11-
GameObject.Destroy(GameObject.Find("HowToPlayButton"));
12-
GameObject.Destroy(GameObject.Find("PlayOnlineButton"));
13-
GameObject.Destroy(GameObject.Find("FreePlayButton"));
11+
Object.Destroy(GameObject.Find("HowToPlayButton"));
12+
Object.Destroy(GameObject.Find("PlayOnlineButton"));
13+
Object.Destroy(GameObject.Find("FreePlayButton"));
1414
GameObject.Find("PlayLocalButton").transform.localPosition = new Vector3(0, -1f, 0);
1515

1616
var inf = new GameObject("Info");

MCI/Patches/OnGameStart.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using HarmonyLib;
2+
3+
namespace MCI.Patches
4+
{
5+
[HarmonyPatch]
6+
public sealed class OnGameStart
7+
{
8+
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CoStartGameHost))]
9+
[HarmonyPrefix]
10+
11+
public static void Postfix(AmongUsClient __instance)
12+
{
13+
foreach (var p in __instance.allClients)
14+
{
15+
p.IsReady = true;
16+
}
17+
}
18+
}
19+
}

MCI/Patches/PatchMeetingHud.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace MCI.Patches
44
{
55
[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Confirm))]
6-
class SameVoteAll
6+
public sealed class SameVoteAll
77
{
88
public static void Postfix(MeetingHud __instance, ref byte suspectStateIdx)
99
{

MCI/Patches/PingTracker.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using HarmonyLib;
2+
using UnityEngine;
3+
4+
namespace MCI.Patches
5+
{
6+
[HarmonyPriority(Priority.Low)]
7+
[HarmonyPatch(typeof(PingTracker), nameof(PingTracker.Update))]
8+
public static class PingTracker_Update
9+
{
10+
[HarmonyPostfix]
11+
public static void Postfix(PingTracker __instance)
12+
{
13+
var position = __instance.GetComponent<AspectPosition>();
14+
position.DistanceFromEdge = new Vector3(3.6f, 0.1f, 0);
15+
position.AdjustPosition();
16+
__instance.text.text +=
17+
"\n<color=#ff6700FF>MCI v" + MCIPlugin.VersionString + "</color>";
18+
if (UpdateChecker.needsUpdate) __instance.text.text += " - <color=#ff0000FF>UPDATE AVAILABLE</color>";
19+
__instance.text.text +=
20+
"\n by MyDragonBreath, whichTwix";
21+
}
22+
}
23+
}

MCI/UpdateChecker.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Net;
2+
using System.Net.Http;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
using System.Threading.Tasks;
6+
7+
namespace MCI
8+
{
9+
static class UpdateChecker
10+
{
11+
public static void checkForUpdate()
12+
{
13+
needsUpdate = taskUpdate().GetAwaiter().GetResult();
14+
}
15+
16+
public static async Task<bool> taskUpdate()
17+
{
18+
HttpClient http = new HttpClient();
19+
http.DefaultRequestHeaders.Add("User-Agent", "MCI-Agent");
20+
var response = await http.GetAsync(new System.Uri("https://api.github.com/repos/MyDragonBreath/AmongUs.MultiClientInstancing/releases/latest"), HttpCompletionOption.ResponseContentRead);
21+
22+
if (response.StatusCode != HttpStatusCode.OK || response.Content == null) return false;
23+
24+
string json = await response.Content.ReadAsStringAsync();
25+
var data = JsonSerializer.Deserialize<GitHubApiObject>(json);
26+
string tagname = data.tag_name;
27+
if (tagname == null) return false;
28+
int diff = 0;
29+
System.Version ver = System.Version.Parse(tagname.Replace("v", ""));
30+
diff = MCIPlugin.vVersion.CompareTo(ver);
31+
if (diff < 0) return true;
32+
return false;
33+
}
34+
35+
36+
public static bool needsUpdate = false;
37+
38+
39+
40+
41+
class GitHubApiObject
42+
{
43+
[JsonPropertyName("tag_name")]
44+
public string tag_name { get; set; }
45+
[JsonPropertyName("assets")]
46+
public GitHubApiAsset[] assets { get; set; }
47+
}
48+
49+
class GitHubApiAsset
50+
{
51+
[JsonPropertyName("browser_download_url")]
52+
public string browser_download_url { get; set; }
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)