void BSP_SkipTag(VFILE *fd, int fcc) { int i, j; switch(BSP_GetFccMode(fcc)&3) { case 0: break; case 1: while(1) { i=BSP_ReadFourcc(fd); if(i==FCC_enD_)break; BSP_SkipTag(fd, i); } break; case 2: j=BSP_ReadInt32(fd); vfseek(fd, j, 1); break; case 3: j=BSP_ReadInt32(fd); vfseek(fd, j, 1); break; } }
int ttvfs_stdio_fsize(VFILE *f, size_t *sizep) { long int sz = 0; if ( vfseek(f, 0, SEEK_END) != 0 || (sz = vftell(f)) < 0 || vfseek(f, 0, SEEK_SET) != 0) { return -1; } *sizep = sz; return 0; }
/********************************************************************************* * Ftell returns a file with the same indicator value, but within the range of the file occupies. */ long __stdcall vftell (VFileHandle *pVFH) { /// Indicator that the current position of the opened file is transferred vfseek (pVFH, 0, VFSEEK_CUR); /// And return. Location indicator of the relative position of the current value Im return pVFH->lCurrentOffset; }
/********************************************************************************* * 파일 indicator값을 리턴한다 ftell과 동일하지만 이 파일이 차지하는 범위내에서.. */ long __stdcall vftell (VFileHandle *pVFH) { /// 오픈된 파일의 Indicator를 현재위치로 옮긴다 vfseek (pVFH, 0, VFSEEK_CUR); /// 그리고 리턴. 현재 indicator 위치값은 상대위치임 return pVFH->lCurrentOffset; }
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); }
int RIFF_ReadChunkInfo(VFILE *fd, int ofs, int *id, int *sz, int *lid) { vfseek(fd, ofs, 0); if(id)*id=RIFF_ReadInt32(fd); if(sz)*sz=RIFF_ReadInt32(fd); if(lid)*lid=RIFF_ReadInt32(fd); return(0); }
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 }
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); }
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); }
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); }
BSP_LM *BSP_ReadLM(VFILE *fd) { static byte *buf2=NULL; BSP_LM *tmp; byte *buf; // byte *buf, *buf2; int i, j, k, l; tmp=gcalloc(sizeof(BSP_LM)); memset(tmp, 0, sizeof(BSP_LM)); // BSP_ReadFourcc(fd); i=BSP_ReadInt32(fd)+vftell(fd); BSP_ReadNormal(fd, tmp->norm); tmp->xs=BSP_ReadInt16(fd); tmp->ys=BSP_ReadInt16(fd); tmp->fl=BSP_ReadInt16(fd); tmp->dn=BSP_ReadInt16(fd); tmp->dxs=tmp->xs>>2; tmp->dys=tmp->ys>>2; if(tmp->dxs<1)tmp->dxs=1; if(tmp->dys<1)tmp->dys=1; BSP_ReadVector2_14(fd, tmp->udir); BSP_ReadVector2_14(fd, tmp->vdir); tmp->min[0]=BSP_ReadFixed(fd, 65536); tmp->min[1]=BSP_ReadFixed(fd, 65536); tmp->max[0]=BSP_ReadFixed(fd, 65536); tmp->max[1]=BSP_ReadFixed(fd, 65536); tmp->num_vecs=BSP_ReadInt16(fd); tmp->vec_xyz=gcatomic(tmp->num_vecs*3*sizeof(float)); tmp->vec_uv=gcatomic(tmp->num_vecs*2*sizeof(float)); for(j=0; j<tmp->num_vecs; j++) { BSP_ReadVector(fd, tmp->vec_xyz+j*3); BSP_ReadVector2D(fd, tmp->vec_uv+j*2); } // vfseek(fd, i, 0); // return(tmp); // printf("Read LM %dx%d\n", tmp->xs, tmp->ys); if(tmp->fl&BSPLM_FL_MONO) { tmp->lmbuf=gcatomic((tmp->xs+1)*(tmp->ys+1)); BSP_ReadImgMono(fd, tmp->lmbuf, tmp->xs, tmp->ys); tmp->texnum=Tex_LoadTextureMono(tmp->xs, tmp->ys, tmp->lmbuf); for(j=0; j<tmp->dn; j++) { tmp->dlmstyle[j]=vfgetc(fd); tmp->dlmnum[j]==-1; tmp->dlmbuf[j]=gcatomic((tmp->dxs+1)*(tmp->dys+1)); BSP_ReadImgMono(fd, tmp->dlmbuf[j], tmp->dxs, tmp->dys); tmp->dlmnum[j]=Tex_LoadTextureMono(tmp->dxs, tmp->dys, tmp->dlmbuf[j]); } }else { tmp->lmbuf=gcatomic((tmp->xs+1)*(tmp->ys+1)*4); BSP_ReadImg(fd, tmp->lmbuf, tmp->xs, tmp->ys); tmp->texnum=Tex_LoadTexture(tmp->xs, tmp->ys, tmp->lmbuf, 1); for(j=0; j<tmp->dn; j++) { tmp->dlmstyle[j]=vfgetc(fd); tmp->dlmnum[j]==-1; tmp->dlmbuf[j]=gcatomic((tmp->dxs+1)*(tmp->dys+1)*4); BSP_ReadImg(fd, tmp->dlmbuf[j], tmp->dxs, tmp->dys); tmp->dlmnum[j]=Tex_LoadTexture(tmp->dxs, tmp->dys, tmp->dlmbuf[j], 1); } } #if 0 tmp->lmbuf=gcatomic(tmp->xs*tmp->ys*4); if(tmp->fl&1)BSP_ReadImgMono(fd, tmp->lmbuf, tmp->xs, tmp->ys); else BSP_ReadImg(fd, tmp->lmbuf, tmp->xs, tmp->ys); tmp->texnum=-1; buf=tmp->lmbuf; // buf2=gcatomic(tmp->xs*tmp->ys); if(!buf2)buf2=gcatomic(2048*2048); #if 0 l=0; for(j=0; j<(tmp->xs*tmp->ys); j++) { k=(buf[j*4+0]+buf[j*4+1]*2+buf[j*4+2])/4; // k=(buf[j*4+0]+buf[j*4+1]+buf[j*4+2])/3; buf2[j]=k; if(abs(buf[j*4+0]-k)>8)break; if(abs(buf[j*4+1]-k)>8)break; if(abs(buf[j*4+2]-k)>8)break; // if(abs(buf[j*4+0]-k)>8)l=1; // if(abs(buf[j*4+1]-k)>8)l=1; // if(abs(buf[j*4+2]-k)>8)l=1; } #endif if(l) // if(1) { tmp->texnum=Tex_LoadTexture(tmp->xs, tmp->ys, tmp->lmbuf, 1); }else { tmp->texnum=Tex_LoadTextureMono(tmp->xs, tmp->ys, buf2); } // gcfree(buf2); // tmp->texnum=Tex_LoadTexture(tmp->xs, tmp->ys, tmp->lmbuf, 1); // tmp->texnum=Tex_LoadTextureMono(tmp->xs, tmp->ys, tmp->lmbuf); for(j=0; j<tmp->dn; j++) { tmp->dlmstyle[j]=vfgetc(fd); tmp->dlmnum[j]==-1; tmp->dlmbuf[j]=gcatomic(tmp->dxs*tmp->dys*4); if(tmp->fl&1) BSP_ReadImgMono(fd, tmp->dlmbuf[j], tmp->dxs, tmp->dys); else BSP_ReadImg(fd, tmp->dlmbuf[j], tmp->dxs, tmp->dys); tmp->dlmnum[j]=Tex_LoadTexture(tmp->dxs, tmp->dys, tmp->dlmbuf[j], 1); } #endif vfseek(fd, i, 0); return(tmp); }
BSP_Node *BSP_ReadNode(VFILE *fd, BSP_Model *mdl) { BSP_Node *tmp, *ntmp; BSP_Face *ftmp, *ffst, *flst; BSP_Face *ptmp, *pfst, *plst; BSP_Face *ttmp, *tfst, *tlst; int i, j, k; tmp=gcalloc(sizeof(BSP_Node)); memset(tmp, 0, sizeof(BSP_Node)); // BSP_ReadFourcc(fd, FCC_Node); lbxgl_bsp_nodestack[lbxgl_bsp_nodestackpos++]=tmp; ffst=NULL; flst=NULL; pfst=NULL; plst=NULL; tfst=NULL; tlst=NULL; while(1) { i=BSP_ReadFourcc(fd); if(i==FCC_enD_)break; if(i==FCC_nOde) { j=BSP_ReadInt32(fd); k=vftell(fd)+j; BSP_ReadNormal(fd, tmp->norm); 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_fAce) { ftmp=BSP_ReadNodeFace(fd, NULL, mdl); if(ffst) { flst->next=ftmp; flst=ftmp; } else { ffst=ftmp; flst=ftmp; } continue; } if(i==FCC_pRt) { ptmp=BSP_ReadPortal(fd, tmp); if(pfst) { plst->next=ptmp; plst=ptmp; } else { pfst=ptmp; plst=ptmp; } continue; } if(i==FCC_tSrf) { ttmp=BSP_ReadTraceSurf(fd, tmp); if(tfst) { tlst->next=ttmp; tlst=ttmp; } else { tfst=ttmp; tlst=ttmp; } continue; } if(i==FCC_Node) { ntmp=BSP_ReadNode(fd, mdl); if(!tmp->lnode) { tmp->lnode=ntmp; }else if(!tmp->rnode) { tmp->rnode=ntmp; } continue; } if(i==FCC_Leaf) { ntmp=BSP_ReadLeaf(fd, mdl); if(!tmp->lnode) { tmp->lnode=ntmp; }else if(!tmp->rnode) { tmp->rnode=ntmp; } continue; } BSP_SkipTag(fd, i); } // tmp->face=ffst; tmp->prt=pfst; tmp->tsurf=tfst; V3F_SCALEADDSCALE(tmp->mins, 0.5, tmp->maxs, 0.5, tmp->org); tmp->radius=BSP_BoundNodeSphere(tmp, tmp->org); lbxgl_bsp_nodestackpos--; 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); }
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); }
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); }
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; }
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); }