Created
April 17, 2017 13:19
-
-
Save pardeike/12c457e135a42a28e068f2aba5337221 to your computer and use it in GitHub Desktop.
A basic starter for a Rimworld Mod using Harmony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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