mirror of
https://github.com/Jacobwasbeast/LegacyWeaveLoader.git
synced 2026-06-09 14:31:53 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user