static struct HJT * readhindo (FILE *fp) { struct HJT *hjt1; hjt1 = (struct HJT *) malloc (sizeof (struct HJT)); if (input_header_hjt (fp, hjt1) == -1) { wnn_errorno = WNN_NOT_A_FILE; free (hjt1); return (NULL); } hjt1->bufsize_serial = (hjt1->maxserial + MAXSERIAL); hjt1->hindo = (UCHAR *) NULL; hjt1->comment = (w_char *) NULL; if ((hjt1->hindo = (UCHAR *) malloc (hjt1->bufsize_serial)) == NULL || (hjt1->comment = (w_char *) malloc (hjt1->maxcomment * sizeof (w_char))) == NULL) { wnn_errorno = WNN_MALLOC_ERR; free (hjt1->hindo); free (hjt1->comment); free (hjt1); log_err ("could not allocate hindo area."); return (NULL); } if (vfread (hjt1->comment, 2, hjt1->maxcomment, fp) != hjt1->maxcomment) { wnn_errorno = WNN_NOT_HINDO_FILE; log_err ("not a correct hindo file."); goto error; } if (vfread (hjt1->hindo, 1, hjt1->maxserial, fp) != hjt1->maxserial) { wnn_errorno = WNN_NOT_HINDO_FILE; log_err ("not a correct hindo file."); goto error; } hjt1->hdirty = 0; return (hjt1); error: hjt1 = free_hindo (hjt1); return (NULL); }
/** * "파일 풀기"를 눌렀을때 파일을 하나 푸는 함수 */ void CFV_Select::OnMenu_Extract () { int * pIndecies = NULL; /// 선택된 인덱스를 저장 CListBox * plistSel = NULL; /// 리스트 박스용 int nSelCnt = 0; /// 선택된 갯수 BYTE * btBuff = NULL; /// 임시버퍼 CVFS_Manager * pVFS = NULL; /// vfs파일 핸들 FILE * fp = NULL; /// 임시 파일포인터 VFileHandle *pVFH = NULL; /// vfs 파일핸들 CString strText = "", strFileName = "", strDir = ""; /// 스트링, 파일이름, 폴더 if(m_list.GetSelCount () > 0 && (plistSel = GetListBox ()) && (pVFS = ::g_pDlg_Main->GetVFS()) &&::g_pDlg_Main->GetSelectedVfsName ().GetLength () > 0) { /// 파일을 풀 디렉토리를 묻는다 if(GetFolder (&strDir, "파일을 풀 폴더를 선택하세요", GetSafeHwnd (), NULL, NULL)) { /// 인덱스를 저장하기 위해서 메모리를 할당 if((pIndecies = new int[m_list.GetSelCount ()])) { /// 선택된 인덱스들을 가져옴 m_list.GetSelItems (m_list.GetSelCount (), pIndecies); nSelCnt = m_list.GetSelCount (); for(short i = 0; i < nSelCnt; i++) { strText = ""; /// 리스트박스에서 문자열을 가져옴 plistSel->GetText (pIndecies[ nSelCnt - 1 - i ], strText); /// base file명만 불리해서 여기에 다시 저장하고 그리고 파일 생성할 때 사용한다 strFileName = strText; if(strFileName.ReverseFind ('\\') >= 0) { strFileName = strFileName.Right (strFileName.GetLength () - strFileName.ReverseFind ('\\') - 1); } long lFileLength = pVFS->GetFileLength (strText.GetString ()); if(lFileLength >= 0 && (btBuff = new BYTE[ lFileLength ])) { if((pVFH = pVFS->OpenFile (strText.GetString ()))) { vfread (btBuff, sizeof (BYTE), (size_t)lFileLength, pVFH); _fmode = _O_BINARY; if((fp = fopen (strDir + "\\" + strFileName, "w"))) { fwrite (btBuff, sizeof(BYTE), (size_t)lFileLength, fp); fclose (fp); } delete btBuff; pVFS->CloseFile (pVFH); } } } delete pIndecies; } } } }
bool TiXmlDocument::LoadFile( VFILE* file, TiXmlEncoding encoding ) { if ( !file ) { SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } // Delete the existing data: Clear(); location.Clear(); // Get the file size, so we can pre-allocate the string. HUGE speed impact. size_t length = 0; // Strange case, but good to handle up front. if ( vfsize(file, &length) < 0 || length <= 0 ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } // Subtle bug here. TinyXml did use fgets. But from the XML spec: // 2.11 End-of-Line Handling // <snip> // <quote> // ...the XML processor MUST behave as if it normalized all line breaks in external // parsed entities (including the document entity) on input, before parsing, by translating // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to // a single #xA character. // </quote> // // It is not clear fgets does that, and certainly isn't clear it works cross platform. // Generally, you expect fgets to translate from the convention of the OS to the c/unix // convention, and not work generally. /* while( fgets( buf, sizeof(buf), file ) ) { data += buf; } */ char* buf = new char[ length+1 ]; buf[0] = 0; if ( vfread( buf, length, 1, file ) != 1 ) { delete [] buf; SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } return LoadMem(buf, length, encoding); }
int main(int argc, char *argv[]) { #if VFS_USING_C_API // <- This will be defined if VFS_ENABLE_C_API is on and the ttvfs overrides are in use. ttvfs::Root vfs; vfs.AddLoader(new ttvfs::DiskLoader); ttvfs_setroot(&vfs); // The C-like API supports only one (global) root object. // Must be set before calling any of the functions, // and must stay alive and unchanged while any VFILEs are opened. puts("Using VFS"); #else puts("Not using VFS"); #endif VFILE *fh = vfopen("myfile.txt", "r"); if(!fh) { puts("ERROR: File not found: myfile.txt"); return 1; } char buf[513]; size_t bytes = vfread(buf, 1, 512, fh); buf[bytes] = 0; puts(buf); vfclose(fh); //---------------------------------- InStream strm("mydata.txt"); if(strm) { // The below is mostly copied from example #3 unsigned int i, line = 0; float f; std::string s; while(true) { ++line; strm >> s >> i >> f; // we may hit EOF, causing any of the reads to fail if(!strm) // after reading, check if line was read in completely break; std::cout << "Line " << line << ": String '" << s << "', int " << i << ", float " << f << std::endl; } strm.close(); } return 0; }
void *RIFF_ReadInChunk(VFILE *fd, int ofs, int *size) { int cc1, cc2, sz; void *buf; RIFF_ReadChunkInfo(fd, ofs, &cc1, &sz, &cc2); if(size)*size=sz; buf=malloc(sz+1024); vfseek(fd, ofs+8, 0); vfread(buf, 1, sz+1024, fd); return(buf); }
uint32 zz_vfs_pkg::read_ (char * buf, const uint32 size) { assert(size < MAX_FILESIZE); uint32 read_size = 0; if (fp_) { #define KEYSIZE 0x1000 long Mpointer = vftell(fp_) % KEYSIZE; read_size = vfread(buf, 1, size, fp_); if(fp_->btEncrypted==0x90) { size_t spt; spt = fp_->sFileName.find_last_of("/\\"); std::string hashstring1 = fp_->sFileName.substr(spt+1, (fp_->sFileName.length()-spt)); unsigned long key = StrToHashKey(hashstring1.c_str()); char crypttable[KEYSIZE]; DWORD *EAX=reinterpret_cast<DWORD*>(crypttable); DWORD EDI=0; DWORD ECX = key; DWORD EDX = key+1; ECX = ECX*4+1; for(int i = 0; i < 0x400; i++) { EDI=ECX*EDX; *((DWORD*)EAX) = EDI; EAX++; ECX+=4; EDX++; } for(size_t k=0;k<read_size;k++) { *((char*)buf+k)^= crypttable[Mpointer]; Mpointer++; Mpointer %= KEYSIZE; } } } else { ZZ_LOG("vfs_pkg: read_() failed. invalid fp_.\n"); return 0; } assert(read_size < MAX_FILESIZE); if (read_size >= MAX_FILESIZE) { ZZ_LOG("vfs_pkg: read_(%s) failed. read_size = %d.\n", filename_.get(), read_size); read_size = 0; } return read_size; }
LBXGL_Entity *BSP_ReadEnts(VFILE *fd) { char buf[256]; char *tbuf; LBXGL_Entity *ents, *etmp, *elst; char *str, *s, *t, **a; int i, j; // BSP_ReadFourcc(fd, FCC_eNts); i=BSP_ReadInt32(fd); tbuf=gcatomic(i+1); memset(tbuf, 0, i+1); vfread(tbuf, 1, i, fd); ents=NULL; elst=NULL; s=tbuf; while(*s) { t=buf; while(*s && (*s<=' '))s++; while(*s && *s!='\n')*t++=*s++; while(*s && (*s<=' '))s++; *t++=0; a=ksplit(buf); if(!a[0])continue; if(!strcmp(a[0], "{")) { etmp=BSP_ParseEntity(&s); if(elst) { elst->next=etmp; elst=etmp; }else { ents=etmp; elst=etmp; } } } gcfree(tbuf); return(ents); }
BGBBTJ_API byte *BGBBTJ_JPG_Load(VFILE *fd, int *xs, int *ys) { byte *buf, *obuf; int fsz; vfseek(fd, 0, 2); fsz=vftell(fd); vfseek(fd, 0, 0); buf=malloc(fsz+256); vfread(buf, 1, fsz, fd); obuf=BGBBTJ_JPG_Decode(buf, fsz, xs, ys); free(buf); return(obuf); }
char *bgbcc_loadfile(char *name, int *rsz) { VFILE *fd; void *buf; int sz; fd=vffopen(name, "rb"); if(!fd)return(NULL); vfseek(fd, 0, 2); sz=vftell(fd); vfseek(fd, 0, 0); buf=bgbcc_malloc(sz+16); memset(buf, 0, sz+16); vfread(buf, 1, sz, fd); vfclose(fd); if(rsz)*rsz=sz; return(buf); #if 0 char *buf, *buf1; int i, sz; buf=basm_loadfile(name, &sz); if(buf) { buf1=bgbcc_malloc(sz); memcpy(buf1, buf, sz); basm_free(buf); if(rsz)*rsz=sz; return(buf1); } return(NULL); #endif }
PDGL_Sample *PDGL_Sound_LoadWAV(char *name) { VFILE *fd; PDGL_Sample *tmp; int i, j; unsigned int tag, len, rsrc; byte *buf; int chan, rate, bits; kprint("PDGL_Sound_LoadWAV: Loading sample '%s'\n", name); fd=vffopen(name, "rb"); if(!fd) { kprint("PDGL_Sound_LoadWAV: Failed open sample '%s'\n", name); return(NULL); } tag=0; len=0; rsrc=0; for(i=0; i<4; i++) tag+=vfgetc(fd)<<(i*8); for(i=0; i<4; i++) len+=vfgetc(fd)<<(i*8); for(i=0; i<4; i++) rsrc+=vfgetc(fd)<<(i*8); if(tag!=PDGL_RIFF_RIFF) { kprint("PDGL_Sound_LoadWAV: File Tag not RIFF\n"); return(NULL); } if(rsrc!=PDGL_RIFF_WAVE) { kprint("PDGL_Sound_LoadWAV: Resource type not WAVE\n"); return(NULL); } //fmt tag=0; len=0; for(i=0; i<4; i++) tag+=vfgetc(fd)<<(i*8); for(i=0; i<4; i++) len+=vfgetc(fd)<<(i*8); buf=kralloc(len); vfread(buf, 1, len, fd); chan=buf[2]; rate=buf[4]+(buf[5]<<8); bits=buf[14]; //data tag=0; len=0; for(i=0; i<4; i++) tag+=vfgetc(fd)<<(i*8); for(i=0; i<4; i++) len+=vfgetc(fd)<<(i*8); buf=kalloc(len); vfread(buf, 1, len, fd); //fill in sample // tmp->len=len/2; // tmp->buf=buf; tmp=PDGL_Sound_SampleFromBuf(name, buf, chan, rate, bits, len); kfree(buf); // kprint("Loaded sample '%s', %d samples\n", name, tmp->len); return(tmp); }
LBXGL_World *BSP_ReadBSP(char *name) { VFILE *fd; LBXGL_World *tmp; LBXGL_Entity *cur, *ents; BSP_Model *mtmp, *mfst, *mlst, *mcur; LBXGL_Light *lfst, *llst, *ltmp; char *s, *t; int i, j; fd=vffopen(name, "rb"); tmp=gctalloc("lbxgl_world_t", sizeof(LBXGL_World)); i=BSP_ReadFourcc(fd); j=BSP_ReadFourcc(fd); if((i!=FCC_ItCF) || (j!=FCC_bsp)) { kprint("BSP_ReadBSP: Invalid 'ItCF' or 'bsp ' magic\n"); return(NULL); } mfst=NULL; mlst=NULL; while(1) { i=BSP_ReadFourcc(fd); if(i==FCC_enD_)break; if(i==FCC_Mdl) { mtmp=BSP_ReadModel(fd); if(mlst) { mlst->next=mtmp; mlst=mtmp; }else { mfst=mtmp; mlst=mtmp; } continue; } if(i==FCC_eNts) { ents=BSP_ReadEnts(fd); continue; } if(i==FCC_sStr) { j=BSP_ReadInt32(fd); tmp->styles[tmp->num_styles]=gcatomic(j+1); vfread(tmp->styles[tmp->num_styles], 1, j, fd); tmp->style_gamma[tmp->num_styles]=1.0; tmp->style_flags[tmp->num_styles]=1; tmp->num_styles++; continue; } BSP_SkipTag(fd, i); } lfst=NULL; llst=NULL; cur=ents; while(cur) { cur->world=tmp; s=LBXGL_Entity_GetProperty(cur, "model"); if(s && (*s=='*')) { i=atoi(s+1); mcur=mfst; while(mcur && i--)mcur=mcur->next; LBXGL_Entity_SetProperty(cur, "mdl", mcur); cur->bmdl=mcur; // mcur->ent=cur; } s=LBXGL_Entity_GetProperty(cur, "classname"); if(s && !strncmp(s, "light", 5)) { ltmp=gcalloc(sizeof(LBXGL_Light)); LBXGL_Entity_GetPropertyFVector(cur, "origin", ltmp->org, 3); LBXGL_Entity_GetPropertyFVector(cur, "_color", ltmp->clr, 3); ltmp->val[0]=LBXGL_Entity_GetPropertyFloat( cur, "light"); ltmp->val[1]=LBXGL_Entity_GetPropertyFloat( cur, "hilight"); ltmp->flags=LBXGL_Entity_GetPropertyFloat( cur, "spawnflags"); ltmp->style=-1; t=LBXGL_Entity_GetProperty(cur, "style"); if(t) { for(i=0; i<tmp->num_styles; i++) if(!strcmp(tmp->styles[i], t)) break; if(i<tmp->num_styles)ltmp->style=i; } if(Vec3F_Length(ltmp->clr)<0.1) { ltmp->clr[0]=1; ltmp->clr[1]=1; ltmp->clr[2]=1; } Vec3F_Normalize(ltmp->clr, ltmp->clr); if(llst) { llst->next=ltmp; llst=ltmp; }else { lfst=ltmp; llst=ltmp; } } cur=cur->next; } tmp->bsp=mfst->root; tmp->mdls=mfst; tmp->ents=ents; tmp->lights=lfst; tmp->id=-1; return(tmp); }
BSP_Node *BSP_ReadLeaf(VFILE *fd, BSP_Model *mdl) { BSP_Node *tmp; BSP_Face *ftmp, *ffst, *flst, *tfst, *tlst; int i, j, k; tmp=gcalloc(sizeof(BSP_Node)); memset(tmp, 0, sizeof(BSP_Node)); // BSP_ReadFourcc(fd, FCC_Leaf); ffst=NULL; flst=NULL; tfst=NULL; tlst=NULL; while(1) { i=BSP_ReadFourcc(fd); if(i==FCC_enD_)break; if(i==FCC_lEaf) { j=BSP_ReadInt32(fd); k=vftell(fd)+j; BSP_ReadVectorI(fd, tmp->mins); BSP_ReadVectorI(fd, tmp->maxs); tmp->flags=BSP_ReadInt16(fd); tmp->num=BSP_ReadInt16(fd); vfseek(fd, k, 0); continue; } if(i==FCC_vIs) { j=BSP_ReadInt32(fd); tmp->szvis=j; tmp->vis=gcatomic(j); vfread(tmp->vis, 1, j, fd); continue; } if(i==FCC_fAc1) { ftmp=BSP_ReadLeafFace(fd); if(tfst) { tlst->next=ftmp; tlst=ftmp; }else { tfst=ftmp; tlst=ftmp; } continue; } if(i==FCC_fAce) { ftmp=BSP_ReadNodeFace(fd, tmp, mdl); if(ffst) { flst->next=ftmp; flst=ftmp; }else { ffst=ftmp; flst=ftmp; } continue; } BSP_SkipTag(fd, i); } tmp->face=ffst; tmp->tsurf=tfst; V3F_SCALEADDSCALE(tmp->mins, 0.5, tmp->maxs, 0.5, tmp->org); tmp->radius=BSP_BoundNodeSphere(tmp, tmp->org); return(tmp); }
BSP_Model *BSP_ReadModel(VFILE *fd) { char buf[64], buf2[256]; BSP_Model *tmp; BSP_LM *ltmp, *llst; float org[3]; int i, j, k, l; tmp=gctalloc("bsp_model_t", sizeof(BSP_Model)); // memset(tmp, 0, sizeof(BSP_Model)); // BSP_ReadFourcc(fd, FCC_Mdl); // BSP_ReadFourcc(fd, FCC_hEad); // BSP_ReadInt32(fd, 18); l=0; llst=NULL; while(1) { i=BSP_ReadFourcc(fd); if(i==FCC_enD_)break; if(i==FCC_hEad) { j=BSP_ReadInt32(fd); k=vftell(fd)+j; BSP_ReadVectorI(fd, org); //mins BSP_ReadVectorI(fd, org); //maxs BSP_ReadVectorI(fd, org); //org vfseek(fd, k, 0); continue; } if(i==FCC_tExi) { j=BSP_ReadInt32(fd); k=vftell(fd)+j; tmp->num_tex=j/64; tmp->texnames=gcalloc(tmp->num_tex*sizeof(char *)); tmp->tex_xs=gcatomic(tmp->num_tex*sizeof(int)); tmp->tex_ys=gcatomic(tmp->num_tex*sizeof(int)); tmp->tex_fl=gcatomic(tmp->num_tex*sizeof(int)); tmp->tex_num=gcatomic(tmp->num_tex*sizeof(int)); tmp->tex_num2=gcatomic(tmp->num_tex*sizeof(int)); for(j=0; j<tmp->num_tex; j++) { memset(buf, 0, 64); vfread(buf, 1, 56, fd); tmp->texnames[j]=kstrdup(buf); tmp->tex_xs[j]=BSP_ReadInt16(fd); tmp->tex_ys[j]=BSP_ReadInt16(fd); BSP_ReadInt16(fd); BSP_ReadInt16(fd); tmp->tex_num[j]=-1; tmp->tex_num2[j]=-1; sprintf(buf2, "textures/%s", buf); tmp->tex_num[j]=LBXGL_Texture_LoadImage(buf2); sprintf(buf2, "textures/%s_s", buf); tmp->tex_num2[j]=LBXGL_Texture_LoadImage(buf2); tmp->tex_fl[j]= LBXGL_Texture_GetImageFlags( tmp->tex_num[j]); } vfseek(fd, k, 0); continue; } if(i==FCC_lMi) { ltmp=BSP_ReadLM(fd); ltmp->num=l++; if(llst) { llst->next=ltmp; llst=ltmp; }else { tmp->lmroot=ltmp; llst=ltmp; } continue; } if(i==FCC_Node) { lbxgl_bsp_nodestackpos=0; tmp->root=BSP_ReadNode(fd, tmp); continue; } if(i==FCC_Leaf) { lbxgl_bsp_nodestackpos=0; tmp->root=BSP_ReadLeaf(fd, tmp); continue; } BSP_SkipTag(fd, i); } return(tmp); }
LBXGL_QMDL *LBXGL_QuakeMD4_StageLoad(LBXGL_QMDL *tmp, VFILE *fd) { quake_qmdl_t *head; float *vecbuf; quake_md3surf_t *surf; quake_md4lod_t *lod; int i, j, k, base; char namebuf[65]; printf("loading md4 %s\n", tmp->name); head=&tmp->head; // head->ident=ReadInt32LE(fd); // head->version=ReadInt32LE(fd); if(head->ident!=QMD4_ID) { printf("LBXGL_QuakeMD4_Load(%s): Invalid Ident\n", tmp->name); return(NULL); } if(head->version!=QMD4_VERSION) { printf("LBXGL_QuakeMD4_Load(%s): Invalid Version\n", tmp->name); return(NULL); } vfread(namebuf, 1, 64, fd); head->num_frames=ReadInt32LE(fd); head->num_bones=ReadInt32LE(fd); head->ofs_frames=ReadInt32LE(fd); head->num_lods=ReadInt32LE(fd); head->ofs_lods=ReadInt32LE(fd); head->ofs_end=ReadInt32LE(fd); tmp->frames=gcalloc(head->num_frames*sizeof(float *)); tmp->framenames=gcalloc(head->num_frames*sizeof(char *)); tmp->lods=gcalloc(head->num_lods*sizeof(quake_md4lod_t *)); vfseek(fd, head->ofs_frames, 0); for(i=0; i<head->num_frames; i++) { for(j=0; j<10; j++)ReadFloat32LE(fd); vfread(namebuf, 1, 16, fd); printf("frame name: '%s'\n", namebuf); tmp->frames[i]=gcalloc(12*head->num_bones*sizeof(float)); vecbuf=tmp->frames[i]; for(j=0; j<head->num_bones*12; j++) vecbuf[j]=ReadFloat32LE(fd); } base=head->ofs_lods; for(i=0; i<head->num_lods; i++) { vfseek(fd, base, 0); lod=gcalloc(sizeof(quake_md4lod_t)); tmp->lods[i]=lod; lod->num_surfaces=ReadInt32LE(fd); lod->ofs_surfaces=ReadInt32LE(fd); lod->ofs_end=ReadInt32LE(fd); printf("lod: %d surfs: %d\n", i, lod->num_surfaces); LBXGL_QuakeMD4_LoadSurfs(tmp, lod, fd, base); base+=lod->ofs_end; } return(0); }
PDGL_Sample *PDGL_Sound_LoadMP3(char *name) { VFILE *fd; PDGL_Sample *tmp; struct mpstr mp; int i, j; byte *buf, *s, *ibuf, *obuf; int chan, rate, bits, bitrate, lty; int len, ret, size, bufsize, ofs; kprint("PDGL_Sound_LoadMP3: Loading sample '%s'\n", name); fd=vffopen(name, "rb"); if(!fd) { kprint("PDGL_Sound_LoadMP3: Failed open sample '%s'\n", name); return(NULL); } InitMP3(&mp); buf=malloc(10<<20); s=buf; ibuf=kalloc(16384); obuf=kalloc(16384); len=vfread(ibuf, 1, 16384, fd); ofs=statMP3(ibuf, &rate, &chan, &bitrate, <y); bits=16; kprint("PDGL_Sound_LoadMP3: %d Hz, %d chan, %d bps, layer %d, ofs %d\n", rate, chan, bitrate, lty, ofs); vfseek(fd, 0, 2); size=vftell(fd); len=(size+((bitrate/8)-1))/(bitrate/8); bufsize=len*rate*chan*4; //2x est stream len kprint("PDGL_Sound_LoadMP3: aprox %d seconds, buf %d bytes\n", len, bufsize); vfseek(fd, ofs, 0); buf=malloc(bufsize); s=buf; while(!vfeof(fd)) { len=vfread(ibuf, 1, 16384, fd); if(len<=0)break; ret = decodeMP3(&mp,ibuf,len,obuf,16384,&size); while(ret == MP3_OK) { memcpy(s, obuf, size); s+=size; ret = decodeMP3(&mp,NULL,0,obuf,16384,&size); } if((s-buf)>((bufsize*2)/3)) { kprint("PDGL_Sound_LoadMP3: overflow\n"); break; } } len=s-buf; kprint("PDGL_Sound_LoadMP3: decoded %f seconds\n", (float)len/(rate*chan*2)); tmp=PDGL_Sound_SampleFromBuf(name, buf, chan, rate, bits, len); kfree(ibuf); kfree(obuf); free(buf); return(tmp); }
LBXGL_QMDL *LBXGL_QuakeMD3_Load(char *name) { char namebuf[65]; LBXGL_QMDL *tmp; quake_qmdl_t *head; byte *skinbuf; float *vecbuf; quake_md3surf_t *surf; VFILE *fd; char *s, *t; int i, j, k, base; int w, h; fd=vffopen(name, "rb"); if(!fd)return(NULL); printf("loading md3 %s\n", name); tmp=gctalloc("lbxgl_quakemdl_t", sizeof(LBXGL_QMDL)); head=&tmp->head; head->ident=ReadInt32LE(fd); head->version=ReadInt32LE(fd); if(head->ident==QMD4_ID) { tmp->name=dystrdup(name); LBXGL_QuakeMD4_StageLoad(tmp, fd); return(tmp); } if(head->ident!=QMD3_ID) { printf("LBXGL_QuakeMD3_Load(%s): Invalid Ident\n", name); return(NULL); } if(head->version!=QMD3_VERSION) { printf("LBXGL_QuakeMD3_Load(%s): Invalid Version\n", name); return(NULL); } vfread(namebuf, 1, 64, fd); head->flags=ReadInt32LE(fd); head->num_frames=ReadInt32LE(fd); head->num_tags=ReadInt32LE(fd); head->num_surfaces=ReadInt32LE(fd); head->num_skins=ReadInt32LE(fd); head->ofs_frames=ReadInt32LE(fd); head->ofs_tags=ReadInt32LE(fd); head->ofs_surfaces=ReadInt32LE(fd); head->ofs_end=ReadInt32LE(fd); tmp->tags=gcalloc(12*head->num_tags*sizeof(float)); tmp->tagnames=gcalloc(head->num_tags*sizeof(char *)); tmp->surfs=gcalloc(head->num_surfaces*sizeof(quake_md3surf_t *)); vfseek(fd, head->ofs_frames, 0); for(i=0; i<head->num_frames; i++) { for(j=0; j<10; j++)ReadFloat32LE(fd); vfread(namebuf, 1, 16, fd); printf("frame name: '%s'\n", namebuf); } vfseek(fd, head->ofs_tags, 0); for(i=0; i<head->num_tags; i++) { vfread(namebuf, 1, 64, fd); printf("tag name: '%s'\n", namebuf); printf("tag values:"); for(j=0; j<12; j++) { tmp->tags[(i*12)+j]=ReadFloat32LE(fd); printf(" %f", tmp->tags[(i*12)+j]); } printf("\n"); } base=head->ofs_surfaces; for(i=0; i<head->num_surfaces; i++) { vfseek(fd, base, 0); surf=gcalloc(sizeof(quake_md3surf_t)); tmp->surfs[i]=surf; surf->ident=ReadInt32LE(fd); vfread(surf->name, 1, 64, fd); surf->flags=ReadInt32LE(fd); surf->num_frames=ReadInt32LE(fd); surf->num_shaders=ReadInt32LE(fd); surf->num_verts=ReadInt32LE(fd); surf->num_triangles=ReadInt32LE(fd); surf->ofs_triangles=ReadInt32LE(fd); surf->ofs_shaders=ReadInt32LE(fd); surf->ofs_st=ReadInt32LE(fd); surf->ofs_xyz=ReadInt32LE(fd); surf->ofs_end=ReadInt32LE(fd); printf("surface name: '%s'\n", surf->name); printf("surface frames: %d shaders: %d verts: %d tris: %d\n", surf->num_frames, surf->num_shaders, surf->num_verts, surf->num_triangles); surf->tris=gcalloc(3*surf->num_triangles*sizeof(int)); surf->shaders=gcalloc(surf->num_shaders*sizeof(char *)); surf->st=gcalloc(2*surf->num_verts*sizeof(int)); surf->frames=gcalloc(surf->num_frames*sizeof(float *)); surf->sdrnums=gcalloc(surf->num_shaders*sizeof(int)); vfseek(fd, base+surf->ofs_triangles, 0); for(j=0; j<surf->num_triangles; j++) { surf->tris[(j*3)+0]=ReadInt32LE(fd); surf->tris[(j*3)+1]=ReadInt32LE(fd); surf->tris[(j*3)+2]=ReadInt32LE(fd); } vfseek(fd, base+surf->ofs_shaders, 0); for(j=0; j<surf->num_shaders; j++) { vfread(namebuf, 1, 64, fd); surf->shaders[j]=dystrdup(namebuf); ReadInt32LE(fd); s=namebuf+strlen(namebuf); while((s>namebuf) && (*s!='/') && (*s!='.'))s--; if(*s=='.')*s=0; printf("shader name: '%s'\n", namebuf); surf->sdrnums[j]=LBXGL_Texture_LoadImage(namebuf); if(surf->sdrnums[j]<0) { printf("missing skin %s\n", namebuf); surf->sdrnums[j]=0; } #if 0 skinbuf=Tex_LoadFileRaw(namebuf, &w, &h); if(skinbuf) { surf->sdrnums[j]=Tex_LoadTexture(w, h, skinbuf, 1); free(skinbuf); }else { printf("missing skin %s\n", namebuf); } #endif } vfseek(fd, base+surf->ofs_st, 0); for(j=0; j<surf->num_verts; j++) { surf->st[(j*2)+0]=ReadFloat32LE(fd); surf->st[(j*2)+1]=ReadFloat32LE(fd); // printf("st(%d): %f %f\n", j, // surf->st[(j*2)+0], surf->st[(j*2)+1]); } vfseek(fd, base+surf->ofs_xyz, 0); for(j=0; j<surf->num_frames; j++) { vecbuf=gcalloc(3*surf->num_verts*sizeof(float)); surf->frames[j]=vecbuf; for(k=0; k<surf->num_verts; k++) { vecbuf[(k*3)+0]=ReadInt16LE(fd)/64.0; vecbuf[(k*3)+1]=ReadInt16LE(fd)/64.0; vecbuf[(k*3)+2]=ReadInt16LE(fd)/64.0; ReadInt16LE(fd); vecbuf[(k*3)+0]*=QMD3_SCALE; vecbuf[(k*3)+1]*=QMD3_SCALE; vecbuf[(k*3)+2]*=QMD3_SCALE; } } base=base+surf->ofs_end; } printf("\n"); return(tmp); }
int LBXGL_QuakeMD4_LoadSurfs(LBXGL_QMDL *tmp, quake_md4lod_t *lod, VFILE *fd, int base) { quake_qmdl_t *head; quake_md3surf_t *surf; quake_md4vertex_t *vert; int i, j, k; char namebuf[65]; head=&tmp->head; lod->surfs=gcalloc(lod->num_surfaces*sizeof(quake_md3surf_t *)); base+=lod->ofs_surfaces; for(i=0; i<lod->num_surfaces; i++) { vfseek(fd, base, 0); surf=gcalloc(sizeof(quake_md3surf_t)); tmp->surfs[i]=surf; surf->ident=ReadInt32LE(fd); vfread(surf->name, 1, 64, fd); vfread(surf->shader, 1, 64, fd); ReadInt32LE(fd); surf->ofs_header=ReadInt32LE(fd); surf->num_verts=ReadInt32LE(fd); surf->ofs_verts=ReadInt32LE(fd); surf->num_triangles=ReadInt32LE(fd); surf->ofs_triangles=ReadInt32LE(fd); surf->num_bonerefs=ReadInt32LE(fd); surf->ofs_bonerefs=ReadInt32LE(fd); surf->ofs_end=ReadInt32LE(fd); printf("surface name: '%s'\n", surf->name); printf("surface shader: '%s'\n", surf->shader); printf("surface verts: %d tris: %d bonerefs: %d\n", surf->num_verts, surf->num_triangles, surf->num_bonerefs); surf->tris=gcalloc(3*surf->num_triangles*sizeof(int)); surf->md4verts=gcalloc(surf->num_verts*sizeof(quake_md4vertex_t *)); surf->bonerefs=gcalloc(surf->num_bonerefs*sizeof(int)); vfseek(fd, base+surf->ofs_verts, 0); for(j=0; j<surf->num_verts; j++) { vert=gcalloc(sizeof(quake_md4vertex_t)); surf->md4verts[j]=vert; for(k=0; k<3; k++) vert->vertex[k]=ReadFloat32LE(fd); for(k=0; k<3; k++) vert->normal[k]=ReadFloat32LE(fd); for(k=0; k<2; k++) vert->st[k]=ReadFloat32LE(fd); vert->num_weights=ReadInt32LE(fd); vert->bone_indices=gcalloc(vert->num_weights*sizeof(int)); vert->bone_weights=gcalloc(vert->num_weights*sizeof(float)); for(k=0; k<vert->num_weights; k++) { vert->bone_indices[k]=ReadInt32LE(fd); vert->bone_weights[k]=ReadFloat32LE(fd); } } vfseek(fd, base+surf->ofs_triangles, 0); for(j=0; j<surf->num_triangles; j++) { surf->tris[(j*3)+0]=ReadInt32LE(fd); surf->tris[(j*3)+1]=ReadInt32LE(fd); surf->tris[(j*3)+2]=ReadInt32LE(fd); } vfseek(fd, base+surf->ofs_bonerefs, 0); for(j=0; j<surf->num_bonerefs; j++) surf->bonerefs[i]=ReadInt32LE(fd); base=base+surf->ofs_end; } return(0); }
void vfgttxt ( char fname[], int *iret ) /************************************************************************ * vfgttxt * * * * This function gets and reads the ww----.txt file information which * * is used to create SEL, SAW, SEV and the cancel text products for * * SAW and SEL. * * * * vfgttxt ( fname, iret ) * * * * Input parameters: * * fname[] char Input File Name * * * * Output parameters: * * *iret int Return Code * * * ** * * Log: * * A. Hardy/GSC 2/00 Created * * A. Hardy/GSC 5/00 Removed 'file not found' statement * * A. Hardy/GSC 12/00 Removed '&' from iret * ***********************************************************************/ { int ierr; /*---------------------------------------------------------------------*/ *iret = 0; /* * Store the text filename. */ strcpy ( spcinfo.file_info.filnam, fname ); /* * Open text file to be read. */ spcinfo.file_info.ifp = cfl_ropn( spcinfo.file_info.filnam, NULL, &ierr); *iret = ierr; if ( *iret == 0 ) { /* * Read in verification file. */ vfread ( iret ); /* * Close text file. */ cfl_clos ( spcinfo.file_info.ifp, iret ); spcinfo.file_info.ifp = NULL; } /* * If the WW filename is incorrect, send an error. */ else { *iret = -1; } }
bool zz_vfs_pkg::open (const char * filename_in, const zz_vfs_mode mode) { if(mode==ZZ_VFS_WRITE) return false; //ZZ_LOG("vfs_pkg:open(%s)\n", filename); //ZZ_PROFILER_INSTALL(vfs_pkg_open); zz_assert(filename_in); zz_assert(filename_in[0]); zz_slash_converter filename(filename_in); if (fp_) { close(); } assert(!fp_); if (!pkg_system_) { ZZ_LOG("vfs_pkg: open(%s) failed. invalid pkg_system_.\n", filename.get()); return false; } //ZZ_LOG("vfs_pkg: open(%s)\n", filename); VHANDLE fsystem = pkg_system_->get_filesystem(); // switch (mode) { // case zz_vfs::ZZ_VFS_READ: fp_ = VOpenFile(filename, fsystem); zz_assertf( fp_, "vfs_pkg: open(%s) failed.", filename.get() ); filename_.set(filename); //check if it is encrypted fp_->btEncrypted=0; //if(fp_->btFileType==0){ size_t spt; spt = fp_->sFileName.find_last_of("/\\"); std::string hashstring1 = fp_->sFileName.substr(spt+1, (fp_->sFileName.length()-spt)); //OutputDebugString(hashstring1.c_str()); unsigned long key = StrToHashKey(hashstring1.c_str()); char crypttable[16]; DWORD *EAX=reinterpret_cast<DWORD*>(crypttable); DWORD EDI=0; DWORD ECX = key; DWORD EDX = key+1; ECX = ECX*4+1; for(int i = 0; i < 4; i++) { EDI=ECX*EDX; *((DWORD*)EAX) = EDI; EAX++; ECX+=4; EDX++; } vfseek(fp_, 0, VFSEEK_END); long off_set = vftell(fp_); if(off_set>16) { off_set-=16; vfseek(fp_,off_set, VFSEEK_SET); char buffer[16]; vfread(&buffer,1,16,fp_); if(buffer[0]==crypttable[0]){ if(buffer[1]==crypttable[1]){ if(buffer[2]==crypttable[2]){ if(buffer[3]==crypttable[3]){ if(buffer[4]==crypttable[4]){ if(buffer[5]==crypttable[5]){ if(buffer[6]==crypttable[6]){ if(buffer[7]==crypttable[7]){ if(buffer[8]==crypttable[8]){ if(buffer[9]==crypttable[9]){ if(buffer[10]==crypttable[10]){ if(buffer[11]==crypttable[11]){ if(buffer[12]==crypttable[12]){ if(buffer[13]==crypttable[13]){ if(buffer[14]==crypttable[14]){ if(buffer[15]==crypttable[15]){ fp_->btEncrypted=0x90; fp_->lEndOff-=16; //MessageBox(0,fp_->sFileName.c_str()," is encrypted",0); } } } } } } } } } } } } } } } } } vfseek(fp_,0, VFSEEK_SET); // break; // case zz_vfs::ZZ_VFS_WRITE: // not implemented yet!!! // break; // } if (!fp_) { return false; } return true; }
static struct JT * readdict (FILE *fp) { struct JT *jt1; long x; jt1 = (struct JT *) malloc (sizeof (struct JT)); jt1->node = 0; if (input_header_jt (fp, jt1) == -1) { wnn_errorno = WNN_NOT_A_FILE; free (jt1); return (NULL); } if (jt1->syurui == WNN_UD_DICT) { jt1->bufsize_serial = (jt1->maxserial + MAXSERIAL); jt1->bufsize_kanji = (jt1->maxkanji + MAXKANJI); jt1->bufsize_hontai = (jt1->maxhontai + MAXHONTAI); jt1->bufsize_table = (jt1->maxtable + MAXTABLE); jt1->bufsize_ri1[D_YOMI] = 0; jt1->bufsize_ri1[D_KANJI] = 0; #if defined(CONVERT_by_STROKE) || defined(CONVERT_with_SiSheng) } else if ((jt1->syurui & 0xff) == WNN_REV_DICT) { #else } else if (jt1->syurui == WNN_REV_DICT) { #endif /* CONVERT_by_STROKE || CONVERT_with_SiSheng */ jt1->bufsize_serial = (jt1->maxserial + MAXSERIAL); jt1->bufsize_kanji = (jt1->maxkanji + MAXKANJI); jt1->bufsize_hontai = (jt1->maxhontai + MAXHONTAI); jt1->bufsize_table = 0; jt1->bufsize_ri1[D_YOMI] = (jt1->maxri1[D_YOMI] + MAXTABLE); jt1->bufsize_ri1[D_KANJI] = (jt1->maxri1[D_KANJI] + MAXTABLE); } else if (jt1->syurui == WNN_STATIC_DICT) { /* WNN_STATIC_DICT */ jt1->bufsize_serial = jt1->maxserial; jt1->bufsize_kanji = jt1->maxkanji; jt1->bufsize_hontai = jt1->maxhontai; jt1->bufsize_table = 0; jt1->bufsize_ri1[D_YOMI] = 0; jt1->bufsize_ri1[D_KANJI] = 0; } else { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); free (jt1); return (NULL); } if (alloc_dict (jt1) == -1) { free (jt1); return (NULL); } if (vfread (jt1->comment, 2, jt1->maxcomment, fp) != jt1->maxcomment) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } if (vfread (jt1->hinsi_list, 2, jt1->maxhinsi_list, fp) != jt1->maxhinsi_list) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } if (vfread (jt1->hindo, 1, jt1->maxserial, fp) != jt1->maxserial) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } if (vfread (jt1->hinsi, 2, jt1->maxserial, fp) != jt1->maxserial) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } #ifdef CONVERT_with_SiSheng if (jt1->syurui == CWNN_REV_DICT) if (vfread (jt1->sisheng, 2, jt1->maxserial, fp) != jt1->maxserial) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } #endif /* CONVERT_with_SiSheng */ if (vfread (jt1->kanji, 1, jt1->maxkanji, fp) != jt1->maxkanji) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } if (vfread (jt1->table, sizeof (struct uind1), jt1->maxtable, fp) != jt1->maxtable) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } if (vfread (jt1->ri1[D_YOMI], sizeof (struct rind1), jt1->maxri1[D_YOMI], fp) != jt1->maxri1[D_YOMI]) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } if (vfread (jt1->ri1[D_KANJI], sizeof (struct rind1), jt1->maxri1[D_KANJI], fp) != jt1->maxri1[D_KANJI]) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } if (vfread (jt1->hontai, 1, jt1->maxhontai, fp) != jt1->maxhontai) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } if (vfread (jt1->ri2, sizeof (struct rind2), jt1->maxri2, fp) != jt1->maxri2) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } if (fp != NULL) { x = ftell (fp); fseek (fp, 0, 2); if (x != ftell (fp)) { wnn_errorno = WNN_NOT_A_DICT; log_err ("not a correct dictionary."); goto error; } } make_hinsi_list (jt1); if (jt1->maxhontai == 0 && (jt1->syurui == WNN_UD_DICT || jt1->syurui == WNN_STATIC_DICT)) { jt1->maxhontai = 4; } if (little_endian ()) { revdic (jt1, 0); } jt1->dirty = 0; jt1->hdirty = 0; #ifdef CONVERT_by_STROKE if (jt1->syurui == BWNN_REV_DICT) if ((jt1->max_bnode = create_b_index (jt1)) == -1) { goto error; } #endif /* CONVERT_by_STROKE */ return (jt1); error: jt1 = free_dict (jt1); return (NULL); }
byte *BGBBTJ_PCX_Load(VFILE *fd, int *w, int *h, char *pal) { struct PcxHead_s head; unsigned char *buf, *s; int i, j, sz; unsigned char t; int width, height; head.tag=vfgetc(fd); if(head.tag!=0x0A) { printf("PCX_LoadPCX: invalid tag\n"); return(NULL); } head.version=vfgetc(fd); head.encoding=vfgetc(fd); if((head.encoding!=0) && (head.encoding!=1)) { printf("PCX_LoadPCX: bad encoding\n"); return(NULL); } head.bpp=vfgetc(fd); if(head.bpp!=8) { printf("PCX_LoadPCX: bpp is not 8 bits\n"); return(NULL); } head.minx=vfgetc(fd); head.minx+=vfgetc(fd)<<8; head.miny=vfgetc(fd); head.miny+=vfgetc(fd)<<8; head.maxx=vfgetc(fd); head.maxx+=vfgetc(fd)<<8; head.maxy=vfgetc(fd); head.maxy+=vfgetc(fd)<<8; head.hres=vfgetc(fd); head.hres+=vfgetc(fd)<<8; head.vres=vfgetc(fd); head.vres+=vfgetc(fd)<<8; vfread(head.map, 1, 48, fd); head.resv=vfgetc(fd); head.planes=vfgetc(fd); head.linesz=vfgetc(fd); head.linesz+=vfgetc(fd)<<8; head.paltype=vfgetc(fd); head.paltype+=vfgetc(fd)<<8; vfread(head.resv2, 1, 58, fd); width=(head.maxx-head.minx)+1; height=(head.maxy-head.miny)+1; if(w)*w=width; if(h)*h=height; sz=width*height; buf=malloc(sz+256); if(!head.encoding) { vfread(buf, 1, sz, fd); return(buf); } s=buf; while((s-buf)<sz) { t=vfgetc(fd); if(t>=0xC0) { j=t&0x3F; t=vfgetc(fd); while(j--)*s++=t; }else *s++=t; } if(pal) { vfseek(fd, -769, 2); t=vfgetc(fd); if(t==12) vfread(pal, 1, 768, fd); } return(buf); }
/*-- Cat pdnet;Protocols;Meta0 Form int Meta0_HandleConnection(Meta0_Con *con); Description Polls a connection for activity. Status Internal --*/ int Meta0_HandleConnection(Meta0_Con *con) { Meta0_PortInfo *inf; int i, sz; char *s, *t; // printf("Meta0_HandleConnection %p\n", con); if(!con->buf) { con->buf=gcalloc(65536); con->end=con->buf; } inf=con->info; if(inf && inf->think) inf->think(con); while(1) { memset(con->end, 0, 65536-(con->end-con->buf)); sz=vfread(con->end, 1, 65536-(con->end-con->buf), con->sock); if(sz<0)break; // if(sz>0)gc_printf("meta0: %p got %d bytes\n", con, sz); con->end+=sz; *con->end=0; // gc_printf("%s", con->buf); if(con->end==con->buf)break; i=con->end-con->buf; s=con->buf; if(inf->input) sz=inf->input(con); else sz=-1; // gc_printf("meta0 stat: %p %p %d\n", con->buf, s, sz); if(sz==-1)break; s+=sz; if(s!=con->buf) { t=con->buf; while(s<con->end)*t++=*s++; con->end=t; }else break; } if(sz<0) { gc_printf("Meta0: Connection closed, service %s.\n", inf->name); if(inf->closed) inf->closed(con); vfclose(con->sock); con->sock=NULL; meta0_cons[con->num]=NULL; if(con->buf)gcfree(con->buf); gcfree(con); } return(0); }