Skip to content

Commit

Permalink
AutoHook 2.2.2.5 [PUSH]
Browse files Browse the repository at this point in the history
Added #19
  • Loading branch information
InitialDet committed Aug 15, 2022
1 parent 2feb915 commit 6df5e13
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion AutoHook/AutoHook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Det</Authors>
<Version>2.2.2.4</Version>
<Version>2.2.2.5</Version>
<Description>Auto hooks for you</Description>
<PackageProjectUrl>https://github.com/InitialDet/AutoHook</PackageProjectUrl>
<Configurations>Release;Debug</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion AutoHook/AutoHook.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"Tags": ["Gathering","Fishing"],
"DalamudApiLevel": 6,
"IconUrl": "https://raw.githubusercontent.com/InitialDet/AutoHook/main/AutoHook/images/icon.png",
"Changelog": "- Trying to add support for CN server \n- Fixing problems with collectable fish\n- Added a new option to use Double/Triple Hooks only when Identical Cast is Enabled"
"Changelog": "- Added an experimental anti-AFK prevention\n- Trying to add support for CN server \n- Fixing problems with collectable fish\n- Added a new option to use Double/Triple Hooks only when Identical Cast is Enabled"
}
11 changes: 11 additions & 0 deletions AutoHook/HookManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ private void UnSubscribeToParser()
// The current config is updates two times: When we began fishing (to get the config based on the mooch/bait) and when we hooked the fish (in case the user updated their configs).
private void UpdateCurrentSetting()
{
ResetAFKTimer();

if (CurrentSetting == null)
CurrentSetting = HookSettings.FirstOrDefault(mooch => mooch.BaitName.Equals(CurrentBait));

Expand Down Expand Up @@ -302,6 +304,15 @@ private void CheckMaxTimeLimit()
}
}

public static void ResetAFKTimer()
{
if (!InputUtil.TryFindGameWindow(out var windowHandle)) return;

// Virtual key for Right Winkey. Can't be used by FFXIV normally, and in tests did not seem to cause any
// unusual interference.
InputUtil.SendKeycode(windowHandle, 0x5C);
}

private static double debugValueLast = 3000;
private Stopwatch Timerrr = new();
private void CheckState()
Expand Down
43 changes: 43 additions & 0 deletions AutoHook/Utils/InputUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace AutoHook.Utils;

internal static class InputUtil
{
private const uint WM_KEYUP = 0x101;
private const uint WM_KEYDOWN = 0x100;

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpszClass, string? lpszWindow);

[DllImport("user32.dll")]
private static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);

[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);

public static bool TryFindGameWindow(out IntPtr hwnd)
{
hwnd = IntPtr.Zero;
while (true)
{
hwnd = FindWindowEx(IntPtr.Zero, hwnd, "FFXIVGAME", null);
if (hwnd == IntPtr.Zero) break;
GetWindowThreadProcessId(hwnd, out var pid);
if (pid == Process.GetCurrentProcess().Id) break;
}
return hwnd != IntPtr.Zero;
}

public static void SendKeycode(IntPtr hwnd, int keycode)
{
SendMessage(hwnd, WM_KEYDOWN, (IntPtr)keycode, (IntPtr)0);
SendMessage(hwnd, WM_KEYUP, (IntPtr)keycode, (IntPtr)0);
}
}

0 comments on commit 6df5e13

Please sign in to comment.