Skip to content

Commit 5899f75

Browse files
author
siegrest
committedFeb 3, 2018
Initial commit
0 parents  commit 5899f75

16 files changed

+1039
-0
lines changed
 

‎.gitignore

+261
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.userosscache
8+
*.sln.docstates
9+
10+
# User-specific files (MonoDevelop/Xamarin Studio)
11+
*.userprefs
12+
13+
# Build results
14+
[Dd]ebug/
15+
[Dd]ebugPublic/
16+
[Rr]elease/
17+
[Rr]eleases/
18+
x64/
19+
x86/
20+
bld/
21+
[Bb]in/
22+
[Oo]bj/
23+
[Ll]og/
24+
25+
# Visual Studio 2015 cache/options directory
26+
.vs/
27+
# Uncomment if you have tasks that create the project's static files in wwwroot
28+
#wwwroot/
29+
30+
# MSTest test Results
31+
[Tt]est[Rr]esult*/
32+
[Bb]uild[Ll]og.*
33+
34+
# NUNIT
35+
*.VisualState.xml
36+
TestResult.xml
37+
38+
# Build Results of an ATL Project
39+
[Dd]ebugPS/
40+
[Rr]eleasePS/
41+
dlldata.c
42+
43+
# DNX
44+
project.lock.json
45+
project.fragment.lock.json
46+
artifacts/
47+
48+
*_i.c
49+
*_p.c
50+
*_i.h
51+
*.ilk
52+
*.meta
53+
*.obj
54+
*.pch
55+
*.pdb
56+
*.pgc
57+
*.pgd
58+
*.rsp
59+
*.sbr
60+
*.tlb
61+
*.tli
62+
*.tlh
63+
*.tmp
64+
*.tmp_proj
65+
*.log
66+
*.vspscc
67+
*.vssscc
68+
.builds
69+
*.pidb
70+
*.svclog
71+
*.scc
72+
73+
# Chutzpah Test files
74+
_Chutzpah*
75+
76+
# Visual C++ cache files
77+
ipch/
78+
*.aps
79+
*.ncb
80+
*.opendb
81+
*.opensdf
82+
*.sdf
83+
*.cachefile
84+
*.VC.db
85+
*.VC.VC.opendb
86+
87+
# Visual Studio profiler
88+
*.psess
89+
*.vsp
90+
*.vspx
91+
*.sap
92+
93+
# TFS 2012 Local Workspace
94+
$tf/
95+
96+
# Guidance Automation Toolkit
97+
*.gpState
98+
99+
# ReSharper is a .NET coding add-in
100+
_ReSharper*/
101+
*.[Rr]e[Ss]harper
102+
*.DotSettings.user
103+
104+
# JustCode is a .NET coding add-in
105+
.JustCode
106+
107+
# TeamCity is a build add-in
108+
_TeamCity*
109+
110+
# DotCover is a Code Coverage Tool
111+
*.dotCover
112+
113+
# NCrunch
114+
_NCrunch_*
115+
.*crunch*.local.xml
116+
nCrunchTemp_*
117+
118+
# MightyMoose
119+
*.mm.*
120+
AutoTest.Net/
121+
122+
# Web workbench (sass)
123+
.sass-cache/
124+
125+
# Installshield output folder
126+
[Ee]xpress/
127+
128+
# DocProject is a documentation generator add-in
129+
DocProject/buildhelp/
130+
DocProject/Help/*.HxT
131+
DocProject/Help/*.HxC
132+
DocProject/Help/*.hhc
133+
DocProject/Help/*.hhk
134+
DocProject/Help/*.hhp
135+
DocProject/Help/Html2
136+
DocProject/Help/html
137+
138+
# Click-Once directory
139+
publish/
140+
141+
# Publish Web Output
142+
*.[Pp]ublish.xml
143+
*.azurePubxml
144+
# TODO: Comment the next line if you want to checkin your web deploy settings
145+
# but database connection strings (with potential passwords) will be unencrypted
146+
#*.pubxml
147+
*.publishproj
148+
149+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
150+
# checkin your Azure Web App publish settings, but sensitive information contained
151+
# in these scripts will be unencrypted
152+
PublishScripts/
153+
154+
# NuGet Packages
155+
*.nupkg
156+
# The packages folder can be ignored because of Package Restore
157+
**/packages/*
158+
# except build/, which is used as an MSBuild target.
159+
!**/packages/build/
160+
# Uncomment if necessary however generally it will be regenerated when needed
161+
#!**/packages/repositories.config
162+
# NuGet v3's project.json files produces more ignoreable files
163+
*.nuget.props
164+
*.nuget.targets
165+
166+
# Microsoft Azure Build Output
167+
csx/
168+
*.build.csdef
169+
170+
# Microsoft Azure Emulator
171+
ecf/
172+
rcf/
173+
174+
# Windows Store app package directories and files
175+
AppPackages/
176+
BundleArtifacts/
177+
Package.StoreAssociation.xml
178+
_pkginfo.txt
179+
180+
# Visual Studio cache files
181+
# files ending in .cache can be ignored
182+
*.[Cc]ache
183+
# but keep track of directories ending in .cache
184+
!*.[Cc]ache/
185+
186+
# Others
187+
ClientBin/
188+
~$*
189+
*~
190+
*.dbmdl
191+
*.dbproj.schemaview
192+
*.jfm
193+
*.pfx
194+
*.publishsettings
195+
node_modules/
196+
orleans.codegen.cs
197+
198+
# Since there are multiple workflows, uncomment next line to ignore bower_components
199+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200+
#bower_components/
201+
202+
# RIA/Silverlight projects
203+
Generated_Code/
204+
205+
# Backup & report files from converting an old project file
206+
# to a newer Visual Studio version. Backup files are not needed,
207+
# because we have git ;-)
208+
_UpgradeReport_Files/
209+
Backup*/
210+
UpgradeLog*.XML
211+
UpgradeLog*.htm
212+
213+
# SQL Server files
214+
*.mdf
215+
*.ldf
216+
217+
# Business Intelligence projects
218+
*.rdl.data
219+
*.bim.layout
220+
*.bim_*.settings
221+
222+
# Microsoft Fakes
223+
FakesAssemblies/
224+
225+
# GhostDoc plugin setting file
226+
*.GhostDoc.xml
227+
228+
# Node.js Tools for Visual Studio
229+
.ntvs_analysis.dat
230+
231+
# Visual Studio 6 build log
232+
*.plg
233+
234+
# Visual Studio 6 workspace options file
235+
*.opt
236+
237+
# Visual Studio LightSwitch build output
238+
**/*.HTMLClient/GeneratedArtifacts
239+
**/*.DesktopClient/GeneratedArtifacts
240+
**/*.DesktopClient/ModelManifest.xml
241+
**/*.Server/GeneratedArtifacts
242+
**/*.Server/ModelManifest.xml
243+
_Pvt_Extensions
244+
245+
# Paket dependency manager
246+
.paket/paket.exe
247+
paket-files/
248+
249+
# FAKE - F# Make
250+
.fake/
251+
252+
# JetBrains Rider
253+
.idea/
254+
*.sln.iml
255+
256+
# CodeRush
257+
.cr/
258+
259+
# Python Tools for Visual Studio (PTVS)
260+
__pycache__/
261+
*.pyc

‎LICENCE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎LogOut.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27130.2020
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogOut", "LogOut\LogOut.csproj", "{DE691B50-F14E-4D76-96E8-883B5399C067}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{DE691B50-F14E-4D76-96E8-883B5399C067}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{DE691B50-F14E-4D76-96E8-883B5399C067}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{DE691B50-F14E-4D76-96E8-883B5399C067}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{DE691B50-F14E-4D76-96E8-883B5399C067}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {FAEA3126-051F-4856-B228-DA17461B50D9}
24+
EndGlobalSection
25+
EndGlobal

‎LogOut/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>

‎LogOut/App.xaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="LogOut.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:LogOut"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

‎LogOut/App.xaml.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace LogOut {
10+
/// <summary>
11+
/// Interaction logic for App.xaml
12+
/// </summary>
13+
public partial class App : Application {
14+
}
15+
}

‎LogOut/KeyboardHook.cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Runtime.InteropServices;
4+
5+
namespace LogOut {
6+
public static class KeyboardHook {
7+
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
8+
public static event EventHandler KeyBoardAction;
9+
private static LowLevelKeyboardProc _proc = HookCallback;
10+
private static IntPtr _hookID = IntPtr.Zero;
11+
private const int WH_KEYBOARD_LL = 13;
12+
private const int WM_KEYDOWN = 0x100;
13+
public static int KEY;
14+
public static volatile bool flag_saveKey = false;
15+
16+
public static void Start() { _hookID = SetHook(_proc); }
17+
public static void Stop() { UnhookWindowsHookEx(_hookID); }
18+
19+
private static IntPtr SetHook(LowLevelKeyboardProc proc) {
20+
using (Process curProcess = Process.GetCurrentProcess())
21+
using (ProcessModule curModule = curProcess.MainModule) {
22+
return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
23+
}
24+
}
25+
26+
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) {
27+
if (nCode >= 0 && wParam == (IntPtr) WM_KEYDOWN) {
28+
if (flag_saveKey) KEY = Marshal.ReadInt32(lParam);
29+
if (Marshal.ReadInt32(lParam) == KEY) KeyBoardAction?.Invoke(null, new EventArgs());
30+
}
31+
32+
return CallNextHookEx(_hookID, nCode, wParam, lParam);
33+
}
34+
35+
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
36+
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
37+
38+
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
39+
[return: MarshalAs(UnmanagedType.Bool)]
40+
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
41+
42+
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
43+
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
44+
45+
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
46+
private static extern IntPtr GetModuleHandle(string lpModuleName);
47+
}
48+
}

‎LogOut/LogOut.csproj

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{DE691B50-F14E-4D76-96E8-883B5399C067}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>LogOut</RootNamespace>
10+
<AssemblyName>LogOut</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<PlatformTarget>AnyCPU</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<PropertyGroup>
37+
<StartupObject>LogOut.App</StartupObject>
38+
</PropertyGroup>
39+
<PropertyGroup>
40+
<ApplicationIcon>
41+
</ApplicationIcon>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Reference Include="System" />
45+
<Reference Include="System.Data" />
46+
<Reference Include="System.Drawing" />
47+
<Reference Include="System.Xml" />
48+
<Reference Include="Microsoft.CSharp" />
49+
<Reference Include="System.Core" />
50+
<Reference Include="System.Xml.Linq" />
51+
<Reference Include="System.Data.DataSetExtensions" />
52+
<Reference Include="System.Net.Http" />
53+
<Reference Include="System.Xaml">
54+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
55+
</Reference>
56+
<Reference Include="WindowsBase" />
57+
<Reference Include="PresentationCore" />
58+
<Reference Include="PresentationFramework" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<ApplicationDefinition Include="App.xaml">
62+
<Generator>MSBuild:Compile</Generator>
63+
<SubType>Designer</SubType>
64+
</ApplicationDefinition>
65+
<Page Include="MainWindow.xaml">
66+
<Generator>MSBuild:Compile</Generator>
67+
<SubType>Designer</SubType>
68+
</Page>
69+
<Compile Include="App.xaml.cs">
70+
<DependentUpon>App.xaml</DependentUpon>
71+
<SubType>Code</SubType>
72+
</Compile>
73+
<Compile Include="MainWindow.xaml.cs">
74+
<DependentUpon>MainWindow.xaml</DependentUpon>
75+
<SubType>Code</SubType>
76+
</Compile>
77+
</ItemGroup>
78+
<ItemGroup>
79+
<Compile Include="KeyboardHook.cs" />
80+
<Compile Include="Properties\AssemblyInfo.cs">
81+
<SubType>Code</SubType>
82+
</Compile>
83+
<Compile Include="Properties\Resources.Designer.cs">
84+
<AutoGen>True</AutoGen>
85+
<DesignTime>True</DesignTime>
86+
<DependentUpon>Resources.resx</DependentUpon>
87+
</Compile>
88+
<Compile Include="Properties\Settings.Designer.cs">
89+
<AutoGen>True</AutoGen>
90+
<DependentUpon>Settings.settings</DependentUpon>
91+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
92+
</Compile>
93+
<EmbeddedResource Include="Properties\Resources.resx">
94+
<Generator>ResXFileCodeGenerator</Generator>
95+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
96+
</EmbeddedResource>
97+
<None Include="Properties\Settings.settings">
98+
<Generator>SettingsSingleFileGenerator</Generator>
99+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
100+
</None>
101+
</ItemGroup>
102+
<ItemGroup>
103+
<None Include="App.config" />
104+
</ItemGroup>
105+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
106+
</Project>

‎LogOut/MainWindow.xaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Window x:Class="LogOut.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:LogOut"
7+
mc:Ignorable="d" Height="200" Width="525" Closing="Window_Closing">
8+
<Grid>
9+
<Button x:Name="Button_SetKey" Content="Set hotkey" HorizontalAlignment="Left" Margin="10,99,0,0" VerticalAlignment="Top" Width="77" Click="Button_SetKey_Click" IsEnabled="False"/>
10+
<TextBox x:Name="TextBox_Console" TextWrapping="Wrap" VerticalAlignment="Top" AllowDrop="False" VerticalScrollBarVisibility="Visible" IsReadOnly="True" IsUndoEnabled="False" FontFamily="Consolas" Height="64" Margin="10"/>
11+
<CheckBox x:Name="CheckBox_Minimized" Content="Work minimized" HorizontalAlignment="Left" Margin="10,79,0,0" VerticalAlignment="Top" IsEnabled="False"/>
12+
13+
</Grid>
14+
</Window>

‎LogOut/MainWindow.xaml.cs

+254
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Runtime.InteropServices;
4+
using System.Windows;
5+
using System.Linq;
6+
using System.Security.Principal;
7+
8+
namespace LogOut {
9+
/// <summary>
10+
/// Interaction logic for MainWindow.xaml
11+
/// </summary>
12+
public partial class MainWindow : Window {
13+
private EventHandler eventHandler;
14+
private IntPtr client_hWnd;
15+
private uint processId;
16+
private const string GAME_WINDOW_TITLE = "Path of Exile";
17+
private const string APP_WINDOW_TITLE = "TCP Disconnect v0.1";
18+
19+
/// <summary>
20+
/// Utility methods for getting handles and stuffs
21+
/// </summary>
22+
sealed class Win128 {
23+
[DllImport("user32.dll", SetLastError = true)]
24+
static public extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
25+
26+
[DllImport("user32.dll")]
27+
private static extern IntPtr GetForegroundWindow();
28+
29+
[DllImport("user32.dll")]
30+
private static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder text, int count);
31+
32+
public static string GetTopmostWindowTitle() {
33+
int nChars = 256;
34+
35+
System.Text.StringBuilder Buff = new System.Text.StringBuilder(nChars);
36+
IntPtr handle = GetForegroundWindow();
37+
38+
if (GetWindowText(handle, Buff, nChars) > 0)
39+
return Buff.ToString();
40+
else
41+
return null;
42+
}
43+
44+
public static bool checkElevation() {
45+
using (WindowsIdentity identity = WindowsIdentity.GetCurrent()) {
46+
WindowsPrincipal principal = new WindowsPrincipal(identity);
47+
return principal.IsInRole(WindowsBuiltInRole.Administrator);
48+
}
49+
}
50+
}
51+
52+
/// <summary>
53+
/// Made by from /u/Umocrajen
54+
/// </summary>
55+
sealed class KillTCP {
56+
[DllImport("iphlpapi.dll", SetLastError = true)]
57+
private static extern uint GetExtendedTcpTable(IntPtr pTcpTable, ref int dwOutBufLen, bool sort, int ipVersion, TcpTableClass tblClass, uint reserved = 0);
58+
59+
[DllImport("iphlpapi.dll")]
60+
private static extern int SetTcpEntry(IntPtr pTcprow);
61+
62+
[StructLayout(LayoutKind.Sequential)]
63+
public struct MibTcprowOwnerPid {
64+
public uint state;
65+
public uint localAddr;
66+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] localPort;
67+
public uint remoteAddr;
68+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] remotePort;
69+
public uint owningPid;
70+
}
71+
72+
[StructLayout(LayoutKind.Sequential)]
73+
public struct MibTcptableOwnerPid {
74+
public uint dwNumEntries;
75+
private readonly MibTcprowOwnerPid table;
76+
}
77+
78+
private enum TcpTableClass {
79+
TcpTableBasicListener,
80+
TcpTableBasicConnections,
81+
TcpTableBasicAll,
82+
TcpTableOwnerPidListener,
83+
TcpTableOwnerPidConnections,
84+
TcpTableOwnerPidAll,
85+
TcpTableOwnerModuleListener,
86+
TcpTableOwnerModuleConnections,
87+
TcpTableOwnerModuleAll
88+
}
89+
90+
public static void KillTCPConnectionForProcess(uint ProcessId) {
91+
MibTcprowOwnerPid[] table;
92+
var afInet = 2;
93+
var buffSize = 0;
94+
var ret = GetExtendedTcpTable(IntPtr.Zero, ref buffSize, true, afInet, TcpTableClass.TcpTableOwnerPidAll);
95+
var buffTable = Marshal.AllocHGlobal(buffSize);
96+
97+
try {
98+
uint statusCode = GetExtendedTcpTable(buffTable, ref buffSize, true, afInet, TcpTableClass.TcpTableOwnerPidAll);
99+
if (statusCode != 0) return;
100+
101+
var tab = (MibTcptableOwnerPid) Marshal.PtrToStructure(buffTable, typeof(MibTcptableOwnerPid));
102+
var rowPtr = (IntPtr)((long)buffTable + Marshal.SizeOf(tab.dwNumEntries));
103+
table = new MibTcprowOwnerPid[tab.dwNumEntries];
104+
105+
for (var i = 0; i < tab.dwNumEntries; i++) {
106+
var tcpRow = (MibTcprowOwnerPid)Marshal.PtrToStructure(rowPtr, typeof(MibTcprowOwnerPid));
107+
table[i] = tcpRow;
108+
rowPtr = (IntPtr)((long)rowPtr + Marshal.SizeOf(tcpRow));
109+
}
110+
111+
} finally {
112+
Marshal.FreeHGlobal(buffTable);
113+
}
114+
115+
// Kill Path Connection
116+
var PathConnection = table.FirstOrDefault(t => t.owningPid == ProcessId);
117+
PathConnection.state = 12;
118+
var ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(PathConnection));
119+
Marshal.StructureToPtr(PathConnection, ptr, false);
120+
SetTcpEntry(ptr);
121+
}
122+
}
123+
124+
/// <summary>
125+
/// Initialize elements
126+
/// </summary>
127+
public MainWindow() {
128+
InitializeComponent();
129+
130+
// Set window title
131+
Title = APP_WINDOW_TITLE;
132+
133+
// Warn user on no admin rights
134+
if (!Win128.checkElevation()) Log("TCP disconnect will not function without elevated access", 1);
135+
136+
// Print credentials
137+
Log(APP_WINDOW_TITLE + " by Siegrest", 0);
138+
139+
// Hook
140+
eventHandler = new EventHandler(Event_keyboard);
141+
KeyboardHook.KeyBoardAction += eventHandler;
142+
KeyboardHook.Start();
143+
144+
// Run task to find application handle
145+
Log("Waiting for PoE process", 0);
146+
System.Threading.Tasks.Task.Run(() => FindGameTask());
147+
}
148+
149+
/// <summary>
150+
/// Get application's handler and PID
151+
/// </summary>
152+
private void FindGameTask() {
153+
// Run every 100ms and attempt to find game client
154+
while (true) {
155+
System.Threading.Thread.Sleep(1000);
156+
157+
// Get process handler from name
158+
foreach (Process pList in Process.GetProcesses()) {
159+
if (pList.MainWindowTitle == GAME_WINDOW_TITLE) client_hWnd = pList.MainWindowHandle;
160+
}
161+
if (client_hWnd == null) continue;
162+
163+
// Get window PID from handler
164+
Win128.GetWindowThreadProcessId(client_hWnd, out processId);
165+
if (processId <= 0) continue;
166+
167+
break;
168+
}
169+
170+
// Invoke dispatcher, allowing UI element updates
171+
Dispatcher.Invoke(new Action(() => {
172+
Button_SetKey.IsEnabled = true;
173+
CheckBox_Minimized.IsEnabled = true;
174+
Log("PoE process found", 0);
175+
}));
176+
}
177+
178+
/// <summary>
179+
/// Keyboard event handler. Fires when "registred hotkey" is pressed
180+
/// </summary>
181+
/// <param name="sender"></param>
182+
/// <param name="e"></param>
183+
private void Event_keyboard(object sender, EventArgs e) {
184+
if (KeyboardHook.flag_saveKey) {
185+
KeyboardHook.flag_saveKey = false;
186+
Button_SetKey.IsEnabled = true;
187+
Log("Assigned TCP disconnect to key: " + KeyboardHook.KEY, 0);
188+
return;
189+
}
190+
191+
// Don't send disconnect if game is minimized and checkbox is not ticked
192+
if (!(bool)CheckBox_Minimized.IsChecked) {
193+
if (Win128.GetTopmostWindowTitle() != GAME_WINDOW_TITLE) return;
194+
}
195+
196+
// Send disconnect signal
197+
long time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
198+
Log("Closing TCP connections...", 0);
199+
KillTCP.KillTCPConnectionForProcess(processId);
200+
time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - time;
201+
Log("Closed connections (took " + time + " ms)", 0);
202+
}
203+
204+
/// <summary>
205+
/// Event handler that closes hooks on program exit
206+
/// </summary>
207+
/// <param name="sender"></param>
208+
/// <param name="e"></param>
209+
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
210+
KeyboardHook.KeyBoardAction -= eventHandler;
211+
KeyboardHook.Stop();
212+
}
213+
214+
/// <summary>
215+
/// Event handler that flips a flag
216+
/// </summary>
217+
/// <param name="sender"></param>
218+
/// <param name="e"></param>
219+
private void Button_SetKey_Click(object sender, RoutedEventArgs e) {
220+
Log("Press any key...", 0);
221+
Button_SetKey.IsEnabled = false;
222+
KeyboardHook.flag_saveKey = true;
223+
}
224+
225+
/// <summary>
226+
/// Timestamp and prefix local console messages
227+
/// </summary>
228+
/// <param name="str"></param>
229+
/// <param name="status"></param>
230+
private void Log(string str, int status) {
231+
string prefix;
232+
233+
switch (status) {
234+
default:
235+
case 0:
236+
prefix = "[INFO] ";
237+
break;
238+
case 1:
239+
prefix = "[WARN] ";
240+
break;
241+
case 2:
242+
prefix = "[ERROR] ";
243+
break;
244+
case 3:
245+
prefix = "[CRITICAL] ";
246+
break;
247+
}
248+
249+
string time = string.Format("{0:HH:mm:ss}", DateTime.Now);
250+
TextBox_Console.AppendText("[" + time + "]" + prefix + str + "\n");
251+
TextBox_Console.ScrollToEnd();
252+
}
253+
}
254+
}

‎LogOut/Properties/AssemblyInfo.cs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyTitle("LogOut")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("LogOut")]
15+
[assembly: AssemblyCopyright("Copyright © 2018")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
// You can specify all the values or you can default the Build and Revision Numbers
52+
// by using the '*' as shown below:
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

‎LogOut/Properties/Resources.Designer.cs

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎LogOut/Properties/Resources.resx

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:element name="root" msdata:IsDataSet="true">
64+
<xsd:complexType>
65+
<xsd:choice maxOccurs="unbounded">
66+
<xsd:element name="metadata">
67+
<xsd:complexType>
68+
<xsd:sequence>
69+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
70+
</xsd:sequence>
71+
<xsd:attribute name="name" type="xsd:string" />
72+
<xsd:attribute name="type" type="xsd:string" />
73+
<xsd:attribute name="mimetype" type="xsd:string" />
74+
</xsd:complexType>
75+
</xsd:element>
76+
<xsd:element name="assembly">
77+
<xsd:complexType>
78+
<xsd:attribute name="alias" type="xsd:string" />
79+
<xsd:attribute name="name" type="xsd:string" />
80+
</xsd:complexType>
81+
</xsd:element>
82+
<xsd:element name="data">
83+
<xsd:complexType>
84+
<xsd:sequence>
85+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
86+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
87+
</xsd:sequence>
88+
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
89+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
90+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
91+
</xsd:complexType>
92+
</xsd:element>
93+
<xsd:element name="resheader">
94+
<xsd:complexType>
95+
<xsd:sequence>
96+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
97+
</xsd:sequence>
98+
<xsd:attribute name="name" type="xsd:string" use="required" />
99+
</xsd:complexType>
100+
</xsd:element>
101+
</xsd:choice>
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:schema>
105+
<resheader name="resmimetype">
106+
<value>text/microsoft-resx</value>
107+
</resheader>
108+
<resheader name="version">
109+
<value>2.0</value>
110+
</resheader>
111+
<resheader name="reader">
112+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
113+
</resheader>
114+
<resheader name="writer">
115+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
</root>

‎LogOut/Properties/Settings.Designer.cs

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎LogOut/Properties/Settings.settings

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
3+
<Profiles>
4+
<Profile Name="(Default)" />
5+
</Profiles>
6+
<Settings />
7+
</SettingsFile>

‎README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Path of Exile TCP disconnect
2+
3+
## What does it do?
4+
Incredibly quickly logs a character out of the game
5+
6+
## Who is it for?
7+
People who don't want to mess with AutoHotkey
8+
9+
## Sweet. Where can I get one?
10+
Head on over to the [releases](https://github.com/siegrest/LogOut/releases/latest) page and grab the latest version.
11+
12+
## Word of warning
13+
Elevated access (admin privileges) is required to close TCP connections.

0 commit comments

Comments
 (0)
Please sign in to comment.