This commit is contained in:
Ottermandias 2023-06-28 01:39:53 +02:00
parent 63e82d19dc
commit e57538561f
34 changed files with 2428 additions and 720 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.IO;
using Glamourer.Automation;
using Glamourer.Gui;
using Newtonsoft.Json.Linq;
@ -7,13 +8,17 @@ namespace Glamourer.Services;
public class ConfigMigrationService
{
private readonly SaveService _saveService;
private readonly SaveService _saveService;
private readonly FixedDesignMigrator _fixedDesignMigrator;
private Configuration _config = null!;
private JObject _data = null!;
public ConfigMigrationService(SaveService saveService)
=> _saveService = saveService;
public ConfigMigrationService(SaveService saveService, FixedDesignMigrator fixedDesignMigrator)
{
_saveService = saveService;
_fixedDesignMigrator = fixedDesignMigrator;
}
public void Migrate(Configuration config)
{
@ -34,6 +39,7 @@ public class ConfigMigrationService
if (_config.Version > 1)
return;
_fixedDesignMigrator.Migrate(_data["FixedDesigns"]);
_config.Version = 2;
var customizationColor = _data["CustomizationColor"]?.ToObject<uint>() ?? ColorId.CustomizationDesign.Data().DefaultColor;
_config.Colors[ColorId.CustomizationDesign] = customizationColor;

View file

@ -14,6 +14,42 @@ public sealed class CustomizationService : AsyncServiceWrapper<ICustomizationMan
: base(nameof(CustomizationService), () => CustomizationManager.Create(pi, gameData))
{ }
public (Customize NewValue, CustomizeFlag Applied) Combine(Customize oldValues, Customize newValues, CustomizeFlag applyWhich)
{
CustomizeFlag applied = 0;
Customize ret = default;
ret.Load(oldValues);
if (applyWhich.HasFlag(CustomizeFlag.Clan))
{
ChangeClan(ref ret, newValues.Clan);
applied |= CustomizeFlag.Clan;
}
if (applyWhich.HasFlag(CustomizeFlag.Gender))
if (ret.Race is not Race.Hrothgar || newValues.Gender is not Gender.Female)
{
ChangeGender(ref ret, newValues.Gender);
applied |= CustomizeFlag.Gender;
}
var set = AwaitedService.GetList(ret.Clan, ret.Gender);
foreach (var index in Enum.GetValues<CustomizeIndex>())
{
var flag = index.ToFlag();
if (!applyWhich.HasFlag(flag))
continue;
var value = newValues[index];
if (IsCustomizationValid(set, ret.Face, index, value))
{
ret[index] = value;
applied |= flag;
}
}
return (ret, applied);
}
/// <summary> In languages other than english the actual clan name may depend on gender. </summary>
public string ClanName(SubRace race, Gender gender)
{
@ -175,53 +211,59 @@ public sealed class CustomizationService : AsyncServiceWrapper<ICustomizationMan
}
/// <summary> Change a clan while keeping all other customizations valid. </summary>
public bool ChangeClan(ref Customize customize, SubRace newClan)
public CustomizeFlag ChangeClan(ref Customize customize, SubRace newClan)
{
if (customize.Clan == newClan)
return false;
return 0;
if (ValidateClan(newClan, newClan.ToRace(), out var newRace, out newClan).Length > 0)
return false;
return 0;
var flags = CustomizeFlag.Clan | CustomizeFlag.Race;
customize.Race = newRace;
customize.Clan = newClan;
// TODO Female Hrothgar
if (newRace == Race.Hrothgar)
customize.Gender = Gender.Male;
{
customize.Gender = Gender.Male;
flags |= CustomizeFlag.Gender;
}
var set = AwaitedService.GetList(customize.Clan, customize.Gender);
FixValues(set, ref customize);
return true;
return FixValues(set, ref customize) | flags;
}
/// <summary> Change a gender while keeping all other customizations valid. </summary>
public bool ChangeGender(ref Customize customize, Gender newGender)
public CustomizeFlag ChangeGender(ref Customize customize, Gender newGender)
{
if (customize.Gender == newGender)
return false;
return 0;
// TODO Female Hrothgar
if (customize.Race is Race.Hrothgar)
return false;
return 0;
if (ValidateGender(customize.Race, newGender, out newGender).Length > 0)
return false;
return 0;
customize.Gender = newGender;
var set = AwaitedService.GetList(customize.Clan, customize.Gender);
FixValues(set, ref customize);
return true;
return FixValues(set, ref customize) | CustomizeFlag.Gender;
}
private static void FixValues(CustomizationSet set, ref Customize customize)
private static CustomizeFlag FixValues(CustomizationSet set, ref Customize customize)
{
CustomizeFlag flags = 0;
foreach (var idx in Enum.GetValues<CustomizeIndex>().Where(set.IsAvailable))
{
if (ValidateCustomizeValue(set, customize.Face, idx, customize[idx], out var fixedValue).Length > 0)
customize[idx] = fixedValue;
{
customize[idx] = fixedValue;
flags |= idx.ToFlag();
}
}
return flags;
}
}

View file

@ -12,11 +12,13 @@ public class FilenameService
public readonly string DesignFileSystem;
public readonly string MigrationDesignFile;
public readonly string DesignDirectory;
public readonly string AutomationFile;
public FilenameService(DalamudPluginInterface pi)
{
ConfigDirectory = pi.ConfigDirectory.FullName;
ConfigFile = pi.ConfigFile.FullName;
AutomationFile = Path.Combine(ConfigDirectory, "automation.json");
DesignFileSystem = Path.Combine(ConfigDirectory, "sort_order.json");
MigrationDesignFile = Path.Combine(ConfigDirectory, "Designs.json");
DesignDirectory = Path.Combine(ConfigDirectory, "designs");

View file

@ -0,0 +1,54 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace Glamourer.Services;
public class PhrasingService
{
private readonly Configuration _config;
private readonly SHA256 _hasher = SHA256.Create();
public bool Phrasing1 { get; private set; }
public bool Phrasing2 { get; private set; }
public PhrasingService(Configuration config)
{
_config = config;
Phrasing1 = CheckPhrasing(_config.Phrasing1, P1);
Phrasing2 = CheckPhrasing(_config.Phrasing2, P2);
}
public void SetPhrasing1(string newPhrasing)
{
if (_config.Phrasing1 == newPhrasing)
return;
_config.Phrasing1 = newPhrasing;
_config.Save();
Phrasing1 = CheckPhrasing(newPhrasing, P1);
}
public void SetPhrasing2(string newPhrasing)
{
if (_config.Phrasing2 == newPhrasing)
return;
_config.Phrasing2 = newPhrasing;
_config.Save();
Phrasing2 = CheckPhrasing(newPhrasing, P2);
}
private bool CheckPhrasing(string phrasing, ReadOnlySpan<byte> data)
{
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(phrasing));
var sha = _hasher.ComputeHash(stream);
return data.SequenceEqual(sha);
}
// @formatter:off
private static ReadOnlySpan<byte> P1 => new byte[] { 0xD1, 0x35, 0xD7, 0x18, 0xBE, 0x45, 0x42, 0xBD, 0x88, 0x77, 0x7E, 0xC4, 0x41, 0x06, 0x34, 0x4D, 0x71, 0x3A, 0xC5, 0xCC, 0xA4, 0x1B, 0x7D, 0x3F, 0x3B, 0x86, 0x07, 0xCB, 0x63, 0xD7, 0xF9, 0xDB };
private static ReadOnlySpan<byte> P2 => new byte[] { 0x6A, 0x84, 0x12, 0xEA, 0x3B, 0x03, 0x2E, 0xD9, 0xA3, 0x51, 0xB0, 0x4F, 0xE7, 0x4D, 0x59, 0x87, 0xA9, 0xA1, 0x6E, 0x08, 0xC7, 0x3E, 0xD3, 0x15, 0xEE, 0x40, 0x2C, 0xB3, 0x44, 0x78, 0x1F, 0xA0 };
// @formatter:on
}

View file

@ -1,9 +1,11 @@
using Dalamud.Plugin;
using Glamourer.Api;
using Glamourer.Automation;
using Glamourer.Designs;
using Glamourer.Events;
using Glamourer.Gui;
using Glamourer.Gui.Customization;
using Glamourer.Gui.Equipment;
using Glamourer.Gui.Tabs;
using Glamourer.Gui.Tabs.ActorTab;
using Glamourer.Gui.Tabs.DesignTab;
@ -47,6 +49,7 @@ public static class ServiceManager
.AddSingleton<BackupService>()
.AddSingleton<FrameworkManager>()
.AddSingleton<SaveService>()
.AddSingleton<PhrasingService>()
.AddSingleton<ConfigMigrationService>()
.AddSingleton<Configuration>();
@ -54,6 +57,7 @@ public static class ServiceManager
=> services.AddSingleton<VisorStateChanged>()
.AddSingleton<SlotUpdating>()
.AddSingleton<DesignChanged>()
.AddSingleton<AutomationChanged>()
.AddSingleton<StateChanged>()
.AddSingleton<WeaponLoading>()
.AddSingleton<HeadGearVisibilityChanged>()
@ -74,11 +78,15 @@ public static class ServiceManager
.AddSingleton<WeaponService>()
.AddSingleton<PenumbraService>()
.AddSingleton<ObjectManager>()
.AddSingleton<PenumbraAutoRedraw>();
.AddSingleton<PenumbraAutoRedraw>()
.AddSingleton<JobService>();
private static IServiceCollection AddDesigns(this IServiceCollection services)
=> services.AddSingleton<DesignManager>()
.AddSingleton<DesignFileSystem>();
.AddSingleton<DesignFileSystem>()
.AddSingleton<AutoDesignManager>()
.AddSingleton<AutoDesignApplier>()
.AddSingleton<FixedDesignMigrator>();
private static IServiceCollection AddState(this IServiceCollection services)
=> services.AddSingleton<StateManager>()
@ -94,6 +102,7 @@ public static class ServiceManager
.AddSingleton<MainWindow>()
.AddSingleton<GlamourerWindowSystem>()
.AddSingleton<CustomizationDrawer>()
.AddSingleton<EquipmentDrawer>()
.AddSingleton<DesignFileSystemSelector>()
.AddSingleton<DesignPanel>()
.AddSingleton<DesignTab>()