-
Notifications
You must be signed in to change notification settings - Fork 1
/
Patcher_FMOD.cs
107 lines (97 loc) · 4.15 KB
/
Patcher_FMOD.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
using System;
using System.IO;
using System.Linq;
using FMOD;
using FMODUnity;
using HarmonyLib;
using TNH_BGLoader;
using TNHBGLoader.Soundtrack;
using UnityEngine;
namespace TNHBGLoader
{
public class Patcher_FMOD
{
[HarmonyPatch(typeof(RuntimeUtils), "GetBankPath")]
[HarmonyPrefix]
public static bool FMODRuntimeUtilsPatch_GetBankPath(ref string bankName, ref string __result)
{
// 100% going to fucking strangle the person who didn't perchance even fucking THINk that
// sOMEONE WOULD INSERT A FUCKIGN ABSOLUTE PATH LOCATION. HOW STUPID ARE YOU???
// "waa waa the dev will only want banks to be loaded from streamingassets"
// ARE YOU FIFTH GRADE??? OF COURSE THERE'S GONNA BE AN EDGE CASE HAVE YOU NEVER PROGRAMMED BEFORE??
// for a tad bit more context, i had to add the "ispathrooted" bit; fmod would force on the SA path
string streamingAssetsPath = Application.streamingAssetsPath;
if (Path.GetExtension(bankName) != ".bank")
{
if (Path.IsPathRooted(bankName)){
__result = bankName + ".bank";
return false;
} else {
__result = string.Format("{0}/{1}.bank", streamingAssetsPath, bankName);
return false;
}
}
if (Path.IsPathRooted(bankName)) {
__result = bankName;
return false;
} else {
__result = string.Format("{0}/{1}", streamingAssetsPath, bankName);
return false;
}
}
[HarmonyPatch(typeof(RuntimeManager))]
[HarmonyPatch("LoadBank", new Type[] { typeof(string), typeof(bool) })]
[HarmonyPrefix]
public static bool FMODRuntimeManagerPatch_LoadBank(ref string bankName)
{
if (bankName == "MX_TAH")
{
if (!BankAPI.BanksEmptyOrNull) //i don't even think this is possible? it's not. i need to remove this sometime.
{
/*if (BankAPI.CurrentBankLocation != "Select Random" && BankAPI.CurrentBankLocation != "Your Mix") {
SoundtrackAPI.IsMix = false;
PluginMain.IsSoundtrack.Value = false;
}*/
//this relies on Select Random being first. don't fucking touch it
//And that Your Mix is second
//The second check here (Your Mix + Soundtrack.Count == 0) is so that if there isnt any soundtracks, itll just act as Select Random.
if (BankAPI.CurrentBankLocation == "Select Random" && PluginMain.IsSoundtrack.Value == false/* || (BankAPI.CurrentBankLocation == "Your Mix" && SoundtrackAPI.Soundtracks.Count == 0)*/) {
PluginMain.DebugLog.LogInfo($"Activated Random. Current Bank: {BankAPI.CurrentBankLocation}");
int num = UnityEngine.Random.Range(1, BankAPI.LoadedBankLocations.Count + SoundtrackAPI.Soundtracks.Count);
PluginMain.DebugLog.LogInfo($"Selected: {num}");
if (num < BankAPI.LoadedBankLocations.Count) {
PluginMain.IsSoundtrack.Value = false;
BankAPI.CurrentBankIndex = num;
}
else {
PluginMain.IsSoundtrack.Value = true;
SoundtrackAPI.SelectedSoundtrackIndex = num - BankAPI.LoadedBankLocations.Count;
}
}
/*if (BankAPI.CurrentBankLocation == "Your Mix" && SoundtrackAPI.Soundtracks.Count != 0) {
PluginMain.DebugLog.LogInfo($"Activated Your Mix");
PluginMain.IsSoundtrack.Value = true;
return false;
}*/
PluginMain.DebugLog.LogInfo($"IsSoundtrack loading bank/soundtrack time: {PluginMain.IsSoundtrack.Value.ToString()}");
if (!PluginMain.IsSoundtrack.Value) {
PluginMain.DebugLog.LogInfo("Injecting bank " + Path.GetFileName(BankAPI.CurrentBankLocation) +
" into TNH!");
bankName = BankAPI.CurrentBankLocation;
}
else {
if (SoundtrackAPI.SelectedSoundtrackIndex >= SoundtrackAPI.Soundtracks.Count ||
SoundtrackAPI.SelectedSoundtrackIndex < 0) {
// Out of range. Idk how this happened but reset it to prevent console spam
PluginMain.DebugLog.LogInfo("Enabled soundtrack not in soundtrack database! Resetting to default.");
PluginMain.IsSoundtrack.Value = false;
bankName = BankAPI.LoadedBankLocations[0]; // Index 0 SHOULD be default.
}
PluginMain.DebugLog.LogInfo($"Loading soundtrack {SoundtrackAPI.Soundtracks[SoundtrackAPI.SelectedSoundtrackIndex].Guid} into TNH!");
}
}
}
return true;
}
}
}