mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: add DataManager, remote opcodes etc.
This commit is contained in:
parent
829f9fb0cb
commit
27265244ec
3 changed files with 65 additions and 16 deletions
|
|
@ -7,6 +7,7 @@ using System.Reflection;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Dalamud.Data;
|
||||
using Dalamud.DiscordBot;
|
||||
using Dalamud.Game;
|
||||
using Dalamud.Game.Chat;
|
||||
|
|
@ -52,6 +53,8 @@ namespace Dalamud {
|
|||
|
||||
public readonly InterfaceManager InterfaceManager;
|
||||
|
||||
public readonly DataManager Data;
|
||||
|
||||
private readonly string assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString();
|
||||
|
||||
public Dalamud(DalamudStartInfo info) {
|
||||
|
|
@ -76,6 +79,10 @@ namespace Dalamud {
|
|||
ChatHandlers = new ChatHandlers(this);
|
||||
NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);
|
||||
|
||||
this.Data = new DataManager();
|
||||
//Task.Run(() => );
|
||||
this.Data.Initialize();
|
||||
|
||||
this.ClientState = new ClientState(this, info, this.SigScanner, this.targetModule);
|
||||
|
||||
this.BotManager = new DiscordBotManager(this, this.Configuration.DiscordFeatureConfig);
|
||||
|
|
|
|||
51
Dalamud/Data/DataManager.cs
Normal file
51
Dalamud/Data/DataManager.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serilog;
|
||||
|
||||
namespace Dalamud.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// This class provides data for Dalamud-internal features, but can also be used by plugins if needed.
|
||||
/// </summary>
|
||||
public class DataManager {
|
||||
private const string DataBaseUrl = "https://goaaats.github.io/ffxiv/tools/launcher/addons/Hooks/Data/";
|
||||
|
||||
public ReadOnlyDictionary<string, ushort> OpCodes;
|
||||
public ReadOnlyDictionary<uint, JObject> ContentFinderCondition;
|
||||
|
||||
public DataManager() {
|
||||
// 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.ContentFinderCondition = new ReadOnlyDictionary<uint, JObject>(new Dictionary<uint, JObject>());
|
||||
}
|
||||
|
||||
public async Task Initialize() {
|
||||
Log.Verbose("Starting data download...");
|
||||
|
||||
// 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)
|
||||
};
|
||||
|
||||
var opCodeDict = JsonConvert.DeserializeObject<Dictionary<string, ushort>>(await client.GetStringAsync(DataBaseUrl + "opcode.json"));
|
||||
this.OpCodes = new ReadOnlyDictionary<string, ushort>(opCodeDict);
|
||||
|
||||
Log.Verbose("Loaded {0} OpCodes.", opCodeDict.Count);
|
||||
|
||||
var cfcs = JsonConvert.DeserializeObject<Dictionary<uint, JObject>>(await client.GetStringAsync(DataBaseUrl + "contentfindercondition.json"));
|
||||
this.ContentFinderCondition = new ReadOnlyDictionary<uint, JObject>(cfcs);
|
||||
|
||||
Log.Verbose("Loaded {0} ContentFinderCondition.", cfcs.Count);
|
||||
|
||||
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,9 +34,9 @@ namespace Dalamud.Game.Network {
|
|||
}
|
||||
|
||||
private void OnZonePacket(IntPtr dataPtr) {
|
||||
var opCode = (ZoneOpCode) Marshal.ReadInt16(dataPtr, 2);
|
||||
var opCode = (ushort) Marshal.ReadInt16(dataPtr, 2);
|
||||
|
||||
if (opCode == ZoneOpCode.CfNotifyPop) {
|
||||
if (opCode == this.dalamud.Data.OpCodes["CfNotifyPop"]) {
|
||||
var data = new byte[64];
|
||||
Marshal.Copy(dataPtr, data, 0, 64);
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ namespace Dalamud.Game.Network {
|
|||
return;
|
||||
}
|
||||
|
||||
if (opCode == ZoneOpCode.CfPreferredRole) {
|
||||
if (opCode == this.dalamud.Data.OpCodes["CfPreferredRole"]) {
|
||||
if (this.dalamud.Configuration.PreferredRoleReminders == null)
|
||||
return;
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ namespace Dalamud.Game.Network {
|
|||
}
|
||||
|
||||
if (!this.optOutMbUploads) {
|
||||
if (opCode == ZoneOpCode.MarketBoardItemRequestStart) {
|
||||
if (opCode == this.dalamud.Data.OpCodes["MarketBoardItemRequestStart"]) {
|
||||
var catalogId = (uint) Marshal.ReadInt32(dataPtr + 0x10);
|
||||
var amount = Marshal.ReadByte(dataPtr + 0x1B);
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ namespace Dalamud.Game.Network {
|
|||
return;
|
||||
}
|
||||
|
||||
if (opCode == ZoneOpCode.MarketBoardOfferings) {
|
||||
if (opCode == this.dalamud.Data.OpCodes["MarketBoardOfferings"]) {
|
||||
var listing = MarketBoardCurrentOfferings.Read(dataPtr + 0x10);
|
||||
|
||||
var request =
|
||||
|
|
@ -185,7 +185,7 @@ namespace Dalamud.Game.Network {
|
|||
return;
|
||||
}
|
||||
|
||||
if (opCode == ZoneOpCode.MarketBoardHistory) {
|
||||
if (opCode == this.dalamud.Data.OpCodes["MarketBoardHistory"]) {
|
||||
var listing = MarketBoardHistory.Read(dataPtr + 0x10);
|
||||
|
||||
var request = this.marketBoardRequests.LastOrDefault(r => r.CatalogId == listing.CatalogId);
|
||||
|
|
@ -207,7 +207,7 @@ namespace Dalamud.Game.Network {
|
|||
Log.Verbose("Added history for item#{0}", listing.CatalogId);
|
||||
}
|
||||
|
||||
if (opCode == ZoneOpCode.MarketTaxRates)
|
||||
if (opCode == this.dalamud.Data.OpCodes["MarketTaxRates"])
|
||||
{
|
||||
var taxes = MarketTaxRates.Read(dataPtr + 0x10);
|
||||
|
||||
|
|
@ -225,15 +225,6 @@ namespace Dalamud.Game.Network {
|
|||
}
|
||||
}
|
||||
|
||||
private enum ZoneOpCode {
|
||||
CfNotifyPop = 0x1F8,
|
||||
CfPreferredRole = 0x32A,
|
||||
MarketTaxRates = 0x25E,
|
||||
MarketBoardItemRequestStart = 0x328,
|
||||
MarketBoardOfferings = 0x15F,
|
||||
MarketBoardHistory = 0x113
|
||||
}
|
||||
|
||||
private DalamudConfiguration.PreferredRole RoleKeyToPreferredRole(int key) => key switch
|
||||
{
|
||||
1 => DalamudConfiguration.PreferredRole.Tank,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue