From 057e2358af8c365052a6937b729ca37a701c8fe6 Mon Sep 17 00:00:00 2001 From: Sky Copeland Date: Thu, 22 May 2025 23:45:38 -0400 Subject: [PATCH] Updated for Stable & Expanded VAMP Usage --- Commands.cs | 2 +- GiveDrop.cs | 11 +++--- Patches/DateTimeSystem_Patch.cs | 60 +++++++++++++++---------------- Patches/InitializationPatches.cs | 17 --------- Patches/InitializePlayer_Patch.cs | 11 +++--- Patches/SpawnUnit_Patch.cs | 3 +- Plugin.cs | 11 +++--- README.md | 4 +-- SpiderKiller.csproj | 6 ++-- 9 files changed, 51 insertions(+), 74 deletions(-) delete mode 100644 Patches/InitializationPatches.cs diff --git a/Commands.cs b/Commands.cs index 6c276d1..8335099 100644 --- a/Commands.cs +++ b/Commands.cs @@ -36,7 +36,7 @@ public class SpiderRemover : CommandArgumentConverter()._ServerGameManager; - var inventoryResponse = serverGameManager.TryAddInventoryItem(recipient, guid, amount); + var inventoryResponse = ItemUtil.AddItemToInventory(recipient, guid, amount, out var _); #if DEBUG - _log.LogMessage($"AddItemToInventory: {inventoryResponse.Success}"); + _log.LogMessage($"AddItemToInventory: {inventoryResponse}"); #endif - return inventoryResponse.Success; + return inventoryResponse; } catch (Exception e) { diff --git a/Patches/DateTimeSystem_Patch.cs b/Patches/DateTimeSystem_Patch.cs index 9db42e9..bda08c9 100644 --- a/Patches/DateTimeSystem_Patch.cs +++ b/Patches/DateTimeSystem_Patch.cs @@ -13,6 +13,7 @@ using UnityEngine; using Stunlock.Core; using VAMP; +using VAMP.Data; namespace SpiderKiller.Patches; @@ -38,29 +39,29 @@ public class DateTimeSystem_Patch private static readonly HashSet BlockedPrefabGUIDs = new HashSet { - new PrefabGUID(-764515001), // CHAR_Spider_Baneling - new PrefabGUID(-1004061470), // CHAR_Spider_Baneling_Summon - new PrefabGUID(342127250), // CHAR_Spider_Broodmother - new PrefabGUID(-581295882), // CHAR_Spider_Forest - new PrefabGUID(574276383), // CHAR_Spider_Forestling - new PrefabGUID(2136899683), // CHAR_Spider_Melee - new PrefabGUID(-725251219), // CHAR_Spider_Melee_GateBoss_Summon - new PrefabGUID(2119230788), // CHAR_Spider_Melee_Summon - new PrefabGUID(-548489519), // CHAR_Spider_Queen_VBlood - new PrefabGUID(-943858353), // CHAR_Spider_Queen_VBlood_GateBoss_Major - new PrefabGUID(2103131615), // CHAR_Spider_Range - new PrefabGUID(1974733695), // CHAR_Spider_Range_Summon - new PrefabGUID(1078424589), // CHAR_Spider_Spiderling - new PrefabGUID(1767714956), // CHAR_Spider_Spiderling_VerminNest - new PrefabGUID(-18289884) // CHAR_Spiderling_Summon + Prefabs.CHAR_Spider_Baneling, + Prefabs.CHAR_Spider_Baneling_Summon, + Prefabs.CHAR_Spider_Broodmother, + Prefabs.CHAR_Spider_Forest, + Prefabs.CHAR_Spider_Forestling, + Prefabs.CHAR_Spider_Melee, + Prefabs.CHAR_Spider_Melee_GateBoss_Summon, + Prefabs.CHAR_Spider_Melee_Summon, + Prefabs.CHAR_Spider_Queen_VBlood, + Prefabs.CHAR_Spider_Queen_VBlood_GateBoss_Major, + Prefabs.CHAR_Spider_Range, + Prefabs.CHAR_Spider_Range_Summon, + Prefabs.CHAR_Spider_Spiderling, + Prefabs.CHAR_Spider_Spiderling_VerminNest, + Prefabs.CHAR_Spiderling_Summon }; private static readonly HashSet ReplacementPrefabGUIDs = new HashSet { - new PrefabGUID(-744966291), // CHAR_Cursed_Mosquito - new PrefabGUID(-218175217), // CHAR_Cursed_Wolf - new PrefabGUID(-2072914343), // CHAR_Critter_Rat - new PrefabGUID(-559819989) // CHAR_Cursed_Bear_Standard + Prefabs.CHAR_Cursed_Mosquito, + Prefabs.CHAR_Cursed_Wolf, + Prefabs.CHAR_Critter_Rat, + Prefabs.CHAR_Cursed_Bear_Standard }; public static void Prefix(DateTimeSystem __instance) @@ -75,9 +76,9 @@ public static void Prefix(DateTimeSystem __instance) } _noUpdateBefore = DateTime.Now.AddSeconds(Settings.CULL_WAIT_TIME.Value); - if (!Plugin.HasInitialized) return; - EntityManager em = Core.Server.EntityManager; - EntityQuery querySpawnRegion = Core.Server.EntityManager.CreateEntityQuery(new EntityQueryDesc + if (!Core.hasInitialized) return; + EntityManager em = Core.EntityManager; + EntityQuery querySpawnRegion = em.CreateEntityQuery(new EntityQueryDesc { All = new[] { ComponentType.ReadOnly() }, Any = new[] { ComponentType.ReadOnly(), ComponentType.ReadOnly() }, @@ -85,7 +86,7 @@ public static void Prefix(DateTimeSystem __instance) }); foreach (Entity spawnRegion in querySpawnRegion.ToEntityArray(Allocator.Temp)) { - if (Core.Server.EntityManager.TryGetBuffer(spawnRegion, out var spawnSlotEntries)) + if (em.TryGetBuffer(spawnRegion, out var spawnSlotEntries)) { for (int i = 0; i < spawnSlotEntries.Length; i++) { @@ -95,23 +96,23 @@ public static void Prefix(DateTimeSystem __instance) Plugin.LogInstance.LogMessage($"[spawnSlotEntries] current {entry.Entity.GetPrefabGuidNameString()} has spawned?: {entry.HasSpawned}"); #endif var prefabGUID = ReplacementPrefabGUIDs.ElementAt(UnityEngine.Random.Range(0, ReplacementPrefabGUIDs.Count)); - var prefabEntity = EntityQueryHelper.QueryEntityWithPrefabGUID(Core.Server.EntityManager, prefabGUID.GuidHash); + var prefabEntity = EntityQueryHelper.QueryEntityWithPrefabGUID(em, prefabGUID.GuidHash); if (prefabEntity == Entity.Null) continue; #if DEBUG Plugin.LogInstance.LogMessage($"[spawnSlotEntries] with {prefabGUID.GetNamefromPrefabGuid()}"); #endif - entry.Entity = Core.Server.EntityManager.Instantiate(prefabEntity); + entry.Entity = em.Instantiate(prefabEntity); spawnSlotEntries[i] = entry; } } - if (!Core.Server.EntityManager.TryGetBuffer(spawnRegion, out var spawnGroupBuffer)) + if (!em.TryGetBuffer(spawnRegion, out var spawnGroupBuffer)) continue; foreach (var group in spawnGroupBuffer) { - if (!Core.Server.EntityManager.TryGetBuffer(group.SpawnGroup, + if (!em.TryGetBuffer(group.SpawnGroup, out var spawnTableBuffer)) continue; for (int i = 0; i < spawnTableBuffer.Length; i++) @@ -143,8 +144,7 @@ public static void Prefix(DateTimeSystem __instance) var player = em.GetEntityByEntityIndex(playerIndex); if (Settings.CULL_QUEEN.Value) { - var dayNightCycle = Core.Server.GetExistingSystemManaged()._ServerGameManager - .DayNightCycle; + var dayNightCycle = Core.ServerGameManager.DayNightCycle; var now = dayNightCycle.GameDateTimeNow; double dayDurationInSeconds = dayNightCycle.DayDurationInSeconds; double secondsPerInGameHour = dayDurationInSeconds / 24; @@ -226,7 +226,7 @@ private static void KillSpider(Entity spider, Entity player) DoNotDestroy = false }; var deathReason = new DeathReason(); - DeathUtilities.Kill(Core.Server.EntityManager, spider, dead, deathEvent, deathReason); + DeathUtilities.Kill(Core.EntityManager, spider, dead, deathEvent, deathReason); // Destroys the entity without giving any drops // DestroyUtility.CreateDestroyEvent(Core.Server.EntityManager, spider, DestroyReason.Default, DestroyDebugReason.None); } diff --git a/Patches/InitializationPatches.cs b/Patches/InitializationPatches.cs deleted file mode 100644 index 06ab8cb..0000000 --- a/Patches/InitializationPatches.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Reflection; -using HarmonyLib; -using ProjectM; - -namespace SpiderKiller.Patches -{ - [HarmonyPatch(typeof(SpawnTeamSystem_OnPersistenceLoad), "OnUpdate")] - public static class InitializationPatch - { - [HarmonyPostfix] - public static void OneShot_AfterLoad_InitializationPatch() - { - Plugin.Harmony.Unpatch((MethodBase) typeof (SpawnTeamSystem_OnPersistenceLoad).GetMethod("OnUpdate"), typeof (InitializationPatch).GetMethod(nameof (OneShot_AfterLoad_InitializationPatch))); - Plugin.Initialize(); - } - } -} \ No newline at end of file diff --git a/Patches/InitializePlayer_Patch.cs b/Patches/InitializePlayer_Patch.cs index e993ae1..ffc2467 100644 --- a/Patches/InitializePlayer_Patch.cs +++ b/Patches/InitializePlayer_Patch.cs @@ -20,13 +20,10 @@ public static void OnUserConnected_Patch(ServerBootstrapSystem __instance, NetCo try { //RespawnAi(Entity fromCharacter, RespawnAiDebugEvent clientEvent); - - var userIndex = Core.Server.GetExistingSystemManaged() - ._NetEndPointToApprovedUserIndex[netConnectionId]; - var serverClient = Core.Server.GetExistingSystemManaged() - ._ApprovedUsersLookup[userIndex]; + var userIndex = __instance._NetEndPointToApprovedUserIndex[netConnectionId]; + var serverClient = __instance._ApprovedUsersLookup[userIndex]; var userEntity = serverClient.UserEntity; - var user = Core.Server.EntityManager.GetComponentData(userEntity); + var user = Core.EntityManager.GetComponentData(userEntity); var player = user.LocalCharacter.GetEntityOnServer(); if (Settings.ENABLE_UNGORA_UNLOCK.Value) // unlock Ungora progression if enabled @@ -34,7 +31,7 @@ public static void OnUserConnected_Patch(ServerBootstrapSystem __instance, NetCo UnlockVBlood debugEvent = new UnlockVBlood(); debugEvent.VBlood = new PrefabGUID(-548489519); UnlockProgressionDebugEvent evt = new UnlockProgressionDebugEvent(); - DebugEventsSystem debugEventsSystem = Core.Server.GetExistingSystemManaged(); + DebugEventsSystem debugEventsSystem = Core.SystemService.DebugEventsSystem; evt.PrefabGuid = new PrefabGUID(574648849); debugEventsSystem.UnlockProgression( diff --git a/Patches/SpawnUnit_Patch.cs b/Patches/SpawnUnit_Patch.cs index 8b3ae96..d4efb26 100644 --- a/Patches/SpawnUnit_Patch.cs +++ b/Patches/SpawnUnit_Patch.cs @@ -4,6 +4,7 @@ using HarmonyLib; using ProjectM; using Unity.Entities; +using VAMP; namespace SpiderKiller.Patches; @@ -38,7 +39,7 @@ static bool Prefix(Entity stationEntity, PrefabGUID prefabGuid, float3 spawnBase // Check if the PrefabGUID is in the blocked list return !BlockedPrefabGUIDs.Contains(prefabGuid); #if DEBUG - String name = Core.Server.GetExistingSystemManaged()._PrefabLookupMap.GetName(prefabGuid); + string name = Core.Server.GetExistingSystemManaged()._PrefabLookupMap.GetName(prefabGuid); Plugin.LogInstance.LogMessage($"Blocked spawning of PrefabGUID: {prefabGuid} name: {name}"); #endif } diff --git a/Plugin.cs b/Plugin.cs index dad60df..0c9447e 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -9,12 +9,12 @@ namespace SpiderKiller; [BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] +[BepInDependency("VAMP")] [BepInDependency("gg.deca.VampireCommandFramework", BepInDependency.DependencyFlags.SoftDependency)] public class Plugin : BasePlugin { public static Harmony Harmony; - public static bool HasInitialized = false; public static ManualLogSource LogInstance { get; private set; } public override void Load() @@ -26,17 +26,18 @@ public override void Load() if (Application.productName == "VRising") { Log.LogWarning("This plugin is a server-only plugin!"); + return; } + + VAMP.Events.OnCoreLoaded += Initialize; } - public static void Initialize() + private static void Initialize() { if (Application.productName == "VRising") { return; } - if (HasInitialized) - return; LogInstance.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!"); @@ -49,8 +50,6 @@ public static void Initialize() { LogInstance.LogInfo("This mod has extra admin commands. Install VampireCommandFramework to use them."); } - - HasInitialized = true; } public override bool Unload() diff --git a/README.md b/README.md index 87fe042..f8a325f 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ Updated to 1.1 version of V Rising. ## Installation (Manual) -* Install [BepInEx](https://github.com/CrimsonMods/BepInEx/releases) +* Install [BepInEx](https://thunderstore.io/c/v-rising/p/BepInEx/BepInExPack_V_Rising/) * Install [VAMP](https://thunderstore.io/c/v-rising/p/skytech6/VAMP/) -* (optional) Install [VampireCommandFramework](https://github.com/decaprime/VampireCommandFramework/releases) into (VRising server folder)/BepInEx/plugins +* (optional) Install [VampireCommandFramework](https://thunderstore.io/c/v-rising/p/deca/VampireCommandFramework/) into (VRising server folder)/BepInEx/plugins * (optional) Install [ServerLaunchFix](https://v-rising.thunderstore.io/package/Mythic/ServerLaunchFix/) into (VRising server folder)/BepInEx/plugins * Extract _**KillSpiders.dll**_ into (VRising server folder)/BepInEx/plugins diff --git a/SpiderKiller.csproj b/SpiderKiller.csproj index 5b7bd2c..731b7ad 100644 --- a/SpiderKiller.csproj +++ b/SpiderKiller.csproj @@ -14,9 +14,9 @@ - - - + + +