Add project files.

This commit is contained in:
2026-03-08 20:45:01 +01:00
commit 053a4052dd
45 changed files with 2578 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
using System.Diagnostics;
using System.Net.Sockets;
namespace LeagueAPI.Utils;
public static class ProcessFinder
{
public static Process GetProcess()
{
Process[] processesByName = Process.GetProcessesByName("LeagueClientUx");
return processesByName.FirstOrDefault(p => p.ProcessName == "LeagueClientUx")
?? throw new InvalidOperationException("Failed to find LCUx process.");
}
public static ProcessInfo GetProcessInfo()
{
return new ProcessInfo(GetProcess());
}
public static bool IsActive()
{
try
{
GetProcessInfo();
return true;
}
catch (InvalidOperationException)
{
return false;
}
}
public static bool IsPortOpen()
{
try
{
return IsPortOpen(GetProcessInfo());
}
catch (InvalidOperationException)
{
return false;
}
}
public static bool IsPortOpen(ProcessInfo processInfo)
{
try
{
using TcpClient tcpClient = new();
tcpClient.Connect("127.0.0.1", processInfo.AppPort);
tcpClient.Close();
return true;
}
catch (SocketException)
{
return false;
}
}
}