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 [3f10c9de85]:

To Artifact [50c4e83094]:


12
13
14
15
16
17
18

19
20
21
22
23
24
25
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26







+







#include <stdlib.h>
#include <string.h>
#include "sqlite3.h"
#include "smallxrm.h"
#include "heromesh.h"
#include "quarks.h"
#include "cursorshapes.h"
#include "hash.h"

EditorRect editrect;

typedef struct {
  Uint16 class;
  Uint8 img,dir;
  Value misc1,misc2,misc3;
848
849
850
851
852
853
854
855

856
857
858
859
860
861
862
863
864
865
866
867
868

869
870
871
872
873
874
875
849
850
851
852
853
854
855

856
857
858
859
860









861
862
863
864
865
866
867
868







-
+




-
-
-
-
-
-
-
-
-
+







    case TY_CLASS: fprintf(fp," $%s",classes[v.u]->name); break;
    case TY_MESSAGE: fprintf(fp," %s%s",v.u<256?"":"#",v.u<256?standard_message_names[v.u]:messages[v.u-256]);
    case TY_LEVELSTRING: fprintf(fp," %%%u",(int)v.u); break;
    default: fprintf(fp," ???"); break;
  }
}

static void export_level(const char*cmd) {
static void export_level_stream(FILE*fp) {
  Uint32*p=playfield;
  int i;
  Uint32 n;
  Object*o;
  FILE*fp;
  if(!cmd || !*cmd) return;
  fp=popen(cmd,"w");
  if(!fp) {
    screen_message("Cannot open pipe");
    return;
  }
  fprintf(fp,"; Free Hero Mesh exported level ID=%d ORD=%d\n",level_id,level_ord);
  fprint_esc(fp,'@',level_title);
  if(!main_options['S']) fprint_esc(fp,'@',level_title);
  fprintf(fp,"C %d\nD %d %d\n",level_code,pfwidth,pfheight);
  again:
  for(i=0;i<64*64;i++) {
    n=p[i];
    while(n!=VOIDLINK) {
      o=objects[n];
      fprintf(fp,"%d %d $%s %d",o->x,o->y,classes[o->class]->name,o->image);
886
887
888
889
890
891
892












893
894
895
896
897
898
899
879
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







+
+
+
+
+
+
+
+
+
+
+
+







      fprintf(fp,"W\n");
      goto again;
    }
  } else {
    fprintf(fp,"W\n");
  }
  for(i=0;i<nlevelstrings;i++) fprint_esc(fp,'%',levelstrings[i]);
}

static void export_level(const char*cmd) {
  FILE*fp;
  if(!cmd || !*cmd) return;
  fp=popen(cmd,"w");
  if(!fp) {
    screen_message("Cannot open pipe");
    return;
  }
  fprintf(fp,"; Free Hero Mesh exported level ID=%d ORD=%d\n",level_id,level_ord);
  export_level_stream(fp);
  pclose(fp);
}

static char*import_numbers(char*p,int*x,int*y) {
  if(!p) return 0;
  while(*p==' ' || *p=='\t') p++;
  if(*p<'0' || *p>'9') return 0;
2040
2041
2042
2043
2044
2045
2046




















































2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    import_level("#");
    if(nobjects) {
      save_level();
      if(!feof(stdin)) new_level();
    }
  }
}

static inline void hexout(const unsigned char*p,int n) {
  while(n--) printf("%02x",*p++);
}

void make_level_hashes(void) {
  char*v;
  FILE*in;
  FILE*out;
  unsigned char h1[128];
  unsigned char h2[128];
  long long alg;
  int hn,c,n;
  optionquery[1]=Q_hash;
  alg=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"",0,0)?:HASH_SHA3_256;
  hn=hash_length(alg);
  if(hn<1 || hn>128) fatal("Hash algorithm not valid or too long: %llu (length %d)\n",alg,hn);
  // Class hash
  if(main_options['z']) {
    in=composite_slice(".class",1);
  } else {
    v=sqlite3_mprintf("%s.class",basefilename);
    if(!v) fatal("Allocation failed\n");
    in=fopen(v,"r");
    sqlite3_free(v);
  }
  if(!in) fatal("Cannot open class file\n");
  out=hash_stream(alg,0,h1);
  if(!out) fatal("Allocation failed\n");
  while((c=fgetc(in))!=EOF) {
    if(c=='\t') c=' ';
    if(c!='\r') fputc(c,out);
  }
  fclose(in);
  fclose(out);
  printf("-1 0 %llx ",alg);
  hexout(h1,hn);
  putchar('\n');
  for(n=0;n<level_nindex;n++) {
    if(load_level(level_index[n])) fatal("Level load error\n");
    out=hash_stream(alg,0,h2);
    if(!out) fatal("Allocation failed\n");
    fprintf(out,"\x01%llx %x\n",alg,hn);
    fwrite(h1,1,hn,out);
    export_level_stream(out);
    fclose(out);
    printf("%d 0 %llx ",level_id,alg);
    hexout(h2,hn);
    putchar('\n');
  }
  exit(0);
}