BtS Mod Install Script


Mar 1, 2003
BtS Mod Install Script with Icon and optional Add On scripting
BtS Mod Install Script with Icon scripting
BtS Mod Install Script
BtS Mod Patching Script

To use these scripts download and install the free program NSIS installer, found here:

What these Scripts do:

The install scripts make it so any person can simply double click on the .exe you create and automatically installs your mod. No complex instructions for people wanting to use your mod. More importantly, it automatically creates optional shortcuts to launch your mod from the desktop and Start Menu. So that people wol't need to decide to change their main ini file, or load the mod at each start up. They can simply click on the desktop shortcut it creates to launch your mod. The Icon Script includes scripting so that you can make your setup installer have a unique icon, the shortcuts that lauch the mod will also use the icon (looks professional :)). In addition to these functions the Optional Add On script includes scripting so that you may include optional Add Ons along with the installation of your mod.

The install scripts include Uninstall scripting, so that when you update to a full new version, the previous version of your mod is automatically uninstalled before installation. This is to remove old files that may conflict, as happens when mods are updated on occasion. Also just makes things neat and tidy. If this is the first time you use one of these installers, have your users install twice to remove the old version (it triggers off of the regkey the installer writes, and uses the uninstaller it creates, if you haven't used the script before, neither of these exist yet, they are created on the first install. --On the second install everything in the mod folder will be removed as per the uninstall script, removing any left over files from previous versions). After the uninstaller finishes removing old files, the installation procedes to install the mod.

The patch script is set up to simply patch a mod to a higher version.


-Download the script you would like to use. Read the script's directions on the download page.
-Download & Install NSIS installer program (free program)
-Follow the instructions for the script
-Load the script in NSIS, and run it

These have been updated and are now well commented as of the 4th of July 2009. The 4th of July updates to the scripting code streamline and improve the uninstaller, especially for icons, where the original scripting did not link the icons correctly to shortcuts. So if you are using prior versions of the script it is recommended you update.

You will need no knowledge of coding to use these, anyone that is computer proficient enough to make a mod for Civ4, even a simple XML mod, should be able to follow the directions and use these scripts with ease. Well the optional Add On script is slightly more complex, you might need rudimentary coding knowledge to use it or at the very least good common sense.

Thanks to John Elcard for supplying the original template script, and Snarko for helping me on IRC to get this thing working way back in the day, when this was confusing stuff to me. Also thanks to NikNaks for updating the script with more functionality (Optional Add ons and icon scripting, though I had to clean up some of his code ;))
Updated to new version. Now includes uninstaller scripting, and will automatically remove old versions (provided it has already installed once with the uninstall information--If you start using this and want it to uninstall a previous version for your users before this script was used, just have them install it twice).

When it's done compiling, NSIS gives a warning, something about MUI header text. I can't find any error in the code though, and all the text and fuctions work fine (used this script and checked it 3 times now). So I have no idea what the warning is about, but the script still works with no problems.
Added patching script so that modmakers who use this script can release patches that easy install, without triggering the Uninstaller that is in the main Mod installer script.

Also has anyone used either of these?
Yeah, I can't use the BTS registry key to find the files for compression. I tried using the BTSREGKEY, and various ways the script uses this to install to the correct path when the installer runs to install. But when the script is compiling, and looking for the files to compress, I can't use this. So for you, and other modmakers that have a different path (foriegn language/vista etc.) in which your mod is in, you need to adjust this, along with the name of your mod:
  !define NAME "MYMODNAME"
  !define VERSION "X.X.X"
  !define MOD_NAME "MYMODNAME"  ;Example for WolfRevolution this is the same, so I use ${NAME} here, but if you call your mod something different then the name of the folder, note this here.

  !define BTSREGKEY "SOFTWARE\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword"

  !define MYBTSDIR "[B]C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword[/B]"
  !define MYCLSDIR "[B]C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword[/B]\Mods\${MOD_NAME}"

Just change the bolded part of the script to the path that your mod is found in, and it should work. Let me know if it doesn't work, it should, I can't see how it wouldn't.
Ah, I see, you want the Text displayed to be printed in german as well as english? Yeah, I don't know how to do that. Sorry. I bet it's pretty simple though, I know NSIS supports multiple languages, you'd have to browse the NSIS installer information pages, I had to do alot of that to get this script working, lol. But yeah, I'd like to support other languages, but it's not at the top of my list of things to do.... That said if you do get another language supported on this script, please release it, I'd update this one with the bilingual functionality.
No, that's not the problem, atm my installer text is in english.

