somewhat working integration of penumbra
This commit is contained in:
106
MareSynchronos/Factories/CharacterCacheFactory.cs
Normal file
106
MareSynchronos/Factories/CharacterCacheFactory.cs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Dalamud.Game.ClientState;
|
||||||
|
using Dalamud.Logging;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.System.Resource;
|
||||||
|
using MareSynchronos.Managers;
|
||||||
|
using MareSynchronos.Models;
|
||||||
|
using Penumbra.GameData.ByteString;
|
||||||
|
using Penumbra.Interop.Structs;
|
||||||
|
|
||||||
|
namespace MareSynchronos.Factories
|
||||||
|
{
|
||||||
|
public class CharacterCacheFactory
|
||||||
|
{
|
||||||
|
private readonly ClientState _clientState;
|
||||||
|
private readonly IpcManager _ipcManager;
|
||||||
|
private readonly FileReplacementFactory _factory;
|
||||||
|
|
||||||
|
public CharacterCacheFactory(ClientState clientState, IpcManager ipcManager, FileReplacementFactory factory)
|
||||||
|
{
|
||||||
|
_clientState = clientState;
|
||||||
|
_ipcManager = ipcManager;
|
||||||
|
_factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetPlayerName()
|
||||||
|
{
|
||||||
|
return _clientState.LocalPlayer!.Name.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe CharacterCache BuildCharacterCache()
|
||||||
|
{
|
||||||
|
var cache = new CharacterCache();
|
||||||
|
|
||||||
|
while (_clientState.LocalPlayer == null)
|
||||||
|
{
|
||||||
|
PluginLog.Debug("Character is null but it shouldn't be, waiting");
|
||||||
|
Thread.Sleep(50);
|
||||||
|
}
|
||||||
|
var model = (CharacterBase*)((Character*)_clientState.LocalPlayer!.Address)->GameObject.GetDrawObject();
|
||||||
|
for (var idx = 0; idx < model->SlotCount; ++idx)
|
||||||
|
{
|
||||||
|
var mdl = (RenderModel*)model->ModelArray[idx];
|
||||||
|
if (mdl == null || mdl->ResourceHandle == null || mdl->ResourceHandle->Category != ResourceCategory.Chara)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var mdlPath = new Utf8String(mdl->ResourceHandle->FileName()).ToString();
|
||||||
|
|
||||||
|
FileReplacement cachedMdlResource = _factory.Create();
|
||||||
|
cachedMdlResource.GamePaths = _ipcManager.PenumbraReverseResolvePath(mdlPath, GetPlayerName());
|
||||||
|
cachedMdlResource.SetResolvedPath(mdlPath);
|
||||||
|
//PluginLog.Verbose("Resolving for model " + mdlPath);
|
||||||
|
|
||||||
|
cache.AddAssociatedResource(cachedMdlResource, null!, null!);
|
||||||
|
|
||||||
|
for (int mtrlIdx = 0; mtrlIdx < mdl->MaterialCount; mtrlIdx++)
|
||||||
|
{
|
||||||
|
var mtrl = (Material*)mdl->Materials[mtrlIdx];
|
||||||
|
if (mtrl == null) continue;
|
||||||
|
|
||||||
|
//var mtrlFileResource = factory.Create();
|
||||||
|
var mtrlPath = new Utf8String(mtrl->ResourceHandle->FileName()).ToString().Split("|")[2];
|
||||||
|
//PluginLog.Verbose("Resolving for material " + mtrlPath);
|
||||||
|
var cachedMtrlResource = _factory.Create();
|
||||||
|
cachedMtrlResource.GamePaths = _ipcManager.PenumbraReverseResolvePath(mtrlPath, GetPlayerName());
|
||||||
|
cachedMtrlResource.SetResolvedPath(mtrlPath);
|
||||||
|
cache.AddAssociatedResource(cachedMtrlResource, cachedMdlResource, null!);
|
||||||
|
|
||||||
|
var mtrlResource = (MtrlResource*)mtrl->ResourceHandle;
|
||||||
|
for (int resIdx = 0; resIdx < mtrlResource->NumTex; resIdx++)
|
||||||
|
{
|
||||||
|
var texPath = new Utf8String(mtrlResource->TexString(resIdx)).ToString();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(texPath.ToString())) continue;
|
||||||
|
|
||||||
|
var cachedTexResource = _factory.Create();
|
||||||
|
cachedTexResource.GamePaths = new[] { texPath };
|
||||||
|
cachedTexResource.SetResolvedPath(_ipcManager.PenumbraResolvePath(texPath, GetPlayerName())!);
|
||||||
|
if (!cachedTexResource.HasFileReplacement)
|
||||||
|
{
|
||||||
|
// try resolving tex with -- in name instead
|
||||||
|
texPath = texPath.Insert(texPath.LastIndexOf('/') + 1, "--");
|
||||||
|
var reResolvedPath = _ipcManager.PenumbraResolvePath(texPath, GetPlayerName())!;
|
||||||
|
if (reResolvedPath != texPath)
|
||||||
|
{
|
||||||
|
cachedTexResource.GamePaths = new[] { texPath };
|
||||||
|
cachedTexResource.SetResolvedPath(reResolvedPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cache.AddAssociatedResource(cachedTexResource, cachedMdlResource, cachedMtrlResource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,144 +2,67 @@
|
|||||||
using Dalamud.Game.ClientState;
|
using Dalamud.Game.ClientState;
|
||||||
using Dalamud.Game.ClientState.Objects;
|
using Dalamud.Game.ClientState.Objects;
|
||||||
using Dalamud.Logging;
|
using Dalamud.Logging;
|
||||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
|
||||||
using FFXIVClientStructs.FFXIV.Client.Game.Object;
|
using FFXIVClientStructs.FFXIV.Client.Game.Object;
|
||||||
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
|
|
||||||
using FFXIVClientStructs.FFXIV.Client.System.Resource;
|
|
||||||
using MareSynchronos.Factories;
|
using MareSynchronos.Factories;
|
||||||
using MareSynchronos.Models;
|
using MareSynchronos.Models;
|
||||||
using MareSynchronos.Utils;
|
using MareSynchronos.Utils;
|
||||||
using MareSynchronos.WebAPI;
|
using MareSynchronos.WebAPI;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Penumbra.GameData.ByteString;
|
|
||||||
using Penumbra.Interop.Structs;
|
|
||||||
using Penumbra.PlayerWatch;
|
using Penumbra.PlayerWatch;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dalamud.Configuration;
|
|
||||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||||
using MareSynchronos.API;
|
using MareSynchronos.API;
|
||||||
using MareSynchronos.FileCacheDB;
|
using MareSynchronos.FileCacheDB;
|
||||||
|
|
||||||
namespace MareSynchronos.Managers
|
namespace MareSynchronos.Managers
|
||||||
{
|
{
|
||||||
|
public class CachedPlayer
|
||||||
|
{
|
||||||
|
public string? PlayerName { get; set; }
|
||||||
|
public string? PlayerNameHash { get; set; }
|
||||||
|
public int JobId { get; set; }
|
||||||
|
public Dictionary<int, CharacterCacheDto>? CharacterCache { get; set; }
|
||||||
|
public PlayerCharacter? PlayerCharacter { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class CharacterManager : IDisposable
|
public class CharacterManager : IDisposable
|
||||||
{
|
{
|
||||||
private readonly ApiController _apiController;
|
private readonly ApiController _apiController;
|
||||||
readonly Dictionary<string, string> _cachedLocalPlayers = new();
|
readonly Dictionary<string, string> _cachedLocalPlayers = new();
|
||||||
private readonly Dictionary<(string, int), CharacterCacheDto> _characterCache = new();
|
private readonly Dictionary<(string, int), CharacterCacheDto> _characterCache = new();
|
||||||
private readonly ClientState _clientState;
|
private readonly ClientState _clientState;
|
||||||
private readonly FileReplacementFactory _factory;
|
|
||||||
private readonly Framework _framework;
|
private readonly Framework _framework;
|
||||||
private readonly IpcManager _ipcManager;
|
private readonly IpcManager _ipcManager;
|
||||||
private readonly ObjectTable _objectTable;
|
private readonly ObjectTable _objectTable;
|
||||||
private readonly Configuration _pluginConfiguration;
|
private readonly Configuration _pluginConfiguration;
|
||||||
|
private readonly CharacterCacheFactory _characterCacheFactory;
|
||||||
private readonly IPlayerWatcher _watcher;
|
private readonly IPlayerWatcher _watcher;
|
||||||
private DateTime _lastPlayerObjectCheck = DateTime.Now;
|
private DateTime _lastPlayerObjectCheck = DateTime.Now;
|
||||||
private string _lastSentHash = string.Empty;
|
private string _lastSentHash = string.Empty;
|
||||||
private Task? _playerChangedTask = null;
|
private Task? _playerChangedTask = null;
|
||||||
|
|
||||||
private HashSet<string> _onlinePairedUsers = new();
|
private List<CachedPlayer> _onlineCachedPlayers = new();
|
||||||
|
|
||||||
public CharacterManager(ClientState clientState, Framework framework, ApiController apiController, ObjectTable objectTable, IpcManager ipcManager, FileReplacementFactory factory,
|
private Dictionary<string, string> _onlinePairedUsers = new();
|
||||||
Configuration pluginConfiguration)
|
|
||||||
|
public CharacterManager(ClientState clientState, Framework framework, ApiController apiController, ObjectTable objectTable, IpcManager ipcManager,
|
||||||
|
Configuration pluginConfiguration, CharacterCacheFactory characterCacheFactory)
|
||||||
{
|
{
|
||||||
this._clientState = clientState;
|
this._clientState = clientState;
|
||||||
this._framework = framework;
|
this._framework = framework;
|
||||||
this._apiController = apiController;
|
this._apiController = apiController;
|
||||||
this._objectTable = objectTable;
|
this._objectTable = objectTable;
|
||||||
this._ipcManager = ipcManager;
|
this._ipcManager = ipcManager;
|
||||||
this._factory = factory;
|
|
||||||
_pluginConfiguration = pluginConfiguration;
|
_pluginConfiguration = pluginConfiguration;
|
||||||
|
_characterCacheFactory = characterCacheFactory;
|
||||||
_watcher = PlayerWatchFactory.Create(framework, clientState, objectTable);
|
_watcher = PlayerWatchFactory.Create(framework, clientState, objectTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe CharacterCache BuildCharacterCache()
|
|
||||||
{
|
|
||||||
var cache = new CharacterCache();
|
|
||||||
|
|
||||||
while (_clientState.LocalPlayer == null)
|
|
||||||
{
|
|
||||||
PluginLog.Debug("Character is null but it shouldn't be, waiting");
|
|
||||||
Thread.Sleep(50);
|
|
||||||
}
|
|
||||||
var model = (CharacterBase*)((Character*)_clientState.LocalPlayer!.Address)->GameObject.GetDrawObject();
|
|
||||||
for (var idx = 0; idx < model->SlotCount; ++idx)
|
|
||||||
{
|
|
||||||
var mdl = (RenderModel*)model->ModelArray[idx];
|
|
||||||
if (mdl == null || mdl->ResourceHandle == null || mdl->ResourceHandle->Category != ResourceCategory.Chara)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var mdlPath = new Utf8String(mdl->ResourceHandle->FileName()).ToString();
|
|
||||||
|
|
||||||
FileReplacement cachedMdlResource = _factory.Create();
|
|
||||||
cachedMdlResource.GamePaths = _ipcManager.PenumbraReverseResolvePath(mdlPath, GetPlayerName());
|
|
||||||
cachedMdlResource.SetResolvedPath(mdlPath);
|
|
||||||
PluginLog.Verbose("Resolving for model " + mdlPath);
|
|
||||||
|
|
||||||
cache.AddAssociatedResource(cachedMdlResource, null!, null!);
|
|
||||||
|
|
||||||
var imc = (ResourceHandle*)model->IMCArray[idx];
|
|
||||||
if (imc != null)
|
|
||||||
{
|
|
||||||
byte[] imcData = new byte[imc->Data->DataLength / sizeof(long)];
|
|
||||||
Marshal.Copy((IntPtr)imc->Data->DataPtr, imcData, 0, (int)imc->Data->DataLength / sizeof(long));
|
|
||||||
string imcDataStr = BitConverter.ToString(imcData).Replace("-", "");
|
|
||||||
cachedMdlResource.ImcData = imcDataStr;
|
|
||||||
}
|
|
||||||
cache.AddAssociatedResource(cachedMdlResource, null!, null!);
|
|
||||||
|
|
||||||
for (int mtrlIdx = 0; mtrlIdx < mdl->MaterialCount; mtrlIdx++)
|
|
||||||
{
|
|
||||||
var mtrl = (Material*)mdl->Materials[mtrlIdx];
|
|
||||||
if (mtrl == null) continue;
|
|
||||||
|
|
||||||
//var mtrlFileResource = factory.Create();
|
|
||||||
var mtrlPath = new Utf8String(mtrl->ResourceHandle->FileName()).ToString().Split("|")[2];
|
|
||||||
PluginLog.Verbose("Resolving for material " + mtrlPath);
|
|
||||||
var cachedMtrlResource = _factory.Create();
|
|
||||||
cachedMtrlResource.GamePaths = _ipcManager.PenumbraReverseResolvePath(mtrlPath, GetPlayerName());
|
|
||||||
cachedMtrlResource.SetResolvedPath(mtrlPath);
|
|
||||||
cache.AddAssociatedResource(cachedMtrlResource, cachedMdlResource, null!);
|
|
||||||
|
|
||||||
var mtrlResource = (MtrlResource*)mtrl->ResourceHandle;
|
|
||||||
for (int resIdx = 0; resIdx < mtrlResource->NumTex; resIdx++)
|
|
||||||
{
|
|
||||||
var texPath = new Utf8String(mtrlResource->TexString(resIdx)).ToString();
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(texPath.ToString())) continue;
|
|
||||||
PluginLog.Verbose("Resolving for texture " + texPath);
|
|
||||||
|
|
||||||
var cachedTexResource = _factory.Create();
|
|
||||||
cachedTexResource.GamePaths = new[] { texPath };
|
|
||||||
cachedTexResource.SetResolvedPath(_ipcManager.PenumbraResolvePath(texPath, GetPlayerName())!);
|
|
||||||
cache.AddAssociatedResource(cachedTexResource, cachedMdlResource, cachedMtrlResource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task DebugJson()
|
|
||||||
{
|
|
||||||
var cache = CreateFullCharacterCache();
|
|
||||||
while (!cache.IsCompleted)
|
|
||||||
{
|
|
||||||
await Task.Delay(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginLog.Debug(JsonConvert.SerializeObject(cache.Result, Formatting.Indented));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_ipcManager.PenumbraRedrawEvent -= IpcManager_PenumbraRedrawEvent;
|
_ipcManager.PenumbraRedrawEvent -= IpcManager_PenumbraRedrawEvent;
|
||||||
@@ -161,15 +84,10 @@ namespace MareSynchronos.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopWatchPlayer(string name)
|
|
||||||
{
|
|
||||||
_watcher.RemovePlayerFromWatch(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpdatePlayersFromService(Dictionary<string, PlayerCharacter> currentLocalPlayers)
|
public async Task UpdatePlayersFromService(Dictionary<string, PlayerCharacter> currentLocalPlayers)
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Updating local players from service");
|
PluginLog.Debug("Updating local players from service");
|
||||||
currentLocalPlayers = currentLocalPlayers.Where(k => _onlinePairedUsers.Contains(k.Key))
|
currentLocalPlayers = currentLocalPlayers.Where(k => _onlinePairedUsers.ContainsKey(k.Key))
|
||||||
.ToDictionary(k => k.Key, k => k.Value);
|
.ToDictionary(k => k.Key, k => k.Value);
|
||||||
await _apiController.GetCharacterData(currentLocalPlayers
|
await _apiController.GetCharacterData(currentLocalPlayers
|
||||||
.ToDictionary(
|
.ToDictionary(
|
||||||
@@ -177,11 +95,6 @@ namespace MareSynchronos.Managers
|
|||||||
k => (int)k.Value.ClassJob.Id));
|
k => (int)k.Value.ClassJob.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WatchPlayer(string name)
|
|
||||||
{
|
|
||||||
_watcher.AddPlayerToWatch(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void StartWatchingPlayer()
|
internal void StartWatchingPlayer()
|
||||||
{
|
{
|
||||||
_watcher.AddPlayerToWatch(GetPlayerName());
|
_watcher.AddPlayerToWatch(GetPlayerName());
|
||||||
@@ -206,11 +119,12 @@ namespace MareSynchronos.Managers
|
|||||||
{
|
{
|
||||||
PluginLog.Debug(nameof(ApiController_Connected));
|
PluginLog.Debug(nameof(ApiController_Connected));
|
||||||
PluginLog.Debug("MyHashedName:" + Crypto.GetHash256(GetPlayerName() + _clientState.LocalPlayer!.HomeWorld.Id));
|
PluginLog.Debug("MyHashedName:" + Crypto.GetHash256(GetPlayerName() + _clientState.LocalPlayer!.HomeWorld.Id));
|
||||||
|
_lastSentHash = string.Empty;
|
||||||
var apiTask = _apiController.SendCharacterName(Crypto.GetHash256(GetPlayerName() + _clientState.LocalPlayer!.HomeWorld.Id));
|
var apiTask = _apiController.SendCharacterName(Crypto.GetHash256(GetPlayerName() + _clientState.LocalPlayer!.HomeWorld.Id));
|
||||||
|
|
||||||
Task.WaitAll(apiTask);
|
Task.WaitAll(apiTask);
|
||||||
|
|
||||||
_onlinePairedUsers = new HashSet<string>(apiTask.Result);
|
_onlinePairedUsers = apiTask.Result.ToDictionary(k => k, k => string.Empty);
|
||||||
var assignTask = AssignLocalPlayersData();
|
var assignTask = AssignLocalPlayersData();
|
||||||
Task.WaitAll(assignTask);
|
Task.WaitAll(assignTask);
|
||||||
PluginLog.Debug("Online and paired users: " + string.Join(",", _onlinePairedUsers));
|
PluginLog.Debug("Online and paired users: " + string.Join(",", _onlinePairedUsers));
|
||||||
@@ -230,6 +144,7 @@ namespace MareSynchronos.Managers
|
|||||||
{
|
{
|
||||||
RestoreCharacter(character);
|
RestoreCharacter(character);
|
||||||
}
|
}
|
||||||
|
_onlinePairedUsers.Clear();
|
||||||
|
|
||||||
_lastSentHash = string.Empty;
|
_lastSentHash = string.Empty;
|
||||||
}
|
}
|
||||||
@@ -248,35 +163,21 @@ namespace MareSynchronos.Managers
|
|||||||
|
|
||||||
private void ApiControllerOnCharacterReceived(object? sender, CharacterReceivedEventArgs e)
|
private void ApiControllerOnCharacterReceived(object? sender, CharacterReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
PlayerCharacter? playerObject = null;
|
|
||||||
PluginLog.Debug("Received hash for " + e.CharacterNameHash);
|
PluginLog.Debug("Received hash for " + e.CharacterNameHash);
|
||||||
foreach (var obj in _objectTable)
|
string otherPlayerName;
|
||||||
{
|
|
||||||
if (obj.ObjectKind != Dalamud.Game.ClientState.Objects.Enums.ObjectKind.Player) continue;
|
|
||||||
string playerName = obj.Name.ToString();
|
|
||||||
if (playerName == GetPlayerName()) continue;
|
|
||||||
playerObject = (PlayerCharacter)obj;
|
|
||||||
var hashedName = Crypto.GetHash256(playerObject.Name.ToString() + playerObject.HomeWorld.Id.ToString());
|
|
||||||
if (e.CharacterNameHash == hashedName)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
playerObject = null;
|
var localPlayers = GetLocalPlayers();
|
||||||
}
|
if (localPlayers.ContainsKey(e.CharacterNameHash))
|
||||||
|
|
||||||
if (playerObject == null)
|
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Found no suitable hash for " + e.CharacterNameHash);
|
_onlinePairedUsers[e.CharacterNameHash] = localPlayers[e.CharacterNameHash].Name.ToString();
|
||||||
return;
|
otherPlayerName = _onlinePairedUsers[e.CharacterNameHash];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Found suitable player for hash: " + playerObject.Name.ToString());
|
PluginLog.Debug("Found no local player for " + e.CharacterNameHash);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var otherPlayerName = playerObject.Name.ToString();
|
|
||||||
|
|
||||||
_characterCache[(e.CharacterNameHash, e.CharacterData.JobId)] = e.CharacterData;
|
_characterCache[(e.CharacterNameHash, e.CharacterData.JobId)] = e.CharacterData;
|
||||||
|
|
||||||
List<FileReplacementDto> toDownloadReplacements;
|
List<FileReplacementDto> toDownloadReplacements;
|
||||||
@@ -291,6 +192,7 @@ namespace MareSynchronos.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
PluginLog.Debug("Downloading missing files for player " + otherPlayerName);
|
PluginLog.Debug("Downloading missing files for player " + otherPlayerName);
|
||||||
|
// todo: make this cancellable
|
||||||
var downloadTask = _apiController.DownloadFiles(toDownloadReplacements, _pluginConfiguration.CacheFolder);
|
var downloadTask = _apiController.DownloadFiles(toDownloadReplacements, _pluginConfiguration.CacheFolder);
|
||||||
while (!downloadTask.IsCompleted)
|
while (!downloadTask.IsCompleted)
|
||||||
{
|
{
|
||||||
@@ -299,10 +201,11 @@ namespace MareSynchronos.Managers
|
|||||||
|
|
||||||
PluginLog.Debug("Assigned hash to visible player: " + otherPlayerName);
|
PluginLog.Debug("Assigned hash to visible player: " + otherPlayerName);
|
||||||
_ipcManager.PenumbraRemoveTemporaryCollection(otherPlayerName);
|
_ipcManager.PenumbraRemoveTemporaryCollection(otherPlayerName);
|
||||||
_ipcManager.PenumbraCreateTemporaryCollection(otherPlayerName);
|
var tempCollection = _ipcManager.PenumbraCreateTemporaryCollection(otherPlayerName);
|
||||||
Dictionary<string, string> moddedPaths = new();
|
Dictionary<string, string> moddedPaths = new();
|
||||||
using (var db = new FileCacheContext())
|
try
|
||||||
{
|
{
|
||||||
|
using var db = new FileCacheContext();
|
||||||
foreach (var item in e.CharacterData.FileReplacements)
|
foreach (var item in e.CharacterData.FileReplacements)
|
||||||
{
|
{
|
||||||
foreach (var gamePath in item.GamePaths)
|
foreach (var gamePath in item.GamePaths)
|
||||||
@@ -310,44 +213,42 @@ namespace MareSynchronos.Managers
|
|||||||
var fileCache = db.FileCaches.FirstOrDefault(f => f.Hash == item.Hash);
|
var fileCache = db.FileCaches.FirstOrDefault(f => f.Hash == item.Hash);
|
||||||
if (fileCache != null)
|
if (fileCache != null)
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Modifying: " + gamePath + " => " + fileCache.Filepath);
|
|
||||||
moddedPaths.Add(gamePath, fileCache.Filepath);
|
moddedPaths.Add(gamePath, fileCache.Filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginLog.Error(ex, "Something went wrong during calculation replacements");
|
||||||
|
}
|
||||||
|
|
||||||
_ipcManager.PenumbraSetTemporaryMods(otherPlayerName, moddedPaths);
|
WaitWhileCharacterIsDrawing(localPlayers[e.CharacterNameHash].Address);
|
||||||
|
|
||||||
|
_ipcManager.PenumbraSetTemporaryMods(tempCollection, moddedPaths, e.CharacterData.ManipulationData);
|
||||||
_ipcManager.GlamourerApplyCharacterCustomization(e.CharacterData.GlamourerData, otherPlayerName);
|
_ipcManager.GlamourerApplyCharacterCustomization(e.CharacterData.GlamourerData, otherPlayerName);
|
||||||
_ipcManager.PenumbraRedraw(otherPlayerName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApiControllerOnUnpairedFromOther(object? sender, EventArgs e)
|
private void ApiControllerOnUnpairedFromOther(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var characterHash = (string?)sender;
|
var characterHash = (string?)sender;
|
||||||
if (string.IsNullOrEmpty(characterHash)) return;
|
if (string.IsNullOrEmpty(characterHash)) return;
|
||||||
RestoreCharacter(characterHash);
|
RestoreCharacter(new KeyValuePair<string, string>(characterHash, _onlinePairedUsers[characterHash]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RestoreCharacter(string characterHash)
|
private void RestoreCharacter(KeyValuePair<string, string> character)
|
||||||
{
|
{
|
||||||
var players = GetLocalPlayers();
|
if (string.IsNullOrEmpty(character.Value)) return;
|
||||||
|
|
||||||
foreach (var entry in _characterCache.Where(c => c.Key.Item1 == characterHash))
|
foreach (var entry in _characterCache.Where(c => c.Key.Item1 == character.Key))
|
||||||
{
|
{
|
||||||
_characterCache.Remove(entry.Key);
|
_characterCache.Remove(entry.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var player in players)
|
RestorePreviousCharacter(character.Value);
|
||||||
{
|
PluginLog.Debug("Removed from pairing, restoring state for " + character.Value);
|
||||||
if (player.Key != characterHash) continue;
|
_ipcManager.PenumbraRemoveTemporaryCollection(character.Value);
|
||||||
var playerName = player.Value.Name.ToString();
|
_ipcManager.GlamourerRevertCharacterCustomization(character.Value);
|
||||||
RestorePreviousCharacter(playerName);
|
|
||||||
PluginLog.Debug("Removed from pairing, restoring glamourer state for " + playerName);
|
|
||||||
_ipcManager.PenumbraRemoveTemporaryCollection(playerName);
|
|
||||||
_ipcManager.GlamourerRevertCharacterCustomization(playerName);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApiControllerOnPairedClientOffline(object? sender, EventArgs e)
|
private void ApiControllerOnPairedClientOffline(object? sender, EventArgs e)
|
||||||
@@ -359,7 +260,7 @@ namespace MareSynchronos.Managers
|
|||||||
private void ApiControllerOnPairedClientOnline(object? sender, EventArgs e)
|
private void ApiControllerOnPairedClientOnline(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Player online: " + sender!);
|
PluginLog.Debug("Player online: " + sender!);
|
||||||
_onlinePairedUsers.Add((string)sender!);
|
_onlinePairedUsers.Add((string)sender!, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AssignLocalPlayersData()
|
private async Task AssignLocalPlayersData()
|
||||||
@@ -392,8 +293,9 @@ namespace MareSynchronos.Managers
|
|||||||
|
|
||||||
private async Task<CharacterCache> CreateFullCharacterCache()
|
private async Task<CharacterCache> CreateFullCharacterCache()
|
||||||
{
|
{
|
||||||
var cache = BuildCharacterCache();
|
var cache = _characterCacheFactory.BuildCharacterCache();
|
||||||
cache.SetGlamourerData(_ipcManager.GlamourerGetCharacterCustomization()!);
|
cache.GlamourerString = _ipcManager.GlamourerGetCharacterCustomization()!;
|
||||||
|
cache.ManipulationString = _ipcManager.PenumbraGetMetaManipulations(_clientState.LocalPlayer!.Name.ToString());
|
||||||
cache.JobId = _clientState.LocalPlayer!.ClassJob.Id;
|
cache.JobId = _clientState.LocalPlayer!.ClassJob.Id;
|
||||||
await Task.Run(async () =>
|
await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
@@ -428,8 +330,9 @@ namespace MareSynchronos.Managers
|
|||||||
var pObj = (PlayerCharacter)obj;
|
var pObj = (PlayerCharacter)obj;
|
||||||
var hashedName = Crypto.GetHash256(pObj.Name.ToString() + pObj.HomeWorld.Id.ToString());
|
var hashedName = Crypto.GetHash256(pObj.Name.ToString() + pObj.HomeWorld.Id.ToString());
|
||||||
|
|
||||||
if (!_onlinePairedUsers.Contains(hashedName)) continue;
|
if (!_onlinePairedUsers.ContainsKey(hashedName)) continue;
|
||||||
|
|
||||||
|
_onlinePairedUsers[hashedName] = pObj.Name.ToString();
|
||||||
localPlayersList.Add(hashedName);
|
localPlayersList.Add(hashedName);
|
||||||
if (!_cachedLocalPlayers.ContainsKey(hashedName)) newPlayers[hashedName] = pObj;
|
if (!_cachedLocalPlayers.ContainsKey(hashedName)) newPlayers[hashedName] = pObj;
|
||||||
_cachedLocalPlayers[hashedName] = pObj.Name.ToString();
|
_cachedLocalPlayers[hashedName] = pObj.Name.ToString();
|
||||||
@@ -493,6 +396,7 @@ namespace MareSynchronos.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void PlayerChanged(string name)
|
private unsafe void PlayerChanged(string name)
|
||||||
{
|
{
|
||||||
//if (sender == null) return;
|
//if (sender == null) return;
|
||||||
@@ -505,18 +409,7 @@ namespace MareSynchronos.Managers
|
|||||||
|
|
||||||
_playerChangedTask = Task.Run(() =>
|
_playerChangedTask = Task.Run(() =>
|
||||||
{
|
{
|
||||||
var obj = (GameObject*)_clientState.LocalPlayer!.Address;
|
WaitWhileCharacterIsDrawing(_clientState.LocalPlayer!.Address);
|
||||||
|
|
||||||
PluginLog.Debug("Waiting for charater to be drawn");
|
|
||||||
while ((obj->RenderFlags & 0b100000000000) == 0b100000000000) // 0b100000000000 is "still rendering" or something
|
|
||||||
{
|
|
||||||
//PluginLog.Debug("Waiting for character to finish drawing");
|
|
||||||
Thread.Sleep(10);
|
|
||||||
}
|
|
||||||
PluginLog.Debug("Character finished drawing");
|
|
||||||
|
|
||||||
// wait half a second just in case
|
|
||||||
Thread.Sleep(500);
|
|
||||||
|
|
||||||
var characterCacheTask = CreateFullCharacterCache();
|
var characterCacheTask = CreateFullCharacterCache();
|
||||||
Task.WaitAll(characterCacheTask);
|
Task.WaitAll(characterCacheTask);
|
||||||
@@ -532,6 +425,20 @@ namespace MareSynchronos.Managers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public unsafe void WaitWhileCharacterIsDrawing(IntPtr characterAddress)
|
||||||
|
{
|
||||||
|
var obj = (GameObject*)characterAddress;
|
||||||
|
|
||||||
|
while ((obj->RenderFlags & 0b100000000000) == 0b100000000000) // 0b100000000000 is "still rendering" or something
|
||||||
|
{
|
||||||
|
//PluginLog.Debug("Waiting for character to finish drawing");
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait half a second just in case
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
private void RestorePreviousCharacter(string playerName)
|
private void RestorePreviousCharacter(string playerName)
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Restoring state for " + playerName);
|
PluginLog.Debug("Restoring state for " + playerName);
|
||||||
@@ -541,14 +448,26 @@ namespace MareSynchronos.Managers
|
|||||||
|
|
||||||
private void Watcher_PlayerChanged(Dalamud.Game.ClientState.Objects.Types.Character actor)
|
private void Watcher_PlayerChanged(Dalamud.Game.ClientState.Objects.Types.Character actor)
|
||||||
{
|
{
|
||||||
if (actor.Name.ToString() == _clientState.LocalPlayer!.Name.ToString())
|
try
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Watcher: PlayerChanged");
|
// fix for redraw from anamnesis
|
||||||
PlayerChanged(actor.Name.ToString());
|
while (_clientState.LocalPlayer == null)
|
||||||
|
{
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
if (actor.Name.ToString() == _clientState.LocalPlayer!.Name.ToString())
|
||||||
|
{
|
||||||
|
PluginLog.Debug("Watcher: PlayerChanged");
|
||||||
|
PlayerChanged(actor.Name.ToString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PluginLog.Debug("PlayerChanged: " + actor.Name.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
PluginLog.Debug("PlayerChanged: " + actor.Name.ToString());
|
PluginLog.Error(ex, "Actor was null or broken " + actor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,14 @@
|
|||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Plugin.Ipc;
|
using Dalamud.Plugin.Ipc;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Buffers.Text;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace MareSynchronos.Managers
|
namespace MareSynchronos.Managers
|
||||||
{
|
{
|
||||||
@@ -22,8 +27,8 @@ namespace MareSynchronos.Managers
|
|||||||
private readonly ICallGateSubscriber<string, int, object>? _penumbraRedraw;
|
private readonly ICallGateSubscriber<string, int, object>? _penumbraRedraw;
|
||||||
private readonly ICallGateSubscriber<string, string, string[]>? _penumbraReverseResolvePath;
|
private readonly ICallGateSubscriber<string, string, string[]>? _penumbraReverseResolvePath;
|
||||||
private readonly ICallGateSubscriber<string, object> _glamourerRevertCustomization;
|
private readonly ICallGateSubscriber<string, object> _glamourerRevertCustomization;
|
||||||
|
private readonly ICallGateSubscriber<string, string> _penumbraGetMetaManipulations;
|
||||||
private readonly ICallGateSubscriber<string, string, IReadOnlyDictionary<string, string>, List<string>, int, int>
|
private readonly ICallGateSubscriber<string, string, Dictionary<string, string>, string, int, int>
|
||||||
_penumbraSetTemporaryMod;
|
_penumbraSetTemporaryMod;
|
||||||
private readonly ICallGateSubscriber<string, string, bool, (int, string)> _penumbraCreateTemporaryCollection;
|
private readonly ICallGateSubscriber<string, string, bool, (int, string)> _penumbraCreateTemporaryCollection;
|
||||||
private readonly ICallGateSubscriber<string, int> _penumbraRemoveTemporaryCollection;
|
private readonly ICallGateSubscriber<string, int> _penumbraRemoveTemporaryCollection;
|
||||||
@@ -47,13 +52,15 @@ namespace MareSynchronos.Managers
|
|||||||
_glamourerApiVersion = _pluginInterface.GetIpcSubscriber<int>("Glamourer.ApiVersion");
|
_glamourerApiVersion = _pluginInterface.GetIpcSubscriber<int>("Glamourer.ApiVersion");
|
||||||
_glamourerRevertCustomization = _pluginInterface.GetIpcSubscriber<string, object>("Glamourer.RevertCharacterCustomization");
|
_glamourerRevertCustomization = _pluginInterface.GetIpcSubscriber<string, object>("Glamourer.RevertCharacterCustomization");
|
||||||
_penumbraObjectIsRedrawn = _pluginInterface.GetIpcSubscriber<IntPtr, int, object?>("Penumbra.GameObjectRedrawn");
|
_penumbraObjectIsRedrawn = _pluginInterface.GetIpcSubscriber<IntPtr, int, object?>("Penumbra.GameObjectRedrawn");
|
||||||
|
_penumbraGetMetaManipulations =
|
||||||
|
_pluginInterface.GetIpcSubscriber<string, string>("Penumbra.GetMetaManipulations");
|
||||||
|
|
||||||
_penumbraObjectIsRedrawn.Subscribe(RedrawEvent);
|
_penumbraObjectIsRedrawn.Subscribe(RedrawEvent);
|
||||||
_penumbraInit.Subscribe(RedrawSelf);
|
_penumbraInit.Subscribe(RedrawSelf);
|
||||||
|
|
||||||
_penumbraSetTemporaryMod =
|
_penumbraSetTemporaryMod =
|
||||||
_pluginInterface
|
_pluginInterface
|
||||||
.GetIpcSubscriber<string, string, IReadOnlyDictionary<string, string>, List<string>, int,
|
.GetIpcSubscriber<string, string, Dictionary<string, string>, string, int,
|
||||||
int>("Penumbra.AddTemporaryMod");
|
int>("Penumbra.AddTemporaryMod");
|
||||||
|
|
||||||
_penumbraCreateTemporaryCollection =
|
_penumbraCreateTemporaryCollection =
|
||||||
@@ -109,13 +116,17 @@ namespace MareSynchronos.Managers
|
|||||||
public string[] PenumbraReverseResolvePath(string path, string characterName)
|
public string[] PenumbraReverseResolvePath(string path, string characterName)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return new[] { path };
|
if (!CheckPenumbraApi()) return new[] { path };
|
||||||
return _penumbraReverseResolvePath!.InvokeFunc(path, characterName);
|
var resolvedPaths = _penumbraReverseResolvePath!.InvokeFunc(path, characterName);
|
||||||
|
PluginLog.Verbose("ReverseResolving " + path + Environment.NewLine + "=>" + string.Join(", ", resolvedPaths));
|
||||||
|
return resolvedPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? PenumbraResolvePath(string path, string characterName)
|
public string? PenumbraResolvePath(string path, string characterName)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return null;
|
if (!CheckPenumbraApi()) return null;
|
||||||
return _penumbraResolvePath!.InvokeFunc(path, characterName);
|
var resolvedPath = _penumbraResolvePath!.InvokeFunc(path, characterName);
|
||||||
|
PluginLog.Verbose("Resolving " + path + Environment.NewLine + "=>" + string.Join(", ", resolvedPath));
|
||||||
|
return resolvedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? PenumbraModDirectory()
|
public string? PenumbraModDirectory()
|
||||||
@@ -133,6 +144,7 @@ namespace MareSynchronos.Managers
|
|||||||
public void GlamourerApplyCharacterCustomization(string customization, string characterName)
|
public void GlamourerApplyCharacterCustomization(string customization, string characterName)
|
||||||
{
|
{
|
||||||
if (!CheckGlamourerApi()) return;
|
if (!CheckGlamourerApi()) return;
|
||||||
|
PluginLog.Debug("GlamourerString: " + customization);
|
||||||
_glamourerApplyCharacterCustomization!.InvokeAction(customization, characterName);
|
_glamourerApplyCharacterCustomization!.InvokeAction(customization, characterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,25 +160,34 @@ namespace MareSynchronos.Managers
|
|||||||
_penumbraRedraw!.InvokeAction(actorName, 0);
|
_penumbraRedraw!.InvokeAction(actorName, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PenumbraCreateTemporaryCollection(string characterName)
|
public string PenumbraCreateTemporaryCollection(string characterName)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return;
|
if (!CheckPenumbraApi()) return string.Empty;
|
||||||
PluginLog.Debug("Creating temp collection for " + characterName);
|
PluginLog.Debug("Creating temp collection for " + characterName);
|
||||||
//penumbraCreateTemporaryCollection.InvokeFunc("MareSynchronos", characterName, true);
|
return _penumbraCreateTemporaryCollection.InvokeFunc("MareSynchronos", characterName, true).Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PenumbraRemoveTemporaryCollection(string characterName)
|
public void PenumbraRemoveTemporaryCollection(string characterName)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return;
|
if (!CheckPenumbraApi()) return;
|
||||||
PluginLog.Debug("Removing temp collection for " + characterName);
|
PluginLog.Debug("Removing temp collection for " + characterName);
|
||||||
//penumbraRemoveTemporaryCollection.InvokeFunc(characterName);
|
_penumbraRemoveTemporaryCollection.InvokeFunc(characterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PenumbraSetTemporaryMods(string characterName, IReadOnlyDictionary<string, string> modPaths)
|
public void PenumbraSetTemporaryMods(string collectionName, Dictionary<string, string> modPaths, string manipulationData)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return;
|
if (!CheckPenumbraApi()) return;
|
||||||
PluginLog.Debug("Assigning temp mods for " + characterName);
|
|
||||||
//penumbraSetTemporaryMod.InvokeFunc("MareSynchronos", characterName, modPaths, new List<string>(), 0);
|
PluginLog.Debug("Assigning temp mods for " + collectionName);
|
||||||
|
PluginLog.Debug("ManipulationString: " + manipulationData);
|
||||||
|
var ret = _penumbraSetTemporaryMod.InvokeFunc("MareSynchronos", collectionName, modPaths, manipulationData, 0);
|
||||||
|
PluginLog.Debug("Penumbra Ret: " + ret.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PenumbraGetMetaManipulations(string characterName)
|
||||||
|
{
|
||||||
|
if (!CheckPenumbraApi()) return string.Empty;
|
||||||
|
return _penumbraGetMetaManipulations.InvokeFunc(characterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"Author": "darkarchon",
|
"Author": "darkarchon",
|
||||||
"Name": "Mare Synchronos",
|
"Name": "Mare Synchronos",
|
||||||
"Punchline": "",
|
"Punchline": "Let others see you as you see yourself.",
|
||||||
"Description": "",
|
"Description": "",
|
||||||
"InternalName": "mareSynchronos",
|
"InternalName": "mareSynchronos",
|
||||||
"ApplicableVersion": "any",
|
"ApplicableVersion": "any",
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ namespace MareSynchronos.Models
|
|||||||
FileReplacements = AllReplacements.Select(f => f.ToFileReplacementDto()).ToList(),
|
FileReplacements = AllReplacements.Select(f => f.ToFileReplacementDto()).ToList(),
|
||||||
GlamourerData = GlamourerString,
|
GlamourerData = GlamourerString,
|
||||||
Hash = CacheHash,
|
Hash = CacheHash,
|
||||||
JobId = (int)JobId
|
JobId = (int)JobId,
|
||||||
|
ManipulationData = ManipulationString
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,13 +35,15 @@ namespace MareSynchronos.Models
|
|||||||
public List<FileReplacement> FileReplacements { get; set; } = new List<FileReplacement>();
|
public List<FileReplacement> FileReplacements { get; set; } = new List<FileReplacement>();
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public string GlamourerString { get; private set; } = string.Empty;
|
public string GlamourerString { get; set; } = string.Empty;
|
||||||
|
|
||||||
public bool IsReady => FileReplacements.All(f => f.Computed);
|
public bool IsReady => FileReplacements.All(f => f.Computed);
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public string CacheHash { get; set; } = string.Empty;
|
public string CacheHash { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string ManipulationString { get; set; } = string.Empty;
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public uint JobId { get; set; } = 0;
|
public uint JobId { get; set; } = 0;
|
||||||
public void AddAssociatedResource(FileReplacement resource, FileReplacement? mdlParent, FileReplacement? mtrlParent)
|
public void AddAssociatedResource(FileReplacement resource, FileReplacement? mdlParent, FileReplacement? mtrlParent)
|
||||||
@@ -93,10 +96,6 @@ namespace MareSynchronos.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetGlamourerData(string glamourerString)
|
|
||||||
{
|
|
||||||
GlamourerString = glamourerString;
|
|
||||||
}
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
StringBuilder stringBuilder = new();
|
StringBuilder stringBuilder = new();
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ namespace MareSynchronos.Models
|
|||||||
{
|
{
|
||||||
GamePaths = GamePaths,
|
GamePaths = GamePaths,
|
||||||
Hash = Hash,
|
Hash = Hash,
|
||||||
ImcData = ImcData
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ namespace MareSynchronos
|
|||||||
private readonly PluginUi _pluginUi;
|
private readonly PluginUi _pluginUi;
|
||||||
private readonly WindowSystem _windowSystem;
|
private readonly WindowSystem _windowSystem;
|
||||||
private CharacterManager? _characterManager;
|
private CharacterManager? _characterManager;
|
||||||
|
|
||||||
public Plugin(DalamudPluginInterface pluginInterface, CommandManager commandManager,
|
public Plugin(DalamudPluginInterface pluginInterface, CommandManager commandManager,
|
||||||
Framework framework, ObjectTable objectTable, ClientState clientState)
|
Framework framework, ObjectTable objectTable, ClientState clientState)
|
||||||
{
|
{
|
||||||
@@ -59,14 +60,13 @@ namespace MareSynchronos
|
|||||||
var uiSharedComponent =
|
var uiSharedComponent =
|
||||||
new UIShared(_ipcManager, _apiController, _fileCacheManager, _configuration);
|
new UIShared(_ipcManager, _apiController, _fileCacheManager, _configuration);
|
||||||
|
|
||||||
// you might normally want to embed resources and load them from the manifest stream
|
|
||||||
_pluginUi = new PluginUi(_windowSystem, uiSharedComponent, _configuration, _apiController);
|
_pluginUi = new PluginUi(_windowSystem, uiSharedComponent, _configuration, _apiController);
|
||||||
_introUi = new IntroUI(_windowSystem, uiSharedComponent, _configuration, _fileCacheManager);
|
_introUi = new IntroUI(_windowSystem, uiSharedComponent, _configuration, _fileCacheManager);
|
||||||
_introUi.FinishedRegistration += (_, _) =>
|
_introUi.FinishedRegistration += (_, _) =>
|
||||||
{
|
{
|
||||||
|
_introUi.IsOpen = false;
|
||||||
_pluginUi.IsOpen = true;
|
_pluginUi.IsOpen = true;
|
||||||
_introUi?.Dispose();
|
ReLaunchCharacterManager();
|
||||||
ClientState_Login(null, EventArgs.Empty);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
new FileCacheContext().Dispose(); // make sure db is initialized I guess
|
new FileCacheContext().Dispose(); // make sure db is initialized I guess
|
||||||
@@ -96,41 +96,25 @@ namespace MareSynchronos
|
|||||||
_apiController?.Dispose();
|
_apiController?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ClientState_Login(object? sender, EventArgs e)
|
private void ClientState_Login(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Client login");
|
PluginLog.Debug("Client login");
|
||||||
|
|
||||||
_pluginInterface.UiBuilder.Draw += Draw;
|
_pluginInterface.UiBuilder.Draw += Draw;
|
||||||
|
_pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi;
|
||||||
|
_commandManager.AddHandler(CommandName, new CommandInfo(OnCommand)
|
||||||
|
{
|
||||||
|
HelpMessage = "Opens the Mare Synchronos UI"
|
||||||
|
});
|
||||||
|
|
||||||
if (!_configuration.HasValidSetup)
|
if (!_configuration.HasValidSetup)
|
||||||
{
|
{
|
||||||
_introUi.IsOpen = true;
|
_introUi.IsOpen = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
_introUi.IsOpen = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Task.Run(async () =>
|
ReLaunchCharacterManager();
|
||||||
{
|
|
||||||
while (_clientState.LocalPlayer == null)
|
|
||||||
{
|
|
||||||
await Task.Delay(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
_characterManager = new CharacterManager(
|
|
||||||
_clientState, _framework, _apiController, _objectTable, _ipcManager, new FileReplacementFactory(_ipcManager), _configuration);
|
|
||||||
_characterManager.StartWatchingPlayer();
|
|
||||||
_ipcManager.PenumbraRedraw(_clientState.LocalPlayer!.Name.ToString());
|
|
||||||
});
|
|
||||||
|
|
||||||
_pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi;
|
|
||||||
|
|
||||||
_commandManager.AddHandler(CommandName, new CommandInfo(OnCommand)
|
|
||||||
{
|
|
||||||
HelpMessage = "Opens the Mare Synchronos UI"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClientState_Logout(object? sender, EventArgs e)
|
private void ClientState_Logout(object? sender, EventArgs e)
|
||||||
@@ -142,47 +126,26 @@ namespace MareSynchronos
|
|||||||
_commandManager.RemoveHandler(CommandName);
|
_commandManager.RemoveHandler(CommandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyFile(FileReplacement replacement, string targetDirectory, Dictionary<string, string>? resourceDict = null)
|
public void ReLaunchCharacterManager()
|
||||||
{
|
{
|
||||||
if (replacement.HasFileReplacement)
|
_characterManager?.Dispose();
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Copying file \"" + replacement.ResolvedPath + "\"");
|
while (_clientState.LocalPlayer == null)
|
||||||
var db1 = new FileCacheContext();
|
|
||||||
var fileCache = db1.FileCaches.Single(f => f.Filepath.Contains(replacement.ResolvedPath.Replace('/', '\\')));
|
|
||||||
db1.Dispose();
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var ext = new FileInfo(fileCache.Filepath).Extension;
|
await Task.Delay(50);
|
||||||
var newFilePath = Path.Combine(targetDirectory, "files", fileCache.Hash.ToLower() + ext);
|
}
|
||||||
string lc4HcPath = Path.Combine(targetDirectory, "files", "lz4hc." + fileCache.Hash.ToLower() + ext);
|
|
||||||
if (!File.Exists(lc4HcPath))
|
|
||||||
{
|
|
||||||
|
|
||||||
Stopwatch st = Stopwatch.StartNew();
|
var characterCacheFactory =
|
||||||
File.WriteAllBytes(lc4HcPath, LZ4Codec.WrapHC(File.ReadAllBytes(fileCache.Filepath), 0, (int)new FileInfo(fileCache.Filepath).Length));
|
new CharacterCacheFactory(_clientState, _ipcManager, new FileReplacementFactory(_ipcManager));
|
||||||
st.Stop();
|
_characterManager = new CharacterManager(
|
||||||
PluginLog.Debug("Compressed " + new FileInfo(fileCache.Filepath).Length + " bytes to " + new FileInfo(lc4HcPath).Length + " bytes in " + st.Elapsed);
|
_clientState, _framework, _apiController, _objectTable, _ipcManager, _configuration, characterCacheFactory);
|
||||||
File.Copy(fileCache.Filepath, newFilePath);
|
_characterManager.StartWatchingPlayer();
|
||||||
if (resourceDict != null)
|
_ipcManager.PenumbraRedraw(_clientState.LocalPlayer!.Name.ToString());
|
||||||
{
|
});
|
||||||
foreach (var path in replacement.GamePaths)
|
|
||||||
{
|
|
||||||
resourceDict[path] = $"files\\{fileCache.Hash.ToLower() + ext}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//File.AppendAllLines(Path.Combine(targetDirectory, "filelist.txt"), new[] { $"\"{replacement.GamePath}\": \"files\\\\{fileCache.Hash.ToLower() + ext}\"," });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
PluginLog.Error(ex, "error during copy");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
_windowSystem.Draw();
|
_windowSystem.Draw();
|
||||||
@@ -190,66 +153,6 @@ namespace MareSynchronos
|
|||||||
|
|
||||||
private void OnCommand(string command, string args)
|
private void OnCommand(string command, string args)
|
||||||
{
|
{
|
||||||
if (args == "printjson")
|
|
||||||
{
|
|
||||||
_ = _characterManager?.DebugJson();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.StartsWith("watch"))
|
|
||||||
{
|
|
||||||
var playerName = args.Replace("watch", "").Trim();
|
|
||||||
_characterManager!.WatchPlayer(playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.StartsWith("stop"))
|
|
||||||
{
|
|
||||||
var playerName = args.Replace("watch", "").Trim();
|
|
||||||
_characterManager!.StopWatchPlayer(playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args == "createtestmod")
|
|
||||||
{
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
var playerName = _clientState.LocalPlayer!.Name.ToString();
|
|
||||||
var modName = $"Mare Synchronos Test Mod {playerName}";
|
|
||||||
var modDirectory = _ipcManager!.PenumbraModDirectory()!;
|
|
||||||
string modDirectoryPath = Path.Combine(modDirectory, modName);
|
|
||||||
if (Directory.Exists(modDirectoryPath))
|
|
||||||
{
|
|
||||||
Directory.Delete(modDirectoryPath, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Directory.CreateDirectory(modDirectoryPath);
|
|
||||||
Directory.CreateDirectory(Path.Combine(modDirectoryPath, "files"));
|
|
||||||
Meta meta = new()
|
|
||||||
{
|
|
||||||
Name = modName,
|
|
||||||
Author = playerName,
|
|
||||||
Description = "Mare Synchronous Test Mod Export",
|
|
||||||
};
|
|
||||||
|
|
||||||
var resources = _characterManager!.BuildCharacterCache();
|
|
||||||
var metaJson = JsonConvert.SerializeObject(meta);
|
|
||||||
File.WriteAllText(Path.Combine(modDirectoryPath, "meta.json"), metaJson);
|
|
||||||
|
|
||||||
DefaultMod defaultMod = new();
|
|
||||||
|
|
||||||
//using var db = new FileCacheContext();
|
|
||||||
Stopwatch st = Stopwatch.StartNew();
|
|
||||||
Parallel.ForEach(resources.AllReplacements, resource =>
|
|
||||||
{
|
|
||||||
CopyFile(resource, modDirectoryPath, defaultMod.Files);
|
|
||||||
});
|
|
||||||
PluginLog.Debug("Compression took " + st.Elapsed);
|
|
||||||
|
|
||||||
var defaultModJson = JsonConvert.SerializeObject(defaultMod);
|
|
||||||
File.WriteAllText(Path.Combine(modDirectoryPath, "default_mod.json"), defaultModJson);
|
|
||||||
|
|
||||||
PluginLog.Debug("Mod created to " + modDirectoryPath);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(args))
|
if (string.IsNullOrEmpty(args))
|
||||||
{
|
{
|
||||||
_pluginUi.Toggle();
|
_pluginUi.Toggle();
|
||||||
@@ -258,7 +161,10 @@ namespace MareSynchronos
|
|||||||
|
|
||||||
private void OpenConfigUi()
|
private void OpenConfigUi()
|
||||||
{
|
{
|
||||||
_pluginUi.Toggle();
|
if(_configuration.HasValidSetup)
|
||||||
|
_pluginUi.Toggle();
|
||||||
|
else
|
||||||
|
_introUi.Toggle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ namespace MareSynchronos.UI
|
|||||||
};
|
};
|
||||||
|
|
||||||
_windowSystem.AddWindow(this);
|
_windowSystem.AddWindow(this);
|
||||||
IsOpen = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
@@ -164,7 +163,10 @@ namespace MareSynchronos.UI
|
|||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
UIShared.TextWrapped(_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri]);
|
UIShared.TextWrapped(_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri]);
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
ImGui.Button("Copy secret key to clipboard");
|
if (ImGui.Button("Copy secret key to clipboard"))
|
||||||
|
{
|
||||||
|
ImGui.SetClipboardText(_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri]);
|
||||||
|
}
|
||||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);
|
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);
|
||||||
UIShared.TextWrapped("This is the only time you will be able to see this key in the UI. You can copy it to make a backup somewhere.");
|
UIShared.TextWrapped("This is the only time you will be able to see this key in the UI. You can copy it to make a backup somewhere.");
|
||||||
ImGui.PopStyleColor();
|
ImGui.PopStyleColor();
|
||||||
|
|||||||
@@ -238,9 +238,8 @@ namespace MareSynchronos.UI
|
|||||||
{
|
{
|
||||||
if (_apiController.PairedClients.All(w => w.OtherUID != tempNameUID))
|
if (_apiController.PairedClients.All(w => w.OtherUID != tempNameUID))
|
||||||
{
|
{
|
||||||
_ = _apiController.SendPairedClientAddition(tempNameUID);
|
|
||||||
|
|
||||||
tempNameUID = string.Empty;
|
tempNameUID = string.Empty;
|
||||||
|
_ = _apiController.SendPairedClientAddition(tempNameUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui.PopFont();
|
ImGui.PopFont();
|
||||||
|
|||||||
@@ -1,27 +1,17 @@
|
|||||||
using Dalamud.Configuration;
|
using Dalamud.Logging;
|
||||||
using Dalamud.Logging;
|
|
||||||
using MareSynchronos.Models;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers.Text;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dalamud.Game.ClientState.Objects.Types;
|
|
||||||
using LZ4;
|
using LZ4;
|
||||||
using MareSynchronos.API;
|
using MareSynchronos.API;
|
||||||
using MareSynchronos.FileCacheDB;
|
using MareSynchronos.FileCacheDB;
|
||||||
using Microsoft.AspNetCore.SignalR.Client;
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
using Microsoft.VisualBasic;
|
|
||||||
|
|
||||||
namespace MareSynchronos.WebAPI
|
namespace MareSynchronos.WebAPI
|
||||||
{
|
{
|
||||||
@@ -124,7 +114,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
await LoadInitialData();
|
await LoadInitialData();
|
||||||
Connected?.Invoke(this, EventArgs.Empty);
|
Connected?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
//PluginLog.Error(ex, "Error during Heartbeat initialization");
|
//PluginLog.Error(ex, "Error during Heartbeat initialization");
|
||||||
}
|
}
|
||||||
@@ -241,9 +231,15 @@ namespace MareSynchronos.WebAPI
|
|||||||
private void UpdateLocalClientPairs(ClientPairDto dto, string characterIdentifier)
|
private void UpdateLocalClientPairs(ClientPairDto dto, string characterIdentifier)
|
||||||
{
|
{
|
||||||
var entry = PairedClients.SingleOrDefault(e => e.OtherUID == dto.OtherUID);
|
var entry = PairedClients.SingleOrDefault(e => e.OtherUID == dto.OtherUID);
|
||||||
|
if (dto.IsRemoved)
|
||||||
|
{
|
||||||
|
PairedClients.RemoveAll(p => p.OtherUID == dto.OtherUID);
|
||||||
|
UnpairedFromOther?.Invoke(characterIdentifier, EventArgs.Empty);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
{
|
{
|
||||||
UnpairedFromOther?.Invoke(characterIdentifier, EventArgs.Empty);
|
PairedClients.Add(dto);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +321,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
var uploadToken = uploadCancellationTokenSource.Token;
|
var uploadToken = uploadCancellationTokenSource.Token;
|
||||||
PluginLog.Debug("New Token Created");
|
PluginLog.Debug("New Token Created");
|
||||||
|
|
||||||
var filesToUpload = await _fileHub!.InvokeAsync<List<string>>("SendFiles", character.FileReplacements, uploadToken);
|
var filesToUpload = await _fileHub!.InvokeAsync<List<string>>("SendFiles", character.FileReplacements.Select(c => c.Hash).Distinct(), uploadToken);
|
||||||
|
|
||||||
IsUploading = true;
|
IsUploading = true;
|
||||||
|
|
||||||
@@ -333,6 +329,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
Dictionary<string, byte[]> compressedFileData = new();
|
Dictionary<string, byte[]> compressedFileData = new();
|
||||||
foreach (var file in filesToUpload)
|
foreach (var file in filesToUpload)
|
||||||
{
|
{
|
||||||
|
PluginLog.Debug(file);
|
||||||
var data = await GetCompressedFileData(file, uploadToken);
|
var data = await GetCompressedFileData(file, uploadToken);
|
||||||
compressedFileData.Add(data.Item1, data.Item2);
|
compressedFileData.Add(data.Item1, data.Item2);
|
||||||
CurrentUploads[data.Item1] = (0, data.Item2.Length);
|
CurrentUploads[data.Item1] = (0, data.Item2.Length);
|
||||||
|
|||||||
Reference in New Issue
Block a user