mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-25 15:47:59 +03:00
56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using Windows.Win32;
|
|
using Windows.Win32.Foundation;
|
|
|
|
namespace AMNet.Server;
|
|
|
|
internal static class Config
|
|
{
|
|
internal const string IOSection = "aimeio";
|
|
private const string ConfigFileName = @".\segatools.ini";
|
|
|
|
static Config()
|
|
{
|
|
GameId = ReadKey(IOSection, "gameId", 4);
|
|
ServerName = ReadKey(IOSection, "serverName", 26, Environment.MachineName);
|
|
|
|
PhysicalCardUseIDm = PInvoke.GetPrivateProfileInt(IOSection, "useAimeDBForPhysicalCards", 0, ConfigFileName) > 0;
|
|
EnableAimeTxt = PInvoke.GetPrivateProfileInt(IOSection, "enableKeyboardMode", 1, ConfigFileName) > 0;
|
|
AimeTxtPath = ReadKey("aime", "aimePath", PInvoke.MAX_PATH, @"DEVICE\aime.txt");
|
|
}
|
|
|
|
public static string GameId { get; }
|
|
|
|
/// <summary>
|
|
/// The server name to show on devices. Defaults to the computer name.
|
|
/// </summary>
|
|
public static string ServerName { get; }
|
|
|
|
/// <summary>
|
|
/// Whether physically scanned cards should have their IDm forwarded to the game instead of the access code.
|
|
/// </summary>
|
|
public static bool PhysicalCardUseIDm { get; }
|
|
|
|
/// <summary>
|
|
/// Whether holding the enter key should trigger a card scan using the code from the aime.txt file
|
|
/// </summary>
|
|
public static bool EnableAimeTxt { get; }
|
|
|
|
/// <summary>
|
|
/// Path to the aime.txt file. Defaults to .\DEVICE\aime.txt
|
|
/// </summary>
|
|
public static string AimeTxtPath { get; }
|
|
|
|
public static Version ServerVersion { get; } = new(Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "1.0");
|
|
|
|
internal static unsafe string ReadKey(string section, string key, uint maxLength, string @default = null)
|
|
{
|
|
// +1 for null terminator
|
|
var buffer = stackalloc char[(int)maxLength + 1];
|
|
var bufferStr = new PWSTR(buffer);
|
|
|
|
PInvoke.GetPrivateProfileString(section, key, @default ?? string.Empty, bufferStr, maxLength + 1, ConfigFileName);
|
|
return bufferStr.ToString();
|
|
}
|
|
} |