This repository has been archived by the owner on Aug 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathPlugin.cs
129 lines (108 loc) · 4.11 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using IllusionPlugin;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace SaberTailor
{
[UsedImplicitly]
public class Plugin : IPlugin
{
public const string Name = "SaberTailor";
public const string Version = "1.1.0";
string IPlugin.Name => Name;
string IPlugin.Version => Version;
readonly List<Tweaks.ITweak> _tweaks = new List<Tweaks.ITweak>
{
new Tweaks.SaberLength(),
new Tweaks.SaberGrip(),
new Tweaks.SaberTrail()
};
public void OnApplicationStart()
{
_tweaks.ForEach(tweak =>
{
try
{
tweak.Load();
Log("Loaded tweak: {0}", tweak.Name);
}
catch (Exception ex)
{
Log("Failed to load tweak: {0}. Exception: {1}", tweak.Name, ex);
}
});
SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged;
}
public void OnApplicationQuit()
{
_tweaks.ForEach(tweak =>
{
try
{
tweak.Cleanup();
Log("Unloaded tweak: {0}", tweak.Name);
}
catch (Exception ex)
{
Log("Failed to unload tweak: {0}. Exception: {1}", tweak.Name, ex);
}
});
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
}
void SceneManagerOnActiveSceneChanged(Scene previousScene, Scene currentScene)
{
Preferences.Load();
EnsureMainGameSceneSetup();
}
MainGameSceneSetupData _mainGameSceneSetupData;
bool _justPreventedSubmission;
void EnsureMainGameSceneSetup()
{
if (_mainGameSceneSetupData == null)
{
_mainGameSceneSetupData = Resources.FindObjectsOfTypeAll<MainGameSceneSetupData>().FirstOrDefault();
if (_mainGameSceneSetupData == null) return;
_mainGameSceneSetupData.didFinishEvent += OnMainGameSceneDidFinish;
}
if (_justPreventedSubmission)
{
var resultsViewController = Resources.FindObjectsOfTypeAll<ResultsViewController>().FirstOrDefault();
if (resultsViewController == null) return;
resultsViewController.continueButtonPressedEvent += controller =>
{
PersistentSingleton<GameDataModel>.instance
.gameDynamicData.GetCurrentPlayerDynamicData()
.gameplayOptions.noEnergy = false;
_justPreventedSubmission = false;
};
}
}
void OnMainGameSceneDidFinish(MainGameSceneSetupData setupData, LevelCompletionResults levelCompletionResults)
{
if (!setupData.gameplayOptions.validForScoreUse) return; // NoFail active
if (levelCompletionResults?.levelEndStateType != LevelCompletionResults.LevelEndStateType.Cleared) return;
var submissionBlockers = _tweaks.Where(tweak => tweak.IsPreventingScoreSubmission).ToList();
if (submissionBlockers.Count == 0) return;
submissionBlockers.ForEach(tweak => Log("Score submission prevented by tweak: {0}", tweak.Name));
setupData.gameplayOptions.noEnergy = true;
_justPreventedSubmission = true;
}
public static void Log(string format, params object[] args)
{
Console.WriteLine($"[{Name}] " + format, args);
}
public static void Log(string message)
{
Log(message, new object[] { });
}
#region Unused IPlugin Members
void IPlugin.OnUpdate() { }
void IPlugin.OnFixedUpdate() { }
void IPlugin.OnLevelWasLoaded(int level) { }
void IPlugin.OnLevelWasInitialized(int level) { }
#endregion
}
}