static struct font* font_load_header(struct font *pf) { /* Check we have enough data */ if (!HAVEBYTES(28)) return NULL; /* read magic and version #*/ if (memcmp(pf->buffer_position, VERSION, 4) != 0) return NULL; pf->buffer_position += 4; /* font info*/ pf->maxwidth = readshort(pf); pf->height = readshort(pf); pf->ascent = readshort(pf); pf->buffer_position += 2; /* Skip padding */ pf->firstchar = readlong(pf); pf->defaultchar = readlong(pf); pf->size = readlong(pf); /* get variable font data sizes*/ /* # words of bitmap_t*/ pf->bits_size = readlong(pf); return pf; }
void readMidiFileHeader(FILE *fp, struct mhead *h) { fread(h->chunktype, sizeof h->chunktype, 1, fp); h->length = readlong(fp); h->format = readshort(fp); h->ntrks = readshort(fp); h->division = readshort(fp); }
void readq(int *q,dword addr) { int i; readshort(q,addr,64*2); // for(i=0;i<64;i++) q[i]=8; for(i=1;i<64;i++) q[i]*=2; }
void LoadMesh3(char *fn) { FILE *file; int i, ver, nparts, nverts, form; file = fopen(fn, "rb"); if(!file) fErr("Cannot open file.", -4); form = readint(file); if(form != 'hseM') // If file format in not mesh3 fErr("Unknown format.", -5); ver = readint(file); // Attachment Points // Can also be attached to another Mesh3/Anim3 or even to particles (.PSystem) // At the moment ignored. fseek(file, 12, SEEK_SET); nparts = readshort(file); for(i = 0; i < nparts; i++) { ignorestr(file); fseek(file, 0x1D, SEEK_CUR); ignorestr(file); } // Positions nverts = readshort(file); lstverts = (float*)malloc(nverts*3*sizeof(float)); int x = 0; fread(lstverts, nverts*3*sizeof(float), 1, file); dbg("1"); // Sphere fseek(file, 16, SEEK_CUR); // Remapper // Only exists if version is 3 (WKO), version 4 (WKBattles) removed it. if(ver < 4) { nremap = (ushort)readshort(file); remapper = new uint[nremap]; for(int i = 0; i < nremap; i++) remapper[(ushort)readshort(file)] = i; //remapper[i] = (ushort)readshort(file); } else { nremap = nverts; remapper = new uint[nremap]; for(int i = 0; i < nremap; i++) remapper[i] = i; } // Normals // At the moment they are ignored. int nnorm = readshort(file); fseek(file, readint(file) * 2, SEEK_CUR); // Materials // A material consists of 2 things: // - a single byte indicating if alpha test should be enabled (1) or not (0) // on this material // - a string of 8-bit characters ending with byte 0 which is the file name // of the texture located in "Warrior Kings Game Set\Textures\" int nmat = readshort(file); lstmatflags = (int*)malloc(nmat*sizeof(int)); lstmattex = (IDirect3DTexture9**)malloc(nmat*sizeof(IDirect3DTexture9*)); for(i = 0; i < nmat; i++) { char *s = new char[256]; char *p = s; lstmatflags[i] = readchar(file); strcpy(s, texdir); p = s + strlen(s); while(*(p++) = fgetc(file)); IDirect3DTexture9 *tex; if(FAILED(D3DXCreateTextureFromFile(ddev, s, &tex))) fErr("Cannot load texture. Be sure you have made the \"Textures\" directory in the directory of the executable and you have copied the textures from the game in that directory. Look at \"readme.txt\" for more details.", -700); lstmattex[i] = tex; delete [] s; } dbg("2"); // Texture coordinates // Every UV list contains the same amount of texture coordinates. // Each UV list correspond to a player color. For example the UV list #0 // contains UV vertices that map to brown parts of the texture which correspond // to the brown player, #1 corresponds to blue, #2 yellow, #3 red, ... // As such, if you want to switch the player color, you simply switch to // the corresponding UV list. int nuvlist = readint(file); lstuvlist = (float**)malloc(nuvlist * sizeof(float*)); for(int l = 0; l < nuvlist; l++) { int ntexc = readshort(file); float *uvl = (float*)malloc(ntexc * 2 * sizeof(float)); fread(uvl, ntexc * 2 * sizeof(float), 1, file); lstuvlist[l] = uvl; muvlist.add(new GrowList<float>); } dbg("3"); // Groups // A group of a certain number corresponds to the material with the // same number. Logically there must be as many groups as materials. ngrp = readint(file); mgrpindex = (uint*)malloc((ngrp+1) * sizeof(uint)); mgrpindex[0] = 0; for(i = 0; i < ngrp; i++) { int sg = readshort(file); for(int j = 0; j < sg; j++) { int v = readshort(file); iverts.add(v); for(int k = 0; k < 3; k++) mverts.add(lstverts[v*3+k]); readshort(file); // Index to normal list v = readshort(file); for(int u = 0; u < nuvlist; u++) for(int k = 0; k < 2; k++) (muvlist[u])->add((lstuvlist[u])[v*2+k]); } mgrpindex[i+1] = mgrpindex[i]+sg; } dbg("4"); // Polygon Lists // One used at the moment. int ntrilist = readint(file); readshort(file); readshort(file); readshort(file); readfloat(file); mstartix = (uint*)malloc((nmat + 1) * sizeof(uint)); mstartix[0] = 0; // For every group/material for(int n = 0; n < nmat; n++) { int np = readshort(file); readshort(file); readshort(file); mstartix[n+1] = mstartix[n] + (np * 3); // For every triangle (polygon with 3 points) for(i = 0; i < np; i++) for(int j = 0; j < 3; j++) mindices.add(readshort(file)+mgrpindex[n]); } // Output some debug file. //FILE *df = fopen("debug.txt", "w"); //for(i = 0; i < mindices.len/3; i++) // fprintf(df, "%u %u %u\n", mindices[i*3], mindices[i*3+1], mindices[i*3+2]); //for(i = 0; i < mgrpindex.len; i++) // fprintf(df, "%u\n", mgrpindex[i]); //for(i = 0; i < mverts.len/3; i++) // fprintf(df, "%f %f %f\n", mverts[i*3], mverts[i*3+1], mverts[i*3+2]); //for(i = 0; i < muvlist[0]->len/2; i++) // fprintf(df, "%f %f\n", muvlist[0]->get(i*2), muvlist[0]->get(i*2+1)); //fclose(df); fclose(file); }
// error: !=0 si erreur fatale static RESP_STRUCT readtable(htsmoduleStruct * str, FILE * fp, RESP_STRUCT trans, int *error) { char rname[1024]; unsigned short int length; int j; *error = 0; // pas d'erreur trans.file_position = -1; trans.type = (int) (unsigned char) fgetc(fp); switch (trans.type) { case HTS_CLASS: strcpy(trans.name, "Class"); trans.index1 = readshort(fp); break; case HTS_FIELDREF: strcpy(trans.name, "Field Reference"); trans.index1 = readshort(fp); readshort(fp); break; case HTS_METHODREF: strcpy(trans.name, "Method Reference"); trans.index1 = readshort(fp); readshort(fp); break; case HTS_INTERFACE: strcpy(trans.name, "Interface Method Reference"); trans.index1 = readshort(fp); readshort(fp); break; case HTS_NAMEANDTYPE: strcpy(trans.name, "Name and Type"); trans.index1 = readshort(fp); readshort(fp); break; case HTS_STRING: // CONSTANT_String strcpy(trans.name, "String"); trans.index1 = readshort(fp); break; case HTS_INTEGER: strcpy(trans.name, "Integer"); for(j = 0; j < 4; j++) fgetc(fp); break; case HTS_FLOAT: strcpy(trans.name, "Float"); for(j = 0; j < 4; j++) fgetc(fp); break; case HTS_LONG: strcpy(trans.name, "Long"); for(j = 0; j < 8; j++) fgetc(fp); break; case HTS_DOUBLE: strcpy(trans.name, "Double"); for(j = 0; j < 8; j++) fgetc(fp); break; case HTS_ASCIZ: case HTS_UNICODE: if (trans.type == HTS_ASCIZ) strcpy(trans.name, "HTS_ASCIZ"); else strcpy(trans.name, "HTS_UNICODE"); { char BIGSTK buffer[1024]; char *p; p = &buffer[0]; //fflush(fp); trans.file_position = ftell(fp); length = readshort(fp); if (length < HTS_URLMAXSIZE) { // while ((length > 0) && (length<500)) { while(length > 0) { *p++ = fgetc(fp); length--; } *p = '\0'; //#if JDEBUG // if(tris(buffer)==1) printf("%s\n ",buffer); // if(tris(buffer)==2) printf("%s\n ",printname(buffer)); //#endif if (tris(str->opt, buffer) == 1) str->addLink(str, buffer); /* trans.file_position */ else if (tris(str->opt, buffer) == 2) str->addLink(str, printname(rname, buffer)); strcpy(trans.name, buffer); } else { // gros pb while((length > 0) && (!feof(fp))) { fgetc(fp); length--; } if (!feof(fp)) { trans.type = -1; } else { sprintf(str->err_msg, "Internal stucture error (ASCII)"); *error = 1; } return (trans); } } break; default: // printf("Type inconnue\n"); // on arrête tout sprintf(str->err_msg, "Internal structure unknown (type %d)", trans.type); *error = 1; return (trans); break; } return (trans); }
static int hts_parse_java(t_hts_callbackarg * carg, httrackp * opt, htsmoduleStruct * str) { /* The wrapper_name memebr has changed: not for us anymore */ if (str->wrapper_name == NULL || strcmp(str->wrapper_name, libName) != 0) { /* Call parent functions if multiple callbacks are chained. */ if (CALLBACKARG_PREV_FUN(carg, parse) != NULL) { return CALLBACKARG_PREV_FUN(carg, parse) (CALLBACKARG_PREV_CARG(carg), opt, str); } strcpy(str->err_msg, "unexpected error: bad wrapper_name and no previous wrapper"); return 0; /* Unexpected error */ } else { if (detect_mime(str)) { /* (Legacy code) */ char catbuff[CATBUFF_SIZE]; FILE *fpout; JAVA_HEADER header; RESP_STRUCT *tab; const char *file = str->filename; str->relativeToHtmlLink = 1; #if JAVADEBUG printf("fopen\n"); #endif if ((fpout = FOPEN(fconv(catbuff, sizeof(catbuff), file), "r+b")) == NULL) { //fprintf(stderr, "Cannot open input file.\n"); sprintf(str->err_msg, "Unable to open file %s", file); return 0; // une erreur.. } #if JAVADEBUG printf("fread\n"); #endif //if (fread(&header,1,sizeof(JAVA_HEADER),fpout) != sizeof(JAVA_HEADER)) { // pas complet.. if (fread(&header, 1, 10, fpout) != 10) { // pas complet.. fclose(fpout); sprintf(str->err_msg, "File header too small (file len = " LLintP ")", (LLint) fsize(file)); return 0; } #if JAVADEBUG printf("header\n"); #endif // tester en tête if (reverse_endian()) { header.magic = hts_swap32(header.magic); header.count = hts_swap16(header.count); } if (header.magic != 0xCAFEBABE) { sprintf(str->err_msg, "non java file"); if (fpout) { fclose(fpout); fpout = NULL; } return 0; } tab = (RESP_STRUCT *) calloc(header.count, sizeof(RESP_STRUCT)); if (!tab) { sprintf(str->err_msg, "Unable to alloc %d bytes", (int) sizeof(RESP_STRUCT)); if (fpout) { fclose(fpout); fpout = NULL; } return 0; // erreur.. } #if JAVADEBUG printf("calchead\n"); #endif { int i; for(i = 1; i < header.count; i++) { int err = 0; // ++ tab[i] = readtable(str, fpout, tab[i], &err); if (!err) { if ((tab[i].type == HTS_LONG) || (tab[i].type == HTS_DOUBLE)) i++; //2 element si double ou float } else { // ++ une erreur est survenue! if (strnotempty(str->err_msg) == 0) strcpy(str->err_msg, "Internal readtable error"); free(tab); if (fpout) { fclose(fpout); fpout = NULL; } return 0; } } } #if JAVADEBUG printf("addfiles\n"); #endif { //unsigned int acess; unsigned int Class; unsigned int SClass; int i; //acess = readshort(fpout); Class = readshort(fpout); SClass = readshort(fpout); for(i = 1; i < header.count; i++) { if (tab[i].type == HTS_CLASS) { if ((tab[i].index1 < header.count) && (tab[i].index1 >= 0)) { if ((tab[i].index1 != SClass) && (tab[i].index1 != Class) && (tab[tab[i].index1].name[0] != '[')) { if (!strstr(tab[tab[i].index1].name, "java/")) { char BIGSTK tempo[1024]; tempo[0] = '\0'; sprintf(tempo, "%s.class", tab[tab[i].index1].name); #if JAVADEBUG printf("add %s\n", tempo); #endif if (tab[tab[i].index1].file_position >= 0) str->addLink(str, tempo); /* tab[tab[i].index1].file_position */ } } } else { i = header.count; // exit } } } } #if JAVADEBUG printf("end\n"); #endif free(tab); if (fpout) { fclose(fpout); fpout = NULL; } return 1; } else { strcpy(str->err_msg, "bad MIME type"); } } return 0; /* Error */ }
/* Load memory font */ static struct font* font_load_in_memory(struct font* pf) { int32_t i, noffset, nwidth; if (!HAVEBYTES(4)) return NULL; /* # longs of offset*/ noffset = readlong(pf); /* # bytes of width*/ nwidth = readlong(pf); /* variable font data*/ pf->bits = (unsigned char *)pf->buffer_position; pf->buffer_position += pf->bits_size*sizeof(unsigned char); if (pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS) { /* pad to 16-bit boundary */ pf->buffer_position = (unsigned char *)(((intptr_t)pf->buffer_position + 1) & ~1); } else { /* pad to 32-bit boundary*/ pf->buffer_position = (unsigned char *)(((intptr_t)pf->buffer_position + 3) & ~3); } if (noffset) { if (pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS) { pf->long_offset = 0; pf->offset = (uint16_t*)pf->buffer_position; /* Check we have sufficient buffer */ if (!HAVEBYTES(noffset * sizeof(uint16_t))) return NULL; for (i=0; i<noffset; ++i) { ((uint16_t*)(pf->offset))[i] = (uint16_t)readshort(pf); } } else { pf->long_offset = 1; pf->offset = (uint16_t*)pf->buffer_position; /* Check we have sufficient buffer */ if (!HAVEBYTES(noffset * sizeof(int32_t))) return NULL; for (i=0; i<noffset; ++i) { ((uint32_t*)(pf->offset))[i] = (uint32_t)readlong(pf); } } } else pf->offset = NULL; if (nwidth) { pf->width = (unsigned char *)pf->buffer_position; pf->buffer_position += nwidth*sizeof(unsigned char); } else pf->width = NULL; if (pf->buffer_position > pf->buffer_end) return NULL; return pf; /* success!*/ }
struct rtgui_font *fnt_font_create(const char* filename, const char* font_family) { int fd = -1; rt_uint32_t index; struct rtgui_font *font = RT_NULL; struct fnt_font *fnt = RT_NULL; struct fnt_header *fnt_header; fd = open(filename, O_RDONLY, 0); if (fd < 0) { goto __exit; } font = (struct rtgui_font*) rtgui_malloc (sizeof(struct rtgui_font)); if (font == RT_NULL) goto __exit; fnt = (struct fnt_font*) rtgui_malloc (sizeof(struct fnt_font)); if (fnt == RT_NULL) goto __exit; rt_memset(fnt, 0x00, sizeof(struct fnt_font)); font->data = (void*)fnt; fnt_header = &(fnt->header); if (readstr(fd, fnt_header->version, 4) != 4) goto __exit; if (!readshort(fd, &fnt_header->max_width)) goto __exit; if (!readshort(fd, &fnt_header->height)) goto __exit; if (!readshort(fd, &fnt_header->ascent)) goto __exit; if (!readshort(fd, &fnt_header->depth)) goto __exit; if (!readlong(fd, &fnt_header->first_char)) goto __exit; if (!readlong(fd, &fnt_header->default_char)) goto __exit; if (!readlong(fd, &fnt_header->size)) goto __exit; if (!readlong(fd, &fnt_header->nbits)) goto __exit; if (!readlong(fd, &fnt_header->noffset)) goto __exit; if (!readlong(fd, &fnt_header->nwidth)) goto __exit; fnt->bits = (MWIMAGEBITS*) rtgui_malloc (fnt_header->nbits * sizeof(MWIMAGEBITS)); if (fnt->bits == RT_NULL) goto __exit; /* read data */ if (readstr(fd, &(fnt->bits[0]), fnt_header->nbits) != fnt_header->nbits) goto __exit; /* check boundary */ if (fnt_header->nbits & 0x01) { rt_uint16_t pad; readshort(fd, &pad); pad = pad; /* skip warning */ } if (fnt_header->noffset != 0) { fnt->offset = rtgui_malloc (fnt_header->noffset * sizeof(rt_uint32_t)); if (fnt->offset == RT_NULL) goto __exit; for (index = 0; index < fnt_header->noffset; index ++) { if (!readshort(fd, &(fnt->offset[index]))) goto __exit; } } if (fnt_header->nwidth != 0) { fnt->width = rtgui_malloc (fnt_header->nwidth * sizeof(rt_uint8_t)); if (fnt->width == RT_NULL) goto __exit; for (index = 0; index < fnt_header->nwidth; index ++) { if (!readbyte(fd, &(fnt->width[index]))) goto __exit; } } close(fd); font->family = rt_strdup(font_family); font->height = fnt->header.height; font->refer_count = 0; font->engine = &fnt_font_engine; /* add to system */ rtgui_font_system_add_font(font); return font; __exit: if (fd >= 0) close(fd); if (fnt != RT_NULL) { if (fnt->bits != RT_NULL) rtgui_free(fnt->bits); if (fnt->offset != RT_NULL) rtgui_free(fnt->offset); if (fnt->width != RT_NULL) rtgui_free(fnt->width); rtgui_free(fnt); } if (font != RT_NULL) { rtgui_free(font); } return RT_NULL; }
int dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, size_t packetlen) { char name[QUERY_NAME_SIZE]; char rdata[4*1024]; HEADER *header; short qdcount; short ancount; uint32_t ttl; unsigned short class; unsigned short type; char *data; unsigned short rlen; uint16_t id; int rv; rv = 0; header = (HEADER*)packet; /* Reject short packets */ if (packetlen < sizeof(HEADER)) return 0; if (header->qr != qr) { warnx("header->qr does not match the requested qr"); return -1; } data = packet + sizeof(HEADER); qdcount = ntohs(header->qdcount); ancount = ntohs(header->ancount); id = ntohs(header->id); rlen = 0; if (q != NULL) q->rcode = header->rcode; switch (qr) { case QR_ANSWER: if(qdcount < 1) { /* We need a question */ return -1; } if (q != NULL) q->id = id; /* Read name even if no answer, to give better error message */ readname(packet, packetlen, &data, name, sizeof(name)); CHECKLEN(4); readshort(packet, &data, &type); readshort(packet, &data, &class); /* if CHECKLEN okay, then we're sure to have a proper name */ if (q != NULL) { /* We only need the first char to check it */ q->name[0] = name[0]; q->name[1] = '\0'; } if (ancount < 1) { /* DNS errors like NXDOMAIN have ancount=0 and stop here. CNAME may also have A; MX/SRV may have multiple results. */ return -1; } /* Here type is still the question type */ if (type == T_NULL || type == T_PRIVATE) { /* Assume that first answer is what we wanted */ readname(packet, packetlen, &data, name, sizeof(name)); CHECKLEN(10); readshort(packet, &data, &type); readshort(packet, &data, &class); readlong(packet, &data, &ttl); readshort(packet, &data, &rlen); rv = MIN(rlen, sizeof(rdata)); rv = readdata(packet, &data, rdata, rv); if (rv >= 2 && buf) { rv = MIN(rv, buflen); memcpy(buf, rdata, rv); } else { rv = 0; } } else if ((type == T_A || type == T_CNAME ||
void zlist_uncompress(OSTask_t *task) { int z; static int cnt=1; static int lastframe=-1; static int firsttime=1; readdata(&zdata,task->m_data_ptr,sizeof(ZData)); if((zdata.m_pic&0x7f000000)!=0 || (zdata.m_q1 &0x7f000000)!=0 || (zdata.m_q2 &0x7f000000)!=0 || (zdata.m_q3 &0x7f000000)!=0 || !zdata.m_pic || !zdata.m_q1 || !zdata.m_q2 || !zdata.m_q3) { print("zelda: JPEG-DCT (buffer %08X, quant %08X) INVALID, ignored.\n", zdata.m_pic,zdata.m_q1,zdata.m_q2,zdata.m_q3); return; } readq(q1,zdata.m_q1); readq(q2,zdata.m_q2); readq(q3,zdata.m_q3); if(firsttime) { firsttime=0; disasm_dumpucode("rspzlist.log", task->m_ucode ,task->ucode_size, task->m_ucode_data,task->ucode_data_size,0x80); logd("RSP microcode/data dumped to RSPZLIST.LOG\n"); } if(st.frames!=lastframe) { print("zelda: JPEG-DCT (buffer %08X, quant %08X %08X %08X)\n", zdata.m_pic,zdata.m_q1,zdata.m_q2,zdata.m_q3); lastframe=st.frames; } for(z=0;z<4;z++) { readshort ((int *)in ,zdata.m_pic+z*768,8*8*2*6); uncompress(); writeshort((int *)out,zdata.m_pic+z*768,16*16*2); } /* if(cnt==1) { FILE *f1; f1=fopen("bgin.dat","wb"); for(z=0;z<3072*2;z+=4) { d=mem_read32(zdata.m_pic+z); d=FLIP32(d); fwrite(&d,1,4,f1); } fclose(f1); } d1=(cnt)+(cnt<<8)+(cnt<<16)+(cnt<<24); d2=d1^-1; for(z=0;z<4;z++) { for(y=0;y<16;y++) for(x=0;x<16;x++) { if(x==0 || y==0 || x==15 || y==15) { mem_write16(zdata.m_pic+z*768+x*2+y*2*16,d1); } } } */ cnt++; }