Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('memory_limit', '900M');
- ini_set('display_errors', '1');
- // set here the valid ranges for all coordinates
- $min_x = -5000;
- $max_x = 5000;
- $min_y = -5000;
- $max_y = 5000;
- $min_z = -5000;
- $max_z = 5000;
- if (!isset($argv[1])) die('Usage: php find_locs.php <filename>');
- $file = $argv[1];
- /////////////////////////////////////
- print "\r\nXSC positions in $file (floats separated by 0x29):\r\n";
- $data = file_get_contents($file);
- if ($data === false) die('Cannot open file');
- $total = strlen($data);
- $offset = 0;
- while (($total - $offset) >= 15)
- {
- check_valid_xsc_loc($data, $offset);
- $offset++;
- }
- /////////////////////////////////////
- print "\r\nBulk positions in $file (consequtive floats):\r\n";
- $handle = fopen($file, "r");
- if ($handle === false) die('Cannot open file');
- $x = NAN;
- $y = NAN;
- $z = NAN;
- while (($x !== false) && ($y !== false) && ($z !== false))
- {
- if (is_valid_loc($x, $y, $z))
- {
- printf("%.4f, %.4f, %.4f\r\n", $x, $y, $z);
- $x = NAN;
- $y = NAN;
- $z = NAN;
- }
- $x = $y;
- $y = $z;
- $z = read_float($handle);
- }
- fclose($handle);
- function read_float($handle)
- {
- $dword = fread($handle, 4);
- if ($dword === false) return false;
- if (strlen($dword) != 4) return false;
- return parse_float($dword);
- }
- function parse_float($dword)
- {
- return array_pop(unpack("f", strrev($dword)));
- }
- function check_valid_xsc_loc($data, $offset)
- {
- if ($data[$offset] != "\x29") return false;
- if ($data[$offset+5] != "\x29") return false;
- if ($data[$offset+10] != "\x29") return false;
- $x = parse_float(substr($data, $offset+1, 4));
- $y = parse_float(substr($data, $offset+6, 4));
- $z = parse_float(substr($data, $offset+11, 4));
- if (is_valid_loc($x, $y, $z))
- {
- printf("%.4f, %.4f, %.4f\r\n", $x, $y, $z);
- return true;
- }
- return false;
- }
- function is_valid_loc($x, $y, $z)
- {
- global $min_x;
- global $max_x;
- global $min_y;
- global $max_y;
- global $min_z;
- global $max_z;
- if ($x === false) return false;
- if (!is_finite($x)) return false;
- if ($x > $max_x) return false;
- if ($x < $min_x) return false;
- if (abs($x) < 0.1) return false;
- if ($x == 1) return false;
- if ($x == -1) return false;
- if ($y === false) return false;
- if (!is_finite($y)) return false;
- if ($y > $max_y) return false;
- if ($y < $min_y) return false;
- if (abs($y) < 0.1) return false;
- if ($y == 1) return false;
- if ($y == -1) return false;
- if ($z === false) return false;
- if (!is_finite($z)) return false;
- if ($z > $max_z) return false;
- if ($z < $min_z) return false;
- if (abs($z) < 0.1) return false;
- if ($z == 1) return false;
- if ($z == -1) return false;
- return true;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment