Update player's data from external code (php, linux sheel script,..)

    Nyl

    Joined
    Jun 30, 2013
    Messages
    5
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    Hi,

    I 'd like to make a donation system for my server, the system will reward givers with in game money or items.

    is it possible to update players datas like credits from a php code or shell script?
    If yes, how?

    Thanks
     
    Joined
    Jun 25, 2013
    Messages
    403
    Reaction score
    11
    • Legacy Citizen 2
    • Legacy Citizen
    If we knew the file formats we could. I asked a similar question about the Ship File Format.We could work out the format ourselves if the code wasn\'t obfusticated. But, since it is, a lot more work is required.

    I made a tiny bit of headway on the Ship File Format reading the decompiled source. But it\'s slow work. I haven\'t worked with the player file yet. Which one is that? If the file is of fixed length, you can probably work it out by comparing the files before and after a small change to money.
     

    Nyl

    Joined
    Jun 30, 2013
    Messages
    5
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    The file is named \"ENTITY_PLAYERSTATE_.ent\"

    Sounds like a binary file. If we could find the serializer in the sources.. OR send admin commands with the shell (not safe)
     
    Joined
    Jun 25, 2013
    Messages
    403
    Reaction score
    11
    • Legacy Citizen 2
    • Legacy Citizen
    I think this is the class that deals with reading/writing this file.

    Decompiled with JAD.

    Decompiled with JD.

    With luck, all their .ent files use the same format. Looking into it...
     
    Joined
    Jun 25, 2013
    Messages
    403
    Reaction score
    11
    • Legacy Citizen 2
    • Legacy Citizen
    Converted the decompiled code. I can now read the playerstate entity file. There\'s a dump below. I should be able to probably write it too. I\'ll do a wrapper for that. Will a jar file that you can call with command line arguments give you what you need?

    Jo






    Code:
    PlayerState (STRUCT) = {
      credits (INT) = 376472
      spawn (VECTOR3f) = (0.0, -6.5, -8.0)
      inventory (STRUCT) = {
        slots (LIST) = [
          (INT) = 3
          (INT) = 6
          (INT) = 4
          (INT) = 0
        ]
        types (LIST) = [
          (SHORT) = 78
          (SHORT) = 2
          (SHORT) = 77
          (SHORT) = 75
        ]
        values (LIST) = [
          (INT) = 6
          (INT) = 143
          (INT) = 2
          (INT) = 1
        ]
      }
      sector (VECTOR3i) = (2, 2, 2)
      lspawn (VECTOR3f) = (8.00286, 55.510994, 174.78363)
      lsector (VECTOR3i) = (10, -5, 7)
      pFac-v0 (STRUCT) = {
        null (INT) = 0
      }
      null (LONG) = 1372465329229
      null (LONG) = 1372470226541
      ips (STRUCT) = {
        null (STRING) = /127.0.0.1
      }
    }
     

    Nyl

    Joined
    Jun 30, 2013
    Messages
    5
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    Thanks a lot for that :) yeash a jar file would be amazing ! I \'ll also try to make a php reader and writer, I think it\'s safer than calling sheel script from the web server .
     

    Nyl

    Joined
    Jun 30, 2013
    Messages
    5
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    here\'s a begining from the php reader: this code read the credits




    $data = file_get_contents(\"ENTITY_PLAYERSTATE_Nyl.ent\");
    $match = preg_match(\'/(?:credits)(.+)(?:spawn)/\', $data, $matches);
    $byteCredit = $matches[1];
    echo \"Binary String:\\n\";

    var_dump($byteCredit);
    echo \"\\n\";
    echo \"\\n\";

    echo \"Binary values\\n\";
    for ($i = 0; $i < strlen($byteCredit) - 3; $i++)
    {
    echo var_dump(sprintf(\"%08b\", ord($byteCredit[$i])));
    }
    $byteInteger =
    sprintf(\"%08b\", ord($byteCredit[0])) .
    sprintf(\"%08b\", ord($byteCredit[1])) .
    sprintf(\"%08b\", ord($byteCredit[2])) .
    sprintf(\"%08b\", ord($byteCredit[3]));
    echo \"\\n\";
    echo \"Recomposed binary number:\\n\";
    var_dump($byteInteger);
    echo \"\\n\";
    echo \"Recomposed Integer \\n\";
    var_dump(bindec($byteInteger));
    echo \"\\n\";


    Output:







    Binary String:



    string(7) \"=+Y? \"











    Binary values



    string(8) \"00111101\"



    string(8) \"00101011\"



    string(8) \"01011001\"



    string(8) \"10101111\"







    Recomposed binary number:



    string(32) \"00111101001010110101100110101111\"







    Recomposed Integer



    int(1026251183)
     
    Joined
    Jun 25, 2013
    Messages
    403
    Reaction score
    11
    • Legacy Citizen 2
    • Legacy Citizen
    I\'ve posted a first draft of the program here.

    I changed the output format to XML. Should be easier for others to parse.

    The source code is included in the jar file. That will help if you want to do a native version in PHP. I looked or a place on the wikis to start documenting the file format, but didn\'t see anywhere obvious. If someone wants to pick somewhere, I\'ll start entering data.

    Here\'s the \"read me\" included in the zip:

    Code:
    STARMADE UTILS
    ~~~~~~~~~~~~~~
    
    These tools are for doing basic manipulations to StarMade files. Unzip this file into the
    directory where StarMade.jar is. You can run them with sm_jo.cmd (Windows) or sm_jo.sh
    (Linux/Mac). The first argument is the desired operation. The remaining arguments depend
    on the operation.
    
    Current operations are:
    
    DUMP
      This will dump files in Entity format in XML to the console. Optionally, a starting point
    may be given and the tree will be dumped from there. A starting point ident is a slash
    delimited path using the tag names to the element.
      Examples:
     
      sm_jo.sh dump ENTITY_PLAYERSTATE_jjaquinta.ent
      sm_jo.sh dump ENTITY_PLAYERSTATE_jjaquinta.ent PlayerState/credits
    
    EDIT
      This will edit tags in the given entity file. The first argument is the name of the entity
    file. Following are sets of three arguments. The first is the path to the tag you want to
    change. (Same format as for dump.) The second is the operation to be performed. (=, +=,
    or -=). The third is the value to be applied.
      Not all operations are supported on all types.
      WARNING: this does not work well right now. There is a high chance it will corrupt the
    file given. Always back up your file first.
      Examples:
     
      sm_jo.sh edit ENTITY_PLAYERSTATE_jjaquinta.ent PlayerState/credits += 1000000
    
    DISCLAIMER
    These tools are crude, prone to errors, and unreliable. You may corrupt or render inoperable
    any files you touch with them. StarMade has chosen to obfusticate their code which means much
    of the analysis done to get this going is guess work. If you feel that producing clear source
    will benefit both the community and the StarMade developers, please contribute to this thread:
    
    http://star-made.org/content/obfustication-why
    
    And, yes, I practice what I preach. The source code for these utilities can be found within
    the jar file.
    
    DISTRIBUTION
    This set of utilities is distributed as \"begware\". If you use and like them, I would ask that
    you go and download my audiobook \"The Raider\'s Lament\":
      http://podiobooks.com/title/the-reaiders-lament
    It\'s a light hearted Sci-Fi novel that\'s a fun waste of time. You dont have to actually listen
    to it. Clocking up the downloads is appreciated.
    If you *really* like these tools (or the story), there is a Donate button on the audiobook page.
    All proceeds will go towards buying my daughter the Minecraft Lego kit.
     

    Nyl

    Joined
    Jun 30, 2013
    Messages
    5
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    I organized the future php API: here is an exemple of use:





    I \'ll release the \'alpha\' sources soon :)
     
    Joined
    Jun 25, 2013
    Messages
    403
    Reaction score
    11
    • Legacy Citizen 2
    • Legacy Citizen
    I refreshed the utility. Give it another go. I was able to successfully add 1,000,000 credits to my player. :)