Skip to content

Commit

Permalink
feat(option): Comms Sabotage Anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandraghon committed Mar 19, 2021
0 parents commit dd115e0
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 0 deletions.
16 changes: 16 additions & 0 deletions BetterSabotage.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterSabotage", "BetterSabotage\BetterSabotage.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
EndGlobal
91 changes: 91 additions & 0 deletions BetterSabotage/BetterSabotage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System.Collections.Generic;
using System.Reflection;
using BepInEx;
using BepInEx.IL2CPP;
using Essentials.Options;
using HarmonyLib;
using Reactor;
using Reactor.Patches;
using UnityEngine;

namespace Glaucus
{
public class Main
{
public static ModdedPalette Palette = new ModdedPalette();
public static ModdedLogic Logic = new ModdedLogic();
}

public class ModdedLogic
{
public List<ModdedPlayer> AllModdedPlayer = new List<ModdedPlayer>();
}

public class ModdedPalette
{
public Color UnknownBackColor = new Color(0.3f, 0.3f, 0.3f, 1f);
public Color UnknownBodyColor = new Color(0.4f, 0.4f, 0.4f, 1f);
}

public class ModdedPlayer
{
public PlayerControl PlayerControl { get; set; }
public uint SavedSkin { get; set; }
public uint SavedHat { get; set; }

public void SetAnonymous()
{
PlayerControl.myRend.material.SetColor("_BackColor", Main.Palette.UnknownBackColor);
PlayerControl.myRend.material.SetColor("_BodyColor", Main.Palette.UnknownBodyColor);
PlayerControl.nameText.Text = "";
PlayerControl.SetHat(0U, 0);
PlayerControl.SetSkin(0U);
if (PlayerControl.CurrentPet != null)
PlayerControl.CurrentPet.Visible = false;
}

public void RemoveAnonymous()
{
PlayerControl.nameText.Text = PlayerControl.name;
PlayerControl.SetHat(SavedHat, PlayerControl.Data.ColorId);
PlayerControl.SetSkin(SavedSkin);
PlayerControl.SetColor(PlayerControl.Data.ColorId);
if (PlayerControl.CurrentPet != null)
PlayerControl.CurrentPet.Visible = true;
}
}

public static class Extensions
{
public static ModdedPlayer getModded(this PlayerControl player)
{
return Main.Logic.AllModdedPlayer.Find(x => x.PlayerControl == player);
}
}

[BepInPlugin(Id)]
[BepInProcess("Among Us.exe")]
[BepInDependency(ReactorPlugin.Id)]
public class BetterSabotage : BasePlugin
{
public const string Id = "glaucus.pocus.BetterSabotage";

//Credit to https://github.com/DorCoMaNdO/Reactor-Essentials
public static CustomStringOption CommsSabotageAnonymous = CustomOption.AddString("Comms Sabotage Anonymous", new string[] { "Nobody", "Crewmates", "Everyone" });
public Harmony Harmony { get; } = new Harmony(Id);

public override void Load()
{
CustomOption.ShamelessPlug = false;

ReactorVersionShower.TextUpdated += (text) =>
{
int index = text.Text.LastIndexOf('\n');
text.Text = text.Text.Insert(index == -1 ? text.Text.Length - 1 : index,
"\n[FFBB66FF]" + typeof(BetterSabotage).Assembly.GetCustomAttribute<AssemblyDescriptionAttribute>().Description + " " + typeof(BetterSabotage).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion + "[] by Pandraghon");
};

Harmony.PatchAll();
}
}
}
36 changes: 36 additions & 0 deletions BetterSabotage/BetterSabotage.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>1.0.1</Version>
<Mappings>NuclearPowered/Mappings:0.2.0</Mappings>

<Description>BetterSabotage</Description>
<Authors>Pandraghon</Authors>
</PropertyGroup>

<PropertyGroup Condition="'$(GamePlatform)' == 'Steam'">
<GameVersion>2021.3.5s</GameVersion>
<DefineConstants>$(DefineConstants);STEAM</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(GamePlatform)' == 'Itch'">
<GameVersion>2020.11.17i</GameVersion>
<DefineConstants>$(DefineConstants);ITCH</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Deobfuscate Include="$(AmongUs)\BepInEx\plugins\Reactor-$(GameVersion).dll" />

