This commit is contained in:
Aleksander Waage 2020-09-07 20:27:56 +02:00
parent c639285d05
commit 26dc3c5c80
7 changed files with 37 additions and 31 deletions

View File

@ -14,7 +14,8 @@ namespace QSB.OrbSync
}
}
public static bool CheckOrbCollision(ref bool __result, NomaiInterfaceSlot __instance, NomaiInterfaceOrb orb, bool ____ignoreDraggedOrbs, float ____radius, float ____exitRadius, ref NomaiInterfaceOrb ____occupyingOrb)
public static bool CheckOrbCollision(ref bool __result, NomaiInterfaceSlot __instance, NomaiInterfaceOrb orb,
bool ____ignoreDraggedOrbs, float ____radius, float ____exitRadius, ref NomaiInterfaceOrb ____occupyingOrb)
{
if (____ignoreDraggedOrbs && orb.IsBeingDragged())
{
@ -22,7 +23,7 @@ namespace QSB.OrbSync
return false;
}
var orbDistance = Vector3.Distance(orb.transform.position, __instance.transform.position);
var triggerRadius = (!orb.IsBeingDragged()) ? ____radius : ____exitRadius;
var triggerRadius = !orb.IsBeingDragged() ? ____radius : ____exitRadius;
if (____occupyingOrb == null && orbDistance < ____radius)
{
____occupyingOrb = orb;
@ -50,5 +51,11 @@ namespace QSB.OrbSync
__result = true;
return false;
}
public static void AddPatches()
{
QSB.Helper.HarmonyHelper.AddPostfix<NomaiInterfaceOrb>("StartDragFromPosition", typeof(OrbPatches), nameof(StartDragCallEvent));
QSB.Helper.HarmonyHelper.AddPrefix<NomaiInterfaceSlot>("CheckOrbCollision", typeof(OrbPatches), nameof(CheckOrbCollision));
}
}
}

View File

