1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Initial GTA data class

This commit is contained in:
Daniel Evans 2013-06-30 22:21:23 +01:00
parent b006c308df
commit 3cf53a5dd6
4 changed files with 145 additions and 34 deletions

View File

@ -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 )

View File

@ -12,6 +12,7 @@
#include <iostream>
#include <fstream>
#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;
}

61
framework/gtadata.cpp Normal file
View File

@ -0,0 +1,61 @@
#include "gtadata.h"
#include <iostream>
#include <fstream>
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;
}

40
framework/gtadata.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef _GTADATA_H_
#define _GTADATA_H_
#include "gtfwpre.h"
#include <string>
/**
* 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