sewer56lol

Reloaded Test Program: Heroes Live SET Reload

Apr 3rd, 2018
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.68 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Security.Permissions;
  4. using System.Threading;
  5. using System.Windows.Forms;
  6. using Reloaded.GameProcess;
  7. using Reloaded.GameProcess.CustomFunctionFactory;
  8. using Reloaded.GameProcess.Functions.CustomFunctionFactory;
  9. using Reloaded.Input;
  10.  
  11. namespace Reloaded_Mod_Template
  12. {
  13.     public static class Program
  14.     {
  15.         /*
  16.          *  Reloaded Mod Loader DLL Modification Template
  17.          *  Sewer56, 2018 ©
  18.          *
  19.          *  -------------------------------------------------------------------------------
  20.          *
  21.          *  Here starts your own mod loader DLL code.
  22.          *
  23.          *  The Init function below is ran at the initialization stage of the game.
  24.          *
  25.          *  The game at this point suspended and frozen in memory. There is no execution
  26.          *  of game code currently ongoing.
  27.          *
  28.          *  This is where you do your hot-patches such as graphics stuff, patching the
  29.          *  window style of the game to borderless, setting up your initial variables, etc.
  30.          *
  31.          *  -------------------------------------------------------------------------------
  32.          *
  33.          *  Important Note:
  34.          *
  35.          *  This function is executed once during startup and SHOULD return as the
  36.          *  mod loader awaits successful completion of the main function.
  37.          *
  38.          *  If you want your mod/code to sit running in the background, please initialize
  39.          *  another thread and run your code in the background on that thread, otherwise
  40.          *  please remember to return from the function.
  41.          *
  42.          *  There is also some extra code, including DLL stubs for Reloaded, classes
  43.          *  to interact with the Mod Loader Server as well as other various loader related
  44.          *  utilities available.
  45.          *
  46.          *  -------------------------------------------------------------------------------
  47.          *
  48.          *  Brief Walkthrough:
  49.          *
  50.          *  > Reloaded/Initializer.cs
  51.          *      Stores Reloaded Mod Loader DLL Template/Initialization Code.
  52.          *      You are not required/should not (need) to modify any of the code.
  53.          *
  54.          *  > Reloaded/Client.cs
  55.          *      Contains various pieces of code to interact with the mod loader server.
  56.          *
  57.          *      For convenience it's recommended you import Client static(ally) into your
  58.          *      classes by doing it as such `Reloaded_Mod_Template.Reloaded_Code.Client`.
  59.          *
  60.          *      This will avoid you typing the full class name and let you simply type
  61.          *      e.g. Print("SomeTextToConsole").
  62.          *
  63.          *  Reloaded Wiki:
  64.          *      <TBA>
  65.          *
  66.          *  -------------------------------------------------------------------------------
  67.          *
  68.          *  If you like Reloaded, please consider giving a helping hand. This has been
  69.          *  my sole project taking up most of my free time for months. Being the programmer,
  70.          *  artist, tester, quality assurance, alongside various other roles is pretty hard
  71.          *  and time consuming, not to mention that I am doing all of this for free.
  72.          *
  73.          *  Well, alas, see you when Reloaded releases.
  74.          *
  75.          *  Please keep this notice here for future contributors or interested parties.
  76.          *  If it bothers you, consider wrapping it in a #region.
  77.         */
  78.  
  79.         /// <summary>
  80.         /// Holds the game process for us to manipulate.
  81.         /// Allows you to read/write memory, perform pattern scans, etc.
  82.         /// See libReloaded/GameProcess (folder)
  83.         /// </summary>
  84.         public static ReloadedProcess GameProcess;
  85.  
  86.  
  87.         // Stub
  88.         private static Thread controllerTestThread;
  89.         private static ControllerManager controllerManager;
  90.  
  91.         /// <summary>
  92.         /// [USERCALL] Function delegate to play a music track in Sanic Heroes.
  93.         /// </summary>
  94.         /// <param name="someObjectPointer">Wonder what that object is, it is the address at 0xA7784C</param>
  95.         /// <param name="objectListPointer">Pointer to Heroes' object list, normally 0x007CFF90</param>
  96.         /// <param name="stageNamePrefix">The prefix of the stage name e.g. s03, stg05.</param>
  97.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  98.         public delegate void LoadSETLayout(IntPtr someObjectPointer, IntPtr objectListPointer, [MarshalAs(UnmanagedType.LPStr)] string stageNamePrefix);
  99.  
  100.         // Define custom function.
  101.         private static FunctionInformation loadSetFunctionInformation = new FunctionInformation()
  102.         {
  103.             returnRegister = FunctionInformation.TargetRegister.eax,
  104.             sourceRegisters = new[] { FunctionInformation.TargetRegister.eax },
  105.             stackCleanup = FunctionInformation.StackCleanup.Callee
  106.         };
  107.  
  108.         /// <summary>
  109.         /// Call this function to change the current music track.
  110.         /// </summary>
  111.         private static LoadSETLayout _loadSetLayoutFunction;
  112.         private static IntPtr setGeneratorObjectPointer => (IntPtr)GameProcess.ReadMemorySafe<int>((IntPtr) 0xa7784c);
  113.  
  114.         /// <summary>
  115.         /// Your own user code starts here.
  116.         /// If this is your first time, do consider reading the notice above.
  117.         /// It contains some very useful information.
  118.         /// </summary>
  119.         public static void Init()
  120.         {
  121.             // Initialize Controller Manager
  122.             controllerManager = new ControllerManager();
  123.             _loadSetLayoutFunction = Marshal.GetDelegateForFunctionPointer<LoadSETLayout>(FunctionWrapper.CreateWrapperFunction((IntPtr)0x43D080, loadSetFunctionInformation, typeof(LoadSETLayout)));
  124.  
  125.             // Thread test
  126.             controllerTestThread = new Thread
  127.             (
  128.                 () =>
  129.                 {
  130.                    
  131.                     while (true)
  132.                     {
  133.                         ControllerCommon.ControllerInputs inputs = controllerManager.GetInput(0);
  134.  
  135.                         if (inputs.controllerButtons.Button_Back)
  136.                         {
  137.                             _loadSetLayoutFunction(setGeneratorObjectPointer, (IntPtr)0x7CFF90, "s01");
  138.                             while (inputs.controllerButtons.Button_Back)
  139.                             {
  140.                                 inputs = controllerManager.GetInput(0);
  141.                                 Thread.Sleep(16);
  142.                             }
  143.                         }
  144.  
  145.                         Thread.Sleep(16);
  146.                     }
  147.                    
  148.                 }  
  149.             );
  150.             controllerTestThread.Start();
  151.         }
  152.     }
  153. }
Add Comment
Please, Sign In to add comment