Created
September 9, 2018 13:59
-
-
Save juntalis/a6fdd5d2abab1042601210a071cafc5e to your computer and use it in GitHub Desktop.
Patched for B19
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 MapReroll.Patches; | |
using MapReroll.UI; | |
using RimWorld; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Runtime.CompilerServices; | |
using UnityEngine; | |
using Verse; | |
namespace MapReroll.Compat | |
{ | |
public class Compat_ConfigurableMaps | |
{ | |
private delegate TerrainDef RFRBeachMakerBeachTerrainAt(IntVec3 c, Map map, BiomeDef biome); | |
[CompilerGenerated] | |
[Serializable] | |
private sealed class <>c | |
{ | |
public static readonly Compat_ConfigurableMaps.<>c <>9 = new Compat_ConfigurableMaps.<>c(); | |
public static Func<Mod, bool> <>9__4_0; | |
internal bool <ExtraMapPreviewsDialogOnGUI>b__4_0(Mod m) | |
{ | |
return m.GetType().FullName == "ConfigurableMaps.Settings.TerrainSettingsController"; | |
} | |
} | |
private static Compat_ConfigurableMaps.RFRBeachMakerBeachTerrainAt BeachMakerBeachTerrainAt; | |
public static void Apply(HarmonyInstance harmonyInst) | |
{ | |
try | |
{ | |
Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly("ConfigurableMaps.Maker.CMGenStep_Terrain"); | |
bool flag = typeInAnyAssembly == null; | |
if (!flag) | |
{ | |
ReflectionCache.BeachMakerType = ReflectionCache.ReflectType("ConfigurableMaps.Maker.CMBeachMaker", typeInAnyAssembly.Assembly); | |
bool flag2 = ReflectionCache.BeachMakerType != null; | |
if (flag2) | |
{ | |
ReflectionCache.BeachMaker_Init = ReflectionCache.ReflectMethod("Init", ReflectionCache.BeachMakerType, typeof(void), new Type[] | |
{ | |
typeof(Map) | |
}); | |
ReflectionCache.BeachMaker_Cleanup = ReflectionCache.ReflectMethod("Cleanup", ReflectionCache.BeachMakerType, typeof(void), new Type[0]); | |
MethodInfo method = ReflectionCache.ReflectMethod("BeachTerrainAt", ReflectionCache.BeachMakerType, typeof(TerrainDef), new Type[] | |
{ | |
typeof(IntVec3), | |
typeof(Map), | |
typeof(BiomeDef) | |
}); | |
Compat_ConfigurableMaps.BeachMakerBeachTerrainAt = (Compat_ConfigurableMaps.RFRBeachMakerBeachTerrainAt)Delegate.CreateDelegate(typeof(Compat_ConfigurableMaps.RFRBeachMakerBeachTerrainAt), null, method); | |
bool flag3 = Compat_ConfigurableMaps.BeachMakerBeachTerrainAt == null; | |
if (flag3) | |
{ | |
throw new Exception("Failed to create BeachTerrainAt delegate"); | |
} | |
} | |
ReflectionCache.RiverMakerType = ReflectionCache.ReflectType("ConfigurableMaps.Maker.CMRiverMaker", null); | |
bool flag4 = ReflectionCache.RiverMakerType != null; | |
if (flag4) | |
{ | |
ReflectionCache.GenStepTerrain_GenerateRiver = ReflectionCache.ReflectMethod("GenerateRiver", typeInAnyAssembly, ReflectionCache.RiverMakerType, new Type[] | |
{ | |
typeof(Map) | |
}); | |
ReflectionCache.RiverMaker_TerrainAt = ReflectionCache.ReflectMethod("TerrainAt", ReflectionCache.RiverMakerType, typeof(TerrainDef), new Type[] | |
{ | |
typeof(IntVec3), | |
typeof(bool) | |
}); | |
} | |
MapPreviewGenerator.AlternateBeachTerrainAtDelegate = new MapPreviewGenerator.BeachMakerBeachTerrainAt(Compat_ConfigurableMaps.AlternateBeachTerrainAt); | |
Dialog_MapPreviews.DialogOnGUI -= new Action<Dialog_MapPreviews, Rect>(Compat_ConfigurableMaps.ExtraMapPreviewsDialogOnGUI); | |
Dialog_MapPreviews.DialogOnGUI += new Action<Dialog_MapPreviews, Rect>(Compat_ConfigurableMaps.ExtraMapPreviewsDialogOnGUI); | |
MethodInfo methodInfo = AccessTools.Method(GenTypes.GetTypeInAnyAssembly("ConfigurableMaps.Maker.CMBeachMaker"), "Init", null, null); | |
bool flag5 = methodInfo == null; | |
if (flag5) | |
{ | |
throw new Exception("Failed to reflect ConfigurableMaps.Maker.CMBeachMaker.Init"); | |
} | |
MethodInfo method2 = new Action<Map>(DeterministicGenerationPatcher.DeterministicBeachSetup).Method; | |
DeterministicGenerationPatcher.InstrumentMethodForDeterministicGeneration(methodInfo, method2, harmonyInst); | |
MethodInfo methodInfo2 = AccessTools.Method(typeInAnyAssembly, "GenerateRiver", new Type[] | |
{ | |
typeof(Map) | |
}, null); | |
bool flag6 = methodInfo2 == null; | |
if (flag6) | |
{ | |
throw new Exception("Failed to reflect ConfigurableMaps.Maker.CMGenStep_Terrain.GenerateRiver"); | |
} | |
method2 = new Action<Map>(DeterministicGenerationPatcher.DeterministicRiverSetup).Method; | |
DeterministicGenerationPatcher.InstrumentMethodForDeterministicGeneration(methodInfo2, method2, harmonyInst); | |
MapRerollController.Instance.Logger.Message("Applied Configurable Maps compatibility layer", new object[0]); | |
} | |
} | |
catch (Exception arg) | |
{ | |
MapRerollController.Instance.Logger.Error("Failed to apply compatibility layer for Configurable Maps:" + arg, new object[0]); | |
} | |
} | |
private static TerrainDef AlternateBeachTerrainAt(IntVec3 c, BiomeDef biome) | |
{ | |
return Compat_ConfigurableMaps.BeachMakerBeachTerrainAt(c, null, biome); | |
} | |
private static void ExtraMapPreviewsDialogOnGUI(Dialog_MapPreviews previewsDialog, Rect inRect) | |
{ | |
Vector2 vector = new Vector2(120f, 40f); | |
Vector2 vector2 = new Vector2(140f, 40f); | |
float num = 10f; | |
bool flag = Widgets.ButtonText(new Rect(inRect.width - vector.x - num - vector2.x, inRect.yMax - vector2.y, vector2.x, vector2.y), "Reroll2_previews_configureMap".Translate(), true, false, true); | |
if (flag) | |
{ | |
IEnumerable<Mod> arg_9A_0 = LoadedModManager.ModHandles; | |
Func<Mod, bool> arg_9A_1; | |
if ((arg_9A_1 = Compat_ConfigurableMaps.<>c.<>9__4_0) == null) | |
{ | |
arg_9A_1 = (Compat_ConfigurableMaps.<>c.<>9__4_0 = new Func<Mod, bool>(Compat_ConfigurableMaps.<>c.<>9.<ExtraMapPreviewsDialogOnGUI>b__4_0)); | |
} | |
Mod mod = arg_9A_0.FirstOrDefault(arg_9A_1); | |
bool flag2 = mod != null; | |
if (flag2) | |
{ | |
previewsDialog.Close(true); | |
Dialog_ModSettings dialog_ModSettings = new Dialog_ModSettings(); | |
ReflectionCache.DialogModSettings_SelMod.SetValue(dialog_ModSettings, mod); | |
Find.WindowStack.Add(dialog_ModSettings); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment