mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
Added World Restriction Checks
This commit is contained in:
parent
5f6a85984d
commit
71d780248f
2 changed files with 344 additions and 313 deletions
|
@ -2,8 +2,14 @@
|
||||||
using ABI_RC.Core.Networking.IO.Instancing;
|
using ABI_RC.Core.Networking.IO.Instancing;
|
||||||
using ABI_RC.Core.UI;
|
using ABI_RC.Core.UI;
|
||||||
using ABI_RC.Systems.GameEventSystem;
|
using ABI_RC.Systems.GameEventSystem;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using NAK.Stickers.Networking;
|
using NAK.Stickers.Networking;
|
||||||
using NAK.Stickers.Utilities;
|
using NAK.Stickers.Utilities;
|
||||||
|
using System.EnterpriseServices;
|
||||||
|
using UnityEngine;
|
||||||
|
using MelonLoader;
|
||||||
|
using UnityEngine.ProBuilder.MeshOperations;
|
||||||
|
using NAK.Stickers.Integrations;
|
||||||
|
|
||||||
namespace NAK.Stickers;
|
namespace NAK.Stickers;
|
||||||
|
|
||||||
|
@ -11,6 +17,8 @@ public partial class StickerSystem
|
||||||
{
|
{
|
||||||
#region Singleton
|
#region Singleton
|
||||||
|
|
||||||
|
public static bool RestrictedInstance = false;
|
||||||
|
|
||||||
public static StickerSystem Instance { get; private set; }
|
public static StickerSystem Instance { get; private set; }
|
||||||
|
|
||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
|
@ -28,7 +36,8 @@ public partial class StickerSystem
|
||||||
|
|
||||||
// listen for game events
|
// listen for game events
|
||||||
CVRGameEventSystem.Initialization.OnPlayerSetupStart.AddListener(Instance.OnPlayerSetupStart);
|
CVRGameEventSystem.Initialization.OnPlayerSetupStart.AddListener(Instance.OnPlayerSetupStart);
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Singleton
|
#endregion Singleton
|
||||||
|
|
||||||
|
@ -37,6 +46,7 @@ public partial class StickerSystem
|
||||||
private void OnPlayerSetupStart()
|
private void OnPlayerSetupStart()
|
||||||
{
|
{
|
||||||
CVRGameEventSystem.World.OnUnload.AddListener(_ => OnWorldUnload());
|
CVRGameEventSystem.World.OnUnload.AddListener(_ => OnWorldUnload());
|
||||||
|
CVRGameEventSystem.World.OnLoad.AddListener(_ => OnWorldLoad());
|
||||||
CVRGameEventSystem.Instance.OnConnected.AddListener((_) => { if (!Instances.IsReconnecting) OnInitialConnection(); });
|
CVRGameEventSystem.Instance.OnConnected.AddListener((_) => { if (!Instances.IsReconnecting) OnInitialConnection(); });
|
||||||
|
|
||||||
CVRGameEventSystem.Player.OnJoinEntity.AddListener(Instance.OnPlayerJoined);
|
CVRGameEventSystem.Player.OnJoinEntity.AddListener(Instance.OnPlayerJoined);
|
||||||
|
@ -51,12 +61,29 @@ public partial class StickerSystem
|
||||||
|
|
||||||
private void OnInitialConnection()
|
private void OnInitialConnection()
|
||||||
{
|
{
|
||||||
|
OnWorldLoad(); //Checks the world again in case the bundle updated.
|
||||||
ClearStickersSelf(); // clear stickers on remotes just in case we rejoined
|
ClearStickersSelf(); // clear stickers on remotes just in case we rejoined
|
||||||
ModNetwork.Reset(); // reset network buffers and metadata
|
ModNetwork.Reset(); // reset network buffers and metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnWorldLoad()
|
||||||
|
{
|
||||||
|
GameObject StickerWorldRestriction = GameObject.Find("[DisableStickers]");
|
||||||
|
if (StickerWorldRestriction != null)
|
||||||
|
{
|
||||||
|
RestrictedInstance = true;
|
||||||
|
MelonLogger.Msg("This is a Restricted Instance");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MelonLogger.Msg("This is NOT a Restricted Instance");
|
||||||
|
}
|
||||||
|
BTKUIAddon.UpdateStickerMenu();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnWorldUnload()
|
private void OnWorldUnload()
|
||||||
{
|
{
|
||||||
|
RestrictedInstance = false;
|
||||||
CleanupAllButSelf(); // release all stickers except for self
|
CleanupAllButSelf(); // release all stickers except for self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ public partial class StickerSystem
|
||||||
|
|
||||||
private bool PlaceStickerSelf(Vector3 position, Vector3 forward, Vector3 up, bool alignWithNormal = true)
|
private bool PlaceStickerSelf(Vector3 position, Vector3 forward, Vector3 up, bool alignWithNormal = true)
|
||||||
{
|
{
|
||||||
if (!AttemptPlaceSticker(PlayerLocalId, position, forward, up, alignWithNormal, SelectedStickerSlot))
|
if (!AttemptPlaceSticker(PlayerLocalId, position, forward, up, alignWithNormal, SelectedStickerSlot, RestrictedInstance))
|
||||||
return false; // failed
|
return false; // failed
|
||||||
|
|
||||||
// placed, now network
|
// placed, now network
|
||||||
|
@ -59,7 +59,7 @@ public partial class StickerSystem
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool AttemptPlaceSticker(string playerId, Vector3 position, Vector3 forward, Vector3 up, bool alignWithNormal = true, int stickerSlot = 0, bool isPreview = false)
|
private bool AttemptPlaceSticker(string playerId, Vector3 position, Vector3 forward, Vector3 up, bool alignWithNormal = true, int stickerSlot = 0, bool RestrictedInstance = false, bool isPreview = false)
|
||||||
{
|
{
|
||||||
StickerData stickerData = GetOrCreateStickerData(playerId);
|
StickerData stickerData = GetOrCreateStickerData(playerId);
|
||||||
if (Time.time - stickerData.LastPlacedTime < StickerCooldown)
|
if (Time.time - stickerData.LastPlacedTime < StickerCooldown)
|
||||||
|
@ -75,6 +75,10 @@ public partial class StickerSystem
|
||||||
if (hit.transform.gameObject.name.StartsWith("[NoSticker]"))
|
if (hit.transform.gameObject.name.StartsWith("[NoSticker]"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// if the world contained a gameobject with the [DisableStickers] name and restricted the instance disable stickers!
|
||||||
|
if (RestrictedInstance == true)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (isPreview)
|
if (isPreview)
|
||||||
{
|
{
|
||||||
stickerData.PlacePreview(hit, alignWithNormal ? -hit.normal : forward, up, stickerSlot);
|
stickerData.PlacePreview(hit, alignWithNormal ? -hit.normal : forward, up, stickerSlot);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue