working with rope storage and hazard res
Some checks are pending
build / build (push) Waiting to run

This commit is contained in:
Sakimori 2025-04-18 02:54:24 -04:00
parent c3ec0dfa0a
commit c7b223c993
6 changed files with 52 additions and 103 deletions

View file

@ -1,81 +0,0 @@
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using NineSolsAPI;
using System;
using UnityEngine;
namespace GlitchRestore;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class ExampleMod : BaseUnityPlugin {
// https://docs.bepinex.dev/articles/dev_guide/plugin_tutorial/4_configuration.html
private ConfigEntry<bool> enableSomethingConfig = null!;
private ConfigEntry<KeyboardShortcut> somethingKeyboardShortcut = null!;
private Harmony harmony = null!;
[HarmonyPatch(typeof(PlayerHurtState), nameof(PlayerHurtState.OnStateEnter))]
internal static class RopeRestore {
private static void Prefix(Player ___player, out ClimbableRope __state) {
__state = ___player.touchingRope;
}
private static void Postfix(ClimbableRope __state, ref Player ___player) {
if (__state != null) {
___player.touchingRope = __state;
}
}
}
//[HarmonyPatch(typeof(EffectDealer), nameof(EffectDealer.HitEffectSensorExitCheck))]
//internal static class DamageRespawnRestore {
//I think it's in EffectDealer but I'm not sure
//}
private void Awake() {
Log.Init(Logger);
RCGLifeCycle.DontDestroyForever(gameObject);
// Load patches from any class annotated with @HarmonyPatch
harmony = Harmony.CreateAndPatchAll(typeof(ExampleMod).Assembly);
enableSomethingConfig = Config.Bind("General.Something", "Enable", true, "Enable the thing");
somethingKeyboardShortcut = Config.Bind("General.Something", "Shortcut",
new KeyboardShortcut(KeyCode.H, KeyCode.LeftControl), "Shortcut to execute");
// Usage of the modding API is entirely optional.
// It provides utilities like the KeybindManager, utilities for Instantiating objects including the
// NineSols lifecycle hooks, displaying toast messages and preloading objects from other scenes.
// If you do use the API make sure do have it installed when running your mod, and keep the dependency in the
// thunderstore.toml.
KeybindManager.Add(this, TestMethod, () => somethingKeyboardShortcut.Value);
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
}
// Some fields are private and need to be accessed via reflection.
// You can do this with `typeof(Player).GetField("_hasHat", BindingFlags.Instance|BindingFlags.NonPublic).GetValue(Player.i)`
// or using harmony access tools:
private static readonly AccessTools.FieldRef<Player, bool>
PlayerHasHat = AccessTools.FieldRefAccess<Player, bool>("_hasHat");
private void TestMethod() {
if (!enableSomethingConfig.Value) return;
ToastManager.Toast("Shortcut activated");
Log.Info("Log messages will only show up in the logging console and LogOutput.txt");
// Sometimes variables aren't set in the title screen. Make sure to check for null to prevent crashes.
if (Player.i == null) return;
var hasHat = PlayerHasHat.Invoke(Player.i);
Player.i.SetHasHat(!hasHat);
}
private void OnDestroy() {
// Make sure to clean up resources here to support hot reloading
harmony.UnpatchSelf();
}
}

View file

@ -1,19 +0,0 @@
using HarmonyLib;
namespace ExampleMod;
[HarmonyPatch]
public class Patches {
// Patches are powerful. They can hook into other methods, prevent them from runnning,
// change parameters and inject custom code.
// Make sure to use them only when necessary and keep compatibility with other mods in mind.
// Documentation on how to patch can be found in the harmony docs: https://harmony.pardeike.net/articles/patching.html
[HarmonyPatch(typeof(Player), nameof(Player.SetStoryWalk))]
[HarmonyPrefix]
private static bool PatchStoryWalk(ref float walkModifier) {
walkModifier = 1.0f;
return true; // the original method should be executed
}
}

50
Source/Plugin.cs Normal file
View file

@ -0,0 +1,50 @@
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
namespace GlitchRestore;
[BepInPlugin("com.kobold60.glitchrestore", "Glitch Restore", "0.1.0")]
public class Plugin : BaseUnityPlugin {
private Harmony harmony = null!;
[HarmonyPatch(typeof(PlayerHurtState), nameof(PlayerHurtState.OnStateEnter))]
internal static class RopeRestore {
private static void Prefix(Player ___player, out ClimbableRope __state) {
__state = ___player.touchingRope;
}
private static void Postfix(ClimbableRope __state, ref Player ___player) {
if (__state != null) {
___player.touchingRope = __state;
}
}
}
[HarmonyPatch(typeof(Player), "OnTakeInvincibleHit")]
internal static class DamageRespawnRestore {
private static bool Prefix(DamageDealer damageDealer, Player __instance) {
if (__instance.IsCurrentState(PlayerStateType.Roll) && !damageDealer.parriable) {
DamageType type = damageDealer.type;
}
return false;
}
}
private void Awake() {
Log.Init(Logger);
RCGLifeCycle.DontDestroyForever(gameObject);
// Load patches from any class annotated with @HarmonyPatch
harmony = Harmony.CreateAndPatchAll(typeof(Plugin).Assembly);
Logger.LogInfo($"Plugin com.kobold60.glitchrestore is loaded!");
}
private void OnDestroy() {
// Make sure to clean up resources here to support hot reloading
harmony.UnpatchSelf();
}
}

View file

@ -1,4 +1,3 @@
# Nine Sols Example Mod
# Glitch Restore
Write a description of your mod here, it will be displayed on thunderstore.
Remember to update the icon.png to something representing your mod.
Re-implements rope storage and hazard respawn glitches from the speedrun patch. Piss skip currently doesn't work, but early city access does.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 13 KiB