From 6cfcf1f1796c9d3125596666362ce5162fd406ae Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 15 Aug 2016 19:43:01 +0600 Subject: HE: Add setupStringArrayFromString() It's based on PUI_ScummStringArrayFromCString(), which is used as SPUTM_ScummStringArrayFromCString() in Moonbase networking code. --- engines/scumm/he/intern_he.h | 3 ++- engines/scumm/he/script_v72he.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/engines/scumm/he/intern_he.h b/engines/scumm/he/intern_he.h index 95f6f2cf8d..8d7ed81dd8 100644 --- a/engines/scumm/he/intern_he.h +++ b/engines/scumm/he/intern_he.h @@ -288,7 +288,8 @@ public: virtual byte *getStringAddress(ResId idx); virtual int setupStringArray(int size); - void getStringFromArray(int arrayNumber, char *buffer, int maxLength); + virtual int setupStringArrayFromString(char *cStr); + virtual void getStringFromArray(int arrayNumber, char *buffer, int maxLength); protected: virtual void setupOpcodes(); diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp index 192675190c..4385475a30 100644 --- a/engines/scumm/he/script_v72he.cpp +++ b/engines/scumm/he/script_v72he.cpp @@ -230,6 +230,23 @@ int ScummEngine_v72he::setupStringArray(int size) { return readVar(0); } +int ScummEngine_v72he::setupStringArrayFromString(char *cStr) { + // this is PUI_ScummStringArrayFromCString() found in PUSERMAC.cpp + // I can see how its done up there in setupStringArray() + // yet I'd note that 'SCUMMVAR_user_reserved' var was used instead of 0 + // and strlen(), not strlen() + 1 was used + // plus, this function actually copies the string, not just 'sets up' the array + + writeVar(0, 0); + + int len = strlen(cStr); + byte *ptr = defineArray(0, kStringArray, 0, 0, 0, len); + if (ptr != nullptr) + strcpy((char*)ptr, cStr); + + return readVar(0); +} + void ScummEngine_v72he::readArrayFromIndexFile() { int num; int a, b, c; -- cgit v1.2.3