Reconstruct lab story, interactions, patrol and jet pack practice flow
This commit is contained in:
1 parent
58424120bb
commit
c929f942e1
84 files changed
+7957
-305
No files matched your search
@@ -0,0 +1,173 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only original collision/pivot evidence checks; executes no original code.
|
||||
|
||||
Run from GamePort: python3 tools/binary/collision_evidence.py
|
||||
Outputs bounded JSON facts from the original PE, GAM, OMT and standing ASE bytes.
|
||||
"""
|
||||
from pathlib import Path
|
||||
import collections
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
PROJECT = HERE.parent.parent
|
||||
sys.path.insert(0, str(HERE))
|
||||
sys.path.insert(0, str(PROJECT / 'tools/levels'))
|
||||
sys.path.insert(0, str(PROJECT / 'tools/extractors'))
|
||||
from pe_inspect import PE
|
||||
from rtti_map import rtti_map
|
||||
from gam import parse
|
||||
from omt import Database, read_shape
|
||||
|
||||
|
||||
def f32(value):
|
||||
return struct.unpack('<f', struct.pack('<f', value))[0]
|
||||
|
||||
|
||||
def fingerprint(data):
|
||||
value = 2166136261
|
||||
for byte in data:
|
||||
value = ((value ^ byte) * 16777619) & 0xffffffff
|
||||
return f'{value:08x}'
|
||||
|
||||
|
||||
def main():
|
||||
originals = PROJECT.parent / 'Original'
|
||||
pe = PE(originals / 'Neutron.exe')
|
||||
omt_pe = PE(originals / 'OMT2.dll')
|
||||
# These assertions guard the decisive instructions against source mismatch.
|
||||
sequences = {
|
||||
'jimmy_postload_radius60_push': (0x4236a3, '6800007042'),
|
||||
'jimmy_postload_support_factor_push': (0x4236b3, '6885eba13f'),
|
||||
'grounded_gadget0_radius160_push': (0x4246b4, '6800002043'),
|
||||
'grounded_other_radius60_push': (0x4246dc, '6800007042'),
|
||||
'support_radius_getter': (0x47b8b0, 'ff9060020000'),
|
||||
'support_factor_getter': (0x47b8be, 'ff9250020000'),
|
||||
'support_radius_factor_multiply': (0x47b8c8, 'd84c2420'),
|
||||
'support_hit_height_plus_clearance': (0x47bae1, 'd90564fc5c00d8442408'),
|
||||
'support_set_grounded': (0x47bb7c, '6a018bceff921c020000'),
|
||||
'null_polygon_material_returns_false': (0x4794e8, '8b460485c00f8495020000'),
|
||||
'ai_support_factor_point3_push': (0x407b2b, '689a99993e'),
|
||||
'goddard_postload_radius130_push': (0x41e64a, '6800000243'),
|
||||
'support_clearance_threshold_reference': (0x47ba48, 'd81d20d94800'),
|
||||
'support_prevent_lowering_root_compare': (0x47bafd, 'd9442410d85c2408'),
|
||||
'support_prevent_lowering_reject_above': (0x47bb0a, '0f8497000000'),
|
||||
'ray_one_sided_flag': (0x469c7e, '8a842480000000'),
|
||||
'ray_one_sided_reject': (0x469c85, '84c00f8491010000'),
|
||||
'ray_negative_distance_reject': (0x469ddd, '753f'),
|
||||
'ray_strict_endpoint_reject': (0x469dee, '752e'),
|
||||
'physics_capture_previous_grounded': (0x479d2e, 'ff9018020000'),
|
||||
'physics_clear_current_grounded': (0x479d4e, 'ff901c020000'),
|
||||
'physics_support_after_motion_call': (0x47a235, 'e856160000'),
|
||||
}
|
||||
for label, (va, expected) in sequences.items():
|
||||
offset = pe.offset(va - pe.base)
|
||||
actual = pe.data[offset:offset + len(expected) // 2].hex()
|
||||
if actual != expected:
|
||||
raise ValueError(f'{label} instruction mismatch at {va:#x}: {actual}')
|
||||
dll_sequences = {
|
||||
'quick_magnitude_ratio_scale': (0x10020027, 'd80d54481110'),
|
||||
'quick_magnitude_angle_lookup': (0x10020041, '668b1445381e1610'),
|
||||
'quick_magnitude_sine_lookup': (0x1002004f, 'd83495301e1410'),
|
||||
'sine_initializer_step': (0x100edc21, 'dc0dc0661110'),
|
||||
'angle_initializer_step': (0x100edc90, 'dc0d88451110'),
|
||||
}
|
||||
for label, (va, expected) in dll_sequences.items():
|
||||
offset = omt_pe.offset(va - omt_pe.base)
|
||||
actual = omt_pe.data[offset:offset + len(expected) // 2].hex()
|
||||
if actual != expected:
|
||||
raise ValueError(f'{label} instruction mismatch at {va:#x}: {actual}')
|
||||
threshold = struct.unpack_from('<f', pe.data, pe.offset(0x48d920 - pe.base))[0]
|
||||
assert threshold == f32(0.1)
|
||||
sine = [struct.pack('<f', math.sin(i * 0.0003834951969604492)) for i in range(16384)]
|
||||
for index, value in [(0, 0), (8192, 0), (4096, 1), (12288, -1)]:
|
||||
sine[index] = struct.pack('<f', value)
|
||||
angles = [struct.pack('<H', int(math.acos(i * 0.0001220703125 - 1) * 2607.5945876921437 * 0.5))
|
||||
for i in range(16384)]
|
||||
sine_hash, angle_hash = fingerprint(b''.join(sine)), fingerprint(b''.join(angles))
|
||||
# Actual original-DLL tables observed in copied-install mode2 probe2026-10-24.
|
||||
assert (sine_hash, angle_hash) == ('431383b5', '4f800433')
|
||||
slot_offsets = [0x100, 0x110, 0x208, 0x210, 0x250, 0x254, 0x260, 0x264,
|
||||
0x2e0, 0x2e8, 0x310, 0x318, 0x40c]
|
||||
interface_vtable = 0x4a373c
|
||||
slots = {hex(slot): hex(pe.u32(pe.offset(interface_vtable + slot - pe.base)))
|
||||
for slot in slot_offsets}
|
||||
game_acceptance = {}
|
||||
for cls in ['CJimmyGame', 'CLevel01BGame']:
|
||||
tables = rtti_map(pe, cls)['vtables']
|
||||
complete = next(t for t in tables if t['object_displacement'] == '0x0')
|
||||
game_acceptance[cls] = next(m['va'] for m in complete['methods'] if m['slot'] == '0x134')
|
||||
# Object conversion mode references are only collected, not executed.
|
||||
mode_va = 0x1013d6cc
|
||||
mode_refs = [hex(omt_pe.va(m.start())) for m in re.finditer(
|
||||
re.escape(struct.pack('<I', mode_va)), omt_pe.data)]
|
||||
source = (originals / 'ASE/jimstop.ase').read_text(encoding='latin-1')
|
||||
count = int(re.search(r'\*MESH_NUMVERTEX\s+(\d+)', source)[1])
|
||||
points = [(float(x), float(z), float(y)) for x, y, z in re.findall(
|
||||
r'\*MESH_VERTEX\s+\d+\s+([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)', source)[:count]]
|
||||
low = [min(p[i] for p in points) for i in range(3)]
|
||||
high = [max(p[i] for p in points) for i in range(3)]
|
||||
level = parse((originals / 'gam/level1b.gam').read_bytes())
|
||||
start = next(e.values() for e in level.entities if e.kind == '3JIM')
|
||||
x, z = start['PositionX'], start['PositionZ']
|
||||
scene = Database(originals / 'omt/level1b.omt')
|
||||
materials = {e.id: e.name for e in scene.entries if e.type == '3DMa'}
|
||||
triangles = unresolved = excluded = 0
|
||||
hits = []
|
||||
checkpoint_names = {'cstart', *(f'ccheck{i}' for i in range(1, 10))}
|
||||
for entry in scene.entries:
|
||||
if entry.type != '3DSh':
|
||||
continue
|
||||
shape = read_shape(scene.payload(entry))
|
||||
for index, polygon in enumerate(shape['polygons']):
|
||||
triangles += len(polygon['corners']) - 2
|
||||
material_id = polygon['material']['id'] if polygon['material'] else None
|
||||
unresolved += int(material_id not in materials) * (len(polygon['corners']) - 2)
|
||||
excluded += int(materials.get(material_id) in checkpoint_names) * (len(polygon['corners']) - 2)
|
||||
a, b, c = (shape['vertices'][p['vertex']] for p in polygon['corners'][:3])
|
||||
denominator = (b[2]-c[2])*(a[0]-c[0]) + (c[0]-b[0])*(a[2]-c[2])
|
||||
if abs(denominator) < 1e-8:
|
||||
continue
|
||||
u = ((b[2]-c[2])*(x-c[0]) + (c[0]-b[0])*(z-c[2])) / denominator
|
||||
v = ((c[2]-a[2])*(x-c[0]) + (a[0]-c[0])*(z-c[2])) / denominator
|
||||
if min(u, v, 1-u-v) < -1e-5:
|
||||
continue
|
||||
hits.append(dict(y=u*a[1]+v*b[1]+(1-u-v)*c[1], shape=entry.name,
|
||||
shape_id=entry.id, polygon=index, normal=polygon['normal'],
|
||||
material=material_id))
|
||||
factor = struct.unpack('<f', bytes.fromhex('85eba13f'))[0]
|
||||
clearance = f32(60 * factor)
|
||||
floor = max(h['y'] for h in hits if h['y'] <= start['PositionY'])
|
||||
result = dict(
|
||||
source_sha256=hashlib.sha256(pe.data).hexdigest(),
|
||||
verified_instruction_sequences=len(sequences) + len(dll_sequences),
|
||||
jimmy_interface_vtable=hex(interface_vtable), interface_slots=slots,
|
||||
scene_acceptance_slot134=game_acceptance,
|
||||
jimmy_postload=dict(radius=60, support_factor=factor,
|
||||
flat_floor_clearance=clearance,
|
||||
predicted_flat_root_y=floor+clearance,
|
||||
raw_sole_above_flat_floor=clearance+low[1]),
|
||||
goddard_postload=dict(radius=130, inherited_ai_support_factor=f32(0.3), flat_floor_clearance=f32(130 * f32(0.3))),
|
||||
support_ray_factor_threshold=threshold,
|
||||
regenerated_math_table_fingerprints=dict(sine=sine_hash, half_acos=angle_hash,
|
||||
reference='Recorded isolated copied-DLL execution2026-10-24; no original code executed by this script'),
|
||||
standing_ase=dict(vertex_count=count, min=low, max=high,
|
||||
geomobjects=len(re.findall(r'\*GEOMOBJECT\s*\{', source)),
|
||||
groups=len(re.findall(r'\*GROUP\s', source)),
|
||||
tm_animation='*TM_ANIMATION' in source),
|
||||
object_conversion_mode_address=hex(mode_va), object_mode_references=mode_refs,
|
||||
lab=dict(triangles=triangles, unresolved_material_triangles=unresolved,
|
||||
checkpoint_material_triangles=excluded,
|
||||
has_collision_counts=dict(collections.Counter(
|
||||
str(e.values()['HasCollision']) for e in level.entities if 'HasCollision' in e.values())),
|
||||
spawn_vertical_hits=sorted(hits, key=lambda h: h['y'])),
|
||||
limitation='Static arithmetic/data evidence; no original code executed; model pivot and full solver fidelity remain unverified.')
|
||||
print(json.dumps(result, indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,134 @@
|
||||
/* Original-DLL conversion probe. Run only against an isolated COPIED install.
|
||||
* API: collision_mode2_probe.exe [ASE\jimstop.ase] [object_mode=2] [animation_mode=2]
|
||||
* Reads source bytes, converts into in-memory OMT objects/database, prints bounded
|
||||
* geometry/frame-offset summaries. Never writes original asset files. */
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#define OMT_THISCALL __attribute__((thiscall))
|
||||
typedef void *(OMT_THISCALL *ctor0)(void *);
|
||||
typedef void *(OMT_THISCALL *dbctor)(void *, void *);
|
||||
typedef void (OMT_THISCALL *writefn)(void *, void *, unsigned);
|
||||
typedef void (OMT_THISCALL *seekfn)(void *, unsigned, short);
|
||||
typedef void *(OMT_THISCALL *converterctor)(void *, void *, void *);
|
||||
typedef void (OMT_THISCALL *convertfn)(void *);
|
||||
typedef void *(__cdecl *builderfn)(void);
|
||||
typedef void (__cdecl *registerfn)(unsigned, builderfn, long);
|
||||
typedef void *(OMT_THISCALL *getfn)(void *, unsigned, long);
|
||||
typedef float (OMT_THISCALL *magnitudefn)(const void *);
|
||||
static FARPROC required(HMODULE h, const char *name) {
|
||||
FARPROC p=GetProcAddress(h,name);
|
||||
if(!p){fprintf(stderr,"Missing export: %s\n",name);exit(2);} return p;
|
||||
}
|
||||
static void dump_vectors(const char *label, float *begin, float *end) {
|
||||
intptr_t bytes=(intptr_t)end-(intptr_t)begin;
|
||||
if(bytes==0){printf("%s VERTICES 0 (animation-only base may be empty)\n",label);return;}
|
||||
if(!begin || bytes<=0 || bytes%16 || bytes>16000000){
|
||||
fprintf(stderr,"Unexpected %s vectors: %p..%p (%ld bytes)\n",label,begin,end,(long)bytes);exit(3);
|
||||
}
|
||||
float lo[3]={FLT_MAX,FLT_MAX,FLT_MAX},hi[3]={-FLT_MAX,-FLT_MAX,-FLT_MAX};
|
||||
for(float *p=begin;p<end;p+=4)for(int i=0;i<3;i++){
|
||||
if(!isfinite(p[i])){fprintf(stderr,"Nonfinite %s coordinate\n",label);exit(3);}
|
||||
if(p[i]<lo[i])lo[i]=p[i];
|
||||
if(p[i]>hi[i])hi[i]=p[i];
|
||||
}
|
||||
printf("%s VERTICES %ld\n",label,(long)bytes/16);
|
||||
printf("%s MIN %.9g %.9g %.9g MAX %.9g %.9g %.9g\n",label,lo[0],lo[1],lo[2],hi[0],hi[1],hi[2]);
|
||||
for(int i=0;i<3 && begin+i*4<end;i++)printf("%s V%d %.9g %.9g %.9g\n",label,i,begin[i*4],begin[i*4+1],begin[i*4+2]);
|
||||
}
|
||||
static uint32_t fingerprint(const unsigned char *p, unsigned count) {
|
||||
uint32_t result=2166136261u;
|
||||
for(unsigned i=0;i<count;i++)result=(result^p[i])*16777619u;
|
||||
return result;
|
||||
}
|
||||
int main(int argc,char **argv) {
|
||||
setbuf(stdout,NULL);
|
||||
const char *input=argc>1?argv[1]:"ASE\\jimstop.ase";
|
||||
int object_mode=argc>2?atoi(argv[2]):2,animation_mode=argc>3?atoi(argv[3]):2;
|
||||
if(object_mode<0 || object_mode>2 || animation_mode<0 || animation_mode>3)return 2;
|
||||
FILE *f=fopen(input,"rb");if(!f){perror(input);return 2;}
|
||||
fseek(f,0,SEEK_END);long length=ftell(f);rewind(f);
|
||||
if(length<=0 || length>64000000){fclose(f);return 2;}
|
||||
char *data=malloc(length);if(!data || fread(data,1,length,f)!=(size_t)length){fclose(f);return 2;}fclose(f);
|
||||
HMODULE h=LoadLibraryA("Z:\\work\\game\\OMT2.dll");
|
||||
if(!h){fprintf(stderr,"LoadLibrary OMT error %lu\n",GetLastError());return 2;}
|
||||
printf("PROBE MODES object=%d animation=%d input=%s\n",object_mode,animation_mode,input);
|
||||
magnitudefn magnitude=(magnitudefn)required(h,"?quick_magnitude@OMedia3DVector@@QBEMXZ");
|
||||
float vectors[][4]={{0,0,0,0},{10,0,0,0},{3,4,0,0},{-4,0,-3,0},{1,1,1,0},
|
||||
{500,100,300,0},{.25f,.125f,.75f,0},{1.2345f,678.125f,-90.75f,0}};
|
||||
for(unsigned i=0;i<sizeof(vectors)/sizeof(vectors[0]);i++){
|
||||
union {float f;uint32_t u;} value;value.f=magnitude(vectors[i]);
|
||||
printf("QUICK_MAG %.9g %.9g %.9g = %.9g BITS %08lx\n",vectors[i][0],vectors[i][1],vectors[i][2],value.f,(unsigned long)value.u);
|
||||
}
|
||||
/* Preferred OMT2 VAs10141E30 and10161E38; module-relative offsets allow ASLR. */
|
||||
printf("SINE_TABLE_FNV32 %08lx HALF_ACOS_TABLE_FNV32 %08lx\n",
|
||||
(unsigned long)fingerprint((const unsigned char*)h+0x141e30,16384*4),
|
||||
(unsigned long)fingerprint((const unsigned char*)h+0x161e38,16384*2));
|
||||
registerfn register_object=(registerfn)required(h,"?register_object@OMediaDataBase@@SAXKP6APAVOMediaDBObject@@XZJ@Z");
|
||||
register_object(0x33445368,(builderfn)required(h,"?db_builder@OMedia3DShape@@SAPAVOMediaDBObject@@XZ"),0);
|
||||
register_object(0x4133646d,(builderfn)required(h,"?db_builder@OMedia3DMorphAnimDef@@SAPAVOMediaDBObject@@XZ"),0);
|
||||
register_object(0x33444d61,(builderfn)required(h,"?db_builder@OMedia3DMaterial@@SAPAVOMediaDBObject@@XZ"),0);
|
||||
register_object(0x43616e76,(builderfn)required(h,"?db_builder@OMediaCanvas@@SAPAVOMediaDBObject@@XZ"),0);
|
||||
unsigned char *stream=calloc(1,8192),*database_stream=calloc(1,8192),*database=calloc(1,8192),*converter=calloc(1,8192);
|
||||
ctor0 memctor=(ctor0)required(h,"??0OMediaMemStream@@QAE@XZ");
|
||||
memctor(stream);memctor(database_stream);
|
||||
((writefn)required(h,"?write@OMediaStream@@UAEXPAXK@Z"))(stream,data,length);
|
||||
((seekfn)required(h,"?setposition@OMediaStream@@UAEXKF@Z"))(stream,0,0);
|
||||
puts("DATABASE_BEGIN");
|
||||
((dbctor)required(h,"??0OMediaDataBase@@QAE@PAVOMediaStream@@@Z"))(database,database_stream);
|
||||
getfn get=(getfn)required(h,"?get_object@OMediaDataBase@@UAEPAVOMediaDBObject@@KJ@Z");
|
||||
unsigned char *shape=get(database,0x33445368,0);
|
||||
if(!shape){fputs("No database shape\n",stderr);return 3;}
|
||||
printf("DATABASE_SHAPE %p DATABASE_LINK %p\n",shape,*(void**)(shape+0x1c));
|
||||
if(*(void**)(shape+0x1c)!=database){fputs("Shape not attached to in-memory database\n",stderr);return 3;}
|
||||
*(int*)required(h,"?obj_conv_mode@OMedia3DShapeConverter@@1W4omt_3DObjectConvertMode@@A")=object_mode;
|
||||
*(int*)required(h,"?anim_conv_mode@OMedia3DShapeConverter@@1W4omt_3DAnimConvertMode@@A")=animation_mode;
|
||||
((converterctor)required(h,"??0OMediaASEConverter@@QAE@PAVOMediaStreamOperators@@PAVOMedia3DShape@@@Z"))(converter,stream,shape);
|
||||
puts("CONVERT_BEGIN");
|
||||
((convertfn)required(h,"?convert@OMediaASEConverter@@UAEXXZ"))(converter);
|
||||
puts("CONVERT_END");
|
||||
dump_vectors("SHAPE",*(float**)(shape+0x68),*(float**)(shape+0x6c));
|
||||
if(*(float**)(shape+0x68)!=*(float**)(shape+0x6c))
|
||||
printf("SHAPE CENTER %.9g %.9g %.9g RADIUS %.9g\n",*(float*)(shape+0x3c),*(float*)(shape+0x40),*(float*)(shape+0x44),*(float*)(shape+0x4c));
|
||||
unsigned char *related=(unsigned char*)required(h,"?related_morphdefs@OMedia3DShapeConverter@@2V?$vector@JV?$allocator@J@std@@@std@@A");
|
||||
long *ids=*(long**)(related+4),*ids_end=*(long**)(related+8);
|
||||
intptr_t id_bytes=(intptr_t)ids_end-(intptr_t)ids;
|
||||
if(id_bytes<0 || id_bytes%4 || id_bytes>4096){fputs("Invalid related morph IDs\n",stderr);return 3;}
|
||||
printf("MORPH_DEFINITIONS %ld\n",(long)id_bytes/4);
|
||||
for(long *id=ids;id<ids_end;id++){
|
||||
unsigned char *db_object=get(database,0x4133646d,*id);
|
||||
if(!db_object){fputs("Missing morph definition\n",stderr);return 3;}
|
||||
/* get_object returns the builder's complete pointer in this DLL. Some
|
||||
* paths expose its virtual-base table; accept only the proven layouts. */
|
||||
uintptr_t table=*(uintptr_t*)db_object;
|
||||
unsigned displacement=table==(uintptr_t)h+0x114304?0:table==(uintptr_t)h+0x1142f8?0x38:0xffffffffu;
|
||||
if(displacement==0xffffffffu){fprintf(stderr,"Unexpected morph vtable %p\n",(void*)table);return 3;}
|
||||
printf("DATABASE_OBJECT_DISPLACEMENT %u\n",displacement);
|
||||
unsigned char *definition=db_object-displacement;
|
||||
unsigned char **sequences=*(unsigned char***)(definition+0x28),**sequences_end=*(unsigned char***)(definition+0x2c);
|
||||
intptr_t sequence_bytes=(intptr_t)sequences_end-(intptr_t)sequences;
|
||||
if(sequence_bytes<0 || sequence_bytes%4 || sequence_bytes>16384){fputs("Invalid sequence table\n",stderr);return 3;}
|
||||
printf("MORPH_ID %ld SEQUENCES %ld\n",*id,(long)sequence_bytes/4);
|
||||
for(unsigned char **sequence=sequences;sequence<sequences_end;sequence++){
|
||||
unsigned char *sentinel=*(unsigned char**)(*sequence+4),*node=*(unsigned char**)sentinel;
|
||||
unsigned frame_count=*(unsigned*)(*sequence+8),frame_index=0;
|
||||
if(frame_count>4096){fputs("Invalid frame count\n",stderr);return 3;}
|
||||
printf("SEQUENCE_%ld FRAMES %u\n",(long)(sequence-sequences),frame_count);
|
||||
while(node!=sentinel && frame_index<frame_count){
|
||||
unsigned char *p=*(unsigned char**)(node+8);
|
||||
char label[64];snprintf(label,sizeof(label),"SEQUENCE_%ld_FRAME_%u",(long)(sequence-sequences),frame_index);
|
||||
printf("%s OFFSET %.9g %.9g %.9g\n",label,*(float*)(p+8),*(float*)(p+0xc),*(float*)(p+0x10));
|
||||
dump_vectors(label,*(float**)(p+0x2c),*(float**)(p+0x30));
|
||||
node=*(unsigned char**)node;frame_index++;
|
||||
}
|
||||
if(node!=sentinel || frame_index!=frame_count){fputs("Frame list count mismatch\n",stderr);return 3;}
|
||||
}
|
||||
}
|
||||
printf("POSTLOAD_STATIC radius=60 factor=%.9g clearance=%.9g\n",1.265f,60.0f*1.265f);
|
||||
puts("PROBE_COMPLETE");
|
||||
/* Process exit releases probe-only objects; no source/database is flushed. */
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only 3DUD/defaults/oriented-cube collision evidence; executes no originals."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
PROJECT = HERE.parent.parent
|
||||
sys.path.insert(0, str(HERE))
|
||||
sys.path.insert(0, str(PROJECT / 'tools/levels'))
|
||||
from pe_inspect import PE
|
||||
from rtti_map import rtti_map
|
||||
from gam import parse
|
||||
|
||||
|
||||
def main():
|
||||
original = PROJECT.parent / 'Original'
|
||||
pe = PE(original / 'Neutron.exe')
|
||||
checks = {
|
||||
'door_pair_collision_enable': (0x4175b0, '56e80a9b0500'),
|
||||
'door_mode2_push': (0x4175c6, '6a02'),
|
||||
'door_mode2_setter': (0x4175ca, 'e861a10500'),
|
||||
'door_integration_disable': (0x4175cf, '578bcde8599a0500'),
|
||||
'door_postload_radius40': (0x417cab, '6800002042'),
|
||||
'door_postload_radius_setter': (0x417cb2, 'ff9210010000'),
|
||||
'activation_has_collision_sentinel': (0x40e410, '83f8ff747c'),
|
||||
'activation_enable_pairs': (0x40e427, 'ff90ac030000'),
|
||||
'activation_disable_pairs': (0x40e44b, 'ff90a4030000'),
|
||||
'pair_dispatch_box_mode': (0x47a4cf, 'ff9078010000'),
|
||||
'pair_dispatch_box_first': (0x47a4dc, 'e8ff000000'),
|
||||
'pair_dispatch_box_second': (0x47a4f4, 'e8e7000000'),
|
||||
'box_query_other_geometry_gate': (0x47a5f5, 'ff90d0010000'),
|
||||
'box_query_other_mode': (0x47a707, 'ff9278010000'),
|
||||
'box_sphere_double_box_radius': (0x47a73f, 'd9842498000000dcc0d8842494000000'),
|
||||
'box_min_bound_getter': (0x47a776, 'ff90e4020000'),
|
||||
'box_max_bound_getter': (0x47a7a5, 'ff90dc020000'),
|
||||
'box_corner_transform': (0x47a7ec, 'ff9084030000'),
|
||||
'box_triangle_count12': (0x47ab67, 'c784240c0100000c000000'),
|
||||
'box_triangle_narrowphase': (0x47b277, 'e8040b0000'),
|
||||
'box_response_inhibition_gate': (0x47b2ef, 'ff90e0010000'),
|
||||
'box_response_world_clip': (0x47b364, 'e847010000'),
|
||||
'box_response_position_setter': (0x47b399, 'ff9014030000'),
|
||||
'shape_change_cube_query': (0x4622d4, 'ff5044'),
|
||||
'shape_change_min_bound_setter': (0x4622fb, 'ff90e8020000'),
|
||||
'shape_change_max_bound_setter': (0x462325, 'ff90e0020000'),
|
||||
}
|
||||
for label, (va, expected) in checks.items():
|
||||
offset = pe.offset(va - pe.base)
|
||||
actual = pe.data[offset:offset + len(expected) // 2].hex()
|
||||
if actual != expected:
|
||||
raise ValueError(f'{label} at{va:#x}: {actual} != {expected}')
|
||||
table = struct.unpack_from('<12I', pe.data, pe.offset(0x47b3ac - pe.base))
|
||||
assert table == (0x47ab82, 0x47abf3, 0x47ac64, 0x47acd5, 0x47ad46, 0x47adb7,
|
||||
0x47ae34, 0x47aeb1, 0x47af22, 0x47af93, 0x47aff8, 0x47b075)
|
||||
# These bounded switch cases copy three source corners into the triangle
|
||||
# scratch vectors. Decode their mov EAX/ECX/EDX,[ESP+disp] loads directly.
|
||||
locals_to_corners = {0xdc: 0, 0x70: 1, 0x40: 2, 0xac: 3,
|
||||
0x50: 4, 0x60: 5, 0xbc: 6, 0x9c: 7}
|
||||
triangles = []
|
||||
for start, end in zip(table, (*table[1:], 0x47b0ef)):
|
||||
code = pe.data[pe.offset(start - pe.base):pe.offset(end - pe.base)]
|
||||
offsets = [m[1][0] if m[1] else struct.unpack('<I', m[2])[0] for m in re.finditer(
|
||||
rb'\x8b[\x44\x4c\x54]\x24(.)|\x8b[\x84\x8c\x94]\x24(.{4})', code)]
|
||||
assert len(offsets) == 12
|
||||
triangles.extend(locals_to_corners[offsets[i]] for i in (0, 4, 8))
|
||||
assert triangles == [0,1,2,1,3,2,0,2,4,2,6,4,4,6,5,6,7,5,5,7,3,5,3,1,0,4,1,4,5,1,2,3,7,7,6,2]
|
||||
interface = next(t for t in rtti_map(pe, 'C3DDoorUpDown')['vtables']
|
||||
if t['object_displacement'] == '0xc0')
|
||||
assert interface['va'] == '0x4993ac'
|
||||
methods = {m['slot']: m['va'] for m in interface['methods']}
|
||||
for slot, target in {'0x178': '0x471720', '0x384': '0x472980', '0x40c': '0x417c50'}.items():
|
||||
assert methods[slot] == target
|
||||
level_path = original / 'gam/level1b.gam'
|
||||
level = parse(level_path.read_bytes())
|
||||
bars_entity = next(e for e in level.entities if e.kind == '3DUD' and e.values().get('ObjectTag') == 'bars')
|
||||
bars = bars_entity.values()
|
||||
assert bars['HasCollision'] == -1 and bars['CanMove'] == 1
|
||||
source = next(p for p in (original / 'ASE').iterdir() if p.name.casefold() == bars['ASEFile'].casefold())
|
||||
text = source.read_text(encoding='latin-1')
|
||||
count = int(re.search(r'\*MESH_NUMVERTEX\s+(\d+)', text)[1])
|
||||
points = [(float(x), float(z), float(y)) for x, y, z in re.findall(
|
||||
r'\*MESH_VERTEX\s+\d+\s+([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)', text)[:count]]
|
||||
assert count == len(points) == 42
|
||||
low = [min(v[i] for v in points) for i in range(3)]
|
||||
high = [max(v[i] for v in points) for i in range(3)]
|
||||
print(json.dumps(dict(
|
||||
executable_sha256=hashlib.sha256(pe.data).hexdigest(),
|
||||
verified_instruction_sequences=len(checks), verified_jump_table_entries=len(table),
|
||||
door_interface=interface['va'], mode=2, postload_radius=40,
|
||||
constructor_defaults=dict(entity_pair_collision=True, integrate_own_physics=False,
|
||||
has_collision_minus1='preserves both defaults'),
|
||||
normal_sphere_broadphase='quick_magnitude(otherRoot-boxRoot) <=2*boxRadius+otherRadius',
|
||||
second_mode2_broadphase='quick_magnitude(otherRoot-boxRoot) <=boxRadius+otherRadius; returns directly',
|
||||
bounds_origin='OMT shape find_cube ->EXE462270 ->iface2E8(min),2E0(max)',
|
||||
corners='bit4 selects maxX,bit2 maxY,bit1 maxZ; transform by current root/rotation viaiface384',
|
||||
triangle_corners=triangles,
|
||||
lab_bars=dict(gam_offset=hex(bars_entity.offset), gam_sha256=hashlib.sha256(level_path.read_bytes()).hexdigest(),
|
||||
ase_source=source.relative_to(original).as_posix(), ase_sha256=hashlib.sha256(source.read_bytes()).hexdigest(),
|
||||
source_vertices=count, local_min=low, local_max=high,
|
||||
position=[bars['Position'+a] for a in 'XYZ'], rotation=[bars['Rotation'+a] for a in 'XYZ'],
|
||||
has_collision=bars['HasCollision'], can_move=bars['CanMove'], open_amount=bars['OpenAmount']),
|
||||
limitation='Static geometry/dispatch/default evidence.47BD80 narrowphase and original runtime door blocking remain unverified.'
|
||||
), indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only checks for the original Level3B/E entity/archive loader paths.
|
||||
|
||||
No original code is executed. Run from GamePort with Python 3.
|
||||
This proves what the loader requests, not normal-gameplay reachability.
|
||||
"""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import struct
|
||||
import sys
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
PROJECT = HERE.parent.parent
|
||||
sys.path.insert(0, str(HERE))
|
||||
sys.path.insert(0, str(PROJECT / 'tools/levels'))
|
||||
from pe_inspect import PE
|
||||
from rtti_map import rtti_map
|
||||
from gam import parse
|
||||
|
||||
|
||||
def main():
|
||||
original = PROJECT.parent / 'Original'
|
||||
pe = PE(original / 'Neutron.exe')
|
||||
checks = {
|
||||
'b_ctor_level_code': (0x451ba8, '684233564c'),
|
||||
'b_archive_string_length': (0x451c99, 'bf241f4f00'),
|
||||
'b_archive_string_copy': (0x451cc5, 'be241f4f00'),
|
||||
'b_archive_loader_dispatch': (0x451ce8, 'ff92e4000000'),
|
||||
'e_ctor_level_code': (0x452748, '684533564c'),
|
||||
'e_archive_string_length': (0x452839, 'bffc1f4f00'),
|
||||
'e_archive_string_copy': (0x452865, 'befc1f4f00'),
|
||||
'e_archive_loader_dispatch': (0x452888, 'ff92e4000000'),
|
||||
'loader_omt_directory': (0x44e7ff, '681c1b4f00'),
|
||||
'loader_file_open': (0x44e8b4, 'e8b7780200'),
|
||||
'loader_database_open': (0x44e8ce, 'e82d770200'),
|
||||
'b_factory_ctor': (0x45d635, 'e8b644ffff'),
|
||||
'e_factory_ctor': (0x45d78b, 'e8004fffff'),
|
||||
}
|
||||
for name, (va, expected) in checks.items():
|
||||
off = pe.offset(va - pe.base)
|
||||
actual = pe.data[off:off + len(expected)//2].hex()
|
||||
if actual != expected:
|
||||
raise ValueError(f'{name} at {va:#x}: {actual} != {expected}')
|
||||
directory = pe.cstr(pe.offset(0x4f1b1c - pe.base))
|
||||
assert directory == 'omt'
|
||||
scenes = []
|
||||
for suffix, string_va in [('B', 0x4f1f24), ('E', 0x4f1ffc)]:
|
||||
level_path = original / 'gam' / f'Level3{suffix}.gam'
|
||||
level = parse(level_path.read_bytes())
|
||||
archive_name = pe.cstr(pe.offset(string_va - pe.base))
|
||||
table = next(v for v in rtti_map(pe, f'CLevel03{suffix}Game')['vtables']
|
||||
if v['object_displacement'] == '0x0')
|
||||
methods = {m['slot']: m['va'] for m in table['methods']}
|
||||
assert methods['0xe4'] == '0x44e7b0'
|
||||
matches = [p for p in (original / directory).iterdir()
|
||||
if p.name.casefold() == archive_name.casefold()]
|
||||
scenes.append(dict(
|
||||
gam=str(level_path.relative_to(original)),
|
||||
gam_sha256=hashlib.sha256(level_path.read_bytes()).hexdigest(),
|
||||
gam_bytes=level.size, gam_code=level.code,
|
||||
entity_count=len(level.entities),
|
||||
entity_kinds=[e.kind for e in level.entities],
|
||||
complete_vtable=table['va'], initialize_slot_b4=methods['0xb4'],
|
||||
archive_loader_slot_e4=methods['0xe4'],
|
||||
archive_string_va=hex(string_va), archive=archive_name,
|
||||
matching_files=[str(p.relative_to(original)) for p in matches]))
|
||||
print(json.dumps(dict(
|
||||
executable_sha256=hashlib.sha256(pe.data).hexdigest(),
|
||||
verified_instruction_sequences=len(checks), archive_directory=directory,
|
||||
scenes=scenes,
|
||||
same_gam_bytes_after_header=(
|
||||
(original/'gam/Level3B.gam').read_bytes()[4:] ==
|
||||
(original/'gam/Level3E.gam').read_bytes()[4:]),
|
||||
limitation='Static loader evidence only. Normal-gameplay reachability, unused/stub status and original runtime failure/success remain unverified.'), indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user