From 6d19374ae866699321d1dda318a0c9d495fc3d72 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 11 Feb 2019 00:46:13 +0100 Subject: [PATCH] Only replace Strife dialogue content if the default strings from zd_extra.pk3 are present. If not, use the dialogue file's content directly. --- src/gamedata/stringtable.cpp | 26 ++++++++++++++++++++++++++ src/gamedata/stringtable.h | 1 + src/p_conversation.cpp | 13 +++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/gamedata/stringtable.cpp b/src/gamedata/stringtable.cpp index 95c2e754ed..1afc68e439 100644 --- a/src/gamedata/stringtable.cpp +++ b/src/gamedata/stringtable.cpp @@ -208,6 +208,32 @@ size_t FStringTable::ProcessEscapes (char *iptr) return optr - sptr; } +bool FStringTable::exists(const char *name) +{ + // Checks if the given key exists in any one of the default string tables that are valid for all languages. + // To replace IWAD content this condition must be true. + if (name == nullptr || *name == 0) + { + return false; + } + FName nm(name, true); + if (nm != NAME_None) + { + uint32_t defaultStrings[] = { MAKE_ID('*', '*', '*', 0), MAKE_ID('*', 0, 0, 0), MAKE_ID('*', '*', 0, 0) }; + + for (auto mapid : defaultStrings) + { + auto map = allStrings.CheckKey(mapid); + if (map) + { + auto item = map->CheckKey(nm); + if (item) return true; + } + } + } + return false; +} + // Finds a string by name and returns its value const char *FStringTable::operator[] (const char *name) const { diff --git a/src/gamedata/stringtable.h b/src/gamedata/stringtable.h index 1c479ba5a5..11416367c1 100644 --- a/src/gamedata/stringtable.h +++ b/src/gamedata/stringtable.h @@ -71,6 +71,7 @@ public: const char *operator() (const char *name) const; // Never returns NULL const char *operator[] (const char *name) const; // Can return NULL + bool exists(const char *name); private: diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index d5514c09b6..957f3b0a2f 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -352,7 +352,7 @@ static FStrifeDialogueNode *ReadRetailNode (FLevelLocals *Level, const char *nam if (name) { FStringf label("$TXT_DLG_%s_d%d_%s", name, int(pos), TokenFromString(speech.Dialogue).GetChars()); - node->Dialogue = label; + node->Dialogue = GStrings.exists(label)? label : FString(speech.Dialogue); } else { @@ -376,6 +376,8 @@ static FStrifeDialogueNode *ReadRetailNode (FLevelLocals *Level, const char *nam label.ReplaceChars(' ', '_'); label.ReplaceChars('\'', '_'); node->SpeakerName.Format("$TXT_SPEAKER_%s", label.GetChars()); + if (!GStrings.exists(node->SpeakerName)) node->SpeakerName = speech.Name; + } else { @@ -446,7 +448,7 @@ static FStrifeDialogueNode *ReadTeaserNode (FLevelLocals *Level, const char *nam if (name) { FStringf label("$TXT_DLG_%s_d%d_%s", name, pos, TokenFromString(speech.Dialogue).GetChars()); - node->Dialogue = label; + node->Dialogue = GStrings.exists(label)? label : FString(speech.Dialogue); } else { @@ -475,6 +477,7 @@ static FStrifeDialogueNode *ReadTeaserNode (FLevelLocals *Level, const char *nam label.ReplaceChars(' ', '_'); label.ReplaceChars('\'', '_'); node->SpeakerName.Format("$TXT_SPEAKER_%s", label.GetChars()); + if (!GStrings.exists(node->SpeakerName)) node->SpeakerName = speech.Name; } else { @@ -566,6 +569,8 @@ static void ParseReplies (const char *name, int pos, FStrifeDialogueReply **repl if (name) { FStringf label("$TXT_RPLY%d_%s_d%d_%s", j, name, pos, TokenFromString(rsp->Reply).GetChars()); + reply->Reply = GStrings.exists(label)? label : FString(rsp->Reply); + reply->Reply = label; } else @@ -590,7 +595,7 @@ static void ParseReplies (const char *name, int pos, FStrifeDialogueReply **repl if (name) { FStringf label("$TXT_RYES%d_%s_d%d_%s", j, name, pos, TokenFromString(rsp->Yes).GetChars()); - reply->QuickYes = label; + reply->QuickYes = GStrings.exists(label)? label : FString(rsp->Yes); } else { @@ -600,7 +605,7 @@ static void ParseReplies (const char *name, int pos, FStrifeDialogueReply **repl if (reply->ItemCheck[0].Item != 0) { FStringf label("$TXT_RNO%d_%s_d%d_%s", j, name, pos, TokenFromString(rsp->No).GetChars()); - reply->QuickNo = label; + reply->QuickNo = GStrings.exists(label)? label : FString(rsp->No); } else {