Index: mbtofhm.c ================================================================== --- mbtofhm.c +++ mbtofhm.c @@ -445,11 +445,11 @@ } static void one_level(FILE*fp,int ord) { unsigned char buf[16]; unsigned char mru[32]; - int i,j,x,y,n,q; + int i,j,x,y,n,q,r; i=fgetc(stdin); i|=fgetc(stdin)<<8; levelid[ord]=i; sprintf(nam,"%d.LVL",i); hamarc_begin(fp); @@ -483,20 +483,20 @@ fread(mru,1,32,stdin); // Skip border colours fread(buf,1,2,stdin); // Skip border colours mru[0x04]=mru[0x14]=255; n=fgetc(stdin); n|=fgetc(stdin)<<8; - x=q=0; + x=q=r=0; y=1; // Free Hero Mesh level format for objects: // * bit flags (or 0xFF for end): // bit7 = MRU (omit everything but position) // bit6 = Next position // bit5 = New X position // bit4 = New Y position - // bit3 = Has MiscVars - // bit2-bit0 = LastDir (should be RLE in case of MRU?) + // bit3 = Has MiscVars (RLE in case of MRU) + // bit2-bit0 = LastDir (RLE in case of MRU) // * new X if applicable // * new Y if applicable // * class (one-based; add 0x8000 for image 0) (two bytes) // * image (one byte) // * data types (if has MiscVars): @@ -520,13 +520,19 @@ } else { i|=buf[4]&7; if(buf[5] || memcmp(buf+10,"\0\0\0\0\0\0",6)) i|=0x08; if(q<32) memcpy(mru+q,buf,16); } - fputc(i,fp); x=buf[6]; y=buf[8]; + if(i==0xC0) { + if(++r==16) fputc(r+0xBF,fp),r=0; + continue; + } else if(r) { + fputc(r+0xBF,fp),r=0; + } + fputc(i,fp); if(i&0x20) fputc(x,fp); if(i&0x10) fputc(y,fp); if(i<0x80) { if(buf[2]) { fwrite(buf,1,3,fp); @@ -565,10 +571,11 @@ fwrite(buf+14,1,2,fp); } } } } + if(r) fputc(r+0xBF,fp); fputc(255,fp); // End of objects n=fgetc(stdin); n|=fgetc(stdin)<<8; while(n--) { i=fgetc(stdin);