initial version 13.37.1

This commit is contained in:
Nikita Vilunov 2024-03-09 19:48:17 +01:00
commit 20a3234371
5 changed files with 194 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
.idea/
*.dll

16
MuzikaGromche.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MuzikaGromche", "MuzikaGromche\MuzikaGromche.csproj", "{72633315-F098-4E09-B32B-9224376CD9A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{72633315-F098-4E09-B32B-9224376CD9A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72633315-F098-4E09-B32B-9224376CD9A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72633315-F098-4E09-B32B-9224376CD9A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72633315-F098-4E09-B32B-9224376CD9A5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>MuzikaGromche</AssemblyName>
<Description>Opa che tut u nas</Description>
<Version>1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all"/>
<PackageReference Include="BepInEx.Core" Version="5.*"/>
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*"/>
<PackageReference Include="UnityEngine.Modules" Version="2022.3.9" IncludeAssets="compile"/>
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all" />
<Reference Include="Assembly-CSharp" HintPath="Assembly-CSharp.dll" Publicize="true" />
<Reference Include="Unity.Netcode.Runtime" HintPath="Unity.Netcode.Runtime.dll" Publicize="true" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all"/>
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
</packageSources>
</configuration>

140
MuzikaGromche/Plugin.cs Normal file
View File

@ -0,0 +1,140 @@
using System.Collections;
using System.Collections.Generic;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;
namespace MuzikaGromche
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public static AudioClip AudioStart;
public static AudioClip AudioLoop;
public static Coroutine JesterLightSwitching;
private void Awake()
{
string text = Info.Location.TrimEnd((PluginInfo.PLUGIN_NAME + ".dll").ToCharArray());
UnityWebRequest audioClipStart = UnityWebRequestMultimedia.GetAudioClip("File://" + text + "MuzikaGromcheStart.mp3", AudioType.MPEG);
UnityWebRequest audioClipLoop = UnityWebRequestMultimedia.GetAudioClip("File://" + text + "MuzikaGromcheLoop.mp3", AudioType.MPEG);
audioClipStart.SendWebRequest();
audioClipLoop.SendWebRequest();
while (!audioClipStart.isDone || !audioClipLoop.isDone) { }
if (audioClipStart.result == UnityWebRequest.Result.Success && audioClipLoop.result == UnityWebRequest.Result.Success) {
AudioStart = DownloadHandlerAudioClip.GetContent(audioClipStart);
AudioLoop = DownloadHandlerAudioClip.GetContent(audioClipLoop);
new Harmony(PluginInfo.PLUGIN_NAME).PatchAll(typeof(JesterPatch));
Logger.LogInfo("Muzika gromche, glaza zakryvaj! " + PluginInfo.PLUGIN_VERSION);
} else {
Logger.LogError("Could not load audio file");
}
}
}
[HarmonyPatch(typeof(JesterAI))]
internal class JesterPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void AudioPatch(JesterAI __instance)
{
__instance.popGoesTheWeaselTheme = Plugin.AudioStart;
__instance.screamingSFX = Plugin.AudioLoop;
}
[HarmonyPatch("SetJesterInitialValues")]
[HarmonyPostfix]
public static void ForceTime(JesterAI __instance)
{
__instance.popUpTimer = 46.3f;
}
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static void DoNotStopTheMusicPrefix(JesterAI __instance, out State __state)
{
__state = new State();
__state.prevStateindex = __instance.previousState;
if (__instance.currentBehaviourStateIndex is 1 or 2) {
__state.farAudio = __instance.farAudio;
__instance.farAudio = __instance.creatureSFX;
}
}
static List<Color> colors = [Color.magenta, Color.cyan, Color.green, Color.yellow];
public static IEnumerator rotateColors()
{
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;
if (i >= colors.Count) i = 0;
yield return new WaitForSeconds(0.5f);
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void DoNotStopTheMusic(JesterAI __instance, State __state)
{
if (__state.farAudio != null)
{
__instance.farAudio = __state.farAudio;
}
if (__instance.currentBehaviourStateIndex is 1 && !__instance.farAudio.isPlaying)
{
__instance.farAudio.PlayOneShot(Plugin.AudioStart);
}
if (__instance.currentBehaviourStateIndex is 2 && __state.prevStateindex != 2)
{
__instance.creatureVoice.Stop();
if (Plugin.JesterLightSwitching != null) {
__instance.StopCoroutine(Plugin.JesterLightSwitching);
Plugin.JesterLightSwitching = null;
}
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.farAudio.isPlaying)
{
__instance.creatureVoice.clip = Plugin.AudioLoop;
__instance.creatureVoice.Play();
}
}
}
internal class State
{
public AudioSource farAudio;
public int prevStateindex;
}
}