Skip to content

Commit

Permalink
Merge pull request #17 from AlchlcDvl/master
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
MyDragonBreath authored Apr 21, 2024
2 parents 5a6de8b + eeb4d0c commit bb2dc95
Show file tree
Hide file tree
Showing 17 changed files with 459 additions and 456 deletions.
20 changes: 10 additions & 10 deletions MCI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MCI", "MCI\MCI.csproj", "{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
193 changes: 152 additions & 41 deletions MCI/InstanceControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,179 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using BepInEx.Unity.IL2CPP;
using MCI.Patches;

namespace MCI
namespace MCI;

public static class InstanceControl
{
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();
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)
return i;
}

return -1;
}

public static void SwitchTo(byte playerId)
{
internal static Dictionary<int, ClientData> clients = new();
SavedPositions[PlayerControl.LocalPlayer.PlayerId] = PlayerControl.LocalPlayer.transform.position;
PlayerControl.LocalPlayer.NetTransform.RpcSnapTo(PlayerControl.LocalPlayer.transform.position);
PlayerControl.LocalPlayer.moveable = false;

var light = PlayerControl.LocalPlayer.lightSource;
var savedId = PlayerControl.LocalPlayer.PlayerId;

//Setup new player
var newPlayer = PlayerById(playerId);

internal static Dictionary<byte, int> PlayerIdClientId = new();
if (newPlayer == null)
return;

public const int MaxID = 100;
PlayerControl.LocalPlayer = newPlayer;
PlayerControl.LocalPlayer.lightSource = light;
PlayerControl.LocalPlayer.moveable = true;

public static int AvailableId()
AmongUsClient.Instance.ClientId = PlayerControl.LocalPlayer.OwnerId;
AmongUsClient.Instance.HostId = PlayerControl.LocalPlayer.OwnerId;

HudManager.Instance.SetHudActive(true);
HudManager.Instance.ShadowQuad.gameObject.SetActive(!newPlayer.Data.IsDead);
HudManager.Instance.KillButton.buttonLabelText.gameObject.SetActive(false);

//hacky "fix" for twix and det

HudManager.Instance.KillButton.transform.parent.GetComponentsInChildren<Transform>().ToList().ForEach(x =>
{
for (int i = 2; i < MaxID; i++)
{
if (!clients.ContainsKey(i) && PlayerControl.LocalPlayer.OwnerId != i)
return i;
}
return -1;
}
if (x.gameObject.name == "KillButton(Clone)")
Object.Destroy(x.gameObject);
});

public static PlayerControl CurrentPlayerInPower { get; private set; }
HudManager.Instance.KillButton.transform.GetComponentsInChildren<Transform>().ToList().ForEach(x =>
{
if (x.gameObject.name == "KillTimer_TMP(Clone)")
Object.Destroy(x.gameObject);
});

public static void SwitchTo(byte playerId)
HudManager.Instance.transform.GetComponentsInChildren<Transform>().ToList().ForEach(x =>
{
PlayerControl.LocalPlayer.NetTransform.RpcSnapTo(PlayerControl.LocalPlayer.transform.position);
PlayerControl.LocalPlayer.moveable = false;
if (x.gameObject.name == "KillButton(Clone)")
Object.Destroy(x.gameObject);
});

var light = PlayerControl.LocalPlayer.lightSource;
light.transform.SetParent(newPlayer.transform);
light.transform.localPosition = newPlayer.Collider.offset;
Camera.main.GetComponent<FollowerCamera>().SetTarget(newPlayer);
newPlayer.MyPhysics.ResetMoveState(true);
KillAnimation.SetMovement(newPlayer, true);
newPlayer.MyPhysics.inputHandler.enabled = true;
CurrentPlayerInPower = newPlayer;

if (SavedPositions.TryGetValue(playerId, out var pos))
newPlayer.NetTransform.RpcSnapTo(pos);

if (SavedPositions.TryGetValue(savedId, out var pos2))
PlayerById(savedId).NetTransform.RpcSnapTo(pos2);

if (MeetingHud.Instance)
{
if (newPlayer.Data.IsDead)
MeetingHud.Instance.SetForegroundForDead();
else
MeetingHud.Instance.SetForegroundForAlive(); //Parially works, i still need to get the darkening effect to go
}
}

