Get the map metadata.

def get_map(self):
        """Get the map metadata."""
        if self._cache['map']:
            return self._cache['map']
        map_id = self._header.scenario.game_settings.map_id
        instructions = self._header.scenario.messages.instructions
        size = mgz.const.MAP_SIZES.get(self._header.map_info.size_x)
        dimension = self._header.map_info.size_x
        custom = True
        name = 'Unknown'
        language = None
        encoding = 'unknown'

        # detect encoding and language
        for pair in ENCODING_MARKERS:
            marker = pair[0]
            test_encoding = pair[1]
            e_m = marker.encode(test_encoding)
            for line in instructions.split(b'\n'):
                pos = line.find(e_m)
                if pos > -1:
                    encoding = test_encoding
                    name = line[pos+len(e_m):].decode(encoding)
                    language = pair[2]
                    break

        # disambiguate certain languages
        if not language:
            language = 'unknown'
            for pair in LANGUAGE_MARKERS:
                if instructions.find(pair[0].encode(pair[1])) > -1:
                    language = pair[2]
                    break
        self._cache['encoding'] = encoding
        self._cache['language'] = language

        # lookup base game map if applicable
        if map_id != 44:
            if map_id not in mgz.const.MAP_NAMES:
                raise ValueError('unspecified builtin map')
            name = mgz.const.MAP_NAMES[map_id]
            custom = False

        # extract map seed
        match = re.search(b'\x00.*? (\-?[0-9]+)\x00.*?\.rms', instructions)
        seed = None
        if match:
            seed = int(match.group(1))

        # extract userpatch modes
        has_modes = name.find(': !')
        mode_string = ''
        if has_modes > -1:
            mode_string = name[has_modes + 3:]
            name = name[:has_modes]
        modes = {
            'direct_placement': 'P' in mode_string,
            'effect_quantity': 'C' in mode_string,
            'guard_state': 'G' in mode_string,
            'fixed_positions': 'F' in mode_string
        }

        self._cache['map'] = {
            'id': map_id if not custom else None,
            'name': name.strip(),
            'size': size,
            'dimension': dimension,
            'seed': seed,
            'modes': modes,
            'custom': custom,
            'zr': name.startswith('ZR@')
        }
        return self._cache['map']