paavohtl Claude Opus 4.6 (1M context) commited on
Commit
37cd0fa
·
1 Parent(s): 130a6de

fix: correct EAX register values in FireWeapon type-4 dispatch

Browse files

Audit of all 24 type-4 special weapon cases against original disasm
revealed three distinct EAX patterns:
- EAX=worm (explicit MOV EAX,ESI): AirStrike, Mail/Mine, Freeze, Surrender
- EAX=entry (unchanged from switch): Drill, Prod, Napalm, SkipGo,
SelectWorm, JetPack, LowGrav
- EAX=*(worm+0x44) (state field): Teleport check

Previously all cases passed EAX=worm, which was wrong for entry-based
and state-based handlers. Fixed by passing entry pointer or worm state
as appropriate per case.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

crates/openwa-wormkit/src/replacements/weapon.rs CHANGED
@@ -232,7 +232,7 @@ unsafe extern "cdecl" fn fire_weapon_impl(
232
  }
233
  4 => {
234
  let subtype_38_ptr = &raw const (*entry).fire_subtype_38 as u32;
235
- fire_weapon_special(subtype_34, subtype_38_ptr, w, local_struct);
236
  }
237
  _ => {}
238
  }
@@ -343,41 +343,49 @@ unsafe extern "C" fn call_fire_stdcall2(
343
  }
344
 
345
  /// Type 4 (special) weapon dispatch.
346
- /// Type 4 (special) weapon dispatch. All sub-functions use EAX=ESI=EDI=worm.
347
- unsafe fn fire_weapon_special(subtype: i32, params_38: u32, worm: u32, local_struct: u32) {
 
 
 
 
 
 
 
348
  use openwa_core::rebase::rb;
 
349
 
350
- // All handlers use EAX=worm (self-pointer at CTaskWorm+0x36C).
351
  match subtype {
352
- 1 => fire_worm_vtable_0xe(worm, 0x6C), // Blowtorch
353
- 2 => call_fire_usercall(worm, worm, rb(0x51E3E0)), // Pneumatic Drill
354
- 3 => call_fire_stdcall3(worm, params_38 as *const WeaponFireParams, local_struct, rb(0x51E350)),
355
- 4 => fire_worm_vtable_0xe(worm, 0x6D), // Baseball Bat
356
- 5 => fire_worm_vtable_0xe(worm, 0x75), // Fire Punch
357
- 6 => fire_worm_vtable_0xe(worm, 0x70), // Dragon Ball
358
- 8 => fire_worm_vtable_0xe(worm, 0x6E), // Kamikaze
359
- 9 => call_fire_usercall_stdcall1(worm, worm, local_struct, rb(0x51E480)), // Prod
360
- 10 => call_fire_usercall(worm, worm, rb(0x51E710)), // Air Strike (EAX=worm)
361
- 11 => fire_worm_vtable_0xe(worm, 0x71), // Scales of Justice
362
- 13 => call_fire_usercall(worm, worm, rb(0x51E5C0)), // Napalm Strike
363
- 14 => call_fire_usercall(worm, worm, rb(0x51E670)), // Mail/Mine/Mole (EAX=worm!)
364
  16 => {
365
- // Teleport: check condition, then fire or vtable fallback
366
- let result = call_fire_usercall_ret(worm, worm, rb(0x516930));
 
367
  if result != 0 {
368
- call_fire_usercall(worm, worm, rb(0x51EB00));
369
  } else {
370
  fire_worm_vtable_0xe(worm, 0x74);
371
  }
372
  }
373
- 17 => call_fire_usercall(worm, worm, rb(0x51E920)), // Freeze
374
- 18 => fire_worm_vtable_0xe(worm, 0x72), // Suicide Bomber
375
- 19 => call_fire_usercall(worm, worm, rb(0x51E8C0)), // Skip Go
376
- 20 => call_fire_usercall(worm, worm, rb(0x51E600)), // Surrender
377
- 21 => call_fire_usercall(worm, worm, rb(0x51EBE0)), // Select Worm
378
- 22 => call_fire_usercall(worm, worm, rb(0x51EC30)), // Jet Pack
379
- 23 => fire_worm_vtable_0xe(worm, 0x78), // Magic Bullet
380
- 24 => call_fire_usercall(worm, worm, rb(0x51EA60)), // Low Gravity / Fast Walk
381
  _ => {}
382
  }
383
  }
 
