Batch file to launch Civ4BtS

kcwong

Emperor
Joined
Jan 31, 2002
Messages
1,108
Location
Hong Kong
I made this batch script, so that I don't need to have a dozen of shortcuts on my desktop to launch Civ4BtS with mods.

I'll post it here, and if you find it useful... well, use it! ;)

Instructions

1. Copy all the text in the following spoiler tag.
Spoiler :
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

:Setup
SET MOD_DIR="Mods"
SET CMD_LINE=Civ4BeyondSword.exe
SET MOD_LINE= -mod=
SET PARAM=

:ChooseMod
CLS
SET INDEX=1
SET CHOICE=
ECHO ============= Available Mods =============
FOR /F "tokens=*" %%i IN ('DIR %MOD_DIR%\*. /b /on') DO (
ECHO [!INDEX!] - %%i
SET OPTION_!INDEX!=%%i
SET /A INDEX+=1
)
ECHO ==========================================
ECHO [-] - Start without mod
ECHO [X] - Exit
ECHO ==========================================
SET /P CHOICE=Choose mod:

:CheckChoice
IF "%CHOICE%"=="" GOTO :ChooseMod
IF "%CHOICE%"=="X" GOTO :End
IF "%CHOICE%"=="x" GOTO :End
IF "%CHOICE%"=="-" GOTO :LaunchCiv
SET /A NUMBER=%CHOICE%
IF /I %NUMBER% LEQ 0 (
GOTO :ChooseMod
)
IF /I %NUMBER% GEQ %INDEX% (
GOTO :ChooseMod
)

:SetCmdLine
ECHO Launching !OPTION_%NUMBER%!...
SET PARAM=%MOD_LINE%"!OPTION_%NUMBER%!"

:LaunchCiv
START /B %CMD_LINE% %PARAM%

:End
ENDLOCAL

2. Open Notepad and paste.
3. Click File Menu, Save.
4. In the dialog box, there's a "Save as type" box. Select "All Files" in it.
5. In the "File name" box, type "Civ4BtS.cmd".
6. In the above, browse to your Civ4BtS folder, where your Civ4BeyondSword.exe is.
7. Save the file there.
8. On your desktop, right-click and select New, then Shortcut.
9. Browse to the Civ4BtS.cmd file you just created. Press OK and then Next.
10. Give it a name, e.g. "Civ4BtS". Click Finish.
11. Now the shortcut you created with have a very ugly icon. We're going to change it. Right-click on it, and select Properties.
12. Press the Change Icon button. It will prompt you that the file contains no icon. Press OK.
13. Browse to CivBeyondSword.exe. Select one of the icons displayed, and press OK.

And that's it. Now you can double-click the shortcut, and you will see this:
Spoiler :
cmdeh3.jpg


Type an option, and press Enter. Civ4BtS will then launch with the mod you selected. Press "x" to exit without launching, and "-" to launch without any mod.

The script dynamically generates the list when you run it, so you will never need to make changes when you add a new mod. The list of mods is sorted by name.
 
I had thought about posting it in general... but it's a tech support related thing - people would ask here about how they could launch Civ with a mod loaded wouldn't they? :ack:

Also Fetus told me that it won't work if you're running the Steam version. Steam has its own UI for adding commandline parameters, and Steam doesn't like batch files - it won't add a .cmd or .bat file into its list of shortcuts.

Edit: If this is in the wrong place, then let's hope a mod will drop by and move it... :worship:
Also this is my 777th post here! Yay!
 
I always wondered why they didn't follow the model that Morrowind did, where you can select the mods to run before actually starting the game.

Hell, that would have made running multiple mods together easy. Firaxis kinda dropped the ball on IV.
 
Well... my batch file does that, just without a nice graphical interface. If you insist on a graphical interface, it would be extremely easy to make one.
 
Well, I could modify my batch to include vanilla and warlords easily (will even fetch the installation directories from registry)... but since it's already done, there's no need to re-invent the wheel. :)
 
I used AutoHotKey to make a launcher for Civilization IV.

Features:
- It launches Civilization IV with the selected module
- Supports Civilization IV (vanilla), Warlords and Beyond the Sword
- Supports Steam version of Civilization IV
- Saves your last played game version and module, and they will be automatically selected next time.

Known Issues:
- I do not have the application ID for Steam Warlords, and thus you cannot launch Steam Warlords with the launcher. If you have the Steam version of Warlords, please let me know. :help:

Screenshot:
image1rg9.jpg


If you have Steam installed, you will see this instead.
image1zc0.jpg


Installation:
You can either:
1) You can download the zip file I attached in this post. Extract it anywhere you want, and make a shortcut to it.
2) Install AutoHotKey, and launch/compile the script (provided below) yourself, since downloading an .exe file is always a security risk.

