generated from MMike17/ArtOfRally_ModBase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatches.cs
119 lines (97 loc) · 5.04 KB
/
Patches.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
using HarmonyLib;
using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
namespace FASTER
{
[HarmonyPatch(typeof(HudManager), "Awake")]
static class HudGetter
{
public static HudManager hud;
static void Postfix(HudManager __instance) => hud = __instance;
}
[HarmonyPatch(typeof(CarCameras))]
static class SpeedEffectManager
{
static PostProcessProfile customProfile;
static Func<float> GetSpeed;
static Transform player;
static float effectAmount;
[HarmonyPatch("Start")]
[HarmonyPostfix]
static void StartPostfix(CarCameras __instance)
{
if (HudGetter.hud != null)
GetSpeed = () => Main.GetField<float, HudManager>(HudGetter.hud, "digitalSpeedoVelo", BindingFlags.Instance);
PostProcessVolume volume = __instance.GetComponentInChildren<PostProcessVolume>();
customProfile = PostProcessProfile.CreateInstance<PostProcessProfile>();
customProfile.name = "Custom profile";
foreach (PostProcessEffectSettings effectSettings in volume.profile.settings)
customProfile.settings.Add(effectSettings);
LensDistortion lensDistortion = customProfile.AddSettings<LensDistortion>();
lensDistortion.enabled.overrideState = true;
lensDistortion.enabled.value = Main.settings.enableLensDistortion;
lensDistortion.intensity.overrideState = true;
lensDistortion.centerY.overrideState = true;
lensDistortion.intensity.value = 0;
ChromaticAberration chromaticAberration = customProfile.AddSettings<ChromaticAberration>();
chromaticAberration.enabled.overrideState = true;
chromaticAberration.enabled.value = Main.settings.enableChromaticAberration;
chromaticAberration.intensity.overrideState = true;
chromaticAberration.fastMode.overrideState = true;
chromaticAberration.fastMode.value = Main.settings.aberrationFastMode;
volume.profile = customProfile;
if (!Main.settings.disableInfoLogs)
Main.Log("Switched post processing to " + customProfile.name);
}
[HarmonyPatch("LateUpdate")]
[HarmonyPrefix]
static void LateUpdatePrefix()
{
// also check here to make sure we have it
if (GetSpeed == null && HudGetter.hud != null)
GetSpeed = () => Main.GetField<float, HudManager>(HudGetter.hud, "digitalSpeedoVelo", BindingFlags.Instance);
// don't move that to Awake, we risk a game crashing null ref
if (player == null)
player = GameEntryPoint.EventManager.playerManager.playerRigidBody.transform;
if (GetSpeed == null || player == null)
return;
float speedPercent = Mathf.InverseLerp(Main.settings.minSpeedThreshold, Main.settings.maxSpeedThreshold, GetSpeed());
float speed = (speedPercent > effectAmount ? Main.settings.effectUpSpeed : Main.settings.effectDownSpeed) / 10;
effectAmount = Mathf.MoveTowards(effectAmount, speedPercent, speed * Time.deltaTime);
if (Main.settings.testMaxEffect)
effectAmount = 1;
if (customProfile.TryGetSettings(out LensDistortion lens))
{
lens.enabled.value = Main.enabled && Main.settings.enableLensDistortion;
if (lens.enabled.value)
{
float positionPercent = Camera.main.WorldToViewportPoint(player.position + player.forward * 100).y;
lens.centerY.value = Mathf.Lerp(-0.5f, 0.5f, positionPercent);
lens.intensity.value = Mathf.Lerp(0, -Main.settings.distortionIntensity, effectAmount);
}
}
if (customProfile.TryGetSettings(out ChromaticAberration aberration))
{
aberration.enabled.value = Main.enabled && Main.settings.enableChromaticAberration;
if (aberration.enabled.value)
{
aberration.fastMode.value = Main.settings.aberrationFastMode;
aberration.intensity.value = Mathf.Lerp(0, Main.settings.aberrationIntensity, effectAmount);
}
}
if (customProfile.TryGetSettings(out Bloom bloom))
{
bool bloomEnabled = Main.enabled && Main.settings.enableBloom;
bloom.threshold.value = Mathf.Lerp(0.98f, Main.settings.bloomThreshold, bloomEnabled ? effectAmount : 0);
bloom.intensity.value = Mathf.Lerp(0.5f, Main.settings.bloomIntensity, bloomEnabled ? effectAmount : 0);
}
if (customProfile.TryGetSettings(out Vignette vignette))
{
bool vignetteEnabled = Main.enabled && Main.settings.enableVignette;
vignette.intensity.value = Mathf.Lerp(0.15f, Main.settings.vignetteIntensity, vignetteEnabled ? effectAmount : 0);
}
}
}
}