Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Reflection.Emit;
  6. using Enki;
  7. using Harmony12;
  8.  
  9.  
  10. public class HorizonEnki : Mod {
  11.  
  12.  
  13.  
  14.         private static readonly String name = "Horizon";
  15.         public static bool enabled;
  16.  
  17.         // Fields used to modify the dynamic of the modification
  18.  
  19.         public static int gridLimit = 400;
  20.         public static int maxTrees = 60000;
  21.         public static int w;
  22.  
  23.         public override void BeforeLoad()
  24.         {
  25.         /*
  26.           var harmony = HarmonyInstance.Create(name);
  27.           harmony.PatchAll(Assembly.GetExecutingAssembly());
  28.           */
  29.             Console.WriteLine("Horizon");
  30.             Console.WriteLine("Horizon");
  31.             Console.WriteLine("Horizon");
  32.             Console.WriteLine("Horizon");
  33.     }
  34.        
  35. }
  36.  
  37.  
  38.  
  39. /* Below this point are the Harmony methods, which patch
  40.     * certain code before or after the exectuion of certain methods.
  41.     * Some override existing code.
  42.     */
  43.  
  44.  
  45. // WorldGenerationPatch gets executed before World.Setup()
  46. [HarmonyPatch(typeof(World))]
  47. [HarmonyPatch("Setup")]
  48. static class WorldGenerationPatch
  49. {
  50.  
  51.     private static int maxGrid = HorizonEnki.gridLimit;
  52.     private static int momentaryGrid;
  53.     static bool Prefix(World __instance, ref int width, ref int height)
  54.     {
  55.        
  56.          width = maxGrid;
  57.          height = width;
  58.        
  59.         momentaryGrid = width;
  60.         HorizonEnki.w = width;
  61.  
  62.         return true;
  63.     }
  64.  
  65.     public static int MaxGrid
  66.     {
  67.         get { return WorldGenerationPatch.maxGrid; }
  68.     }
  69.  
  70.     public static int MomentaryGrid
  71.     {
  72.         get { return WorldGenerationPatch.momentaryGrid; }
  73.     }
  74. }
  75.  
  76. //MapGenerationPatch
  77. [HarmonyPatch(typeof(MapGenTest))]
  78. [HarmonyPatch("Init")]
  79. static class MapGenerationPatch
  80. {
  81.    
  82.     private static int maxWorldSize = WorldGenerationPatch.MaxGrid;
  83.     private static int actualWorldSize = WorldGenerationPatch.MomentaryGrid;
  84.     private static int treeAimToSpawn;
  85.  
  86.     static bool Prefix(MapGenTest __instance, ref int w, ref int h,
  87.        ref int desiredTiles, ref int islandCount)
  88.     {
  89.         treeAimToSpawn = HorizonEnki.maxTrees;
  90.  
  91.         desiredTiles = (w * h / 2) - 1;
  92.         TreeGrowth.inst.MaxTreesOnMap = treeAimToSpawn;
  93.         return true;
  94.     }
  95. }
  96.  
  97.  
  98.  
  99.  
  100. /*
  101. [HarmonyPatch(typeof(TreeGrowth))]
  102. [HarmonyPatch("TryInit")]
  103. static class TreeGenerationPatch
  104. {
  105.     private static UnityModManager.ModEntry mod = Main.mod;
  106.     static bool Prefix(TreeGrowth __instance, ref int number)
  107.     {
  108.         Type type = AccessTools.TypeByName("treeData");
  109.         FieldInfo field = AccessTools.Field(type, "treeData");
  110.         mod.Logger.Log(field.ToString());
  111.         return true;
  112.     }
  113. }
  114. */
  115.  
  116. [HarmonyPatch(typeof(TreeSystem))]
  117. [HarmonyPatch("TryInit")]
  118. public static class TreeGenerationPatch
  119. {
  120.    
  121.     private static int treeLimit = (HorizonEnki.maxTrees / 1000);
  122.     static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
  123.     {
  124.         var codes = new List<CodeInstruction>(instructions);
  125.         for (int i = 0; i < codes.Count; i++)
  126.         {
  127.             if (codes[i].opcode == OpCodes.Ldc_I4_5)
  128.                 codes[i] = new CodeInstruction(OpCodes.Ldc_I4_S, treeLimit);
  129.             else
  130.                 // TODO Insert implementation later
  131.                 codes[i].opcode = codes[i].opcode;
  132.         }
  133.         return codes.AsEnumerable();
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement