Every locale.cfg client build is LOCALE_SERVICE_EUROPE and sends CG_CLIENT_VERSION2, and 203 compares that timestamp with atoi against 1215955205. The client now sends "1215955205 mt20261016", so the gate looks for "mt" instead of requiring it at the start. Found on channel5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
8.4 KiB
Python
114 lines
8.4 KiB
Python
#!/usr/bin/env python3
|
|
"""AVA2 switchbot (docs/FEATURE-SWITCHBOT.md): the SWITCHBOT window (7), AVA2's headers 171 / GG 31 with the
|
|
same subheaders and field order, wire sizes pinned by static_assert and mirrored by the client, the window
|
|
hooks, the P2P hand-over, the boot ALTER and the switcher choice. The old /mt_switchbot command is gone."""
|
|
from pathlib import Path
|
|
import re
|
|
ROOT=Path(__file__).resolve().parents[2]
|
|
SRC=ROOT/'src/server'
|
|
CLIENT=ROOT.parent/'metin2-client/src/port/UserInterface'
|
|
def source(name):return (SRC/name).read_bytes().decode('latin1')
|
|
def enum_after(text,start,end):
|
|
body=text[text.index(start):];body=body[:body.index(end)]
|
|
return re.findall(r'^\s*([A-Z_0-9]+)\s*[,=]',body,re.M)
|
|
def struct(text,name):
|
|
body=text[text.index('struct %s\n'%name):];body=body[:body.index('};')]
|
|
return re.findall(r'^\s*([A-Za-z_][A-Za-z_0-9]*)\s+(\w+)(\[[^;]*\])?;',body,re.M)
|
|
|
|
length=source('common/length.h')
|
|
windows=enum_after(length,'enum EWindows','};')
|
|
assert windows.index('SWITCHBOT')==7 and windows[6]=='BELT_INVENTORY',windows
|
|
for k,v in (('SWITCHBOT_SLOT_COUNT',6),('SWITCHBOT_SLOT_COUNT_REAL',5),('SWITCHBOT_ALTERNATIVE_COUNT',2),('SWITCHBOT_NORM_ATTR_NUM',5)):
|
|
assert re.search(r'\b%s = %d,'%(k,v),length),k
|
|
assert 'bool IsSwitchbotPosition() const' in length
|
|
|
|
packet=source('game/src/packet.h')
|
|
for name,v in (('HEADER_CG_SWITCHBOT',171),('HEADER_GC_SWITCHBOT',171),('HEADER_GG_SWITCHBOT',31)):
|
|
assert re.search(r'\b%s\s*= %d,'%(name,v),packet),name
|
|
cg=enum_after(packet,'enum ECGSwitchbotSubheader','};');gc=enum_after(packet,'enum EGCSwitchbotSubheader','};')
|
|
assert cg==['SUBHEADER_CG_SWITCHBOT_START','SUBHEADER_CG_SWITCHBOT_STOP'],cg
|
|
assert gc==['SUBHEADER_GC_SWITCHBOT_UPDATE','SUBHEADER_GC_SWITCHBOT_UPDATE_ITEM','SUBHEADER_GC_SWITCHBOT_SEND_ATTRIBUTE_INFORMATION'],gc
|
|
head=[('BYTE','header'),('int','size'),('BYTE','subheader'),('BYTE','slot')]
|
|
for name in ('TPacketCGSwitchbot','TPacketGCSwitchbot'):
|
|
assert [(t,n) for t,n,_ in struct(packet,name)]==head,name
|
|
upd=struct(packet,'TSwitchbotUpdateItem')
|
|
assert upd==[('BYTE','slot',''),('DWORD','vnum',''),('WORD','count',''),('long','alSockets','[ITEM_SOCKET_MAX_NUM]'),
|
|
('TPlayerItemAttribute','aAttr','[ITEM_ATTRIBUTE_MAX_NUM]')],upd
|
|
tables=source('common/tables.h')
|
|
assert tables.index('#pragma pack(1)')<tables.index('struct TSwitchbotTable')<tables.rindex('#pragma pack()')
|
|
assert packet.index('#pragma pack(1)')<packet.index('struct TSwitchbotUpdateItem')<packet.rindex('#pragma pack()')
|
|
table=[n for _,n,_ in struct(tables,'TSwitchbotTable')]
|
|
assert table==['player_id','active','finished','items','alternatives'],table
|
|
|
|
port=source('game/src/port_switchbot.cpp')
|
|
sizes={'TSwitchbotTable':220,'TSwitchbotAttributeAlternativeTable':15,'TSwitchbottAttributeTable':9,'TSwitchbotUpdateItem':40}
|
|
for name,size in sizes.items():assert 'static_assert(sizeof(%s) == %d,'%(name,size) in port,name
|
|
assert 'static_assert(sizeof(TPacketCGSwitchbot) == 7 && sizeof(TPacketGCSwitchbot) == 7,' in port
|
|
assert 'static_assert(sizeof(TPacketGGSwitchbot) == 223,' in port
|
|
|
|
# switcher choice and roll path
|
|
for text in ('const float c_fSpeed = 0.1f;','return FindUsableSwitcher(ch, 71302);','s_adwLow[] = { 71151, 76023 };',
|
|
's_adwNormal[] = { 71084, 39028 };','ItemLog(pkOwner, pkScroll, "SWITCHBOT", szHint);',
|
|
'"switchbot_end %d"','"switchbot_stop noattr %d"','"switchbot_stop nochanger %d"',
|
|
'SWITCHBOT_ATTRIBUTE_SET_NEW_RINGS = ATTRIBUTE_SET_MAX_NUM,','GetNewRingAttrMaxValue(','GetPendantAttrMaxValue(',
|
|
"'BELT_INVENTORY','SWITCHBOT') NOT NULL DEFAULT 'INVENTORY'"):
|
|
assert text in port,text
|
|
# costume enchants and the other talisman scrolls never roll: only these vnums are looked up
|
|
assert 'IsCostumeEnchant' not in port and 'GetPendantScrollKind' not in port
|
|
|
|
items=source('game/src/char_item.cpp')
|
|
for text in ('return m_pointsInstant.pSwitchbotItems[wCell];','CSwitchbotManager::Instance().RegisterItem(GetPlayerID(), pItem->GetID(), wCell);',
|
|
'CSwitchbotManager::Instance().UnregisterItem(GetPlayerID(), wCell);','pItem->SetWindow(SWITCHBOT);',
|
|
'if (wCell >= SWITCHBOT_SLOT_COUNT_REAL)\n\t\t\t\treturn false;','"switchbot_error active"','"switchbot_error invalid"',
|
|
'if (!other.IsSwitchbotPosition() && !other.IsDefaultInventoryPosition())'):
|
|
assert text in items,text
|
|
assert items.count('if (Cell.IsSwitchbotPosition())\t// PORT: switchbot items go back to the inventory first')==2 # drop + give
|
|
char_h=source('game/src/char.h')
|
|
assert re.search(r'LPITEM\s+pSwitchbotItems\[SWITCHBOT_SLOT_COUNT\];',char_h) and 'm_portSwitchbotLastCommand' not in char_h
|
|
assert 'if (m_bWindow == SWITCHBOT)' in source('game/src/item.cpp')
|
|
assert 'if (item_pos.IsSwitchbotPosition())' in source('game/src/exchange.cpp')
|
|
inputs=source('game/src/input_main.cpp')
|
|
assert inputs.count('p->ItemPos.IsSwitchbotPosition()')==2 # safebox checkin + checkout
|
|
assert 'case HEADER_CG_SWITCHBOT:\n\t\t\tif ((iExtraLen = Switchbot(ch, c_pData, m_iBufferLeft)) < 0)' in inputs
|
|
info=source('game/src/packet_info.cpp')
|
|
assert 'Set(HEADER_CG_SWITCHBOT, sizeof(TPacketCGSwitchbot), "Switchbot", true);' in info
|
|
assert re.search(r'Set\(HEADER_GG_SWITCHBOT,\s*sizeof\(TPacketGGSwitchbot\),\s*"Switchbot",\s*false\);',info)
|
|
assert 'case HEADER_GG_SWITCHBOT:' in source('game/src/input_p2p.cpp')
|
|
char=source('game/src/char.cpp')
|
|
warp=char[char.index('CSwitchbotManager::Instance().SetIsWarping(GetPlayerID(), true);'):]
|
|
assert warp.index('P2PSendSwitchbot(GetPlayerID(), p.wPort)')<warp.index('GetDesc()->Packet(&p, sizeof(TPacketGCWarp))')
|
|
assert 'CSwitchbotManager::Instance().EnterGame(ch);' in source('game/src/input_login.cpp')
|
|
# version gate: only "mt<date>" clients from PORT_SWITCHBOT_CLIENT_VERSION on get GC_SWITCHBOT at EnterGame
|
|
assert 'enum { PORT_SWITCHBOT_CLIENT_VERSION = 20261016 };' in source('game/src/port_switchbot.h')
|
|
enter=port[port.index('void CSwitchbotManager::EnterGame'):];enter=enter[:enter.index('\n}\n')]
|
|
assert enter.index('if (!SwitchbotHelper::IsClientSupported(ch))\n\t\treturn;')<enter.index('SendItemAttributeInformations(ch);')
|
|
assert 'strstr(d->GetClientVersion(), "mt")' in port and 'atoi(c_pszMark + 2) >= PORT_SWITCHBOT_CLIENT_VERSION' in port
|
|
assert 'case SWITCHBOT:' in source('game/src/input_db.cpp')
|
|
main=source('game/src/main.cpp')
|
|
assert 'CSwitchbotManager switchbotManager;' in main and 'PortSwitchbotBoot();' in main
|
|
assert source('db/src/ClientManagerPlayer.cpp').count('SAFEBOX, DRAGON_SOUL_INVENTORY, SWITCHBOT')==3
|
|
assert 'port_switchbot.cpp' in source('game/src/Makefile')
|
|
assert '"mt_switchbot"' not in source('game/src/cmd.cpp') and 'port_switchbot.h' not in source('game/src/cmd_general.cpp')
|
|
|
|
# the client mirrors headers, subheaders, structs and sizes (packets in Packet.h, the table in PythonSwitchbot.h)
|
|
cpacket=CLIENT/'Packet.h'
|
|
if cpacket.is_file():
|
|
client=cpacket.read_bytes().decode('latin1')
|
|
for name in ('HEADER_CG_SWITCHBOT','HEADER_GC_SWITCHBOT'):
|
|
assert re.search(r'\b%s\s*= 171,'%name,client),name
|
|
assert enum_after(client,'enum ECGSwitchbotSubheader','};')==cg
|
|
assert enum_after(client,'enum EGCSwitchbotSubheader','};')==gc
|
|
assert [n for _,n,_ in struct(client,'TSwitchbotUpdateItem')]==[n for _,n,_ in upd]
|
|
assert 'static_assert(sizeof(TSwitchbotUpdateItem) == 40,' in client
|
|
assert 'static_assert(sizeof(TPacketCGSwitchbot) == 7 && sizeof(TPacketGCSwitchbot) == 7,' in client
|
|
stream=(CLIENT/'PythonNetworkStreamPhaseGame.cpp').read_bytes().decode('latin1')
|
|
# the EU branch (the one every locale.cfg build takes) keeps 1215955205 first for the atoi version check
|
|
assert 'strncpy(kVersionPacket.timestamp, "1215955205 mt20261016", sizeof(kVersionPacket.timestamp)-1);' in stream
|
|
assert 'strncpy(kVersionPacket.timestamp, "mt20261016", sizeof(kVersionPacket.timestamp)-1);' in stream
|
|
pyswitch=(CLIENT/'PythonSwitchbot.h').read_bytes().decode('latin1')
|
|
ctable=pyswitch[pyswitch.index('struct TSwitchbotTable'):];ctable=ctable[:ctable.index('};')]
|
|
assert re.findall(r'^\s*[A-Za-z_][\w:]*\s+(\w+)(?:\[[^;]*\])?;',ctable,re.M)==table,ctable
|
|
for name in ('TSwitchbotTable','TSwitchbotAttributeAlternativeTable','TSwitchbottAttributeTable'):
|
|
assert 'static_assert(sizeof(CPythonSwitchbot::%s) == %d,'%(name,sizes[name]) in pyswitch,name
|
|
print('PASS: SWITCHBOT window 7, version gate mt20261016, CG/GC 171 + GG 31, AVA2 subheaders/fields, sizes 220/15/9/40/7/223, window hooks, P2P, boot ALTER, switchers 71302/71151/76023/71084/39028')
|