-
Notifications
You must be signed in to change notification settings - Fork 1
/
Testing.cs
518 lines (473 loc) · 23.6 KB
/
Testing.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
using BepInEx;
using HarmonyLib;
using Nautilus.Handlers;
using Nautilus.Options;
using Nautilus.Options.Attributes;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using UnityEngine;
using UWE;
using static ErrorMessage;
namespace Tweaks_Fixes
{
class Testing
{
public static GameObject storedGO;
public static PrefabIdentifier prefabIdentifier;
static bool GetScanTarget(float distance, out GameObject result)
{
bool flag = false;
Transform transform = MainCamera.camera.transform;
Vector3 position = transform.position;
Vector3 forward = transform.forward;
Ray ray = new Ray(position, forward);
int layerMask = ~(1 << LayerID.OnlyVehicle);
int numHits = UWE.Utils.RaycastIntoSharedBuffer(ray, distance, layerMask, QueryTriggerInteraction.Collide);
//DebugTargetConsoleCommand.radius = -1f;
RaycastHit resultHit = new RaycastHit();
AddDebug("GetScanTarget numHits1 " + numHits);
//if (Targeting.Filter(UWE.Utils.sharedHitBuffer, numHits1, out resultHit))
// flag = true;
for (int index1 = 0; index1 < numHits; ++index1)
{
RaycastHit hit = UWE.Utils.sharedHitBuffer[index1];
Collider collider = hit.collider;
if (collider == null)
continue;
GameObject gameObject = collider.gameObject;
Transform transform1 = collider.transform;
if (gameObject == null || transform1 == null)
continue;
int layer = gameObject.layer;
//Transform transform2 = null;
bool next = false;
for (int index2 = 0; index2 < Targeting.ignoreList.Count; ++index2)
{
Transform ignore = Targeting.ignoreList[index2];
if (transform1.IsAncestorOf(ignore))
{
//transform2 = ignore;
next = true;
break;
}
}
if (next)
continue;
//if (transform2 == null)
if (resultHit.collider == null || hit.distance < resultHit.distance)
resultHit = hit;
}
if (resultHit.collider != null)
{
GameObject go = Util.GetEntityRoot(resultHit.collider.gameObject);
if (go)
AddDebug("GetScanTarget resultHit " + go.name);
}
//if (!flag)
//{
// foreach (float radius in GameInput.IsPrimaryDeviceGamepad() ? Targeting.gamepadRadiuses : Targeting.standardRadiuses)
// {
// DebugTargetConsoleCommand.radius = radius;
// ray.origin = position + forward * radius;
// int numHits2 = UWE.Utils.SpherecastIntoSharedBuffer(ray, radius, distance, layerMask, queryTriggerInteraction);
// if (Targeting.Filter(UWE.Utils.sharedHitBuffer, numHits2, out resultHit))
// {
// flag = true;
// break;
// }
// }
//}
Targeting.Reset();
DebugTargetConsoleCommand.Stop();
result = resultHit.collider != null ? resultHit.collider.gameObject : null;
distance = resultHit.distance;
return flag;
}
public static bool GetTarget(float maxDistance, out GameObject result, out float distance)
{
bool flag = false;
Transform transform = MainCamera.camera.transform;
Vector3 position = transform.position;
Vector3 forward = transform.forward;
Ray ray = new Ray(position, forward);
int layerMask = ~(1 << LayerID.Trigger | 1 << LayerID.OnlyVehicle);
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Collide;
int numHits1 = UWE.Utils.RaycastIntoSharedBuffer(ray, maxDistance, layerMask, queryTriggerInteraction);
DebugTargetConsoleCommand.radius = -1f;
RaycastHit resultHit;
if (Targeting.Filter(UWE.Utils.sharedHitBuffer, numHits1, out resultHit))
flag = true;
if (!flag)
{
foreach (float radius in GameInput.IsPrimaryDeviceGamepad() ? Targeting.gamepadRadiuses : Targeting.standardRadiuses)
{
DebugTargetConsoleCommand.radius = radius;
ray.origin = position + forward * radius;
int numHits2 = UWE.Utils.SpherecastIntoSharedBuffer(ray, radius, maxDistance, layerMask, queryTriggerInteraction);
if (Targeting.Filter(UWE.Utils.sharedHitBuffer, numHits2, out resultHit))
{
flag = true;
break;
}
}
}
Targeting.Reset();
DebugTargetConsoleCommand.Stop();
result = resultHit.collider != null ? resultHit.collider.gameObject : null;
distance = resultHit.distance;
return flag;
}
//[HarmonyPatch(typeof(GasPod), "Detonate")]
class SubRoot_FixedUpdate_Patch
{ // bfe8345c-fe3c-4c2b-9a03-51bcc5a2a782
static bool Prefix(GasPod __instance)
{
//if (Player.main.currentSub && Player.main.currentSub == __instance)
{
//AddDebug("SubRoot FixedUpdate");
return false;
}
//return true;
}
}
//[HarmonyPatch(typeof(Player), "Update")]
class Player_Update_Patch
{
static void Postfix(Player __instance)
{
if (!Main.gameLoaded)
return;
if (__instance.currentSub)
{
//AddDebug("IsLeaking " + __instance.currentSub.IsLeaking());
}
//AddDebug("camera transform forward " + MainCamera.camera.transform.forward);
//AddDebug("isUnderwaterForSwimming " + Player.main.isUnderwaterForSwimming.value);
//AddDebug("motorMode " + Player.main.motorMode);
//AddDebug("precursorOutOfWater " + Player.main.precursorOutOfWater);
//AddDebug(PlatformUtils.main.GetServices().GetRichPresence());
//if (Input.GetKey(KeyCode.LeftShift))
// AddDebug("timePassed " + DayNightCycle.main.timePassedAsFloat);
if (Input.GetKeyDown(KeyCode.B))
{
//if (Player.main.IsInBase())
// AddDebug("IsInBase");
//else if (Player.main.IsInSubmarine())
// AddDebug("IsInSubmarine");
//else if (Player.main.inExosuit)
// AddDebug("GetInMechMode");
//else if (Player.main.inSeamoth)
// AddDebug("inSeamoth");
int x = Mathf.RoundToInt(Player.main.transform.position.x);
int y = Mathf.RoundToInt(Player.main.transform.position.y);
int z = Mathf.RoundToInt(Player.main.transform.position.z);
//AddDebug(x + " " + y + " " + z);
}
else if (Input.GetKeyDown(KeyCode.C))
{
//AddDebug("targetFrameRate " + Application.targetFrameRate);
//Application.targetFrameRate = 11;
//PrintTerrainSurfaceType();
//FindObjectClosestToPlayer(3);
//AddDebug("activeTarget " + Player.main.guiHand.activeTarget);
// bool hit = Physics.Linecast(Player.main.transform.position, Vector3.zero
// , Voxeland.GetTerrainLayerMask());
// AddDebug(" hit from player " + hit);
// hit = Physics.Linecast(Vector3.zero, Player.main.transform.position
//, Voxeland.GetTerrainLayerMask());
// AddDebug(" hit to player " + hit);
//if (Input.GetKey(KeyCode.LeftShift))
// Main.survival.water++;
//else
// Main.survival.food++;
}
else if (Input.GetKeyDown(KeyCode.V))
{
//AddDebug("techTypesToDespawn Count " + LargeWorldEntity_Patch.techTypesToDespawn.Count());
//AddDebug("RightHand " + GameInput.GetBinding(GameInput.Device.Controller, GameInput.Button.RightHand, GameInput.BindingSet.Primary));
//AddDebug("LeftHand " + GameInput.GetBinding(GameInput.Device.Controller, GameInput.Button.RightHand, GameInput.BindingSet.Primary));
//AddDebug("ControllerLeftTrigger index " + GameInput.GetInputIndex("ControllerLeftTrigger")); // 179
//AddDebug("ControllerRightTrigger index " + GameInput.GetInputIndex("ControllerRightTrigger")); // 180
printTarget();
}
else if (Input.GetKeyDown(KeyCode.X))
{
if (Input.GetKey(KeyCode.LeftShift))
// //survival.water--;
__instance.liveMixin.health--;
else
// //survival.food--;
__instance.liveMixin.health++;
}
else if (Input.GetKeyDown(KeyCode.Z))
{
//GameObject goToTest = Player.main.guiHand.activeTarget;
//AddDebug("PDAScanner " + PDAScanner.complete.Contains(TechType.SeaglideFragment));
//AddDebug("KnownTech " + KnownTech.Contains(TechType.Seaglide));
//AddDebug("Exosuit " + BehaviourData.GetEcoTargetType(TechType.Exosuit));
//AddDebug("GetDepth " + Player.main.GetDepth());
//Vector3 vel = Player.main.currentMountedVehicle.useRigidbody.velocity;
//bool moving = vel.x > 1f || vel.y > 1f || vel.z > 1f;
//AddDebug("moving " + moving);
//AddDebug(" " + target.gameObject.name );
//if (target.transform.parent)
// AddDebug("parent " + target.transform.parent.name);
//if (target.GetComponent<InfectedMixin>())
//{
// AddDebug("infectedAmount " + target.GetComponent<InfectedMixin>().infectedAmount);
//}
//int x = (int)target.transform.position.x;
//int y = (int)target.transform.position.y;
//int z = (int)target.transform.position.z;
//AddDebug(x + " " + y + " " + z);
//Rigidbody rb = target.GetComponent<Rigidbody>();
//if (rb)
// AddDebug("Rigidbody " + rb.mass);
if (Input.GetAxis("Mouse ScrollWheel") > 0f)
{
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0f)
{
}
}
}
}
static void PrintTerrainSurfaceType()
{
VFXSurfaceTypes vfxSurfaceTypes = VFXSurfaceTypes.none;
int layerMask = 1 << LayerID.TerrainCollider | 1 << LayerID.Default;
RaycastHit hitInfo;
if (Physics.Raycast(MainCamera.camera.transform.position, MainCamera.camera.transform.forward, out hitInfo, 111f, layerMask) && hitInfo.collider.gameObject.layer == LayerID.TerrainCollider)
{
vfxSurfaceTypes = Utils.GetTerrainSurfaceType(hitInfo.point, hitInfo.normal);
AddDebug("vfxSurfaceTypes " + vfxSurfaceTypes);
}
else
AddDebug("no terrain ");
}
public static void printTarget()
{
GameObject target = Player.main.guiHand.activeTarget;
RaycastHit hitInfo = new RaycastHit();
if (!target)
//Util.GetTarget(Player.mainObject.transform.position, MainCamera.camera.transform.forward, 11f, out hitInfo);
Targeting.GetTarget(Player.main.gameObject, 11f, out target, out float targetDist);
//if (hitInfo.collider)
// target = hitInfo.collider.gameObject;
if (!target)
return;
//AddDebug("target " + target.name);
GameObject root = Util.GetEntityRoot(target);
if (root)
target = root;
//WorldForces worldForces = target.GetComponent<WorldForces>();
//if (worldForces != null)
//{
// AddDebug("WorldForces IsAboveWater " + worldForces.IsAboveWater());
//}
VFXSurfaceTypes vfxSurfaceType = VFXSurfaceTypes.none;
TerrainChunkPieceCollider tcpc = target.GetComponent<TerrainChunkPieceCollider>();
if (tcpc)
{
vfxSurfaceType = Utils.GetTerrainSurfaceType(hitInfo.point, hitInfo.normal);
AddDebug("Terrain vfxSurfaceType " + vfxSurfaceType);
return;
}
if (target)
vfxSurfaceType = Util.GetObjectSurfaceType(target);
LargeWorldEntity lwe = target.GetComponentInParent<LargeWorldEntity>();
if (lwe)
{
//goToTest = lwe.gameObject;
//target = lwe.gameObject;
//Rigidbody rb = lwe.GetComponent<Rigidbody>();
//if (rb)
// AddDebug(" mass " + rb.mass + " drag " + rb.drag + " ang drag " + rb.angularDrag);
//AddDebug("PDAScanner isValid " + PDAScanner.scanTarget.isValid);
//AddDebug("PDAScanner CanScan " + PDAScanner.CanScan());
//AddDebug("PDAScanner scanTarget " + PDAScanner.scanTarget.techType);
AddDebug(" cellLevel " + lwe.cellLevel);
//AddDebug("vfxSurfaceType " + vfxSurfaceType);
//LiveMixin lm = lwe.GetComponent<LiveMixin>();
//if (lm)
// AddDebug("max HP " + lm.data.maxHealth + " HP " + lm.health);
}
AddDebug(target.gameObject.name);
//if (target.transform.parent)
// AddDebug(target.transform.parent.name);
//AddDebug("parent " + target.transform.parent.gameObject.name);
//if (target.transform.parent.parent)
// AddDebug("parent parent " + target.transform.parent.parent.gameObject.name);
TechType techType = CraftData.GetTechType(target);
if (techType != TechType.None)
AddDebug("TechType " + techType);
int x = (int)target.transform.position.x;
int y = (int)target.transform.position.y;
int z = (int)target.transform.position.z;
//AddDebug(x + " " + y + " " + z);
}
private Vector3 ClipWithTerrain(GameObject go)
{
Vector3 origin = go.transform.position;
//origin.y = go.transform.position.y + 5f;
//RaycastHit hitInfo;
//if (!Physics.Raycast(new Ray(origin, Vector3.down), out hitInfo, 10f, Voxeland.GetTerrainLayerMask(), QueryTriggerInteraction.Ignore))
// return;
//go.transform.position.y = Mathf.Max(go.transform.position.y, hitInfo.point.y + 0.3f);
return origin;
}
void GetGO()
{
int numHits = UWE.Utils.SpherecastIntoSharedBuffer(Player.main.transform.position, 2f, Vector3.forward);
AddDebug("num Hits " + numHits);
AddDebug("sharedHitBuffer.Length " + UWE.Utils.sharedHitBuffer.Length);
for (int index1 = 0; index1 < numHits; ++index1)
{
RaycastHit raycastHit = UWE.Utils.sharedHitBuffer[index1];
Vector3 point = raycastHit.point;
AddDebug("raycastHit " + raycastHit.collider.gameObject.name);
GameObject go = UWE.Utils.GetEntityRoot(raycastHit.collider.gameObject);
if (go == null)
AddDebug("go == null " + raycastHit.collider.gameObject.name);
else
AddDebug(go.name);
}
}
//[HarmonyPatch(typeof(VoxelandGrassBuilder), "CreateUnityMeshes")]
class VoxelandGrassBuilder_CreateUnityMeshes_Patch
{
static bool Prefix(VoxelandGrassBuilder __instance, IVoxelandChunk2 chunk, TerrainPoolManager terrainPoolManager)
{
for (int index = 0; index < __instance.builtMeshes.Count; ++index)
{
TerrainChunkPiece grassObj = __instance.GetGrassObj(chunk, terrainPoolManager);
chunk.grassFilters.Add(grassObj.meshFilter);
chunk.grassRenders.Add(grassObj.meshRenderer);
chunk.chunkPieces.Add(grassObj);
MeshFilter grassFilter = chunk.grassFilters[index];
grassFilter.gameObject.SetActive(true);
MeshRenderer grassRender = chunk.grassRenders[index];
VoxelandBlockType type = __instance.types[index];
grassFilter.sharedMesh = terrainPoolManager.GetMeshForPiece(grassObj);
Material grassMaterial = type.grassMaterial;
grassRender.sharedMaterial = grassMaterial;
//Main.logger.LogDebug("material " + grassRender.material.name + " VoxelandBlockType " + type.name + " grassMeshName " + type.grassMeshName + " layer " + type.layer + " filled " + type.filled);
//AddDebug("grassRender.material " + grassRender.material.name);
//Main.logger.LogDebug("grassRender " + grassRender.material.name);
//coral_reef_grass_10_gr coral_reef_grass_11_02_gr coral_reef_grass_07_gr
//if (grassRender.material.name == "Coral_reef_red_seaweed_03 (Instance)" || grassRender.material.name == "Coral_reef_red_seaweed_01 (Instance)")
{
//AddDebug("!!!");
UWE.MeshBuffer builtMesh = __instance.builtMeshes[index];
builtMesh.Upload(grassFilter.sharedMesh);
builtMesh.Return();
}
}
__instance.state = VoxelandGrassBuilder.State.Init;
return false;
}
}
//[HarmonyPatch(typeof(SubRoot), "Update")]
class SubControl_Update_Patch
{
public static void Prefix(SubRoot __instance)
{
AddDebug("SubRoot Update LOD " + __instance.LOD.IsFull());
//AddDebug("CyclopsHelmHUDManager Update IsAlive " + __instance.subLiveMixin.IsAlive());
}
}
//[HarmonyPatch(typeof(Story.StoryGoal), "Execute")]
class StoryGoal_Execute_Patch
{
public static void Postfix(Story.StoryGoal __instance, string key, Story.GoalType goalType)
{
AddDebug("StoryGoal " + key);
AddDebug("goalType " + goalType);
//return false;
}
}
//[HarmonyPatch(typeof(PDAEncyclopedia), "AddAndPlaySound")]
class PDAEncyclopedia_AddAndPlaySound_Patch
{
public static void Postfix(string key, PDAEncyclopedia.EntryData __result)
{
AddDebug("AddAndPlaySound " + key);
AddDebug("EntryData " + __result.key);
//return false;
}
}
//[HarmonyPatch(typeof(LargeWorldEntity), "Awake")]
class LargeWorldEntity_Awake_patch
{
public static void Postfix(LargeWorldEntity __instance)
{
if (__instance.name == "AbandonedBaseJellyShroom1(Clone)")
{
Material dirtyGlassMat = null;
//Transform dirtyGlassTr = __instance.transform.Find("Culling/BaseCell/BaseAbandonedObservatory/BaseAbandonedRoomObservatory/BaseRoomObservatory_glass");
Transform dirtyGlassTr = __instance.transform.Find("Culling/BaseCell/BaseAbandonedRoomWindowSide/BaseRoomGenericInteriorWindowSide01Broken01/BaseExteriorRoomGenericWindowSide01Glass");
if (dirtyGlassTr)
{
MeshRenderer mr = dirtyGlassTr.GetComponent<MeshRenderer>();
if (mr)
dirtyGlassMat = mr.material;
}
if (dirtyGlassMat == null)
return;
Transform glassTr = __instance.transform.Find("Culling/BaseCell/BaseAbandonedCorridorIShapeGlass/models/BaseCorridorhIShapeGlass01Exterior/BaseCorridorhIShapeGlass01ExteriorGlass");
if (glassTr)
{
MeshRenderer mr = glassTr.GetComponent<MeshRenderer>();
mr.material = dirtyGlassMat;
//mr.sharedMaterial = dirtyGlassMat;
//mr.material.mainTextureOffset = new Vector2(.5f, 1.5f);
//AddDebug("color " + mr.material.color);
}
}
}
}
static void Debug(GameObject go)
{
if (!go || go.name == "Debug")
return;
if (!go.transform.Find("Debug"))
{
GameObject debug = GameObject.CreatePrimitive(PrimitiveType.Sphere);
debug.name = "Debug";
debug.GetComponent<SphereCollider>().enabled = false;
debug.transform.SetParent(go.transform, false);
debug.GetComponent<MeshRenderer>().material.color = new Color(1f, 0f, 0f);
AddDebug("Creating debug sphere for: " + go.name);
//debug.transform.localScale = Vector3.one * 0.1f;
}
//for (var i = 0; i < go.transform.childCount; ++i)
// Debug(go.transform.GetChild(i).gameObject);
}
//[HarmonyPatch(typeof(Targeting), "GetTarget", new Type[] { typeof(float), typeof(GameObject), typeof(float), typeof(Targeting.FilterRaycast) }, new[] { ArgumentType.Normal, ArgumentType.Out, ArgumentType.Out, ArgumentType.Normal })]
class Targeting_GetTarget_PostfixPatch
{
public static void Postfix(ref GameObject result)
{
//AddDebug(" Targeting GetTarget " + result.name);
}
}
//[HarmonyPatch(typeof(CrafterLogic), "progress", MethodType.Getter)]
class CrafterLogic_progress_Patch
{ // patch property getter
public static bool Prefix(CrafterLogic __instance, ref float __result)
{
double timePassed = DayNightCycle.main.timePassed;
double num1 = __instance.timeCraftingEnd - __instance.timeCraftingBegin;
double timeCraftingBegin = __instance.timeCraftingBegin;
double num2 = ((timePassed - timeCraftingBegin) / num1);
__result = __instance.timeCraftingEnd <= __instance.timeCraftingBegin ? -1f : Mathf.Clamp01((float)num2);
return false;
}
}
}
}