Skip to content

Commit 9091e24

Browse files
committed
Added Custom Lowpass
Adds custom lowpass to little things
1 parent 0edd063 commit 9091e24

8 files changed

Lines changed: 226 additions & 1 deletion

File tree

Distance.LittleThings/ConfigLogic.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public bool ActiveCompass
3030
get { return Get<bool>("ActiveCompass"); }
3131
set { Set("ActiveCompass", value); }
3232
}
33+
34+
public bool EnableCustomLowpass
35+
{
36+
get { return Get<bool>("EnableCustomLowpass"); }
37+
set { Set("EnableCustomLowpass", value); }
38+
}
3339
#endregion
3440

3541
internal Settings Config;
@@ -50,6 +56,7 @@ public void Awake()
5056
Get("EnableQuarantineInArcade", true);
5157
Get("EnableHeadLights", false);
5258
Get("ActiveCompass", false);
59+
Get("EnableCustomLowpass", true);
5360
//Save settings to Config.json
5461
Save();
5562
}

Distance.LittleThings/Distance.LittleThings.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
</ItemGroup>
9292
<ItemGroup>
9393
<Compile Include="ConfigLogic.cs" />
94+
<Compile Include="Harmony\Assembly-CSharp\AudioManager\PostEvent.cs" />
95+
<Compile Include="Harmony\Assembly-CSharp\AudioManager\SetCustomMusicDSP.cs" />
96+
<Compile Include="Harmony\Assembly-CSharp\AudioManager\SetRTPCValue.cs" />
97+
<Compile Include="Harmony\Assembly-CSharp\AudioManager\Update.cs" />
98+
<Compile Include="Harmony\Assembly-CSharp\AudioManager\SetState.cs" />
9499
<Compile Include="Harmony\Assembly-CSharp\CarScreenLogic\OnEventGo.cs" />
95100
<Compile Include="Harmony\Assembly-CSharp\CarScreenLogic\UpdateBeforeRender.cs" />
96101
<Compile Include="Harmony\Assembly-CSharp\GPSTrigger\Start.cs" />
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using HarmonyLib;
2+
3+
namespace Distance.LittleThings.Harmony
4+
{
5+
[HarmonyPatch(typeof(AudioManager), "PostEvent", new System.Type[] { typeof(string) })]
6+
internal class AudioManager__PostEvent1
7+
{
8+
[HarmonyPostfix]
9+
internal static void CheckCustomDSP(string eventName)
10+
{
11+
if (Mod.Instance.Config.EnableCustomLowpass)
12+
{
13+
AudioManager audioManager;
14+
if (Mod.Instance.audioManager != null)
15+
audioManager = Mod.Instance.audioManager;
16+
else
17+
return;
18+
19+
//Mod.Instance.Logger.Debug("POST EVENT NAME: " + eventName);
20+
if (audioManager.currentMusicState_ == AudioManager.MusicState.CustomMusic)
21+
{
22+
if (eventName == "Set_Master_Low_Pass_Fade_In")
23+
{
24+
if (audioManager.customMusicLowPass_ != null)
25+
audioManager.StopCoroutine(audioManager.customMusicLowPass_);
26+
27+
audioManager.SetCustomMusicDSP(.01f, AudioManager.highPassFreqDefault_);
28+
audioManager.customMusicLowPass_ = audioManager.StartCoroutine(Mod.Instance.CustomMusicDSP(AudioManager.lowPassFreqDefault_, 2f));
29+
return;
30+
}
31+
if (eventName == "Set_Car_Low_Pass_Filter_Off")
32+
{
33+
audioManager.SetCustomMusicDSP(AudioManager.lowPassFreqDefault_, AudioManager.highPassFreqDefault_);
34+
}
35+
}
36+
}
37+
}
38+
}
39+
40+
[HarmonyPatch(typeof(AudioManager), "PostEvent", new System.Type[] { typeof(string), typeof(UnityEngine.GameObject) })]
41+
internal class AudioManager__PostEvent2
42+
{
43+
[HarmonyPostfix]
44+
internal static void CheckCustomDSP(string eventName)
45+
{
46+
//Mod.Instance.Logger.Debug("POST EVENT NAME: " + eventName);
47+
}
48+
}
49+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using HarmonyLib;
2+
3+
namespace Distance.LittleThings.Harmony
4+
{
5+
[HarmonyPatch(typeof(AudioManager), "SetCustomMusicDSP", new System.Type[] { typeof(float), typeof(float), typeof(bool) })]
6+
internal class AudioManaher__SetCustomMusicDSP
7+
{
8+
[HarmonyPostfix]
9+
internal static void CheckingIfItIsCalled(float lowPassFreq, float highPassFreq, bool forceUpdate)
10+
{
11+
//Mod.Instance.Logger.Debug("DSP Freaks: " + lowPassFreq + " " + highPassFreq);
12+
}
13+
}
14+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using HarmonyLib;
2+
3+
namespace Distance.LittleThings.Harmony
4+
{
5+
[HarmonyPatch(typeof(AudioManager), "SetRTPCValue", new System.Type[] { typeof(string), typeof(float) })]
6+
internal class AudioManager__SetRTPCValue
7+
{
8+
[HarmonyPostfix]
9+
internal static void AdjustCustomRTPC(string rtpcName, float value)
10+
{
11+
if (Mod.Instance.Config.EnableCustomLowpass)
12+
{
13+
AudioManager audioManager;
14+
if (Mod.Instance.audioManager != null)
15+
audioManager = Mod.Instance.audioManager;
16+
else
17+
return;
18+
19+
20+
//Mod.Instance.Logger.Debug(rtpcName + " " + value);
21+
if (audioManager.currentMusicState_ == AudioManager.MusicState.CustomMusic)
22+
{
23+
if (rtpcName == "TunnelHorror")
24+
{
25+
if (value != 0)
26+
{
27+
28+
audioManager.SetCustomMusicDSP(AudioManager.lowPassFreqDefault_ / (float)System.Math.Pow(10.0, value), AudioManager.highPassFreqDefault_, false);
29+
}
30+
else
31+
{
32+
//Hoping there's no popping because of this
33+
//For whatever reason this isn't guarenteed?
34+
audioManager.SetCustomMusicDSP(AudioManager.lowPassFreqDefault_, AudioManager.highPassFreqDefault_);
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using HarmonyLib;
2+
3+
namespace Distance.LittleThings.Harmony
4+
{
5+
[HarmonyPatch(typeof(AudioManager), "SetState", new System.Type[] { typeof(string), typeof(string) })]
6+
internal class AudioManager__SetState
7+
{
8+
[HarmonyPostfix]
9+
internal static void CustomAudioCheck(string stateGroup, string state)
10+
{
11+
if (Mod.Instance.Config.EnableCustomLowpass)
12+
{
13+
AudioManager audioManager;
14+
if (Mod.Instance.audioManager != null)
15+
audioManager = Mod.Instance.audioManager;
16+
else
17+
return;
18+
19+
//Mod.Instance.Logger.Debug("Audio StateGroup String: " + stateGroup + " Audio State String: " + state);
20+
if (audioManager.currentMusicState_ == AudioManager.MusicState.CustomMusic)
21+
{
22+
if (state == "Under_Water")
23+
{
24+
if (audioManager.customMusicLowPass_ != null)
25+
audioManager.StopCoroutine(audioManager.customMusicLowPass_);
26+
27+
audioManager.customMusicLowPass_ = audioManager.StartCoroutine(Mod.Instance.CustomMusicDSP(230f, .75f));
28+
return;
29+
}
30+
if (state == "Normal")
31+
{
32+
if (stateGroup == "Water_States" || stateGroup == "GravityLowPass")
33+
{
34+
if (audioManager.customMusicLowPass_ != null)
35+
audioManager.StopCoroutine(audioManager.customMusicLowPass_);
36+
37+
audioManager.customMusicLowPass_ = audioManager.StartCoroutine(Mod.Instance.CustomMusicDSP(AudioManager.lowPassFreqDefault_, .75f));
38+
}
39+
}
40+
}
41+
}
42+
}
43+
44+
}
45+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using HarmonyLib;
2+
3+
namespace Distance.LittleThings.Harmony
4+
{
5+
[HarmonyPatch(typeof(AudioManager), "Update")]
6+
internal class AudioManager__Update
7+
{
8+
[HarmonyPostfix]
9+
internal static void LiterallyJustGettingTheAudioManager(AudioManager __instance)
10+
{
11+
Mod.Instance.audioManager = __instance;
12+
//Mod.Instance.Logger.Debug("DSP Freaks: " + __instance.lowPassFreq_ + " " + __instance.highPassFreq_);
13+
}
14+
}
15+
}

Distance.LittleThings/Mod.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public sealed class Mod : MonoBehaviour
2424

2525
public ConfigLogic Config { get; private set; }
2626

27+
public AudioManager audioManager { get; set; }
28+
2729
/// <summary>
2830
/// Method called as soon as the mod is loaded.
2931
/// WARNING: Do not load asset bundles/textures in this function
@@ -79,6 +81,23 @@ public void Initialize(IManager manager)
7981
}
8082
}
8183

84+
/*private void Update()
85+
{
86+
if (Input.anyKey)
87+
{
88+
if (Input.GetKey(KeyCode.O))
89+
audioManager.lowPassFreq_ += 10;
90+
if (Input.GetKey(KeyCode.P))
91+
audioManager.lowPassFreq_ -= 10;
92+
if (Input.GetKey(KeyCode.K))
93+
audioManager.highPassFreq_ += 1;
94+
if (Input.GetKey(KeyCode.L))
95+
audioManager.highPassFreq_ -= 1;
96+
97+
audioManager.SetCustomMusicDSP(audioManager.lowPassFreq_, audioManager.highPassFreq_, false);
98+
}
99+
}*/
100+
82101
private void CreateSettingsMenu()
83102
{
84103
MenuTree settingsMenu = new MenuTree("menu.mod.littlethings", "Little Thing Settings")
@@ -102,6 +121,11 @@ private void CreateSettingsMenu()
102121
.WithGetter(() => Config.ActiveCompass)
103122
.WithSetter((x) => Config.ActiveCompass = x)
104123
.WithDescription("The compass will always stay active on the carscreen and never change"),
124+
125+
new CheckBox(MenuDisplayMode.Both, "settings::enable_lowpass", "ENABLE CUSTOM LOWPASS FILTERS")
126+
.WithGetter(() => Config.EnableCustomLowpass)
127+
.WithSetter((x) => Config.EnableCustomLowpass = x)
128+
.WithDescription("Toggles whether or not lowpass filters get applied to custom music."),
105129
};
106130

107131
Menus.AddNew(MenuDisplayMode.Both, settingsMenu, "LITTLE THINGS", "Settings for the LittleThings mod");
@@ -111,7 +135,32 @@ public void OnConfigChanged(ConfigLogic configLogic)
111135
{
112136

113137
}
114-
}
138+
139+
public System.Collections.IEnumerator CustomMusicDSP(float lowpassEnd, float timer)
140+
{
141+
if (audioManager == null)
142+
yield break;
143+
144+
if (audioManager.sampleAggregator_ == null || !audioManager.audioSettings_.AffectedByGameplay_)
145+
yield break;
146+
147+
if (audioManager.lowPassFreq_.ApproxEquals(lowpassEnd))
148+
yield break;
149+
150+
float startLowFreq = (float)Math.Log10((double)audioManager.lowPassFreq_);
151+
float endLowFreq = (float)Math.Log10((double)lowpassEnd);
152+
float time = 0f;
153+
while (time < timer)
154+
{
155+
audioManager.lowPassFreq_ = (float)Math.Pow(10.0, (double)Mathf.Lerp(startLowFreq, endLowFreq, time / timer));
156+
audioManager.SetCustomMusicDSP(audioManager.lowPassFreq_, audioManager.highPassFreq_, false);
157+
time += Time.deltaTime;
158+
yield return null;
159+
}
160+
audioManager.SetCustomMusicDSP((float)Math.Pow(10.0, (double)endLowFreq), -1f, false);
161+
yield break;
162+
}
163+
}
115164
}
116165

117166

0 commit comments

Comments
 (0)