-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Plugin.cs
103 lines (87 loc) · 3.27 KB
/
Plugin.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using BeatSaberMarkupLanguage.Util;
using Camera2.HarmonyPatches;
using Camera2.Managers;
using Camera2.Middlewares;
using Camera2.Utils;
using HarmonyLib;
using IPA;
using System.Reflection;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
using IPALogger = IPA.Logging.Logger;
namespace Camera2 {
[Plugin(RuntimeOptions.SingleStartInit)]
public class Plugin {
internal static Plugin Instance { get; private set; }
internal static IPALogger Log { get; private set; }
internal static Harmony harmony { get; private set; }
internal static Material ShaderMat_LuminanceKey;
internal static Material ShaderMat_Outline;
internal static Shader Shader_VolumetricBlit;
[Init]
/// <summary>
/// Called when the plugin is first loaded by IPA (either when the game starts or when the plugin is enabled if it starts disabled).
/// [Init] methods that use a Constructor or called before regular methods like InitWithConfig.
/// Only use [Init] with one Constructor.
/// </summary>
public void Init(IPALogger logger) {
Instance = this;
Log = logger;
Log.Info("Camera2 loaded");
LoadShaders();
}
internal static void LoadShaders() {
void LoadNormalShaders(AssetBundle bundle) {
ShaderMat_LuminanceKey = new Material(bundle.LoadAsset<Shader>("luminancekey.shader"));
// Why does this one need the full path and others dont? I have no fing idea!
ShaderMat_Outline = new Material(bundle.LoadAsset<Shader>("assets/bundledassets/cam2/texouline.shader"));
bundle.Unload(false);
}
void LoadVRShaders(AssetBundle bundle) {
Shader_VolumetricBlit = bundle.LoadAsset<Shader>("volumetricblit.shader");
bundle.Unload(false);
}
#if !DEV
using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Camera2.Shaders.camera2utils"))
LoadNormalShaders(AssetBundle.LoadFromStream(stream));
using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Camera2.Shaders.camera2utilsvr"))
LoadVRShaders(AssetBundle.LoadFromStream(stream));
#else
LoadNormalShaders(AssetBundle.LoadFromFile(@"D:\Unity Shit\Projects\AssetBundlePacker\Assets\StreamingAssets\camera2utils"));
LoadVRShaders(AssetBundle.LoadFromFile(@"D:\Unity Shit\Projects\AssetBundlePacker\Assets\StreamingAssets\camera2utilsvr"));
#endif
}
[OnStart]
public void OnApplicationStart() {
harmony = new Harmony("Kinsi55.BeatSaber.Cam2");
harmony.PatchAll(Assembly.GetExecutingAssembly());
MovementScriptManager.LoadMovementScripts();
//GlobalFPSCap.Init();
SceneManager.activeSceneChanged += SceneUtil.OnActiveSceneChanged;
// Marinate the Reflection stuff off-thread so the loading of cameras later is less blocking
Task.Run(() => {
ModmapExtensions.Reflect();
CustomNotesUtil.Reflect();
if(ScoresaberUtil.Reflect())
SDK.ReplaySources.Register(new ScoresaberUtil.SSReplaySource());
});
MainMenuAwaiter.MainMenuInitializing += delegate {
UI.SpaghettiUI.Init();
};
}
[OnExit]
public void OnApplicationQuit() {
harmony.UnpatchSelf();
}
}
#if DEBUG
public static class lol {
public static string GetPath(this Transform current) {
if(current.parent == null)
return "/" + current.name;
return current.parent.GetPath() + "/" + current.name;
}
}
#endif
}