Forum > Software Development

Understanding the DBC Format

(1/6) > >>

iindigo:
As practice for creating WoW modding tools, I'm trying to write a little DBC Editor, since it seemed like a simple task compared to reading and editing other file types.

So far I can read the file type, number of entries, and number of fields correctly (was much easier than I expected). How do I read each individual entry? The type, entry count, and field count are as simple as grabbing values at certain addresses (0-4, 4-8, and 8-12 to be exact), but how do you deal with strings at varying addresses?

I'm guessing I need to somehow predict the length of each string and then iterate through the data, keeping track of my position?

schlumpf:
Nope. The strings in the string block are zero terminated. The entries contain an offset.


--- Code: ---struct foo_dbc_entry
{
  uint32_t id;
  uint32_t some_string;  
};

char* string_block;
foo_dbc_entry* entries;

for (size_t i (0); i < num_entries; ++i)
{
  printf ( "%i: %i, '%s'n"
         , entries[i].id
         , string_block + entries[i].some_string
         );
}
--- End code ---

iindigo:
Thanks for the clarification!

But ouch, reading this makes my head hurt, haha. I'm definitely not used to reading plain C or C++.

So let me get this straight. In this snippet, you are:

1. Defining a DBC entry object to store the id and string data in
2. Defining variables for the string data block and processed entries
3. Looping through the data, pulling strings and printing them until the num_entries int equals the number of zero-terminations

Did I miss anything?

Sorry for bothering you with this elementary-level stuff  :oops: and thanks again.

schlumpf:

* An entry e={field_i} has field_k of type string.
* DBC has string block B={b_i} and entries E={e_i}.
* Then, an entry has -- for field_k -- the string value [b_{field_k}, b_{field_k + n}] where n >= 0 and b_{field_k + n} = 0 and b_{field_k + l} != 0 for all -1 <= l < n.
* n might be 0 for a zero length string. A string contains a zero terminator in this definition.

iindigo:
This might take me a while to get my head around. If I were using C++ I could just copy and paste (which is actually bad) but I'm trying to do this in Objective-C which is forcing me to think about it and understand it (obviously good). It's something I'm going to have to do some research on.

Here's the code I have thus far:


--- Code: ---- (NSDictionary *)readDBCFromData:(NSData *)data
{
    NSData *typeData = [data subdataWithRange:NSMakeRange(0, 4)];
    NSString *typeString = [NSString stringWithUTF8String:[typeData bytes]];
   
    NSDictionary *dataDictionary;
   
    if ([typeString isEqualToString:@"WDBC"]) {
       
          NSData    *recordCountData = [data subdataWithRange:NSMakeRange(4, 8)];
        NSNumber    *recordCount     = [NSNumber numberWithInt:*(int*)([recordCountData bytes])];
          NSData    *fieldCountData  = [data subdataWithRange:NSMakeRange(8, 12)];
        NSNumber    *fieldCount      = [NSNumber numberWithInt:*(int*)([fieldCountData bytes])];
       
        dataDictionary = @{ @"recordCount":recordCount, @"fieldCount":fieldCount };
    }

    return dataDictionary;
}
--- End code ---

Which, after some UI code, looks like this:

Navigation

[0] Message Index

[#] Next page

Go to full version