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()
|
||||
@@ -0,0 +1,196 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Prepare source-backed GAM entity references without assigning gameplay rules.
|
||||
|
||||
Keeps source order/offsets, duplicate tags and exact typed property values. Optional
|
||||
resource decoding exports only resources named by explicit database/index pairs.
|
||||
It does not turn editor icons into rendered actors or infer class asset defaults.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from collections import Counter, defaultdict
|
||||
from dataclasses import asdict
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
import wave
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'levels'))
|
||||
from gam import parse
|
||||
from omt import Database, FormatError, read_canvas, read_shape, safe_name, write_png
|
||||
|
||||
|
||||
SENTINELS = {'none', 'null', 'default', 'end', ''}
|
||||
OBJECT_LINKS = {
|
||||
'StartTrigger', 'NextTrigger', 'ToggleObject', 'ActivateObject', 'CameraTarget',
|
||||
'PlayerControlled', 'FaceObject', 'AITarget', 'AIPatrol', 'AINewPos', 'PatrolPoint',
|
||||
'NextPatrolPoint', 'CallObjectTag', 'ActivateBy', 'PickupLink', 'ActivateButton',
|
||||
}
|
||||
|
||||
|
||||
def resolve_asset(root: Path, relative: str) -> Path:
|
||||
"""Portable case-insensitive lookup, rejecting traversal and ambiguities."""
|
||||
root = root.resolve()
|
||||
current = root
|
||||
parts = relative.replace('\\', '/').split('/')
|
||||
if not relative or any(p in ('', '.', '..') for p in parts):
|
||||
raise FormatError(f'Invalid asset path: {relative!r}')
|
||||
for part in parts:
|
||||
matches = [p for p in current.iterdir() if p.name.casefold() == part.casefold()]
|
||||
if len(matches) != 1:
|
||||
raise FormatError(f'Missing or ambiguous asset: {relative}')
|
||||
current = matches[0]
|
||||
if not current.resolve().is_relative_to(root):
|
||||
raise FormatError(f'Asset escapes original root: {relative}')
|
||||
return current
|
||||
|
||||
|
||||
def _object_link(name: str) -> bool:
|
||||
return name in OBJECT_LINKS or bool(re.fullmatch(r'(CameraTarget|ActivateObject)\d+', name))
|
||||
|
||||
|
||||
def resource_pairs(values: dict):
|
||||
"""Explicit serialized pairings only; no implicit global sound bank assumption."""
|
||||
for prefix, resource_type in (('Sprite', 'Canv'), ('Music', 'Wave'), ('Omt', '3DSh')):
|
||||
database, index = values.get(prefix + 'Database'), values.get(prefix + 'Index')
|
||||
if isinstance(database, str) and isinstance(index, int) and index >= 0 and database.casefold() not in SENTINELS:
|
||||
yield prefix + 'Index', database, resource_type, index
|
||||
database = values.get('SpriteDatabase')
|
||||
if isinstance(database, str) and database.casefold() not in SENTINELS:
|
||||
for name, index in values.items():
|
||||
if re.fullmatch(r'Sprite[1-9]', name) and isinstance(index, int) and index >= 0:
|
||||
yield name, database, 'Canv', index
|
||||
database = values.get('SoundDatabase')
|
||||
if isinstance(database, str) and database.casefold() not in SENTINELS:
|
||||
for name, index in values.items():
|
||||
if re.fullmatch(r'SoundIndex\d*', name) and isinstance(index, int) and index >= 0:
|
||||
yield name, database, 'Wave', index
|
||||
|
||||
|
||||
def prepare_entities(original: Path, level_file: str, output: Path, decode: bool = False) -> dict:
|
||||
original = original.resolve()
|
||||
output = output.resolve()
|
||||
if output.is_relative_to(original) or original.is_relative_to(output):
|
||||
raise FormatError('Output must be separate from the original directory')
|
||||
source = resolve_asset(original, 'gam/' + level_file)
|
||||
data = source.read_bytes()
|
||||
level = parse(data)
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
tags = defaultdict(list)
|
||||
for ordinal, entity in enumerate(level.entities):
|
||||
tag = entity.values().get('ObjectTag', '')
|
||||
tags[str(tag).casefold()].append(ordinal)
|
||||
databases, resources = {}, {}
|
||||
entities = []
|
||||
for ordinal, entity in enumerate(level.entities):
|
||||
values = entity.values()
|
||||
record = {
|
||||
'ordinal': ordinal, 'kind': entity.kind, 'offset': entity.offset,
|
||||
'tag': values.get('ObjectTag'),
|
||||
'position': [values.get('Position' + axis, 0) for axis in 'XYZ'],
|
||||
'rotation': [values.get('Rotation' + axis, 0) for axis in 'XYZ'],
|
||||
'properties': values,
|
||||
'propertyEvidence': {p.name: {'offset': p.offset, 'type': p.type, 'length': p.length, 'raw': p.raw}
|
||||
for p in entity.properties},
|
||||
'objectReferences': [], 'resourceReferences': [], 'fileReferences': [],
|
||||
}
|
||||
for name, value in values.items():
|
||||
if _object_link(name) and isinstance(value, str) and value.casefold() not in SENTINELS:
|
||||
candidates = tags.get(value.casefold(), [])
|
||||
record['objectReferences'].append({'property': name, 'tag': value,
|
||||
'candidateOrdinals': candidates})
|
||||
if isinstance(value, str) and value.lower().endswith(('.ase', '.png')):
|
||||
folder = 'ASE' if value.lower().endswith('.ase') else 'png'
|
||||
try:
|
||||
path = resolve_asset(original, folder + '/' + value)
|
||||
record['fileReferences'].append({'property': name, 'source': path.relative_to(original).as_posix(),
|
||||
'sha256': hashlib.sha256(path.read_bytes()).hexdigest()})
|
||||
except FormatError as error:
|
||||
record['fileReferences'].append({'property': name, 'source': value, 'unresolved': str(error)})
|
||||
for property_name, database_name, resource_type, identity in resource_pairs(values):
|
||||
database_path = resolve_asset(original, 'omt/' + database_name)
|
||||
canonical = database_path.relative_to(original).as_posix()
|
||||
if canonical not in databases:
|
||||
databases[canonical] = Database(database_path)
|
||||
database = databases[canonical]
|
||||
key = (canonical, resource_type, identity)
|
||||
if key not in resources:
|
||||
matches = [e for e in database.entries if e.type == resource_type and e.id == identity]
|
||||
resource = {'database': canonical, 'type': resource_type, 'id': identity,
|
||||
'databaseSha256': hashlib.sha256(database.data).hexdigest()}
|
||||
if len(matches) != 1:
|
||||
resource['unresolved'] = 'No matching resource in explicitly named database'
|
||||
else:
|
||||
entry = matches[0]
|
||||
resource.update(name=entry.name, offset=entry.offset, size=entry.size)
|
||||
if decode:
|
||||
_decode(database, entry, resource, output)
|
||||
resources[key] = resource
|
||||
record['resourceReferences'].append({'property': property_name, 'database': canonical,
|
||||
'type': resource_type, 'id': identity})
|
||||
entities.append(record)
|
||||
report = {
|
||||
'schema': 1, 'source': source.relative_to(original).as_posix(),
|
||||
'sha256': hashlib.sha256(data).hexdigest(), 'level': level.code,
|
||||
'policy': 'Exact source entity data and explicit references only; gameplay/visibility rules are not inferred.',
|
||||
'counts': dict(sorted(Counter(e.kind for e in level.entities).items())),
|
||||
'duplicateTags': {tag: ids for tag, ids in sorted(tags.items()) if len(ids) > 1},
|
||||
'entities': entities, 'resources': [resources[key] for key in sorted(resources)],
|
||||
}
|
||||
(output / 'entities.json').write_text(json.dumps(report, indent=2, allow_nan=False) + '\n', encoding='utf8')
|
||||
return report
|
||||
|
||||
|
||||
def _decode(database, entry, resource: dict, output: Path):
|
||||
folder = output / 'resources' / safe_name(database.path.stem)
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
stem = f'{entry.type}_{entry.id:08x}_{safe_name(entry.name)}'
|
||||
payload = database.payload(entry)
|
||||
if entry.type == 'Canv':
|
||||
image = read_canvas(payload)
|
||||
rgba = image.pop('rgba')
|
||||
raw, png = folder / (stem + '.rgba'), folder / (stem + '.png')
|
||||
raw.write_bytes(rgba)
|
||||
write_png(png, image['width'], image['height'], rgba)
|
||||
resource.update(image, path=raw.relative_to(output).as_posix(), png=png.relative_to(output).as_posix())
|
||||
elif entry.type == '3DSh':
|
||||
path = folder / (stem + '.json')
|
||||
path.write_text(json.dumps(read_shape(payload), allow_nan=False) + '\n', encoding='utf8')
|
||||
resource['path'] = path.relative_to(output).as_posix()
|
||||
elif entry.type == 'Wave':
|
||||
start = payload.find(b'RIFF')
|
||||
if start < 0 or payload[start + 8:start + 12] != b'WAVE' or start + 12 > len(payload):
|
||||
raise FormatError(f'Wave resource is missing bounded RIFF: {entry.id}')
|
||||
size = struct.unpack_from('<I', payload, start + 4)[0] + 8
|
||||
if size < 12 or start + size > len(payload):
|
||||
raise FormatError(f'RIFF outside resource: {entry.id}')
|
||||
audio = payload[start:start + size]
|
||||
path = folder / (stem + '.wav')
|
||||
path.write_bytes(audio)
|
||||
resource['path'] = path.relative_to(output).as_posix()
|
||||
try:
|
||||
with wave.open(io.BytesIO(audio)) as wav:
|
||||
resource['audio'] = {'rate': wav.getframerate(), 'channels': wav.getnchannels(),
|
||||
'sampleWidth': wav.getsampwidth(), 'frames': wav.getnframes(),
|
||||
'seconds': wav.getnframes() / wav.getframerate()}
|
||||
except wave.Error:
|
||||
resource['audio'] = {'encoding': 'non-PCM RIFF retained unchanged'}
|
||||
|
||||
|
||||
def main():
|
||||
cli = argparse.ArgumentParser(description=__doc__)
|
||||
cli.add_argument('--original', type=Path, default=Path('../Original'))
|
||||
cli.add_argument('--level', default='level1b.gam')
|
||||
cli.add_argument('--output', type=Path, required=True)
|
||||
cli.add_argument('--decode', action='store_true')
|
||||
args = cli.parse_args()
|
||||
report = prepare_entities(args.original, args.level, args.output, args.decode)
|
||||
print(f"{report['level']}: {len(report['entities'])} source entities, {len(report['resources'])} explicit resource references")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,194 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Prepare only explicitly bound original static entity models and their materials."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from ase import expand_mesh, read_ase
|
||||
from entities import resolve_asset
|
||||
from gam import parse
|
||||
from omt import Database, FormatError, export_scene, read_material, read_shape
|
||||
from png import read_png
|
||||
|
||||
|
||||
def _digest(path: Path) -> str:
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def _bounds(points: list) -> dict:
|
||||
if not points:
|
||||
raise FormatError('Original model has no source points for local bounds')
|
||||
return {'min': [min(p[i] for p in points) for i in range(3)],
|
||||
'max': [max(p[i] for p in points) for i in range(3)]}
|
||||
|
||||
|
||||
def _one(database: Database, kind: str, identity: int):
|
||||
matches = [e for e in database.entries if e.type == kind and e.id == identity]
|
||||
if len(matches) != 1:
|
||||
raise FormatError(f'Missing or ambiguous {database.path.name}:{kind}:{identity}')
|
||||
return matches[0]
|
||||
|
||||
|
||||
def export_omt_model(database: Database, identity: int, output: Path) -> dict:
|
||||
"""Index only the selected mesh and transitively referenced material/canvas."""
|
||||
shape_entry = _one(database, '3DSh', identity)
|
||||
shape = read_shape(database.payload(shape_entry))
|
||||
keys = {('3DSh', identity)}
|
||||
missing_materials = set()
|
||||
for polygon in shape['polygons']:
|
||||
link = polygon['material']
|
||||
if link is None:
|
||||
continue # Null materials remain null, retaining invisible geometry.
|
||||
if link['type'] != '3DMa':
|
||||
raise FormatError(f'Unexpected shape material type {link["type"]}')
|
||||
matches = [e for e in database.entries if e.type == '3DMa' and e.id == link['id']]
|
||||
if not matches:
|
||||
# An unresolved original material stream link becomes a null pointer.
|
||||
# LV1B's invisible proxies name absent material18; preserve those
|
||||
# original polygons without inventing a visible replacement surface.
|
||||
missing_materials.add(link['id'])
|
||||
continue
|
||||
material_entry = _one(database, '3DMa', link['id'])
|
||||
keys.add(('3DMa', link['id']))
|
||||
texture = read_material(database.payload(material_entry))['texture']
|
||||
if texture is not None:
|
||||
if texture['type'] != 'Canv':
|
||||
raise FormatError(f'Unexpected material texture type {texture["type"]}')
|
||||
_one(database, 'Canv', texture['id'])
|
||||
keys.add(('Canv', texture['id']))
|
||||
selected = copy.copy(database)
|
||||
selected.entries = [e for e in database.entries if (e.type, e.id) in keys]
|
||||
scene = export_scene(selected, output)
|
||||
return {
|
||||
'kind': 'OMT', 'database': database.path.name, 'databaseSha256': _digest(database.path),
|
||||
'shapeId': identity, 'shapeName': shape_entry.name,
|
||||
'resources': [{'type': e.type, 'id': e.id, 'offset': e.offset, 'size': e.size, 'name': e.name}
|
||||
for e in selected.entries],
|
||||
'vertices': len(scene['vertices']), 'triangles': len(scene['indices']) // 3,
|
||||
'materials': len(scene['materials']), 'textures': len(scene['textures']),
|
||||
'nullMaterialIds': sorted(missing_materials),
|
||||
'localBounds': _bounds(shape['vertices']),
|
||||
}
|
||||
|
||||
|
||||
def export_ase_model(source: Path, texture_source: Path, output: Path) -> dict:
|
||||
"""Keep first authored sample of each node, with the explicit game PNG override."""
|
||||
animation = read_ase(source)
|
||||
scene = {'source': source.name, 'sha256': animation['sha256'],
|
||||
'vertices': [], 'uvs': [], 'normals': [], 'indices': [], 'meshes': [],
|
||||
'materials': [{'id': 0, 'texture': {'type': 'Canv', 'id': 0},
|
||||
'colours': {'diffuse': [1, 1, 1]}}], 'textures': []}
|
||||
for node in animation['objects']:
|
||||
sample = node['samples'][0]
|
||||
if not sample['textureFaces']:
|
||||
raise FormatError(f'Explicit static model lacks texture coordinates: {source.name}')
|
||||
mesh = expand_mesh(sample)
|
||||
first_vertex, first_index = len(scene['vertices']), len(scene['indices'])
|
||||
for field in ('vertices', 'uvs', 'normals'):
|
||||
scene[field].extend(mesh[field])
|
||||
scene['indices'].extend(i + first_vertex for i in mesh['indices'])
|
||||
scene['meshes'].append({'name': node['name'], 'shapeId': len(scene['meshes']),
|
||||
'firstIndex': first_index, 'indexCount': len(mesh['indices']), 'material': 0})
|
||||
texture = read_png(texture_source)
|
||||
rgba = texture.pop('rgba')
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
(output / 'texture.rgba').write_bytes(rgba)
|
||||
scene['textures'].append({'id': 0, 'path': 'texture.rgba', **texture})
|
||||
(output / 'scene.json').write_text(json.dumps(scene, separators=(',', ':'), allow_nan=False) + '\n', encoding='utf8')
|
||||
return {'kind': 'ASE', 'ase': source.name, 'aseSha256': animation['sha256'],
|
||||
'png': texture_source.name, 'pngSha256': _digest(texture_source),
|
||||
'mode': 'First original authored sample; no morph playback implied',
|
||||
'localBounds': _bounds([p for node in animation['objects'] for p in node['samples'][0]['vertices']]),
|
||||
'vertices': len(scene['vertices']), 'triangles': len(scene['indices']) // 3,
|
||||
'materials': 1, 'textures': 1}
|
||||
|
||||
|
||||
def prepare_models(original: Path, level_file: str, output: Path) -> dict:
|
||||
original, output = original.resolve(), output.resolve()
|
||||
if output.is_relative_to(original) or original.is_relative_to(output):
|
||||
raise FormatError('Output must be separate from the original installation')
|
||||
source = resolve_asset(original, 'gam/' + level_file)
|
||||
level = parse(source.read_bytes())
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
models, actors, unresolved, cache, databases = [], [], [], {}, {}
|
||||
|
||||
def omt_model(name: str, identity: int) -> str:
|
||||
archive = resolve_asset(original, 'omt/' + name)
|
||||
key = ('OMT', str(archive), identity)
|
||||
if key not in cache:
|
||||
if archive not in databases:
|
||||
databases[archive] = Database(archive)
|
||||
database = databases[archive]
|
||||
model_key = f'model_{len(models):04d}'
|
||||
details = export_omt_model(database, identity, output / model_key)
|
||||
models.append({'key': model_key, 'path': model_key + '/scene.json', 'source': details})
|
||||
cache[key] = model_key
|
||||
return cache[key]
|
||||
|
||||
def ase_model(ase_name: str, png_name: str) -> str:
|
||||
ase = resolve_asset(original, 'ASE/' + ase_name)
|
||||
png = resolve_asset(original, 'png/' + png_name)
|
||||
key = ('ASE', str(ase), str(png))
|
||||
if key not in cache:
|
||||
model_key = f'model_{len(models):04d}'
|
||||
details = export_ase_model(ase, png, output / model_key)
|
||||
models.append({'key': model_key, 'path': model_key + '/scene.json', 'source': details})
|
||||
cache[key] = model_key
|
||||
return cache[key]
|
||||
|
||||
for ordinal, entity in enumerate(level.entities):
|
||||
values, variants, evidence = entity.values(), {}, ''
|
||||
if entity.kind == '3OMT':
|
||||
database, identity = values.get('OmtDatabase'), values.get('OmtIndex')
|
||||
if not isinstance(database, str) or not isinstance(identity, int) or identity < 0:
|
||||
raise FormatError(f'3OMT has no explicit model at 0x{entity.offset:x}')
|
||||
variants['STATIC'] = omt_model(database, identity)
|
||||
evidence = 'Explicit GAM OmtDatabase/OmtIndex'
|
||||
elif entity.kind == '3PHO':
|
||||
# Verified original class binding, not the unrelated phone.ASE prop.
|
||||
variants['STATIC'] = omt_model('phone.omt', 0)
|
||||
evidence = 'EXE43579D opens phone.omt;4357C9 selects3DSh0'
|
||||
elif entity.kind == '3BUT':
|
||||
names = [values.get(key) for key in ('Up.ase', 'Down.ase', 'UpDown.Png')]
|
||||
if not all(isinstance(name, str) and name.casefold() not in ('none', '') for name in names):
|
||||
unresolved.append({'ordinal': ordinal, 'offset': entity.offset, 'kind': entity.kind,
|
||||
'tag': values.get('ObjectTag'), 'reason': 'Button lacks a complete explicit ASE/PNG mapping; constructor fallback not inferred'})
|
||||
continue
|
||||
variants['UP'] = ase_model(names[0], names[2])
|
||||
variants['DOWN'] = ase_model(names[1], names[2])
|
||||
evidence = 'Explicit GAM Up.ase/Down.ase/UpDown.Png; EXE411B93 initialUP'
|
||||
elif isinstance(values.get('ASEFile'), str) and isinstance(values.get('PNGFile'), str):
|
||||
if any(values[name].casefold() in ('none', '') for name in ('ASEFile', 'PNGFile')):
|
||||
unresolved.append({'ordinal': ordinal, 'offset': entity.offset, 'kind': entity.kind,
|
||||
'tag': values.get('ObjectTag'), 'reason': 'Incomplete explicit ASEFile/PNGFile mapping; no default inferred'})
|
||||
continue
|
||||
variants['STATIC'] = ase_model(values['ASEFile'], values['PNGFile'])
|
||||
evidence = 'Explicit GAM ASEFile/PNGFile (no class default inferred)'
|
||||
if variants:
|
||||
actors.append({'ordinal': ordinal, 'offset': entity.offset,
|
||||
'tag': values.get('ObjectTag'), 'kind': entity.kind,
|
||||
'defaultVariant': 'UP' if entity.kind == '3BUT' else 'STATIC',
|
||||
'variants': variants, 'evidence': evidence})
|
||||
report = {'schema': 1, 'source': source.relative_to(original).as_posix(),
|
||||
'sha256': _digest(source), 'level': level.code, 'models': models, 'actors': actors, 'unresolved': unresolved,
|
||||
'policy': 'Original local coordinates and source actor transforms; static samples only; no floor correction.'}
|
||||
(output / 'models.json').write_text(json.dumps(report, indent=2, allow_nan=False) + '\n', encoding='utf8')
|
||||
return report
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--original', type=Path, default=Path('../Original'))
|
||||
parser.add_argument('--level', default='level1b.gam')
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
report = prepare_models(args.original, args.level, args.output)
|
||||
print(f"{report['level']}: {len(report['actors'])} authored model instances; {len(report['models'])} unique models")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -265,12 +265,13 @@ def export_scene(database: Database, output: Path):
|
||||
scene = {'source': database.path.name, 'sha256': hashlib.sha256(database.data).hexdigest(),
|
||||
'coordinates': 'Original OMT world coordinates, unchanged',
|
||||
'vertices': [], 'uvs': [], 'normals': [], 'indices': [], 'meshes': [],
|
||||
'materials': [], 'textures': [], 'warnings': []}
|
||||
'materials': [], 'textures': [], 'warnings': [], 'collisionPolygons': []}
|
||||
material_names = {entry.id: entry.name for entry in database.entries if entry.type == '3DMa'}
|
||||
for entry in database.entries:
|
||||
payload = database.payload(entry)
|
||||
if entry.type == '3DSh':
|
||||
shape = read_shape(payload)
|
||||
for poly in shape['polygons']:
|
||||
for polygon_index, poly in enumerate(shape['polygons']):
|
||||
first_index = len(scene['indices'])
|
||||
first_vertex = len(scene['vertices'])
|
||||
for corner in poly['corners']:
|
||||
@@ -280,6 +281,8 @@ def export_scene(database: Database, output: Path):
|
||||
scene['normals'].append(shape['normals'][ni] if ni < len(shape['normals']) else poly['normal'])
|
||||
for i in range(1, len(poly['corners'])-1):
|
||||
scene['indices'].extend((first_vertex, first_vertex+i, first_vertex+i+1))
|
||||
scene['collisionPolygons'].append({'shapeId': entry.id, 'polygonIndex': polygon_index,
|
||||
'normal': poly['normal'], 'materialName': material_names.get(poly['material']['id']) if poly['material'] else None})
|
||||
if len(poly['corners']) > 3:
|
||||
scene['warnings'].append(f'{entry.id}: polygon with {len(poly["corners"])} corners fan triangulated; concavity not validated')
|
||||
material = poly['material']['id'] if poly['material'] else -1
|
||||
|
||||
@@ -7,6 +7,10 @@ from pathlib import Path
|
||||
from omt import Database, export_scene, extract
|
||||
from ase import export_ase
|
||||
from png import read_png
|
||||
from entities import prepare_entities
|
||||
from models import prepare_models
|
||||
from ui import export_ui
|
||||
from sound_bank import export_sound_bank
|
||||
|
||||
|
||||
def find_archive(original: Path, name: str) -> Path:
|
||||
@@ -17,20 +21,65 @@ def find_archive(original: Path, name: str) -> Path:
|
||||
return matches[0]
|
||||
|
||||
|
||||
def prepare_actor(original: Path, output: Path, name: str, texture_name: str, actions: dict, base_name: str | None = None,
|
||||
ignored_animations: tuple[str, ...] = ()):
|
||||
"""Explicit EXE registration mappings; no texture guessed from ASE adjacency."""
|
||||
target = output / 'actors' / name
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
texture_source = next(p for p in (original/'png').iterdir() if p.name.casefold() == texture_name.casefold())
|
||||
texture = read_png(texture_source)
|
||||
(target/'texture.rgba').write_bytes(texture.pop('rgba'))
|
||||
base_name = base_name or next(iter(actions.values()))
|
||||
base = next(p for p in (original/'ASE').iterdir() if p.stem.casefold() == base_name.casefold())
|
||||
for stem in dict.fromkeys(actions.values()):
|
||||
source = next(p for p in (original/'ASE').iterdir() if p.stem.casefold() == stem.casefold())
|
||||
manifest = export_ase(source, target/stem, base)
|
||||
manifest['texture'] = {'path': '../texture.rgba', **texture}
|
||||
(target/stem/'animation.json').write_text(json.dumps(manifest, indent=2)+'\n')
|
||||
(target/'family.json').write_text(json.dumps({'default': next(iter(actions)),
|
||||
'actions': {key: value+'/animation.json' for key, value in actions.items()},
|
||||
'ignoredAnimations': list(ignored_animations)}, indent=2)+'\n')
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--original', type=Path, default=Path('../Original'))
|
||||
parser.add_argument('--output', type=Path, default=Path('artifacts/extracted'))
|
||||
parser.add_argument('--scenes', nargs='+', default=['level1b', 'VR01'])
|
||||
parser.add_argument('--all-scenes', action='store_true', help='Prepare every supplied GAM/OMT scene pair')
|
||||
parser.add_argument('--audio', nargs='*', default=['sounds', 'musicjimmyshouse', 'musicneighborhood'])
|
||||
parser.add_argument('--animations', nargs='*', default=['jimstop', 'jimrun', 'jimjump', 'jimscratch', 'jimbackpedal', 'jimfall'])
|
||||
parser.add_argument('--animations', nargs='*', default=['jimstop', 'jimrun', 'jimjump', 'jimscratch', 'jimbackpedal', 'jimfall', 'jimtalk', 'jimfly'])
|
||||
args = parser.parse_args()
|
||||
if args.output.resolve().is_relative_to(args.original.resolve()):
|
||||
parser.error('Output must be outside the original installation')
|
||||
if args.all_scenes:
|
||||
args.scenes = sorted((p.stem for p in (args.original/'gam').iterdir() if p.suffix.casefold()=='.gam'), key=str.casefold)
|
||||
catalog = {'prepared': [], 'unavailable': []}
|
||||
for name in args.scenes:
|
||||
source = find_archive(args.original, name)
|
||||
try:
|
||||
source = find_archive(args.original, name)
|
||||
except ValueError:
|
||||
if not args.all_scenes:
|
||||
raise
|
||||
# GAM entities and OMT geometry are distinct. The executable registers
|
||||
# level3b/3e, but their use in normal progression is not established.
|
||||
# Report the absent geometry without calling it required game content.
|
||||
catalog['unavailable'].append({'level': name+'.gam', 'archive': name+'.omt',
|
||||
'reason': 'GAM supplied; matching geometry archive absent; gameplay use unverified'})
|
||||
print(f'{name}.gam is supplied; no matching {name}.omt geometry archive '
|
||||
'(gameplay use unverified; no substitution)')
|
||||
continue
|
||||
scene = export_scene(Database(source), args.output / source.stem)
|
||||
print(f"{source.name}: {len(scene['indices'])//3} triangles, {len(scene['textures'])} textures")
|
||||
report = prepare_entities(args.original, source.stem + '.gam', args.output / source.stem / 'entities', True)
|
||||
print(f"{report['level']}: {len(report['resources'])} explicit entity resources")
|
||||
models = prepare_models(args.original, source.stem + '.gam', args.output / source.stem / 'models')
|
||||
print(f"{models['level']}: {len(models['actors'])} model actors; {len(models['unresolved'])} unresolved bindings")
|
||||
catalog['prepared'].append({'level': name+'.gam', 'archive': source.name, 'scene': source.stem+'/scene.json'})
|
||||
(args.output/'scene-catalog.json').write_text(json.dumps(catalog, indent=2)+'\n')
|
||||
export_ui(Database(find_archive(args.original, 'screens')), args.output / 'ui', Database(args.original / 'alpha.omt'))
|
||||
effects = export_sound_bank(args.original, args.output / 'effects')
|
||||
print(f"SoundEffects.omt: {len(effects['resources'])} original sound identities")
|
||||
for name in args.audio:
|
||||
source = find_archive(args.original, name)
|
||||
report = extract(Database(source), args.output / source.stem)
|
||||
@@ -50,6 +99,16 @@ def main():
|
||||
manifest['texture'] = {'path':'../jimycarl.rgba', **texture}
|
||||
(target/name/'animation.json').write_text(json.dumps(manifest,indent=2)+'\n',encoding='utf-8')
|
||||
print(f"{matches[0].name}: {len(manifest['frames'])} animation samples")
|
||||
# EXE413D8C..413DF9 (Carl);41CDA0..41CE5F (Goddard high-detail clips).
|
||||
prepare_actor(args.original, args.output, 'carl', 'carl.png', {
|
||||
'STOP': 'carlstop', 'WALK': 'carlwalk', 'TALK': 'carltalk', 'INHALE': 'carlinhale',
|
||||
'CHEER': 'carlcheer', 'TELE': 'carlteleport'})
|
||||
prepare_actor(args.original, args.output, 'goddard', 'goddard02.png', {
|
||||
'SIT': 'godsit', 'RUN': 'godrun', 'GROWL': 'godgrowl', 'WAG': 'godwag',
|
||||
'EAT': 'godeat', 'FLY': 'godfly', 'POINT': 'godpoint'}, 'godpoint', ('STOP', 'WALK', 'TALK'))
|
||||
prepare_actor(args.original, args.output, 'trophy', 'trophy.png', {'STOP': 'trophy'})
|
||||
# C3DJetpackFire421F30..96: DEFAULT fire.ase, HINONE fire2.ase, fire.png.
|
||||
prepare_actor(args.original, args.output, 'jetpack', 'fire.png', {'DEFAULT': 'fire', 'NONE': 'fire2'}, 'fire')
|
||||
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
@@ -0,0 +1,58 @@
|
||||
"""Prepare the original default SoundEffects.omt bank (EXE423642..656).
|
||||
|
||||
Numeric effect IDs are archive identities, not offsets into the four-entry
|
||||
sounds.omt archive. Preserve the original PCM/RIFF bytes and explicit metadata.
|
||||
"""
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
|
||||
from entities import _decode, resolve_asset
|
||||
from omt import Database, FormatError
|
||||
|
||||
|
||||
def export_sound_bank(original: Path, output: Path) -> dict:
|
||||
original, output = original.resolve(), output.resolve()
|
||||
if output.is_relative_to(original) or original.is_relative_to(output):
|
||||
raise FormatError('Sound output must be separate from original files')
|
||||
source = resolve_asset(original, 'omt/SoundEffects.omt')
|
||||
database = Database(source)
|
||||
source_hash = hashlib.sha256(database.data).hexdigest()
|
||||
resources = []
|
||||
for entry in database.entries:
|
||||
if entry.type != 'Wave':
|
||||
continue
|
||||
resource = {'database': source.relative_to(original).as_posix(), 'type': 'Wave',
|
||||
'id': entry.id, 'name': entry.name, 'offset': entry.offset,
|
||||
'size': entry.size, 'databaseSha256': source_hash}
|
||||
_decode(database, entry, resource, output)
|
||||
if 'seconds' not in resource['audio']:
|
||||
# Some original resources contain MPEG Layer3 in RIFF. Preserve the
|
||||
# encoded bytes; duration comes from the explicit fact sample count.
|
||||
raw = (output/resource['path']).read_bytes()
|
||||
position, rate, frames, encoding = 12, None, None, None
|
||||
while position + 8 <= len(raw):
|
||||
tag = raw[position:position+4]
|
||||
size = struct.unpack_from('<I', raw, position+4)[0]
|
||||
begin, end = position+8, position+8+size
|
||||
if end > len(raw):
|
||||
raise FormatError('Sound RIFF chunk escapes resource')
|
||||
if tag == b'fmt ' and size >= 16:
|
||||
encoding, channels, rate = struct.unpack_from('<HHI', raw, begin)
|
||||
elif tag == b'fact' and size >= 4:
|
||||
frames = struct.unpack_from('<I', raw, begin)[0]
|
||||
position = end+(size & 1)
|
||||
if not rate or frames is None:
|
||||
raise FormatError(f'No explicit sound duration for encoding: {entry.id}')
|
||||
resource['audio'] = {'formatTag': encoding, 'channels': channels, 'rate': rate,
|
||||
'frames': frames, 'seconds': frames/rate,
|
||||
'encoding': 'encoded RIFF preserved; decoder support is separate'}
|
||||
resource['sha256'] = hashlib.sha256((output/resource['path']).read_bytes()).hexdigest()
|
||||
resources.append(resource)
|
||||
if not resources or len({r['id'] for r in resources}) != len(resources):
|
||||
raise FormatError('Missing or duplicate original sound identities')
|
||||
report = {'schema': 1, 'evidence': 'Neutron.exe423642..423656; default current sound database',
|
||||
'resources': resources}
|
||||
(output/'effects.json').write_text(json.dumps(report, indent=2)+'\n', encoding='utf8')
|
||||
return report
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Export proven laboratory HUD/PracticeYesNo Canv resources, without changing originals."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from omt import Database, FormatError, read_canvas, validate_output, write_png
|
||||
|
||||
|
||||
# Neutron.exe 402687..4026E8 registers pad and laboratory objective IDs;
|
||||
# 40224F registers PracticeYesNo. These are original identities, not guessed art.
|
||||
CANVASES = {120: (256, 29), 121: (256, 29), 122: (256, 29),
|
||||
156: (320, 173), 169: (207, 100)}
|
||||
ALPHA_CANVASES = {83: (8, 8), 84: (8, 8), 85: (8, 8)}
|
||||
|
||||
|
||||
def export_ui(database: Database, output: Path, alpha: Database | None = None) -> dict:
|
||||
validate_output(database, output)
|
||||
if alpha is None:
|
||||
# The original font database is beside omt/, not within screens.omt.
|
||||
alpha = Database(database.path.parent.parent / 'alpha.omt')
|
||||
validate_output(alpha, output)
|
||||
recovered = []
|
||||
for source, identities in ((database, CANVASES), (alpha, ALPHA_CANVASES)):
|
||||
for identity, expected in identities.items():
|
||||
entry = next((e for e in source.entries if e.type == 'Canv' and e.id == identity), None)
|
||||
if entry is None:
|
||||
raise FormatError(f'Missing original UI canvas {source.path.name}:{identity}')
|
||||
canvas = read_canvas(source.payload(entry))
|
||||
if (canvas['width'], canvas['height']) != expected:
|
||||
raise FormatError(f'Unexpected original UI canvas dimensions {identity}')
|
||||
recovered.append((source, entry, canvas))
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
textures = []
|
||||
for source, entry, canvas in recovered:
|
||||
name = f'canvas_{entry.id}'
|
||||
rgba = canvas['rgba']
|
||||
(output / (name + '.rgba')).write_bytes(rgba)
|
||||
write_png(output / (name + '.png'), canvas['width'], canvas['height'], rgba)
|
||||
textures.append({'id': entry.id, 'name': entry.name, 'width': canvas['width'],
|
||||
'height': canvas['height'], 'path': name + '.rgba',
|
||||
'source': source.path.name, 'sourceOffset': entry.offset, 'sourceBytes': entry.size,
|
||||
'rgbaSha256': hashlib.sha256(rgba).hexdigest()})
|
||||
manifest = {'version': 1, 'source': database.path.name,
|
||||
'sourceSha256': hashlib.sha256(database.data).hexdigest(),
|
||||
'alphaSha256': hashlib.sha256(alpha.data).hexdigest(),
|
||||
'referenceWidth': 640, 'referenceHeight': 480, 'textures': textures}
|
||||
(output / 'ui.json').write_text(json.dumps(manifest, indent=2) + '\n', encoding='utf-8')
|
||||
return manifest
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('database', type=Path)
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
parser.add_argument('--alpha', type=Path, help='Original alpha.omt (default: beside the omt directory)')
|
||||
args = parser.parse_args()
|
||||
result = export_ui(Database(args.database), args.output, Database(args.alpha) if args.alpha else None)
|
||||
print(f"{len(result['textures'])} original UI canvases exported to {args.output}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -53,11 +53,11 @@ def inside(args):
|
||||
application = ['/opt/wine-stable/bin/wine', r'Z:\port\GamePort.exe',
|
||||
'--assets', r'Z:\port\assets', '--scene', r'Z:\port\scenes\level1b\scene.json',
|
||||
'--level', 'gam/level1b.gam', '--original-camera', '--with-player',
|
||||
'--frames', '240' if args.port_walk else '6' if args.port_window else '2', '--no-validation',
|
||||
'--frames', '240' if args.port_walk else '12' if args.port_practice else '6' if args.port_window else '2', '--no-validation',
|
||||
'--screenshot', r'Z:\work\port-frame.ppm']
|
||||
application += ['--smoke-walk'] if args.port_walk else ['--inspect', '--time', '0.05']
|
||||
application += ['--smoke-window'] if args.port_window and not args.port_walk else []
|
||||
application += [] if args.port_window or args.port_walk else ['--headless']
|
||||
application += ['--smoke-walk'] if args.port_walk else ['--smoke-practice-window'] if args.port_practice else ['--story', '--story-time', '12'] if args.port_story else ['--inspect', '--time', '0.05']
|
||||
application += ['--smoke-window'] if args.port_window and not (args.port_walk or args.port_practice) else []
|
||||
application += [] if args.port_window or args.port_walk or args.port_practice else ['--headless']
|
||||
if args.asset_probe:
|
||||
application = ['/opt/wine-stable/bin/wine', r'Z:\probe.exe', args.probe_model]
|
||||
wine = subprocess.Popen(application, cwd='/work' if args.port_smoke else '/work/game', stdout=wlog, stderr=wlog, env=wine_env)
|
||||
@@ -97,12 +97,18 @@ def main():
|
||||
p.add_argument('--port-smoke', action='store_true', help='Preliminary Windows port check under Wine64; not native Windows validation')
|
||||
p.add_argument('--port-window', action='store_true', help='Windows port SDL window/input/resize/animation smoke under Wine64')
|
||||
p.add_argument('--port-walk', action='store_true', help='Windows port walking/jump/keyboard/resize checkpoint under Wine64')
|
||||
p.add_argument('--port-story', action='store_true', help='Windows port original-resource story/camera render under Wine64')
|
||||
p.add_argument('--port-practice', action='store_true', help='Windows port practice modal/input/resize under Wine64')
|
||||
p.add_argument('--asset-probe', action='store_true', help='Run compiled read-only OMT shape probe inside isolated copy')
|
||||
p.add_argument('--probe-model', default=r'ASE\jimstop.ase')
|
||||
p.add_argument('--probe-executable', type=Path, help='Local probe executable to mount read-only for --asset-probe')
|
||||
p.add_argument('--output', type=Path)
|
||||
args = p.parse_args()
|
||||
args.port_smoke = args.port_smoke or args.port_window or args.port_walk
|
||||
args.port_smoke = args.port_smoke or args.port_window or args.port_walk or args.port_story or args.port_practice
|
||||
if args.port_smoke and args.asset_probe: p.error('Select either port smoke or asset probe')
|
||||
if args.port_story and (args.port_window or args.port_walk or args.port_practice): p.error('Story comparison uses headless fixed time; select one port check')
|
||||
if args.port_practice and (args.port_walk or args.port_window): p.error('Select one windowed port check')
|
||||
if args.probe_executable and not args.asset_probe: p.error('--probe-executable requires --asset-probe')
|
||||
if not 3 <= args.seconds <= 120: p.error('--seconds must be 3..120')
|
||||
if args.inside: return inside(args)
|
||||
project = Path(__file__).resolve().parents[2]
|
||||
@@ -128,7 +134,9 @@ def main():
|
||||
if args.port_smoke:
|
||||
cmd += ['--ro-bind', str(project/'dist/win-x64'), '/port']
|
||||
if args.asset_probe:
|
||||
cmd += ['--ro-bind', str(project/'artifacts/binary/omt_shape_probe.exe'), '/probe.exe']
|
||||
probe = (args.probe_executable or project/'artifacts/binary/omt_shape_probe.exe').resolve(strict=True)
|
||||
if probe.is_relative_to(source.resolve()): p.error('Probe must be a generated executable outside originals')
|
||||
cmd += ['--ro-bind', str(probe), '/probe.exe']
|
||||
for key,value in {'HOME':'/work/home', 'WINEPREFIX':'/work/prefix', 'WINEARCH':'win64' if args.port_smoke else 'win32',
|
||||
'DISPLAY':':89', 'PATH':'/opt/wine-stable/bin:/usr/bin:/bin', 'LANG':'C.UTF-8',
|
||||
'WINEDEBUG':'-all,err+all,warn+ddraw,warn+d3d,+seh' if args.debug else '-all',
|
||||
@@ -148,6 +156,8 @@ def main():
|
||||
if args.port_smoke: cmd += ['--port-smoke']
|
||||
if args.port_window: cmd += ['--port-window']
|
||||
if args.port_walk: cmd += ['--port-walk']
|
||||
if args.port_story: cmd += ['--port-story']
|
||||
if args.port_practice: cmd += ['--port-practice']
|
||||
if args.asset_probe: cmd += ['--asset-probe', '--probe-model', args.probe_model]
|
||||
print('Running isolated Windows port' if args.port_smoke else 'Running copied original', 'with no network and no original-directory mount:', work, flush=True)
|
||||
subprocess.run(cmd, check=True, timeout=args.seconds + 40)
|
||||
|
||||
Reference in new issue
Block a user