74 lines
4.9 KiB
Python
74 lines
4.9 KiB
Python
"""Byte parity with the pinned original70334 mirror-timer packet writers.
|
|
|
|
Read-only source extraction; compile only under a fresh runtime temporary dir.
|
|
No game, credential, network, installed module or root-build interaction.
|
|
"""
|
|
from pathlib import Path
|
|
import hashlib,json,re,shlex,subprocess,sys,tempfile
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
FOREVER=ROOT.parent/'servers/trinity-forever'
|
|
source=FOREVER/'src/server/game/Server/Packets/MiscPackets.cpp'
|
|
if not source.is_file()or not(FOREVER/'build/build.ninja').is_file():raise SystemExit(77)
|
|
profile=json.loads((ROOT/'docs/FOREVER_SCHEMA_PROFILE.json').read_text())
|
|
assert hashlib.sha256(source.read_bytes()).hexdigest()==profile['forever_sha256'][str(source.relative_to(FOREVER))]
|
|
text=source.read_text();methods=[]
|
|
for name in('StartMirrorTimer','PauseMirrorTimer','StopMirrorTimer'):
|
|
start=text.index('WorldPacket const* '+name+'::Write()');brace=text.index('{',start);end=brace+1;depth=1
|
|
while depth:depth+=(text[end]=='{')-(text[end]=='}');end+=1
|
|
methods.append(text[start:end])
|
|
ninja=(FOREVER/'build/build.ninja').read_text();start=ninja.index('build src/server/game/CMakeFiles/game.dir/Entities/Object/Updates/UpdateFields.cpp.o:');block=ninja[start:ninja.index('\n\nbuild ',start)]
|
|
includes=shlex.split(re.search(r' INCLUDES = (.+)',block)[1])
|
|
with tempfile.TemporaryDirectory(dir=ROOT/'runtime',prefix='mirror-timer-writer-')as tmp:
|
|
d=Path(tmp);cpp=d/'oracle.cpp'
|
|
cpp.write_text('''// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include "MiscPackets.h"
|
|
#include "PacketOperators.h"
|
|
#include "Errors.h"
|
|
#include "gateway/mirror_timer.hpp"
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
void ByteBuffer::append(uint8 const* src,size_t count){
|
|
if(!src||!count||_wpos+count>1048576)throw ByteBufferPositionException(_wpos,size(),count);
|
|
FlushBits();if(_storage.size()<_wpos+count)_storage.resize(_wpos+count);
|
|
std::memcpy(_storage.data()+_wpos,src,count);_wpos+=count;
|
|
}
|
|
ByteBufferPositionException::ByteBufferPositionException(size_t,size_t,size_t):ByteBufferException("buffer range"){}
|
|
ByteBufferInvalidValueException::ByteBufferInvalidValueException(char const*,std::string_view):ByteBufferException("invalid buffer"){}
|
|
WorldPackets::Packet::Packet(WorldPacket&& p):_worldPacket(std::move(p)){}
|
|
WorldPackets::ServerPacket::ServerPacket(OpcodeServer op,size_t size,ConnectionType c):Packet(WorldPacket(op,size,c)){}
|
|
void WorldPackets::ServerPacket::Read(){std::abort();}
|
|
namespace Trinity{
|
|
[[noreturn]]void Assert(char const*,int,char const*,char const*,std::string)noexcept{std::abort();}
|
|
[[noreturn]]void Assert(char const*,int,char const*,char const*,std::string,char const*,...)noexcept{std::abort();}
|
|
}
|
|
std::string GetDebugInfo(){return {};}
|
|
namespace WorldPackets::Misc{
|
|
'''+ '\n'.join(methods)+'''
|
|
}
|
|
static void compare(uint32_t op,gateway::Bytes input,WorldPackets::ServerPacket& native){
|
|
auto translated=gateway::forever_mirror_timer(op,input);auto packet=native.Write();
|
|
uint32_t wireOpcode=0;
|
|
switch(uint32_t(native.GetOpcode())){case 0x4501bb:wireOpcode=0x4701bb;break;case 0x4501bc:wireOpcode=0x4701bc;break;case 0x4501bd:wireOpcode=0x4701bd;break;default:throw gateway::Error("unreviewed mirror writer opcode");}
|
|
if(translated.opcode!=wireOpcode||translated.body!=gateway::Bytes(packet->data(),packet->data()+packet->size()))throw gateway::Error("original writer mismatch");
|
|
}
|
|
int main(){try{
|
|
unsigned n=0;
|
|
for(uint8_t timer=0;timer<3;++timer)for(int32_t value:{0,1,45000,60000})for(int32_t scale:{-1,0,10,INT32_MIN,INT32_MAX})for(bool paused:{false,true})for(int32_t spell:{0,5384}){
|
|
gateway::Bytes input;for(auto v:{uint32_t(timer),uint32_t(value),60000u,uint32_t(scale)})gateway::le(input,v,4);gateway::le(input,paused,1);gateway::le(input,spell,4);
|
|
WorldPackets::Misc::StartMirrorTimer native(timer,value,60000,scale,spell,paused);compare(0x1d9,input,native);++n;
|
|
}
|
|
for(uint8_t timer=0;timer<3;++timer){
|
|
gateway::Bytes input;gateway::le(input,timer,4);WorldPackets::Misc::StopMirrorTimer native(timer);compare(0x1db,input,native);++n;
|
|
for(bool paused:{false,true}){auto b=input;gateway::le(b,paused,1);WorldPackets::Misc::PauseMirrorTimer pause(timer,paused);compare(0x1da,b,pause);++n;}
|
|
}
|
|
std::cout<<n<<" complete mirror timer payloads match reference writers; opcodes match pinned70334 normalization. Offline only.\\n";
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\\n';return 1;}}
|
|
''')
|
|
# CMake supplies TARGET_FILE from its binary directory, which may be outside
|
|
# the source tree. Reuse that archive read-only; never trigger a build.
|
|
archive=Path(sys.argv[1]).resolve()if len(sys.argv)>1 else ROOT/'build/libgateway_protocol.a'
|
|
assert archive.is_file(), f'Protocol archive missing: {archive}'
|
|
cmd=['clang++','-std=c++20','-O1','-DFMT_HEADER_ONLY','-DBOOST_BIND_NO_PLACEHOLDERS','-DBOOST_ASIO_NO_DEPRECATED',*includes,'-I'+str(ROOT/'include'),str(cpp),str(archive),'-lcrypto','-lz','-o',str(d/'oracle')]
|
|
subprocess.run(cmd,check=True)
|
|
subprocess.run([str(d/'oracle')],check=True)
|