-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Support 2021.6.30s - Fixed exception when using extensions GetText, GetTextWithDefault, GetString and GetStringWithDefault, "STRMISS" or the provided default value will be returned instead. - Added "Convert" example mod. - Updated readme.
- Loading branch information
1 parent
22a8940
commit 7941a0b
Showing
16 changed files
with
333 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
<Version>1.0.1</Version> | ||
|
||
<Description>Impostor conversion plugin</Description> | ||
<Authors>CoMaNdO</Authors> | ||
<Configurations>S20201209;S20210305;S202103313;S20210412;S20210510;S20210615;S20210630</Configurations> | ||
|
||
<Optimize>false</Optimize> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<NoWarn>1701;1702;</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="Resources\Button.png" /> | ||
|
||
<ProjectReference Include="..\Essentials\Essentials.csproj" /> | ||
</ItemGroup> | ||
|
||
<Import Project="../AmongUs.props" /> | ||
<Import Project="../Reactor.props" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using HarmonyLib; | ||
using UnityEngine; | ||
|
||
namespace Convert | ||
{ | ||
[HarmonyPatch] | ||
internal partial class ConvertPlugin | ||
{ | ||
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.Start))] | ||
[HarmonyPostfix] | ||
private static void PlayerControlStart() | ||
{ | ||
Conversions = 0; | ||
} | ||
|
||
#if S20201209 || S20210305 | ||
[HarmonyPatch(typeof(IntroCutscene.CoBegin__d), nameof(IntroCutscene.CoBegin__d.MoveNext))] | ||
#elif S202103313 || S20210510 | ||
[HarmonyPatch(typeof(IntroCutscene._CoBegin_d__11), nameof(IntroCutscene._CoBegin_d__11.MoveNext))] | ||
#elif S20210615 || UNOBFUSCATED | ||
[HarmonyPatch(typeof(IntroCutscene._CoBegin_d__14), nameof(IntroCutscene._CoBegin_d__14.MoveNext))] | ||
#else | ||
[HarmonyPatch(typeof(IntroCutscene.Nested_0), nameof(IntroCutscene.Nested_0.MoveNext))] | ||
#endif | ||
[HarmonyPostfix] | ||
private static void IntroCutsceneCoBegin() | ||
{ | ||
Conversions = 0; | ||
} | ||
|
||
[HarmonyPatch(typeof(EndGameManager), nameof(EndGameManager.Start))] | ||
[HarmonyPostfix] | ||
private static void EndGameManagerStart() | ||
{ | ||
Conversions = 0; | ||
} | ||
|
||
// Disallow SetInfected RPC when conversion count is at the limit. | ||
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.HandleRpc))] | ||
[HarmonyPrefix] | ||
private static bool PlayerControlHandleRpc([HarmonyArgument(0)] byte callid) | ||
{ | ||
return callid != (byte)RpcCalls.SetInfected || ImpostorConversions.GetValue() == 0 || Conversions < ImpostorConversions.GetValue(); | ||
} | ||
|
||
// Apply convert cooldown after kill when "Conversion has kill cooldown" is enabled. | ||
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.MurderPlayer))] | ||
[HarmonyPostfix] | ||
private static void PlayerControlMurderPlayer(PlayerControl __instance) | ||
{ | ||
if (!ConversionCooldown.GetValue() || !__instance || !__instance.AmOwner || !DestroyableSingleton<HudManager>.Instance.KillButton.isCoolingDown) return; | ||
|
||
ConvertButton.ApplyCooldown(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Hazel; | ||
using Reactor; | ||
#if !S20201209 && !S20210305 | ||
using Reactor.Networking; | ||
#endif | ||
|
||
namespace Convert | ||
{ | ||
internal partial class ConvertPlugin | ||
{ | ||
#if S20201209 || S20210305 | ||
[RegisterCustomRpc] | ||
#else | ||
[RegisterCustomRpc(0)] | ||
#endif | ||
private class Rpc : PlayerCustomRpc<ConvertPlugin, byte> | ||
{ | ||
public static Rpc Instance { get { return Rpc<Rpc>.Instance; } } | ||
|
||
#if S20201209 || S20210305 | ||
public Rpc(ConvertPlugin plugin) : base(plugin) | ||
#else | ||
public Rpc(ConvertPlugin plugin, uint id) : base(plugin, id) | ||
#endif | ||
{ | ||
} | ||
|
||
public override RpcLocalHandling LocalHandling { get { return RpcLocalHandling.After; } } | ||
|
||
public override void Write(MessageWriter writer, byte newImpostor) | ||
{ | ||
writer.Write(newImpostor); | ||
} | ||
|
||
public override byte Read(MessageReader reader) | ||
{ | ||
return reader.ReadByte(); | ||
} | ||
|
||
public override void Handle(PlayerControl innerNetObject, byte impostor) | ||
{ | ||
if (innerNetObject?.Data == null) return; | ||
|
||
Conversions++; | ||
|
||
PluginSingleton<ConvertPlugin>.Instance.Log.LogInfo($"{innerNetObject.Data.PlayerName} reported new impostor: {impostor} {GameData.Instance.GetPlayerById(impostor).PlayerName}, conversions: {Conversions}"); | ||
|
||
UpdateImpostors(impostor); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using BepInEx; | ||
using BepInEx.IL2CPP; | ||
using BepInEx.Logging; | ||
using Essentials; | ||
using Essentials.Options; | ||
//using Essentials.Rpc; | ||
using Essentials.UI; | ||
using HarmonyLib; | ||
using Hazel; | ||
using Reactor; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
|
||
namespace Convert | ||
{ | ||
[BepInPlugin(Id)] | ||
[BepInProcess("Among Us.exe")] | ||
[BepInDependency(EssentialsPlugin.Id)] | ||
[ReactorPluginSide(PluginSide.Both)] | ||
internal partial class ConvertPlugin : BasePlugin | ||
{ | ||
public const string Id = "com.comando.convert"; | ||
|
||
public Harmony Harmony { get; } = new Harmony(Id); | ||
|
||
private static CustomNumberOption ImpostorConversions = CustomOption.AddNumber(nameof(ImpostorConversions), "Impostor conversions", 1, 0, 2, 1); | ||
private static CustomToggleOption ConversionCooldown = CustomOption.AddToggle(nameof(ConversionCooldown), "Conversion applies kill cooldown", true); | ||
private static CooldownButton ConvertButton; | ||
private static int Conversions = 0; | ||
|
||
public override void Load() | ||
{ | ||
Harmony.PatchAll(); | ||
|
||
#if !S20210615 && !S20210630 | ||
RegisterInIl2CppAttribute.Register(); | ||
RegisterCustomRpcAttribute.Register(this); | ||
#endif | ||
|
||
ConvertButton = new CooldownButton("Resources.Button.png", new HudPosition(GameplayButton.OffsetX, GameplayButton.OffsetY, HudAlignment.BottomRight), PlayerControl.GameOptions.KillCooldown, 0, 10) | ||
{ | ||
Visible = false, | ||
Clickable = false | ||
}; | ||
ConvertButton.OnClick += ConvertButton_OnClick; | ||
ConvertButton.OnUpdate += ConvertButton_OnUpdate; | ||
} | ||
|
||
private void ConvertButton_OnClick(object sender, CancelEventArgs e) | ||
{ | ||
PlayerControl currentTarget = DestroyableSingleton<HudManager>.Instance?.KillButton?.CurrentTarget; | ||
if (!currentTarget) | ||
{ | ||
e.Cancel = true; | ||
|
||
return; | ||
} | ||
|
||
Rpc.Instance.Send(currentTarget.PlayerId); | ||
|
||
if (ConversionCooldown.GetValue()) PlayerControl.LocalPlayer.SetKillTimer(PlayerControl.GameOptions.KillCooldown); | ||
} | ||
|
||
private void ConvertButton_OnUpdate(object sender, EventArgs e) | ||
{ | ||
ConvertButton.CooldownDuration = PlayerControl.GameOptions.KillCooldown; | ||
|
||
ConvertButton.Clickable = DestroyableSingleton<HudManager>.Instance?.KillButton?.CurrentTarget != null; | ||
|
||
ConvertButton.Visible = !PlayerControl.LocalPlayer.Data.IsDead && PlayerControl.LocalPlayer.Data.IsImpostor && ImpostorConversions.GetValue() > Conversions; | ||
} | ||
|
||
public static void UpdateImpostors(byte newImpostor) | ||
{ | ||
List<byte> impostors = PlayerControl.AllPlayerControls.ToArray().Where(p => p && p.Data?.IsImpostor == true).Select(p => p.PlayerId).ToList(); | ||
|
||
impostors.Add(newImpostor); | ||
|
||
for (int i = 0; i < impostors.Count; i++) GameData.Instance.GetPlayerById(impostors[i]).IsImpostor = true; | ||
|
||
if (PlayerControl.LocalPlayer && PlayerControl.LocalPlayer.Data?.IsImpostor == true) | ||
{ | ||
if (PlayerControl.LocalPlayer.PlayerId == newImpostor) // Current player is new impostor, set kill button on cooldown | ||
{ | ||
DestroyableSingleton<HudManager>.Instance.KillButton.gameObject.SetActive(true); | ||
PlayerControl.LocalPlayer.SetKillTimer(PlayerControl.GameOptions.KillCooldown); | ||
|
||
ConvertButton.ApplyCooldown(); | ||
} | ||
|
||
for (int j = 0; j < impostors.Count; j++) // Display other impostors | ||
{ | ||
GameData.PlayerInfo playerById = GameData.Instance.GetPlayerById(impostors[j]); | ||
#if S20201209 || S20210305 || S202103313 | ||
if (playerById != null) playerById.Object.nameText.Color = Palette.ImpostorRed; | ||
#else | ||
if (playerById != null) playerById.Object.nameText.color = Palette.ImpostorRed; | ||
#endif | ||
} | ||
} | ||
|
||
if (AmongUsClient.Instance.AmHost) // TODO: Delay game end? New impostor doesn't always appear if the game ends by impostor count from convert by host. | ||
{ | ||
MessageWriter messageWriter = AmongUsClient.Instance.StartRpc(PlayerControl.LocalPlayer.NetId, (byte)RpcCalls.SetInfected, SendOption.Reliable); | ||
messageWriter.WriteBytesAndSize(impostors.ToArray()); | ||
messageWriter.EndMessage(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"profiles": { | ||
"2020.12.9s": { | ||
"commandName": "Executable", | ||
"executablePath": "%AmongUsMods%\\2020.12.9s\\Among Us.exe" | ||
}, | ||
"2021.3.5s": { | ||
"commandName": "Executable", | ||
"executablePath": "%AmongUsMods%\\2021.3.5s\\Among Us.exe" | ||
}, | ||
"2021.3.31.3s": { | ||
"commandName": "Executable", | ||
"executablePath": "%AmongUsMods%\\2021.3.31.3s\\Among Us.exe" | ||
}, | ||
"2021.4.12s": { | ||
"commandName": "Executable", | ||
"executablePath": "%AmongUsMods%\\2021.4.12s\\Among Us.exe" | ||
}, | ||
"2021.5.10s": { | ||
"commandName": "Executable", | ||
"executablePath": "%AmongUsMods%\\2021.5.10s\\Among Us.exe" | ||
}, | ||
"2021.6.15s": { | ||
"commandName": "Executable", | ||
"executablePath": "%AmongUsMods%\\2021.6.15s\\Among Us.exe" | ||
}, | ||
"2021.6.30s": { | ||
"commandName": "Executable", | ||
"executablePath": "%AmongUsMods%\\2021.6.30s\\Among Us.exe" | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.