-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.cs
87 lines (72 loc) · 3.14 KB
/
Main.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
using Il2Cpp;
using Il2CppAssets.Scripts.PeroTools.Commons;
using MelonLoader;
using UnityEngine;
using UnityEngine.Video;
using Object = UnityEngine.Object;
namespace Cinema
{
public class Main : MelonMod
{
internal static bool GameStarted;
internal static VideoPlayer Player;
internal static bool Christmas;
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
DriftCorrector.Stop();
}
public override void OnInitializeMelon()
{
base.OnInitializeMelon();
DriftCorrector.Init();
// Clean up old file from v1.1.x and below
if (File.Exists(Application.persistentDataPath + "/cinema.mp4"))
File.Delete(Application.persistentDataPath + "/cinema.mp4");
if (File.Exists(Application.dataPath + "/cinema.mp4"))
File.Delete(Application.dataPath + "/cinema.mp4");
}
public override void OnDeinitializeMelon()
{
base.OnDeinitializeMelon();
if (File.Exists(Application.dataPath + "/cinema.mp4"))
File.Delete(Application.dataPath + "/cinema.mp4");
}
internal static void InitCamera(float opacity)
{
var camera = Camera.allCameras.Single(c => c.name == "Camera_3D");
// Create new cinema camera
var videoCamera = Object.Instantiate(camera);
videoCamera.name = "Camera_Cinema";
videoCamera.depth = -2;
videoCamera.transform.position = new Vector3(0, 0, -9001);
videoCamera.clearFlags = CameraClearFlags.SolidColor;
videoCamera.orthographic = true;
videoCamera.orthographicSize = Camera.main.orthographicSize;
videoCamera.cullingMask = -1;
videoCamera.backgroundColor = Color.black;
Camera.main.clearFlags = CameraClearFlags.Depth;
// Add video player to new camera
Player = videoCamera.gameObject.AddComponent<VideoPlayer>();
Player.playOnAwake = false;
Player.targetCameraAlpha = opacity;
Player.audioOutputMode = VideoAudioOutputMode.None;
Player.aspectRatio = VideoAspectRatio.FitOutside;
Player.url = Application.dataPath + "/cinema.mp4";
Player.skipOnDrop = true;
Player.Prepare();
}
internal static void HideSceneElements()
{
var sceneName = SceneChangeController.curScene > 9
? $"scene_{SceneChangeController.curScene}"
: $"scene_0{SceneChangeController.curScene}";
if (Christmas && sceneName == "scene_05") sceneName += "_christmas";
var sceneObject = GameObject.Find("SceneObjectController").transform.Find(sceneName);
if (sceneObject == null) return;
SingletonMonoBehaviour<GameSceneContainer>.instance.sprLightness.color = new Color(0, 0, 0, 0);
for (var i = 0; i < sceneObject.childCount; i++)
sceneObject.GetChild(i).gameObject.SetActive(false);
sceneObject.gameObject.SetActive(false);
}
}
}