Author: Socrates1984
Original Thread: How to fix the custom settlement bug in Linux (Ubuntu) and Mac

(Medieval 2: Total War)

How to fix the custom settlement bug in Linux (Ubuntu) and Mac
Contents


IntroductionThis is a tutorial on how to fix the custom settlement bug (Crash To Desktop - CTD) in Linux. I am using Ubuntu (16.04 LTS), but I guess the procedure isn't very different in other distros.

What is this bug?
For Windows users this is a non issue. For Linux and Mac users, there are certain custom settlements that crash the game. It has been proved through experimenting that the wall and gate animations are the culprits. What exactly happens is this: When fighting a siege battle, including a sally out, the game zooms in, the loading screen shows up, the music stops and the game crashes even before the loading bar starts filling up.
It has to be said right from the start that this fix isn't a complete one. This means that custom settlements will not crash the game, but it also means that some graphics and some animations will not work.

This guide assumes a SteamOS installation. I don't think there will be any differences in the CD version of the game (becuase the folder paths must be the same), but if anyone tries it out and has any feedback, please share and I will update this post to include the information.

It is a prerequisite to have unpacked the game for all this to work. If you haven't done so already, please do it before proceeding. This tutorial on Unpacking the Game in Linux (Ubuntu) explains everything.

Where applicable, this guide assumes you know how to download a package either through Ubuntu Software or through the Terminal, so that won't be covered here.

Up

1. Essential softwareFirst, the general advice to leave your PC in peace when downloading. This means not using the Internet, not playing games, not reading pdfs, not using the Office suite, not having other applications running, not doing anything in general. Just be absent and let it download.
We will be downloading three programs fo this tutorial.

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 installing mods, 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.

Integrated World Terrain Editor (IWTE)
Spoiler Alert, click show to read: 

This is a convenient program to edit lots of things in the game. I quote from its short description in its own dedicated subforum. You can find more information about it here and you can download it here.
You can extract IWTE wherever you want, but a good place would be near the folders that you will be working on, i.e. near the mod folder whose settlements you want to fix. This will save you time and reduce the chances of selecting the wrong folder and/or file.
As far as this tutorial is concerned, you will not have to become a master in its use, but in case you want to become a bit more familiarized there are a lot of tutorials explaining its functions. Most of them are somewhat outdated, but leo's seem to be the more recent (you can find them in the first post here under "Leo.civil.uefs IWTE Tutorials").

About unzipping
Spoiler Alert, click show to read: 
In case you need to unzip the files that you downloaded, you don't need unzip, unrar, 7zip or any program like that, because the default Archive Manager does it all.

Up

2. IWTEMake some backups
Spoiler Alert, click show to read: 
The best thing to do with every mod you have is to back it up. The whole thing. Because you never know what file you might need in the future.
In our case two folders are important:
1) /data/blockset
2) /date/settlements
Make a backup of at least these two folders in case something is messed up.

How to run IWTE
Spoiler Alert, click show to read: 
After having extracted the downloaded .rar file, you simply right click on it and press "Open with">"Wine Windows Program Loader". Besides the IWTE main window, another one will open, a Terminal. This Terminal simply notes what is happening in the main window and tracks any bugs. Disregard it and don't close it.

Read 3 Binary Files
Spoiler Alert, click show to read: 
In the WorldFiles tab click on the Read 3 Binary Files button.


A new window will pop-up.


You have to find the path to the custom settlement that is causing the CTD. The files are in the /data/settlements folder. For example, in TATW the file to choose is in /data/settlements/unique_settlements.

That's why I advised you to place IWTE near the mod folder, because now the trip to the settlement folder is relatively short.
Now, open the settlement folder you know is causing a CTD and select the only file that is selectable, i.e. a .world file.

This you will have to do three times in succession each time choosing the new selectable file that appears from the same folder as before (.worldcollision the second time and .animinstances the third). That's why it's called Read 3 Binary Files afterall.

After that a new window will pop-up prompting you to save the file. Save it in the same folder as before, but choose a different name to be sure.


If everything worked fine, you will now notice that the windows on the left of your screen have filled up with info.


Well done! You have loaded the buggy custom settlement and we are now ready to fix it!

Removing the wall animations
Spoiler Alert, click show to read: 
Next thing to do is grab the Objects window and enlarge it up to the point that the Animref column is visible. Sort the table by this column. You can see that the Animref values are (in this case) -4, 0 or 4. What we have to change is all the Objects labeled as Wall in the TypeDescr column.


