Files

1830 lines
120 KiB
C

#include "client_drop_diagnostic.h"
#include "accepted_feature_defaults.h"
#include "battleground_requests.h"
#include "club_bootstrap.h"
/* Experimental70334 engine-owned TCP adapter. No listeners/sockets, account
* state writes, fabricated events, Lua callbacks or external packet process.
* Bind only after the verified original pipe constructor and before connect.
*/
#include <windows.h>
#include "wine_wire_abi.h"
#include "wine_wire_host.h"
#include "wine_pipe_host.h"
#include "wine_session_retirement.h"
#include "engine_realm_context.h"
#include "current_realm_record.h"
#include "login_timing.h"
#include "wine_engine_realm.h"
#include "wine_channel_policy.h"
#include "hotfix_request_split.h"
#include "spell_hotfix_trace.h"
#include "world_locator_fifo.h"
#include "gateway/spellbook_hidden_readiness.h"
#include "engine_spell_locator_ready.h"
#include "engine_original_main_header.h"
#include "engine_shipped_main_header.h"
#include "native_account_name.h"
#include "native_account_reserve_code.h"
extern struct gw_engine_realm_previous gw_wire_realm_previous;
extern NTSTATUS WINAPI gw_wire_account_transport(struct gw_wire_call*);
extern LONG WINAPI gw_wire_account_attach_engine_session(void);
extern LONG WINAPI gw_wire_club_source_context_state(void);
extern LONG WINAPI gw_wire_account_engine_heartbeat(void);
extern void WINAPI gw_wire_account_detach_engine_session(void);
extern uint32_t WINAPI gw_wire_account_generation(void);
extern struct gw_wire_auth_control gw_wire_auth_data;
__declspec(dllexport) struct gw_pipe_control gw_wire_pipe_data={.abi=1,.size=sizeof(struct gw_pipe_control)};
__declspec(dllexport) struct gw_pipe_create_observation gw_wire_create_observation={.abi=1,.size=sizeof(struct gw_pipe_create_observation)};
__declspec(dllexport) struct gw_pipe_db_queries gw_wire_pipe_queries={.abi=1,.size=sizeof(struct gw_pipe_db_queries)};
__declspec(dllexport) struct gw_pipe_hotfix gw_wire_hotfix_data={.abi=1,.size=sizeof(struct gw_pipe_hotfix)};
__declspec(dllexport) struct gw_pipe_spell_locator_barrier gw_wire_spell_locator_barrier={.abi=1,.size=sizeof(struct gw_pipe_spell_locator_barrier)};
__declspec(dllexport) struct gw_pipe_spell_locator_guard gw_wire_spell_locator_guard={.abi=1,.size=sizeof(struct gw_pipe_spell_locator_guard)};
__declspec(dllexport) struct gw_pipe_initial_spell_ids_call gw_wire_initial_spell_ids_call={.abi=1,.size=sizeof(struct gw_pipe_initial_spell_ids_call)};
__declspec(dllexport) struct gw_pipe_entities gw_wire_entity_data={.abi=3,.size=sizeof(struct gw_pipe_entities),.unit_fields={.abi=1,.size=2080}};
__declspec(dllexport) struct gw_pipe_world_control gw_wire_world_data={.abi=1,.size=sizeof(struct gw_pipe_world_control)};
__declspec(dllexport) struct gw_pipe_world_failure gw_wire_world_failure={.abi=1,.size=48};
__declspec(dllexport) struct gw_pipe_world_call_failure gw_wire_world_call_failure={.abi=1,.size=32};
__declspec(dllexport) struct gw_pipe_world_call_phase gw_wire_world_call_phase={.abi=1,.size=16};
__declspec(dllexport) struct gw_pipe_motion gw_wire_motion_data={.abi=2,.size=sizeof(struct gw_pipe_motion)};
__declspec(dllexport) struct gw_pipe_item_request gw_wire_item_request={.abi=1,.size=sizeof(struct gw_pipe_item_request)};
__declspec(dllexport) struct gw_pipe_item_request gw_wire_spell_request={.abi=1,.size=sizeof(struct gw_pipe_item_request)};
__declspec(dllexport) struct gw_pipe_cast_result gw_wire_cast_result={.abi=1,.size=sizeof(struct gw_pipe_cast_result)};
__declspec(dllexport) struct gw_pipe_inventory gw_wire_inventory_data={.abi=2,.size=sizeof(struct gw_pipe_inventory)};
__declspec(dllexport) struct gw_pipe_auras gw_wire_aura_data={.abi=1,.size=sizeof(struct gw_pipe_auras)};
__declspec(dllexport) struct gw_pipe_movement_failure gw_wire_movement_failure={.abi=1,.size=48};
/* Cached public shape/rejection metadata only; survives a failed roster encode.
* Names, GUIDs, credentials and raw packet bytes are never copied here. */
__declspec(dllexport) struct gw_native_roster_diagnostics gw_wire_roster_diagnostics_data={.abi=GW_NATIVE_ROSTER_DIAGNOSTICS_ABI,.size=sizeof(struct gw_native_roster_diagnostics)};
_Static_assert(sizeof(struct gw_native_roster_diagnostics)==256,"Public roster metadata ABI changed");
static SRWLOCK lock=SRWLOCK_INIT;
static volatile LONG pipe_generation=1;
/* Source kicks players after repeated CMSG_PING intervals below 27 seconds.
* The modern client can ping more often; keep Source's clock independent of
* client pongs, as the Linux relay already does. Protected by lock. */
static ULONGLONG last_source_ping_ms;
/* Sealed only by authenticated source-backed transfer presentations. This is
* a forwarding bridge while the genuine native world is loading, never a
* self-create/world-ready claim. Owner/connection proofs remain mandatory. */
static volatile LONG transfer_phase;
static uint64_t transfer_owner,transfer_connection;
static void clear_transfer_bridge(void){InterlockedExchange(&transfer_phase,0);}
static int transfer_bridge_matches(void){
return InterlockedCompareExchange(&transfer_phase,0,0)>0 &&
transfer_owner==gw_wire_pipe_data.owner && transfer_connection==gw_wire_pipe_data.connection;
}
static unsigned char challenge[8],incoming[65533],outgoing[65535],converted[1048576],queued[1048580];
static uint32_t challenge_size;
static struct gw_world_locator_fifo spell_barrier_fifo;
static uint32_t spell_barrier_known[4096],spell_barrier_required[4096];
static unsigned char spell_barrier_ids[12+4096*4],spell_barrier_metadata[1048576];
static unsigned char spell_barrier_main_header[4096],spell_barrier_main_now[4096];
static uintptr_t spell_barrier_main;
static DWORD spell_barrier_main_type,spell_barrier_main_protect,spell_barrier_main_allocation_protect,spell_barrier_main_state;
static uint64_t spell_barrier_owner,spell_barrier_connection,spell_barrier_pipe;
static uint32_t spell_barrier_bypassed,spell_barrier_missing_count,spell_barrier_missing_ids[32];
static int retirement_readable(const void*,SIZE_T);
static void pipe_note(const char*,uint32_t);
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
static void local_raid_note(const char* kind,uint32_t bytes);
#endif
#if defined(GW_PRIVATE_TEST_COLD_START_TRACE) && GW_SOURCE_ONLY_PROFILE == 5
/* A local test build can identify the original fresh-cache disconnect caller
* without competing with nohelper's hardware return leases. Only executable
* Main RVAs from the current call chain are retained: no packet, credentials,
* general registers, stack bytes or other module paths are logged. */
static void cold_start_disconnect_trace(uint32_t reason){
static LONG captured;
char option[2];void* frames[64];USHORT depth;unsigned i;
uintptr_t main=(uintptr_t)GetModuleHandleW(0);
if(reason!=14||gw_wire_pipe_data.world_auth||gw_wire_pipe_data.closed||
gw_wire_pipe_data.error||!gw_wire_pipe_data.auth_request_sent||
GetEnvironmentVariableA("GW_PRIVATE_COLD_START_TRACE",option,sizeof(option))!=1||option[0]!='1'||
main!=(uintptr_t)0x140000000ULL||InterlockedCompareExchange(&captured,1,0))return;
depth=CaptureStackBackTrace(0,64,frames,0);
pipe_note("GW_COLD_START disconnect-stack-depth=",depth);
for(i=0;i<depth&&i<64;++i){
uintptr_t pc=(uintptr_t)frames[i];MEMORY_BASIC_INFORMATION info;DWORD protection;
if(pc<main+0x1000u||pc>=main+0x47c145cu||
VirtualQuery((void*)pc,&info,sizeof(info))!=sizeof(info)||
info.State!=MEM_COMMIT||info.AllocationBase!=(void*)main||
(info.Protect&(PAGE_GUARD|PAGE_NOACCESS)))continue;
protection=info.Protect&0xffu;
if(protection!=PAGE_EXECUTE_READ&&protection!=PAGE_EXECUTE_READWRITE&&
protection!=PAGE_EXECUTE_WRITECOPY)continue;
pipe_note("GW_COLD_START main-frame-rva=",(uint32_t)(pc-main));
}
}
#endif
static void initial_spell_trace_note(const unsigned char* body,uint32_t bytes){
char option[2];uint32_t count=0,present=0;
if(GetEnvironmentVariableA("GW_PRIVATE_SPELL_HOTFIX_TRACE",option,sizeof(option))!=1 || option[0]!='1')return;
pipe_note("GW_SPELL_HOTFIX initial-known-submitted=",bytes); /* bytes, not ID count */
if(gw_spell_hotfix_trace_initial(body,bytes,&count,&present)){
pipe_note("GW_SPELL_HOTFIX initial-known-shape-held=",bytes);return;
}
pipe_note("GW_SPELL_HOTFIX initial-known-count=",count);
pipe_note("GW_SPELL_HOTFIX initial-known-target-mask=",present);
}
static int spell_barrier_fail_open(uint32_t);
static void* spell_barrier_alloc(void* context,size_t bytes){(void)context;return HeapAlloc(GetProcessHeap(),0,bytes);}
static void spell_barrier_free(void* context,void* pointer){(void)context;HeapFree(GetProcessHeap(),0,pointer);}
static void spell_barrier_cancel(uint32_t reason){
struct gw_pipe_spell_locator_barrier* d=&gw_wire_spell_locator_barrier;
gw_world_locator_fifo_clear(&spell_barrier_fifo,spell_barrier_free,0);
if(d->state==1u||d->state==2u){d->state=reason?4u:5u;d->error=reason;}
}
static void spell_barrier_reset(void){
spell_barrier_cancel(0);
gw_wire_spell_locator_barrier=(struct gw_pipe_spell_locator_barrier){.abi=1,.size=sizeof(struct gw_pipe_spell_locator_barrier)};
gw_wire_spell_locator_guard=(struct gw_pipe_spell_locator_guard){.abi=1,.size=sizeof(struct gw_pipe_spell_locator_guard)};
gw_wire_initial_spell_ids_call=(struct gw_pipe_initial_spell_ids_call){.abi=1,.size=sizeof(struct gw_pipe_initial_spell_ids_call)};
spell_barrier_main=0;spell_barrier_owner=spell_barrier_connection=spell_barrier_pipe=0;
spell_barrier_main_type=spell_barrier_main_protect=spell_barrier_main_allocation_protect=spell_barrier_main_state=0;
spell_barrier_bypassed=spell_barrier_missing_count=0;
SecureZeroMemory(spell_barrier_known,sizeof(spell_barrier_known));
SecureZeroMemory(spell_barrier_required,sizeof(spell_barrier_required));
}
static void init(struct gw_wire_call* c,uint32_t op){
__builtin_memset(c,0,sizeof(*c));c->abi=GW_WINE_WIRE_ABI;c->size=sizeof(*c);c->operation=op;
c->realm_id=70;c->virtual_address=0x46010046;c->super_district=2;
}
static int call(struct gw_wire_call* c){return gw_wire_account_transport(c)?-1:c->result;}
static void diagnostic_client_drop(uint32_t opcode,uint32_t bytes){
struct gw_wire_call c;
/* Trace the first dropped client requests beside the client (journal can be stalled). */
{static volatile LONG traced=0;if(InterlockedIncrement(&traced)<=200)pipe_note("GW_WIRE client-drop opcode=",opcode);}
if(!gw_wire_world_data.login_sent || !gw_client_drop_should_count(opcode,bytes))return;
gw_client_drop_call_init(&c,opcode,bytes);(void)call(&c);
}
static uint32_t u32(const unsigned char* p){return (uint32_t)p[0]|((uint32_t)p[1]<<8)|((uint32_t)p[2]<<16)|((uint32_t)p[3]<<24);}
static void record_movement_failure(uint32_t opcode,const unsigned char* body,uint32_t size,int result){
struct gw_pipe_movement_failure* d=&gw_wire_movement_failure;uint32_t mask,g=2,i,base;
__builtin_memset(d,0,sizeof(*d));d->abi=1;d->size=sizeof(*d);d->opcode=opcode;d->bytes=size;d->result=result;
if(size<2)return;
mask=(uint32_t)body[0]|((uint32_t)body[1]<<8);
for(i=0;i<16;++i)if(mask&(1u<<i))++g;
if(g>size || size-g<50)return;
d->flags_lo=u32(body+g);d->flags_hi=u32(body+g+4);d->forces=u32(body+g+36);
d->options=body[g+48];d->tail=body[g+49];base=g+50;d->remaining=size-base;
if((d->options&0x20) && size-base>=9)d->fall_direction=body[base+8];
}
static int movement_opcode(uint32_t opcode){
return (opcode>=0x420000&&opcode<=0x420006)||(opcode>=0x420008&&opcode<=0x42000f)||
opcode==0x420016||opcode==0x420017||opcode==0x420018||opcode==0x420019||
opcode==0x420027||opcode==0x420028||opcode==0x42002e||opcode==0x42007f||
opcode==0x420048||opcode==0x420049||opcode==0x42004f||
opcode==0x420029||opcode==0x42002a||opcode==0x42002b||opcode==0x42003f||opcode==0x420040||opcode==0x420041||
opcode==0x420039||opcode==0x42002c||opcode==0x42002d||opcode==0x420030||opcode==0x420031||opcode==0x42003a||opcode==0x42003b;
}
/* Fixed DB_QUERY_BULK only: public table/record IDs, never generic payload.
* Caller serializes access. The exported parser also has an own-PE fixture. */
__declspec(dllexport) void gw_wire_record_db_query(const unsigned char* body,uint32_t size){
uint32_t count,index;struct gw_pipe_db_query* row;
if(!body||size<6)goto invalid;
count=((uint32_t)body[4]<<5)|(body[5]>>3);
if(count>8191||size!=6+count*4||(body[5]&7))goto invalid;
if(gw_wire_pipe_queries.count>=8)return;
row=gw_wire_pipe_queries.rows+gw_wire_pipe_queries.count;
row->hash=u32(body);row->count=count;row->captured=count>32?32:count;
for(index=0;index<row->captured;++index)row->ids[index]=u32(body+6+index*4);
++gw_wire_pipe_queries.count;return;
invalid:
++gw_wire_pipe_queries.malformed;
}
static void trace(uint32_t direction,uint32_t opcode,uint32_t bytes){
struct gw_pipe_control* d=&gw_wire_pipe_data;uint32_t count=d->trace_count,i=count%32;
/* Direction 2 is admitted outbound metadata under the existing pipe lock.
* A saturated counter remains explicitly marked; no body is retained. */
if(direction==2 && opcode==0x420070){
if(gw_wire_create_observation.count==UINT32_MAX)gw_wire_create_observation.saturated=1;
else ++gw_wire_create_observation.count;
}
d->trace[i].direction=direction;d->trace[i].opcode=opcode;d->trace[i].bytes=bytes;
if(count<0xffffffffu)d->trace_count=count+1;
if(direction==1){d->last_in_opcode=opcode;d->last_in_bytes=bytes;}
else{d->last_out_opcode=opcode;d->last_out_bytes=bytes;}
}
static int owned(void* p){
struct gw_pipe_control* d=&gw_wire_pipe_data;
return gw_wire_pipe_receiver_allowed((uint64_t)p)&&d->abi==1&&d->size==sizeof(*d)&&d->stage==1&&!d->error&&!d->closed&&
(uint64_t)p==d->pipe && *(uint64_t*)((unsigned char*)p+8)==d->owner &&
*(uint64_t*)((unsigned char*)p+16)==d->connection &&
*(uint64_t*)d->connection==0x1450396b0ULL && *(uint64_t*)d->queue==d->owner;
}
/* Pure ownership/proof predicate for the opt-in single-channel policy. Caller
* holds the original NetClient critical section; no auth/lifecycle state writes. */
static int bound_source_channel(void* owner){
struct gw_pipe_control* d=&gw_wire_pipe_data;
unsigned char* object=(unsigned char*)owner;uint64_t holder;
if(!owner || d->stage!=1 || d->error || d->closed || !d->world_auth ||
!gw_wire_world_data.login_sent ||
d->owner!=(uint64_t)owner || *(uint64_t*)0x145e7a098ULL!=(uint64_t)owner ||
*(volatile LONG*)(object+0x98)!=5 || *(uint64_t*)(object+0x1a0)!=d->connection ||
*(uint64_t*)d->queue!=(uint64_t)owner || !owned((void*)d->pipe))return 0;
holder=*(uint64_t*)(object+0x228);
return holder && *(uint64_t*)holder==d->pipe;
}
int WINAPI gw_wire_native_channel_ready(void* owner){
return gw_wire_world_data.self_create && bound_source_channel(owner);
}
int WINAPI gw_wire_native_channel_transfer_ready(void* owner){
return transfer_bridge_matches() && bound_source_channel(owner);
}
static int transfer_presentation(uint32_t opcode){
if(opcode==0x470041){
if(!gw_wire_world_data.self_create && !transfer_bridge_matches())return -1;
transfer_owner=gw_wire_pipe_data.owner;transfer_connection=gw_wire_pipe_data.connection;
MemoryBarrier();InterlockedExchange(&transfer_phase,1);
}else if(opcode==0x47002b){
if(!transfer_bridge_matches() || InterlockedCompareExchange(&transfer_phase,0,0)!=1)return -1;
InterlockedExchange(&transfer_phase,2);gw_wire_world_data.self_create=0;
}else if(opcode==0x470042){
if(!transfer_bridge_matches() || InterlockedCompareExchange(&transfer_phase,0,0)!=2)return -1;
InterlockedExchange(&transfer_phase,3);
}else if(opcode==0x5e0000){
gw_wire_world_data.self_create=1;clear_transfer_bridge();
}
return 0;
}
static void clear_world_failure(void){
gw_wire_world_failure=(struct gw_pipe_world_failure){.abi=1,.size=sizeof(gw_wire_world_failure)};
gw_wire_world_call_failure=(struct gw_pipe_world_call_failure){.abi=1,.size=sizeof(gw_wire_world_call_failure)};
gw_wire_world_call_phase=(struct gw_pipe_world_call_phase){.abi=1,.size=sizeof(gw_wire_world_call_phase)};
}
static void close_pipe(int error){
spell_barrier_cancel(error?2u:0u);
clear_transfer_bridge();
struct gw_pipe_control* d=&gw_wire_pipe_data;
if(error&&!d->error)d->error=error;
/* Every session end names its cause in the startup log: close code, then world drain phase/opcode. */
if(error&&!d->closed){pipe_note("GW_WIRE close error=",(uint32_t)error);pipe_note("GW_WIRE close world-phase=",gw_wire_world_failure.phase);pipe_note("GW_WIRE close world-modern=",gw_wire_world_failure.modern_opcode);pipe_note("GW_WIRE close world-source=",gw_wire_world_failure.source_opcode);pipe_note("GW_WIRE close world-result=",(uint32_t)gw_wire_world_failure.result);pipe_note("GW_WIRE close world-required=",gw_wire_world_failure.required);pipe_note("GW_WIRE close call-phase=",gw_wire_world_call_phase.phase);pipe_note("GW_WIRE close call-transport=",(uint32_t)gw_wire_world_call_failure.transport_status);pipe_note("GW_WIRE close call-backend=",gw_wire_world_call_failure.backend_state);}
if(!d->closed){gw_wire_account_detach_engine_session();d->closed=1;((void (WINAPI *)(void*))(*(uint64_t**)d->connection)[17])((void*)d->connection);}
}
static void private_capture_notice(uint32_t kind,uint32_t opcode,uint32_t bytes);
static void private_capture_notice_input(uint32_t kind,uint32_t opcode,uint32_t bytes,const unsigned char* body);
static int send_wire_uncaptured(const unsigned char* bytes,uint32_t size){
struct gw_pipe_view view={bytes,0,size,0,0};
/* Original pipe releases its own temporary buffers immediately after this
* verified wrapper method returns; descriptor data is borrowed through call. */
((void (WINAPI *)(void*,const struct gw_pipe_view*,int))(*(uint64_t**)gw_wire_pipe_data.connection)[18])((void*)gw_wire_pipe_data.connection,&view,1);
return 0;
}
static int send_wire(const unsigned char* bytes,uint32_t size){
int result=send_wire_uncaptured(bytes,size);private_capture_notice(result?3:2,0,0);return result;
}
static struct gw_login_timing login_timing;
static int submit(uint32_t opcode,const unsigned char* bytes,uint32_t size){
struct gw_pipe_control* d=&gw_wire_pipe_data;
if(size>sizeof(queued)-4)return -1;
queued[0]=(unsigned char)opcode;queued[1]=(unsigned char)(opcode>>8);queued[2]=(unsigned char)(opcode>>16);queued[3]=(unsigned char)(opcode>>24);
if(size)__builtin_memcpy(queued+4,bytes,size);
/* Already validated actual engine boundary; synchronous deep-copy plus
* engine owner refcount, later decoded by its genuine main-frame queue. */
((void (WINAPI *)(void*,uint32_t,void*,void*,const void*,uint32_t))0x141e54190ULL)((void*)d->queue,0x12,0,(void*)d->owner,queued,size+4);
++d->queued;trace(3,opcode,size);
if(opcode==0x4b0003u || opcode==0x4b0000u)private_capture_notice_input(4,opcode,size,bytes);
if(gw_login_timing_take(&login_timing,GW_LOGIN_FIRST_SUBMIT,GetTickCount64()))
pipe_note("GW_LOGIN_TIMING first-client-submit opcode=",opcode);
if((opcode==0x4701b4u||opcode==0x4701b5u)&&gw_login_timing_take(&login_timing,GW_LOGIN_ACCOUNT_REPLY,GetTickCount64()))
pipe_note("GW_LOGIN_TIMING account-reply-submit opcode=",opcode);
if(opcode==0x4b0000u&&gw_login_timing_take(&login_timing,GW_LOGIN_DB2_REPLY,GetTickCount64()))
pipe_note("GW_LOGIN_TIMING db2-reply-submit opcode=",opcode);
if(opcode==0x4b0003u&&gw_login_timing_take(&login_timing,GW_LOGIN_HOTFIX_REPLY,GetTickCount64()))
pipe_note("GW_LOGIN_TIMING hotfix-reply-submit opcode=",opcode);
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
if(opcode==0x470097 && gw_wire_world_data.login_sent)local_raid_note("submit-470097 bytes=",size);
#endif
if(opcode==0x5e0000)InterlockedOr((volatile LONG*)&gw_wire_world_data.realm_context_bound,GW_WORLD_SELF_CREATE_QUEUED);
if(opcode==0x5e0003)InterlockedOr((volatile LONG*)&gw_wire_world_data.realm_context_bound,GW_WORLD_ACTIVE_MOVER_QUEUED);
return 0;
}
struct private_capture_status {uint32_t abi,size,configured,error;uint64_t records,bytes;};
__declspec(dllexport) struct private_capture_status gw_wire_private_capture={1,32,0,0,0,0};
static void private_capture_notice(uint32_t kind,uint32_t opcode,uint32_t bytes){
private_capture_notice_input(kind,opcode,bytes,0);
}
static void private_capture_notice_input(uint32_t kind,uint32_t opcode,uint32_t bytes,const unsigned char* body){
static int enabled=-1;struct gw_wire_call capture;
if(enabled<0){char present;enabled=GetEnvironmentVariableA("GW_PRIVATE_GAMEPLAY_CAPTURE",&present,1)>0;}
if(!enabled)return;
init(&capture,GW_WIRE_PRIVATE_GAMEPLAY_CAPTURE);capture.index=kind;capture.opcode=opcode;capture.build=bytes;
(void)gw_wire_private_gameplay_body_input(&capture,gw_wire_pipe_data.world_auth!=0,gw_wire_world_data.self_create!=0,body,bytes);
capture.output=(unsigned char*)&gw_wire_private_capture;capture.capacity=sizeof(gw_wire_private_capture);(void)call(&capture);
}
static struct {
uint64_t owner;uint32_t generation,address;int bound;char name[128];
} current_realm_record;
static struct {int ready,bound,loading_started;char name[33];} current_account_name;
static int encode_submit(uint32_t operation,uint32_t opcode){
struct gw_wire_call c;uint64_t time;FILETIME ft;
init(&c,operation);c.output=converted;c.capacity=sizeof(converted);
if(operation==GW_WIRE_AUTH_INITIALIZATION){GetSystemTimeAsFileTime(&ft);time=(((uint64_t)ft.dwHighDateTime<<32)|ft.dwLowDateTime)/10000000ULL-11644473600ULL;c.input=(const unsigned char*)&time;c.input_bytes=8;}
if(operation==GW_WIRE_GLUE_FEATURES)c.index=10;
if(operation==GW_WIRE_AUTH_INITIALIZATION){
memset(&current_realm_record,0,sizeof(current_realm_record));
SecureZeroMemory(&current_account_name,sizeof(current_account_name));
}
if(call(&c))return -1;
if(operation==GW_WIRE_AUTH_INITIALIZATION){
struct gw_wire_call account;init(&account,GW_WIRE_ACCOUNT_NAME);
account.output=(unsigned char*)current_account_name.name;account.capacity=sizeof(current_account_name.name);
if(!call(&account)&&account.required>=2&&account.required<=sizeof(current_account_name.name)&&
!current_account_name.name[account.required-1]&&gw_account_name_length(current_account_name.name,sizeof(current_account_name.name)))
current_account_name.ready=1;
else {SecureZeroMemory(current_account_name.name,sizeof(current_account_name.name));pipe_note("GW_ACCOUNT_PROFILE name-unavailable=",1);}
}
if(submit(opcode,converted,c.required))return -1;
if(operation==GW_WIRE_AUTH_INITIALIZATION){
current_realm_record.owner=gw_wire_pipe_data.owner;
current_realm_record.generation=(uint32_t)pipe_generation;
current_realm_record.address=c.value;
memcpy(current_realm_record.name,c.realm.name,sizeof(current_realm_record.name));
}
return 0;
}
/* Creation uses the same authenticated source socket and genuine native queue.
* Only the core lifecycle can produce an encrypted source frame or a native
* result. NONE (including BUSY) cannot send or fabricate an outcome. */
static int creation_output(const struct gw_wire_call* c){
int result;
if(c->required>c->capacity || c->required>sizeof(outgoing) || c->output!=outgoing)return -1;
if(c->value==GW_CREATE_NONE)return c->required?-1:0;
if(c->value==GW_CREATE_SOURCE_FRAME){
if((c->packet.opcode!=0x36 && c->packet.opcode!=0x37 && c->packet.opcode!=0x38 && c->packet.opcode!=0x2c7) || c->required<6)return -1;
result=send_wire(outgoing,c->required);
}else if(c->value==GW_CREATE_NATIVE_REPLY){
if((c->packet.opcode!=0x4701ac && c->packet.opcode!=0x4701ad && c->packet.opcode!=0x47020e) || !c->required)return -1;
result=submit(c->packet.opcode,outgoing,c->required);
}else return -1;
SecureZeroMemory(outgoing,c->required);
return result;
}
static int creation_request_opcode(uint32_t opcode,const unsigned char* body,uint32_t size){
struct gw_wire_call c;
init(&c,GW_WIRE_CREATE_CHARACTER);c.opcode=opcode;c.input=body;c.input_bytes=size;
c.output=outgoing;c.capacity=sizeof(outgoing);
if(call(&c))return -1;
return creation_output(&c);
}
static int creation_request(const unsigned char* body,uint32_t size){return creation_request_opcode(0x420070,body,size);}
#include "owner-queue.private.inc"
static int creation_result(void){
struct gw_wire_call c;
#if defined(GW_SOURCE_UI_CREATE_EXPERIMENT) && defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3 || GW_SOURCE_ONLY_PROFILE == 5)
int terminal=0,result;
#endif
init(&c,GW_WIRE_CREATE_RESULT);c.output=outgoing;c.capacity=sizeof(outgoing);
#if defined(GW_SOURCE_UI_CREATE_EXPERIMENT) && defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3 || GW_SOURCE_ONLY_PROFILE == 5)
if(call(&c)){gw_ui_queue_reply_failure_locked();return -1;}
#else
if(call(&c))return -1;
#endif
#if defined(GW_SOURCE_UI_CREATE_EXPERIMENT) && defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3 || GW_SOURCE_ONLY_PROFILE == 5)
if(c.value==GW_CREATE_NATIVE_REPLY && c.packet.opcode==0x4701ac &&
c.output==outgoing && c.required>=4 && c.required<=sizeof(outgoing))
terminal=u32(outgoing)!=23; /* original CHAR_CREATE_IN_PROGRESS */
result=creation_output(&c);
if(result)gw_ui_queue_reply_failure_locked();
else if(terminal)gw_ui_queue_terminal_reply_locked(u32(outgoing));
return result;
#else
return creation_output(&c);
#endif
}
static int hotfix_submit_page(void* context,const unsigned char* body,uint32_t size){
struct gw_pipe_hotfix* h=(struct gw_pipe_hotfix*)context;struct gw_wire_call c;
char trace_option[2];uint32_t trace_push=0;
if(GetEnvironmentVariableA("GW_PRIVATE_SPELL_HOTFIX_TRACE",trace_option,sizeof(trace_option))==1 && trace_option[0]=='1')
trace_push=gw_spell_hotfix_trace_push(body,size);
if(trace_push)pipe_note("GW_SPELL_HOTFIX requested-push=",trace_push);
init(&c,GW_WIRE_HOTFIX_REPLY);c.input=body;c.input_bytes=size;c.output=converted;c.capacity=sizeof(converted);
h->result=call(&c);if(h->result){if(trace_push)pipe_note("GW_SPELL_HOTFIX conversion-failed-push=",trace_push);return h->result;}
if(submit(0x4b0003,converted,c.required)){if(trace_push)pipe_note("GW_SPELL_HOTFIX submit-failed-push=",trace_push);return -1;}
if(trace_push)pipe_note("GW_SPELL_HOTFIX submitted-push=",trace_push);
++h->replies;h->reply_bytes+=c.required;return 0;
}
static int client_initialization(uint32_t phase){
struct gw_wire_call c;uint32_t count,at=4,index,opcode,size;FILETIME ft;uint64_t time;
GetSystemTimeAsFileTime(&ft);time=(((uint64_t)ft.dwHighDateTime<<32)|ft.dwLowDateTime)/10000000ULL-11644473600ULL;
init(&c,GW_WIRE_CLIENT_INITIALIZATION);c.index=phase;c.input=(const unsigned char*)&time;c.input_bytes=8;c.output=converted;c.capacity=sizeof(converted);
if(call(&c)||c.required<4)return -1;
count=u32(converted);if(count!=(phase?1u:2u))return -1;
for(index=0;index<count;++index){
if(at>c.required||c.required-at<8)return -1;
opcode=u32(converted+at);size=u32(converted+at+4);at+=8;
if(size>c.required-at||opcode!=(phase?0x470363:(index?0x4701b6:0x4b0001)))return -1;
if(submit(opcode,converted+at,size))return -1;
at+=size;
}
return at==c.required?0:-1;
}
static int db_query_missing(const unsigned char* body,uint32_t size){
struct gw_wire_call c;uint32_t count,index,fields[3];FILETIME ft;uint64_t epoch;
if(!body||size<6)return -1;
count=((uint32_t)body[4]<<5)|(body[5]>>3);
if(count>1024||size!=6+count*4||(body[5]&7))return -1;
GetSystemTimeAsFileTime(&ft);epoch=(((uint64_t)ft.dwHighDateTime<<32)|ft.dwLowDateTime)/10000000ULL-11644473600ULL;
if(epoch>0xffffffffu)return -1;
fields[0]=u32(body);fields[2]=(uint32_t)epoch;
for(index=0;index<count;++index){
fields[1]=u32(body+6+index*4);init(&c,GW_WIRE_DB_REPLY_MISSING);
c.input=(const unsigned char*)fields;c.input_bytes=12;c.output=converted;c.capacity=sizeof(converted);
if(call(&c)||submit(0x4b0000,converted,c.required))return -1;
}
return 0;
}
static void world_trace(uint32_t direction,uint32_t opcode,uint32_t bytes){
struct gw_pipe_world_control* w=&gw_wire_world_data;unsigned i=w->trace_count%32;
w->trace[i].direction=direction;w->trace[i].opcode=opcode;w->trace[i].bytes=bytes;++w->trace_count;
}
/* All functions below run under the existing pipe lock. The frame caller uses
* try-lock and returns to the genuine poll; neither metadata nor frames wait. */
static int spell_barrier_hard_fail(uint32_t reason){
struct gw_pipe_spell_locator_barrier* d=&gw_wire_spell_locator_barrier;
d->error=reason;d->state=4;
spell_barrier_cancel(reason);
if(!gw_wire_world_failure.phase){
gw_wire_world_failure.result=-(int32_t)reason;
gw_wire_world_failure.index=d->missing_id;
MemoryBarrier();gw_wire_world_failure.phase=13;
}
return -1;
}
/* Optional readiness must not turn an otherwise accepted login into failure.
* Existing authenticated engine ownership and actual submission stay strict. */
static int spell_barrier_fail(uint32_t reason){
if(reason==2u||reason==9u)return spell_barrier_hard_fail(reason);
return spell_barrier_fail_open(reason);
}
static int spell_barrier_identity(void){
struct gw_pipe_control* d=&gw_wire_pipe_data;unsigned char* owner=(unsigned char*)(uintptr_t)d->owner;
uint64_t holder;LONG state;
if(d->abi!=1||d->size!=sizeof(*d)||d->stage!=1||d->error||d->closed||!d->world_auth||
!gw_wire_world_data.login_sent||gw_wire_spell_locator_barrier.generation!=(uint32_t)pipe_generation||
d->owner!=spell_barrier_owner||d->connection!=spell_barrier_connection||d->pipe!=spell_barrier_pipe||
!retirement_readable(owner,0x230)||!retirement_readable((void*)(uintptr_t)d->pipe,24)||
!retirement_readable((void*)(uintptr_t)d->connection,8)||!retirement_readable((void*)(uintptr_t)d->queue,8)||
!retirement_readable((void*)0x145e7a098ULL,8)||*(uint64_t*)0x145e7a098ULL!=d->owner)return 0;
state=*(volatile LONG*)(owner+0x98);
if((state!=4&&state!=5)||*(uint64_t*)(owner+0x1a0)!=d->connection||!owned((void*)(uintptr_t)d->pipe))return 0;
holder=*(uint64_t*)(owner+0x228);
return holder&&retirement_readable((void*)(uintptr_t)holder,8)&&*(uint64_t*)(uintptr_t)holder==d->pipe;
}
static int spell_barrier_guard_failure(uint32_t condition,uint32_t span){
gw_wire_spell_locator_guard.failed_condition=condition;
gw_wire_spell_locator_guard.failed_span=span;return 0;
}
static SIZE_T spell_barrier_span_query(struct gw_pipe_spell_locator_guard_span* span,uintptr_t address,size_t bytes,uintptr_t main_base,int readable,MEMORY_BASIC_INFORMATION* info){
SIZE_T result=VirtualQuery((void*)address,info,sizeof(*info));DWORD error=result?0:GetLastError();uintptr_t begin,end;
*span=(struct gw_pipe_spell_locator_guard_span){0};span->observed=1;
span->sequence=gw_wire_spell_locator_guard.sequence;span->requested_bytes=(uint32_t)bytes;
span->readable=!!readable;span->vq_result_bytes=(uint32_t)result;span->win32_error=error;
if(result){
span->protect=info->Protect;span->allocation_protect=info->AllocationProtect;
span->state=info->State;span->type=info->Type;span->allocation_matches_main=(uintptr_t)info->AllocationBase==main_base;
begin=(uintptr_t)info->BaseAddress;
if(address<=UINTPTR_MAX-bytes&&begin<=UINTPTR_MAX-info->RegionSize){
end=address+bytes;span->span_contained=address>=begin&&end<=begin+info->RegionSize;
}
}
return result;
}
/* Run only on the owned engine poll, after original auth callbacks and
* current-address adoption. No auth/session flags or routing fields are changed. */
static void current_realm_record_poll(void* owner){
uintptr_t base=(uintptr_t)GetModuleHandleA(0),start=(uintptr_t)owner+0x89cu;
MEMORY_BASIC_INFORMATION info;size_t length=0;uintptr_t region;
if(current_realm_record.bound||current_realm_record.owner!=(uint64_t)(uintptr_t)owner||
current_realm_record.generation!=(uint32_t)pipe_generation||!gw_wire_pipe_data.auth_queued||
base!=UINT64_C(0x140000000))return;
while(length<sizeof(current_realm_record.name)&&current_realm_record.name[length])++length;
if(!length||length>=sizeof(current_realm_record.name))return;
if(!retirement_readable((void*)base,GW_ENGINE_ORIGINAL_MAIN_HEADER_BYTES)||
!gw_engine_shipped_main_header_matches((const unsigned char*)base,GW_ENGINE_SHIPPED_MAIN_HEADER_BYTES)||
!retirement_readable((void*)(base+GW_CURRENT_REALM_OWNER_RVA),8)||
!retirement_readable(owner,0x8a0u+length+1u))return;
if(!VirtualQuery((void*)start,&info,sizeof(info))||info.State!=MEM_COMMIT||
(info.Protect&(PAGE_GUARD|PAGE_NOACCESS))||
((info.Protect&0xffu)!=PAGE_READWRITE&&(info.Protect&0xffu)!=PAGE_WRITECOPY))return;
region=(uintptr_t)info.BaseAddress;
if(region>start||info.RegionSize<start-region||info.RegionSize-(start-region)<4u+length+1u)return;
if(!gw_current_realm_record((void*)base,GW_CURRENT_REALM_OWNER_RVA+8u,owner,0x8a0u+length+1u,
70334u,1,current_realm_record.address,current_realm_record.name,sizeof(current_realm_record.name)))
current_realm_record.bound=1;
}
static int account_name_writable(void* pointer,size_t bytes,void* context){
MEMORY_BASIC_INFORMATION info;uintptr_t start=(uintptr_t)pointer,region;(void)context;
if(!pointer||!bytes||start>UINTPTR_MAX-bytes||!VirtualQuery(pointer,&info,sizeof(info))||info.State!=MEM_COMMIT||
(info.Protect&(PAGE_GUARD|PAGE_NOACCESS))||
((info.Protect&0xffu)!=PAGE_READWRITE&&(info.Protect&0xffu)!=PAGE_WRITECOPY))return 0;
region=(uintptr_t)info.BaseAddress;
return region<=start&&info.RegionSize>=start-region&&info.RegionSize-(start-region)>=bytes;
}
static int account_name_reserve(void* object,size_t length,void* context){
uintptr_t code=(uintptr_t)context+GW_NATIVE_ACCOUNT_RESERVE_RVA;MEMORY_BASIC_INFORMATION info;
if(!retirement_readable((void*)code,sizeof(gw_account_reserve_code))||
memcmp((const void*)code,gw_account_reserve_code,sizeof(gw_account_reserve_code))||
!VirtualQuery((void*)code,&info,sizeof(info))||info.State!=MEM_COMMIT||
(info.Protect&(PAGE_GUARD|PAGE_NOACCESS))||
((info.Protect&0xffu)!=PAGE_EXECUTE_READ&&(info.Protect&0xffu)!=PAGE_EXECUTE_READWRITE))return -1;
((void (WINAPI *)(void*,size_t))code)(object,length);
return 0;
}
static void current_account_name_poll(void* owner){
uintptr_t base=(uintptr_t)GetModuleHandleA(0);
if(!current_account_name.ready||current_account_name.bound||current_account_name.loading_started||!current_realm_record.bound||
current_realm_record.owner!=(uint64_t)(uintptr_t)owner||current_realm_record.generation!=(uint32_t)pipe_generation||
base!=UINT64_C(0x140000000)||!gw_wire_pipe_data.auth_queued||
!retirement_readable((void*)base,1024)||!retirement_readable((void*)(base+GW_CURRENT_REALM_OWNER_RVA),8)||
!retirement_readable((void*)(base+GW_NATIVE_ACCOUNT_NAME_RVA),sizeof(struct gw_native_account_string))||
!retirement_readable(owner,0x8a1u))return;
if(!gw_bind_native_account_name((void*)base,GW_CURRENT_REALM_OWNER_RVA+8u,owner,0x8a1u,70334u,1,!current_account_name.loading_started,
current_realm_record.address,current_account_name.name,sizeof(current_account_name.name),
account_name_reserve,account_name_writable,(void*)base)){
current_account_name.bound=1;SecureZeroMemory(current_account_name.name,sizeof(current_account_name.name));
pipe_note("GW_ACCOUNT_PROFILE name-bound-before-world=",gw_wire_world_data.login_sent?0u:1u);
}
}
static int spell_barrier_shipped_main_opt_in(void){
static int enabled=-1;
if(enabled<0){
char option[2];enabled=GetEnvironmentVariableA("GW_SPELL_LOCATOR_CURRENT_MAIN",option,sizeof(option))==1&&option[0]=='1';
pipe_note("GW_SPELL current-main-opt-in=",(uint32_t)enabled);
}
return enabled;
}
static int spell_barrier_main_qualified(int first){
uintptr_t base=(uintptr_t)GetModuleHandleA(0);MEMORY_BASIC_INFORMATION info;int readable;SIZE_T result;
struct gw_pipe_spell_locator_guard* d=&gw_wire_spell_locator_guard;
++d->sequence;d->generation=(uint32_t)pipe_generation;d->failed_condition=d->failed_span=0;
d->module_present=base!=0;d->module_expected=base==UINT64_C(0x140000000);d->module_error=base?0:GetLastError();
d->header_valid=d->header_unchanged=0;d->header=(struct gw_pipe_spell_locator_guard_span){0};
d->identity_ok=!!spell_barrier_identity();
if(!d->identity_ok)return spell_barrier_guard_failure(1,1);
if(!d->module_expected)return spell_barrier_guard_failure(2,1);
readable=retirement_readable((void*)base,4096);
result=spell_barrier_span_query(&d->header,base,4096,base,readable,&info);
/* A failed readability gate still gets adjacent query metadata, but is
* never bypassed. The metadata snapshot is not claimed to be atomic. */
if(!readable)return spell_barrier_guard_failure(3,1);
if(!result)return spell_barrier_guard_failure(4,1);
if((uintptr_t)info.AllocationBase!=base)return spell_barrier_guard_failure(5,1);
if(info.Type!=MEM_IMAGE&&info.Type!=MEM_MAPPED)return spell_barrier_guard_failure(6,1);
/* Actual J2e guest Main is this narrowly pinned mapped-image profile.
* A mapped type alone never establishes Main identity or admission. */
if(info.Type==MEM_MAPPED&&(info.State!=MEM_COMMIT||info.Protect!=PAGE_READONLY||
info.AllocationProtect!=PAGE_EXECUTE_READWRITE||!d->header.span_contained))return spell_barrier_guard_failure(15,1);
__builtin_memcpy(spell_barrier_main_now,(void*)base,4096);
d->header_valid=!!gw_world_locator_main_header(spell_barrier_main_now,4096,base);
if(!d->header_valid)return spell_barrier_guard_failure(7,1);
if(info.Type==MEM_MAPPED&&!gw_engine_spell_main_header_matches(spell_barrier_main_now,0x400,spell_barrier_shipped_main_opt_in()))return spell_barrier_guard_failure(16,1);
if(first){
spell_barrier_main=base;__builtin_memcpy(spell_barrier_main_header,spell_barrier_main_now,4096);d->header_unchanged=1;
spell_barrier_main_type=info.Type;spell_barrier_main_state=info.State;
spell_barrier_main_protect=info.Protect;spell_barrier_main_allocation_protect=info.AllocationProtect;
}
else{
d->header_unchanged=base==spell_barrier_main&&!__builtin_memcmp(spell_barrier_main_header,spell_barrier_main_now,0x400);
if(!d->header_unchanged)return spell_barrier_guard_failure(8,1);
if(info.Type!=spell_barrier_main_type||info.State!=spell_barrier_main_state||
info.Protect!=spell_barrier_main_protect||info.AllocationProtect!=spell_barrier_main_allocation_protect)return spell_barrier_guard_failure(17,1);
}
return 1;
}
static int spell_barrier_read(void* context,uintptr_t address,void* output,size_t bytes){
MEMORY_BASIC_INFORMATION info;uintptr_t fixed_begin=spell_barrier_main+0x79c3d70u;
uintptr_t fixed_end=fixed_begin+0x288u,vtable=spell_barrier_main+(uintptr_t)GW_SPELL_LOCATOR_PROVIDER_VTABLE_RVA;
int fixed,readable;SIZE_T result;uint32_t role;
if(address>=vtable&&address<vtable+16u){fixed_begin=vtable;fixed_end=vtable+16u;}
fixed=address>=fixed_begin&&address<fixed_end;role=fixed?2u:3u;
(void)context;
if(!output||!bytes)return spell_barrier_guard_failure(9,role);
if(!spell_barrier_identity())return spell_barrier_guard_failure(1,role);
readable=retirement_readable((void*)address,bytes);
/* The fixed storage spans retain the same strict allocation/type guard.
* On failure capture only public query facts, never the selected bytes. */
if(fixed){
if(bytes>fixed_end-address||address<spell_barrier_main||address-spell_barrier_main>139165696u||
bytes>139165696u-(address-spell_barrier_main))return spell_barrier_guard_failure(14,2);
result=spell_barrier_span_query(&gw_wire_spell_locator_guard.fixed,address,bytes,spell_barrier_main,readable,&info);
if(!readable)return spell_barrier_guard_failure(10,2);
if(!result)return spell_barrier_guard_failure(11,2);
if((uintptr_t)info.AllocationBase!=spell_barrier_main)return spell_barrier_guard_failure(12,2);
if(info.Type!=spell_barrier_main_type)return spell_barrier_guard_failure(13,2);
if(info.State!=MEM_COMMIT||!gw_wire_spell_locator_guard.fixed.span_contained||
info.AllocationProtect!=spell_barrier_main_allocation_protect)return spell_barrier_guard_failure(18,2);
}else if(!readable)return spell_barrier_guard_failure(10,3);
__builtin_memcpy(output,(void*)address,bytes);return 1;
}
static int spell_barrier_initial_ids_result(NTSTATUS transport_status,const struct gw_wire_call* c,uint64_t expected_guid,uint32_t* known,uint32_t* count){
struct gw_pipe_initial_spell_ids_call* d=&gw_wire_initial_spell_ids_call;uint64_t guid;uint32_t n;
d->transport_status=(int32_t)transport_status;d->call_result=c->result;
d->input_bytes=c->input_bytes;d->input_is_null=c->input==0;
d->required=c->required;d->capacity=c->capacity;d->consumed=c->consumed;
if(transport_status){d->bound_step=4;return 0;}
/* There is no independent bytes-written ABI field. The exact op45 Core
* contract guarantees no copy for -1/-3, exact required on success. */
if(c->result==-1||c->result==-3)d->contract_written_known=1;
if(c->result){d->bound_step=5;return 0;}
if(c->required>=12u&&c->required<=sizeof(spell_barrier_ids)){
d->header_bounds_valid=1;
if(c->required<=c->capacity){d->contract_written_known=1;d->contract_written_bytes=c->required;}
}else{d->bound_step=6;return 0;}
guid=gw_world_locator_u64(spell_barrier_ids);n=u32(spell_barrier_ids+8);
if(!guid){d->bound_step=7;return 0;}
if(n>4096u){d->bound_step=8;return 0;}
if(c->required!=12u+4u*n){d->bound_step=9;return 0;}
d->header_shape_valid=1;d->source_guid=guid;d->decoded_count=n;
d->expected_guid_matches=guid==expected_guid;
if(!d->expected_guid_matches){d->bound_step=10;return 0;}
if(gw_world_locator_spell_ids(spell_barrier_ids,c->required,expected_guid,known,count)){d->bound_step=11;return 0;}
d->bound_step=12;return 1;
}
static int spell_barrier_initial_bundle(uint32_t bytes){
uint32_t records;
if(gw_world_locator_bundle_shape(converted,bytes,&records)||!records||bytes<12){gw_wire_initial_spell_ids_call.bound_step=13;return 0;}
if(u32(converted+4)!=0x690019){gw_wire_initial_spell_ids_call.bound_step=14;return 0;}
gw_wire_initial_spell_ids_call.first_bundle_valid=1;gw_wire_initial_spell_ids_call.bound_step=15;return 1;
}
static int spell_barrier_begin(void){
struct gw_pipe_spell_locator_barrier* d=&gw_wire_spell_locator_barrier;
struct gw_wire_call c;char option[16];DWORD n;int configured,production_default=1;NTSTATUS transport_status;uint64_t snapshot_guid=0;
struct gw_pipe_initial_spell_ids_call* observation=&gw_wire_initial_spell_ids_call;
/* The original pending dispatcher now progresses on each owned poll.
* Fresh-cache native paladin/warrior construction is qualified; normal
* play uses the gate without requiring environment setup. */
n=GetEnvironmentVariableA("GW_PRIVATE_SPELL_LOCATOR_BARRIER",option,sizeof(option));
configured=gw_world_locator_config(option,n,production_default);
if(configured<=0)return configured<0?spell_barrier_fail(1):0;
{uint32_t attempt=observation->attempt+1u;
*observation=(struct gw_pipe_initial_spell_ids_call){.abi=1,.size=sizeof(*observation),.generation=(uint32_t)pipe_generation,.attempt=attempt,.bound_step=1};}
observation->precondition_flags=(d->state?1u:0u)|(gw_wire_world_data.self_create?2u:0u)|
(gw_wire_world_data.realm_context_bound&GW_WORLD_SELF_CREATE_QUEUED?4u:0u);
if(observation->precondition_flags)return spell_barrier_fail(4);
d->enabled=1;d->state=1;d->generation=(uint32_t)pipe_generation;d->source_guid=0;d->started_ms=GetTickCount64();
spell_barrier_owner=gw_wire_pipe_data.owner;spell_barrier_connection=gw_wire_pipe_data.connection;spell_barrier_pipe=gw_wire_pipe_data.pipe;
observation->bound_step=2;
if(!spell_barrier_main_qualified(1))return spell_barrier_fail(3);
init(&c,GW_WIRE_INITIAL_SPELL_IDS);c.output=spell_barrier_ids;c.capacity=sizeof(spell_barrier_ids);
observation->bound_step=3;
transport_status=gw_wire_account_transport(&c);
/* op45 is authenticated, roster-selected and Source0x12a-ready under the
* transport lock. Read its identity only after a successful bounded copy;
* retaining the same pipe owner/connection binds this snapshot's lifetime. */
if(!transport_status&&!c.result&&c.required>=12u&&c.required<=c.capacity&&c.required<=sizeof(spell_barrier_ids))
snapshot_guid=gw_world_locator_u64(spell_barrier_ids);
if(!spell_barrier_initial_ids_result(transport_status,&c,snapshot_guid,spell_barrier_known,&d->known_count))return spell_barrier_fail(4);
d->source_guid=snapshot_guid;
if(!spell_barrier_identity())return spell_barrier_fail(2);
return 1;
}
static int spell_barrier_hold(uint32_t source_received,uint32_t bytes){
struct gw_pipe_spell_locator_barrier* d=&gw_wire_spell_locator_barrier;
if(spell_barrier_bypassed)return 0;
/* Only the first initial snapshot of this transport. A genuine worldport
* later sends another0x12a; it must retain its ordinary delivery path. */
if(source_received&&gw_wire_world_data.last_legacy==0x12a&&!d->state){
int result=spell_barrier_begin();if(result<=0)return result;
if(!spell_barrier_initial_bundle(bytes))return spell_barrier_fail(4);
}
if(d->state==4)return -1;
if(d->state!=1&&d->state!=2)return 0;
if(!spell_barrier_identity())return spell_barrier_fail(2);
/* The deadline bounds metadata readiness. Once readiness is proved,
* original callbacks can take time while the bounded FIFO is delivered;
* that is not a metadata timeout. Keep the same identity and size guards. */
if(d->state==1&&gw_world_locator_expired(d->started_ms,GetTickCount64()))return spell_barrier_fail(7);
if(gw_world_locator_fifo_append(&spell_barrier_fifo,converted,bytes,spell_barrier_alloc,0))return spell_barrier_fail(6);
d->held_bundles=spell_barrier_fifo.bundles;d->held_records=spell_barrier_fifo.records;d->held_bytes=spell_barrier_fifo.bytes;
return 1;
}
static int spell_barrier_classify(void){
struct gw_pipe_spell_locator_barrier* d=&gw_wire_spell_locator_barrier;uint32_t work=0;
while(d->classified<d->known_count&&work++<8u){
struct gw_wire_call c;uint32_t fields[3]={0xe111669eu,spell_barrier_known[d->classified],0};uint32_t status;
init(&c,GW_WIRE_DB_REPLY_MISSING);c.input=(const unsigned char*)fields;c.input_bytes=sizeof(fields);
c.output=spell_barrier_metadata;c.capacity=sizeof(spell_barrier_metadata);
/* Local canonical-registry classification only. Never submit this
* serialization result or invent an unsolicited native DB2 reply. */
if(call(&c))return spell_barrier_fail(5);
status=(uint32_t)gw_world_locator_registry_status(spell_barrier_metadata,c.required,fields[1]);
if(status==1){
/* The original generic book skips hidden Attribute0/0x80 rows.
* Unknown/ambiguous metadata remains a required candidate. */
if(!gw_spellbook_hidden_for_initial_gate(fields[1]))
spell_barrier_required[d->required_count++]=fields[1];
}else if(status!=0)return spell_barrier_fail(5);
++d->classified;
}
return d->classified==d->known_count;
}
static int spell_barrier_flush(void){
struct gw_pipe_spell_locator_barrier* d=&gw_wire_spell_locator_barrier;uint32_t work=0;
while(spell_barrier_fifo.head&&work++<128u){
struct gw_world_locator_bundle* node=spell_barrier_fifo.head;
const unsigned char* body=(const unsigned char*)(node+1);uint32_t at=node->cursor,opcode,size;
if(at>node->bytes||node->bytes-at<8)return spell_barrier_hard_fail(6);
opcode=u32(body+at);size=u32(body+at+4);at+=8;
if(size>node->bytes-at)return spell_barrier_hard_fail(6);
if(transfer_presentation(opcode)||submit(opcode,body+at,size))return spell_barrier_fail(9);
if(opcode==0x690019)initial_spell_trace_note(body+at,size);
++d->submitted;++gw_wire_world_data.queued;
gw_wire_world_data.last_modern=opcode;gw_wire_world_data.last_bytes=size;
world_trace(3,opcode,size);node->cursor=at+size;
if(node->cursor==node->bytes)gw_world_locator_fifo_pop(&spell_barrier_fifo,spell_barrier_free,0);
}
if(!spell_barrier_fifo.head)d->state=3;
return 0;
}
static int spell_barrier_fail_open(uint32_t reason){
struct gw_pipe_spell_locator_barrier* d=&gw_wire_spell_locator_barrier;
uint32_t rounds=0,i;
/* A held FIFO belongs only to its original authenticated engine epoch.
* Never forward it into a replaced/closed connection. */
if(spell_barrier_fifo.head&&!spell_barrier_identity())return spell_barrier_hard_fail(2);
spell_barrier_bypassed=1;d->error=reason;d->generation=(uint32_t)pipe_generation;
pipe_note("GW_SPELL fail-open reason=",reason);
if(reason==3u){
pipe_note("GW_SPELL guard-failed-condition=",gw_wire_spell_locator_guard.failed_condition);
pipe_note("GW_SPELL guard-failed-span=",gw_wire_spell_locator_guard.failed_span);
}
pipe_note("GW_SPELL missing-observed-count=",spell_barrier_missing_count);
for(i=0;i<spell_barrier_missing_count;++i)pipe_note("GW_SPELL missing-observed-id=",spell_barrier_missing_ids[i]);
/* The diagnostic list contains observed failures, not an invented full
* enumeration. No extra native reads/requests are made on failure. */
if(d->required_count>spell_barrier_missing_count)pipe_note("GW_SPELL missing-set-not-enumerated=",1);
d->state=2;
while(spell_barrier_fifo.head&&rounds++<GW_WORLD_LOCATOR_MAX_RECORDS/128u+1u){
if(spell_barrier_flush())return -1;
}
if(spell_barrier_fifo.head)return spell_barrier_hard_fail(6);
d->state=3; /* Released/degraded; error retains the readiness reason. */
return 0;
}
static volatile uint64_t held_cast_poll_until,held_cast_poll_last;
/* Releases a held cast at its time (report 58f1cc). Same lock discipline as spell_barrier_poll. Only the
* Source request queue is pulled: a world drain with no Source packet queued fails its first call. */
static void held_cast_poll(void){
struct gw_wire_call c;uint64_t now;uint32_t index;
if(!held_cast_poll_until)return;
now=GetTickCount64();
if(now>=held_cast_poll_until){held_cast_poll_until=0;return;}
if(now-held_cast_poll_last<25u)return;
if(!TryAcquireSRWLockExclusive(&lock))return;
held_cast_poll_last=now;
{static volatile LONG n=0;if(InterlockedIncrement(&n)<=8)pipe_note("GW_WIRE cast-held poll login=",(uint32_t)gw_wire_world_data.login_sent|((uint32_t)gw_wire_pipe_data.world_auth<<1)|((uint32_t)gw_wire_pipe_data.closed<<2));}
if(!gw_wire_pipe_data.closed && gw_wire_pipe_data.world_auth && gw_wire_world_data.login_sent)
for(index=0;index<8;++index){
int status;init(&c,GW_WIRE_WORLD_REQUEST);c.output=outgoing;c.capacity=sizeof(outgoing);status=call(&c);
if(status==1)break;
{static volatile LONG n=0;if(InterlockedIncrement(&n)<=16)pipe_note("GW_WIRE cast-held request status=",(uint32_t)status|(c.opcode<<8));}
if(status){held_cast_poll_until=0;break;}
if(send_wire(outgoing,c.required)){held_cast_poll_until=0;break;}
world_trace(4,c.opcode,c.required>=6?c.required-6:0);
}
ReleaseSRWLockExclusive(&lock);
}
static void spell_barrier_poll(void){
struct gw_pipe_spell_locator_barrier* d=&gw_wire_spell_locator_barrier;int result=0;
if(d->state!=1&&d->state!=2)return;
if(!TryAcquireSRWLockExclusive(&lock)){++d->skipped_busy;return;}
if(d->state!=1&&d->state!=2)goto done;
if(!spell_barrier_identity()){result=spell_barrier_fail(2);goto done;}
if(d->state==1&&gw_world_locator_expired(d->started_ms,GetTickCount64())){result=spell_barrier_fail(7);goto done;}
if(!spell_barrier_main_qualified(0)){result=spell_barrier_fail(3);goto done;}
if(d->state==1){
struct gw_spell_locator_diagnostics observation;
result=spell_barrier_classify();if(result<0)goto done;if(!result)goto done;
++d->probes;
__builtin_memset(&observation,0,sizeof(observation));
result=d->required_count?gw_spell_locators_available(spell_barrier_main,spell_barrier_required,d->required_count,spell_barrier_read,0,&observation):1;
d->missing_id=observation.problem_spell_id;d->map_reason=observation.reason;d->read_bytes=observation.read_bytes;
if(d->missing_id){
uint32_t i;for(i=0;i<spell_barrier_missing_count&&spell_barrier_missing_ids[i]!=d->missing_id;++i){}
if(i==spell_barrier_missing_count&&i<32u)spell_barrier_missing_ids[spell_barrier_missing_count++]=d->missing_id;
}
if(result<0){result=spell_barrier_fail(8);goto done;}
if(!result)goto done;
if(!spell_barrier_identity()){result=spell_barrier_fail(2);goto done;}
if(!spell_barrier_main_qualified(0)){result=spell_barrier_fail(3);goto done;}
d->state=2;
}
result=spell_barrier_flush();
done:
if(result<0&&gw_wire_pipe_data.connection)close_pipe(26);
ReleaseSRWLockExclusive(&lock);
}
static int drain_world_packets(int source_received){
struct gw_wire_call c;FILETIME ft;uint64_t clock;uint32_t count,index,at=4,modern,size;int held_world=0;
struct gw_pipe_world_control* w=&gw_wire_world_data;
if(!source_received){gw_wire_world_failure.source_opcode=0;gw_wire_world_failure.source_bytes=0;}
GetSystemTimeAsFileTime(&ft);clock=(((uint64_t)ft.dwHighDateTime<<32)|ft.dwLowDateTime)/10000000ULL-11644473600ULL;
init(&c,GW_WIRE_WORLD_PACKET);c.input=(const unsigned char*)&clock;c.input_bytes=8;c.output=converted;c.capacity=sizeof(converted);
{
NTSTATUS transport_status=gw_wire_account_transport(&c);
int status=transport_status?-1:c.result;
if(status||c.required<4){
uint32_t phase=c.reserved ^ GW_WORLD_CALL_PHASE_MAGIC;
gw_wire_world_call_phase.phase=phase>=1u && phase<=GW_WORLD_CALL_PHASE_MAX ? phase : 0u;
MemoryBarrier();gw_wire_world_call_phase.present=1;
gw_wire_world_call_failure.generation=gw_wire_account_generation();
gw_wire_world_call_failure.transport_status=(int32_t)transport_status;
gw_wire_world_call_failure.call_result=c.result;
/* Accept only the versioned boolean mask, including on a transport
* fault; an absent/partial backend snapshot stays unavailable. */
gw_wire_world_call_failure.backend_state=
(c.value&0x80000000u) && !(c.value&~0x8000007fu) ? c.value : 0;
gw_wire_world_call_failure.source_received=!!source_received;
MemoryBarrier();gw_wire_world_call_failure.present=1;
gw_wire_world_failure.phase=1;gw_wire_world_failure.result=status;gw_wire_world_failure.required=c.required;gw_wire_world_failure.capacity=sizeof(converted);return -1;
}
}
held_world=spell_barrier_hold((uint32_t)source_received,c.required);if(held_world<0)return -1;
if(held_world){count=0;at=c.required;}else count=u32(converted);
if(count>1024){gw_wire_world_failure.phase=2;gw_wire_world_failure.count=count;return -1;}
if(!count&&source_received&&!held_world)++w->ignored;
for(index=0;index<count;++index){
if(at>c.required||c.required-at<8){gw_wire_world_failure.phase=3;gw_wire_world_failure.index=index;return -1;}
modern=u32(converted+at);size=u32(converted+at+4);at+=8;
if(size>c.required-at){gw_wire_world_failure.phase=4;gw_wire_world_failure.modern_opcode=modern;gw_wire_world_failure.modern_bytes=size;return -1;}
if(transfer_presentation(modern)){gw_wire_world_failure.phase=5;gw_wire_world_failure.result=-1;gw_wire_world_failure.modern_opcode=modern;return -1;}
{int status=submit(modern,converted+at,size);if(status){gw_wire_world_failure.phase=5;gw_wire_world_failure.result=status;gw_wire_world_failure.modern_opcode=modern;gw_wire_world_failure.modern_bytes=size;return -1;}}
if(modern==0x690019)initial_spell_trace_note(converted+at,size);
++w->queued;w->last_modern=modern;w->last_bytes=size; /* Core orders genuine self-create first. */
world_trace(3,modern,size);at+=size;
}
if(at!=c.required){gw_wire_world_failure.phase=6;return -1;}
/* A pre-login presentation can drain here while the Backend still owns a
* pending world packet. Requests are sendable only after player login. */
for(index=0;w->login_sent && index<64;++index){
int status;init(&c,GW_WIRE_WORLD_REQUEST);c.output=outgoing;c.capacity=sizeof(outgoing);status=call(&c);
if(status==1)break;
if(status){
pipe_note("GW_WORLD_REQUEST_FAIL result=",(uint32_t)status);
pipe_note("GW_WORLD_REQUEST_FAIL opcode=",c.opcode);
pipe_note("GW_WORLD_REQUEST_FAIL state=",(uint32_t)gw_wire_world_data.login_sent|
((uint32_t)gw_wire_pipe_data.world_auth<<1)|((uint32_t)gw_wire_pipe_data.closed<<2));
gw_wire_world_failure.phase=7;gw_wire_world_failure.result=status;return -1;
}
send_wire(outgoing,c.required);
world_trace(4,c.opcode,c.required>=6?c.required-6:0);
}
/* #118 (11-30, owner OCTO): the world-state blocks below exist only after player login; a pre-login drain
* (character select presentation) got -1 at ENTITY_STATE (phase 8) and closed the Wire on every first login. */
if(!w->login_sent)return 0;
init(&c,GW_WIRE_ENTITY_STATE);c.output=(unsigned char*)&gw_wire_entity_data;c.capacity=sizeof(gw_wire_entity_data);
{int status=call(&c);if(status || c.required!=sizeof(gw_wire_entity_data)){gw_wire_world_failure.phase=8;gw_wire_world_failure.result=status;return -1;}}
init(&c,GW_WIRE_MOTION_STATE);c.output=(unsigned char*)&gw_wire_motion_data;c.capacity=sizeof(gw_wire_motion_data);
{int status=call(&c);if(status || c.required!=sizeof(gw_wire_motion_data)){gw_wire_world_failure.phase=9;gw_wire_world_failure.result=status;return -1;}}
init(&c,GW_WIRE_INVENTORY_STATE);c.output=(unsigned char*)&gw_wire_inventory_data;c.capacity=sizeof(gw_wire_inventory_data);
{int status=call(&c);if(status || c.required!=sizeof(gw_wire_inventory_data)){gw_wire_world_failure.phase=10;gw_wire_world_failure.result=status;return -1;}}
init(&c,GW_WIRE_AURA_STATE);c.output=(unsigned char*)&gw_wire_aura_data;c.capacity=sizeof(gw_wire_aura_data);
{int status=call(&c);if(status || c.required!=sizeof(gw_wire_aura_data)){gw_wire_world_failure.phase=11;gw_wire_world_failure.result=status;return -1;}}
return 0;
}
static int world_packet(uint32_t opcode,uint32_t bytes){
struct gw_pipe_world_control* w=&gw_wire_world_data;
++w->received;w->last_legacy=opcode;world_trace(1,opcode,bytes);
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
if(opcode==0x31e)local_raid_note("source-in-31e bytes=",bytes);
if(opcode==0x31f)local_raid_note("source-in-31f bytes=",bytes);
#endif
if(opcode==0x130 && bytes>=5){
struct gw_pipe_cast_result* result=&gw_wire_cast_result;
++result->count;result->opcode=opcode;result->bytes=bytes;result->spell=u32(incoming);
result->status=incoming[4];result->reason=bytes>=6?incoming[5]:0;
}
if(opcode==0x112 && bytes){++gw_wire_cast_result.inventory_count;gw_wire_cast_result.inventory_reason=incoming[0];}
if(opcode==0x29d && bytes==1){++gw_wire_cast_result.stand_received;gw_wire_cast_result.stand_state=incoming[0];}
{
/* 2026-11-25 (Mindvex, Windows): one 83-byte SMSG_UPDATE_OBJECT the Backend could not convert (phase 1)
* closed the whole session (error=15). An object update the Backend rejects is dropped instead: the
* source packet is already consumed, so the stream stays aligned. Its words go to the startup log (no
* text in update blocks) to find the conversion gap; 32 rejections in a row still close the session. */
static uint32_t rejected_in_row;
int status=drain_world_packets(1);
if(!status){rejected_in_row=0;return 0;}
gw_wire_world_failure.source_opcode=opcode;gw_wire_world_failure.source_bytes=bytes;
/* 2026-11-25 23:49 (owner, Octo live): an SMSG_TRADE_STATUS 0x120 the Backend rejected closed the session the
* same way. Trade window packets are self-contained (each carries its whole state), so they are dropped too:
* at worst the trade window misses one state, the session stays. */
if(gw_wire_world_failure.phase!=1 || (opcode!=0xa9 && opcode!=0x1f6 && opcode!=0x120 && opcode!=0x121) || ++rejected_in_row>32)return status;
{
static volatile LONG traced=0;
if(InterlockedIncrement(&traced)<=16){
uint32_t i,words=bytes/4u>32u?32u:bytes/4u;
pipe_note("GW_WIRE update-dropped opcode=",opcode);pipe_note("GW_WIRE update-dropped bytes=",bytes);
pipe_note("GW_WIRE update-dropped result=",(uint32_t)gw_wire_world_failure.result);
for(i=0;i<words;++i)pipe_note("GW_WIRE update-dropped word=",u32(incoming+4u*i));
}
}
/* The rejection was handled here. Keep its drop log, but leave no
* failed call or Source opcode for an unrelated later pipe close. */
clear_world_failure();
return 0;
}
}
/* Local services can answer at character selection, before actor and movement state exist. */
static int service_packets(void){
struct gw_wire_call c;uint64_t clock=0;
uint32_t entries[32],count,at=4,index;
init(&c,GW_WIRE_WORLD_PACKET);c.index=1;c.input=(const unsigned char*)&clock;c.input_bytes=8;
c.output=converted;c.capacity=sizeof(converted);
if(call(&c) || c.required<4 || c.required>sizeof(converted))return -1;
count=u32(converted);
if(count>32)return -1;
for(index=0;index<count;++index){
uint32_t opcode,size;
if(c.required-at<8)return -1;
entries[index]=at;
opcode=u32(converted+at);size=u32(converted+at+4);at+=8;
if(opcode!=0x53002c && opcode!=0x4702b0 && opcode!=0x4701b4 && opcode!=0x4701b5)return -1;
if(size>c.required-at)return -1;
at+=size;
}
if(at!=c.required)return -1;
for(index=0;index<count;++index){
const unsigned char* entry=converted+entries[index];
uint32_t opcode=u32(entry),size=u32(entry+4);
if(submit(opcode,entry+8,size))return -1;
world_trace(3,opcode,size);
}
return 0;
}
/* Private startup-log note (no CRT): "<prefix><number> ms=<tick>\n". */
static char* pipe_note_number(char* at,unsigned long long value){
char digits[24];int n=0;do{digits[n++]=(char)('0'+value%10);value/=10;}while(value&&n<24);
while(n)*at++=digits[--n];
return at;
}
static void pipe_note(const char* prefix,uint32_t value){
char path[1024],line[160],*at=line;DWORD length,written=0;HANDLE file;
length=GetEnvironmentVariableA("GW_NATIVE_STARTUP_LOG",path,sizeof(path));
if(length>=sizeof(path))return;
if(!length){
/* Windows clients start without a launcher-set log: session-end causes go to <client>\Logs\Gateway.log
(numbers only, capped at 4 MiB) so a player's disconnect still names its cause. */
static const char tail[]="Logs\\Gateway.log";DWORD slash=0,i;
length=GetModuleFileNameA(0,path,sizeof(path));
if(!length||length>=sizeof(path))return;
for(i=0;i<length;i++)if(path[i]=='\\'||path[i]=='/')slash=i+1;
if(!slash||slash+sizeof(tail)>sizeof(path))return;
for(i=0;i<sizeof(tail);i++)path[slash+i]=tail[i];
{WIN32_FILE_ATTRIBUTE_DATA info;
if(GetFileAttributesExA(path,GetFileExInfoStandard,&info)&&(info.nFileSizeHigh||info.nFileSizeLow>4u*1024*1024))return;}
}
while(*prefix&&at<line+100)*at++=*prefix++;
at=pipe_note_number(at,value);
{const char* ms=" ms=";while(*ms)*at++=*ms++;}
at=pipe_note_number(at,GetTickCount64());*at++='\n';
file=CreateFileA(path,FILE_APPEND_DATA,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if(file==INVALID_HANDLE_VALUE)return;
WriteFile(file,line,(DWORD)(at-line),&written,0);CloseHandle(file);
}
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
/* Serialized by the pipe lock. Count every eligible event before logging so
* failed writes leave a gap. A complete observation requires both boundaries
* in a fresh per-process log and consecutive sequence numbers throughout. */
static void local_raid_note(const char* kind,uint32_t bytes){
static uint32_t sequence;
char label[80]="GW_RAID ",*at=label+8;
const char* suffix=" seq=";
DWORD saved=GetLastError();
while(*kind)*at++=*kind++;
at=pipe_note_number(at,bytes);
while(*suffix)*at++=*suffix++;
*at=0;
pipe_note(label,++sequence);
SetLastError(saved);
}
/* Opt-in only for a private LOCAL control. Use the existing sequence for loss
* detection and keep this observer independent of the body and all routing. */
static int local_chat_range_enabled(void){
static int enabled=-1;
if(enabled<0){
char value[2];
enabled=GetEnvironmentVariableA("GW_LOCAL_CHAT_RANGE",value,sizeof(value))==1 && value[0]=='1';
}
return enabled;
}
/* This switch is sampled once per world, under the same lock as the notes.
* The input marker uses only the decoded opcode and the length before dispatch. */
static int local_battlemaster_observing;
static void local_battlemaster_begin(void){
char value[2];
DWORD saved=GetLastError();
local_battlemaster_observing=GetEnvironmentVariableA("GW_LOCAL_BATTLEMASTER",value,sizeof(value))==1 && value[0]=='1';
if(local_battlemaster_observing)local_raid_note("battlemaster-enabled bytes=",0);
SetLastError(saved);
}
static void local_battlemaster_input(uint32_t opcode,uint32_t bytes){
if(!local_battlemaster_observing || !gw_wire_world_data.login_sent)return;
if(opcode==0x3e0191)local_raid_note("input-3e0191 bytes=",bytes);
else if(opcode==0x3f00c0)local_raid_note("input-3f00c0 bytes=",bytes);
}
static void local_chat_range_input(uint32_t opcode,uint32_t bytes){
char label[40]="chat-range opcode=";
char* at;
if(opcode<0x2d0000 || opcode>0x2d00ff || !gw_wire_world_data.login_sent || !local_chat_range_enabled())return;
at=pipe_note_number(label+sizeof("chat-range opcode=")-1,opcode);
__builtin_memcpy(at," bytes=",sizeof(" bytes="));
local_raid_note(label,bytes);
}
/* Public message kind only. Never record text, sender, destination or size. */
static void local_group_chat_note(const char* stage,uint32_t opcode){
if(gw_wire_world_data.login_sent &&
(opcode==0x2d0026 || opcode==0x2d0027 || opcode==0x2d0029))
local_raid_note(stage,opcode);
}
#endif
/* Error14 covers both a failed dispatch and invalid feed progress. Keep their
* exact public metadata before close_pipe can detach the Source account. */
static void pipe_feed_failure_note(NTSTATUS status,const struct gw_wire_call* c,uint32_t remaining){
char path[1024],line[512],*at=line;DWORD length,written=0;HANDLE file;unsigned i;
const char* names[]={" status="," result="," input="," consumed="," remaining=",
" last_source="," source_bytes="," last_native="," native_bytes=",
" auth_state="," pipe_closed="," generation="," ms="};
uint64_t values[]={(uint32_t)status,(uint32_t)c->result,c->input_bytes,c->consumed,remaining,
gw_wire_pipe_data.last_in_opcode,gw_wire_pipe_data.last_in_bytes,
gw_wire_pipe_data.last_out_opcode,gw_wire_pipe_data.last_out_bytes,
(uint32_t)gw_wire_auth_data.state,gw_wire_pipe_data.closed,
gw_wire_account_generation(),GetTickCount64()};
const char* prefix="GW_FEED_FAILURE";
length=GetEnvironmentVariableA("GW_NATIVE_STARTUP_LOG",path,sizeof(path));
if(!length||length>=sizeof(path))return;
while(*prefix)*at++=*prefix++;
for(i=0;i<sizeof(values)/sizeof(values[0]);++i){
const char* name=names[i];while(*name)*at++=*name++;
at=pipe_note_number(at,values[i]);
}
*at++='\n';
file=CreateFileA(path,FILE_APPEND_DATA,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if(file==INVALID_HANDLE_VALUE)return;
WriteFile(file,line,(DWORD)(at-line),&written,0);CloseHandle(file);
}
#ifdef GW_PRIVATE_TEST_GROUND_SOURCE_GUID
/* Local fixture evidence only. The general Unix capture is deliberately not
* available in PE builds. Keep this separate, explicitly compiled/opted in,
* and limited to numeric object updates and spell lifecycle packets. It never
* captures authentication, chat, mail, item text or arbitrary unknown bodies.
* arrival_ms is the receiving client's tick, NOT an invented Source CastTime. */
static void ground_source_capture(uint32_t opcode,uint32_t size){
static uint64_t started,bytes;static int stopped;
static const char hex[]="0123456789abcdef";
char option[2],path[1024],*line,*at;const char* text;
DWORD length,written=0;HANDLE file;uint64_t now;uint32_t i,capacity;
if(stopped||(opcode!=0xa9&&opcode!=0x1f6&&opcode!=0x131&&opcode!=0x132)||!size||size>65535)return;
if(!gw_wire_pipe_data.world_auth||!gw_wire_world_data.login_sent||!gw_wire_world_data.self_create||
gw_wire_pipe_data.closed||gw_wire_pipe_data.error||
gw_wire_spell_locator_barrier.source_guid!=(uint64_t)GW_PRIVATE_TEST_GROUND_SOURCE_GUID)return;
if(GetEnvironmentVariableA("GW_PRIVATE_GROUND_CAPTURE",option,sizeof(option))!=1||option[0]!='1')return;
length=GetEnvironmentVariableA("GW_NATIVE_STARTUP_LOG",path,sizeof(path));
if(!length||length>=sizeof(path))return;
now=GetTickCount64();if(!started)started=now?now:1;
capacity=size*2+192;
if(now-started>30000||bytes>8u*1024u*1024u-capacity){stopped=1;return;}
line=VirtualAlloc(0,capacity,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);if(!line){stopped=1;return;}
at=line;text="GW_GROUND_SOURCE opcode=";while(*text)*at++=*text++;
at=pipe_note_number(at,opcode);text=" bytes=";while(*text)*at++=*text++;
at=pipe_note_number(at,size);text=" guid=";while(*text)*at++=*text++;
at=pipe_note_number(at,gw_wire_spell_locator_barrier.source_guid);
text=" arrival_ms=";while(*text)*at++=*text++;at=pipe_note_number(at,now);
text=" body=";while(*text)*at++=*text++;
for(i=0;i<size;++i){*at++=hex[incoming[i]>>4];*at++=hex[incoming[i]&15];}*at++='\n';
file=CreateFileA(path,FILE_APPEND_DATA,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(file==INVALID_HANDLE_VALUE)stopped=1;
else{if(!WriteFile(file,line,(DWORD)(at-line),&written,0)||written!=(DWORD)(at-line))stopped=1;else bytes+=written;CloseHandle(file);}
VirtualFree(line,0,MEM_RELEASE);
}
#endif
static int packet(uint32_t opcode,uint32_t size){
struct gw_pipe_control* d=&gw_wire_pipe_data;struct gw_wire_call c;
trace(1,opcode,size);
#ifdef GW_PRIVATE_TEST_GROUND_SOURCE_GUID
ground_source_capture(opcode,size);
#endif
/* Publish before queueing the original completion, so its main-thread
* handler cannot invalidate world readiness before suspension is seen. */
if(opcode==0x4d && !size && d->world_auth && gw_wire_world_data.login_sent)
gw_wire_channel_world_left((void*)d->owner);
if(opcode==0x55 && d->world_auth && !gw_wire_world_data.login_sent && service_packets())return -1;
if(gw_wire_world_data.login_sent && world_packet(opcode,size))return -1;
private_capture_notice(0,0,0);
if(opcode==0x4d){
/* Original completion was queued above. Keep the authenticated realm
* socket; future roster/ping packets use their original non-world path.
* A fresh selected character must supply a new self-create/mover ACK. */
if((gw_wire_spell_locator_barrier.state==1||gw_wire_spell_locator_barrier.state==2)&&spell_barrier_fail(10))return -1;
spell_barrier_reset();
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
if(!size && d->world_auth && gw_wire_world_data.login_sent)local_raid_note("end bytes=",0);
#endif
gw_wire_world_data.login_sent=0;gw_wire_world_data.self_create=0;clear_transfer_bridge();
InterlockedAnd((volatile LONG*)&gw_wire_world_data.realm_context_bound,GW_WORLD_REALM_CONTEXT_BOUND);
}
if(opcode==0x1ee){
init(&c,GW_WIRE_AUTHENTICATED);if(call(&c)||c.value!=1)return -1;
d->world_auth=1;pipe_note("GW_WORLD auth-response-ok size=",size);
if(gw_wire_account_attach_engine_session())return -1;
pipe_note("GW_WORLD club-source-context state=",(uint32_t)gw_wire_club_source_context_state());
if(encode_submit(GW_WIRE_AUTH_INITIALIZATION,0x470001))return -1;
d->auth_queued=1;
if(encode_submit(GW_WIRE_GLUE_FEATURES,0x470064))return -1;
d->glue_queued=1;
if(client_initialization(0))return -1;
/* Original authenticated service bootstrap: ConnectionStatus State1,
* SuppressNotification=false. Starts the real guild club RPC client;
* it does not assert any Battle.net account/friends/membership. */
{const unsigned char connected=0x40;if(submit(0x4702b2,&connected,1))return -1;}
if(submit(0x4702b0,gw_club_empty_friends_subscription,sizeof(gw_club_empty_friends_subscription)) ||
submit(0x4702b0,gw_club_empty_block_subscription,sizeof(gw_club_empty_block_subscription)))return -1;
}else if(opcode==0x2c8){
/* The bound lifecycle handles the real Source rename result. A successful
* rename requests a fresh 0x3B before its native result can be presented. */
if(d->world_auth && !gw_wire_world_data.login_sent && creation_result())return -1;
}else if(opcode==0x3a || opcode==0x3c){
if(!d->world_auth || creation_result())return -1;
}else if(opcode==0x3b){
if(!d->world_auth || creation_result())return -1;
init(&c,GW_WIRE_CHARACTER_COUNT);if(call(&c))return -1;d->characters=c.value;
init(&c,GW_WIRE_ROSTER_DIAGNOSTICS);c.output=(unsigned char*)&gw_wire_roster_diagnostics_data;
c.capacity=sizeof(gw_wire_roster_diagnostics_data);
if(call(&c)||c.required!=sizeof(gw_wire_roster_diagnostics_data))return -1;
if(encode_submit(GW_WIRE_ENCODE_ROSTER,0x470018))return -1;
++d->roster_queued;
if(encode_submit(GW_WIRE_RESTRICTIONS,0x470019))return -1;
++d->restrictions_queued;
if(client_initialization(1))return -1;
}else if(opcode==0x55 && !gw_wire_world_data.login_sent){/* Read-only roster guild cache above. */}
else if(opcode==0x1dd){
/* Client pongs were queued for every genuine client ping. Retain the
* Source acknowledgment diagnostic without delivering a duplicate. */
if(size!=4)return -1;
++d->pongs_received;
}
else ++d->unsupported_in;
return 0;
}
static int drain(void){
struct gw_wire_call c;int result;
for(;;){
init(&c,GW_WIRE_PACKET);c.output=incoming;c.capacity=sizeof(incoming);result=call(&c);
if(result==1)return 0;
if(result)return result;
if(packet(c.packet.opcode,c.packet.payload_bytes))return -1;
}
}
static void WINAPI pipe_read_current(void* p,const struct gw_pipe_view* view,uint32_t epoch){
struct gw_wire_call c;const unsigned char* at;uint32_t remaining,take;int error=0;
NTSTATUS transport_status;
AcquireSRWLockExclusive(&lock);
/* Disconnect can leave the original native receiver alive until the next
* OpenRealm. Its borrowed arguments must not reach a closed Source pipe. */
if(epoch!=(uint32_t)pipe_generation || gw_wire_pipe_data.closed)goto done;
if(!owned(p)||!view||(!view->data&&view->bytes)||view->bytes>1024*1024){error=10;goto done;}
++gw_wire_pipe_data.read_calls;gw_wire_pipe_data.read_thread=GetCurrentThreadId();at=view->data;remaining=view->bytes;
if(!gw_wire_pipe_data.world_auth)pipe_note("GW_WORLD preauth-read bytes=",view->bytes);
/* An empty borrowed view is a no-op, including when its data pointer is null. */
if(!remaining)goto done;
#if defined(GW_SOURCE_UI_CREATE_EXPERIMENT) && defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3 || GW_SOURCE_ONLY_PROFILE == 5)
gw_ui_queue_drain_locked(p,epoch);
#endif
if(challenge_size<8){
take=8-challenge_size;if(take>remaining)take=remaining;
if(take)__builtin_memcpy(challenge+challenge_size,at,take);
challenge_size+=take;at+=take;remaining-=take;gw_wire_pipe_data.challenge_bytes=challenge_size;
if(challenge_size<8)goto done;
if(challenge[0]!=0||challenge[1]!=6||challenge[2]!=0xec||challenge[3]!=1){error=11;goto done;}
init(&c,GW_WIRE_CHALLENGE);c.opcode=0x1ec;c.input=challenge+4;c.input_bytes=4;
if(call(&c)){error=12;goto done;}
init(&c,GW_WIRE_AUTH_REQUEST);c.output=outgoing;c.capacity=sizeof(outgoing);
if(call(&c)){error=13;goto done;}
send_wire(outgoing,c.required);SecureZeroMemory(outgoing,c.required);gw_wire_pipe_data.auth_request_sent=1;pipe_note("GW_WORLD auth-request-sent bytes=",c.required);
}
while(remaining){
init(&c,GW_WIRE_FEED);c.input=at;c.input_bytes=remaining>65535?65535:remaining;
transport_status=gw_wire_account_transport(&c);
if(transport_status||c.result||!c.consumed||c.consumed>remaining){
pipe_feed_failure_note(transport_status,&c,remaining);error=14;goto done;
}
at+=c.consumed;remaining-=c.consumed;
if(drain()){error=15;goto done;}
}
done:
if(error&&gw_wire_pipe_data.connection)close_pipe(error);
ReleaseSRWLockExclusive(&lock);
}
static void WINAPI pipe_write_current(void* p,const struct gw_pipe_view* views,int count,uint32_t epoch){
struct gw_wire_call c;int index,error=0;uint32_t opcode;const char* banner="WORLD OF WARCRAFT CONNECTION - CLIENT TO SERVER - V2\n";
AcquireSRWLockExclusive(&lock);
if(epoch!=(uint32_t)pipe_generation || gw_wire_pipe_data.closed)goto done;
if(!owned(p)||!views||count<1||count>128){error=20;goto done;}
++gw_wire_pipe_data.write_calls;gw_wire_pipe_data.write_thread=GetCurrentThreadId();
/* Source NetClientSend submits one complete opcode+body descriptor. Reject
* unsupported scatter packets rather than misreading segments as opcodes. */
if(count!=1){error=21;goto done;}
for(index=0;index<count;++index){
const struct gw_pipe_view* v=views+index;
if(!v->data||v->bytes<4){error=22;goto done;}
/* A local layout write may include up to 128 KiB of compressed data, 38 bytes
* of update fields and a four-byte opcode. The original Source bounds still apply elsewhere. */
if(v->bytes>65533 && (!gw_wire_pipe_data.world_auth || u32(v->data)!=0x4400c4 ||
v->bytes>0x20000u+42u)){error=22;goto done;}
#if defined(GW_SOURCE_UI_CREATE_EXPERIMENT) && defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3 || GW_SOURCE_ONLY_PROFILE == 5)
gw_ui_queue_drain_locked(p,epoch);
#endif
if(v->bytes==53&&!__builtin_memcmp(v->data,banner,53))continue;
opcode=u32(v->data);trace(2,opcode,v->bytes-4);world_trace(2,opcode,v->bytes-4);
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
local_chat_range_input(opcode,v->bytes-4);
local_battlemaster_input(opcode,v->bytes-4);
local_group_chat_note("chat-input opcode=",opcode);
if(opcode==0x44007f && gw_wire_world_data.login_sent)local_raid_note("input-44007f bytes=",v->bytes-4);
if(opcode==0x450011 && gw_wire_world_data.login_sent)local_raid_note("input-450011 bytes=",v->bytes-4);
if(opcode==0x440094 && gw_wire_world_data.login_sent)local_raid_note("input-440094 bytes=",v->bytes-4);
#endif
private_capture_notice_input(1,opcode,v->bytes-4,v->data+4);
/* Forever source Map::SendInitSelf documents CMSG_MOVE_INIT_ACTIVE_MOVER_COMPLETE
* after an SMSG_UPDATE_OBJECT ThisIsYou create. Turtle has no matching
* legacy opcode; retain only the fact that the genuine engine emitted
* its four-byte client-tick ack so movement diagnostics can distinguish
* self-create acceptance from active-mover selection. Never forward it. */
if(opcode==0x420064){
InterlockedOr((volatile LONG*)&gw_wire_world_data.realm_context_bound,
v->bytes==8?GW_WORLD_MOVE_INIT_COMPLETE:GW_WORLD_MOVE_INIT_COMPLETE_BAD_SIZE);
++gw_wire_pipe_data.unsupported_out;diagnostic_client_drop(opcode,v->bytes-4);
gw_wire_pipe_data.reserved=(uint64_t)opcode|((uint64_t)(v->bytes-4)<<32);
continue;
}
if(opcode==0x440024 && gw_wire_pipe_data.world_auth && !gw_wire_world_data.login_sent){
current_account_name.loading_started=1;
pipe_note("GW_ACCOUNT_PROFILE name-ready-before-loading=",current_account_name.bound?1u:0u);
if(!current_account_name.bound){current_account_name.ready=0;SecureZeroMemory(current_account_name.name,sizeof(current_account_name.name));}
gw_login_timing_begin(&login_timing,GetTickCount64());
pipe_note("GW_LOGIN_TIMING loading-notify-input opcode=",opcode);
}
if(opcode==0x440010){
if(gw_login_timing_take(&login_timing,GW_LOGIN_DB2_REQUEST,GetTickCount64()))
pipe_note("GW_LOGIN_TIMING db2-request opcode=",opcode);
gw_wire_record_db_query(v->data+4,v->bytes-4);
if(db_query_missing(v->data+4,v->bytes-4)){error=24;goto done;}
continue;
}
if(opcode==0x440011){
if(gw_login_timing_take(&login_timing,GW_LOGIN_HOTFIX_REQUEST,GetTickCount64()))
pipe_note("GW_LOGIN_TIMING hotfix-request opcode=",opcode);
/* Source CMSG_HOTFIX_REQUEST only. Authentication stays in the
* existing registry gate; data records use original DB2 dispatch.
* No Warden/integrity opcode or engine function is intercepted. */
struct gw_pipe_hotfix* h=&gw_wire_hotfix_data;++h->queries;h->request_bytes=v->bytes-4;
h->client_build=h->data_build=h->push_count=h->reply_bytes=0;
if(v->bytes>=16){h->client_build=u32(v->data+4);h->data_build=u32(v->data+8);h->push_count=u32(v->data+12);}
/* Every page remains <=1MiB. submit() deep-copies synchronously
* into the existing engine queue before these buffers are reused.
* Full request validation precedes the first page; duplicates are
* sent once, and failure stops without replaying accepted pages. */
h->result=gw_hotfix_split_request(v->data+4,v->bytes-4,hotfix_submit_page,h);
if(h->result){++gw_wire_pipe_data.unsupported_out;diagnostic_client_drop(opcode,v->bytes-4);continue;}
continue;
}
if(opcode==0x460007){
/* Build70334 CMSG_LOG_DISCONNECT -> core0x440007 is a uint32
* reason report, not a socket-close command. The reference
* WorldSocket::HandleLogDisconnect logs it and returns Ok.
* In particular, preserve authenticated character selection
* after a genuine source LogoutComplete. */
if(v->bytes!=8){error=22;goto done;}
if(!gw_wire_pipe_data.world_auth){
uint32_t reason=(uint32_t)v->data[4]|(uint32_t)v->data[5]<<8|(uint32_t)v->data[6]<<16|(uint32_t)v->data[7]<<24;
pipe_note("GW_WORLD client-log-disconnect-preauth reason=",reason);
#if defined(GW_PRIVATE_TEST_COLD_START_TRACE) && GW_SOURCE_ONLY_PROFILE == 5
cold_start_disconnect_trace(reason);
#endif
}
continue;
}
if(opcode==0x420070){
if(creation_request(v->data+4,v->bytes-4)){error=26;goto done;}
continue;
}
if(opcode==0x4400f0){
/* Ordinary forced rename at the authenticated character selector. */
if(gw_wire_pipe_data.world_auth && !gw_wire_world_data.login_sent &&
creation_request_opcode(opcode,v->data+4,v->bytes-4)){error=26;goto done;}
continue;
}
if(opcode==0x4400cb){
/* CMSG_CHAR_DELETE: core validates roster identity -> source 0x38. */
if(creation_request_opcode(0x4400cb,v->data+4,v->bytes-4)){error=26;goto done;}
continue;
}
if(opcode==0x440016){
gw_login_timing_begin(&login_timing,GetTickCount64());
pipe_note("GW_LOGIN_TIMING client-player-login opcode=",opcode);
init(&c,GW_WIRE_BEGIN_WORLD);c.input=v->data+4;c.input_bytes=v->bytes-4;c.output=outgoing;c.capacity=sizeof(outgoing);
if(call(&c)){error=25;goto done;}
pipe_note("GW_LOGIN_TIMING backend-login-return bytes=",c.required);
/* Preserve existing transport behavior; record the actual result,
* never label mere encoding as a successful network submission. */
{int sent=send_wire(outgoing,c.required);
pipe_note(sent?"GW_LOGIN_TIMING player-login-send-failed bytes=":"GW_LOGIN_TIMING player-login-sent bytes=",c.required);}
++gw_wire_world_data.login_sent;
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
local_raid_note("begin bytes=",0);
local_battlemaster_begin();
if(local_chat_range_enabled())local_raid_note("chat-range-enabled bytes=",0);
#endif
continue;
}
if(opcode==0x2d0023){
init(&c,GW_WIRE_SAY);c.input=v->data+4;c.input_bytes=v->bytes-4;c.output=outgoing;c.capacity=sizeof(outgoing);
/* Reject unsupported/invalid text without closing an authenticated
* world session. Content is never included in diagnostics. */
if(call(&c)){++gw_wire_pipe_data.unsupported_out;diagnostic_client_drop(opcode,v->bytes-4);continue;}
if(c.required)send_wire(outgoing,c.required);
/* Adapter-local controls may produce only source-backed UI state.
* Reuse the same owned engine queue without a zero-byte TCP send
* or inventing an incoming source packet/received counter. */
else if(drain_world_packets(0)){error=24;goto done;}
continue;
}
if((opcode==0x3e0171 || opcode==0x3e0176) && gw_wire_pipe_data.world_auth && gw_wire_world_data.self_create && v->bytes>=4 && v->bytes-4<=256){
/* Actual compiled layout specimen; only this authenticated world
* gameplay opcode can enter the diagnostic record. */
struct gw_pipe_item_request* item=opcode==0x3e0171?&gw_wire_item_request:&gw_wire_spell_request;
item->captured=0;item->result=1;MemoryBarrier();
__builtin_memset(item->payload,0,sizeof(item->payload));
item->opcode=opcode;item->bytes=v->bytes-4;
__builtin_memcpy(item->payload,v->data+4,item->bytes);
MemoryBarrier();item->captured=item->bytes;
}
if((opcode==0x4400c4 || opcode==0x4400c3 || opcode==0x4401b1) && gw_wire_pipe_data.world_auth){
if(opcode!=0x4401b1&&gw_login_timing_take(&login_timing,GW_LOGIN_ACCOUNT_REQUEST,GetTickCount64()))
pipe_note("GW_LOGIN_TIMING account-request opcode=",opcode);
/* Authenticated account settings are available at character selection and in world.
* Only account-data requests and updates produce a service presentation. */
init(&c,GW_WIRE_GAMEPLAY);c.opcode=opcode;c.input=v->data+4;c.input_bytes=v->bytes-4;
c.output=outgoing;c.capacity=sizeof(outgoing);
if(call(&c)){++gw_wire_pipe_data.unsupported_out;diagnostic_client_drop(opcode,v->bytes-4);continue;}
if(opcode!=0x4401b1 && service_packets()){error=24;goto done;}
continue;
}
if(opcode==0x440124 && gw_wire_pipe_data.world_auth){
/* Original club RPCs terminate in the authenticated Source Core.
* Other services retain the existing unsupported behavior. A cold
* guild query drains a real empty bundle before Source requests. */
init(&c,GW_WIRE_GAMEPLAY);c.opcode=opcode;c.input=v->data+4;c.input_bytes=v->bytes-4;
c.output=outgoing;c.capacity=sizeof(outgoing);
if(call(&c)){++gw_wire_pipe_data.unsupported_out;diagnostic_client_drop(opcode,v->bytes-4);continue;}
if(c.required && send_wire(outgoing,c.required)){error=23;goto done;}
if(!gw_wire_world_data.login_sent ? service_packets() : drain_world_packets(0)){error=24;goto done;}
continue;
}
if(opcode==0x4400b6 && gw_wire_pipe_data.world_auth && !gw_wire_world_data.login_sent){
init(&c,GW_WIRE_GAMEPLAY);c.opcode=opcode;c.input=v->data+4;c.input_bytes=v->bytes-4;
c.output=outgoing;c.capacity=sizeof(outgoing);
/* Core validates fresh owned roster/guild/member/realm. Refusal
* drops this query, never the authenticated realm session. */
if(call(&c)){++gw_wire_pipe_data.unsupported_out;diagnostic_client_drop(opcode,v->bytes-4);continue;}
if(c.required && send_wire(outgoing,c.required)){error=23;goto done;}
continue;
}
/* Original GuildBankFrame requests use the same authenticated gameplay
* route. The native provider validates the actual NPC binding, source
* guild, slots and counts before producing any server request. */
/* Group/raid (0x44007f stats, ping, raid target, ready check, leader), trade 0x3e0000-0x3e0009,
* and mail (0x3f00db list .. 0x440081 return) reach the authenticated gameplay translator. */
/* Equipment manager sets (Codex 46e5aa02): saved locally by the native backend, swaps confirmed by the server. */
const int equipment_set_request = opcode==0x3f00a8 || opcode==0x3f00a9 || opcode==0x410001 || opcode==0x3e00c4;
if(opcode==0x4400b5 || equipment_set_request || gw_battleground_request(opcode) || opcode==0x44007f || opcode==0x440077 || opcode==0x44007c || opcode==0x44005e || opcode==0x44005f || opcode==0x440076 ||
(opcode>=0x3e0000 && opcode<=0x3e0009) || (opcode>=0x3f00db && opcode<=0x3f00e0) || opcode==0x3e00e9 || opcode==0x440026 || opcode==0x440081 || opcode==0x44008e || opcode==0x3f007f || opcode==0x4400b0 || opcode==0x3f0073 || opcode==0x3e0147 || opcode==0x2d0025 || opcode==0x2d0026 || opcode==0x2d0027 || opcode==0x2d0029 || opcode==0x2d002a || opcode==0x440146 || opcode==0x3e005c || opcode==0x440094 || opcode==0x3e0143 || opcode==0x3f0068 || opcode==0x3f006c || opcode==0x3f006d || opcode==0x3f006e ||
opcode==0x3d0154 || opcode==0x3e021c || opcode==0x3e021d || opcode==0x3f012c || opcode==0x3e00d8 || opcode==0x3f0061 || (opcode>=0x3f0020 && opcode<=0x3f0023) || opcode==0x3f0025 || opcode==0x3f0026 || opcode==0x3f0027 || opcode==0x3e0175 || opcode==0x3f0089 || opcode==0x4400f7 || opcode==0x3f0062 || opcode==0x3f006f || opcode==0x3f006b || opcode==0x3f0063 || opcode==0x3f0065 || opcode==0x3f0069 || opcode==0x3f006a || opcode==0x3f007b || opcode==0x3f007c || opcode==0x3f007e || opcode==0x3f00d7 || opcode==0x3e013a || opcode==0x3e0212 || opcode==0x3e0213 || opcode==0x3e0214 || opcode==0x4400af || opcode==0x3f0066 || opcode==0x3f004a || opcode==0x3e00ca || opcode==0x3e0156 || opcode==0x3e0186 || opcode==0x3e0188 || opcode==0x3f005e || opcode==0x3f005f || opcode==0x3f0060 || opcode==0x3e014b || opcode==0x3f00d8 || opcode==0x3f00d9 || opcode==0x3f00da || opcode==0x4400f8 || opcode==0x3f0028 || opcode==0x3e0012 || opcode==0x3f002a || opcode==0x3f0067 || opcode==0x3e018b || opcode==0x440080 || opcode==0x44010c || opcode==0x440100 || opcode==0x440101 || opcode==0x440104 || opcode==0x440105 || opcode==0x450011 || opcode==0x3e0148 ||
(opcode>=0x3f002d && opcode<=0x3f0037) || opcode==0x3f00ef || opcode==0x3f00d3 ||
opcode==0x3e0145 || opcode==0x3e0146 || opcode==0x3e014e || opcode==0x4400ad || opcode==0x4400f9 || opcode==0x4400ca || opcode==0x440073 || opcode==0x440078 || opcode==0x440079 || opcode==0x44007a || opcode==0x44007b || opcode==0x3e0029 || opcode==0x3e0023 || opcode==0x3e0022 || opcode==0x4400de ||
opcode==0x3f001e || opcode==0x3f00e6 || opcode==0x2d0024 || opcode==0x3f00d6 || opcode==0x3e028c || opcode==0x3f007d || opcode==0x2f0003 || opcode==0x3f0082 || opcode==0x3e0191 || opcode==0x3f00c0 || opcode==0x3f0048 || opcode==0x3f0049 || opcode==0x3f004c || opcode==0x3f004d || opcode==0x3f004e || opcode==0x3f004f ||
opcode==0x3f0052 || opcode==0x3f0053 || opcode==0x3f0054 || opcode==0x3f0055 ||
opcode==0x3f0050 || opcode==0x3f0051 || opcode==0x3f0056 || opcode==0x3f0057 || opcode==0x3f0058 ||
opcode==0x3f0059 || opcode==0x3f005a || opcode==0x3f005b || opcode==0x3f005c || opcode==0x3f005d || opcode==0x2f001a || opcode==0x2f0019 || opcode==0x3e018a ||
opcode==0x440030 || opcode==0x440032 || opcode==0x440096 || opcode==0x440034 || opcode==0x440029 || opcode==0x44002a || opcode==0x440075 || opcode==0x440074 || gw_native_far_control_kind(opcode)!=GW_NATIVE_FAR_NONE || opcode==0x3f0105 || opcode==0x3e00cc || opcode==0x3e00cd || opcode==0x3e00ce || opcode==0x3e00cf || opcode==0x3e00d2 || opcode==0x3e00d3 || opcode==0x3f0074 || opcode==0x3f0075 || opcode==0x3f00e9 || opcode==0x3f00ea || opcode==0x44008c || opcode==0x3f0078 || opcode==0x3f0047 || opcode==0x3f00cb || opcode==0x3e0155 || opcode==0x3e0061 || opcode==0x3f0043 || opcode==0x3f0040 || opcode==0x3f0041 || opcode==0x3f0042 || opcode==0x2d0008 || opcode==0x2d002b || opcode==0x2d000d || opcode==0x2d000e || opcode==0x4400b6 || opcode==0x2f0014 || opcode==0x2f001b || ((opcode==0x2f0000 || opcode==0x2f0001 || opcode==0x2f0002 || opcode==0x2f0005 || opcode==0x2f0013 || opcode==0x2f0008 || opcode==0x2f0015 || opcode==0x2f0016 || opcode==0x2f0009 || opcode==0x2f0006) && gw_accepted_feature_enabled("GW_GUILD_MANAGEMENT_PROTOTYPE")) || (opcode==0x2f000e && gw_accepted_feature_enabled("GW_GUILD_RANKS_PROTOTYPE")) || opcode==0x2d0000 || opcode==0x2d0001 || opcode==0x2d000f || opcode==0x2d0010 || opcode==0x2d0011 || opcode==0x2d0012 || opcode==0x2d0007 || opcode==0x3e0176 || opcode==0x440062 || opcode==0x3f00ce || opcode==0x3f00cd || opcode==0x3f001f || opcode==0x3e011e || opcode==0x3e011f || opcode==0x3f008b || opcode==0x3e0144 || opcode==0x3f0038 || opcode==0x3f0039 || opcode==0x3f003c || opcode==0x3f003b || opcode==0x3f0045 || opcode==0x3f0046 || opcode==0x3f004b || opcode==0x3f0029 || opcode==0x3f002b || opcode==0x410002 || opcode==0x410003 || opcode==0x410007 || opcode==0x410004 || opcode==0x410008 || opcode==0x410006 || opcode==0x3e0171 || opcode==0x3e0036 || opcode==0x3f0084 || opcode==0x3e0179 || opcode==0x3e016c || opcode==0x3e008a){
init(&c,GW_WIRE_GAMEPLAY);c.opcode=opcode;c.input=v->data+4;c.input_bytes=v->bytes-4;c.output=outgoing;c.capacity=sizeof(outgoing);
{int status=call(&c);if(opcode==0x3e0171)gw_wire_item_request.result=status;else if(opcode==0x3e0176)gw_wire_spell_request.result=status;
if(opcode==0x440026||(opcode>=0x3f00db&&opcode<=0x3f00e0)||opcode==0x3e00d8||opcode==0x3e00e9||opcode==0x440081){pipe_note("GW_WIRE mail opcode=",opcode);pipe_note("GW_WIRE mail status=",(uint32_t)status);pipe_note("GW_WIRE mail out=",c.required);}
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
local_group_chat_note(status ? "chat-declined opcode=" : (c.required ? "chat-translated opcode=" : "chat-empty opcode="),opcode);
#endif
if(status){++gw_wire_pipe_data.unsupported_out;diagnostic_client_drop(opcode,v->bytes-4);continue;}}
/* Report 58f1cc (2026-11-28): a cast the Backend holds (Turtle wand GCD, source standing) produces no
* packet; no Source packet need arrive before its release time, so the frame poll drains until then. */
if(opcode==0x3e0176 && !c.required){held_cast_poll_until=GetTickCount64()+4000u;{static volatile LONG n=0;if(InterlockedIncrement(&n)<=16)pipe_note("GW_WIRE cast-held armed=",1u);}}
if(c.required){
int sent=send_wire(outgoing,c.required);
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
if(!sent)local_group_chat_note("chat-handed opcode=",opcode);
if(!sent && opcode==0x440094 && c.required==6)local_raid_note("reset-frame-sent bytes=",c.required);
#endif
if(opcode==0x440025){
if(sent){error=24;goto done;}
/* Completion is after actual socket success, independent
* of the optional private capture environment. */
struct gw_wire_call completed;init(&completed,GW_WIRE_GAMEPLAY);
completed.index=1;completed.opcode=opcode;
if(call(&completed) || drain_world_packets(0)){error=24;goto done;}
}
/* #93 (2026-11-26): a sort with swaps sends CMSG_SWAP_ITEMs AND queues BagCleanupFinished. Without
* this drain the finish stayed queued, and the native client refused every later SortBags in the session. */
else if(!sent && c.value==GW_WIRE_LOCAL_PRESENTATION_READY && drain_world_packets(0)){error=24;goto done;}
}
/* Self-addressed addon IPC (0x2d002b) drains only when the backend reports a ready local reply:
* an OctoBM subscription has none, and draining an empty world ended the session (2026-11-22). */
else if((equipment_set_request || c.value==GW_WIRE_LOCAL_PRESENTATION_READY || opcode==0x3e0004 || opcode==0x440146 || opcode==0x44010c || opcode==0x450011 || opcode==0x3e0148 || opcode==0x3d0154 || gw_native_far_control_kind(opcode)==GW_NATIVE_FAR_SUSPEND) && drain_world_packets(0)){error=24;goto done;}
continue;
}
if(opcode==0x42005B||movement_opcode(opcode)){
if(opcode==0x42005B)InterlockedOr((volatile LONG*)&gw_wire_world_data.realm_context_bound,GW_WORLD_ACTIVE_MOVER_REQUEST);
else InterlockedOr((volatile LONG*)&gw_wire_world_data.realm_context_bound,GW_WORLD_MOVEMENT_REQUEST);
init(&c,opcode==0x42005B?GW_WIRE_ACTIVE_MOVER:GW_WIRE_MOVEMENT);
c.opcode=opcode;c.input=v->data+4;c.input_bytes=v->bytes-4;c.output=outgoing;c.capacity=sizeof(outgoing);
if(call(&c)){
if(opcode!=0x42005B)record_movement_failure(opcode,v->data+4,v->bytes-4,c.result);
if(opcode!=0x42005B&&c.result==-1){InterlockedOr((volatile LONG*)&gw_wire_world_data.realm_context_bound,GW_WORLD_MOVEMENT_REJECTED);++gw_wire_pipe_data.unsupported_out;diagnostic_client_drop(opcode,v->bytes-4);continue;}
pipe_note("GW_WIRE movement-fail opcode=",opcode);pipe_note("GW_WIRE movement-fail result=",(uint32_t)c.result);pipe_note("GW_WIRE movement-fail bytes=",v->bytes-4);
error=23;goto done;
}
InterlockedOr((volatile LONG*)&gw_wire_world_data.realm_context_bound,opcode==0x42005B?GW_WORLD_ACTIVE_MOVER_ACCEPTED:GW_WORLD_MOVEMENT_ACCEPTED);
send_wire(outgoing,c.required);world_trace(2,opcode,v->bytes-4);continue;
}
if(opcode==0x460006&&v->bytes==12){
ULONGLONG now;
/* A local pong must not conceal a known closed, unauthenticated,
* or failed Source session. Check the owned backend each time. */
if(!gw_wire_pipe_data.world_auth){error=23;goto done;}
init(&c,GW_WIRE_AUTHENTICATED);
if(call(&c)||c.value!=1){error=23;goto done;}
now=GetTickCount64();
if(!last_source_ping_ms||now-last_source_ping_ms>=28000u){
init(&c,GW_WIRE_SEND);c.opcode=0x1dc;c.input=v->data+4;c.input_bytes=8;
c.output=outgoing;c.capacity=sizeof(outgoing);
if(call(&c)||c.required!=14){error=23;goto done;}
if(send_wire(outgoing,c.required)){error=23;goto done;}
last_source_ping_ms=now;++gw_wire_pipe_data.pings_sent;
}
if(submit(0x4e0009,v->data+4,4)){error=23;goto done;}
continue;
}
if(opcode==0x440014&&v->bytes==4)c.opcode=0x37;
else{
/* Retain only the latest public opcode and body length so a
* controlled input can be mapped without exporting packet data.
* The packed value reuses the existing reserved diagnostic word,
* preserving the engine-pipe ABI. */
++gw_wire_pipe_data.unsupported_out;diagnostic_client_drop(opcode,v->bytes-4);
gw_wire_pipe_data.reserved=(uint64_t)opcode|((uint64_t)(v->bytes-4)<<32);
continue;
}
opcode=c.opcode;init(&c,GW_WIRE_SEND);c.opcode=opcode;c.input=v->data+4;c.input_bytes=v->bytes-4;c.output=outgoing;c.capacity=sizeof(outgoing);
if(call(&c)){error=23;goto done;}
send_wire(outgoing,c.required);
++gw_wire_pipe_data.enum_sent;
}
done:
if(error&&gw_wire_pipe_data.connection)close_pipe(error);
ReleaseSRWLockExclusive(&lock);
}
/* Original70334 pending-definition dispatch, qualified through both natural
* frame callers and a same-primary-thread/pre-world witness. This gate
* consumes genuine registered rows; it neither creates records nor replays
* initial spells. Never call native callbacks while holding our pipe lock. */
static LONG spell_pending_drain_active;
static int spell_pending_drain_before_barrier(void){
static const unsigned char prefix[]={0x48,0x89,0x5c,0x24,0x18,0x55,0x41,0x56,0x41,0x57,0x48,0x83,0xec,0x50,0x48,0x8d,0x0d,0x83,0xdb,0x39,0x07,0xff,0x15,0x1d,0x3f,0x17,0x04};
struct gw_pipe_spell_locator_barrier* d=&gw_wire_spell_locator_barrier;
MEMORY_BASIC_INFORMATION info;uintptr_t entry=0;DWORD protection;
void* frames[64];USHORT depth;
uint64_t started=0,owner=0,connection=0,pipe=0;uint32_t generation=0;
char option[2];unsigned index;int qualified=0,retained=0;
if(InterlockedCompareExchange(&spell_pending_drain_active,0,0))return 0;
if(d->state!=1||d->classified!=d->known_count||!d->required_count||!d->started_ms||
gw_world_locator_expired(d->started_ms,GetTickCount64()))return 1;
if(gw_world_locator_config(option,GetEnvironmentVariableA("GW_PRIVATE_SPELL_PENDING_DRAIN",option,sizeof(option)),1)<=0)return 1;
/* Exclude an already-active NATURAL dispatcher too, not just recursion
* through this integration. The complete original unwind fragments are
* contiguous64E630..64E862; incomplete/bounded captures do not admit it. */
depth=CaptureStackBackTrace(0,64,frames,0);
if(!depth||depth>=64)return 1;
for(index=0;index<depth;++index){
uintptr_t pc=(uintptr_t)frames[index];
if(pc>=spell_barrier_main+0x64e630u&&pc<spell_barrier_main+0x64e862u)return 1;
}
if(InterlockedCompareExchange(&spell_pending_drain_active,1,0))return 0;
if(TryAcquireSRWLockExclusive(&lock)){
if(d->state==1&&d->classified==d->known_count&&
spell_barrier_identity()&&spell_barrier_main_qualified(0)){
entry=spell_barrier_main+0x64e630u;
if(VirtualQuery((void*)entry,&info,sizeof(info))==sizeof(info)&&
info.State==MEM_COMMIT&&info.AllocationBase==(void*)spell_barrier_main&&
!(info.Protect&(PAGE_GUARD|PAGE_NOACCESS))&&
entry>=(uintptr_t)info.BaseAddress&&
entry-(uintptr_t)info.BaseAddress<=info.RegionSize&&
sizeof(prefix)<=info.RegionSize-(entry-(uintptr_t)info.BaseAddress)){
protection=info.Protect&0xffu;
if(protection==PAGE_EXECUTE_READ||protection==PAGE_EXECUTE_READWRITE||
protection==PAGE_EXECUTE_WRITECOPY){
qualified=1;
for(index=0;index<sizeof(prefix);++index)
if(((const unsigned char*)entry)[index]!=prefix[index]){qualified=0;break;}
}
}
if(qualified){
started=d->started_ms;generation=d->generation;
owner=spell_barrier_owner;connection=spell_barrier_connection;pipe=spell_barrier_pipe;
}
}
ReleaseSRWLockExclusive(&lock);
}
if(qualified){
/* The original dispatcher snapshots/unlocks its own queue before
* paired callbacks and typed updates. A store's 2000-entry/refcount
* bound can yield; its cleanup releases bodies and self-requeues
* leftovers. Resume that ordinary lifecycle on the next admitted
* owner poll while held, rather than treating one pass as a flush. */
((void (WINAPI *)(void))entry)();
/* A paired native callback may retire/reset the Source epoch. Never
* continue with the caller's cached engine object after that action. */
if(TryAcquireSRWLockExclusive(&lock)){
retained=d->state==1&&d->started_ms==started&&d->generation==generation&&
(uint32_t)pipe_generation==generation&&spell_barrier_owner==owner&&
spell_barrier_connection==connection&&spell_barrier_pipe==pipe&&spell_barrier_identity();
ReleaseSRWLockExclusive(&lock);
}
pipe_note("GW_SPELL original-pending-drain=",retained?1u:2u);
}
InterlockedExchange(&spell_pending_drain_active,0);
return qualified?retained:1;
}
/* Called only by our verified original-frame poll wrapper. Read only current
* engine-owned identities; never follow a stale historical pipe/socket. */
void WINAPI gw_wire_engine_session_poll(void* owner){
#if defined(GW_SOURCE_UI_CREATE_EXPERIMENT) && defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3 || GW_SOURCE_ONLY_PROFILE == 5)
gw_ui_queue_owner_poll(owner);
#endif
struct gw_pipe_control* d=&gw_wire_pipe_data;unsigned char* object=(unsigned char*)owner;uint64_t holder;
LONG observed_state=0;uint32_t ownership_loss=1;
if(d->abi!=1||d->size!=sizeof(*d)||d->stage!=1||!d->world_auth||d->closed||d->owner!=(uint64_t)owner)return;
if(((observed_state=*(volatile LONG*)(object+0x98))==5 || (observed_state=*(volatile LONG*)(object+0x98))==4) && *(uint64_t*)(object+0x1a0)==d->connection){
holder=*(uint64_t*)(object+0x228);
if(holder && *(uint64_t*)holder==d->pipe){
if(!spell_pending_drain_before_barrier())return;
spell_barrier_poll();
held_cast_poll();
if(d->closed)return;
if(!gw_wire_account_engine_heartbeat() &&
!(gw_wire_world_data.realm_context_bound&GW_WORLD_REALM_CONTEXT_BOUND) &&
*(volatile LONG*)(object+0x98)==5 && object[0x7e8]==1 && object[0xc49]==1){
/* Original realm adoption1422bbe90 copies parameter+68 to
* owner+198 (1422bbfcf) and owner+898 (1422bbff1). The original
* EnterWorld realm manager142429ba0 compares character+274
* against owner+898 before using its existing connection.
* Only public routing namespace is adopted here, AFTER genuine
* SRP/M2/world auth and original engine success callbacks.
* No account/session prefix, flags, proof or token is written.
*/
if(gw_wire_realm_previous.abi==1 && gw_wire_realm_previous.size==sizeof(gw_wire_realm_previous) &&
!gw_engine_adopt_realm_routing(owner,0xc4b,0x46010046,gw_wire_realm_previous.current,gw_wire_realm_previous.route))InterlockedOr((volatile LONG*)&gw_wire_world_data.realm_context_bound,GW_WORLD_REALM_CONTEXT_BOUND);
}
if((gw_wire_world_data.realm_context_bound&GW_WORLD_REALM_CONTEXT_BOUND)&&
*(volatile LONG*)(object+0x98)==5){current_realm_record_poll(owner);current_account_name_poll(owner);}
return;
}
ownership_loss=holder?8u:4u;
}else if(observed_state==5 || observed_state==4){
ownership_loss=2;
}
/* Existing48B status only: phase12 is the first observed native-owner
* identity loss, result bits1/2/4/8 identify state/connection/holder/pipe,
* and index retains the raw state already used by the original guard.
* No pointer or packet data is copied, no extra engine field is read,
* and a prior world-pipeline failure keeps its original attribution. */
if(!gw_wire_world_failure.phase){
gw_wire_world_failure.result=(int32_t)ownership_loss;
gw_wire_world_failure.index=(uint32_t)observed_state;
MemoryBarrier();gw_wire_world_failure.phase=12;
}
/* Actual engine-owned connection/pipe is gone; no engine pointer writes. */
spell_barrier_cancel(2);gw_wire_account_detach_engine_session();d->closed=1;
}
/* Immutable callback entrypoints prevent old captured function pointers from
* entering the next account epoch, even if native addresses are reused. */
uint32_t WINAPI gw_wire_pipe_generation(void){return (uint32_t)InterlockedCompareExchange(&pipe_generation,0,0);}
__declspec(dllexport) void WINAPI gw_wire_pipe_read(void* p,const struct gw_pipe_view* view){if(gw_wire_pipe_generation()==1)pipe_read_current(p,view,1);}
__declspec(dllexport) void WINAPI gw_wire_pipe_write(void* p,const struct gw_pipe_view* views,int count){if(gw_wire_pipe_generation()==1)pipe_write_current(p,views,count,1);}
#define GW_PIPE_EPOCH(N) \
static void WINAPI pipe_read_##N(void* p,const struct gw_pipe_view* view){if(gw_wire_pipe_generation()==N)pipe_read_current(p,view,N);} \
static void WINAPI pipe_write_##N(void* p,const struct gw_pipe_view* views,int count){if(gw_wire_pipe_generation()==N)pipe_write_current(p,views,count,N);}
GW_PIPE_EPOCH(2)
GW_PIPE_EPOCH(3)
GW_PIPE_EPOCH(4)
GW_PIPE_EPOCH(5)
GW_PIPE_EPOCH(6)
GW_PIPE_EPOCH(7)
GW_PIPE_EPOCH(8)
GW_PIPE_EPOCH(9)
GW_PIPE_EPOCH(10)
GW_PIPE_EPOCH(11)
GW_PIPE_EPOCH(12)
GW_PIPE_EPOCH(13)
GW_PIPE_EPOCH(14)
GW_PIPE_EPOCH(15)
GW_PIPE_EPOCH(16)
GW_PIPE_EPOCH(17)
GW_PIPE_EPOCH(18)
GW_PIPE_EPOCH(19)
GW_PIPE_EPOCH(20)
GW_PIPE_EPOCH(21)
GW_PIPE_EPOCH(22)
GW_PIPE_EPOCH(23)
GW_PIPE_EPOCH(24)
GW_PIPE_EPOCH(25)
GW_PIPE_EPOCH(26)
GW_PIPE_EPOCH(27)
GW_PIPE_EPOCH(28)
GW_PIPE_EPOCH(29)
GW_PIPE_EPOCH(30)
GW_PIPE_EPOCH(31)
GW_PIPE_EPOCH(32)
GW_PIPE_EPOCH(33)
GW_PIPE_EPOCH(34)
GW_PIPE_EPOCH(35)
GW_PIPE_EPOCH(36)
GW_PIPE_EPOCH(37)
GW_PIPE_EPOCH(38)
GW_PIPE_EPOCH(39)
GW_PIPE_EPOCH(40)
GW_PIPE_EPOCH(41)
GW_PIPE_EPOCH(42)
GW_PIPE_EPOCH(43)
GW_PIPE_EPOCH(44)
GW_PIPE_EPOCH(45)
GW_PIPE_EPOCH(46)
GW_PIPE_EPOCH(47)
GW_PIPE_EPOCH(48)
GW_PIPE_EPOCH(49)
GW_PIPE_EPOCH(50)
GW_PIPE_EPOCH(51)
GW_PIPE_EPOCH(52)
GW_PIPE_EPOCH(53)
GW_PIPE_EPOCH(54)
GW_PIPE_EPOCH(55)
GW_PIPE_EPOCH(56)
GW_PIPE_EPOCH(57)
GW_PIPE_EPOCH(58)
GW_PIPE_EPOCH(59)
GW_PIPE_EPOCH(60)
GW_PIPE_EPOCH(61)
GW_PIPE_EPOCH(62)
GW_PIPE_EPOCH(63)
GW_PIPE_EPOCH(64)
#undef GW_PIPE_EPOCH
__declspec(dllexport) struct gw_session_pipe_callbacks gw_wire_session_pipe_callbacks={.abi=1,.size=sizeof(struct gw_session_pipe_callbacks),.count=GW_SESSION_EPOCH_LIMIT,.callbacks={
{(uint64_t)(uintptr_t)gw_wire_pipe_write,(uint64_t)(uintptr_t)gw_wire_pipe_read},
{(uint64_t)(uintptr_t)pipe_write_2,(uint64_t)(uintptr_t)pipe_read_2},
{(uint64_t)(uintptr_t)pipe_write_3,(uint64_t)(uintptr_t)pipe_read_3},
{(uint64_t)(uintptr_t)pipe_write_4,(uint64_t)(uintptr_t)pipe_read_4},
{(uint64_t)(uintptr_t)pipe_write_5,(uint64_t)(uintptr_t)pipe_read_5},
{(uint64_t)(uintptr_t)pipe_write_6,(uint64_t)(uintptr_t)pipe_read_6},
{(uint64_t)(uintptr_t)pipe_write_7,(uint64_t)(uintptr_t)pipe_read_7},
{(uint64_t)(uintptr_t)pipe_write_8,(uint64_t)(uintptr_t)pipe_read_8},
{(uint64_t)(uintptr_t)pipe_write_9,(uint64_t)(uintptr_t)pipe_read_9},
{(uint64_t)(uintptr_t)pipe_write_10,(uint64_t)(uintptr_t)pipe_read_10},
{(uint64_t)(uintptr_t)pipe_write_11,(uint64_t)(uintptr_t)pipe_read_11},
{(uint64_t)(uintptr_t)pipe_write_12,(uint64_t)(uintptr_t)pipe_read_12},
{(uint64_t)(uintptr_t)pipe_write_13,(uint64_t)(uintptr_t)pipe_read_13},
{(uint64_t)(uintptr_t)pipe_write_14,(uint64_t)(uintptr_t)pipe_read_14},
{(uint64_t)(uintptr_t)pipe_write_15,(uint64_t)(uintptr_t)pipe_read_15},
{(uint64_t)(uintptr_t)pipe_write_16,(uint64_t)(uintptr_t)pipe_read_16},
{(uint64_t)(uintptr_t)pipe_write_17,(uint64_t)(uintptr_t)pipe_read_17},
{(uint64_t)(uintptr_t)pipe_write_18,(uint64_t)(uintptr_t)pipe_read_18},
{(uint64_t)(uintptr_t)pipe_write_19,(uint64_t)(uintptr_t)pipe_read_19},
{(uint64_t)(uintptr_t)pipe_write_20,(uint64_t)(uintptr_t)pipe_read_20},
{(uint64_t)(uintptr_t)pipe_write_21,(uint64_t)(uintptr_t)pipe_read_21},
{(uint64_t)(uintptr_t)pipe_write_22,(uint64_t)(uintptr_t)pipe_read_22},
{(uint64_t)(uintptr_t)pipe_write_23,(uint64_t)(uintptr_t)pipe_read_23},
{(uint64_t)(uintptr_t)pipe_write_24,(uint64_t)(uintptr_t)pipe_read_24},
{(uint64_t)(uintptr_t)pipe_write_25,(uint64_t)(uintptr_t)pipe_read_25},
{(uint64_t)(uintptr_t)pipe_write_26,(uint64_t)(uintptr_t)pipe_read_26},
{(uint64_t)(uintptr_t)pipe_write_27,(uint64_t)(uintptr_t)pipe_read_27},
{(uint64_t)(uintptr_t)pipe_write_28,(uint64_t)(uintptr_t)pipe_read_28},
{(uint64_t)(uintptr_t)pipe_write_29,(uint64_t)(uintptr_t)pipe_read_29},
{(uint64_t)(uintptr_t)pipe_write_30,(uint64_t)(uintptr_t)pipe_read_30},
{(uint64_t)(uintptr_t)pipe_write_31,(uint64_t)(uintptr_t)pipe_read_31},
{(uint64_t)(uintptr_t)pipe_write_32,(uint64_t)(uintptr_t)pipe_read_32},
{(uint64_t)(uintptr_t)pipe_write_33,(uint64_t)(uintptr_t)pipe_read_33},
{(uint64_t)(uintptr_t)pipe_write_34,(uint64_t)(uintptr_t)pipe_read_34},
{(uint64_t)(uintptr_t)pipe_write_35,(uint64_t)(uintptr_t)pipe_read_35},
{(uint64_t)(uintptr_t)pipe_write_36,(uint64_t)(uintptr_t)pipe_read_36},
{(uint64_t)(uintptr_t)pipe_write_37,(uint64_t)(uintptr_t)pipe_read_37},
{(uint64_t)(uintptr_t)pipe_write_38,(uint64_t)(uintptr_t)pipe_read_38},
{(uint64_t)(uintptr_t)pipe_write_39,(uint64_t)(uintptr_t)pipe_read_39},
{(uint64_t)(uintptr_t)pipe_write_40,(uint64_t)(uintptr_t)pipe_read_40},
{(uint64_t)(uintptr_t)pipe_write_41,(uint64_t)(uintptr_t)pipe_read_41},
{(uint64_t)(uintptr_t)pipe_write_42,(uint64_t)(uintptr_t)pipe_read_42},
{(uint64_t)(uintptr_t)pipe_write_43,(uint64_t)(uintptr_t)pipe_read_43},
{(uint64_t)(uintptr_t)pipe_write_44,(uint64_t)(uintptr_t)pipe_read_44},
{(uint64_t)(uintptr_t)pipe_write_45,(uint64_t)(uintptr_t)pipe_read_45},
{(uint64_t)(uintptr_t)pipe_write_46,(uint64_t)(uintptr_t)pipe_read_46},
{(uint64_t)(uintptr_t)pipe_write_47,(uint64_t)(uintptr_t)pipe_read_47},
{(uint64_t)(uintptr_t)pipe_write_48,(uint64_t)(uintptr_t)pipe_read_48},
{(uint64_t)(uintptr_t)pipe_write_49,(uint64_t)(uintptr_t)pipe_read_49},
{(uint64_t)(uintptr_t)pipe_write_50,(uint64_t)(uintptr_t)pipe_read_50},
{(uint64_t)(uintptr_t)pipe_write_51,(uint64_t)(uintptr_t)pipe_read_51},
{(uint64_t)(uintptr_t)pipe_write_52,(uint64_t)(uintptr_t)pipe_read_52},
{(uint64_t)(uintptr_t)pipe_write_53,(uint64_t)(uintptr_t)pipe_read_53},
{(uint64_t)(uintptr_t)pipe_write_54,(uint64_t)(uintptr_t)pipe_read_54},
{(uint64_t)(uintptr_t)pipe_write_55,(uint64_t)(uintptr_t)pipe_read_55},
{(uint64_t)(uintptr_t)pipe_write_56,(uint64_t)(uintptr_t)pipe_read_56},
{(uint64_t)(uintptr_t)pipe_write_57,(uint64_t)(uintptr_t)pipe_read_57},
{(uint64_t)(uintptr_t)pipe_write_58,(uint64_t)(uintptr_t)pipe_read_58},
{(uint64_t)(uintptr_t)pipe_write_59,(uint64_t)(uintptr_t)pipe_read_59},
{(uint64_t)(uintptr_t)pipe_write_60,(uint64_t)(uintptr_t)pipe_read_60},
{(uint64_t)(uintptr_t)pipe_write_61,(uint64_t)(uintptr_t)pipe_read_61},
{(uint64_t)(uintptr_t)pipe_write_62,(uint64_t)(uintptr_t)pipe_read_62},
{(uint64_t)(uintptr_t)pipe_write_63,(uint64_t)(uintptr_t)pipe_read_63},
{(uint64_t)(uintptr_t)pipe_write_64,(uint64_t)(uintptr_t)pipe_read_64},
}};
/* Each epoch row holds original RTTI+all9 methods and is written once by
* the exact owned binder. Retirement never zeros or reuses these tables. */
__declspec(dllexport) struct gw_session_pipe_tables gw_wire_session_pipe_tables={.abi=1,.size=sizeof(struct gw_session_pipe_tables),.count=GW_SESSION_EPOCH_LIMIT};
/* Retired native objects are not replaced or dereferenced. A later epoch may
* use the same address after the allocator creates a fresh pipe there. */
__declspec(dllexport) struct gw_session_pipe_receivers gw_wire_session_pipe_receivers={.abi=1,.size=528,.count=GW_SESSION_EPOCH_LIMIT};
int WINAPI gw_wire_pipe_receiver_allowed(uint64_t receiver){
uint32_t i;const struct gw_session_pipe_receivers* history=&gw_wire_session_pipe_receivers;
if(!receiver || history->abi!=1 || history->size!=528 || history->count!=GW_SESSION_EPOCH_LIMIT || history->reserved)return 0;
/* Windows may recycle a retired pipe's address on the next OpenRealm.
* Bind acceptance to the current epoch's published owner instead of the
* address history. Old callbacks are separately gated by their immutable
* epoch, and owned() also checks the live native owner/connection chain. */
i=(uint32_t)pipe_generation;
return i && i<=GW_SESSION_EPOCH_LIMIT && !history->objects[i-1] &&
gw_wire_pipe_data.abi==1 && gw_wire_pipe_data.size==sizeof(gw_wire_pipe_data) &&
gw_wire_pipe_data.stage==1 && gw_wire_pipe_data.pipe==receiver;
}
static int retirement_readable(const void* pointer,SIZE_T length){
MEMORY_BASIC_INFORMATION info;uintptr_t start=(uintptr_t)pointer,end;
if(!pointer || !length || start>UINTPTR_MAX-length)return 0;
end=start+length;
if(!VirtualQuery(pointer,&info,sizeof(info)) || info.State!=MEM_COMMIT || (info.Protect&(PAGE_GUARD|PAGE_NOACCESS)))return 0;
return start>=(uintptr_t)info.BaseAddress && end<=(uintptr_t)info.BaseAddress+info.RegionSize;
}
int WINAPI gw_wire_pipe_retirement_lock(void){return TryAcquireSRWLockExclusive(&lock)?0:-17;}
void WINAPI gw_wire_pipe_retirement_unlock(void){ReleaseSRWLockExclusive(&lock);}
int WINAPI gw_wire_pipe_retirement_ready(void* owner,uint32_t expected){
unsigned char* object=(unsigned char*)owner;uint64_t holder;
struct gw_pipe_control* d=&gw_wire_pipe_data;
if(expected!=(uint32_t)pipe_generation || !expected || expected>=GW_SESSION_EPOCH_LIMIT)return -10;
if(gw_wire_session_pipe_receivers.abi!=1 || gw_wire_session_pipe_receivers.size!=528 || gw_wire_session_pipe_receivers.count!=GW_SESSION_EPOCH_LIMIT || gw_wire_session_pipe_receivers.reserved || gw_wire_session_pipe_receivers.objects[expected-1])return -18;
if(!owner || *(void**)0x145e7a098ULL!=owner || !retirement_readable(owner,0x230))return -11;
/* Only the already source-bound connection/primary-pipe absence is asserted;
* this is deliberately not an invented Login UI state constant. */
if(*(uint64_t*)(object+0x1a0))return -12;
holder=*(uint64_t*)(object+0x228);
if(holder && (!retirement_readable((void*)holder,8) || *(uint64_t*)holder))return -13;
if(d->abi!=1 || d->size!=sizeof(*d) || (d->stage!=0 && d->stage!=1))return -14;
if(d->stage==1 && (d->owner!=(uint64_t)owner || !d->closed))return -15;
if(d->stage==0 && d->owner)return -16;
if(d->pipe && !gw_wire_pipe_receiver_allowed(d->pipe))return -19;
return 0;
}
void WINAPI gw_wire_pipe_retire_generation(uint32_t next){
#if defined(GW_SOURCE_UI_CREATE_EXPERIMENT) && defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3 || GW_SOURCE_ONLY_PROFILE == 5)
gw_ui_queue_retire_locked();
#endif
spell_barrier_reset();clear_transfer_bridge();
last_source_ping_ms=0;
if(gw_wire_pipe_data.pipe)gw_wire_session_pipe_receivers.objects[(uint32_t)pipe_generation-1]=gw_wire_pipe_data.pipe;
gw_wire_pipe_data=(struct gw_pipe_control){.abi=1,.size=sizeof(struct gw_pipe_control)};
gw_wire_pipe_queries=(struct gw_pipe_db_queries){.abi=1,.size=sizeof(struct gw_pipe_db_queries)};
gw_wire_hotfix_data=(struct gw_pipe_hotfix){.abi=1,.size=sizeof(struct gw_pipe_hotfix)};
gw_wire_entity_data=(struct gw_pipe_entities){.abi=3,.size=sizeof(struct gw_pipe_entities),.unit_fields={.abi=1,.size=2080}};
gw_wire_world_data=(struct gw_pipe_world_control){.abi=1,.size=sizeof(struct gw_pipe_world_control)};
clear_world_failure();
gw_wire_motion_data=(struct gw_pipe_motion){.abi=2,.size=sizeof(struct gw_pipe_motion)};
gw_wire_item_request=(struct gw_pipe_item_request){.abi=1,.size=sizeof(struct gw_pipe_item_request)};
gw_wire_spell_request=(struct gw_pipe_item_request){.abi=1,.size=sizeof(struct gw_pipe_item_request)};
gw_wire_cast_result=(struct gw_pipe_cast_result){.abi=1,.size=sizeof(struct gw_pipe_cast_result)};
gw_wire_inventory_data=(struct gw_pipe_inventory){.abi=2,.size=sizeof(struct gw_pipe_inventory)};
gw_wire_aura_data=(struct gw_pipe_auras){.abi=1,.size=sizeof(struct gw_pipe_auras)};
gw_wire_movement_failure=(struct gw_pipe_movement_failure){.abi=1,.size=48};
gw_wire_roster_diagnostics_data=(struct gw_native_roster_diagnostics){.abi=GW_NATIVE_ROSTER_DIAGNOSTICS_ABI,.size=sizeof(struct gw_native_roster_diagnostics)};
SecureZeroMemory(challenge,sizeof(challenge));challenge_size=0;
SecureZeroMemory(incoming,sizeof(incoming));SecureZeroMemory(outgoing,sizeof(outgoing));
SecureZeroMemory(converted,sizeof(converted));SecureZeroMemory(queued,sizeof(queued));
InterlockedExchange(&pipe_generation,(LONG)next);
}
#include "pipe_snapshot.private.inc"