function ProcessGameDataDir($root, $path = '') { global $gamedata_files, $gamedata_data; $entries = glob(MergePath($root, $path, "*")); foreach ($entries as $entry) { $entry_path = MergePath($path, basename($entry)); // var_dump("ep: {$entry_path}, pgd: {$entry}"); if (is_dir($entry)) { ProcessGameDataDir($root, $entry_path); } if (substr(basename($entry), -4) == ".txt") { $gamedata_files[$entry_path] = parseKeyValues(file_get_contents(MergePath($root, $entry_path))); // var_dump($gamedata_files[$entry_path]); $gamedata_data = theater_array_replace_recursive($gamedata_data, $gamedata_files[$entry_path]); } } }
function ParseTheaterFile($filename, $version = '', $path = '', $collapse_conditionals = true) { global $custom_theater_paths, $newest_version, $theaterpath, $rootpath; if ($version == '') { $version = $newest_version; } // If file exists at $path, use that as the path. // Next, try the specified theater path for this file // Finally, try the stock theaters for the current version $filepath = file_exists("{$path}/" . basename($filename)) ? $path : (file_exists("{$theaterpath}/" . basename($filename)) ? $theaterpath : "{$rootpath}/data/theaters/{$version}"); $filepath .= "/" . basename($filename); $data = file_get_contents($filepath); $thisfile = parseKeyValues($data); $bases = isset($thisfile["#base"]) ? (array) $thisfile["#base"] : array(); $basedata = array(); //If the theater sources another theater, process them in order using a merge which blends sub-array values from bottom to top, recursively replacing. //This appears to be the way the game processes these files it appears. if (count($bases)) { foreach ($bases as $base) { $basedata = merge_theaters($basedata, ParseTheaterFile($base, $version, $path, $collapse_conditionals)); } $theater = merge_theaters($basedata, $thisfile["theater"]); } //Include parts that might be conditional in their parents, basically put everything in flat arrays //This isn't congruent with how the game handles them, I believe this ougght to be a selector in the UI that can handle this better if ($collapse_conditionals) { foreach ($theater as $sec => $data) { foreach ($data as $key => $val) { if ($key[0] == '?' && is_array($val)) { unset($theater[$sec][$key]); $theater[$sec] = $val; //theater_array_replace_recursive($theater[$sec],$val); } } } } return $theater; }
/* This will parse the playlist files and produce a user-friendly list of what each playlist does. It will pull data from the cvarlists to get friendly names and information about the variables. */ $title = "Insurgency Playlist Parser"; $tableclasses = "table table-striped table-bordered table-condensed table-responsive"; require_once "include/header.php"; $dirs = glob("data/playlists/*"); foreach ($dirs as $dir) { $versions[] = basename($dir); } asort($versions); $newest_version = $version = end($versions); if ($_REQUEST['version']) { if (in_array($_REQUEST['version'], $versions)) { $version = $_REQUEST['version']; } } $version_compare = $version; if ($_REQUEST['version_compare']) { if (in_array($_REQUEST['version_compare'], $versions)) { $version_compare = $_REQUEST['version_compare']; } } $data = array(); $files = rglob("data/playlists/{$version}/*.playlist"); foreach ($files as $file) { $data = array_merge_recursive($data, parseKeyValues(file_get_contents($file))); } var_dump($data);
<?php include "include/functions.php"; include "vdf.php"; include "vdfparser.php"; $file = "data/maps/src/buhriz_coop_d.vmf"; $data = file_get_contents($file); //$data = preg_replace('/^(\s*)([a-zA-Z]+)/m','${1}"${2}"',$data); $out = parseKeyValues($data); //VDFParse($file); //vdf_decode($data); var_dump($out);
function ParseTheaterFile($filename, $mod = '', $version = '', $path = '', &$base_theaters = array(), $depth = 0) { //var_dump("ParseTheaterFile",$filename,$mod,$version,$path,$base_theaters,$depth); global $custom_theater_paths, $newest_version, $latest_version, $theaterpath, $datapath, $steam_ver, $mods; if ($version == '') { $version = $newest_version; } $basename = basename($filename); if (file_exists($filename)) { $filepath = $filename; } else { if (file_exists("{$path}/{$filename}")) { $filepath = "{$path}/{$filename}"; } else { $filepath = GetDataFile("scripts/theaters/{$basename}", $mod, $version); } } $base_theaters[$basename] = md5($filepath); $sniproot = "{$GLOBALS['rootpath']}/theaters/snippets/"; $snipfile = str_replace($sniproot, "", $filepath); if ($snipfile != $filepath) { $cachefile = "theaters/snippets/" . str_replace("/", "_", "{$snipfile}"); //var_dump($sniproot,$snipfile,$snippath,$cachefile); } else { $cachefile = "theaters/{$mod}/{$version}/{$basename}"; } // Attempt to load file from cache $cachedata = GetCacheFile($cachefile); if (isset($cachedata['base'])) { // Check all files for MD5 foreach ($cachedata['base'] as $file => $md5) { if ($file == $basename) { $filemd5 = $base_theaters[$basename]; } else { $bfpath = GetDataFile("scripts/theaters/{$file}", $mod, $version); $filemd5 = md5($bfpath); } // If a component file is modified, do not use the cache. if ($filemd5 != $md5) { //var_dump("md5 no match for {$file} - {$filemd5} != {$md5}"); $cachedata['theater'] = ''; break; } } } if (!is_array($cachedata['theater'])) { //var_dump("processing {$filename}"); // Load raw theater file $data = file_get_contents($filepath); // Parse KeyValues data $thisfile = parseKeyValues($data); //var_dump($thisfile); // Get theater array // If the theater sources another theater, process them in order using a merge which blends sub-array values from bottom to top, recursively replacing. // This appears to be the way the game processes these files it appears. if (isset($thisfile["#base"])) { $basedata = array(); // Create an array of base files if (is_array($thisfile["#base"])) { $bases = $thisfile["#base"]; } else { $bases = array($thisfile["#base"]); } // Merge all base files into basedata array foreach ($bases as $base) { //var_dump("base {$base}"); $base_file = GetDataURL("scripts/theaters/{$base}", $mod, $version); $cachedata['base'][$base] = md5($base_file); if (in_array($base, array_keys($base_theaters)) === true) { continue; } $base_theaters[$base] = $cachedata['base'][$base]; //var_dump("processing base {$base}"); $basedata = array_merge_recursive(ParseTheaterFile($base, $mod, $version, $path, $base_theaters, $depth + 1), $basedata); } // Merge this theater on top of combined base $cachedata['theater'] = theater_array_replace_recursive($basedata, $thisfile['theater']); } else { $cachedata['theater'] = $thisfile["theater"]; } /* // Include parts that might be conditional in their parents, basically put everything in flat arrays // This isn't congruent with how the game handles them, I believe this ougght to be a selector in the UI that can handle this better foreach ($cachedata['theater'] as $sec => $data) { foreach ($data as $key => $val) { if (($key[0] == '?') && (is_array($val))) { unset($cachedata['theater'][$sec][$key]); $cachedata['theater'][$sec] = $val;// theater_array_replace_recursive($cachedata['theater'][$sec],$val); } } } */ // Save cache data //var_dump($cachedata); PutCacheFile($cachefile, $cachedata); } // Send back theater object return $cachedata['theater']; }
<pre><?php $name = 'data/maps/src/amber_spirits_coop_d.vmf'; if (file_exists($name)) { echo "Converting {$name}\n"; } else { die("ERROR: File not found, aborting.\n"); } $vmfString = file_get_contents($name); if (!preg_match('/^(world|versioninfo)\\b/', $vmfString)) { die("ERROR: Invalid file loaded, aborting.\n"); } $vmf = parseKeyValues($vmfString); var_dump($vmf); exit; /* $map = exportVMFasMAP($vmf, $extend_map); $gsc = exportVMFasGSC($vmf); $newmap = str_replace(".vmf", ".map", $name); $newgsc = str_replace(".vmf", ".gsc", $name); file_put_contents($newmap, $map); echo("Writing $newmap\n"); file_put_contents($newgsc, $gsc); echo("Writing $newgsc\n"); die("SUCCESS: Converting completed.\n"); */ function parseKeyValues($vmfString, $debug = false) { $len = strlen($vmfString); if ($debug) { $len = 2098;
} } } //var_dump($return); return $return; } // Display map if selected if ($map) { // Load gametype data $gametypes = array_keys($maps[$map]['gametypes']); // Display map overview $img = GetMaterial($maps[$map]['overview']['material'], 'bare'); echo "\t\t\t\t\t\t<img src='{$img}' class='map-image' id='map-image' alt='{$map}' style='z-index: 0;'/><br />\n"; // Include overlays if they exist if (file_exists("{$datapath}/maps/overlays/{$map}.txt")) { $data = parseKeyValues(strtolower(file_get_contents("{$datapath}/maps/overlays/{$map}.txt"))); foreach ($data as $layername => $layerdata) { foreach ($layerdata as $pname => $pdata) { if ($pdata['pos_name'] == '') { $pdata['pos_name'] = $pname; } $map_objects[$layername][] = $pdata; } } } // Set navmesh to map name by default $navmesh = $map; $types = array('ins_spawnzone' => 'spawn', 'trigger_capture_zone' => 'cap', 'ins_blockzone' => 'block'); foreach ($maps[$map]['gametypes'] as $gtname => $gtdata) { // Skip theater conditions if ($gtname == 'theater_conditions') {