Advertisement
authorblues

Untitled

Mar 5th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function swapExits(stage, rom)
  2. {
  3.     if (stage.exits !== 2) return;
  4.     console.log('swapping exits @ ' + stage.name);
  5.    
  6.     // secret exit triggers event+1
  7.     var ndxa = rom[0x2D608 + stage.translevel];
  8.     var ndxb = ndxa + 1, ndxc = ndxa + 2;
  9.    
  10.     // get offsets into the event data table
  11.     var offseta = rom[0x26359 + ndxa * 2] | (rom[0x26359 + ndxa * 2 + 1] << 8);
  12.     var offsetb = rom[0x26359 + ndxb * 2] | (rom[0x26359 + ndxb * 2 + 1] << 8);
  13.     var offsetc = rom[0x26359 + ndxc * 2] | (rom[0x26359 + ndxc * 2 + 1] << 8);
  14.    
  15.     // get the size of each event
  16.     var asz = offsetb - offseta;
  17.     var bsz = offsetc - offsetb;
  18.    
  19.     // copy the event data to temporary storage
  20.     var eventa = rom.slice(0x025D8D + offseta, 0x025D8D + offseta + asz);
  21.     var eventb = rom.slice(0x025D8D + offsetb, 0x025D8D + offsetb + bsz);
  22.    
  23.     // update the new offset for where event+1 should go
  24.     offsetb = offseta + bsz;
  25.    
  26.     // copy the event data back into the event table
  27.     rom.set(eventb, 0x025D8D + offseta);
  28.     rom.set(eventa, 0x025D8D + offsetb);
  29.    
  30.     // update the offset for event+1 back into the table
  31.     rom.set([offsetb & 0xFF, (offsetb >> 8) & 0xFF], 0x26359 + ndxb * 2);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement