MinecraftConsoles/Minecraft.Client/Font.h
MrTheShy 4f2352361a Add Mojang/Ely.by/offline authentication system
The old Windows64 port had no real player identity — it used hardcoded
fake XUIDs, so anyone could impersonate anyone. This replaces that with
proper auth supporting Mojang, Ely.by, and offline accounts.

MCAuth library (new, MCAuth/):
  Mojang auth via MSA device code flow (XBL, SISU, MC services),
  Ely.by via Yggdrasil with 2FA, offline UUID generation matching
  Java Edition (MD5 v3 from "OfflinePlayer:<name>"). Multi-account
  manager with background token refresh, per-slot sessions, and
  on-disk token persistence. Server-side session verification via
  Mojang/Ely.by hasJoined API. Skin fetching and PNG validation
  from texture servers.

Network protocol (version bumped to 80):
  Three new packets (AuthScheme, AuthResponse, AuthResult) implement
  a server-driven auth handshake before login completes. Player
  identity migrated from 64-bit XUID to 128-bit GameUUID backed by
  two uint64 fields (hi/lo). readPlayerUID/writePlayerUID now
  serialize 16 bytes on the wire. Old and new clients cannot connect
  to each other — version mismatch is rejected at PreLogin.

Save migration:
  Map data mappings auto-migrate from old format: the old 64-bit
  XUID is placed in hi, lo is set to 0 as a sentinel. On first
  access by the real player, the sentinel entry is upgraded in-place
  to the full 128-bit UUID. Format detection is by file size (2080,
  2112, or 4160 bytes). Player .dat filenames inside saveData.ms
  change from decimal XUID to dashed UUID — old saves need manual
  entry renaming in the archive.

UI:
  NativeUIRenderer: immediate-mode drawing system (quads, text,
  9-slice panels, scrollbars, focus lists) for rendering auth
  screens without Flash/Scaleform. UIScene_MSAuth handles device
  code display, Ely.by credential input with 2FA, per-account
  skin head preview, and multi-account add/remove/switch.

Server:
  online-mode and auth-provider (mojang/elyby) in server.properties.
  Whitelist and ban checks validate against the server-verified UUID.
  Incompatible auth scheme logs which provider the server expects
  vs what the client is using.

Also fixes a pre-existing exploit where any client could send a
DebugOptionsPacket to grant themselves CraftAnything and other debug
privileges on any server — now requires OP status server-side.
2026-03-23 01:14:23 +01:00

123 lines
4.1 KiB
C++

#pragma once
class IntBuffer;
class Options;
class Textures;
class ResourceLocation;
class Font
{
private:
int *charWidths;
public:
int fontTexture;
Random *random;
private:
int colors[32]; // RGB colors for formatting
Textures *textures;
float xPos;
float yPos;
// § format state (bold, italic, underline, strikethrough); set during draw(), reset by §r
bool m_bold;
bool m_italic;
bool m_underline;
bool m_strikethrough;
bool enforceUnicodeSheet; // use unicode sheet for ascii
bool bidirectional; // use bidi to flip strings
int m_cols; // Number of columns in font sheet
int m_rows; // Number of rows in font sheet
int m_charWidth; // Maximum character width
int m_charHeight; // Maximum character height
ResourceLocation *m_textureLocation; // Texture
std::map<int, int> m_charMap;
public:
Font(Options *options, const wstring& name, Textures* textures, bool enforceUnicode, ResourceLocation *textureLocation, int cols, int rows, int charWidth, int charHeight, unsigned short charMap[] = nullptr);
#ifndef _XBOX
// 4J Stu - This dtor clashes with one in xui! We never delete these anyway so take it out for now. Can go back when we have got rid of XUI
~Font();
#endif
void renderFakeCB(IntBuffer *cb); // 4J added
private:
void renderCharacter(wchar_t c); // 4J added
void addCharacterQuad(wchar_t c);
void renderStyleLine(float x0, float y0, float x1, float y1); // solid line for underline/strikethrough
public:
void drawShadow(const wstring& str, int x, int y, int color);
void drawShadowLiteral(const wstring& str, int x, int y, int color); // draw without interpreting § codes
void drawShadowWordWrap(const wstring &str, int x, int y, int w, int color, int h); // 4J Added h param
void draw(const wstring &str, int x, int y, int color);
/**
* Reorders the string according to bidirectional levels. A bit expensive at
* the moment.
*
* @param str
* @return
*/
private:
wstring reorderBidi(const wstring &str);
void draw(const wstring &str, bool dropShadow);
void draw(const wstring& str, int x, int y, int color, bool dropShadow);
void drawLiteral(const wstring& str, int x, int y, int color); // no § parsing
int MapCharacter(wchar_t c); // 4J added
bool CharacterExists(wchar_t c); // 4J added
public:
int width(const wstring& str);
int widthLiteral(const wstring& str); // width without skipping § codes (for chat input)
wstring sanitize(const wstring& str);
void drawWordWrap(const wstring &string, int x, int y, int w, int col, int h); // 4J Added h param
private:
void drawWordWrapInternal(const wstring &string, int x, int y, int w, int col, int h); // 4J Added h param
public:
void drawWordWrap(const wstring &string, int x, int y, int w, int col, bool darken, int h); // 4J Added h param
private:
void drawWordWrapInternal(const wstring& string, int x, int y, int w, int col, bool darken, int h); // 4J Added h param
public:
int wordWrapHeight(const wstring& string, int w);
void setEnforceUnicodeSheet(bool enforceUnicodeSheet);
void setBidirectional(bool bidirectional);
// Bind the font atlas texture so external code (e.g. NativeUI) can sample
// the white texel at UV (0,0) for solid-colour rectangles.
void bindFontTexture() { textures->bindTexture(m_textureLocation); }
// Expose font metrics for NativeUI D3D11 text renderer.
int getCols() const { return m_cols; }
int getRows() const { return m_rows; }
int getCharWidth() const { return m_charWidth; }
int getCharHeight() const { return m_charHeight; }
int getCharPixelWidth(wchar_t c) const { return charWidths[MapCharacterConst(c)]; }
wchar_t mapChar(wchar_t c) const { return static_cast<wchar_t>(MapCharacterConst(c)); }
ResourceLocation* getTextureLocation() const { return m_textureLocation; }
Textures* getTextures() const { return textures; }
private:
int MapCharacterConst(wchar_t c) const
{
if (!m_charMap.empty() && c != L' ')
{
auto it = m_charMap.find(c);
return (it != m_charMap.end()) ? it->second : 0;
}
return c;
}
public:
// 4J-PB - check for invalid player name - Japanese local name
bool AllCharactersValid(const wstring &str);
};