232
  }
233
  4 => {
234
  let subtype_38_ptr = &raw const (*entry).fire_subtype_38 as u32;
235
+ fire_weapon_special(subtype_34, subtype_38_ptr, w, local_struct, entry);
236
  }
237
  _ => {}
238
  }
 
343
  }
344
 
345
  /// Type 4 (special) weapon dispatch.
346
+ /// Type 4 (special) weapon dispatch.
347
+ ///
348
+ /// EAX at entry = weapon entry pointer (unchanged from type-4 switch).
349
+ /// Some handlers explicitly set EAX=worm or EAX=*(worm+0x44).
350
+ /// Handlers without explicit MOV EAX inherit the entry pointer.
351
+ unsafe fn fire_weapon_special(
352
+ subtype: i32, params_38: u32, worm: u32, local_struct: u32,
353
+ entry: *const WeaponEntry,
354
+ ) {
355
  use openwa_core::rebase::rb;
356
+ let entry_u32 = entry as u32;
357
 
 
358
  match subtype {
359
+ 1 => fire_worm_vtable_0xe(worm, 0x6C), // Blowtorch
360
+ 2 => call_fire_usercall(entry_u32, worm, rb(0x51E3E0)), // Drill (EAX=entry)
361
+ 3 => call_fire_stdcall3(worm, params_38 as *const WeaponFireParams, local_struct, rb(0x51E350)), // Girder
362
+ 4 => fire_worm_vtable_0xe(worm, 0x6D), // Baseball Bat
363
+ 5 => fire_worm_vtable_0xe(worm, 0x75), // Fire Punch
364
+ 6 => fire_worm_vtable_0xe(worm, 0x70), // Dragon Ball
365
+ 8 => fire_worm_vtable_0xe(worm, 0x6E), // Kamikaze
366
+ 9 => call_fire_usercall_stdcall1(entry_u32, worm, local_struct, rb(0x51E480)), // Prod (EAX=entry)
367
+ 10 => call_fire_usercall(worm, worm, rb(0x51E710)), // Air Strike (EAX=worm)
368
+ 11 => fire_worm_vtable_0xe(worm, 0x71), // Scales of Justice
369
+ 13 => call_fire_usercall(entry_u32, worm, rb(0x51E5C0)), // Napalm (EAX=entry)
370
+ 14 => call_fire_usercall(worm, worm, rb(0x51E670)), // Mail/Mine/Mole (EAX=worm)
371
  16 => {
372
+ // Teleport: MOV EAX,[ESI+0x44] (worm state byte) before check
373
+ let worm_state = *((worm as *const u8).add(0x44) as *const u32);
374
+ let result = call_fire_usercall_ret(worm_state, worm, rb(0x516930));
375
  if result != 0 {
376
+ call_fire_usercall(result as u32, worm, rb(0x51EB00)); // EAX=check result
377
  } else {
378
  fire_worm_vtable_0xe(worm, 0x74);
379
  }
380
  }
381
+ 17 => call_fire_usercall(worm, worm, rb(0x51E920)), // Freeze (EAX=worm)
382
+ 18 => fire_worm_vtable_0xe(worm, 0x72), // Suicide Bomber
383
+ 19 => call_fire_usercall(entry_u32, worm, rb(0x51E8C0)), // Skip Go (EAX=entry)
384
+ 20 => call_fire_usercall(worm, worm, rb(0x51E600)), // Surrender (EAX=worm)
385
+ 21 => call_fire_usercall(entry_u32, worm, rb(0x51EBE0)), // Select Worm (EAX=entry)
386
+ 22 => call_fire_usercall(entry_u32, worm, rb(0x51EC30)), // Jet Pack (EAX=entry)
387
+ 23 => fire_worm_vtable_0xe(worm, 0x78), // Magic Bullet
388
+ 24 => call_fire_usercall(entry_u32, worm, rb(0x51EA60)), // Low Grav (EAX=entry)
389
  _ => {}
390
  }
391
  }