-
Notifications
You must be signed in to change notification settings - Fork 1
/
Flare_Patch.cs
181 lines (163 loc) · 7.14 KB
/
Flare_Patch.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
using HarmonyLib;
using System;
using System.Collections.Generic;
using UnityEngine;
using static ErrorMessage;
namespace Tweaks_Fixes
{
[HarmonyPatch(typeof(Flare))]
class Flare_Patch
{
public static float originalIntensity = -1f;
static float originalEnergy = -1f;
public static float halfOrigIntensity;
static float originalRange;
static float lowEnergy;
public static bool intensityChanged = false;
public static void LightFlare(Flare flare)
{
//AddDebug("LightFlare ");
//flare._isInUse = true;
flare.loopingSound.Play();
if (flare.fxControl)
{
flare.fxIsPlaying = true;
flare.fxControl.Play(0);
flare.fxControl.Play(1);
}
flare.capRenderer.enabled = false;
flare.light.enabled = true;
flare.isLightFadinfIn = true;
//flare.isThrowing = true;
flare.hasBeenThrown = true;
flare.flareActivateTime = DayNightCycle.main.timePassedAsFloat;
flare.flareActiveState = true;
flare.throwDuration = .1f;
}
public static void KillFlareLight(Flare flare)
{
//AddDebug("KillFlareLight ");
if (flare.fxIsPlaying)
{
flare.fxControl.StopAndDestroy(1, 2f);
flare.fxIsPlaying = false;
}
flare.light.enabled = false;
flare.isLightFadinfIn = false;
flare.hasBeenThrown = true;
flare.loopingSound.Stop();
flare.pickupable.isPickupable = false;
}
public static void PlayerToolAwake(PlayerTool playerTool)
{
playerTool.energyMixin = playerTool.GetComponent<EnergyMixin>();
playerTool.savedRightHandIKTarget = playerTool.rightHandIKTarget;
playerTool.savedLeftHandIKTarget = playerTool.leftHandIKTarget;
playerTool.savedIkAimRightArm = playerTool.ikAimRightArm;
playerTool.savedIkAimLeftArm = playerTool.ikAimLeftArm;
}
public static void PlayerToolOnDraw(Player p, PlayerTool playerTool)
{
playerTool.usingPlayer = p;
playerTool.SetHandIKTargetsEnabled(true);
LargeWorldEntity component = playerTool.GetComponent<LargeWorldEntity>();
if (component != null && LargeWorldStreamer.main != null && LargeWorldStreamer.main.IsReady())
LargeWorldStreamer.main.cellManager.UnregisterEntity(component);
playerTool.isDrawn = true;
playerTool.firstUseAnimationStarted = false;
if (playerTool.hasFirstUseAnimation && playerTool.pickupable)
{
TechType techType = playerTool.pickupable.GetTechType();
bool flag = Player.main.AddUsedTool(techType);
if (GameOptions.GetVrAnimationMode())
flag = false;
Player.main.playerAnimator.SetBool("using_tool_first", flag);
playerTool.firstUseAnimationStarted = flag;
}
if (playerTool.firstUseAnimationStarted && playerTool.firstUseSound)
playerTool.firstUseSound.Play();
else
{
if (playerTool.drawSound)
Utils.PlayFMODAsset(playerTool.drawSound, playerTool.transform);
}
}
[HarmonyPrefix]
[HarmonyPatch(nameof(Flare.UpdateLight))]
static bool UpdateLightPrefix(Flare __instance)
{
if (Main.flareRepairLoaded)
return true;
//if (!ConfigToEdit.flareTweaks.Value)
// return true;
if (intensityChanged)
{
//AddDebug("intensityChaned ");
__instance.light.intensity = Light_Control.GetLightIntensity(TechType.Flare);
__instance.originalIntensity = __instance.light.intensity;
//intensityChanged = false;
return false;
}
else
{
float burnTime = DayNightCycle.main.timePassedAsFloat - __instance.flareActivateTime;
if (burnTime < 0.1f)
return false;
float num2 = burnTime / __instance.flickerInterval / DayNightCycle.main._dayNightSpeed;
float num3 = __instance.originalIntensity * (0.45f + 0.55f * Mathf.PerlinNoise(num2, 0f));
float num4 = (__instance.originalrange * 0.65f + 0.35f * Mathf.Sin(num2));
if (burnTime < 0.43f)
{
float t = (burnTime * 3.0f - 0.1f);
FlashingLightHelpers.SafeIntensityChangePerFrame(__instance.light, Mathf.Lerp(0f, num3, t));
FlashingLightHelpers.SafeRangeChangePreFrame(__instance.light, Mathf.Lerp(0f, num4, t));
}
else
{
FlashingLightHelpers.SafeIntensityChangePerFrame(__instance.light, num3);
FlashingLightHelpers.SafeRangeChangePreFrame(__instance.light, num4);
}
//__instance.light.intensity = halfOrigIntensity + halfOrigIntensity * Mathf.PerlinNoise(Time.time * 6f, 0f);
//AddDebug("energyLeft " + (int)__instance.energyLeft);
//if (__instance.energyLeft < lowEnergy)
{
//float f1 = __instance.energyLeft / lowEnergy;
//AddDebug("lowEnergy " + f.ToString("0.0"));
//__instance.light.intensity = Mathf.Lerp(0f, __instance.light.intensity, f1);
//__instance.light.range = Mathf.Lerp(0f, originalRange, f1);
}
}
return false;
}
//[HarmonyPrefix]
//[HarmonyPatch(nameof(Flare.OnDraw))]
static bool OnDrawPostfix(Flare __instance, Player p)
{
//AddDebug("OnDraw originalRange " + originalRange);
//AddDebug("OnDraw originalIntensity " + originalIntensity);
if (Main.flareRepairLoaded)
return true;
//if (!ConfigToEdit.flareTweaks.Value)
// return true;
//if (!Main.flareRepairLoaded)
// intensityChanged = false;
return true;
}
[HarmonyPrefix]
[HarmonyPatch(nameof(Flare.OnRightHandDown))]
static bool OnRightHandDownPostfix(Flare __instance)
{ // fix: can throw flare in base
bool canThrow = ConfigToEdit.dropItemsAnywhere.Value || Inventory.CanDropItemHere(__instance.GetComponent<Pickupable>(), false);
//AddDebug("OnRightHandDown CanDropItemHere " + canThrow);
return canThrow;
}
[HarmonyPrefix]
[HarmonyPatch(nameof(Flare.OnToolUseAnim))]
static bool OnToolUseAnimPostfix(Flare __instance)
{ // fix: can throw flare in base
bool canThrow = ConfigToEdit.dropItemsAnywhere.Value || Inventory.CanDropItemHere(__instance.GetComponent<Pickupable>(), false);
//AddDebug("OnToolUseAnim CanDropItemHere " + canThrow);
return canThrow;
}
}
}