Skip to content

Commit b2f7b4a

Browse files
committed
fixed some bugs and made the custom presets system not shit
1 parent 698c694 commit b2f7b4a

3 files changed

Lines changed: 401 additions & 65 deletions

File tree

BetterWeaponColourMenu.cs

Lines changed: 210 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using HarmonyLib;
22
using System.Collections.Generic;
3+
using System.Reflection;
34
using UMM;
45
using UnityEngine;
56
using UnityEngine.SceneManagement;
67
using UnityEngine.UI;
78

89
namespace BetterWeaponColourMenu
910
{
10-
[UKPlugin("Better Weapon Colour Menu", "1.0.0", "IDFK WHAT TO PUT HERE :)", true, true)]
11+
[UKPlugin("Better Weapon Colour Menu", "1.0.1", "A simple mod that improves the custom weapon colour system", true, true)]
1112
public class BetterWeaponColourMenu : UKMod
1213
{
1314

@@ -42,13 +43,18 @@ private void SceneManagerOnsceneLoaded(Scene scene, LoadSceneMode mode)
4243
}
4344

4445

46+
//public static int currentPresetCollectionIndex = 0;
47+
48+
4549
string[] windowNames = new string[] { "Revolver", "Shotgun", "Nailgun", "Railcannon", "RocketLauncher" };
4650

4751
public void CreateSkinGUI()
4852
{
4953
foreach (ShopGearChecker shopGearChecker in Resources.FindObjectsOfTypeAll<ShopGearChecker>())
5054
{
5155

56+
//if (!shopGearChecker.gameObject.activeInHierarchy) continue;
57+
5258
foreach(var name in windowNames)
5359
{
5460
var pannel = shopGearChecker.gameObject.transform.Find($"{name}Window");
@@ -73,6 +79,8 @@ public void CreateSkinGUI()
7379
LoadCustomColourPreset(colourScreen.Find("Standard").gameObject, name, false);
7480
LoadCustomColourPreset(colourScreen.Find("Alternate").gameObject, name, true);
7581

82+
typeof(UKAPI).Assembly.GetType("UMM.UKAPI+SaveFileHandler").GetMethod("DumpFile", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null);
83+
7684
}
7785
}
7886
}
@@ -143,15 +151,62 @@ public void DoModificationsToPage(GameObject gameObject, string type, bool alt)
143151

144152
var templates = gameObject.transform.Find("Template");
145153

146-
for(int i = 2; i <= 5; i++)
154+
Transform nextPresetRButton = Instantiate(sliders.parent.parent.parent.Find("Done"), templates);
155+
156+
nextPresetRButton.gameObject.name = "NextPresetRight";
157+
nextPresetRButton.localPosition = new Vector3(5, -185.0001f, -14.9917f);
158+
nextPresetRButton.localScale = new Vector3(0.2f, 1f, 1f);
159+
nextPresetRButton.GetComponentInChildren<Text>().text = ">";
160+
nextPresetRButton.GetComponentInChildren<Text>().transform.localScale = new Vector3(5f, 1f, 1f);
161+
162+
GameObject nRAGO = Instantiate(new GameObject(), nextPresetRButton.transform);
163+
nRAGO.SetActive(false);
164+
165+
var nextPresetRButtonController = nextPresetRButton.gameObject.AddComponent<NextPresetCollectionButton>();
166+
nextPresetRButtonController.activator = nRAGO;
167+
nextPresetRButtonController.triggerMessage = false;
168+
nextPresetRButtonController.side = NextPresetCollectionButton.Side.Right;
169+
nextPresetRButtonController.weaponType = type;
170+
nextPresetRButtonController.alt = alt;
171+
172+
nextPresetRButton.GetComponent<ShopButton>().toActivate = new GameObject[] { nRAGO };
173+
nextPresetRButton.GetComponent<ShopButton>().toDeactivate = new GameObject[0];
174+
175+
176+
Transform nextPresetLButton = Instantiate(sliders.parent.parent.parent.Find("Done"), templates);
177+
178+
nextPresetLButton.gameObject.name = "NextPresetLeft";
179+
nextPresetLButton.localPosition = new Vector3(-55, -185.0001f, -14.9917f);
180+
nextPresetLButton.localScale = new Vector3(0.2f, 1f, 1f);
181+
nextPresetLButton.GetComponentInChildren<Text>().text = "<";
182+
nextPresetLButton.GetComponentInChildren<Text>().transform.localScale = new Vector3(5f, 1f, 1f);
183+
184+
185+
GameObject nLAGO = Instantiate(new GameObject(), nextPresetLButton.transform);
186+
nLAGO.SetActive(false);
187+
188+
var nextPresetLButtonController = nextPresetLButton.gameObject.AddComponent<NextPresetCollectionButton>();
189+
nextPresetLButtonController.activator = nLAGO;
190+
nextPresetLButtonController.triggerMessage = false;
191+
nextPresetLButtonController.side = NextPresetCollectionButton.Side.Left;
192+
nextPresetLButtonController.weaponType = type;
193+
nextPresetLButtonController.alt = alt;
194+
195+
196+
nextPresetLButton.GetComponent<ShopButton>().toActivate = new GameObject[] { nLAGO };
197+
nextPresetLButton.GetComponent<ShopButton>().toDeactivate = new GameObject[0];
198+
199+
200+
for (int i = 2; i <= 5; i++)
147201
{
148202
var template = templates.Find($"Template {i}");
149203

150-
template.transform.GetChild(0).localScale = new Vector3(0.75f, 1, 1);
151-
template.transform.GetChild(0).GetChild(0).localScale = new Vector3(1.5f, 1, 1);
204+
//template.transform.GetChild(0).localScale = new Vector3(0.75f, 1, 1);
205+
//template.transform.GetChild(0).GetChild(0).localScale = new Vector3(1.5f, 1, 1);
152206

153207
Transform saveButton = Instantiate(sliders.parent.parent.parent.Find("Done"), template);
154208

209+
saveButton.gameObject.SetActive(false);
155210
saveButton.gameObject.name = "Save";
156211
saveButton.localPosition = new Vector3(225, -40, -0.0005f);
157212
saveButton.localScale = new Vector3(0.2f, 1f, 1f);
@@ -163,7 +218,7 @@ public void DoModificationsToPage(GameObject gameObject, string type, bool alt)
163218

164219
var saveButtonController = saveButton.gameObject.AddComponent<SaveButton>();
165220
saveButtonController.activator = sAGO;
166-
saveButtonController.messagePopupText = "Overrode Preset!";
221+
saveButtonController.messagePopupText = "Preset Saved!";
167222
saveButtonController.index = i - 1;
168223
saveButtonController.text = template.transform.GetChild(0).GetChild(0).GetComponent<UnityEngine.UI.Text>();
169224
saveButtonController.weaponType = type;
@@ -175,6 +230,7 @@ public void DoModificationsToPage(GameObject gameObject, string type, bool alt)
175230

176231
Transform clearButton = Instantiate(sliders.parent.parent.parent.Find("Done"), template);
177232

233+
clearButton.gameObject.SetActive(false);
178234
clearButton.gameObject.name = "Clear";
179235
clearButton.localPosition = new Vector3(285, -40, -0.0005f);
180236
clearButton.localScale = new Vector3(0.2f, 1f, 1f);
@@ -186,7 +242,7 @@ public void DoModificationsToPage(GameObject gameObject, string type, bool alt)
186242

187243
var clearButtonController = clearButton.gameObject.AddComponent<ClearButton>();
188244
clearButtonController.activator = cAGO;
189-
clearButtonController.messagePopupText = "Reset Preset!";
245+
clearButtonController.messagePopupText = "Cleared!";
190246
clearButtonController.index = i - 1;
191247
clearButtonController.text = template.transform.GetChild(0).GetChild(0).GetComponent<UnityEngine.UI.Text>();
192248
clearButtonController.weaponType = type;
@@ -219,28 +275,72 @@ public void DoModificationsToPage(GameObject gameObject, string type, bool alt)
219275

220276

221277
}
222-
278+
223279
public void LoadCustomColourPreset(GameObject gameObject, string weaponType, bool alt)
224280
{
225-
for(int i = 1; i < 5; i++)
226-
{
227-
281+
for (int i = 1; i < 5; i++)
282+
{
228283
var template = gameObject.transform.Find("Template").Find($"Template {i + 1}");
229284

230285
Color[] colours = new Color[3];
231286

287+
288+
if (UKMod.PersistentModDataExists($"customPresetOverride.{weaponType}.{i}.isCustom", GUID))
289+
{
290+
string value = UKMod.RetrieveStringPersistentModData($"customPresetOverride.{weaponType}.{i}.isCustom", GUID);
291+
292+
UKMod.SetPersistentModData($"customPresetOverride.0.{weaponType}.{i}.isCustom", value, GUID);
293+
294+
RemovePersistentModData($"customPresetOverride.{weaponType}.{i}.isCustom", GUID);
295+
296+
Debug.LogWarning($"updated save data \"{$"customPresetOverride.{weaponType}.{i}.isCustom"}\"");
297+
}
298+
299+
for (int t = 1; t <= 3; t++)
300+
{
301+
for (int c = 0; c < 3; c++)
302+
{
303+
if (UKMod.PersistentModDataExists($"customPresetOverride.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}", GUID))
304+
{
305+
string value = UKMod.RetrieveStringPersistentModData($"customPresetOverride.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}", GUID);
306+
307+
UKMod.SetPersistentModData($"customPresetOverride.0.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}", value, GUID);
308+
309+
RemovePersistentModData($"customPresetOverride.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}", GUID);
310+
311+
Debug.LogWarning($"updated save data \"{$"customPresetOverride.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}"}\"");
312+
}
313+
}
314+
}
315+
316+
317+
232318
//fucking die
233319
//if (!(EnsurePersistentModDataExists($"customPresetOverride.{weaponType}.{i}.isCustom", GUID) && UKMod.RetrieveBooleanPersistentModData($"customPresetOverride.{weaponType}.{i}.isCustom", GUID))) continue;
234-
if (!(EnsurePersistentModDataExists($"customPresetOverride.{weaponType}.{i}.isCustom", GUID) && UKMod.RetrieveBooleanPersistentModData(GUID, $"customPresetOverride.{weaponType}.{i}.isCustom"))) continue;
320+
//if (!(UKMod.PersistentModDataExists($"customPresetOverride.{currentPresetCollectionIndex}.{weaponType}.{i}.isCustom", GUID) && UKMod.RetrieveBooleanPersistentModData(GUID, $"customPresetOverride.{currentPresetCollectionIndex}.{weaponType}.{i}.isCustom"))) continue;
321+
322+
var key = $"customPresetOverride.{weaponType}{(alt ? ".a" : "")}.CurrentPresetCollectionIndex";
323+
if (!UKMod.PersistentModDataExists(key, BetterWeaponColourMenu.GUID)) UKMod.SetPersistentModData(key, "-1", BetterWeaponColourMenu.GUID);
324+
325+
var currentPresetColI = UKMod.RetrieveFloatPersistentModData(BetterWeaponColourMenu.GUID, key);
235326

236327
for (int t = 1; t <= 3; t++)
237328
{
238329
float[] rgbColourValues = new float[3];
239330

240331
for (int c = 0; c < 3; c++)
241332
{
242-
EnsurePersistentModDataExists($"customPresetOverride.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}", GUID);
243-
rgbColourValues[c] = UKMod.RetrieveFloatPersistentModData(GUID, $"customPresetOverride.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}");
333+
if (UKMod.PersistentModDataExists($"customPresetOverride.{currentPresetColI}.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}", GUID))
334+
{
335+
rgbColourValues[c] = UKMod.RetrieveFloatPersistentModData(GUID, $"customPresetOverride.{currentPresetColI}.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}");
336+
}
337+
else
338+
{
339+
rgbColourValues[c] = 0;
340+
341+
Debug.LogWarning($"could not find data \"{$"customPresetOverride.{currentPresetColI}.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}"}\"!!!!");
342+
}
343+
244344
}
245345

246346
colours[t - 1] = new Color(rgbColourValues[0], rgbColourValues[1], rgbColourValues[2]);
@@ -250,44 +350,109 @@ public void LoadCustomColourPreset(GameObject gameObject, string weaponType, boo
250350

251351
GunColorPreset newPreset = new GunColorPreset(colours[0], colours[1], colours[2]);
252352

253-
template.transform.GetChild(0).GetChild(0).GetComponent<UnityEngine.UI.Text>().text = "Custom " + i;
353+
if (currentPresetColI >= 0)
354+
{
355+
template.transform.GetChild(0).GetChild(0).GetComponent<UnityEngine.UI.Text>().text = $"Custom {(4 * currentPresetColI) + i}";
356+
357+
switch (weaponType)
358+
{
359+
case "Revolver":
360+
MonoSingleton<GunColorController>.Instance.revolverColors[i] = newPreset;
361+
break;
362+
case "Shotgun":
363+
MonoSingleton<GunColorController>.Instance.shotgunColors[i] = newPreset;
364+
break;
365+
case "Nailgun":
366+
MonoSingleton<GunColorController>.Instance.nailgunColors[i] = newPreset;
367+
break;
368+
case "Railcannon":
369+
MonoSingleton<GunColorController>.Instance.railcannonColors[i] = newPreset;
370+
break;
371+
case "RocketLauncher":
372+
MonoSingleton<GunColorController>.Instance.rocketLauncherColors[i] = newPreset;
373+
break;
374+
}
375+
}
376+
}
377+
}
378+
379+
public static Color[] GetColoursForPreset(string weaponType, int index, int collectionIndex)
380+
{
381+
Color[] colours = new Color[3];
382+
383+
for (int t = 1; t <= 3; t++)
384+
{
385+
float[] rgbColourValues = new float[3];
254386

255-
switch (weaponType)
387+
for (int c = 0; c < 3; c++)
256388
{
257-
case "Revolver":
258-
MonoSingleton<GunColorController>.Instance.revolverColors[i] = newPreset;
259-
break;
260-
case "Shotgun":
261-
MonoSingleton<GunColorController>.Instance.shotgunColors[i] = newPreset;
262-
break;
263-
case "Nailgun":
264-
MonoSingleton<GunColorController>.Instance.nailgunColors[i] = newPreset;
265-
break;
266-
case "Railcannon":
267-
MonoSingleton<GunColorController>.Instance.railcannonColors[i] = newPreset;
268-
break;
269-
case "RocketLauncher":
270-
MonoSingleton<GunColorController>.Instance.rocketLauncherColors[i] = newPreset;
271-
break;
389+
if (UKMod.PersistentModDataExists($"customPresetOverride.{collectionIndex}.{weaponType}.{index}.{t}.{rgbValueFromInt[c]}", GUID))
390+
{
391+
rgbColourValues[c] = UKMod.RetrieveFloatPersistentModData(GUID, $"customPresetOverride.{collectionIndex}.{weaponType}.{index}.{t}.{rgbValueFromInt[c]}");
392+
}
393+
else
394+
{
395+
rgbColourValues[c] = 0;
396+
397+
Debug.LogWarning($"could not find data \"{$"customPresetOverride.{collectionIndex}.{weaponType}.{index}.{t}.{rgbValueFromInt[c]}"}\"!!!!");
398+
}
399+
272400
}
401+
402+
colours[t - 1] = new Color(rgbColourValues[0], rgbColourValues[1], rgbColourValues[2]);
273403
}
404+
405+
return colours;
274406
}
275407

276-
public bool EnsurePersistentModDataExists(string key, string modName)
277-
{
278-
//Debug.LogWarning($"{key}: \"{UKMod.RetrieveStringPersistentModData(key, modName)}\"");
279-
return !string.IsNullOrEmpty(UKMod.RetrieveStringPersistentModData(key, modName));
280-
}
408+
public static GunColorPreset GetPreset(string weaponType, int index, int collectionIndex)
409+
{
410+
Color[] colours = new Color[3];
411+
412+
for (int t = 1; t <= 3; t++)
413+
{
414+
float[] rgbColourValues = new float[3];
415+
416+
for (int c = 0; c < 3; c++)
417+
{
418+
if (UKMod.PersistentModDataExists($"customPresetOverride.{collectionIndex}.{weaponType}.{index}.{t}.{rgbValueFromInt[c]}", GUID))
419+
{
420+
rgbColourValues[c] = UKMod.RetrieveFloatPersistentModData(GUID, $"customPresetOverride.{collectionIndex}.{weaponType}.{index}.{t}.{rgbValueFromInt[c]}");
421+
}
422+
else
423+
{
424+
rgbColourValues[c] = 0;
425+
426+
//Debug.LogWarning($"could not find data \"{$"customPresetOverride.{currentPresetCollectionIndex}.{weaponType}.{index}.{t}.{rgbValueFromInt[c]}"}\"!!!!");
427+
}
428+
429+
}
430+
431+
colours[t - 1] = new Color(rgbColourValues[0], rgbColourValues[1], rgbColourValues[2]);
432+
}
433+
434+
return new GunColorPreset(colours[0], colours[1], colours[2]); ;
435+
}
281436

282437
public static bool swapped;
283438

284-
Dictionary<int, string> rgbValueFromInt = new Dictionary<int, string>()
439+
public static Dictionary<int, string> rgbValueFromInt = new Dictionary<int, string>()
285440
{
286441
{ 0, "r" },
287442
{ 1, "g" },
288443
{ 2, "b" },
289444
};
290445

446+
public static Dictionary<string, int> weaponNumberFromName = new Dictionary<string, int>()
447+
{
448+
{ "Revolver", 1 },
449+
{ "Shotgun", 2 },
450+
{ "Nailgun", 3 },
451+
{ "Railcannon", 4 },
452+
{ "RocketLauncher", 5 },
453+
};
454+
455+
291456
public static Dictionary<string, GunColorPreset[]> baseWeaponPresetColours = new Dictionary<string, GunColorPreset[]>()
292457
{
293458
{ "Revolver", new GunColorPreset[] { new GunColorPreset(new Color(0, 0, 0), new Color(0, 0, 0), new Color(0.42f, 0.19f, 0)), new GunColorPreset(new Color(0, 0.6f, 1), new Color(0.4f, 0.5f, 0.54f), new Color(0.4f, 0.5f, 0.54f)), new GunColorPreset(new Color(1, 0.24f, 0), new Color(0.25f, 0.25f, 0.25f), new Color(0.25f, 0.25f, 0.25f)), new GunColorPreset(new Color(0.5f, 0f, 0f), new Color(0.25f, 0f, 0f), new Color(0.25f, 0f, 0f)) } },
@@ -297,5 +462,14 @@ public bool EnsurePersistentModDataExists(string key, string modName)
297462
{ "RocketLauncher", new GunColorPreset[] { new GunColorPreset(new Color(0.5f, 0.25f, 0.25f), new Color(1f, 0.85f, 0.6f), new Color(0.65f, 0.65f, 0.65f)), new GunColorPreset(new Color(0.66f, 0.66f, 0.66f), new Color(1f, 0f, 0.42f), new Color(0.44f, 0.44f, 0.44f)), new GunColorPreset(new Color(0.7f, 1f, 0f), new Color(0.6f, 0f, 0.4f), new Color(0.64f, 0f, 0.48f)), new GunColorPreset(new Color(0f, 0f, 0f), new Color(0.32f, 0.2f, 0.6f), new Color(0f, 0f, 0f)), } },
298463
};
299464

465+
public static Dictionary<string, string[]> baseWeaponPresetNames = new Dictionary<string, string[]>()
466+
{
467+
{ "Revolver", new string[] { "Magnum", "Icebreaker", "Hot & Ready", "Sanguine" } },
468+
{ "Shotgun", new string[] { "Classic", "Palace", "Caramel", "Luxus" } },
469+
{ "Nailgun", new string[] { "Acidic", "Clear Sky", "Snow Leopard", "Vampire" } },
470+
{ "Railcannon", new string[] { "Inverse", "Love & Liquorice", "Statue Vein", "Industrial" } },
471+
{ "RocketLauncher", new string[] { "Rustic", "Lipstick", "Eggplant", "Night Amethyst" } },
472+
};
473+
300474
}
301475
}

BetterWeaponColourMenu.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@
104104
<Reference Include="TwitchLib.Unity">
105105
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ULTRAKILL\ULTRAKILL_Data\Managed\TwitchLib.Unity.dll</HintPath>
106106
</Reference>
107-
<Reference Include="UMM">
107+
<Reference Include="UMM, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
108+
<SpecificVersion>False</SpecificVersion>
108109
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ULTRAKILL\BepInEx\plugins\UMM\UMM.dll</HintPath>
109110
</Reference>
110111
<Reference Include="Unity.Analytics.DataPrivacy">

0 commit comments

Comments
 (0)