Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSF and BIG file tools #306

Merged
merged 4 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Documents/BigFileFormat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#### Supplied by xezon

--- BIG HEADER
.BIG signature (4 bytes) - it must be 0x46474942 - 'BIGF'
.BIG file size (4 bytes)
FILE HEADER count (4 bytes)
BIG HEADER + FILE HEADER (count) + LAST HEADER size in bytes (4 bytes)

--- FILE HEADER
File data offset (4 bytes) - position in the .BIG file where the content of this specific file starts
File data size (4 bytes)
File name - null terminated string

--- LAST HEADER
Unknown value (4 bytes)
Unknown value (4 bytes)


#### Supplied by Thyme Wiki

https://github.com/TheAssemblyArmada/Thyme/wiki/BIG-File-Format

BIG File Format

BIG files are an archive format used in many games published by Electronic Arts.
The supported features vary between games, with some using compression or encryption, but for SAGE, the files are trivially concatenated together and wrapped with a header containing a series of index entries that located a given file within the archive.

__Header__

struct BIGFileHeader
{
uint32_t id;
uint32_t archive_size;
uint32_t file_count;
uint32_t data_start;
};

struct IndexEntry
{
int32_t file_size;
int32_t position;
char file_name[n];
};

The header "id" is a FourCC that is either "BIGF" for Generals/Zero Hour or "BIG4" for the Battle for Middle Earth games. Thyme will accept either of these as valid. Next is the size of the archive in bytes stored as a little endian 32bit integer.
All other integers in the header are big endian and thus require byte swapping on popular CPU architectures such as x86 and common modes of ARM. "file_count" provides the number of files the archive contains and thus how many index entries there are and "data_start" is the offset to the end of the header.

The index entries themselves consist of a "file_size" and "position" allowing the game to locate files within the archive and stay within its bounds.
"file_name" is a null terminated string used to identify the file and includes the relative path to the file from the game directory if the file existed in the normal file system. This path length is limited such that n must be less than or equal to 260 characters in keeping with the path limit on Windows which is all the game buffers for.

With the information in the index it is possible to locate and read files within the archive which constitute the rest of the file.
100 changes: 100 additions & 0 deletions Documents/CsfFileFormat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#### Supplied by xezon

HEADER:
4 bytes: ' FSC': file type identifier
4 bytes: 3: unknown value, maybe file type version
4 bytes: 0x1916: 6422, could be number of string table entries
4 bytes: 0x1915: 6421, similar to number above, not clear what the difference is
8 bytes: all 0: unknown

BODY (repeats):
4 bytes: ' LBL': keyword identifier
4 bytes: 1: unknown value, maybe number of keywords? seems to be 1 always.
4 bytes: length of ascii string (N)
N bytes: ascii string
4 bytes: ' RTS': locale string identifier
4 bytes: length of unicode string (N)
N bytes: unicode string: XOR'ed by 0xFF


#### Supplied by Thyme Wiki

https://github.com/TheAssemblyArmada/Thyme/wiki/Compiled-String-File-Format

Compiled String File Format

This file format holds most of the game strings in an encoded format that decodes to USC2 Unicode strings. The file consists of a header followed by a series of ASCII label strings and encoded Unicode strings.

__Header__

enum LanguageID : int32_t
{
LANGUAGE_ID_US,
LANGUAGE_ID_UK,
LANGUAGE_ID_GERMAN,
LANGUAGE_ID_FRENCH,
LANGUAGE_ID_SPANISH,
LANGUAGE_ID_ITALIAN,
LANGUAGE_ID_JAPANSE,
LANGUAGE_ID_JABBER,
LANGUAGE_ID_KOREAN,
LANGUAGE_ID_CHINESE,
LANGUAGE_ID_UNK1,
LANGUAGE_ID_UNK2,
LANGUAGE_ID_POLISH,
LANGUAGE_ID_UNKNOWN,
};

struct CSFHeader
{
uint32_t id;
int32_t version;
int32_t num_labels;
int32_t num_strings;
int32_t skip;
LanguageID langid;
};

The "id" is a FourCC code that translates to the ASCII string " FSC", essentially "CSF " in little endian format.

"version" is always 3 for SAGE engine games, though the engine does check for a value of 1 or less, in which case the langid is ignored and set to 0.

