📄 script.cpp
字号:
c=fgetc(ScriptFile); } return (c==EOF);}char* AsciiScripter::digits()// includes filtering of CR/LF's{ char c; char *str=scanner; BOOL done=FALSE; while (!done) { c=fgetc(ScriptFile); if (((c>='0')&&(c<='9')) || ((c>='a')&&(c<='f')) || ((c>='A')&&(c<='F')) ) *str++ = c; else if (c==' ') { done=TRUE; *str++=c; } else if ((c!=10)&&(c!=13)) { scanner[0]=0; done=TRUE; } } *str=0; return scanner;}void AsciiScripter::ReadRLE(int instreamlen, BYTE* outstream)// Does run-length-decoding from stream.{ int count,total,i,j; BYTE b; int bi; BYTE* buff=(BYTE*)pSys->AllocMem(instreamlen*2,FALSE); int colorsize=instreamlen/3; // first fill up 3-part buffer with all reds,then all greens, all blues for (i=0;i<3;i++) // for each color { total=0; while (total<colorsize) // assumes correct input, so that total count=instreamlen/3 { if (FindPercent()) break; sscanf(digits(),"%x ",&count); if (FindPercent()) break; sscanf(digits(),"%x ",&bi); b= (BYTE)bi; for (j=0;j<count;j++) buff[ total + (i*colorsize) + j ] = b; total+=count; } } // now interleave for (i=0;i<(instreamlen/3);i++) { *outstream++ = buff[i]; *outstream++ = buff[i+colorsize]; *outstream++ = buff[i+(2*colorsize)]; } pSys->FreeMem(buff,FALSE);}void AsciiScripter::ReadRaw(int instreamlen, BYTE* outstream){ BYTE b; int bi; for (int i=0;i<instreamlen;i++) { if (FindPercent()) break; sscanf(digits(),"%x ",&bi); b=(BYTE)bi; *outstream++ = b; }}///////////////////////////////////////////////////////////////////BOOL AsciiScripter::GetDebugToken(int& token){ char c; if (GetDebugInt(token)) return TRUE; if ((token<0)||(token>LAST_TOKEN)) return TRUE; // now expect LF<string>LF c=fgetc(ScriptFile); if (c!=10) return TRUE; while ( (c=fgetc(ScriptFile))!=10) ; // successfully ate debug string ReplayTokenCount++; return FALSE;}BOOL AsciiScripter::GetDebugInt(int& data){ int res,k; if (FindPercent()) { data=-1; return TRUE; } res = sscanf(digits(),"%x ",&k); if (!res) data = -1; else data=k; return FALSE;}BOOL AsciiScripter::GetDebugByte(BYTE& data){ int temp; BOOL res=GetDebugInt(temp); if (res) return TRUE; data=temp; return FALSE;}BOOL AsciiScripter::GetDebugString(char*& str,int& length){ int res,len,i; str=NULL; // in case of err rtn for (i=0; i<TEMPLEN; i++) tempStr[i]=0; GetDebugInt(res); // look for tokCharPtr if (res != tokCharPtr) return TRUE; GetDebugInt(len); // get length if (len >= TEMPLEN) return TRUE; char c=fgetc(ScriptFile); if (c!='"') return TRUE; i=0; tempStr[i]=fgetc(ScriptFile); while ((i<TEMPLEN) && (tempStr[i] != '"')) tempStr[++i]=fgetc(ScriptFile); if ((i==TEMPLEN) || (i!=len)) return TRUE; tempStr[i]=0; str=tempStr; length=len; return FALSE;}BOOL AsciiScripter::GetDebugStream(const unsigned int buffersize, BYTE*& buffer){ BYTE tok; int token; GetDebugToken(token); if (token == tokStream) { buffer = (BYTE*)pSys->AllocMem(buffersize,FALSE); if (buffer==NULL) return TRUE; int len; GetDebugInt(len); if (len==0) return FALSE; if (((unsigned int)len) != buffersize) return TRUE; for (int i=0; i < len; i++) { GetDebugByte(tok); buffer[i] = tok; } } else if ((token == tokRLEstream) || (token == tokRawStream)) { int len; GetDebugInt(len); if (len==0) buffer=NULL; else { buffer = (BYTE*)pSys->AllocMem(len,FALSE); if (token == tokRLEstream) ReadRLE(len, buffer); else ReadRaw(len, buffer); } } else return TRUE; return FALSE;}/////////////////////////////////////////////////////////////////////BOOL BinaryScripter::OpenDebugStreamR(const char* FileName){ strcpy(ScriptFileName,FileName); ScriptFile = fopen(ScriptFileName, "rb"); if (ScriptFile == NULL) return TRUE; int x; if (GetDebugInt(x)) return TRUE; TokenCount=x; ReplayTokenCount=0; fontcount=0; char *ver; if (GetDebugString(ver,x)) return TRUE; if (ParseVer(ver)) return TRUE; return FALSE;}BOOL BinaryScripter::OpenDebugStreamW(const char* FileName){ strcpy(ScriptFileName,FileName); ScriptFile = fopen(ScriptFileName, "wb"); if (ScriptFile == NULL) return TRUE; pSys->Capturing=TRUE; TokenCount=0; fontcount=0; PutDebugInt(-1); // leave space for token count char version[TEMPLEN]; sprintf(version, Version(FALSE) ); int len = strlen(version); if (PutDebugString(version, len)) return TRUE; return FALSE;}BOOL BinaryScripter::PutDebugToken(const int token){ TokenCount++; return PutDebugByte(token);}BOOL BinaryScripter::PutDebugInt(const int data){ int res=fwrite( &data, sizeof(int), 1, ScriptFile ); return (res == EOF);}BOOL BinaryScripter::PutDebugByte(const BYTE data){ int res=fputc( data, ScriptFile ); return (res == EOF);}BOOL BinaryScripter::PutDebugString(const char* str,const int len){ if (PutDebugToken(tokCharPtr)) return TRUE; if (PutDebugInt(len)) return TRUE; for (int i=0; i < len; i++) if ((fputc(str[i],ScriptFile))==EOF) return TRUE;return FALSE;}BOOL BinaryScripter::PutDebugStream(const BYTE* str,const int len){ if (PutDebugToken(tokStream)) return TRUE; if (PutDebugInt(len)) return TRUE; for (int i=0; i < len; i++) if ((fputc(str[i],ScriptFile))==EOF) return TRUE;return FALSE;}BOOL BinaryScripter::GetDebugToken(int& token){ BYTE b; if (GetDebugByte(b)) return TRUE; token=b; if (token>LAST_TOKEN) return TRUE; ReplayTokenCount++; return FALSE;}BOOL BinaryScripter::GetDebugInt(int& data){ int temp; int res = fread(&temp, sizeof(int), 1, ScriptFile); data=temp; return (res<1);}BOOL BinaryScripter::GetDebugByte(BYTE& data){ data=fgetc(ScriptFile); return FALSE;}BOOL BinaryScripter::GetDebugString(char*& str,int& length){ int res,len,i; str=NULL; // in case of err rtn for (i=0; i<TEMPLEN; i++) tempStr[i]=0; GetDebugToken(res); // look for tokCharPtr if (res != tokCharPtr) return TRUE; GetDebugInt(len); // get length if (len >= TEMPLEN) return TRUE; for (i=0; i<len; i++) if ((tempStr[i]=fgetc(ScriptFile))==EOF) return TRUE; tempStr[i]=0; str=tempStr; length=len; return FALSE;}BOOL BinaryScripter::GetDebugStream(const unsigned int buffersize, BYTE*& buffer){ int token; BYTE tok; GetDebugToken(token); if (token != tokStream) return TRUE; buffer = (BYTE*)pSys->AllocMem(buffersize,FALSE); if (buffer==NULL) return TRUE; int len; GetDebugInt(len); if (len==0) { pSys->FreeMem(buffer,FALSE); buffer=NULL; return FALSE; } if (((unsigned int)len) != buffersize) return TRUE; for (int i=0; i < len; i++) { GetDebugByte(tok); buffer[i] = tok; } return FALSE;}APDK_END_NAMESPACE#endif //APDK_CAPTURE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -