-
Notifications
You must be signed in to change notification settings - Fork 1
/
Library.fs
60 lines (50 loc) · 2.03 KB
/
Library.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace BaboonAPI
open BaboonAPI.Hooks.Initializer
open BaboonAPI.Hooks.Saves
open BaboonAPI.Internal
open BaboonAPI.Patch
open BepInEx
open HarmonyLib
[<BepInPlugin("ch.offbeatwit.baboonapi.plugin", "BaboonAPI", "2.3.0.0")>]
type BaboonPlugin() =
inherit BaseUnityPlugin()
let harmony = Harmony("ch.offbeatwit.baboonapi.plugin")
member this.Awake() =
GameInitializationEvent.EVENT.Register this
CustomSaveRegistry.Register this.Info (fun cap ->
cap.Attach "scores" ScoreStorage.customStorage)
// Apply the initializer patchset
harmony.PatchAll(typeof<BrandingPatch>)
member this.TryLoadTracks() =
try
TrackAccessor.load()
Ok(())
with
| TrackAccessor.DuplicateTrackrefException trackref ->
let msg = String.concat "\n" [
$"Duplicate tracks found with track ID '{trackref}'"
"Please check your songs folder for duplicates!"
]
Error { PluginInfo = this.Info
Message = msg }
interface GameInitializationEvent.Listener with
member this.Initialize() =
this.Logger.LogInfo "Unlocking the secrets of the baboon..."
// Apply the rest of the patches
GameInitializationEvent.attempt this.Info (fun () ->
[
typeof<TrackCountPatches>
typeof<TrackLoaderPatch>
typeof<TrackTitlePatches>
typeof<LoaderPatch>
typeof<GameControllerPatch>
typeof<PausePatches>
typeof<SaverLoaderPatch>
typeof<TrackScorePatches>
] |> List.iter harmony.PatchAll
// We've patched it now so we can call it.
SaverLoader.loadLevelData()
// First-time backup.
ScoreStorage.baseGameStorage
|> Option.iter (fun bgs -> bgs.firstTimeBackup()))
|> Result.bind this.TryLoadTracks