var newPlayer = Utils.PlayerById(playerId);
public static void CleanUpLoad()
{
if (GameData.Instance.AllPlayers.Count == 1)
{
Clients.Clear();
PlayerClientIDs.Clear();
SavedPositions.Clear();
}
}

HudManager.Instance.KillButton.buttonLabelText.gameObject.SetActive(false);
public static PlayerControl CreatePlayerInstance()
{
var sampleId = AvailableId();
var sampleC = new ClientData(sampleId, $"Bot-{sampleId}", new()
{
Platform = Platforms.StandaloneWin10,
PlatformName = "Bot"
}, 1, "", "robotmodeactivate");

PlayerControl.LocalPlayer = newPlayer;
PlayerControl.LocalPlayer.lightSource = light;
PlayerControl.LocalPlayer.moveable = true;
AmongUsClient.Instance.CreatePlayer(sampleC);
AmongUsClient.Instance.allClients.Add(sampleC);

AmongUsClient.Instance.ClientId = PlayerControl.LocalPlayer.OwnerId;
AmongUsClient.Instance.HostId = PlayerControl.LocalPlayer.OwnerId;
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);

HudManager.Instance.SetHudActive(true);
Clients.Add(sampleId, sampleC);
PlayerClientIDs.Add(sampleC.Character.PlayerId, sampleId);
sampleC.Character.MyPhysics.ResetAnimState();
sampleC.Character.MyPhysics.ResetMoveState();

//hacky "fix" for twix and det
if (SubmergedCompatibility.Loaded)
SubmergedCompatibility.ImpartSub(sampleC.Character);

HudManager.Instance.KillButton.transform.parent.GetComponentsInChildren<Transform>().ToList().ForEach((x) => { if (x.gameObject.name == "KillButton(Clone)") Object.Destroy(x.gameObject); });
HudManager.Instance.KillButton.transform.GetComponentsInChildren<Transform>().ToList().ForEach((x) => { if (x.gameObject.name == "KillTimer_TMP(Clone)") Object.Destroy(x.gameObject); });
HudManager.Instance.transform.GetComponentsInChildren<Transform>().ToList().ForEach((x) => { if (x.gameObject.name == "KillButton(Clone)") Object.Destroy(x.gameObject); });
if (IL2CPPChainloader.Instance.Plugins.ContainsKey("me.eisbison.theotherroles"))
sampleC.Character.GetComponent<DummyBehaviour>().enabled = true;

light.transform.SetParent(PlayerControl.LocalPlayer.transform);
light.transform.localPosition = PlayerControl.LocalPlayer.Collider.offset;
Camera.main.GetComponent<FollowerCamera>().SetTarget(PlayerControl.LocalPlayer);
PlayerControl.LocalPlayer.MyPhysics.ResetMoveState(true);
KillAnimation.SetMovement(PlayerControl.LocalPlayer, true);
PlayerControl.LocalPlayer.MyPhysics.inputHandler.enabled = true;
CurrentPlayerInPower = newPlayer;
}
return sampleC.Character;
}

public static void SwitchTo(int clientId)
public static void UpdateNames(string name)
{
foreach (var playerId in PlayerClientIDs.Keys)
{
byte? id = PlayerIdClientId.Keys.FirstOrDefault((byte x) => PlayerIdClientId[x] == clientId);
if (id != null) SwitchTo((byte)id);
if (MCIPlugin.IKnowWhatImDoing)
PlayerById(playerId).SetName(name + $" {{{playerId}:{PlayerClientIDs[playerId]}}}");
else
PlayerById(playerId).SetName(name + $" {playerId}");
}
}

public static PlayerControl PlayerById(byte id) => PlayerControl.AllPlayerControls.ToArray().ToList().Find(x => x.PlayerId == id);

public static void RemovePlayer(byte id)
{
if (id == 0)
return;

var clientId = Clients.FirstOrDefault(x => x.Value.Character.PlayerId == id).Key;
Clients.Remove(clientId, out var outputData);
PlayerClientIDs.Remove(id);
SavedPositions.Remove(id);
AmongUsClient.Instance.RemovePlayer(clientId, DisconnectReasons.Custom);
AmongUsClient.Instance.allClients.Remove(outputData);
}

public static void RemoveAllPlayers()
{
PlayerClientIDs.Keys.ToList().ForEach(RemovePlayer);
SwitchTo(0);
Keyboard_Joystick.ControllingFigure = 0;
}

