Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some values are encoded in a non-readable way #59

Open
captain-majid opened this issue Oct 31, 2023 · 9 comments
Open

Some values are encoded in a non-readable way #59

captain-majid opened this issue Oct 31, 2023 · 9 comments

Comments

@captain-majid
Copy link

{
        "Frame": 444,
        "PlayerID": 0,
        "Type": {
          "Name": "Cheat",
          "ID": 18
        },
        "Data": "AQAAAA=="
},

Would like to know the cheat type, so how Data is encoded here ?

@icza
Copy link
Owner

icza commented Oct 31, 2023

JSON encodes binary data as Base64.

@captain-majid
Copy link
Author

captain-majid commented Oct 31, 2023

I tried to convert that to byte array which gives [1 0 0 0] but the value isn't static, I think it depends on whether other cheats ran with it or b4 it or not, probabply using enum bit-or to represent the whole state of cheat codes, any idea how this is structured ? otherwise the "Data": "AQAAAA==" isn't useful.

@icza
Copy link
Owner

icza commented Oct 31, 2023

Binary data of some commands are not parsed / modeled. They are still retained and outputted as-is, which reflects the data stored in replays. In such cases the parser needs to be updated to interpret the data, or you have to do your own research what the data means.

In most such cases I lacked the information how to interpret the data and was "lazy" to figure it out myself.

@captain-majid
Copy link
Author

captain-majid commented Oct 31, 2023

Any other cmds have values that still encoded as base64 string in json ?

@icza
Copy link
Owner

icza commented Oct 31, 2023

Yes, there are some, there are also some that partly interpret the data, and outputs the rest, uninterpreted part as Base64.

@captain-majid
Copy link
Author

cmds like what exactly ?

@icza
Copy link
Owner

icza commented Oct 31, 2023

Actually, looking at the code, I don't see anything else besides the "Use Cheat" command.

@captain-majid
Copy link
Author

captain-majid commented Nov 1, 2023

I think I finally got it working, this code is in C#, no experience in Go, so hopefully you can port it and tell me if it's working on your side:

if (cmdType == "Cheat")
{
    cheatByteArray_new = Convert.FromBase64String(item.XPathSelectElement("Data").Value); // convert encoded Base64 string to byte array
    string[] excludeThose = new string[] { "16,0,0,0" , "0,0,4,0", "0,0,8,0", "8,0,0,0" }; //don't know how, but ignoring those seems to have the correct values.
    byte[] result = new byte[4];
    for (int i = 0; i < 4; i++)
    {
        result[i] = (byte)(cheatByteArray_new[i] ^ cheatByteArray_old[i]); //xoring the items in the 2 byte arrays
    }
    data = string.Join(",", result);
    if (!excludeThose.Contains(data))
        cheatByteArray_old = cheatByteArray_new;

    switch (data) //The initial values of every cheat code, can be different if the order of issuing them changed.
    {
        case "16,0,0,0": more = ": show me the money " + data; break;
        case "1,0,0,0": more = ": black sheep wall " + data; break;
        case "2,0,0,0": more = ": operation cwal " + data; break;
        case "4,0,0,0": more = ": power overwhelming " + data; break;
        case "0,1,0,0": more = ": staying alive " + data; break;
        case "128,0,0,0": more = ": there is no cow level " + data; break;

        case "64,0,0,0": more = ": game over man " + data; break;
        case "0,0,4,0": more = ": whats mine is mine " + data; break;
        case "0,8,0,0": more = ": the gathering " + data; break;
        case "0,0,8,0": more = ": breathe deep " + data; break;

        case "8,0,0,0": more = ": something for nothing " + data; break;
        case "0,16,0,0": more = ": medieval man " + data; break;
        case "0,32,0,0": more = ": modify the phase variance " + data; break;
        case "0,64,0,0": more = ": war aint what it used to be " + data; break;

        case "0,0,2,0": more = ": food for thought " + data; break;
        case "0,0,0,32": more = ": noglues " + data; break;
        case "0,2,0,0": more = ": ophelia " + data; break;
        case "0,0,16,0": more = ": zoom zoom " + data; break;
        default: more = ": ??? unknown " + data; break;
    }
}

@icza
Copy link
Owner

icza commented Nov 2, 2023

So it seems there are 4 bytes of data, and each bit of those corresponds to a specific cheat code (there may be unsued bits).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants