Stickers: cleanup

This commit is contained in:
NotAKidoS 2024-09-21 01:07:04 -05:00
parent 50804b323d
commit dbc6341f9e
12 changed files with 113 additions and 126 deletions

View file

@ -9,6 +9,8 @@ public static partial class BTKUIAddon
{ {
private static Category _ourCategory; private static Category _ourCategory;
private static Button _placeStickersButton;
private static readonly MultiSelection _sfxSelection = private static readonly MultiSelection _sfxSelection =
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_SelectedSFX); MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_SelectedSFX);
@ -18,16 +20,14 @@ public static partial class BTKUIAddon
private static readonly MultiSelection _tabDoubleClickSelection = private static readonly MultiSelection _tabDoubleClickSelection =
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_TabDoubleClick); MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_TabDoubleClick);
public static Button placeStickersButton;
#region Category Setup #region Category Setup
private static void Setup_StickersModCategory() private static void Setup_StickersModCategory()
{ {
_ourCategory = _rootPage.AddMelonCategory(ModSettings.Hidden_Foldout_SettingsCategory); _ourCategory = _rootPage.AddMelonCategory(ModSettings.Hidden_Foldout_SettingsCategory);
placeStickersButton = _ourCategory.AddButton("Place Stickers", "Stickers-magic-wand", "Place stickers via raycast.", ButtonStyle.TextWithIcon); _placeStickersButton = _ourCategory.AddButton("Place Stickers", "Stickers-magic-wand", "Place stickers via raycast.", ButtonStyle.TextWithIcon);
placeStickersButton.OnPress += OnPlaceStickersButtonClick; _placeStickersButton.OnPress += OnPlaceStickersButtonClick;
Button clearSelfStickersButton = _ourCategory.AddButton("Clear Self", "Stickers-eraser", "Clear own stickers.", ButtonStyle.TextWithIcon); Button clearSelfStickersButton = _ourCategory.AddButton("Clear Self", "Stickers-eraser", "Clear own stickers.", ButtonStyle.TextWithIcon);
clearSelfStickersButton.OnPress += OnClearSelfStickersButtonClick; clearSelfStickersButton.OnPress += OnClearSelfStickersButtonClick;
@ -62,17 +62,16 @@ public static partial class BTKUIAddon
{ {
if (!_isOurTabOpened) return; if (!_isOurTabOpened) return;
if (StickerSystem.RestrictedInstance == false) if (StickerSystem.Instance.IsRestrictedInstance)
{ {
QuickMenuAPI.ShowAlertToast("Stickers are not allowed in this world!", 2);
return;
}
string mode = StickerSystem.Instance.IsInStickerMode ? "Exiting" : "Entering"; string mode = StickerSystem.Instance.IsInStickerMode ? "Exiting" : "Entering";
QuickMenuAPI.ShowAlertToast($"{mode} sticker placement mode...", 2); QuickMenuAPI.ShowAlertToast($"{mode} sticker placement mode...", 2);
StickerSystem.Instance.IsInStickerMode = !StickerSystem.Instance.IsInStickerMode; StickerSystem.Instance.IsInStickerMode = !StickerSystem.Instance.IsInStickerMode;
} }
else
{
QuickMenuAPI.ShowAlertToast("Stickers are not allowed in this world!", 2);
}
}
private static void OnClearSelfStickersButtonClick() private static void OnClearSelfStickersButtonClick()
{ {
@ -95,28 +94,25 @@ public static partial class BTKUIAddon
StickerSystem.OpenStickersFolder(); StickerSystem.OpenStickersFolder();
} }
public static void UpdateStickerMenu() //TODO: add Icon changing, Bono needs to expose the value first. public static void OnStickerRestrictionUpdated(bool isRestricted = false) //TODO: add Icon changing, Bono needs to expose the value first.
{ {
if (StickerSystem.RestrictedInstance == true) if (isRestricted)
{ {
_rootPage.MenuSubtitle = "Stickers... are sadly disabled in this world."; _rootPage.MenuSubtitle = "Stickers... are sadly disabled in this world.";
placeStickersButton.Disabled = true; _placeStickersButton.Disabled = true;
placeStickersButton.ButtonText = "Stickers Disabled"; _placeStickersButton.ButtonText = "Stickers Disabled";
placeStickersButton.ButtonTooltip = "This world is not allowing Stickers."; _placeStickersButton.ButtonTooltip = "This world is not allowing Stickers.";
placeStickersButton.ButtonIcon = "Stickers-magic-wand-broken"; _placeStickersButton.ButtonIcon = "Stickers-magic-wand-broken";
return;
} }
else
{
_rootPage.MenuSubtitle = "Stickers! Double-click the tab to quickly toggle Sticker Mode."; _rootPage.MenuSubtitle = "Stickers! Double-click the tab to quickly toggle Sticker Mode.";
placeStickersButton.Disabled = false; _placeStickersButton.Disabled = false;
placeStickersButton.ButtonText = "Place Stickers"; _placeStickersButton.ButtonText = "Place Stickers";
placeStickersButton.ButtonTooltip = "Place stickers via raycast."; _placeStickersButton.ButtonTooltip = "Place stickers via raycast.";
placeStickersButton.ButtonIcon = "Stickers-magic-wand"; _placeStickersButton.ButtonIcon = "Stickers-magic-wand";
}
} }
#endregion Button Actions #endregion Button Actions

View file

@ -25,27 +25,33 @@ public static partial class BTKUIAddon
private static void Setup_Icons() private static void Setup_Icons()
{ {
Assembly assembly = Assembly.GetExecutingAssembly();
string assemblyName = assembly.GetName().Name;
// All icons used - https://www.flaticon.com/authors/gohsantosadrive // All icons used - https://www.flaticon.com/authors/gohsantosadrive
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-alphabet", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-alphabet.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-alphabet", GetIconStream("Gohsantosadrive_Icons.Stickers-alphabet.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-eraser", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-eraser.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-eraser", GetIconStream("Gohsantosadrive_Icons.Stickers-eraser.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-folder", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-folder.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-folder", GetIconStream("Gohsantosadrive_Icons.Stickers-folder.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-headset", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-headset.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-headset", GetIconStream("Gohsantosadrive_Icons.Stickers-headset.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magnifying-glass", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-magnifying-glass.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magnifying-glass", GetIconStream("Gohsantosadrive_Icons.Stickers-magnifying-glass.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-magic-wand.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand", GetIconStream("Gohsantosadrive_Icons.Stickers-magic-wand.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand-broken", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-magic-wand-broken.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand-broken", GetIconStream("Gohsantosadrive_Icons.Stickers-magic-wand-broken.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-mouse", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-mouse.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-mouse", GetIconStream("Gohsantosadrive_Icons.Stickers-mouse.png"));
//QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-pencil", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-pencil.png")); //QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-pencil", GetIconStream("Gohsantosadrive_Icons.Stickers-pencil.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-puzzle.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle", GetIconStream("Gohsantosadrive_Icons.Stickers-puzzle.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle-disabled", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-puzzle-disabled.png")); //Disabled Sticker Puzzle QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle-disabled", GetIconStream("Gohsantosadrive_Icons.Stickers-puzzle-disabled.png")); // disabled Sticker Puzzle
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-rubbish-bin", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-rubbish-bin.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-rubbish-bin", GetIconStream("Gohsantosadrive_Icons.Stickers-rubbish-bin.png"));
return;
Stream GetIconStream(string iconName) => assembly.GetManifestResourceStream($"{assemblyName}.Resources.{iconName}");
} }
private static void Setup_StickerModTab() private static void Setup_StickerModTab()
{ {
_rootPage = new Page(ModSettings.ModName, ModSettings.SM_SettingsCategory, true, "Stickers-Puzzle") //Sticker Icon will be left blank as it is updated on world join, AFTER Icon value is exposed.. _rootPage = new Page(ModSettings.ModName, ModSettings.SM_SettingsCategory, true, "Stickers-Puzzle") // sticker icon will be left blank as it is updated on world join, AFTER Icon value is exposed..
{ {
MenuTitle = ModSettings.SM_SettingsCategory, MenuTitle = ModSettings.SM_SettingsCategory,
MenuSubtitle = "", //Left this blank as it is defined when the world loads MenuSubtitle = "", // left this blank as it is defined when the world loads
}; };
_rootPageElementID = _rootPage.ElementID; _rootPageElementID = _rootPage.ElementID;
@ -91,10 +97,7 @@ public static partial class BTKUIAddon
{ {
default: default:
case TabDoubleClick.ToggleStickerMode: case TabDoubleClick.ToggleStickerMode:
if (StickerSystem.RestrictedInstance == false)
{
OnPlaceStickersButtonClick(); OnPlaceStickersButtonClick();
}
break; break;
case TabDoubleClick.ClearAllStickers: case TabDoubleClick.ClearAllStickers:
OnClearAllStickersButtonClick(); OnClearAllStickersButtonClick();

View file

@ -23,10 +23,10 @@ public class StickerMod : MelonMod
ModSettings.Initialize(); ModSettings.Initialize();
StickerSystem.Initialize(); StickerSystem.Initialize();
ApplyPatches(typeof(Patches.PlayerSetupPatches)); ApplyPatches(typeof(Patches.PlayerSetup_Patches));
ApplyPatches(typeof(Patches.ControllerRayPatches)); ApplyPatches(typeof(Patches.ControllerRay_Patches));
ApplyPatches(typeof(Patches.ShaderFilterHelperPatches)); ApplyPatches(typeof(Patches.ShaderFilterHelper_Patches));
ApplyPatches(typeof(Patches.CVRToolsPatches)); ApplyPatches(typeof(Patches.CVRTools_Patches));
LoadAssetBundle(); LoadAssetBundle();
@ -38,17 +38,10 @@ public class StickerMod : MelonMod
if (StickerSystem.Instance == null) if (StickerSystem.Instance == null)
return; return;
if (!MetaPort.Instance.isUsingVr
&& StickerSystem.Instance.IsInStickerMode)
{
if (Input.mouseScrollDelta.y != 0f if (Input.mouseScrollDelta.y != 0f
&& Cursor.lockState == CursorLockMode.Locked // prevent scrolling while in menus && Cursor.lockState == CursorLockMode.Locked // prevent scrolling while in menus
&& !CVRInputManager.Instance.zoom) // prevent scrolling while using scroll zoom && !CVRInputManager.Instance.zoom) // prevent scrolling while using scroll zoom
{
StickerSystem.Instance.SelectedStickerSlot += (int)Input.mouseScrollDelta.y; StickerSystem.Instance.SelectedStickerSlot += (int)Input.mouseScrollDelta.y;
}
StickerSystem.Instance.PlaceStickerFromControllerRay(PlayerSetup.Instance.activeCam.transform, CVRHand.Left, true);
}
StickerSystem.Instance.UpdateStickerPreview(); // flashy flash StickerSystem.Instance.UpdateStickerPreview(); // flashy flash
@ -58,6 +51,9 @@ public class StickerMod : MelonMod
if (!Input.GetKeyDown((KeyCode)ModSettings.Entry_PlaceBinding.Value)) if (!Input.GetKeyDown((KeyCode)ModSettings.Entry_PlaceBinding.Value))
return; return;
if (CVRInputManager.Instance.textInputFocused)
return; // prevent placing stickers while typing
StickerSystem.Instance.PlaceStickerFromControllerRay(PlayerSetup.Instance.activeCam.transform); StickerSystem.Instance.PlaceStickerFromControllerRay(PlayerSetup.Instance.activeCam.transform);
} }

View file

@ -8,7 +8,7 @@ using UnityEngine;
namespace NAK.Stickers.Patches; namespace NAK.Stickers.Patches;
internal static class PlayerSetupPatches internal static class PlayerSetup_Patches
{ {
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.GetCurrentPropSelectionMode))] [HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.GetCurrentPropSelectionMode))]
@ -18,7 +18,7 @@ internal static class PlayerSetupPatches
} }
} }
internal static class ControllerRayPatches internal static class ControllerRay_Patches
{ {
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(ControllerRay), nameof(ControllerRay.HandlePropSpawn))] [HarmonyPatch(typeof(ControllerRay), nameof(ControllerRay.HandlePropSpawn))]
@ -37,7 +37,7 @@ internal static class ControllerRayPatches
} }
} }
internal static class ShaderFilterHelperPatches internal static class ShaderFilterHelper_Patches
{ {
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(ShaderFilterHelper), nameof(ShaderFilterHelper.SetupFilter))] [HarmonyPatch(typeof(ShaderFilterHelper), nameof(ShaderFilterHelper.SetupFilter))]
@ -51,7 +51,7 @@ internal static class ShaderFilterHelperPatches
} }
} }
internal static class CVRToolsPatches internal static class CVRTools_Patches
{ {
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(CVRTools), nameof(CVRTools.ReplaceShaders), typeof(Material), typeof(string))] [HarmonyPatch(typeof(CVRTools), nameof(CVRTools.ReplaceShaders), typeof(Material), typeof(string))]

View file

@ -32,6 +32,10 @@
<EmbeddedResource Include="Resources\Gohsantosadrive_Icons\Stickers-magnifying-glass.png" /> <EmbeddedResource Include="Resources\Gohsantosadrive_Icons\Stickers-magnifying-glass.png" />
<None Remove="Resources\Gohsantosadrive_Icons\Stickers-mouse.png" /> <None Remove="Resources\Gohsantosadrive_Icons\Stickers-mouse.png" />
<EmbeddedResource Include="Resources\Gohsantosadrive_Icons\Stickers-mouse.png" /> <EmbeddedResource Include="Resources\Gohsantosadrive_Icons\Stickers-mouse.png" />
<None Remove="Resources\Gohsantosadrive_Icons\Stickers-puzzle-disabled.png" />
<EmbeddedResource Include="Resources\Gohsantosadrive_Icons\Stickers-puzzle-disabled.png" />
<None Remove="Resources\Gohsantosadrive_Icons\Stickers-magic-wand-broken.png" />
<EmbeddedResource Include="Resources\Gohsantosadrive_Icons\Stickers-magic-wand-broken.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="BTKUILib"> <Reference Include="BTKUILib">

View file

@ -1,7 +1,4 @@
using ABI_RC.Core.Util.AnimatorManager; namespace NAK.Stickers.Networking;
using NAK.Stickers.Properties;
namespace NAK.Stickers.Networking;
public static partial class ModNetwork public static partial class ModNetwork
{ {
@ -9,7 +6,7 @@ public static partial class ModNetwork
internal const int MaxTextureSize = 1024 * 256; // 256KB internal const int MaxTextureSize = 1024 * 256; // 256KB
private const string NetworkVersion = "1.0.2"; // change each time network protocol changes private const string NetworkVersion = "1.0.3"; // change each time network protocol changes
private const string ModId = $"MelonMod.NAK.Stickers_v{NetworkVersion}"; private const string ModId = $"MelonMod.NAK.Stickers_v{NetworkVersion}";
private const int ChunkSize = 1024; // roughly 1KB per ModNetworkMessage private const int ChunkSize = 1024; // roughly 1KB per ModNetworkMessage
private const int MaxChunkCount = MaxTextureSize / ChunkSize; private const int MaxChunkCount = MaxTextureSize / ChunkSize;

View file

@ -43,7 +43,8 @@ public static partial class ModNetwork
if (ModSettings.Entry_FriendsOnly.Value && !Friends.FriendsWith(sender)) if (ModSettings.Entry_FriendsOnly.Value && !Friends.FriendsWith(sender))
return false; // ignore messages from non-friends if friends only is enabled return false; // ignore messages from non-friends if friends only is enabled
if (StickerSystem.RestrictedInstance == true) // ignore messages from users when the world is restricted. This also includes older or modified version of Stickers mod.
if (StickerSystem.Instance.IsRestrictedInstance) // ignore messages from users when the world is restricted. This also includes older or modified version of Stickers mod.
return false; return false;
return true; return true;

View file

@ -69,16 +69,16 @@ namespace NAK.Stickers
} }
} }
public Guid GetTextureHash(int spawnerIndex = 0) // public Guid GetTextureHash(int spawnerIndex = 0)
{ // {
if (spawnerIndex < 0 || spawnerIndex >= _decalSpawners.Length) // if (spawnerIndex < 0 || spawnerIndex >= _decalSpawners.Length)
{ // {
StickerMod.Logger.Warning("Invalid spawner index!"); // StickerMod.Logger.Warning("Invalid spawner index!");
return Guid.Empty; // return Guid.Empty;
} // }
//
return _textureHashes[spawnerIndex]; // return _textureHashes[spawnerIndex];
} // }
public bool CheckHasTextureHash(Guid textureHash) public bool CheckHasTextureHash(Guid textureHash)
{ {
@ -132,7 +132,7 @@ namespace NAK.Stickers
Transform rootObject = null; Transform rootObject = null;
GameObject hitGO = hit.transform.gameObject; GameObject hitGO = hit.transform.gameObject;
if (hitGO.scene.buildIndex == 4 // additive (dynamic) content if (hitGO.scene.buildIndex == 4 // additive (dynamic) content
|| hitGO.TryGetComponent(out Animator _) // potentially movable || hitGO.GetComponentInParent<Animator>() != null // potentially movable
|| hitGO.GetComponentInParent<Rigidbody>() != null) // movable || hitGO.GetComponentInParent<Rigidbody>() != null) // movable
rootObject = hitGO.transform; rootObject = hitGO.transform;
@ -244,21 +244,18 @@ namespace NAK.Stickers
if (_previewDecalSpawner == null) if (_previewDecalSpawner == null)
return; // uh fuck return; // uh fuck
// clear previous
ClearPreview();
// place at hit pos // place at hit pos
Transform rootObject = null; Transform rootObject = null;
GameObject hitGO = hit.transform.gameObject; GameObject hitGO = hit.transform.gameObject;
if (hitGO.scene.buildIndex == 4 || hitGO.TryGetComponent(out Animator _) || hitGO.GetComponentInParent<Rigidbody>() != null) if (hitGO.scene.buildIndex == 4 // additive (dynamic) content
|| hitGO.GetComponentInParent<Animator>() != null // potentially movable
|| hitGO.GetComponentInParent<Rigidbody>() != null) // movable
rootObject = hitGO.transform; rootObject = hitGO.transform;
Vector3 position = hit.point; _previewDecalSpawner.AddDecal(
_previewDecalSpawner.AddDecal(position, hit.point, Quaternion.LookRotation(forwardDirection, upDirection),
Quaternion.LookRotation(forwardDirection, upDirection),
hitGO, hitGO,
DECAL_SIZE, DECAL_SIZE, 1f, 1f, 0f, DECAL_SIZE, DECAL_SIZE, 1f, 1f, 0f, rootObject);
rootObject);
} }
public void UpdatePreview(int spawnerIndex) public void UpdatePreview(int spawnerIndex)

