Skip to content

Commit

Permalink
6.18 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
whichtwix committed Jul 1, 2024
1 parent bb2dc95 commit d8cf1e5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
22 changes: 14 additions & 8 deletions MCI/InstanceControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@
using UnityEngine;
using BepInEx.Unity.IL2CPP;
using MCI.Patches;
using System.Collections;

namespace MCI;

public static class InstanceControl
{
internal static Dictionary<int, ClientData> Clients = new();
internal static Dictionary<byte, int> PlayerClientIDs = new();
internal static Dictionary<byte, Vector2> SavedPositions = new();
internal static Dictionary<int, ClientData> Clients = [];

internal static Dictionary<byte, int> PlayerClientIDs = [];

internal static Dictionary<byte, Vector2> SavedPositions = [];

public static PlayerControl CurrentPlayerInPower { get; private set; }

public static int AvailableId()
{
for (var i = 1; i < 128; i++)
{
if (!Clients.ContainsKey(i) && PlayerControl.LocalPlayer.OwnerId != i)
if (!AmongUsClient.Instance.allClients.ToArray().Any(x => x.Id == i) && !Clients.ContainsKey(i) && PlayerControl.LocalPlayer.OwnerId != i)
return i;
}

Expand Down Expand Up @@ -104,7 +108,7 @@ public static void CleanUpLoad()
}
}

public static PlayerControl CreatePlayerInstance()
public static IEnumerator CreatePlayerInstance()
{
var sampleId = AvailableId();
var sampleC = new ClientData(sampleId, $"Bot-{sampleId}", new()
Expand All @@ -113,15 +117,16 @@ public static PlayerControl CreatePlayerInstance()
PlatformName = "Bot"
}, 1, "", "robotmodeactivate");

AmongUsClient.Instance.CreatePlayer(sampleC);
AmongUsClient.Instance.allClients.Add(sampleC);
AmongUsClient.Instance.GetOrCreateClient(sampleC);
yield return AmongUsClient.Instance.CreatePlayer(sampleC);

sampleC.Character.SetName(MCIPlugin.IKnowWhatImDoing ? $"Bot {{{sampleC.Character.PlayerId}:{sampleId}}}" : $"Bot {sampleC.Character.PlayerId}");
sampleC.Character.SetSkin(HatManager.Instance.allSkins[Random.Range(0, HatManager.Instance.allSkins.Count)].ProdId, 0);
sampleC.Character.SetNamePlate(HatManager.Instance.allNamePlates[Random.RandomRangeInt(0, HatManager.Instance.allNamePlates.Count)].ProdId);
sampleC.Character.SetPet(HatManager.Instance.allPets[Random.RandomRangeInt(0, HatManager.Instance.allPets.Count)].ProdId);
sampleC.Character.SetColor(Random.Range(0, Palette.PlayerColors.Length));
sampleC.Character.SetHat("hat_NoHat", 0);
sampleC.Character.SetVisor("visor_EmptyVisor", 0);

Clients.Add(sampleId, sampleC);
PlayerClientIDs.Add(sampleC.Character.PlayerId, sampleId);
Expand All @@ -134,7 +139,8 @@ public static PlayerControl CreatePlayerInstance()
if (IL2CPPChainloader.Instance.Plugins.ContainsKey("me.eisbison.theotherroles"))
sampleC.Character.GetComponent<DummyBehaviour>().enabled = true;

return sampleC.Character;
yield return sampleC.Character.MyPhysics.CoSpawnPlayer(LobbyBehaviour.Instance);
yield break;
}

public static void UpdateNames(string name)
Expand Down
5 changes: 3 additions & 2 deletions MCI/MCI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.674" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2023.10.24" />
<PackageReference Include="Reactor" Version="2.2.0" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.688" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.6.18" />
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" />
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.1.0-rc.1" />
<PackageReference Include="System.Text.Json" Version="6.0.7" />
Expand Down
8 changes: 1 addition & 7 deletions MCI/MCIPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using System;
using UnityEngine.SceneManagement;

namespace MCI;

[BepInAutoPlugin("dragonbreath.au.mci", "MCI", VersionString)]
[BepInProcess("Among Us.exe")]
[BepInDependency(SubmergedCompatibility.SUBMERGED_GUID, BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency(Reactor.ReactorPlugin.Id)]
public partial class MCIPlugin : BasePlugin
{
public const string VersionString = "0.0.6";
Expand All @@ -32,11 +32,5 @@ public override void Load()
Harmony.PatchAll();
UpdateChecker.CheckForUpdate();
SubmergedCompatibility.Initialize();

SceneManager.add_sceneLoaded((Action<Scene, LoadSceneMode>)((scene, _) =>
{
if (scene.name == "MainMenu")
ModManager.Instance.ShowModStamp();
}));
}
}
5 changes: 3 additions & 2 deletions MCI/Patches/KeyboardJoystick.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using Reactor.Utilities;
using UnityEngine;

namespace MCI.Patches;
Expand All @@ -21,7 +22,7 @@ public static void Postfix()
return; //press f6 and f5 to bypass limit

InstanceControl.CleanUpLoad();
InstanceControl.CreatePlayerInstance();
Coroutines.Start(InstanceControl.CreatePlayerInstance());
}

if (Input.GetKeyDown(KeyCode.F9))
Expand Down Expand Up @@ -63,7 +64,7 @@ private static void Cycle(bool increment)

if (ControllingFigure < 0)
ControllingFigure = InstanceControl.Clients.Count - 1;
else if (ControllingFigure >= InstanceControl.Clients.Count)
else if (ControllingFigure > InstanceControl.Clients.Count)
ControllingFigure = 0;
}
}
3 changes: 2 additions & 1 deletion MCI/Patches/OnLobbyStart.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using Reactor.Utilities;

namespace MCI.Patches;

Expand All @@ -17,7 +18,7 @@ public static void Postfix()
InstanceControl.SavedPositions.Clear();

for (var i = 0; i < count; i++)
InstanceControl.CreatePlayerInstance();
Coroutines.Start(InstanceControl.CreatePlayerInstance());
}
}
}

0 comments on commit d8cf1e5

Please sign in to comment.