Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/1.2.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
Luxusio committed Jul 9, 2022
2 parents 21132ef + f3def1f commit 88da7e0
Show file tree
Hide file tree
Showing 8 changed files with 1,036 additions and 352 deletions.
195 changes: 195 additions & 0 deletions Helper/KeyCodeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
using System;
using System.Collections.Generic;
using SharpHook.Native;

namespace NoStopMod.Helper
{

/*
Normal Keys, Numpad keys is reversed
Normal Keys
UpArrow -> VcNumPadUp;
DownArrow -> VcNumPadDown;
LeftArrow -> VcNumPadLeft;
RightArrow -> VcNumPadRight;
Insert -> VcNumPadInsert;
Home -> VcNumPadHome;
PageUp -> VcNumPadPageUp;
Delete -> VcNumPadDelete;
End -> VcNumPadEnd;
PageDown -> VcNumPadPageDown;
Numpad Keys
UpArrow -> VcUp
DownArrow -> VcDown
LeftArrow -> VcLeft
RightArrow -> VcRight
Insert -> VcInsert
Home -> VcHome
PageUp -> VcPageUp
Delete -> VcDelete
End -> VcEnd
PageDown -> VcPageDown
*/

public class KeyCodeHelper
{

private static readonly IReadOnlyDictionary<ushort, ushort> NativeKeyCodeMapper;
public static readonly IReadOnlyList<Tuple<UnityEngine.KeyCode, ushort>> UnityNativeKeyCodeList;

static KeyCodeHelper()
{
NativeKeyCodeMapper = InitNativeKeyCodeMapper();
UnityNativeKeyCodeList = InitUnityNativeKeyCodeList();
}

private static List<Tuple<UnityEngine.KeyCode, ushort>> InitUnityNativeKeyCodeList() => new()
{
new(UnityEngine.KeyCode.None, (ushort) KeyCode.VcUndefined ),
new(UnityEngine.KeyCode.Escape, (ushort) KeyCode.VcEscape ),
new(UnityEngine.KeyCode.Alpha1, (ushort) KeyCode.Vc1 ),
new(UnityEngine.KeyCode.Alpha2, (ushort) KeyCode.Vc2 ),
new(UnityEngine.KeyCode.Alpha3, (ushort) KeyCode.Vc3 ),
new(UnityEngine.KeyCode.Alpha4, (ushort) KeyCode.Vc4 ),
new(UnityEngine.KeyCode.Alpha5, (ushort) KeyCode.Vc5 ),
new(UnityEngine.KeyCode.Alpha6, (ushort) KeyCode.Vc6 ),
new(UnityEngine.KeyCode.Alpha7, (ushort) KeyCode.Vc7 ),
new(UnityEngine.KeyCode.Alpha8, (ushort) KeyCode.Vc8 ),
new(UnityEngine.KeyCode.Alpha9, (ushort) KeyCode.Vc9 ),
new(UnityEngine.KeyCode.Alpha0, (ushort) KeyCode.Vc0 ),
new(UnityEngine.KeyCode.Minus, (ushort) KeyCode.VcMinus ),
new(UnityEngine.KeyCode.Equals, (ushort) KeyCode.VcEquals ),
new(UnityEngine.KeyCode.Backspace, (ushort) KeyCode.VcBackspace ),
new(UnityEngine.KeyCode.Tab, (ushort) KeyCode.VcTab ),
new(UnityEngine.KeyCode.Q, (ushort) KeyCode.VcQ ),
new(UnityEngine.KeyCode.W, (ushort) KeyCode.VcW ),
new(UnityEngine.KeyCode.E, (ushort) KeyCode.VcE ),
new(UnityEngine.KeyCode.R, (ushort) KeyCode.VcR ),
new(UnityEngine.KeyCode.T, (ushort) KeyCode.VcT ),
new(UnityEngine.KeyCode.Y, (ushort) KeyCode.VcY ),
new(UnityEngine.KeyCode.U, (ushort) KeyCode.VcU ),
new(UnityEngine.KeyCode.I, (ushort) KeyCode.VcI ),
new(UnityEngine.KeyCode.O, (ushort) KeyCode.VcO ),
new(UnityEngine.KeyCode.P, (ushort) KeyCode.VcP ),
new(UnityEngine.KeyCode.LeftBracket, (ushort) KeyCode.VcOpenBracket ),
new(UnityEngine.KeyCode.RightBracket, (ushort) KeyCode.VcCloseBracket ),
new(UnityEngine.KeyCode.Return, (ushort) KeyCode.VcEnter ),
new(UnityEngine.KeyCode.LeftControl, (ushort) KeyCode.VcLeftControl ),
new(UnityEngine.KeyCode.A, (ushort) KeyCode.VcA ),
new(UnityEngine.KeyCode.S, (ushort) KeyCode.VcS ),
new(UnityEngine.KeyCode.D, (ushort) KeyCode.VcD ),
new(UnityEngine.KeyCode.F, (ushort) KeyCode.VcF ),
new(UnityEngine.KeyCode.G, (ushort) KeyCode.VcG ),
new(UnityEngine.KeyCode.H, (ushort) KeyCode.VcH ),
new(UnityEngine.KeyCode.J, (ushort) KeyCode.VcJ ),
new(UnityEngine.KeyCode.K, (ushort) KeyCode.VcK ),
new(UnityEngine.KeyCode.L, (ushort) KeyCode.VcL ),
new(UnityEngine.KeyCode.Semicolon, (ushort) KeyCode.VcSemicolon ),
new(UnityEngine.KeyCode.Quote, (ushort) KeyCode.VcQuote ),
new(UnityEngine.KeyCode.BackQuote, (ushort) KeyCode.VcBackquote ),
new(UnityEngine.KeyCode.LeftShift, (ushort) KeyCode.VcLeftShift ),
new(UnityEngine.KeyCode.Backslash, (ushort) KeyCode.VcBackSlash ),
new(UnityEngine.KeyCode.Z, (ushort) KeyCode.VcZ ),
new(UnityEngine.KeyCode.X, (ushort) KeyCode.VcX ),
new(UnityEngine.KeyCode.C, (ushort) KeyCode.VcC ),
new(UnityEngine.KeyCode.V, (ushort) KeyCode.VcV ),
new(UnityEngine.KeyCode.B, (ushort) KeyCode.VcB ),
new(UnityEngine.KeyCode.N, (ushort) KeyCode.VcN ),
new(UnityEngine.KeyCode.M, (ushort) KeyCode.VcM ),
new(UnityEngine.KeyCode.Comma, (ushort) KeyCode.VcComma ),
new(UnityEngine.KeyCode.Period, (ushort) KeyCode.VcPeriod ),
new(UnityEngine.KeyCode.Slash, (ushort) KeyCode.VcSlash ),
new(UnityEngine.KeyCode.RightShift, (ushort) KeyCode.VcRightShift ),
new(UnityEngine.KeyCode.KeypadMultiply, (ushort) KeyCode.VcNumPadMultiply ),
new(UnityEngine.KeyCode.LeftAlt, (ushort) KeyCode.VcLeftAlt ),
new(UnityEngine.KeyCode.Space, (ushort) KeyCode.VcSpace ),
new(UnityEngine.KeyCode.CapsLock, (ushort) KeyCode.VcCapsLock ),
new(UnityEngine.KeyCode.F1, (ushort) KeyCode.VcF1 ),
new(UnityEngine.KeyCode.F2, (ushort) KeyCode.VcF2 ),
new(UnityEngine.KeyCode.F3, (ushort) KeyCode.VcF3 ),
new(UnityEngine.KeyCode.F4, (ushort) KeyCode.VcF4 ),
new(UnityEngine.KeyCode.F5, (ushort) KeyCode.VcF5 ),
new(UnityEngine.KeyCode.F6, (ushort) KeyCode.VcF6 ),
new(UnityEngine.KeyCode.F7, (ushort) KeyCode.VcF7 ),
new(UnityEngine.KeyCode.F8, (ushort) KeyCode.VcF8 ),
new(UnityEngine.KeyCode.F9, (ushort) KeyCode.VcF9 ),
new(UnityEngine.KeyCode.F10, (ushort) KeyCode.VcF10 ),
new(UnityEngine.KeyCode.Numlock, (ushort) KeyCode.VcNumLock ),
new(UnityEngine.KeyCode.ScrollLock, (ushort) KeyCode.VcScrollLock ),
new(UnityEngine.KeyCode.Keypad7, (ushort) KeyCode.VcNumPad7 ),
new(UnityEngine.KeyCode.Keypad8, (ushort) KeyCode.VcNumPad8 ),
new(UnityEngine.KeyCode.Keypad9, (ushort) KeyCode.VcNumPad9 ),
new(UnityEngine.KeyCode.KeypadMinus, (ushort) KeyCode.VcNumPadSubtract ),
new(UnityEngine.KeyCode.Keypad4, (ushort) KeyCode.VcNumPad4 ),
new(UnityEngine.KeyCode.Keypad5, (ushort) KeyCode.VcNumPad5 ),
new(UnityEngine.KeyCode.Keypad6, (ushort) KeyCode.VcNumPad6 ),
new(UnityEngine.KeyCode.KeypadPlus, (ushort) KeyCode.VcNumPadAdd ),
new(UnityEngine.KeyCode.Keypad1, (ushort) KeyCode.VcNumPad1 ),
new(UnityEngine.KeyCode.Keypad2, (ushort) KeyCode.VcNumPad2 ),
new(UnityEngine.KeyCode.Keypad3, (ushort) KeyCode.VcNumPad3 ),
new(UnityEngine.KeyCode.Keypad0, (ushort) KeyCode.VcNumPad0 ),
new(UnityEngine.KeyCode.KeypadPeriod, (ushort) KeyCode.VcNumPadSeparator ),
new(UnityEngine.KeyCode.F11, (ushort) KeyCode.VcF11 ),
new(UnityEngine.KeyCode.F12, (ushort) KeyCode.VcF12 ),
new(UnityEngine.KeyCode.F13, (ushort) KeyCode.VcF13 ),
new(UnityEngine.KeyCode.F14, (ushort) KeyCode.VcF14 ),
new(UnityEngine.KeyCode.F15, (ushort) KeyCode.VcF15 ),
new(UnityEngine.KeyCode.Underscore, (ushort) KeyCode.VcUnderscore ),
new(UnityEngine.KeyCode.KeypadEquals, (ushort) KeyCode.VcNumPadEquals ),
new(UnityEngine.KeyCode.RightControl, (ushort) KeyCode.VcRightControl ),
new(UnityEngine.KeyCode.KeypadDivide, (ushort) KeyCode.VcNumPadDivide ),
new(UnityEngine.KeyCode.Print, (ushort) KeyCode.VcPrintscreen ),
new(UnityEngine.KeyCode.RightAlt, (ushort) KeyCode.VcRightAlt ),
new(UnityEngine.KeyCode.Pause, (ushort) KeyCode.VcPause ),
new(UnityEngine.KeyCode.LeftMeta, (ushort) KeyCode.VcLeftMeta ),
new(UnityEngine.KeyCode.RightMeta, (ushort) KeyCode.VcRightMeta ),
new(UnityEngine.KeyCode.Menu, (ushort) KeyCode.VcContextMenu ),
new(UnityEngine.KeyCode.Clear, (ushort) KeyCode.VcEnter ),
new(UnityEngine.KeyCode.KeypadEnter, (ushort) KeyCode.VcNumPadEnter ),
new(UnityEngine.KeyCode.LeftApple, (ushort) KeyCode.VcLeftMeta ),
new(UnityEngine.KeyCode.UpArrow, (ushort) KeyCode.VcNumPadUp ),
new(UnityEngine.KeyCode.DownArrow, (ushort) KeyCode.VcNumPadDown ),
new(UnityEngine.KeyCode.LeftArrow, (ushort) KeyCode.VcNumPadLeft ),
new(UnityEngine.KeyCode.RightArrow, (ushort) KeyCode.VcNumPadRight ),
new(UnityEngine.KeyCode.Insert, (ushort) KeyCode.VcNumPadInsert ),
new(UnityEngine.KeyCode.Home, (ushort) KeyCode.VcNumPadHome ),
new(UnityEngine.KeyCode.PageUp, (ushort) KeyCode.VcNumPadPageUp ),
new(UnityEngine.KeyCode.Delete, (ushort) KeyCode.VcNumPadDelete ),
new(UnityEngine.KeyCode.End, (ushort) KeyCode.VcNumPadEnd ),
new(UnityEngine.KeyCode.PageDown, (ushort) KeyCode.VcNumPadPageDown ),
new(UnityEngine.KeyCode.Mouse0, (ushort) (1000 + MouseButton.Button1) ),
new(UnityEngine.KeyCode.Mouse1, (ushort) (1000 + MouseButton.Button2) ),
new(UnityEngine.KeyCode.Mouse2, (ushort) (1000 + MouseButton.Button3) ),
new(UnityEngine.KeyCode.Mouse3, (ushort) (1000 + MouseButton.Button4) ),
new(UnityEngine.KeyCode.Mouse4, (ushort) (1000 + MouseButton.Button5) ),
};

private static Dictionary<ushort, ushort> InitNativeKeyCodeMapper() => new()
{
[(ushort) KeyCode.VcDelete] = (ushort) KeyCode.VcNumPadDelete, // original position : KeyCode.VcNumPadSeparator
[(ushort) KeyCode.VcInsert] = (ushort) KeyCode.VcNumPadInsert, // original position : KeyCode.VcNumPad0
[(ushort) KeyCode.VcEnd] = (ushort) KeyCode.VcNumPadEnd, // original position : KeyCode.VcNumPad1
[(ushort) KeyCode.VcDown] = (ushort) KeyCode.VcNumPadDown, // original position : KeyCode.VcNumPad2
[(ushort) KeyCode.VcPageDown] = (ushort) KeyCode.VcNumPadPageDown, // original position : KeyCode.VcNumPad3
[(ushort) KeyCode.VcLeft] = (ushort) KeyCode.VcNumPadLeft, // original position : KeyCode.VcNumPad4
[(ushort) KeyCode.VcRight] = (ushort) KeyCode.VcNumPadRight, // original position : KeyCode.VcNumPad6
[(ushort) KeyCode.VcHome] = (ushort) KeyCode.VcNumPadHome, // original position : KeyCode.VcNumPad7
[(ushort) KeyCode.VcUp] = (ushort) KeyCode.VcNumPadUp, // original position : KeyCode.VcNumPad8
[(ushort) KeyCode.VcPageUp] = (ushort) KeyCode.VcNumPadPageUp, // original position : KeyCode.VcNumPad9
};


public static ushort ConvertNativeKeyCode(ushort keyCode)
{
return NativeKeyCodeMapper.TryGetValue(keyCode, out var newKeyCode) ? newKeyCode
: keyCode;
}

}

}
28 changes: 14 additions & 14 deletions Helper/ReflectionField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@

namespace NoStopMod.Helper
{
public class ReflectionField<T>
public class ReflectionField<T, TV>
{
private static FieldInfo fieldInfo;
private FieldInfo _fieldInfo;

private readonly string[] fieldNames;
private readonly string[] _fieldNames;

public ReflectionField(params string[] fieldNames)
{
this.fieldNames = fieldNames;
this._fieldNames = fieldNames;
}

public FieldInfo GetFieldInfo(Type type)
{
if (fieldInfo == null)
if (_fieldInfo == null)
{
for (int i=0;i < fieldNames.Count();i++)
for (int i = 0; i < _fieldNames.Count(); i++)
{
fieldInfo = type.GetField(fieldNames[i],
_fieldInfo = type.GetField(_fieldNames[i],
BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty);
if (fieldInfo != null) break;
if (_fieldInfo != null) break;
}
if (fieldInfo == null)
if (_fieldInfo == null)
{
NoStopMod.mod.Logger.Error("Cannot find fieldInfo : (type=" + type + ", name" + fieldNames + ")");
NoStopMod.mod.Logger.Error("Cannot find fieldInfo : (type=" + type + ", name" + _fieldNames + ")");
}
}
return fieldInfo;
return _fieldInfo;
}

public void SetValue(object obj, T value)
public void SetValue(T obj, TV value)
{
GetFieldInfo(obj.GetType())?.SetValue(obj, value);
}

public T GetValue(object obj)
public TV GetValue(T obj)
{
return (T) GetFieldInfo(obj.GetType())?.GetValue(obj);
return (TV) GetFieldInfo(obj.GetType())?.GetValue(obj);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "NoStopMod",
"DisplayName": "NoStopMod",
"Author": "Luxus",
"Version": "1.2.8",
"Version": "1.2.9",
"ManagerVersion": "0.23.4.0",
"LoadAfter": ["AdofaiTweaks"],
"AssemblyName": "NoStopMod.dll",
Expand Down
46 changes: 33 additions & 13 deletions InputFixer/HitIgnore/HitIgnoreManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static void Init()
HashSet<KeyCode> ignoreScnNewIntro = new HashSet<KeyCode>();
_dictionary["scnNewIntro"] = ignoreScnNewIntro;

ignoreScnNewIntro.Add(KeyCode.VcQuote);
ignoreScnNewIntro.Add(KeyCode.VcBackquote);
ignoreScnNewIntro.Add(KeyCode.Vc0);
ignoreScnNewIntro.Add(KeyCode.Vc1);
Expand All @@ -33,15 +32,17 @@ public static void Init()

HashSet<KeyCode> ignoreScnCLS_ = new HashSet<KeyCode>();
_dictionary["scnCLS"] = ignoreScnCLS_;
ignoreScnCLS_.Add(KeyCode.VcS);
ignoreScnCLS_.Add(KeyCode.VcDelete);
ignoreScnCLS_.Add(KeyCode.VcF);
ignoreScnCLS_.Add(KeyCode.VcO);
ignoreScnCLS_.Add(KeyCode.Vc7);
ignoreScnCLS_.Add(KeyCode.VcUp);
ignoreScnCLS_.Add(KeyCode.VcNumPadUp);
ignoreScnCLS_.Add(KeyCode.VcDown);
ignoreScnCLS_.Add(KeyCode.VcNumPadDown);
ignoreScnCLS_.Add(KeyCode.VcR);
ignoreScnCLS_.Add(KeyCode.VcS);
ignoreScnCLS_.Add(KeyCode.VcDelete);
ignoreScnCLS_.Add(KeyCode.VcI);
ignoreScnCLS_.Add(KeyCode.VcF);
ignoreScnCLS_.Add(KeyCode.VcO);
ignoreScnCLS_.Add(KeyCode.VcN);

HashSet<KeyCode> ignoreScnTaroMenu0 = new HashSet<KeyCode>();
_dictionary["scnTaroMenu0"] = ignoreScnTaroMenu0;
Expand All @@ -51,6 +52,15 @@ public static void Init()
ignoreScnTaroMenu0.Add(KeyCode.Vc4);
ignoreScnTaroMenu0.Add(KeyCode.Vc5);
ignoreScnTaroMenu0.Add(KeyCode.Vc6);

HashSet<KeyCode> ignoreScnTaroMenu3 = new HashSet<KeyCode>();
_dictionary["scnTaroMenu3"] = ignoreScnTaroMenu3;
ignoreScnTaroMenu3.Add(KeyCode.Vc0);
ignoreScnTaroMenu3.Add(KeyCode.Vc1);
ignoreScnTaroMenu3.Add(KeyCode.Vc2);
ignoreScnTaroMenu3.Add(KeyCode.Vc3);
ignoreScnTaroMenu3.Add(KeyCode.Vc4);
ignoreScnTaroMenu3.Add(KeyCode.Vc5);

scnCLS_searchMode = false;

Expand All @@ -65,7 +75,7 @@ public static void Init()
public static bool ShouldBeIgnored(KeyCode keyCode)
{
#if DEBUG
NoStopMod.mod.Logger.Log($"scene : {GCS.sceneToLoad}, keyCode: {keyCode}");
//NoStopMod.mod.Logger.Log($"scene : {GCS.sceneToLoad}, keyCode: {keyCode}");
#endif

if (keyCode == KeyCode.VcEscape) return true;
Expand All @@ -74,19 +84,29 @@ public static bool ShouldBeIgnored(KeyCode keyCode)
KeyLimiterManager.UpdateKeyLimiter(keyCode);
return true;
}

if (scrController_state != scrController.States.PlayerControl && !scrController.instance.isEditingLevel && scrController.instance.uiController.difficultyUIMode != DifficultyUIMode.DontShow)
{
if (keyCode is KeyCode.VcNumPadLeft
or KeyCode.VcLeft)
{
return true;
}
if (keyCode is KeyCode.VcNumPadRight
or KeyCode.VcRight)
{
return true;
}
}

if (scrController_state != scrController.States.PlayerControl)
if (GCS.sceneToLoad == "scnCLS" && scnCLS_searchMode)
{
return true;
}

HashSet<KeyCode> ignoreScnCLS;
if (_dictionary.TryGetValue(GCS.sceneToLoad, out ignoreScnCLS))
{
if (GCS.sceneToLoad == "scnCLS" && scnCLS_searchMode)
{
return true;
}
if (ignoreScnCLS.Contains(keyCode))
{
return true;
Expand Down
Loading

0 comments on commit 88da7e0

Please sign in to comment.