Skip to content

Instantly share code, notes, and snippets.

@apollyon600
Last active March 24, 2024 12:33
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apollyon600/17521f0978d164bdeb3902afabaf89cd to your computer and use it in GitHub Desktop.
Save apollyon600/17521f0978d164bdeb3902afabaf89cd to your computer and use it in GitHub Desktop.
This is a quick tutorial using Harmony, you can come here after you've created your first mod in https://docs.reactor.gg/

Welcome to Apollo's Little Guide on how to start modding! And no I don't plan to make a video on this.

This is a tutorial after 5 days of modding, I may get some terms wrong

Yes, if you are determined you can understand a lot instead of asking for a spoonfeed

Let's get started! Head on to https://docs.reactor.gg and follow the documentation, come back here after you've got your first mod created!

Before getting into modding

Before getting into modding, it is recommended to know the necessary Classes when modding

You will most likely use these always when creating mods for youself or other clients.

  • VersionShower.Start - Shows Versions in the Start Menu
  • PingTracker.Update - Shows the Ping at the top right while in game (Good for advertising or whatever)
  • BanPatch.AmBanned - Prevents bans
  • PlayerControl.HandleRpc - Handles custom RPCs that has been sent through a code
  • IntroCutScene.MoveNext - Handles the "Crewmates" or "Impostor" intro.
  • PlayerControl.RpcSetInfected - Handles the role giving before the game starts
  • HudManager.Update - This is used to update the meeting and players name

These are the important classes you want to know, some of them contains methods youll use A LOT.

  • PlayerControl - The main source for nearly everything through the player.
  • ShipStatus - Controls the starting and ending of the game

RPC = Remote Procedure Call

RPC allows you to send a message with data across the network to tell other players to do something. Look at the Reactor.Example inside of Reactor Repo for an example on how to use RPC

For a list of classes, you can use dnSpy along with inspecting Assembly-CSharp-2020.12.9s.dll in #resources

Creating your REAL first mod

After you've created your first mod, you can now head to your TemplatePlugin.cs

Replace everything in that class into:

using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
using HarmonyLib;
using Reactor;

namespace Example
{
    [BepInPlugin(Id)]
    [BepInProcess("Among Us.exe")]
    [BepInDependency(ReactorPlugin.Id)]
    public class ExamplePlugin : BasePlugin
    {
        public const string Id = "gg.reactor.Example";

        public Harmony Harmony { get; } = new Harmony(Id);

        public override void Load()
        {
            Harmony.PatchAll();
        }
    }
}

Now create a patches directory/folder and create a class named PingTrackerPatch.cs

Input the following code below, I'd advise you learn everything I've commented inside it otherwise you're just a poor child who just wants to be successful by doing nothing.

Change ExampleProject to whatever you named your project!

using HarmonyLib;

namespace ExampleProject
{
  [HarmonyPatch(typeof(PingTracker), nameof(PingTracker.Update))]
  public class PingTrackerPatch {
    public static void Postfix(PingTracker __instance) {
      __instance.text.Text += "Mod by YOURNAME";
    }
  }
}

Now for an in-depth analysis of what you need to understand and what is happening

using HarmonyLib; // Call HarmonyLib to use HarmonyPatch

namespace ExampleProject
{
  // Make sure you patch at the top of the class otherwise it wont work.
  // typeof(Class) delcares what class youll be detecting
  // nameof(Class.Method) determines what method you want to detect when it is executed
  [HarmonyPatch(typeof(Class), nameof(Class.SpecificMethodToDetect))]
  // Name can be anything, just make sure it has Patch at the end for better practice.
  // Also optional, you can create a patch directory
  public class ClassPatch {

    // Prefix runs the code before it sends the method
    public static bool Prefix(Class __instance) {
      // Do something with the Class you declared
      return true;
    }

    // Postfix runs the code the moment the class starts
    public static void Postfix(Class __instance) {
      // Do something with the class you delcared
    }
  }
}

Debugging

Before testing the mod, I would recommend to turn on logs so you can debug any errors.

Head to the path: C:\Program Files (x86)\Steam\steamapps\common\Among Us\BepInEx\config or wherever bepinex is located in

Click BepInEx.cfg and change Enabled = true in the [Logging.Console] header

Being a lazy ass

If you want to run 4 instances of Among Us without clicking the exe file 8 times, you can download this .bat file and place it inside:

C:\Program Files (x86)\Steam\steamapps\common\Among Us

now run the bat file once you're done!

Download the .bat file https://cdn.discordapp.com/attachments/790517195003527189/816540451062153226/AUTester.bat

If you want a Part 2 on how to create custom buttons let's get to 30 stars in this gist!

@apollyon600
Copy link
Author

Yep, that's the best I can do without going into something too advanced, lmk if there's any incorrect terms and I will correct them.
If you want to add on to the tutorial, lmk on discord too Apollo#6000

@apollyon600
Copy link
Author

If you want to learn more about altering other classes, you can head on to the Reactor discord and look at source codes in #showcase

@Netika503
Copy link

you should've done faster so that i don't have to waste my time reading the docs :c

@Will0wYT
Copy link

Will0wYT commented Apr 21, 2022

Hey @apollyon600 , i seem to have an issue wit this one line of code: [BepInDependency(ReactorPlugin.Id)]
It the variable 'Id)]' seems to be underlined red and im not sure why that is?

Some help would be great!!

@GameTechGuides
Copy link

GameTechGuides commented Mar 24, 2024

this is outated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment