Initial commit

A modern .NET 9 NativeAOT framework for Asheron's Call client modding.
Self-contained injection system that hooks D3D9 EndScene to render an
ImGui overlay inside the AC client process.
This commit is contained in:
tombohar 2026-04-10 18:38:07 -04:00
commit 80b71d295d
179 changed files with 52858 additions and 0 deletions

View file

@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace RynthCore.App;
internal sealed class AcClientLaunchSettingsService
{
private const string UserPreferencesFileName = "UserPreferences.ini";
private const string NetSectionName = "Net";
private const string ComputeUniquePortKey = "ComputeUniquePort";
private const string IntroVideoFileName = "turbine_logo_ac.avi";
private const string DisabledIntroVideoSuffix = ".rynthcore-disabled";
public void Apply(string acClientPath, bool allowMultipleClients, bool skipIntroVideos, Action<string>? log = null)
{
if (string.IsNullOrWhiteSpace(acClientPath) || !File.Exists(acClientPath))
return;
string gameDirectory = Path.GetDirectoryName(acClientPath) ?? string.Empty;
UpdateUserPreferences(allowMultipleClients, log);
UpdateIntroVideoState(gameDirectory, skipIntroVideos, log);
}
private static void UpdateUserPreferences(bool allowMultipleClients, Action<string>? log)
{
string documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string prefsDirectory = Path.Combine(documentsDirectory, "Asheron's Call");
string prefsPath = Path.Combine(prefsDirectory, UserPreferencesFileName);
Directory.CreateDirectory(prefsDirectory);
List<string> lines = File.Exists(prefsPath)
? File.ReadAllLines(prefsPath).ToList()
: [];
bool changed = SetIniValue(lines, NetSectionName, ComputeUniquePortKey, allowMultipleClients ? "True" : "False");
if (!changed)
return;
File.WriteAllLines(prefsPath, lines);
log?.Invoke($"Launch setting applied: ComputeUniquePort={(allowMultipleClients ? "True" : "False")} in UserPreferences.ini.");
}
private static void UpdateIntroVideoState(string gameDirectory, bool skipIntroVideos, Action<string>? log)
{
if (string.IsNullOrWhiteSpace(gameDirectory) || !Directory.Exists(gameDirectory))
return;
string introVideoPath = Path.Combine(gameDirectory, IntroVideoFileName);
string parkedIntroVideoPath = introVideoPath + DisabledIntroVideoSuffix;
if (skipIntroVideos)
{
if (File.Exists(parkedIntroVideoPath))
return;
if (!File.Exists(introVideoPath))
return;
File.Move(introVideoPath, parkedIntroVideoPath);
log?.Invoke("Launch setting applied: intro video parked so AC opens without the turbine logo movie.");
return;
}
if (!File.Exists(parkedIntroVideoPath) || File.Exists(introVideoPath))
return;
File.Move(parkedIntroVideoPath, introVideoPath);
log?.Invoke("Launch setting applied: intro video restored.");
}
private static bool SetIniValue(List<string> lines, string sectionName, string key, string value)
{
string sectionHeader = $"[{sectionName}]";
int sectionIndex = lines.FindIndex(line => string.Equals(line.Trim(), sectionHeader, StringComparison.OrdinalIgnoreCase));
if (sectionIndex < 0)
{
if (lines.Count > 0 && !string.IsNullOrWhiteSpace(lines[^1]))
lines.Add(string.Empty);
lines.Add(sectionHeader);
lines.Add($"{key}={value}");
return true;
}
int nextSectionIndex = sectionIndex + 1;
while (nextSectionIndex < lines.Count && !IsSectionHeader(lines[nextSectionIndex]))
nextSectionIndex++;
for (int i = sectionIndex + 1; i < nextSectionIndex; i++)
{
string line = lines[i].Trim();
if (!line.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase))
continue;
string updatedLine = $"{key}={value}";
if (string.Equals(lines[i], updatedLine, StringComparison.Ordinal))
return false;
lines[i] = updatedLine;
return true;
}
lines.Insert(nextSectionIndex, $"{key}={value}");
return true;
}
private static bool IsSectionHeader(string line)
{
string trimmed = line.Trim();
return trimmed.StartsWith("[", StringComparison.Ordinal) && trimmed.EndsWith("]", StringComparison.Ordinal);
}
}

View file

