GuJian 3 to ITA

How to translate the files of a game
Hexaae
Posts: 61
Joined: Sat Mar 04, 2017 10:37 am

GuJian 3 to ITA

Post by Hexaae »

I'd like to translate the chinese game GuJian3, and I've found the "new_sword_legends.bms" for it...
Trying it on the idx game file I get this error:

Code: Select all

- open input file D:\Steam\steamapps\common\Gujian3\data\_index\303.idx
- open script bms\new_sword_legends.bms
- set output folder GuJian3\

  offset           filesize   filename
--------------------------------------

Error: the compressed LZMA input is wrong or incomplete (0)
Info:  algorithm   16
       offset      000000000000006c
       input size  0x00000000000239c8 145864
       output size 0x0000000000080000 524288
       result      0xffffffffffffff9c -100

Error: the uncompressed data (-100) is bigger than the allocated buffer (524288)

Last script line before the error or that produced the error:
  48  clog MEMORY_FILE OFFSET CHUNK_ZSIZE CHUNK_SIZE
SaraKale
Posts: 17
Joined: Tue Oct 02, 2018 11:46 am

Re: GuJian 3 to ITA

Post by SaraKale »

I also encountered the same problem, did you solve it?
Hexaae
Posts: 61
Joined: Sat Mar 04, 2017 10:37 am

Re: GuJian 3 to ITA

Post by Hexaae »

