Module: WolfRpg
- Defined in:
- lib/wolfrpg/command.rb,
lib/wolfrpg/map.rb,
lib/wolfrpg/debug.rb,
lib/wolfrpg/route.rb,
lib/wolfrpg/database.rb,
lib/wolfrpg/game_dat.rb,
lib/wolfrpg/filecoder.rb,
lib/wolfrpg/common_events.rb
Overview
Special thanks to vgperson for mapping most of these command IDs out.
Defined Under Namespace
Classes: Command, CommonEvents, Database, FileCoder, GameDat, Map, RouteCommand
Class Method Summary collapse
-
.parse_strings(data) ⇒ Object
Find strings in binary string and return them inline in an array.
Class Method Details
.parse_strings(data) ⇒ Object
Find strings in binary string and return them inline in an array
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/wolfrpg/debug.rb', line 3 def self.parse_strings(data) result = [] # Scan for strings str_len = 0 can_seek_multibyte = false data.each_byte.with_index do |c, i| result << c if can_seek_multibyte if (c >= 0x40 && c <= 0x9E && c != 0x7F) || (c >= 0xA0 && c <= 0xFC) str_len += 1 next end end if (c >= 0x81 && c <= 0x84) || (c >= 0x87 && c <= 0x9F) || (c >= 0xE0 && c <= 0xEA) || (c >= 0xED && c <= 0xEE) || (c >= 0xFA && c <= 0xFC) # head of multibyte character str_len += 1 can_seek_multibyte = true next end can_seek_multibyte = false if c == 0x0A || c == 0x0D || c == 0x09 || # newline, CR, tab (c >= 0x20 && c <= 0x7E) || # printable ascii (c >= 0xA1 && c <= 0xDF) # half-width katakana str_len += 1 else str = '' if c == 0 && str_len > 0 # End of the string. Make sure it's valid by checking for # a length prefix. str_len_check = data[i - str_len - 4,4].unpack('V').first if str_len_check == str_len + 1 begin str = data[i - str_len,str_len].encode(Encoding::UTF_8, Encoding::WINDOWS_31J) rescue #do nothing end end end # Either append the string or hex bytes unless str.empty? result.slice!(-(4 + str_len + 1)..-1) result << str end # Reset str length str_len = 0 end end return result end |