From 8997a45773a51583b2e686907cfa60f85b79bfc2 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 22 Feb 2009 19:45:53 +0000 Subject: SCI: Replaced two uses of sci_fopen by Common::File; moved is_print_str() to the only spot it is used svn-id: r38791 --- engines/sci/engine/game.cpp | 9 +++++---- engines/sci/engine/kstring.cpp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'engines/sci/engine') diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 5c7bd07f3e..83a62c57b0 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -24,6 +24,7 @@ */ #include "common/system.h" +#include "common/file.h" #include "sci/include/sciresource.h" #include "sci/include/engine.h" @@ -139,10 +140,10 @@ int _reset_graphics_input(EngineState *s) { } } else { // Check for Amiga palette file. - FILE *f = sci_fopen("spal", "rb"); - if (f) { - s->gfx_state->resstate->static_palette = gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, f); - fclose(f); + Common::File file; + if (file.open("spal")) { + s->gfx_state->resstate->static_palette = gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, file); + file.close(); _sci1_alloc_system_colors(s); } else { resource = scir_find_resource(s->resmgr, sci_palette, 999, 1); diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index f961515c94..0e48254026 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -408,6 +408,23 @@ reg_t kStrCpy(EngineState *s, int funct_nr, int argc, reg_t *argv) { return argv[0]; } +/* Simple heuristic to work around array handling peculiarity in SQ4: +It uses StrAt() to read the individual elements, so we must determine +whether a string is really a string or an array. */ +static int is_print_str(char *str) { + int printable = 0; + int len = strlen(str); + + if (len == 0) return 1; + + while (*str) { + if (isprint(*str)) printable++; + str++; + } + + return ((float)printable / (float)len >= 0.5); +} + reg_t kStrAt(EngineState *s, int funct_nr, int argc, reg_t *argv) { unsigned char *dest = (unsigned char *) kernel_dereference_bulk_pointer(s, argv[0], 0); -- cgit v1.2.3