Usage:
1) Double click the shortcut you've made.
2) Select game version in the first drop down list.
3) Select a module in the second drop down list.
4) If you have Steam, a "Launch Steam Version" checkbox will appear and checked by default.
5) Press the Launch button.
6) The selected game will start with the specified module. The launcher will then terminate.
7) After the first launch, "Civ4Launcher.ini" will be created. It stores the game and module you last played.
[Launcher]
GameVersion=Sid Meier's Civilization 4 - Beyond the Sword
Mod=Fall from Heaven 2 025
Steam=1

Source code (save them into a .ahk file):
Spoiler :
; Sid Meier's Civilization 4 Launcer

; Version
VERSION := 1.0

; INI
INI_FILE := "Civ4Launcher.ini"
INI_SECTION := "Launcher"
INI_VERSION := "GameVersion"
INI_STEAM := "Steam"
INI_MOD := "Mod"

; Civ4 registry keys
ROOT_KEY := "SOFTWARE\Firaxis Games\"
CIV4_KEY := "Sid Meier's Civilization 4"
WARLORDS_KEY := "Sid Meier's Civilization 4 - Warlords"
BEYONDTHESWORD_KEY := "Sid Meier's Civilization 4 - Beyond the Sword"
STEAM_KEY := "SOFTWARE\Valve\Steam"

; Executable names
CIV4_EXE := "Civilization4.exe"
WARLORDS_EXE := "Civ4Warlords.exe"
BEYONDTHESWORD_EXE := "Civ4BeyondSword.exe"
STEAM_EXE := "Steam.exe"

; Steam application IDs
STEAM_APP_CIV4 := 3900
STEAM_APP_WARLORDS := 0 ; Who knows what Steam Warlords' application ID is?
STEAM_APP_BEYONDTHESWORD := 8800

; Constants
FLAG_YES := 1
FLAG_NO := 0
DIRECTORY_KEY := "INSTALLDIR"
STEAM_DIRECTORY_KEY := "InstallPath"
MOD_DIRECTORY := "\Mods"
MOD_SWITCH := "-mod="
STEAM_APP_SWITCH := "-applaunch "
STEAM_MOD_SWITCH := "-mod="
SLEEP_AMOUNT := 1500
DROPDOWNLIST_WIDTH := 300
BUTTON_WIDTH := 100
VERSION_LIST_SIZE := 3
MOD_LIST_SIZE := 10
PIPE := "|"

; Display messages
MSG_WITHOUT_MOD := "- Start Without Module -"
MSG_SELECT_GAME := "- Select Game Version -"
MSG_GAME_NOT_FOUND := "- Sid Meier's Civilization IV not found -"
MSG_GAME_VERSION_ERROR := "Error: Invalid game version specified."
MSG_LAUNCH_ERROR := "Error: Cannot launch Civilization IV"

; Variable for directories
StreamDirectory :=
Civ4Directory :=
WarlordsDirectory :=
BeyondTheSwordDirectory :=

; Read registry
RegRead, SteamDirectory, HKEY_LOCAL_MACHINE, %STEAM_KEY%, %STEAM_DIRECTORY_KEY%
RegRead, Civ4Directory, HKEY_LOCAL_MACHINE, %ROOT_KEY%%CIV4_KEY%, %DIRECTORY_KEY%
RegRead, WarlordsDirectory, HKEY_LOCAL_MACHINE, %ROOT_KEY%%WARLORDS_KEY%, %DIRECTORY_KEY%
RegRead, BeyondTheSwordDirectory, HKEY_LOCAL_MACHINE, %ROOT_KEY%%BEYONDTHESWORD_KEY%, %DIRECTORY_KEY%

; Read list of mods available for each version
InstalledVersions =
Civ4ModListString = %MSG_WITHOUT_MOD%
If (StrLen(Civ4Directory) > 0) {
Loop, %Civ4Directory%%MOD_DIRECTORY%\*., 2, 0
{
Civ4ModListString = %A_LoopFileName%|%Civ4ModListString%
}
InstalledVersions = %InstalledVersions%|%CIV4_KEY%
}
WarlordsModListString = %MSG_WITHOUT_MOD%
If (StrLen(WarlordsDirectory) > 0) {
Loop, %WarlordsDirectory%%MOD_DIRECTORY%\*., 2, 0
{
WarlordsModListString = %A_LoopFileName%|%WarlordsModListString%
}
InstalledVersions = %InstalledVersions%|%WARLORDS_KEY%
}
BeyondTheSwordModListString = %MSG_WITHOUT_MOD%
If (StrLen(BeyondTheSwordDirectory) > 0) {
Loop, %BeyondTheSwordDirectory%%MOD_DIRECTORY%\*., 2, 0
{
BeyondTheSwordModListString = %A_LoopFileName%|%BeyondTheSwordModListString%
}
InstalledVersions = %InstalledVersions%|%BEYONDTHESWORD_KEY%
}
; Remove first pipe
If (SubStr(InstalledVersions, 1, 1) = PIPE) {
InstalledVersions := SubStr(InstalledVersions, 2)
}
If (StrLen(InstalledVersions) = 0) {
InstalledVersions = %MSG_GAME_NOT_FOUND%
}

