def dump_section_locations(filepath, dump_suffix=""):

    name = filepath.name
    #name = name[:-4] if name.endswith(".map") or name.endswith(".sav") else name

    from sourcehold import load_map

    with open(f"sections_dump.{name}{dump_suffix}.txt", 'w') as f:
        memdump = process.read_all_memory()

        m = load_map(filepath)
        datas = {
            i: m.directory[i].get_data()
            for i in m.directory.section_indices if i != 0
        }

        f.write(f"section\toffsets\tactual offsets\n")

        for si, data in datas.items():
            offs = memory_find(data, memdump)
            hexoffs = [hex(v) for v in offs]
            hexactualoffs = [hex(v + process.base) for v in offs]

            f.write(f"{si}\t{hexoffs}\t{hexactualoffs}\n")
            f.flush()
    def test_dump_to_folder(self):
        m = load_map("resources/map/crusader/MxM_unseen_1.map")
        m.unpack(True)

        tempdir = tempfile.TemporaryDirectory()

        path = tempdir.name

        m.dump_to_folder(path)
        tempdir.cleanup()
    def test_load_from_folder(self):
        map = load_map("resources/map/crusader/MxM_unseen_1.map")
        map.unpack(force=True)

        tempdir = tempfile.TemporaryDirectory()

        path = tempdir.name

        map.dump_to_folder(path)

        map2 = Map().load_from_folder(path)
        map2.pack(True)
        map2.serialize_to_buffer(Buffer())

        tempdir.cleanup()
Beispiel #4
0
    def test_tile_index_translator(self):

        m = load_map(pathlib.Path("resources") / "map" / "crusader" / "xlcr.map")

        ts = m.directory.sections[0].get_system()

        tit = TileIndexTranslator(square_size=400)
        self.assertEqual(tit.translate_file_index_to_game_tile_index(0, 0), 199)
        self.assertEqual(tit.translate_game_tile_index_to_file_index(199), (0, 0))

        r = random.randint(0, (400*400)-1)
        r = 54464
        titi, titj = tit.translate_game_tile_index_to_file_index(r)
        ts.get_tile_number_for_index((titi, titj))


        self.assertEqual((0, 199), ts.get_index_for_tile_number(0, True))
        ts.get_tile_number_for_index((0, 0))

        self.assertEqual(m.directory.sections[0].get_system().get_tile_number_for_index((2, 199), True), 8)
        self.assertEqual(12, m.directory.sections[0].get_system().get_tile_number_for_index((3, 0), False))
        self.assertEqual(12, m.directory.sections[0].get_system().get_tile_number_for_index((3, 196), True))
        self.assertEqual(12, m.directory.sections[0].get_system().get_tile_number_for_index((3, 196), True))
Beispiel #5
0
import pathlib

from sourcehold import expand_var_path, load_map
from sourcehold.debugtools.memory.common.access import AccessContext
process = AccessContext()

# Number of maps: 7 * 2
map_files = [
    load_map(expand_var_path(f"shcusermap~/m{i}.map")) for i in range(1, 16)
]
dumps = [
    b''.join(section.get_data() for section in p.directory.sections)
    for p in map_files
]
#dumps.append(process.read_all_memory())

# section 1023, and section 1085 are the primary two candidates, focus the dumps on that:
dumps = [p.directory[1023].get_data() for p in map_files]

equality_matrix = [
    # unit type:     1   2   3   4   5   6   7
    [1, 1, 1, 1, 1, 1, 1],  # map 1
    [1, 0, 1, 1, 1, 1, 1],  # map 2
    [1, 1, 0, 1, 1, 1, 1],  # map 3
    [1, 1, 1, 0, 1, 1, 1],  # map 4
    [1, 1, 1, 1, 0, 1, 1],  # map 5
    [1, 1, 1, 1, 1, 0, 1],  # map 6
    [1, 1, 1, 1, 1, 1, 0],  # map 7
    [1, 0, 0, 1, 1, 1, 1],  # map 8
    [1, 1, 1, 0, 0, 1, 1],  # map 9
    [1, 1, 1, 1, 1, 0, 0],  # map 10
Beispiel #6
0
from sourcehold import SHC_FILES, load_map, expand_var_path

map = load_map(SHC_FILES.get_all_map_paths()[0])

map2 = load_map(expand_var_path("shcmap~/Close Encounters.map"))
map2 = load_map(expand_var_path("shcusermap~/Close Encounters.map"))
def load_save(mapname):
    return load_map(expand_var_path("shcusersav~/" + mapname + ".sav"))
Beispiel #8
0
        if not args.out:
            args.out = str(pathlib.Path().absolute())


if args.subparser_name == "file":
    input_files = getattr(args, "in")

    if args.unpack and args.pack:
        raise Exception("Cannot unpack and pack at the same time")

    if args.unpack:
        for file in input_files:

            path = pathlib.Path(file)
            map = load_map(file)

            name = path.name
            name = name.split(".")[0]

            if args.what != "all":
                if args.what.isnumeric():
                    section = args.what
                    what = map.directory[int(section)].get_data()
                    what_name = section
                else:
                    what_elements = [p for p in args.what.split("/") if p]
                    obj = map

                    wel = what_elements
Beispiel #9
0
            args.out = str(pathlib.Path().absolute())

if args.debug:
    print(args)

if args.subparser_name == "file":
    input_files = getattr(args, "in")

    if args.unpack and args.pack:
        raise Exception("Cannot unpack and pack at the same time")

    if args.unpack:
        for file in input_files:

            path = pathlib.Path(file)
            map = load_map(file)

            name = path.name
            name = name.split(".")[0]

            if args.what != "all":
                if args.what.isnumeric():
                    section = args.what
                    what = map.directory[int(section)].get_data()
                    what_name = section
                else:
                    what_elements = [p for p in args.what.split("/") if p]
                    obj = map

                    wel = what_elements
Beispiel #10
0
        # write_to_file("{}/{}.spec".format(destination, index), dump_spec(d))


from sourcehold import palette
from sourcehold.iotools import read_file, write_to_file
from sourcehold.maps.sections.tools import cut_strict, TiledDiamondSystem

hexformat = "#{0:02x}{1:02x}{2:02x}"
datumhexformat = "{:016x}"
datumintformat = "{:16d}"
hexform = "{:02x}"

import argparse

parser = argparse.ArgumentParser(
    description="Export images of imageable map sections")
parser.add_argument("src", help="unpacked map folder", nargs=1)
parser.add_argument("dst", help="destination folder for images", nargs=1)

import sys

from sourcehold import load_map

if __name__ == "__main__":
    args = parser.parse_args(sys.argv[1:])

    if args.src[0].endswith(".map") or args.src[0].endswith(".sav"):
        export_images_from_map(load_map(args.src[0]), args.dst[0])
    else:
        export_images(args.src[0], args.dst[0])