This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mod.cs
99 lines (84 loc) · 2.82 KB
/
Mod.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
88
89
90
91
92
93
94
95
96
97
98
99
using AlexejheroYTB.Common;
using Harmony;
using SMLHelper.V2.Handlers;
using SMLHelper.V2.Options;
using System;
using System.Reflection;
using UnityEngine;
using Logger = AlexejheroYTB.Common.Logger;
namespace AlexejheroYTB.ConfigurableDrillableCount
{
public static class QMod
{
public static void Patch()
{
HarmonyHelper.Patch();
Logger.Log($"Patched successfully!");
CDC_Config.Min = PlayerPrefs.GetInt("cdcMin", 1);
CDC_Config.Max = PlayerPrefs.GetInt("cdcMax", 3);
Logger.Log("Obtained min/max values from config");
OptionsPanelHandler.RegisterModOptions(new Options("Configurable Drillable Count"));
Logger.Log("Registered mod options");
}
}
public static class Patches
{
[HarmonyPatch(typeof(Drillable), "Start")]
public static class Drillable_Start
{
[HarmonyPostfix]
public static void Postfix(Drillable __instance)
{
CDC_Config cdc = __instance.gameObject.AddComponent<CDC_Config>();
Logger.Log("Added component to Drillable!");
}
}
}
public class CDC_Config : MonoBehaviour
{
public static int Min = 1;
public static int Max = 3;
public void Start()
{
UpdateNumbers();
}
public void UpdateNumbers()
{
Drillable drillable = gameObject.EnsureComponent<Drillable>();
drillable.minResourcesToSpawn = Min;
drillable.maxResourcesToSpawn = Max;
}
}
public class Options : ModOptions
{
public Options(string name) : base(name)
{
SliderChanged += OnSliderChanged;
}
public override void BuildModOptions()
{
AddSliderOption("cdcMin", "Minimum", 0, 10, CDC_Config.Min);
AddSliderOption("cdcMax", "Maximum", 0, 10, CDC_Config.Max);
}
public void OnSliderChanged(object sender, SliderChangedEventArgs e)
{
int val = (int)Math.Round(e.Value, 0);
if (e.Id == "cdcMin")
{
Logger.Log($"Minimum value updated from {CDC_Config.Min} to {val}");
CDC_Config.Min = val;
PlayerPrefs.SetInt("cdcMin", val);
PlayerPrefs.Save();
}
else if (e.Id == "cdcMax")
{
Logger.Log($"Maximum value updated from {CDC_Config.Max} to {val}");
CDC_Config.Max = val;
PlayerPrefs.SetInt("cdcMax", val);
PlayerPrefs.Save();
}
UnityEngine.Object.FindObjectsOfType<CDC_Config>().Do(cdc => cdc.UpdateNumbers());
Logger.Log("Updated Drillable components for all objects");
}
}
}