Next step: Select the first Wall Object, select the Animations tab, click on Remove Object Animation button and then OK.


You will notice that this particular Obect has been removed from the list. Re-sort by Animref and rinse and repeat until all Wall objects with 0 value in the Animref column have been removed. (If there are other Walls with different values in the Animref column, don't touch them.)
After removing all the Walls you will also notice that the Animref of the Gates Objects have been renumbered. This doesn't always happen, but in any case be cautious not to remove any Gate animations.

Well done! Now your custom settlements have no wall animation, which means that when they are receiving artillery fire they will proceed to the next level of destruction abruptly without any animation! Hey, you've been warned...

Redirecting the gate animations
Spoiler Alert, click show to read: 
Now, we have to redirect the gate animations back to the vanilla ones. This is where having unpacked the game becomes crucial, because otherwise there are no vanilla animations to redirect to. Be sure to place (a copy of) the vanilla M2TW in the right place.
To do this drag and drop the Objects window back to its place, select the WorldFiles tab again, then the update animations paths button and then OK.


A new set of fields will appear. Each one describes what animation is used when something is happening to the Gates; for example what animation to use when the Gates open, when they are damaged, when they are destroyed etc.
Watch carefully the folder paths in there and you will notice that they direct to files in the mod folder, TATW in this case, in the blockset/new_settlements/animations/gate_animations/ folder.
We have to redirect these paths to vanilla animations and to the corresponding city size. But what animations to use for these custom settlements? Are they huge cities, fortresses or what? You can see what it is easily by looking at the end of the path, where the file name is mentioned, for example NE_huge_city_gate_damage_impact.anim. As you can see it refers to Northern European huge city settlements.


Now, click on it and replace only the mod folders. For example replace

BlockSet/new_settlements/Animations/Gate_Animations/minas_tirith_gate_anims/NE_huge_city_gate_damage_impact.anim

with

blockset/north_european/animations/gate_animations/huge_city_gate_anims/NE_huge_city_gate_damage_impact.anim

Keep in mind that we only edit the folder paths NE_huge_city_gate_damage_impact.anim, not the files themselves. It should look something like this:


You have to do this for all the fields. You can copy-paste, but I'm not a fun of this, because it lowers the levels of the attention required to do everything right.

Well done! You now have vanilla animations for this particular settlement! They might show some graphic glitches, but hey you've been warned on this too.

Saving and exiting
Spoiler Alert, click show to read: 
You can now save by clicking on the Save 3 Binary Files button. Be sure that your files are saved where they should be by going to the place that you saved them and checking.


Now, delete the old ones (remember, I told you to back them up first?) and rename the new ones by removing the _1-1 part.

Exit IWTE and play with your new working custom settlement, Minas Tirith!



Up

3. The settlement list for TATWThe method described above works for any mod or submod that has custom settlements, but seeing that TATW sparked the effort to fix it and its sheer popularity, I find it useful to list the settlements that have been tested so far. It's not complete, but it's close to it.

Non working settlements
Edoras
Hornburg
Isengard
Minas Tirith
Minas Morgul
East and West Osgiliath
Black Gate
Moria
Cair Andros

Working settlements (just for the record)
Esgaroth
Erebor
Imladris
Dol Guldur
Caras Galadhon
Goblin Town
Amon Sul
Hobbiton
Carn Dum
Henneth Annun
Barad Dur (It looked like a normal settlement to me)
Pelargir (ditto)

Note: Esgaroth is in red because it is reported elsewhere as non-working.

Up

4. For Mac usersAs I have said probably a million times by now, I am a Linux user, which necessarily means that I am not a Mac user. Despite that, the two OSs seem to face the same problem as has been reported. The reason must be the same, because the tests so far have proved that this fix works for Mac too.
This means that Mac users can utilize this Tutorial to fix the bug themselves, by adjusting a bit the instructions. For example, Mac users probably have no use of WINE or winetricks or they probably need an unzipper. I honestly don't know but I will happy to include in this section any relevant information provided.


Thanks
The true magician behind all this is makanyane. I merely put this Tutorial together while she was doing all the hard work.
I have to also thank Gigantus, Withwnar and xHolyCrusader who contributed greatly in the adventure to find the root of the problem and fix it.
I also have to thank c.l. and vconesa (a Mac user) for the parallel tests, despite them being latecomers.
Finally, a "thank you" is due to all who created this great tool, IWTE, whom I don't exactly know, but from what I see wilddog must be included.
I probably forget some of the good people that helped and I apologize.