From 3cf53a5dd60fd3c195e99a9f1a0fca56cef96fa7 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Sun, 30 Jun 2013 22:21:23 +0100 Subject: [PATCH] Initial GTA data class --- datadump/CMakeLists.txt | 2 +- datadump/main.cpp | 76 +++++++++++++++++++++++------------------ framework/gtadata.cpp | 61 +++++++++++++++++++++++++++++++++ framework/gtadata.h | 40 ++++++++++++++++++++++ 4 files changed, 145 insertions(+), 34 deletions(-) create mode 100644 framework/gtadata.cpp create mode 100644 framework/gtadata.h diff --git a/datadump/CMakeLists.txt b/datadump/CMakeLists.txt index ebecf741..545a565e 100644 --- a/datadump/CMakeLists.txt +++ b/datadump/CMakeLists.txt @@ -1,4 +1,4 @@ -add_executable(datadump main.cpp ../framework/LoaderIMG.cpp) +add_executable(datadump main.cpp ../framework/gtadata.cpp ../framework/LoaderIMG.cpp) target_link_libraries( datadump sfml-graphics sfml-window sfml-system GL GLEW ) diff --git a/datadump/main.cpp b/datadump/main.cpp index ebc7e0e2..84df1465 100644 --- a/datadump/main.cpp +++ b/datadump/main.cpp @@ -12,6 +12,7 @@ #include #include #include "../framework/rwbinarystream.h" +#include "../framework/gtadata.h" using RW::BSSectionHeader; using RW::BSFrameList; @@ -727,9 +728,9 @@ void dumpGenericTree(char* data) int main(int argc, char** argv) { - bool render = false, raw = false; + bool render = false, raw = false, loadgame = false; int c; - while ((c = getopt (argc, argv, "rt")) != -1) { + while ((c = getopt (argc, argv, "rtg")) != -1) { switch (c) { case 'r': render = true; @@ -737,47 +738,56 @@ int main(int argc, char** argv) case 't': raw = true; break; + case 'g': + loadgame = true; + break; } } char *data; - if (render) { - if (loadFile(argv[2], &data)) { - renderModel(data, atoi(argv[3])); + if(!loadgame) { + if (render) { + if (loadFile(argv[2], &data)) { + renderModel(data, atoi(argv[3])); - delete[] data; - } - } if(raw) { - if(loadFile(argv[2], &data)) { - dumpGenericTree(data); - } - } else { - for (int i = 1; i < argc; ++i) { - if ( ! loadFile(argv[i], &data)) - continue; + delete[] data; + } + } if(raw) { + if(loadFile(argv[2], &data)) { + dumpGenericTree(data); + } + } else { + for (int i = 1; i < argc; ++i) { + if ( ! loadFile(argv[i], &data)) + continue; - std::string fname = argv[i]; - auto ext = fname.substr(fname.size()-3); + std::string fname = argv[i]; + auto ext = fname.substr(fname.size()-3); + + if(ext == "dff" || ext == "DFF") + { + std::cout << "Dumping model file" << std::endl; + dumpModelFile(data); + } + else if(ext == "txd" || ext == "TXD") + { + std::cout << "Dumping texture archive" << std::endl; + dumpTextureDictionary(data); + } + else + { + std::cout << "I'm not sure what that is" << std::endl; + } - if(ext == "dff" || ext == "DFF") - { - std::cout << "Dumping model file" << std::endl; - dumpModelFile(data); - } - else if(ext == "txd" || ext == "TXD") - { - std::cout << "Dumping texture archive" << std::endl; - dumpTextureDictionary(data); - } - else - { - std::cout << "I'm not sure what that is" << std::endl; - } - - delete[] data; + delete[] data; + } } } + else { + GTAData gamedata(argv[2]); + gamedata.load(); + } return 0; } diff --git a/framework/gtadata.cpp b/framework/gtadata.cpp new file mode 100644 index 00000000..ab838eeb --- /dev/null +++ b/framework/gtadata.cpp @@ -0,0 +1,61 @@ +#include "gtadata.h" +#include +#include + +GTAData::GTAData(const std::string& path) +: datpath(path) +{ + +} + +void GTAData::load() +{ + std::ifstream datfile(datpath.c_str()); + + std::string line, cmd; + while(!datfile.eof()) + { + std::getline(datfile, line); + if(line.size() == 0 || line[0] == '#') continue; + line.erase(line.size()-1); + + size_t space = line.find_first_of(' '); + if(space != line.npos) + { + cmd = line.substr(0, space); + if(cmd == "IDE") + { + loadIDE(line.substr(space+1)); + } + else if(cmd == "SPLASH") + { + splash = line.substr(space+1); + } + else if(cmd == "COLFILE") + { + int zone = atoi(line.substr(space+1,1).c_str()); + std::string file = line.substr(space+3); + loadCOL(zone, file); + } + else if(cmd == "IPL") + { + loadIPL(line.substr(space+1)); + } + } + } +} + +void GTAData::loadIDE(const std::string& name) +{ + std::cout << "IDE File " << name << std::endl; +} + +void GTAData::loadCOL(const size_t zone, const std::string& name) +{ + std::cout << "COL File " << name << " for zone " << zone << std::endl; +} + +void GTAData::loadIPL(const std::string& name) +{ + std::cout << "IPL File " << name << std::endl; +} diff --git a/framework/gtadata.h b/framework/gtadata.h new file mode 100644 index 00000000..d3809198 --- /dev/null +++ b/framework/gtadata.h @@ -0,0 +1,40 @@ +#ifndef _GTADATA_H_ +#define _GTADATA_H_ +#include "gtfwpre.h" +#include + +/** + * Handles loading and management of the Game's DAT + */ +class GTAData +{ + std::string datpath; + std::string splash; +public: + + GTAData(const std::string& path); + + /** + * Returns the current platform + */ + std::string getPlatformString() + { + return "PC"; + } + + /** + * Loads the data contained in the given file + */ + void loadIDE(const std::string& name); + + /** + * Handles the parsing of a COL file. + */ + void loadCOL(const size_t zone, const std::string& name); + + void loadIPL(const std::string& name); + + void load(); +}; + +#endif \ No newline at end of file