@ -0,0 +1,88 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace RynthCore.App;
internal sealed class AcClientLoginAutomationService
{
private const uint WmMouseMove = 0x0200;
private const uint WmLButtonDown = 0x0201;
private const uint WmLButtonUp = 0x0202;
private const nuint MkLButton = 0x0001;
private const int LogoBypassX = 350;
private const int LogoBypassY = 100;
private const int ClickAttempts = 4;
[DllImport("user32.dll", SetLastError = true)]
private static extern nint PostMessageW(nint hWnd, uint msg, nuint wParam, nint lParam);
public async Task TryBypassLoginLogosAsync(int processId, Action<string>? log = null)
{
try
{
nint hwnd = await WaitForMainWindowAsync(processId).ConfigureAwait(false);
if (hwnd == nint.Zero)
{
log?.Invoke($"Skip Login Logos: no main window found for PID {processId}.");
return;
}
await Task.Delay(2500).ConfigureAwait(false);
for (int i = 0; i < ClickAttempts; i++)
{
if (!TrySendClick(hwnd, LogoBypassX, LogoBypassY))
{
log?.Invoke($"Skip Login Logos: click {i + 1}/{ClickAttempts} failed for PID {processId}.");
return;
}
log?.Invoke($"Skip Login Logos: sent click {i + 1}/{ClickAttempts} to PID {processId}.");
await Task.Delay(1000).ConfigureAwait(false);
}
}
catch (Exception ex)
{
log?.Invoke($"Skip Login Logos failed for PID {processId}: {ex.Message}");
}
}
private static async Task<nint> WaitForMainWindowAsync(int processId)
{
DateTime deadline = DateTime.UtcNow.AddSeconds(20);
while (DateTime.UtcNow < deadline)
{
try
{
using Process process = Process.GetProcessById(processId);
if (process.HasExited)
return nint.Zero;
process.Refresh();
if (process.MainWindowHandle != nint.Zero)
return process.MainWindowHandle;
}
catch
{
return nint.Zero;
}
await Task.Delay(500).ConfigureAwait(false);
}
return nint.Zero;
}
private static bool TrySendClick(nint hwnd, int x, int y)
{
if (hwnd == nint.Zero)
return false;
nint lParam = (nint)((y << 16) | (x & 0xFFFF));
nint move = PostMessageW(hwnd, WmMouseMove, 0, lParam);
nint down = PostMessageW(hwnd, WmLButtonDown, MkLButton, lParam);
nint up = PostMessageW(hwnd, WmLButtonUp, 0, lParam);
return move != 0 && down != 0 && up != 0;
}
}

View file

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Globalization;
namespace RynthCore.App;
internal sealed class AcLaunchArgumentBuilder
{
public string BuildArguments(LaunchServerProfile server, LaunchAccountProfile account)
{
ArgumentNullException.ThrowIfNull(server);
ArgumentNullException.ThrowIfNull(account);
Validate(server, account);
return server.Emulator switch
{
AcEmulatorKind.Ace => string.Join(" ",
"-a", Quote(account.AccountName),
"-v", Quote(account.Password),
"-h", Quote(server.ConnectionString),
"-rodat", server.RodatEnabled ? "on" : "off"),
AcEmulatorKind.Gdle => string.Join(" ",
"-h", Quote(server.Host),
"-p", server.Port.ToString(CultureInfo.InvariantCulture),
"-a", Quote($"{account.AccountName}:{account.Password}"),
"-rodat", server.RodatEnabled ? "on" : "off"),
_ => throw new InvalidOperationException($"Unsupported emulator type '{server.Emulator}'.")
};
}
public string Describe(LaunchServerProfile server, LaunchAccountProfile account)
{
return $"{server.DisplayName} / {account.DisplayName}";
}
private static void Validate(LaunchServerProfile server, LaunchAccountProfile account)
{
var errors = new List<string>();
if (string.IsNullOrWhiteSpace(server.Name))
errors.Add("Server name is required.");
if (string.IsNullOrWhiteSpace(server.Host))
errors.Add("Server host is required.");
if (server.Port <= 0)
errors.Add("Server port must be greater than zero.");
if (string.IsNullOrWhiteSpace(account.AccountName))
errors.Add("Account name is required.");
if (errors.Count > 0)
throw new InvalidOperationException(string.Join(" ", errors));
}
private static string Quote(string value)
{
value ??= string.Empty;
if (value.Length == 0)
return "\"\"";
if (!NeedsQuoting(value))
return value;
return "\"" + value.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"";
}
private static bool NeedsQuoting(string value)
{
foreach (char ch in value)
{
if (char.IsWhiteSpace(ch) || ch == '"')
return true;
}
return false;
}
}

