Files
GameLauncher/Services/Codecs/YurisSaveCodec.cs
T
armonica 8cea2a147d 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/ の再帰配置に対応
2026-10-07 02:30:49 +09:00

137 lines
4.3 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using GameLauncher.Models;
using GameLauncher.Engines.Unity;
namespace GameLauncher.Services.Codecs
{
/// <summary>
/// YU-RIS エンジン形式のセーブデータ(YSSD シグネチャ)用コーデック
/// </summary>
public class YurisSaveCodec : ISaveDataCodec
{
public string CodecName => "YU-RIS セーブデータ (YSSD) コーデック";
public bool RequiresPassword => false;
public string? PasswordPromptMessage => null;
public bool CanHandle(UnityGameItem game, SaveFileEntry file)
{
if (!File.Exists(file.FilePath)) return false;
try
{
using var fs = File.OpenRead(file.FilePath);
if (fs.Length < 16) return false;
var magic = new byte[4];
fs.ReadExactly(magic);
// "YSSD" (0x59 0x53 0x53 0x44)
return magic[0] == 0x59 && magic[1] == 0x53 && magic[2] == 0x53 && magic[3] == 0x44;
}
catch
{
return false;
}
}
public List<SaveDataPropertyEntry> LoadProperties(string filePath, string? optionalPassword = null)
{
var list = new List<SaveDataPropertyEntry>();
if (!File.Exists(filePath)) return list;
byte[] bytes = File.ReadAllBytes(filePath);
if (bytes.Length < 16) return list;
int headerSize = BitConverter.ToInt32(bytes, 4);
int version = BitConverter.ToInt32(bytes, 8);
list.Add(new SaveDataPropertyEntry
{
Key = "Signature",
Category = "ヘッダー情報",
Type = "String",
EditValue = "YSSD (YU-RIS Save Data)",
Description = "セーブ識別子"
});
list.Add(new SaveDataPropertyEntry
{
Key = "HeaderSize",
Category = "ヘッダー情報",
Type = "Int32",
EditValue = headerSize.ToString(),
Description = "ヘッダーサイズ"
});
list.Add(new SaveDataPropertyEntry
{
Key = "SaveVersion",
Category = "ヘッダー情報",
Type = "Int32",
EditValue = version.ToString(),
Description = "セーブバージョン番号"
});
// 16バイト以降の変数領域から、4バイト整数および文字列をスキャン
int offset = 16;
int varIndex = 0;
while (offset + 4 <= bytes.Length && varIndex < 100)
{
int val = BitConverter.ToInt32(bytes, offset);
list.Add(new SaveDataPropertyEntry
{
Key = $"Var_{varIndex:D3} (0x{offset:X4})",
Category = "ゲーム変数 / フラグ",
Type = "Int32",
EditValue = val.ToString(),
Description = $"オフセット 0x{offset:X4} の4バイト値",
RawData = offset
});
offset += 4;
varIndex++;
}
return list;
}
public bool SaveProperties(string filePath, List<SaveDataPropertyEntry> properties, string? optionalPassword = null)
{
try
{
byte[] bytes = File.ReadAllBytes(filePath);
foreach (var prop in properties)
{
if (prop.RawData is int offset && offset + 4 <= bytes.Length)
{
if (int.TryParse(prop.EditValue, out int val))
{
var b = BitConverter.GetBytes(val);
Array.Copy(b, 0, bytes, offset, 4);
}
}
}
if (File.Exists(filePath))
{
File.Copy(filePath, filePath + ".bak", overwrite: true);
}
File.WriteAllBytes(filePath, bytes);
return true;
}
catch
{
return false;
}
}
}
}