# Given game version 1.27.1, how to effectively inject a common Jass script snippet into every map of a custom campaign?
## Problem
I intend to make a custom campaign for a legacy version of the game (1.27.1). The most critical problem at the moment for me is to make a chunk of my Jass script available for every map in my campaign. I could not come up with a satisfactory solution myself, so I ask here how to do it.
## Motivation
Most importantly, I want the scripts for my custom spells to be easily packaged with the campaign. Less important, but still desireable, to share helper functions and such, and simultaneously keep those separated from map-specific scripts.
I used to manually open every map and insert the code into the "custom scripts" section of the trigger editor. This approach is extremely error prone and time consuming. It won't do if I am ever making another campaign.
## What was tried so far
Here is how I approached the problem before asking here.
Create a skeleton campaign file (w3n) with native World Editor.
Use an MPQ editor. I tried the following implementations (backend):
- WinMPQ (SFmpq.dll);
- smpq (libstorm);
- Ladik's MPQ Editor (libstorm);
- jmpq3 (jmpq3)
Extract all map files. Patch all the map files by replacing "war3map.j" script in each extracted file map with purposefully modified ones (that much is trivial). Finally, patch the campaign file by replacing every original map file that is contained in the campaign archive with the patched map files. Fail.
Patching map files works as intended, even if it's much clunkier than I hoped. Individual maps, patched in this manner, given they are executed without the campaign archive, are parsed by the game as expected. The problem is that the patched campaign file produces fatal errors at runtime and is not recognized by the game.
In other words, I can patch scripts in maps, but I cannot patch map files in campaign.
Each MPQ editor tool I tried fails slightly differently. But the gist of it, no matter what options I choose, it never produces the desired result. It all ends at a fatal runtime error of some form or another. libstorm backend produces error message when the map is selected in campaign screen reading "corrupted file". SFmpq backend hangs to a black screen without any message before the campaign screen even shows. With certain configurations MPQ editors refuse to modify the campaign archive to begin with. smpq "single-unit" option does nothing. WinMPQ "embedded mpq" seems like it's intended for something else, I couldn't even figure out how that feature works.
The other approach I though about is patching the game MPQ archive by replacing their Blizzard.j file. I would rather avoid this. It seems less maintainable and more difficult to install for end users.
The last approach I thought of is patching map files without extracting them. For that I will probably need to write and compile my own program relying on the libraries. But it seems to me that it's the problem of the libraries themselves and not their front-ends. I might be missing some obvious configuration option, but I read up pretty much everything I could find on the topic and still can't produce a workable solution.
So, how do I inject my Jass script snippets into all my custom campaign maps automatically?
## Problem
I intend to make a custom campaign for a legacy version of the game (1.27.1). The most critical problem at the moment for me is to make a chunk of my Jass script available for every map in my campaign. I could not come up with a satisfactory solution myself, so I ask here how to do it.
## Motivation
Most importantly, I want the scripts for my custom spells to be easily packaged with the campaign. Less important, but still desireable, to share helper functions and such, and simultaneously keep those separated from map-specific scripts.
I used to manually open every map and insert the code into the "custom scripts" section of the trigger editor. This approach is extremely error prone and time consuming. It won't do if I am ever making another campaign.
## What was tried so far
Here is how I approached the problem before asking here.
Create a skeleton campaign file (w3n) with native World Editor.
Use an MPQ editor. I tried the following implementations (backend):
- WinMPQ (SFmpq.dll);
- smpq (libstorm);
- Ladik's MPQ Editor (libstorm);
- jmpq3 (jmpq3)
Extract all map files. Patch all the map files by replacing "war3map.j" script in each extracted file map with purposefully modified ones (that much is trivial). Finally, patch the campaign file by replacing every original map file that is contained in the campaign archive with the patched map files. Fail.
Patching map files works as intended, even if it's much clunkier than I hoped. Individual maps, patched in this manner, given they are executed without the campaign archive, are parsed by the game as expected. The problem is that the patched campaign file produces fatal errors at runtime and is not recognized by the game.
In other words, I can patch scripts in maps, but I cannot patch map files in campaign.
Each MPQ editor tool I tried fails slightly differently. But the gist of it, no matter what options I choose, it never produces the desired result. It all ends at a fatal runtime error of some form or another. libstorm backend produces error message when the map is selected in campaign screen reading "corrupted file". SFmpq backend hangs to a black screen without any message before the campaign screen even shows. With certain configurations MPQ editors refuse to modify the campaign archive to begin with. smpq "single-unit" option does nothing. WinMPQ "embedded mpq" seems like it's intended for something else, I couldn't even figure out how that feature works.
The other approach I though about is patching the game MPQ archive by replacing their Blizzard.j file. I would rather avoid this. It seems less maintainable and more difficult to install for end users.
The last approach I thought of is patching map files without extracting them. For that I will probably need to write and compile my own program relying on the libraries. But it seems to me that it's the problem of the libraries themselves and not their front-ends. I might be missing some obvious configuration option, but I read up pretty much everything I could find on the topic and still can't produce a workable solution.
So, how do I inject my Jass script snippets into all my custom campaign maps automatically?