$parseDurationString = ""; $debug = 0; if ($_POST['debug'] == 1 || $_POST['test'] == 1) { echo sprintf("<b>Debugging is on.</b><br />\n"); $debug = 2; } $a = new MPQFile($tmpname, true, $debug); $init = $a->getState(); if (isset($_POST['test']) && $_POST['test'] == 1) { if (class_exists("SC2Replay") || (include 'sc2replay.php')) { //$bool = $a->insertChatLogMessage("testing testing", "testguy", 1); //$bool = $a->insertChatLogMessage("testing 2", 1, 5); //$a->saveAs("testfile.SC2Replay", true); //$a = new MPQFile("testfile.SC2Replay", true, 2); $byte = 0; $b = new SC2Replay($a); $b->setDebug(true); $tmp = $b->parseDetailsValue($a->readFile("replay.details"), $byte); echo "<pre>"; var_dump($tmp); echo "</pre>"; die; } } if ($init == false) { echo "Error parsing uploaded file, make sure it is a valid MPQ archive!<br />\n"; } else { if ($a->getFileType() == "SC2replay") { echo sprintf("Version: %s<br />\n", $a->getVersionString()); $b = $a->parseReplay(); $parseDurationString .= sprintf("Parsed replay in %d ms.<br />\n", (microtime_float() - $start) * 1000);
public function insertChatLogMessage($newMessage, $player, $time) { if (!$this->init || $this->getFileSize("replay.message.events") == 0) { return false; } if (!is_numeric($player)) { return false; } else { $playerId = $player; } if ($playerId <= 0) { return false; } if ($this->getFileSize("replay.message.events") == 0) { return false; } $string = $this->readFile("replay.message.events"); $numByte = 0; $time = $time * 16; $fileSize = strlen($string); $messageSize = strlen($newMessage); if ($messageSize >= 256) { return false; } $totTime = 0; $haveMessage = false; while ($numByte < $fileSize) { $pastHeaders = true; $start = $numByte; $timestamp = SC2Replay::parseTimeStamp($string, $numByte); $pid = self::readByte($string, $numByte); $nopcode = self::readByte($string, $numByte); $totTime += $timestamp; if ($nopcode == 0x80) { $numByte += 4; $pastHeaders = false; } elseif (($nopcode & 0x80) == 0) { // message $messageTarget = $opcode & 3; $messageLength = self::readByte($string, $numByte); if (($nopcode & 8) == 8) { $messageLength += 64; } if (($nopcode & 16) == 16) { $messageLength += 128; } $message = self::readBytes($string, $numByte, $messageLength); $haveMessage = true; } elseif ($nopcode == 0x83) { // ping on map? 8 bytes? $numByte += 8; } $end = $numByte; if ($pastHeaders && $totTime >= $time) { $opcode = 0; if ($messageSize >= 128) { $opcode = $opcode | 16; $messageSize -= 128; } if ($messageSize >= 64) { $opcode = $opcode | 8; $messageSize -= 64; } break; } } $nFrames = $time - ($totTime - $timestamp); $frameNum = SC2Replay::createTimeStamp($nFrames); $newMessageTS = ""; for ($i = $frameNum[1] - 1; $i >= 0; $i--) { $newMessageTS .= pack("C", ($frameNum[2] & 0xff << $i * 8) >> $i * 8); } $messageString = $newMessageTS . pack("C3", $playerId, $opcode, $messageSize) . $newMessage; $width = 0; if ($haveMessage) { // $haveMessage is true if there is at least one chatlog message. $nextMessageTS = ""; $newTimeStamp = SC2Replay::createTimeStamp($timestamp - $nFrames); // calculate new timestamp for the messages following the inserted one for ($i = $newTimeStamp[1] - 1; $i >= 0; $i--) { $nextMessageTS .= pack("C", ($newTimeStamp[2] & 0xff << $i * 8) >> $i * 8); } $messageString .= $nextMessageTS . pack("C3", $pid, $nopcode, $messageLength) . $message; $width = $end - $start; } $newData = substr_replace($string, $messageString, $start, $width); $this->replaceFile("replay.message.events", $newData); return true; }
function parseReplay() { if ($this->init !== MPQFILE_PARSE_OK) { if ($this->debug) { $this->debug("Tried to use parseReplay without initializing"); } return false; } if (class_exists("SC2Replay") || (include 'sc2replay.php')) { $tmp = new SC2Replay(); if ($this->debug) { $tmp->setDebug($this->debug); } $tmp->parseReplay($this); return $tmp; } else { if ($this->debug) { $this->debug("Unable to find or load class SC2Replay"); } return false; } }