mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 05:04:15 +01:00
fix: add IsDataReady flag to DataManager
This commit is contained in:
parent
d447bc7c61
commit
1ac738cd25
2 changed files with 36 additions and 21 deletions
|
|
@ -16,36 +16,48 @@ namespace Dalamud.Data
|
||||||
public class DataManager {
|
public class DataManager {
|
||||||
private const string DataBaseUrl = "https://goaaats.github.io/ffxiv/tools/launcher/addons/Hooks/Data/";
|
private const string DataBaseUrl = "https://goaaats.github.io/ffxiv/tools/launcher/addons/Hooks/Data/";
|
||||||
|
|
||||||
public ReadOnlyDictionary<string, ushort> OpCodes;
|
public ReadOnlyDictionary<string, ushort> ServerOpCodes;
|
||||||
public ReadOnlyDictionary<uint, JObject> ContentFinderCondition;
|
public ReadOnlyDictionary<uint, JObject> ContentFinderCondition;
|
||||||
|
|
||||||
|
public bool IsDataReady { get; private set; }
|
||||||
|
|
||||||
public DataManager() {
|
public DataManager() {
|
||||||
// Set up default values so plugins do not null-reference when data is being loaded.
|
// Set up default values so plugins do not null-reference when data is being loaded.
|
||||||
this.OpCodes = new ReadOnlyDictionary<string, ushort>(new Dictionary<string, ushort>());
|
this.ServerOpCodes = new ReadOnlyDictionary<string, ushort>(new Dictionary<string, ushort>());
|
||||||
this.ContentFinderCondition = new ReadOnlyDictionary<uint, JObject>(new Dictionary<uint, JObject>());
|
this.ContentFinderCondition = new ReadOnlyDictionary<uint, JObject>(new Dictionary<uint, JObject>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Initialize() {
|
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
|
// This is due to GitHub not supporting TLS 1.0
|
||||||
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
|
System.Net.ServicePointManager.SecurityProtocol =
|
||||||
|
SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
|
||||||
|
|
||||||
using var client = new HttpClient() {
|
using var client = new HttpClient() {
|
||||||
BaseAddress = new Uri(DataBaseUrl)
|
BaseAddress = new Uri(DataBaseUrl)
|
||||||
};
|
};
|
||||||
|
|
||||||
var opCodeDict = JsonConvert.DeserializeObject<Dictionary<string, ushort>>(await client.GetStringAsync(DataBaseUrl + "opcode.json"));
|
var opCodeDict =
|
||||||
this.OpCodes = new ReadOnlyDictionary<string, ushort>(opCodeDict);
|
JsonConvert.DeserializeObject<Dictionary<string, ushort>>(
|
||||||
|
await client.GetStringAsync(DataBaseUrl + "serveropcode.json"));
|
||||||
|
this.ServerOpCodes = new ReadOnlyDictionary<string, ushort>(opCodeDict);
|
||||||
|
|
||||||
Log.Verbose("Loaded {0} OpCodes.", opCodeDict.Count);
|
Log.Verbose("Loaded {0} ServerOpCodes.", opCodeDict.Count);
|
||||||
|
|
||||||
var cfcs = JsonConvert.DeserializeObject<Dictionary<uint, JObject>>(await client.GetStringAsync(DataBaseUrl + "contentfindercondition.json"));
|
var cfcs = JsonConvert.DeserializeObject<Dictionary<uint, JObject>>(
|
||||||
this.ContentFinderCondition = new ReadOnlyDictionary<uint, JObject>(cfcs);
|
await client.GetStringAsync(DataBaseUrl + "contentfindercondition.json"));
|
||||||
|
this.ContentFinderCondition = new ReadOnlyDictionary<uint, JObject>(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.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,12 @@ namespace Dalamud.Game.Network {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnZonePacket(IntPtr dataPtr) {
|
private void OnZonePacket(IntPtr dataPtr) {
|
||||||
|
if (!this.dalamud.Data.IsDataReady)
|
||||||
|
return;
|
||||||
|
|
||||||
var opCode = (ushort) Marshal.ReadInt16(dataPtr, 2);
|
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];
|
var data = new byte[64];
|
||||||
Marshal.Copy(dataPtr, data, 0, 64);
|
Marshal.Copy(dataPtr, data, 0, 64);
|
||||||
|
|
||||||
|
|
@ -59,7 +62,7 @@ namespace Dalamud.Game.Network {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opCode == this.dalamud.Data.OpCodes["CfPreferredRole"]) {
|
if (opCode == this.dalamud.Data.ServerOpCodes["CfPreferredRole"]) {
|
||||||
if (this.dalamud.Configuration.PreferredRoleReminders == null)
|
if (this.dalamud.Configuration.PreferredRoleReminders == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -114,7 +117,7 @@ namespace Dalamud.Game.Network {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.optOutMbUploads) {
|
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 catalogId = (uint) Marshal.ReadInt32(dataPtr + 0x10);
|
||||||
var amount = Marshal.ReadByte(dataPtr + 0x1B);
|
var amount = Marshal.ReadByte(dataPtr + 0x1B);
|
||||||
|
|
||||||
|
|
@ -129,7 +132,7 @@ namespace Dalamud.Game.Network {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opCode == this.dalamud.Data.OpCodes["MarketBoardOfferings"]) {
|
if (opCode == this.dalamud.Data.ServerOpCodes["MarketBoardOfferings"]) {
|
||||||
var listing = MarketBoardCurrentOfferings.Read(dataPtr + 0x10);
|
var listing = MarketBoardCurrentOfferings.Read(dataPtr + 0x10);
|
||||||
|
|
||||||
var request =
|
var request =
|
||||||
|
|
@ -184,7 +187,7 @@ namespace Dalamud.Game.Network {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opCode == this.dalamud.Data.OpCodes["MarketBoardHistory"]) {
|
if (opCode == this.dalamud.Data.ServerOpCodes["MarketBoardHistory"]) {
|
||||||
var listing = MarketBoardHistory.Read(dataPtr + 0x10);
|
var listing = MarketBoardHistory.Read(dataPtr + 0x10);
|
||||||
|
|
||||||
var request = this.marketBoardRequests.LastOrDefault(r => r.CatalogId == listing.CatalogId);
|
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);
|
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);
|
var taxes = MarketTaxRates.Read(dataPtr + 0x10);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue