fix broken QM eye vortex warp

This commit is contained in:
Mister_Nebula 2021-02-16 20:49:10 +00:00
parent 329bd3de5a
commit 934538d3cd
2 changed files with 85 additions and 91 deletions

View File

@ -7,6 +7,7 @@ using QSB.WorldSync;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace QSB.QuantumSync.Patches
@ -26,6 +27,7 @@ namespace QSB.QuantumSync.Patches
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumShrine>("ChangeQuantumState", typeof(QuantumPatches), nameof(Shrine_ChangeQuantumState));
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumShrine>("OnEntry", typeof(QuantumPatches), nameof(Shrine_OnEntry));
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumShrine>("OnExit", typeof(QuantumPatches), nameof(Shrine_OnExit));
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumMoon>("CheckPlayerFogProximity", typeof(ServerQuantumPatches), nameof(Moon_CheckPlayerFogProximity));
}
public override void DoUnpatches()
@ -39,6 +41,7 @@ namespace QSB.QuantumSync.Patches
QSBCore.Helper.HarmonyHelper.Unpatch<QuantumShrine>("ChangeQuantumState");
QSBCore.Helper.HarmonyHelper.Unpatch<QuantumShrine>("OnEntry");
QSBCore.Helper.HarmonyHelper.Unpatch<QuantumShrine>("OnExit");
QSBCore.Helper.HarmonyHelper.Unpatch<QuantumMoon>("CheckPlayerFogProximity");
}
public static bool Socketed_ChangeQuantumState(SocketedQuantumObject __instance)
@ -204,5 +207,83 @@ namespace QSB.QuantumSync.Patches
}
return false;
}
public static bool Moon_CheckPlayerFogProximity(
QuantumMoon __instance,
int ____stateIndex,
float ____eyeStateFogOffset,
ref bool ____isPlayerInside,
float ____fogRadius,
float ____fogThickness,
float ____fogRolloffDistance,
string ____revealFactID,
OWRigidbody ____moonBody,
bool ____hasSunCollapsed,
Transform ____vortexReturnPivot,
OWAudioSource ____vortexAudio,
ref int ____collapseToIndex,
VisibilityTracker ____visibilityTracker,
QuantumFogEffectBubbleController ____playerFogBubble,
QuantumFogEffectBubbleController ____shipLandingCamFogBubble)
{
var playerDistance = Vector3.Distance(__instance.transform.position, Locator.GetPlayerCamera().transform.position);
var fogOffset = (____stateIndex != 5) ? 0f : ____eyeStateFogOffset;
var distanceFromFog = playerDistance - (____fogRadius + fogOffset);
var fogAlpha = 0f;
if (!____isPlayerInside)
{
fogAlpha = Mathf.InverseLerp(____fogThickness + ____fogRolloffDistance, ____fogThickness, distanceFromFog);
if (distanceFromFog < 0f)
{
if ((bool)__instance.GetType().GetMethod("IsLockedByProbeSnapshot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) || QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, true))
{
____isPlayerInside = true;
__instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { ____stateIndex });
Locator.GetShipLogManager().RevealFact(____revealFactID, true, true);
QSBEventManager.FireEvent("PlayerEnterQuantumMoon");
}
else
{
__instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true });
}
}
}
else if (____isPlayerInside)
{
fogAlpha = Mathf.InverseLerp(-____fogThickness - ____fogRolloffDistance, -____fogThickness, distanceFromFog);
if (distanceFromFog >= 0f)
{
if (____stateIndex != 5)
{
____isPlayerInside = false;
if (!(bool)__instance.GetType().GetMethod("IsLockedByProbeSnapshot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) && !QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, true))
{
__instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true });
}
__instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { -1 });
QSBEventManager.FireEvent("PlayerExitQuantumMoon");
}
else
{
var vector = Locator.GetPlayerTransform().position - __instance.transform.position;
Locator.GetPlayerBody().SetVelocity(____moonBody.GetPointVelocity(Locator.GetPlayerTransform().position) - (vector.normalized * 5f));
var d = 80f;
Locator.GetPlayerBody().SetPosition(__instance.transform.position + (____vortexReturnPivot.up * d));
if (!Physics.autoSyncTransforms)
{
Physics.SyncTransforms();
}
var component = Locator.GetPlayerCamera().GetComponent<PlayerCameraController>();
component.SetDegreesY(component.GetMinDegreesY());
____vortexAudio.SetLocalVolume(0f);
____collapseToIndex = 1;
__instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true });
}
}
}
____playerFogBubble.SetFogAlpha(fogAlpha);
____shipLandingCamFogBubble.SetFogAlpha(fogAlpha);
return false;
}
}
}

