-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Settings): save config to disk periodically
- Loading branch information
1 parent
22237a1
commit 60310e8
Showing
4 changed files
with
100 additions
and
0 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
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,34 @@ | ||
using System.IO; | ||
using System.Reflection; | ||
using HarmonyLib; | ||
using JetBrains.Annotations; | ||
using Osu.Stubs.Helpers; | ||
using Osu.Utils; | ||
|
||
namespace Osu.Patcher.Hook.Patches.PatcherOptions; | ||
|
||
/// <summary> | ||
/// Hooks osu!'s datastore saving mechanism to save our own options every so often. | ||
/// </summary> | ||
[OsuPatch] | ||
[HarmonyPatch] | ||
[UsedImplicitly] | ||
internal static class SaveOptions | ||
{ | ||
[UsedImplicitly] | ||
[HarmonyTargetMethod] | ||
private static MethodBase Target() => DataStoreUpdater.Save.Reference; | ||
|
||
[UsedImplicitly] | ||
[HarmonyPostfix] | ||
internal static void Save() | ||
{ | ||
var osuDir = Path.GetDirectoryName(OsuAssembly.Assembly.Location)!; | ||
var settings = new Settings(); | ||
|
||
// Write settings to this instance | ||
Hook.PatchOptions.Do(opts => opts.Save(settings)); | ||
|
||
Settings.WriteToDisk(settings, osuDir); | ||
} | ||
} |
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 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,38 @@ | ||
using JetBrains.Annotations; | ||
using Osu.Utils.Lazy; | ||
using static System.Reflection.Emit.OpCodes; | ||
|
||
namespace Osu.Stubs.Helpers; | ||
|
||
/// <summary> | ||
/// Original: <c>osu.Helpers.DataStoreUpdater</c> | ||
/// </summary> | ||
[PublicAPI] | ||
public class DataStoreUpdater | ||
{ | ||
/// <summary> | ||
/// Original: <c>Save(bool final)</c> | ||
/// </summary> | ||
[Stub] | ||
public static readonly LazyMethod<bool> Save = LazyMethod<bool>.ByPartialSignature( | ||
"osu.Helpers.DataStoreUpdater::Save(bool)", | ||
[ | ||
Ldc_I4_0, | ||
Stloc_0, | ||
Leave_S, | ||
Ldarg_0, | ||
Ldsfld, | ||
Stfld, | ||
Ldarg_0, | ||
Ldc_I4_0, | ||
Stfld, | ||
Ldarg_0, | ||
Ldfld, | ||
Callvirt, | ||
Pop, | ||
Endfinally, | ||
Ldloc_0, | ||
Ret, | ||
] | ||
); | ||
} |