Skip to content

Commit

Permalink
0.2.0-dev13:
Browse files Browse the repository at this point in the history
- 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
DorCoMaNdO committed Jul 8, 2021
1 parent 22a8940 commit 7941a0b
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 23 deletions.
4 changes: 4 additions & 0 deletions AmongUs.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<GameVersion>2021.6.15s</GameVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='S20210630'">
<GameVersion>2021.6.30s</GameVersion>
</PropertyGroup>

<PropertyGroup Condition="$(Mappings) == ''">
<DefineConstants>$(DefineConstants);UNOBFUSCATED</DefineConstants>
</PropertyGroup>
Expand Down
24 changes: 24 additions & 0 deletions Convert/Convert.csproj
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>
56 changes: 56 additions & 0 deletions Convert/ConvertPlugin.Patches.cs
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();
}
}
}
52 changes: 52 additions & 0 deletions Convert/ConvertPlugin.Rpc.cs
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);
}
}
}
}
112 changes: 112 additions & 0 deletions Convert/ConvertPlugin.cs
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();
}
}
}
}
32 changes: 32 additions & 0 deletions Convert/Properties/launchSettings.json
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"
}
}
}
Binary file added Convert/Resources/Button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions Essentials.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Convert", "Convert\Convert.csproj", "{13629A8B-E7DB-4E60-B248-CE83A31DD61D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
S20201209|Any CPU = S20201209|Any CPU
Expand All @@ -18,6 +20,7 @@ Global
S20210412|Any CPU = S20210412|Any CPU
S20210510|Any CPU = S20210510|Any CPU
S20210615|Any CPU = S20210615|Any CPU
S20210630|Any CPU = S20210630|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A33582B2-0882-445B-A972-12DBF7AF1D18}.S20201209|Any CPU.ActiveCfg = S20201209|Any CPU
Expand All @@ -32,6 +35,22 @@ Global
{A33582B2-0882-445B-A972-12DBF7AF1D18}.S20210510|Any CPU.Build.0 = S20210510|Any CPU
{A33582B2-0882-445B-A972-12DBF7AF1D18}.S20210615|Any CPU.ActiveCfg = S20210615|Any CPU
{A33582B2-0882-445B-A972-12DBF7AF1D18}.S20210615|Any CPU.Build.0 = S20210615|Any CPU
{A33582B2-0882-445B-A972-12DBF7AF1D18}.S20210630|Any CPU.ActiveCfg = S20210630|Any CPU
{A33582B2-0882-445B-A972-12DBF7AF1D18}.S20210630|Any CPU.Build.0 = S20210630|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20201209|Any CPU.ActiveCfg = S20201209|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20201209|Any CPU.Build.0 = S20201209|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210305|Any CPU.ActiveCfg = S20210305|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210305|Any CPU.Build.0 = S20210305|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S202103313|Any CPU.ActiveCfg = S202103313|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S202103313|Any CPU.Build.0 = S202103313|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210412|Any CPU.ActiveCfg = S20210412|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210412|Any CPU.Build.0 = S20210412|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210510|Any CPU.ActiveCfg = S20210510|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210510|Any CPU.Build.0 = S20210510|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210615|Any CPU.ActiveCfg = S20210615|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210615|Any CPU.Build.0 = S20210615|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210630|Any CPU.ActiveCfg = S20210630|Any CPU
{13629A8B-E7DB-4E60-B248-CE83A31DD61D}.S20210630|Any CPU.Build.0 = S20210630|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions Essentials/Essentials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>0.2.0-dev12</Version>
<Version>0.2.0-dev13</Version>

<Description>Among Us modding essentials</Description>
<Authors>CoMaNdO</Authors>
<Configurations>S20201209;S20210305;S202103313;S20210412;S20210510;S20210615</Configurations>
<Configurations>S20201209;S20210305;S202103313;S20210412;S20210510;S20210615;S20210630</Configurations>

<Optimize>false</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
2 changes: 1 addition & 1 deletion Essentials/EssentialsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void Load()
{
Harmony.PatchAll();

#if !S20210615
#if !S20210615 && !S20210630
PluginSingleton<EssentialsPlugin>.Instance = this;

RegisterInIl2CppAttribute.Register();
Expand Down
Loading

0 comments on commit 7941a0b

Please sign in to comment.