-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathGameService.cs
More file actions
87 lines (80 loc) · 3.41 KB
/
GameService.cs
File metadata and controls
87 lines (80 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using OpenKh.Common;
using OpenKh.Tools.ModsManager.Models;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace OpenKh.Tools.ModsManager.Services
{
public static class GameService
{
private const int BlockIso = 0x800;
private static readonly List<GameInfoModel> Games = new()
{
new GameInfoModel()
{
Id = "kh1",
Name = "Kingdom Hearts I",
UniqueFileName = "btltbl.bin",
Detectors = new()
{
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLPS_251.97;1" },
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLPS_251.98;1" },
}
},
new GameInfoModel()
{
Id = "kh2",
Name = "Kingdom Hearts II",
UniqueFileName = "00objentry.bin",
Detectors = new()
{
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLPM_662.33;1" },
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLUS_210.05;1" },
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_541.14;1" },
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_542.32;1" },
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_542.33;1" },
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLES_542.34;1" },
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLPM_666.75;1" },
}
},
new GameInfoModel()
{
Id = "Recom",
Name = "Kingdom Hearts Re:Chain of Memories",
UniqueFileName = "CST_sora.pss",
Detectors = new()
{
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLPM_666.76;1" },
new GameDetectorModel { FileName = "SYSTEM.CNF;1", ProductId = "SLUS_217.99;1" },
}
}
};
public static GameInfoModel DetectGameId(string isoFilePath)
{
using var stream = File.OpenRead(isoFilePath);
foreach (var game in Games)
{
foreach (var detector in game.Detectors)
{
var blockIndex = IsoUtility.GetFileOffset(stream, detector.FileName);
if (blockIndex < 0)
continue;
var data = stream.SetPosition(blockIndex * BlockIso).ReadBytes(BlockIso);
var expectData = Encoding.UTF8.GetBytes(detector.ProductId);
if (string.Join(' ', data).Contains(string.Join(' ', expectData))) // TODO: inefficient, but it works lol
return game;
}
}
return default;
}
public static GameInfoModel Lookup(string gameId) => Games.FirstOrDefault(x => x.Id == gameId);
public static bool FolderContainsUniqueFile(string gameId, string path)
{
var game = Lookup(gameId);
if (game == null)
return false;
return File.Exists(Path.Combine(path, game.UniqueFileName));
}
}
}