Skip to content

Instantly share code, notes, and snippets.

@pardeike
Created April 17, 2017 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pardeike/12c457e135a42a28e068f2aba5337221 to your computer and use it in GitHub Desktop.
Save pardeike/12c457e135a42a28e068f2aba5337221 to your computer and use it in GitHub Desktop.
A basic starter for a Rimworld Mod using Harmony
using Harmony;
using System;
using System.Linq;
using System.Reflection;
using Verse;
namespace Namespace
{
[StaticConstructorOnStartup]
static class YourMod
{
static YourMod()
{
var harmony = HarmonyInstance.Create("com.whatever.is.your.modname");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
// start rimworld with -rungame "savegamename" to activate this
[HarmonyPatch(typeof(UIRoot_Entry), "Init", new Type[0])]
static class UIRoot_Entry_Init_Patch
{
static bool firstTime = true;
static void Postfix()
{
Environment.GetCommandLineArgs().Aggregate((prev, saveGameName) =>
{
if (firstTime && GenScene.InEntryScene && prev.ToLower() == "-rungame")
{
PreLoadUtility.CheckVersionAndLoad(GenFilePaths.FilePathForSavedGame(saveGameName), ScribeMetaHeaderUtility.ScribeHeaderMode.Map, () =>
{
firstTime = false;
LongEventHandler.QueueLongEvent(delegate
{
Current.Game = new Game() { InitData = new GameInitData() { gameToLoad = saveGameName } };
}, "Play", "LoadingLongEvent", true, null);
});
}
return saveGameName;
});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment