- gr2: BitKnit2 decompression, 64-bit LE files, compressed curves - net: remaining GamePhase handlers, generated GC packet table - python: event/chat/chr/minimap/guild/quest/messenger/shop-search and other native modules ported against the AVA2 Windows client - render: D3D8 fixed-function lighting in Gr2ModelRenderer, terrain without baked shade; cape/NPC equipment attachment - tests + audits updated; docs/PORT-PLAN.md and WINDOWS-PARITY.md Batch 4 (render pipeline: background.*, app.RenderGame/UpdateGame, camera bindings, main.cpp fake-content removal) is still in progress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
135 lines
5.8 KiB
Python
135 lines
5.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate src/eter_net/Ava2GcPacketTable.inc from the AVA2 Windows reference.
|
|
|
|
Source of truth:
|
|
* UserInterface/PythonNetworkStream.cpp CMainPacketHeaderMap (header -> size, static/dynamic)
|
|
* UserInterface/PythonNetworkStreamPhaseGame.cpp GamePhase() switch (headers with a handler)
|
|
* UserInterface/Packet.h + Locale_inc.h struct layouts and feature defines
|
|
|
|
sizeof() is evaluated by clang for i686-pc-windows-msvc (the Win32 client ABI) with
|
|
_USE_32BIT_TIME_T semantics (StdAfx.h), so the table is the Win32 wire size, not a
|
|
guess. Only constants used by Packet.h are stubbed; they are copied from the reference.
|
|
"""
|
|
import json
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
ui = root / "upstream/ava2-client/UserInterface"
|
|
out = root / "src/eter_net/Ava2GcPacketTable.inc"
|
|
|
|
|
|
def ascii_text(path):
|
|
return re.sub(r"[^\t\n\r\x20-\x7e]", "", path.read_bytes().decode("latin1"))
|
|
|
|
|
|
PRELUDE = """
|
|
#include <stdint.h>
|
|
typedef uint8_t BYTE; typedef uint16_t WORD; typedef uint32_t DWORD; typedef int32_t LONG;
|
|
typedef int BOOL; typedef uint32_t UINT; typedef int INT; typedef int64_t LONGLONG;
|
|
typedef uint64_t ULONGLONG; typedef int16_t SHORT; typedef char CHAR; typedef float FLOAT;
|
|
#define NULL 0
|
|
typedef int time_t; /* StdAfx.h: _USE_32BIT_TIME_T */
|
|
typedef unsigned int size_t;
|
|
extern "C" void* memset(void*, int, size_t); extern "C" float sqrtf(float);
|
|
class CResource {}; struct TPixelPosition { float x, y, z; };
|
|
namespace std { template<class T> struct vector { T* a; T* b; T* c; }; struct string { char b[24]; };
|
|
template<class K, class V, class C = int> struct map {}; template<class A, class B> struct pair { A first; B second; }; }
|
|
/* UserInterface/StdAfx.h */
|
|
enum { POINT_MAX_NUM = 255, CHARACTER_NAME_MAX_LEN = 24, PLAYER_NAME_MAX_LEN = 12 };
|
|
"""
|
|
|
|
# GameLib/ItemData.h CItemData enum values referenced by Packet.h / GameType.h
|
|
ITEMDATA = """#pragma once
|
|
class CItemData { public: enum { ITEM_NAME_MAX_LEN = 24, ITEM_LIMIT_MAX_NUM = 2, ITEM_VALUES_MAX_NUM = 6,
|
|
ITEM_APPLY_MAX_NUM = 3, ITEM_SOCKET_MAX_NUM = 8, WEAR_MAX_NUM = 32, DS_SLOT_NUM_TYPES = 6 }; };
|
|
"""
|
|
|
|
|
|
def header_map_body():
|
|
text = ascii_text(ui / "PythonNetworkStream.cpp")
|
|
start = text.index("CMainPacketHeaderMap()")
|
|
body_start = text.index("{", start) + 1
|
|
end = text.index("\n};", body_start)
|
|
body = text[body_start:end].rstrip()
|
|
assert body.endswith("}")
|
|
return body[:-1]
|
|
|
|
|
|
def game_switch_body():
|
|
text = ascii_text(ui / "PythonNetworkStreamPhaseGame.cpp")
|
|
start = text.index("void CPythonNetworkStream::GamePhase()")
|
|
end = text.index("RecvDefaultPacket(header)", start)
|
|
lines = []
|
|
body = re.sub(r"/\*.*?\*/", "", text[start:end], flags=re.S)
|
|
for line in body.splitlines():
|
|
s = line.split("//", 1)[0].strip()
|
|
if re.match(r"#\s*(if|ifdef|ifndef|else|elif|endif)\b", s):
|
|
lines.append(s)
|
|
else:
|
|
for m in re.finditer(r"case\s+(HEADER_GC_\w+)\s*:", s):
|
|
lines.append(f"handled[{m.group(1)}] = 1;")
|
|
return "\n".join(lines)
|
|
|
|
|
|
GEN = """#include "Locale_inc.h"
|
|
#include "GameType.h"
|
|
#include "Packet.h"
|
|
struct CNetworkPacketHeaderMap { struct TPacketType { int s, d; constexpr TPacketType(int a = 0, int b = 0) : s(a), d(b) {} }; };
|
|
struct Table {
|
|
enum { STATIC_SIZE_PACKET = 0, DYNAMIC_SIZE_PACKET = 1 };
|
|
int size[256] = {}; int dyn[256] = {}; int set[256] = {}; int handled[256] = {};
|
|
constexpr void Set(int h, CNetworkPacketHeaderMap::TPacketType t) { size[h] = t.s; dyn[h] = t.d; set[h] = 1; }
|
|
constexpr Table() {
|
|
#include "map.inc"
|
|
#include "switch.inc"
|
|
}
|
|
};
|
|
extern "C" const Table exported_table = Table();
|
|
"""
|
|
|
|
|
|
def main():
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
tmp = Path(tmp)
|
|
(tmp / "x").mkdir()
|
|
(tmp / "GameLib").mkdir()
|
|
for name in ("Packet.h", "GameType.h", "Locale_inc.h"):
|
|
(tmp / "x" / name).write_bytes((ui / name).read_bytes())
|
|
(tmp / "x" / "Locale.h").write_text("")
|
|
(tmp / "GameLib" / "ItemData.h").write_text(ITEMDATA)
|
|
(tmp / "GameLib" / "RaceData.h").write_text("")
|
|
(tmp / "prelude.h").write_text(PRELUDE)
|
|
(tmp / "map.inc").write_text(header_map_body())
|
|
(tmp / "switch.inc").write_text(game_switch_body())
|
|
(tmp / "gen.cpp").write_text(GEN)
|
|
cmd = ["clang++", "-target", "i686-pc-windows-msvc", "-fms-extensions", "-fms-compatibility",
|
|
"-std=c++17", "-S", "-emit-llvm", "-o", str(tmp / "gen.ll"), "-I", str(tmp / "x"),
|
|
"-I", str(tmp), "-include", str(tmp / "prelude.h"), str(tmp / "gen.cpp")]
|
|
subprocess.run(cmd, check=True)
|
|
ir = (tmp / "gen.ll").read_text()
|
|
line = next(l for l in ir.splitlines() if l.startswith("@exported_table"))
|
|
values = []
|
|
for m in re.finditer(r"\[(\d+) x i32\] zeroinitializer|(?<![x\[] )i32 (-?\d+)", line.split("} {", 1)[1]):
|
|
values += [0] * int(m.group(1)) if m.group(1) else [int(m.group(2))]
|
|
if len(values) != 1024:
|
|
sys.exit(f"unexpected IR table length {len(values)}")
|
|
size, dyn, present, handled = (values[i * 256:(i + 1) * 256] for i in range(4))
|
|
rows = []
|
|
for h in range(256):
|
|
if present[h] or handled[h]:
|
|
rows.append(f" {{{h}, {size[h]}, {int(bool(dyn[h]))}, {int(bool(present[h]))}, {int(bool(handled[h]))}}},")
|
|
out.write_text(
|
|
"// Generated by tools/generate_ava2_gc_packet_table.py from the AVA2 Windows reference\n"
|
|
"// (CMainPacketHeaderMap in PythonNetworkStream.cpp + GamePhase() switch, Win32 i686 layout).\n"
|
|
"// {header, size, dynamic, in CMainPacketHeaderMap, handled by GamePhase()}\n"
|
|
+ "\n".join(rows) + "\n")
|
|
print(f"{sum(present)} mapped headers, {sum(handled)} GamePhase handlers -> {out.relative_to(root)}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|