Snapshot for release 2026.10.13.3 (internal c8b9b39)
This commit is contained in:
parent
401a8613cd
commit
67574b56e6
17 changed files with 894 additions and 18 deletions
125
src/RynthCore.PluginSdk/ObjectPropertyTypes.cs
Normal file
125
src/RynthCore.PluginSdk/ObjectPropertyTypes.cs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace RynthCore.PluginSdk;
|
||||
|
||||
// ─── Every property of an object (engine API v84) ──────────────────────────
|
||||
// RynthCoreHost.TryGetObjectProperties returns all the keys the engine holds for one object
|
||||
// (what UtilityBelt's propertydump lists from Decal's WorldObject), not one key at a time:
|
||||
//
|
||||
// if (Host.TryGetObjectProperties(id, out ObjectProperties p))
|
||||
// foreach (var kv in p.Ints) Log($"{kv.Key} = {kv.Value}");
|
||||
//
|
||||
// Item properties beyond the CreateObject basics only exist after an identify (RequestId):
|
||||
// check p.HasIdData. Asked off AC's main thread, the client's own qualities tables are read at
|
||||
// the next main-thread tick: when p.QualitiesPending is set, ask again ~0.2 s later.
|
||||
|
||||
/// <summary>What <see cref="ObjectProperties"/> was built from (the engine's record flags).</summary>
|
||||
[Flags]
|
||||
public enum ObjectPropertyFlags : ushort
|
||||
{
|
||||
None = 0,
|
||||
/// <summary>The server answered an identify (appraisal) for the object this session.</summary>
|
||||
HasIdData = 0x0001,
|
||||
/// <summary>The client's own qualities tables of the object were read in.</summary>
|
||||
QualitiesRead = 0x0002,
|
||||
/// <summary>A read of the client's qualities tables was requested for AC's next main-thread tick: ask again shortly.</summary>
|
||||
QualitiesPending = 0x0004,
|
||||
/// <summary>The object is the player's character.</summary>
|
||||
IsPlayer = 0x0008,
|
||||
/// <summary>The client's CreateObject copy of the object was read in.</summary>
|
||||
HasCreateData = 0x0010,
|
||||
}
|
||||
|
||||
/// <summary>Every property of one object, a dictionary per AC property type (keys are the AC/ACE property ids).</summary>
|
||||
public sealed class ObjectProperties
|
||||
{
|
||||
public const uint RecordMagic = 0x31445052; // "RPD1"
|
||||
public const ushort RecordVersion = 1;
|
||||
private const int HeaderSize = 20;
|
||||
private const byte KindInt = 0, KindInt64 = 1, KindBool = 2, KindFloat = 3, KindString = 4,
|
||||
KindDataId = 5, KindInstanceId = 6, KindSpell = 7;
|
||||
|
||||
public ObjectPropertyFlags Flags { get; private set; }
|
||||
/// <summary>Unix seconds of the last identify answer; 0 never.</summary>
|
||||
public long LastIdTime { get; private set; }
|
||||
|
||||
public bool HasIdData => (Flags & ObjectPropertyFlags.HasIdData) != 0;
|
||||
public bool QualitiesPending => (Flags & ObjectPropertyFlags.QualitiesPending) != 0;
|
||||
public bool IsPlayer => (Flags & ObjectPropertyFlags.IsPlayer) != 0;
|
||||
|
||||
public Dictionary<uint, int> Ints { get; } = new();
|
||||
public Dictionary<uint, long> Int64s { get; } = new();
|
||||
public Dictionary<uint, bool> Bools { get; } = new();
|
||||
public Dictionary<uint, double> Floats { get; } = new();
|
||||
public Dictionary<uint, string> Strings { get; } = new();
|
||||
/// <summary>Data ids (STypeDID: icons, setups, spell, ...).</summary>
|
||||
public Dictionary<uint, uint> DataIds { get; } = new();
|
||||
/// <summary>Instance ids (STypeIID: container, wielder, owner, monarch, ...).</summary>
|
||||
public Dictionary<uint, uint> InstanceIds { get; } = new();
|
||||
/// <summary>The spell book from the last identify, in its order.</summary>
|
||||
public List<uint> Spells { get; } = new();
|
||||
|
||||
public int Count => Ints.Count + Int64s.Count + Bools.Count + Floats.Count + Strings.Count
|
||||
+ DataIds.Count + InstanceIds.Count + Spells.Count;
|
||||
|
||||
/// <summary>
|
||||
/// Reads the engine's v84 record. False (and <paramref name="props"/> null) when it isn't
|
||||
/// one: wrong magic, a newer format, or an entry that runs past the end.
|
||||
/// </summary>
|
||||
public static bool TryParse(ReadOnlySpan<byte> rec, out ObjectProperties? props)
|
||||
{
|
||||
props = null;
|
||||
if (rec.Length < HeaderSize || BinaryPrimitives.ReadUInt32LittleEndian(rec) != RecordMagic)
|
||||
return false;
|
||||
if (BinaryPrimitives.ReadUInt16LittleEndian(rec.Slice(4)) != RecordVersion)
|
||||
return false;
|
||||
var p = new ObjectProperties
|
||||
{
|
||||
Flags = (ObjectPropertyFlags)BinaryPrimitives.ReadUInt16LittleEndian(rec.Slice(6)),
|
||||
LastIdTime = BinaryPrimitives.ReadInt64LittleEndian(rec.Slice(8)),
|
||||
};
|
||||
uint count = BinaryPrimitives.ReadUInt32LittleEndian(rec.Slice(16));
|
||||
int o = HeaderSize;
|
||||
for (uint i = 0; i < count; i++)
|
||||
{
|
||||
if (o + 5 > rec.Length) return false;
|
||||
byte kind = rec[o];
|
||||
uint key = BinaryPrimitives.ReadUInt32LittleEndian(rec.Slice(o + 1));
|
||||
o += 5;
|
||||
int need = kind switch
|
||||
{
|
||||
KindInt or KindDataId or KindInstanceId => 4,
|
||||
KindInt64 or KindFloat => 8,
|
||||
KindBool => 1,
|
||||
KindString => 2,
|
||||
KindSpell => 0,
|
||||
_ => -1,
|
||||
};
|
||||
if (need < 0 || o + need > rec.Length) return false;
|
||||
switch (kind)
|
||||
{
|
||||
case KindInt: p.Ints[key] = BinaryPrimitives.ReadInt32LittleEndian(rec.Slice(o)); break;
|
||||
case KindInt64: p.Int64s[key] = BinaryPrimitives.ReadInt64LittleEndian(rec.Slice(o)); break;
|
||||
case KindBool: p.Bools[key] = rec[o] != 0; break;
|
||||
case KindFloat: p.Floats[key] = BitConverter.Int64BitsToDouble(BinaryPrimitives.ReadInt64LittleEndian(rec.Slice(o))); break;
|
||||
case KindDataId: p.DataIds[key] = BinaryPrimitives.ReadUInt32LittleEndian(rec.Slice(o)); break;
|
||||
case KindInstanceId: p.InstanceIds[key] = BinaryPrimitives.ReadUInt32LittleEndian(rec.Slice(o)); break;
|
||||
case KindSpell: p.Spells.Add(key); break;
|
||||
case KindString:
|
||||
{
|
||||
int len = BinaryPrimitives.ReadUInt16LittleEndian(rec.Slice(o));
|
||||
if (o + 2 + len > rec.Length) return false;
|
||||
p.Strings[key] = Encoding.UTF8.GetString(rec.Slice(o + 2, len));
|
||||
o += 2 + len;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
o += need;
|
||||
}
|
||||
props = p;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -172,6 +172,8 @@ public struct RynthCoreApiNative
|
|||
// v83: ghost creatures (objects the client draws but the server no longer has for this player)
|
||||
public IntPtr GetObjectServerAgeFn; // int GetObjectServerAge(uint id) -> ms since the server's last message about it, -1 none
|
||||
public IntPtr RemoveClientObjectFn; // int RemoveClientObject(uint id) -> 1 removed, 2 queued, 0 refused, -1 unbound
|
||||
// v84: every property of an object (/ub propertydump), one record (ObjectProperties.TryParse)
|
||||
public IntPtr GetObjectPropertiesFn; // int GetObjectProperties(uint id, byte* buf, int size) -> record size (copied if <= size), 0 unknown, -1 bad args
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -176,6 +176,9 @@ public readonly unsafe struct RynthCoreHost
|
|||
|
||||
/// <summary>v83: <see cref="RemoveClientObject"/> (drop a ghost creature from the client).</summary>
|
||||
public bool HasRemoveClientObject => _api.Version >= 83 && _api.RemoveClientObjectFn != IntPtr.Zero;
|
||||
|
||||
/// <summary>v84: <see cref="TryGetObjectProperties"/> (every property of an object at once).</summary>
|
||||
public bool HasGetObjectProperties => _api.Version >= 84 && _api.GetObjectPropertiesFn != IntPtr.Zero;
|
||||
public bool HasGetPluginExportJson => _api.Version >= 66 && _api.GetPluginExportJsonFn != IntPtr.Zero;
|
||||
// Version-checked first: on an older engine the field lies past the end of its API table.
|
||||
public bool HasGetMergeStackResult => _api.Version >= 81 && _api.GetMergeStackResultFn != IntPtr.Zero;
|
||||
|
|
@ -1919,6 +1922,37 @@ public readonly unsafe struct RynthCoreHost
|
|||
? ((delegate* unmanaged[Cdecl]<uint, int>)_api.RemoveClientObjectFn)(objectId)
|
||||
: -2;
|
||||
|
||||
// ─── Every property of an object (API v84) ─────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// v84: every property the engine knows for <paramref name="objectId"/> (int, int64, bool,
|
||||
/// float, string, data id, instance id and the spell book), merged from the client's
|
||||
/// CreateObject copy, its qualities tables, the last identify and the server's property
|
||||
/// updates, the way the per-key reads (TryGetObjectIntProperty, ...) answer. False on an
|
||||
/// engine before v84 (fall back to per-key reads) or when the engine knows nothing about
|
||||
/// the object. Item details need an identify first (<see cref="RequestId"/>, then
|
||||
/// <see cref="ObjectProperties.HasIdData"/>). When <see cref="ObjectProperties.QualitiesPending"/>
|
||||
/// is set, the client's qualities tables are read at AC's next main-thread tick: ask again
|
||||
/// shortly. Any thread.
|
||||
/// </summary>
|
||||
public bool TryGetObjectProperties(uint objectId, out ObjectProperties? properties)
|
||||
{
|
||||
properties = null;
|
||||
if (!HasGetObjectProperties || objectId == 0) return false;
|
||||
var fn = (delegate* unmanaged[Cdecl]<uint, byte*, int, int>)_api.GetObjectPropertiesFn;
|
||||
byte[] buffer = new byte[8192];
|
||||
for (int attempt = 0; attempt < 4; attempt++)
|
||||
{
|
||||
int n;
|
||||
fixed (byte* p = buffer) n = fn(objectId, p, buffer.Length);
|
||||
if (n <= 0) return false;
|
||||
if (n <= buffer.Length)
|
||||
return ObjectProperties.TryParse(new ReadOnlySpan<byte>(buffer, 0, n), out properties);
|
||||
buffer = new byte[Math.Max(n + 1024, buffer.Length * 2)]; // grew between calls: some room
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int SalvageDirect(uint toolId, ReadOnlySpan<uint> itemIds)
|
||||
{
|
||||
if (!HasSalvageDirect) return -2;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<!-- The engine API this SDK knows; tools\PluginManifestTests checks it equals PluginContractVersion.Current. -->
|
||||
<RynthCoreSdkApiVersion>83</RynthCoreSdkApiVersion>
|
||||
<RynthCoreSdkApiVersion>84</RynthCoreSdkApiVersion>
|
||||
<_RynthPluginManifestOn Condition="'$(RynthPluginMinEngineApi)' != '' and '$(RynthPluginManifest)' != 'false'">true</_RynthPluginManifestOn>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue