Skip to content

Commit

Permalink
updated for Coordinates-Grabber 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Feb 21, 2021
1 parent c9697d6 commit 6c2aff1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: MelonInfo(typeof(KeyboardUtilities.Implementation), "KeyboardUtilities", "1.1.0", "Sinai, ds5678")]
[assembly: AssemblyVersion("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: MelonInfo(typeof(KeyboardUtilities.Implementation), "KeyboardUtilities", "1.2.0", "Sinai, ds5678")]
[assembly: MelonGame("Hinterland", "TheLongDark")]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# Keyboard Utilities

> Disclaimer: Almost all of the code in this project comes from the [Unity Explorer](https://github.com/sinai-dev/UnityExplorer) project by [Sinai](https://github.com/sinai-dev).
> Disclaimer:
This is a utility mod for *The Long Dark* that enables other mods to more easily use Keyboard input.

## Special Thanks

I greatly appreciate the work [Sinai](https://github.com/sinai-dev) has done. Most of the code in this project comes from his [Unity Explorer](https://github.com/sinai-dev/UnityExplorer) project. I adapted the code for use with modding The Long Dark and added my own additional funcionality, but none of it would have been possible without [Unity Explorer](https://github.com/sinai-dev/UnityExplorer).

## [Patreon](https://www.patreon.com/ds5678)

I know many people might skip over this, but I hope you don't. You are so special, and I would appreciate your support. Modding takes lots of time, and I have expenses like food, internet, and rent. If you feel that I have improved your playing experience, please consider supporting me on my [Patreon](https://www.patreon.com/ds5678). Your support helps to ensure that I can continue making mods for you at the pace I am :)

## Installation

1. If you haven't done so already, install MelonLoader by downloading and running [MelonLoader.Installer.exe](https://github.com/HerpDerpinstine/MelonLoader/releases/latest/download/MelonLoader.Installer.exe).
Expand Down
2 changes: 2 additions & 0 deletions src/IHandleInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface IHandleInput
{
Vector2 MousePosition { get; }

Vector2 MouseScrollDelta { get; }

bool GetKeyDown(KeyCode key);
bool GetKey(KeyCode key);

Expand Down
1 change: 1 addition & 0 deletions src/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class InputManager
private static IHandleInput m_inputModule;

public static Vector3 MousePosition => m_inputModule.MousePosition;
public static Vector2 MouseScrollDelta => m_inputModule.MouseScrollDelta;

public static bool GetKeyDown(KeyCode key) => m_inputModule.GetKeyDown(key);
public static bool GetKey(KeyCode key) => m_inputModule.GetKey(key);
Expand Down
20 changes: 20 additions & 0 deletions src/InputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public InputSystem()
m_leftButtonProp = TMouse.GetProperty("leftButton");
m_rightButtonProp = TMouse.GetProperty("rightButton");
m_middleButtonProp = TMouse.GetProperty("middleButton");
m_scrollProp = TMouse.GetProperty("scroll");

m_positionProp = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Pointer")
.GetProperty("position");
Expand Down Expand Up @@ -70,6 +71,10 @@ public InputSystem()
private static object m_mmb;
private static PropertyInfo m_middleButtonProp;

private static object MouseScrollInfo => m_scroll ?? (m_scroll = m_scrollProp.GetValue(CurrentMouse, null));
private static object m_scroll;
private static PropertyInfo m_scrollProp;

private static object MousePositionInfo => m_pos ?? (m_pos = m_positionProp.GetValue(CurrentMouse, null));
private static object m_pos;
private static PropertyInfo m_positionProp;
Expand All @@ -90,6 +95,21 @@ public Vector2 MousePosition
}
}

public Vector2 MouseScrollDelta
{
get
{
try
{
return (Vector2)m_readVector2InputMethod.Invoke(MouseScrollInfo, new object[0]);
}
catch
{
return Vector2.zero;
}
}
}

internal static Dictionary<KeyCode, object> ActualKeyDict = new Dictionary<KeyCode, object>();

internal object GetActualKey(KeyCode key)
Expand Down
4 changes: 4 additions & 0 deletions src/LegacyInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public LegacyInput()
Implementation.Log("Initializing Legacy Input support...");

m_mousePositionProp = TInput.GetProperty("mousePosition");
m_mouseScrollDeltaProp = TInput.GetProperty("mouseScrollDelta");
m_getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
m_getKeyDownMethod = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
m_getKeyUpMethod = TInput.GetMethod("GetKeyUp", new Type[] { typeof(KeyCode) });
Expand All @@ -28,6 +29,7 @@ public LegacyInput()
private static Type m_tInput;

private static PropertyInfo m_mousePositionProp;
private static PropertyInfo m_mouseScrollDeltaProp;
private static MethodInfo m_getKeyMethod;
private static MethodInfo m_getKeyDownMethod;
private static MethodInfo m_getKeyUpMethod;
Expand All @@ -37,6 +39,8 @@ public LegacyInput()

public Vector2 MousePosition => (Vector3)m_mousePositionProp.GetValue(null, null);

public Vector2 MouseScrollDelta => (Vector2)m_mouseScrollDeltaProp.GetValue(null, null);

public bool GetKey(KeyCode key) => (bool)m_getKeyMethod.Invoke(null, new object[] { key });

public bool GetKeyDown(KeyCode key) => (bool)m_getKeyDownMethod.Invoke(null, new object[] { key });
Expand Down
1 change: 1 addition & 0 deletions src/NoInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace KeyboardUtilities
public class NoInput : IHandleInput
{
public Vector2 MousePosition => Vector2.zero;
public Vector2 MouseScrollDelta => Vector2.zero;

public bool GetKey(KeyCode key) => false;
public bool GetKeyDown(KeyCode key) => false;
Expand Down

0 comments on commit 6c2aff1

Please sign in to comment.