View File

@ -12,17 +12,11 @@ namespace QSB.QuantumSync.Patches
{
public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect;
public override void DoPatches()
{
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumMoon>("ChangeQuantumState", typeof(ServerQuantumPatches), nameof(Moon_ChangeQuantumState));
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumMoon>("CheckPlayerFogProximity", typeof(ServerQuantumPatches), nameof(Moon_CheckPlayerFogProximity));
}
public override void DoPatches()
=> QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumMoon>("ChangeQuantumState", typeof(ServerQuantumPatches), nameof(Moon_ChangeQuantumState));
public override void DoUnpatches()
{
QSBCore.Helper.HarmonyHelper.Unpatch<QuantumMoon>("ChangeQuantumState");
QSBCore.Helper.HarmonyHelper.Unpatch<QuantumMoon>("CheckPlayerFogProximity");
}
public override void DoUnpatches()
=> QSBCore.Helper.HarmonyHelper.Unpatch<QuantumMoon>("ChangeQuantumState");
public static bool Moon_ChangeQuantumState(
QuantumMoon __instance,
@ -164,86 +158,5 @@ namespace QSB.QuantumSync.Patches
__result = false;
return false;
}
public static bool Moon_CheckPlayerFogProximity(
QuantumMoon __instance,
int ____stateIndex,
float ____eyeStateFogOffset,
ref bool ____isPlayerInside,
float ____fogRadius,
float ____fogThickness,
float ____fogRolloffDistance,
string ____revealFactID,
OWRigidbody ____moonBody,
bool ____hasSunCollapsed,
Transform ____vortexReturnPivot,
OWAudioSource ____vortexAudio,
ref int ____collapseToIndex,
VisibilityTracker ____visibilityTracker,
QuantumFogEffectBubbleController ____playerFogBubble,
QuantumFogEffectBubbleController ____shipLandingCamFogBubble)
{
var playerDistance = Vector3.Distance(__instance.transform.position, Locator.GetPlayerCamera().transform.position);
var fogOffset = (____stateIndex != 5) ? 0f : ____eyeStateFogOffset;
var distanceFromFog = playerDistance - (____fogRadius + fogOffset);
var fogAlpha = 0f;
if (!____isPlayerInside)
{
fogAlpha = Mathf.InverseLerp(____fogThickness + ____fogRolloffDistance, ____fogThickness, distanceFromFog);
if (distanceFromFog < 0f)
{
if ((bool)__instance.GetType().GetMethod("IsLockedByProbeSnapshot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) || QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, true))
{
____isPlayerInside = true;
__instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { ____stateIndex });
Locator.GetShipLogManager().RevealFact(____revealFactID, true, true);
QSBEventManager.FireEvent("PlayerEnterQuantumMoon");
}
else
{
__instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true });
}
}
}
else if (____isPlayerInside)
{
fogAlpha = Mathf.InverseLerp(-____fogThickness - ____fogRolloffDistance, -____fogThickness, distanceFromFog);
if (distanceFromFog >= 0f)
{
if (____stateIndex != 5)
{
____isPlayerInside = false;
if (!(bool)__instance.GetType().GetMethod("IsLockedByProbeSnapshot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null) && !QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)____visibilityTracker, true))
{
__instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true });
}
__instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { -1 });
QSBEventManager.FireEvent("PlayerExitQuantumMoon");
}
else
{
var vector = Locator.GetPlayerTransform().position - __instance.transform.position;
Locator.GetPlayerBody().SetVelocity(____moonBody.GetPointVelocity(Locator.GetPlayerTransform().position) - (vector.normalized * 5f));
var d = (!____hasSunCollapsed) ? (____fogRadius - 1f) : 80f;
Locator.GetPlayerBody().SetPosition(__instance.transform.position + (____vortexReturnPivot.up * d));
if (!Physics.autoSyncTransforms)
{
Physics.SyncTransforms();
}
var component = Locator.GetPlayerCamera().GetComponent<PlayerCameraController>();
component.SetDegreesY(component.GetMinDegreesY());
____vortexAudio.SetLocalVolume(0f);
____collapseToIndex = 1;
// TODO : Handle players exiting eye state when other players are still on eye state, etc...
__instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true });
}
}
}
____playerFogBubble.SetFogAlpha(fogAlpha);
____shipLandingCamFogBubble.SetFogAlpha(fogAlpha);
return false;
}
}
}