Simple changes for 6.1

This commit is contained in:
Ottermandias 2022-04-14 21:59:30 +02:00
parent b141da40b0
commit e6e033bb8b
8 changed files with 539 additions and 529 deletions

View file

@ -2,11 +2,11 @@
using Lumina.Excel;
using Lumina.Excel.GeneratedSheets;
namespace Glamourer.Customization
namespace Glamourer.Customization;
[Sheet("CharaMakeParams")]
public class CharaMakeParams : ExcelRow
{
[Sheet("CharaMakeParams")]
public class CharaMakeParams : ExcelRow
{
public const int NumMenus = 28;
public const int NumVoices = 12;
public const int NumGraphics = 10;
@ -51,7 +51,7 @@ namespace Glamourer.Customization
public Menu[] Menus { get; set; } = new Menu[NumMenus];
public byte[] Voices { get; set; } = new byte[NumVoices];
public FacialFeatures[] FacialFeatureByFace { get; set; } = new FacialFeatures[NumFaces];
public CharaMakeType.CharaMakeTypeUnkData3347Obj[] Equip { get; set; } = new CharaMakeType.CharaMakeTypeUnkData3347Obj[NumEquip];
public CharaMakeType.UnkData3347Obj[] Equip { get; set; } = new CharaMakeType.UnkData3347Obj[NumEquip];
public override void PopulateData(RowParser parser, Lumina.GameData gameData, Language language)
{
@ -64,11 +64,11 @@ namespace Glamourer.Customization
{
Menus[i].Id = parser.ReadColumn<uint>(3 + 0 * NumMenus + i);
Menus[i].InitVal = parser.ReadColumn<byte>(3 + 1 * NumMenus + i);
Menus[i].Type = (MenuType) parser.ReadColumn<byte>(3 + 2 * NumMenus + i);
Menus[i].Type = (MenuType)parser.ReadColumn<byte>(3 + 2 * NumMenus + i);
Menus[i].Size = parser.ReadColumn<byte>(3 + 3 * NumMenus + i);
Menus[i].LookAt = parser.ReadColumn<byte>(3 + 4 * NumMenus + i);
Menus[i].Mask = parser.ReadColumn<uint>(3 + 5 * NumMenus + i);
Menus[i].Customization = (CustomizationId) parser.ReadColumn<uint>(3 + 6 * NumMenus + i);
Menus[i].Customization = (CustomizationId)parser.ReadColumn<uint>(3 + 6 * NumMenus + i);
Menus[i].Values = new uint[Menus[i].Size];
switch (Menus[i].Type)
@ -95,13 +95,15 @@ namespace Glamourer.Customization
{
FacialFeatureByFace[i].Icons = new uint[NumFeatures];
for (var j = 0; j < NumFeatures; ++j)
{
FacialFeatureByFace[i].Icons[j] =
(uint) parser.ReadColumn<int>(3 + (MaxNumValues + 7 + NumGraphics) * NumMenus + NumVoices + j * NumFaces + i);
(uint)parser.ReadColumn<int>(3 + (MaxNumValues + 7 + NumGraphics) * NumMenus + NumVoices + j * NumFaces + i);
}
}
for (var i = 0; i < NumEquip; ++i)
{
Equip[i] = new CharaMakeType.CharaMakeTypeUnkData3347Obj()
Equip[i] = new CharaMakeType.UnkData3347Obj()
{
Helmet = parser.ReadColumn<ulong>(
3 + (MaxNumValues + 7 + NumGraphics) * NumMenus + NumVoices + NumFaces * NumFeatures + i * 7 + 0),
@ -120,5 +122,4 @@ namespace Glamourer.Customization
};
}
}
}
}

View file

@ -23,7 +23,7 @@ namespace Glamourer.Customization
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CharacterCustomization
{
public const int CustomizationOffset = 0xDD8;
public const int CustomizationOffset = 0x830;
public const int CustomizationBytes = 26;
public static CharacterCustomization Default = new()

View file

@ -196,7 +196,7 @@ namespace Glamourer.Customization
if (set.Faces.Count > 0)
set.SetAvailable(CustomizationId.Face);
var count = race.ToRace() == Race.Hrothgar ? set.HairStyles.Count : set.Faces.Count;
var count = set.Faces.Count;
var featureDict = new List<IReadOnlyList<Customization>>(count);
for (var i = 0; i < count; ++i)
{

View file

@ -4,14 +4,17 @@ namespace Glamourer;
public static class CharacterExtensions
{
public const int WetnessOffset = 0x19E4;
public const byte WetnessFlag = 0x08;
public const int StateFlagsOffset = 0xDF6;
public const int WetnessOffset = 0x1ADA;
public const byte WetnessFlag = 0x80;
public const int HatVisibleOffset = 0x84E;
public const int VisorToggledOffset = 0x84F;
public const byte HatHiddenFlag = 0x01;
public const byte VisorToggledFlag = 0x10;
public const int AlphaOffset = 0x18B8;
public const int WeaponHiddenOffset = 0xCD4;
public const byte WeaponHiddenFlag = 0x02;
public const byte VisorToggledFlag = 0x08;
public const int AlphaOffset = 0x19E0;
public const int WeaponHiddenOffset1 = 0x84F;
public const int WeaponHiddenOffset2 = 0x72C; // maybe
public const byte WeaponHiddenFlag1 = 0x01;
public const byte WeaponHiddenFlag2 = 0x02;
public static unsafe bool IsWet(this Character a)
=> (*((byte*)a.Address + WetnessOffset) & WetnessFlag) != 0;
@ -29,49 +32,62 @@ public static class CharacterExtensions
return true;
}
public static unsafe ref byte StateFlags(this Character a)
=> ref *((byte*)a.Address + StateFlagsOffset);
public static unsafe bool IsHatVisible(this Character a)
=> (*((byte*)a.Address + HatVisibleOffset) & HatHiddenFlag) == 0;
public static bool SetStateFlag(this Character a, bool value, byte flag)
public static unsafe bool SetHatVisible(this Character a, bool visible)
{
var current = a.StateFlags();
var previousValue = (current & flag) != 0;
if (previousValue == value)
var current = IsHatVisible(a);
if (current == visible)
return false;
if (value)
a.StateFlags() = (byte)(current | flag);
if (visible)
*((byte*)a.Address + HatVisibleOffset) = (byte)(*((byte*)a.Address + HatVisibleOffset) & ~HatHiddenFlag);
else
a.StateFlags() = (byte)(current & ~flag);
*((byte*)a.Address + HatVisibleOffset) = (byte)(*((byte*)a.Address + HatVisibleOffset) | HatHiddenFlag);
return true;
}
public static bool IsHatHidden(this Character a)
=> (a.StateFlags() & HatHiddenFlag) != 0;
public static unsafe bool IsVisorToggled(this Character a)
=> (*((byte*)a.Address + VisorToggledOffset) & VisorToggledFlag) == VisorToggledFlag;
public static unsafe bool SetVisorToggled(this Character a, bool toggled)
{
var current = IsVisorToggled(a);
if (current == toggled)
return false;
if (toggled)
*((byte*)a.Address + VisorToggledOffset) = (byte)(*((byte*)a.Address + VisorToggledOffset) | VisorToggledFlag);
else
*((byte*)a.Address + VisorToggledOffset) = (byte)(*((byte*)a.Address + VisorToggledOffset) & ~VisorToggledFlag);
return true;
}
public static unsafe bool IsWeaponHidden(this Character a)
=> (a.StateFlags() & WeaponHiddenFlag) != 0
&& (*((byte*)a.Address + WeaponHiddenOffset) & WeaponHiddenFlag) != 0;
public static bool IsVisorToggled(this Character a)
=> (a.StateFlags() & VisorToggledFlag) != 0;
public static bool SetHatHidden(this Character a, bool value)
=> SetStateFlag(a, value, HatHiddenFlag);
=> (*((byte*)a.Address + WeaponHiddenOffset1) & WeaponHiddenFlag1) == WeaponHiddenFlag1
&& (*((byte*)a.Address + WeaponHiddenOffset2) & WeaponHiddenFlag2) == WeaponHiddenFlag2;
public static unsafe bool SetWeaponHidden(this Character a, bool value)
{
var ret = SetStateFlag(a, value, WeaponHiddenFlag);
var val = *((byte*)a.Address + WeaponHiddenOffset);
if (value)
*((byte*)a.Address + WeaponHiddenOffset) = (byte)(val | WeaponHiddenFlag);
else
*((byte*)a.Address + WeaponHiddenOffset) = (byte)(val & ~WeaponHiddenFlag);
return ret || (val & WeaponHiddenFlag) != 0 != value;
}
var hidden = IsWeaponHidden(a);
if (hidden == value)
return false;
public static bool SetVisorToggled(this Character a, bool value)
=> SetStateFlag(a, value, VisorToggledFlag);
var val1 = *((byte*)a.Address + WeaponHiddenOffset1);
var val2 = *((byte*)a.Address + WeaponHiddenOffset2);
if (value)
{
*((byte*)a.Address + WeaponHiddenOffset1) = (byte)(val1 | WeaponHiddenFlag1);
*((byte*)a.Address + WeaponHiddenOffset2) = (byte)(val2 | WeaponHiddenFlag2);
}
else
{
*((byte*)a.Address + WeaponHiddenOffset1) = (byte)(val1 & ~WeaponHiddenFlag1);
*((byte*)a.Address + WeaponHiddenOffset2) = (byte)(val2 & ~WeaponHiddenFlag2);
}
return true;
}
public static unsafe ref float Alpha(this Character a)
=> ref *(float*)((byte*)a.Address + AlphaOffset);

View file

@ -8,10 +8,10 @@ using Newtonsoft.Json.Linq;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs;
namespace Glamourer
namespace Glamourer;
public class CharacterSaveConverter : JsonConverter
{
public class CharacterSaveConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
=> objectType == typeof(CharacterSave);
@ -29,15 +29,15 @@ namespace Glamourer
{
if (value != null)
{
var s = ((CharacterSave) value).ToBase64();
var s = ((CharacterSave)value).ToBase64();
serializer.Serialize(writer, s);
}
}
}
}
[JsonConverter(typeof(CharacterSaveConverter))]
public class CharacterSave
{
[JsonConverter(typeof(CharacterSaveConverter))]
public class CharacterSave
{
public const byte CurrentVersion = 2;
public const byte TotalSizeVersion1 = 1 + 1 + 2 + 56 + CharacterCustomization.CustomizationBytes;
public const byte TotalSizeVersion2 = 1 + 1 + 2 + 56 + CharacterCustomization.CustomizationBytes + 4 + 1;
@ -55,7 +55,7 @@ namespace Glamourer
public CharacterSave Copy()
{
var ret = new CharacterSave();
_bytes.CopyTo((Span<byte>) ret._bytes);
_bytes.CopyTo((Span<byte>)ret._bytes);
return ret;
}
@ -65,37 +65,37 @@ namespace Glamourer
public bool WriteCustomizations
{
get => (_bytes[1] & 0x01) != 0;
set => _bytes[1] = (byte) (value ? _bytes[1] | 0x01 : _bytes[1] & ~0x01);
set => _bytes[1] = (byte)(value ? _bytes[1] | 0x01 : _bytes[1] & ~0x01);
}
public bool IsWet
{
get => (_bytes[1] & 0x02) != 0;
set => _bytes[1] = (byte) (value ? _bytes[1] | 0x02 : _bytes[1] & ~0x02);
set => _bytes[1] = (byte)(value ? _bytes[1] | 0x02 : _bytes[1] & ~0x02);
}
public bool SetHatState
{
get => (_bytes[1] & 0x04) != 0;
set => _bytes[1] = (byte) (value ? _bytes[1] | 0x04 : _bytes[1] & ~0x04);
set => _bytes[1] = (byte)(value ? _bytes[1] | 0x04 : _bytes[1] & ~0x04);
}
public bool SetWeaponState
{
get => (_bytes[1] & 0x08) != 0;
set => _bytes[1] = (byte) (value ? _bytes[1] | 0x08 : _bytes[1] & ~0x08);
set => _bytes[1] = (byte)(value ? _bytes[1] | 0x08 : _bytes[1] & ~0x08);
}
public bool SetVisorState
{
get => (_bytes[1] & 0x10) != 0;
set => _bytes[1] = (byte) (value ? _bytes[1] | 0x10 : _bytes[1] & ~0x10);
set => _bytes[1] = (byte)(value ? _bytes[1] | 0x10 : _bytes[1] & ~0x10);
}
public bool WriteProtected
{
get => (_bytes[1] & 0x20) != 0;
set => _bytes[1] = (byte) (value ? _bytes[1] | 0x20 : _bytes[1] & ~0x20);
set => _bytes[1] = (byte)(value ? _bytes[1] | 0x20 : _bytes[1] & ~0x20);
}
public byte StateFlags
@ -107,39 +107,39 @@ namespace Glamourer
public bool HatState
{
get => (StateFlags & 0x01) == 0;
set => StateFlags = (byte) (value ? StateFlags & ~0x01 : StateFlags | 0x01);
set => StateFlags = (byte)(value ? StateFlags & ~0x01 : StateFlags | 0x01);
}
public bool VisorState
{
get => (StateFlags & 0x10) != 0;
set => StateFlags = (byte) (value ? StateFlags | 0x10 : StateFlags & ~0x10);
set => StateFlags = (byte)(value ? StateFlags | 0x10 : StateFlags & ~0x10);
}
public bool WeaponState
{
get => (StateFlags & 0x02) == 0;
set => StateFlags = (byte) (value ? StateFlags & ~0x02 : StateFlags | 0x02);
set => StateFlags = (byte)(value ? StateFlags & ~0x02 : StateFlags | 0x02);
}
public CharacterEquipMask WriteEquipment
{
get => (CharacterEquipMask) (_bytes[2] | (_bytes[3] << 8));
get => (CharacterEquipMask)(_bytes[2] | (_bytes[3] << 8));
set
{
_bytes[2] = (byte) ((ushort) value & 0xFF);
_bytes[3] = (byte) ((ushort) value >> 8);
_bytes[2] = (byte)((ushort)value & 0xFF);
_bytes[3] = (byte)((ushort)value >> 8);
}
}
private static Dictionary<EquipSlot, (int, int, bool)> Offsets()
{
var stainOffsetWeapon = (int) Marshal.OffsetOf<CharacterWeapon>("Stain");
var stainOffsetEquip = (int) Marshal.OffsetOf<CharacterArmor>("Stain");
var stainOffsetWeapon = (int)Marshal.OffsetOf<CharacterWeapon>("Stain");
var stainOffsetEquip = (int)Marshal.OffsetOf<CharacterArmor>("Stain");
(int, int, bool) ToOffsets(IntPtr offset, bool weapon)
{
var off = 4 + CharacterCustomization.CustomizationBytes + (int) offset;
var off = 4 + CharacterCustomization.CustomizationBytes + (int)offset;
return weapon ? (off, off + stainOffsetWeapon, weapon) : (off, off + stainOffsetEquip, weapon);
}
@ -168,7 +168,7 @@ namespace Glamourer
return false;
var (_, stainOffset, _) = FieldOffsets[slot];
if (_bytes[stainOffset] == (byte) stainId)
if (_bytes[stainOffset] == (byte)stainId)
return false;
_bytes[stainOffset] = stainId.Value;
@ -201,7 +201,7 @@ namespace Glamourer
}
else
{
ret |= WriteIfDifferent(ref _bytes[offset + 2], (byte) variant);
ret |= WriteIfDifferent(ref _bytes[offset + 2], (byte)variant);
}
return ret;
@ -231,17 +231,17 @@ namespace Glamourer
{
fixed (byte* ptr = &_bytes[60 + CharacterCustomization.CustomizationBytes])
{
return *(float*) ptr;
return *(float*)ptr;
}
}
set
{
fixed (byte* ptr = _bytes)
{
*(ptr + 60 + CharacterCustomization.CustomizationBytes + 0) = *((byte*) &value + 0);
*(ptr + 60 + CharacterCustomization.CustomizationBytes + 1) = *((byte*) &value + 1);
*(ptr + 60 + CharacterCustomization.CustomizationBytes + 2) = *((byte*) &value + 2);
*(ptr + 60 + CharacterCustomization.CustomizationBytes + 3) = *((byte*) &value + 3);
*(ptr + 60 + CharacterCustomization.CustomizationBytes + 0) = *((byte*)&value + 0);
*(ptr + 60 + CharacterCustomization.CustomizationBytes + 1) = *((byte*)&value + 1);
*(ptr + 60 + CharacterCustomization.CustomizationBytes + 2) = *((byte*)&value + 2);
*(ptr + 60 + CharacterCustomization.CustomizationBytes + 3) = *((byte*)&value + 3);
}
}
}
@ -277,7 +277,7 @@ namespace Glamourer
private static void CheckCharacterMask(byte val1, byte val2)
{
var mask = (CharacterEquipMask) (val1 | (val2 << 8));
var mask = (CharacterEquipMask)(val1 | (val2 << 8));
if (mask > CharacterEquipMask.All)
throw new Exception($"Can not parse Base64 string into CharacterSave:\n\tInvalid value {mask} in byte 3 and 4.");
}
@ -292,7 +292,7 @@ namespace Glamourer
SetHatState = true;
SetVisorState = true;
SetWeaponState = true;
StateFlags = a.StateFlags();
StateFlags = (byte)((a.IsHatVisible() ? 0x00 : 0x01) | (a.IsVisorToggled() ? 0x10 : 0x00) | (a.IsWeaponHidden() ? 0x02 : 0x00));
IsWet = a.IsWet();
Alpha = a.Alpha();
@ -309,20 +309,13 @@ namespace Glamourer
Equipment.Write(a.Address, WriteEquipment, WriteEquipment);
a.SetWetness(IsWet);
a.Alpha() = Alpha;
if ((_bytes[1] & 0b11100) == 0b11100)
{
a.StateFlags() = StateFlags;
}
else
{
if (SetHatState)
a.SetHatHidden(HatState);
a.SetHatVisible(!HatState);
if (SetVisorState)
a.SetVisorToggled(VisorState);
if (SetWeaponState)
a.SetWeaponHidden(WeaponState);
}
}
public void ApplyOnlyEquipment(Character a)
{
@ -383,7 +376,7 @@ namespace Glamourer
{
fixed (byte* ptr = _bytes)
{
return ref *(CharacterCustomization*) (ptr + 4);
return ref *(CharacterCustomization*)(ptr + 4);
}
}
}
@ -397,5 +390,4 @@ namespace Glamourer
return ret;
}
}
}
}

View file

@ -140,7 +140,7 @@ namespace Glamourer.Gui
ImGui.SameLine();
if (InputInt($"##text_{id}", ref current, 1, count))
{
customization[id] = set.Data(id, current).Value;
customization[id] = (byte) current;
ret = true;
}

View file

@ -277,8 +277,9 @@ namespace Glamourer.Gui
var label = $"##fsPopup{child.FullName()}";
if (ImGui.BeginPopup(label))
{
if (ImGui.MenuItem("Delete"))
if (ImGui.MenuItem("Delete") && ImGui.GetIO().KeyCtrl && ImGui.GetIO().KeyShift)
_designs.DeleteAllChildren(child, false);
ImGuiCustom.HoverTooltip("Hold Control and Shift to delete.");
RenameChildInput(child);

View file

@ -38,7 +38,7 @@ namespace Glamourer.Gui
ret |= DrawCheckMark("Hat Visible", save.HatState, v =>
{
save.HatState = v;
player?.SetHatHidden(!v);
player?.SetHatVisible(v);
});
ret |= DrawCheckMark("Weapon Visible", save.WeaponState, v =>