So this code is definitely wrong I want to modify the method in dnspy from this public…
- User
So this code is definitely wrong
I want to modify the method in dnspy from this
public void JumpValue() { this.Jump(7.55f, false); }
To
public void JumpValue() { this.Jump(16.55f, false); }
Here's the code could u fix it
using HarmonyLib; using SFD; using System.Reflection;
namespace SuperFightersDeluxeCustomJump { public class EntryPoint { public static void Init() { var harmony = new Harmony("com.yourname.superfightersdeluxe.customjump"); harmony.PatchAll(Assembly.GetExecutingAssembly()); } }
[HarmonyPatch(typeof(SFD.Player))] public class PlayerJumpPatch { [HarmonyPostfix] [HarmonyPatch("Jump")] public static void PostfixJump(SFD.Player __instance) { // Modify the jump power and other parameters here MethodInfo jumpWithValueMethod = typeof(SFD.Player).GetMethod("JumpValue", BindingFlags.Public | BindingFlags.Instance); if (jumpWithValueMethod != null) { jumpWithValueMethod.Invoke(__instance, null); } // Assuming JumpPower is a private method, use reflection to invoke it. MethodInfo jumpPowerMethod = typeof(SFD.Player).GetMethod("JumpPower", BindingFlags.NonPublic | BindingFlags.Instance); if (jumpPowerMethod != null) { jumpPowerMethod.Invoke(__instance, new object[] { 16.55f, false }); } } }}
- Assistant
The code you provided seems to be aimed at patching a method using Harmony. However, the patching is done incorrectly because it attempts to invoke methods (
JumpValueandJumpPower) that do not appear to directly set the jump value. Instead, you would want to find and patch the method that assigns the jump value (in your case, it seems likeJumpValuemethod you would like to change).To set the jump power to
16.55fwhenever theJumpValuemethod is called, you could patch theJumpValuemethod directly and change the argument it uses when callingJump. The relevant part in your code is thePlayerJumpPatchclass, which currently doesn't do anything meaningful.Here's the revised version of the
PlayerJumpPatchclass that should correctly change the jump power to16.55f:using HarmonyLib; using SFD; // Assuming SFD.Player is the correct namespace for the Player class namespace SuperFightersDeluxeCustomJump { [HarmonyPatch(typeof(SFD.Player))] public static class PlayerJumpPatch { // This HarmonyPrefix will replace the original JumpValue method call. [HarmonyPrefix] [HarmonyPatch("JumpValue")] public static bool PrefixJumpValue(SFD.Player __instance) { // Call the original method with the modified parameter. __instance.Jump(16.55f, false); // Return false to prevent the original JumpValue method from running after this return false; } } }What this code does is apply a prefix patch to the
JumpValuemethod of theSFD.Playerclass. WhenJumpValueis called, the patched method runs instead, which callsJumpwith your desired value (16.55f) and returnsfalseto prevent the originalJumpValuemethod from executing.Please make sure that Harmony is properly set up in your project, and you've correctly initialized your Harmony instance as shown in your provided
EntryPoint.Initmethod. Harmony needs to be initialized before you can patch. You would generally call theInitmethod from somewhere early in your program's lifecycle, like at startup.Additionally, be aware that patching methods with Harmony can be sensitive to changes in the target application. If the
SFD.Playerclass or theJumpValuemethod definition changes in future versions of the application, your patch may need to be updated. - User
When I injected into my game the claslibrary.dll it still didnt change the jump value after jumping. How can I troubleshoot this issue, could you add debugging to see if it finds the method find, if it is accessible and if it really changes?
I've seen .dll injected through process explorer so the problem isnt the injector
- Assistant
Certainly, adding some basic logging can help you troubleshoot the issue. Assuming the game doesn't already have a logging system that you can hook into, you could use simple console writing or file writing for debugging purposes.
Here's how you could add some basic debugging by writing to a file to check whether your patch is being applied and identify any potential issues:
using HarmonyLib; using SFD; // Assuming SFD.Player is the correct namespace for the Player class using System; using System.IO; namespace SuperFightersDeluxeCustomJump { [HarmonyPatch(typeof(SFD.Player))] public static class PlayerJumpPatch { // This HarmonyPrefix will replace the original JumpValue method call. [HarmonyPrefix] [HarmonyPatch("JumpValue")] public static bool PrefixJumpValue(SFD.Player __instance) { try { DebugLog("Attempting to patch the JumpValue method..."); // Call the original method with the modified parameter. __instance.Jump(16.55f, false); DebugLog("Successfully patched JumpValue with new jump value 16.55f"); // Return false to prevent the original JumpValue method from running after this return false; } catch (Exception ex) { DebugLog($"Error while patching JumpValue method: {ex}"); throw; } } private static void DebugLog(string message) { // Choose a log file path that you have write access to string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "SuperFightersDeluxeCustomJump.log"); try { File.AppendAllText(logPath, $"{DateTime.Now}: {message}{Environment.NewLine}"); } catch (Exception ex) { // If for some reason writing to the file fails, you could consider // using a different method of logging (e.g., to a different location or using a MessageBox) } } } }This will append debug messages to a log file on your desktop (if it has permission to do so). Replace
Environment.SpecialFolder.Desktopwith a different folder if the desktop isn't suitable.Once you've added the debug logging, attempt to run your game and perform the action that triggers the
JumpValuemethod. After that, check the log file for any entries. If there are no entries at all, your patch may not have been applied. Make sure that yourInitmethod is getting called on application startup.If the patching logic is running but the jump height isn't changing, then the issue may lie elsewhere. Possible reasons might include:
- The application immediately overwrites the value set in the patched method.
- Another method or property is affecting jump height after your patch.
- There could be a condition somewhere else in the code that limits the application's jump height, regardless of what you set.
Ensure you understand the game's code well enough to identify if there are additional constraints you need to address. If you're still having trouble, you might need a more detailed understanding of the execution flow, which could involve attaching a debugger to the game's process and stepping through the code to see what is happening after you change the jump value. However, this level of debugging should generally be done by someone with permission to modify the game, as it could violate terms of service or user agreements.