Skip to content

Commit

Permalink
Handle poe 2 in DockingHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
C1rdec committed Dec 4, 2024
1 parent e4a5d9e commit 79fa0f0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = file_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_prefer_primary_constructors = false:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
Expand Down
22 changes: 21 additions & 1 deletion src/PoeLurker.Core/ClientLurker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class ClientLurker : IDisposable
private readonly CancellationTokenSource _tokenSource;
private readonly Process _pathOfExileProcess;
private string _currentLeague;
private bool _poe2;

#endregion

Expand Down Expand Up @@ -73,6 +74,11 @@ public ClientLurker(int processId)

#region Events

/// <summary>
/// Occurs when the player changed the location.
/// </summary>
public event EventHandler<bool> Poe2;

/// <summary>
/// Occurs when [request admin].
/// </summary>
Expand Down Expand Up @@ -143,6 +149,7 @@ public ClientLurker(int processId)
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
Expand Down Expand Up @@ -360,14 +367,27 @@ private void OnFileChanged(string newline)
var generatingLevelEvent = GeneratingLevelEvent.TryParse(newline);
if (generatingLevelEvent != null)
{
Models.PoeApplicationContext.Poe2 = true;
if (!_poe2)
{
_poe2 = true;
Models.PoeApplicationContext.Poe2 = true;
Poe2?.Invoke(this, Models.PoeApplicationContext.Poe2);
}

GeneratingLevel?.Invoke(this, generatingLevelEvent);
return;
}

var locationEvent = LocationChangedEvent.TryParse(newline);
if (locationEvent != null)
{
if (_poe2)
{
_poe2 = false;
Models.PoeApplicationContext.Poe2 = false;
Poe2?.Invoke(this, Models.PoeApplicationContext.Poe2);
}

Models.PoeApplicationContext.Location = locationEvent.Location;
LocationChanged?.Invoke(this, locationEvent);
return;
Expand Down
12 changes: 11 additions & 1 deletion src/PoeLurker.Core/Helpers/DockingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class DockingHelper : IDisposable
private readonly IntPtr _windowHandle;
private IntPtr _currentWindowStyle;
private readonly Process _process;
private readonly ClientLurker _clientLurker;

#endregion

Expand All @@ -55,11 +56,14 @@ public class DockingHelper : IDisposable
/// </summary>
/// <param name="processId">The process identifier.</param>
/// <param name="settingsService">The settings service.</param>
public DockingHelper(int processId, SettingsService settingsService)
public DockingHelper(int processId, SettingsService settingsService, ClientLurker clientLurker)
{
_process = Process.GetProcessById(processId);
_clientLurker = clientLurker;

if (_process != null)
{
_clientLurker.Poe2 += ClientLurker_Poe2;
_myProcess = Process.GetCurrentProcess();
_tokenSource = new CancellationTokenSource();
_settingsService = settingsService;
Expand Down Expand Up @@ -153,12 +157,18 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_clientLurker.Poe2 -= ClientLurker_Poe2;
_myProcess.Dispose();
_tokenSource.Cancel();
UnhookWinEvent(_hook);
}
}

private void ClientLurker_Poe2(object sender, bool e)
{
InvokeWindowMove();
}

/// <summary>
/// Removes the window border.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/PoeLurker.UI/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private void ShowOverlays(int processId)
{
Execute.OnUIThread(() =>
{
_currentDockingHelper = new DockingHelper(processId, _settingsService);
_currentDockingHelper = new DockingHelper(processId, _settingsService, _currentLurker);

// Keyboard
var keyboarHelper = new PoeKeyboardHelper(processId);
Expand Down

0 comments on commit 79fa0f0

Please sign in to comment.