x2Fusion

Untitled

Dec 30th, 2022
1,244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.76 KB | None | 0 0
  1. <?php
  2.  
  3. functio dump_tgm($version, $type = 'full', $platform = 'android', $year_celebration = '_2020') {
  4.     $url = 'http://mafia2cdn.yottagames.com/res/';
  5.     $uri = 'version_' . $platform . $version . $year_celebration '.json';
  6.     $final_url = $url . $uri;
  7.    
  8.     $options = array(
  9.     'http'  => array(
  10.                 'method' => "GET",
  11.                 'header' => "Access-language: en\r\n" .
  12.                             "User-Agent: " . // i.e. An iPad
  13.                                 "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) " .
  14.                                 "AppleWebKit/531.21.10 (KHTML, like Gecko) " .
  15.                                 "Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n"
  16.                 )
  17.     );
  18.  
  19.     $context = stream_context_create($options);
  20.     $version_json = file_get_contents($final_url, false, $context);
  21.     $version_data = json_decode($version_json);
  22.    
  23.     $download_type = 0 + $argv[1];
  24.  
  25. foreach($version_data->resources as $resource) {
  26.     echo    'Type: ' . $resource->type .
  27.             ' | Size: ' . $resource->size .
  28.             ' | Path: ' . $resource->path . PHP_EOL;
  29.  
  30.     $uri = $resource->res . '.' . $resource->md5;
  31.     $file_data = file_get_contents($url . $uri, false, $context);
  32.  
  33.     switch($download_type) {
  34.         default:
  35.         case 'full':
  36.             $download_type = 0;
  37.             _file_put_contents($resource->path, $file_data);
  38.             break;
  39.  
  40.         case 'res':
  41.         case 'resource':
  42.             if(!str_contains($resource->path, '.lua'))
  43.                 _file_put_contents($resource->path, $file_data);
  44.             break;
  45.  
  46.         case 'lua':
  47.         case 'luajcode':
  48.             if(str_contains($resource->path, '.lua'))
  49.                 _file_put_contents($resource->path, $file_data);
  50.             break;
  51.     }
  52. }
  53.  
  54. foreach($version_data->resources as $resource) {
  55.     if(str_contains($resource->path, '.lua')) {
  56.         echo 'Type: ' . $resource->type .
  57.             ' | Path: ' . $resource->path .
  58.             ' | Size: ' . $resource->size . PHP_EOL;
  59.  
  60.         $uri = $resource->res . '.' . $resource->md5;
  61.         $file_data = file_get_contents($url . $uri, false, $context);
  62.  
  63.         _file_put_contents($resource->path, $file_data);
  64.     }
  65. }
  66.  
  67. /**
  68.  * Create file with content, and create folder structure if doesn't exist
  69.  * @param String $filepath
  70.  * @param String $message
  71.  */
  72. function _file_put_contents($filepath, $message){
  73.     try {
  74.         $isInFolder = preg_match("/^(.*)\/([^\/]+)$/", $filepath, $filepathMatches);
  75.         if($isInFolder) {
  76.             $folderName = $filepathMatches[1];
  77.             $fileName = $filepathMatches[2];
  78.             if (!is_dir($folderName)) {
  79.                 mkdir($folderName, 0777, true);
  80.             }
  81.         }
  82.         file_put_contents($filepath, $message);
  83.     } catch (Exception $e) {
  84.         echo "ERR: error writing '$message' to '$filepath', ". $e->getMessage();
  85.     }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment