using System.Runtime.CompilerServices;
using System.Text;
namespace AcDream.Core.Net.Messages;
///
/// Shared text encodings for the AC wire protocol.
///
///
/// Retail and holtburger both use Windows-1252 (CP1252) for every
/// String16L on the wire — chat, character names, item names,
/// system messages, popup text. Before Phase I.5 we used ASCII,
/// which was wrong: any non-ASCII byte (e.g. é = 0xE9, name accents
/// or chat punctuation from Latin-1 locales) decoded to '?'. Switching
/// to CP1252 matches what the server actually sends.
///
///
///
/// .NET 6+ ships only ASCII / Latin-1 / UTF8/16/32 in the base library;
/// Windows-1252 lives in System.Text.Encoding.CodePages. The
/// module initializer below registers that provider on first load of
/// any type in AcDream.Core.Net.Messages, so call sites can use
/// with id 1252 directly.
///
///
public static class Encodings
{
///
/// Module initializer — guaranteed by ECMA-335 to run before any
/// other code in this module (in particular, before any static
/// field initializer in user code that follows). Registers
/// CodePagesEncodingProvider so
/// with id 1252 returns a
/// real encoding instance instead of throwing
/// .
///
#pragma warning disable CA2255 // Library-internal: registers CP1252 once
// before any wire-string parser is invoked.
[ModuleInitializer]
internal static void Register()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
#pragma warning restore CA2255
///
/// CP1252 (Windows-1252). Cached so callers don't look it up each frame.
/// Initialized after via field-init ordering.
///
public static readonly Encoding Windows1252 = Encoding.GetEncoding(1252);
}