Skip to content

Commit

Permalink
v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
huantianad committed May 19, 2022
1 parent 0e08406 commit b452eb4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 47 deletions.
4 changes: 2 additions & 2 deletions RDTweaks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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("0.4.0")]
[assembly: AssemblyFileVersion("0.4.0")]
[assembly: AssemblyVersion("0.5.0")]
[assembly: AssemblyFileVersion("0.5.0")]
110 changes: 70 additions & 40 deletions RDTweaks/RDTweaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@

namespace RDTweaks
{
[BepInPlugin(Guid, "RDTweaks", "0.4.0")]
[BepInPlugin(Guid, "RDTweaks", "0.5.0")]
[BepInProcess("Rhythm Doctor.exe")]
public class RDTweaks : BaseUnityPlugin
{
private const string Guid = "dev.huantian.plugins.rdtweaks";

private ConfigEntry<bool> configAlwaysUseSteam;
private static ConfigEntry<SkipLocation> configSkipOnStartupTo;
private static class PConfig
{
internal static ConfigEntry<bool> alwaysUseSteam;
internal static ConfigEntry<SkipLocation> skipOnStartupTo;

internal static ConfigEntry<bool> skipTitle;

private ConfigEntry<bool> configSkipTitle;
internal static ConfigEntry<bool> CLSScrollWheel;
internal static ConfigEntry<bool> CLSScrollSound;
internal static ConfigEntry<bool> skipToLibrary;

internal static ConfigEntry<bool> hideMouseCursor;
}

private ConfigEntry<bool> configCLSScrollWheel;
private static ConfigEntry<bool> configCLSScrollSound;
private ConfigEntry<bool> configSkipToLibrary;

private enum SkipLocation
{
Expand All @@ -35,43 +41,31 @@ private enum SkipLocation
// Awake is called once when both the game and the plug-in are loaded
public void Awake()
{
configAlwaysUseSteam = Config.Bind("Startup", "AlwaysUseSteam", false,
PConfig.alwaysUseSteam = Config.Bind("Startup", "AlwaysUseSteam", false,
"Whether or not to force steam to be used to start the game.");
configSkipOnStartupTo = Config.Bind("Startup", "SkipOnStartupTo", SkipLocation.MainMenu,
PConfig.skipOnStartupTo = Config.Bind("Startup", "SkipOnStartupTo", SkipLocation.MainMenu,
"Where the game should go on startup.");
configSkipTitle = Config.Bind("MainMenu", "SkipTitle", false,
PConfig.skipTitle = Config.Bind("MainMenu", "SkipTitle", false,
"Whether or not to skip the logo screen and go directly to the main menu.");
configCLSScrollWheel = Config.Bind("CLS", "ScrollWheel", false,
PConfig.CLSScrollWheel = Config.Bind("CLS", "ScrollWheel", false,
"Whether or not to enable using scroll wheel to scroll in CLS.");
configCLSScrollSound = Config.Bind("CLS", "ScrollSound", true,
PConfig.CLSScrollSound = Config.Bind("CLS", "ScrollSound", true,
"Whether or not to play a sound when scrolling with scroll wheel.");
configSkipToLibrary = Config.Bind("CLS", "SkipToLibrary", false,
PConfig.skipToLibrary = Config.Bind("CLS", "SkipToLibrary", false,
"Whether or not to automatically enter the level library when entering CLS.");
PConfig.hideMouseCursor = Config.Bind("Gameplay", "hideMouseCursor", false,
"Whether or not to hide mouse cursor when in a level");

switch (configSkipOnStartupTo.Value)
{
case SkipLocation.CLS:
case SkipLocation.Editor:
Harmony.CreateAndPatchAll(typeof(SkipOnStartup), Guid + ".SkipOnStartup");
break;
case SkipLocation.MainMenu:
// Main Menu is default game behavior, don't change anything.
break;
default:
throw new ArgumentOutOfRangeException();
}
if (PConfig.skipOnStartupTo.Value != SkipLocation.MainMenu)
Harmony.CreateAndPatchAll(typeof(SkipOnStartup), Guid + ".SkipOnStartup");

if (configAlwaysUseSteam.Value)
if (PConfig.alwaysUseSteam.Value)
Harmony.CreateAndPatchAll(typeof(AlwaysUseSteam), Guid + ".alwaysUseSteam");

if (configSkipTitle.Value)
Harmony.CreateAndPatchAll(typeof(SkipTitle), Guid + ".skipTitle");

if (configCLSScrollWheel.Value)
Harmony.CreateAndPatchAll(typeof(CLSScrollWheel), Guid + ".CLSScrollWheel");

if (configSkipToLibrary.Value)
Harmony.CreateAndPatchAll(typeof(SkipToLibrary), Guid + ".skipToLibrary");

Harmony.CreateAndPatchAll(typeof(SkipTitle), Guid + ".skipTitle");
Harmony.CreateAndPatchAll(typeof(CLSScrollWheel), Guid + ".CLSScrollWheel");
Harmony.CreateAndPatchAll(typeof(SkipToLibrary), Guid + ".skipToLibrary");
Harmony.CreateAndPatchAll(typeof(HideMouseCursor), Guid + ".hideMouseCursor");

Logger.LogMessage("Loaded!");
}
Expand All @@ -97,7 +91,10 @@ public static class SkipOnStartup
[HarmonyPatch(typeof(scnLogo), "Exit")]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var methodName = configSkipOnStartupTo.Value == SkipLocation.Editor ? "GoToLevelEditor" : "GoToCustomLevelSelect";
var methodName = PConfig.skipOnStartupTo.Value == SkipLocation.Editor
? "GoToLevelEditor"
: "GoToCustomLevelSelect";

return new CodeMatcher(instructions)
.MatchForward(false,
new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(scnBase), "GoToMainMenu")))
Expand All @@ -112,6 +109,8 @@ public static class SkipTitle
[HarmonyPatch(typeof(scnMenu), "Start")]
public static void Postfix(scnMenu __instance)
{
if (!PConfig.skipTitle.Value) return;

var rdBase = (scnMenu)Traverse.Create(__instance).Field("_instance").GetValue();
rdBase.StartCoroutine(GoToMain(__instance));
}
Expand All @@ -136,6 +135,8 @@ public static class SkipToLibrary
[HarmonyPatch(typeof(scnCLS), "Start")]
public static void Postfix(scnCLS __instance)
{
if (!PConfig.skipToLibrary.Value) return;

var rdBase = (scnCLS)Traverse.Create(__instance).Field("_instance").GetValue();

// Copied from scnCLS.SelectWardOption()
Expand All @@ -150,12 +151,16 @@ public class CLSScrollWheel
[HarmonyPatch(typeof(scnCLS), "Update")]
public static bool Prefix(scnCLS __instance)
{
if (!PConfig.CLSScrollWheel.Value) return true;

var rdBase = (scnCLS)Traverse.Create(__instance).Field("_instance").GetValue();

if (!CanSelectLevel(__instance)) return true; // Not in right place

// Check if they're in the level select
if (!CanSelectLevel(__instance)) return true;

// Check if they can scroll
var scrolling = Input.GetAxis("Mouse ScrollWheel");
if (scrolling == 0f) return true; // They aren't scrolling
if (scrolling == 0f) return true;

// Now, based on the direction they scroll, move them up or down.
var direction = scrolling < 0f ? 1 : -1;
Expand All @@ -171,7 +176,7 @@ public static bool Prefix(scnCLS __instance)
__instance.sendLevelDataToLevelDetailCoroutine = __instance.SendLevelDataToLevelDetail(timeToUpdate: 0.0f);
rdBase.StartCoroutine(__instance.sendLevelDataToLevelDetailCoroutine);

if (configCLSScrollSound.Value)
if (PConfig.CLSScrollSound.Value)
{
var sound = __instance.CurrentLevel.CurrentRank == -3 ? "sndLibrarySelectWrapper" : "sndLibrarySelectSyringe";
var percent = RDUtils.PitchSemitonesToPercent(direction);
Expand All @@ -192,5 +197,30 @@ private static bool CanSelectLevel(scnCLS __instance)
&& (bool)Traverse.Create(__instance).Field("canSelectLevel").GetValue()
&& !__instance.SelectedLevel && !__instance.ShowingWard;
}

public static class HideMouseCursor
{
[HarmonyPrefix]
[HarmonyPatch(typeof(scnGame), "Start")]
public static bool Prefix(scnGame __instance)
{
if (!PConfig.hideMouseCursor.Value) return true;

if (__instance.editor != null) return true;

Cursor.visible = false;
return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(scnBase), "Start")]
public static bool Prefix(scnBase __instance)
{
if (!(__instance is scnGame))
Cursor.visible = true;

return true;
}
}
}
}
3 changes: 2 additions & 1 deletion RDTweaks/RDTweaks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<TestPluginPath Include="/home/huantian/.steam/steam/steamapps/common/Rhythm Doctor/BepInEx/plugins/RDTweaks/" />
<!-- <TestPluginPath Include="/home/huantian/.steam/steam/steamapps/common/Rhythm Doctor/BepInEx/plugins/RDTweaks/" />-->
<TestPluginPath Include="/home/huantian/Games/RhythmDoctor_linux/BepInEx/plugins/RDTweaks/" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\BepInEx.Analyzers.1.0.8\analyzers\dotnet\cs\BepInEx.Analyzers.CodeFixes.dll" />
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ Still a big work in progress!
## Features
- Skip to main menu, editor, or CLS on startup.
- Skip main menu logo.
- CLS level randomizer (default key: R).
- Skip to CLS library when entering.
- Scroll wheen in CLS!
- Configurable keybinds for changing editor UI scale.
- Scroll wheel in CLS!
- Hide mouse cursor while in game.
- Now works with [BepInEx Configuration Manager](https://github.com/BepInEx/BepInEx.ConfigurationManager)!

## TODO
Expand All @@ -30,7 +29,7 @@ Still a big work in progress!
4. Download the latest version of the mod from [here](https://github.com/huantianad/RDTweaks/releases). It should be named `RDTweaks vx.x.x.zip`.
5. Unzip the file you downloaded into your Rhythm Doctor installation folder. You should now have a file at `BepInEx/Plugins/RDTweaks/RDTweaks.dll`.
6. Launch the game, and configure the mod in `BepInEx/Config`.
7. Optional: Install the [BepInEx Configuration Manager](https://github.com/BepInEx/BepInEx.ConfigurationManager) to configure the mod with a GUI.
7. *Optional*: Install the [BepInEx Configuration Manager](https://github.com/BepInEx/BepInEx.ConfigurationManager) to configure the mod with a GUI.

For more information, check out the [BepInEx installation guide](https://docs.bepinex.dev/articles/user_guide/installation/index.html).

Expand Down

0 comments on commit b452eb4

Please sign in to comment.