 b2276a1883
			
		
	
	b2276a1883
	
	
	
		
			
			* most of the groups refactoring on client * register OnMethods for group stuff * start implementing client (still pretty broken) * finish implementing new api first iteration * idk rework everything for pair shit (still WIP); goal is to remove PairedClients and GroupPairClients from ApiController * move everything to PairManager, remove dictionaries from APiController * remove admin stuff from client, cleanup * adjust reconnection handling, add new settings, todo still to remove access from old stuff that's marked obsolete from config * add back adding servers, fix intro ui * fix obsolete calls * adjust config namespace * add UI for setting animation/sound permissions to syncshells * add ConfigurationService to hot reload config on change from external * move transient data cache to configuration * add deleting service to ui * fix saving of transient resources * fix group pair user assignments * halt scanner when penumbra inactive, add visible/online/offline split to individual pairs and tags * add presence to syncshell ui * move fullpause from config to server config * fixes in code style * more codestyle * show info icon on player in shells, don't show icon when no changes from default state are made, add online notifs * fixes to intro UI --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
		
			
				
	
	
		
			164 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			164 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Dalamud.Game.ClientState.Objects.Types;
 | |
| using LZ4;
 | |
| using MareSynchronos.FileCache;
 | |
| using MareSynchronos.Managers;
 | |
| using MareSynchronos.Utils;
 | |
| using MareSynchronos.API.Data;
 | |
| using MareSynchronos.API.Data.Enum;
 | |
| using MareSynchronos.MareConfiguration;
 | |
| 
 | |
| namespace MareSynchronos.Export;
 | |
| public class MareCharaFileManager
 | |
