ScenarioResizer - Resizing a Scenario done fairly easy!

Hey there.

Inspired by the Coop Campaigns by Albtertha94 I thought about enlarging a few of the maps to create extra space for and additional human player!
After digging arround in soem ancient aoe.heavengames.com threads I actually found a solution.
Reading and following the Editing Scenario Data is mandator to work with my little tool.
For my examples I use the “Scx1-04-The Battle of the Metaurus.aoescn” scenario!

  1. Follow the first page of the Tutorial! I work with the Zlibnoh Compressor/Decompressor
    It can also decompress and compress aoe DEs new .aoescn files.
    When working with non empty scenarios the first part of removing the first 28 bytes is a little bit different.
    We also need to delet the scenario introduction. But the you can farily easily recognice the “EC” start in the Hex file as soon as it only encodes gibberish.
Summary

After the successful operation you can now decompress the .aoescn to the .hex file.

In the hex file you can now search for “ÿÿÿ” or “9D FF FF FF” in HEX. There will be multiple versions of that. The one you are looking for will be followed by 8 byte where I don’t know what they are doing. But they have been added in the DE version and are not present in the legacy version.
After these the map size and the terrain data follows
In my case the mapsize is “90 00 00 00”
As the map is always squared it is follows by another “90 00 00 00”
After that terrain information is follows!
This is easily recognizable by the pattern of xx xx 00 as every tiles exists of 3 byte where the last one is always 00.

Summary

grafik

Now my script comes in! Note down the first byte of the map size! “90” in our case and delet everythink op to and including the map size!

Summary

grafik

After that the file should start with the terrain data.

Summary

grafik

Save this as another file so you still have the beginning of the file.
Open a commandline and execute either my .py python script or the compiled .exe as followed:

Map_ResizerV01.exe inputfile.hex outputfile.hex

Summary

The new file should be bigger! Otherwise you either decreased the size (not supported right now) or something went wrong!
grafik

Now we open the original .hex file we got from our uncompiler and paste everything up to and including the map size into the newly created .hex file.

Don’t forget to chane the map size from 90 to FF or what ever you expanded your map to! (You automatically override existing bytes when editiing in cygnus)

Summary

grafik

We now have everything back together to follow the 5. gage of the aoe.heavengames tutorial.

In short. You uncompress your newly expanded .hex file back to a .aoescn file.

Summary

Now you paste the bytes you deleted in the beginning back into your compressed files!
You save it, copy it into your scenarios folder and enjoy the enlarged map!

Summary

The black artefacts are a result of not matching elevation can easily be fixed by using the elevation tool!

Summary

Enjoy!

Download

More details:

While aoe.heavens only describes how to resize an empty map. I quickly learned that all existing tiles are all in one realy long list. That means just adding the added tiles at the end of the list will result in some quite bizzar looking artefacts.

Summary

Here each row of terrain is 5tiles to short. So formerly matching terrain moves forward by 5 tiles each east to north row!

Thats why I created a small python script that adds the additional tiles at the end of each row of terrain.

Summary

Further things to improve would be!

  1. Automatically detecting the start of the terrain data so less hex editing needs to be done by hand.

  2. Including the initial hex editing and uncompressing as well as compressing into the script so it will be a 1 command action to change the map size. To be more accessible for less tech savvy folks.

  3. Support map enlarging on the south to east or east to north axis.
    this is problematic right now as everything already placed gets the coordinates starting in the east corner. So adding terrain there with my current script would just shift the terrain unterneath all placed objects.

If you are more skilled in python than I am or you got a great idea please let me know as help is always appreciated.

python script:

Summary
# Map_Resizer V0.1 by DesAnderes!

import sys
import binascii
import os

# get the Paths
inputpath = sys.argv[1]
ouputpath = sys.argv[2]

# read .hex file
############ = binascii.hexlify(open(inputpath, "rb").read())

# determin old map size in hex
print("Please Enter the scenario maplenth in hex")
maplength = int(input(),16)
print("The maplenght is:  ", maplength)

# create a 2D array the size of the old map size i.e. FA = 250x250
maparray = [[""] * maplength for s in range(maplength)]

# number of byte per tile
splitindex = 6

# fill the 2D array with the corresponding tile information
i = 0
while i < maplength:
    j = 0 
    while j < maplength:
        maparray[i][j] = asciitosplit[splitindex - 6:splitindex]
        j += 1
        splitindex += 6
    i += 1
# save the remaining part of the file
remainingascii = asciitosplit[splitindex - 6:]

# determin output map size in hex
print("Please Enter the new maplenth in hex")
newmaplength = int(input(),16)

#create and 2D array the size of the new map i.e. FF = 255x255
# 060100 is the placeholder terrain: 06 = dirt; 01 = elevation 1; 00 = end of tile
newmaparray = [["060100"] * newmaplength for t in range(newmaplength)] 

"""  override the 2D array of the new and larger map with the information of
the original smaller map
i.e. Fill 250x250 from 255x255 with the existing data.
All rows and columns < 250 will keep the place holder terrain.
"""
i = 0
while i < maplength:
    j = 0 
    while j < maplength:
        newmaparray[i][j] = maparray[i][j]
        j += 1
    i += 1

#check if output file already exisits, if yes: deletes the file
if os.path.isfile(ouputpath):
    os.remove(ouputpath)

# creates and opens the output file
fo = open(ouputpath, mode = "wb")

# append the outputfile with the exisiting data
i = 0
while i < newmaplength:
    j = 0 
    while j < newmaplength:
        fo.write(binascii.a2b_hex(newmaparray[i][j]))
       # print(str(i) + " : " + str(j))
        j += 1
    i += 1
fo.write(binascii.a2b_hex(remainingascii))
fo.close()
2 Likes

Nice!, I will give it a shot once I have an opportunity.

1 Like

Very nice! However you can already do map resizing with rocknror addon without hex editing. Also all map sizes have been unlocked already, search the granary downloads section. You should post this tool on aoe heaven too.

1 Like

Awesome, didn’t know there was a tool that could already do that.
I stumbled across the custom size map downloads. But as I wanted to not delet the existing stuff, that isn’t an alternative for me right now.

The RockNRoR looks like an Awesome tool. But as far as I did read into this now. It’s not compatible with DE?

Yeah I created an account today. Had some problems as heavens didn’t like my password :sweat_smile:

1 Like

Yes rocknror can do many things, its very useful. But indeed not compatible with DE. The custom map sizes all work in DE, you can simply add them to the scenario directory.

1 Like

Yes I know that. But I wantes to enlarg existing Scenarios without losing everything thats already placed.so to say a resize and a copy!

Maybe the thread title does not tell what my tool is realy about?

It does, but hex editing is not for the average player, and difficult to understand. I think your resize tool has a place though and could be very useful for DE especialy. Rocknror has map copy function, probably easier to pick new map size and then paste your city or village, so you dont have to mess with weird numbers. Then port to DE.