bahamut/tools/script-extractor.hpp
//after analyzing the script, this runs through to look for any text without matching pointers.
after analyzing the script, this runs through to look for any text without matching pointers.
after analyzing the script this runs through to look for any text without matching pointers .
auto Script::findOrphaned() -> void {
  auto orphan = [&](u16 offset, u16 target) -> void {
    if(target < offset) return;
    u16 length = target - offset;
    if(length <= 4) return;
    debug(label(), " 0x", hex(offset, 4L), " orphaned string => ", length);
    Pointer pointer;
    pointer.target = offset;
    if(auto terminal = findTerminal(offset)) {
      pointer.terminal = data[*terminal];
      pointers.append(pointer);
    }
  };
  auto skipTerminal = [&](u16& offset) -> void {
    while(offset < data.size()) {
      if(mode == Mode::Chapter) {
        if(data[offset] == 0xff) { offset++; continue; }
        if(data[offset] == 0xfd) { offset++; continue; }
      }
      if(mode == Mode::Field) {
        if(data[offset] == 0xff) { offset++; continue; }
      }
      if(data[offset] == 0xfe) { offset++; continue; }
      if(data[offset] == 0xef && data(offset + 1, 0x00) == 0xfe) { offset += 2; continue; }
      break;
    }
  };
  u16 offset = origin;
  for(auto& pointer : pointers) {
    skipTerminal(offset);
    orphan(offset, pointer.target);
    offset = pointer.target;
    if(auto terminal = findTerminal(offset)) {
      offset = *terminal;
    }
  }
  skipTerminal(offset);
  orphan(offset, data.size());
}
auto Script :: findOrphaned ( ) -> void { auto orphan = [ & ] ( u16 offset , u16 target ) -> void { if ( target < offset ) return ; u16 length = target - offset ; if ( length <= 4 ) return ; debug ( label ( ) , " " , hex ( offset , 4L ) , " " , length ) ; Pointer pointer ; pointer . target = offset ; if ( auto terminal = findTerminal ( offset ) ) { pointer . terminal = data [ * terminal ] ; pointers . append ( pointer ) ; } } ; auto skipTerminal = [ & ] ( u16 & offset ) -> void { while ( offset < data . size ( ) ) { if ( mode == Mode :: Chapter ) { if ( data [ offset ] == 0xff ) { offset ++ ; continue ; } if ( data [ offset ] == 0xfd ) { offset ++ ; continue ; } } if ( mode == Mode :: Field ) { if ( data [ offset ] == 0xff ) { offset ++ ; continue ; } } if ( data [ offset ] == 0xfe ) { offset ++ ; continue ; } if ( data [ offset ] == 0xef && data ( offset + 1 , 0x00 ) == 0xfe ) { offset += 2 ; continue ; } break ; } } ; u16 offset = origin ; for ( auto & pointer : pointers ) { skipTerminal ( offset ) ; orphan ( offset , pointer . target ) ; offset = pointer . target ; if ( auto terminal = findTerminal ( offset ) ) { offset = * terminal ; } } skipTerminal ( offset ) ; orphan ( offset , data . size ( ) ) ; }
after analyzing the script, this runs through to look for any text without matching pointers.
after analyzing the script this runs through to look for any text without matching pointers .