Mount&Blade Mod Installer Script v1.5
for NSIS, tested with v2.10 - 2.14
by Brett Flannigan (aka Janus)

Ok, you've downloaded this mod installer script because you're interested in having a nifty installer for your Mount&Blade mod. Don't be daunted by the size of this document, it's just quite thorough in an attempt to cover everything you should need to know. The process is pretty simple. 
As long as your mod is contained within a subfolder of the Modules folder, this script will be very easy for you to use. If your mod needs to install files elsewhere as well, feel free to modify this script for your own uses. If you'd like some help adapting it, I can probably help you out with modifying it. Just send me a PM on the Taleworlds forums (to Janus), or e-mail me at repository@fenrisoft.com.

What This Script Actually Does
This script will create a fairly robust standalone installer for your mod, which will automatically detect the Mount&Blade folder and be easy for the end user of your mod to install. For an example, the current latest version of my Arena Expansion Mod uses this script, as does the Hundred years War mod and a few others.
If you want a complete rundown of everything it does, skip down towards the bottom of the file for a rundown of the steps it goes through.

Preparation
Ok, first things first, you will need to have a folder for this process. If you have your mod set up in the Modules folder already and plan to include every file (including SCO files in the SceneObj folder, as well as the Textures, Resource, and Sounds folders if you've added them), all you need to do is unzip everything included in this zip file into that folder.
If you plan to exclude SCO or other files (such as map.txt), or have only SCO files (such as the old Project Detail Props mod), you should make a new empty staging folder for this purpose instead. Just copy the files you want to include to this new folder, keeping the folder structure intact for "SceneObj", "Textures", "Sound", and "Resource" if you plan to include them. Then unzip these files there.

Updating From Previous Versions
If you have not previously used an earlier version of this script, disregard this section.
It is easy to update to the new version. You can simply copy each of the lines you changed at the top of the old script to the new version; copying the entire first section over is acceptable.

Download the Tools
Now then, let's make sure you have the needed tools to use this script. They are open source and absolutely free.

The one thing you absolutely need is the NSIS compiler, which can be downloaded at: http://nsis.sourceforge.net/Download/
An optional download, recommended if you plan to do more than basic editing of this script, is the one of the following tools:
HM NIS Editor: http://hmne.sourceforge.net/index.php#Download
Notepad++: http://notepad-plus.sourceforge.net/
This guide will not cover using HM NIS Editor or Notepad++, as they are unecessary for what the guide covers.

Of course another "tool" is the script include in this file. You can get the latest version from my Mount&Blade Unofficial File Repository site here: http://www.mbrepository.com/

Go ahead and run through the installation process for NSIS once it's downloaded, installing all optional components when it gives you the option. This is important, since some of the optional components are required by this installer script. You can uncheck the "Run NSIS" option at the finish screen, there's no need to run it now.

Edit the Script
Now to get to the main editing you'll be doing. This section contains a lot of text, but you'll be doing very little. I just like to try to be thorough, so bear with me.
Go ahead and locate the file named "MnB Mod Installer Script 1.3.nsi" and double-click it to open it in notepad. You should now see mostly a bunch of lines at the top that start with "!define", which is what we'll be editing. You'll notice a lot of comments begun with a hash (#) symbol; this script is rather heavily commented if you do decide to mess with stuff in it that you probably shouldn't.

Ok, the first line we'll edit reads  !define PRODUCT_NAME "Amazing Stuff Mod". This is where the simple name of your mod goes, in place of "Amazing Stuff Mod"; in the case of my Arena Expansion Mod, this would be "Arena Expansion Mod" if you can believe it.

The line below that contains the default folder name to install to by. In place of "Amazing Stuff", mine is "Arena Expansion". You can use spaces in the folder name if you want since M&B is not bothered by them, though some people will prefer to stick the the "underscore in place of spaces" convention. It's up to you.

The next line contains the version of your mod, and defaults to "1.0". Quite simple, just change it to whatever version your mod is currently at.

After a blank line, you'll see  Name "${PRODUCT_NAME} ${PRODUCT_VERSION}". You can skip this, you don't need to edit it. This is the name of your mod given during the installation process, and defaults to the name of the mod you entered on the first line followed by the version number, i.e. "Amazing Stuff Mod 1.0".

The next line is  OutFile "amazing_stuff_mod_${PRODUCT_VERSION}.exe". When the installer executable is created, this is the filename it will have. Just replace the "amazing_stuff_mod" part of it with an internet-friendly name for your mod.

With that past us, let's move on the the line  !define README_FILE "readme.txt". This line points to the readme file for your mod, and will display a checkbox to "Show Readme" at the finish page of the installer. Just change "readme.txt" to the filename of your readme file if it's different. The installer should be able to open files other than simple text files, such as RTF documents or HTML files if you use them for your readme. Alternately, if you don't want to have the "Show Readme" option available on the finish page, you can comment out this line with a semicolon (";") at the very start of the line to disable that option.

Now then, the next line is  !define INSTALL_TEXT "installer.txt". This line points to the install notes file for your mod, which will be shown on the page right after the welcome screen in the installer. You'll notice an "installer.txt" file was included in this zip file with some default install notes. We'll get to them later. If you want this page to be skipped so the installer goes straight from the welcome screen to the directory choice screen, comment out this line with a semicolon.

Ok, time to set the icon your installer will use with the line  !define MUI_ICON "icons\knight-z8.ico".  You can use any valid ICO icon file, though this zip file includes a few to choose from (in the icons folder). You can browse the icons folder to see which one it is pointing to, and change "icons\knight-z8.ico" to point to another icon.

The next line is almost identical,  !define MUI_UNICON "icons\knight-z6.ico". This is the icon file for the uninstaller that will be created for your mod. It can be the same icon as for the installer, or a different one. Be careful here though, as the installer creation will fail if the two icons are not the exact same format. Some icon files include just 32x32 and 16x16 versions, some also include up to 128x128, and some have the sized images stored in a different order in the ICO file. All icons included in this zip file should be compatible with one another.

You will see next a section titled "Optional Graphics". You can safely skip this section completely if you're not worried about customizing the look of the installer. The first line ;!define MUI_WELCOMEFINISHPAGE_BITMAP "welcome.bmp" defines the image shown on the left side of the welcome and finish pages. You must remove the ";" at the start of the line to enable it. You can change "welcome.bmp" to the filename of any valid BMP (bitmap, output by the Windows Paint program among others) in the installer's folder. The BMP image should be sized 164 (width) by 314 (height). The second line ;!define MUI_HEADERIMAGE_BITMAP "header.bmp" defines the small image shown at the top left corner of all pages between welcome and finish. Like the other line, this one must have the ";" removed to be enabled, and must refer to a valid BMP file. This second smaller image should be sized 150x57. If you uncomment one of these lines and the BMP file referenced by it isn't there or is invalid, the installer creation will fail completely, so be careful. 

The  !define CREATE_UNINSTALLER "no" line is next. This will determine whether an uninstaller is created for your mod in it's folder and appended to the Add/Remove Programs list in Windows. It defaults to "no" since an uninstaller shouldn't normally be necessary for your mod, and the Add/Remove Programs window will certainly load more slowly for each additional listing added.

Ok, you're basically done with the script. Not many lines to edit, eh? Everything below the lines we just edited should be left alone, unless you know what you're doing.
Save the file and close it.

Final Preparation and Installer Creation
Now let's look at the "installer.txt" file included. As said above, the contents of this text file will be displayed within the installer on the second page. If you disabled it in the script, you can skip this step. Open this file in notepad. You'll see some basic installation info. You can simply change the title at the top of the file to your mod's name and specify the version of Mount&Blade it's for. The other info can be changed to whatever you want displayed on the second screen of the installer, such as a disclaimer or special installation instructions. It's up to you.
Save and close the file when you're done with it.

We're almost ready to create the installer. Before we do so, here are some notes on the files it will add. It will skip over the script itself along with other NSI scripts, this readme file you are viewing, and the "installer.txt" file (it doesn't need it since it just reads the file's contents to create the installer). It will also skip over files with these extensions: EXE, ZIP, ICO, RAR, and BAK. It will not get files from any subfolders other than "SceneObj", "Resource", "Sounds", "Textures", and "Music", which it will skip if those folders aren't present. All other files within the folder will be added to your installer when it is created.

Ok, we'll go ahead and create the installer now and test it out. Right-click the "MnB Mod Installer Script 1.5.nsi" file. You should the option to "Compile NSIS Script". If this option doesn't show up, you should make sure you have NSIS installed. Go ahead and click this option. A new window will pop up titled "MakeNSISW" and the installer will be created. In this window it will show the creation process. If you get a warning message at the top or bottom of the screen but not a failure message, this is normally fine. It gives a warning if it finds no valid files in the main folder and/or within the SceneObj, Resource, Sounds, Textures, or Music folders. If you get a failure related to the icon, you probably selected two incompatible icons for the installer and the uninstaller.
Assuming you got no fatal error messages, it should finish and give you a "Close" button and "Test Installer" button at the bottom. Click "Close" since we'll test it ourselves in a second.

Now, in the folder with your other mod files, you should see a nice new installer executable. It will have a filename based on the one you set in the script, and it will have the icon you set above (or the default I had set, if you didn't change it). Go ahead and double-click your new installer and try it out.
The welcome page will show the basic installer intro from most any other installer, but with the title of your mod indicated. Click the Next button.
If you didn't disable the install notes in the script, you will see the file's text on this next page.
The next page will be the directory choice screen. The default directory is given by reading Mount&Blade's install directory from the Windows Registry, along with "\Modules\" and the folder name you chose for your mod in the script. This default should be perfect in almost every case. Now, for testing sake, try choosing another folder outside of the Modules folder. You'll notice the button to install is disabled until a subfolder of Modules is again indicated, to prevent installation to the wrong place. Note that it can install to another Mount&Blade Modules folder, if the person has it installed in more than one place (such as an older version they're keeping). Change the install directory back to something valid, but for testing sake, choose a folder that doesn't already exist; add a "2" at the end or something. I'm serious, choose a folder that doesn't exist; don't choose the folder you're working in. We'll test the uninstall process later, and you wouldn't want it to delete all your files, would you? Ok then, click the "Install" button.
This will take you to the actual installation process, with it's progress displayed on the page. Towards the start it will probably (depends on whether it thinks it might need them) copy over all files from the Native folder to your new mod folder to make sure it has all necessary files, and then it will install all your mod files. Assuming you had it install to a new folder and didn't disable the "copy native saved games" option, it will pop up a yes/no dialog asking if it should copy the Native saved games over. Answer it as you wish, though I recommend "No" for now since we'll be uninstalling it in a minute.
It will then be at the finish page. If you have a readme file and didn't disable that option, you will see a checked box for "Show Readme". Leave it checked and click Finish. Your readme file should then pop up.
Ok, it got through the install process, cool deal. Now then, unless it installed to the Native folder it will have created an uninstaller to remove your mod. Go to "Add/Remove Programs" in the Windows Control Panel, and look for your mod's name in the list. You'll see it has an entry like any regular program. Go ahead and uninstall it. It will walk you through the process as normal. The uninstall process will actually delete every file in the folder, and try to delete the folder for your mod as well. You should note that saved games for the mod are not deleted.
Well, now you've run all the way through the process and should know basically everything you need.

That's it, you should now have a nice installer for your mod. You can later update the script to reflect new versions of your mod, and otherwise just recompile the script for the new version. Simple for you, simple for the users of your mod. Enjoy!

(Somewhat) Detailed Script Process
Here you can see a step-by-step list of what the script does when it goes through the installation.
-Installer starts
-Registry is read to find the Mount&Blade directory. If it is not there, Mount&Blade isn't properly installed; in this case a warning message comes up indicating this, and the default directory ("Program Files\Mount&Blade") is used instead.
-Installation directory is set based on Mount&Blade directory and the folder name indicated in the first lines of the script
-Native directory is determined as well
-Welcome page is shown
-[Next] If install notes file was defined, the contents are displayed in a modified License Agreement page; otherwise, this screen is skipped
-[Next] Directory selection page, where user can select a folder other than default. Whenever it is changed, path is checked to make sure "Modules" folder is in-between two other folders (should be between M&B directory and folder for the mod). If not, the Install/Open buttons are disabled.
-[Install] Installation process begins. Path is checked to determine if path to Mount&Blade was changed (like if person had a second installation of it), and updates the working path stored for the M&B folder and Native folder to reflect this change if so.
-Installation folder for the mod is created if it doesn't already exist.
-Install folder is checked to see if it is the "Native" folder. If so, it skips past this section. If not, it does the following. It checks for the Installation directory's SceneObj folder; if no files exist there, it makes sure the SceneObj folder exists and then copies over all files from the Native folder.
-It then actually installs all of the mod files, first to the SceneObj subdirectory and then to the main installation directory. If Textures and Resource folders are included, it installs them before the files in the main folder as well.
-If mod is being installed to the Native folder, it skips creation of an uninstaller (as the uninstaller would delete the whole "Native" folder) and goes to the next step. If the CREATE_UNINSTALLER option is set to "no", it likewise skips creation of an uninstaller and continues with the next step. If the mod is being installed to it's own folder, an uninstaller executable is created and placed in the installation folder, and an entry for it is put in "Add/Remove Programs".
-The Finish page is displayed, indicating a successful install. If a readme file was specified in the top options, a checked box for "Show Readme" is available here.
-[Finish] The installer exits, having completed. If the "Show Readme" box was checked, the specified readme file will pop up.

Change List
1.5:
- Updated to include "Music" folder for use in M&B .800.
- Updated to not exclude BMP files, so the new .800 intro BMP image is included.
- Ability to have it copy over Native saved games was removed, since the savegame path is changed and it's unnecessary anyway.

1.4:
- Uninstaller creation changed to optional (set at top of file), and now defaults to not creating an uninstaller.

1.3:
- Updated to include "Sounds" folder for use in M&B .730+.

1.2:
- Added support for 2 optional graphics, one to be shown on the welcome/finish page and one for all pages in-between.
- Now files with the extension ORIG are skipped and not added to the installation; this file type is a backup created by the Unofficial Editor and is not needed by the end user. BMP files are also skipped.

1.1:
- Updated to support "Textures" and "Resource" folders if they exist (M&B v0.710), for installing new textures and meshes.
- If M&B folder couldn't be determined from registry, v1.0 would notify user and exit. Now it will just warn the user, then use the default installation path ("Program Files\Mount&Blade").
- installer.txt is updated with a bit more info on uninstallation and the like.

1.0:
Initial release.