forked from KSP-RO/RealismOverhaul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRainbowPloom.cs
130 lines (117 loc) · 4.27 KB
/
RainbowPloom.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
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace RealismOverhaul
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
public class RainbowPloom : MonoBehaviour
{
private const string ConfigPatches = @"
COLORMODIFIER
{
controllerName = __rainbow_rand
combinationType = REPLACE
rCurve
{
key = 0.00 0.9 0 0
key = 0.25 0.9 0 0
key = 0.45 0.0 0 0
key = 0.55 0.0 0 0
key = 0.75 0.9 0 0
key = 1.00 0.9 0 0
}
gCurve
{
key = 0.0 0.0 0 0
key = 0.1 0.0 0 0
key = 0.3 0.9 0 0
key = 0.7 0.0 0 0
key = 0.9 0.0 0 0
key = 1.0 0.0 0 0
}
bCurve
{
key = 0.0 0.0 0 0
key = 0.1 0.0 0 0
key = 0.3 0.0 0 0
key = 0.7 0.9 0 0
key = 0.9 0.0 0 0
key = 1.0 0.0 0 0
}
aCurve {}
}
CONTROLLER
{
name = __rainbow_rand
linkedTo = random
noiseType = perlin
minimum = 0
scale = 1
speed = 0.3
}";
private static ConfigNode s_modifierBase;
private static ConfigNode s_controller;
private static bool EscapeHatch => File.Exists(Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"PluginData",
"DisableRainbowPloom"));
public void Awake()
{
var patches = ConfigNode.Parse(ConfigPatches);
s_modifierBase = patches.GetNode("COLORMODIFIER");
s_controller = patches.GetNode("CONTROLLER");
}
public void ModuleManagerPostLoad()
{
if (DateTime.Now.Month == 4 && DateTime.Now.Day == 1
&& AssemblyLoader.loadedAssemblies.Any(asm => asm.name == "Waterfall")
&& !EscapeHatch)
{
StartCoroutine(Patch());
}
Destroy(this);
}
private static IEnumerator Patch()
{
var WaterfallTemplates = Type.GetType("Waterfall.WaterfallTemplates, Waterfall");
var Library = (IDictionary)WaterfallTemplates.GetField("Library").GetValue(null);
while (Library.Count == 0) yield return null;
PatchTemplates();
Library.Clear();
WaterfallTemplates.GetMethod("LoadTemplates").Invoke(null, null);
PatchEngines();
}
private static void PatchTemplates()
{
foreach (var template in GameDatabase.Instance.GetConfigNodes("EFFECTTEMPLATE"))
{
foreach (var effect in template.GetNodes("EFFECT"))
{
string transform = effect.GetNode("MODEL")?.GetNode("MATERIAL")?.GetValue("transform");
if (transform == null) continue;
var modifierStart = s_modifierBase.CreateCopy();
modifierStart.AddValue("name", "__rainbowploom_start");
modifierStart.AddValue("transformName", transform);
modifierStart.AddValue("colorName", "_StartTint");
effect.AddNode(modifierStart);
var modifierEnd = s_modifierBase.CreateCopy();
modifierEnd.AddValue("name", "__rainbowploom_end");
modifierEnd.AddValue("transformName", transform);
modifierEnd.AddValue("colorName", "_EndTint");
effect.AddNode(modifierEnd);
}
}
}
private static void PatchEngines()
{
foreach (var part in GameDatabase.Instance.GetConfigNodes("PART"))
{
foreach (var mod in part.GetNodes("MODULE", "name", "ModuleWaterfallFX"))
mod.AddNode(s_controller);
}
}
}
}