• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to Externally Overwrite Map Data?

Status
Not open for further replies.
Looking at the Tools section, there's a race installer for the Creep Rebellion race which allows them to be installed on any map. I am interested to create a similar installer but I am at a loss on how to write over the map files with my version of the data (data is taken from Last Revolt [Techtree Contest #14] for those who are curious). The target map is assumed to be melee maps, though I don't care if people just want to plug it into their altered map, risk on them.

Since I work with C# and Unity, I found this stormlib for C# that might fit might need. But, since I have 0 ideas of how these files work, would be great if someone can shed some light on the process. I can also work with C++, but I rather not unless it is mandatory.

Thanks.
 
Level 18
Joined
Jan 1, 2018
Messages
728
You can use War3Net.IO.Mpq for this:
C#:
var originalArchive = MpqArchive.Open(path);
var mpqArchiveBuilder = new MpqArchiveBuilder(originalArchive);

foreach (var filePath in files)
{
    var mpqFile = MpqFile.New(File.OpenRead(filePath), filePath.SubString(...));
    mpqArchiveBuilder.AddFile(mpqFile);
}

mpqArchiveBuilder.SaveTo(...);

You can also use War3Net.Build.Core for its MpqArchiveBuilder extension method 'SaveWithPreArchiveData' to replace the 'SaveTo' method call, this will automatically find the war3map.w3i file and use it to create the .w3x header, though this is not needed for 1.31+ maps.

The MpqArchiveBuilder will give higher priority to new files when there's a conflict, so make sure you don't try to overwrite files like war3map.w3e from the original map.

You should also keep in mind simply adding/replacing files may not be enough, since the map script's main/config/etc methods are generated using war3map.w3i and other files. To regenerate these methods I also have the MapScriptBuilder class in War3Net.Build, though it'd be up to you to inject these updated methods into the existing map script.
 
Level 3
Joined
Dec 11, 2022
Messages
20
I have a similar issue. Share scripts among custom campaign maps

My purpose is to update script files in a map automatically. That much I did with smpq and some other tools.

Then I need to modify a campaign archive file, not just a map. Specifically, I need to replace a map file inside a campaign archive automatically, by compiling a program or using a CLI. And I just can't do it, no matter what tool I used. The campaign archive ends up corrupted in some way or another.

Is there some hash that the game checks for campaign archives? Where is it? I can't find it.
 
Level 18
Joined
Jan 1, 2018
Messages
728
Map and campaign files are not just an MPQ file, they have their own header as well. If the header are missing then the game can't read the w3m/w3x/w3n file.
For map files this header requirement was removed when the feature to save maps as folder was added, but i don't think the same was done for campaigns, so these still require the header.
Can't find the documentation in my bookmarks so I'll just link the source code where I implement writing this header: War3Net/CampaignInfoExtensions.cs at master · Drake53/War3Net
Note that this excludes the padding (the MPQ data offset must be a multiple of 512 bytes).
The w3n header is basically the same as w3m/w3x header (magic number + version number? (always 0?) + name + flags + max players), only difference is the flags, which can be the following for campaigns: War3Net/CampaignFlags.cs at master · Drake53/War3Net
 
Level 3
Joined
Dec 11, 2022
Messages
20
I produced headers for campaigns and maps successfully. The game file browser recognizes them.

The problem is that patching map files that are nested inside a campaign produces corrupted archives. I can't quite understand the mechanism behind this nesting. It appears in hexeditor and all MPQ editors that the map files are simultaneously: 1) added to campaign archive as any other imported or metadata file; 2) appended to campaign file in a way that the map header is visible in hexeditor and the map file isn't compressed.

#2 reminds me of the ability of MPQ archives to be appended to any other file with an offset that is then later fed to the MPQ editor to parse that particular part of the overall "owner" file. I think maps are somehow like this. I don't have the time to investigate right now, but I want to do it eventually.

 
Level 18
Joined
Jan 1, 2018
Messages
728
I produced headers for campaigns and maps successfully. The game file browser recognizes them.

The problem is that patching map files that are nested inside a campaign produces corrupted archives. I can't quite understand the mechanism behind this nesting. It appears in hexeditor and all MPQ editors that the map files are simultaneously: 1) added to campaign archive as any other imported or metadata file; 2) appended to campaign file in a way that the map header is visible in hexeditor and the map file isn't compressed.

#2 reminds me of the ability of MPQ archives to be appended to any other file with an offset that is then later fed to the MPQ editor to parse that particular part of the overall "owner" file. I think maps are somehow like this. I don't have the time to investigate right now, but I want to do it eventually.

Maps are added to a campaign the same way as any other file. Not sure what you see in hex editors that makes you think #2 is the case. Maybe you should share your campaign file so we can see what's wrong with it.
 
Level 3
Joined
Dec 11, 2022
Messages
20
I was just being retarded, I figured it out. The map file must be overwritten as a single unit and without compression. That's the only issue. It's just a matter of passing correct arguments to the MPQ tool. I use smpq, which is based on libstorm. I am sure Ladik's can do the same thing just as well.

+++What I was seeing in the hexeditor is that default zlib compression was stripping the map header when it patched the campaign archive.
 
Last edited:
Status
Not open for further replies.
Top