diff options
author | Chris Xiong <chirs241097@gmail.com> | 2015-08-17 22:40:33 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2015-08-17 22:40:33 +0800 |
commit | 03a307b58ddc6244d3fad8d77d7f0bac0a24e05d (patch) | |
tree | c578005d3c66ccc53ed454e63403c30f72230924 /extensions | |
parent | bfe4f5ac512493bd9a359a06875288fbfaea6ff8 (diff) | |
download | bullet-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.
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/smanim.cpp | 11 | ||||
-rw-r--r-- | extensions/smbmfont.cpp | 6 | ||||
-rw-r--r-- | extensions/smdatapack.cpp | 6 | ||||
-rw-r--r-- | extensions/smentity.cpp | 17 | ||||
-rw-r--r-- | extensions/smttfont.cpp | 2 |
5 files changed, 31 insertions, 11 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 ©) { memcpy(this,©,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); |