Skip to content

Commit

Permalink
Use AurieLoader in game directory
Browse files Browse the repository at this point in the history
- Removes hardcoded AurieLoader path from the installer, now defaults to %gamedir%\mods\AurieLoader.exe
- Added MmGetFrameworkVersion call to allow plugins to bail if a required feature is not yet implemented in Aurie.
  • Loading branch information
Archie-osu committed Nov 18, 2023
1 parent d72d0d1 commit f65341a
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 6 deletions.
16 changes: 16 additions & 0 deletions Aurie/source/framework/Memory Manager/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,20 @@ namespace Aurie
return hook_object->HookInstance.original<PVOID>();
}

EXPORTED void MmGetFrameworkVersion(
OUT OPTIONAL short* Major,
OUT OPTIONAL short* Minor,
OUT OPTIONAL short* Patch
)
{
if (Major)
*Major = AURIE_FWK_MAJOR;

if (Minor)
*Minor = AURIE_FWK_MINOR;

if (Patch)
*Patch = AURIE_FWK_PATCH;
}

}
6 changes: 6 additions & 0 deletions Aurie/source/framework/Memory Manager/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

namespace Aurie
{
EXPORTED void MmGetFrameworkVersion(
OUT OPTIONAL short* Major,
OUT OPTIONAL short* Minor,
OUT OPTIONAL short* Patch
);

// Allocates memory that may be freed only after the Aurie Framework gets unloaded.
EXPORTED PVOID MmAllocatePersistentMemory(
IN size_t Size
Expand Down
22 changes: 22 additions & 0 deletions Aurie/source/framework/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
#define OPTIONAL
#endif

#ifndef AURIE_FWK_MAJOR
#define AURIE_FWK_MAJOR 1
#endif // AURIE_FWK_MAJOR

#ifndef AURIE_FWK_MINOR
#define AURIE_FWK_MINOR 0
#endif // AURIE_FWK_MINOR

#ifndef AURIE_FWK_PATCH
#define AURIE_FWK_PATCH 0
#endif // AURIE_FWK_PATCH


namespace Aurie
{
namespace fs = ::std::filesystem;
Expand Down Expand Up @@ -260,6 +273,15 @@ namespace Aurie
return AURIE_API_CALL(ElIsProcessSuspended, Suspended);
}

inline void MmGetFrameworkVersion(
OUT OPTIONAL short* Major,
OUT OPTIONAL short* Minor,
OUT OPTIONAL short* Patch
)
{
return AURIE_API_CALL(MmGetFrameworkVersion, Major, Minor, Patch);
}

inline PVOID MmAllocatePersistentMemory(
IN size_t Size
)
Expand Down
70 changes: 66 additions & 4 deletions AurieInstaller/ViewModels/Pages/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
using Microsoft.Extensions.Options;
using Microsoft.Win32;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Windows.Input;

namespace AurieInstaller.ViewModels.Pages
{
public partial class DashboardViewModel : ObservableObject
{
private readonly string m_IFEOPath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options";
private static readonly string m_IFEOPath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options";

internal static void ThrowError(string Message)
{
Expand All @@ -35,17 +37,45 @@ internal static OpenFileDialog PickGame(string Title, string Filter)
return runner_selection_dialog;
}

internal RegistryKey? GetIFEOKey(bool WriteAccess)
internal static RegistryKey? GetIFEOKey(bool WriteAccess)
{
return Registry.LocalMachine.OpenSubKey(m_IFEOPath, WriteAccess);
}

internal RegistryKey? GetRunnerKey(string RunnerName, bool WriteAccess)
internal static RegistryKey? GetRunnerKey(string RunnerName, bool WriteAccess)
{
using RegistryKey? ifeo = GetIFEOKey(WriteAccess);
return ifeo?.CreateSubKey(RunnerName, true);
}

internal static List<RegistryKey> GetAurieInstallerKeys()
{
List<RegistryKey> keys = new();

using (RegistryKey? ifeo = GetIFEOKey(false))
{
if (ifeo is null)
{
ThrowError("Failed to get runner IFEO key!");
return keys;
}

foreach (string subkey in ifeo.GetSubKeyNames())
{
RegistryKey? key = ifeo.OpenSubKey(subkey, false);
if (key is null)
continue;

if (!key.GetValueNames().Contains("IsAurieInstallerKey"))
continue;

keys.Add(key);
}
}

return keys;
}

[RelayCommand]
private void OnUninstallButton()
{
Expand All @@ -72,6 +102,18 @@ private void OnUninstallButton()

string registry_runner_path = runner_path.Replace('\\', '_');

if (!runner_key.GetValueNames().Contains("IsAurieInstallerKey"))
{
MessageBox.Show(
"The Aurie Framework registry key is corrupt.\nReinstall the framework and try again.",
"Key is corrupt.",
MessageBoxButton.OK,
MessageBoxImage.Error
);

return;
}

if (!runner_key.GetSubKeyNames().Contains(registry_runner_path))
{
MessageBox.Show(
Expand All @@ -85,6 +127,13 @@ private void OnUninstallButton()
}

runner_key.DeleteSubKeyTree(registry_runner_path);

// If there's no more stuff registered for this runner key, remove the runner key completely
if (runner_key.GetSubKeyNames().Length == 0)
{
using RegistryKey? ifeo = GetIFEOKey(true);
ifeo?.DeleteSubKeyTree(runner_name);
}
}

MessageBox.Show(
Expand Down Expand Up @@ -126,6 +175,7 @@ private void OnInstallButton()
}

// Set up the UseFilter registry key
runner_key.SetValue("IsAurieInstallerKey", 1, RegistryValueKind.DWord);
runner_key.SetValue("UseFilter", 1, RegistryValueKind.DWord);

string registry_runner_path = runner_path.Replace('\\', '_');
Expand All @@ -151,7 +201,19 @@ private void OnInstallButton()
return;
}

filter_subkey.SetValue("Debugger", @"E:\Code\GitHub\Aurie\x64\Debug\AurieLoader.exe");
// Craft the path to %GAMEFOLDER%\\mods
// TODO: Create an entry in %localappdata% that has the loader so that
// one loader can be reused for multiple games.
string loader_path = Directory.GetParent(runner_path)?.FullName ?? "";
if (loader_path.Equals(string.Empty))
{
ThrowError("Failed to get game folder!");
return;
}

loader_path = Path.Combine(loader_path, "mods", "AurieLoader.exe");

filter_subkey.SetValue("Debugger", loader_path);
filter_subkey.SetValue("FilterFullPath", runner_path);
}
}
Expand Down
22 changes: 22 additions & 0 deletions TestModule/source/Aurie/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
#define OPTIONAL
#endif

#ifndef AURIE_FWK_MAJOR
#define AURIE_FWK_MAJOR 1
#endif // AURIE_FWK_MAJOR

#ifndef AURIE_FWK_MINOR
#define AURIE_FWK_MINOR 0
#endif // AURIE_FWK_MINOR

#ifndef AURIE_FWK_PATCH
#define AURIE_FWK_PATCH 0
#endif // AURIE_FWK_PATCH


namespace Aurie
{
namespace fs = ::std::filesystem;
Expand Down Expand Up @@ -260,6 +273,15 @@ namespace Aurie
return AURIE_API_CALL(ElIsProcessSuspended, Suspended);
}

inline void MmGetFrameworkVersion(
OUT OPTIONAL short* Major,
OUT OPTIONAL short* Minor,
OUT OPTIONAL short* Patch
)
{
return AURIE_API_CALL(MmGetFrameworkVersion, Major, Minor, Patch);
}

inline PVOID MmAllocatePersistentMemory(
IN size_t Size
)
Expand Down
4 changes: 2 additions & 2 deletions TestModule/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ EXPORTED AurieStatus ModulePreinitialize(

bool is_game_suspended = false;
ElIsProcessSuspended(is_game_suspended);
printf("[TestModule] ModulePreload. ElIsProcessSuspended returns %d\n", is_game_suspended);
printf("[TestModule] ModulePreload. ElIsProcessSuspended returns %s\n", is_game_suspended ? "true" : "false");

return AURIE_SUCCESS;
}
Expand All @@ -28,7 +28,7 @@ EXPORTED AurieStatus ModuleInitialize(
{
AurieStatus last_status = AURIE_SUCCESS;

printf("Hello from the first Aurie Framework module!\n");
printf("Hello from the test Aurie Framework module!\n");
printf("- AurieModule: %p\n", Module);
printf("- ModulePath: %S\n", ModulePath.wstring().c_str());
printf("- g_ArInitialImage: %p\n", g_ArInitialImage);
Expand Down

0 comments on commit f65341a

Please sign in to comment.