-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,904 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace HsReconnectTool | ||
{ | ||
class Constants | ||
{ | ||
public const String HsProcessName = "Hearthstone"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Windows.Forms; | ||
|
||
namespace HsReconnectTool | ||
{ | ||
class HsHelper | ||
{ | ||
static Process[] GetHsProcesses() | ||
{ | ||
return Process.GetProcessesByName(Constants.HsProcessName); | ||
} | ||
static List<iphlpapi.MIB_TCPROW_OWNER_PID> GetHsConnections(Process[] processes) | ||
{ | ||
var pids = new HashSet<uint>(); | ||
foreach (var p in processes) | ||
pids.Add((uint)p.Id); | ||
|
||
List<iphlpapi.MIB_TCPROW_OWNER_PID> connections = iphlpapi.GetAllTCPConnections(); | ||
connections = connections.Where(c => pids.Contains(c.ProcessId)).ToList(); | ||
|
||
foreach (var c in connections) | ||
{ | ||
Console.WriteLine(c.ToString()); | ||
} | ||
|
||
return connections; | ||
} | ||
|
||
public static HsState GetHsState() | ||
{ | ||
Process[] processes = GetHsProcesses(); | ||
List<iphlpapi.MIB_TCPROW_OWNER_PID> connections = GetHsConnections(processes); | ||
return new HsState(processes, connections); | ||
} | ||
public static void CloseConnectionsToServer() | ||
{ | ||
HsState state = GetHsState(); | ||
foreach(var c in state.Connections) | ||
{ | ||
if (IPAddress.IsLoopback(c.LocalAddress) || IPAddress.IsLoopback(c.RemoteAddress)) | ||
continue; | ||
if (c.dwLocalAddr == 0 || c.dwRemoteAddr == 0) | ||
continue; | ||
|
||
|
||
Console.WriteLine("Closing connection. {0}", c); | ||
String error = iphlpapi.CloseRemoteIP(c.ToTcpRow()); | ||
if (null != error) | ||
MessageBox.Show(String.Format("Cannot close connection {0}\r\nError: {1}", c, error)); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{DC7CB814-A6C4-471F-93A5-375803E1365E}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<RootNamespace>HsReconnectTool</RootNamespace> | ||
<AssemblyName>HsReconnectTool</AssemblyName> | ||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<Deterministic>true</Deterministic> | ||
<PublishUrl>publish\</PublishUrl> | ||
<Install>true</Install> | ||
<InstallFrom>Disk</InstallFrom> | ||
<UpdateEnabled>false</UpdateEnabled> | ||
<UpdateMode>Foreground</UpdateMode> | ||
<UpdateInterval>7</UpdateInterval> | ||
<UpdateIntervalUnits>Days</UpdateIntervalUnits> | ||
<UpdatePeriodically>false</UpdatePeriodically> | ||
<UpdateRequired>false</UpdateRequired> | ||
<MapFileExtensions>true</MapFileExtensions> | ||
<ApplicationRevision>0</ApplicationRevision> | ||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> | ||
<IsWebBootstrapper>false</IsWebBootstrapper> | ||
<UseApplicationTrust>false</UseApplicationTrust> | ||
<BootstrapperEnabled>true</BootstrapperEnabled> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ApplicationManifest>app.manifest</ApplicationManifest> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ApplicationIcon>icon.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Deployment" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Constants.cs" /> | ||
<Compile Include="HsHelper.cs" /> | ||
<Compile Include="HsState.cs" /> | ||
<Compile Include="iphlpapi.cs" /> | ||
<Compile Include="MainWindow.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="MainWindow.Designer.cs"> | ||
<DependentUpon>MainWindow.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<EmbeddedResource Include="MainWindow.resx"> | ||
<DependentUpon>MainWindow.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
<SubType>Designer</SubType> | ||
</EmbeddedResource> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
<None Include="app.manifest" /> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<BootstrapperPackage Include=".NETFramework,Version=v4.8"> | ||
<Visible>False</Visible> | ||
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName> | ||
<Install>true</Install> | ||
</BootstrapperPackage> | ||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> | ||
<Visible>False</Visible> | ||
<ProductName>.NET Framework 3.5 SP1</ProductName> | ||
<Install>false</Install> | ||
</BootstrapperPackage> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="icon.ico" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30523.141 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HsReconnectTool", "HsReconnectTool.csproj", "{DC7CB814-A6C4-471F-93A5-375803E1365E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DC7CB814-A6C4-471F-93A5-375803E1365E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DC7CB814-A6C4-471F-93A5-375803E1365E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DC7CB814-A6C4-471F-93A5-375803E1365E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DC7CB814-A6C4-471F-93A5-375803E1365E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {457EF42B-2259-4A95-90C7-63502471A80C} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Net; | ||
namespace HsReconnectTool | ||
{ | ||
class HsState | ||
{ | ||
Process[] processes; | ||
List<iphlpapi.MIB_TCPROW_OWNER_PID> connections; | ||
|
||
public HsState(Process[] _processes, List<iphlpapi.MIB_TCPROW_OWNER_PID> _connections) | ||
{ | ||
processes = _processes; | ||
connections = _connections; | ||
} | ||
|
||
public bool IsRunning | ||
{ | ||
get | ||
{ | ||
return processes.Length > 0; | ||
} | ||
} | ||
public int ProcessCount | ||
{ | ||
get | ||
{ | ||
return processes.Length; | ||
} | ||
} | ||
public int ConnectionCount | ||
{ | ||
get | ||
{ | ||
return connections.Count; | ||
} | ||
} | ||
public List<iphlpapi.MIB_TCPROW_OWNER_PID> Connections | ||
{ | ||
get | ||
{ | ||
return connections; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.