Skip to content

Commit

Permalink
Added: Uninstall Hint to Loader Log
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Mar 17, 2024
1 parent e9d256b commit 1721e1a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

/* For C# source, see EntryPoint.cs */
#define CURRENT_VERSION 7
#define CURRENT_VERSION 8

enum EntryPointFlags : int
{
Expand All @@ -19,6 +19,7 @@ struct EntryPointParameters
public:
int version { CURRENT_VERSION };
EntryPointFlags flags { None };
LPWSTR dll_path { nullptr };

EntryPointParameters() = default;
};
Expand Down
4 changes: 4 additions & 0 deletions source/Reloaded.Mod.Loader.Bootstrapper/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ bool load_reloaded(ReloadedPaths& reloadedPaths)
throw std::exception("Failed to load .NET assembly.");
}

// Set path to current dll
// Using GetModuleFileNameW
entryPointParameters.dll_path = new wchar_t[MAX_PATH];
GetModuleFileNameW(thisProcessModule, entryPointParameters.dll_path, MAX_PATH);
initialize(&entryPointParameters, sizeof(EntryPointParameters));
return true;
}
Expand Down
10 changes: 9 additions & 1 deletion source/Reloaded.Mod.Loader/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,18 @@ private static unsafe void SetupLoader2(EntryPointParameters* parameters)

var setupHooksTask = Task.Run(() => ExecuteTimed("Setting Up Hooks (Async)", () => SetupHooks(hooks)));
InitialiseParameters(parameters);
if (_parameters.SupportsDllPath && _parameters.DllPath != null)
{
var reloadedPath = Marshal.PtrToStringUni((nint)_parameters.DllPath);
Logger!.LogWriteLineAsync($"Loaded via: {reloadedPath}", Logger.ColorInformation);
if (reloadedPath!.EndsWith(".asi"))
Logger!.LogWriteLineAsync($"Remove the above `.asi` file to uninstall. (Should be in your app/game folder)", Logger.ColorInformation);
}

ExecuteTimed("Loading Mods (Total)", () => LoadMods(hooks));

setupHooksTask.Wait();
Logger?.LogWriteLineAsync($"Total Loader Initialization Time: {_stopWatch.ElapsedMilliseconds}ms");
Logger!.LogWriteLineAsync($"Total Loader Initialization Time: {_stopWatch.ElapsedMilliseconds}ms");
_stopWatch.Reset();
}

Expand Down
17 changes: 16 additions & 1 deletion source/Reloaded.Mod.Shared/EntryPointParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct EntryPointParameters
/// <summary>
/// Current version of parameters.
/// </summary>
public const int CurrentVersion = 7;
public const int CurrentVersion = 8;

// Version 1
/// <summary>
Expand All @@ -30,6 +30,11 @@ public struct EntryPointParameters
// Version 2
// ...

/// <summary>
/// Contains the path to the native DLL which loaded the loader.
/// </summary>
public unsafe char* DllPath;

/// <summary>
/// Checks if struct is using latest version.
/// </summary>
Expand All @@ -55,9 +60,19 @@ public static unsafe EntryPointParameters Copy(EntryPointParameters* pointer)
result.Version = pointer->Version;
result.Flags = pointer->Flags;
}

if (pointer->Version >= 8)
{
result.DllPath = pointer->DllPath;
}

return result;
}

/// <summary>
/// True if reading the DLL path is supported.
/// </summary>
public bool SupportsDllPath => Version >= 8;
}

/// <summary>
Expand Down

0 comments on commit 1721e1a

Please sign in to comment.