feat: WOLF RPGエディター対応(Data.wolf解凍・改造・セーブ編集、プロキシDLL倍速)
This commit is contained in:
1 parent
bc5ba43ce7
commit
0befb0a972
5 files changed
+1496
No files matched your search
@@ -0,0 +1,217 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using GameLauncher.Helpers;
|
||||||
|
using GameLauncher.Models;
|
||||||
|
|
||||||
|
namespace GameLauncher.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ウディタ(WOLF RPGエディター)の Data.wolf アーカイブの解凍・抽出・状態管理サービス
|
||||||
|
/// </summary>
|
||||||
|
public class WolfArchiveService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 指定されたゲームフォルダ内に Data.wolf または .wolf アーカイブが存在するか判定します。
|
||||||
|
/// </summary>
|
||||||
|
public bool HasWolfArchive(string gameDirectory)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(gameDirectory) || !Directory.Exists(gameDirectory))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var dataWolf = Path.Combine(gameDirectory, "Data.wolf");
|
||||||
|
if (File.Exists(dataWolf)) return true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Directory.EnumerateFiles(gameDirectory, "*.wolf", SearchOption.TopDirectoryOnly).Any();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 指定されたゲームフォルダ内に Data.wolf の解凍先フォルダ(Data フォルダ)が存在するか判定します。
|
||||||
|
/// </summary>
|
||||||
|
public bool IsExtracted(string gameDirectory)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(gameDirectory) || !Directory.Exists(gameDirectory))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var dataDir = Path.Combine(gameDirectory, "Data");
|
||||||
|
return Directory.Exists(dataDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 有効な Wolf 解凍ツールの実行ファイルパスを取得します。
|
||||||
|
/// </summary>
|
||||||
|
public string? ResolveExtractorPath(string? customPath)
|
||||||
|
{
|
||||||
|
// 1. ユーザー指定パス
|
||||||
|
if (!string.IsNullOrWhiteSpace(customPath) && File.Exists(customPath))
|
||||||
|
{
|
||||||
|
return customPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. ランチャー直下の Tools\UberWolfCli.exe
|
||||||
|
var exeDir = AppPathHelper.GetExeDirectory();
|
||||||
|
var candidates = new[]
|
||||||
|
{
|
||||||
|
Path.Combine(exeDir, "Tools", "UberWolfCli.exe"),
|
||||||
|
Path.Combine(exeDir, "Tools", "UberWolf.exe"),
|
||||||
|
Path.Combine(exeDir, "Tools", "WolfDec.exe"),
|
||||||
|
@"C:\VS2026\GameLauncher\Tools\UberWolfCli.exe",
|
||||||
|
@"Z:\自作ソフト\GameLauncher\Tools\UberWolfCli.exe"
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var candidate in candidates)
|
||||||
|
{
|
||||||
|
if (File.Exists(candidate))
|
||||||
|
{
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Data.wolf を解凍・抽出します。
|
||||||
|
/// </summary>
|
||||||
|
public async Task<(bool success, string message)> ExtractArchiveAsync(
|
||||||
|
TkoolGameItem game,
|
||||||
|
string? customExtractorPath,
|
||||||
|
IProgress<string>? progress = null)
|
||||||
|
{
|
||||||
|
var gameDir = game.RootDirectory;
|
||||||
|
if (!Directory.Exists(gameDir))
|
||||||
|
{
|
||||||
|
return (false, "ゲームのルートディレクトリが見つかりません。");
|
||||||
|
}
|
||||||
|
|
||||||
|
var extractorPath = ResolveExtractorPath(customExtractorPath);
|
||||||
|
if (string.IsNullOrEmpty(extractorPath) || !File.Exists(extractorPath))
|
||||||
|
{
|
||||||
|
return (false, "Wolf RPG アーカイブ解凍ツール(UberWolfCli.exe / WolfDec.exe)が見つかりません。設定ダイアログからツールのパスを指定してください。");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解凍対象の探索 (Data.wolf または Game.exe)
|
||||||
|
var targetFile = Path.Combine(gameDir, "Data.wolf");
|
||||||
|
if (!File.Exists(targetFile))
|
||||||
|
{
|
||||||
|
var wolfFiles = Directory.GetFiles(gameDir, "*.wolf");
|
||||||
|
if (wolfFiles.Length > 0)
|
||||||
|
{
|
||||||
|
targetFile = wolfFiles[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
targetFile = Path.Combine(gameDir, "Game.exe");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(targetFile))
|
||||||
|
{
|
||||||
|
return (false, "解凍対象の Data.wolf または Game.exe が見つかりません。");
|
||||||
|
}
|
||||||
|
|
||||||
|
progress?.Report($"[解凍開始] ツール: {Path.GetFileName(extractorPath)} 対象: {Path.GetFileName(targetFile)}");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// UberWolfCli.exe の場合は -o (上書き) -u (プロテクト解除) を渡す
|
||||||
|
var isUberWolf = Path.GetFileName(extractorPath).Contains("UberWolf", StringComparison.OrdinalIgnoreCase);
|
||||||
|
var arguments = isUberWolf
|
||||||
|
? $"-o -u \"{targetFile}\""
|
||||||
|
: $"\"{targetFile}\"";
|
||||||
|
|
||||||
|
var psi = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = extractorPath,
|
||||||
|
Arguments = arguments,
|
||||||
|
WorkingDirectory = gameDir,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true
|
||||||
|
};
|
||||||
|
|
||||||
|
using var process = new Process { StartInfo = psi };
|
||||||
|
var outputLog = new System.Text.StringBuilder();
|
||||||
|
|
||||||
|
process.OutputDataReceived += (_, e) =>
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(e.Data))
|
||||||
|
{
|
||||||
|
outputLog.AppendLine(e.Data);
|
||||||
|
progress?.Report(e.Data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
process.ErrorDataReceived += (_, e) =>
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(e.Data))
|
||||||
|
{
|
||||||
|
outputLog.AppendLine(e.Data);
|
||||||
|
progress?.Report($"[情報] {e.Data}");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Start();
|
||||||
|
process.BeginOutputReadLine();
|
||||||
|
process.BeginErrorReadLine();
|
||||||
|
|
||||||
|
await process.WaitForExitAsync();
|
||||||
|
|
||||||
|
var dataDir = Path.Combine(gameDir, "Data");
|
||||||
|
if (Directory.Exists(dataDir) && Directory.EnumerateFileSystemEntries(dataDir).Any())
|
||||||
|
{
|
||||||
|
progress?.Report($"[解凍完了] Data フォルダへの抽出に成功しました: {dataDir}");
|
||||||
|
return (true, "Data.wolf の解凍・抽出が完了しました。Data フォルダのファイルを直接編集・改造できます。");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (false, $"解凍処理は終了しましたが、Data フォルダが確認できませんでした。\nログ: {outputLog}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return (false, $"解凍処理中に例外が発生しました: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解凍された Data フォルダを Backups フォルダに退避し、元の Data.wolf 優先読み込み状態に復元します。
|
||||||
|
/// </summary>
|
||||||
|
public (bool success, string message) RestoreArchiveState(TkoolGameItem game)
|
||||||
|
{
|
||||||
|
var gameDir = game.RootDirectory;
|
||||||
|
var dataDir = Path.Combine(gameDir, "Data");
|
||||||
|
|
||||||
|
if (!Directory.Exists(dataDir))
|
||||||
|
{
|
||||||
|
return (true, "Data フォルダは存在しないため、既に元のアーカイブ読み込み状態です。");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// バックアップ保存先(Backups フォルダ)
|
||||||
|
var backupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
|
||||||
|
var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
||||||
|
var backupDataDir = Path.Combine(backupDir, $"Data_Extracted_{timestamp}");
|
||||||
|
|
||||||
|
// Data フォルダを Backups へ移動(元に戻す)
|
||||||
|
Directory.Move(dataDir, backupDataDir);
|
||||||
|
|
||||||
|
return (true, $"解凍されていた Data フォルダを Backups フォルダへ退避しました。\n(退避先: {backupDataDir})\n元の Data.wolf アーカイブ優先読み込みに復元されました。");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return (false, $"復元処理中にエラーが発生しました: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using GameLauncher.Helpers;
|
||||||
|
using GameLauncher.Models;
|
||||||
|
|
||||||
|
namespace GameLauncher.Services
|
||||||
|
{
|
||||||
|
/// <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(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>
|
||||||
|
/// デバッグ(テストプレイ)モード用の起動コマンドライン引数を取得します。
|
||||||
|
/// ウディタ公式仕様の引数(Test_Of_Main Use_Debug_Window)
|
||||||
|
/// </summary>
|
||||||
|
public string GetDebugArguments(bool useDebugWindow = true)
|
||||||
|
{
|
||||||
|
return useDebugWindow ? "Test_Of_Main Use_Debug_Window" : "Test_Of_Main";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
var exeDir = AppPathHelper.GetExeDirectory();
|
||||||
|
var candidates = new[]
|
||||||
|
{
|
||||||
|
Path.Combine(exeDir, "Tools", "speedhack-i686", ProxyDllName),
|
||||||
|
Path.Combine(exeDir, "Tools", ProxyDllName),
|
||||||
|
@"C:\VS2026\GameLauncher\Tools\speedhack-i686\version.dll",
|
||||||
|
@"Z:\自作ソフト\GameLauncher\Tools\speedhack-i686\version.dll"
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var path in candidates)
|
||||||
|
{
|
||||||
|
if (File.Exists(path)) return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,401 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using GameLauncher.Helpers;
|
||||||
|
|
||||||
|
namespace GameLauncher.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ウディタ(WOLF RPGエディター)セーブデータ内の1つの変数項目
|
||||||
|
/// </summary>
|
||||||
|
public class WolfVariableItem
|
||||||
|
{
|
||||||
|
public string Category { get; set; } = "通常変数";
|
||||||
|
public int Index { get; set; }
|
||||||
|
public string DisplayName { get; set; } = string.Empty;
|
||||||
|
public int Value { get; set; }
|
||||||
|
public int Offset { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ウディタセーブデータ内の可変データベース項目
|
||||||
|
/// </summary>
|
||||||
|
public class WolfDbItem
|
||||||
|
{
|
||||||
|
public string TypeName { get; set; } = string.Empty;
|
||||||
|
public int TypeId { get; set; }
|
||||||
|
public int DataId { get; set; }
|
||||||
|
public string DataName { get; set; } = string.Empty;
|
||||||
|
public int FieldId { get; set; }
|
||||||
|
public string FieldName { get; set; } = string.Empty;
|
||||||
|
public bool IsString { get; set; }
|
||||||
|
public int NumberValue { get; set; }
|
||||||
|
public string StringValue { get; set; } = string.Empty;
|
||||||
|
public int Offset { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ウディタセーブデータ内の文字列項目
|
||||||
|
/// </summary>
|
||||||
|
public class WolfStringItem
|
||||||
|
{
|
||||||
|
public int Offset { get; set; }
|
||||||
|
public int Length { get; set; }
|
||||||
|
public string Value { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// パース済みウディタセーブデータ
|
||||||
|
/// </summary>
|
||||||
|
public class WolfSaveData
|
||||||
|
{
|
||||||
|
public string FilePath { get; set; } = string.Empty;
|
||||||
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
public string GameTitle { get; set; } = string.Empty;
|
||||||
|
public ushort FileVersion { get; set; }
|
||||||
|
public bool IsUtf8 { get; set; }
|
||||||
|
public byte[] RawDecryptedBytes { get; set; } = [];
|
||||||
|
public List<WolfVariableItem> Variables { get; set; } = [];
|
||||||
|
public List<WolfDbItem> DatabaseItems { get; set; } = [];
|
||||||
|
public List<WolfStringItem> Strings { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WOLF RPGエディターのセーブデータ(SaveXX.sav)の復号・暗号化・解析・編集サービス
|
||||||
|
/// </summary>
|
||||||
|
public class WolfSaveService
|
||||||
|
{
|
||||||
|
private const int START_OFFSET = 0x14;
|
||||||
|
private static readonly uint[] INC_STEPS = [1, 2, 5];
|
||||||
|
private static readonly uint[] ENC_INC_STEPS = [5, 2, 1];
|
||||||
|
|
||||||
|
static WolfSaveService()
|
||||||
|
{
|
||||||
|
// Shift-JIS (932) のサポート登録
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 指定されたゲームディレクトリからセーブデータファイル一覧を取得します。
|
||||||
|
/// </summary>
|
||||||
|
public List<string> GetSaveFiles(string gameDirectory)
|
||||||
|
{
|
||||||
|
var result = new List<string>();
|
||||||
|
if (string.IsNullOrEmpty(gameDirectory) || !Directory.Exists(gameDirectory))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
var searchDirs = new List<string> { gameDirectory };
|
||||||
|
var saveSubDir = Path.Combine(gameDirectory, "Save");
|
||||||
|
if (Directory.Exists(saveSubDir)) searchDirs.Add(saveSubDir);
|
||||||
|
var saveSubDir2 = Path.Combine(gameDirectory, "save");
|
||||||
|
if (Directory.Exists(saveSubDir2) && !searchDirs.Contains(saveSubDir2)) searchDirs.Add(saveSubDir2);
|
||||||
|
|
||||||
|
foreach (var dir in searchDirs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var files = Directory.GetFiles(dir, "*.sav")
|
||||||
|
.OrderBy(f => Path.GetFileName(f), StringComparer.OrdinalIgnoreCase);
|
||||||
|
result.AddRange(files);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 暗号化されたウディタセーブデータを復号します。
|
||||||
|
/// </summary>
|
||||||
|
public byte[] Decrypt(byte[] encryptedData)
|
||||||
|
{
|
||||||
|
if (encryptedData == null || encryptedData.Length < START_OFFSET)
|
||||||
|
return encryptedData ?? [];
|
||||||
|
|
||||||
|
byte[] copy = (byte[])encryptedData.Clone();
|
||||||
|
byte[] seeds = [copy[0], copy[3], copy[9]];
|
||||||
|
|
||||||
|
for (int i = 0; i < seeds.Length; i++)
|
||||||
|
{
|
||||||
|
uint state = seeds[i];
|
||||||
|
int inc = (int)INC_STEPS[i];
|
||||||
|
|
||||||
|
for (int j = START_OFFSET; j < copy.Length; j += inc)
|
||||||
|
{
|
||||||
|
state = state * 214013 + 2531011;
|
||||||
|
int r = (int)((state >> 16) & 0x7FFF);
|
||||||
|
byte xor = (byte)((r >> 12) & 0xFF);
|
||||||
|
copy[j] ^= xor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 復号状態のウディタセーブデータを暗号化します(チェックサム自動更新付き)。
|
||||||
|
/// </summary>
|
||||||
|
public byte[] Encrypt(byte[] plainData)
|
||||||
|
{
|
||||||
|
if (plainData == null || plainData.Length < START_OFFSET)
|
||||||
|
return plainData ?? [];
|
||||||
|
|
||||||
|
byte[] copy = (byte[])plainData.Clone();
|
||||||
|
|
||||||
|
// 1. チェックサムの再計算 (オフセット 0x14 からの総和を 0x02 に格納)
|
||||||
|
byte checksum = 0;
|
||||||
|
for (int i = START_OFFSET; i < copy.Length; i++)
|
||||||
|
{
|
||||||
|
checksum += copy[i];
|
||||||
|
}
|
||||||
|
copy[0x02] = checksum;
|
||||||
|
|
||||||
|
// 2. 暗号化 (seeds は copy[9], copy[3], copy[0] の逆順、インクリメントも 5, 2, 1)
|
||||||
|
byte[] seeds = [copy[9], copy[3], copy[0]];
|
||||||
|
|
||||||
|
for (int i = 0; i < seeds.Length; i++)
|
||||||
|
{
|
||||||
|
uint state = seeds[i];
|
||||||
|
int inc = (int)ENC_INC_STEPS[i];
|
||||||
|
|
||||||
|
for (int j = START_OFFSET; j < copy.Length; j += inc)
|
||||||
|
{
|
||||||
|
state = state * 214013 + 2531011;
|
||||||
|
int r = (int)((state >> 16) & 0x7FFF);
|
||||||
|
byte xor = (byte)((r >> 12) & 0xFF);
|
||||||
|
copy[j] ^= xor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// セーブファイルを読み込み、復号してパースします。
|
||||||
|
/// </summary>
|
||||||
|
public WolfSaveData LoadSave(string filePath)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
throw new FileNotFoundException($"セーブデータファイルが見つかりません: {filePath}");
|
||||||
|
|
||||||
|
byte[] rawBytes = File.ReadAllBytes(filePath);
|
||||||
|
byte[] decrypted = Decrypt(rawBytes);
|
||||||
|
|
||||||
|
var result = new WolfSaveData
|
||||||
|
{
|
||||||
|
FilePath = filePath,
|
||||||
|
FileName = Path.GetFileName(filePath),
|
||||||
|
RawDecryptedBytes = decrypted
|
||||||
|
};
|
||||||
|
|
||||||
|
if (decrypted.Length < 0x20) return result;
|
||||||
|
|
||||||
|
// 文字エンコーディング判定 (オフセット6が 0x55 なら UTF-8, それ以外は Shift-JIS)
|
||||||
|
result.IsUtf8 = (decrypted[6] == 0x55);
|
||||||
|
Encoding enc = result.IsUtf8 ? Encoding.UTF8 : Encoding.GetEncoding(932);
|
||||||
|
|
||||||
|
// ゲームタイトルの取得 (オフセット 0x15 からの文字列)
|
||||||
|
if (decrypted[0x14] == 0x19 && decrypted.Length > 0x17)
|
||||||
|
{
|
||||||
|
ushort titleLen = BitConverter.ToUInt16(decrypted, 0x15);
|
||||||
|
if (titleLen > 1 && 0x17 + titleLen <= decrypted.Length)
|
||||||
|
{
|
||||||
|
result.GameTitle = enc.GetString(decrypted, 0x17, titleLen - 1).Trim('\0');
|
||||||
|
int nextOffset = 0x17 + titleLen;
|
||||||
|
if (nextOffset + 2 <= decrypted.Length)
|
||||||
|
{
|
||||||
|
result.FileVersion = BitConverter.ToUInt16(decrypted, nextOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// セーブデータ内の全文字列スキャン
|
||||||
|
ScanStrings(result, decrypted, enc);
|
||||||
|
|
||||||
|
// セーブデータ内の通常変数スキャン
|
||||||
|
ScanVariables(result, decrypted);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文字列の検出スキャン
|
||||||
|
/// </summary>
|
||||||
|
private void ScanStrings(WolfSaveData model, byte[] data, Encoding enc)
|
||||||
|
{
|
||||||
|
for (int i = START_OFFSET; i < data.Length - 4; i++)
|
||||||
|
{
|
||||||
|
uint strLen = BitConverter.ToUInt32(data, i);
|
||||||
|
if (strLen >= 2 && strLen <= 128 && i + 4 + strLen <= data.Length)
|
||||||
|
{
|
||||||
|
// 末尾がNULL終端かチェック
|
||||||
|
if (data[i + 4 + strLen - 1] == 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string s = enc.GetString(data, i + 4, (int)strLen - 1);
|
||||||
|
// 意味のあるテキストか判定(2文字以上の文字、制御文字を含まない)
|
||||||
|
if (s.Length >= 2 && !s.Any(c => char.IsControl(c) && c != '\r' && c != '\n' && c != '\t'))
|
||||||
|
{
|
||||||
|
model.Strings.Add(new WolfStringItem
|
||||||
|
{
|
||||||
|
Offset = i + 4,
|
||||||
|
Length = (int)strLen - 1,
|
||||||
|
Value = s
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 変数テーブルのスキャン(32bit整数群)
|
||||||
|
/// </summary>
|
||||||
|
private void ScanVariables(WolfSaveData model, byte[] data)
|
||||||
|
{
|
||||||
|
// 4バイト境界に沿って整数値を抽出(特に100以上の意味ありそうな数値やステータス)
|
||||||
|
int varIdx = 0;
|
||||||
|
for (int i = 0x50; i < data.Length - 4; i += 4)
|
||||||
|
{
|
||||||
|
int val = BitConverter.ToInt32(data, i);
|
||||||
|
// 範囲制限(極端に大きなゴミデータや負の値のノイズを適度にフィルタ)
|
||||||
|
if (val >= 0 && val <= 999999999)
|
||||||
|
{
|
||||||
|
model.Variables.Add(new WolfVariableItem
|
||||||
|
{
|
||||||
|
Category = "通常・内部変数",
|
||||||
|
Index = varIdx++,
|
||||||
|
DisplayName = $"変数 [0x{i:X5}]",
|
||||||
|
Value = val,
|
||||||
|
Offset = i
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// セーブファイルをバックアップしてから上書き保存します。
|
||||||
|
/// バックアップは必ず Z:\自作ソフト\GameLauncher\Backups に保存されます。
|
||||||
|
/// </summary>
|
||||||
|
public string SaveToFile(WolfSaveData model, string folderName, string rootDirectory)
|
||||||
|
{
|
||||||
|
if (model == null || model.RawDecryptedBytes == null || model.RawDecryptedBytes.Length == 0)
|
||||||
|
throw new InvalidOperationException("保存対象のデータが空です。");
|
||||||
|
|
||||||
|
// 1. バックアップ作成 (Backups フォルダへ)
|
||||||
|
string? backupPath = BackupSaveFile(model.FilePath, folderName, rootDirectory);
|
||||||
|
|
||||||
|
// 2. 変数・項目の変更を RawDecryptedBytes に書き戻し
|
||||||
|
foreach (var item in model.Variables)
|
||||||
|
{
|
||||||
|
if (item.Offset >= START_OFFSET && item.Offset + 4 <= model.RawDecryptedBytes.Length)
|
||||||
|
{
|
||||||
|
byte[] valBytes = BitConverter.GetBytes(item.Value);
|
||||||
|
Buffer.BlockCopy(valBytes, 0, model.RawDecryptedBytes, item.Offset, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 暗号化 & チェックサム再計算
|
||||||
|
byte[] encrypted = Encrypt(model.RawDecryptedBytes);
|
||||||
|
|
||||||
|
// 4. アトミック書き込み
|
||||||
|
string tempFile = model.FilePath + ".tmp_" + Guid.NewGuid().ToString("N");
|
||||||
|
File.WriteAllBytes(tempFile, encrypted);
|
||||||
|
File.Move(tempFile, model.FilePath, overwrite: true);
|
||||||
|
|
||||||
|
return backupPath ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// セーブデータのバックアップを作成します。
|
||||||
|
/// </summary>
|
||||||
|
public string? BackupSaveFile(string saveFilePath, string folderName, string rootDirectory)
|
||||||
|
{
|
||||||
|
if (!File.Exists(saveFilePath)) return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var backupDir = AppPathHelper.GetGameBackupDirectory(folderName, rootDirectory);
|
||||||
|
if (!Directory.Exists(backupDir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(backupDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileName = Path.GetFileNameWithoutExtension(saveFilePath);
|
||||||
|
var ext = Path.GetExtension(saveFilePath);
|
||||||
|
var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
||||||
|
var destName = $"{fileName}_{timestamp}{ext}";
|
||||||
|
var destPath = Path.Combine(backupDir, destName);
|
||||||
|
|
||||||
|
File.Copy(saveFilePath, destPath, overwrite: true);
|
||||||
|
return destPath;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"[WolfSaveService] Backup error: {ex.Message}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// セーブデータを JSON 形式でエクスポートします。
|
||||||
|
/// </summary>
|
||||||
|
public void ExportToJson(WolfSaveData model, string jsonFilePath)
|
||||||
|
{
|
||||||
|
var dto = new
|
||||||
|
{
|
||||||
|
model.FileName,
|
||||||
|
model.GameTitle,
|
||||||
|
model.FileVersion,
|
||||||
|
model.IsUtf8,
|
||||||
|
Variables = model.Variables.Select(v => new { v.Offset, v.DisplayName, v.Value }),
|
||||||
|
Strings = model.Strings.Select(s => new { s.Offset, s.Length, s.Value })
|
||||||
|
};
|
||||||
|
|
||||||
|
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||||
|
string json = JsonSerializer.Serialize(dto, options);
|
||||||
|
File.WriteAllText(jsonFilePath, json, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// JSON 形式の編集内容をセーブデータモデルへインポート・反映します。
|
||||||
|
/// </summary>
|
||||||
|
public void ImportFromJson(WolfSaveData model, string jsonFilePath)
|
||||||
|
{
|
||||||
|
if (!File.Exists(jsonFilePath))
|
||||||
|
throw new FileNotFoundException($"JSONファイルが見つかりません: {jsonFilePath}");
|
||||||
|
|
||||||
|
string json = File.ReadAllText(jsonFilePath, Encoding.UTF8);
|
||||||
|
using var doc = JsonDocument.Parse(json);
|
||||||
|
var root = doc.RootElement;
|
||||||
|
|
||||||
|
if (root.TryGetProperty("Variables", out var varsElement) && varsElement.ValueKind == JsonValueKind.Array)
|
||||||
|
{
|
||||||
|
var varDict = model.Variables.ToDictionary(v => v.Offset, v => v);
|
||||||
|
foreach (var item in varsElement.EnumerateArray())
|
||||||
|
{
|
||||||
|
if (item.TryGetProperty("Offset", out var offsetProp) &&
|
||||||
|
item.TryGetProperty("Value", out var valProp))
|
||||||
|
{
|
||||||
|
int offset = offsetProp.GetInt32();
|
||||||
|
int val = valProp.GetInt32();
|
||||||
|
if (varDict.TryGetValue(offset, out var entry))
|
||||||
|
{
|
||||||
|
entry.Value = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,322 @@
|
|||||||
|
<Window x:Class="GameLauncher.WolfSaveEditorDialog"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:GameLauncher"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="WOLF RPGエディター セーブデータエディタ" Height="750" Width="1100"
|
||||||
|
MinHeight="550" MinWidth="850"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
Background="#181820" Foreground="#E0E0E6"
|
||||||
|
FontFamily="Segoe UI, Meiryo UI, Yu Gothic UI">
|
||||||
|
|
||||||
|
<Window.Resources>
|
||||||
|
<!-- カラーパレット -->
|
||||||
|
<SolidColorBrush x:Key="BgDark" Color="#181820"/>
|
||||||
|
<SolidColorBrush x:Key="CardBg" Color="#22222C"/>
|
||||||
|
<SolidColorBrush x:Key="CardHoverBg" Color="#2C2C3A"/>
|
||||||
|
<SolidColorBrush x:Key="SidePanelBg" Color="#1F1F2A"/>
|
||||||
|
<SolidColorBrush x:Key="BorderBrushColor" Color="#38384C"/>
|
||||||
|
<SolidColorBrush x:Key="TextPrimary" Color="#F2F2F7"/>
|
||||||
|
<SolidColorBrush x:Key="TextSecondary" Color="#9E9EB4"/>
|
||||||
|
<SolidColorBrush x:Key="AccentWolf" Color="#4834D4"/>
|
||||||
|
<SolidColorBrush x:Key="AccentWolfHover" Color="#686DE0"/>
|
||||||
|
<SolidColorBrush x:Key="AccentGreen" Color="#00B894"/>
|
||||||
|
<SolidColorBrush x:Key="AccentGreenHover" Color="#10D3AC"/>
|
||||||
|
<SolidColorBrush x:Key="AccentRed" Color="#D63031"/>
|
||||||
|
|
||||||
|
<!-- ボタン標準スタイル -->
|
||||||
|
<Style x:Key="ModernButton" TargetType="Button">
|
||||||
|
<Setter Property="Background" Value="#2E2E3E"/>
|
||||||
|
<Setter Property="Foreground" Value="#E0E0E6"/>
|
||||||
|
<Setter Property="BorderThickness" Value="1"/>
|
||||||
|
<Setter Property="BorderBrush" Value="#44445A"/>
|
||||||
|
<Setter Property="Padding" Value="12,6"/>
|
||||||
|
<Setter Property="FontSize" Value="12"/>
|
||||||
|
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||||
|
<Setter Property="Cursor" Value="Hand"/>
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<Border Background="{TemplateBinding Background}"
|
||||||
|
BorderBrush="{TemplateBinding BorderBrush}"
|
||||||
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
|
CornerRadius="6"
|
||||||
|
Padding="{TemplateBinding Padding}">
|
||||||
|
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Border>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
<Style.Triggers>
|
||||||
|
<Trigger Property="IsMouseOver" Value="True">
|
||||||
|
<Setter Property="Background" Value="#3D3D52"/>
|
||||||
|
<Setter Property="BorderBrush" Value="{StaticResource AccentWolfHover}"/>
|
||||||
|
</Trigger>
|
||||||
|
<Trigger Property="IsEnabled" Value="False">
|
||||||
|
<Setter Property="Opacity" Value="0.4"/>
|
||||||
|
<Setter Property="Cursor" Value="Arrow"/>
|
||||||
|
</Trigger>
|
||||||
|
</Style.Triggers>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<!-- プライマリ(保存)ボタンスタイル -->
|
||||||
|
<Style x:Key="PrimaryButton" TargetType="Button" BasedOn="{StaticResource ModernButton}">
|
||||||
|
<Setter Property="Background" Value="{StaticResource AccentGreen}"/>
|
||||||
|
<Setter Property="BorderBrush" Value="{StaticResource AccentGreen}"/>
|
||||||
|
<Setter Property="Foreground" Value="#FFFFFF"/>
|
||||||
|
<Style.Triggers>
|
||||||
|
<Trigger Property="IsMouseOver" Value="True">
|
||||||
|
<Setter Property="Background" Value="{StaticResource AccentGreenHover}"/>
|
||||||
|
<Setter Property="BorderBrush" Value="{StaticResource AccentGreenHover}"/>
|
||||||
|
</Trigger>
|
||||||
|
</Style.Triggers>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<!-- タブコントロールスタイル -->
|
||||||
|
<Style x:Key="ModernTabItem" TargetType="TabItem">
|
||||||
|
<Setter Property="Foreground" Value="{StaticResource TextSecondary}"/>
|
||||||
|
<Setter Property="FontSize" Value="13"/>
|
||||||
|
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||||
|
<Setter Property="Padding" Value="16,8"/>
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="TabItem">
|
||||||
|
<Border x:Name="TabBorder" Background="Transparent" BorderThickness="0,0,0,2" BorderBrush="Transparent" Padding="{TemplateBinding Padding}" Margin="0,0,8,0" Cursor="Hand">
|
||||||
|
<ContentPresenter ContentSource="Header"/>
|
||||||
|
</Border>
|
||||||
|
<ControlTemplate.Triggers>
|
||||||
|
<Trigger Property="IsSelected" Value="True">
|
||||||
|
<Setter TargetName="TabBorder" Property="BorderBrush" Value="{StaticResource AccentWolfHover}"/>
|
||||||
|
<Setter Property="Foreground" Value="#FFFFFF"/>
|
||||||
|
</Trigger>
|
||||||
|
<Trigger Property="IsMouseOver" Value="True">
|
||||||
|
<Setter Property="Foreground" Value="#FFFFFF"/>
|
||||||
|
</Trigger>
|
||||||
|
</ControlTemplate.Triggers>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</Window.Resources>
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<!-- ヘッダーエリア -->
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<!-- 操作ツールバー -->
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<!-- メインコンテンツ -->
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<!-- ステータスバー -->
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<!-- 1. ヘッダー -->
|
||||||
|
<Border Grid.Row="0" Background="{StaticResource SidePanelBg}" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="0,0,0,1" Padding="20,14">
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<StackPanel Grid.Column="0">
|
||||||
|
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||||
|
<Border Background="{StaticResource AccentWolf}" CornerRadius="4" Padding="6,2" Margin="0,0,10,0">
|
||||||
|
<TextBlock Text="🐺 ウディタ" FontSize="11" FontWeight="Bold" Foreground="#FFFFFF"/>
|
||||||
|
</Border>
|
||||||
|
<TextBlock Text="セーブデータエディタ" FontSize="18" FontWeight="Bold" Foreground="{StaticResource TextPrimary}" VerticalAlignment="Center"/>
|
||||||
|
<TextBlock x:Name="lblGameTitle" Text="" FontSize="14" Foreground="{StaticResource TextSecondary}" Margin="12,0,0,0" VerticalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
<TextBlock x:Name="lblGamePath" Text="" FontSize="11" Foreground="{StaticResource TextSecondary}" Margin="0,4,0,0" TextTrimming="CharacterEllipsis"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- セーブスロット選択 -->
|
||||||
|
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||||
|
<TextBlock Text="対象セーブ:" VerticalAlignment="Center" Margin="0,0,8,0" Foreground="{StaticResource TextSecondary}" FontSize="12"/>
|
||||||
|
<ComboBox x:Name="cboSaveFiles" Width="180" Height="28" VerticalContentAlignment="Center"
|
||||||
|
SelectionChanged="cboSaveFiles_SelectionChanged" Margin="0,0,8,0"/>
|
||||||
|
<Button Content="🔄 再読み込み" Style="{StaticResource ModernButton}" Click="btnReload_Click" Margin="0,0,8,0"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- 2. 操作ツールバー -->
|
||||||
|
<Border Grid.Row="1" Background="{StaticResource CardBg}" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="0,0,0,1" Padding="20,10">
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<!-- 数値ピンポイント検索(所持金・ステータス特定) -->
|
||||||
|
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,16,0">
|
||||||
|
<TextBlock Text="🎯 数値検索 (所持金等):" VerticalAlignment="Center" Foreground="{StaticResource TextSecondary}" FontSize="12" Margin="0,0,6,0"/>
|
||||||
|
<TextBox x:Name="txtTargetValue" Width="110" Height="26" VerticalContentAlignment="Center" Padding="4,0"
|
||||||
|
Background="#14141C" Foreground="#FFFFFF" BorderBrush="{StaticResource BorderBrushColor}" Text=""/>
|
||||||
|
<Button Content="検索" Style="{StaticResource ModernButton}" Click="btnSearchValue_Click" Margin="6,0,4,0"/>
|
||||||
|
<Button Content="MAX(9999999)化" Style="{StaticResource ModernButton}" Click="btnSetMaxTarget_Click" Margin="0,0,4,0" ToolTip="検索された数値を 9,999,999 に書き換えます"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- リアルタイムフィルター -->
|
||||||
|
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,16,0">
|
||||||
|
<TextBlock Text="🔍 絞り込み:" VerticalAlignment="Center" Foreground="{StaticResource TextSecondary}" FontSize="12" Margin="0,0,6,0"/>
|
||||||
|
<TextBox x:Name="txtFilter" Width="150" Height="26" VerticalContentAlignment="Center" Padding="4,0"
|
||||||
|
Background="#14141C" Foreground="#FFFFFF" BorderBrush="{StaticResource BorderBrushColor}"
|
||||||
|
TextChanged="txtFilter_TextChanged"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- アクションボタン群 -->
|
||||||
|
<StackPanel Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||||
|
<Button Content="📤 JSONエクスポート" Style="{StaticResource ModernButton}" Click="btnExportJson_Click" Margin="0,0,8,0"/>
|
||||||
|
<Button Content="📥 JSONインポート" Style="{StaticResource ModernButton}" Click="btnImportJson_Click" Margin="0,0,8,0"/>
|
||||||
|
<Button Content="📁 バックアップを開く" Style="{StaticResource ModernButton}" Click="btnOpenBackups_Click" Margin="0,0,12,0"/>
|
||||||
|
<Button Content="💾 上書き保存 (自動バックアップ)" Style="{StaticResource PrimaryButton}" Click="btnSave_Click" Padding="16,6"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- 3. メインコンテンツ -->
|
||||||
|
<TabControl Grid.Row="2" Background="Transparent" BorderThickness="0" Margin="16,10,16,10">
|
||||||
|
<!-- 変数・数値データタブ -->
|
||||||
|
<TabItem Header="📊 通常変数・ステータス数値" Style="{StaticResource ModernTabItem}">
|
||||||
|
<DataGrid x:Name="dgVariables" AutoGenerateColumns="False" CanUserAddRows="False"
|
||||||
|
Background="{StaticResource CardBg}" BorderBrush="{StaticResource BorderBrushColor}"
|
||||||
|
RowBackground="#22222C" AlternatingRowBackground="#1D1D26"
|
||||||
|
Foreground="#FFFFFF" GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="#333344"
|
||||||
|
HeadersVisibility="Column" SelectionMode="Single"
|
||||||
|
CellEditEnding="dgVariables_CellEditEnding">
|
||||||
|
<DataGrid.Resources>
|
||||||
|
<Style TargetType="DataGridColumnHeader">
|
||||||
|
<Setter Property="Background" Value="#2A2A38"/>
|
||||||
|
<Setter Property="Foreground" Value="#E0E0E6"/>
|
||||||
|
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||||
|
<Setter Property="Padding" Value="10,6"/>
|
||||||
|
<Setter Property="BorderBrush" Value="{StaticResource BorderBrushColor}"/>
|
||||||
|
<Setter Property="BorderThickness" Value="0,0,1,1"/>
|
||||||
|
</Style>
|
||||||
|
</DataGrid.Resources>
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="分類" Binding="{Binding Category}" Width="120" IsReadOnly="True"/>
|
||||||
|
<DataGridTextColumn Header="項目名" Binding="{Binding DisplayName}" Width="180" IsReadOnly="True"/>
|
||||||
|
<DataGridTextColumn Header="オフセット" Binding="{Binding Offset, StringFormat=0x{0:X5}}" Width="110" IsReadOnly="True"/>
|
||||||
|
<DataGridTextColumn Header="現在の値 (ダブルクリックで編集)" Binding="{Binding Value, UpdateSourceTrigger=LostFocus}" Width="200">
|
||||||
|
<DataGridTextColumn.ElementStyle>
|
||||||
|
<Style TargetType="TextBlock">
|
||||||
|
<Setter Property="FontWeight" Value="Bold"/>
|
||||||
|
<Setter Property="Foreground" Value="#55EFC4"/>
|
||||||
|
<Setter Property="Padding" Value="8,3"/>
|
||||||
|
</Style>
|
||||||
|
</DataGridTextColumn.ElementStyle>
|
||||||
|
</DataGridTextColumn>
|
||||||
|
<DataGridTemplateColumn Header="クイック操作" Width="140">
|
||||||
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Button Content="MAX(9999999)" Style="{StaticResource ModernButton}" Padding="8,2" FontSize="11"
|
||||||
|
Click="btnQuickMax_Click" Tag="{Binding}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
|
</DataGridTemplateColumn>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
</TabItem>
|
||||||
|
|
||||||
|
<!-- 文字列データタブ -->
|
||||||
|
<TabItem Header="💬 文字列データ" Style="{StaticResource ModernTabItem}">
|
||||||
|
<DataGrid x:Name="dgStrings" AutoGenerateColumns="False" CanUserAddRows="False" IsReadOnly="True"
|
||||||
|
Background="{StaticResource CardBg}" BorderBrush="{StaticResource BorderBrushColor}"
|
||||||
|
RowBackground="#22222C" AlternatingRowBackground="#1D1D26"
|
||||||
|
Foreground="#FFFFFF" GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="#333344"
|
||||||
|
HeadersVisibility="Column" SelectionMode="Single">
|
||||||
|
<DataGrid.Resources>
|
||||||
|
<Style TargetType="DataGridColumnHeader">
|
||||||
|
<Setter Property="Background" Value="#2A2A38"/>
|
||||||
|
<Setter Property="Foreground" Value="#E0E0E6"/>
|
||||||
|
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||||
|
<Setter Property="Padding" Value="10,6"/>
|
||||||
|
<Setter Property="BorderBrush" Value="{StaticResource BorderBrushColor}"/>
|
||||||
|
<Setter Property="BorderThickness" Value="0,0,1,1"/>
|
||||||
|
</Style>
|
||||||
|
</DataGrid.Resources>
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="オフセット" Binding="{Binding Offset, StringFormat=0x{0:X5}}" Width="120"/>
|
||||||
|
<DataGridTextColumn Header="バイト長" Binding="{Binding Length}" Width="90"/>
|
||||||
|
<DataGridTextColumn Header="文字列内容" Binding="{Binding Value}" Width="*"/>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
</TabItem>
|
||||||
|
|
||||||
|
<!-- セーブ詳細情報タブ -->
|
||||||
|
<TabItem Header="ℹ️ セーブ情報" Style="{StaticResource ModernTabItem}">
|
||||||
|
<Border Background="{StaticResource CardBg}" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="1" CornerRadius="8" Padding="20">
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="セーブデータ詳細メタ情報" FontSize="14" FontWeight="Bold" Foreground="#FFFFFF" Margin="0,0,0,12"/>
|
||||||
|
<Grid Margin="0,0,0,8">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="160"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Text="ゲームタイトル:" Foreground="{StaticResource TextSecondary}"/>
|
||||||
|
<TextBlock x:Name="txtInfoTitle" Grid.Column="1" Foreground="#FFFFFF" FontWeight="SemiBold"/>
|
||||||
|
</Grid>
|
||||||
|
<Grid Margin="0,0,0,8">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="160"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Text="セーブバージョン:" Foreground="{StaticResource TextSecondary}"/>
|
||||||
|
<TextBlock x:Name="txtInfoVersion" Grid.Column="1" Foreground="#FFFFFF"/>
|
||||||
|
</Grid>
|
||||||
|
<Grid Margin="0,0,0,8">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="160"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Text="エンコーディング:" Foreground="{StaticResource TextSecondary}"/>
|
||||||
|
<TextBlock x:Name="txtInfoEncoding" Grid.Column="1" Foreground="#FFFFFF"/>
|
||||||
|
</Grid>
|
||||||
|
<Grid Margin="0,0,0,8">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="160"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Text="復号後データサイズ:" Foreground="{StaticResource TextSecondary}"/>
|
||||||
|
<TextBlock x:Name="txtInfoSize" Grid.Column="1" Foreground="#FFFFFF"/>
|
||||||
|
</Grid>
|
||||||
|
<Grid Margin="0,0,0,8">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="160"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Text="暗号化方式:" Foreground="{StaticResource TextSecondary}"/>
|
||||||
|
<TextBlock Text="WOLF RPG LCG XOR暗号化 (チェックサム自動計算対応)" Grid.Column="1" Foreground="#00B894"/>
|
||||||
|
</Grid>
|
||||||
|
<Grid Margin="0,0,0,8">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="160"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Text="バックアップ先:" Foreground="{StaticResource TextSecondary}"/>
|
||||||
|
<TextBlock x:Name="txtInfoBackupDir" Grid.Column="1" Foreground="{StaticResource TextSecondary}" TextWrapping="Wrap"/>
|
||||||
|
</Grid>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
</TabItem>
|
||||||
|
</TabControl>
|
||||||
|
|
||||||
|
<!-- 4. ステータスバー -->
|
||||||
|
<Border Grid.Row="3" Background="#14141C" BorderBrush="{StaticResource BorderBrushColor}" BorderThickness="0,1,0,0" Padding="16,8">
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock x:Name="lblStatus" Text="準備完了" Foreground="{StaticResource TextSecondary}" FontSize="12" VerticalAlignment="Center"/>
|
||||||
|
<TextBlock x:Name="lblSaveCount" Grid.Column="1" Text="" Foreground="{StaticResource TextSecondary}" FontSize="12" VerticalAlignment="Center"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,332 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using GameLauncher.Helpers;
|
||||||
|
using GameLauncher.Models;
|
||||||
|
using GameLauncher.Services;
|
||||||
|
|
||||||
|
namespace GameLauncher
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ウディタ用セーブデータエディタの画面ロジック
|
||||||
|
/// </summary>
|
||||||
|
public partial class WolfSaveEditorDialog : Window
|
||||||
|
{
|
||||||
|
private readonly TkoolGameItem _game;
|
||||||
|
private readonly WolfSaveService _saveService;
|
||||||
|
private WolfSaveData? _currentSaveData;
|
||||||
|
private List<WolfVariableItem> _allVariables = [];
|
||||||
|
private List<WolfStringItem> _allStrings = [];
|
||||||
|
|
||||||
|
public WolfSaveEditorDialog(TkoolGameItem game, WolfSaveService saveService)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_game = game;
|
||||||
|
_saveService = saveService;
|
||||||
|
|
||||||
|
lblGameTitle.Text = _game.Title;
|
||||||
|
lblGamePath.Text = _game.RootDirectory;
|
||||||
|
txtInfoBackupDir.Text = AppPathHelper.GetGameBackupDirectory(_game.FolderName, _game.RootDirectory);
|
||||||
|
|
||||||
|
LoadSaveFileList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// セーブファイル一覧の読み込みとコンボボックス設定
|
||||||
|
/// </summary>
|
||||||
|
private void LoadSaveFileList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var files = _saveService.GetSaveFiles(_game.RootDirectory);
|
||||||
|
cboSaveFiles.Items.Clear();
|
||||||
|
|
||||||
|
foreach (var f in files)
|
||||||
|
{
|
||||||
|
cboSaveFiles.Items.Add(Path.GetFileName(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cboSaveFiles.Items.Count > 0)
|
||||||
|
{
|
||||||
|
cboSaveFiles.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lblStatus.Text = "セーブデータ(*.sav)が見つかりませんでした。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
lblStatus.Text = $"セーブファイル列挙エラー: {ex.Message}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cboSaveFiles_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (cboSaveFiles.SelectedItem == null) return;
|
||||||
|
var fileName = cboSaveFiles.SelectedItem.ToString();
|
||||||
|
if (string.IsNullOrEmpty(fileName)) return;
|
||||||
|
|
||||||
|
LoadSaveFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 指定されたセーブファイルの読み込み・解析
|
||||||
|
/// </summary>
|
||||||
|
private void LoadSaveFile(string fileName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var files = _saveService.GetSaveFiles(_game.RootDirectory);
|
||||||
|
var fullPath = files.FirstOrDefault(f => string.Equals(Path.GetFileName(f), fileName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(fullPath) || !File.Exists(fullPath))
|
||||||
|
{
|
||||||
|
lblStatus.Text = $"ファイルが存在しません: {fileName}";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_currentSaveData = _saveService.LoadSave(fullPath);
|
||||||
|
_allVariables = [.. _currentSaveData.Variables];
|
||||||
|
_allStrings = [.. _currentSaveData.Strings];
|
||||||
|
|
||||||
|
// メタ情報表示
|
||||||
|
txtInfoTitle.Text = string.IsNullOrEmpty(_currentSaveData.GameTitle) ? "(不明)" : _currentSaveData.GameTitle;
|
||||||
|
txtInfoVersion.Text = $"0x{_currentSaveData.FileVersion:X4}";
|
||||||
|
txtInfoEncoding.Text = _currentSaveData.IsUtf8 ? "UTF-8" : "Shift-JIS (CP932)";
|
||||||
|
txtInfoSize.Text = $"{_currentSaveData.RawDecryptedBytes.Length:N0} バイト";
|
||||||
|
|
||||||
|
ApplyFilter();
|
||||||
|
|
||||||
|
lblStatus.Text = $"'{fileName}' を正常に読み込みました。";
|
||||||
|
lblSaveCount.Text = $"変数項目: {_allVariables.Count}件, 文字列項目: {_allStrings.Count}件";
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"セーブデータの読み込みに失敗しました:\n{ex.Message}", "読み込みエラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
lblStatus.Text = $"読み込みエラー: {ex.Message}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnReload_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (cboSaveFiles.SelectedItem != null)
|
||||||
|
{
|
||||||
|
LoadSaveFile(cboSaveFiles.SelectedItem.ToString()!);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadSaveFileList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// フィルターの適用
|
||||||
|
/// </summary>
|
||||||
|
private void ApplyFilter()
|
||||||
|
{
|
||||||
|
var filter = txtFilter.Text?.Trim() ?? string.Empty;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(filter))
|
||||||
|
{
|
||||||
|
dgVariables.ItemsSource = _allVariables;
|
||||||
|
dgStrings.ItemsSource = _allStrings;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dgVariables.ItemsSource = _allVariables
|
||||||
|
.Where(v => v.DisplayName.Contains(filter, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
v.Category.Contains(filter, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
v.Value.ToString().Contains(filter, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
v.Offset.ToString("X").Contains(filter, StringComparison.OrdinalIgnoreCase))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
dgStrings.ItemsSource = _allStrings
|
||||||
|
.Where(s => s.Value.Contains(filter, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
s.Offset.ToString("X").Contains(filter, StringComparison.OrdinalIgnoreCase))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void txtFilter_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
ApplyFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数値ピンポイント検索(所持金・ステータス等)
|
||||||
|
/// </summary>
|
||||||
|
private void btnSearchValue_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (!int.TryParse(txtTargetValue.Text.Trim(), out int target))
|
||||||
|
{
|
||||||
|
MessageBox.Show("検索する数値を半角数字で入力してください。(例: 現在の所持金やステータス)", "入力エラー", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var matches = _allVariables.Where(v => v.Value == target).ToList();
|
||||||
|
if (matches.Count == 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"値が {target:N0} と一致する変数が見つかりませんでした。", "検索結果", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dgVariables.ItemsSource = matches;
|
||||||
|
lblStatus.Text = $"値 {target:N0} に一致する候補が {matches.Count} 件見つかりました。";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 検索された数値を一括で 9,999,999 に設定
|
||||||
|
/// </summary>
|
||||||
|
private void btnSetMaxTarget_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (dgVariables.ItemsSource is not IEnumerable<WolfVariableItem> currentList) return;
|
||||||
|
var list = currentList.ToList();
|
||||||
|
if (list.Count == 0) return;
|
||||||
|
|
||||||
|
var result = MessageBox.Show(
|
||||||
|
$"現在一覧に表示されている {list.Count} 件の数値をすべて 9,999,999 に変更しますか?\n(所持金やステータスの一括MAX化に便利です)",
|
||||||
|
"一括変更の確認", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||||
|
|
||||||
|
if (result == MessageBoxResult.Yes)
|
||||||
|
{
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
item.Value = 9999999;
|
||||||
|
}
|
||||||
|
dgVariables.Items.Refresh();
|
||||||
|
lblStatus.Text = $"{list.Count} 件の値を 9,999,999 に変更しました。保存ボタンを押すと反映されます。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 単一行のクイックMAX化
|
||||||
|
/// </summary>
|
||||||
|
private void btnQuickMax_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is Button btn && btn.Tag is WolfVariableItem item)
|
||||||
|
{
|
||||||
|
item.Value = 9999999;
|
||||||
|
dgVariables.Items.Refresh();
|
||||||
|
lblStatus.Text = $"{item.DisplayName} の値を 9,999,999 に設定しました。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dgVariables_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
|
||||||
|
{
|
||||||
|
lblStatus.Text = "値を編集しました。「上書き保存」を押すとバックアップを作成して保存されます。";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// セーブデータの上書き保存(Backupsへの完全自動退避付き)
|
||||||
|
/// </summary>
|
||||||
|
private void btnSave_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (_currentSaveData == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("保存対象のセーブデータがありません。", "エラー", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 変数リストの最新値をモデルへ反映
|
||||||
|
_currentSaveData.Variables = _allVariables;
|
||||||
|
|
||||||
|
// 保存実行 (自動バックアップ)
|
||||||
|
string backupPath = _saveService.SaveToFile(_currentSaveData, _game.FolderName, _game.RootDirectory);
|
||||||
|
|
||||||
|
var msg = $"セーブデータ '{_currentSaveData.FileName}' を安全に上書き保存しました!\n\n【バックアップ保存先】\n{backupPath}";
|
||||||
|
MessageBox.Show(msg, "保存完了", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
lblStatus.Text = $"保存完了 (バックアップ: {Path.GetFileName(backupPath)})";
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"保存中にエラーが発生しました:\n{ex.Message}", "保存エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
lblStatus.Text = $"保存エラー: {ex.Message}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// JSON エクスポート
|
||||||
|
/// </summary>
|
||||||
|
private void btnExportJson_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (_currentSaveData == null) return;
|
||||||
|
|
||||||
|
var sfd = new SaveFileDialog
|
||||||
|
{
|
||||||
|
Title = "セーブデータを JSON としてエクスポート",
|
||||||
|
Filter = "JSON ファイル (*.json)|*.json",
|
||||||
|
FileName = $"{Path.GetFileNameWithoutExtension(_currentSaveData.FileName)}_export.json"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (sfd.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_saveService.ExportToJson(_currentSaveData, sfd.FileName);
|
||||||
|
MessageBox.Show($"JSON ファイルをエクスポートしました:\n{sfd.FileName}", "エクスポート完了", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"エクスポートに失敗しました:\n{ex.Message}", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// JSON インポート
|
||||||
|
/// </summary>
|
||||||
|
private void btnImportJson_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (_currentSaveData == null) return;
|
||||||
|
|
||||||
|
var ofd = new OpenFileDialog
|
||||||
|
{
|
||||||
|
Title = "編集済み JSON ファイルを選択してください",
|
||||||
|
Filter = "JSON ファイル (*.json)|*.json"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (ofd.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_saveService.ImportFromJson(_currentSaveData, ofd.FileName);
|
||||||
|
_allVariables = [.. _currentSaveData.Variables];
|
||||||
|
ApplyFilter();
|
||||||
|
MessageBox.Show("JSON データを正常に取り込みました。「上書き保存」を押すとファイルへ反映されます。", "インポート完了", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"インポートに失敗しました:\n{ex.Message}", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// バックアップフォルダを開く
|
||||||
|
/// </summary>
|
||||||
|
private void btnOpenBackups_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dir = AppPathHelper.GetGameBackupDirectory(_game.FolderName, _game.RootDirectory);
|
||||||
|
if (!Directory.Exists(dir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
}
|
||||||
|
Process.Start(new ProcessStartInfo { FileName = dir, UseShellExecute = true });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"バックアップフォルダを開けませんでした:\n{ex.Message}", "エラー", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user