| {
 | |
|     private readonly FileCacheManager _manager;
 | |
|     private readonly IpcManager _ipcManager;
 | |
|     private readonly ConfigurationService _configService;
 | |
|     private readonly DalamudUtil _dalamudUtil;
 | |
|     private readonly MareCharaFileDataFactory _factory;
 | |
|     public MareCharaFileHeader? LoadedCharaFile { get; private set; }
 | |
|     public bool CurrentlyWorking { get; private set; } = false;
 | |
| 
 | |
|     public MareCharaFileManager(FileCacheManager manager, IpcManager ipcManager, ConfigurationService configService, DalamudUtil dalamudUtil)
 | |
|     {
 | |
|         _factory = new(manager);
 | |
|         _manager = manager;
 | |
|         _ipcManager = ipcManager;
 | |
|         _configService = configService;
 | |
|         _dalamudUtil = dalamudUtil;
 | |
|     }
 | |
| 
 | |
|     public void ClearMareCharaFile()
 | |
|     {
 | |
|         LoadedCharaFile = null;
 | |
|     }
 | |
| 
 | |
|     public void LoadMareCharaFile(string filePath)
 | |
|     {
 | |
|         CurrentlyWorking = true;
 | |
|         try
 | |
|         {
 | |
|             using var unwrapped = File.OpenRead(filePath);
 | |
|             using var lz4Stream = new LZ4Stream(unwrapped, LZ4StreamMode.Decompress, LZ4StreamFlags.HighCompression);
 | |
|             using var reader = new BinaryReader(lz4Stream);
 | |
|             LoadedCharaFile = MareCharaFileHeader.FromBinaryReader(filePath, reader);
 | |
|             Logger.Debug("Read Mare Chara File");
 | |
|             Logger.Debug("Version: " + (LoadedCharaFile?.Version ?? -1));
 | |
| 
 | |
|         }
 | |
|         catch { throw; }
 | |
|         finally { CurrentlyWorking = false; }
 | |
|     }
 | |
| 
 | |
|     public async Task ApplyMareCharaFile(GameObject? charaTarget)
 | |
|     {
 | |
|         Dictionary<string, string> extractedFiles = new(StringComparer.Ordinal);
 | |
|         CurrentlyWorking = true;
 | |
|         try
 | |
|         {
 | |
|             if (LoadedCharaFile == null || charaTarget == null || !File.Exists(LoadedCharaFile.FilePath)) return;
 | |
|             var unwrapped = File.OpenRead(LoadedCharaFile.FilePath);
 | |
|             await using (unwrapped.ConfigureAwait(false))
 | |
|             {
 | |
|                 using var lz4Stream = new LZ4Stream(unwrapped, LZ4StreamMode.Decompress, LZ4StreamFlags.HighCompression);
 | |
|                 using var reader = new BinaryReader(lz4Stream);
 | |
|                 LoadedCharaFile.AdvanceReaderToData(reader);
 | |
|                 Logger.Debug("Applying to " + charaTarget.Name.TextValue);
 | |
|                 extractedFiles = ExtractFilesFromCharaFile(LoadedCharaFile, reader);
 | |
|                 Dictionary<string, string> fileSwaps = new(StringComparer.Ordinal);
 | |
|                 foreach (var fileSwap in LoadedCharaFile.CharaFileData.FileSwaps)
 | |
|                 {
 | |
|                     foreach (var path in fileSwap.GamePaths)
 | |
|                     {
 | |
|                         fileSwaps.Add(path, fileSwap.FileSwapPath);
 | |
|                     }
 | |
|                 }
 | |
|                 _ipcManager.ToggleGposeQueueMode(on: true);
 | |
|                 _ipcManager.PenumbraRemoveTemporaryCollection(charaTarget.Name.TextValue);
 | |
|                 _ipcManager.PenumbraSetTemporaryMods(charaTarget.Name.TextValue,
 | |
|                     extractedFiles.Union(fileSwaps).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal),
 | |
|                     LoadedCharaFile.CharaFileData.ManipulationData);
 | |
|                 _ipcManager.GlamourerApplyAll(LoadedCharaFile.CharaFileData.GlamourerData, charaTarget.Address);
 | |
|                 _dalamudUtil.WaitWhileGposeCharacterIsDrawing(charaTarget.Address);
 | |
|                 _ipcManager.PenumbraRemoveTemporaryCollection(charaTarget.Name.TextValue);
 | |
|                 _ipcManager.ToggleGposeQueueMode(on: false);
 | |
|             }
 | |
|         }
 | |
|         catch { throw; }
 | |
|         finally
 | |
|         {
 | |
|             CurrentlyWorking = false;
 | |
| 
 | |
|             Logger.Debug("Clearing local files");
 | |
|             foreach (var file in extractedFiles)
 | |
|             {
 | |
|                 File.Delete(file.Value);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private Dictionary<string, string> ExtractFilesFromCharaFile(MareCharaFileHeader charaFileHeader, BinaryReader reader)
 | |
|     {
 | |
|         Dictionary<string, string> gamePathToFilePath = new(StringComparer.Ordinal);
 | |
|         int i = 0;
 | |
|         foreach (var fileData in charaFileHeader.CharaFileData.Files)
 | |
|         {
 | |
|             var fileName = Path.Combine(_configService.Current.CacheFolder, "mare_" + (i++) + ".tmp");
 | |
|             var length = fileData.Length;
 | |
|             var bufferSize = 4 * 1024 * 1024;
 | |
|             var buffer = new byte[bufferSize];
 | |
|             using var fs = File.OpenWrite(fileName);
 | |
|             using var wr = new BinaryWriter(fs);
 | |
|             while (length > 0)
 | |
|             {
 | |
|                 if (length < bufferSize) bufferSize = (int)length;
 | |
|                 buffer = reader.ReadBytes(bufferSize);
 | |
|                 wr.Write(length > bufferSize ? buffer : buffer.Take((int)length).ToArray());
 | |
|                 length -= bufferSize;
 | |
|             }
 | |
|             foreach (var path in fileData.GamePaths)
 | |
|             {
 | |
|                 gamePathToFilePath[path] = fileName;
 | |
|                 Logger.Verbose(path + " => " + fileName);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         return gamePathToFilePath;
 | |
|     }
 | |
| 
 | |
|     public void SaveMareCharaFile(CharacterData? dto, string description, string filePath)
 | |
|     {
 | |
|         CurrentlyWorking = true;
 | |
|         try
 | |
|         {
 | |
|             if (dto == null) return;
 | |
| 
 | |
|             var mareCharaFileData = _factory.Create(description, dto);
 | |
|             MareCharaFileHeader output = new(MareCharaFileHeader.CurrentVersion, mareCharaFileData);
 | |
| 
 | |
|             using var fs = new FileStream(filePath, FileMode.Create);
 | |
|             using var lz4 = new LZ4Stream(fs, LZ4StreamMode.Compress, LZ4StreamFlags.HighCompression);
 | |
|             using var writer = new BinaryWriter(lz4);
 | |
|             output.WriteToStream(writer);
 | |
|             var bufferSize = 4 * 1024 * 1024;
 | |
|             byte[] buffer = new byte[bufferSize];
 | |
| 
 | |
|             if (dto.FileReplacements.TryGetValue(ObjectKind.Player, out var replacement))
 | |
|             {
 | |
|                 foreach (var file in replacement.Select(item => _manager.GetFileCacheByHash(item.Hash)).Where(file => file != null))
 | |
|                 {
 | |
|                     var length = new FileInfo(file!.ResolvedFilepath).Length;
 | |
|                     using var fsRead = File.OpenRead(file.ResolvedFilepath);
 | |
|                     using var br = new BinaryReader(fsRead);
 | |
|                     int readBytes = 0;
 | |
|                     while ((readBytes = br.Read(buffer, 0, bufferSize)) > 0)
 | |
|                     {
 | |
|                         writer.Write(readBytes == bufferSize ? buffer : buffer.Take(readBytes).ToArray());
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         catch { throw; }
 | |
|         finally { CurrentlyWorking = false; }
 | |
|     }
 | |
| }
 |