diff --git a/.gitignore b/.gitignore index fcdef46..c1630b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,493 @@ -bin/ -obj/ -/packages/ -riderModule.iml -/_ReSharper.Caches/ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from `dotnet new gitignore` + +# dotenv files +.env + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml .idea/ + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/main/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/main/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Vim temporary swap files +*.swp + +# Override *.user rule for templates +!*.template.props.user +!*.template.just.user + +riderModule.iml +dist/ *.dll -MuzikaGromche.sln.DotSettings.user +*.zip diff --git a/Assets/.gitattributes b/Assets/.gitattributes index 6b9df02..58b97d0 100644 --- a/Assets/.gitattributes +++ b/Assets/.gitattributes @@ -1 +1,3 @@ *.mp3 filter=lfs diff=lfs merge=lfs -text +*.ogg filter=lfs diff=lfs merge=lfs -text +*.wav filter=lfs diff=lfs merge=lfs -text diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..5801846 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,4 @@ + + + + diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..4f48f5d --- /dev/null +++ b/Justfile @@ -0,0 +1,28 @@ +import? 'MuzikaGromche.just.user' + +build: build-debug build-release + +build-release: + dotnet build --configuration Release + +build-debug: + dotnet build --configuration Debug + +clean: + rm -rf dist MuzikaGromche/bin MuzikaGromche/obj + +plugin_dir := "$HOME/.config/r2modmanPlus-local/LethalCompany/profiles" / imperium_profile / "BepInEx/plugins/Oflor-MuzikaGromche/" + +install-imperium: + rm -rf "{{ plugin_dir }}" + mkdir "{{ plugin_dir }}" + unzip -q dist/MuzikaGromche-Debug.zip -d "{{ plugin_dir }}" + +run-imperium: + DRI_PRIME=1 steam -applaunch 1966720 --doorstop-enable true --doorstop-target "Z:$HOME/.config/r2modmanPlus-local/LethalCompany/profiles/{{ imperium_profile }}/BepInEx/core/BepInEx.Preloader.dll" --r2profile "{{ imperium_profile }}" + +bump version_number: + [[ "v{{ version_number }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || (echo "Invalid version format" && exit 1) + jq --indent 4 --arg v "{{ version_number }}" '.version_number = $v' < manifest.json > manifest.json.copy + mv manifest.json.copy manifest.json + sed -i 's/.*<\/Version>/{{ version_number }}<\/Version>/' MuzikaGromche/MuzikaGromche.csproj diff --git a/MuzikaGromche.template.just.user b/MuzikaGromche.template.just.user new file mode 100644 index 0000000..96c04fd --- /dev/null +++ b/MuzikaGromche.template.just.user @@ -0,0 +1,3 @@ +# Copy me to MuzikaGromche.just.user and adjust tasks to your workflow + +imperium_profile := "Muzika Gromche with Imperium" diff --git a/MuzikaGromche.template.props.user b/MuzikaGromche.template.props.user new file mode 100644 index 0000000..4c60799 --- /dev/null +++ b/MuzikaGromche.template.props.user @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/MuzikaGromche/MuzikaGromche.csproj b/MuzikaGromche/MuzikaGromche.csproj index 65641fc..e0cfde1 100644 --- a/MuzikaGromche/MuzikaGromche.csproj +++ b/MuzikaGromche/MuzikaGromche.csproj @@ -4,7 +4,7 @@ netstandard2.1 MuzikaGromche Opa che tut u nas - 1.0.0 + 13.37.6 true latest @@ -15,11 +15,56 @@ - - + + + + + $(LethalCompanyDir)Lethal Company_Data\Managed\Assembly-CSharp.dll + + + $(LethalCompanyDir)Lethal Company_Data\Managed\Unity.Collections.dll + + + $(LethalCompanyDir)Lethal Company_Data\Managed\Unity.Netcode.Runtime.dll + + + + + $(TargetDir)MuzikaGromche\ + $(TargetDir)MuzikaGromche-$(Configuration).zip + + + + + + + + + + + + + + + + + + + + diff --git a/MuzikaGromche/Plugin.cs b/MuzikaGromche/Plugin.cs index 159cf2c..9b4ef28 100644 --- a/MuzikaGromche/Plugin.cs +++ b/MuzikaGromche/Plugin.cs @@ -13,199 +13,257 @@ namespace MuzikaGromche [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BaseUnityPlugin { - public static Track[] Tracks = [ - new Track - { - Name = "MuzikaGromche", - WindUpTimer = 46.3f, - Bpm = 130f, - }, - new Track - { - Name = "VseVZale", - WindUpTimer = 39f, - Bpm = 138f, - }, - new Track - { - Name = "DeployDestroy", - WindUpTimer = 40.7f, - Bpm = 130f, - }, - new Track - { - Name = "MoyaZhittya", - WindUpTimer = 34.5f, - Bpm = 120f, - }, - new Track - { - Name = "Gorgorod", - WindUpTimer = 43.2f, - Bpm = 180f, - }, - new Track - { - Name = "Durochka", - WindUpTimer = 37f, - Bpm = 130f, - } - ]; + public static Track[] Tracks = [ + new Track + { + Name = "MuzikaGromche", + WindUpTimer = 46.3f, + Bpm = 130f, + }, + new Track + { + Name = "VseVZale", + WindUpTimer = 39f, + Bpm = 138f, + }, + new Track + { + Name = "DeployDestroy", + WindUpTimer = 40.7f, + Bpm = 130f, + }, + new Track + { + Name = "MoyaZhittya", + WindUpTimer = 34.5f, + Bpm = 120f, + }, + new Track + { + Name = "Gorgorod", + WindUpTimer = 43.2f, + Bpm = 180f, + }, + new Track + { + Name = "Durochka", + WindUpTimer = 37f, + Bpm = 130f, + } + ]; - public static Coroutine JesterLightSwitching; - public static Track CurrentTrack; + public static Coroutine JesterLightSwitching; + public static Track CurrentTrack; - private void Awake() - { - string text = Info.Location.TrimEnd((PluginInfo.PLUGIN_NAME + ".dll").ToCharArray()); - UnityWebRequest[] requests = new UnityWebRequest[Tracks.Length * 2]; - for (int i = 0; i < Tracks.Length; i++) { - Track track = Tracks[i]; - 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].SendWebRequest(); - requests[i * 2 + 1].SendWebRequest(); - } + public static void StartLightSwitching(MonoBehaviour __instance) + { + StopLightSwitching(__instance); + JesterLightSwitching = __instance.StartCoroutine(RotateColors()); + } - while (!requests.All(request => request.isDone)) { } + public static void StopLightSwitching(MonoBehaviour __instance) + { + if (JesterLightSwitching != null) + { + __instance.StopCoroutine(JesterLightSwitching); + JesterLightSwitching = null; + } + } - if (requests.All(request => request.result == UnityWebRequest.Result.Success)) { - for (int i = 0; i < Tracks.Length; i++) { - Tracks[i].LoadedStart = DownloadHandlerAudioClip.GetContent(requests[i * 2]); - Tracks[i].LoadedLoop = DownloadHandlerAudioClip.GetContent(requests[i * 2 + 1]); - } - new Harmony(PluginInfo.PLUGIN_NAME).PatchAll(typeof(JesterPatch)); - } else { - Logger.LogError("Could not load audio file"); - } - } + public static void SetLightColor(Color color) + { + foreach (var light in RoundManager.Instance.allPoweredLights) + { + light.color = color; + } + } + + public static void ResetLightColor() + { + SetLightColor(Color.white); + } + + // TODO: Move to Track class to make them customizable per-song + static List 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); + SetLightColor(color); + i = (i + 1) % colors.Count; + if (CurrentTrack != null) + { + yield return new WaitForSeconds(60f / CurrentTrack.Bpm); + } + else + { + yield break; + } + } + } + + private void Awake() + { + string text = Info.Location.TrimEnd((PluginInfo.PLUGIN_NAME + ".dll").ToCharArray()); + UnityWebRequest[] requests = new UnityWebRequest[Tracks.Length * 2]; + for (int i = 0; i < Tracks.Length; i++) + { + Track track = Tracks[i]; + requests[i * 2] = UnityWebRequestMultimedia.GetAudioClip($"File://{text}{track.FileNameStart}", track.AudioType); + requests[i * 2 + 1] = UnityWebRequestMultimedia.GetAudioClip($"File://{text}{track.FileNameLoop}", track.AudioType); + requests[i * 2].SendWebRequest(); + requests[i * 2 + 1].SendWebRequest(); + } + + while (!requests.All(request => request.isDone)) { } + + if (requests.All(request => request.result == UnityWebRequest.Result.Success)) + { + for (int i = 0; i < Tracks.Length; i++) + { + Track track = Tracks[i]; + track.LoadedStart = DownloadHandlerAudioClip.GetContent(requests[i * 2]); + track.LoadedLoop = DownloadHandlerAudioClip.GetContent(requests[i * 2 + 1]); + } + new Harmony(PluginInfo.PLUGIN_NAME).PatchAll(typeof(JesterPatch)); + } + else + { + Logger.LogError("Could not load audio file"); + } + } } public class Track { - public string Name; - public float WindUpTimer; - public float Bpm; - public AudioClip LoadedStart; - public AudioClip LoadedLoop; + public string Name; + // Wind-up time can and should be shorter than the Start audio track, + // so that the "pop" effect can be baked into the Start audio and kept away + // from the looped part. This also means that the light show starts before + // the looped track does, so we need to sync them up as soon as we enter the Loop. + public float WindUpTimer; + // BPM for light switching in sync with the music. There is no offset, + // so the Loop track should start precisely on a beat. + public float Bpm; + + // MPEG is basically mp3, and it can produce gaps at the start. + // WAV is OK, but takes a lot of space. Try OGGVORBIS instead. + public AudioType AudioType = AudioType.MPEG; + + public AudioClip LoadedStart; + public AudioClip LoadedLoop; + + public string FileNameStart => $"{Name}Start.{Ext}"; + public string FileNameLoop => $"{Name}Loop.{Ext}"; + private string Ext => AudioType switch + { + AudioType.MPEG => "mp3", + AudioType.WAV => "wav", + AudioType.OGGVORBIS => "ogg", + _ => "", + }; } [HarmonyPatch(typeof(JesterAI))] internal class JesterPatch { - [HarmonyPatch("Update")] - [HarmonyPrefix] - public static void DoNotStopTheMusicPrefix(JesterAI __instance, out State __state) - { - __state = new State(); - __state.prevStateindex = __instance.previousState; - if (__instance.currentBehaviourStateIndex == 2 && __instance.previousBehaviourStateIndex != 2) { - // if just popped out - // then override farAudio so that vanilla logic does not stop the music - __state.farAudio = __instance.farAudio; - __instance.farAudio = __instance.creatureVoice; - } - } - - static List colors = [Color.magenta, Color.cyan, Color.green, Color.yellow]; +#if DEBUG + [HarmonyPatch("SetJesterInitialValues")] + [HarmonyPostfix] + public static void AlmostInstantFollowTimerPostfix(JesterAI __instance) + { + __instance.beginCrankingTimer = 1f; + } +#endif + [HarmonyPatch("Update")] + [HarmonyPrefix] + public static void DoNotStopTheMusicPrefix(JesterAI __instance, out State __state) + { + __state = new State + { + previousState = __instance.previousState + }; + if (__instance.currentBehaviourStateIndex == 2 && __instance.previousState != 2) + { + // if just popped out + // then override farAudio so that vanilla logic does not stop the music + __state.farAudio = __instance.farAudio; + __instance.farAudio = __instance.creatureVoice; + } + } - 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(60f / Plugin.CurrentTrack.Bpm); - } - } - - [HarmonyPatch("Update")] + [HarmonyPatch("Update")] [HarmonyPostfix] public static void DoNotStopTheMusic(JesterAI __instance, State __state) { - if (__state.farAudio != null) - { - __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 (__state.farAudio != null) + { + __instance.farAudio = __state.farAudio; + } - 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.previousState == 1 && __state.previousState != 1) + { + // if just started winding up + // then stop the default music... + __instance.farAudio.Stop(); + __instance.creatureVoice.Stop(); - 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; - } - } + // ...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 && !__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); - } + if (__instance.previousState == 2 && __state.previousState != 2) + { + __instance.creatureVoice.Stop(); + Plugin.StartLightSwitching(__instance); + } + + if (__instance.previousState != 2 && __state.previousState == 2) + { + Plugin.StopLightSwitching(__instance); + Plugin.ResetLightColor(); + } + + if (__instance.previousState == 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 { - public AudioSource farAudio; - public int prevStateindex; + public AudioSource farAudio; + public int previousState; } } diff --git a/MuzikaGromche/NuGet.Config b/NuGet.Config similarity index 100% rename from MuzikaGromche/NuGet.Config rename to NuGet.Config diff --git a/README.md b/README.md new file mode 100644 index 0000000..a4f4898 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Adds some content to your reverse teleports on Titan \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..e111710 Binary files /dev/null and b/icon.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..8cc5352 --- /dev/null +++ b/manifest.json @@ -0,0 +1,10 @@ +{ + "name": "MuzikaGromche", + "version_number": "13.37.6", + "author": "Oflor", + "description": "Glaza zakryvaj", + "website_url": "https://git.vilunov.me/nikita/muzika-gromche", + "dependencies": [ + "BepInEx-BepInExPack-5.4.2100" + ] +}