public static void SetForegroundForAlive(this MeetingHud __instance)
{
__instance.amDead = false;
__instance.SkipVoteButton.gameObject.SetActive(true);
__instance.SkipVoteButton.AmDead = false;
__instance.Glass.gameObject.SetActive(false);
}
}
26 changes: 9 additions & 17 deletions MCI/MCI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,22 @@
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<DebugType>embedded</DebugType>

<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>dev</VersionSuffix>
<VersionSuffix>dev</VersionSuffix>
<Description>MultiClientInstancing</Description>
<Authors>MyDragonBreath, whichtwix</Authors>
</PropertyGroup>

<PropertyGroup>
<GamePlatform Condition="'$(GamePlatform)' == ''">Steam</GamePlatform>
<GameVersion Condition="'$(GamePlatform)' == 'Steam'">2023.6.13</GameVersion>
<GameVersion Condition="'$(GamePlatform)' == 'Itch'">2023.6.13</GameVersion>
<Authors>MyDragonBreath, whichtwix, AlchlcSystm</Authors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.670" />
<PackageReference Include="AmongUs.GameLibs.$(GamePlatform)" Version="$(GameVersion)" PrivateAssets="all" />

<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.0.1" PrivateAssets="all" />

<PackageReference Include="System.Text.Json" Version="6.0.7" PrivateAssets="all" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.674" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2023.10.24" />
<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" />
<PackageReference Include="Samboy063.Cpp2IL.Core" Version="2022.1.0-development.866" />
</ItemGroup>

<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUs)/BepInEx/plugins/" UseSymboliclinksIfPossible="true" />
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUs)/BepInEx/plugins/"/>
</Target>
</Project>
66 changes: 27 additions & 39 deletions MCI/MCIPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,39 @@
using System;
using UnityEngine.SceneManagement;

namespace MCI
{
[BepInAutoPlugin("dragonbreath.au.mci", "MCI", VersionString)]
[BepInProcess("Among Us.exe")]
[BepInDependency(SubmergedCompatibility.SUBMERGED_GUID, BepInDependency.DependencyFlags.SoftDependency)]
public partial class MCIPlugin : BasePlugin
{
public const string VersionString = "0.0.6";
internal static Version vVersion = new(VersionString);
public Harmony Harmony { get; } = new(Id);
namespace MCI;

public static MCIPlugin Singleton { get; private set; } = null;

public static string RobotName { get; set; } = "Bot";
[BepInAutoPlugin("dragonbreath.au.mci", "MCI", VersionString)]
[BepInProcess("Among Us.exe")]
[BepInDependency(SubmergedCompatibility.SUBMERGED_GUID, BepInDependency.DependencyFlags.SoftDependency)]
public partial class MCIPlugin : BasePlugin
{
public const string VersionString = "0.0.6";
public static Version vVersion = new(VersionString);
public Harmony Harmony { get; } = new(Id);

public static bool Enabled { get; set; } = true;
public static bool IKnowWhatImDoing { get; set; } = false;
public override void Load()
{
if (Singleton != null) return;
Singleton = this;
public static MCIPlugin Singleton { get; private set; } = null;

Harmony.PatchAll();
UpdateChecker.CheckForUpdate();
public static string RobotName { get; set; } = "Bot";

SubmergedCompatibility.Initialize();
public static bool Enabled { get; set; } = true;
public static bool IKnowWhatImDoing { get; set; } = false;
public static bool Persistence { get; set; } = true;

SceneManager.add_sceneLoaded((Action<Scene, LoadSceneMode>)((scene, _) =>
{
if (scene.name == "MainMenu")
{
ModManager.Instance.ShowModStamp();
}
}));
}
public override void Load()
{
if (Singleton != null)
return;

internal static bool Persistence = true;
}
Singleton = this;
Harmony.PatchAll();
UpdateChecker.CheckForUpdate();
SubmergedCompatibility.Initialize();

[HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Update))]
public static class CountdownPatch
{
public static void Prefix(GameStartManager __instance)
SceneManager.add_sceneLoaded((Action<Scene, LoadSceneMode>)((scene, _) =>
{
__instance.countDownTimer = 0;
}
if (scene.name == "MainMenu")
ModManager.Instance.ShowModStamp();
}));
}
}
}
Loading

0 comments on commit bb2dc95

Please sign in to comment.