feat(modloader): add item use and summon APIs

Add managed item use hooks, server-authoritative summon support, and side-aware use item context.

Include IdHelper mappings, example ruby wand usage, and related runtime/crash-handler updates.
This commit is contained in:
Jacobwasbeast
2026-03-07 19:54:52 -06:00
parent eabf8fe858
commit 0b4c87acbc
21 changed files with 1862 additions and 45 deletions

View File

@@ -1,5 +1,6 @@
using System.Runtime.InteropServices;
using WeaveLoader.API;
using WeaveLoader.API.Events;
using WeaveLoader.API.Item;
namespace WeaveLoader.Core;
@@ -106,4 +107,85 @@ public static class WeaveLoaderCore
return 0;
}
}
public static int OnItemUse(IntPtr args, int sizeBytes)
{
try
{
return ManagedItemDispatcher.HandleUseItem(args, sizeBytes);
}
catch (Exception ex)
{
Logger.Error($"OnItemUse EXCEPTION: {ex}");
return 0;
}
}
[StructLayout(LayoutKind.Sequential)]
private struct WorldLoadedNativeArgs
{
public IntPtr LevelPtr;
}
[StructLayout(LayoutKind.Sequential)]
private struct EntitySummonedNativeArgs
{
public int EntityNumericId;
public float X;
public float Y;
public float Z;
}
public static int OnWorldLoaded(IntPtr args, int sizeBytes)
{
try
{
var native = Marshal.PtrToStructure<WorldLoadedNativeArgs>(args);
GameEvents.FireWorldLoaded(new WorldLoadedEventArgs
{
NativeLevelPointer = native.LevelPtr
});
return 0;
}
catch (Exception ex)
{
Logger.Error($"OnWorldLoaded EXCEPTION: {ex}");
return 0;
}
}
public static int OnWorldUnloaded(IntPtr args, int sizeBytes)
{
try
{
GameEvents.FireWorldUnloaded(new WorldUnloadedEventArgs());
return 0;
}
catch (Exception ex)
{
Logger.Error($"OnWorldUnloaded EXCEPTION: {ex}");
return 0;
}
}
public static int OnEntitySummoned(IntPtr args, int sizeBytes)
{
try
{
var native = Marshal.PtrToStructure<EntitySummonedNativeArgs>(args);
GameEvents.FireEntitySpawn(new EntitySpawnEventArgs
{
EntityId = $"entity:{native.EntityNumericId}",
X = native.X,
Y = native.Y,
Z = native.Z
});
return 0;
}
catch (Exception ex)
{
Logger.Error($"OnEntitySummoned EXCEPTION: {ex}");
return 0;
}
}
}