Author: Socrates1984
Original Thread: Unpacking the Game in Linux (Ubuntu)

(Medieval 2: Total War)

Unpacking the Game in Linux (Ubuntu)
IntroductionThis is a tutorial on how to unpack the game in Linux. I am using Ubuntu (16.04 LTS), but I guess the procedure isn't very different in other distros.
When contacting Feral Interactive because the unpacker wasn't included in their version and mentioning the attempt to make the unpacker available I received this positive feedback:

The basic steps are the same as in the thread on how to unpack the game in Windows by Gigantus, but we have to do some things differently. If you want to know more about unpacking the game, its purpose and why it is useful, check this tutorial.

This guide assumes a SteamOS installation. What changes in the CD version of the game is probably only the folder paths, but if anyone tries it out and has any feedback, please share and I will update this post to include the information.

Moreover, this guide assumes you know how to download and install packages in Linux, so that won't be covered here.

Preparation
Spoiler Alert, click show to read: 

Downloading Files
First, we need the relevant files. The Windows files from Gigantus' tutorial are not suitable for Linux use, a full set of Linux adapted files in zipped format can be downloaded here.
Spoiler for Download Content
unpacker.exe
ReadMe.txt
unpack_all.bat
unpack_americas.bat
unpack_britannia.bat
unpack_crusades.bat
unpack_teutonic.bat
files_individual.bat
files_types.bat
Required programs
● A text editor
Spoiler Alert, click show to read: 
gedit, the default text editor in Ubuntu, works fine for the purpose of unpacking the game, but it is less user-friendly than geany, which has very helpful little features similar to Notepad++. Now, there is a version of Notepad++ for Linux, but it's underdeveloped, outdated and I have not tested it yet.

● WINE
Spoiler Alert, click show to read: 
If you are interested in running some of the Windows programs or you are interested in playing some Med2TW mods, you probably already know what this is. If not, shame on you.
Spoiler Alert, click show to read: 
Okay, to elaborate, this is what WINE is.
This link is a bit more technical, but necessary nonetheless.
And if you are feeling lazy, How to install and configure WINE is the absolute must-read. Even if you don't open the other two links, this one you have to open and read carefully, because it explains what version of WINE to install and most importantly how to configure it with WINEtricks, our next prerequisite program.
Just to clarify, installing WINE this way is not required per se for unpacking the game, but assuming you didn't already have it installed, this is as good time as any to install it properly.

● WINEtricks
Spoiler Alert, click show to read: 
This is the program to configure WINE. Otherwise WINE is more or less bare and in any case doesn't have full functionality and potential. Again, it is crucial to read the How to install and configure WINE link provided above, because, well, it worked great for me and I guess it will be the same for you.

● About unzipping
Spoiler Alert, click show to read: 
Of course you need to unzip the files that you downloaded from the Required Files section. You don't need unzip, unrar, 7zip or any program like that, because the default Archive Manager does it all.

Getting the Download into place
The default SteamOS installation for Linux doesn't include the unpacker.exe file (although it does include all the .pack files). Not only that; it doesn't even include the folder path where it would normally be put. Consequently, we will have to create one.

  • Go to .../Medieval II Total War/share/data folder and create a folder named tools.
  • Inside the newly created tools folder create a folder named unpacker.
  • Place the downloaded ZIP file into the newly created unpacker folder and extract it there


Unpacking Files
Spoiler Alert, click show to read: 

Choosing a BAT file
If you are looking to simply unpack the complete game or one of the campaigns then choose one of these files:

  • unpack_all.bat - unpacks the main game
  • unpack_americas.bat - unpacks the individual campaign
  • unpack_britannia.bat - unpacks the individual campaign
  • unpack_crusades.bat - unpacks the individual campaign
  • unpack_teutonic.bat - unpacks the individual campaign

Restricted unpacking
The unpacker cannot handle the extracting of complete folders, but it is possible to restrict unpacking to individual files or types of files.

Individual Files
The files_individual BAT file contains as example the export_descr_units.txt file of the main game. This can be altered to extract other individual files from other packs as well.
Example provided:

Code:
unpacker.exe --source=..\..\packs\*.pack --destination=/home/user/unpack  --filter=export_descr_unit.txt
Other file from Americas campaign:
Code:
unpacker.exe --source=..\..\mods\americas\packs\*.pack--destination=/home/user/unpack --filter= battle_models.modeldb
File Types
The files_types BAT file contains as example the TXT files of the main game. As discussed in the ’Individual Files’ section this can be changed to different types and from different packs.
Example provided:

Code:
unpacker.exe --source=..\..\packs\*.pack--destination=/home/user/unpack  --filter=*.txt
Other file type from Americas campaign:
Code:
unpacker.exe --source=..\..\mods\americas\packs\*.pack --destination=/home/user/unpack --filter= *.TGA
Editing the BAT Files
Now is when the text editor comes into play. Before running the .bat file we first have to edit it to suit our needs. The reason for this is that the destination folder of the .bat file had to be written with the placeholder user folder.
● Open the .bat file by right clicking and "Open with geany (or gedit)"
● This is just an example, but generally you will see this:
Code:
@echo off 
unpacker.exe --source=..\..\packs\*.pack --destination=/home/user/unpack --verbosity=1 
pause
● The placeholder user is actually you, your name, the one who is reading this, so replace it with your username. The unpack folder will be created, you don't have to create it beforehand. You now have a folder named unpack in you main home folder.

Running the BAT Files
Finally, we are ready to give the order. Unpack! Although, you will notice that simply double-clicking the .bat file will simply open it with a text editor. Trying to execute the file with WINE bears the same results. So, this is how to run a .bat file in Linux:

  • Open a terminal. In Ubuntu this done by pressing Ctrl + LAlt + T.
  • First, go to WINE environment by typing
    Code:
    wine cmd
  • Then, go to the folder we created in Getting the Download into place. You can do this by using the command cd:
    Code:
    cd .../Medieval II Total War/share/data/tools/unpacker
  • Now we are in the folder. So, it's time to execute the .bat file. You can do this by typing:
    Code:
    start   *.bat
    The asterisk stands for the name of whatever .bat file you want the unpacker.exe to run, depending on what exactly you want to unpack as explained in the Choosing a BAT file section.
  • Yes, you have to accept three times for the unpacking to begin, but as always read everything in the window that appears.
  • Depending on which file you are using the unpacking process can take some time. Do not close the window until you see the ‘Successfully extracted all pack files’ message.
  • After the unpacking process ends, don't close the Terminal right away because you are still in WINE environment and closing it may cause problems with the unpacking. The chances are small, but just to be sure, type the command exit, and then close the Terminal.


Error SolvingMissing DLL file prevents the unpacker from running
● Copy the missing file from the game’s main directory into the tools\unpacker directory
Success message and no files
● If you use the provided BAT files then the files will be in a folder named unpack in you main home folder
● If the files are not in that directory and you have modified the provided files, check the spelling and syntax
Error message about unpacking a file
● The file in the pack is corrupt. You will need to re-install the game.

Conclusion
I hope this guide will help Linux users to avoid the nightmare I went through to unpack the game. Of course, I wouldn't be able to write this guide save for the immense and invaluable help from Gigantus. So, rep him even more!

Feel free to comment, ask or propose anything. I wrote this as a constant WIP and I aim to include any useful bit of info or clarification.

Useful notes
Note 1: In this guide the Medieval II Total War folder was located in
Code:
/home/user/.local/share/Steam/steamapps/common
Note 2: When using the cd command there is a problem with folder names containing multiple words, like Medieval II Total War. You can bypass this problem by using quotes, i.e. cd .../"Medieval II Total War"/...