diff --git a/src/fileio/CExeFile.cpp b/src/fileio/CExeFile.cpp
index 45ae82653..cf00d6f58 100644
--- a/src/fileio/CExeFile.cpp
+++ b/src/fileio/CExeFile.cpp
@@ -17,7 +17,7 @@ using namespace std;
CExeFile::CExeFile(int episode, const std::string& datadirectory) {
m_episode = episode;
m_datadirectory = datadirectory;
- if( m_datadirectory != "" && *(m_datadirectory.end()) != '/') m_datadirectory += "/";
+ if( m_datadirectory != "") if(*(m_datadirectory.end()-1) != '/') m_datadirectory += "/";
m_data = NULL;
}
@@ -30,7 +30,6 @@ bool CExeFile::readData()
std::string filename = "data/" + m_datadirectory + "keen" + itoa(m_episode) + ".exe";
std::ifstream File; OpenGameFileR(File, filename, ios::binary);
- // TODO: If Exe-file wasn't detected, make the program quit somehow, or it crashes
if(!File) return false;
diff --git a/src/fileio/story.cpp b/src/fileio/story.cpp
index 54234cbd4..d09480fa9 100644
--- a/src/fileio/story.cpp
+++ b/src/fileio/story.cpp
@@ -24,43 +24,37 @@ int readStoryText(char **ptext, int episode, const std::string& path)
FILE *fp;
if((fp=OpenGameFile(buf.c_str(),"rt"))==NULL)
{
- buf = buf2 + "keen" + itoa(episode) + ".exe";
+ unsigned char *filebuf;
+ int startflag=0, endflag=0; // where story begins and ends!
- if((fp=OpenGameFile(buf.c_str(),"rb"))!=NULL)
+ CExeFile *ExeFile = new CExeFile(episode, path);
+ if(!ExeFile) return -1;
+ ExeFile->readData();
+ filebuf = ExeFile->getData();
+
+ if(episode == 2)
{
- unsigned char *filebuf;
- int startflag=0, endflag=0; // where story begins and ends!
+ startflag = 92864;
+ endflag = 96088;
+ }
+ if(episode == 3)
+ {
+ startflag = 101328;
+ endflag = 104435;
+ }
- CExeFile *ExeFile = new CExeFile(episode, buf2);
- ExeFile->readData();
- filebuf = ExeFile->getData();
-
- if(episode == 2)
- {
- startflag = 92864;
- endflag = 96088;
- }
- if(episode == 3)
- {
- startflag = 101328;
- endflag = 104435;
- }
-
- if(startflag == 0 || endflag == 0)
- {
- g_pLogFile->textOut(PURPLE,"Sorry, but your exe-file is not compatible for reading the story.
");
- }
- else
- {
- *ptext = (char*) malloc((endflag-startflag+10)*sizeof(char));
- strncpy((*ptext),(char*)filebuf+startflag,(endflag-startflag)*sizeof(char));
- }
- delete ExeFile;
-
- return (endflag-startflag);
+ if(startflag == 0 || endflag == 0)
+ {
+ g_pLogFile->textOut(PURPLE,"Sorry, but your exe-file is not compatible for reading the story.
");
}
else
- return -1;
+ {
+ *ptext = (char*) malloc((endflag-startflag+10)*sizeof(char));
+ strncpy((*ptext),(char*)filebuf+startflag,(endflag-startflag)*sizeof(char));
+ }
+ delete ExeFile;
+
+ return (endflag-startflag);
}
else
{
diff --git a/src/include/menu.h b/src/include/menu.h
index 0a88dc501..44c1b49ad 100644
--- a/src/include/menu.h
+++ b/src/include/menu.h
@@ -22,4 +22,4 @@ void keensleft(stCloneKeenPlus *pCKP);
void showmapatpos(int level, int xoff, int yoff, int wm, stCloneKeenPlus *pCKP);
short loadResourcesforStartMenu(stCloneKeenPlus *pCKP, CGame *Game);
int getDifficulty(stCloneKeenPlus *pCKP);
-void showPage(const std::string& text, stCloneKeenPlus *pCKP, int textsize);
+void showPage(const std::string& str_text, stCloneKeenPlus *pCKP, int textsize);
diff --git a/src/menu.cpp b/src/menu.cpp
index 6969e35e6..e01865b4f 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -28,7 +28,7 @@
#include
#include "StringUtils.h"
#include "FindFile.h"
-
+#include
#define SELMOVE_SPD 3
@@ -928,8 +928,9 @@ short GraphicsDlg(stCloneKeenPlus *pCKP)
// This function shows the Story of Commander Keen!
-void showPage(const std::string& text, stCloneKeenPlus *pCKP, int textsize)
+void showPage(const std::string& str_text, stCloneKeenPlus *pCKP, int textsize)
{
+ char *text;
unsigned int i, j, k;
int exit=0;
int textpos;
@@ -938,6 +939,14 @@ void showPage(const std::string& text, stCloneKeenPlus *pCKP, int textsize)
unsigned int scroll, maxscroll;
char buffer[200][40];
+
+ // copy the string to an array since string manipulation are dangerous here!
+
+ text = new char[textsize];
+ memset(text,0,textsize);
+
+ memcpy(text,str_text.c_str(),textsize);
+
showmapatpos(90, STORYBOARD_X, STORYBOARD_Y, 0, pCKP);
fade.mode = FADE_GO;
@@ -963,16 +972,16 @@ void showPage(const std::string& text, stCloneKeenPlus *pCKP, int textsize)
memset(buffer,0,200*40*sizeof(char));
// Prepare the buffer
- std::string sbuf;
+ char sbuf[256];
unsigned int totnumline=0;
for(i=0;i<200;i++)
{
for(j=0;j dlgW-2)
+ if(((strlen(sbuf) + j) > dlgW-2))
{
if(text[textpos] == ' ')
{
@@ -987,14 +996,14 @@ void showPage(const std::string& text, stCloneKeenPlus *pCKP, int textsize)
break;
}
- buffer[i][j] = text[textpos];
-
if(text[textpos]==31 ) // I don't know, what they do,
//but original version seems to ignore them!
{
- buffer[i][j]=' ';
+ text[textpos]=' ';
}
+
+ buffer[i][j]=text[textpos];
textpos++;
if(textpos >= textsize)
break;
@@ -1009,7 +1018,9 @@ void showPage(const std::string& text, stCloneKeenPlus *pCKP, int textsize)
}
buffer[i][j] = ' '; // Last character is empty!
- std::string coverline(37, (char)2);
+ delete [] text;
+
+ std::string coverline(38, (char)2);
do
{
@@ -1026,7 +1037,7 @@ void showPage(const std::string& text, stCloneKeenPlus *pCKP, int textsize)
{
if(buffer[i+(scroll>>3)][0]=='~') // Special Background Colour
{
- std::string temp(37, ' ');
+ std::string temp(38, ' ');
g_pGraphics->sb_color_font_draw(temp, (dlgX+1)<<3, (((dlgY+i+1)<<3) -(scroll%8)),COLOUR_DARKRED,COLOUR_GREY);
g_pGraphics->sb_color_font_draw(buffer[i+(scroll>>3)]+1, (dlgX+1)<<3, (((dlgY+i+1)<<3) -(scroll%8)),COLOUR_DARKRED,COLOUR_GREY);
}