View file

@ -0,0 +1,28 @@
using System.Collections.Generic;
namespace RynthCore.App;
internal sealed class AppSettings
{
public string AcClientPath { get; set; } = string.Empty;
public string EnginePath { get; set; } = string.Empty;
public string LaunchArguments { get; set; } = string.Empty;
public string SelectedServerProfileId { get; set; } = string.Empty;
public string SelectedAccountProfileId { get; set; } = string.Empty;
public List<string> CheckedLaunchAccountProfileIds { get; set; } = [];
public string SelectedMainTabId { get; set; } = "launcher";
public bool AllowMultipleClients { get; set; }
public bool SkipIntroVideos { get; set; }
public bool SkipLoginLogos { get; set; }
public bool AutoLaunch { get; set; }
public bool AutoInjectAfterLaunch { get; set; } = true;
public bool WatchForAcStart { get; set; } = true;
public List<string> EnabledPluginIds { get; set; } = [];
public List<LaunchServerProfile> ServerProfiles { get; set; } = [];
public List<LaunchAccountProfile> AccountProfiles { get; set; } = [];
public double? WindowX { get; set; }
public double? WindowY { get; set; }
public double? WindowWidth { get; set; }
public double? WindowHeight { get; set; }
}

View file

@ -0,0 +1,56 @@
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace RynthCore.App;
internal static class AppSettingsStore
{
private static readonly JsonSerializerOptions JsonOptions = new()
{
WriteIndented = true,
Converters =
{
new JsonStringEnumConverter()
}
};
private static string SettingsDirectory =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RynthCore");
private static string SettingsPath => Path.Combine(SettingsDirectory, "appsettings.json");
public static AppSettings Load()
{
try
{
if (!File.Exists(SettingsPath))
return new AppSettings();
string json = File.ReadAllText(SettingsPath);
AppSettings settings = JsonSerializer.Deserialize<AppSettings>(json, JsonOptions) ?? new AppSettings();
using JsonDocument document = JsonDocument.Parse(json);
JsonElement root = document.RootElement;
if (!root.TryGetProperty(nameof(AppSettings.AutoLaunch), out _) &&
root.TryGetProperty("AutoRelaunch", out JsonElement legacyAutoRelaunch) &&
legacyAutoRelaunch.ValueKind is JsonValueKind.True or JsonValueKind.False)
{
settings.AutoLaunch = legacyAutoRelaunch.GetBoolean();
}
return settings;
}
catch
{
return new AppSettings();
}
}
public static void Save(AppSettings settings)
{
Directory.CreateDirectory(SettingsDirectory);
File.WriteAllText(SettingsPath, JsonSerializer.Serialize(settings, JsonOptions));
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View file

@ -0,0 +1,159 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
namespace RynthCore.App;
internal static class CharacterCacheStore
{
public static List<string> Read(string accountName, string serverName = "")
{
try
{
if (string.IsNullOrWhiteSpace(accountName))
return [];
string safeAccount = SanitizeFileName(accountName);
if (!string.IsNullOrWhiteSpace(serverName))
{
string safeServer = SanitizeFileName(serverName);
List<string> serverCharacters = ReadCharacterFile(GetServerScopedPath(safeServer, safeAccount));
if (serverCharacters.Count > 0)
return serverCharacters;
}
return ReadCharacterFile(GetAccountScopedPath(safeAccount));
}
catch
{
return [];
}
}
public static void Write(string accountName, string serverName, IReadOnlyCollection<string> characters)
{
if (string.IsNullOrWhiteSpace(accountName))
return;
List<string> sanitizedCharacters = SanitizeCharacters(characters);
if (sanitizedCharacters.Count == 0)
return;
Directory.CreateDirectory(GetRootDirectory());
string safeAccount = SanitizeFileName(accountName);
string json = BuildCharacterListJson(sanitizedCharacters, DateTime.Now);
if (!string.IsNullOrWhiteSpace(serverName))
{
string safeServer = SanitizeFileName(serverName);
File.WriteAllText(GetServerScopedPath(safeServer, safeAccount), json);
return;
}
File.WriteAllText(GetAccountScopedPath(safeAccount), json);
}
public static void UpsertCharacter(string accountName, string serverName, string characterName)
{
if (string.IsNullOrWhiteSpace(accountName) || string.IsNullOrWhiteSpace(characterName))
return;
List<string> characters = Read(accountName, serverName);
if (!characters.Contains(characterName, StringComparer.OrdinalIgnoreCase))
characters.Add(characterName);
Write(accountName, serverName, characters);
}
public static void DeleteForAccount(string accountName)
{
if (string.IsNullOrWhiteSpace(accountName))
return;
try
{
string rootDirectory = GetRootDirectory();
if (!Directory.Exists(rootDirectory))
return;
string safeAccount = SanitizeFileName(accountName);
foreach (string file in Directory.GetFiles(rootDirectory, $"characters_*_{safeAccount}.json"))
{
try { File.Delete(file); } catch { }
}
string accountScopedPath = GetAccountScopedPath(safeAccount);
if (File.Exists(accountScopedPath))
{
try { File.Delete(accountScopedPath); } catch { }
}
}
catch
{
}
}
private static string GetRootDirectory() =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RynthCore");
private static string GetServerScopedPath(string safeServerName, string safeAccountName) =>
Path.Combine(GetRootDirectory(), $"characters_{safeServerName}_{safeAccountName}.json");
private static string GetAccountScopedPath(string safeAccountName) =>
Path.Combine(GetRootDirectory(), $"characters_{safeAccountName}.json");
private static List<string> ReadCharacterFile(string filePath)
{
if (!File.Exists(filePath))
return [];
using JsonDocument document = JsonDocument.Parse(File.ReadAllBytes(filePath));
if (!document.RootElement.TryGetProperty("Characters", out JsonElement value) || value.ValueKind != JsonValueKind.Array)
return [];
return value.EnumerateArray()
.Select(element => element.GetString()?.Trim() ?? string.Empty)
.Where(character => !string.IsNullOrWhiteSpace(character))
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
private static List<string> SanitizeCharacters(IEnumerable<string>? characters)
{
return (characters ?? [])
.Select(character => character?.Trim() ?? string.Empty)
.Where(character => !string.IsNullOrWhiteSpace(character))
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
private static string BuildCharacterListJson(IReadOnlyList<string> characters, DateTime updatedAt)
{
using var stream = new MemoryStream();
using (var writer = new Utf8JsonWriter(stream))
{
writer.WriteStartObject();
writer.WritePropertyName("Characters");
writer.WriteStartArray();
foreach (string character in characters)
writer.WriteStringValue(character);
writer.WriteEndArray();
writer.WriteString("UpdatedAt", updatedAt.ToString("O", CultureInfo.InvariantCulture));
writer.WriteEndObject();
}
return Encoding.UTF8.GetString(stream.ToArray());
}
private static string SanitizeFileName(string name)
{
var sb = new StringBuilder(name.Length);
foreach (char c in name)
sb.Append(char.IsLetterOrDigit(c) ? c : '_');
return sb.ToString();
}
}

View file

@ -0,0 +1,55 @@
using System;
namespace RynthCore.App;
internal sealed class LaunchAccountProfile
{
public string Id { get; set; } = Guid.NewGuid().ToString("N");
public string AccountName { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public string CharacterName { get; set; } = string.Empty;
public string Alias { get; set; } = string.Empty;
public string ServerId { get; set; } = string.Empty;
public string DisplayName
{
get
{
string launchLabel = !string.IsNullOrWhiteSpace(CharacterName)
? CharacterName
: Alias;
return string.IsNullOrWhiteSpace(launchLabel)
? AccountName
: $"{launchLabel} ({AccountName})";
}
}
public LaunchAccountProfile Clone()
{
return new LaunchAccountProfile
{
Id = Id,
AccountName = AccountName,
Password = Password,
CharacterName = CharacterName,
Alias = Alias,
ServerId = ServerId
};
}
public void CopyFrom(LaunchAccountProfile source)
{
Id = source.Id;
AccountName = source.AccountName;
Password = source.Password;
CharacterName = source.CharacterName;
Alias = source.Alias;
ServerId = source.ServerId;
}
public override string ToString()
{
return DisplayName;
}
}

View file

@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
namespace RynthCore.App;
internal sealed class LaunchContextRecord
{
public int ProcessId { get; set; }
public string AccountName { get; set; } = string.Empty;
public string ServerName { get; set; } = string.Empty;
public string TargetCharacter { get; set; } = string.Empty;
public bool SkipLoginLogos { get; set; }
public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow;
}
internal static class LaunchContextStore
{
private const string LegacyFileName = "launch_context.json";
private const string ContextDirectoryName = "launch_contexts";
public static LaunchContextRecord CreateRecord(
string accountName,
string serverName,
string targetCharacter,
bool skipLoginLogos)
{
return new LaunchContextRecord
{
AccountName = accountName ?? string.Empty,
ServerName = serverName ?? string.Empty,
TargetCharacter = targetCharacter ?? string.Empty,
SkipLoginLogos = skipLoginLogos,
CreatedAtUtc = DateTime.UtcNow
};
}
public static void WriteLegacy(LaunchContextRecord context)
{
ArgumentNullException.ThrowIfNull(context);
Directory.CreateDirectory(GetRootDirectory());
File.WriteAllText(GetLegacyPath(), JsonSerializer.Serialize(context));
}
public static void WriteForProcess(int processId, LaunchContextRecord context)
{
ArgumentNullException.ThrowIfNull(context);
Directory.CreateDirectory(GetContextDirectory());
var processContext = new LaunchContextRecord
{
ProcessId = processId,
AccountName = context.AccountName,
ServerName = context.ServerName,
TargetCharacter = context.TargetCharacter,
SkipLoginLogos = context.SkipLoginLogos,
CreatedAtUtc = DateTime.UtcNow
};
File.WriteAllText(GetProcessPath(processId), JsonSerializer.Serialize(processContext));
}
public static LaunchContextRecord? TryReadForProcess(int processId)
{
string path = GetProcessPath(processId);
if (!File.Exists(path))
return null;
try
{
return JsonSerializer.Deserialize<LaunchContextRecord>(File.ReadAllText(path));
}
catch
{
return null;
}
}
public static Dictionary<int, LaunchContextRecord> ReadForActiveProcesses(IEnumerable<int> activeProcessIds)
{
var result = new Dictionary<int, LaunchContextRecord>();
foreach (int processId in activeProcessIds.Distinct())
{
LaunchContextRecord? context = TryReadForProcess(processId);
if (context != null)
result[processId] = context;
}
return result;
}
public static void DeleteStaleProcessFiles(IEnumerable<int> activeProcessIds)
{
string contextDirectory = GetContextDirectory();
if (!Directory.Exists(contextDirectory))
return;
HashSet<int> active = activeProcessIds.ToHashSet();
foreach (string filePath in Directory.GetFiles(contextDirectory, "launch_context_*.json"))
{
string fileName = Path.GetFileNameWithoutExtension(filePath);
const string prefix = "launch_context_";
if (!fileName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
continue;
if (!int.TryParse(fileName[prefix.Length..], out int processId) || active.Contains(processId))
continue;
try
{
File.Delete(filePath);
}
catch
{
}
}
}
private static string GetRootDirectory() =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RynthCore");
private static string GetLegacyPath() =>
Path.Combine(GetRootDirectory(), LegacyFileName);
private static string GetContextDirectory() =>
Path.Combine(GetRootDirectory(), ContextDirectoryName);
private static string GetProcessPath(int processId) =>
Path.Combine(GetContextDirectory(), $"launch_context_{processId}.json");
}

View file

@ -0,0 +1,224 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace RynthCore.App;
internal static class LaunchProfileDialogs
{
public static bool TryEditServer(IWin32Window owner, LaunchServerProfile profile)
{
using var dialog = CreateEditorDialog("Server Profile", 520, 300);
var nameBox = CreateTextBox(profile.Name);
var aliasBox = CreateTextBox(profile.Alias);
var hostBox = CreateTextBox(profile.Host);
var portBox = CreateTextBox(profile.Port > 0 ? profile.Port.ToString() : string.Empty);
var emulatorCombo = CreateComboBox();
emulatorCombo.Items.AddRange(Enum.GetNames<AcEmulatorKind>());
emulatorCombo.SelectedItem = profile.Emulator.ToString();
var rodatCheck = new CheckBox
{
Text = "Enable Rodat",
AutoSize = true,
Checked = profile.RodatEnabled,
ForeColor = Color.White,
BackColor = Color.Transparent,
Margin = new Padding(0, 6, 0, 0)
};
var body = CreateFormLayout();
body.Controls.Add(CreateLabeledRow("Server Name", nameBox), 0, 0);
body.Controls.Add(CreateLabeledRow("Alias", aliasBox), 0, 1);
body.Controls.Add(CreateLabeledRow("Host", hostBox), 0, 2);
body.Controls.Add(CreateLabeledRow("Port", portBox), 0, 3);
body.Controls.Add(CreateLabeledRow("Emulator", emulatorCombo), 0, 4);
body.Controls.Add(rodatCheck, 0, 5);
dialog.Controls.Add(body);
void SaveAndClose(object? _, EventArgs __)
{
if (string.IsNullOrWhiteSpace(nameBox.Text))
{
ShowValidation(dialog, "Server name is required.");
return;
}
if (string.IsNullOrWhiteSpace(hostBox.Text))
{
ShowValidation(dialog, "Server host is required.");
return;
}
if (!int.TryParse(portBox.Text.Trim(), out int port) || port <= 0)
{
ShowValidation(dialog, "Server port must be a positive integer.");
return;
}
if (emulatorCombo.SelectedItem is not string emulatorText ||
!Enum.TryParse(emulatorText, ignoreCase: true, out AcEmulatorKind emulator))
{
ShowValidation(dialog, "Select an emulator type.");
return;
}
profile.Name = nameBox.Text.Trim();
profile.Alias = aliasBox.Text.Trim();
profile.Host = hostBox.Text.Trim();
profile.Port = port;
profile.Emulator = emulator;
profile.RodatEnabled = rodatCheck.Checked;
dialog.DialogResult = DialogResult.OK;
dialog.Close();
}
WireDialogButtons(dialog, SaveAndClose);
return dialog.ShowDialog(owner) == DialogResult.OK;
}
public static bool TryEditAccount(IWin32Window owner, LaunchAccountProfile profile)
{
using var dialog = CreateEditorDialog("Account Profile", 520, 300);
var accountBox = CreateTextBox(profile.AccountName);
var passwordBox = CreateTextBox(profile.Password);
passwordBox.UseSystemPasswordChar = true;
var characterBox = CreateTextBox(profile.CharacterName);
var aliasBox = CreateTextBox(profile.Alias);
var body = CreateFormLayout();
body.Controls.Add(CreateLabeledRow("Account", accountBox), 0, 0);
body.Controls.Add(CreateLabeledRow("Password", passwordBox), 0, 1);
body.Controls.Add(CreateLabeledRow("Character / Slot", characterBox), 0, 2);
body.Controls.Add(CreateLabeledRow("Alias (Optional)", aliasBox), 0, 3);
dialog.Controls.Add(body);
void SaveAndClose(object? _, EventArgs __)
{
if (string.IsNullOrWhiteSpace(accountBox.Text))
{
ShowValidation(dialog, "Account name is required.");
return;
}
profile.AccountName = accountBox.Text.Trim();
profile.Password = passwordBox.Text;
profile.CharacterName = characterBox.Text.Trim();
profile.Alias = aliasBox.Text.Trim();
dialog.DialogResult = DialogResult.OK;
dialog.Close();
}
WireDialogButtons(dialog, SaveAndClose);
return dialog.ShowDialog(owner) == DialogResult.OK;
}
private static Form CreateEditorDialog(string title, int width, int height)
{
return new Form
{
Text = title,
FormBorderStyle = FormBorderStyle.FixedDialog,
StartPosition = FormStartPosition.CenterParent,
MinimizeBox = false,
MaximizeBox = false,
ShowInTaskbar = false,
Width = width,
Height = height,
BackColor = Color.FromArgb(20, 28, 36),
ForeColor = Color.White
};
}
private static TableLayoutPanel CreateFormLayout()
{
return new TableLayoutPanel
{
Dock = DockStyle.Fill,
ColumnCount = 1,
RowCount = 6,
Padding = new Padding(14, 14, 14, 56),
AutoSize = false
};
}
private static Panel CreateLabeledRow(string labelText, Control editor)
{
var panel = new Panel
{
Dock = DockStyle.Top,
Height = 54
};
var label = new Label
{
Text = labelText,
AutoSize = true,
ForeColor = Color.Gainsboro,
Location = new Point(0, 2)
};
editor.Location = new Point(0, 22);
editor.Width = 458;
panel.Controls.Add(label);
panel.Controls.Add(editor);
return panel;
}
private static TextBox CreateTextBox(string value)
{
return new TextBox
{
Text = value,
BorderStyle = BorderStyle.FixedSingle,
BackColor = Color.FromArgb(15, 22, 30),
ForeColor = Color.White
};
}
private static ComboBox CreateComboBox()
{
return new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList,
BackColor = Color.FromArgb(15, 22, 30),
ForeColor = Color.White,
FlatStyle = FlatStyle.Flat
};
}
private static void WireDialogButtons(Form dialog, EventHandler saveHandler)
{
var okButton = new Button
{
Text = "Save",
Width = 96,
Height = 34,
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
Location = new Point(dialog.ClientSize.Width - 214, dialog.ClientSize.Height - 46),
DialogResult = DialogResult.None
};
okButton.Click += saveHandler;
var cancelButton = new Button
{
Text = "Cancel",
Width = 96,
Height = 34,
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
Location = new Point(dialog.ClientSize.Width - 108, dialog.ClientSize.Height - 46),
DialogResult = DialogResult.Cancel
};
dialog.AcceptButton = okButton;
dialog.CancelButton = cancelButton;
dialog.Controls.Add(okButton);
dialog.Controls.Add(cancelButton);
}
private static void ShowValidation(IWin32Window owner, string message)
{
MessageBox.Show(owner, message, "Incomplete Profile", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

View file

@ -0,0 +1,56 @@
using System;
namespace RynthCore.App;
internal enum AcEmulatorKind
{
Ace,
Gdle
}
internal sealed class LaunchServerProfile
{
public string Id { get; set; } = Guid.NewGuid().ToString("N");
public string Name { get; set; } = string.Empty;
public string Alias { get; set; } = string.Empty;
public string Host { get; set; } = string.Empty;
public int Port { get; set; }
public AcEmulatorKind Emulator { get; set; } = AcEmulatorKind.Ace;
public bool RodatEnabled { get; set; }
public string DisplayName =>
string.IsNullOrWhiteSpace(Alias) ? Name : $"{Alias} ({Name})";
public string ConnectionString =>
string.IsNullOrWhiteSpace(Host) || Port <= 0 ? string.Empty : $"{Host}:{Port}";
public LaunchServerProfile Clone()
{
return new LaunchServerProfile
{
Id = Id,
Name = Name,
Alias = Alias,
Host = Host,
Port = Port,
Emulator = Emulator,
RodatEnabled = RodatEnabled
};
}
public void CopyFrom(LaunchServerProfile source)
{
Id = source.Id;
Name = source.Name;
Alias = source.Alias;
Host = source.Host;
Port = source.Port;
Emulator = source.Emulator;
RodatEnabled = source.RodatEnabled;
}
public override string ToString()
{
return DisplayName;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,10 @@
namespace RynthCore.App;
internal sealed class PluginDefinition
{
public required string Id { get; init; }
public required string Name { get; init; }
public required string Summary { get; init; }
public required string StatusText { get; init; }
public bool RuntimeImplemented { get; init; }
}

View file

@ -0,0 +1,14 @@
using System;
using System.Windows.Forms;
namespace RynthCore.App;
internal static class Program
{
[STAThread]
private static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new MainForm());
}
}

View file

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<PlatformTarget>x86</PlatformTarget>
<RootNamespace>RynthCore.App</RootNamespace>
<AssemblyName>RynthCore.App</AssemblyName>
<Platforms>x86</Platforms>
<Nullable>enable</Nullable>
<ApplicationIcon>Assets\RynthCore.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\RynthCore.Injector\RynthCore.Injector.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,187 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
namespace RynthCore.App;
internal sealed class SessionStateRecord
{
public int ProcessId { get; set; }
public string AccountName { get; set; } = string.Empty;
public string ServerName { get; set; } = string.Empty;
public string TargetCharacter { get; set; } = string.Empty;
public string CharacterName { get; set; } = string.Empty;
public DateTime LaunchStartedAtUtc { get; set; } = DateTime.UtcNow;
public DateTime? LoginCompletedAtUtc { get; set; }
public DateTime LastUpdatedAtUtc { get; set; } = DateTime.UtcNow;
public bool IsLoggedIn { get; set; }
}
internal static class SessionStateStore
{
private const string SessionDirectoryName = "sessions";
public static void WriteForProcess(int processId, SessionStateRecord record)
{
ArgumentNullException.ThrowIfNull(record);
Directory.CreateDirectory(GetSessionDirectory());
record.ProcessId = processId;
record.LastUpdatedAtUtc = DateTime.UtcNow;
File.WriteAllText(GetProcessPath(processId), BuildSessionJson(record), Encoding.UTF8);
}
public static SessionStateRecord? TryReadForProcess(int processId)
{
string path = GetProcessPath(processId);
if (!File.Exists(path))
return null;
try
{
using JsonDocument document = JsonDocument.Parse(File.ReadAllBytes(path));
JsonElement root = document.RootElement;
var record = new SessionStateRecord
{
ProcessId = GetInt32(root, "ProcessId"),
AccountName = GetString(root, "AccountName"),
ServerName = GetString(root, "ServerName"),
TargetCharacter = GetString(root, "TargetCharacter"),
CharacterName = GetString(root, "CharacterName"),
LaunchStartedAtUtc = GetDateTime(root, "LaunchStartedAtUtc") ?? DateTime.UtcNow,
LoginCompletedAtUtc = GetDateTime(root, "LoginCompletedAtUtc"),
LastUpdatedAtUtc = GetDateTime(root, "LastUpdatedAtUtc") ?? DateTime.UtcNow,
IsLoggedIn = GetBoolean(root, "IsLoggedIn")
};
if (record.ProcessId == 0)
record.ProcessId = processId;
return record;
}
catch
{
return null;
}
}
public static Dictionary<int, SessionStateRecord> ReadForActiveProcesses(IEnumerable<int> activeProcessIds)
{
var result = new Dictionary<int, SessionStateRecord>();
foreach (int processId in activeProcessIds.Distinct())
{
SessionStateRecord? record = TryReadForProcess(processId);
if (record != null)
result[processId] = record;
}
return result;
}
public static void DeleteStaleProcessFiles(IEnumerable<int> activeProcessIds)
{
string directory = GetSessionDirectory();
if (!Directory.Exists(directory))
return;
HashSet<int> active = activeProcessIds.ToHashSet();
foreach (string filePath in Directory.GetFiles(directory, "session_*.json"))
{
string fileName = Path.GetFileNameWithoutExtension(filePath);
const string prefix = "session_";
if (!fileName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
continue;
if (!int.TryParse(fileName[prefix.Length..], out int processId) || active.Contains(processId))
continue;
try
{
File.Delete(filePath);
}
catch
{
}
}
}
private static string GetRootDirectory() =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RynthCore");
private static string GetSessionDirectory() =>
Path.Combine(GetRootDirectory(), SessionDirectoryName);
private static string GetProcessPath(int processId) =>
Path.Combine(GetSessionDirectory(), $"session_{processId}.json");
private static string BuildSessionJson(SessionStateRecord record)
{
using var stream = new MemoryStream();
using (var writer = new Utf8JsonWriter(stream))
{
writer.WriteStartObject();
writer.WriteNumber("ProcessId", record.ProcessId);
writer.WriteString("AccountName", record.AccountName ?? string.Empty);
writer.WriteString("ServerName", record.ServerName ?? string.Empty);
writer.WriteString("TargetCharacter", record.TargetCharacter ?? string.Empty);
writer.WriteString("CharacterName", record.CharacterName ?? string.Empty);
writer.WriteString("LaunchStartedAtUtc", record.LaunchStartedAtUtc.ToString("O", CultureInfo.InvariantCulture));
if (record.LoginCompletedAtUtc.HasValue)
writer.WriteString("LoginCompletedAtUtc", record.LoginCompletedAtUtc.Value.ToString("O", CultureInfo.InvariantCulture));
else
writer.WriteNull("LoginCompletedAtUtc");
writer.WriteString("LastUpdatedAtUtc", record.LastUpdatedAtUtc.ToString("O", CultureInfo.InvariantCulture));
writer.WriteBoolean("IsLoggedIn", record.IsLoggedIn);
writer.WriteEndObject();
}
return Encoding.UTF8.GetString(stream.ToArray());
}
private static string GetString(JsonElement root, string propertyName)
{
return root.TryGetProperty(propertyName, out JsonElement value) && value.ValueKind == JsonValueKind.String
? value.GetString() ?? string.Empty
: string.Empty;
}
private static int GetInt32(JsonElement root, string propertyName)
{
return root.TryGetProperty(propertyName, out JsonElement value) && value.ValueKind == JsonValueKind.Number && value.TryGetInt32(out int number)
? number
: 0;
}
private static bool GetBoolean(JsonElement root, string propertyName)
{
return root.TryGetProperty(propertyName, out JsonElement value) && value.ValueKind is JsonValueKind.True or JsonValueKind.False
? value.GetBoolean()
: false;
}
private static DateTime? GetDateTime(JsonElement root, string propertyName)
{
if (!root.TryGetProperty(propertyName, out JsonElement value))
return null;
if (value.ValueKind == JsonValueKind.Null)
return null;
if (value.ValueKind != JsonValueKind.String)
return null;
return DateTime.TryParse(
value.GetString(),
CultureInfo.InvariantCulture,
DateTimeStyles.RoundtripKind,
out DateTime parsed)
? parsed
: null;
}
}