The problem is, that i would need 1 installer, which would install the mod on english windows versions in the C:\program files\...path, but on german computers in the C:\Programme\...path, and it seems, that it can't be done with this script :(.
Are you sure? The installation should follow the registry on the machine it installs on, it should install wherever BtS has been assigned to, regardless of language or operating system. So long as BTS has signed itself on the Registry key, the installation should follow that path, weather it be program or programme. I see nothing in the script that should limit it. The install directory is defined here:

  ;Default installation folder
  InstallDir ""

  ;Get installation folder from registry if available

I tried to use this to locate the files to compress though, but it wouldn't let me, the MYCLSDIR & MYBTSDIR have to be set manually if they are different.

Anyway, I've never had anyone say the installation failed, and I'm pretty sure there have been a few foriegn users of it with the WolfRevolution that would have let me know if the installation failed.
Okay, i've tested it now, it works.
Compressionrate is like with WinZip :).

My problem was, that i didn't change MYBTSDIR and MYCLSDIR :blush:.

I'll use it, when i upload the next version of my mod :).

I wonder, if it could also be used for patchs. Do you use it for patchs, or do you think, that it can be used?
There are two scripts there. One is for patching, the other is for full versions. The full version one signs the mod to the registry and creates an uninstaller. It also is set up so that when the mod is reinstalled, ie you up the version#, it automatically uninstalls the previous version. The patch version does niether of these things, and simple adds/overwrites files from a previous version. You need to move your full mod from it's folder, and put the patching files in the folder where your mod usually is (following the same pathing structure as your main mod) when compiling the patch script, as it basically uses the same script as the full install version and thus finds and compresses the mod and it's files from it's normal folder (the only difference is that the patching version does not trigger or create an uninstall)
Hey no problem, thanks for bringing up the issue that the script doesn't follow the regkey when searching for the files to compress when it compiles, I didn't realize this until you brought it up, so hopefully that makes this script useable for more folks, as now they know to change the MYBTSDIR and MYCLSDIR paths when using this script.
Ok, I'm trying to use this for my Native America add-on for VD, but it throws out an error at line 64 (the uninstall part) when I try to compile:
Spoiler :
MakeNSIS v2.44 - Copyright 1995-2009 Contributors
See the file COPYING for license details.
Credits can be found in the Users Manual.

Processing config: 
Processing plugin dlls: "C:\Program Files\NSIS\Plugins\*.dll"
 - AdvSplash::show
 - Banner::destroy
 - Banner::getWindow
 - Banner::show
 - BgImage::AddImage
 - BgImage::AddText
 - BgImage::Clear
 - BgImage::Destroy
 - BgImage::Redraw
 - BgImage::SetBg
 - BgImage::SetReturn
 - BgImage::Sound
 - Dialer::AttemptConnect
 - Dialer::AutodialHangup
 - Dialer::AutodialOnline
 - Dialer::AutodialUnattended
 - Dialer::GetConnectedState
 - InstallOptions::dialog
 - InstallOptions::initDialog
 - InstallOptions::show
 - LangDLL::LangDialog
 - Math::Script
 - NSISdl::download
 - NSISdl::download_quiet
 - Splash::show
 - StartMenu::Init
 - StartMenu::Select
 - StartMenu::Show
 - System::Alloc
 - System::Call
 - System::Copy
 - System::Free
 - System::Get
 - System::Int64Op
 - System::Store
 - TypeLib::GetLibVersion
 - TypeLib::Register
 - TypeLib::UnRegister
 - UserInfo::GetAccountType
 - UserInfo::GetName
 - UserInfo::GetOriginalAccountType
 - VPatch::GetFileCRC32
 - VPatch::GetFileMD5
 - VPatch::vpatchfile
 - nsDialogs::Create
 - nsDialogs::CreateControl
 - nsDialogs::CreateItem
 - nsDialogs::CreateTimer
 - nsDialogs::GetUserData
 - nsDialogs::KillTimer
 - nsDialogs::OnBack
 - nsDialogs::OnChange
 - nsDialogs::OnClick
 - nsDialogs::OnNotify
 - nsDialogs::SelectFileDialog
 - nsDialogs::SelectFolderDialog
 - nsDialogs::SetRTL
 - nsDialogs::SetUserData
 - nsDialogs::Show
 - nsExec::Exec
 - nsExec::ExecToLog
 - nsExec::ExecToStack


Changing directory to: "C:\Coding\Civ\New Civs\Native America"

