Skip to content

Commit f043bf8

Browse files
committed
Integrate Hassel changes
1 parent 44ad1f1 commit f043bf8

13 files changed

Lines changed: 466 additions & 634 deletions

PrefPro/ActuallyRawPayload.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

PrefPro/CodeUtil.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.

PrefPro/Configuration.cs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Dalamud.Configuration;
22
using System;
33
using System.Collections.Generic;
4-
using Dalamud.Game.ClientState.Objects.Enums;
54
using Newtonsoft.Json;
65
using PrefPro.Settings;
76

@@ -24,7 +23,7 @@ public struct ConfigHolder
2423
public TribeSetting Tribe;
2524
}
2625

27-
public Dictionary<ulong, ConfigHolder> Configs { get; set; } = new Dictionary<ulong, ConfigHolder>();
26+
public Dictionary<ulong, ConfigHolder> Configs { get; set; } = new();
2827

2928
[JsonIgnore]
3029
public bool Enabled
@@ -34,7 +33,7 @@ public bool Enabled
3433
{
3534
var config = GetOrDefault();
3635
config.Enabled = value;
37-
Configs[_prefPro.CurrentPlayerContentId] = config;
36+
Configs[PlayerApi.ContentId] = config;
3837
}
3938
}
4039
[JsonIgnore]
@@ -45,7 +44,7 @@ public string Name
4544
{
4645
var config = GetOrDefault();
4746
config.Name = value;
48-
Configs[_prefPro.CurrentPlayerContentId] = config;
47+
Configs[PlayerApi.ContentId] = config;
4948
}
5049
}
5150
[JsonIgnore]
@@ -56,7 +55,7 @@ public NameSetting FullName
5655
{
5756
var config = GetOrDefault();
5857
config.FullName = value;
59-
Configs[_prefPro.CurrentPlayerContentId] = config;
58+
Configs[PlayerApi.ContentId] = config;
6059
}
6160
}
6261
[JsonIgnore]
@@ -67,7 +66,7 @@ public NameSetting FirstName
6766
{
6867
var config = GetOrDefault();
6968
config.FirstName = value;
70-
Configs[_prefPro.CurrentPlayerContentId] = config;
69+
Configs[PlayerApi.ContentId] = config;
7170
}
7271
}
7372
[JsonIgnore]
@@ -78,7 +77,7 @@ public NameSetting LastName
7877
{
7978
var config = GetOrDefault();
8079
config.LastName = value;
81-
Configs[_prefPro.CurrentPlayerContentId] = config;
80+
Configs[PlayerApi.ContentId] = config;
8281
}
8382
}
8483
[JsonIgnore]
@@ -89,7 +88,7 @@ public GenderSetting Gender
8988
{
9089
var config = GetOrDefault();
9190
config.Gender = value;
92-
Configs[_prefPro.CurrentPlayerContentId] = config;
91+
Configs[PlayerApi.ContentId] = config;
9392
}
9493
}
9594
[JsonIgnore]
@@ -100,7 +99,7 @@ public RaceSetting Race
10099
{
101100
var config = GetOrDefault();
102101
config.Race = value;
103-
Configs[_prefPro.CurrentPlayerContentId] = config;
102+
Configs[PlayerApi.ContentId] = config;
104103
}
105104
}
106105
[JsonIgnore]
@@ -111,25 +110,20 @@ public TribeSetting Tribe
111110
{
112111
var config = GetOrDefault();
113112
config.Tribe = value;
114-
Configs[_prefPro.CurrentPlayerContentId] = config;
113+
Configs[PlayerApi.ContentId] = config;
115114
}
116115
}
117116

118117
public int GetGender()
119118
{
120-
switch (Gender)
119+
return Gender switch
121120
{
122-
case GenderSetting.Male:
123-
return 0;
124-
case GenderSetting.Female:
125-
return 1;
126-
case GenderSetting.Random:
127-
var ret = new Random().Next(0, 2);
128-
return ret;
129-
case GenderSetting.Model:
130-
return _prefPro.PlayerGender;
131-
}
132-
return 0;
121+
GenderSetting.Male => 0,
122+
GenderSetting.Female => 1,
123+
GenderSetting.Random => Random.Shared.Next(0, 2),
124+
// Model is PlayerApi.Sex as well
125+
_ => PlayerApi.Sex,
126+
};
133127
}
134128

135129
[NonSerialized] private PrefPro _prefPro;
@@ -141,12 +135,12 @@ public void Initialize(PrefPro prefPro)
141135

142136
public ConfigHolder GetOrDefault()
143137
{
144-
bool result = Configs.TryGetValue(_prefPro.CurrentPlayerContentId, out var holder);
138+
bool result = Configs.TryGetValue(PlayerApi.ContentId, out var holder);
145139
if (!result)
146140
{
147141
var ch = new ConfigHolder
148142
{
149-
Name = _prefPro.PlayerName ?? "",
143+
Name = PlayerApi.CharacterName,
150144
FullName = NameSetting.FirstLast,
151145
FirstName = NameSetting.FirstOnly,
152146
LastName = NameSetting.LastOnly,

PrefPro/DalamudApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class DalamudApi
2323
// [PluginService] public static IFlyTextGui FlyTextGui { get; private set; } = null;
2424
[PluginService] public static IFramework Framework { get; private set; } = null;
2525
// [PluginService] public static IGameGui GameGui { get; private set; } = null;
26+
[PluginService] public static IGameConfig GameConfig { get; private set; } = null;
2627
// [PluginService] public static IGameNetwork GameNetwork { get; private set; } = null;
2728
// [PluginService] public static IGamepadState GamePadState { get; private set; } = null;
2829
// [PluginService] public static IJobGauges JobGauges { get; private set; } = null;

PrefPro/GenderHandler.cs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace PrefPro;
77

88
public sealed unsafe class GenderHandler: IDisposable
99
{
10-
private delegate int GetCutVoGenderPrototype(void* a1, void* a2);
10+
private delegate int GetCutVoGenderPrototype(nint a1, nint a2);
1111
private readonly Hook<GetCutVoGenderPrototype>? _getCutVoGenderHook;
1212

13-
private delegate int GetCutVoLangPrototype(void* a1);
13+
private delegate int GetCutVoLangPrototype(nint a1);
1414
private readonly GetCutVoLangPrototype? _getCutVoLang;
1515

1616
private delegate byte GetLuaVarPrototype(nint poolBase, nint a2, nint a3);
@@ -102,34 +102,23 @@ private void SetLuaVarGender(nint poolBase, int gender)
102102
*(int*)(poolBase + 4 * genderVarId) = gender;
103103
}
104104

105-
private int GetCutVoGenderDetour(void* a1, void* a2)
105+
private int GetCutVoGenderDetour(nint a1, nint a2)
106106
{
107-
var originalRet = _getCutVoGenderHook!.Original(a1, a2);
108-
// DalamudApi.PluginLog.Verbose($"[GetCutVoGenderDetour] original returned {originalRet}");
107+
var originalRet = _getCutVoGenderHook.Original(a1, a2);
109108

110109
if (!_configuration.Enabled)
111110
return originalRet;
112111

113-
var lang = GetCutVoLang();
114-
// DalamudApi.PluginLog.Verbose($"[GetCutVoGenderDetour] Lang returned {lang}");
112+
// see Client::System::Framework::EnvironmentManager.GetCutsceneLanguage
113+
var lang = (uint)Framework.Instance()->EnvironmentManager->CutsceneMovieVoice;
114+
if (lang == uint.MaxValue)
115+
lang = DalamudApi.GameConfig.System.GetUInt("CutsceneMovieVoice");
116+
if (lang == uint.MaxValue)
117+
lang = DalamudApi.GameConfig.System.GetUInt("Language");
115118

116-
var v1 = *(int*) ((ulong)a2 + 28);
117-
var v2 = 12 * lang;
118-
var v3 = *(int*) ((ulong)a2 + (ulong)v1 + (ulong)v2);
119+
if (*(int*)(a2 + *(int*)(a2 + 0x1C) + (12 * lang)) != 1)
120+
return _configuration.GetGender();
119121

120-
if (v3 == 1)
121-
{
122-
// DalamudApi.PluginLog.Verbose($"[GetCutVoGenderDetour] v3 is 1");
123-
return 0;
124-
}
125-
126-
return _configuration.GetGender();
127-
}
128-
129-
private int GetCutVoLang()
130-
{
131-
// var offs = *(void**) ((nint)Framework.Instance() + (int) _frameworkLangCallOffset);
132-
// DalamudApi.PluginLog.Verbose($"[GetCutVoLang] {(ulong) offs} {(ulong) offs:X}");
133-
return _getCutVoLang!(Framework.Instance()->EnvironmentManager);
122+
return 0;
134123
}
135124
}

PrefPro/LoginState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private unsafe void OnLogin()
2626
if (LoggedIn) return;
2727

2828
var playerState = PlayerState.Instance();
29-
if (playerState->IsLoaded == 1) {
29+
if (playerState->IsLoaded) {
3030
var name = playerState->CharacterNameString;
3131
if (name.Length > 0) {
3232
PlayerName = name;

PrefPro/LuaHandler.cs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ public unsafe class LuaHandler : IDisposable
1212
private Hook<LuaFunction>? _getSex;
1313
private Hook<LuaFunction>? _getTribe;
1414

15-
private byte* _luaRacePtr;
16-
private byte* _luaSexPtr;
17-
private byte* _luaTribePtr;
18-
1915
private bool _initialized = false;
2016

2117
private readonly Configuration _configuration;
@@ -73,18 +69,10 @@ private void Initialize()
7369
_getSex = DalamudApi.Hooks.HookFromAddress<LuaFunction>(sexFunctionAddress, SexFunctionDetour);
7470
_getTribe = DalamudApi.Hooks.HookFromAddress<LuaFunction>(tribeFunctionAddress, TribeFunctionDetour);
7571

76-
_luaRacePtr = (byte*)CodeUtil.GetStaticAddressFromPtr(raceFunctionAddress + 0x32);
77-
_luaSexPtr = (byte*)CodeUtil.GetStaticAddressFromPtr(sexFunctionAddress + 0x32);
78-
_luaTribePtr = (byte*)CodeUtil.GetStaticAddressFromPtr(tribeFunctionAddress + 0x32);
79-
8072
DalamudApi.PluginLog.Debug($"[LuaHandler] Race function address: {raceFunctionAddress:X}");
8173
DalamudApi.PluginLog.Debug($"[LuaHandler] Sex function address: {sexFunctionAddress:X}");
8274
DalamudApi.PluginLog.Debug($"[LuaHandler] Tribe function address: {tribeFunctionAddress:X}");
8375

84-
DalamudApi.PluginLog.Debug($"[LuaHandler] Race data address: {(nint) _luaRacePtr:X}");
85-
DalamudApi.PluginLog.Debug($"[LuaHandler] Sex data address: {(nint) _luaSexPtr:X}");
86-
DalamudApi.PluginLog.Debug($"[LuaHandler] Tribe data address: {(nint) _luaTribePtr:X}");
87-
8876
_initialized = true;
8977
}
9078

@@ -102,11 +90,11 @@ private nuint RaceFunctionDetour(nuint a1)
10290
{
10391
try
10492
{
105-
var oldRace = *_luaRacePtr;
106-
*_luaRacePtr = (byte)_configuration.Race;
93+
var oldRace = PlayerApi.Race;
94+
PlayerApi.Race = (byte)_configuration.Race;
10795
DalamudApi.PluginLog.Debug($"[RaceFunctionDetour] oldRace: {oldRace} race: {(byte)_configuration.Race}");
10896
var ret = _getRace!.Original(a1);
109-
*_luaRacePtr = oldRace;
97+
PlayerApi.Race = oldRace;
11098
return ret;
11199
}
112100
catch (Exception e)
@@ -120,11 +108,11 @@ private nuint SexFunctionDetour(nuint a1)
120108
{
121109
try
122110
{
123-
var oldSex = *_luaSexPtr;
124-
*_luaSexPtr = (byte)_configuration.GetGender();
111+
var oldSex = PlayerApi.Sex;
112+
PlayerApi.Sex = (byte)_configuration.GetGender();
125113
DalamudApi.PluginLog.Debug($"[SexFunctionDetour] oldSex: {oldSex} sex: {(byte)_configuration.GetGender()}");
126114
var ret = _getSex!.Original(a1);
127-
*_luaSexPtr = oldSex;
115+
PlayerApi.Sex = oldSex;
128116
return ret;
129117
}
130118
catch (Exception e)
@@ -138,11 +126,11 @@ private nuint TribeFunctionDetour(nuint a1)
138126
{
139127
try
140128
{
141-
var oldTribe = *_luaTribePtr;
142-
*_luaTribePtr = (byte)_configuration.Tribe;
129+
var oldTribe = PlayerApi.Tribe;
130+
PlayerApi.Tribe = (byte)_configuration.Tribe;
143131
DalamudApi.PluginLog.Debug($"[TribeFunctionDetour] oldTribe: {oldTribe} sex: {(byte)_configuration.Tribe}");
144132
var ret = _getTribe!.Original(a1);
145-
*_luaTribePtr = oldTribe;
133+
PlayerApi.Tribe = oldTribe;
146134
return ret;
147135
}
148136
catch (Exception e)

PrefPro/PlayerApi.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using FFXIVClientStructs.FFXIV.Client.Game.UI;
2+
3+
namespace PrefPro;
4+
5+
public static unsafe class PlayerApi
6+
{
7+
public static string CharacterName => PlayerState.Instance()->CharacterNameString;
8+
public static ref ulong ContentId => ref PlayerState.Instance()->ContentId;
9+
public static ref byte Sex => ref PlayerState.Instance()->Sex;
10+
public static ref byte Race => ref PlayerState.Instance()->Race;
11+
public static ref byte Tribe => ref PlayerState.Instance()->Tribe;
12+
}

0 commit comments

Comments
 (0)