Port the authored Link Status, Vitae, and Mini Game detail roots and register every indicator page with retail's one-active gmPanelUI owner. Helpful/Harmful and the new pages now replace Inventory, Character, or Magic at one canonical window position while preserving the DAT restore-previous flag. Correct the retail ping wire to its payload-free request/response, publish measured RTT, and port Vitae recovery XP from the live modifier and player properties. Keep transport packet-loss averaging and mini-game gameplay explicitly tracked under AP-110. Release build and all 5,814 tests pass with five intentional skips. Connected visual gate pending. Co-authored-by: OpenAI Codex <codex@openai.com>
192 lines
8.4 KiB
C#
192 lines
8.4 KiB
C#
using System;
|
|
using System.Buffers.Binary;
|
|
using System.Text;
|
|
|
|
namespace AcDream.Core.Net.Messages;
|
|
|
|
/// <summary>
|
|
/// Outbound social + query GameActions. These share a common pattern:
|
|
/// single-target / single-parameter GameActions inside the <c>0xF7B1</c>
|
|
/// envelope.
|
|
///
|
|
/// <para>
|
|
/// Wire format:
|
|
/// <code>
|
|
/// u32 0xF7B1 envelope
|
|
/// u32 gameActionSequence
|
|
/// u32 subOpcode
|
|
/// <payload> per-action
|
|
/// </code>
|
|
/// </para>
|
|
///
|
|
/// <para>
|
|
/// References: r08 §3 rows for each opcode.
|
|
/// </para>
|
|
/// </summary>
|
|
public static class SocialActions
|
|
{
|
|
public const uint GameActionEnvelope = 0xF7B1u;
|
|
|
|
// Queries
|
|
public const uint QueryHealthOpcode = 0x01BFu; // u32 targetGuid
|
|
public const uint QueryItemManaOpcode = 0x0263u; // u32 itemGuid; zero cancels
|
|
public const uint PingRequestOpcode = 0x01E9u; // no payload
|
|
|
|
// Fellowship
|
|
public const uint FellowshipCreateOpcode = 0x00A2u; // string16L name, bool openness, bool shareXP
|
|
public const uint FellowshipQuitOpcode = 0x00A3u; // bool disband
|
|
public const uint FellowshipDismissOpcode = 0x00A4u; // u32 guid
|
|
public const uint FellowshipRecruitOpcode = 0x00A5u; // u32 guid
|
|
public const uint FellowshipUpdateOpcode = 0x00A6u; // bool open
|
|
|
|
// Character options
|
|
public const uint SetCharacterOptionsOpcode = 0x01A1u; // u32 options bitmap
|
|
|
|
// Chat channels
|
|
public const uint AddChannelOpcode = 0x0145u; // string16L channelName
|
|
public const uint RemoveChannelOpcode = 0x0146u; // string16L channelName
|
|
|
|
/// <summary>Query a target's health — server replies with UpdateHealth (0x01C0).</summary>
|
|
public static byte[] BuildQueryHealth(uint seq, uint targetGuid)
|
|
{
|
|
byte[] body = new byte[16];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), seq);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), QueryHealthOpcode);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(12), targetGuid);
|
|
return body;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query an owned item's mana fraction, or cancel the active query with item guid zero.
|
|
/// Retail anchor: <c>CM_Item::Event_QueryItemMana @ 0x006A8610</c>.
|
|
/// </summary>
|
|
public static byte[] BuildQueryItemMana(uint seq, uint itemGuid)
|
|
{
|
|
byte[] body = new byte[16];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), seq);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), QueryItemManaOpcode);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(12), itemGuid);
|
|
return body;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Request the empty PingResponse (0x01EA). Retail
|
|
/// <c>CM_Character::Event_RequestPing @ 0x006A19A0</c> sends no payload.
|
|
/// </summary>
|
|
public static byte[] BuildPingRequest(uint seq)
|
|
{
|
|
byte[] body = new byte[12];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), seq);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), PingRequestOpcode);
|
|
return body;
|
|
}
|
|
|
|
/// <summary>Create a fellowship with a chosen name + options.</summary>
|
|
public static byte[] BuildFellowshipCreate(
|
|
uint seq, string fellowshipName, bool openness, bool shareXp)
|
|
{
|
|
byte[] name = PackString16L(fellowshipName);
|
|
// 2 bools consume 2 bytes + alignment pad to 4.
|
|
int boolBlock = 2;
|
|
int pad = (4 - ((name.Length + boolBlock) & 3)) & 3;
|
|
byte[] body = new byte[12 + name.Length + boolBlock + pad];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), seq);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), FellowshipCreateOpcode);
|
|
Array.Copy(name, 0, body, 12, name.Length);
|
|
body[12 + name.Length] = openness ? (byte)1 : (byte)0;
|
|
body[12 + name.Length + 1] = shareXp ? (byte)1 : (byte)0;
|
|
return body;
|
|
}
|
|
|
|
/// <summary>Quit your current fellowship (optionally disband if leader).</summary>
|
|
public static byte[] BuildFellowshipQuit(uint seq, bool disband)
|
|
{
|
|
byte[] body = new byte[16]; // envelope + 1 byte bool aligned to 4
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), seq);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), FellowshipQuitOpcode);
|
|
body[12] = disband ? (byte)1 : (byte)0;
|
|
return body;
|
|
}
|
|
|
|
/// <summary>Dismiss a specific vassal from your fellowship.</summary>
|
|
public static byte[] BuildFellowshipDismiss(uint seq, uint targetGuid)
|
|
=> SingleGuid(seq, FellowshipDismissOpcode, targetGuid);
|
|
|
|
/// <summary>Recruit a target into your fellowship.</summary>
|
|
public static byte[] BuildFellowshipRecruit(uint seq, uint targetGuid)
|
|
=> SingleGuid(seq, FellowshipRecruitOpcode, targetGuid);
|
|
|
|
/// <summary>Toggle fellowship open / closed recruiting.</summary>
|
|
public static byte[] BuildFellowshipUpdate(uint seq, bool open)
|
|
{
|
|
byte[] body = new byte[16];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), seq);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), FellowshipUpdateOpcode);
|
|
body[12] = open ? (byte)1 : (byte)0;
|
|
return body;
|
|
}
|
|
|
|
/// <summary>Push the client's character-options bitmap to the server.</summary>
|
|
public static byte[] BuildSetCharacterOptions(uint seq, uint optionsBitmap)
|
|
{
|
|
byte[] body = new byte[16];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), seq);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), SetCharacterOptionsOpcode);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(12), optionsBitmap);
|
|
return body;
|
|
}
|
|
|
|
/// <summary>Subscribe to a named chat channel.</summary>
|
|
public static byte[] BuildAddChannel(uint seq, string channelName)
|
|
=> SingleString(seq, AddChannelOpcode, channelName);
|
|
|
|
/// <summary>Unsubscribe from a named chat channel.</summary>
|
|
public static byte[] BuildRemoveChannel(uint seq, string channelName)
|
|
=> SingleString(seq, RemoveChannelOpcode, channelName);
|
|
|
|
// ── Helpers ──────────────────────────────────────────────────────────────
|
|
|
|
private static byte[] SingleGuid(uint seq, uint sub, uint guid)
|
|
{
|
|
byte[] body = new byte[16];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), seq);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), sub);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(12), guid);
|
|
return body;
|
|
}
|
|
|
|
private static byte[] SingleString(uint seq, uint sub, string s)
|
|
{
|
|
byte[] str = PackString16L(s);
|
|
byte[] body = new byte[12 + str.Length];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), seq);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), sub);
|
|
Array.Copy(str, 0, body, 12, str.Length);
|
|
return body;
|
|
}
|
|
|
|
private static byte[] PackString16L(string s)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(s);
|
|
// Windows-1252 matches retail (and holtburger's encoding_rs::WINDOWS_1252).
|
|
byte[] data = Encoding.GetEncoding(1252).GetBytes(s);
|
|
if (data.Length > ushort.MaxValue)
|
|
throw new ArgumentException("String too long for 16-bit length prefix.", nameof(s));
|
|
|
|
int recordSize = 2 + data.Length;
|
|
int padding = (4 - (recordSize & 3)) & 3;
|
|
byte[] result = new byte[recordSize + padding];
|
|
BinaryPrimitives.WriteUInt16LittleEndian(result, (ushort)data.Length);
|
|
Array.Copy(data, 0, result, 2, data.Length);
|
|
return result;
|
|
}
|
|
}
|