"num_labels" is a count of how many string references there are in the file while "num_strings" is a count of how many encoded strings there are as each label can have more than one, though this feature is unused in SAGE games.

"skip" is a reserved 4 bytes that are unused.

"langid" corresponds to an internal enum which enumerates which language the file is intended to provide text for, though the SAGE engine games don't appear to make use of it. The provided enum is valid for Generals and Zero Hour, but not the Battle for Middle Earth games based on examination of the string files from different translations.


__Labels__

struct Label
{
uint32_t id;
int32_t string_count;
int32_t length;
char label[length]
};

Each label entry begins with a FourCC "id" equivalent to the string " LBL", again likely a little endian "LBL ". This is followed by the number of strings the label can refer to, then the length of the label ASCII string followed by the string itself. The "label" string is not null terminated and must match the given "length". The engine code refers only to the label when requesting a string for display so that localisation can be done separately.


__Strings__

struct String
{
uint32_t id;
int32_t length;
uint16_t string[length]
int32_t ex_length; // Only present when id matches 'WRTS'
char ex_string[ex_length]; // Only present when id matches 'WRTS'
};

The FourCC "id" for the string must be either " RTS" or "WRTS" (little endian "STR " and "STRW"), with "WRTS" indicating an additional ASCII string appended on. The values for the string are little endian and are encoded using a binary NOT on the value. The following is an example of how it might be decoded in C:

for (int i = 0; i < length; ++i) {
string[i] = ~string[i];
}

Debug information left in certain executables suggests that the "ex_string" was related to audio files in some way, possibly as a file name for an audio file containing a reading of the string text. However it appears such a feature is not used in any SAGE game.

Binary file added Tools/FinalBIG/FinalBIG.exe
Binary file not shown.
187 changes: 187 additions & 0 deletions Tools/FinalBIG/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
FinalBIG

Version 0.4 Beta released March 20th, 2006.

Copyright by Matthias Wagner 2006

C&C Generals is a trademark or registered trademark of Electronic Arts in the USA and/or other countries. All rights reserved.
The Lord of the Rings(tm), The Battle for Middle-earth(tm) is a trademark or registered trademark of Electronic Arts in the USA and/or other countries. All rights reserved.
LucasArts, the LucasArts logo, STAR WARS and related properties are trademarks in the United States and/or in other countries of Lucasfilm Ltd. and/or its affiliates. (c) 2006 Lucasfilm Entertainment Company Ltd. or Lucasfilm Ltd. All rights reserved.

This software is based in part on the work of the Independent JPEG Group


-----------
Information
-----------
FinalBIG is a viewer and editor for the BIG files of C&C Generals and Lord of the Rings: Battle for Middle Earth.
It can also open and save the MEG files of Star Wars(TM): Empire at War(TM).
I tried to make it as easy to use as possible.

-------
Contact
-------
Suggestions? Questions?

Mail: webmaster *at* wagnerma.de
Website: http://www.wagnerma.de

-------
Credits
-------
Thanks to Jonathan Wilson for W3D help
Thanks to Deezire for his Module list
Thanks to Waraddict for adding modules
Uses CRC code available at http://www.zorc.breitbandkatze.de/crc.html
Uses MEG file information found here: http://alpha1.dyns.net/eaw/MegFileFormat, http://www.technical-difficulties.com/

-------
License
-------
FinalBIG is freeware and is provided "as-is". Use at your own risk.
No reverse engineering allowed. Editing finalbig.ini welcome.
Please don't mirror FinalBIG without asking me.

--------------------
System Requirements
--------------------
- OpenGL drivers installed
- DirectX 9.0c installed (for DX9 version)
- Tested on WinXP only

----------
HOW TO USE
----------
Actually FinalBIG is very easy to use, especially if you are used to other packaging & compression programs.
You can use FinalBIG to distribute your modifications to Generals and LOTR:BFME.
To open a BIG file, just click on File->Open and select your BIG file. You can now browse the files
included in this BIG file. However, you can also edit it. You can do this either by using the Edit menu,
or you can drag & drop files from Windows Explorer into FinalBIG. Just drop the files (or directories!)
on the file list of your BIG file. A window will come up telling you that FinalBIG needs to activate EditMode.
Accept that, but you really should back up any original BIG files before saving. That�s it! Now save your work,
and you are done!
It works exactly the same way for MEG files.

