Skip to content

Instantly share code, notes, and snippets.

@crbednarz
Last active Jun 26, 2020
Embed
What would you like to do?
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