| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include "heheader.h" |
| 26 |
|
| 27 |
#ifdef HUGO_GLKUNIX |
| 28 |
#include "glkstart.h" |
| 29 |
#endif |
| 30 |
|
| 31 |
|
| 32 |
long FindResource(char *filename, char *resname); |
| 33 |
static int GetResourceParameters(char *filename, char *resname); |
| 34 |
|
| 35 |
|
| 36 |
int hugo_displaypicture(HUGO_FILE infile, long len); |
| 37 |
|
| 38 |
|
| 39 |
int hugo_playmusic(HUGO_FILE infile, long reslength, char loop_flag); |
| 40 |
int hugo_playsample(HUGO_FILE infile, long reslength, char loop_flag); |
| 41 |
void hugo_musicvolume(int vol); |
| 42 |
void hugo_stopmusic(void); |
| 43 |
void hugo_samplevolume(int vol); |
| 44 |
void hugo_stopsample(void); |
| 45 |
|
| 46 |
|
| 47 |
#if !defined (COMPILE_V25) |
| 48 |
int hugo_hasvideo(void); |
| 49 |
int hugo_playvideo(HUGO_FILE infile, long reslength, |
| 50 |
char loop_flag, char background, int volume); |
| 51 |
void hugo_stopvideo(void); |
| 52 |
#endif |
| 53 |
|
| 54 |
|
| 55 |
#ifndef MAX_RES_PATH |
| 56 |
#define MAX_RES_PATH 255 |
| 57 |
#endif |
| 58 |
|
| 59 |
HUGO_FILE resource_file; |
| 60 |
int extra_param; |
| 61 |
char loaded_filename[MAX_RES_PATH]; |
| 62 |
char loaded_resname[MAX_RES_PATH]; |
| 63 |
char resource_type = 0; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
#define STAT_UNAVAILABLE ((short)-1) |
| 68 |
#define STAT_NOFILE 101 |
| 69 |
#define STAT_NORESOURCE 102 |
| 70 |
#define STAT_LOADERROR 103 |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
void DisplayPicture(void) |
| 76 |
{ |
| 77 |
char filename[MAX_RES_PATH], resname[MAX_RES_PATH]; |
| 78 |
long reslength; |
| 79 |
|
| 80 |
GetResourceParameters(filename, resname); |
| 81 |
|
| 82 |
if (!hugo_hasgraphics()) |
| 83 |
{ |
| 84 |
var[system_status] = STAT_UNAVAILABLE; |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
if (!(reslength = FindResource(filename, resname))) |
| 93 |
return; |
| 94 |
|
| 95 |
|
| 96 |
resource_type = (char)((fgetc(resource_file)==0xff)?JPEG_R:UNKNOWN_R); |
| 97 |
fseek(resource_file, -1, SEEK_CUR); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
if (!hugo_displaypicture(resource_file, reslength)) |
| 105 |
var[system_status] = STAT_LOADERROR; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
void PlayMusic(void) |
| 112 |
{ |
| 113 |
char filename[MAX_RES_PATH], resname[MAX_RES_PATH]; |
| 114 |
char loop_flag = 0; |
| 115 |
long resstart, reslength; |
| 116 |
|
| 117 |
if (MEM(codeptr+1)==REPEAT_T) loop_flag = true, codeptr++; |
| 118 |
|
| 119 |
hugo_stopmusic(); |
| 120 |
|
| 121 |
|
| 122 |
if (!GetResourceParameters(filename, resname)) |
| 123 |
{ |
| 124 |
return; |
| 125 |
} |
| 126 |
|
| 127 |
if (extra_param>=0) |
| 128 |
{ |
| 129 |
if (extra_param > 100) extra_param = 100; |
| 130 |
hugo_musicvolume(extra_param); |
| 131 |
} |
| 132 |
|
| 133 |
if (!(reslength = FindResource(filename, resname))) |
| 134 |
return; |
| 135 |
|
| 136 |
|
| 137 |
resstart = ftell(resource_file); |
| 138 |
|
| 139 |
|
| 140 |
if (fseek(resource_file, resstart, SEEK_SET) == 0 |
| 141 |
&& fread(resname, 4, 1, resource_file) == 1 |
| 142 |
&& !memcmp(resname, "MThd", 4)) |
| 143 |
{ |
| 144 |
resource_type = MIDI_R; |
| 145 |
goto Identified; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
if (fseek(resource_file, resstart, SEEK_SET) == 0 |
| 150 |
&& fread(resname, 17, 1, resource_file) == 1 |
| 151 |
&& !memcmp(resname, "Extended Module: ", 17)) |
| 152 |
{ |
| 153 |
resource_type = XM_R; |
| 154 |
goto Identified; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
if (fseek(resource_file, resstart+0x2c, SEEK_SET) == 0 |
| 159 |
&& fread(resname, 4, 1, resource_file) == 1 |
| 160 |
&& !memcmp(resname, "SCRM", 4)) |
| 161 |
{ |
| 162 |
resource_type = S3M_R; |
| 163 |
goto Identified; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
resname[4] = '\0'; |
| 168 |
|
| 169 |
if (fseek(resource_file, resstart+1080, SEEK_SET) == 0 |
| 170 |
&& fread(resname, 4, 1, resource_file) == 1 |
| 171 |
&& (!strcmp(resname+1, "CHN") |
| 172 |
|| !strcmp(resname+2, "CN") |
| 173 |
|| !strcmp(resname, "M.K.") |
| 174 |
|| !strcmp(resname, "M!K!") |
| 175 |
|| !strcmp(resname, "FLT4") |
| 176 |
|| !strcmp(resname, "CD81") |
| 177 |
|| !strcmp(resname, "OKTA") |
| 178 |
|| !strcmp(resname, " "))) |
| 179 |
{ |
| 180 |
resource_type = MOD_R; |
| 181 |
goto Identified; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
else |
| 187 |
{ |
| 188 |
resource_type = MP3_R; |
| 189 |
goto Identified; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
resource_type = UNKNOWN_R; |
| 194 |
|
| 195 |
Identified: |
| 196 |
fseek(resource_file, resstart, SEEK_SET); |
| 197 |
|
| 198 |
if (!hugo_playmusic(resource_file, reslength, loop_flag)) |
| 199 |
var[system_status] = STAT_LOADERROR; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
void PlaySample(void) |
| 206 |
{ |
| 207 |
char filename[MAX_RES_PATH], resname[MAX_RES_PATH]; |
| 208 |
char loop_flag = 0; |
| 209 |
long reslength; |
| 210 |
|
| 211 |
if (MEM(codeptr+1)==REPEAT_T) loop_flag = true, codeptr++; |
| 212 |
|
| 213 |
hugo_stopsample(); |
| 214 |
|
| 215 |
|
| 216 |
if (!GetResourceParameters(filename, resname)) |
| 217 |
{ |
| 218 |
return; |
| 219 |
} |
| 220 |
|
| 221 |
if (extra_param>=0) |
| 222 |
{ |
| 223 |
if (extra_param > 100) extra_param = 100; |
| 224 |
hugo_samplevolume(extra_param); |
| 225 |
} |
| 226 |
|
| 227 |
if (!(reslength = FindResource(filename, resname))) |
| 228 |
return; |
| 229 |
|
| 230 |
|
| 231 |
if (fread(resname, 4, 1, resource_file) == 1 && !memcmp(resname, "WAVE", 4)) |
| 232 |
resource_type = WAVE_R; |
| 233 |
else |
| 234 |
resource_type = UNKNOWN_R; |
| 235 |
|
| 236 |
fseek(resource_file, -4, SEEK_CUR); |
| 237 |
|
| 238 |
if (!hugo_playsample(resource_file, reslength, loop_flag)) |
| 239 |
var[system_status] = STAT_LOADERROR; |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
void PlayVideo(void) |
| 246 |
{ |
| 247 |
char filename[MAX_RES_PATH], resname[MAX_RES_PATH]; |
| 248 |
char loop_flag = 0, background = 0; |
| 249 |
int volume = 100; |
| 250 |
long resstart, reslength; |
| 251 |
|
| 252 |
#if defined (COMPILE_V25) |
| 253 |
var[system_status] = STAT_UNAVAILABLE; |
| 254 |
#endif |
| 255 |
if (MEM(codeptr+1)==REPEAT_T) loop_flag = true, codeptr++; |
| 256 |
|
| 257 |
#if !defined (COMPILE_V25) |
| 258 |
hugo_stopvideo(); |
| 259 |
#endif |
| 260 |
|
| 261 |
|
| 262 |
if (!GetResourceParameters(filename, resname)) |
| 263 |
{ |
| 264 |
return; |
| 265 |
} |
| 266 |
|
| 267 |
if (MEM(codeptr-1)==COMMA_T) |
| 268 |
{ |
| 269 |
background = (char)GetValue(); |
| 270 |
codeptr++; |
| 271 |
} |
| 272 |
|
| 273 |
if (extra_param>=0) |
| 274 |
{ |
| 275 |
if (extra_param > 100) extra_param = 100; |
| 276 |
volume = extra_param; |
| 277 |
} |
| 278 |
|
| 279 |
if (!(reslength = FindResource(filename, resname))) |
| 280 |
return; |
| 281 |
|
| 282 |
|
| 283 |
resstart = ftell(resource_file); |
| 284 |
|
| 285 |
|
| 286 |
if (fseek(resource_file, resstart, SEEK_SET) == 0 |
| 287 |
&& fread(resname, 4, 1, resource_file) == 1 |
| 288 |
&& resname[2]==0x01 && (unsigned char)resname[3]==0xba) |
| 289 |
{ |
| 290 |
resource_type = MPEG_R; |
| 291 |
goto Identified; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
if (fseek(resource_file, resstart+8, SEEK_SET) == 0 |
| 296 |
&& fread(resname, 4, 1, resource_file) == 1 |
| 297 |
&& !memcmp(resname, "AVI ", 4)) |
| 298 |
{ |
| 299 |
resource_type = AVI_R; |
| 300 |
goto Identified; |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
resource_type = UNKNOWN_R; |
| 305 |
|
| 306 |
Identified: |
| 307 |
fseek(resource_file, resstart, SEEK_SET); |
| 308 |
|
| 309 |
#if !defined (COMPILE_V25) |
| 310 |
if (!hugo_playvideo(resource_file, reslength, loop_flag, background, volume)) |
| 311 |
var[system_status] = STAT_LOADERROR; |
| 312 |
#else |
| 313 |
fclose(resource_file); |
| 314 |
resource_file = NULL; |
| 315 |
#endif |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
long FindResource(char *filename, char *resname) |
| 336 |
{ |
| 337 |
char resource_in_file[MAX_RES_PATH]; |
| 338 |
int i, len; |
| 339 |
int rescount; |
| 340 |
unsigned int startofdata; |
| 341 |
long resposition, reslength; |
| 342 |
#if defined (GLK) |
| 343 |
frefid_t fref; |
| 344 |
#endif |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
int res_32bits = true; |
| 349 |
|
| 350 |
resource_file = NULL; |
| 351 |
|
| 352 |
strcpy(loaded_filename, filename); |
| 353 |
strcpy(loaded_resname, resname); |
| 354 |
if (!strcmp(filename, "")) strcpy(loaded_filename, resname); |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
if (!strcmp(filename, "")) |
| 360 |
goto NotinResourceFile; |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
strupr(filename); |
| 365 |
|
| 366 |
#if !defined (GLK) |
| 367 |
|
| 368 |
if (!(resource_file = TrytoOpen(filename, "rb", "games"))) |
| 369 |
if (!(resource_file = TrytoOpen(filename, "rb", "object"))) |
| 370 |
{ |
| 371 |
var[system_status] = STAT_NOFILE; |
| 372 |
return 0; |
| 373 |
} |
| 374 |
#else |
| 375 |
|
| 376 |
#ifdef HUGO_GLKUNIX |
| 377 |
|
| 378 |
char temp[1024]; |
| 379 |
snprintf(temp, sizeof temp, "%s/%s", hugo_path_to_game, filename); |
| 380 |
resource_file = glkunix_stream_open_pathname(temp, 0, 0); |
| 381 |
#else |
| 382 |
fref = glk_fileref_create_by_name(fileusage_Data | fileusage_BinaryMode, |
| 383 |
filename, 0); |
| 384 |
if (glk_fileref_does_file_exist(fref)) |
| 385 |
resource_file = glk_stream_open_file(fref, filemode_Read, 0); |
| 386 |
else |
| 387 |
resource_file = NULL; |
| 388 |
glk_fileref_destroy(fref); |
| 389 |
#endif |
| 390 |
if (!resource_file) |
| 391 |
{ |
| 392 |
var[system_status] = STAT_NOFILE; |
| 393 |
return 0; |
| 394 |
} |
| 395 |
#endif |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
i = fgetc(resource_file); |
| 400 |
if (i=='r') |
| 401 |
res_32bits = true; |
| 402 |
else if (i=='R') |
| 403 |
res_32bits = false; |
| 404 |
else |
| 405 |
goto ResfileError; |
| 406 |
|
| 407 |
fgetc(resource_file); |
| 408 |
rescount = fgetc(resource_file); |
| 409 |
rescount += fgetc(resource_file)*256; |
| 410 |
startofdata = fgetc(resource_file); |
| 411 |
startofdata += (unsigned int)fgetc(resource_file)*256; |
| 412 |
if (ferror(resource_file)) |
| 413 |
goto ResfileError; |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
for (i=1; i<=rescount; i++) |
| 420 |
{ |
| 421 |
len = fgetc(resource_file); |
| 422 |
if (ferror(resource_file)) |
| 423 |
goto ResfileError; |
| 424 |
|
| 425 |
if (!(fgets(resource_in_file, len+1, resource_file))) |
| 426 |
goto ResfileError; |
| 427 |
|
| 428 |
resposition = (long)fgetc(resource_file); |
| 429 |
resposition += (long)fgetc(resource_file)*256L; |
| 430 |
resposition += (long)fgetc(resource_file)*65536L; |
| 431 |
if (res_32bits) |
| 432 |
{ |
| 433 |
resposition += (long)fgetc(resource_file)*16777216L; |
| 434 |
} |
| 435 |
|
| 436 |
reslength = (long)fgetc(resource_file); |
| 437 |
reslength += (long)fgetc(resource_file)*256L; |
| 438 |
reslength += (long)fgetc(resource_file)*65536L; |
| 439 |
if (res_32bits) |
| 440 |
{ |
| 441 |
reslength += (long)fgetc(resource_file)*16777216L; |
| 442 |
} |
| 443 |
if (ferror(resource_file)) goto ResfileError; |
| 444 |
|
| 445 |
if (!strcmp(resname, resource_in_file)) |
| 446 |
{ |
| 447 |
if (fseek(resource_file, (long)startofdata+resposition, SEEK_SET)) |
| 448 |
goto ResfileError; |
| 449 |
return reslength; |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
ResfileError: |
| 454 |
|
| 455 |
var[system_status] = STAT_NORESOURCE; |
| 456 |
|
| 457 |
#if defined (DEBUGGER) |
| 458 |
SwitchtoDebugger(); |
| 459 |
sprintf(debug_line, "Unable to find \"%s\" in \"%s\"", resname, filename); |
| 460 |
DebugMessageBox("Resource Error", debug_line); |
| 461 |
SwitchtoGame(); |
| 462 |
#endif |
| 463 |
fclose(resource_file); |
| 464 |
resource_file = NULL; |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
NotinResourceFile: |
| 472 |
|
| 473 |
#if !defined (GLK) |
| 474 |
|
| 475 |
if (!(resource_file = TrytoOpen(resname, "rb", "resource"))) |
| 476 |
if (!(resource_file = TrytoOpen(resname, "rb", "source"))) |
| 477 |
{ |
| 478 |
if (!strcmp(filename, "")) |
| 479 |
var[system_status] = STAT_NOFILE; |
| 480 |
else |
| 481 |
var[system_status] = STAT_NORESOURCE; |
| 482 |
return 0; |
| 483 |
} |
| 484 |
#else |
| 485 |
|
| 486 |
#ifdef HUGO_GLKUNIX |
| 487 |
snprintf(temp, sizeof temp, "%s/%s", hugo_path_to_game, resname); |
| 488 |
resource_file = glkunix_stream_open_pathname(temp, 0, 0); |
| 489 |
#else |
| 490 |
fref = glk_fileref_create_by_name(fileusage_Data | fileusage_BinaryMode, |
| 491 |
resname, 0); |
| 492 |
if (glk_fileref_does_file_exist(fref)) |
| 493 |
resource_file = glk_stream_open_file(fref, filemode_Read, 0); |
| 494 |
else |
| 495 |
resource_file = NULL; |
| 496 |
glk_fileref_destroy(fref); |
| 497 |
#endif |
| 498 |
if (!resource_file) |
| 499 |
{ |
| 500 |
if (!strcmp(filename, "")) |
| 501 |
var[system_status] = STAT_NOFILE; |
| 502 |
else |
| 503 |
var[system_status] = STAT_NORESOURCE; |
| 504 |
return 0; |
| 505 |
} |
| 506 |
#endif |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
fseek(resource_file, 0, SEEK_END); |
| 512 |
reslength = ftell(resource_file); |
| 513 |
fseek(resource_file, 0, SEEK_SET); |
| 514 |
if (ferror(resource_file)) |
| 515 |
{ |
| 516 |
fclose(resource_file); |
| 517 |
resource_file = NULL; |
| 518 |
return false; |
| 519 |
} |
| 520 |
|
| 521 |
return reslength; |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
static int GetResourceParameters(char *filename, char *resname) |
| 533 |
{ |
| 534 |
int f; |
| 535 |
|
| 536 |
var[system_status] = 0; |
| 537 |
|
| 538 |
extra_param = -1; |
| 539 |
|
| 540 |
codeptr++; |
| 541 |
|
| 542 |
f = GetValue(); |
| 543 |
|
| 544 |
|
| 545 |
if (!f && MEM(codeptr)!=COMMA_T) |
| 546 |
{ |
| 547 |
++codeptr; |
| 548 |
return 0; |
| 549 |
} |
| 550 |
|
| 551 |
strcpy(filename, GetWord((unsigned int)f)); |
| 552 |
|
| 553 |
if (MEM(codeptr++)!=EOL_T) |
| 554 |
{ |
| 555 |
strupr(filename); |
| 556 |
strcpy(resname, GetWord(GetValue())); |
| 557 |
if (MEM(codeptr++)==COMMA_T) |
| 558 |
{ |
| 559 |
extra_param = GetValue(); |
| 560 |
codeptr++; |
| 561 |
} |
| 562 |
} |
| 563 |
else |
| 564 |
{ |
| 565 |
strcpy(resname, filename); |
| 566 |
strcpy(filename, ""); |
| 567 |
} |
| 568 |
|
| 569 |
return true; |
| 570 |
} |