----------
W3D Viewer
----------
The W3D viewer should display almost all W3Ds fine.
If you want to rotate the model, press the NumKeys (at the right of your keyboard).
8 is up, 2 is down, 4 is left, 6 is right.
You can also zoom in & out by pressing - and + (NumKeys).

This viewer probably will be extended to display SW:EAW models if I have the time to do this.

-----------
INI Editor
-----------
For Generals & LOTR Ini style files!
Easy to use. Right click and you'll be presented with several options regarding the clicked item.
For example, if you click inside an Object module you'll be presented with a list of Modules/Values to insert.
For many values you can also use Set Value, which will present you a list of values.
Just try it out in the several sections of an INI file.
If you click onto GoTo, another menu pops up that allows you to jump to the several sections inside the current
INI file.
Basically, you do not have to use the INI Editor menu, you can do everything by typing, too. FinalBIG does
not take away your freedom to plainly edit the INI by hand, it just additionally supports some helper features.

----------------
External Editors
----------------
Simple: Define your favorite editors using View->Options. Once you have done that, close the dialog.
Then simply select the file to edit at the left and press CTRL+E (or Edit->Edit with Editor).
FinalBIG will then launch the editor with the selected file. If you want to change the file, don't forget to
save the file in the editor (without changing the filename).
While the editor is opened, FinalBIG will block access to this specific file. This is to avoid sharing difficulties.

----------------
Quick Save
----------------
Currently only implemented for BIG files, this feature tries to only save any changed files inside
the BIG file. That way, it does need much less time than saving several hundred MB of unchanged data.
Keep in mind that this can increase the BIG file, so before distributing, use the normal Save command.
For MEG files, this just works as pressing Save, thus rewriting the whole MEG. However, I will work
on implementing this feature for MEG files, too.

----------------
MEG File Support
----------------
Keep in mind that MEG files do not support lowercase letters inside filenames. FinalBIG automatically
changes those to uppercase letters.



---------------
TODO List
---------------
- Support QuickSave for MEG files (Top prio)
- Probably add viewer for SW:EAW models
- Probably add XML Editor with more features
- Probably add Texture->DDS support (for converting for example TGA's, BMP's etc into DDS format)



----------------------
Changes in 0.4 (beta)
----------------------
- Support for saving & loading MEG files of Star Wars(TM): Empire At War(TM)
- Support for DDS texture loading extended for SW: EAW

----------------------
Changes in 0.36 (beta)
----------------------
- External Editor support: Use your favorite editors (like PSP, Wordpad, etc) to directly edit files inside the BIG file!

----------------------
Changes in 0.35 (beta)
----------------------
- INI Editor extended: Lists modules & values and allows to set values *** IMPORTANT: I'm searching for people willing to complete the module list! ***
- Adding a file to a BIG that already exists will now overwrite the original file (you'll be asked)
- It may now be possible to open BIG files of other games than Generals/LOTR if the file format is compatible

-------------------
Changes in 0.34
-------------------
- INI Editor
- Quick Save

-------------------
Changes in 0.33
-------------------
- W3D Viewer now displays (almost) all W3Ds correctly, including skins
- JPEG and PNG support
- Image viewer now uses correct aspect ratio (if width!=height)
- Manual rotation and zooming possible in W3D viewer

-------------------
Changes in 0.32
-------------------
- W3D viewer now displays all W3Ds correctly except skin meshes
- W3D viewer now also displays textures (DDS, TGA and BMP)
- D3D9 support (optionally)

-------------------
Changes in 0.31
-------------------
- Added simple W3D viewer (no mesh hierarchy/textures supported yet, will come asap)
- Fixed Crash Bug when pressing Cancel when inserting a directory

-------------------
Changes in 0.3
-------------------
- Added Support for LOTR:BFME
- Added TGA, BMP & DDS Viewer

-------------------
Changes in 0.21
-------------------
- Fixed crash that occured sometimes when deleting files

-------------------
Changes in 0.2
-------------------
- Deleting files
- Renaming files
- Drag & Drop for adding files & directories
- Including the folder name when inserting a directory instead of skipping it

Loading