; Read preference
IniRead, SavedVersion, %INI_FILE%, %INI_SECTION%, %INI_VERSION%, %A_Space%
IniRead, SavedMod, %INI_FILE%, %INI_SECTION%, %INI_MOD%, %A_Space%
IniRead, SavedSteam, %INI_FILE%, %INI_SECTION%, %INI_STEAM%, 0

; Create UI for user to select game and mod
Gui, Add, DropDownList, vGameVersion R%VERSION_LIST_SIZE% Choose1 W%DROPDOWNLIST_WIDTH% Section gVersionChanged, %InstalledVersions%
Gui, Add, DropDownList, vMod R%MOD_LIST_SIZE% Sort Choose1 W%DROPDOWNLIST_WIDTH% xs
Gui, Add, Button, Default W%BUTTON_WIDTH% Section ys gLaunch, &Launch
Gui, Add, Button, W%BUTTON_WIDTH% xs gExit, E&xit
If (StrLen(SteamDirectory) > 0) {
Gui, Add, CheckBox, vUseSteam Checked Section xm, Launch Steam Version
}
GoSub VersionChanged

; Restore preferences
GuiControl, ChooseString, GameVersion, %SavedVersion%
GoSub VersionChanged
GuiControl, ChooseString, Mod, %SavedMod%
If (SavedSteam = FLAG_YES) {
GuiControl,, UseSteam, 1
} else {
GuiControl,, UseSteam, 0
}

; Ready... show window
Gui, Show, AutoSize Center, Sid Meier's Civilization IV Launcher %VERSION%
Return

VersionChanged:
; With changes in game version, update mod list
Gui, Submit, nohide
If (GameVersion = CIV4_KEY) {
GuiControl,, Mod, |%Civ4ModListString%
GuiControl, Choose, Mod, 1
} else if (GameVersion = WARLORDS_KEY) {
GuiControl,, Mod, |%WarlordsModListString%
GuiControl, Choose, Mod, 1
} else if (GameVersion = BEYONDTHESWORD_KEY) {
GuiControl,, Mod, |%BeyondTheSwordModListString%
GuiControl, Choose, Mod, 1
} else {
GuiControl,, Mod, |%MSG_WITHOUT_MOD%
}
Return

Exit:
Gui, Destroy
ExitApp

Launch:
; Save changes and destroy window
Gui, Submit
Gui, Destroy
Execute :=
Switch :=
; Determine executable and commandline to use
If (UseSteam = FLAG_YES) {
Execute = "%SteamDirectory%\%STEAM_EXE%"
} else {
if (GameVersion = CIV4_KEY) {
Execute = "%Civ4Directory%\%CIV4_EXE%"
} else if (GameVersion = WARLORDS_KEY) {
Execute = "%WarlordsDirectory%\%WARLORDS_EXE%"
} else if (GameVersion = BEYONDTHESWORD_KEY) {
Execute = "%BeyondTheSwordDirectory%\%BEYONDTHESWORD_EXE%"
} else {
; Error... shouldn't happen as it's from a list
MsgBox %MSG_GAME_VERSION_ERROR%
ExitApp
}
}
If (Mod = MSG_WITHOUT_MOD) {
Gui, Add, Text,, Launching %GameVersion%
} else {
Gui, Add, Text,, Launching %GameVersion% with mod %Mod%
If (UseSteam = FLAG_YES) {
AppID :=
if (GameVersion = CIV4_KEY) {
AppID = %STEAM_APP_CIV4%
} else if (GameVersion = WARLORDS_KEY) {
AppID = %STEAM_APP_WARLORDS%
} else if (GameVersion = BEYONDTHESWORD_KEY) {
AppID = %STEAM_APP_BEYONDTHESWORD%
} else {
; Error... shouldn't happen as it's from a list
MsgBox %MSG_GAME_VERSION_ERROR%
ExitApp
}
Switch = %STEAM_APP_SWITCH%%AppID% %STEAM_MOD_SWITCH%"%Mod%"
} else {
Switch = %MOD_SWITCH%"%Mod%"
}
}
; Save preference
IniWrite, %GameVersion%, %INI_FILE%, %INI_SECTION%, %INI_VERSION%
IniWrite, %Mod%, %INI_FILE%, %INI_SECTION%, %INI_MOD%
IniWrite, %UseSteam%, %INI_FILE%, %INI_SECTION%, %INI_STEAM%

; Display message and launch
Gui, Show
Run, %Execute% %Switch%,, UseErrorLevel
Sleep SLEEP_AMOUNT
Gui, Destroy
If (ErrorLevel) {
MsgBox %MSG_LAUNCH_ERROR% (Error code: %A_LastError%)
}
ExitApp

GuiClose:
ExitApp
 
Back
Top Bottom