Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Reflection.Emit;
- using Enki;
- using Harmony12;
- public class HorizonEnki : Mod {
- private static readonly String name = "Horizon";
- public static bool enabled;
- // Fields used to modify the dynamic of the modification
- public static int gridLimit = 400;
- public static int maxTrees = 60000;
- public static int w;
- public override void BeforeLoad()
- {
- /*
- var harmony = HarmonyInstance.Create(name);
- harmony.PatchAll(Assembly.GetExecutingAssembly());
- */
- Console.WriteLine("Horizon");
- Console.WriteLine("Horizon");
- Console.WriteLine("Horizon");
- Console.WriteLine("Horizon");
- }
- }
- /* Below this point are the Harmony methods, which patch
- * certain code before or after the exectuion of certain methods.
- * Some override existing code.
- */
- // WorldGenerationPatch gets executed before World.Setup()
- [HarmonyPatch(typeof(World))]
- [HarmonyPatch("Setup")]
- static class WorldGenerationPatch
- {
- private static int maxGrid = HorizonEnki.gridLimit;
- private static int momentaryGrid;
- static bool Prefix(World __instance, ref int width, ref int height)
- {
- width = maxGrid;
- height = width;
- momentaryGrid = width;
- HorizonEnki.w = width;
- return true;
- }
- public static int MaxGrid
- {
- get { return WorldGenerationPatch.maxGrid; }
- }
- public static int MomentaryGrid
- {
- get { return WorldGenerationPatch.momentaryGrid; }
- }
- }
- //MapGenerationPatch
- [HarmonyPatch(typeof(MapGenTest))]
- [HarmonyPatch("Init")]
- static class MapGenerationPatch
- {
- private static int maxWorldSize = WorldGenerationPatch.MaxGrid;
- private static int actualWorldSize = WorldGenerationPatch.MomentaryGrid;
- private static int treeAimToSpawn;
- static bool Prefix(MapGenTest __instance, ref int w, ref int h,
- ref int desiredTiles, ref int islandCount)
- {
- treeAimToSpawn = HorizonEnki.maxTrees;
- desiredTiles = (w * h / 2) - 1;
- TreeGrowth.inst.MaxTreesOnMap = treeAimToSpawn;
- return true;
- }
- }
- /*
- [HarmonyPatch(typeof(TreeGrowth))]
- [HarmonyPatch("TryInit")]
- static class TreeGenerationPatch
- {
- private static UnityModManager.ModEntry mod = Main.mod;
- static bool Prefix(TreeGrowth __instance, ref int number)
- {
- Type type = AccessTools.TypeByName("treeData");
- FieldInfo field = AccessTools.Field(type, "treeData");
- mod.Logger.Log(field.ToString());
- return true;
- }
- }
- */
- [HarmonyPatch(typeof(TreeSystem))]
- [HarmonyPatch("TryInit")]
- public static class TreeGenerationPatch
- {
- private static int treeLimit = (HorizonEnki.maxTrees / 1000);
- static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
- {
- var codes = new List<CodeInstruction>(instructions);
- for (int i = 0; i < codes.Count; i++)
- {
- if (codes[i].opcode == OpCodes.Ldc_I4_5)
- codes[i] = new CodeInstruction(OpCodes.Ldc_I4_S, treeLimit);
- else
- // TODO Insert implementation later
- codes[i].opcode = codes[i].opcode;
- }
- return codes.AsEnumerable();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement