diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs index db7e107fd..3b9713ebf 100644 --- a/Dalamud/Data/DataManager.cs +++ b/Dalamud/Data/DataManager.cs @@ -16,36 +16,48 @@ namespace Dalamud.Data public class DataManager { private const string DataBaseUrl = "https://goaaats.github.io/ffxiv/tools/launcher/addons/Hooks/Data/"; - public ReadOnlyDictionary OpCodes; + public ReadOnlyDictionary ServerOpCodes; public ReadOnlyDictionary ContentFinderCondition; + public bool IsDataReady { get; private set; } + public DataManager() { // Set up default values so plugins do not null-reference when data is being loaded. - this.OpCodes = new ReadOnlyDictionary(new Dictionary()); + this.ServerOpCodes = new ReadOnlyDictionary(new Dictionary()); this.ContentFinderCondition = new ReadOnlyDictionary(new Dictionary()); } public async Task Initialize() { - Log.Verbose("Starting data download..."); + try { + Log.Verbose("Starting data download..."); - // This is due to GitHub not supporting TLS 1.0 - System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; + // This is due to GitHub not supporting TLS 1.0 + System.Net.ServicePointManager.SecurityProtocol = + SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; - using var client = new HttpClient() { - BaseAddress = new Uri(DataBaseUrl) - }; + using var client = new HttpClient() { + BaseAddress = new Uri(DataBaseUrl) + }; - var opCodeDict = JsonConvert.DeserializeObject>(await client.GetStringAsync(DataBaseUrl + "opcode.json")); - this.OpCodes = new ReadOnlyDictionary(opCodeDict); + var opCodeDict = + JsonConvert.DeserializeObject>( + await client.GetStringAsync(DataBaseUrl + "serveropcode.json")); + this.ServerOpCodes = new ReadOnlyDictionary(opCodeDict); - Log.Verbose("Loaded {0} OpCodes.", opCodeDict.Count); + Log.Verbose("Loaded {0} ServerOpCodes.", opCodeDict.Count); - var cfcs = JsonConvert.DeserializeObject>(await client.GetStringAsync(DataBaseUrl + "contentfindercondition.json")); - this.ContentFinderCondition = new ReadOnlyDictionary(cfcs); + var cfcs = JsonConvert.DeserializeObject>( + await client.GetStringAsync(DataBaseUrl + "contentfindercondition.json")); + this.ContentFinderCondition = new ReadOnlyDictionary(cfcs); - Log.Verbose("Loaded {0} ContentFinderCondition.", cfcs.Count); + Log.Verbose("Loaded {0} ContentFinderCondition.", cfcs.Count); - System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault; + System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault; + + IsDataReady = true; + } catch (Exception ex) { + Log.Error(ex, "Could not download data."); + } } } } diff --git a/Dalamud/Game/Network/NetworkHandlers.cs b/Dalamud/Game/Network/NetworkHandlers.cs index 7f7a74fda..a3da8c57c 100644 --- a/Dalamud/Game/Network/NetworkHandlers.cs +++ b/Dalamud/Game/Network/NetworkHandlers.cs @@ -34,9 +34,12 @@ namespace Dalamud.Game.Network { } private void OnZonePacket(IntPtr dataPtr) { + if (!this.dalamud.Data.IsDataReady) + return; + var opCode = (ushort) Marshal.ReadInt16(dataPtr, 2); - if (opCode == this.dalamud.Data.OpCodes["CfNotifyPop"]) { + if (opCode == this.dalamud.Data.ServerOpCodes["CfNotifyPop"]) { var data = new byte[64]; Marshal.Copy(dataPtr, data, 0, 64); @@ -59,7 +62,7 @@ namespace Dalamud.Game.Network { return; } - if (opCode == this.dalamud.Data.OpCodes["CfPreferredRole"]) { + if (opCode == this.dalamud.Data.ServerOpCodes["CfPreferredRole"]) { if (this.dalamud.Configuration.PreferredRoleReminders == null) return; @@ -114,7 +117,7 @@ namespace Dalamud.Game.Network { } if (!this.optOutMbUploads) { - if (opCode == this.dalamud.Data.OpCodes["MarketBoardItemRequestStart"]) { + if (opCode == this.dalamud.Data.ServerOpCodes["MarketBoardItemRequestStart"]) { var catalogId = (uint) Marshal.ReadInt32(dataPtr + 0x10); var amount = Marshal.ReadByte(dataPtr + 0x1B); @@ -129,7 +132,7 @@ namespace Dalamud.Game.Network { return; } - if (opCode == this.dalamud.Data.OpCodes["MarketBoardOfferings"]) { + if (opCode == this.dalamud.Data.ServerOpCodes["MarketBoardOfferings"]) { var listing = MarketBoardCurrentOfferings.Read(dataPtr + 0x10); var request = @@ -184,7 +187,7 @@ namespace Dalamud.Game.Network { return; } - if (opCode == this.dalamud.Data.OpCodes["MarketBoardHistory"]) { + if (opCode == this.dalamud.Data.ServerOpCodes["MarketBoardHistory"]) { var listing = MarketBoardHistory.Read(dataPtr + 0x10); var request = this.marketBoardRequests.LastOrDefault(r => r.CatalogId == listing.CatalogId); @@ -206,7 +209,7 @@ namespace Dalamud.Game.Network { Log.Verbose("Added history for item#{0}", listing.CatalogId); } - if (opCode == this.dalamud.Data.OpCodes["MarketTaxRates"]) + if (opCode == this.dalamud.Data.ServerOpCodes["MarketTaxRates"]) { var taxes = MarketTaxRates.Read(dataPtr + 0x10);