The Ur-Quan Masters Discussion Forum

The Ur-Quan Masters Re-Release => Technical Issues => Topic started by: Eco-Mono on August 05, 2008, 08:14:23 am

Title: Internals Question: String_Table
Post by: Eco-Mono on August 05, 2008, 08:14:23 am

I'm currently at work on a UQM patch of secret purpose. However, in order to make it work I have a feeling I will need to use the STRING_TABLE data structure. And looking through the code provides no hint as to how to pull individual string values from the table once it has been loaded from the game content.

Could someone who knows this code provide a helping hand? You can reach me on AIM, or at "ecomono asperand gmail point com" if you don't use AIM.

Thanks!  :)

Title: Re: Internals Question: String_Table
Post by: meep-eep on August 05, 2008, 11:36:13 am
Loading the string table:
    STRING str = CaptureStringTable (LoadStringTable (SOME_STRTAB));
Selecting string 17:
    STRING str17 = SetAbsStringTableIndex (str, 17);
Getting the next string:
    STRING str18 = SetRelStringTableIndex (str17, 1);
Getting a pointer to the actual string data:
    char *strData = (char *) GetStringAddress (str18);
When you're done:
     DestroyStringTable (ReleaseStringTable (str));

src/sc2code/gamestr.h defines the 'GAME_STRING' convenience macro to get a pointer to a string by number:
    char *strData = GAME_STRING(18);

See src/sc2code/libs/strlib.h for more useful functions. The actual functions are defined in src/sc2code/libs/strings/strings.c.