<PackageReference Include="Reactor.OxygenFilter.MSBuild" Version="0.2.9" />
</ItemGroup>

<ItemGroup>
<Reference Include="Essentials, Version=0.2.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>$(AmongUs)\BepInEx\plugins\Essentials-$(GameVersion).dll</HintPath>
</Reference>
</ItemGroup>

<Target Name="Copy" AfterTargets="Reobfuscate">
<Copy SourceFiles="$(OutputPath)reobfuscated/$(AssemblyName)-$(GameVersion).dll" DestinationFolder="$(AmongUs)/BepInEx/plugins/" Condition="'$(Configuration)' == 'Debug'" />
</Target>
</Project>
15 changes: 15 additions & 0 deletions BetterSabotage/GameSettingsPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using HarmonyLib;
using UnhollowerBaseLib;
using UnityEngine;

namespace Glaucus
{
[HarmonyPatch(typeof(GameSettingMenu), nameof(GameSettingMenu.OnEnable))]
public static class GameSettingsMenuPatch
{
public static void Prefix(ref GameSettingMenu __instance)
{
__instance.HideForOnline = new Il2CppReferenceArray<Transform>(0);
}
}
}
40 changes: 40 additions & 0 deletions BetterSabotage/PlayerControlPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using HarmonyLib;

namespace Glaucus
{
[HarmonyPatch(typeof(PlayerControl))]
class PlayerControlPatch
{
[HarmonyPatch(nameof(PlayerControl.AddSystemTask))]
static void Postfix(SystemTypes IBKONFPFHAB)
{
System.Console.WriteLine("AddSystemTask");
SystemTypes system = IBKONFPFHAB;
switch (system)
{
case SystemTypes.Comms:
if (BetterSabotage.CommsSabotageAnonymous.GetValue() == 1 && !PlayerControl.LocalPlayer.Data.IsImpostor
|| BetterSabotage.CommsSabotageAnonymous.GetValue() == 2)
foreach (PlayerControl playerControl in PlayerControl.AllPlayerControls)
playerControl.getModded().SetAnonymous();
break;
}
}

[HarmonyPatch(nameof(PlayerControl.RemoveTask))]
static void Postfix(PlayerTask HHCGLKKJDLA)
{
System.Console.WriteLine("RemoveTask");
PlayerTask task = HHCGLKKJDLA;
switch (task.TaskType)
{
case TaskTypes.FixComms:
if (BetterSabotage.CommsSabotageAnonymous.GetValue() == 1 && !PlayerControl.LocalPlayer.Data.IsImpostor
|| BetterSabotage.CommsSabotageAnonymous.GetValue() == 2)
foreach (PlayerControl playerControl in PlayerControl.AllPlayerControls)
playerControl.getModded().RemoveAnonymous();
break;
}
}
}
}
19 changes: 19 additions & 0 deletions BetterSabotage/ShipStatusPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using HarmonyLib;

namespace Glaucus
{
[HarmonyPatch(typeof(ShipStatus))]
class ShipStatusPatch
{
[HarmonyPatch(nameof(ShipStatus.Start))]
static void Postfix()
{
Main.Logic.AllModdedPlayer.Clear();

foreach (PlayerControl player in PlayerControl.AllPlayerControls.ToArray())
{
Main.Logic.AllModdedPlayer.Add(new ModdedPlayer { PlayerControl = player, SavedSkin = player.Data.SkinId, SavedHat = player.Data.HatId });
}
}
}
}
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# BetterSabotage

BetterSabotage is an Among Us mod. Its purpose is to add functionality to sabotages.

For the moment, only the Steam version of the game is supported.

## Features

- **Sabotage Comms** makes everyone **anonymous**.
Everyone is gray, without skin, hat or pet.
- Options : [ `Nobody` | `Crewmates` | `Everyone` ]
- `Nobody`: disable this feature
- `Crewmates`: only Crewmates are impacted. Impostors' vision remains unchanged
- `Everyone`: even Impostors are impacted

## Extra features

- **Map Selection** and **# Impostors** options are available in Online Lobby

## Using

- https://github.com/NuclearPowered/Reactor
- https://github.com/DorCoMaNdO/Reactor-Essentials

0 comments on commit dd115e0

Please sign in to comment.