aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2015-08-17 22:40:33 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2015-08-17 22:40:33 +0800
commit03a307b58ddc6244d3fad8d77d7f0bac0a24e05d (patch)
treec578005d3c66ccc53ed454e63403c30f72230924
parentbfe4f5ac512493bd9a359a06875288fbfaea6ff8 (diff)
downloadbullet-lab-remix-03a307b58ddc6244d3fad8d77d7f0bac0a24e05d.tar.xz
Fix crashes in smAnmFile.
Do not crash if a non-exist file is requested in a DTP file. Fix several stupid typos. Fix missing smEntity3D constructor. Fix line spacing in smTTFont.
-rw-r--r--extensions/smanim.cpp11
-rw-r--r--extensions/smbmfont.cpp6
-rw-r--r--extensions/smdatapack.cpp6
-rw-r--r--extensions/smentity.cpp17
-rw-r--r--extensions/smttfont.cpp2
-rw-r--r--include/smanim.hpp4
-rw-r--r--include/smbmfont.hpp4
-rw-r--r--include/smdatapack.hpp4
-rw-r--r--include/smelt.hpp14
-rw-r--r--smelt/sdl/smelt_internal.hpp8
-rw-r--r--smelt/sdl/sys_sdl.cpp8
11 files changed, 52 insertions, 32 deletions
diff --git a/extensions/smanim.cpp b/extensions/smanim.cpp
index 5d8cac5..6d09032 100644
--- a/extensions/smanim.cpp
+++ b/extensions/smanim.cpp
@@ -12,9 +12,10 @@
#include <cstdio>
#include <cstring>
#define METAWARN(s) printf("metafile warning at line %d: %s\n",lc,s)
-void smAnmFile::parseMeta(char* meta,DWORD size)
+SMELT* smAnmFile::sm=NULL;
+void smAnmFile::parseMeta(const char* meta,DWORD size)
{
- char* cp=meta;
+ const char* cp=meta;
bool inAnim=false;
int lc=0;
smAnmInfo cur;
@@ -23,7 +24,7 @@ void smAnmFile::parseMeta(char* meta,DWORD size)
int cc=0;
for(;*(cp+cc)!='\n';++cc);
char line[65];
- strncpy(cp,line,cc);line[cc-1]='\0';
+ strncpy(line,cp,cc);line[cc-1]='\0';
cp+=cc+1;++lc;
if(inAnim&&line[0]!='F'&&line[0]!='E'){METAWARN("Only instruction F is allowed between A and E.");continue;}
if(line[0]=='E')
@@ -76,7 +77,7 @@ void smAnmFile::parseMeta(char* meta,DWORD size)
int cn=0;while(line[cn+2]!=',')++cn;
t.name=new char[cn];strncpy(t.name,line+2,cn);
t.name[cn-1]='\0';
- int cn2=0;while(line[cn+3+cn2]!=',')++cn2;
+ int cn2=0;while(line[cn+3+cn2]!=',')++cn2;++cn2;
t.path=new char[cn2];strncpy(t.path,line+3+cn,cn2);
t.path[cn2-1]='\0';
sscanf(line+4+cn+cn2,"%f,%f,%f,%f",&t.rect.x,&t.rect.y,&t.rect.w,&t.rect.h);
@@ -101,7 +102,7 @@ void smAnmFile::parseMeta(char* meta,DWORD size)
}
}
}
-bool smAnmFile::loadAnmFromMemory(char* ptr,DWORD size)
+bool smAnmFile::loadAnmFromMemory(const char* ptr,DWORD size)
{
sm=smGetInterface(SMELT_APILEVEL);
anm.openDtpFromMemory(ptr,size);
diff --git a/extensions/smbmfont.cpp b/extensions/smbmfont.cpp
index fb550a0..292c2b7 100644
--- a/extensions/smbmfont.cpp
+++ b/extensions/smbmfont.cpp
@@ -16,9 +16,9 @@
SMELT *smBMFont::sm=NULL;
SMELT *smBMFontw::sm=NULL;
-void smBMFont::parseMeta(char* meta,DWORD size)
+void smBMFont::parseMeta(const char* meta,DWORD size)
{
- char* cp=meta;
+ const char* cp=meta;
char line[65];
int cc,cod,pa,pb;smTexRect rct;
while(cp-meta<=size)
@@ -44,7 +44,7 @@ void smBMFont::parseMeta(char* meta,DWORD size)
}
}
}
-bool smBMFont::loadAnmFromMemory(char* ptr,DWORD size)
+bool smBMFont::loadAnmFromMemory(const char* ptr,DWORD size)
{
sm=smGetInterface(SMELT_APILEVEL);
anm.openDtpFromMemory(ptr,size);hadv=0;
diff --git a/extensions/smdatapack.cpp b/extensions/smdatapack.cpp
index 78082bb..2e77324 100644
--- a/extensions/smdatapack.cpp
+++ b/extensions/smdatapack.cpp
@@ -36,7 +36,7 @@ bool smDtpFileR::openDtp(const char* path)
m[std::string(f.path)]=f;
}
}
-bool smDtpFileR::openDtpFromMemory(char* ptr,DWORD size)
+bool smDtpFileR::openDtpFromMemory(const char* ptr,DWORD size)
{
enmemory=true;msize=size;
if(!ptr||size<4)return false;
@@ -84,6 +84,7 @@ char* smDtpFileR::getPrevFile(const char* path)
char* smDtpFileR::getFilePtr(const char* path)
{
std::string fns(path);
+ if(m.find(fns)==m.end()){printf("error: file not found in the archive.\n");return NULL;}
if(m.at(fns).data)return m.at(fns).data;
else
{
@@ -112,6 +113,7 @@ char* smDtpFileR::getFilePtr(const char* path)
void smDtpFileR::releaseFilePtr(const char* path)
{
std::string fns(path);
+ if(m.find(fns)==m.end()){printf("error: file not found in the archive.\n");return;}
if(m[fns].data)
{
delete[] m[fns].data;
@@ -119,7 +121,7 @@ void smDtpFileR::releaseFilePtr(const char* path)
}
}
DWORD smDtpFileR::getFileSize(const char* path)
-{return m[std::string(path)].size;}
+{if(m.find(std::string(path))==m.end()){printf("error: file not found in the archive.\n");return 0;}return m[std::string(path)].size;}
smDtpFileW::smDtpFileW(){fcnt=0;}
bool smDtpFileW::addFile(const char* path,const char* realpath)
diff --git a/extensions/smentity.cpp b/extensions/smentity.cpp
index ea28e74..00660e5 100644
--- a/extensions/smentity.cpp
+++ b/extensions/smentity.cpp
@@ -126,6 +126,23 @@ smEntity3D::smEntity3D(SMTEX tex,float _x,float _y,float _w,float _h)
for(int i=0;i<4;++i){quad.v[i].z=.5f;quad.v[i].col=0xFFFFFFFF;}
quad.blend=BLEND_ALPHABLEND;
}
+smEntity3D::smEntity3D(SMTEX tex,smTexRect rect)
+{
+ sm=smGetInterface(SMELT_APILEVEL);
+ tx=rect.x;ty=rect.y;w=rect.w;h=rect.h;
+ if(tex)
+ {
+ texw=sm->smTextureGetWidth(tex);
+ texh=sm->smTextureGetHeight(tex);
+ }else texw=texh=1.;
+ ctrx=ctry=0;quad.tex=tex;
+ quad.v[0].tx=rect.x/texw;quad.v[0].ty=rect.y/texh;
+ quad.v[1].tx=(rect.x+rect.w)/texw;quad.v[1].ty=rect.y/texh;
+ quad.v[2].tx=(rect.x+rect.w)/texw;quad.v[2].ty=(rect.y+rect.h)/texh;
+ quad.v[3].tx=rect.x/texw;quad.v[3].ty=(rect.y+rect.h)/texh;
+ for(int i=0;i<4;++i){quad.v[i].z=.5f;quad.v[i].col=0xFFFFFFFF;}
+ quad.blend=BLEND_ALPHABLEND;
+}
smEntity3D::smEntity3D(const smEntity3D &copy)
{
memcpy(this,&copy,sizeof(smEntity3D));
diff --git a/extensions/smttfont.cpp b/extensions/smttfont.cpp
index 935b8a8..f3e8b1c 100644
--- a/extensions/smttfont.cpp
+++ b/extensions/smttfont.cpp
@@ -20,7 +20,7 @@ bool smTTChar::setChar(wchar_t c,FT_Face ttface)
FT_UInt glyph_index=FT_Get_Char_Index(ttface,c);
if(FT_Load_Glyph(ttface,glyph_index,FT_LOAD_DEFAULT))return false;
if(FT_Render_Glyph(ttface->glyph,FT_RENDER_MODE_NORMAL))return false;
- _w=slot->advance.x>>6;_h=slot->advance.y?slot->advance.y>>6:slot->bitmap.rows;_h=(int)(_h*1.5);
+ _w=slot->advance.x>>6;_h=3*slot->bitmap.rows-2*slot->bitmap_top;
rw=slot->bitmap.width;rh=slot->bitmap.rows;
xofs=slot->bitmap_left;yofs=slot->bitmap.rows-slot->bitmap_top;
quad.tex=sm->smTextureCreate(rw?rw:1,rh?rh:1);
diff --git a/include/smanim.hpp b/include/smanim.hpp
index 8cc4eef..c203961 100644
--- a/include/smanim.hpp
+++ b/include/smanim.hpp
@@ -35,12 +35,12 @@ class smAnmFile
private:
static SMELT *sm;
smDtpFileR anm;
- void parseMeta(char* meta,DWORD size);
+ void parseMeta(const char* meta,DWORD size);
std::map<std::string,smTexInfo> tm;
std::map<std::string,smAnmInfo> am;
std::map<std::string,SMTEX> xm;
public:
- bool loadAnmFromMemory(char* ptr,DWORD size);
+ bool loadAnmFromMemory(const char* ptr,DWORD size);
void close();
smTexInfo* getTextureInfo(const char* name);
smAnmInfo* getAnimationInfo(const char* name);
diff --git a/include/smbmfont.hpp b/include/smbmfont.hpp
index 6a0f1c1..44f2e2f 100644
--- a/include/smbmfont.hpp
+++ b/include/smbmfont.hpp
@@ -27,9 +27,9 @@ private:
int pdb[256],pda[256],b;
DWORD color;
std::map<std::string,SMTEX> xm;
- void parseMeta(char* meta,DWORD size);
+ void parseMeta(const char* meta,DWORD size);
public:
- bool loadAnmFromMemory(char* ptr,DWORD size);
+ bool loadAnmFromMemory(const char* ptr,DWORD size);
void close();
void render(float x,float y,float z,int align,float *rw,const char* text);
void printf(float x,float y,float z,int align,float *rw,const char* format,...);
diff --git a/include/smdatapack.hpp b/include/smdatapack.hpp
index 8431b58..2689eb3 100644
--- a/include/smdatapack.hpp
+++ b/include/smdatapack.hpp
@@ -30,10 +30,10 @@ private:
bool enmemory;
DWORD msize;
- char *cp,*bp;
+ const char *cp,*bp;
public:
bool openDtp(const char* path);
- bool openDtpFromMemory(char* ptr,DWORD size);
+ bool openDtpFromMemory(const char* ptr,DWORD size);
void closeDtp();
char* getFirstFile();
char* getLastFile();
diff --git a/include/smelt.hpp b/include/smelt.hpp
index b5c324e..95b3934 100644
--- a/include/smelt.hpp
+++ b/include/smelt.hpp
@@ -42,7 +42,7 @@ typedef uint8_t BYTE;
//Handles
typedef size_t SMTEX;//Texture Handle
typedef size_t SMTRG;//Target Handle
-typedef size_t SMSFX;//Sound/FX Handle
+typedef size_t SMSFX;//SoundFX Handle
typedef size_t SMCHN;//Channel Handle
//Color Marcos
@@ -58,15 +58,15 @@ typedef size_t SMCHN;//Channel Handle
#define SETB(col,b) (((col)&0xFFFFFF00)+DWORD(b))
//Blend Modes
-#define BLEND_COLORINV 0x8
#define BLEND_COLORADD 0x1
#define BLEND_COLORMUL 0x0
+#define BLEND_COLORINV 0x8
#define BLEND_ALPHABLEND 0x2
#define BLEND_ALPHAADD 0x0
#define BLEND_ZWRITE 0x4
#define BLEND_NOZWRITE 0x0
-typedef bool (*SMHook)();
+typedef bool (*smHook)();
#define FPS_FREE 0
#define FPS_VSYNC -1
@@ -120,10 +120,10 @@ public:
virtual bool smInit()=0;
virtual void smFinale()=0;
virtual void smMainLoop()=0;
- virtual void smUpdateFunc(SMHook func)=0;
- virtual void smUnFocFunc(SMHook func)=0;
- virtual void smFocFunc(SMHook func)=0;
- virtual void smQuitFunc(SMHook func)=0;
+ virtual void smUpdateFunc(smHook func)=0;
+ virtual void smUnFocFunc(smHook func)=0;
+ virtual void smFocFunc(smHook func)=0;
+ virtual void smQuitFunc(smHook func)=0;
virtual void smWinTitle(const char* title)=0;
virtual bool smIsActive()=0;
virtual void smNoSuspend(bool para)=0;
diff --git a/smelt/sdl/smelt_internal.hpp b/smelt/sdl/smelt_internal.hpp
index 8b36ebf..73960a7 100644
--- a/smelt/sdl/smelt_internal.hpp
+++ b/smelt/sdl/smelt_internal.hpp
@@ -91,10 +91,10 @@ public:
virtual bool smInit();
virtual void smFinale();
virtual void smMainLoop();
- virtual void smUpdateFunc(SMHook func);
- virtual void smUnFocFunc(SMHook func);
- virtual void smFocFunc(SMHook func);
- virtual void smQuitFunc(SMHook func);
+ virtual void smUpdateFunc(smHook func);
+ virtual void smUnFocFunc(smHook func);
+ virtual void smFocFunc(smHook func);
+ virtual void smQuitFunc(smHook func);
virtual void smWinTitle(const char* title);
virtual bool smIsActive();
virtual void smNoSuspend(bool para);
diff --git a/smelt/sdl/sys_sdl.cpp b/smelt/sdl/sys_sdl.cpp
index 1892069..8ae3da1 100644
--- a/smelt/sdl/sys_sdl.cpp
+++ b/smelt/sdl/sys_sdl.cpp
@@ -178,10 +178,10 @@ void SMELT_IMPL::smMainLoop()
}
clearQueue();Active=false;
}
-void SMELT_IMPL::smUpdateFunc(SMHook func){pUpdateFunc=func;}
-void SMELT_IMPL::smUnFocFunc(SMHook func){pUnFocFunc=func;}
-void SMELT_IMPL::smFocFunc(SMHook func){pFocFunc=func;}
-void SMELT_IMPL::smQuitFunc(SMHook func){pQuitFunc=func;}
+void SMELT_IMPL::smUpdateFunc(smHook func){pUpdateFunc=func;}
+void SMELT_IMPL::smUnFocFunc(smHook func){pUnFocFunc=func;}
+void SMELT_IMPL::smFocFunc(smHook func){pFocFunc=func;}
+void SMELT_IMPL::smQuitFunc(smHook func){pQuitFunc=func;}
void SMELT_IMPL::smWinTitle(const char *title){strcpy(winTitle,title);}
bool SMELT_IMPL::smIsActive(){return Active;}
void SMELT_IMPL::smNoSuspend(bool para){noSuspend=para;}