Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
support upper case, add debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lxymahatma committed May 4, 2023
1 parent dae61ac commit ae7c3f7
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 27 deletions.
37 changes: 28 additions & 9 deletions Main.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Collections.Generic;
using System.IO;
using MelonLoader;
using UnityEngine.UI;
using Tomlet;
using Tomlet.Attributes;

namespace CustomHitSound;

internal class Main : MelonMod
{
internal static Dictionary<string, string[]> Paths { get; } = new();
internal static Dictionary<string, Toggle> Toggles { get; } = new();

public override void OnInitializeMelon()
{
Expand All @@ -23,22 +23,41 @@ public override void OnInitializeMelon()

public override void OnDeinitializeMelon()
{
if (!Paths.ContainsKey(Save.Sfx))
Save.Sfx = string.Empty;
File.WriteAllText(Path.Combine("UserData", "Custom Hit Sound.cfg"), Save.Sfx);
if (!Paths.ContainsKey(Save.Setting.Sfx))
Save.Setting.Sfx = string.Empty;
File.WriteAllText(Path.Combine("UserData", "Custom Hit Sound.cfg"), TomletMain.TomlStringFrom(Save.Setting));
}
}

internal static class Save
{
private const string Default = "Celeste";
internal static string Sfx { get; set; }
private static readonly Data Default = new("Celeste", false);
internal static Data Setting;

public static void Load()
{
if (!File.Exists(Path.Combine("UserData", "Custom Hit Sound.cfg")))
File.WriteAllText(Path.Combine("UserData", "Custom Hit Sound.cfg"), Default);
{
var defaultConfig = TomletMain.TomlStringFrom(Default);
File.WriteAllText(Path.Combine("UserData", "Custom Hit Sound.cfg"), defaultConfig);
}

Sfx = File.ReadAllText(Path.Combine("UserData", "Custom Hit Sound.cfg"));
var data = File.ReadAllText(Path.Combine("UserData", "Custom Hit Sound.cfg"));
Setting = TomletMain.To<Data>(data);
}

internal struct Data
{
[TomlPrecedingComment("The current using sfx pack")]
internal string Sfx { get; set; }

[TomlPrecedingComment("Whether debug mode enabled or not")]
internal bool DebugModeEnabled { get; set; }

internal Data(string sfx, bool debugModeEnabled)
{
Sfx = sfx;
DebugModeEnabled = debugModeEnabled;
}
}
}
30 changes: 19 additions & 11 deletions Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Assets.Scripts.Database;
using Assets.Scripts.PeroTools.Managers;
using HarmonyLib;
using MelonLoader;
using RuntimeAudioClipLoader;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -15,19 +16,28 @@ internal static class AudioManagerPatch
{
private static void Postfix(AudioManager __instance)
{
if (!Main.Paths.ContainsKey(Save.Sfx))
if (!Main.Paths.ContainsKey(Save.Setting.Sfx))
{
Save.Sfx = string.Empty;
Save.Setting.Sfx = string.Empty;
return;
}

foreach (var path in Main.Paths[Save.Sfx])
foreach (var path in Main.Paths[Save.Setting.Sfx])
{
var postfix = "_" + Save.Sfx.ToLower();
var name = Path.GetFileNameWithoutExtension(path).Replace(postfix, string.Empty);
var length = Save.Setting.Sfx.Length + 1;
var name = Path.GetFileNameWithoutExtension(path);
name = name.Remove(name.Length - length);
var audioClip = Manager.Load(path);
__instance.m_SfxBuffer[name] = audioClip;
}

if (!Save.Setting.DebugModeEnabled) return;
foreach (var pair in __instance.m_SfxBuffer)
{
MelonLogger.Msg("Key name: " + pair.Key);
MelonLogger.Msg("Audio path: " + pair.Value.name);
MelonLogger.Msg(string.Empty);
}
}
}

Expand All @@ -36,7 +46,6 @@ internal static class VolumeSelectPatch
{
private static void Postfix()
{
Main.Toggles.Clear();
var toggles = GameObject.Find("Forward").transform.GetChild(5).GetChild(6).GetChild(2);
var x = -6.35f;
foreach (var key in Main.Paths.Keys)
Expand All @@ -54,22 +63,21 @@ private static void Postfix()
if (val)
{
DataHelper.battleSfxType = 0;
Save.Sfx = key;
Save.Setting.Sfx = key;
}
else
{
Save.Sfx = string.Empty;
Save.Setting.Sfx = string.Empty;
}
}));

if (Save.Sfx == key)
if (Save.Setting.Sfx == key)
toggleComp.SetIsOnWithoutNotify(true);

Main.Toggles.Add(key, toggleComp);
x += 1f + key.Length * 0.2f;
}

if (Save.Sfx == string.Empty && DataHelper.battleSfxType == 0)
if (Save.Setting.Sfx == string.Empty && DataHelper.battleSfxType == 0)
toggles.GetChild(0).GetComponent<Toggle>().SetIsOnWithoutNotify(true);
}
}
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.3")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: MelonInfo(typeof(Main), "CustomHitSound", "1.0.3", "lxy")]
[assembly: AssemblyVersion("1.0.4")]
[assembly: AssemblyFileVersion("1.0.4")]
[assembly: MelonInfo(typeof(Main), "CustomHitSound", "1.0.4", "lxy")]
[assembly: MelonGame("PeroPeroGames", "MuseDash")]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ VoiceAmiyaHurt05

**You should name the audio file with the following format:**

**soundname_<folder name in lowercase>.wav (or mp3, aiff, ogg)**
**soundname_<folder name in lowercase/uppercase>.wav (or mp3, aiff, ogg)**

For example: sfx_forte_2_celeste.wav in Celeste folder.
For example: `sfx_forte_2_celeste.wav` (or you can name it as `sfx_forte_2_Celeste.wav`) in Celeste folder.

### The game will use the default sound if you don't implement the sound.

Expand Down
4 changes: 2 additions & 2 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ VoiceAmiyaHurt05

**你需要把文件命名为以下的格式:**

**音效名称_<小写的文件夹名字>.wav (或者是mp3,aiff,ogg)**
**音效名称_<小写或大写的文件夹名字>.wav (或者是mp3,aiff,ogg)**

例子:sfx_forte_2_celeste.wav在Celeste文件夹里
例子:Celeste文件夹里的`sfx_forte_2_celeste.wav` (也可以命名为`sfx_forte_2_Celeste.wav`

### 如果你没有替换对应音效游戏会使用默认音效

Expand Down

0 comments on commit ae7c3f7

Please sign in to comment.