Impossible Creatures

Impossible Creatures

Not enough ratings
Modifying Game Text With Visual Studio (No Resource Hacker)
By the2ndSign
Explains how to use Visual Studio to generate a new ModText.dll file. No more broken text.
   
Award
Favorite
Favorited
Unfavorite
Introduction
Text editing is an often overlooked but absolutely vital component of creating a new Impossible Creatures mod. Whether you’re adding new stock animals to the game, creating campaign missions, or modifying the UI, you will inevitably cross paths with IC’s localization system, dubbed ModText. This is a .dll file located within IC’s “locale” directory and contains all of the text your mod needs to display important information.

Traditionally, this file is edited via the resource editing tool Resource Hacker. Unfortunately, Resource Hacker can be unwieldy for such a large file with so many strings and, within the past few years, compiling ModText.dll with this software has introduced a fault that can cause the file to become unreadable by IC at unpredictable intervals. If there is no other locale file for IC to fall back on, the affected mod simply stops working altogether.

This is, in fact, the culprit behind the infamous "Korean bug" that plagued Tellurian several years ago. Because Tellurian has multiple localizations, IC was able to switch to the next available ModText file instead of failing to load the mod. In most cases, this was the Korean localization. Most players' IC installations don't support Korean characters by default, so all of the mod-specific text was rendered as question marks.

As of writing, this bug still occurs and has been identified in at least three separate mods.
Exporting Resources from ModText.dll
Fortunately, there is a much better method to edit the game text. This guide will walk mod developers through the process of using Microsoft Visual Studio to create a brand new ModText.dll file from a .rc resource.

Required software:
Microsoft Visual Studio Community 2022[visualstudio.microsoft.com]
Resource Hacker[www.angusj.com] (we still need this to perform a simple operation)

Exporting ModText Content to a .RC Resource:

The first step is to export all of the text strings inside the .dll to a .rc file, which will serve as the basis for our new .dll a bit later. Open up ModText.dll with Resource Hacker and navigate to the “Action” drop-down at the top of the window. Select Save ALL Resources to an RC File....



I recommend simply naming this file “modtext.rc” and saving it somewhere easy to access.

Preparing Your .RC File:

Once you have it, we need to make a few adjustments before it’s ready for Visual Studio. Open your new .rc with a text editor of your choice (I recommend Notepad++). You should see something resembling this:

STRINGTABLE LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US { 34000, "Albatross" 34001, "Alb" 34002, "atross" 34003, "The Albatross is a big mean bird that will bite off your toes." }

This should resemble what you saw inside Resource Hacker and is very close to what we need. There are a couple of adjustments to be made, however. Firstly, we’re going to tell it to include a few system files. Add the following to the top of the file:

#include <windows.h> #include <commctrl.h> #include <richedit.h> #include <winresrc.h>

Now we need to make a minor edit to the way the stringtables are declared. There are way too many to do this manually for each one, so we’ll use Find and Replace, accessed via Ctrl+H in most text editors. In the “Find” field, input STRINGTABLE, and in the “Replace” field, input LANGUAGE 9, SUBLANG_DEFAULT. Now click on “Replace All.” Next, repeat this process with LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US in the Find field, and STRINGTABLE in the Replace field. Once again, select Replace All. Your file should now look something like this:

#include <windows.h> #include <commctrl.h> #include <richedit.h> #include <winresrc.h> LANGUAGE 9, SUBLANG_DEFAULT STRINGTABLE { 34000, "Albatross" 34001, "Alb" 34002, "atross" 34003, "The Albatross is a big mean bird that will bite off your toes." }

We are now ready to create our Visual Studio project.
Configuring Your Visual Studio Project
Creating Your Project:

At this point you'll install Visual Studio. During the installation, make sure that you select the workload titled Desktop development with C++.

Now, launch Visual Studio and create a new project following this guide[learn.microsoft.com]. For simplicity’s sake, I recommend once again naming the project ModText. Go ahead and skip the step to create a new .rc file, as we already have ours ready to go. Make sure you follow the link in step 5 explaining how to specify the /NOENTRY linker option. This is important and your file won’t work if you don’t do this.

Editing Text:

Now that you’ve created the project and added your .rc, let’s view it to make sure everything is in order. Right-click your file in the Solution Explorer and click on View Code.



You should see the same text as before when we were modifying the file in a text editor. From now on, this is where you will edit your mod’s text. Unlike in Resource Hacker, you can now also leave comments by typing // followed by some text. For example, // This is a comment. This can be helpful for labeling and these comments will not appear inside the game. Creating new strings is also a less cumbersome process than before and you shouldn’t run into inexplicable errors when doing so as you may have in Resource Hacker.

Configuring for 32-bit Systems

Anyway, with those steps complete, there is one more thing to check before we’re ready to build. Because IC is over 20 years old, we need to make sure our solution generates a 32-bit (x86) .dll instead of a more modern 64-bit (x64) file.

In Solution Explorer (the same place we added our .rc file), right-click the project and choose Properties. At the top of the window, ensure Platform is set to Win32.



There is a high chance it was set to x64 by default, so make sure you don’t skip this step. Now click on Configuration Manager and repeat this step, ensuring to also change the project configuration.



Building Your .DLL:

And that’s that—we’re ready to build. Return to your project and build the solution from the Build drop-down menu at the top of the window. You can check the terminal at the bottom for any errors, but if all was in order you should see some text saying the build was successful.

Adding the New .DLL to IC:

To retrieve your newly-built .dll, navigate to your project in Windows Explorer (Visual Studio normally saves projects to C:\users\<your_username>\source) and open the Debug folder. Create a backup of your old text file and copy the new modtext.dll to your mod’s locale folder. Run the game. If you have done everything correctly, nothing should be amiss with your mod. If you want to run a test to make sure it’s working, just make an edit to the text in Visual Studio and build the solution again, copying the new file to IC. You’ll need to repeat that process each time you edit the text, so I recommend creating a shortcut to the Debug folder either in the Quick Access panel of Windows Explorer or in your mod’s locale folder itself.

And that’s that! You should now have an error-free ModText.dll file and a cleaner editing environment.