SRL Archive - FAQ

Simba string storing foreign language


riwu

2015-01-25 10:14:12

i stored the string returned in a string variable text, write(text) printed 'Poser un pi?ge Jeune arbre'

However, it seems like the actual string stored in the variable was different as when i did
writeln('Poser un pi?ge Jeune arbre' = text)
it printed false.
writeln('Poser un piège Jeune arbre' = text)
printed false as well.

StringMatch() returned 0.961538462

@Brandon; any idea?

Brandon

2015-01-25 11:05:18

From: riwu
i stored the string returned in a string variable text, write(text) printed 'Poser un pi?ge Jeune arbre'

However, it seems like the actual string stored in the variable was different as when i did
writeln('Poser un pi?ge Jeune arbre' = text)
it printed false.
writeln('Poser un piège Jeune arbre' = text)
printed false as well.

StringMatch() returned 0.961538462



How did you retrieve the text? If the text was retrieved via Simba's text recognition, then you are screwed. If it's via Tesseract or OpenGL, it should give you the proper characters for the comparison.

That ? mark is not actually a ? mark. it's a byte representing part of the unicode character that should have been recognised so when you compare the two, it will never be true.

`writeln('Poser un piège Jeune arbre' = 'Poser un piège Jeune arbre');` will print true so whatever is in your "Text" string is not the same.

riwu

2015-01-25 11:16:05

From: Brandon
How did you retrieve the text? If the text was retrieved via Simba's text recognition, then you are screwed. If it's via Tesseract or OpenGL, it should give you the proper characters for the comparison.

That ? mark is not actually a ? mark. it's a byte representing part of the unicode character that should have been recognised so when you compare the two, it will never be true.

`writeln('Poser un piège Jeune arbre' = 'Poser un piège Jeune arbre');` will print true so whatever is in your "Text" string is not the same.

It's from your ogl plugin glCharsToTexts(glGetChars())
That ? is not è either as

writeln('Poser un piège Jeune arbre' = trim(options[i].Text));
printed false.

How should i compare it then?
Do i have to resort to StringMatch() or avoid including ? in substring?

EDIT:
Ord(options.Text[12]) returned 232
Guess i could make use of Ord() to compare but that'd be really clumsy.
According to http://www.asciitable.com/, 232 is the char phi?! Seems like Ord() doesnt work for the extended ASCII characters.

Brandon

2015-01-25 11:41:30

From: riwu
…



The ? is actually character 233 (the exact character code the game uses).


Simba says that é is 195 but the UTF16 Table disagrees: http://www.fileformat.info/info/unicode/char/e9/index.htm
In fact, it says that the plugin is 100% correct.. Since Java by default uses UTF16, you need to convert the chars to UTF16 encoding or from Latin-1 to UTF8.





See:



Works fine normally.. However, in Simba:



Not only is the characters in the string completely wrong, but it also isn't able to print them.. It's fine that Simba only supports UTF8 but it needs a conversion function.


Solution @riwu:

So.. I've been forced to add a conversion to the GLX plugin: https://github.com/Brandon-T/GLX/commit/fc9283352abc048df962ef1df1e61d170ef00943 is changed.


Usage:


{$DEFINE SMART}
{$I GLX/Setup.Simba}

Function glToWStr(Str: String): WideString;
var
I: Integer;
begin
SetLength(Result, Length(Str));
For I := 1 To Length(Str) Do
begin
Result[I] := Chr(Int16(Ord(Str[I])));
end;
end;

Function glToUTF8(Str: WideString): String;
var
L: Integer;
begin
Str := glToWStr(Str);
L := GLXUTF16ToUTF8(@Str[1], nil);
SetLength(Result, L - 1);
GLXUTF16ToUTF8(@Str[1], @Result[1]);
end;

Function glToUTF16(Str: String): WideString;
var
L: Integer;
begin
L := GLXUTF8ToUTF16(@Str[1], nil);
SetLength(Result, L - 1);
GLXUTF8ToUTF16(@Str[1], @Result[1]);
end;

var
Smart: TSmart;
t: TStringArray;
S: String;
begin
ClearDebug();
SetupGLX(Smart, 800, 600);

T := glCharsToText(glGetChars(IntToBox(286, 531, 511, 551)), 3);
S := glToUTF8(T[0]);

writeln(glToUTF8(T[0]) = 'Créer un compte gratuit');
writeln(T[0] = glToUTF16('Créer un compte gratuit'));
end.


Paired with SMART[7892]
True
True
Successfully executed.


That means that for strings containing special characters, you must do A OR B:

a. Convert the returned string to UTF8 and compare.
b. Convert the compared string to UTF16 and compare.

Up to you.. Note: You don't have to do this for strings with characters in the range: 0 inclusive to 127 inclusive.

riwu

2015-02-13 02:00:44

@Brandon;
I got an access violation at the line 'L := GLXUTF8ToUTF16(@Str[1], nil);' when i run the following:

{$DEFINE SMART}
{$include_once GLX/Setup.Simba}

Function glToWStr(Str: String): WideString;
var
I: Integer;
begin
SetLength(Result, Length(Str));
For I := 1 To Length(Str) Do
begin
Result[I] := Chr(Int16(Ord(Str[I])));
end;
end;

Function glToUTF8(Str: String): String;
var
L: Integer;
begin
Str := glToWStr(Str);
L := GLXUTF16ToUTF8(@Str[1], nil);
SetLength(Result, L - 1);
GLXUTF16ToUTF8(@Str[1], @Result[1]);
end;