View file

@ -17,8 +17,6 @@ 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()
@ -45,8 +43,9 @@ public partial class StickerSystem
private void OnPlayerSetupStart() private void OnPlayerSetupStart()
{ {
CVRGameEventSystem.World.OnUnload.AddListener(_ => OnWorldUnload()); // TODO: this can be spammed by world author toggling CVRWorld.enabled state
CVRGameEventSystem.World.OnLoad.AddListener(_ => OnWorldLoad()); CVRGameEventSystem.World.OnLoad.AddListener(_ => OnWorldLoad());
CVRGameEventSystem.World.OnUnload.AddListener(_ => OnWorldUnload());
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);
@ -61,30 +60,21 @@ 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() private void OnWorldLoad()
{ {
GameObject StickerWorldRestriction = GameObject.Find("[DisableStickers]"); IsRestrictedInstance = GameObject.Find("[DisableStickers]") != null;
if (StickerWorldRestriction != null) if (IsRestrictedInstance) StickerMod.Logger.Msg("Stickers are restricted by the world author.");
{ BTKUIAddon.OnStickerRestrictionUpdated(IsRestrictedInstance);
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; IsRestrictedInstance = false;
CleanupAllButSelf(); // release all stickers except for self CleanupAllButSelf();
} }
#endregion Game Events #endregion Game Events
@ -107,6 +97,8 @@ public partial class StickerSystem
// } // }
// } // }
public bool IsRestrictedInstance { get; internal set; }
private string SelectedStickerName => ModSettings.Hidden_SelectedStickerNames.Value[_selectedStickerSlot]; private string SelectedStickerName => ModSettings.Hidden_SelectedStickerNames.Value[_selectedStickerSlot];
private const float StickerKillTime = 30f; private const float StickerKillTime = 30f;
@ -131,7 +123,7 @@ public partial class StickerSystem
get => _isInStickerMode; get => _isInStickerMode;
set set
{ {
_isInStickerMode = value; _isInStickerMode = value && !IsRestrictedInstance; // ensure cannot enter when restricted
if (_isInStickerMode) if (_isInStickerMode)
{ {
CohtmlHud.Instance.SelectPropToSpawn( CohtmlHud.Instance.SelectPropToSpawn(

View file

@ -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, RestrictedInstance)) if (!AttemptPlaceSticker(PlayerLocalId, position, forward, up, alignWithNormal, SelectedStickerSlot))
return false; // failed return false; // failed
// placed, now network // placed, now network
@ -59,8 +59,12 @@ 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 RestrictedInstance = false, bool isPreview = false) private bool AttemptPlaceSticker(string playerId, Vector3 position, Vector3 forward, Vector3 up, bool alignWithNormal = true, int stickerSlot = 0, bool isPreview = false)
{ {
// if the world contained a gameobject with the [DisableStickers] name and restricted the instance disable stickers!
if (IsRestrictedInstance)
return false;
StickerData stickerData = GetOrCreateStickerData(playerId); StickerData stickerData = GetOrCreateStickerData(playerId);
if (Time.time - stickerData.LastPlacedTime < StickerCooldown) if (Time.time - stickerData.LastPlacedTime < StickerCooldown)
return false; return false;
@ -75,10 +79,6 @@ 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);
@ -181,6 +181,7 @@ public partial class StickerSystem
if (!IsInStickerMode) return; if (!IsInStickerMode) return;
StickerData localStickerData = GetOrCreateStickerData(PlayerLocalId); StickerData localStickerData = GetOrCreateStickerData(PlayerLocalId);
localStickerData.ClearPreview(); // clear prior frames sticker preview
localStickerData.UpdatePreview(SelectedStickerSlot); localStickerData.UpdatePreview(SelectedStickerSlot);
} }

View file

@ -1,11 +1,11 @@
{ {
"_id": 232, "_id": 232,
"name": "Stickers", "name": "Stickers",
"modversion": "1.0.6", "modversion": "1.0.8",
"gameversion": "2024r175", "gameversion": "2024r177",
"loaderversion": "0.6.1", "loaderversion": "0.6.1",
"modtype": "Mod", "modtype": "Mod",
"author": "NotAKidoS", "author": "NotAKidoS, SketchFoxsky",
"description": "Stickers! Allows you to place small images on any surface. Requires both users to have the mod installed. Synced over Mod Network.\n\nLimitations:\n- Image should be under 256KB in size.\n- Image dimensions should be a power of 2 (e.g. 512x512, 1024x1024).\n - If the image exceeds the size limit or is not a power of 2 the mod will automatically resize it.\n - The automatic resizing may result in loss of quality (or may just fail), so it is recommended to resize the image yourself before placing it in the `UserData/Stickers/` folder.\n\n-# More information can be found on the [README](https://github.com/NotAKidoS/NAK_CVR_Mods/blob/main/Stickers/README.md).", "description": "Stickers! Allows you to place small images on any surface. Requires both users to have the mod installed. Synced over Mod Network.\n\nLimitations:\n- Image should be under 256KB in size.\n- Image dimensions should be a power of 2 (e.g. 512x512, 1024x1024).\n - If the image exceeds the size limit or is not a power of 2 the mod will automatically resize it.\n - The automatic resizing may result in loss of quality (or may just fail), so it is recommended to resize the image yourself before placing it in the `UserData/Stickers/` folder.\n\n-# More information can be found on the [README](https://github.com/NotAKidoS/NAK_CVR_Mods/blob/main/Stickers/README.md).",
"searchtags": [ "searchtags": [
"stickers", "stickers",
@ -16,8 +16,8 @@
"requirements": [ "requirements": [
"None" "None"
], ],
"downloadlink": "https://github.com/NotAKidoS/NAK_CVR_Mods/releases/download/r40/Stickers.dll", "downloadlink": "https://github.com/NotAKidoS/NAK_CVR_Mods/releases/download/r41/Stickers.dll",
"sourcelink": "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/Stickers/", "sourcelink": "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/Stickers/",
"changelog": "- Added Friends Only setting.\n- Added button to clear sticker thumbnail cache.\n- Added Identify button to Player Selection page.\n- Added `[NoSticker]` GameObject name check. \n- Adjusted inbound network buffers to be cleared on initial connection to an instance.\n- Adjusted selecting a new image for a sticker slot to clear stickers in-scene for that slot.\n- Stripped all unused classes a bunch of other methods from decalery.\n - Completely removed Skinned Mesh Renderer support as it required running on CPU.\n - Most uploaded content is not marked as readable anyways (plus it crashed consistantly).\n- Fixed nullref spam when clearing stickers when sticker was already marked as dead.\n- Fixed issue where saving melon preferences would error due to null sticker selection.", "changelog": "- Added world restriction via `[DisableStickers]` GameObject (thx Sketch).\n- Added sticker placement preview.\n- Fixed stickers being hit by VR switch shader replacement.\n- Fixed Desktop Sticker placement bind firing when a text field was focused.",
"embedcolor": "#f61963" "embedcolor": "#f61963"
} }