Jump to content

How should I covert(decode) an bytes array to UTF-16LE text(or string)?


 Share

Recommended Posts

My script has a functional requirement: I search all actor(hero) names in the game, then I want to show the user a list of names,the user selects one of them.The script performs subsequent operations based on this selection.

My question is : How to convert byte arrays to text(string)?

In Java, His effect is similar to :

    String content = new String(bytes, "UTF-16LE");

How to do this in Lua Script?

I know "string.char" can decode UTF-8, but when the code is UTF-16LE, the text is garbled.(My game language is Chinese).I see some code that can be implemented, but that requires bit operation on Lua53.

Who can give me some suggest,or some tools and methods that can run on Lua52

Thanks.

Link to comment
Share on other sites

On 1/12/2022 at 10:45 PM, ctbear said:

I see some code that can be implemented, but that requires bit operation on Lua53.

Lua implementation in GG is source-compatible with Lua 5.3 (as mentioned in the documentation), meaning that bitwise operators are supported.

For example, the following code should work correctly when executed by GG

print("2 XOR 4 = " .. (2 ~ 4)) -- should print "2 XOR 4 = 6"
Link to comment
Share on other sites

10 hours ago, CmP said:

Lua implementation in GG is source-compatible with Lua 5.3 (as mentioned in the documentation), meaning that bitwise operators are supported.

For example, the following code should work correctly when executed by GG

print("2 XOR 4 = " .. (2 ~ 4)) -- should print "2 XOR 4 = 6"

thank you for your reply.

The code you said is useful. But doing so faces another problem. My Script is can't run after Luac(5.3) compilation.  

The error message is:

Invalid binary script header.
Unknown version. Expected '52' butfound '54'.
Unknown endianness. Expected '0'or'1' but found '25'.
Unknown size of int. Expected '4' butfound '147'.
Unknown size of size t. Expected '4'but found '13'.
Unknown size of instruction.
Expected '4' but found '10'.
Unknown size of Lua number.Expected '4' or '8' but found '26'.

 Now I use the code of bitwise operators solved the problems mentioned in the topic.  My code can only run as source code now. This makes people feel helpless.

 Anyway, thank you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Similar Content

    • By TopGEOYT
      View File Decompiler For Script (Remove Binary Chunk)
      Hello Guys .
      this script is client for send selected script in server .
      main actions happen in servers .
      this decompiler uses modified unluac .
      unluac is executing in servers .
      this unluac can solve some hard cases where another unluacs get fail .
      if you like this script , dont forget to ❤️ this script .
      Video Review : 
       
       
      Submitter TopGEOYT Submitted 12/01/2019 Category Tools  
    • By TopGEOYT
      Hello Guys .
      this script is client for send selected script in server .
      main actions happen in servers .
      this decompiler uses modified unluac .
      unluac is executing in servers .
      this unluac can solve some hard cases where another unluacs get fail .
      if you like this script , dont forget to ❤️ this script .
      Video Review : 
       
       
    • By Re_Load
      I know load→print is decoding, but PMC can’t decode with print. How can I decode it?
      I try many time(130 times), and This file is decode 1/4.
      PMC VIP 2.8 - Edited by Reload download link
       
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.