Skip to content

Instantly share code, notes, and snippets.

@crbednarz
Last active June 26, 2020 03:03
Show Gist options
  • Save crbednarz/33d5dc1ca782227ccc733e2b0f223efb to your computer and use it in GitHub Desktop.
Save crbednarz/33d5dc1ca782227ccc733e2b0f223efb to your computer and use it in GitHub Desktop.
Program.cs for Terraria Light Mod
using System;
using System.Reflection;
using Terraria;
using ReLogic.Peripherals.RGB;
using Terraria.Initializers;
namespace TerrariaLeds
{
class Program
{
private static MyRgbDevice device = new MyRgbDevice();
private static void RegisterOurDevice()
{
var engine = (ChromaEngine)typeof(ChromaInitializer).GetField("_engine", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
engine.AddDeviceGroup("LedStrip", new VirtualRgbDeviceGroup(device));
engine.EnableDeviceGroup("LedStrip");
}
public static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyLoad += (sender, sargs) =>
{
if (sargs.LoadedAssembly.GetName().Name == "Newtonsoft.Json")
Terraria.Main.OnEngineLoad += RegisterOurDevice;
};
// Invoke Terraria's Main for Windows-based systems.
typeof(WindowsLaunch).GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { args });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment