[Feature] Add an option to output to JSON and output to file directly.
First off, thank you this seems like the way to easily keep data up to date with the game itself. However the output format for my uses leaves something to be desired. It would be awesome if an optional parameter could be given to the script so it outputs in for example JSON instead.
It would also be awesome if the output could be written to a file (preferably using a parameter for the location) rather than copying it to the clipboard.
I'm working in PHP at the moment and protobuf isn't natively supported, I'm sure there's other languages as well where protobuf parsing can be a bit of a hassle. JSON is however widely supported in afaik every language that's why I'm requesting this feature.
PS: First I thought it was malformed JSON, then I thought it might be YAML, before looking at the source of the parser and googling protobuf. Then it finally hit me that the format is protobuf, perhaps that's worth adding to the frontpage in case anyone like me gets confused :).
PPS: In case anyone else wants to use the output in PHP without pulling in big external libraries. With some creative regular expression use I've managed to turn it into valid JSON as follows:
$rawData = file_get_contents($currentFolder.'decoded_master.json');
$dataParts = explode("item_templates",$rawData);
//The data used is in the protobuf format which sadly cannot be parsed easily in PHP.
//However - using a few regular expressions it can be converted into valid JSON.
for($i = 1; $i < count($dataParts)-1; $i++) //First and last items are of no interest.
{
$part = $dataParts[$i];
//Quotes all 'keys' of objects and values that aren't booleans or numbers
$jsonPart = preg_replace_callback(
'~([a-z_0-9]+): ([a-zA-Z0-9\._\- :/"]+)~',
function($matches)
{
$escapedValues = '"'.$matches[1].'": ';
if(is_numeric($matches[2]) || $matches[2] === 'true' || $matches[2] === 'false')
$escapedValues .= $matches[2];
else if(strpos($matches[2], '"') === 0) //Don't quote already quoted values
$escapedValues .= $matches[2];
else
$escapedValues .= '"'.$matches[2].'"';
return $escapedValues.',';
},
$part);
//Quote all keys that come before an object and add the needed colon, e.g.
//avatar_customization { } becomes "avatar_customization": {}
$jsonPart = preg_replace('~([a-z_]+) {~', '"$1": {', $jsonPart);
//Filter out commas after the last value in an object as that isn't valid JSON.
$jsonPart = preg_replace('~(,)(\s+})~', '$2', $jsonPart);
//Add comma's between object values
$jsonPart = preg_replace('~}(\s+"[a-z_0-9]+")~', '},$1', $jsonPart);
$json = json_decode($jsonPart);
if($json===null)
{
echo '<h1 style="color: red;">Error: '.json_last_error_msg().'</h1>';
echo '<h2>Whilst parsing input:</h2>';
echo '<pre>'.$part.'</pre>';
echo '<h2>as JSONified: </h2>';
echo '<pre>'.$jsonPart.'</pre>';
echo '<hr/>';
}
else
{
echo '<h1 style="color: green">Success</h1>';
echo '<pre>'.print_r($json, true).'</pre><hr/>';
}
}
@Axeia don't know how active this repository is, so I thought I post it here; I'm currently running a repository which archives the decoded GAME_MASTER versions, similar like this repository, but also with JSON output
Have a look here