bahamut/tools/script-extractor.hpp
//scan backward to find the beginning of a string
scan backward to find the beginning of a string
scan backward to find the beginning of a string
auto Script::findTarget(u16 offset) -> maybe<u16> {
  maybe<u16> found;
  while(offset >= origin) {
    if(mode == Mode::Chapter) {
      if(data[offset] == 0xff) { found = offset; break; }
      if(data[offset] == 0xfd) { found = offset; break; }
    }
    if(mode == Mode::Field) {
      if(data[offset] == 0xff) { found = offset; break; }
    }
    offset--;
  }
  if(found) {
    if(data[*found + 1] == 0xfe) return *found + 2;
    if(data[*found + 1] == 0xef && data[*found + 2] == 0xfe) return *found + 3;
    return *found + 1;
  }
  return nothing;
}
auto Script :: findTarget ( u16 offset ) -> maybe < u16 > { maybe < u16 > found ; while ( offset >= origin ) { if ( mode == Mode :: Chapter ) { if ( data [ offset ] == 0xff ) { found = offset ; break ; } if ( data [ offset ] == 0xfd ) { found = offset ; break ; } } if ( mode == Mode :: Field ) { if ( data [ offset ] == 0xff ) { found = offset ; break ; } } offset -- ; } if ( found ) { if ( data [ * found + 1 ] == 0xfe ) return * found + 2 ; if ( data [ * found + 1 ] == 0xef && data [ * found + 2 ] == 0xfe ) return * found + 3 ; return * found + 1 ; } return nothing ; }
scan backward to find the beginning of a string
scan backward to find the beginning of a string