Skip to content

Commit

Permalink
Updated comments for the new get/set methods for MemoryManager
Browse files Browse the repository at this point in the history
  • Loading branch information
gurrenm3 committed Jun 28, 2022
1 parent 4b34b41 commit 5911549
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
68 changes: 41 additions & 27 deletions NoMansSky.Api/Extensions/MemoryManagerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Reloaded.ModHelper;
using System;
using System.Security.Cryptography;
using System.Threading.Tasks;

namespace NoMansSky.Api
Expand All @@ -13,14 +12,18 @@ public static class MemoryManagerExtensions
private static MemoryManagerCache cache = new MemoryManagerCache();

/// <summary>
/// Sets an object in memory at the provided address on a separate thread and returns when its done.
/// Use this for big objects so you don't lock the game.
/// <br/><br/>Takes a full path to the object you want to set.
/// <br/>Example: pathToValue = "GcPlayerGlobals.GroundRunSpeed"
/// Sets a value in memory at the provided path. Path must be the full location of the object you want
/// to set, separated by periods. Works on nested objects.
/// <br/>Example Path: "GcPlayerGlobals.GroundRunSpeed"
///
/// <br/><br/>Runs on a separate thread and returns when it's done.
/// It's recommended that you use this for bigger objects so you don't lock the game while
/// the value is being set.
/// <br/>Note: Since this runs on a separate thread it will not be synced with game loop.
/// </summary>
/// <param name="manager"></param>
/// <param name="pathToValue"></param>
/// <param name="valueToSet"></param>
/// <param name="pathToValue">The full path to the object you want to set, separated by periods.</param>
/// <param name="valueToSet">The value to be assigned to the provided path.</param>
/// <returns></returns>
public static async Task SetValueAsync(this MemoryManager manager, string pathToValue, object valueToSet)
{
Expand All @@ -32,12 +35,13 @@ public static async Task SetValueAsync(this MemoryManager manager, string pathTo
}

/// <summary>
/// Sets an object in memory at the provided address. Takes a full path to the object you want to set.
/// <br/>Example: pathToValue = "GcPlayerGlobals.GroundRunSpeed"
/// Sets a value in memory at the provided path. Path must be the full location of the object you want
/// to set, separated by periods. Works on nested objects.
/// <br/>Example Path: "GcPlayerGlobals.GroundRunSpeed"
/// </summary>
/// <param name="manager"></param>
/// <param name="pathToValue"></param>
/// <param name="valueToSet"></param>
/// <param name="pathToValue">The full path to the object you want to set, separated by periods.</param>
/// <param name="valueToSet">The value to be assigned to the provided path.</param>
public static void SetValue(this MemoryManager manager, string pathToValue, object valueToSet)
{
if (string.IsNullOrEmpty(pathToValue))
Expand All @@ -60,13 +64,17 @@ public static void SetValue(this MemoryManager manager, string pathToValue, obje


/// <summary>
/// Reads an object in memory on a separate thread and returns when its done.
/// Use this for big objects so you don't lock the game.
/// <br/><br/>Takes a full path to the object you want to set.
/// <br/>Example: pathToValue = "GcPlayerGlobals.GroundRunSpeed"
/// Returns the value that is stored in memory at the provided path. Path must be the full location
/// of the object you want to get, separated by periods. Works on nested objects.
/// <br/>Example Path: "GcPlayerGlobals.GroundRunSpeed"
///
/// <br/><br/>Runs on a separate thread and returns when it's done.
/// It's recommended that you use this for bigger objects so you don't lock the game while
/// the value is being retrieved.
/// <br/>Note: Since this runs on a separate thread it will not be synced with game loop.
/// </summary>
/// <param name="manager"></param>
/// <param name="pathToValue"></param>
/// <param name="pathToValue">The full path to the object you want to set, separated by periods.</param>
/// <returns></returns>
public static async Task<object> GetValueAsync(this MemoryManager manager, string pathToValue)
{
Expand All @@ -78,14 +86,18 @@ public static async Task<object> GetValueAsync(this MemoryManager manager, strin
}

/// <summary>
/// Reads an object in memory on a separate thread and returns when its done.
/// Use this for big objects so you don't lock the game.
/// <br/><br/>Takes a full path to the object you want to set.
/// <br/>Example: pathToValue = "GcPlayerGlobals.GroundRunSpeed"
/// Returns the value that is stored in memory at the provided path. Path must be the full location
/// of the object you want to get, separated by periods. Works on nested objects.
/// <br/>Example Path: "GcPlayerGlobals.GroundRunSpeed"
///
/// <br/><br/>Runs on a separate thread and returns when it's done.
/// It's recommended that you use this for bigger objects so you don't lock the game while
/// the value is being retrieved.
/// <br/>Note: Since this runs on a separate thread it will not be synced with game loop.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="manager"></param>
/// <param name="pathToValue"></param>
/// <param name="pathToValue">The full path to the object you want to set, separated by periods.</param>
/// <returns></returns>
public static async Task<T> GetValueAsync<T>(this MemoryManager manager, string pathToValue)
{
Expand All @@ -99,11 +111,12 @@ public static async Task<T> GetValueAsync<T>(this MemoryManager manager, string


/// <summary>
/// Reads an object in memory. Takes a full path to the object you want to set.
/// <br/>Example: pathToValue = "GcPlayerGlobals.GroundRunSpeed"
/// Returns the value that is stored in memory at the provided path. Path must be the full location
/// of the object you want to get, separated by periods. Works on nested objects.
/// <br/><br/>Example Path: "GcPlayerGlobals.GroundRunSpeed"
/// </summary>
/// <param name="manager"></param>
/// <param name="pathToValue"></param>
/// <param name="pathToValue">The full path to the object you want to set, separated by periods.</param>
/// <returns></returns>
public static object GetValue(this MemoryManager manager, string pathToValue)
{
Expand All @@ -119,12 +132,13 @@ public static object GetValue(this MemoryManager manager, string pathToValue)
}

/// <summary>
/// Reads an object in memory. Takes a full path to the object you want to set.
/// <br/>Example: pathToValue = "GcPlayerGlobals.GroundRunSpeed"
/// Returns the value that is stored in memory at the provided path. Path must be the full location
/// of the object you want to get, separated by periods. Works on nested objects.
/// <br/><br/>Example Path: "GcPlayerGlobals.GroundRunSpeed"
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="manager"></param>
/// <param name="pathToValue"></param>
/// <param name="pathToValue">The full path to the object you want to set, separated by periods.</param>
/// <returns></returns>
public static T GetValue<T>(this MemoryManager manager, string pathToValue)
{
Expand Down
1 change: 1 addition & 0 deletions NoMansSky.Api/Hooks/GameHooks/Game_Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void InitHook(IModLogger _logger, IReloadedHooks _hooks)
{
logger = _logger;

// Old pattern. Doesn't run on splash screen when game is starting. Replaced with new one below.
//string pattern = "40 53 48 83 EC 20 48 8D 4C 24 ? FF 15 ? ? ? ? 48 8B 5C 24 ? 48 8D 4C 24 ? FF 15 ? ? ? ? F2";
string pattern = "41 56 48 83 EC 60 48 8B 41 58";
Function = _hooks.CreateFunction<HookDelegate>(new Signature(pattern).Scan());
Expand Down
6 changes: 5 additions & 1 deletion NoMansSky.Api/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ private void PrintInventory()
long playerGlobalsAddress = 0;
public async override void Update()
{

if (Keyboard.IsPressed(Key.UpArrow))
{
var mem = new MemoryManager();
int value = mem.GetValue(0);
}
}

internal static void WriteLine(string message) => Instance?.Logger?.WriteLine(message);
Expand Down

0 comments on commit 5911549

Please sign in to comment.