Skip to content

Commit

Permalink
Migrated to use Custom Song Data Loader
Browse files Browse the repository at this point in the history
This version is now using the Custom Song Data Loader utility to do loading of the difficulty names
  • Loading branch information
Meeps committed Sep 18, 2020
1 parent f127a52 commit e2e7d49
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 181 deletions.
18 changes: 17 additions & 1 deletion AudicaMod/CustomDifficultyNames.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<HintPath>lib\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="CustomSongData, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>src\lib\CustomSongData.dll</HintPath>
</Reference>
<Reference Include="Il2CppMono.Security">
<HintPath>lib\Il2CppMono.Security.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -190,12 +194,24 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="src\CustomDifficultyName\CustomDifficultyNames.cs" />
<Compile Include="src\CustomDifficultyName\DifficultyHooks.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="src\CustomSongData.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion AudicaMod/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: MelonInfo(typeof(CustomDifficultyNames), "Custom Difficulty Names", "1.0.0", "MeepsKitten")]
[assembly: MelonInfo(typeof(AudicaModding.CustomDifficultyNames), "Custom Difficulty Names", "1.0.0", "MeepsKitten")]


// Create and Setup a MelonModGame to mark a Mod as Universal or Compatible with specific Games.
Expand Down
197 changes: 128 additions & 69 deletions AudicaMod/src/CustomDifficultyName/CustomDifficultyNames.cs
Original file line number Diff line number Diff line change
@@ -1,88 +1,147 @@
using Il2CppSystem;
using MelonLoader;
using System.Collections.Generic;
using MelonLoader;
using UnityEngine;
using System.IO;
using System.IO.Compression;
using MelonLoader.TinyJSON;
using TMPro;
using System.Collections;
using Harmony;
using System;
using System.Linq;

//[assembly: MelonOptionalDependencies("CustomSongDataLoader")]


