-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player_Patches.cs
298 lines (272 loc) · 11.8 KB
/
Player_Patches.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
using FMOD;
using FMOD.Studio;
using FMODUnity;
using HarmonyLib;
using ProtoBuf;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UWE;
using static ErrorMessage;
namespace Tweaks_Fixes
{
class Player_Patches
{
public static float exitWaterOffset = 0.8f; // 0.8f
public static float crushPeriod = 3f;
public static float healTime = 0f;
public static void DisableExosuitClawArmScan()
{
if (PDAScanner.mapping.ContainsKey(TechType.ExosuitClawArmFragment))
{
//AddDebug("DisableExosuitClawArmScan");
PDAScanner.mapping.Remove(TechType.ExosuitClawArmFragment);
}
}
[HarmonyPatch(typeof(Player))]
class Player_Patch
{
private static float crushTime = 0f;
static IEnumerator Test()
{
AddDebug("Test start ");
//Main.Log("Test start ");
while (!uGUI.main.hud.active)
yield return null;
AddDebug("Test end ");
}
//[HarmonyPrefix]
//[HarmonyPatch("MovePlayerToRespawnPoint")]
static void MovePlayerToRespawnPointPostfix(Player __instance)
{
AddDebug("MovePlayerToRespawnPoint lastValidSub " + __instance.lastValidSub);
if (__instance.lastValidSub)
{
AddDebug("MovePlayerToRespawnPoint CheckSubValid " + __instance.CheckSubValid(__instance.lastValidSub));
}
}
//[HarmonyPrefix]
//[HarmonyPatch("CheckSubValid")]
static bool CheckSubValidPrefix(Player __instance, SubRoot sub, ref bool __result)
{
//AddDebug("CheckSubValid lastValidSub " + __instance.lastValidSub);
bool valid = false;
if (sub != null)
{
bool isAlive = true;
LiveMixin liveMixin = sub.GetComponent<LiveMixin>();
if (liveMixin != null)
isAlive = liveMixin.IsAlive();
AddDebug("CheckSubValid IsAlive " + isAlive);
AddDebug("CheckSubValid GetLeakAmount " + sub.GetLeakAmount());
valid = isAlive && sub.GetLeakAmount() <= 0.2;
}
__result = valid;
return false;
}
//[HarmonyPostfix]
//[HarmonyPatch("Start")]
static void StartPostfix(Player __instance)
{
//__instance.StartCoroutine(Test());
Main.survival = __instance.GetComponent<Survival>();
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
static void UpdatePostfix(Player __instance)
{
if (!Main.gameLoaded)
return;
if (__instance.currentMountedVehicle)
Vehicle_patch.UpdateLights();
else if (__instance.currentSub && __instance.currentSub.isCyclops && __instance.isPiloting)
Vehicle_patch.UpdateLights();
//Main.Message("Depth Class " + __instance.GetDepthClass());
if (ConfigMenu.crushDamage.Value > 0f && Crush_Damage.crushInterval + crushTime < Time.time)
{
crushTime = Time.time;
Crush_Damage.CrushDamagePlayer();
}
if (Main.configMain.medKitHPtoHeal > 0 && Time.time > healTime)
//if (Main.config.medKitHPtoHeal > 0 && DayNightCycle.main.timePassedAsFloat > healTime)
{ // not checking savegame slot
healTime = Time.time + 1.0f;
//healTime = DayNightCycle.main.timePassedAsFloat + 1f;
__instance.liveMixin.AddHealth(ConfigToEdit.medKitHPperSecond.Value);
//AddDebug("AddHealth " + Main.config.medKitHPperSecond);
Main.configMain.medKitHPtoHeal -= ConfigToEdit.medKitHPperSecond.Value;
if (Main.configMain.medKitHPtoHeal < 0)
Main.configMain.medKitHPtoHeal = 0;
}
if (Main.survival == null)
Main.survival = __instance.GetComponent<Survival>();
if (!GameModeUtils.RequiresSurvival() || Main.survival.freezeStats)
return;
if (Food_Patch.hungerUpdateTime > Time.time)
return;
if (ConfigMenu.newHungerSystem.Value)
{
Food_Patch.UpdateStats(Main.survival);
//__instance.Invoke("UpdateHunger", updateHungerInterval);
//AddDebug("updateHungerInterval " + updateHungerInterval);
}
else
Main.survival.UpdateHunger();
}
[HarmonyPrefix]
[HarmonyPatch("GetDepthClass")]
public static bool GetDepthClassPrefix(Player __instance, ref Ocean.DepthClass __result)
{
//AddDebug("GetDepthClass");
Ocean.DepthClass depthClass = Ocean.DepthClass.Surface;
if (!Main.gameLoaded)
{ // avoid null reference exception when loading game inside cyclops
//__result = depthClass;
//return false;
}
CrushDamage crushDamage = null;
if (__instance.currentSub != null && !__instance.currentSub.isBase || __instance.mode == Player.Mode.LockedPiloting)
crushDamage = __instance.currentSub == null ? __instance.gameObject.GetComponentInParent<CrushDamage>() : __instance.currentSub.gameObject.GetComponent<CrushDamage>();
if (crushDamage != null)
{
depthClass = crushDamage.GetDepthClass();
__instance.crushDepth = crushDamage.crushDepth;
}
else
{
__instance.crushDepth = ConfigMenu.crushDepth.Value;
float depth = Ocean.GetDepthOf(__instance.gameObject);
if (depth > __instance.crushDepth)
depthClass = Ocean.DepthClass.Crush;
else if (depth > __instance.crushDepth * .5f)
depthClass = Ocean.DepthClass.Unsafe;
else if (depth > __instance.GetSurfaceDepth())
depthClass = Ocean.DepthClass.Safe;
}
__result = depthClass;
return false;
}
}
//[HarmonyPatch(typeof(CrushDamage), "GetDepth")]
class CrushDamage_GetDepth_Patch
{
public static void Prefix(CrushDamage __instance)
{
if (__instance.depthCache == null)
{
AddDebug("__instance.depthCache == null");
}
else
AddDebug("depthCache" + __instance.depthCache.Get());
}
}
[HarmonyPatch(typeof(Inventory), "LoseItems")]
class Inventory_LoseItems_Patch
{
public static bool Prefix(Inventory __instance)
{
//AddDebug("LoseItems");
if (ConfigMenu.dropItemsOnDeath.Value == ConfigMenu.DropItemsOnDeath.Drop_everything)
{
List<InventoryItem> inventoryItemList = new List<InventoryItem>();
foreach (InventoryItem inventoryItem in Inventory.main.container)
{
inventoryItemList.Add(inventoryItem);
}
foreach (InventoryItem inventoryItem in (IItemsContainer)Inventory.main.equipment)
{
//AddDebug("equipment " + inventoryItem.item.GetTechName());
inventoryItemList.Add(inventoryItem);
}
foreach (InventoryItem item in inventoryItemList)
{
//AddDebug("DROP " + item.item.GetTechName());
__instance.InternalDropItem(item.item, false);
}
return false;
}
else if (ConfigMenu.dropItemsOnDeath.Value == ConfigMenu.DropItemsOnDeath.Do_not_drop_anything)
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(FootstepSounds), "OnStep")]
class FootstepSounds_OnStep_Patch
{
static bool Prefix(FootstepSounds __instance, Transform xform)
{
if (!ConfigToEdit.disableFootstepClickSound.Value)
return true;
if (!__instance.ShouldPlayStepSounds())
return false;
//FMODAsset test = new FMODAsset() { path = "event:/player/footstep_rocket" };
FMODAsset asset;
float volume;
if (Player.main.precursorOutOfWater)
{
asset = __instance.precursorInteriorSound;
volume = __instance.precursorInteriorSoundVolume;
}
else if (__instance.groundMoveable.GetGroundSurfaceType() == VFXSurfaceTypes.metal || Player.main.IsInside() || Player.main.GetBiomeString() == FootstepSounds.crashedShip)
{
asset = __instance.metalSound;
volume = __instance.metalSoundVolume;
}
else
{
asset = __instance.landSound;
volume = __instance.landSoundVolume;
}
//asset = test;
EventInstance evt = FMODUWE.GetEvent(asset);
if (!evt.isValid())
return false;
if (FMODUWE.IsInvalidParameterId(__instance.fmodIndexSpeed))
__instance.fmodIndexSpeed = FMODUWE.GetEventInstanceParameterIndex(evt, "speed");
//AddDebug("Velocity.magnitude " + __instance.groundMoveable.GetVelocity().magnitude);
ATTRIBUTES_3D attributes = xform.To3DAttributes();
evt.set3DAttributes(attributes);
float velMag = __instance.groundMoveable.GetVelocity().magnitude;
evt.setParameterValueByIndex(__instance.fmodIndexSpeed, velMag);
evt.setVolume(volume);
//AddDebug("FootstepSounds onstep " + asset.name);
if (asset != __instance.landSound)
{
//AddDebug("FIX");
evt.setParameterValueByIndex(__instance.fmodIndexSpeed, 7f);
if (velMag < 6f)
evt.setVolume(.3f);
}
evt.start();
evt.release();
return false;
}
}
[HarmonyPatch(typeof(VoiceNotification), "Play", new Type[1] { typeof(object[]) })]
class VoiceNotification_Play_Patch
{
public static bool Prefix(VoiceNotification __instance)
{
//AddDebug("VoiceNotification Play");
if (!Main.gameLoaded)
return false;
return true;
}
}
[HarmonyPatch(typeof(SoundQueue), "PlayQueued", new Type[2] { typeof(string), typeof(string) })]
class SoundQueue_PlayQueued_Patch
{
public static bool Prefix(SoundQueue __instance, string sound)
{
//AddDebug(" PlayQueued " + sound);
if (!Main.gameLoaded)
return false;
return true;
}
}
}
}