Skip to content

Commit

Permalink
ADDED: Quick support for KH1
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpleHato committed May 14, 2021
1 parent 0ed760d commit e577082
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions KHPCPatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ static KHPCPatchManager(){
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}

static string[] kh1files = new string[]{
"kh1_first",
"kh1_second",
"kh1_third",
"kh1_fourth",
"kh1_fifth",
};

static string[] kh2files = new string[]{
"kh2_first",
"kh2_second",
Expand All @@ -57,7 +65,7 @@ static void Main(string[] args){
}

Console.WriteLine($"KHPCPatchManager {version}");
string hedFile = null, pkgFile = null, pkgFolder = null, kh2pcpatchFile = null;
string hedFile = null, pkgFile = null, pkgFolder = null, kh1pcpatchFile = null, kh2pcpatchFile = null;
List<string> patchFolders = new List<string>();
try{
for(int i=0;i<args.Length;i++){
Expand All @@ -68,6 +76,8 @@ static void Main(string[] args){
}else if(Directory.Exists(args[i])){
pkgFolder = args[i];
patchFolders.Add(args[i]);
}else if(Path.GetExtension(args[i]) == ".kh1pcpatch"){
kh1pcpatchFile = args[i];
}else if(Path.GetExtension(args[i]) == ".kh2pcpatch"){
kh2pcpatchFile = args[i];
}
Expand All @@ -89,12 +99,51 @@ static void Main(string[] args){
for(int i=0;i<patchFolders.Count;i++){
Console.WriteLine("Adding: {0}", patchFolders[i]);
zip.AddDirectory(patchFolders[i], "");
if (Directory.Exists(patchFolders[i] + @"\kh1_first") || Directory.Exists(patchFolders[i] + @"\kh1_second") || Directory.Exists(patchFolders[i] + @"\kh1_third") || Directory.Exists(patchFolders[i] + @"\kh1_fourth") || Directory.Exists(patchFolders[i] + @"\kh1_fifth")){
zip.Save("MyPatch.kh1pcpatch");
}else if (Directory.Exists(patchFolders[i] + @"\kh2_first") || Directory.Exists(patchFolders[i] + @"\kh2_second") || Directory.Exists(patchFolders[i] + @"\kh2_third") || Directory.Exists(patchFolders[i] + @"\kh2_fourth") || Directory.Exists(patchFolders[i] + @"\kh2_fifth") || Directory.Exists(patchFolders[i] + @"\kh2_sixth")){
zip.Save("MyPatch.kh2pcpatch");
}
}
zip.Save("MyPatch.kh2pcpatch");
}
Console.WriteLine("Done!");

}else if(kh1pcpatchFile != null){
Console.WriteLine("Applying KH1 patch...");
string epicFolder = null;
while(!Directory.Exists(epicFolder)){
Console.WriteLine("Please drag your \"en\" folder (the one that contains kh1_first, kh1_second, etc.) located under \"Kingdom Hearts HD 1 5 and 2 5 ReMIX/Image/\" here:");
epicFolder = Console.ReadLine().Trim('"');
}
Console.WriteLine("Extracting patch...");
string timestamp = kh1pcpatchFile + "_" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss_ms");
ZipFile zip = ZipFile.Read(kh1pcpatchFile);
Directory.CreateDirectory(timestamp);
string epicBackup = Path.Combine(epicFolder, "backup");
Directory.CreateDirectory(epicBackup);
zip.ExtractAll(timestamp, ExtractExistingFileAction.OverwriteSilently);
for(int i=0;i<kh1files.Length;i++){
string epicFile = Path.Combine(epicFolder, kh1files[i] + ".pkg");
string epicHedFile = Path.Combine(epicFolder, kh1files[i] + ".hed");
string patchFolder = Path.Combine(timestamp, kh1files[i]);
string epicPkgBackupFile = Path.Combine(epicBackup, kh1files[i] + ".pkg");
string epicHedBackupFile = Path.Combine(epicBackup, kh1files[i] + ".hed");
if(Directory.Exists(patchFolder) && File.Exists(epicFile)){
if(File.Exists(epicPkgBackupFile)) File.Delete(epicPkgBackupFile);
File.Move(epicFile, epicPkgBackupFile);
if(File.Exists(epicHedBackupFile)) File.Delete(epicHedBackupFile);
File.Move(epicHedFile, epicHedBackupFile);
Console.WriteLine($"Patching {epicFile}...");
var egs = new OpenKh.Command.IdxImg.Program.EpicGamesAssets.PatchCommand();
egs.Execute(epicPkgBackupFile, patchFolder, epicFolder);
}else{
Console.WriteLine($"Could not find {kh1files[i]} n/or any patch for it.");
}
}
Directory.Delete(timestamp, true);
Console.WriteLine("Done!");
}else if(kh2pcpatchFile != null){
Console.WriteLine("Applying patch...");
Console.WriteLine("Applying KH2 patch...");
string epicFolder = null;
while(!Directory.Exists(epicFolder)){
Console.WriteLine("Please drag your \"en\" folder (the one that contains kh2_first, kh2_second, etc.) located under \"Kingdom Hearts HD 1 5 and 2 5 ReMIX/Image/\" here:");
Expand Down Expand Up @@ -130,8 +179,8 @@ static void Main(string[] args){
}else{
Console.WriteLine("- Drop a .hed file to unpack the associated .pkg file");
Console.WriteLine("- Drop a .pkg file and its unpacked folder to patch it");
Console.WriteLine("- Drop a folder(s) (extracted .pkg format) to create a kh2pcpatch");
Console.WriteLine("- Drop a kh2pcpatch to patch your .pkgs");
Console.WriteLine("- Drop a folder(s) (extracted .pkg format) to create a kh2pcpatch or a kh2pcpatch");
Console.WriteLine("- Drop a kh1pcpatch or a kh2pcpatch to patch your .pkgs");
}
}catch(Exception e){
Console.WriteLine($"Error: {e}");
Expand Down

0 comments on commit e577082

Please sign in to comment.