Skip to content

Instantly share code, notes, and snippets.

@Byteflux
Created September 27, 2024 23:14
Show Gist options
  • Save Byteflux/1a1b5181e6c0ba2965f88a2d308e8761 to your computer and use it in GitHub Desktop.
Save Byteflux/1a1b5181e6c0ba2965f88a2d308e8761 to your computer and use it in GitHub Desktop.
A simple TCP logout macro for Path of Exile using Autohotkey 2 and CurrPorts
#Requires AutoHotkey v2.0
#SingleInstance Force
LogoutHotkey := "``" ; Keybind used to trigger the logout action
ClientProcessName := "PathOfExileSteam.exe" ; Should be "PathOfExile_x64.exe" or "PathOfExileSteam.exe"
CurrPortsName := "cports.exe"
CurrPortsDownloadURL := "https://www.nirsoft.net/utils/cports-x64.zip"
TestCurrPortsPath(Path)
{
global CurrPortsName
TestPath := Path "\" CurrPortsName
return FileExist(TestPath) ? TestPath : ""
}
CurrPortsPath := ""
Loop Parse, EnvGet("Path"), ";"
{
TestPath := TestCurrPortsPath(A_LoopField)
if (TestPath)
{
CurrPortsPath := TestPath
break
}
}
if (!CurrPortsPath)
{
SplitPath CurrPortsDownloadURL, &DownloadedFileName,,, &FileNameWithoutExt
if (!DirExist(FileNameWithoutExt))
{
if (!FileExist(DownloadedFileName))
{
Download CurrPortsDownloadURL, DownloadedFileName
}
if (FileExist(DownloadedFileName))
{
RunWait 'PowerShell -Command Expand-Archive "' DownloadedFileName '" -DestinationPath "' FileNameWithoutExt '"'
}
}
CurrPortsPath := TestCurrPortsPath(FileNameWithoutExt)
if (!CurrPortsPath)
{
MsgBox "Cannot find CurrPorts (" CurrPortsName ")"
ExitApp
}
}
if (!A_IsAdmin)
{
if (InStr(DllCall("GetCommandLine", "str"), "/restart"))
{
MsgBox "This script requires administrator privileges to close connections owned by other processes."
ExitApp
}
try
{
if (A_IsCompiled)
{
Run '*RunAs "' A_ScriptFullPath '" /restart'
}
else
{
Run '*RunAs "' A_AhkPath '" /restart "' A_ScriptFullPath '"'
}
ExitApp
}
}
LogoutCallback(ThisHotkey)
{
global CurrPortsPath, ClientProcessName
Run '"' CurrPortsPath '" /close * * * 6112 "' ClientProcessName '"'
}
HotIfWinActive "ahk_class POEWindowClass"
Hotkey LogoutHotkey, LogoutCallback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment