gamecore common-function-table slots: paths, files, registry, resources, string tables, timers,
profanity filter.  Reimplementation notes for the native (arm64 macOS) gamecore.
=================================================================================================
Date: 2026-09-24. Static only, plus unicorn emulation of the real gamecore code
(reverse-engineering/unpacked/gamecore.unpacked.dll, image base 0x10000000) to confirm outputs.
Table: gamecore 0x1006fbe8; slot N = u32 at 0x1006fbe8 + 4*N ("+0xDISP" = 4*N).
FFXiMain thunks: mov eax,[0x10456a6c]; jmp [eax+disp].  FFXiMain call sites below are the
`call <thunk>` addresses (the live log prints the return address = site+5).
Live log = scratchpad gamecore_live_calls.txt (seq, slot, return site, 4 stack dwords, = eax).

CONVENTIONS THAT APPLY TO EVERY SLOT IN THIS FILE
  * Every slot here is plain __cdecl: the gamecore function ends in a bare `ret`, and every
    FFXiMain site cleans up with `add esp,4*argc`. Pop count = 0 for all of them. None uses ecx
    (no thiscall). Return value in eax (edx also for none of these).
  * "Root" = gamecore global 0x103dfa24 (char[0x200]): the viewer's install directory,
    stored WITH a trailing backslash, '/' converted to '\'. It is set by slot 125 (+0x1f4,
    0x10048a40) / slot 1456 (+0x16c0, wide variant); the retail launcher/app.dll set it, FFXI
    never does. On this machine: the retail install's viewer folder (62 chars;
    consistent with the live log: id 0x13 -> 0x47 = 62 + len("data\dic\")).
  * "User index" = gamecore global 0x100992e0 (int; slot 870 +0xd98 sets it; read via
    0x10045fd0 under mutex 0). Negative is treated as 0. It becomes the two digits of "homeNN"
    (tens = (u/10)%10, units = u%10). Normally 0 (the Viewer's first member slot).
  * "Language code" = slot 421 (+0x694, 0x10018200) = global 0x100740f8 (fallback 0x100aa31c).
    Live value: 1. 0 = Japanese, 1 = US English, 2..8 = EU EN/FR/DE/IT/ES/EL/PT.
    (0x10018200 is also what FFXi.dll stores at param block +0x28.)

Confidence tags: HIGH = read + emulated/verified; MEDIUM = read, not exercised; LOW = inferred.

-------------------------------------------------------------------------------------------------
+0x1f8  slot 126   gamecore 0x10048be0   GetPath(id)                          confidence HIGH
-------------------------------------------------------------------------------------------------
Convention : cdecl, 4 args, pop 0.
Signature  : int GetPath(int id, char *buf, int size, int extra);
Returns    : strlen of what was written (>0); 0 if size < 1, buf == NULL or id > 0x26.
             (size==1 also returns 0: the usable length is size-1.)
Writes     : buf <- Root + components, every component followed by '\', NUL-terminated.
             Truncates at size-1 chars (always NUL-terminated); the "NN" digits are poked at
             [len-3],[len-2] after the "homeNN\" component, so a truncated buffer can be
             garbage - irrelevant in practice (FFXI passes 0x200 or 0x1ff).
State read : Root, User index (under gamecore mutex 0: WaitForSingleObject/ReleaseMutex on
             0x103df808[0]), Language code (ids 0x14, 0x17, 0x26 only).
Side effects: none besides the mutex.
Table (lang = Language code, NN = User index as 2 digits, R = Root):
  id  path                                         notes
  00  R usr\homeNN\
  01  R pub\homeNN\mail\s\b\
  02  R pub\homeNN\mail\s\a\
  03  R pub\homeNN\mail\r\b\
  04  R pub\homeNN\mail\r\a\
  05  R pub\homeNN\msg\s\b\
  06  R pub\homeNN\msg\s\a\
  07  R pub\homeNN\msg\r\b\
  08  R pub\homeNN\msg\r\a\
  09  R tmp\
  0a  R usr\
  0b  R patch\
  0c  R usr\all\
  0d  R pub\homeNN\mail\uidl\
  0e  R data\
  0f  R data\utf\
  10  R pub\homeNN\mail\adr\
  11  R pub\homeNN\
  12  R pub\all\
  13  R data\dic\
  14  R data\db\             lang 2..8: R EU\<LL>\db\
  15  R data\icon\
  16  R pub\
  17  R data\doc\            lang 2..8: R EU\<LL>\doc\
  18  R pub\homeNN\open\<extra>\      extra = char*; NULL -> "Unknown"
  19  R pub\homeNN\hidden\<extra>\    extra = char*; NULL -> "Unknown"
  1a  R export\drv\
  1b  R default\pub\home\
  1c  R data\code\
  1d  R pub\homeNN\open\
  1e  R default\usr\home\
  1f  R pub\homeNN\open\GreetingCards\
  20  R pub\homeNN\open\SaveFiles\
  21  R pub\homeNN\open\ScreenShots\<T>\  extra = title id, see <T>
  22  R pub\homeNN\open\etc\
  23  R data\font\
  24  R pub\homeNN\open\ContentsData\<T>\ extra = title id, see <T>
  25  R pub\homeNN\log\
  26  R default\pub\home\    lang 2..8: R EU\<LL>\   (no further component)
  >26 returns 0, buf untouched.
  <LL> = "EN","FR","DE","IT","ES","EL","PT" for lang 2..8 (table index lang+0x24 in the
         component table 0x1009ac14). Lang 0, 1 and anything >= 9 use the non-EU form.
  <T>  = extra 1 "FinalFantasyXI", 2 "TetraMaster", 3 "Janhourou", 4..0x3ff "Contents%04d";
         extra <= 0 or >= 0x400: the component is omitted (path ends at ScreenShots\ /
         ContentsData\).
  extra is ignored for every other id.
Verified: emulated every id x {lang 0..9} x {user 0,3,123,-5}; live log agrees for ids 6, 7,
  8 (0x51 = 81 chars) and 0x13 (0x47 = 71 chars).
FFXiMain call sites (24) and use:
  100e7c26, 100e7f36  id 0x14 -> the viewer profile DB's .pib / .pfb names (sprintf via slot 258),
                      the viewer's profile DB (data\db\), into [0x104df7b0]+0x3d8/+0x5f4.
  100f518e 100f51de 100f522e 100f53ee 100f547e 100f54de 100f56ce 100f571e 100f576e
                      ids 5/6/7/8: the service's message-box dirs pub\homeNN\msg\{s,r}\{b,a}\ written to
                      object+0xc48; then a presence file slot is called with object+0xe48.
  100f5b6c 100f5c6c 100f5d4d 100f6269 100f62f9 100f6379 100f66de 100f67fe 100f68ee
                      ids 6/7/8 into a zeroed 0x200 local: message-box enumeration (the live
                      log has 100f626e/62fe/637e = ids 7, 8, 6, each -> 81).
  101c09d8, 101c0acd  id 0x21, extra 1: ...\open\ScreenShots\FinalFantasyXI\ ; FFXiMain then
                      CreateDirectoryA()s it (screenshot saving, see slots 1134-1136).
  101c0d0c            id 0x24, extra 1: ...\open\ContentsData\FinalFantasyXI\ ; CreateDirectoryA,
                      then slots 1296/1295 (see there).
  101c3e6a            generic wrapper FFXiMain 0x101c3e50 (thiscall, ret 0x10):
                      (out, id, name, extra) -> GetPath(id,tmp,0x1ff,extra);
                      sprintf(out,"%s%s",tmp,name). Used by the profanity filter loader with
                      id 0x13 for "vulgar2.dic" and "entryz.dic" (live: 2 calls, ret 0x47), and
                      by the screenshot / ContentsData code with ids 0x21 / 0x24.
Native     : Implement the table above literally. Keep Root = the Mac copy of the Viewer
             directory with a trailing '\' (the game concatenates "%s%s", and FFXiMain later
             passes these strings to CreateDirectoryA / CreateFileA through the CRT/kernel32
             layer, so keep Windows separators; the host's path layer maps '\' -> '/').
             Return strlen. NN from the host's member index (use 0). Language from slot 421.

-------------------------------------------------------------------------------------------------
+0x1fc  slot 127   gamecore 0x10049430   GetFileName(id)                       confidence HIGH
-------------------------------------------------------------------------------------------------
Convention : cdecl, 4 args, pop 0.
Signature  : int GetFileName(int id, char *buf, int size, int extra);
Returns    : strlen of the full path; 0 if id > 0xe (buf untouched) or if the directory part
             returned 0.
Writes     : buf <- GetPath(dir_id, buf, size, 0) followed by the file name (truncated to
             size-1, NUL-terminated).
  id  dir(slot126 id)   file                 full path (lang 1)
  0   0x1a              sqsound.irx          R export\drv\sqsound.irx
  1   0x17              polerr.bin           R data\doc\polerr.bin      (EU: R EU\LL\doc\...)
  6   0x13              entrynw.dic          R data\dic\entrynw.dic
  7   0x13              entry.dic            R data\dic\entry.dic
  8   0x23              fnt%03d.bin(extra)   R data\font\fnt000.bin (extra = font number)
  9   0x13              entry_f.dic
  a   0x13              entry_b.dic
  b   0x13              entryz.dic
  c   0x13              vulgar2.dic
  d   0x13              entryu.dic           (not present in this install)
  e   0x13              vulgaru.dic          (not present in this install)
State      : as slot 126.
FFXiMain call site: 100f6ad8  id 1 into object+0xe48 (0x200): the service's error-message file
             polerr.bin for the error-text class used with slots 1004-1006. If the return is
             <= 0 FFXiMain just empties the string.
Native     : as the table; build from the slot-126 implementation.

-------------------------------------------------------------------------------------------------
+0x124c slot 1171  gamecore 0x1004a0e0   PatchVerDecrypt                        confidence HIGH
-------------------------------------------------------------------------------------------------
Convention : cdecl, 4 args, pop 0.
Signature  : int PatchVerDecrypt(const u8 src[0x120], char *out, int outsize, int product);
             product = title id as a number: 1 FFXI, 2 Tetra Master, 1000 the viewer.
Returns    : 0 on success, -1 on failure (bad key/checksum, or outsize <= strlen(version)).
Writes     : out <- the version string, NUL-terminated (e.g. "30260805_0"). Nothing else.
             src is not modified (decrypts into a 0x120 local).
State/OS   : Registry: RegOpenKeyExA(HKLM, <launcher Interface key, US variant>, 0, KEY_QUERY_VALUE)
             when gamecore global 0x100aa318 != 0 (US build), else the non-US variant of that key;
             a non-empty string at 0x103dfc24 overrides the key path. (Key strings are stored
             Caesar +1 and decoded by 0x10049da0: each alphabetic char minus 1.)
             RegQueryValueExA(value name = sprintf("%04d", product), type ignored, 0x80 bytes).
             On this machine (WOW6432Node): 0001="0", 0002="01234567", 1000="001b1394".
Algorithm (all verified: a Python reimplementation decrypts all three retail patch.ver files to
  exactly what the emulated gamecore produces: FFXI "30260805_0", Viewer "20110829_E",
  TetraMaster "20040909_0"):
  1. seed64: r = registry string. k[8] = 0; for i < strlen(r): k[i&7] += r[i] (bytes, mod 256);
     seed64 = little-endian u64 of k.  Tries, in order: (a) over strlen(r), (b) over all 0x80
     bytes of the value buffer (differs only if junk follows the NUL), (c) seed64 = 0 (also the
     only try when the registry read fails). First try whose decrypt succeeds wins.
  2. key64 = seed64 + (int64)(int32)product.
  3. Key schedule (0x10007bc0): lo = key64 & 0xffffffff, hi = key64 >> 32;
       s[0..3] = LE(ror32(hi,16)), s[4..7] = LE(rol32(lo,8));
       s[0] += 0x45; for i=1..7: b = s[i] + s[i-1] - 0x2c; s[i] = (s[i-1]<<2) ^ b ^ 0x45 (bytes);
       K[0] = LE u64 of s; K[j] = K[j-1]*5 mod 2^64 for j=1..31.
  4. Decrypt 8-byte blocks (size must be a nonzero multiple of 8; 0x120 = 36 blocks);
     ctr = 0 (bytes processed), sum = 0 (u32). For each block at offset off:
       idx = (ctr>>3) & 31; S = (sum of the 8 bytes of K[idx]) mod 256
       byte stage: d = ((ctr>>3) ^ 0x45) & 0xff;
                   for k in 0..7: c = in[off+k]; x[k] = ((c ^ d) + 0xc0 - S) & 0xff; d = c;
                   (this is 8 rounds of x = SBOX[x] - Kbyte[j] with SBOX = gamecore 0x100715e4,
                    which is exactly x+0x78; 8*0x78 = 0x3c0 = 0xc0 mod 256)
       word stage: v = LE u64 of x; v -= K[idx];
                   t = ctr; t = (t<<10)|ctr three times (64-bit); t += 0xa1652347;
                   v ^= t; v ^= K[idx]; swap the 32-bit halves; store LE at out[off].
       sum += out[off] + out[off+4];  ctr += 8.
     Before the LAST block, remember sum_before_last. Success iff
       sum_before_last == u32 LE out[0x11c]; the function then returns u32 LE out[0x118]
       (0x118 = 280 in all three files; treated as ok if >= 0).
  5. Plaintext layout (0x120): 0x00..0x17 zero; 0x18 version string NUL-padded; zeros;
     0x118 u32 = 0x118; 0x11c u32 = checksum. The slot copies the string at 0x18 (fails with
     -1 if outsize < strlen+1).
KEY RECOVERY WITHOUT THE REGISTRY (important for macOS): blocks 0 and 1 are known plaintext
  (all zero), so K[0] is recoverable: for each (S0,S1) in 256x256 compute the byte stage, then
  solve (v0-K)^K = t0 and (v1-5K)^(5K) = t1 bit by bit from the LSB (low bits of K fix the low
  bits of both equations), then keep the K whose byte sums match S0/S1 and whose full decrypt
  passes the checksum. Python does all three retail files in < 0.4 s; C is instant. Result
  K[0]: FFXI 0x7796ab35ec794845, Viewer 0xee8e6f4611e93b7e, TM 0x1a45575caace2f7b.
FFXiMain call site: 101c4641 (in 0x101c45a0 = the game's file-system object Open(root,size)):
  reads "patch.ver" (0x120) from the FFXI install directory via its own file layer, calls
  slot1171(copy, buf, 0x100, 1) and copies the result to fs+0x10. A negative return makes
  Open() return -1, and FFXiMain's startup (0x10015cb0, 4 call paths) then FAILS: this slot is
  on the boot path. Live: (…, …, 0x100, 1) = 0.
  fs+0x10 is read through 0x101c46c0 (returns NULL if empty): window/version text
  (0x100012c5, falls back to "Version Error!!!!"), copied to 0x1047d280 (0x1007819b), a UI string
  (0x10114da8), and 0x102400a3 / 0x1024567e (login/lobby path). The lobby login carries the client
  version, so this string is what LSB's version check sees.
Native     : return 0 and write the FFXI version string. Options (DESIGN DECISION):
             (a) decrypt <FFXI dir>/patch.ver with the known-plaintext key recovery above (no
                 registry needed; exact retail behaviour for any install); or
             (b) take the string from host config (e.g. read once from the Windows install);
             (c) emulate the registry with a host-supplied Interface value per product and run
                 steps 1-5 literally.
             (a) is self-contained and faithful; recommended. On failure return -1 (the game
             will refuse to start, as retail does).

-------------------------------------------------------------------------------------------------
+0xe2c .. +0xe44  slots 907-913   the viewer option store (option.bin)     confidence HIGH (format
                                                                             verified by decrypting
                                                                             the retail file)
-------------------------------------------------------------------------------------------------
One gamecore module (globals 0x100be9e0..0x100be9f8) that loads, queries, edits and saves the
member's viewer options file. All seven are cdecl, pop 0.
  state:  0x100be9e8 file handle (-1 none), 0x100be9ec u16 step, 0x100be9f0 size,
          0x100be9f4 mode, 0x100be9f8 heap image of the decrypted file (NULL = not loaded),
          0x100be9e0 optional full-path override (NULL in practice).
File     : mode 0 -> GetPath(0x11) + "option.bin" = R pub\homeNN\option.bin  (FFXI uses this)
           mode 1 -> GetPath(0x26) + "option.bin" = R default\pub\home\option.bin (defaults;
           set by slot +0xe4c 0x10030e40, not called by FFXI). 13208 bytes here.
Encryption: the patch.ver cipher (slot 1171 steps 3-4) with key64 = 0 (no product, no registry).
           Decrypted payload = size-8 bytes; the last 8-byte block is the trailer
           {u32 payload_len, u32 checksum}; 0x100081e0 returns payload_len (13200 here).
Decrypted image (offsets relative to the image start; gamecore relocates them to pointers in
  place after loading, and back to offsets before saving):
  +0  u32 count (109 here)     +4 u32 (0)
  +8  count x 0x20-byte items, sorted ascending by the 8-byte key read as a LE u64:
      +0x00 char key[8]  (not NUL-terminated, e.g. "GOPN1ESL", "LPOL1WDY", "LSKF1JHT")
      +0x08 u16 (0)       +0x0a u16 type: 0 = int, 1 = string
      +0x0c int  min  (type 0)  | max string length (type 1)
      +0x10 int  max  (type 0)  | 0
      +0x14 int  default        | char* default string   (relocated only for type 1)
      +0x18 int  current value  | char* current string   (relocated only for type 1)
      +0x1c char* description (always relocated), e.g. "Set date format."
  then the string pool.
  After loading, the item whose key is "GOPN1ESL" also sets the language code (setter
  0x100181f0(value), ignored unless 0..8). Retail value here is -1, so no change.

+0xe2c slot 907 = +0xe34 slot 909   gamecore 0x10030e00   OptBegin()
  int OptBegin(void); FFXI passes no args. Sets mode = 0, step = 0, handle = -1. Returns 1.
  FFXI calls it before a load (907 sites) and again before a save (909 sites 101956c7,
  10196500). It is the same function; it only resets the step machine.
+0xe30 slot 908   gamecore 0x10030e50   OptLoadPoll()
  int OptLoadPoll(void). Non-blocking step machine over gamecore's async file slots 921/922/926/
  927 (open for read, seek end, tell, malloc, seek 0, read, wait, close + decrypt):
  returns 0 = still working (call again; FFXI Sleep(0)s and retries, up to 100 times at the
  101964xx sites), 1 = loaded (image at 0x100be9f8, relocated, GOPN1ESL applied, sorted),
  <0 = error (a file-slot error code, or 0xffffd7fd = -10243 on decrypt/checksum failure);
  on error it runs OptEnd(). Polls after completion return 0.
+0xe38 slot 910   gamecore 0x100312e0   OptSavePoll()
  int OptSavePoll(void). Same contract. Steps: open the same path for write (mode 2); sort;
  pointers back to offsets; encrypt in place (0x100081a0, key 0: payload = size-8, then the
  trailer block); write; wait; close; decrypt the buffer again. Returns 1 when written.
  After a save the in-memory image holds OFFSETS, not pointers: callers must OptEnd().
+0xe3c slot 911   gamecore 0x10030da0   OptEnd()
  void OptEnd(void). Closes the handle if open, frees the image, step = 0. eax is undefined
  (FFXI ignores it; live log shows 1).
+0xe40 slot 912   gamecore 0x100315a0   OptFind(key)
  OptItem *OptFind(const char key[8]). Binary search of the sorted items by LE-u64 key.
  Returns a pointer INTO the image (FFXI reads item+0x18 directly), or NULL if not found or
  nothing loaded. Live: key "LSKF1JHT" -> non-NULL.
+0xe44 slot 913   gamecore 0x100314d0   OptSet(item, value)
  int OptSet(OptItem *item, const void *value). value NULL -> 0.
   type 0: v = *(int*)value; unless (min==0 && max==0), require min <= v <= max, else return 0;
           item+0x18 = v; if the key is "GOPN1ESL", set the language code(v). Returns 1.
   type 1: s = (char*)value; strlen(s) must be <= item+0xc (max), else 0; copies s into the
           buffer at item+0x18 (<= max chars) and NUL-terminates. Returns 1.
   other types: 0.
FFXiMain use:
  * Startup load (FFXiMain 0x10195700, from 0x10195400 at boot): 907; poll 908 until != 0; for
    each of its 206 option entries (0x2c bytes, key at +0x10) of kind 1 call 912 and copy
    item+0x18 into its own option. Kind 2 are the viewer-owned keys LPOL1WDY / LPOL1WSC, which
    come from slots 697/698 instead of the file. Then 911.
    Live: 907 x2, 908 x32 (0 while pending), 912 x20, 911.
  * Save (0x10195650): 907, poll 908, set every kind-1 option via 912+913 (retry while 913
    returns 0), 909, poll 910, 911.
  * 0x10196480 / 0x10196550: GOPN1_FT (reply method for incoming friend requests): read it, or set it
    to !arg and save, then push it to the server via presence slots 195/196.
Native     : Keep the file format so a player's retail option.bin just works. Implement it
             synchronously: 907/909 -> 1; 908 -> load, decrypt (key 0), relocate, sort, return 1
             (or <0 if the file is missing or corrupt: FFXI then keeps its own defaults);
             912/913 exactly as above, on an image in GUEST memory with the 0x20-byte item
             layout (FFXI dereferences the returned pointer); 911 -> free.
             910: either write back with the inverse cipher (per block: swap the halves,
             v ^= K[idx], v ^= t, v += K[idx], then per byte x = (x + S + 0x40) & 0xff,
             c = x ^ d, d = c; the checksum sums plaintext bytes 0 and 4 of each block; a
             payload that is not a multiple of 8 gets a special packed tail block in 0x10007e50,
             not analysed - option.bin payloads here are multiples of 8), or save nothing and
             return 1. DESIGN DECISION: whether the Mac build writes option.bin.

-------------------------------------------------------------------------------------------------
+0xae4  slot 697   gamecore 0x1004d240   CoreGetDateFormat()                    confidence HIGH
+0xae8  slot 698   gamecore 0x1004d270   CoreGetTimeFormat()                    confidence HIGH
-------------------------------------------------------------------------------------------------
cdecl, no args, pop 0. They return the globals 0x103e4c44 (date format 0,1,2) and 0x103e4c48
(time format 0,1). Those are set only by slots 702 (+0xaf8, 0x1004d250, accepts 0..2) and 703
(+0xafc, 0x1004d280), which the Viewer calls from its options LPOL1WDY / LPOL1WSC. They stay 0
(bss) if the Viewer never set them. Live: both 1.
FFXiMain: 10195839 / 10195885 in 0x10195820 (option load, kind-2 entries): "LPOL1WDY" sets the
  game's date format global 0x1062fbe4 = 0/1/2 (any other value: entry skipped); "LPOL1WSC"
  sets the time format 0/1.
Native     : return host settings. Defaults matching the live run: date 1, time 1. Or read
             LPOL1WDY / LPOL1WSC from option.bin while loading it.

-------------------------------------------------------------------------------------------------
+0xac0  slot 688   gamecore 0x1004ccc0   GetTime(tm)                            confidence HIGH
-------------------------------------------------------------------------------------------------
cdecl, 1 arg (FFXI pushes 1), pop 0.
Signature  : int GetTime(int tm[9]);
Writes     : tm = gmtime(t & 0x7fffffff) as 9 ints {sec, min, hour, mday, mon(0-11),
             year (FULL year: tm_year+1900), wday, yday, isdst}, where
             t = base_time(0x103e4c30) + (GetTickCount() - base_tick(0x103e4c40)) / 1000.
             0 if only the init-time local clock (time(NULL) at gamecore init) is in use.
             The struct is written either way. Live: = 1.
FFXiMain   : 10239c29 (character-creation menu) and 10243638: if it returns non-zero,
             srand(tm[1] * tm[0] * 0x3bd1948). Only used as a random seed.
Native     : fill from the host UTC clock (year as full year), return 1.

-------------------------------------------------------------------------------------------------
+0x774  slot 477   gamecore 0x1004ca20   IconPath(buf,size,kind,icon)           confidence HIGH
-------------------------------------------------------------------------------------------------
cdecl, 4 args, pop 0.
Signature  : int IconPath(char *buf, int size, int kind, int icon);
Writes     : buf = GetPath(0x15) [+ "download\" for kind 0] + file name, where
             (i = icon & 0xffff):
               kind 0: "hnf%03d.png"    % (i/8)   (in R data\icon\download\)
               kind 1: "cicn_l%03d.png" % (i/4)   (large member icons)
               kind 2: "cicn_s%03d.png" % (i/4)   (small member icons)
             e.g. kind 1, icon 1003 -> R data\icon\cicn_l250.png.
Returns    : the sub-image index inside that PNG: kind 0: i%8; kind 1/2: i%4.
             kind other than 0..2: -1 (buf holds just R data\icon\).
             Emulated for all three kinds.
FFXiMain   : 101c7c08, kind 2, size 0x1ff: loads the PNG (0x10253860) into a 4-entry icon
             cache and stores (sub-index/4?) and a tick; returns NULL on a negative result.
             (Member icons in the friend list / the service's UI.)
Native     : as above. The files live in the Viewer's data\icon\.

-------------------------------------------------------------------------------------------------
+0x76c  slot 475   gamecore 0x1004c720   FormatId(buf, lo, hi)                  confidence HIGH
-------------------------------------------------------------------------------------------------
cdecl, 3 args, pop 0.
Signature  : char *FormatId(char *buf, u32 lo, u32 hi);   v = (hi<<32)|lo
Writes     : if v >= 2^44 (hi >= 0x1000): buf = "" .
             else take v as 14 decimal digits d0..d13 (zero-padded) and write:
               d0 only if it is not '0', then d1 d2, '-', then d3..d13 with leading zeros
               removed ("0" if all zero), NUL.  At most 16 bytes.
             Examples (emulated): 0 -> "00-0"; 123456789 -> "00-123456789";
               1e11 -> "01-0"; 12345678901234 -> "123-45678901234".
Returns    : pointer to the terminating NUL (FFXI ignores it).
FFXiMain   : 100f1b1b, 1023eadd: v = (id64 >> 1) & 0xfff_ffffffff of an account ID -> the
             displayed id string. 101eb909: friend-list entry (then "%s"-copied at +0x28).
Native     : as above (pure function).

-------------------------------------------------------------------------------------------------
+0x73c  slot 463   gamecore 0x10048020   BackupCancel()                         confidence MEDIUM
+0x740  slot 464   gamecore 0x10048240   BackupQueryBegin(&out)                 confidence MEDIUM
-------------------------------------------------------------------------------------------------
Context: gamecore has ONE "server-side title data" job slot (array 0x1009aab8, stride 0x14c,
1 entry): state +0 (0 = free), socket handle +4, args +8/+0xc/+0x24, progress +0x18..+0x20.
It is driven by slot 465 (+0x744, network; not in this group), which talks to the presence service
Slot 1535/1536 (+0x17fc/+0x1800) start download/upload jobs (state 9) on the same slot.
463: void BackupCancel(void). If the job's socket handle (0x1009aabc) >= 0, closes it
     (0x10027c00); then state = 0, handle = -1. eax is garbage (it is the struct address:
     live 0x039aaab8 = 0x1009aab8 rebased), callers ignore it.
464: int BackupQueryBegin(u32 *out). out NULL -> 0xffffec00 (-5120); slot busy ->
     0xffffff00 (-256); else state = 0xf (query), out stored at +0x24, returns 0 (the job id).
     Then slot 465(id) returns progress 0..99, 100 = done (and *out = the size of the stored
     data, 0 = none), <0 = error.
FFXiMain: config-backup menu (FFXiMain 0x1023c550 vtable method; 0x10244980 "netwait/netbar"
  progress bar, "FFXI%d.DAT"): 1023c594 / 1024498d call 464, then poll 465; 1023d12d and the
  tail-jump 10164566 call 463 to reset (live: at 10163bba during startup, and at 1023d132).
  When 465 reports 100 with *out == 0 the UI shows "NO DATA!" / "---".
Native     : 463 -> no-op (return 0). 464 -> DESIGN DECISION: no account storage server exists for
             the host. Simplest faithful "nothing stored": 464 sets *out = 0 and returns 0, and
             465(0) returns 100 -> the menu shows NO DATA. (If 464 returns < 0 instead, FFXI
             just retries on its next update; also safe.)

-------------------------------------------------------------------------------------------------
Screenshots: slots 1134, 1135, 1136                                          confidence HIGH
-------------------------------------------------------------------------------------------------
Shared machinery: gamecore's async directory scanner 0x1002f630(path, param) / poll
0x1002f970(h, &files, &bytes, &param) / close 0x1002f620(h). The scan runs on gamecore's worker
thread: it recursively (depth 2) walks path\* with _findfirst/_findnext, skipping "." entries,
counting files and summing their sizes. Up to 4 handles (0..3). If gamecore's file subsystem is
not initialised (0x100be998 == 0): 0xffffd7fe (-10242); bad handle 0xffffd800 (-10240).

+0x11bc slot 1135  gamecore 0x100497d0   ShotScanBegin(unused, param)
  int ShotScanBegin(int unused, int param). Starts a scan of GetPath(0x21, extra 0) =
  R pub\homeNN\open\ScreenShots\ (ALL titles' screenshot folders, not just FFXI's);
  param defaults to 0xc800 when a NULL is passed internally; FFXI passes (1, 0x14000).
  Returns the scan handle (>= 0) or < 0.
+0x11b8 slot 1134  gamecore 0x100497f0   ShotScanPoll(h)
  int ShotScanPoll(int h). poll <0: close, return it. 0: return 0 (still scanning).
  >0: close; files >= 200 -> 0xffffe3e5 (-7195, "too many screenshots"); else 201 - files
  (>= 2: how many more may be saved, +1).
+0x11c0 slot 1136  gamecore 0x10049860   ValidName(name)   (= slot 1294's 0x10049d20)
  int ValidName(const char *name). 1 iff 1 <= strlen < 31 and every byte is in the bitmap
  at gamecore 0x10066078 (bit (c&7) of byte[c>>3]); else 0. That bitmap
  (000000000860ff03ffffffc7feffff07 + 16 zero bytes) allows exactly:
  # - . 0-9 @ A-Z ^ _ a-z
FFXiMain: 0x101c09c0 (query free slots) and 0x101c0a50 (save a screenshot):
  1136(name) -> 0 means refuse; GetPath(0x21, extra 1) and CreateDirectoryA on
  ...\ScreenShots\FinalFantasyXI\; 1135(1, 0x14000); spin on 1134 until != 0; if > 0 build
  ...\ScreenShots\FinalFantasyXI\<name> and write the image.
Native     : 1135/1134: count files under the ScreenShots tree synchronously; 1135 returns a
             handle, 1134 returns (files >= 200 ? -7195 : 201 - files). 1136: charset + length.

-------------------------------------------------------------------------------------------------
ContentsData (per-title saved data, "FFXI%d.DAT"): slots 1294-1299           confidence HIGH
                                                                   (format round-trip emulated)
-------------------------------------------------------------------------------------------------
Container = 0x200-byte header + payload, each separately encrypted with the patch.ver cipher
(slot 1171 steps 3-4; encryption = its inverse) under
  key64 = 0x37564 + sum of (signed char) name[i] for i = len-1 down to 1, stopping before the
          last '\' or '/'  (NOTE: index 0 of the name is NOT included when there is no
          separator; e.g. "FFXI2.DAT" -> 0x37564 + sum("FXI2.DAT")).
  Header plaintext (0x1f8 bytes + 8-byte trailer = 0x200): title string (<= 255 chars,
  NUL-padded) at +0, u32 payload size at +0x108, rest zero; trailer {0x1f8, checksum}.
  Payload: size bytes (multiple of 8) + trailer {size, checksum} = size+8 bytes at +0x200.
  Total = size + 0x208.

+0x144c slot 1299  gamecore 0x10049900   CDataSize(size)
  int CDataSize(int size): size%8 != 0 or size <= 0 -> 0xffffe3e4 (-7196); else size+0x208.
+0x1448 slot 1298  gamecore 0x10049920   CDataEncode(src,size,out,cap,title,name)
  int CDataEncode(const void *src, int size, u8 *out, int cap, const char *title,
                  const char *name).  cap%8 != 0 or cap < CDataSize(size) -> -7196.
  Writes out[0 .. size+0x208). Returns size+0x208.
+0x1444 slot 1297  gamecore 0x10049ad0   CDataDecode(in,insize,out,cap,name,title,titlecap)
  int CDataDecode(const u8 *in, int insize, void *out, int cap, const char *name,
                  char *title, int titlecap).
  insize < 0x200 or header decrypt fails -> 0xffffe3e2 (-7198). If out != NULL: cap < size+8
  -> -7196; payload decrypt fails -> -7198; else out = payload (size+8 bytes are written,
  including the 8-byte trailer). If title && titlecap > 0: strncpy(title, header, titlecap)
  (strncpy semantics). Returns size (header +0x108).
+0x1440 slot 1296  gamecore 0x10049c60   CDataScanBegin(newsize)
  Starts the async scan of GetPath(0x24, extra 0) = R pub\homeNN\open\ContentsData\ with
  param = newsize. Returns handle or < 0.
+0x143c slot 1295  gamecore 0x10049ca0   CDataScanPoll(h)
  <0: close, return it. 0: pending. >0: close; files >= 99 -> 0xffffe3e0 (-7200);
  bytes + newsize > 0x800000 (8 MB) -> 0xffffe3e1 (-7199); else 1.
+0x1438 slot 1294  gamecore 0x10049d20   ValidName(name)  (same body as slot 1136)
FFXiMain:
  save 0x101c0c20 (from the config-backup menu 0x102447d0): 1294(name) twice; size rounded
    up to a multiple of 8; 1299(size); GetPath(0x24, extra 1) + CreateDirectoryA of
    ...\ContentsData\FinalFantasyXI\; 1296(total) then spin on 1295; path = that dir + name;
    1298(src, size, buf, total, title, name); write the file.
  load 0x101bf800 (menu listing and restore; name "FFXI%d.DAT"): reads the file via
    0x101bf720, 1297(buf, len, out, cap, name, title, 0xff); on error the title becomes
    "NO DATA!-0"; the title format is "<text>-<n>".
Native     : pure functions 1297/1298/1299/1294 as above (needs the cipher both ways); the
             scan pair as for screenshots. Files written by retail are readable (same key).
-------------------------------------------------------------------------------------------------
+0x10bc slot 1071  gamecore 0x1001ae90   MsgLine(id, buf, size)                 confidence HIGH
-------------------------------------------------------------------------------------------------
cdecl, 3 args, pop 0.  Body 0x1001add0(id, buf, size, arg=NULL).
Signature  : void MsgLine(int id, char *buf, int size);   (eax: undefined, ignored)
Table      : 10 entries at 0x100748e0, {i16 id, i16 index, i16 flag, i16 0}; text =
             char[0x80] at 0x100743d8 + index*0x80. flag is 0 for all 10, so the text is
             strncpy'd (size-1 chars, NUL-terminated) - no formatting. Unknown id -> "".
             size <= 0 -> nothing.
  id  idx  meaning (the default text shipped in the binary is Japanese Shift-JIS; not reproduced)
  1   0    friend request (invitation to become friends)
  9   1    friend request accepted
  0xa 2    friend request declined
  0xb 3    deletion done (confirmation)
  0xc 4    deletion requested (asks the other side to delete)
  0xe 5    group invitation (asks whether to join)
  0xf 6    group join accepted            0x10 7  group join declined
  0x12 8   removed from group             0x13 9  group disbanded
  The Viewer overwrites the 10 texts at startup with its localized ones through slot 1072
  (+0x10c0, 0x1001ada0: SetMsgLine(index<10, text), copies <= 0x7f): app.dll 0x100579a3,
  catalog ids 0x46c9, 0x46d0-0x46d4, 0x46d6, 0x46d8, 0x46da, 0x46dc. So under the retail
  Viewer FFXI gets English here, not the Japanese defaults.
FFXiMain   : 101ff51b / 101ff723 / 101ff734 / 101fff52 / 102000fc - the friend-request
             dialog (ids 1, 9, 0xa) into 0x7f-byte buffers (size 0x7f).
Native     : static English table for ids 1, 9, 0xa (others optional). DESIGN DECISION: the
             exact retail English wording is in the Viewer's message catalog, not read here;
             pick wording or extract it from the Viewer catalog later.

-------------------------------------------------------------------------------------------------
+0x145c slot 1303  gamecore 0x1001aeb0   NoticeFormat(id, buf, size, arg)       confidence HIGH
-------------------------------------------------------------------------------------------------
cdecl, 4 args, pop 0.
Signature  : void NoticeFormat(int id, char *buf, int size, const void *arg);
Formats    : fmt = char[0x100] at 0x10074930 + id*0x100 (Japanese in the binary; the Viewer
             localizes them through slot 1302 +0x1458, 0x1001b100, from app.dll 0x10057aae).
             size <= 0: nothing. id >= 10: buf[0] = 0. Output via gamecore's snprintf
             (0x10012420, limit size-1).
  (meanings paraphrased; the retail format strings are not reproduced)
  id 0  friend invitation                                 plain copy
  id 1  <name> accepted your friend request               arg = member record, name resolved*
  id 2  <name> declined your friend request               arg = member record, name resolved*
  id 3  <name>'s message memo is not public               %s = (char*)arg + 0xa0 ("" if NULL)
  id 4  name already in use, choose another               plain copy (arg ignored)
  id 5  <name> accepted joining group <group>             arg = {record*, char *group}*
  id 6  <name> declined joining group <group>             arg = {record*, char *group}*
  id 7  you were removed from group <group>               %s = arg or "unknown"
  id 8  group <group> was disbanded                       %s = arg or "unknown"
  id 9  invitation to join group <group>                  %s = arg or "unknown"
  * name resolution goes through gamecore's friend list (0x10025410); FFXI never uses 1,2,5,6.
FFXiMain   : 10017dc4: once, id 4 into global 0x10456c58 (size 0xff): the "name already in
             use" text for an error-code table. 100e8373: on error 0xffffeb34, id 3 with arg
             = a member record ([0x104df7b0] + 0xa90 + index*0x100; name at +0xa0), then
             shown via the callback at [0x104df7b0]+0x828.
Native     : implement ids 3 and 4 (and plain copies for 0) with English text; the rest can
             format as above. Same wording decision as slot 1071.

-------------------------------------------------------------------------------------------------
Idle / AFK logout timer: slots 1140, 1141, 1148, 1149, 1150                  confidence HIGH
-------------------------------------------------------------------------------------------------
gamecore state (all under gamecore mutex 0 unless noted): enabled 0x1009aa18, deadline 0x1009aa1c
(GetTickCount ms), period 0x1009aa20 (ms), warned 0x1009aa30, expired 0x1009aa34,
warn_cb 0x1009aa28, expire_cb 0x1009aa2c, activity flag 0x1009aa38 (mutex 1), hook 0x1009aa24.
restart() = deadline = GetTickCount() + period; warned = expired = 0.
+0x11d0 slot 1140  0x100464f0  void IdleEnable(int on)   enabled = on; restart().
+0x11d4 slot 1141  0x10046520  void IdleSetPeriod(u32 ms) if ms == 0: enabled = 0;
                                period = ms; restart().
+0x11f4 slot 1149  0x10046720  void IdleSetCallbacks(void (*warn)(int), void (*expire)(int))
+0x11f0 slot 1148  0x100466c0  void IdleHook(int *arg): if gamecore is up (0x103df7f8) and
        enabled: cb = hook(0x1009aa24, set only by slot 1147 which FFXI never calls); with
        arg == NULL call cb(NULL) if set; with arg != NULL only if table 0x1009aa3c[*arg]==1.
        For FFXI: a no-op. eax undefined (live: 1).
+0x11f8 slot 1150  0x10046750  void GoOffline(void): under mutex 0, 0x10045840(0): if the
        online session is connected (0x1009924c == 1) tear it down (sign-out of the service), reset
        session state. eax undefined.
The check itself runs inside gamecore's per-frame pump (0x10045480, reached from slot 705 which
FFXiMain calls every frame, and slot 818):
  if enabled: if activity flag: restart(), clear it.
    if !warned: rem = deadline > now ? deadline - now : 0;
                if 0 < rem <= 60000: warn_cb(0) (called with the mutex released); warned = 1.
    else if !expired and now >= deadline: expire_cb ? expire_cb(0) : GoOffline()
                (the latter also makes the pump return 0xfffffbed); expired = 1.
  (Quirk: if the deadline passes without a warn tick, it never warns and so never expires.)
FFXiMain (0x1019c3f0-0x1019c5c8, the "auto logout after N minutes" option, config 0x41):
  1019c3fa  1149(warn = FFXiMain 0x1019c410 "logging out in 60 s" message, expire =
            FFXiMain 0x1019c450, which logs the character out, disables the timer (1140(0),
            1149(0,0)) and tail-jumps to 1150 at 1019c4e0 = sign out of the online session too).
  1019c401  1140(1)          1019c502/1019c50b  1140(0) + 1149(0,0)
  1019c551  1141(minutes*60*1000) then 1140(1) (1019c562); minutes == 0 -> 1140(0) (1019c57c)
  1019c592 / 1019c5b0  1140(0) / 1140(1) from the input handler 0x1015f3f0 (activity resets it)
  1019c5c2  1148(0) every frame from the main loop 0x10011a00.
Native     : keep the state machine and run the check in the native slot-705/818 pump;
             the callbacks are GUEST cdecl functions (1 arg, 0) and must be invoked through
             the recompiler's guest-call path. 1148: no-op. 1150: no online session to drop -
             no-op (optionally notify the host). Without the pump part, AFK auto-logout
             silently never fires (harmless).

-------------------------------------------------------------------------------------------------
Profanity filter: slots 362, 363 (chat) and 1109, 1110 (names)        confidence: interface HIGH,
                                                                       matcher internals MEDIUM
-------------------------------------------------------------------------------------------------
Files: R data\dic\vulgar2.dic (67,568 bytes) and R data\dic\entryz.dic (626,608 bytes), read by
FFXiMain itself (0x101c4b90 size, 0x101c47e0 read; path via slot 126 id 0x13) into a heap
buffer tagged "Vulgar" / "VulgarName". gamecore works IN PLACE on that buffer.

+0x5a8 slot 362   gamecore 0x1004e3f0   void *DicOpen(u8 *buf, const u8 opts[8], int size)
  Decrypts buf in place (patch.ver cipher, key64 = 1; payload = size-8), copies opts over
  buf[0..8), then relocates: A = buf + u32[buf+0x4a30], B = buf + u32[buf+0x4a34];
  buf+8 = A, buf+0xc = B; the 4 dwords at A and at B get (A|B) + 0x48f4 added.
  Returns buf (the handle; live: 362(0x12480ca8, …, 0x107f0) = 0x12480ca8), NULL if the
  checksum fails. Verified: vulgar2.dic decrypts with key 1 to 67,560 bytes.
  opts from FFXiMain (0x101ba42b): u32 mode = 0, u8 mask = '?', u8[2] = 81 9B (the SJIS
  full-width mask char), u8 0.
  Decrypted layout (offsets into buf): +0x10 32-byte bitmap (lead bytes / single chars that
  are "separators"), +0x30 32-byte bitmap (trail bytes), +0x50 u8[256] lead-byte class,
  +0x150 u8[256] trail-byte class, +0x250 u16[] DBCS normalisation (index =
  lead_class + trail_class*48), +0x46f4 u16[] single-byte node index, +0x48f4.. trie
  string pool, +0x4930 u8[256] single-byte normalisation, +0x4a30/+0x4a34 trie table offsets.
+0x5ac slot 363   gamecore 0x1004e4b0   int DicFilter(void *h, char *s, int len)
  = 0x1004e4d0(h, s, len, 0). Scans s (Shift-JIS aware: a byte pair is DBCS when
  lead_class[b0] && trail_class[b1]); skips separator characters; at each position looks up
  the longest match in trie B (whitelist) then trie A (vulgar words), comparing through the
  normalisation tables (case/width folding); each matched vulgar word is overwritten: every
  single byte -> opts mask ('?'), every DBCS pair -> mask + NUL (mode 0), the other modes
  (opts u32 = 1, 2) differ in how pairs are masked. If anything was masked the string is
  compacted in place (NUL bytes removed, re-terminated), so it can get shorter.
  Returns 1 if anything was masked, else 0. h NULL -> 0.
+0x1154 slot 1109 gamecore 0x1004f310   void *NameDicOpen(u8 *buf, int size)
  buf = entryz.dic. Header 8 x u32: {off0,len0, off1,len1, off2,len2, off3,len3}, offsets
  relative to buf+0x20; size must equal 0x20 + len0+len1+len2+len3 (else NULL).
  Part 0 (len 38464, "entrynw"-like): decrypted with key 0, a 0x400-bucket hash table of
  {char *word, next*} lists (offsets relocated, -1 -> NULL). Parts 1-3 (475,128 / 56,488 /
  56,496 bytes = entry.dic, entry_b.dic, entry_f.dic images): each opened with DicOpen and
  opts {0, 'X', 0,0,...}. All four decrypt with the checksum passing (verified).
  On success writes the header in place: +0 = 1 (open), +4 hash, +8 dic1, +0xc dic2,
  +0x10 dic3; returns buf. Any failure -> NULL. (FFXiMain passes (buf, size).)
+0x1158 slot 1110 gamecore 0x1004f400   int NameIsForbidden(void *h, const char *name, int len)
  h NULL or not open -> 0. Returns 1 if dic1 matches (0x1004ef40), or the hash table holds
  the name (0x1004f130), or dic2 (0x1004ef60) or dic3 (0x1004ef80) matches; else 0.
  (The three dic tests are the DicFilter matcher run in detect-only form.)
FFXiMain:
  0x101ba3a0 (from 0x101ba470 when an option == 0x18): load vulgar2.dic, 362 -> handle at
    filter+8 (live: seq 1593 at startup). 0x101ba360: if the filter is on and a handle
    exists, 363(handle, text, strlen(text)); result ignored. Used from chat input/output
    (0x100d9b30, 0x100d9e60, 0x101ca260, 0x101dd790, 0x10200df0).
  0x101ba490: load entryz.dic, 1109 -> handle (live seq 18828). 0x101ba530: returns
    (1110(h, name, strlen) == 1); used by character creation / naming (0x10238320,
    0x102384f0, 0x10239710, 0x10094170).
Native     : DESIGN DECISION.
  Minimal faithful-enough: 362 decrypt+relocate as above (or just return buf), 363 return 0
  and leave the text alone (= filter off, which is also the retail option GOPN1_HF default),
  1109 validate the header and return buf, 1110 return 0 (LSB validates names server-side).
  Exact port: the matcher is ~1,000 instructions (0x1004e4d0-0x1004ef13 and 0x1004ef40-
  0x1004f2ff); it is pure computation on the decrypted buffers, so a later bit-exact port can
  be checked against the real code under unicorn (harness used for this file: scratchpad
  files/emu.py). Not done here.

-------------------------------------------------------------------------------------------------
Not present / not in FFXI's surface
-------------------------------------------------------------------------------------------------
  1134/1135/1136 exist and are covered above. Slots 921-931, 195/196, 465, 705/818, 1535/1536
  are touched here only as dependencies (other groups).

-------------------------------------------------------------------------------------------------
Open items / design decisions
-------------------------------------------------------------------------------------------------
  1. Slot 1171 (patch.ver) is on the boot path. Recommended: decrypt without the registry by
     known-plaintext key recovery (proved on all 3 retail files). Alternatives in the block.
  2. option.bin: read yes (key 0); write back or not (slot 910).
  3. Profanity filter: stub (filter off) vs exact port.
  4. English texts for slots 1071/1303 (retail wording lives in the Viewer catalog).
  5. Slot 464/465: no account storage server - answer "NO DATA".
  6. AFK timer (1140-1150): only works if the native slot-705 pump runs the check and can call
     guest callbacks.
