22.Jul.2009

git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@95 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
gerstrong
2009-07-22 16:38:10 +00:00
parent b45ce76900
commit 531ce04fa1
53 changed files with 7040 additions and 5553 deletions
+8 -10
View File
@@ -6,31 +6,29 @@
*/
#include "CExeFile.h"
#include <cstring>
#include <string.h>
#include <iostream>
#include <fstream>
#include "../StringUtils.h"
using namespace std;
CExeFile::CExeFile(int episode, const std::string& datadirectory) {
CExeFile::CExeFile(int episode, char *datadirectory) {
m_episode = episode;
m_datadirectory = datadirectory;
m_data = NULL;
}
CExeFile::~CExeFile() {
if(m_data) delete m_data;
if(m_data) delete [] m_data;
}
bool CExeFile::readData()
{
char filename[256];
unsigned char *m_data_temp;
std::string filename = "data/" + m_datadirectory + "keen" + itoa(m_episode) + ".exe";
sprintf(filename, "data/%skeen%d.exe", m_datadirectory, m_episode);
std::ifstream File(filename.c_str(),ios::binary);
ifstream File(filename,ios::binary);
if(!File) return false;
@@ -49,7 +47,7 @@ bool CExeFile::readData()
{
m_datasize = decdata.size();
m_data = new unsigned char[m_datasize];
memcpy(m_data, &decdata[0], m_datasize);
memcpy(m_data, decdata->data(), m_datasize);
}
else
{
@@ -57,7 +55,7 @@ bool CExeFile::readData()
m_data = new unsigned char[m_datasize];
memcpy(m_data, m_data_temp+512,m_datasize);
}
delete m_data_temp;
delete [] m_data_temp;
return true;
}
+4 -4
View File
@@ -12,11 +12,11 @@
#define CEXEFILE_H_
#include <vector>
#include <string>
using namespace std;
class CExeFile {
public:
CExeFile(int episode, const std::string& datadirectory);
CExeFile(int episode, char *datadirectory);
virtual ~CExeFile();
bool readData();
@@ -27,10 +27,10 @@ private:
int m_datasize;
int m_episode;
unsigned char *m_data;
std::string m_datadirectory;
char *m_datadirectory;
int get_bit(int *p_bit_count, unsigned char *fin, int *posin);
int unlzexe(unsigned char *fin, std::vector<unsigned char> *outbuffer);
int unlzexe(unsigned char *fin, vector<unsigned char> *outbuffer);
};
#endif /* CEXEFILE_H_ */
+3 -3
View File
@@ -83,7 +83,7 @@ bool CParser::saveParseFile(void) // open, write on the file and close
if((fp=fopen(CONFIGFILENAME,"wt")))
{
std::list<char*>::iterator i;
list<char*>::iterator i;
for(i=m_filebuffer.begin() ; i != m_filebuffer.end() ; ++i )
fprintf(fp,"%s",*i);
@@ -104,7 +104,7 @@ bool CParser::saveParseFile(void) // open, write on the file and close
int CParser::getIntValue(const char *keyword, const char *category)
{
// The getter will search for category and than for keyword. After that, read the value and return it!
std::list<char*>::iterator i;
list<char*>::iterator i;
char *line;
@@ -152,7 +152,7 @@ void CParser::saveIntValue(const char *keyword, const char *category,int value)
// 2.- category exists, but keyword not
// 3.- category and keyword exist, only the value must be changed
std::list<char*>::iterator i;
list<char*>::iterator i;
char *line;
+2 -1
View File
@@ -10,6 +10,7 @@
#include <iostream>
#include <list>
using namespace std;
class CParser {
@@ -42,7 +43,7 @@ public:
private:
bool m_isOpen;
std::list<char*> m_filebuffer;
list<char*> m_filebuffer;
};
+8 -8
View File
@@ -10,11 +10,11 @@
#include <string.h>
#include <fstream>
CPatcher::CPatcher(int episode, int version,unsigned char *data, const std::string& datadir) {
CPatcher::CPatcher(int episode, int version,unsigned char *data, char *datadir) {
m_episode = episode;
m_version = version;
m_data = data;
m_datadirectory = datadir;
strcpy(m_datadirectory, datadir);
}
CPatcher::~CPatcher() {
@@ -35,7 +35,7 @@ void CPatcher::patchMemory()
// change to the proper directory
chdir("data");
chdir(m_datadirectory.c_str());
chdir(m_datadirectory);
// TODO: Extend this part further with more commands
while(!m_TextList.empty())
@@ -80,6 +80,7 @@ void CPatcher::patchMemory()
}
}
}
}
if(!m_TextList.empty())
@@ -108,7 +109,7 @@ bool CPatcher::loadPatchfile()
{
bool ret = false;
chdir("data");
chdir(m_datadirectory.c_str());
chdir(m_datadirectory);
// Detect the patchfile
DIR *dir = opendir(".");
struct dirent *dp;
@@ -120,9 +121,8 @@ bool CPatcher::loadPatchfile()
if(strstr(dp->d_name,".pat"))
{
// The file was found! now read it into the memory!
char* buf;
std::ifstream Patchfile(dp->d_name);
ifstream Patchfile(dp->d_name);
while(!Patchfile.eof())
{
@@ -157,12 +157,12 @@ bool CPatcher::loadPatchfile()
return ret;
}
void CPatcher::patchMemfromFile(const std::string& patch_file_name, int offset)
void CPatcher::patchMemfromFile(const char *patch_file_name, int offset)
{
unsigned char *buf_to_patch;
unsigned char byte;
std::ifstream Patchfile(patch_file_name.c_str(), std::ios::binary);
ifstream Patchfile(patch_file_name, ios::binary);
if(!Patchfile) return;
+6 -6
View File
@@ -9,15 +9,15 @@
#define CPATCHER_H_
#include <list>
#include <string>
using namespace std;
class CPatcher {
public:
CPatcher(int episode, int version,unsigned char *data, const std::string& datadir);
CPatcher(int episode, int version,unsigned char *data, char *datadir);
virtual ~CPatcher();
void patchMemory();
void patchMemfromFile(const std::string& patch_file_name, int offset);
void patchMemfromFile(const char *patch_file_name, int offset);
private:
@@ -26,9 +26,9 @@ private:
int m_episode;
int m_version;
unsigned char *m_data;
std::string m_datadirectory;
std::list<char*> m_TextList;
char m_datadirectory[256];
list<char*> m_TextList;
};
+14 -9
View File
@@ -12,19 +12,24 @@
#include "../include/fileio.h"
#include "../fileio/CExeFile.h"
#include "../CLogFile.h"
#include "../StringUtils.h"
int readStoryText(char **ptext, int episode, const std::string& path)
int readStoryText(char **ptext, int episode, char *path)
{
std::string buf2 = formatPathString(path);
std::string buf = buf2 + "storytxt.ck" + itoa(episode);
FILE *fp;
if((fp=fopen(buf.c_str(),"rt"))==NULL)
{
buf = buf2 + "keen" + itoa(episode) + ".exe";
char buf[256];
char buf2[256];
if((fp=fopen(buf.c_str(),"rb"))!=NULL)
memset(buf,0,256*sizeof(char));
formatPathString(buf2,path);
sprintf(buf,"%sstorytxt.ck%d",buf2,episode);
if((fp=fopen(buf,"rt"))==NULL)
{
sprintf(buf,"%skeen%d.exe",buf2,episode);
if((fp=fopen(buf,"rb"))!=NULL)
{
unsigned char *filebuf;
int startflag=0, endflag=0; // where story begins and ends!