Exemplo n.º 1
0
 /**
  * @param Modification $mod
  * @return void
  */
 private function applyModification(Modification $mod)
 {
     // First get the map for this modification
     $map = $mod->getMap();
     // Get the selected setting
     $setting = $mod->getSetting();
     // Get all ranges and iterate through them
     $ranges = $map->getRanges();
     foreach ($ranges as $range) {
         // Define start and end of the range
         $rangeStart = hexdec($range->getStart());
         $rangeEnd = hexdec($range->getEnd());
         // Iterate through every single position within the range
         for ($offset = $rangeStart; $offset <= $rangeEnd; $offset++) {
             // Hex represantation of our decimal offset
             $hexOffset = str_pad(dechex($offset), 5, '0', STR_PAD_LEFT);
             // Seek to offset position
             fseek($this->_patchedFile, $offset);
             // Check if the setting contains a value for this position
             if ($setting->hasValueAtOffset($hexOffset)) {
                 $value = $setting->getValue($hexOffset);
                 fwrite($this->_patchedFile, pack('H*', $value->getValue()));
                 continue;
             }
             // Setting does not contain a value for this position, so
             // we'll write the value of the original file from this position
             fseek($this->_originalFile, $offset);
             fwrite($this->_patchedFile, fread($this->_originalFile, 1));
         }
     }
 }