-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMelonLoaderMod.cs
153 lines (124 loc) · 4.66 KB
/
MelonLoaderMod.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using MelonLoader;
using UnityEngine;
using ModThatIsNotMod.BoneMenu;
using System.Threading;
using HarmonyLib;
using System.Reflection;
using System.Threading.Tasks;
namespace InstantDeath
{
public static class BuildInfo
{
public const string Name = "InstantDeath"; // Name of the Mod. (MUST BE SET)
public const string Author = "Fizzy"; // Author of the Mod. (Set as null if none)
public const string Company = null; // Company that made the Mod. (Set as null if none)
public const string Version = "1.0.6"; // Version of the Mod. (MUST BE SET)
public const string DownloadLink = null; // Download Link for the Mod. (Set as null if none)
}
public class InstantDeath : MelonMod
{
private static Player_Health playerHealth;
private static bool instantDeathEnabled = false;
private static float deathTimeAmount = 2;
private static bool healthOverridesEnabled = false;
private static bool healthOverridesWarningUndelivered = false;
private static MenuCategory boneMenuCategory;
private static MenuCategory healthCategory;
private static MelonPreferences_Category preferences;
private static MelonPreferences_Entry<float> maxHealthPreference;
private static MelonPreferences_Entry<float> healthRegenPreference;
private void DisplayHealthOverrideWarning()
{
if (healthOverridesEnabled != true && healthOverridesWarningUndelivered)
{
healthOverridesWarningUndelivered = false;
ModThatIsNotMod.Notifications.SendNotification("Enable the override to use these settings!", 4, Color.red);
}
}
public void UpdatePreferences()
{
preferences.SaveToFile();
MelonLogger.Msg($"instantDeathEnabled is set to {instantDeathEnabled}");
MelonLogger.Msg($"maxHealthOverride is set to {maxHealthPreference.Value}");
MelonLogger.Msg($"totalRegenDuration is set to {playerHealth.totalRegenDuration}");
}
private void UpdateSettings()
{
if (healthOverridesEnabled)
{
playerHealth.max_Health = maxHealthPreference.Value;
playerHealth.totalRegenDuration = healthRegenPreference.Value;
playerHealth.SetFullHealth();
}
if (instantDeathEnabled)
{
if (playerHealth.deathTimeAmount != 0)
{
deathTimeAmount = playerHealth.deathTimeAmount;
};
playerHealth.healthMode = Player_Health.HealthMode.Mortal;
playerHealth.deathTimeAmount = 0;
}
else
{
// Revert to default value
playerHealth.deathTimeAmount = deathTimeAmount;
}
}
public static void MaxHealthPostfix(ref float __result)
{
if (healthOverridesEnabled)
{
__result = maxHealthPreference.Value;
}
}
public override void OnApplicationStart()
{
boneMenuCategory = MenuManager.CreateCategory("Instant Death", Color.red);
preferences = MelonPreferences.CreateCategory("InstantDeath", "Instant Death");
preferences.SetFilePath("UserData/InstantDeathPreferences.cfg");
maxHealthPreference = preferences.CreateEntry<float>("MaxHealth", 10, "Max Health");
healthRegenPreference = preferences.CreateEntry<float>("HealthRegenDuration", 10, "Health Regeneration Duration");
boneMenuCategory.CreateBoolElement("Instant Death Enabled", Color.white, false, delegate (bool enabled)
{
instantDeathEnabled = enabled;
UpdateSettings();
});
healthCategory = boneMenuCategory.CreateSubCategory("Health Settings", Color.green);
healthCategory.CreateBoolElement("Enable health settings", Color.green, healthOverridesEnabled, delegate (bool enabled)
{
healthOverridesEnabled = enabled;
UpdateSettings();
});
healthCategory.CreateFloatElement("Max Health (default: 10)", Color.white, maxHealthPreference.Value, delegate (float maxHealth)
{
DisplayHealthOverrideWarning();
maxHealthPreference.Value = maxHealth;
UpdateSettings();
UpdatePreferences();
}, 1, 1, 1000, true);
healthCategory.CreateFloatElement("Regen Duration (default: 10)", Color.white, healthRegenPreference.Value, delegate (float regenDuration)
{
DisplayHealthOverrideWarning();
healthRegenPreference.Value = regenDuration;
UpdateSettings();
UpdatePreferences();
}, 1, 0, 1000, true);
boneMenuCategory.CreateFunctionElement("Suicide", Color.red, delegate ()
{
UpdateSettings();
var oldHealthMode = playerHealth.healthMode;
// Health mode needs to be set to normal, otherwise the player may take damage and live.
playerHealth.healthMode = Player_Health.HealthMode.Mortal;
playerHealth.Death();
// Revert health mode back to the old one
playerHealth.healthMode = oldHealthMode;
});
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
playerHealth = GameObject.FindObjectOfType<Player_Health>();
UpdateSettings();
}
}
}