-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLight_Control.cs
266 lines (238 loc) · 10.2 KB
/
Light_Control.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
using BepInEx;
using HarmonyLib;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using UnityEngine;
using UWE;
using static ErrorMessage;
namespace Tweaks_Fixes
{
internal class Light_Control
{
public static Dictionary<TechType, float> lightIntensityStep = new Dictionary<TechType, float>();
public static Dictionary<TechType, float> lightOrigIntensity = new Dictionary<TechType, float>();
public static GameInput.Button lightButton;
public static Light[] currentLights = new Light[2];
public static void SaveLightIntensity(TechType tt, float f)
{
Main.configMain.lightIntensity[tt.ToString()] = f;
}
public static bool IsLightSaved(TechType tt)
{
return Main.configMain.lightIntensity.ContainsKey(tt.ToString());
}
public static float GetLightIntensity(TechType tt)
{
return Main.configMain.lightIntensity[tt.ToString()];
}
public static void UpdateLights()
{
//AddDebug("UpdateLights " + currentLights.Length);
if (currentLights == null || currentLights.Length == 0 || currentLights[0] == null || currentLights[0].gameObject == null || !currentLights[0].gameObject.activeInHierarchy)
return;
if (!Input.GetKey(ConfigMenu.lightButton.Value))
return;
TechType vehTT = Vehicle_patch.currentVehicleTT;
//Light[] lights = __instance.GetComponentsInChildren<Light>();
//AddDebug("lights.Length " + currentLights[0].gameObject.activeInHierarchy);
if (!lightIntensityStep.ContainsKey(vehTT))
{
AddDebug("lightIntensityStep missing " + vehTT);
return;
}
if (!lightOrigIntensity.ContainsKey(vehTT))
{
AddDebug("lightOrigIntensity missing " + vehTT);
return;
}
float step = 0f;
//AddDebug("UpdateLights currentVehicleTT " + currentVehicleTT);
if (GameInput.GetButtonDown(GameInput.Button.CycleNext))
step = lightIntensityStep[vehTT];
else if (GameInput.GetButtonDown(GameInput.Button.CyclePrev))
step = -lightIntensityStep[vehTT];
if (step == 0f)
return;
foreach (Light l in currentLights)
{
if (step > 0 && l.intensity > lightOrigIntensity[vehTT])
return;
l.intensity += step;
//AddDebug("Light Intensity " + l.intensity);
SaveLightIntensity(vehTT, l.intensity);
}
}
[HarmonyPatch(typeof(Vehicle))]
public class Vehicle_patch_
{
[HarmonyPostfix]
[HarmonyPatch("EnterVehicle")]
public static void EnterVehiclePostfix(Vehicle __instance)
{
if (__instance is Exosuit) { }
else
{
Transform lightT = __instance.transform.Find("lights_parent");
if (lightT)
currentLights = lightT.GetComponentsInChildren<Light>(true);
}
}
[HarmonyPostfix]
[HarmonyPatch("OnPilotModeEnd")]
public static void OnPilotModeEndPostfix(Vehicle __instance)
{
currentLights[0] = null;
//AddDebug("Vehicle OnPilotModeEnd " + currentLights.Length);
}
}
[HarmonyPatch(typeof(QuickSlots))]
class QuickSlots_Bind_Patch
{
[HarmonyPrefix]
[HarmonyPatch("SlotNext")]
public static bool SlotNextPrefix(QuickSlots __instance)
{
//AddDebug("SlotNext");
if (Input.GetKey(ConfigMenu.lightButton.Value) || GameInput.GetButtonHeld(lightButton))
{
//AddDebug("lightButton");
Pickupable p = Inventory.main.GetHeld();
if (p == null)
return true;
Light[] lights = p.GetComponentsInChildren<Light>();
//AddDebug("lights.Length " + lights.Length);
if (lights.Length == 0 || !lights[0].gameObject.activeInHierarchy)
return true;
TechType tt = CraftData.GetTechType(p.gameObject);
//AddDebug("lights TechType " + tt);
if (tt == TechType.DiveReel || tt == TechType.LaserCutter)
return true;
if (!lightIntensityStep.ContainsKey(tt))
{
AddDebug("lightIntensityStep missing " + tt);
return false;
}
if (!lightOrigIntensity.ContainsKey(tt))
{
AddDebug("lightOrigIntensity missing " + tt);
return false;
}
float origIntensity = lightOrigIntensity[tt];
//AddDebug("origIntensity " + origIntensity);
//float step = origIntensity / 15f;
Flare flare = p.GetComponent<Flare>();
if (flare && flare.flareActivateTime == 0)
return true;
foreach (Light l in lights)
{
if (l.intensity < origIntensity)
{
l.intensity += lightIntensityStep[tt];
//AddDebug("Light Intensity Up " + l.intensity);
SaveLightIntensity(tt, l.intensity);
}
if (flare)
{
Flare_Patch.intensityChanged = true;
Flare_Patch.originalIntensity = l.intensity;
Flare_Patch.halfOrigIntensity = Flare_Patch.originalIntensity * .5f;
}
return false;
}
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("SlotPrevious")]
public static bool SlotPreviousPrefix(QuickSlots __instance)
{
if (Input.GetKey(ConfigMenu.lightButton.Value) || GameInput.GetButtonHeld(lightButton))
{
Pickupable p = Inventory.main.GetHeld();
if (p == null)
return true;
Light[] lights = p.GetComponentsInChildren<Light>();
//AddDebug("lights.Length " + lights.Length);
if (lights.Length == 0)
{
//AddDebug("lights.Length == 0 ");
return true;
}
TechType tt = CraftData.GetTechType(p.gameObject);
if (tt == TechType.DiveReel || tt == TechType.LaserCutter)
return true;
if (!lightIntensityStep.ContainsKey(tt))
{
AddDebug("lightIntensityStep missing " + tt);
return false;
}
if (!lightOrigIntensity.ContainsKey(tt))
{
AddDebug("lightOrigIntensity missing " + tt);
return false;
}
//float origIntensity = Tools_Patch.lightOrigIntensity[CraftData.GetTechType(p.gameObject)];
//float step = origIntensity / 15f;
Flare flare = p.GetComponent<Flare>();
if (flare && flare.flareActivateTime == 0)
return true;
foreach (Light l in lights)
{
l.intensity -= lightIntensityStep[tt];
//AddDebug("Light Intensity Down " + l.intensity);
//AddDebug("Light Intensity Step " + Tools_Patch.lightIntensityStep[tt]);
SaveLightIntensity(tt, l.intensity);
if (flare)
{
Flare_Patch.intensityChanged = true;
Flare_Patch.originalIntensity = l.intensity;
Flare_Patch.halfOrigIntensity = Flare_Patch.originalIntensity * .5f;
}
}
return false;
}
return true;
}
}
[HarmonyPatch(typeof(MapRoomScreen), "CycleCamera")]
class MapRoomScreen_CycleCamera_Patch
{
[HarmonyPrefix]
[HarmonyPatch("CycleCamera")]
static bool CycleCameraPrefix(MapRoomScreen __instance, int direction)
{
if (!Input.GetKey(ConfigMenu.lightButton.Value))
return true;
if (currentLights.Length == 0)
{
//AddDebug("lights.Length == 0 ");
return true;
}
if (!lightIntensityStep.ContainsKey(TechType.MapRoomCamera))
{
AddDebug("lightIntensityStep missing " + TechType.MapRoomCamera);
return false;
}
if (!lightOrigIntensity.ContainsKey(TechType.MapRoomCamera))
{
AddDebug("lightOrigIntensity missing " + TechType.MapRoomCamera);
return false;
}
float step = lightIntensityStep[TechType.MapRoomCamera];
if (direction < 0)
step = -step;
foreach (Light l in currentLights)
{
if (step > 0 && l.intensity > lightOrigIntensity[TechType.MapRoomCamera])
return false;
l.intensity += step;
//AddDebug("Light Intensity " + l.intensity);
SaveLightIntensity(TechType.MapRoomCamera, l.intensity);
}
return false;
}
}
}
}