-
Notifications
You must be signed in to change notification settings - Fork 3
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
Xilophor
committed
Jan 25, 2024
1 parent
a3fa50d
commit 0366f60
Showing
6 changed files
with
72 additions
and
52 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,30 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using HarmonyLib; | ||
|
||
namespace LobbyCompatibility.Features; | ||
|
||
/// <summary> | ||
/// Helper class related to Harmony Patching. | ||
/// </summary> | ||
internal class HarmonyHelper | ||
{ | ||
/// <summary> | ||
/// Retrieves the MethodInfo of the compiler-generated async method. | ||
/// Async method content is not actually in the <c>async Method()</c>, but instead is in a separate <c>struct</c> under the method "MoveNext"; | ||
/// this function retrieves that method info. | ||
/// </summary> | ||
/// <param name="type">(<see cref="Type"/>) The type of the class housing the method.</param> | ||
/// <param name="method">(<see cref="string"/>) The name of the method being patched.</param> | ||
/// <returns>(<see cref="MethodInfo"/>) The info of the async "MoveNext" method.</returns> | ||
public static MethodInfo? GetAsyncInfo(Type type, string method) | ||
{ | ||
// Get the Method Info of the target Async Method | ||
return AccessTools.Method(type, method) | ||
// Find the AsyncStateMachine class from target method | ||
.GetCustomAttribute<AsyncStateMachineAttribute>() | ||
// Get the struct type (random compiler junk) | ||
.StateMachineType.GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.NonPublic); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
LobbyCompatibility/Patches/ES3SettingsConstructorPrefix.cs
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 HarmonyLib; | ||
|
||
namespace LobbyCompatibility.Patches; | ||
|
||
/// <summary> | ||
/// Patches <see cref="ES3Settings(string, ES3Settings)" />. | ||
/// Creates a separate modded challenge save file. | ||
/// </summary> | ||
/// <seealso cref="ES3Settings(string, ES3Settings)" /> | ||
[HarmonyPatch(typeof(ES3Settings), MethodType.Constructor, new Type[] { typeof(string), typeof(ES3Settings) })] | ||
[HarmonyPriority(Priority.Last)] | ||
[HarmonyWrapSafe] | ||
internal class ES3SettingsConstructorPrefix | ||
{ | ||
[HarmonyPrefix] | ||
private static void FileSettings(ref string path) | ||
{ | ||
path = path == "LCChallengeFile" ? "LCModdedChallengeFile" : path; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
LobbyCompatibility/Patches/FindOrCreateLeaderboardPrefix.cs
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 HarmonyLib; | ||
using Steamworks; | ||
|
||
namespace LobbyCompatibility.Patches; | ||
|
||
/// <summary> | ||
/// Patches <see cref="ISteamUserStats.FindOrCreateLeaderboard" />. | ||
/// Changes the target leaderboard to a modded one. | ||
/// </summary> | ||
/// <seealso cref="ISteamUserStats.FindOrCreateLeaderboard" /> | ||
[HarmonyPatch(typeof(ISteamUserStats), nameof(ISteamUserStats.FindOrCreateLeaderboard))] | ||
[HarmonyPriority(Priority.Last)] | ||
[HarmonyWrapSafe] | ||
internal class FindOrCreateLeaderboardPrefix | ||
{ | ||
[HarmonyPrefix] | ||
private static void Prefix(ref string pchLeaderboardName) | ||
{ | ||
pchLeaderboardName = (pchLeaderboardName.StartsWith("challenge")) ? $"modded_{pchLeaderboardName}" : pchLeaderboardName; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.