From bb7686747714227e6256fc4bb55c920bd1a04c48 Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Sun, 10 Nov 2024 17:46:33 -0500 Subject: [PATCH] Core/Conversation: Hackfix for NextConversationLineID overflow Port From (https://github.com/TrinityCore/TrinityCore/commit/9c6a5947de5e27755ec81f530882d6d1171fb97b) --- .../DataStorage/ConversationDataStorage.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Source/Game/DataStorage/ConversationDataStorage.cs b/Source/Game/DataStorage/ConversationDataStorage.cs index 4f79851cc..b62a45d96 100644 --- a/Source/Game/DataStorage/ConversationDataStorage.cs +++ b/Source/Game/DataStorage/ConversationDataStorage.cs @@ -99,11 +99,30 @@ namespace Game.DataStorage Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation actors. DB table `conversation_actors` is empty."); } + // TODO: Remove this hack when NextConversationLineID is changed to uint32 + uint getNextConversationLineId(ConversationLineRecord conversationLine) + { + if (conversationLine != null && conversationLine.NextConversationLineID != 0) + { + uint FirstLineId = 60000; // Arbitrary id to cover the affected rows + + if (conversationLine.Id > FirstLineId && conversationLine.NextConversationLineID < (CliDB.ConversationLineStorage.GetNumRows() - ushort.MaxValue - 1)) + return (uint)(ushort.MaxValue + conversationLine.NextConversationLineID + 1); + + return (uint)conversationLine.NextConversationLineID; + } + + return 0u; + }; + // Validate FirstLineId Dictionary prevConversationLineIds = new(); foreach (var conversationLine in CliDB.ConversationLineStorage.Values) - if (conversationLine.NextConversationLineID != 0) - prevConversationLineIds[conversationLine.NextConversationLineID] = conversationLine.Id; + { + uint nextConversationLineId = getNextConversationLineId(conversationLine); + if (nextConversationLineId != 0) + prevConversationLineIds[nextConversationLineId] = conversationLine.Id; + } uint getFirstLineIdFromAnyLineId(uint lineId) { @@ -149,10 +168,11 @@ namespace Game.DataStorage else Log.outError(LogFilter.Sql, "Table `conversation_line_template` has missing template for line (ID: {0}) in Conversation {1}, skipped", currentConversationLine.Id, conversationTemplate.Id); - if (currentConversationLine.NextConversationLineID == 0) + uint nextConversationLineId = getNextConversationLineId(currentConversationLine); + if (nextConversationLineId == 0) break; - currentConversationLine = CliDB.ConversationLineStorage.LookupByKey(currentConversationLine.NextConversationLineID); + currentConversationLine = CliDB.ConversationLineStorage.LookupByKey(nextConversationLineId); } _conversationTemplateStorage[conversationTemplate.Id] = conversationTemplate;