-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
201 lines (157 loc) · 6.55 KB
/
Plugin.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using SpinCore;
using SpinCore.UI;
using SpinCore.Utility;
using SRXDModifiers.Modifiers;
using UnityEngine;
using UnityEngine.UI;
namespace SRXDModifiers;
[BepInDependency("com.pink.spinrhythm.moddingutils", "1.0.2")]
[BepInDependency("com.pink.spinrhythm.spincore")]
[BepInDependency("SRXD.ScoreMod", BepInDependency.DependencyFlags.SoftDependency)]
[BepInPlugin("SRXD.Modifiers", "Modifiers", "1.0.0.0")]
public class Plugin : SpinPlugin {
public static Plugin Instance { get; private set; }
public new static ManualLogSource Logger { get; private set; }
public static ReadOnlyCollection<Modifier> Modifiers { get; private set; }
private static Modifier[] modifiers;
private static List<(string, Modifier[])> modifierCategories;
private static CustomTextMeshProUGUI multiplierText;
private static CustomTextMeshProUGUI submissionDisabledText;
private static bool anyModifiersEnabled;
private static bool scoreModLoaded;
protected override void Awake() {
base.Awake();
Instance = this;
Logger = base.Logger;
scoreModLoaded = Chainloader.PluginInfos.TryGetValue("SRXD.ScoreMod", out var info) && info.Metadata.Version >= Version.Parse("1.2.0.9");
if (scoreModLoaded)
Logger.LogMessage("Found ScoreMod");
else
Logger.LogMessage("ScoreMod not found");
// DO NOT REORDER THIS ARRAY
modifiers = new Modifier[] {
new SlowMode(),
new HyperSpeed(),
new UltraSpeed(),
new Hidden(),
new SurvivalMode(),
new NoFail(),
new AutoPlay()
};
modifierCategories = new List<(string, Modifier[])> {
("Accessibility:", new Modifier[] {
NoFail.Instance,
SlowMode.Instance
}),
("Challenge:", new Modifier[] {
HyperSpeed.Instance,
UltraSpeed.Instance,
Hidden.Instance,
SurvivalMode.Instance
}),
("Other:", new Modifier[] {
AutoPlay.Instance
})
};
var harmony = new Harmony("Modifiers");
harmony.PatchAll(typeof(PlaySpeedManager));
harmony.PatchAll(typeof(CompleteScreenUI));
for (int i = 0; i < modifiers.Length; i++) {
var modifier = modifiers[i];
int j = i;
harmony.PatchAll(modifier.GetType());
modifier.Enabled.Bind(value => OnModifierToggled(modifier, j, value));
}
Modifiers = new ReadOnlyCollection<Modifier>(modifiers);
if (scoreModLoaded)
ScoreModWrapper.CreateScoreModifierSet(modifiers);
}
protected override void CreateMenus() {
var root = CreateOptionsTab("Modifiers").UIRoot;
multiplierText = SpinUI.CreateText("Current Multiplier", root);
submissionDisabledText = SpinUI.CreateText("Score Submission Disabled", root);
var builder = new StringBuilder();
foreach ((string categoryName, var categoryModifiers) in modifierCategories) {
new GameObject("Empty").AddComponent<LayoutElement>().transform.SetParent(root, false);
SpinUI.CreateText(categoryName, root);
foreach (var modifier in categoryModifiers) {
builder.Clear();
builder.Append(modifier.Name);
int value = modifier.Value;
if (scoreModLoaded && value != 0) {
if (value > 0)
builder.Append(" (+");
else
builder.Append(" (-");
MultiplierToString(builder, Math.Abs(value));
builder.Append(')');
}
if (!scoreModLoaded || modifier.BlocksSubmission)
builder.Append(" (Blocks Submission)");
SpinUI.CreateToggle(builder.ToString(), root).Bind(modifier.Enabled);
}
}
UpdateMultiplierText();
}
protected override void LateInit() {
foreach (var modifier in modifiers)
modifier.LateInit();
}
private static void UpdateMultiplierText() {
if (multiplierText == null || submissionDisabledText == null)
return;
if (!scoreModLoaded) {
multiplierText.SetText("ScoreMod not found. Install ScoreMod to enable score multipliers");
submissionDisabledText.enabled = anyModifiersEnabled;
return;
}
int multiplier = ScoreModWrapper.GetOverallMultiplier();
var builder = new StringBuilder("Current Multiplier: ");
if (multiplier == 100)
builder.Append("1x");
else
MultiplierToString(builder, multiplier);
multiplierText.SetText(builder.ToString());
submissionDisabledText.enabled = ScoreModWrapper.GetAnyBlocksSubmission();
}
private static void DisableOthersInExclusivityGroup(ExclusivityGroup group, int indexToKeep) {
for (int i = 0; i < modifiers.Length; i++) {
var modifier = modifiers[i];
if (modifier.ExclusivityGroup == group && i != indexToKeep)
modifier.Enabled.Value = false;
}
}
private static void OnModifierToggled(Modifier modifier, int index, bool value) {
if (value && modifier.ExclusivityGroup > ExclusivityGroup.None)
DisableOthersInExclusivityGroup(modifier.ExclusivityGroup, index);
anyModifiersEnabled = false;
foreach (var modifier1 in modifiers) {
if (!modifier1.Enabled.Value)
continue;
anyModifiersEnabled = true;
break;
}
if (anyModifiersEnabled)
ScoreSubmissionUtility.DisableScoreSubmission(Instance);
else
ScoreSubmissionUtility.EnableScoreSubmission(Instance);
UpdateMultiplierText();
}
private static void MultiplierToString(StringBuilder builder, int multiplier) {
if (multiplier % 100 > 0) {
string multString = multiplier.ToString().PadLeft(3, '0');
builder.Append(multString.Insert(multString.Length - 2, ".").TrimEnd('0'));
}
else
builder.Append(multiplier / 100);
builder.Append('x');
}
}