Free Hero Mesh

Diff
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.

Differences From Artifact [443bde1bde]:

To Artifact [86b6c496cf]:


410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
    }
  }
}

#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 void 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","Player","Destroyed","Stealthy","VisualOnly",
    [48]="Msg","From","Arg1","Arg2",
    [64]="Density","Volume","Strength","Weight","Distance","Height","Climb",







|







410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
    }
  }
}

#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 void 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,const char*cname) {
  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","Player","Destroyed","Stealthy","VisualOnly",
    [48]="Msg","From","Arg1","Arg2",
    [64]="Density","Volume","Strength","Weight","Distance","Height","Climb",
558
559
560
561
562
563
564









565
566
567
568
569
570
571
        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:







>
>
>
>
>
>
>
>
>







558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
        break;
      case 39:
        fprintf(fp," Self");
        break;
      case 40:
        fprintf(fp," ObjClassAt");
        break;
      case 47:
        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.%s",cname,subs+z*10);
        len+=2; break;
      case 48:
        fprintf(fp," Key");
        break;
      case 49:
        SubOpcode("STOP","ONCE","LOOP","3","4","5","6","7","OSC","9","OSCLOOP");
        break;
      case 50:
604
605
606
607
608
609
610




611
612
613
614
615
616
617
      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:







>
>
>
>







613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
      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 61:
        if(*op!=1) goto unknown;
        fprintf(fp," GetArray");
        break;
      case 64:
        fprintf(fp," Send");
        break;
      case 65:
        fprintf(fp," ,Send");
        break;
      case 66:
722
723
724
725
726
727
728
















729
730
731
732
733
734
735
        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;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
        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 114:
        if(op[1]) {
          SubOpcode(";","SetArray","InitArray");
        } else {
          x=0;
          y=nlbl;
          z=-1;
          while(y) {
            if(lbl[x+8]|(lbl[x+9]<<8))==ofs>>1) break;
            y--;
            x+=10;
          }
          if(z!=-1) fprintf(fp,"{Array @%s.%s %d %d}",cname,lbl+z*10,op[1],op[3]);
          len+=4*(op[1]*op[3]+1);
        }
        st=0; break;
      case 126:
        fprintf(fp," Animate");
        st=0; break;
      case 127: case 128:
        fprintf(fp," LoseLevel");
        st=0; break;
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
        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=4;
    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);
      class_codes(fp,c->msgscode[i]+4,o,c->msgslbl,c->nmsgslbl,c->subslbl,c->nsubslbl,c->vars);
      o+=(c->msgscode[i][2]<<1)|(c->msgscode[i][3]<<9);
      fprintf(fp,"\n  )\n");
    }
    fprintf(fp,")\n");
  }
  fclose(fp);
}







|









|







910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
        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,c->name);
      fprintf(fp,"\n  )\n");
    }
    o=4;
    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);
      class_codes(fp,c->msgscode[i]+4,o,c->msgslbl,c->nmsgslbl,c->subslbl,c->nsubslbl,c->vars,c->name);
      o+=(c->msgscode[i][2]<<1)|(c->msgscode[i][3]<<9);
      fprintf(fp,"\n  )\n");
    }
    fprintf(fp,")\n");
  }
  fclose(fp);
}