From eb1bb5b6c2e441224ba27634609c7f5f1738370c Mon Sep 17 00:00:00 2001 From: Amber Date: Wed, 4 Jun 2025 09:44:24 -0400 Subject: [PATCH] Updated for 1.1 --- DataStore.cs | 13 +++++++------ ECSExtensions.cs | 14 +++----------- Killfeed.csproj | 9 ++++----- Plugin.cs | 2 -- VWorld.cs | 37 +++++++++++++++++++++++++++++++++++++ VampireDownedHook.cs | 1 - 6 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 VWorld.cs diff --git a/DataStore.cs b/DataStore.cs index 021ed45..ac118ca 100644 --- a/DataStore.cs +++ b/DataStore.cs @@ -3,7 +3,6 @@ using System.Globalization; using System.IO; using Backtrace.Unity.Common; -using Bloodstone.API; using Il2CppSystem.Linq; using ProjectM; using ProjectM.Network; @@ -245,13 +244,15 @@ private static void AnnounceKill(PlayerStatistics victimUser, PlayerStatistics k 25 => $"{killerName} is godlike!", 30 => $"{killerName} is WICKED SICK!", _ => null - }; - - ServerChatUtils.SendSystemMessageToAllClients(VWorld.Server.EntityManager, Markup.Prefix + message); + }; + + var announceMessage = new FixedString512Bytes(Markup.Prefix + message); + ServerChatUtils.SendSystemMessageToAllClients(VWorld.Server.EntityManager, ref announceMessage); if (!string.IsNullOrEmpty(killMsg) && Settings.AnnounceKillstreak) - { - ServerChatUtils.SendSystemMessageToAllClients(VWorld.Server.EntityManager, Markup.Prefix + killMsg); + { + var killMessage = new FixedString512Bytes(Markup.Prefix + killMsg); + ServerChatUtils.SendSystemMessageToAllClients(VWorld.Server.EntityManager, ref killMessage); } } diff --git a/ECSExtensions.cs b/ECSExtensions.cs index 61f219c..cd31cb9 100644 --- a/ECSExtensions.cs +++ b/ECSExtensions.cs @@ -1,6 +1,5 @@ using System; -using Bloodstone.API; using Il2CppInterop.Runtime; using Unity.Entities; @@ -12,18 +11,11 @@ #pragma warning disable CS8500 internal static class ECSExtensions { - internal static void With(this Entity entity, VExtensions.ActionRef action) where T : struct - { - T item = entity.RW(); - action(ref item); - VWorld.Game.EntityManager.SetComponentData(entity, item); - } - internal static bool Has(this Entity entity) where T : struct { int typeIndex = TypeManager.GetTypeIndex(Il2CppType.Of()); - return VWorld.Game.EntityManager.HasComponentRaw(entity, typeIndex); + return VWorld.Server.EntityManager.HasComponentRaw(entity, typeIndex); } internal static bool Has(this Entity entity, out T value) where T : struct @@ -41,7 +33,7 @@ internal static bool Has(this Entity entity, out T value) where T : struct internal unsafe static T RW(this Entity entity) where T : struct { int typeIndex = TypeManager.GetTypeIndex(Il2CppType.Of()); - T* componentDataRawRW = (T*)VWorld.Game.EntityManager.GetComponentDataRawRW(entity, typeIndex); + T* componentDataRawRW = (T*)VWorld.Server.EntityManager.GetComponentDataRawRW(entity, typeIndex); if (componentDataRawRW == null) { throw new InvalidOperationException($"Failure to access ReadWrite <{typeof(T).Name}> typeIndex({typeIndex}) on entity({entity})."); @@ -52,7 +44,7 @@ internal unsafe static T RW(this Entity entity) where T : struct internal unsafe static T Read(this Entity entity) where T : struct { int typeIndex = TypeManager.GetTypeIndex(Il2CppType.Of()); - T* componentDataRawRO = (T*)VWorld.Game.EntityManager.GetComponentDataRawRO(entity, typeIndex); + T* componentDataRawRO = (T*)VWorld.Server.EntityManager.GetComponentDataRawRO(entity, typeIndex); if (componentDataRawRO == null) { throw new InvalidOperationException($"Failure to access ReadOnly <{typeof(T).Name}> typeIndex({typeIndex}) on entity({entity})."); diff --git a/Killfeed.csproj b/Killfeed.csproj index 8e87079..85acfaa 100644 --- a/Killfeed.csproj +++ b/Killfeed.csproj @@ -15,11 +15,10 @@ - - + + - - - + + diff --git a/Plugin.cs b/Plugin.cs index 3d601e1..2391bbb 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -10,8 +10,6 @@ namespace Killfeed; [BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] [BepInDependency("gg.deca.VampireCommandFramework")] -[BepInDependency("gg.deca.Bloodstone")] -[Bloodstone.API.Reloadable] public partial class Plugin : BasePlugin { Harmony _harmony; diff --git a/VWorld.cs b/VWorld.cs new file mode 100644 index 0000000..9f6d994 --- /dev/null +++ b/VWorld.cs @@ -0,0 +1,37 @@ +using System; +using Unity.Entities; + +static class VWorld +{ + private static World? _serverWorld; + + + /// Extracted from bloodstone to make reintegrating bloodstone later easier if desired. + + public static World Server + { + get + { + if (_serverWorld != null && _serverWorld.IsCreated) + return _serverWorld; + + _serverWorld = GetWorld("Server") + ?? throw new System.Exception("There is no Server world (yet). Did you install a server mod on the client?"); + return _serverWorld; + } + } + private static World? GetWorld(string name) + { + foreach (var world in World.s_AllWorlds) + { + if (world.Name == name) + { + _serverWorld = world; + return world; + } + } + + return null; + } +} + diff --git a/VampireDownedHook.cs b/VampireDownedHook.cs index 6206d87..d72f5bc 100644 --- a/VampireDownedHook.cs +++ b/VampireDownedHook.cs @@ -1,5 +1,4 @@ using System; -using Bloodstone.API; using HarmonyLib; using ProjectM; using Unity.Collections;