Files
AVA2/tools/generate_login_oracle.py
T
shenleiandClaude Opus 5.5 31c74cec28 Net: port the select-phase packets
Character create/delete/rename and empire selection now reach the
server, and LOGIN_SUCCESS3, PLAYER_CREATE_SUCCESS/FAILURE,
PLAYER_DELETE_SUCCESS/WRONG_SOCIAL_ID, POINT_CHANGE and CHANGE_NAME are
parsed and forwarded to the select/create windows like Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 13:27:52 +09:00

53 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Compile original AVA2 declarations using explicit Win32-width types as an oracle."""
from pathlib import Path
import re,sys
root=Path(__file__).resolve().parents[1]
client=(root/'upstream/ava2-client/UserInterface/Packet.h').read_text(errors='replace')
server=(root/'upstream/ava2-server/common/tables.h').read_text(errors='replace')
packet=(root/'upstream/ava2-server/game/src/packet.h').read_text(errors='replace')
tea=(root/'upstream/ava2-client/EterBase/tea.cpp').read_text(errors='replace')
def declaration(source, start, end):
text=source[source.index(start):]
text=text[:text.index(end)+len(end)]
text=re.sub(r'\blong\s+long\b','std::int64_t',text)
return re.sub(r'\blong\b','std::int32_t',text)
def struct(source, tag, name):
match=re.search(r'typedef struct '+tag+r'\s*\{',source)
return declaration(source[match.start():],'typedef struct','} '+name+';')
# Both baseline macro headers enable sash, conqueror and five-character accounts.
for path,names in [
('upstream/ava2-client/UserInterface/Locale_inc.h',['ENABLE_SASH_SYSTEM','ENABLE_CONQUEROR_LEVEL','ENABLE_PLAYER_PER_ACCOUNT5']),
('upstream/ava2-server/common/CommonDefines.h',['__SASH_SYSTEM__','ENABLE_CONQUEROR_LEVEL','ENABLE_PLAYER_PER_ACCOUNT5'])]:
text=(root/path).read_text(errors='replace')
for name in names:
assert re.search(r'^\s*#\s*define\s+'+name+r'\b',text,re.M), name+' not active in baseline'
header='''#pragma once
#include <cstdint>
namespace ava2_oracle {
using BYTE=std::uint8_t; using WORD=std::uint16_t; using DWORD=std::uint32_t; using LONG=std::int32_t;
constexpr int CHARACTER_NAME_MAX_LEN=24, GUILD_NAME_MAX_LEN=12, PLAYER_PER_ACCOUNT3=3, PLAYER_PER_ACCOUNT4=5, PLAYER_PER_ACCOUNT=5, PRIVATE_CODE_LENGTH=8;
#define ENABLE_SASH_SYSTEM
#define __SASH_SYSTEM__
#define ENABLE_CONQUEROR_LEVEL
#pragma pack(push,1)
namespace client {
'''+declaration(client,'typedef struct SSimplePlayerInformation','} TSimplePlayerInformation;')+'\n'+declaration(client,'typedef struct packet_login_success4','} TPacketGCLoginSuccess4;')+'\n'+'\n'.join(struct(client,tag,name) for tag,name in [
# SelectPhase packets (PythonNetworkStreamPhaseSelect.cpp)
('packet_login_success3','TPacketGCLoginSuccess3'),('command_player_create_success','TPacketGCPlayerCreateSuccess'),
('packet_point_change','TPacketGCPointChange'),('SPacketGCChangeName','TPacketGCChangeName'),
('command_player_create','TPacketCGCreateCharacter'),('command_player_delete','TPacketCGDestroyCharacter'),
('SPacketCGChangeName','TPacketCGChangeName')])+'\n}\nnamespace server {\n'+declaration(server,'typedef struct SSimplePlayer','} TSimplePlayer;')+'\n'+declaration(packet,'typedef struct packet_login_success','} TPacketGCLoginSuccess;')+'''\n}
#pragma pack(pop)
namespace original_cipher {
'''
start=tea.index('#define TEA_ROUND')
end=tea.index('int tea_encrypt(' , start)
text=tea[start:end].replace('unsigned long','std::uint32_t').replace('register ','')
header+=text+'\n}\n#undef ENABLE_SASH_SYSTEM\n#undef __SASH_SYSTEM__\n#undef ENABLE_CONQUEROR_LEVEL\n}\n'
out=Path(sys.argv[1]);out.parent.mkdir(parents=True,exist_ok=True);out.write_text(header)