Fixed problem when opening the story scene. Nevertheless, that function must be improved.
git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@190 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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.<br>");
|
||||
}
|
||||
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.<br>");
|
||||
}
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
31
src/menu.cpp
31
src/menu.cpp
@@ -28,7 +28,7 @@
|
||||
#include <fstream>
|
||||
#include "StringUtils.h"
|
||||
#include "FindFile.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#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-1;j++)
|
||||
{
|
||||
sbuf = text.substr(textpos);
|
||||
sscanf(text+textpos,"%s",sbuf);
|
||||
|
||||
if((sbuf.size() + 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user