Function glToUTF16(Str: String): String;
var
L: Integer;
begin
L := GLXUTF8ToUTF16(@Str[1], nil);
SetLength(Result, L - 1);
GLXUTF8ToUTF16(@Str[1], @Result[1]);
end;

begin
glToUTF16('Créer un compte gratuit');
end.



Also any idea why this is returning [Rune, ?, S Offline] with glCharsToText(glGetChars)?
And when i called writeln(glCharsToText(glGetChars)[1]) it did nothing at all! (not even printing an empty line)


EDIT: i managed a temp fix for the above with

str:= TSA.merge; //merge the tstringarray to a string
for i:=1 to Length(str) do
if not ExecRegExpr('\w|\s', result[i]) then //nonspace and nonword
str[i]:= ' ';

Brandon

2015-02-13 02:20:51

From: riwu
…


https://www.diffchecker.com/p9cir73f

I accidentally forgot to mention that the result of a UTF16 string is double the size of a UTF8 string aka WIDESTRING and not STRING. Post edited. I would have to test the friend interface and see why. I can't give a reason without testing.

EDIT: What interface is that and how do I view it (haven't played RS in ages).

riwu

2015-02-13 02:29:49

From: Brandon
https://www.diffchecker.com/p9cir73f

I accidentally forgot to mention that the result of a UTF16 string is double the size of a UTF8 string aka WIDESTRING and not STRING. Post edited. I would have to test the friend interface and see why. I can't give a reason without testing.

EDIT: What interface is that and how do I view it (haven't played RS in ages).

Still getting access violation at 'L := GLXUTF8ToUTF16(@Str[1], nil);'
Changing the return type wouldnt affect it since the problem appears to be with the argument Str?

The interface is at lobby > Friends, most names with space will return that weird ?. eg. 'kit kat'
If it's sth hard to fix/you have no time to do it then it's alright, i could just use the ExecRegExpr fix

EDIT: @Brandon;
Try a name with space
eg. 'Rune S', 'kit kat'

Brandon

2015-02-13 02:41:24

From: riwu
Still getting access violation at 'L := GLXUTF8ToUTF16(@Str[1], nil);'
Changing the return type wouldnt affect it since the problem appears to be with the argument Str?

The interface is at lobby > Friends, most names with space will return that weird ?. eg. 'kit kat'
If it's sth hard to fix/you have no time to do it then it's alright, i could just use the ExecRegExpr fix




riwu

2015-02-13 02:47:02

From: Brandon

Yeah that ? between the Rune and S, what's that?

Brandon

2015-02-13 02:52:24

From: riwu
Yeah that ? between the Rune and S, what's that?


A UTF16 space character lol. If you want, you can modify the text function to not only check for 32 as a space character but also 160 (seeing as Java uses UTF16 and RS is written in Java).. Though, I've never seen the game spit out a space character before! Usually they (and every other company out there) just render the characters a certain amount of distance apart (space simulation) instead of actually rendering a "space" literally. Lol..

I'm not surprised though because Java is UTF16 by default.

I'll add automatic conversion to my todo list (it was already there but I'll make it priority). However, for now, I'd suggest to avoid modifying the function and instead just do the conversion. Or have the function do it for you upon returning the result.




riwu

2015-02-13 03:34:23

From: Brandon
A UTF16 space character lol. If you want, you can modify the text function to not only check for 32 as a space character but also 160 (seeing as Java uses UTF16 and RS is written in Java).. Though, I've never seen the game spit out a space character before! Usually they (and every other company out there) just render the characters a certain amount of distance apart (space simulation) instead of actually rendering a "space" literally. Lol..

I'm not surprised though because Java is UTF16 by default.

I'll add automatic conversion to my todo list (it was already there but I'll make it priority). However, for now, I'd suggest to avoid modifying the function and instead just do the conversion. Or have the function do it for you upon returning the result.

i see…
Did you modify the glx plugin or the code again? I'm still getting the access violation error at 'L := GLXUTF16ToUTF8(@Str[1], nil);' even after changing Str to WideString, or glChar.Letter to WideChar…

Brandon

2015-02-13 04:23:25

From: riwu
i see…
Did you modify the glx plugin or the code again? I'm still getting the access violation error at 'L := GLXUTF16ToUTF8(@Str[1], nil);' even after changing Str to WideString, or glChar.Letter to WideChar…


No changes to the github since.


/Start Documentation:

Fixed via Skype. He was missing the 2 exports so his function pointed to NULL. He patches the plugin himself :D
OpenSource ftl this time but nice work. He has his own version of the above, just missed 2 lines which caused the error.

All solved now. /EndDocumentation.

This post is just so I know that there is no problem. I usually go through all the posts and see what else there is to do. This is a self-note.

riwu

2015-02-13 04:40:32

From: Brandon
No changes to the github since.


/Start Documentation:

Fixed via Skype. He was missing the 2 exports so his function pointed to NULL. He patches the plugin himself :D
OpenSource ftl this time but nice work. He has his own version of the above, just missed 2 lines which caused the error.

All solved now. /EndDocumentation.

This post is just so I know that there is no problem. I usually go through all the posts and see what else there is to do. This is a self-note.

Thanks alot for the help!
Too much editing and missed the 2 lines….
I will make sure to triple check the final diff when updating the source next time :)