Skip to content

Instantly share code, notes, and snippets.

@Talv
Last active April 30, 2023 23:12
Show Gist options
  • Save Talv/b3b35580464bc29a8cd97819f9010ce3 to your computer and use it in GitHub Desktop.
Save Talv/b3b35580464bc29a8cd97819f9010ce3 to your computer and use it in GitHub Desktop.
sc2 maps cache list
#!/usr/bin/python
import re
import glob
from mpyq import MPQArchive
# CACHE_DIR = '/home/kk/.wine/drive_c/users/Public/Application Data/Blizzard Entertainment/Battle.net/Cache'
CACHE_DIR = 'C:\ProgramData\Blizzard Entertainment\Battle.net\Cache'
class SC2Map(object):
def __init__(self, filename):
self.mpq = MPQArchive(filename)
header = self.mpq.read_file('DocumentHeader')
if not header:
raise ValueError
self.mapName = re.search(
b'DocInfo\/Name.{5}\x00([^\x00]+)',
header,
re.DOTALL
).group(1)[:-1]
def main():
for filename in glob.iglob('%s/**/*.s2ma' % CACHE_DIR, recursive=True):
try:
m = SC2Map(filename)
print(m.mapName)
print(filename)
print('')
# break
except ValueError:
continue
if __name__ == '__main__':
main()
# it will list maps in following pattern:
#
# b'Eras Mod File'
# C:\ProgramData\Blizzard Entertainment\Battle.net\Cache\04\80\0480cd5bee0390b4436ed2a5816d0badcda268e57e5d4505f1c2cb42c4fe58ca.s2ma
#
# b'Empire Builder 2'
# C:\ProgramData\Blizzard Entertainment\Battle.net\Cache\05\5d\055d626fff669e52286b7d8223e3a322e4873934d498986361f636b47dfb98f2.s2ma
@munks
Copy link

munks commented Apr 30, 2023

for stability:

        self.mapName = re.search(
            b'DocInfo\/Name.{5}\x00([^\x00]+)',
            header,
            re.DOTALL
        ).group(1)[:-1]

could be replace to

        mnobj = re.search(b'DocInfo\/Name.{5}\x00([^\x00]+)',
            header,
            re.DOTALL
        )
        if mnobj is None:
            raise ValueError
        self.mapName = mnobj.group(1)[:-1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment