This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [QUESTION] VB DBC converter source  (Read 2420 times)

Keta

  • Contributors
  • Model Change Addict
  • *****
  • Posts: 210
    • View Profile
[QUESTION] VB DBC converter source
« on: August 15, 2011, 08:26:53 am »
[center:4nfmo8vn]Hello Modcraft![/center:4nfmo8vn]

I was hoping someone on here might be able to help me with this little project I've begun. Would there by any chance be someone who'd be able to help me in scripting a Visual Basic program to be able to convert DBC data into maybe just lines of numbers, like the DBC -> CSV does. Even if you just have the sourcecode for his program it'd also be nice :) Its just, I don't really know how to approach this, since I don't really understand the structure of the DBC files. I mean, they don't make sense if just changed from .dbc to .txt, and they don't make sense either, if viewed in Hex so... Anyone, please? x)

Thanks
Keta
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Steff

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 4551
    • View Profile
Re: [QUESTION] VB DBC converter source
« Reply #1 on: August 15, 2011, 08:46:29 am »
You should sgtrat to read more about hex.

- little endian
- datatypes
- chunked structure

Here is the description of the DBC file format.
http://wowdev.wiki/index.php?title=DBC
« Last Edit: January 01, 1970, 01:00:00 am by Admin »
Please mark as solved if solved.
Don't ask if you could ask a question... JUST ask the Question.
You can send me also offline messages. I will answer if I get online.
Skype: project.modcraft
Discord: steff#6954

Keta

  • Contributors
  • Model Change Addict
  • *****
  • Posts: 210
    • View Profile
Re: [QUESTION] VB DBC converter source
« Reply #2 on: August 15, 2011, 11:28:37 am »
Yeah I know that, but I still don't understand how I can convert it into text my VB program can read :/ Maybe you could write a C# or C++ code that can do it, and I will try to convert it into VB code? xP
^_^

Thanks
Keta
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [QUESTION] VB DBC converter source
« Reply #3 on: August 15, 2011, 12:02:38 pm »
A quick C++ dbc "viewer", I just wrote for you at work. Note, that I have never tested this except for compiling it after writing (from top to bottom, without being able to correct a previous line due to the behaviour of cat).
It should work though.
It will first output all strings in the string block, then show the first entry as integer, float and string, if an entry exists.

I wrote a better one at work once which analysed the different column types and print all entries, but I can't find that one right now and am lazy.

Code: [Select]
~> cat > dbcview.cpp
#include <stdint.h>
#include <cassert>
#include <cstdio>
#include <cstdlib>

struct dbcHeader_t {
  uint32_t token, records, fields, recSize, stringSize;
};

int main(int cnt, char** arg)
{
  assert( cnt == 2 && "argument: filename" );
  FILE* file = fopen( arg[1], "r" );
  assert( file && "file could not be opened." );
  fseek(file, 0, SEEK_END); size_t fsize = ftell(file); fseek(file, 0, SEEK_SET);
  char* data = new char[fsize];
  fread( data, fsize, 1, file);
  fclose(file);

  dbcHeader_t* header = reinterpret_cast<dbcHeader_t*>(data);
  assert(header->token == 'WDBC');
  printf("records: %in", header->records);
 
  size_t n = 0;
  char* stringblock = data + sizeof(dbcHeader_t) + header->recSize * header->records;
  for( size_t i = 0; i < header->stringSize; ++i)
  {
    if( i == 0 || stringblock[i] == '' )
      printf("#%i: ", n++ );
    else
      ; // mistake.
    if(stringblock[i] != '') printf("%c", stringblock[i]);
  }
 
  if(header->records && header->fields)
  {
    printf("first entry:n");
    char* entry = data + sizeof(dbcHeader_t);
    printf(" as int: %ldn", *reinterpret_cast<int*>(entry));
    printf(" as float: %fn", *reinterpret_cast<float*>(entry));
    if(header->stringSize)
      printf(" as string: %sn", stringblock + *reinterpret_cast<int*>(entry));
  }
  delete[] data;
  return 0;
}
~> clang++ dbcview.cpp -o dbcview
~> ./dbcview
dbcview: dbcview.cpp:12: int main(int, char **): Assertion `cnt == 2 && "argument: filename"' failed.
~> touch test && ./dbcview test
dbcview: dbcview.cpp:21: int main(int, char **): Assertion `header->token == 'WDBC'' failed.
~>
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Keta

  • Contributors
  • Model Change Addict
  • *****
  • Posts: 210
    • View Profile
Re: [QUESTION] VB DBC converter source
« Reply #4 on: August 15, 2011, 12:41:39 pm »
Alright, thanks a lot Schlumpf! ;D This is gonna help me quite a lot I believe ;)
Y U NO WORK AT WORK?! o_o Lol, Im not your boss so I don't really care XD Just felt like adding that ;D

Thanks
Keta
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [QUESTION] VB DBC converter source
« Reply #5 on: August 15, 2011, 12:49:16 pm »
That code was written in about five minutes, so not much time lost. Also, others were at lunch while I stayed in the office.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »