A lot like TamoGameSystem. So similar that it might even be a predecessor.

   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 #include <stdint.h>
   4 
   5 #include <set>
   6 
   7 void fread_or_die(void * a, size_t b, int c, FILE * d)
   8 {
   9     int got = fread(a, b, c, d);
  10     if(feof(d)) {puts("feof"); exit(0);}
  11     if(ferror(d)) {puts("ferror"); exit(0);}
  12     if(got != c) {exit(0);}
  13 }
  14 
  15 int main()
  16 {
  17     auto fs = fopen("scenario.dat", "rb");
  18     auto ft = fopen("textdata.bin", "rb");
  19     auto fo = fopen("script.txt", "wb");
  20     
  21     fseek(fs, 0x20, SEEK_SET);
  22     
  23     
  24     std::set<uint32_t> seen;
  25     
  26     while(!feof(fs) and !ferror(fs))
  27     {
  28         /*
  29          !!!!!!!!!!!!!!!!!!!!!!!
  30         07 03 00 80
  31         54 04 00 00
  32         A2 00 00 00
  33         AA 00 00 00
  34         08 00 00 00
  35         00 00 03 00
  36         01 00 00 00
  37         
  38         02 03 00 01
  39         3C B8 03 00
  40         
  41         07 03 00 80
  42         55 04 00 00
  43         BC 00 00 00
  44         C2 00 00 00
  45         09 00 00 00
  46         00 00 03 00
  47         01 00 00 00
  48         
  49         02 03 00 01
  50         F0 BC 03 00
  51         
  52         07 03 00 80
  53         56 04 00 00
  54         A2 00 00 00
  55         CE 00 00 00
  56         0A 00 00 00
  57         00 00 03 00
  58         01 00 00 00
  59         
  60         02 03 00 01
  61         A8 C6 03 00
  62         
  63         07 03 00 80
  64         57 04 00 00
  65         A2 00 00 00
  66         10 01 00 00
  67         0B 00 00 00
  68         00 00 03 00
  69         01 00 00 00
  70         
  71         02 03 00 01
  72         E0 C9 03 00 # some kind of goto?
  73         
  74         07 03 00 80
  75         58 04 00 00
  76         BC 00 00 00
  77         30 01 00 00
  78         0C 00 00 00
  79         00 00 02 00
  80         01 00 00 00
  81         
  82         02 03 00 01
  83         44 CF 03 00
  84         
  85         01 02 02 80
  86         
  87         04 00 00 04
  88         64 00 00 00
  89         2F 00 00 00
  90         03 00 00 00
  91         
  92         
  93          !!!!!!!!!!!!!!!!!!
  94         06 04 00 80
  95         00 00 00 00 # voicing (nulled)
  96         BC 00 00 00 # name
  97         FF 8A 00 00 # text
  98         00 00 03 00 
  99         01 00 00 00
 100         
 101         
 102         02 0D 00 01
 103         C8 76 00 00
 104         
 105         02 03 00 01
 106         C4 22 73 00
 107         
 108         
 109          !!!!!!!!!!!!!!!!!!!
 110         03 03 00 03
 111         0A 00 00 00
 112         B4 70 00 00 # 普段から流れ星がよく降ることで有名なこの街では、そう珍しいことでもありません。
 113         
 114         
 115         
 116         02 0D 00 01
 117         30 2D 01 00
 118         
 119         04 01 01 80
 120         00 00 00 00
 121         2F 00 00 00
 122         03 00 00 00
 123         
 124         04 00 01 80
 125         01 00 00 00
 126         F4 01 00 00
 127         00 00 00 00
 128         
 129         02 01 01 05
 130         00 00 00 00
 131         
 132         04 00 01 05
 133         24 09 00 00
 134         00 00 00 00
 135         03 00 00 00
 136         
 137         
 138         
 139         
 140         01 02 02 80
 141         
 142         01 00 30 00
 143         
 144         03 01 00 02
 145         00 00 00 30
 146         00 00 00 40
 147         
 148         
 149         01 02 02 80
 150         
 151         03 01 00 02
 152         01 00 00 30
 153         E6 03 00 10
 154         
 155         
 156         00 00 03 00
 157         01 00 00 00
 158         
 159         07 03 00 80
 160         00 00 00 00
 161         00 00 00 00
 162         80 A3 38 00 # ?
 163         C7 4E 01 00 # ?
 164         
 165         00 00 03 00 # 
 166         01 00 00 00 # 
 167         
 168         07 03 00 80 # prefix
 169         70 2A 01 00 # index of voice filename in filename.dat
 170         A1 CB 03 00 # name
 171         9C A3 38 00 # text
 172         C8 4E 01 00 # ?
 173         00 00 03 00 # ?
 174         01 00 00 00 # ?
 175         
 176         
 177         07 03 00 80
 178         00 00 00 00
 179         00 00 00 00
 180         27 CB 07 00 # text
 181         CE 2E 00 00 # probably a counter
 182         00 00 03 00
 183         01 00 00 00
 184         
 185         04 02 01 80
 186         02 00 00 00
 187         36 0A 00 00 # SE?
 188         03 00 00 00
 189         
 190         04 00 01 80
 191         01 00 00 00
 192         64 00 00 00
 193         00 00 00 00
 194         
 195         
 196         07 03 00 80
 197         01 A3 00 00 # SE?
 198         C7 B6 0F 00 # text?
 199         1F 62 1B 00
 200         0B A8 00 00 # counter
 201         00 00 03 00
 202         01 00 00 00
 203         
 204         04 02 01 80
 205         14 00 00 00
 206         90 62 00 00
 207         03 00 00 00
 208         
 209         04 00 01 80
 210         01 00 00 00
 211         64 00 00 00
 212         00 00 00 00
 213         
 214         02 03 00 01
 215         4C AD 70 00
 216         
 217         
 218         
 219         
 220         07 03 00 80 
 221         37 0A 00 00 # SE? X*20 = 146E0; X-10 = 146D0; dereference: = "LLT_A010013"
 222         E0 1D 00 00 # name? dereference = "ロロット"
 223         C5 90 00 00 # text? dereference = "「呼び捨てで構いません」"
 224         CE 02 00 00
 225         00 00 00 00
 226         01 00 00 00
 227         
 228         
 229         04 00 01 05
 230         39 0A 00 00 # SE: "SE_HOE"
 231         00 00 00 00
 232         03 00 00 00
 233         
 234         02 03 00 01
 235         2C 64 70 00
 236         
 237         
 238         
 239         02 01 00 04
 240         02 00 00 00
 241         02 01 00 04
 242         03 00 00 00
 243         
 244         01 04 00 01
 245         07 03 00 80 # ?
 246         54 04 00 00 # ? isn't this for the next line? or is it 1-indexed?
 247         A2 00 00 00 # name
 248         AA 00 00 00 # text line
 249         08 00 00 00
 250         00 00 03 00
 251         01 00 00 00
 252         
 253         02 03 00 01
 254         3C B8 03 00
 255         07 03 00 80
 256         55 04 00 00
 257         BC 00 00 00
 258         C2 00 00 00
 259         09 00 00 00
 260         00 00 03 00
 261         01 00 00 00
 262         */
 263         
 264         /*
 265         02 03 00 01
 266         2C 64 70 00
 267         07 03 00 80
 268         4A 6A 00 00 # voice filename index
 269         A2 00 00 00 # name
 270         EE 19 00 00 # text
 271         C3 69 00 00 # unknown
 272         00 00 03 00
 273         01 00 00 00
 274         04 02 01 80
 275         01 00 00 00
 276         4F 54 00 00 # ?
 277         03 00 00 00
 278         04 00 01 80
 279         01 00 00 00
 280         64 00 00 00
 281         00 00 00 00
 282         
 283         02 03 00 01
 284         38 6D 70 00
 285         07 03 00 80
 286         4B 6A 00 00 # voice filename index
 287         A2 00 00 00 # name
 288         96 30 11 00 # text
 289         C4 69 00 00 # unknown
 290         00 00 03 00
 291         01 00 00 00
 292         04 02 01 80
 293         04 00 00 00
 294         48 6A 00 00 # ?
 295         03 00 00 00
 296         04 00 01 80
 297         01 00 00 00
 298         64 00 00 00
 299         00 00 00 00
 300         
 301         */
 302         uint32_t command;
 303         fread_or_die(&command, 4, 1, fs);
 304         
 305         uint8_t consume = command&0xFF;
 306         
 307         if(consume == 0)
 308         {
 309             printf("Encoding error at %08X.\n", ftell(fs));
 310             exit(0);
 311         }
 312         
 313         static auto last = ftell(fs);
 314         
 315         if(ftell(fs) < last)
 316         {
 317             printf("Movement error at %08X.\n", ftell(fs));
 318             exit(0);
 319         }
 320         
 321         if(command == 0x80000307)
 322         {
 323             fseek(fs, 8, SEEK_CUR);
 324             uint32_t data;
 325             fread_or_die(&data, 4, 1, fs);
 326             
 327             if(!seen.count(data))
 328             {
 329                 seen.insert(data);
 330                 
 331                 fseek(ft, data, SEEK_SET);
 332                 int c = fgetc(ft);
 333                 while(c != 0)
 334                 {
 335                     fputc(c, fo);
 336                     c = fgetc(ft);
 337                 }
 338                 fputc('\n', fo);
 339             }
 340             fseek(fs, 12, SEEK_CUR);
 341         }
 342         else if(command == 0x80000406)
 343         {
 344             fseek(fs, 8, SEEK_CUR);
 345             uint32_t data;
 346             fread_or_die(&data, 4, 1, fs);
 347             
 348             if(!seen.count(data))
 349             {
 350                 seen.insert(data);
 351                 
 352                 fseek(ft, data, SEEK_SET);
 353                 int c = fgetc(ft);
 354                 while(c != 0)
 355                 {
 356                     fputc(c, fo);
 357                     c = fgetc(ft);
 358                 }
 359                 fputc('\n', fo);
 360             }
 361             fseek(fs, 8, SEEK_CUR);
 362         }
 363         else if(command == 0x03000303)
 364         {
 365             fseek(fs, 4, SEEK_CUR);
 366             uint32_t data;
 367             fread_or_die(&data, 4, 1, fs);
 368             
 369             if(!seen.count(data))
 370             {
 371                 seen.insert(data);
 372             
 373                 fseek(ft, data, SEEK_SET);
 374                 int c = fgetc(ft);
 375                 while(c != 0)
 376                 {
 377                     fputc(c, fo);
 378                     c = fgetc(ft);
 379                 }
 380             }
 381             fputc('\n', fo);
 382         }
 383         else
 384             fseek(fs, 4*(consume-1), SEEK_CUR);
 385     }
 386 }

2XT-PJADV (last edited 2017-08-27 20:44:37 by weh)