Ah... makes more sense now. nwn-lib has a environment variable that lets you set the encoding your stuff is in. When Ruby attempts to encode a byte string in your encoding, it has to encode it in UTF-8 first and so if you have invalid utf-8 characters encodings it quits with an error. These aren't even off the wall characters either, but things like minuscule a-circumflex, things that it should be able to convert.
I modified things to work enough that it could read the GFFs without erroring out in nwn-lib-0.5.0\\lib\\nwn\\gff\\reader.rb:
162c162
< @field_data[data_or_offset + 4, len].encode(NWN.setting :in_encoding)
---
> @field_data[data_or_offset + 4, len].force_encoding(NWN.setting :in_encoding)
166c166
< @field_data[data_or_offset + 1, len].encode(NWN.setting :in_encoding)
---
> @field_data[data_or_offset + 1, len].force_encoding(NWN.setting :in_encoding)
179c179
< str = all[8, len].unpack("a*")[0].encode(NWN.setting :in_encoding)
---
> str = all[8, len].unpack("a*")[0].force_encoding(NWN.setting :in_encoding)
No clue if that' would be a good idea to a Rubyist, I'll send it on to Elven and see what he thinks. For querying the GFFs for information the following probably wouldn't really matter, but there is still something fishy going on with the text exports to json and yaml. Windows aware text editors like Notepad++ seem to be able to figure out the (mixture?) of encodings in the file and render the characters properly... others like Emacs and gVim don't. I've not tried anything furter than that.
Is NWN utf-8 aware?
Modifié par pope_leo, 22 décembre 2012 - 05:00 .