Processing script file: "C:\Coding\Civ\New Civs\Native America\BtSModInstallScript.nsi"
!include: "C:\Program Files\NSIS\Include\MUI2.nsh"
!include: "C:\Program Files\NSIS\Contrib\Modern UI 2\MUI2.nsh"
NSIS Modern User Interface version 2.0 - Copyright 2002-2009 Joost Verburg (C:\Program Files\NSIS\Contrib\Modern UI 2\MUI2.nsh:8)
!define: "MUI_INCLUDED"=""
!define: "MUI_SYSVERSION"="2.0"
!define: "MUI_VERBOSE"="3"
!include: closed: "C:\Program Files\NSIS\Contrib\Modern UI 2\MUI2.nsh"
!include: closed: "C:\Program Files\NSIS\Include\MUI2.nsh"
!define: "NAME"="Native America Expanded for VD 5.1"
!define: "VERSION"="2.0"
!define: "MOD_NAME"="Varietas Delectat"
!define: "MOD_LOC"="Native America"
!define: "BTSREGKEY"="SOFTWARE\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword"
!define: "MYBTSDIR"="C:\Games\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword"
!define: "MYCLSDIR"="C:\Games\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Native America"
Name: "Varietas Delectat"
OutFile: "Native America Expanded for VD 5.1 v2.0.exe"
InstallDir: ""
InstallRegKey: "HKLM\SOFTWARE\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword\INSTALLDIR"
Var: "CurrentPage"
Function: ".onInit"
ReadRegStr $R0 HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Varietas Delectat\UninstallString
StrCmp "$R0" "" equal=done, nonequal=
MessageBox: 49: "Native America Expanded for VD 5.1 is already installed. 

Click `OK` to remove the previous version or `Cancel` to cancel this upgrade." (on IDOK goto uninst)
Abort: ""
Exec expects 1 parameters, got 2.
Usage: Exec command_line
Error in script "C:\Coding\Civ\New Civs\Native America\BtSModInstallScript.nsi" on line 64 -- aborting creation process
No clue why. I've happily changed my BtS location to where it is and my files are where the script says they should be (although I have defined it to be somewhere slightly different), and yet I get this error. Have you seen this before?
I just :dunno: I just tested it again, and can't replicate the error. Since you said you defined things slightly differently, I tried having the script run by compiling the mod if I place it on the desktop and it fails, not sure why, but it does... But it throws an error in a different part. Btw, that's a really odd spot to get an error, as line 64 is a blank line:

;Run the uninstaller
  Exec $INSTDIR\Mods\${MOD_NAME}\uninstall.exe
;This is where line 64 is

Yeah, I thought it looked odd. However, I added another variable to the top, so my 64 will be 63 (the Exec $INST... line). Do you think where the script itself is run from has anything to do with it? I have it in a folder a way away from where the mod itself is.
No, i run the script from the desktop. That's a pretty simple line too, you can probably read it as well as I can, all it's saying is "Run the the Uninstaller.exe in the folder, if you find one" ie, uninstall old version, it's pretty straightforward. The only thing I think could be causing an error is if you've moved the mod outside of it's expected path and are compiling from there (ie you've moved it from ...program files/.../mods/ ) This uninstall part of the script is being told to apply to a spot it's not expecting to fire from and so you get an error, this part of the script is definatly following the reg key though, so it shouldn't be machine specific, and I can't see why it would fail at all, so long as the compiler detects a BTSRegKey on your computer. Other then that, I can't think of anything that could cause an error on that line. I suppose it's possible that your NSIS version is missing a key definition or something, maybe it doesn't understand the uninstall execute command? I don't know why that would be the case, I use the same NSIS version that's found on sourceforge as anyone else, and I'd assume you are as well.
Aha! It was a simple matter of placing quotation marks around the folder after "exec". Perhaps they've changed the syntax in a more recent version. Everything else is working perfectly, so thanks! :goodjob:

I have a few questions, too. I'm not too worried if you don't know the answers, but it'd but the icing on the proverbial cake for my little installer. If there are some reference guides for NSIS, I'd love to see those, too.
  • Can you set up a custom icon for the desktop shortcut?
  • Is there a way to split the mod into two parts, one of which is required by default, with the other being an optional add-on?
  • (This is the toughest one) Can the installer be made to detect a pre-existing mod and abort if it's not found? My mod is for VD 5.1, so if it isn't there, I don't want people to install it and not understand why it doesn't work. If there's no way of doing this, could I put a text warning in somehow?
Top Bottom