forked from nikita/muzika-gromche
				
			Convert mixed indentation to spaces
This commit is contained in:
		
							parent
							
								
									ef1e2fd70b
								
							
						
					
					
						commit
						a65dd56bc3
					
				|  | @ -13,199 +13,199 @@ 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 | ||||||
| 			{ |             { | ||||||
| 				Name = "MuzikaGromche", |                 Name = "MuzikaGromche", | ||||||
| 				WindUpTimer = 46.3f, |                 WindUpTimer = 46.3f, | ||||||
| 				Bpm = 130f, |                 Bpm = 130f, | ||||||
| 			}, |             }, | ||||||
| 			new Track |             new Track | ||||||
| 			{ |             { | ||||||
| 				Name = "VseVZale", |                 Name = "VseVZale", | ||||||
| 				WindUpTimer = 39f,  |                 WindUpTimer = 39f, | ||||||
| 				Bpm = 138f, |                 Bpm = 138f, | ||||||
| 			}, |             }, | ||||||
| 			new Track |             new Track | ||||||
| 			{ |             { | ||||||
| 				Name = "DeployDestroy", |                 Name = "DeployDestroy", | ||||||
| 				WindUpTimer = 40.7f, |                 WindUpTimer = 40.7f, | ||||||
| 				Bpm = 130f, |                 Bpm = 130f, | ||||||
| 			}, |             }, | ||||||
| 			new Track |             new Track | ||||||
| 			{ |             { | ||||||
| 				Name = "MoyaZhittya", |                 Name = "MoyaZhittya", | ||||||
| 				WindUpTimer = 34.5f, |                 WindUpTimer = 34.5f, | ||||||
| 				Bpm = 120f, |                 Bpm = 120f, | ||||||
| 			}, |             }, | ||||||
| 			new Track |             new Track | ||||||
| 			{ |             { | ||||||
| 				Name = "Gorgorod", |                 Name = "Gorgorod", | ||||||
| 				WindUpTimer = 43.2f, |                 WindUpTimer = 43.2f, | ||||||
| 				Bpm = 180f, |                 Bpm = 180f, | ||||||
| 			}, |             }, | ||||||
| 			new Track |             new Track | ||||||
| 			{ |             { | ||||||
| 				Name = "Durochka", |                 Name = "Durochka", | ||||||
| 				WindUpTimer = 37f, |                 WindUpTimer = 37f, | ||||||
| 				Bpm = 130f, |                 Bpm = 130f, | ||||||
| 			} |             } | ||||||
| 		]; |         ]; | ||||||
| 
 | 
 | ||||||
| 		public static Coroutine JesterLightSwitching; |         public static Coroutine JesterLightSwitching; | ||||||
| 		public static Track CurrentTrack; |         public static Track CurrentTrack; | ||||||
| 
 | 
 | ||||||
| 		private void Awake() |         private void Awake() | ||||||
| 		{ |         { | ||||||
| 			string text = Info.Location.TrimEnd((PluginInfo.PLUGIN_NAME + ".dll").ToCharArray()); |             string text = Info.Location.TrimEnd((PluginInfo.PLUGIN_NAME + ".dll").ToCharArray()); | ||||||
| 			UnityWebRequest[] requests = new UnityWebRequest[Tracks.Length * 2]; |             UnityWebRequest[] requests = new UnityWebRequest[Tracks.Length * 2]; | ||||||
| 			for (int i = 0; i < Tracks.Length; i++) { |             for (int i = 0; i < Tracks.Length; i++) { | ||||||
| 				Track track = Tracks[i]; |                 Track track = Tracks[i]; | ||||||
| 				requests[i * 2] = UnityWebRequestMultimedia.GetAudioClip($"File://{text}{track.Name}Start.mp3", AudioType.MPEG); |                 requests[i * 2] = UnityWebRequestMultimedia.GetAudioClip($"File://{text}{track.Name}Start.mp3", AudioType.MPEG); | ||||||
| 				requests[i * 2 + 1] = UnityWebRequestMultimedia.GetAudioClip($"File://{text}{track.Name}Loop.mp3", AudioType.MPEG); |                 requests[i * 2 + 1] = UnityWebRequestMultimedia.GetAudioClip($"File://{text}{track.Name}Loop.mp3", AudioType.MPEG); | ||||||
| 				requests[i * 2].SendWebRequest(); |                 requests[i * 2].SendWebRequest(); | ||||||
| 				requests[i * 2 + 1].SendWebRequest(); |                 requests[i * 2 + 1].SendWebRequest(); | ||||||
| 			} |             } | ||||||
| 
 | 
 | ||||||
| 			while (!requests.All(request => request.isDone)) { } |             while (!requests.All(request => request.isDone)) { } | ||||||
| 
 | 
 | ||||||
| 			if (requests.All(request => request.result == UnityWebRequest.Result.Success)) { |             if (requests.All(request => request.result == UnityWebRequest.Result.Success)) { | ||||||
| 				for (int i = 0; i < Tracks.Length; i++) { |                 for (int i = 0; i < Tracks.Length; i++) { | ||||||
| 					Tracks[i].LoadedStart = DownloadHandlerAudioClip.GetContent(requests[i * 2]); |                     Tracks[i].LoadedStart = DownloadHandlerAudioClip.GetContent(requests[i * 2]); | ||||||
| 					Tracks[i].LoadedLoop = DownloadHandlerAudioClip.GetContent(requests[i * 2 + 1]); |                     Tracks[i].LoadedLoop = DownloadHandlerAudioClip.GetContent(requests[i * 2 + 1]); | ||||||
| 				} |                 } | ||||||
| 				new Harmony(PluginInfo.PLUGIN_NAME).PatchAll(typeof(JesterPatch)); |                 new Harmony(PluginInfo.PLUGIN_NAME).PatchAll(typeof(JesterPatch)); | ||||||
| 			} else { |             } else { | ||||||
| 				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]; |  | ||||||
| 
 | 
 | ||||||
| 	    public static IEnumerator rotateColors() |         static List<Color> colors = [Color.magenta, Color.cyan, Color.green, Color.yellow]; | ||||||
| 	    { |  | ||||||
| 		    Debug.Log("Starting color rotation"); |  | ||||||
| 		    var i = 0; |  | ||||||
| 		    while (true) |  | ||||||
| 		    { |  | ||||||
| 			    var color = colors[i]; |  | ||||||
| 			    Debug.Log("Chose color " + color); |  | ||||||
| 			    foreach (var light in RoundManager.Instance.allPoweredLights) |  | ||||||
| 			    { |  | ||||||
| 				    light.color = color; |  | ||||||
| 			    } |  | ||||||
| 
 | 
 | ||||||
| 			    i += 1; |         public static IEnumerator rotateColors() | ||||||
| 			    if (i >= colors.Count) i = 0; |         { | ||||||
| 			    yield return new WaitForSeconds(60f / Plugin.CurrentTrack.Bpm); |             Debug.Log("Starting color rotation"); | ||||||
| 		    } |             var i = 0; | ||||||
| 	    } |             while (true) | ||||||
|  |             { | ||||||
|  |                 var color = colors[i]; | ||||||
|  |                 Debug.Log("Chose color " + color); | ||||||
|  |                 foreach (var light in RoundManager.Instance.allPoweredLights) | ||||||
|  |                 { | ||||||
|  |                     light.color = color; | ||||||
|  |                 } | ||||||
| 
 | 
 | ||||||
| 		[HarmonyPatch("Update")] |                 i += 1; | ||||||
|  |                 if (i >= colors.Count) i = 0; | ||||||
|  |                 yield return new WaitForSeconds(60f / Plugin.CurrentTrack.Bpm); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         [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 just started winding up |  | ||||||
| 		        // then stop the default music... |  | ||||||
| 		        __instance.farAudio.Stop(); |  | ||||||
| 		        __instance.creatureVoice.Stop(); |  | ||||||
| 		         |  | ||||||
| 		        //  ...and start modded music |  | ||||||
| 		        var seed = RoundManager.Instance.dungeonGenerator.Generator.ChosenSeed; |  | ||||||
| 		        var sha = SHA256.Create(); |  | ||||||
| 		        var hash = sha.ComputeHash(BitConverter.GetBytes(seed)); |  | ||||||
| 		        var trackId = 0; |  | ||||||
| 		        foreach (var t in hash) |  | ||||||
| 		        { |  | ||||||
| 			        // modulus division on byte array |  | ||||||
| 			        trackId *= 256 % Plugin.Tracks.Length; |  | ||||||
| 			        trackId %= Plugin.Tracks.Length; |  | ||||||
| 			        trackId += t % Plugin.Tracks.Length; |  | ||||||
| 			        trackId %= Plugin.Tracks.Length; |  | ||||||
| 		        } |  | ||||||
| 		        Debug.Log($"Seed is {seed}, chosen track is {trackId} out of {Plugin.Tracks.Length} tracks"); |  | ||||||
| 		        Plugin.CurrentTrack = Plugin.Tracks[trackId]; |  | ||||||
| 		        __instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer; |  | ||||||
| 		        __instance.farAudio.maxDistance = 150; |  | ||||||
| 		        __instance.farAudio.clip = Plugin.CurrentTrack.LoadedStart; |  | ||||||
| 		        __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}"); |  | ||||||
| 		        __instance.farAudio.Play(); |  | ||||||
| 	        } |  | ||||||
| 
 | 
 | ||||||
| 	        if (__instance.currentBehaviourStateIndex is 2 && __state.prevStateindex != 2) |             if (__instance.currentBehaviourStateIndex is 1 && __state.prevStateindex != 1) | ||||||
| 	        { |             { | ||||||
| 		        __instance.creatureVoice.Stop(); |                 // if just started winding up | ||||||
| 		         |                 // then stop the default music... | ||||||
| 		        if (Plugin.JesterLightSwitching != null) { |                 __instance.farAudio.Stop(); | ||||||
| 			        __instance.StopCoroutine(Plugin.JesterLightSwitching); |                 __instance.creatureVoice.Stop(); | ||||||
| 			        Plugin.JesterLightSwitching = null; |  | ||||||
| 		        } |  | ||||||
| 		        Plugin.JesterLightSwitching = __instance.StartCoroutine(rotateColors()); |  | ||||||
| 	        } |  | ||||||
| 
 | 
 | ||||||
| 	        if (__instance.currentBehaviourStateIndex != 2 && __state.prevStateindex == 2) |                 //  ...and start modded music | ||||||
| 	        { |                 var seed = RoundManager.Instance.dungeonGenerator.Generator.ChosenSeed; | ||||||
| 		        if (Plugin.JesterLightSwitching != null) { |                 var sha = SHA256.Create(); | ||||||
| 			        __instance.StopCoroutine(Plugin.JesterLightSwitching); |                 var hash = sha.ComputeHash(BitConverter.GetBytes(seed)); | ||||||
| 			        Plugin.JesterLightSwitching = null; |                 var trackId = 0; | ||||||
| 		        } |                 foreach (var t in hash) | ||||||
| 		        foreach (var light in RoundManager.Instance.allPoweredLights) |                 { | ||||||
| 		        { |                     // modulus division on byte array | ||||||
| 			        light.color = Color.white; |                     trackId *= 256 % Plugin.Tracks.Length; | ||||||
| 		        } |                     trackId %= Plugin.Tracks.Length; | ||||||
| 	        } |                     trackId += t % Plugin.Tracks.Length; | ||||||
|  |                     trackId %= Plugin.Tracks.Length; | ||||||
|  |                 } | ||||||
|  |                 Debug.Log($"Seed is {seed}, chosen track is {trackId} out of {Plugin.Tracks.Length} tracks"); | ||||||
|  |                 Plugin.CurrentTrack = Plugin.Tracks[trackId]; | ||||||
|  |                 __instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer; | ||||||
|  |                 __instance.farAudio.maxDistance = 150; | ||||||
|  |                 __instance.farAudio.clip = Plugin.CurrentTrack.LoadedStart; | ||||||
|  |                 __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}"); | ||||||
|  |                 __instance.farAudio.Play(); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
| 	        if (__instance.currentBehaviourStateIndex is 2 && !__instance.creatureVoice.isPlaying) |             if (__instance.currentBehaviourStateIndex is 2 && __state.prevStateindex != 2) | ||||||
| 	        { |             { | ||||||
| 		        __instance.creatureVoice.maxDistance = 150; |                 __instance.creatureVoice.Stop(); | ||||||
| 		        __instance.creatureVoice.clip = Plugin.CurrentTrack.LoadedLoop; | 
 | ||||||
| 		        var time = __instance.farAudio.time; |                 if (Plugin.JesterLightSwitching != null) { | ||||||
| 		        var delay = Plugin.CurrentTrack.LoadedStart.length - time; |                     __instance.StopCoroutine(Plugin.JesterLightSwitching); | ||||||
| 		        Debug.Log($"Start length: {Plugin.CurrentTrack.LoadedStart.length}; played time: {time}"); |                     Plugin.JesterLightSwitching = null; | ||||||
| 		        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); |                 Plugin.JesterLightSwitching = __instance.StartCoroutine(rotateColors()); | ||||||
| 	        } |             } | ||||||
|  | 
 | ||||||
|  |             if (__instance.currentBehaviourStateIndex != 2 && __state.prevStateindex == 2) | ||||||
|  |             { | ||||||
|  |                 if (Plugin.JesterLightSwitching != null) { | ||||||
|  |                     __instance.StopCoroutine(Plugin.JesterLightSwitching); | ||||||
|  |                     Plugin.JesterLightSwitching = null; | ||||||
|  |                 } | ||||||
|  |                 foreach (var light in RoundManager.Instance.allPoweredLights) | ||||||
|  |                 { | ||||||
|  |                     light.color = Color.white; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if (__instance.currentBehaviourStateIndex is 2 && !__instance.creatureVoice.isPlaying) | ||||||
|  |             { | ||||||
|  |                 __instance.creatureVoice.maxDistance = 150; | ||||||
|  |                 __instance.creatureVoice.clip = Plugin.CurrentTrack.LoadedLoop; | ||||||
|  |                 var time = __instance.farAudio.time; | ||||||
|  |                 var delay = Plugin.CurrentTrack.LoadedStart.length - 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}"); | ||||||
|  |                 __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