more potential crash fixes + gpose fix

This commit is contained in:
rootdarkarchon
2023-02-15 23:51:55 +01:00
parent eed44f090d
commit 6457a1fe9a
9 changed files with 94 additions and 61 deletions

View File

@@ -454,13 +454,13 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable
if (objectKind == ObjectKind.Player) if (objectKind == ObjectKind.Player)
{ {
Logger.Debug($"Restoring Customization for {PlayerCharacter}: {_originalGlamourerData}"); Logger.Debug($"Restoring Customization for {OnlineUser.User.AliasOrUID}/{PlayerName}: {_originalGlamourerData}");
_ipcManager.GlamourerApplyOnlyCustomization(_originalGlamourerData, PlayerCharacter); _ipcManager.GlamourerApplyOnlyCustomization(_originalGlamourerData, PlayerCharacter);
Logger.Debug($"Restoring Equipment for {PlayerCharacter}: {_lastGlamourerData}"); Logger.Debug($"Restoring Equipment for {OnlineUser.User.AliasOrUID}/{PlayerName}: {_lastGlamourerData}");
_ipcManager.GlamourerApplyOnlyEquipment(_lastGlamourerData, PlayerCharacter); _ipcManager.GlamourerApplyOnlyEquipment(_lastGlamourerData, PlayerCharacter);
Logger.Debug("Restoring Heels"); Logger.Debug($"Restoring Heels for {OnlineUser.User.AliasOrUID}/{PlayerName}");
_ipcManager.HeelsRestoreOffsetForPlayer(PlayerCharacter); _ipcManager.HeelsRestoreOffsetForPlayer(PlayerCharacter);
Logger.Debug("Restoring C+"); Logger.Debug($"Restoring C+ for {OnlineUser.User.AliasOrUID}/{PlayerName}");
_ipcManager.CustomizePlusRevert(PlayerCharacter); _ipcManager.CustomizePlusRevert(PlayerCharacter);
_ipcManager.PalettePlusRemovePalette(PlayerCharacter); _ipcManager.PalettePlusRemovePalette(PlayerCharacter);
} }

View File

@@ -140,7 +140,7 @@ public class IpcManager : MediatorSubscriberBase, IDisposable
_dalamudUtil = dalamudUtil; _dalamudUtil = dalamudUtil;
Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => HandleActionQueue()); Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => HandleActionQueue());
Mediator.Subscribe<GposeFrameworkUpdateMessage>(this, (_) => HandleGposeActionQueue()); Mediator.Subscribe<CutsceneFrameworkUpdateMessage>(this, (_) => HandleGposeActionQueue());
Mediator.Subscribe<ZoneSwitchEndMessage>(this, (_) => ClearActionQueue()); Mediator.Subscribe<ZoneSwitchEndMessage>(this, (_) => ClearActionQueue());
Mediator.Subscribe<DelayedFrameworkUpdateMessage>(this, (_) => PeriodicApiStateCheck()); Mediator.Subscribe<DelayedFrameworkUpdateMessage>(this, (_) => PeriodicApiStateCheck());
} }

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors></Authors> <Authors></Authors>
<Company></Company> <Company></Company>
<Version>0.7.27</Version> <Version>0.7.28</Version>
<Description></Description> <Description></Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl> <PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>

View File

@@ -14,9 +14,11 @@ public record ClassJobChangedMessage : IMessage;
public record DelayedFrameworkUpdateMessage : IMessage; public record DelayedFrameworkUpdateMessage : IMessage;
public record ZoneSwitchStartMessage : IMessage; public record ZoneSwitchStartMessage : IMessage;
public record ZoneSwitchEndMessage : IMessage; public record ZoneSwitchEndMessage : IMessage;
public record CutsceneStartMessage : IMessage;
public record GposeStartMessage : IMessage; public record GposeStartMessage : IMessage;
public record GposeEndMessage : IMessage; public record GposeEndMessage : IMessage;
public record GposeFrameworkUpdateMessage : IMessage; public record CutsceneEndMessage : IMessage;
public record CutsceneFrameworkUpdateMessage : IMessage;
public record ConnectedMessage : IMessage; public record ConnectedMessage : IMessage;
public record DisconnectedMessage : IMessage; public record DisconnectedMessage : IMessage;
public record PenumbraModSettingChangedMessage : IMessage; public record PenumbraModSettingChangedMessage : IMessage;

View File

@@ -56,27 +56,44 @@ public class GameObjectHandler : MediatorSubscriberBase
}); });
} }
Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => FrameworkUpdate());
Mediator.Subscribe<ZoneSwitchEndMessage>(this, (_) => ZoneSwitchEnd());
Mediator.Subscribe<ZoneSwitchStartMessage>(this, (_) => ZoneSwitchStart());
Mediator.Subscribe<CutsceneStartMessage>(this, (_) =>
{
Mediator.Unsubscribe<ZoneSwitchStartMessage>(this);
Mediator.Unsubscribe<FrameworkUpdateMessage>(this);
});
Mediator.Subscribe<CutsceneEndMessage>(this, (_) =>
{
Mediator.Subscribe<ZoneSwitchStartMessage>(this, (_) => ZoneSwitchStart());
Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => FrameworkUpdate());
});
}
private void FrameworkUpdate()
{ {
if (_delayedZoningTask?.IsCompleted ?? true) if (_delayedZoningTask?.IsCompleted ?? true)
{ {
CheckAndUpdateObject(); CheckAndUpdateObject();
} }
}); }
Mediator.Subscribe<ZoneSwitchEndMessage>(this, (_) => private void ZoneSwitchEnd()
{ {
if (!watchedObject) return; if (!_sendUpdates) return;
_clearCts?.Cancel(); _clearCts?.Cancel();
_clearCts?.Dispose(); _clearCts?.Dispose();
_clearCts = null; _clearCts = null;
_zoningCts.CancelAfter(2500); _zoningCts.CancelAfter(2500);
}); }
Mediator.Subscribe<ZoneSwitchStartMessage>(this, (_) => private void ZoneSwitchStart()
{ {
if (!watchedObject) return; if (!_sendUpdates) return;
_zoningCts = new(); _zoningCts = new();
Logger.Debug("Starting Delay After Zoning for " + ObjectKind + " " + Name); Logger.Debug("Starting Delay After Zoning for " + ObjectKind + " " + Name);
@@ -93,7 +110,6 @@ public class GameObjectHandler : MediatorSubscriberBase
_zoningCts.Dispose(); _zoningCts.Dispose();
} }
}); });
});
} }
public byte[] EquipSlotData { get; set; } = new byte[40]; public byte[] EquipSlotData { get; set; } = new byte[40];

View File

@@ -86,8 +86,8 @@ public class CompactUi : WindowMediatorSubscriberBase, IDisposable
Mediator.Subscribe<SwitchToMainUiMessage>(this, (_) => IsOpen = true); Mediator.Subscribe<SwitchToMainUiMessage>(this, (_) => IsOpen = true);
Mediator.Subscribe<SwitchToIntroUiMessage>(this, (_) => IsOpen = false); Mediator.Subscribe<SwitchToIntroUiMessage>(this, (_) => IsOpen = false);
Mediator.Subscribe<GposeStartMessage>(this, (_) => UiShared_GposeStart()); Mediator.Subscribe<CutsceneStartMessage>(this, (_) => UiShared_GposeStart());
Mediator.Subscribe<GposeEndMessage>(this, (_) => UiShared_GposeEnd()); Mediator.Subscribe<CutsceneEndMessage>(this, (_) => UiShared_GposeEnd());
SizeConstraints = new WindowSizeConstraints() SizeConstraints = new WindowSizeConstraints()
{ {

View File

@@ -56,8 +56,8 @@ public class SettingsUi : WindowMediatorSubscriberBase, IDisposable
Mediator.Subscribe<OpenSettingsUiMessage>(this, (_) => Toggle()); Mediator.Subscribe<OpenSettingsUiMessage>(this, (_) => Toggle());
Mediator.Subscribe<SwitchToIntroUiMessage>(this, (_) => IsOpen = false); Mediator.Subscribe<SwitchToIntroUiMessage>(this, (_) => IsOpen = false);
Mediator.Subscribe<GposeStartMessage>(this, (_) => UiShared_GposeStart()); Mediator.Subscribe<CutsceneStartMessage>(this, (_) => UiShared_GposeStart());
Mediator.Subscribe<GposeEndMessage>(this, (_) => UiShared_GposeEnd()); Mediator.Subscribe<CutsceneEndMessage>(this, (_) => UiShared_GposeEnd());
Mediator.Subscribe<CharacterDataCreatedMessage>(this, (msg) => LastCreatedCharacterData = ((CharacterDataCreatedMessage)msg).CharacterData.ToAPI()); Mediator.Subscribe<CharacterDataCreatedMessage>(this, (msg) => LastCreatedCharacterData = ((CharacterDataCreatedMessage)msg).CharacterData.ToAPI());
windowSystem.AddWindow(this); windowSystem.AddWindow(this);

View File

@@ -45,7 +45,7 @@ public partial class UiShared : MediatorSubscriberBase
public bool EditTrackerPosition { get; set; } public bool EditTrackerPosition { get; set; }
public ImFontPtr UidFont { get; private set; } public ImFontPtr UidFont { get; private set; }
public bool UidFontBuilt { get; private set; } public bool UidFontBuilt { get; private set; }
public bool IsInGpose => _dalamudUtil.IsInGpose; public bool IsInGpose => _dalamudUtil.IsInCutscene;
public static bool CtrlPressed() => (GetKeyState(0xA2) & 0x8000) != 0 || (GetKeyState(0xA3) & 0x8000) != 0; public static bool CtrlPressed() => (GetKeyState(0xA2) & 0x8000) != 0 || (GetKeyState(0xA3) & 0x8000) != 0;
public static bool ShiftPressed() => (GetKeyState(0xA1) & 0x8000) != 0 || (GetKeyState(0xA0) & 0x8000) != 0; public static bool ShiftPressed() => (GetKeyState(0xA1) & 0x8000) != 0 || (GetKeyState(0xA0) & 0x8000) != 0;

View File

@@ -16,12 +16,13 @@ public class DalamudUtil : IDisposable
private readonly ClientState _clientState; private readonly ClientState _clientState;
private readonly ObjectTable _objectTable; private readonly ObjectTable _objectTable;
private readonly Framework _framework; private readonly Framework _framework;
private readonly Dalamud.Game.ClientState.Conditions.Condition _condition; private readonly Condition _condition;
private readonly MareMediator _mediator; private readonly MareMediator _mediator;
private uint? _classJobId = 0; private uint? _classJobId = 0;
private DateTime _delayedFrameworkUpdateCheck = DateTime.Now; private DateTime _delayedFrameworkUpdateCheck = DateTime.Now;
private bool _sentBetweenAreas = false; private bool _sentBetweenAreas = false;
public bool IsInCutscene { get; private set; } = false;
public bool IsInGpose { get; private set; } = false; public bool IsInGpose { get; private set; } = false;
public unsafe bool IsGameObjectPresent(IntPtr key) public unsafe bool IsGameObjectPresent(IntPtr key)
@@ -38,8 +39,7 @@ public class DalamudUtil : IDisposable
} }
public DalamudUtil(ClientState clientState, ObjectTable objectTable, Framework framework, public DalamudUtil(ClientState clientState, ObjectTable objectTable, Framework framework,
Dalamud.Game.ClientState.Conditions.Condition condition, Condition condition, Dalamud.Data.DataManager gameData, MareMediator mediator)
Dalamud.Data.DataManager gameData, MareMediator mediator)
{ {
_clientState = clientState; _clientState = clientState;
_objectTable = objectTable; _objectTable = objectTable;
@@ -76,7 +76,25 @@ public class DalamudUtil : IDisposable
_mediator.Publish(new GposeEndMessage()); _mediator.Publish(new GposeEndMessage());
} }
if (_condition[ConditionFlag.BetweenAreas] || _condition[ConditionFlag.BetweenAreas51] || IsInGpose) if (_condition[ConditionFlag.WatchingCutscene] && !IsInCutscene)
{
Logger.Debug("Cutscene start");
IsInCutscene = true;
_mediator.Publish(new CutsceneStartMessage());
_mediator.Publish(new HaltScanMessage("Cutscene"));
}
else if (!_condition[ConditionFlag.WatchingCutscene] && IsInCutscene)
{
Logger.Debug("Cutscene end");
IsInCutscene = false;
_mediator.Publish(new CutsceneEndMessage());
_mediator.Publish(new ResumeScanMessage("Cutscene"));
}
if (IsInCutscene) { _mediator.Publish(new CutsceneFrameworkUpdateMessage()); return; }
if (_condition[ConditionFlag.BetweenAreas] || _condition[ConditionFlag.BetweenAreas51])
{ {
if (!_sentBetweenAreas) if (!_sentBetweenAreas)
{ {
@@ -86,8 +104,6 @@ public class DalamudUtil : IDisposable
_mediator.Publish(new HaltScanMessage("Zone switch")); _mediator.Publish(new HaltScanMessage("Zone switch"));
} }
if (IsInGpose) _mediator.Publish(new GposeFrameworkUpdateMessage());
return; return;
} }
@@ -234,16 +250,21 @@ public class DalamudUtil : IDisposable
try try
{ {
// ReSharper disable once LoopVariableIsNeverChangedInsideLoop // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
while ((!ct?.IsCancellationRequested ?? true) var stillDrawing = _framework.RunOnFrameworkThread(() => ((obj->GetDrawObject() == null
&& curWaitTime < timeOut
&& (((obj->GetDrawObject() == null
|| ((CharacterBase*)obj->GetDrawObject())->HasModelInSlotLoaded != 0 || ((CharacterBase*)obj->GetDrawObject())->HasModelInSlotLoaded != 0
|| ((CharacterBase*)obj->GetDrawObject())->HasModelFilesInSlotLoaded != 0)) || ((CharacterBase*)obj->GetDrawObject())->HasModelFilesInSlotLoaded != 0))
|| ((obj->RenderFlags & 0b100000000000) == 0b100000000000))) // 0b100000000000 is "still rendering" or something || ((obj->RenderFlags & 0b100000000000) == 0b100000000000)).Result;
while ((!ct?.IsCancellationRequested ?? true)
&& curWaitTime < timeOut
&& stillDrawing) // 0b100000000000 is "still rendering" or something
{ {
Logger.Verbose($"Waiting for {name} to finish drawing"); Logger.Verbose($"Waiting for {name} to finish drawing");
curWaitTime += tick; curWaitTime += tick;
Thread.Sleep(tick); Thread.Sleep(tick);
stillDrawing = _framework.RunOnFrameworkThread(() => ((obj->GetDrawObject() == null
|| ((CharacterBase*)obj->GetDrawObject())->HasModelInSlotLoaded != 0
|| ((CharacterBase*)obj->GetDrawObject())->HasModelFilesInSlotLoaded != 0))
|| ((obj->RenderFlags & 0b100000000000) == 0b100000000000)).Result;
} }
} }
catch (NullReferenceException ex) catch (NullReferenceException ex)
@@ -256,12 +277,6 @@ public class DalamudUtil : IDisposable
} }
} }
public unsafe void DisableDraw(IntPtr characterAddress)
{
var obj = (GameObject*)characterAddress;
obj->DisableDraw();
}
public unsafe void WaitWhileGposeCharacterIsDrawing(IntPtr characterAddress, int timeOut = 5000) public unsafe void WaitWhileGposeCharacterIsDrawing(IntPtr characterAddress, int timeOut = 5000)
{ {
Thread.Sleep(500); Thread.Sleep(500);