Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.InteropServices;
- using System.Security.Permissions;
- using System.Threading;
- using System.Windows.Forms;
- using Reloaded.GameProcess;
- using Reloaded.GameProcess.CustomFunctionFactory;
- using Reloaded.GameProcess.Functions.CustomFunctionFactory;
- using Reloaded.Input;
- namespace Reloaded_Mod_Template
- {
- public static class Program
- {
- /*
- * Reloaded Mod Loader DLL Modification Template
- * Sewer56, 2018 ©
- *
- * -------------------------------------------------------------------------------
- *
- * Here starts your own mod loader DLL code.
- *
- * The Init function below is ran at the initialization stage of the game.
- *
- * The game at this point suspended and frozen in memory. There is no execution
- * of game code currently ongoing.
- *
- * This is where you do your hot-patches such as graphics stuff, patching the
- * window style of the game to borderless, setting up your initial variables, etc.
- *
- * -------------------------------------------------------------------------------
- *
- * Important Note:
- *
- * This function is executed once during startup and SHOULD return as the
- * mod loader awaits successful completion of the main function.
- *
- * If you want your mod/code to sit running in the background, please initialize
- * another thread and run your code in the background on that thread, otherwise
- * please remember to return from the function.
- *
- * There is also some extra code, including DLL stubs for Reloaded, classes
- * to interact with the Mod Loader Server as well as other various loader related
- * utilities available.
- *
- * -------------------------------------------------------------------------------
- *
- * Brief Walkthrough:
- *
- * > Reloaded/Initializer.cs
- * Stores Reloaded Mod Loader DLL Template/Initialization Code.
- * You are not required/should not (need) to modify any of the code.
- *
- * > Reloaded/Client.cs
- * Contains various pieces of code to interact with the mod loader server.
- *
- * For convenience it's recommended you import Client static(ally) into your
- * classes by doing it as such `Reloaded_Mod_Template.Reloaded_Code.Client`.
- *
- * This will avoid you typing the full class name and let you simply type
- * e.g. Print("SomeTextToConsole").
- *
- * Reloaded Wiki:
- * <TBA>
- *
- * -------------------------------------------------------------------------------
- *
- * If you like Reloaded, please consider giving a helping hand. This has been
- * my sole project taking up most of my free time for months. Being the programmer,
- * artist, tester, quality assurance, alongside various other roles is pretty hard
- * and time consuming, not to mention that I am doing all of this for free.
- *
- * Well, alas, see you when Reloaded releases.
- *
- * Please keep this notice here for future contributors or interested parties.
- * If it bothers you, consider wrapping it in a #region.
- */
- /// <summary>
- /// Holds the game process for us to manipulate.
- /// Allows you to read/write memory, perform pattern scans, etc.
- /// See libReloaded/GameProcess (folder)
- /// </summary>
- public static ReloadedProcess GameProcess;
- // Stub
- private static Thread controllerTestThread;
- private static ControllerManager controllerManager;
- /// <summary>
- /// [USERCALL] Function delegate to play a music track in Sanic Heroes.
- /// </summary>
- /// <param name="someObjectPointer">Wonder what that object is, it is the address at 0xA7784C</param>
- /// <param name="objectListPointer">Pointer to Heroes' object list, normally 0x007CFF90</param>
- /// <param name="stageNamePrefix">The prefix of the stage name e.g. s03, stg05.</param>
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate void LoadSETLayout(IntPtr someObjectPointer, IntPtr objectListPointer, [MarshalAs(UnmanagedType.LPStr)] string stageNamePrefix);
- // Define custom function.
- private static FunctionInformation loadSetFunctionInformation = new FunctionInformation()
- {
- returnRegister = FunctionInformation.TargetRegister.eax,
- sourceRegisters = new[] { FunctionInformation.TargetRegister.eax },
- stackCleanup = FunctionInformation.StackCleanup.Callee
- };
- /// <summary>
- /// Call this function to change the current music track.
- /// </summary>
- private static LoadSETLayout _loadSetLayoutFunction;
- private static IntPtr setGeneratorObjectPointer => (IntPtr)GameProcess.ReadMemorySafe<int>((IntPtr) 0xa7784c);
- /// <summary>
- /// Your own user code starts here.
- /// If this is your first time, do consider reading the notice above.
- /// It contains some very useful information.
- /// </summary>
- public static void Init()
- {
- // Initialize Controller Manager
- controllerManager = new ControllerManager();
- _loadSetLayoutFunction = Marshal.GetDelegateForFunctionPointer<LoadSETLayout>(FunctionWrapper.CreateWrapperFunction((IntPtr)0x43D080, loadSetFunctionInformation, typeof(LoadSETLayout)));
- // Thread test
- controllerTestThread = new Thread
- (
- () =>
- {
- while (true)
- {
- ControllerCommon.ControllerInputs inputs = controllerManager.GetInput(0);
- if (inputs.controllerButtons.Button_Back)
- {
- _loadSetLayoutFunction(setGeneratorObjectPointer, (IntPtr)0x7CFF90, "s01");
- while (inputs.controllerButtons.Button_Back)
- {
- inputs = controllerManager.GetInput(0);
- Thread.Sleep(16);
- }
- }
- Thread.Sleep(16);
- }
- }
- );
- controllerTestThread.Start();
- }
- }
- }
Add Comment
Please, Sign In to add comment