diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index 2405755c5..02fef0a4f 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -377,7 +377,7 @@ static FStrifeDialogueNode *ReadRetailNode (const char *name, FileReader &lump, 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 { @@ -401,6 +401,8 @@ static FStrifeDialogueNode *ReadRetailNode (const char *name, FileReader &lump, label.ReplaceChars(' ', '_'); label.ReplaceChars('\'', '_'); node->SpeakerName.Format("$TXT_SPEAKER_%s", label.GetChars()); + if (!GStrings.exists(node->SpeakerName)) node->SpeakerName = speech.Name; + } else { @@ -471,7 +473,7 @@ static FStrifeDialogueNode *ReadTeaserNode (const char *name, FileReader &lump, 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 { @@ -500,6 +502,7 @@ static FStrifeDialogueNode *ReadTeaserNode (const char *name, FileReader &lump, label.ReplaceChars(' ', '_'); label.ReplaceChars('\'', '_'); node->SpeakerName.Format("$TXT_SPEAKER_%s", label.GetChars()); + if (!GStrings.exists(node->SpeakerName)) node->SpeakerName = speech.Name; } else { @@ -591,6 +594,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 @@ -615,7 +620,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 { @@ -625,7 +630,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 { diff --git a/src/stringtable.cpp b/src/stringtable.cpp index c57e6e031..bc15b83f4 100644 --- a/src/stringtable.cpp +++ b/src/stringtable.cpp @@ -210,6 +210,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/stringtable.h b/src/stringtable.h index 1c479ba5a..11416367c 100644 --- a/src/stringtable.h +++ b/src/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: