adjust to send only one packet for all changes at once
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Factories;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
{
|
||||
@@ -11,28 +10,30 @@ namespace MareSynchronos.Models
|
||||
public class CharacterData
|
||||
{
|
||||
[JsonProperty]
|
||||
public ObjectKind Kind { get; set; }
|
||||
public List<FileReplacement> FileReplacements { get; set; } = new();
|
||||
public Dictionary<ObjectKind, List<FileReplacement>> FileReplacements { get; set; } = new();
|
||||
|
||||
[JsonProperty]
|
||||
public string GlamourerString { get; set; } = string.Empty;
|
||||
public Dictionary<ObjectKind, string> GlamourerString { get; set; } = new();
|
||||
|
||||
public bool IsReady => FileReplacements.All(f => f.Computed);
|
||||
public bool IsReady => FileReplacements.SelectMany(k => k.Value).All(f => f.Computed);
|
||||
|
||||
[JsonProperty]
|
||||
public string ManipulationString { get; set; } = string.Empty;
|
||||
|
||||
public void AddFileReplacement(FileReplacement fileReplacement)
|
||||
public void AddFileReplacement(ObjectKind objectKind, FileReplacement fileReplacement)
|
||||
{
|
||||
if (!fileReplacement.HasFileReplacement) return;
|
||||
|
||||
var existingReplacement = FileReplacements.SingleOrDefault(f => f.ResolvedPath == fileReplacement.ResolvedPath);
|
||||
if (!FileReplacements.ContainsKey(objectKind)) FileReplacements.Add(objectKind, new List<FileReplacement>());
|
||||
|
||||
var existingReplacement = FileReplacements[objectKind].SingleOrDefault(f => f.ResolvedPath == fileReplacement.ResolvedPath);
|
||||
if (existingReplacement != null)
|
||||
{
|
||||
existingReplacement.GamePaths.AddRange(fileReplacement.GamePaths.Where(e => !existingReplacement.GamePaths.Contains(e)));
|
||||
}
|
||||
else
|
||||
{
|
||||
FileReplacements.Add(fileReplacement);
|
||||
FileReplacements[objectKind].Add(fileReplacement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,15 +41,14 @@ namespace MareSynchronos.Models
|
||||
{
|
||||
return new CharacterCacheDto()
|
||||
{
|
||||
ObjectKind = Kind,
|
||||
FileReplacements = FileReplacements.Where(f => f.HasFileReplacement).GroupBy(f => f.Hash).Select(g =>
|
||||
FileReplacements = FileReplacements.ToDictionary(k => k.Key, k => k.Value.Where(f => f.HasFileReplacement).GroupBy(f => f.Hash).Select(g =>
|
||||
{
|
||||
return new FileReplacementDto()
|
||||
{
|
||||
GamePaths = g.SelectMany(g => g.GamePaths).Distinct().ToArray(),
|
||||
Hash = g.First().Hash
|
||||
};
|
||||
}).ToList(),
|
||||
}).ToList()),
|
||||
GlamourerData = GlamourerString,
|
||||
ManipulationData = ManipulationString
|
||||
};
|
||||
@@ -57,7 +57,7 @@ namespace MareSynchronos.Models
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
foreach (var fileReplacement in FileReplacements.OrderBy(a => a.GamePaths[0]))
|
||||
foreach (var fileReplacement in FileReplacements.SelectMany(k => k.Value).OrderBy(a => a.GamePaths[0]))
|
||||
{
|
||||
stringBuilder.AppendLine(fileReplacement.ToString());
|
||||
}
|
||||
|
||||
@@ -2,33 +2,76 @@
|
||||
using MareSynchronos.API;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||
using System.Runtime.InteropServices;
|
||||
using MareSynchronos.Utils;
|
||||
using Penumbra.GameData.ByteString;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
{
|
||||
internal class PlayerAttachedObject
|
||||
internal class PlayerOrRelatedObject
|
||||
{
|
||||
private readonly Func<IntPtr> getAddress;
|
||||
|
||||
public unsafe Character* Character => (Character*)Address;
|
||||
|
||||
private string _name;
|
||||
|
||||
public ObjectKind ObjectKind { get; }
|
||||
public IntPtr Address { get; set; }
|
||||
public IntPtr DrawObjectAddress { get; set; }
|
||||
|
||||
public IntPtr CurrentAddress => getAddress.Invoke();
|
||||
private IntPtr CurrentAddress => getAddress.Invoke();
|
||||
|
||||
public PlayerAttachedObject(ObjectKind objectKind, IntPtr address, IntPtr drawObjectAddress, Func<IntPtr> getAddress)
|
||||
public PlayerOrRelatedObject(ObjectKind objectKind, IntPtr address, IntPtr drawObjectAddress, Func<IntPtr> getAddress)
|
||||
{
|
||||
ObjectKind = objectKind;
|
||||
Address = address;
|
||||
DrawObjectAddress = drawObjectAddress;
|
||||
this.getAddress = getAddress;
|
||||
_name = string.Empty;
|
||||
}
|
||||
|
||||
public byte[] EquipSlotData { get; set; } = new byte[40];
|
||||
public byte[] CustomizeData { get; set; } = new byte[26];
|
||||
|
||||
public unsafe bool CompareAndUpdateEquipment(byte* equipSlotData, byte* customizeData)
|
||||
public bool HasUnprocessedUpdate { get; set; } = false;
|
||||
public bool IsProcessing { get; set; } = false;
|
||||
|
||||
public unsafe void CheckAndUpdateObject()
|
||||
{
|
||||
var curPtr = CurrentAddress;
|
||||
if (curPtr != IntPtr.Zero)
|
||||
{
|
||||
var chara = (Character*)curPtr;
|
||||
bool addr = Address == IntPtr.Zero || Address != curPtr;
|
||||
bool equip = CompareAndUpdateByteData(chara->EquipSlotData, chara->CustomizeData);
|
||||
bool drawObj = (chara->GameObject.DrawObject != null && (IntPtr)chara->GameObject.DrawObject != DrawObjectAddress);
|
||||
var name = new Utf8String(chara->GameObject.Name).ToString();
|
||||
bool nameChange = (name != _name);
|
||||
if (addr || equip || drawObj || nameChange)
|
||||
{
|
||||
_name = name;
|
||||
Logger.Verbose(ObjectKind + " Changed: " + _name + ", now: " + curPtr + ", " + (IntPtr)chara->GameObject.DrawObject);
|
||||
|
||||
Address = curPtr;
|
||||
DrawObjectAddress = (IntPtr)chara->GameObject.DrawObject;
|
||||
HasUnprocessedUpdate = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Address != IntPtr.Zero || DrawObjectAddress != IntPtr.Zero)
|
||||
{
|
||||
Address = IntPtr.Zero;
|
||||
DrawObjectAddress = IntPtr.Zero;
|
||||
HasUnprocessedUpdate = true;
|
||||
}
|
||||
|
||||
Address = IntPtr.Zero;
|
||||
DrawObjectAddress = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe bool CompareAndUpdateByteData(byte* equipSlotData, byte* customizeData)
|
||||
{
|
||||
bool hasChanges = false;
|
||||
for (int i = 0; i < EquipSlotData.Length; i++)
|
||||
|
||||
Reference in New Issue
Block a user