merge 0.4.0 into main
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Utils;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
{
|
||||
@@ -39,16 +41,31 @@ namespace MareSynchronos.Models
|
||||
|
||||
public CharacterCacheDto ToCharacterCacheDto()
|
||||
{
|
||||
var fileReplacements = FileReplacements.ToDictionary(k => k.Key, k => k.Value.Where(f => f.HasFileReplacement && !f.IsFileSwap).GroupBy(f => f.Hash).Select(g =>
|
||||
{
|
||||
return new FileReplacementDto()
|
||||
{
|
||||
GamePaths = g.SelectMany(g => g.GamePaths).Distinct().ToArray(),
|
||||
Hash = g.First().Hash,
|
||||
};
|
||||
}).ToList());
|
||||
|
||||
Logger.Debug("Adding fileSwaps");
|
||||
foreach (var item in FileReplacements)
|
||||
{
|
||||
Logger.Debug("Checking fileSwaps for " + item.Key);
|
||||
var fileSwapsToAdd = item.Value.Where(f => f.IsFileSwap).Select(f => f.ToFileReplacementDto());
|
||||
Logger.Debug("Adding " + fileSwapsToAdd.Count() + " file swaps");
|
||||
foreach (var swap in fileSwapsToAdd)
|
||||
{
|
||||
Logger.Debug("Adding: " + swap.GamePaths.First() + ":" + swap.FileSwapPath);
|
||||
}
|
||||
fileReplacements[item.Key].AddRange(fileSwapsToAdd);
|
||||
}
|
||||
|
||||
return new CharacterCacheDto()
|
||||
{
|
||||
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()),
|
||||
FileReplacements = fileReplacements,
|
||||
GlamourerData = GlamourerString.ToDictionary(d => d.Key, d => d.Value),
|
||||
ManipulationData = ManipulationString
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ using MareSynchronos.FileCacheDB;
|
||||
using System.IO;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Utils;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
{
|
||||
@@ -20,27 +21,29 @@ namespace MareSynchronos.Models
|
||||
_penumbraDirectory = penumbraDirectory;
|
||||
}
|
||||
|
||||
public bool Computed => !HasFileReplacement || !string.IsNullOrEmpty(Hash);
|
||||
public bool Computed => IsFileSwap || !HasFileReplacement || !string.IsNullOrEmpty(Hash);
|
||||
|
||||
public List<string> GamePaths { get; set; } = new();
|
||||
|
||||
public bool HasFileReplacement => GamePaths.Count >= 1 && GamePaths.Any(p => p != ResolvedPath);
|
||||
|
||||
public bool IsFileSwap => !Regex.IsMatch(ResolvedPath, @"^[a-zA-Z]:(/|\\)", RegexOptions.ECMAScript) && GamePaths.First() != ResolvedPath;
|
||||
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
|
||||
|
||||
public string ResolvedPath { get; set; } = string.Empty;
|
||||
|
||||
|
||||
public void SetResolvedPath(string path)
|
||||
{
|
||||
ResolvedPath = path.ToLower().Replace('/', '\\').Replace(_penumbraDirectory, "").Replace('\\', '/');
|
||||
if (!HasFileReplacement) return;
|
||||
ResolvedPath = path.ToLowerInvariant().Replace('/', '\\').Replace(_penumbraDirectory, "").Replace('\\', '/');
|
||||
if (!HasFileReplacement || IsFileSwap) return;
|
||||
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
FileCache? fileCache;
|
||||
using (FileCacheContext db = new())
|
||||
{
|
||||
fileCache = db.FileCaches.FirstOrDefault(f => f.Filepath == path.ToLower());
|
||||
fileCache = db.FileCaches.FirstOrDefault(f => f.Filepath == path.ToLowerInvariant());
|
||||
}
|
||||
|
||||
if (fileCache != null)
|
||||
@@ -54,7 +57,7 @@ namespace MareSynchronos.Models
|
||||
{
|
||||
Hash = ComputeHash(fi);
|
||||
using var db = new FileCacheContext();
|
||||
var newTempCache = db.FileCaches.Single(f => f.Filepath == path.ToLower());
|
||||
var newTempCache = db.FileCaches.Single(f => f.Filepath == path.ToLowerInvariant());
|
||||
newTempCache.Hash = Hash;
|
||||
db.Update(newTempCache);
|
||||
db.SaveChanges();
|
||||
@@ -73,6 +76,7 @@ namespace MareSynchronos.Models
|
||||
{
|
||||
GamePaths = GamePaths.ToArray(),
|
||||
Hash = Hash,
|
||||
FileSwapPath = IsFileSwap ? ResolvedPath : string.Empty
|
||||
};
|
||||
}
|
||||
public override string ToString()
|
||||
@@ -88,15 +92,16 @@ namespace MareSynchronos.Models
|
||||
string hash = Crypto.GetFileHash(fi.FullName);
|
||||
|
||||
using FileCacheContext db = new();
|
||||
var fileAddedDuringCompute = db.FileCaches.FirstOrDefault(f => f.Filepath == fi.FullName.ToLower());
|
||||
var fileAddedDuringCompute = db.FileCaches.FirstOrDefault(f => f.Filepath == fi.FullName.ToLowerInvariant());
|
||||
if (fileAddedDuringCompute != null) return fileAddedDuringCompute.Hash;
|
||||
|
||||
try
|
||||
{
|
||||
Logger.Debug("Adding new file to DB: " + fi.FullName + ", " + hash);
|
||||
db.Add(new FileCache()
|
||||
{
|
||||
Hash = hash,
|
||||
Filepath = fi.FullName.ToLower(),
|
||||
Filepath = fi.FullName.ToLowerInvariant(),
|
||||
LastModifiedDate = fi.LastWriteTimeUtc.Ticks.ToString()
|
||||
});
|
||||
db.SaveChanges();
|
||||
|
||||
@@ -19,7 +19,18 @@ namespace MareSynchronos.Models
|
||||
public IntPtr Address { get; set; }
|
||||
public IntPtr DrawObjectAddress { get; set; }
|
||||
|
||||
private IntPtr CurrentAddress => getAddress.Invoke();
|
||||
private IntPtr CurrentAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return getAddress.Invoke();
|
||||
}
|
||||
catch
|
||||
{ return IntPtr.Zero; }
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerRelatedObject(ObjectKind objectKind, IntPtr address, IntPtr drawObjectAddress, Func<IntPtr> getAddress)
|
||||
{
|
||||
@@ -53,7 +64,7 @@ namespace MareSynchronos.Models
|
||||
if (addr || equip || drawObj || nameChange)
|
||||
{
|
||||
_name = name;
|
||||
Logger.Verbose(ObjectKind + " Changed: " + _name + ", now: " + curPtr + ", " + (IntPtr)chara->GameObject.DrawObject);
|
||||
Logger.Verbose($"{ObjectKind} changed: {_name}, now: {curPtr:X}, {(IntPtr)chara->GameObject.DrawObject:X}");
|
||||
|
||||
Address = curPtr;
|
||||
DrawObjectAddress = (IntPtr)chara->GameObject.DrawObject;
|
||||
|
||||
Reference in New Issue
Block a user