How to unpack game files and create a simple mod

The place to discuss scripting and game modifications for X²: The Threat.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

How to unpack game files and create a simple mod

Post by Burianek »

This brief post covers how to:

Unpack game files to prepare them for being modified
Edit the files to achieve the desired result
Repack the files to get them into standardized .cat/.dat format
Activate the mod so that it can be used

Unpacking .cat/.dat files using X2tool

Just as an fyi before I start, you may hear people referring to Stone D's X2Patcher. Among other things, this is an unpacker with a gui attached that is not supported by egosoft.
Using X2tool to unpack your game files is relatively easy.
The first thing you need to do is download the latest version of the X2 modding kit available in your personal download page from the main egosoft page.
X2tool needs to be run from a command prompt, it has no graphical user interface. Double clicking on the file won't accomplish what you want. To open a command prompt from most versions of windows, go to the start>run menu and type cmd
I'm going to assume you can navigate to the proper directory using the command prompt.
Navigate to your X2 root directory and make sure the x2tool.exe is also in this folder (you can't run the command if it isn't in the folder you're trying to run it from) (I know this isn't quite correct, but this guide is for newbs ;))
Usage is x2tool -extract-dat 01.dat
You can think of the .dat file as comparable to a zip file which contains many files within it. You're using x2tool to unpackage it. It will create multiple folders and extract the contents of the .dat to these folders. As egosoft releases new patches, they add additional .dat files, so the 01.dat contains the oldest data, the higher numbers are more recent. Therefore, when you extract the game files, extract 01.dat first, then 02.dat, etc. Extracting the later versions on top of the newer will overwrite previous files in case of duplicates, and make sure that at the end you have the most recent files extracted.
Ok, you're almost done. Most files will still now be in compressed format. If you look in the newly created /types folder, you'll see that the files end in extension .pck. Next we need to unpack the specific files that we want to use/change/mod.
To unpack the file TShips.pck, the usage is x2tool -unpack TShips.pck TShips.txt (remember to put a copy of x2tool in the directory or it won't work)
This will create a new file TShips.txt that can be edited using any text editor.
Congrats! You're done learning how to unpack the game files.

Edit the files to achieve the desired result

Editing can be accomplished using any text editor. I use notepad myself. There are 3rd party editors made specific to X2 and can be found by searching fan sites, but these are unsupported by egosoft.
An excellent 3rd party editor is doubleshadow's X2 editor.
Most of the files that you'll want to edit will be in the X2/types directory.
Opening the TShips.txt file that you just created will display a bunch of numbers that won't make much sense to you at first.
Download Storm Front's Mod Kit from the site in my signature. It's the best compilation/description to date of what all of the numbers in each file mean.
In brief,
TShips - contains data dealing with ship speeds, turning, weapon mounts, etc.
TRockets - missile parameters.
TLaser and TBullets - weapon parameters.
TShields - shield parameters.
TWare? - price, volume, size class, etc. data for all wares.
There are many others.
Pick the parameter that you want to change, find the correct location using Storm Front's mod kit, locate the number in the correct .txt file, and change it using a text editor. Use some common sense. Experiment! If you're wondering how to use a specific field, or what a particular number means beyond the desciption given in SF's mod kit, post a question in this thread. I don't know how to use all of them, but chances are someone out there does.
That's it. You now have a new version of the file that incorporates your changes. Now we have to tell the computer to use your file instead of the egosoft ones.

Repack the files to get them into standardized .cat/.dat format
As explained in the modding documentation, the new standard for mods is to put your modded files into .cat/.dat format. This means compressing your modified file/files into a pair of files, {yourmod}.cat and {yourmod}.dat.

Step by step:
Create a folder 'temp' (or whatever)
create a folder in temp called types
put your types .txt files in there to be packaged
run gzip on each file: gzip <TBullets.txt >TBullets.txt.gz
run x2tool on each: x2tool -crypt TBullets.txt.gz TBullets.pck
delete/move the .txt and .txt.gz files so you have only .pck files in the directory
now you're ready to make the .cat/.dat
back out to the directory that contains the temp folder, everything in this folder will be recursively added to the .dat. (that's why you make the types folder in it) You can think of the .dat as a zip that will be extracted to the root x2 directory in terms of how things will be used.
run x2build: x2build mymod temp (will create mymod.dat/.cat using all files in /temp

Activate the mod so that it can be used
There is already a tutorial that deals with installing and managing scripts and mods so I'll just reference it.

That's it!
That should be enough to get you on your feet, editing game parameters to your heart's content.
Remember that pretty much everything I just covered is also covered in the instructions in the egosoft mod kit.
Ask a specific question and receive a specific answer.
Have fun.
Last edited by Burianek on Mon, 8. Nov 04, 01:00, edited 1 time in total.
"Nature's first green is gold" . . . stay golden.
Jha'dur
Posts: 1211
Joined: Sun, 21. Mar 04, 17:13
x2

Post by Jha'dur »

This is from someone who have no idea how to do, well, anything regarding mods and scripts and similar, I just wanted to change a thing or two in the game. But:

When I type "x2tool -extract-dat 01.dat", I get "error: can not open 01.dat.cat."

If I type only "x2tool -extract-dat", I get something that appears to be instructions (unpack, crypt, decrypt etc), but I don't know what to do with them (think of a caveman finding a mixmaster, and you get the general idea :wink:) But it would seem that I am on the right track, so to say, but I don't know why it can't open the file.

So, anyone have any help for me?

EDIT: oh, "x2tool -extract-dat 01" seems to work, instead of "x2tool -extract-dat 01.dat". So nevermind. Let's see now...
+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

Post by Burianek »

You got it.
Feel free to ask though, that's what we're here for.
Here's the explanation:
The .dat file is where all of the files are actually compressed. Think of the .cat file as instructions for how to translate the .dat file. The .cat file contains a list of every file packaged within the .dat file and how to find it more or less. So when you run the extract dat command, it automatically goes looking for the extraction instructions (the .cat file) Therefore the filename extension is not needed. So when you type x2tool -extract-dat 01 it finds 01.cat which tells it how to unpackage 01.dat
"Nature's first green is gold" . . . stay golden.
Jha'dur
Posts: 1211
Joined: Sun, 21. Mar 04, 17:13
x2

Post by Jha'dur »

I managed to do the changes I wanted (well, most), with good help from this thread and the links herein.

Tried giving the Falcon an extra shield, but it didn't stick. That is, the Falcons description says it can take 4, but only 3 are installed no matter how many are in the hold. My reasoning is that an extra shield would be very fitting on the Teladi Falcon, to balance it's slowness. But seeing as I have one of the superfalcons (from assassination-missions), it would be cheating. Just wanted to see if I could make it work, for future reference (in case superships are "fixed" in 1.4. In which case that 4th shiled is on again)

Anyway, good guide :)
+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
Yonder
Posts: 322
Joined: Wed, 24. Mar 04, 22:53
x3

Post by Yonder »

I copied all of the .cat's and .dat's to a separate folder for my mod work, and put a x2build and x2tool in there with them. When I try to extract or decrpyt I get an error saying it cannot read 01.cat, I looked at the directory to make sure it was there and it was, what am I doing wrong?

Heres what I did in the command prompt:

F:\>Games\x2\mods\x2tool.exe -extract-dat 01
error: can not open 01.cat

F:\>F:\Games\X2\mods\x2tool.exe -extract-dat 01
error: can not open 01.cat

F:\>F:\Games\X2\mods\x2tool.exe -decrypt-cat 01.cat 01index.txt
error: can not open 01.cat

F:\>dir\Games\x2\mods/p
Volume in drive F is WDC USB2
Volume Serial Number is 15E7-2925

Directory of F:\Games\x2\mods

07/02/2004 04:57 PM <DIR> .
07/02/2004 04:57 PM <DIR> ..
11/03/2003 06:20 AM 80,471 01.cat
11/03/2003 06:20 AM 534,011,156 01.dat
01/16/2004 12:25 AM 2,227 02.cat
01/16/2004 12:25 AM 20,235,375 02.dat
01/17/2004 10:44 PM 265 03.cat
01/17/2004 10:44 PM 3,087,224 03.dat
03/09/2004 10:25 PM 1,252 04.cat
03/09/2004 10:25 PM 17,761,620 04.dat
02/26/2004 12:11 AM 122,880 x2tool.exe
04/13/2004 04:18 PM 102,400 x2build.exe
10 File(s) 575,404,870 bytes
2 Dir(s) 67,354,066,944 bytes free

F:\>
User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

Post by Burianek »

Yonder wrote:what am I doing wrong?

Heres what I did in the command prompt:

F:\>Games\x2\mods\x2tool.exe -extract-dat 01
error: can not open 01.cat
You have two choices:

1.
f:\> cd Games\x2\mods

and then

F:\Games\x2\mods> x2tool -extract-dat 01

or
2.
F:\> Games\x2\mods\x2tool -extract-dat F:\Games\x2\mods\01

you see what's happening?
when you run the command from your F:\ root directory, the computer interprets the argument of 01 as meaning f:\01.dat which is not where it is. Either run the command from the directory that contains the 01.dat file or include the entire path in the command line.
:wink:
Cheers.
"Nature's first green is gold" . . . stay golden.
Yonder
Posts: 322
Joined: Wed, 24. Mar 04, 22:53
x3

Post by Yonder »

ooooooh, I thought that might have been the problem, but I couldn't remember for the life of me the cd thing. I haven't used DOS/ cmd prompt in like 7 years. Thank you very much, lets go try that (I need to double the range of the mining laser so my TL stops getting ground into teensy little bits)

(edit)
Cool, it worked perfectly, although I ended up having to triple the range in order to be completely out of harms way. Thank you very much for your help Burianek.

**Bows to the master**
User avatar
Tsar_of_Cows
Posts: 9966
Joined: Sat, 31. Jan 04, 14:38
x4

Post by Tsar_of_Cows »

Is it possible to play the game with the files unpacked?
D_Zorro
Posts: 2027
Joined: Wed, 6. Nov 02, 20:31
x3tc

Post by D_Zorro »

Tsar_of_Cows wrote:Is it possible to play the game with the files unpacked?

Yes i think so, but you won't be able to play a custom game, because then it locks up or somehting.




DZorro,
System spec: Pentium (R) D 2.66 Ghz, Ram : 2048 DDR, HD : 250 GIG 7200 RPM intern 8 MB cash
Videocard : Nvidia Geforce 8800 GTS 320mb : Realtek
Laptop : AMD athlon 64 3200 + 1024 DDR 80 gig HD Conexant AMC Audio, Ati mobility Radeon Express 200
User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

Post by Burianek »

The following is taken directly from this post.

You can also run your game in comepletely unpacked mode. This can be very useful if you're planning on making modifications to your game, but not necessary for casual users. If you've unpacked the original egosoft 01 - 04.dat (or whatever) .dat files as per the instructions in this guide, you'll have a bunch of extra files and folders in your X2 directory. These are the raw game files that were "zipped up" in the 01 - 04.dat files. When you boot your game up, the game looks for files to load in this order:
1. Mods placed in the /mods directory and activated using the startup screen.
2. The original 01 - 04.dat files in the X2 main directory.
3. If these have been deleted (or moved is a better solution) then it will run the game off of the unpacked files.
This can be useful to a modder, because using this method, a modder wouldn't need to repackage game files every time they made small changes. The game loads the changes automatically as it is running off of the raw game files which the modder can modify.
(That shouldn't make sense to someone not interested in modding, don't worry about it )
"Nature's first green is gold" . . . stay golden.
User avatar
esd
Posts: 17998
Joined: Tue, 2. Sep 03, 05:57
x3tc

Post by esd »

Pretty sure that adding -raw to the shortcut command line paramater forces the game to run in "raw mode" (Use the unpacked files) without having to move or delete the dats.
esd's Guides: X² Loops - X³ MORTs
User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

Post by Burianek »

The commandline is +r to use only uncompressed files. I'm not sure however what will happen if you haven't uncompressed all the .pck files and you use this commandline.
"Nature's first green is gold" . . . stay golden.
Scarecrow23
Posts: 16
Joined: Tue, 27. Jan 04, 14:47
x3tc

Post by Scarecrow23 »

Hey, I am trying to combine some mod's, but every time I exec the x2build ~stuff, it makes the .cat/.dat file's correctly, but the dat file is alway's empty... any idea's?

EDIT: NM, I figured it out, and for anyone else who has this problem your probably doing what I did, all you have to do is put the name of the folder at the end, not the parent directory's. For example:

"x2build" "yournameofmod" "yourfoldername"

Ignore the quotes and have a space in between each segment. The instructions that were above kinda confused me :roll:.
User avatar
Red Spot
Posts: 3461
Joined: Fri, 4. Feb 05, 13:44
x3

Post by Red Spot »

have gone over the X2 modding docu .. and read this post .. but I understand out of both that I should "gzip" al files before packin em in the dat/cat-files ..

but how do I do that ??

I've tried this

"C:\Documents and Settings\G5_11\Bureaublad\AA\Types\gzip.exe" gzip <Tbullets.txt >Tbullets.txt.gz

simple link to my desktop \AA\types

put a copy of gzip in the AA-folder and the types-folder .. have tried it without the extra "gzip" etc etc .. but I cant seem to get it done .. it just doesnt do anything ..

or am I just doing it wrong ??


Edit : <T****.txt >T****.txt.gz .. didnt work .. but .. without the "<" it works perfect .. :roll:
User avatar
Red Spot
Posts: 3461
Joined: Fri, 4. Feb 05, 13:44
x3

Post by Red Spot »

ok now I'm really confused ..

redid TRockets, TBullets and TShips .. repacked it al .. loaded it .. *crash*

repack it .. without the TShips .. almost perfect ..

so I got a fresh TShips .. and just redid the speeds and max upgrades .. nothing else .. and in general ships should go a little faster .. but the fastest ship (P M5) has been reset at a lower max-speed .. so it cant be that I just overstreched it ..

packed all the files after an other in the same way .. so I gues it couldnt be that...

so it must be that I am doing something wrong in adjusting speeds .. are there any rules about it .. does a ship require some speed-upgrades or can I set the base-speed at max and 0 speed-upgrades??
Galaxy613
Posts: 3285
Joined: Tue, 28. Dec 04, 02:19
x4

Post by Galaxy613 »

When I used X2Tool I made myself a batch program that went along the lines of:

Code: Select all

echo "X2Tool Auto-Extractor"
x2tool -extract-dat 01
x2tool -extract-dat 02
x2tool -extract-dat 03
x2tool -extract-dat 04
echo "Finnished!"
pause
I used it everytime I screwed something up and it works.
10,000 Lightyears of awesomeness
User avatar
Red Spot
Posts: 3461
Joined: Fri, 4. Feb 05, 13:44
x3

Post by Red Spot »

I dont think it has to do with unpackin .. at least .. have had a couple times that a .txt-file came out empty ..?!? ..

Is there perhaps someone who would like to try and pack it for me .. perhaps it just goes wrong on my PC .. it doesnt really like me .. :(
User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

Post by Burianek »

You have to use both the < and > symbols in the command line. I realize that if you don't, you may very well still get a file which ends in .gz, but I don't think it has been packaged correctly.

As for which parameters do what, that's a bit beyond scope to explain in a forum post. If you haven't, download Storm Front's mod kit from the link in my signature. It contains a lot of useful info on which fields are what.

As for max / base speed, yeah I think you can just define one speed and not allow any speed upgrades. I don't see an issue with that.

Cheers.
"Nature's first green is gold" . . . stay golden.
User avatar
Red Spot
Posts: 3461
Joined: Fri, 4. Feb 05, 13:44
x3

Post by Red Spot »

tnx ...

and I have SF mod (the one that simple shows what number/column means what in the T****-files etc.

so thats also why I know for d*mn sure that I didnt do anything wrong (in changing settings that is) or his mod would be of (what I dont think is the case)

will give it a go later today .. first I wil go and do a little format c: .. :roll:
User avatar
Red Spot
Posts: 3461
Joined: Fri, 4. Feb 05, 13:44
x3

Post by Red Spot »

now I've got a tool to (un)pack the dat/cat and pck files ..

and now the game loads .. until I start a game .. than its right back to desktop .. in custom and normal game

so it seems the packin was 1 issue .. but now the rest

just made a new mod .. just extracted 04.dat .. redid tships so that only the basespeed of the disco was altered .. but when I started a new game .. back to desktop ..

and I made sure that I changed the basespeed and nothing else (wich is 18140 --> new 66600) thats all


am I right to asume that the packing is done right .. cause the game does load .. or doesnt that say anything??

Return to “X²: The Threat - Scripts and Modding”