Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


UTF-16 string from memory to clipboard

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
makerclark
How do I cheat?
Reputation: 0

Joined: 25 Aug 2016
Posts: 5

PostPosted: Thu Aug 25, 2016 4:44 pm    Post subject: UTF-16 string from memory to clipboard Reply with quote

I'm trying to use CE to study Japanese by running games with Japanese subtitles, so I want to grab Japanese strings from memory at certain points and copy them to the clipboard. I have found my break location, I have written the script to attach, debug, and set the breakpoint, and the breakpoint function written, the important part of which is:
Code:

  txt = readString(EAX, 1024, true)
  print(txt)
  control_setCaption(UDF1_CELabel1,  txt)
  writeToClipboard(txt)

The problem is that even though I specify that I'm reading a wide string from memory, all 3 ways of outputting it don't translate it correctly. Everything but Latin characters turns to "?"s, so the string "Jack は殺したモノ" becomes "Jack ??????" which obviously makes the whole point of the exercise moot.

I suspect this is a case of strings being stored as bytes rather than words. My question is, do I have any alternative (short of writing a plugin)?

Thanks for any help!

P.S. For anybody who wants to know, I'm using JGlossator to interpret the Japanese strings. It provides dictionary definitions for every word in a sentence, making it ideal for subtitles.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Aug 25, 2016 5:51 pm    Post subject: Reply with quote

Use readBytes(address, count, true) to return an array of bytes.
You'll have to read extra bytes and interrogate for the end of string yourself.
Code:
local aob = { 0x4A, 0x61, 0x63, 0x6B, 0x20, 0xE3, 0x81, 0xAF, 0xE6, 0xAE, 0xBA, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0x9F, 0xE3, 0x83, 0xA2, 0xE3, 0x83, 0x8E }
local str = {}
for i, v in ipairs(aob) do
  str[i] = string.char(v)
end
print(table.concat(str))
Back to top
View user's profile Send private message
makerclark
How do I cheat?
Reputation: 0

Joined: 25 Aug 2016
Posts: 5

PostPosted: Thu Aug 25, 2016 6:03 pm    Post subject: Reply with quote

Thank you so much! A quick test shows that this works for the clipboard too.

I'm thinking I'll read the string with readString first to get the length (and there's a prefix I need to check anyway) and then use that length x 2 to read the actual bytes.

You have made my day!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites