forked from nikita/muzika-gromche
				
			convert indentation to tabs
This commit is contained in:
		
							parent
							
								
									df4418b040
								
							
						
					
					
						commit
						566bc0993e
					
				|  | @ -10,9 +10,9 @@ using UnityEngine.Networking; | ||||||
| 
 | 
 | ||||||
| namespace MuzikaGromche | namespace MuzikaGromche | ||||||
| { | { | ||||||
|     [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] | 	[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] | ||||||
|     public class Plugin : BaseUnityPlugin | 	public class Plugin : BaseUnityPlugin | ||||||
|     { | 	{ | ||||||
| 		public static Track[] Tracks = [ | 		public static Track[] Tracks = [ | ||||||
| 			new Track | 			new Track | ||||||
| 			{ | 			{ | ||||||
|  | @ -79,133 +79,133 @@ namespace MuzikaGromche | ||||||
| 				Logger.LogError("Could not load audio file"); | 				Logger.LogError("Could not load audio file"); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|     } | 	} | ||||||
| 
 | 
 | ||||||
|     public class Track | 	public class Track | ||||||
|     { | 	{ | ||||||
| 	    public string Name; | 		public string Name; | ||||||
| 	    public float WindUpTimer; | 		public float WindUpTimer; | ||||||
| 	    public float Bpm; | 		public float Bpm; | ||||||
| 	    public AudioClip LoadedStart; | 		public AudioClip LoadedStart; | ||||||
| 	    public AudioClip LoadedLoop; | 		public AudioClip LoadedLoop; | ||||||
|     } | 	} | ||||||
| 
 | 
 | ||||||
|     [HarmonyPatch(typeof(JesterAI))] | 	[HarmonyPatch(typeof(JesterAI))] | ||||||
|     internal class JesterPatch | 	internal class JesterPatch | ||||||
|     { | 	{ | ||||||
| 	    [HarmonyPatch("Update")] | 		[HarmonyPatch("Update")] | ||||||
| 	    [HarmonyPrefix] | 		[HarmonyPrefix] | ||||||
| 	    public static void DoNotStopTheMusicPrefix(JesterAI __instance, out State __state) | 		public static void DoNotStopTheMusicPrefix(JesterAI __instance, out State __state) | ||||||
| 	    { | 		{ | ||||||
| 		    __state = new State(); | 			__state = new State(); | ||||||
| 		    __state.prevStateindex = __instance.previousState; | 			__state.prevStateindex = __instance.previousState; | ||||||
| 		    if (__instance.currentBehaviourStateIndex == 2 && __instance.previousBehaviourStateIndex != 2) { | 			if (__instance.currentBehaviourStateIndex == 2 && __instance.previousBehaviourStateIndex != 2) { | ||||||
| 			    // if just popped out | 				// if just popped out | ||||||
| 			    // then override farAudio so that vanilla logic does not stop the music | 				// then override farAudio so that vanilla logic does not stop the music | ||||||
| 			    __state.farAudio = __instance.farAudio; | 				__state.farAudio = __instance.farAudio; | ||||||
| 			    __instance.farAudio = __instance.creatureVoice; | 				__instance.farAudio = __instance.creatureVoice; | ||||||
| 		    } | 			} | ||||||
| 	    } | 		} | ||||||
| 
 | 
 | ||||||
| 	    static List<Color> colors = [Color.magenta, Color.cyan, Color.green, Color.yellow]; | 		static List<Color> colors = [Color.magenta, Color.cyan, Color.green, Color.yellow]; | ||||||
| 
 | 
 | ||||||
| 	    public static IEnumerator rotateColors() | 		public static IEnumerator rotateColors() | ||||||
| 	    { | 		{ | ||||||
| 		    Debug.Log("Starting color rotation"); | 			Debug.Log("Starting color rotation"); | ||||||
| 		    var i = 0; | 			var i = 0; | ||||||
| 		    while (true) | 			while (true) | ||||||
| 		    { | 			{ | ||||||
| 			    var color = colors[i]; | 				var color = colors[i]; | ||||||
| 			    Debug.Log("Chose color " + color); | 				Debug.Log("Chose color " + color); | ||||||
| 			    foreach (var light in RoundManager.Instance.allPoweredLights) | 				foreach (var light in RoundManager.Instance.allPoweredLights) | ||||||
| 			    { | 				{ | ||||||
| 				    light.color = color; | 					light.color = color; | ||||||
| 			    } | 				} | ||||||
| 
 | 
 | ||||||
| 			    i += 1; | 				i += 1; | ||||||
| 			    if (i >= colors.Count) i = 0; | 				if (i >= colors.Count) i = 0; | ||||||
| 			    yield return new WaitForSeconds(60f / Plugin.CurrentTrack.Bpm); | 				yield return new WaitForSeconds(60f / Plugin.CurrentTrack.Bpm); | ||||||
| 		    } | 			} | ||||||
| 	    } | 		} | ||||||
| 
 | 
 | ||||||
| 		[HarmonyPatch("Update")] | 		[HarmonyPatch("Update")] | ||||||
|         [HarmonyPostfix] | 		[HarmonyPostfix] | ||||||
|         public static void DoNotStopTheMusic(JesterAI __instance, State __state) | 		public static void DoNotStopTheMusic(JesterAI __instance, State __state) | ||||||
|         { | 		{ | ||||||
| 	        if (__state.farAudio != null) | 			if (__state.farAudio != null) | ||||||
| 	        { | 			{ | ||||||
| 		        __instance.farAudio = __state.farAudio; | 				__instance.farAudio = __state.farAudio; | ||||||
| 	        } | 			} | ||||||
| 
 | 
 | ||||||
| 	        if (__instance.currentBehaviourStateIndex is 1 && __state.prevStateindex != 1) | 			if (__instance.currentBehaviourStateIndex is 1 && __state.prevStateindex != 1) | ||||||
| 	        { | 			{ | ||||||
| 		        // if just started winding up | 				// if just started winding up | ||||||
| 		        // then stop the default music... | 				// then stop the default music... | ||||||
| 		        __instance.farAudio.Stop(); | 				__instance.farAudio.Stop(); | ||||||
| 		        __instance.creatureVoice.Stop(); | 				__instance.creatureVoice.Stop(); | ||||||
| 
 | 
 | ||||||
| 		        //  ...and start modded music | 				//  ...and start modded music | ||||||
| 		        var seed = RoundManager.Instance.dungeonGenerator.Generator.ChosenSeed; | 				var seed = RoundManager.Instance.dungeonGenerator.Generator.ChosenSeed; | ||||||
| 		        var sha = SHA256.Create(); | 				var sha = SHA256.Create(); | ||||||
| 		        var hash = sha.ComputeHash(BitConverter.GetBytes(seed)); | 				var hash = sha.ComputeHash(BitConverter.GetBytes(seed)); | ||||||
| 		        var trackId = 0; | 				var trackId = 0; | ||||||
| 		        foreach (var t in hash) | 				foreach (var t in hash) | ||||||
| 		        { | 				{ | ||||||
| 			        // modulus division on byte array | 					// modulus division on byte array | ||||||
| 			        trackId *= 256 % Plugin.Tracks.Length; | 					trackId *= 256 % Plugin.Tracks.Length; | ||||||
| 			        trackId %= Plugin.Tracks.Length; | 					trackId %= Plugin.Tracks.Length; | ||||||
| 			        trackId += t % Plugin.Tracks.Length; | 					trackId += t % Plugin.Tracks.Length; | ||||||
| 			        trackId %= Plugin.Tracks.Length; | 					trackId %= Plugin.Tracks.Length; | ||||||
| 		        } | 				} | ||||||
| 		        Debug.Log($"Seed is {seed}, chosen track is {trackId} out of {Plugin.Tracks.Length} tracks"); | 				Debug.Log($"Seed is {seed}, chosen track is {trackId} out of {Plugin.Tracks.Length} tracks"); | ||||||
| 		        Plugin.CurrentTrack = Plugin.Tracks[trackId]; | 				Plugin.CurrentTrack = Plugin.Tracks[trackId]; | ||||||
| 		        __instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer; | 				__instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer; | ||||||
| 		        __instance.farAudio.maxDistance = 150; | 				__instance.farAudio.maxDistance = 150; | ||||||
| 		        __instance.farAudio.clip = Plugin.CurrentTrack.LoadedStart; | 				__instance.farAudio.clip = Plugin.CurrentTrack.LoadedStart; | ||||||
| 		        __instance.farAudio.loop = false; | 				__instance.farAudio.loop = false; | ||||||
| 		        Debug.Log($"Playing start music: maxDistance: {__instance.farAudio.maxDistance}, minDistance: {__instance.farAudio.minDistance}, volume: {__instance.farAudio.volume}, spread: {__instance.farAudio.spread}"); | 				Debug.Log($"Playing start music: maxDistance: {__instance.farAudio.maxDistance}, minDistance: {__instance.farAudio.minDistance}, volume: {__instance.farAudio.volume}, spread: {__instance.farAudio.spread}"); | ||||||
| 		        __instance.farAudio.Play(); | 				__instance.farAudio.Play(); | ||||||
| 	        } | 			} | ||||||
| 
 | 
 | ||||||
| 	        if (__instance.currentBehaviourStateIndex is 2 && __state.prevStateindex != 2) | 			if (__instance.currentBehaviourStateIndex is 2 && __state.prevStateindex != 2) | ||||||
| 	        { | 			{ | ||||||
| 		        __instance.creatureVoice.Stop(); | 				__instance.creatureVoice.Stop(); | ||||||
| 
 | 
 | ||||||
| 		        if (Plugin.JesterLightSwitching != null) { | 				if (Plugin.JesterLightSwitching != null) { | ||||||
| 			        __instance.StopCoroutine(Plugin.JesterLightSwitching); | 					__instance.StopCoroutine(Plugin.JesterLightSwitching); | ||||||
| 			        Plugin.JesterLightSwitching = null; | 					Plugin.JesterLightSwitching = null; | ||||||
| 		        } | 				} | ||||||
| 		        Plugin.JesterLightSwitching = __instance.StartCoroutine(rotateColors()); | 				Plugin.JesterLightSwitching = __instance.StartCoroutine(rotateColors()); | ||||||
| 	        } | 			} | ||||||
| 
 | 
 | ||||||
| 	        if (__instance.currentBehaviourStateIndex != 2 && __state.prevStateindex == 2) | 			if (__instance.currentBehaviourStateIndex != 2 && __state.prevStateindex == 2) | ||||||
| 	        { | 			{ | ||||||
| 		        if (Plugin.JesterLightSwitching != null) { | 				if (Plugin.JesterLightSwitching != null) { | ||||||
| 			        __instance.StopCoroutine(Plugin.JesterLightSwitching); | 					__instance.StopCoroutine(Plugin.JesterLightSwitching); | ||||||
| 			        Plugin.JesterLightSwitching = null; | 					Plugin.JesterLightSwitching = null; | ||||||
| 		        } | 				} | ||||||
| 		        foreach (var light in RoundManager.Instance.allPoweredLights) | 				foreach (var light in RoundManager.Instance.allPoweredLights) | ||||||
| 		        { | 				{ | ||||||
| 			        light.color = Color.white; | 					light.color = Color.white; | ||||||
| 		        } | 				} | ||||||
| 	        } | 			} | ||||||
| 
 | 
 | ||||||
| 	        if (__instance.currentBehaviourStateIndex is 2 && !__instance.creatureVoice.isPlaying) | 			if (__instance.currentBehaviourStateIndex is 2 && !__instance.creatureVoice.isPlaying) | ||||||
| 	        { | 			{ | ||||||
| 		        __instance.creatureVoice.maxDistance = 150; | 				__instance.creatureVoice.maxDistance = 150; | ||||||
| 		        __instance.creatureVoice.clip = Plugin.CurrentTrack.LoadedLoop; | 				__instance.creatureVoice.clip = Plugin.CurrentTrack.LoadedLoop; | ||||||
| 		        var time = __instance.farAudio.time; | 				var time = __instance.farAudio.time; | ||||||
| 		        var delay = Plugin.CurrentTrack.LoadedStart.length - time; | 				var delay = Plugin.CurrentTrack.LoadedStart.length - time; | ||||||
| 		        Debug.Log($"Start length: {Plugin.CurrentTrack.LoadedStart.length}; played time: {time}"); | 				Debug.Log($"Start length: {Plugin.CurrentTrack.LoadedStart.length}; played time: {time}"); | ||||||
| 		        Debug.Log($"Playing loop music: maxDistance: {__instance.creatureVoice.maxDistance}, minDistance: {__instance.creatureVoice.minDistance}, volume: {__instance.creatureVoice.volume}, spread: {__instance.creatureVoice.spread}, in seconds: {delay}"); | 				Debug.Log($"Playing loop music: maxDistance: {__instance.creatureVoice.maxDistance}, minDistance: {__instance.creatureVoice.minDistance}, volume: {__instance.creatureVoice.volume}, spread: {__instance.creatureVoice.spread}, in seconds: {delay}"); | ||||||
| 		        __instance.creatureVoice.PlayDelayed(delay); | 				__instance.creatureVoice.PlayDelayed(delay); | ||||||
| 	        } | 			} | ||||||
|         } | 		} | ||||||
|     } | 	} | ||||||
| 
 | 
 | ||||||
|     internal class State | 	internal class State | ||||||
|     { | 	{ | ||||||
| 	    public AudioSource farAudio; | 		public AudioSource farAudio; | ||||||
| 	    public int prevStateindex; | 		public int prevStateindex; | ||||||
|     } | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue