-
Notifications
You must be signed in to change notification settings - Fork 1
/
FastAbsorption.cs
87 lines (73 loc) · 3.32 KB
/
FastAbsorption.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace FastAbsorption
{
[BepInPlugin("com.brokenmass.plugin.DSP.FastAbsorption", "FastAbsorption", "1.0.0")]
public class FastAbsorption : BaseUnityPlugin
{
Harmony harmony;
public static ConfigEntry<int> frequencyMultiplier;
public static ConfigEntry<int> travelSpeedMultiplier;
void Start()
{
frequencyMultiplier = Config.Bind<int>("General", "frequencyMultiplier", 10, "How much more frequently should sail be requested by every DysonSphere node [Value must be between 1 (no effect - one sail every 2 seconds) and 120 (one sail every frame)]");
travelSpeedMultiplier = Config.Bind<int>("General", "travelSpeedMultiplier", 1, "How much faster do sails take to travel to the requesting node. Values greater than 1 make the sail teleport to the proximity of the target node. [Value must be between 1 (no effect - 2minutes travel time) and 120 (2 second travel time)]");
frequencyMultiplier.Value = Math.Min(Math.Max(frequencyMultiplier.Value, 1), 120); // clamping value between 1 and 120
travelSpeedMultiplier.Value = Math.Min(Math.Max(travelSpeedMultiplier.Value, 1), 120); // clamping value between 1 and 120
harmony = new Harmony("com.brokenmass.plugin.DSP.FastAbsorption");
try
{
harmony.PatchAll(typeof(DysonSphereLayer_GameTick_Patch));
harmony.PatchAll(typeof(DysonSwarm_AbsorbSail_Patch));
Debug.Log($"[FastAbsorption Mod] frequencyMultiplier : {frequencyMultiplier.Value}x | travelSpeedMultiplier : {travelSpeedMultiplier.Value}x ");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
internal void OnDestroy()
{
// For ScriptEngine hot-reloading
harmony.UnpatchSelf();
}
[HarmonyPatch(typeof(DysonSphereLayer), "GameTick")]
public static class DysonSphereLayer_GameTick_Patch
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var code = new List<CodeInstruction>(instructions);
for (int i = 0; i < code.Count; i++)
{
if (code[i].LoadsConstant(120L))
{
code[i].operand = (int)(120 / frequencyMultiplier.Value);
}
}
return code.AsEnumerable();
}
}
[HarmonyPatch(typeof(DysonSwarm), "AbsorbSail")]
public static class DysonSwarm_AbsorbSail_Patch
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var code = new List<CodeInstruction>(instructions);
for (int i = 0; i < code.Count; i++)
{
if (code[i].LoadsConstant(14400L))
{
code[i].operand = (int)(14400L / travelSpeedMultiplier.Value);
break;
}
}
return code.AsEnumerable();
}
}
}
}