From 9e1bf888b8b3095a844c636e78b0bf35708878a9 Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Sun, 20 Nov 2016 19:25:12 -0600 Subject: SCI: Deduplicate text-reading code in kGetFarText --- engines/sci/engine/kstring.cpp | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 74c1f99778..ab1f0210e7 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -438,31 +438,15 @@ reg_t kStrLen(EngineState *s, int argc, reg_t *argv) { reg_t kGetFarText(EngineState *s, int argc, reg_t *argv) { - Resource *textres = g_sci->getResMan()->findResource(ResourceId(kResourceTypeText, argv[0].toUint16()), 0); - char *seeker; - int counter = argv[1].toUint16(); - - if (!textres) { - error("text.%d does not exist", argv[0].toUint16()); - return NULL_REG; - } - - seeker = (char *)textres->data; - - // The second parameter (counter) determines the number of the string - // inside the text resource. - while (counter--) { - while (*seeker++) - ; - } + const Common::String text = g_sci->getKernel()->lookupText(make_reg(0, argv[0].toUint16()), argv[1].toUint16()); // If the third argument is NULL, allocate memory for the destination. This // occurs in SCI1 Mac games. The memory will later be freed by the game's // scripts. if (argv[2] == NULL_REG) - s->_segMan->allocDynmem(strlen(seeker) + 1, "Mac FarText", &argv[2]); + s->_segMan->allocDynmem(text.size() + 1, "Mac FarText", &argv[2]); - s->_segMan->strcpy(argv[2], seeker); // Copy the string and get return value + s->_segMan->strcpy(argv[2], text.c_str()); // Copy the string and get return value return argv[2]; } -- cgit v1.2.3