Skip to content

Commit

Permalink
Fix challenge menus in training room
Browse files Browse the repository at this point in the history
  • Loading branch information
loriswit committed Oct 7, 2023
1 parent e375254 commit 7dfb7da
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Rlcm/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public partial class App

private void AppStartup(object sender, StartupEventArgs startupEventArgs)
{
Version.Number = 312;
Version.Name = "3.1.2";
Version.Number = 313;
Version.Name = "3.1.3";

var args = Environment.GetCommandLineArgs();
if (args.Contains("--updated") || args.Contains("-u"))
Expand Down
58 changes: 33 additions & 25 deletions Rlcm/Game/TrainingRoom.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
Expand Down Expand Up @@ -42,16 +43,17 @@ public void SetGameLocation(string location)
Settings.SetValue("GameLocation", _location);
}

public void InstallMod()
public void InstallMod(bool skipWarning = false)
{
var patchFilename = _location + PatchName;
if (File.Exists(patchFilename))
{
MessageBox.Show(
"There is already a patch in the game folder.\n\n"
+ "Installing the training room will replace the existing patch, "
+ "which will be restored when uninstalling the training room.",
"Existing patch found", MessageBoxButton.OK, MessageBoxImage.Information);
if (!skipWarning)
MessageBox.Show(
"There is already a patch in the game folder.\n\n"
+ "Installing the training room will replace the existing patch, "
+ "which will be restored when uninstalling the training room.",
"Existing patch found", MessageBoxButton.OK, MessageBoxImage.Information);

var uuid = Guid.NewGuid();
File.Move(patchFilename, _location + uuid + ".ipk");
Expand All @@ -64,30 +66,33 @@ public void InstallMod()
new BinaryWriter(file).Write(modData);
}

public void UninstallMod()
public void UninstallMod(bool skipWarning = false, bool skipRestore = false)
{
var patchFilename = _location + PatchName;
File.Delete(patchFilename);

// restore the previous saved patch, if any
var uuid = Settings.GetValue("PreviousPatch");
if (uuid != null)
if (!skipRestore)
{
try
{
File.Move(_location + uuid + ".ipk", patchFilename);
}
catch (IOException e)
var uuid = Settings.GetValue("PreviousPatch");
if (uuid != null)
{
MessageBox.Show(e.Message, "Failed to restore previous patch",
MessageBoxButton.OK, MessageBoxImage.Warning);
try
{
File.Move(_location + uuid + ".ipk", patchFilename);
}
catch (IOException e)
{
MessageBox.Show(e.Message, "Failed to restore previous patch",
MessageBoxButton.OK, MessageBoxImage.Warning);
}

Settings.DeleteValue("PreviousPatch");
}

Settings.DeleteValue("PreviousPatch");
}

// show warning only once
if (Settings.GetValue("UninstallWarning") == null)
if (!skipWarning && Settings.GetValue("UninstallWarning") == null)
{
MessageBox.Show(
"If you installed the mod with a previous version of RLCM, "
Expand All @@ -101,18 +106,21 @@ public void UninstallMod()
}

public bool IsModInstalled()
{
return CheckPatch(new byte[]
{
0x25, 0xc6, 0x2f, 0x1f, 0x93, 0x8b, 0x61, 0xc3,
0x91, 0x57, 0x68, 0xe1, 0x25, 0x5d, 0x7b, 0x17
});
}

public bool CheckPatch(IEnumerable<byte> checksum)
{
var patchFilename = _location + PatchName;

if (GameNotFound() || !File.Exists(patchFilename))
return false;

byte[] checksum =
{
0x86, 0xa, 0xb4, 0xcc, 0xf1, 0x9f, 0x94, 0xf1,
0xe7, 0xb8, 0xe7, 0xf3, 0x6b, 0x72, 0x82, 0x7e
};

using var file = File.OpenRead(patchFilename);
var hash = MD5.Create().ComputeHash(file);
return checksum.SequenceEqual(hash);
Expand Down
Binary file modified Rlcm/Resources/Mod/patch_PC.ipk
Binary file not shown.
22 changes: 20 additions & 2 deletions Rlcm/Util/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using System.Web.Script.Serialization;
using System.Windows;
using Rlcm.Game;
using Rlcm.Windows;

namespace Rlcm.Util
Expand Down Expand Up @@ -43,7 +44,7 @@ public static void Update()
File.Move(newPath, path);

// start the new version
var process = new Process {StartInfo = {FileName = path, Arguments = "--updated"}};
var process = new Process { StartInfo = { FileName = path, Arguments = "--updated" } };
process.Start();

Application.Current.Shutdown();
Expand Down Expand Up @@ -74,7 +75,24 @@ public static void OnUpdated()
Thread.Sleep(500);
}

MessageBox.Show("Successfully updated to version " + App.Version.Name,
// if the old patch is installed, update it
var patchUpdated = false;
var trainingRoom = new TrainingRoom();
if (trainingRoom.CheckPatch(new byte[]
{
0x86, 0xa, 0xb4, 0xcc, 0xf1, 0x9f, 0x94, 0xf1,
0xe7, 0xb8, 0xe7, 0xf3, 0x6b, 0x72, 0x82, 0x7e
}))
{
trainingRoom.UninstallMod(skipWarning: true, skipRestore: true);
trainingRoom.InstallMod(skipWarning: true);
patchUpdated = true;
}

MessageBox.Show("Successfully updated to version " + App.Version.Name +
(patchUpdated ? "\n\nThe training room mod has been automatically updated." : "") +
"\n\nWhat's new?\n" +
"• The challenge menus are now displayed correctly in the training room.",
"RLCM Updated", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
Expand Down

0 comments on commit 7dfb7da

Please sign in to comment.