Appearance
question:Ok so the code gives me no errors but upon building the solution it gives me an injector.dll Isn't it suppost to give me an injector.exe instead? using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Text; class Program { [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId); [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetProcAddress(IntPtr hModule, string procName); [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetModuleHandle(string lpModuleName); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool CloseHandle(IntPtr hObject); [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten); [DllImport("kernel32.dll")] public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttribute, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId); // P/Invoke constants const uint MEM_COMMIT = 0x00001000; const uint PAGE_READWRITE = 0x04; const uint PAGE_EXECUTE_READWRITE = 0x40; const uint PROCESS_ALL_ACCESS = 0x1F0FFF; static void Main(string[] args) { string dllPath = @"C:UsersNinjasourcereposClassLibrary1ClassLibrary1binReleasenetstandard2.1ClassLibrary1.dll"; // Replace with the actual path to your DLL // Get the process to inject into Process targetProcess = Process.GetProcessesByName("Superfighters Deluxe")[0]; if (targetProcess == null) { Console.WriteLine("Superfighters Deluxe process not found!"); return; } // Allocate memory within the process for our DLL path IntPtr procHandle = OpenProcess(PROCESS_ALL_ACCESS, false, targetProcess.Id); IntPtr loadLibraryAddr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA"); IntPtr allocMemAddress = VirtualAllocEx(procHandle, IntPtr.Zero, (uint)((dllPath.Length + 1) * Marshal.SizeOf(typeof(char))), MEM_COMMIT | PAGE_READWRITE, PAGE_READWRITE); // Write the path to our DLL in the allocated memory byte[] dllBytes = Encoding.UTF8.GetBytes(dllPath); bool result = WriteProcessMemory(procHandle, allocMemAddress, dllBytes, (uint)dllBytes.Length, out _); // Create a remote thread that calls LoadLibrary with our DLL path argument if (result) { CreateRemoteThread(procHandle, IntPtr.Zero, 0, loadLibraryAddr, allocMemAddress, 0, IntPtr.Zero); } CloseHandle(procHandle); } }
answer:The problem here might be related to your project setup. If your Visual Studio project is set up as a Class Library, it will output a DLL file since that's the default output for such a project type. To create an executable (EXE), you will need to set up your project as a Console App or a Windows Forms App. Here's what you should do: 1. Open Visual Studio. 2. Create a new project. 3. Choose "Console App" or "Windows Forms App" (depending on your preference) from the list of project templates. 4. Ensure the output type is set to "Console Application" or "Windows Application" in the project properties if you're creating a Windows Forms App. 5. Add the code provided to the `Program.cs` or whichever file is the entry point for your application. To check or change the output type of your existing project: 1. Right-click on the project in Solution Explorer. 2. Click on "Properties." 3. Navigate to the "Application" tab. 4. Under Output type, choose either "Console Application" or "Windows Application" from the dropdown menu. 5. Save the properties. Once you've changed the output type to an application, rebuilding the project should produce an EXE file instead of a DLL. The rest of the operation remains the same, and upon running the newly created EXE, it should attempt to inject the `ClassLibrary1.dll` into the running `Superfighters Deluxe` process. Remember to always run such tools as an administrator, especially when dealing with process manipulation functions, to ensure they have the necessary permissions to perform their tasks.
question:So it seems that it didnt change anything on the game when executing the injector. when it was suppost to change the method in runtime and for me to jump higher heres the classlibrary1.dll using System; using HarmonyLib; using SFD; using SFD.GameKeyboard; using SFDGameScriptInterface; using System.Reflection; public class CustomPlayer { private Player player; public float AimSpeed { get; set; } = 0.1f; internal PlayerVirtualKeyboard? VirtualKeyboard { get; set; } public bool ImportantUpdate { get; set; } public CustomPlayer(Player player) { this.player = player; VirtualKeyboard = null; // or initialize with an actual value // Initialize Harmony in your constructor or another initialization method Harmony harmony = new Harmony("com.example.mygame.mod"); harmony.PatchAll(Assembly.GetExecutingAssembly()); // This will apply all patches in this assembly } public void AimUp() { if (VirtualKeyboard != null) { // Perform your logic using VirtualKeyboard if (AimSpeed >= 0f) { AimSpeed = 1f; // Set AimSpeed value to 0.1 } if (VirtualKeyboard.PressingKey(21, false)) { AimSpeed += 1f; // Increase AimSpeed value by 0.01 } else { AimSpeed -= 1f; // Decrease AimSpeed value by 0.01 } ImportantUpdate = true; } // Handle the case where VirtualKeyboard is null if needed } public void Jump(float jumpPower, bool keepRolling) { } // Override the parameterless Jump method public void Jump() { // Call your customized Jump method with specific arguments this.Jump(17.55f, false); } } [HarmonyPatch(typeof(Player))] [HarmonyPatch("Jump")] internal class JumpPatch { private static MethodBase JumpOriginal = AccessTools.Method(typeof(Player), "Jump", new Type[] { typeof(float), typeof(bool) }); // Prefix method to be executed before the original Jump method public static bool Prefix(Player __instance) { // Your modified Jump logic here JumpOriginal.Invoke(__instance, new object[] { 17.55f, false }); // Return false to prevent the original Jump from running return false; } } Heres the injector.exe using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Text; class Program { [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId); [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetProcAddress(IntPtr hModule, string procName); [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetModuleHandle(string lpModuleName); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool CloseHandle(IntPtr hObject); [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten); [DllImport("kernel32.dll")] public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttribute, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId); // P/Invoke constants const uint MEM_COMMIT = 0x00001000; const uint PAGE_READWRITE = 0x04; const uint PAGE_EXECUTE_READWRITE = 0x40; const uint PROCESS_ALL_ACCESS = 0x1F0FFF; static void Main(string[] args) { string dllPath = @"C:UsersNinjaDownloadsidkClassLibrary1.dll"; // Replace with the actual path to your DLL // Get the process to inject into Process targetProcess = Process.GetProcessesByName("Superfighters Deluxe")[0]; if (targetProcess == null) { Console.WriteLine("Superfighters Deluxe process not found!"); return; } // Allocate memory within the process for our DLL path IntPtr procHandle = OpenProcess(PROCESS_ALL_ACCESS, false, targetProcess.Id); IntPtr loadLibraryAddr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA"); IntPtr allocMemAddress = VirtualAllocEx(procHandle, IntPtr.Zero, (uint)((dllPath.Length + 1) * Marshal.SizeOf(typeof(char))), MEM_COMMIT | PAGE_READWRITE, PAGE_READWRITE); // Write the path to our DLL in the allocated memory byte[] dllBytes = Encoding.UTF8.GetBytes(dllPath); bool result = WriteProcessMemory(procHandle, allocMemAddress, dllBytes, (uint)dllBytes.Length, out _); // Create a remote thread that calls LoadLibrary with our DLL path argument if (result) { CreateRemoteThread(procHandle, IntPtr.Zero, 0, loadLibraryAddr, allocMemAddress, 0, IntPtr.Zero); } CloseHandle(procHandle); } } And here's a raw text of Player.cs https://raw.githubusercontent.com/howque/fsaf/main/Player.cs
answer:The issue you are encountering could be related to several different things such as: 1. **Injection Method**: The injection might not be successful. CreateRemoteThread and LoadLibrary are commonly used methods but not always reliable for every situation. Also, you may need to run the injector as an administrator for it to work. 2. **Harmony Patching**: Harmony is complex, and proper use requires a detailed understanding of both the library you are trying to patch and Harmony itself. It's also possible that the game code you are trying to patch has been obfuscated or altered in a way that makes it incompatible with Harmony's normal workings. 3. **Matching Game Assembly Version**: Your patch library needs to be compiled against the same version of the assembly used by the game, or it might not work due to version differences. 4. **Game Updates**: If the game has been updated since the source you have was extracted, offsets and methods may have changed, making your patches fail to apply correctly. 5. **Typo or Naming Issue**: You must ensure all method names, class names, and namespaces exactly match those in the game. For example, if the game class is `SFD.Player` but you patch `Player`, then the patch won't apply without the correct namespace. 6. **DLL Compatibility**: If you compiled your `ClassLibrary1.dll` as `.NET Standard 2.1`, it might have compatibility issues if the game doesn't run on a compatible runtime. You would generally ensure the compiled library matches the target framework of the game. Without investigating the specific details, it's difficult to provide more precise guidance. However, I can give you some generic debugging steps: - Confirm that the `dllPath` is correct and that the injector is executing without any exceptions. - Make sure that the game's `Player` class and `Jump` method signatures match what you are using in your Harmony patch. - Check the process name is correct. You use `"Superfighters Deluxe"` in your injection code, which may not be the correct process name. You should verify this in the Task Manager. - Make sure that your `Harmony` patch is activated at the right time. Consider adding logging to see if your patch code is executed. - Verify that the game uses managed code that is compatible with the .NET version you are targeting. Harmony works with .NET Framework, .NET Core, and Mono-based games but not with games that don't use managed code (e.g., written in C++). - Use Debugging Tools: Employ a debugger to step through your injection code and ensure that each step (memory allocation, writing, remote thread creation) completes without error. Please be aware that my role as an AI is to provide information, but I cannot condone or assist in activities that may violate terms of service for software or games, which can include unauthorized modification of game code. The guidance provided here is for educational purposes and should only be used in a manner consistent with the game's terms of service and applicable laws. Remember that even if a game doesn't have cheat protection, unauthorized modification might still be against its terms of use. Always respect the rights and work of software developers.
question:When executing the injector.exe I can see the game frozen for like 2 seconds. That means that it's injecting correctly right? Maybe the problem is inside classlibrary1.dll and it's not overwriting the Jump() method?
answer:The game freezing momentarily could indicate that your injection is taking place, as the game may be momentarily affected by the injection process. However, this isn't a definite confirmation that the injection is successful or that it's having the desired effect. If the game doesn't behave as expected after the injection, it's possible that the patch isn't being applied correctly. Here are some potential reasons and steps to consider: # Check Harmony Patching Ensure that your Harmony patch correctly targets the method you're trying to patch. The target method's signature must match exactly. If there's any discrepancy, your patch will not be applied. # Verify Patch Application You can verify if your patch has been applied by using Harmony's debug features. Harmony can report on what patches are currently active. Implement logging to check if Harmony is patching the expected methods. # Use Debug Logging Add debug logging to your `ClassLibrary1.dll` to see if the constructor for `CustomPlayer` gets called and if `Harmony.PatchAll` runs without errors. Use `File.AppendAllText` to write log entries to a text file, which can help you determine if your code is running: ```csharp public CustomPlayer(Player player) { File.AppendAllText("C:path_to_log_filelog.txt", "CustomPlayer constructor called.n"); this.player = player; Harmony harmony = new Harmony("com.example.mygame.mod"); harmony.PatchAll(Assembly.GetExecutingAssembly()); File.AppendAllText("C:path_to_log_filelog.txt", "Harmony patching completed.n"); } ``` # Compatibility with Game's .NET Version Ensure that your `ClassLibrary1.dll` is compiled against the same .NET version that the game uses. If there's a mismatch, that could cause problems. # Timing of Patch Application Consider when your patch is being applied. The game might be initializing certain things at launch that are affected by your patch. Look into when your DLL is being loaded and when the patches are applied relative to the game's lifecycle. # Game's Anti-Cheat or Protection Mechanisms Even though you mentioned that the game doesn't have anti-cheat or protected code, it's crucial to double-check this. Some games have hidden or non-obvious protection mechanisms that might be preventing your changes from taking effect. # Confirm DLL Loading To ensure your DLL is being loaded, you can use a tool like Process Explorer or Process Hacker to see if your DLL shows up in the list of modules for the game process after injection. # Evaluate Game Behavior It's also possible that the game has internal checks or resets values in ways that might negate the effect of your patch. This wouldn't necessarily prevent injection but could overwrite or bypass your modifications. Ultimately, debugging this is a step-by-step process. Ensure each part of your system works independently before putting them all together. If after all your checks, the method still isn't being patched as expected, you might need to further investigate how Harmony works with the game's specific .NET runtime version and execution environment, as well as the order in which the game loads its assemblies and initializes its classes.
question:I am using .net framework 2.1 and the game uses .net framework 4.5? Maybe that's the problem? Look // C:UsersNinjaDownloadsReferencesSuperfighters Deluxe.exe // Superfighters Deluxe, Version=1.0.8107.30539, Culture=neutral, PublicKeyToken=b7212d0512a3740a // Entry point: SFD.Program.Main // Timestamp: 622E1486 (13/03/2022 15:57:58) using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; [assembly: AssemblyVersion("1.0.8107.30539")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")] [assembly: AssemblyTitle("Superfighters Deluxe")] [assembly: AssemblyProduct("Superfighters Deluxe")] [assembly: AssemblyDescription("Superfighters Deluxe")] [assembly: AssemblyCompany("MythoLogic Interactive")] [assembly: AssemblyCopyright("Copyright © MythoLogic Interactive 2011-2018")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("88e511ad-fb20-4af8-a543-7a8b3320b1be")]
answer:Yes, the mismatch in .NET Framework versions is very likely the issue. Your `ClassLibrary1.dll` is targeting .NET Standard 2.1, which is not directly compatible with the .NET Framework 4.5 that the game is using. To create a compatible DLL, you need to target the same version of .NET Framework that the game uses, or at least a version that is compatible with it. To fix this issue: 1. Open your `ClassLibrary1` project in Visual Studio. 2. Right-click on the project in the Solution Explorer, and select Properties. 3. Go to the Application tab. 4. In the Target Framework dropdown, select `.NET Framework 4.5` or another compatible version that is as close as possible to the one used by the game. 5. Save these project properties and recompile your DLL. Once you've done that, your DLL should be compatible with the game's .NET Framework version and your Harmony patches have a better chance of being applied correctly. Recompile `ClassLibrary1.dll` with the correct target framework, and then try injecting it into the game process again using your injector. If the previously observed freeze still occurs, then it's likely that your DLL is being loaded, but now it should also be able to apply your modifications properly. Remember to make sure that your injector is run with administrative privileges so that it has the necessary permissions to inject into another process. If you continue to experience issues, revisit the other steps outlined in my previous responses for debugging your injection process and verifying that the correct methods are being patched.