Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/feature-spec-roman-endless.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ internal static Dictionary<string, byte[]> Build(BackupManager backup, bool maxP
### 3.3 `src/Core/Services/PatchEngine.cs`

- 步驟 G(team.dat)改為傳入兩個布林:
`GetPatchedTeamDatBytes(backupManager, options.MaxPopulation, options.RomanEndless)`。
`GetPatchedTeamDatBytes(gamePath, backupManager, options.MaxPopulation, options.RomanEndless)`。
- log:新增鍵 `SvcLogTeamDatRoman`(見 §3.6),在 romanEndless 為 true 時輸出
「已將 {n} 張無盡地圖的玩家陣營改為羅馬」。既有
`SvcLogTeamDatApplied/Restored` 邏輯保持。
Expand Down
4 changes: 1 addition & 3 deletions src/Core/Features/FeatureDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,9 @@ internal PatchProfile Detect(string gamePath, BackupManager backupManager)
// 使用塞爾特祭司 FigKelPri00_Priester 偵測法師施法距離
bool spellEntireMap = false;
if (unitRows.TryGetValue("FigKelPri00_Priester", out var testSpellCols) &&
origUnitRows.TryGetValue("FigKelPri00_Priester", out var testSpellOrigCols))
origUnitRows.ContainsKey("FigKelPri00_Priester"))
{
double curRange = BackupManager.GetUnitMaxRange(testSpellCols, "priest");
double origRange = BackupManager.GetUnitMaxRange(testSpellOrigCols, "priest");
double expectedBaseRange = isFileBalanced ? 3840.0 : origRange;
if (curRange > 0)
{
if (Math.Abs(curRange - 30000.0) < 100.0)
Expand Down
11 changes: 9 additions & 2 deletions src/Core/Services/PatchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void ApplyPatches(string gamePath, PatchProfile profile, BackupManager ba
patchedFiles[Path.Combine(gamePath, @"SYSTEM\DATA_MP\DEFAULTS\objdef.dau")] = objdefBytes;

// G. team.dat
var teamDatPatches = GetPatchedTeamDatBytes(backupManager, options.MaxPopulation, options.RomanEndless);
var teamDatPatches = GetPatchedTeamDatBytes(gamePath, backupManager, options.MaxPopulation, options.RomanEndless);
foreach (var kvp in teamDatPatches)
{
patchedFiles[Path.Combine(gamePath, kvp.Key.Replace('/', '\\'))] = kvp.Value;
Expand Down Expand Up @@ -276,6 +276,8 @@ private void RestoreStatsFiles(string gamePath, BackupManager backupManager, Fil
if (kvp.Key.StartsWith("MAPS/", StringComparison.OrdinalIgnoreCase) && kvp.Key.EndsWith("team.dat", StringComparison.OrdinalIgnoreCase))
{
string destPath = Path.Combine(gamePath, kvp.Key.Replace('/', '\\'));
// 與套用路徑一致:地圖已被玩家移除時不重建其 team.dat。
if (!File.Exists(destPath)) continue;
byte[] patchedBytes = TeamDatPatcher.GetPatchedBytes(kvp.Value, new TeamDatOptions(false));
SafeWriteAllBytes(destPath, patchedBytes, rollback);
_logger.Log(string.Format(Loc.Get("SvcLogRestoredPopulation"), destPath));
Expand Down Expand Up @@ -304,9 +306,14 @@ private byte[] GetPatchedObjdefBytes(BackupManager backupManager, PatchProfile o
return ObjdefFeaturePatcher.Build(backupManager, options);
}

private Dictionary<string, byte[]> GetPatchedTeamDatBytes(BackupManager backupManager, bool maxPopulation, bool romanEndless)
private Dictionary<string, byte[]> GetPatchedTeamDatBytes(string gamePath, BackupManager backupManager, bool maxPopulation, bool romanEndless)
{
var results = MaxPopulationFeature.Build(backupManager, maxPopulation, romanEndless);
// 備份中可能保有玩家已自行移除的地圖;只改寫磁碟上仍存在的 team.dat,不重建已刪除的地圖檔。
foreach (string key in results.Keys.Where(k => !File.Exists(Path.Combine(gamePath, k.Replace('/', '\\')))).ToList())
{
results.Remove(key);
}
_logger.Log(maxPopulation ? string.Format(Loc.Get("SvcLogTeamDatApplied"), TeamDatPatcher.DefaultPopulationLimit, results.Count) : Loc.Get("SvcLogTeamDatRestored"));
int endlessCount = results.Keys.Count(key => key.StartsWith("MAPS/ENDL_", StringComparison.OrdinalIgnoreCase));
_logger.Log(romanEndless
Expand Down
Loading