-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2aa7e57
commit 9583573
Showing
21 changed files
with
1,720 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SenLib { | ||
public static class SenCommonPaths { | ||
public static readonly string Sen1SteamDir = @"c:\Program Files (x86)\Steam\steamapps\common\Trails of Cold Steel\"; | ||
public static readonly string Sen1GalaxyDir = @"c:\Program Files (x86)\GOG Galaxy\Games\The Legend of Heroes - Trails of Cold Steel\"; | ||
public static readonly string Sen1EnExePath = "ed8.exe"; | ||
public static readonly string Sen1JpExePath = "ed8jp.exe"; | ||
|
||
public static readonly string Sen2SteamDir = @"c:\Program Files (x86)\Steam\steamapps\common\Trails of Cold Steel II\"; | ||
public static readonly string Sen2GalaxyDir = @"c:\Program Files (x86)\GOG Galaxy\Games\The Legend of Heroes Trails of Cold Steel II\"; | ||
public static readonly string Sen2EnExePath = @"bin\Win32\ed8_2_PC_US.exe"; | ||
public static readonly string Sen2JpExePath = @"bin\Win32\ed8_2_PC_JP.exe"; | ||
|
||
public static readonly string BackupPostfix = ".senpatcher.bkp"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using HyoutaUtils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SenLib { | ||
public enum SenVersion { | ||
Sen1_v1_6_En, | ||
Sen1_v1_6_Jp, | ||
Sen2_v1_4_1_En, | ||
Sen2_v1_4_1_Jp, | ||
Sen2_v1_4_2_En, | ||
Sen2_v1_4_2_Jp, | ||
} | ||
|
||
public static class SenVersionIdentifier { | ||
public static (Stream binary, SenVersion? version) OpenAndIdentifyGame(string path) { | ||
if (!File.Exists(path)) { | ||
return (null, null); | ||
} | ||
|
||
var try1 = TryIdentify(path); | ||
|
||
if (try1.binary != null && try1.version != null) { | ||
return try1; | ||
} | ||
|
||
string backuppath = path + SenCommonPaths.BackupPostfix; | ||
if (File.Exists(backuppath)) { | ||
// we have a backup file, try that one | ||
return TryIdentify(backuppath); | ||
} | ||
|
||
return (null, null); | ||
} | ||
|
||
private static (Stream binary, SenVersion? version) TryIdentify(string p) { | ||
using (var s = new FileStream(p, FileMode.Open, FileAccess.Read, FileShare.Read)) { | ||
if (s.Length > 16 * 1024 * 1024) { | ||
// way too large to be any CS game | ||
return (null, null); | ||
} | ||
|
||
MemoryStream ms = s.CopyToMemory(); | ||
using (SHA1 sha1 = SHA1.Create()) { | ||
byte[] hashbytes = sha1.ComputeHash(ms); | ||
ms.Position = 0; | ||
StringBuilder sb = new StringBuilder(28); | ||
foreach (byte b in hashbytes) { | ||
sb.Append(b.ToString("x2")); | ||
} | ||
switch (sb.ToString()) { | ||
case "373c1d1b30001af360042365ed257e070bf40acc": return (ms, SenVersion.Sen1_v1_6_En); | ||
case "1d56abf5aa02eeae334797c287ef2109c7a103fa": return (ms, SenVersion.Sen1_v1_6_Jp); | ||
case "d5c333b4cd517d43e3868e159fbec37dba4122d6": return (ms, SenVersion.Sen2_v1_4_1_En); | ||
case "b8158fb59e43c02e904f813150d841336d1a13e5": return (ms, SenVersion.Sen2_v1_4_1_Jp); | ||
case "b08ece4ee38e6e3a99e58eb11cffb45e49704f86": return (ms, SenVersion.Sen2_v1_4_2_En); | ||
case "7d1db7e0bb91ab77a3fd1eba53b0ed25806186c1": return (ms, SenVersion.Sen2_v1_4_2_Jp); | ||
default: ms.Dispose(); return (null, null); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" /> | ||
</startup> | ||
</configuration> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using SenLib; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace SenPatcherGui { | ||
public partial class MainForm : Form { | ||
public MainForm() { | ||
InitializeComponent(); | ||
} | ||
|
||
private void buttonCs1SteamEn_Click(object sender, EventArgs e) { | ||
OpenFileGui(Path.Combine(SenCommonPaths.Sen1SteamDir, SenCommonPaths.Sen1EnExePath), new List<SenVersion>() { SenVersion.Sen1_v1_6_En }); | ||
} | ||
|
||
private void buttonCs1SteamJp_Click(object sender, EventArgs e) { | ||
OpenFileGui(Path.Combine(SenCommonPaths.Sen1SteamDir, SenCommonPaths.Sen1JpExePath), new List<SenVersion>() { SenVersion.Sen1_v1_6_Jp }); | ||
} | ||
|
||
private void buttonCs1GalaxyEn_Click(object sender, EventArgs e) { | ||
OpenFileGui(Path.Combine(SenCommonPaths.Sen1GalaxyDir, SenCommonPaths.Sen1EnExePath), new List<SenVersion>() { SenVersion.Sen1_v1_6_En }); | ||
} | ||
|
||
private void buttonCs1GalaxyJp_Click(object sender, EventArgs e) { | ||
OpenFileGui(Path.Combine(SenCommonPaths.Sen1GalaxyDir, SenCommonPaths.Sen1JpExePath), new List<SenVersion>() { SenVersion.Sen1_v1_6_Jp }); | ||
} | ||
|
||
private void buttonCs2SteamEn_Click(object sender, EventArgs e) { | ||
OpenFileGui(Path.Combine(SenCommonPaths.Sen2SteamDir, SenCommonPaths.Sen2EnExePath), new List<SenVersion>() { SenVersion.Sen2_v1_4_1_En, SenVersion.Sen2_v1_4_2_En }); | ||
} | ||
|
||
private void buttonCs2SteamJp_Click(object sender, EventArgs e) { | ||
OpenFileGui(Path.Combine(SenCommonPaths.Sen2SteamDir, SenCommonPaths.Sen2JpExePath), new List<SenVersion>() { SenVersion.Sen2_v1_4_1_Jp, SenVersion.Sen2_v1_4_2_Jp }); | ||
} | ||
|
||
private void buttonCs2GalaxyEn_Click(object sender, EventArgs e) { | ||
OpenFileGui(Path.Combine(SenCommonPaths.Sen2GalaxyDir, SenCommonPaths.Sen2EnExePath), new List<SenVersion>() { SenVersion.Sen2_v1_4_1_En, SenVersion.Sen2_v1_4_2_En }); | ||
} | ||
|
||
private void buttonCs2GalaxyJp_Click(object sender, EventArgs e) { | ||
OpenFileGui(Path.Combine(SenCommonPaths.Sen2GalaxyDir, SenCommonPaths.Sen2JpExePath), new List<SenVersion>() { SenVersion.Sen2_v1_4_1_Jp, SenVersion.Sen2_v1_4_2_Jp }); | ||
} | ||
|
||
private void buttonManuallySelect_Click(object sender, EventArgs e) { | ||
using (OpenFileDialog d = new OpenFileDialog()) { | ||
d.Filter = "Cold Steel executables (ed8*.exe)|ed8*.exe|All files (*.*)|*.*"; | ||
if (d.ShowDialog() == DialogResult.OK) { | ||
OpenFileGui(d.FileName, null); | ||
} | ||
} | ||
} | ||
|
||
private void OpenFileGui(string path, List<SenVersion> expectedVersions) { | ||
if (!File.Exists(path)) { | ||
MessageBox.Show("No file found at " + path + "."); | ||
return; | ||
} | ||
|
||
Stream binary = null; | ||
SenVersion? actualVersion = null; | ||
try { | ||
(binary, actualVersion) = SenVersionIdentifier.OpenAndIdentifyGame(path); | ||
} catch (Exception ex) { | ||
MessageBox.Show("Error while identifying " + path + ": " + ex.ToString()); | ||
return; | ||
} | ||
|
||
if (binary == null || actualVersion == null) { | ||
MessageBox.Show("Could not identify file at " + path + " as any supported Cold Steel executable."); | ||
return; | ||
} | ||
|
||
if (actualVersion == SenVersion.Sen1_v1_6_En || actualVersion == SenVersion.Sen1_v1_6_Jp) { | ||
new Sen1Form(path, binary, actualVersion.Value).ShowDialog(); | ||
return; | ||
} | ||
|
||
if (actualVersion == SenVersion.Sen2_v1_4_1_En || actualVersion == SenVersion.Sen2_v1_4_1_Jp || actualVersion == SenVersion.Sen2_v1_4_2_En || actualVersion == SenVersion.Sen2_v1_4_2_Jp) { | ||
new Sen2Form(path, binary, actualVersion.Value).ShowDialog(); | ||
return; | ||
} | ||
|
||
MessageBox.Show("Internal error?"); | ||
} | ||
} | ||
} |
Oops, something went wrong.