forked from Mercury/2dxAutoClip
replaced WebClient with HttpClient, refactored ffmpeg and apploopback downloads to be async tasks, added regex rules for demo loop
This commit is contained in:
parent
b5327f1574
commit
807945aed9
|
@ -7,8 +7,7 @@ using NAudio.Wave;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace _2dxAutoClip;
|
namespace _2dxAutoClip;
|
||||||
#pragma warning disable CA1416
|
|
||||||
#pragma warning disable SYSLIB0014
|
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
@ -30,9 +29,9 @@ class Program
|
||||||
|
|
||||||
private static async Task Main(string[] args)
|
private static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
DownloadFFmpeg();
|
await DownloadFFmpeg();
|
||||||
LoadSettingsFromPropFile();
|
LoadSettingsFromPropFile();
|
||||||
FetchAppLB();
|
await FetchAppLB();
|
||||||
_encoder = GetHardwareEncoder();
|
_encoder = GetHardwareEncoder();
|
||||||
var gameProcesses = Process.GetProcessesByName(_gameProcessName);
|
var gameProcesses = Process.GetProcessesByName(_gameProcessName);
|
||||||
if (gameProcesses.Length > 0)
|
if (gameProcesses.Length > 0)
|
||||||
|
@ -45,7 +44,7 @@ class Program
|
||||||
Console.WriteLine($"Unable to find {_gameProcessName}. Is the game running and TickerHook enabled?");
|
Console.WriteLine($"Unable to find {_gameProcessName}. Is the game running and TickerHook enabled?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void DownloadFFmpeg()
|
private static async Task DownloadFFmpeg()
|
||||||
{
|
{
|
||||||
const string ffmpegExe = "ffmpeg.exe";
|
const string ffmpegExe = "ffmpeg.exe";
|
||||||
const string ffmpegUrl = "https://tfm2.mercurio.moe/ffmpeg.exe";
|
const string ffmpegUrl = "https://tfm2.mercurio.moe/ffmpeg.exe";
|
||||||
|
@ -53,25 +52,32 @@ class Program
|
||||||
if (File.Exists(ffmpegExe))
|
if (File.Exists(ffmpegExe))
|
||||||
{
|
{
|
||||||
Console.WriteLine("FFmpeg already exists.");
|
Console.WriteLine("FFmpeg already exists.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
Console.WriteLine("FFmpeg not found. Downloading...");
|
||||||
|
|
||||||
|
using (HttpClient client = new HttpClient())
|
||||||
{
|
{
|
||||||
Console.WriteLine("FFmpeg not found. Downloading...");
|
using (HttpResponseMessage response = await client.GetAsync(ffmpegUrl))
|
||||||
using (WebClient client = new WebClient())
|
|
||||||
{
|
{
|
||||||
client.DownloadFile(ffmpegUrl, ffmpegExe);
|
response.EnsureSuccessStatusCode();
|
||||||
|
byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();
|
||||||
|
await File.WriteAllBytesAsync(ffmpegExe, fileBytes);
|
||||||
}
|
}
|
||||||
Console.WriteLine("FFmpeg downloaded successfully.");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Error downloading FFmpeg: {ex.Message}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("FFmpeg downloaded successfully.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error downloading FFmpeg: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void FetchAppLB()
|
|
||||||
|
private static async Task FetchAppLB()
|
||||||
{
|
{
|
||||||
const string applbBinary = "applb.exe";
|
const string applbBinary = "applb.exe";
|
||||||
const string applburl = "https://tfm2.mercurio.moe/applb.exe";
|
const string applburl = "https://tfm2.mercurio.moe/applb.exe";
|
||||||
|
@ -79,22 +85,26 @@ class Program
|
||||||
if (File.Exists(applbBinary))
|
if (File.Exists(applbBinary))
|
||||||
{
|
{
|
||||||
Console.WriteLine("AppLB already exists.");
|
Console.WriteLine("AppLB already exists.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
Console.WriteLine("AppLB not found. Downloading...");
|
||||||
|
using (HttpClient client = new HttpClient())
|
||||||
{
|
{
|
||||||
Console.WriteLine("AppLB not found. Downloading...");
|
var response = await client.GetAsync(applburl);
|
||||||
using (WebClient client = new WebClient())
|
response.EnsureSuccessStatusCode();
|
||||||
{
|
|
||||||
client.DownloadFile(applburl, applbBinary);
|
await using var fileStream = new FileStream(applbBinary, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||||
}
|
await using var httpStream = await response.Content.ReadAsStreamAsync();
|
||||||
Console.WriteLine("AppLB downloaded successfully.");
|
await httpStream.CopyToAsync(fileStream);
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Error downloading AppLB: {ex.Message}");
|
|
||||||
}
|
}
|
||||||
|
Console.WriteLine("AppLB downloaded successfully.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error downloading AppLB: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static int GetFirstProcessIdByName(string executableName)
|
public static int GetFirstProcessIdByName(string executableName)
|
||||||
|
@ -232,6 +242,12 @@ class Program
|
||||||
var message = Encoding.UTF8.GetString(buffer, 0, result.Count).Trim().ToUpper();
|
var message = Encoding.UTF8.GetString(buffer, 0, result.Count).Trim().ToUpper();
|
||||||
Console.WriteLine($"[TickerHook] Received message: {message}");
|
Console.WriteLine($"[TickerHook] Received message: {message}");
|
||||||
|
|
||||||
|
if (Regex.IsMatch(message, "^WELCOME TO BEATMANIA.*") || message.Contains("DEMO PLAY"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("[TickerHook] Ignoring excluded message.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (message == lastMessage && !message.Contains("SELECT FROM"))
|
if (message == lastMessage && !message.Contains("SELECT FROM"))
|
||||||
{
|
{
|
||||||
consecutiveMessageCount++;
|
consecutiveMessageCount++;
|
||||||
|
@ -269,6 +285,7 @@ class Program
|
||||||
return !reconnecting;
|
return !reconnecting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void StartRecording(string songName)
|
private static void StartRecording(string songName)
|
||||||
{
|
{
|
||||||
if (_sysaudio == true)
|
if (_sysaudio == true)
|
||||||
|
|
Loading…
Reference in a new issue