namespace AudicaModding
{
public class CustomDifficultyNames : MelonMod
{
public static Dictionary<string, CustomNameData> CustomDifficulties = new Dictionary<string, CustomNameData>();
public static bool NamesAlreadyLoaded = false;
public class CustomNameData
public static IEnumerator ChangeNamesLP(LaunchPanel __instance)
{
public bool hasCustomExpertName = false;
public bool hasCustomAdvancedName = false;
public bool hasCustomModerateName = false;
public bool hasCustomBeginnerName = false;
yield return new WaitForSeconds(0.05f);

var song = SongDataHolder.I.songData;

if (!CustomSongDataLoader.SongHasCustomData(song.songID))
yield break;

if (CustomSongDataLoader.SongHasCustomDataKey(song.songID, "customExpert"))
{
__instance.expert.GetComponentInChildren<TextMeshPro>().text = CustomSongDataLoader.GetCustomData<string>(song.songID, "customExpert");
}
else
{
__instance.expert.GetComponentInChildren<TextMeshPro>().text = "Expert";
}

if (CustomSongDataLoader.SongHasCustomDataKey(song.songID, "customAdvanced"))
{
__instance.hard.GetComponentInChildren<TextMeshPro>().text = CustomSongDataLoader.GetCustomData<string>(song.songID, "customAdvanced");
}
else
{
__instance.hard.GetComponentInChildren<TextMeshPro>().text = "Advanced";

}

if (CustomSongDataLoader.SongHasCustomDataKey(song.songID, "customModerate"))
{
__instance.normal.GetComponentInChildren<TextMeshPro>().text = CustomSongDataLoader.GetCustomData<string>(song.songID, "customModerate");
}
else
{
__instance.normal.GetComponentInChildren<TextMeshPro>().text = "Moderate";

}

if (CustomSongDataLoader.SongHasCustomDataKey(song.songID, "customBeginner"))
{
__instance.easy.GetComponentInChildren<TextMeshPro>().text = CustomSongDataLoader.GetCustomData<string>(song.songID, "customBeginner");
}
else
{
__instance.easy.GetComponentInChildren<TextMeshPro>().text = "Beginner";

public string customExpert = "";
public string customAdvanced = "";
public string customModerate = "";
public string customBeginner = "";
}
}

public static void LoadCustomNames()
public static IEnumerator ChangeNamesDS(DifficultySelect __instance)
{
if (!NamesAlreadyLoaded)
yield return new WaitForSeconds(0.05f);

var song = SongDataHolder.I.songData;

if (!CustomSongDataLoader.SongHasCustomData(song.songID))
yield break;

if (CustomSongDataLoader.SongHasCustomDataKey(song.songID, "customExpert"))
{
CustomDifficulties = new Dictionary<string, CustomNameData>();
__instance.expert.label.SetText(CustomSongDataLoader.GetCustomData<string>(song.songID, "customExpert"));
}
else
{
__instance.expert.label.text = "Expert";
}

foreach (SongList.SongData data in SongList.I.songs.ToArray())
{
ZipArchive SongFiles = ZipFile.OpenRead(data.foundPath);

foreach (ZipArchiveEntry entry in SongFiles.Entries)
{
if (entry.Name == "song.desc")
{
Stream songData = entry.Open();
StreamReader reader = new StreamReader(songData);
string descDump = reader.ReadToEnd();
CustomNameData DifficultyNames = new CustomNameData();
DifficultyNames = JSON.Load(descDump).Make<CustomNameData>();

bool anyAreTrue = false;


if (DifficultyNames.customExpert.Length > 0)
{
DifficultyNames.hasCustomExpertName = true;
anyAreTrue = true;
}

if (DifficultyNames.customAdvanced.Length > 0)
{
DifficultyNames.hasCustomAdvancedName = true;
anyAreTrue = true;
}

if (DifficultyNames.customModerate.Length > 0)
{
DifficultyNames.hasCustomModerateName = true;
anyAreTrue = true;
}

if (DifficultyNames.customBeginner.Length > 0)
{
DifficultyNames.hasCustomBeginnerName = true;
anyAreTrue = true;
}

if (anyAreTrue)
CustomDifficulties[data.songID] = DifficultyNames;


}
}
NamesAlreadyLoaded = true;
SongFiles.Dispose();
if (CustomSongDataLoader.SongHasCustomDataKey(song.songID, "customAdvanced"))
{
__instance.hard.label.SetText(CustomSongDataLoader.GetCustomData<string>(song.songID, "customAdvanced"));
}
else
{
__instance.hard.label.text = "Advanced";

}

if (CustomSongDataLoader.SongHasCustomDataKey(song.songID, "customModerate"))
{
__instance.normal.label.SetText(CustomSongDataLoader.GetCustomData<string>(song.songID, "customModerate"));
}
else
{
__instance.normal.label.text = "Moderate";

}

if (CustomSongDataLoader.SongHasCustomDataKey(song.songID, "customBeginner"))
{
__instance.easy.label.SetText(CustomSongDataLoader.GetCustomData<string>(song.songID, "customBeginner"));
}
else
{
__instance.easy.label.text = "Beginner";
}



}

[HarmonyPatch(typeof(LaunchPanel), "OnEnable", new Type[0])]
private static class DisplayCustomNameLP
{
private static void Prefix(LaunchPanel __instance)
{
if (MelonHandler.Mods.Any(it => it.Info.SystemType.Name == nameof(CustomSongDataLoader))) {
IEnumerator coroutine = ChangeNamesLP(__instance);
MelonCoroutines.Start(coroutine);
}
else
MelonLogger.LogError("Custom Song Data mod not detected, Custom difficulty names will not run");
}

}

[HarmonyPatch(typeof(DifficultySelect), "OnEnable", new Type[0])]
private static class DisplayCustomNameDS
{
private static void Prefix(DifficultySelect __instance)
{
if (MelonHandler.Mods.Any(it => it.Info.SystemType.Name == nameof(CustomSongDataLoader)))
{
IEnumerator coroutine = ChangeNamesDS(__instance);
MelonCoroutines.Start(coroutine);
}
else
MelonLogger.LogError("Custom Song Data mod not detected, Custom difficulty names will not run");
}

}
}
}
110 changes: 0 additions & 110 deletions AudicaMod/src/CustomDifficultyName/DifficultyHooks.cs

This file was deleted.

Binary file added AudicaMod/src/lib/CustomSongData.dll
Binary file not shown.

0 comments on commit e2e7d49

Please sign in to comment.