refactor: reorganize engine-based structure and add agent rules

- Engines/ 配下へエンジン別に再編 (Common/Rgss/Tkool/Tyrano/Wolf/Unity/Nwjs)
- ゲーム個別処理を Engines/<Engine>/Games/<GameName>/ へ分離し、共通処理から明示呼び出し
- 外部ツールを Engines/<Engine>/Tools/ へ移動し、AppPathHelper 経由で解決
- 旧 Tools/ 直下参照と不要な参照ファイル/バックアップを削除
- エージェント規則 AGENTS.md を追加し、README から参照
- publish.ps1 を Engines/<Engine>/Tools/ の再帰配置に対応
This commit is contained in:
armonica committed 2026-10-07 02:30:49 +09:00
1 parent 0d11039ee9
commit 8cea2a147d
47 files changed
+2976 -176

No files matched your search

+216
View File
@@ -0,0 +1,216 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.Json;
using GameLauncher.Helpers;
using GameLauncher.Models;
using GameLauncher.Engines.Tkool;
namespace GameLauncher.Engines.Wolf
{
/// <summary>
/// ウディタ(WOLF RPGエディター)向けのプロキシDLL(メモリフック/スピードハック)
/// およびデバッグモード(テストプレイモード)管理サービス
/// </summary>
public class WolfModService
{
public const string ProxyDllName = "version.dll";
public const string ConfigFileName = "speedhack_config.json";
public const string GameExeBackupSuffix = ".original_launcher_backup";
/// <summary>
/// プロキシDLL(version.dll)がゲームフォルダ内に配置されているか判定します。
/// </summary>
public bool IsProxyDllInstalled(TkoolGameItem game)
{
if (string.IsNullOrEmpty(game.RootDirectory) || !Directory.Exists(game.RootDirectory))
return false;
var dllPath = Path.Combine(game.RootDirectory, ProxyDllName);
return File.Exists(dllPath);
}
/// <summary>
/// プロキシDLL(メモリフック/スピードハック)をゲームフォルダに適用します。
/// </summary>
/// <param name="game">対象のウディタゲーム</param>
/// <param name="baseSpeed">基本スピード倍率(1.0〜10.0)</param>
/// <param name="toggleSpeed">F6キー押下時のトグルスピード倍率(3.0など)</param>
/// <param name="holdSpeed">Ctrlキー押下時の早送り倍率(5.0など)</param>
public (bool success, string message) ApplyProxyDll(
TkoolGameItem game,
double baseSpeed = 1.0,
double toggleSpeed = 3.0,
double holdSpeed = 5.0)
{
var gameDir = game.RootDirectory;
if (!Directory.Exists(gameDir))
return (false, "ゲームディレクトリが見つかりません。");
try
{
// 1. プロキシDLL本体の探索 (Tools\speedhack-i686\version.dll)
var sourceDllPath = ResolveProxyDllPath();
if (string.IsNullOrEmpty(sourceDllPath) || !File.Exists(sourceDllPath))
{
return (false, "プロキシDLL(Engines\\Wolf\\Tools\\speedhack-i686\\version.dll)が見つかりません。");
}
var targetDllPath = Path.Combine(gameDir, ProxyDllName);
var targetConfigPath = Path.Combine(gameDir, ConfigFileName);
// 2. 元々同名DLLが存在していた場合は Backups フォルダに退避
var backupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
var backupDllPath = Path.Combine(backupDir, ProxyDllName + GameExeBackupSuffix);
if (File.Exists(targetDllPath) && !File.Exists(backupDllPath))
{
File.Copy(targetDllPath, backupDllPath, overwrite: true);
}
// 3. プロキシDLLをコピー配置
File.Copy(sourceDllPath, targetDllPath, overwrite: true);
// 4. speedhack_config.json の生成・書き込み
var configContent = GenerateSpeedhackConfig(baseSpeed, toggleSpeed, holdSpeed);
File.WriteAllText(targetConfigPath, configContent, new UTF8Encoding(false));
game.WolfProxyDll = true;
game.IsModded = true;
return (true, $"プロキシDLL(version.dll)を配置しました。\n・[F6] キー: {toggleSpeed:0.#}倍速 トグル\n・[Ctrl] キー: {holdSpeed:0.#}倍速 早送り\n・通常速度: {baseSpeed:0.#}倍");
}
catch (Exception ex)
{
return (false, $"プロキシDLLの適用に失敗しました: {ex.Message}");
}
}
/// <summary>
/// プロキシDLLをゲームフォルダから削除し、初期状態に完全復元します。
/// </summary>
public (bool success, string message) RemoveProxyDll(TkoolGameItem game)
{
var gameDir = game.RootDirectory;
if (!Directory.Exists(gameDir))
return (false, "ゲームディレクトリが見つかりません。");
try
{
var targetDllPath = Path.Combine(gameDir, ProxyDllName);
var targetConfigPath = Path.Combine(gameDir, ConfigFileName);
var backupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
var backupDllPath = Path.Combine(backupDir, ProxyDllName + GameExeBackupSuffix);
// 1. プロキシDLLの削除またはオリジナル復元
if (File.Exists(backupDllPath))
{
File.Copy(backupDllPath, targetDllPath, overwrite: true);
try { File.Delete(backupDllPath); } catch { }
}
else if (File.Exists(targetDllPath))
{
File.Delete(targetDllPath);
}
// 2. 設定ファイルの削除
if (File.Exists(targetConfigPath))
{
try { File.Delete(targetConfigPath); } catch { }
}
game.WolfProxyDll = false;
game.IsModded = false;
return (true, "プロキシDLL(version.dll)を解除し、ゲームを元の状態に復元しました。");
}
catch (Exception ex)
{
return (false, $"プロキシDLLの解除に失敗しました: {ex.Message}");
}
}
/// <summary>
/// 全ての改造(プロキシDLL、パッチ等)を解除し、ゲームを完全に元に戻します。
/// </summary>
public (bool success, string message) RestoreAllMods(TkoolGameItem game)
{
var sb = new StringBuilder();
// 1. プロキシDLLの解除
var (dllSuccess, dllMsg) = RemoveProxyDll(game);
sb.AppendLine(dllMsg);
// 2. Game.exe バックアップからの復元(存在する場合)
var backupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
var backupExePath = Path.Combine(backupDir, "Game.exe" + GameExeBackupSuffix);
var gameExePath = Path.Combine(game.RootDirectory, "Game.exe");
if (File.Exists(backupExePath))
{
try
{
File.Copy(backupExePath, gameExePath, overwrite: true);
sb.AppendLine("・Game.exe をオリジナルバックアップから復元しました。");
}
catch (Exception ex)
{
sb.AppendLine($"・Game.exe の復元中にエラーが発生しました: {ex.Message}");
}
}
return (true, sb.ToString().Trim());
}
/// <summary>
/// speedhack-rs の version.dll の配置パスを探索・解決します。
/// </summary>
private string? ResolveProxyDllPath()
{
// エンジン別ツールフォルダ (Engines\Wolf\Tools\speedhack-i686\version.dll) を優先解決
var resolved = AppPathHelper.ResolveEngineTool("Wolf", Path.Combine("speedhack-i686", ProxyDllName));
if (!string.IsNullOrEmpty(resolved) && File.Exists(resolved))
{
return resolved;
}
// 互換: プロキシDLL直置きのケース
var direct = AppPathHelper.ResolveEngineTool("Wolf", ProxyDllName);
if (!string.IsNullOrEmpty(direct) && File.Exists(direct))
{
return direct;
}
return null;
}
/// <summary>
/// speedhack_config.json の JSON 文字列を生成します。
/// </summary>
private string GenerateSpeedhackConfig(double baseSpeed, double toggleSpeed, double holdSpeed)
{
var obj = new
{
console = false,
base_speed = baseSpeed,
speed_states = new object[]
{
new
{
keys = new[] { "F6" },
speed = toggleSpeed,
is_toggle = true
},
new
{
keys = new[] { "Control" },
speed = holdSpeed,
is_toggle = false
}
}
};
return JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true });
}
}
}