From d6e459b494a667420858f3db82e909fc3e6de706 Mon Sep 17 00:00:00 2001
From: Mister_Nebula <41904486+misternebula@users.noreply.github.com>
Date: Tue, 12 Jan 2021 19:24:07 +0000
Subject: [PATCH] stuff
---
QSB/Events/EventNames.cs | 1 +
QSB/Events/EventType.cs | 3 +-
QSB/Events/QSBEventManager.cs | 1 +
QSB/QSB.csproj | 2 +
QSB/QuantumSync/Events/ShrineRotationEvent.cs | 34 ++++++++++++++
.../Events/ShrineRotationMessage.cs | 27 ++++++++++++
.../ClientQuantumStateChangePatches.cs | 1 +
.../ServerQuantumStateChangePatches.cs | 44 ++++++++++++++++++-
8 files changed, 111 insertions(+), 2 deletions(-)
create mode 100644 QSB/QuantumSync/Events/ShrineRotationEvent.cs
create mode 100644 QSB/QuantumSync/Events/ShrineRotationMessage.cs
diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs
index 15f719e6..5413d2a5 100644
--- a/QSB/Events/EventNames.cs
+++ b/QSB/Events/EventNames.cs
@@ -45,5 +45,6 @@
public static string QSBIdentifyFrequency = "QSBIdentifyFrequency";
public static string QSBIdentifySignal = "QSBIdentifySignal";
public static string QSBTextTranslated = "QSBTextTranslated";
+ public static string QSBShrineRotation = "QSBShrineRotation";
}
}
\ No newline at end of file
diff --git a/QSB/Events/EventType.cs b/QSB/Events/EventType.cs
index 29a90d22..d939a59c 100644
--- a/QSB/Events/EventType.cs
+++ b/QSB/Events/EventType.cs
@@ -32,6 +32,7 @@
MoonStateChange,
IdentifyFrequency,
IdentifySignal,
- TextTranslated
+ TextTranslated,
+ ShrineRotation
}
}
\ No newline at end of file
diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs
index 0356d328..4b5ab27b 100644
--- a/QSB/Events/QSBEventManager.cs
+++ b/QSB/Events/QSBEventManager.cs
@@ -53,6 +53,7 @@ namespace QSB.Events
new SetAsTranslatedEvent(),
new QuantumShuffleEvent(),
new MoonStateChangeEvent(),
+ new ShrineRotationEvent(),
// Conversation/dialogue/exploration
new ConversationEvent(),
new ConversationStartEndEvent(),
diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj
index fd6fb7f9..1003f2f2 100644
--- a/QSB/QSB.csproj
+++ b/QSB/QSB.csproj
@@ -156,6 +156,8 @@
+
+
diff --git a/QSB/QuantumSync/Events/ShrineRotationEvent.cs b/QSB/QuantumSync/Events/ShrineRotationEvent.cs
new file mode 100644
index 00000000..5c3aa4fb
--- /dev/null
+++ b/QSB/QuantumSync/Events/ShrineRotationEvent.cs
@@ -0,0 +1,34 @@
+using QSB.Events;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using UnityEngine;
+
+namespace QSB.QuantumSync.Events
+{
+ class ShrineRotationEvent : QSBEvent
+ {
+ public override QSB.Events.EventType Type => QSB.Events.EventType.ShrineRotation;
+
+ public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBMoonStateChange, Handler);
+ public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBMoonStateChange, Handler);
+
+ private void Handler(Quaternion rotation) => SendEvent(CreateMessage(rotation));
+
+ private ShrineRotationMessage CreateMessage(Quaternion rotation) => new ShrineRotationMessage
+ {
+ AboutId = LocalPlayerId,
+ Rotation = rotation
+ };
+
+ public override void OnReceiveRemote(bool server, ShrineRotationMessage message)
+ {
+ if (!QSBCore.HasWokenUp)
+ {
+ return;
+ }
+ Resources.FindObjectsOfTypeAll().First().transform.rotation = message.Rotation;
+ }
+ }
+}
diff --git a/QSB/QuantumSync/Events/ShrineRotationMessage.cs b/QSB/QuantumSync/Events/ShrineRotationMessage.cs
new file mode 100644
index 00000000..2c37ee57
--- /dev/null
+++ b/QSB/QuantumSync/Events/ShrineRotationMessage.cs
@@ -0,0 +1,27 @@
+using QSB.Messaging;
+using QuantumUNET.Transport;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using UnityEngine;
+
+namespace QSB.QuantumSync.Events
+{
+ class ShrineRotationMessage : PlayerMessage
+ {
+ public Quaternion Rotation { get; set; }
+
+ public override void Deserialize(QNetworkReader reader)
+ {
+ base.Deserialize(reader);
+ Rotation = reader.ReadQuaternion();
+ }
+
+ public override void Serialize(QNetworkWriter writer)
+ {
+ base.Serialize(writer);
+ writer.Write(Rotation);
+ }
+ }
+}
diff --git a/QSB/QuantumSync/Patches/ClientQuantumStateChangePatches.cs b/QSB/QuantumSync/Patches/ClientQuantumStateChangePatches.cs
index 1321f9d9..8a5c89f4 100644
--- a/QSB/QuantumSync/Patches/ClientQuantumStateChangePatches.cs
+++ b/QSB/QuantumSync/Patches/ClientQuantumStateChangePatches.cs
@@ -12,6 +12,7 @@ namespace QSB.QuantumSync.Patches
QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ClientQuantumStateChangePatches), nameof(ReturnFalsePatch));
QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ClientQuantumStateChangePatches), nameof(ReturnFalsePatch));
QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ClientQuantumStateChangePatches), nameof(ReturnFalsePatch));
+ QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ClientQuantumStateChangePatches), nameof(ReturnFalsePatch));
}
public static bool ReturnFalsePatch() => false;
diff --git a/QSB/QuantumSync/Patches/ServerQuantumStateChangePatches.cs b/QSB/QuantumSync/Patches/ServerQuantumStateChangePatches.cs
index 9799677e..39bfe1da 100644
--- a/QSB/QuantumSync/Patches/ServerQuantumStateChangePatches.cs
+++ b/QSB/QuantumSync/Patches/ServerQuantumStateChangePatches.cs
@@ -2,6 +2,7 @@
using QSB.Patches;
using QSB.Player;
using QSB.QuantumSync.WorldObjects;
+using QSB.Utility;
using QSB.WorldSync;
using System;
using System.Collections.Generic;
@@ -22,6 +23,8 @@ namespace QSB.QuantumSync.Patches
QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ServerQuantumStateChangePatches), nameof(Shuffle_ChangeQuantumState));
QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ServerQuantumStateChangePatches), nameof(Moon_ChangeQuantumState));
QSBCore.Helper.HarmonyHelper.AddPrefix("CheckPlayerFogProximity", typeof(ServerQuantumStateChangePatches), nameof(Moon_CheckPlayerFogProximity));
+ QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ServerQuantumStateChangePatches), nameof(Shrine_ChangeQuantumState));
+ QSBCore.Helper.HarmonyHelper.AddPrefix("AddToRetryQueue", typeof(ServerQuantumStateChangePatches), nameof(Shape_AddToRetryQueue));
}
public static void Socketed_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket)
@@ -286,7 +289,7 @@ namespace QSB.QuantumSync.Patches
else
{
var vector = Locator.GetPlayerTransform().position - __instance.transform.position;
- Locator.GetPlayerBody().SetVelocity(____moonBody.GetPointVelocity(Locator.GetPlayerTransform().position) - vector.normalized * 5f);
+ 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)
@@ -306,5 +309,44 @@ namespace QSB.QuantumSync.Patches
____shipLandingCamFogBubble.SetFogAlpha(fogAlpha);
return false;
}
+
+ public static bool Shrine_ChangeQuantumState(QuantumShrine __instance, ref bool __result, bool skipInstantVisibilityCheck)
+ {
+ DebugLog.DebugWrite("Shrine changequantumstate");
+ var baseObject = __instance as SocketedQuantumObject;
+ if (baseObject == null)
+ {
+ DebugLog.DebugWrite("baseobject null");
+ }
+ var method = typeof(SocketedQuantumObject).GetMethod("ChangeQuantumState", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (method == null)
+ {
+ DebugLog.DebugWrite("method null");
+ }
+ var pointer = method.MethodHandle.GetFunctionPointer();
+ if (pointer == null)
+ {
+ DebugLog.DebugWrite("pointer null");
+ }
+ var function = (Func)Activator.CreateInstance(typeof(Func), __instance, pointer);
+ var flag = function(skipInstantVisibilityCheck);
+ if (flag)
+ {
+ var vector = Locator.GetPlayerTransform().position - __instance.transform.position;
+ var to = Vector3.ProjectOnPlane(vector, __instance.transform.up);
+ var num = OWMath.Angle(__instance.transform.forward, to, __instance.transform.up);
+ num = OWMath.RoundToNearestMultiple(num, 120f);
+ __instance.transform.rotation = Quaternion.AngleAxis(num, __instance.transform.up) * __instance.transform.rotation;
+ GlobalMessenger.FireEvent(EventNames.QSBShrineRotation, __instance.transform.rotation);
+ }
+ __result = flag;
+ return false;
+ }
+
+ public static bool Shape_AddToRetryQueue(QuantumObject obj)
+ {
+ DebugLog.DebugWrite($"adding {obj.name} to retry queue");
+ return true;
+ }
}
}
\ No newline at end of file