Unfortunately no... still waiting for help :(
SaraKale
Posts: 17
Joined: Tue Oct 02, 2018 11:46 am

Re: GuJian 3 to ITA

Post by SaraKale »

Don't be sad! Try contacting Aluigi? I don't know how to contact Aluigi :(
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: GuJian 3 to ITA

Post by Shokoniraya »

SaraKale wrote:Don't be sad! Try contacting Aluigi? I don't know how to contact Aluigi :(

according to error, it has problem in compression type, no one can help without a sample file
SaraKale
Posts: 17
Joined: Tue Oct 02, 2018 11:46 am

Re: GuJian 3 to ITA

Post by SaraKale »

Shokoniraya wrote:
SaraKale wrote:Don't be sad! Try contacting Aluigi? I don't know how to contact Aluigi :(

according to error, it has problem in compression type, no one can help without a sample file


303.idx file has been uploaded, you can click the link to download, Thank you very much!
https://mega.nz/#F!l0o3SBSC!uF3vm1TSgoJwK5gidu71gw
haibaer
Posts: 20
Joined: Wed Apr 17, 2019 4:03 pm

Re: GuJian 3 to ITA

Post by haibaer »

Maybe I can help if you guys haven't found any solution. I'll update a new script as soon as possible.
SaraKale
Posts: 17
Joined: Tue Oct 02, 2018 11:46 am

Re: GuJian 3 to ITA

Post by SaraKale »

haibaer wrote:Maybe I can help if you guys haven't found any solution. I'll update a new script as soon as possible.

Aluigi updated the script, which can be downloaded from the following address:
http://aluigi.org/bms/new_sword_legends.bms
But some files are encrypted with the algorithm of xxtea, and some people provide the key, But I don't know how to use it? Is there an xxtea script?

Code: Select all

cutscene\1010\cs_1010_1a.xxx: 84bf71f9a6a44fa3f3e1a266166dac7297f6018b
cutscene\1010\cs_1010_1b.xxx: 3cdfdf73bef25ae40a40215025fcabaffca2c72a
interface\resource\movie\cg00100b.xxx: 25bcfb70b5cc7e0f2253ffe8a9e3d6e831aad2f5
interface\resource_en\movie\optxt.xxx: 73be7f337c0c248926630719cdbe927895866a41
maps\m01\elems.xxx: 4a40a9712bfdc8e79c46b0ab735130d947dfe6f1
sounds_console\bgm.xxx: 5ff3f69e1d15a67f5d578dbc4d7ce263c1e83135
sounds_console\bgm_p1.xxx: b388c0bf15d0b39c684a0af3c2c3b925c00598b0
sounds_console\voice.xxx: 7ba2771ca1907e9f7348f38a5b8b3881d44db8a2
sounds_console\voice_npc.xxx: 960513d4e71a2b003eda159891e102c43e344eed
sounds_console\voice_p1.xxx: 1b2466ac36ee2e9c2fce01f76dbb1e873df42c06
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: GuJian 3 to ITA

Post by aluigi »

Just a little note about xxtea. xxtea is not a standard algorithm (like xxtea + key = 100% job done) because there are some settings, different endianess and even customizations that force you to reverse engineering the algorithm.
quickbms supports all the settings so, with some patience and luck, you can find the correct settings if it's not the default one.
End of my little technical note :D
Kaplas
Posts: 60
Joined: Fri Jan 25, 2019 2:47 pm

Re: GuJian 3 to ITA

Post by Kaplas »

Here is the C# code for decrypting the files. Each data chunk is 1000 bytes length.

Code: Select all

        private static uint[] GetKey(string key)
        {
            var temp = new byte[16];
            byte[] hexKey = Encoding.ASCII.GetBytes(string.Concat(key, key.Substring(24, 8)));

            for (int i = 0; i < 16; i++)
            {
                temp[i] = (byte)(hexKey[i] ^ hexKey[i + 16] ^ hexKey[i + 32]);
            }

            var result = new uint[temp.Length / sizeof(uint)];
            Buffer.BlockCopy(temp, 0, result, 0, temp.Length);

            return result;
        }

        private static void DecryptChunk(byte[] buffer, int size, IReadOnlyList<uint> key)
        {
            int chunkCount = size / 256;

            for (int i = 0; i < chunkCount; i++)
            {
                var data = new uint[64];
                Buffer.BlockCopy(buffer, i * 256, data, 0, 256);
                DecryptBlock(data, 64, key);
                Buffer.BlockCopy(data, 0, buffer, i * 256, 256);
            }

            // Process the last block
            int lastBlockLength = (size - (chunkCount * 256)) / 4;
            if (lastBlockLength > 0)
            {
                var data = new uint[lastBlockLength];
                Buffer.BlockCopy(buffer, chunkCount * 256, data, 0, lastBlockLength * 4);
                DecryptBlock(data, lastBlockLength, key);
                Buffer.BlockCopy(data, 0, buffer, chunkCount * 256, lastBlockLength * 4);
            }

            // Process the last bytes
            int lastBytesCount = size - (chunkCount * 256) - (lastBlockLength * 4);
            if (lastBytesCount > 0)
            {
                for (int i = size - lastBytesCount; i < size; i++)
                {
                    buffer[i] = (byte)(buffer[i] ^ (size - i) ^ 0xB7);
                }
            }
        }

        // It's a XXTEA algorithm
        // See: https://en.wikipedia.org/wiki/XXTEA
        private static void DecryptBlock(IList<uint> data, int blockLength, IReadOnlyList<uint> key)
        {
            uint counter = (uint)(((0x34 / blockLength) + 6) * -0x61c88647);
            while (counter != 0)
            {
                uint keyBase = (counter >> 2) & 3;
                uint next = data[0];
                for (int i = blockLength - 1; i >= 0; i--)
                {
                    uint previous = (i - 1) >= 0 ? data[i - 1] : data[blockLength - 1];

                    uint value1 = (next << 2) ^ (previous >> 5);
                    uint value2 = (next >> 3) ^ (previous << 4);
                    uint value3 = next ^ counter;
                    uint value4 = previous ^ key[(int)((i & 3) ^ keyBase)];

                    data[i] = data[i] - (value1 + value2 ^ value3 + value4);

                    next = data[i];
                }

                counter += 0x61c88647;
            }
        }


Anyway, none of the .xxx files has the game texts. I think they are encrypted inside the .exe file.
SaraKale
Posts: 17
Joined: Tue Oct 02, 2018 11:46 am

Re: GuJian 3 to ITA

Post by SaraKale »

i see,Forgive me for not understanding the encryption algorithm, I'm sorry! :cry: Do I need to upload the EXE file?
alanm
Posts: 21
Joined: Mon Aug 17, 2020 4:54 am

Re: GuJian 3 to ITA

Post by alanm »

Sorry for replying to old thread. Has anyone figure out how to extract text from the game .exe for translation? I have no clue what encryption is used to encrypt the dialog text. But I did find where the game store the decrypted dialog text in memory and manage to memory dump it to a file. this is just the cutscene subtitle text, not every UI strings in the game.