Overview
Comment: | Finally, class codes can be converted now. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
fa63933e6772f450c9063d61c651d794 |
User & Date: | user on 2018-03-18 04:37:49 |
Other Links: | manifest | tags |
Context
2018-03-18
| ||
21:57 | Several bugfixes in class codes converter check-in: 890d0c173d user: user tags: trunk | |
04:37 | Finally, class codes can be converted now. check-in: fa63933e67 user: user tags: trunk | |
2018-03-17
| ||
06:10 | Improve the converter program check-in: 6d36e2c377 user: user tags: trunk | |
Changes
Modified mbtofhm.c from [fc1c32314d] to [625d7a51f8].
︙ | ︙ | |||
55 56 57 58 59 60 61 62 63 64 65 66 67 68 | static char**sounds; static unsigned short*soundid; // Common static char*basename; static char*nam; static unsigned long haroffs; static void*alloc(unsigned int s) { void*o=malloc(s); if(s && !o) fatal("Allocation failed\n"); return o; } static void*my_realloc(void*p,unsigned int s) { | > | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | static char**sounds; static unsigned short*soundid; // Common static char*basename; static char*nam; static unsigned long haroffs; static unsigned long puzzlesetnumber; static void*alloc(unsigned int s) { void*o=malloc(s); if(s && !o) fatal("Allocation failed\n"); return o; } static void*my_realloc(void*p,unsigned int s) { |
︙ | ︙ | |||
90 91 92 93 94 95 96 97 98 99 100 101 102 103 | } static inline void read_header(void) { unsigned char buf[30]; int i,s; fread(buf,1,30,stdin); if(memcmp("MESH",buf+2,4)) fatal("Unrecognized file format\n"); for(i=0;i<buf[10];i++) sizes[i]=buf[i+i+12]|(buf[i+i+13]<<8); npic=buf[28]|(buf[29]<<8); Allocate(picalloc,npic); for(i=0;i<npic;i++) { fread(buf,1,2,stdin); picalloc[i]=buf[0]|(buf[1]<<8); } | > | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | } static inline void read_header(void) { unsigned char buf[30]; int i,s; fread(buf,1,30,stdin); if(memcmp("MESH",buf+2,4)) fatal("Unrecognized file format\n"); puzzlesetnumber=buf[6]|(buf[7]<<8)|(buf[8]<<16)|(buf[9]<<24); for(i=0;i<buf[10];i++) sizes[i]=buf[i+i+12]|(buf[i+i+13]<<8); npic=buf[28]|(buf[29]<<8); Allocate(picalloc,npic); for(i=0;i<npic;i++) { fread(buf,1,2,stdin); picalloc[i]=buf[0]|(buf[1]<<8); } |
︙ | ︙ | |||
314 315 316 317 318 319 320 | class[id]->nmsgs=0; class[id]->msgscode=0; for(;;) { fread(buf,1,4,stdin); k=buf[2]|(buf[3]<<8); if(!k) break; i=class[id]->nmsgs++; | | > | 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | class[id]->nmsgs=0; class[id]->msgscode=0; for(;;) { fread(buf,1,4,stdin); k=buf[2]|(buf[3]<<8); if(!k) break; i=class[id]->nmsgs++; Reallocate(class[id]->msgscode,class[id]->nmsgs); Allocate(class[id]->msgscode[i],k<<1); memcpy(class[id]->msgscode[i],buf,4); fread(class[id]->msgscode[i]+4,k-2,2,stdin); } } static inline void do_classes(void) { int n; |
︙ | ︙ | |||
402 403 404 405 406 407 408 409 410 411 412 | return; } else { if(*txt=='"') fputc('\\',fp); fputc(*txt++,fp); } } } static inline void out_classes(void) { FILE*fp; ClassInfo*c; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 | return; } else { if(*txt=='"') fputc('\\',fp); fputc(*txt++,fp); } } } #define SubOpcode(...) do{ static const char*const ss[]={__VA_ARGS__}; if(*op>=sizeof(ss)/sizeof(*ss)) goto unknown; fprintf(fp," %s",ss[*op]); }while(0) #define PushFlowControl() do{ flowblock[flowptr]=ofs+2+(op[1]<<1)+(op[2]<<9); if(++flowptr==64) fatal("Too many nested flow controls\n"); len+=2; ind+=2; }while(0) static int class_codes(FILE*fp,const unsigned char*op,int ofs,const unsigned char*lbl,int nlbl,const unsigned char*subs,int nsubs,unsigned char*vars) { static const char*const stdvars[256]={ [0]="Class","Temperature","Shape", [4]="Xloc","Yloc","Dir","Image","Inertia","Misc1","Misc2","Misc3","Misc4","Misc5","Misc6","Misc7", [16]="Arrived","Departed","Arrivals","Departures", [32]="Busy","Invisible","UserSignal","UserState","KeyCleared","IsPlayer","Destroyed","Stealthy","VisualOnly", [48]="Msg","From","Arg1","Arg2", [64]="Density","Volume","Strength","Weight","Distance","Height","Climb", [72]="Hard","Hard","Hard","Hard","Sharp","Sharp","Sharp","Sharp","ShapeDir","ShapeDir","ShapeDir","ShapeDir", [84]="Shovable", }; static const char*const direction[16]={"E","NE","N","NW","W","SW","S","SE","F","LF","L","LB","B","RB","R","RF"}; int flowblock[64]; int flowptr=0; //int end=ofs+(op[-2]<<1)+(op[-1]<<9); int ind=3; int st=0; int lix=0; int remlbl=nlbl; int x,y,z,len; for(;;) { while(flowptr && flowblock[flowptr-1]==ofs) { --flowptr; fprintf(fp,"\n%*s then",ind-=2,""); } if(*op==102 && op[1]!=1) return ofs+2; if(!st) st=fprintf(fp,"\n%*s",ind,""); //if(ofs>=end) { // fprintf(fp," (?\?\?)"); // return ofs; //} while(remlbl && (lbl[lix+8]|(lbl[lix+9]<<8))==ofs>>1) { fprintf(fp," :%s",lbl+lix); remlbl--; lix+=10; } len=1; switch(*op++) { case 1 ... 4: if(!stdvars[*op]) goto unknown; if(*op>=72 && *op<=83) fprintf(fp," %c","ENWSENWSENWS"[*op&3],stdvars[*op]); fputc(' ',fp); if(op[-1]>2) fputc('=',fp); if(!(op[-1]&1)) fputc(',',fp); fprintf(fp,"%s",stdvars[*op]); if(op[-1]>2) st=0; break; case 5: fprintf(fp," %%%s",vars+*op*8); break; case 6: fprintf(fp," =%%%s",vars+*op*8); st=0; break; case 7: fprintf(fp," %d",*op); break; case 8: fprintf(fp," %u",op[1]|(op[2]<<8)|(op[3]<<16)|(op[4]<<24)); len+=4; break; case 9: if(!class[*op]) goto unknown; fprintf(fp," $%s",class[*op]->name); break; case 11: if(*op<20) { fprintf(fp," %s",standard_message_names[*op]); } else { if(*op-20>=nusermsg || !usermsg[*op-20]) goto unknown; fprintf(fp," #%s",usermsg[*op-20]); } break; case 13: fprintf(fp," \""); len+=x=op[1]|(op[2]<<8); for(y=0;y<x;y++) switch(z=op[y+3]) { case 0: break; // do nothing case 1 ... 8: fprintf(fp,"\\%c",z+'0'-1); break; case 10: fprintf(fp,"\\n"); break; case 11: fprintf(fp,"\\l"); break; case 12: fprintf(fp,"\\c"); break; //case 14: fprintf(fp,"\\i%s:%d\\",class[op[y+4]|(op[y+5]<<8)]->name,op[y+6]|(op[y+7]<<8)); y+=4; break; case 14: fprintf(fp,"\\i%d:%d\\",op[y+4]|(op[y+5]<<8),op[y+6]|(op[y+7]<<8)); y+=4; break; case 15: fprintf(fp,"\\b"); break; case 16: fprintf(fp,"\\q"); break; case 9: case 13: case 17 ... 31: case 127 ... 255: fprintf(fp,"\\x%02X",z); break; case '\\': fputc(z,fp); //fallthrough default: fputc(z,fp); } fputc('"',fp); len+=2; break; case 14: if(*op<16) fprintf(fp," %s",direction[*op]); else fprintf(fp," %d",*op); break; case 15: for(x=0;x<nsounds;x++) { if(soundid[x]==*op) { fprintf(fp," !%s",sounds[x]); break; } } if(x==nsounds) goto unknown; break; case 16: SubOpcode("neg","bnot","lnot"); break; case 17: SubOpcode("*","/","mod"); break; case 18: SubOpcode("+","-","band","bor","bxor"); break; case 19: SubOpcode("lsh","rsh"); break; case 20: SubOpcode("eq","ne","lt","gt","le","ge"); break; case 21: SubOpcode("land","lor","lxor"); break; case 32: if(*op==255) fprintf(fp," ObjDir"); else fprintf(fp," %s ObjDir",direction[*op]); break; case 33: if(*op==255) fprintf(fp," ,ObjDir"); else fprintf(fp," %s ,ObjDir",direction[*op]); break; case 34: fprintf(fp," ObjAbove"); break; case 35: fprintf(fp," ,ObjAbove"); break; case 36: fprintf(fp," ObjBelow"); break; case 37: fprintf(fp," ,ObjBelow"); break; case 38: SubOpcode("ObjTopAt","ObjBottomAt","VolumeAt","HeightAt","Delta"); break; case 39: fprintf(fp," Self"); break; case 40: fprintf(fp," ObjClassAt"); break; case 48: fprintf(fp," Key"); break; case 49: SubOpcode("STOP","ONCE","LOOP","3","4","5","6","7","OSC","9","OSCLOOP"); break; case 50: if(heromesh_key_names[*op]) fprintf(fp," '%s",heromesh_key_names[*op]); else fprintf(fp," %d",*op); break; case 51: fprintf(fp," 0x%02X",*op); break; case 52: fprintf(fp," 0x%X",op[1]|(op[2]<<8)|(op[3]<<16)|(op[4]<<24)); len+=4; break; case 53: if(*op==5) fprintf(fp," %ld",puzzlesetnumber); else SubOpcode("Level","-1","0","1","0","0","MoveNumber"); break; case 54: if(*op==255) fprintf(fp," XDir"); else fprintf(fp," %s XDir",direction[*op]); break; case 55: if(*op==255) fprintf(fp," ,XDir"); else fprintf(fp," %s ,XDir",direction[*op]); break; case 56: if(*op==255) fprintf(fp," YDir"); else fprintf(fp," %s YDir",direction[*op]); break; case 57: if(*op==255) fprintf(fp," ,YDir"); else fprintf(fp," %s ,YDir",direction[*op]); break; case 58: fprintf(fp," New%c",*op+'X'); break; case 59: fprintf(fp," bit%d",*op); break; case 60: if(*op<50) fprintf(fp," %s",standard_sound_names[*op]); else goto unknown; break; case 64: fprintf(fp," Send"); break; case 65: fprintf(fp," ,Send"); break; case 66: fprintf(fp," (Broadcast $%s)",class[*op]->name); break; case 67: fprintf(fp," Broadcast"); break; case 68: if(*op==255) fprintf(fp," Move"); else fprintf(fp," (Move %s)",direction[*op]); break; case 69: if(*op==255) fprintf(fp," ,Move"); else fprintf(fp," %s ,Move",direction[*op]); break; case 70: fprintf(fp," JumpTo"); break; case 71: fprintf(fp," ,JumpTo"); break; case 72: fprintf(fp," Create"); break; case 74: fprintf(fp," Destroy"); break; case 75: fprintf(fp," ,Destroy"); break; case 80: fprintf(fp," Send ."); st=0; break; case 81: fprintf(fp," ,Send ."); st=0; break; case 82: fprintf(fp," (Broadcast $%s) .",class[*op]->name); st=0; break; case 83: fprintf(fp," Broadcast ."); st=0; break; case 84: if(*op==255) fprintf(fp," Move ."); else fprintf(fp," (Move %s) .",direction[*op]); st=0; break; case 85: if(*op==255) fprintf(fp," ,Move ."); else fprintf(fp," %s ,Move .",direction[*op]); st=0; break; case 88: fprintf(fp," Create ."); st=0; break; case 96: fprintf(fp," ;"); len+=x=op[1]|(op[2]<<8); for(y=0;y<x;y++) switch(z=op[y+3]) { case 0: case 13: break; // do nothing case 10: fprintf(fp,"\n%*s ;",ind,""); break; default: fputc(z,fp); } len+=2; st=0; break; case 98: fprintf(fp," Destroy ."); st=0; break; case 99: fprintf(fp," ,Destroy ."); st=0; break; case 100: z=-1; for(x=0;x<nsubs;x++) { if(op[1]==subs[x*10+8] && op[2]==subs[x*10+9]) { z=x; break; } } if(z==-1) fprintf(fp," ,???"); else fprintf(fp," ,:%s",subs+z*10); len+=2; st=0; break; case 101: z=-1; for(x=0;x<nlbl;x++) { if(op[1]==lbl[x*10+8] && op[2]==lbl[x*10+9]) { z=x; break; } } if(z==-1) fprintf(fp," =???"); else fprintf(fp," =:%s",lbl+z*10); len+=2; st=0; break; case 102: case 104: fprintf(fp," ret"); st=0; break; case 103: fprintf(fp," %d ret",*op); st=0; break; case 105: fprintf(fp," if"); PushFlowControl(); st=0; break; case 106: fseek(fp,-1,SEEK_CUR); fprintf(fp,"else"); if(flowptr) flowptr--,ind-=2; PushFlowControl(); st=0; break; case 109: if(*op) fprintf(fp," (PopUp %d)",*op); else fprintf(fp," PopUp"); st=0; break; case 110: fprintf(fp," JumpTo ."); st=0; break; case 111: fprintf(fp," ,JumpTo ."); st=0; break; case 112: case 113: fprintf(fp," Sound"); st=0; break; case 126: fprintf(fp," Animate"); st=0; break; case 127: case 128: fprintf(fp," LoseLevel"); st=0; break; case 129: SubOpcode("WinLevel","LocateMe","IgnoreKey","Misc1 Misc2 Misc3 (PopUp 3)",";"); st=0; break; case 130: fprintf(fp," FlushClass"); st=0; break; case 131: fprintf(fp," FlushObj"); st=0; break; case 132: fprintf(fp," SetInventory 5 MaxInventory"); st=0; break; case 133: fprintf(fp," DelInventory"); st=0; break; case 134: fprintf(fp," (for %%%s)",vars+*op*8); ind+=2; len+=2; st=0; break; case 135: fseek(fp,-1,SEEK_CUR); fprintf(fp,"next"); ind-=2; len+=6; st=0; break; case 240: fprintf(fp," Trace"); st=0; break; default: unknown: fprintf(fp," (??? %d %d)",op[-1],op[0]); st=0; } ofs+=len+1; op+=len; } } static inline void out_classes(void) { FILE*fp; ClassInfo*c; int i,j,n,o; sprintf(nam,"%s.class",basename); fp=fopen(nam,"w"); if(!fp) fatal("Cannot open file '%s' for writing\n",nam); fprintf(fp,"; Note: This file was automatically converted.\n; Remove this notice if you have corrected it.\n"); for(n=0;n<512;n++) if(c=class[n]) { fprintf(fp,"\n($%s Compatible",c->name); if(c->attr[1]&1) fprintf(fp," Input"); |
︙ | ︙ | |||
519 520 521 522 523 524 525 | if(c->attr[42] || c->attr[43]) fprintf(fp," (W %d)",c->attr[42]|(c->attr[43]<<8)); if(c->attr[44] || c->attr[45]) fprintf(fp," (S %d)",c->attr[44]|(c->attr[45]<<8)); fprintf(fp,")\n"); } else { fprintf(fp," (Sharp %d)\n",c->attr[38]|(c->attr[39]<<8)); } } | < | > > > | > | | 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 | if(c->attr[42] || c->attr[43]) fprintf(fp," (W %d)",c->attr[42]|(c->attr[43]<<8)); if(c->attr[44] || c->attr[45]) fprintf(fp," (S %d)",c->attr[44]|(c->attr[45]<<8)); fprintf(fp,")\n"); } else { fprintf(fp," (Sharp %d)\n",c->attr[38]|(c->attr[39]<<8)); } } if(c->subscode[1] || c->subscode[0]>2) { fprintf(fp," (SUBS"); class_codes(fp,c->subscode+2,2,c->subslbl,c->nsubslbl,c->subslbl,c->nsubslbl,c->vars); fprintf(fp,"\n )\n"); } o=0; for(i=0;i<c->nmsgs;i++) { fprintf(fp," ("); j=c->msgscode[i][0]|(c->msgscode[i][1]<<8); if(j<20) fprintf(fp,"%s",standard_message_names[j]); else if(j-20<nusermsg && usermsg[j-20]) fprintf(fp,"#%s",usermsg[j-20]); else fprintf(fp,"#???%d",j); o=class_codes(fp,c->msgscode[i]+4,o+4,c->msgslbl,c->nmsgslbl,c->subslbl,c->nsubslbl,c->vars); fprintf(fp,"\n )\n"); } fprintf(fp,")\n"); } fclose(fp); } static void one_level(FILE*fp,int ord) { |
︙ | ︙ |