@ -3,7 +3,7 @@ using UnityEngine;
namespace QSB.OrbSync
{
class OrbSlotManager : MonoBehaviour
public class OrbSlotManager : MonoBehaviour
{
private void Awake()
{

View File

@ -6,6 +6,7 @@ namespace QSB.OrbSync
public class QSBOrbSlot : WorldObject
{
public NomaiInterfaceSlot InterfaceSlot { get; private set; }
private bool _initialized;
public void Init(NomaiInterfaceSlot slot, int id)

View File

@ -31,7 +31,7 @@ namespace QSB
private GameObject _shipPrefab;
private GameObject _cameraPrefab;
private GameObject _probePrefab;
public GameObject OrbPrefab;
private GameObject _orbPrefab;
private void Awake()
{
@ -61,10 +61,10 @@ namespace QSB
spawnPrefabs.Add(_probePrefab);
DebugLog.LogState("ProbePrefab", _probePrefab);
OrbPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkorb.prefab");
OrbPrefab.AddComponent<NomaiOrbTransformSync>();
spawnPrefabs.Add(OrbPrefab);
DebugLog.LogState("OrbPrefab", OrbPrefab);
_orbPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkorb.prefab");
_orbPrefab.AddComponent<NomaiOrbTransformSync>();
spawnPrefabs.Add(_orbPrefab);
DebugLog.LogState("OrbPrefab", _orbPrefab);
ConfigureNetworkManager();
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
@ -75,7 +75,7 @@ namespace QSB
WorldRegistry.OldOrbList = Resources.FindObjectsOfTypeAll<NomaiInterfaceOrb>().ToList();
if (NetworkServer.active)
{
WorldRegistry.OldOrbList.ForEach(x => NetworkServer.Spawn(Instantiate(OrbPrefab)));
WorldRegistry.OldOrbList.ForEach(x => NetworkServer.Spawn(Instantiate(_orbPrefab)));
}
}
@ -87,7 +87,7 @@ namespace QSB
customConfig = true;
connectionConfig.AddChannel(QosType.Reliable);
connectionConfig.AddChannel(QosType.Unreliable);
((NetworkManager)this).SetValue("m_MaxBufferedPackets", MaxBufferedPackets);
this.SetValue("m_MaxBufferedPackets", MaxBufferedPackets);
channels.Add(QosType.Reliable);
channels.Add(QosType.Unreliable);
}
@ -120,8 +120,7 @@ namespace QSB
WakeUpPatches.AddPatches();
}
QSB.Helper.HarmonyHelper.AddPostfix<NomaiInterfaceOrb>("StartDragFromPosition", typeof(OrbPatches), nameof(OrbPatches.StartDragCallEvent));
QSB.Helper.HarmonyHelper.AddPrefix<NomaiInterfaceSlot>("CheckOrbCollision", typeof(OrbPatches), nameof(OrbPatches.CheckOrbCollision));
OrbPatches.AddPatches();
_lobby.CanEditName = false;

View File

@ -7,14 +7,15 @@ namespace QSB.TransformSync
public class NomaiOrbTransformSync : NetworkBehaviour
{
public NomaiInterfaceOrb AttachedOrb { get; private set; }
public Transform OrbTransform { get; private set; }
private int Index => WorldRegistry.OrbSyncList.FindIndex(x => x == this);
private const int MaxUpdatesBeforeDisable = 5;
public Transform OrbTransform { get; private set; }
private bool _isInitialized;
private bool _isReady;
private Transform OrbParent;
private Transform _orbParent;
private int _updateCount;
public override void OnStartClient()
@ -30,7 +31,7 @@ namespace QSB.TransformSync
_isReady = true;
}
void Awake()
private void Awake()
{
DontDestroyOnLoad(this);
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
@ -41,7 +42,7 @@ namespace QSB.TransformSync
protected void Init()
{
OrbTransform = AttachedOrb.transform;
OrbParent = AttachedOrb.GetAttachedOWRigidbody().GetOrigParent();
_orbParent = AttachedOrb.GetAttachedOWRigidbody().GetOrigParent();
_isInitialized = true;
}
@ -68,12 +69,12 @@ namespace QSB.TransformSync
{
if (hasAuthority)
{
transform.position = OrbParent.InverseTransformPoint(OrbTransform.position);
transform.rotation = OrbParent.InverseTransformRotation(OrbTransform.rotation);
transform.position = _orbParent.InverseTransformPoint(OrbTransform.position);
transform.rotation = _orbParent.InverseTransformRotation(OrbTransform.rotation);
return;
}
OrbTransform.position = OrbParent.TransformPoint(transform.position);
OrbTransform.rotation = OrbParent.InverseTransformRotation(OrbTransform.rotation);
OrbTransform.position = _orbParent.TransformPoint(transform.position);
OrbTransform.rotation = _orbParent.InverseTransformRotation(OrbTransform.rotation);
if (transform.localPosition == Vector3.zero)
{
_updateCount++;

View File

@ -25,7 +25,7 @@
var flagsValue = (int)(object)flags;
var flagValue = (int)(object)flag;
flags = (T)(object)(flagsValue & (~flagValue));
flags = (T)(object)(flagsValue & ~flagValue);
}
}
}

View File

@ -9,22 +9,22 @@ namespace QSB.WorldSync
{
public static class WorldRegistry
{
private static readonly List<WorldObject> _worldObjects = new List<WorldObject>();
private static readonly List<WorldObject> WorldObjects = new List<WorldObject>();
public static List<NomaiOrbTransformSync> OrbSyncList = new List<NomaiOrbTransformSync>();
public static List<NomaiInterfaceOrb> OldOrbList = new List<NomaiInterfaceOrb>();
public static void AddObject(WorldObject worldObject)
{
if (_worldObjects.Contains(worldObject))
if (WorldObjects.Contains(worldObject))
{
return;
}
_worldObjects.Add(worldObject);
WorldObjects.Add(worldObject);
}
public static IEnumerable<T> GetObjects<T>()
{
return _worldObjects.OfType<T>();
return WorldObjects.OfType<T>();
}
public static T GetObject<T>(int id) where T : WorldObject
@ -44,15 +44,13 @@ namespace QSB.WorldSync
public static void RaiseEvent(object instance, string eventName)
{
var type = instance.GetType();
var staticFlags = BindingFlags.Instance | BindingFlags.NonPublic;
var fieldInfo = type.GetField(eventName, staticFlags);
var multDelegate = fieldInfo.GetValue(instance) as MulticastDelegate;
if (multDelegate == null)
if (!(instance.GetType()
.GetField(eventName, BindingFlags.Instance | BindingFlags.NonPublic)?
.GetValue(instance) is MulticastDelegate multiDelegate))
{
return;
}
var delegateList = multDelegate.GetInvocationList().ToList();
var delegateList = multiDelegate.GetInvocationList().ToList();
delegateList.ForEach(x => x.DynamicInvoke(instance));
}
}