-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpawnPointPatch.cs
76 lines (71 loc) · 2.92 KB
/
SpawnPointPatch.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
using HarmonyLib;
using OWML.Utils;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace QSBFPS;
[HarmonyPatch]
public class SpawnPointPatch : MonoBehaviour
{
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerSpawner), nameof(PlayerSpawner.SpawnPlayer))]
public static bool PlayerSpawner_SpawnPlayer_Prefix(PlayerSpawner __instance)
{
SpawnLocation _spawnLocation = SpawnLocation.TimberHearth;
if (qsbFPS.Instance.customSpawn)
{
if (!EnumUtils.IsDefined<SpawnLocation>(17))
{
_spawnLocation = EnumUtils.Create<SpawnLocation>(17, "PVPArena");
}
else
{
_spawnLocation = (SpawnLocation)17;
}
}
if (PlayerData.GetWarpedToTheEye())
{
Debug.Log("Abort player spawn. Vessel will handle it.");
return false;
}
if (__instance._initialSpawnPoint == null)
{
if (LoadManager.GetCurrentScene() == OWScene.SolarSystem || SceneManager.GetActiveScene().name.Contains("TimberHearth") ||
SceneManager.GetActiveScene().name.Contains("TH_BeautifulCorner") || SceneManager.GetActiveScene().name.Contains("Test"))
{
__instance._initialSpawnPoint = __instance.GetSpawnPoint(_spawnLocation);
}
if (!__instance._initialSpawnPoint)
{
for (int i = 0; i < __instance._spawnList.Length; i++)
{
if (__instance._spawnList[i].GetSpawnLocation() != SpawnLocation.Ship && !__instance._spawnList[i].IsShipSpawn())
{
__instance._initialSpawnPoint = __instance._spawnList[i];
break;
}
}
}
}
if (__instance._initialSpawnPoint != null)
{
if (LoadManager.GetCurrentScene() == OWScene.SolarSystem)
{
__instance._cameraController.SetDegreesY(80f);
}
OWRigidbody attachedOWRigidbody = __instance._initialSpawnPoint.gameObject.GetAttachedOWRigidbody(false);
__instance._playerBody.transform.position = __instance._initialSpawnPoint.transform.position;
__instance._playerBody.transform.rotation = __instance._initialSpawnPoint.transform.rotation;
__instance._playerBody.GetRequiredComponent<MatchInitialMotion>().SetBodyToMatch(attachedOWRigidbody);
if (!Physics.autoSyncTransforms)
{
Physics.SyncTransforms();
}
__instance._finishSpawnNextUpdate = true;
qsbFPS.Instance.ModHelper.Console.WriteLine("SPAWN PLAYER");
qsbFPS.Instance.ModHelper.Console.WriteLine($"Player location: {__instance._playerBody.transform.position}");
return false;
}
Debug.LogError("Spawn point is null!");
return false;
}
}