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

Commit 651329c

Browse files
committed
Fix input issues
1 parent 648728e commit 651329c

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

src/Input/InputManager.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
4+
using System.Reflection;
45
using UnityEngine;
56
using UnityEngine.EventSystems;
67
using UniverseLib.UI;
@@ -34,6 +35,20 @@ private static void InitHandler()
3435
// First, just try to use the legacy input, see if its working.
3536
// The InputSystem package may be present but not actually activated, so we can find out this way.
3637

38+
// With BepInEx Il2CppInterop, for some reason InputLegacyModule may be loaded but our ReflectionUtility doesn't cache it?
39+
// No idea why or what is happening but this solves it for now.
40+
if (ReflectionUtility.GetTypeByName("UnityEngine.Input") == null)
41+
{
42+
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
43+
{
44+
if (asm.FullName.Contains("UnityEngine.InputLegacyModule"))
45+
{
46+
ReflectionUtility.CacheTypes(asm);
47+
break;
48+
}
49+
}
50+
}
51+
3752
if (LegacyInput.TInput != null)
3853
{
3954
try
@@ -47,7 +62,7 @@ private static void InitHandler()
4762
Universe.Log("Initialized Legacy Input support");
4863
return;
4964
}
50-
catch
65+
catch
5166
{
5267
// It's not working, we'll fall back to InputSystem.
5368
}

src/Input/InputSystem.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,16 @@ public static object KeyCodeToKeyEnum(KeyCode key)
279279
if (keycodeToKeyFixes.First(it => s.Contains(it.Key)) is KeyValuePair<string, string> entry)
280280
s = s.Replace(entry.Key, entry.Value);
281281
}
282-
catch { }
282+
catch { /* suppressed */ }
283283

284284
try
285285
{
286286
object parsed = Enum.Parse(TKey, s);
287287
KeyCodeToKeyEnumDict.Add(key, parsed);
288288
}
289-
catch
289+
catch (Exception ex)
290290
{
291+
Universe.Log(ex);
291292
KeyCodeToKeyEnumDict.Add(key, default);
292293
}
293294
}
@@ -301,9 +302,10 @@ public bool GetKeyDown(KeyCode key)
301302
{
302303
try
303304
{
304-
return (bool)p_btnWasPressed.GetValue(KeyCodeToActualKey(key), null);
305+
object actual = KeyCodeToActualKey(key);
306+
return (bool)p_btnWasPressed.GetValue(actual, null);
305307
}
306-
catch
308+
catch
307309
{
308310
return false;
309311
}
@@ -411,7 +413,10 @@ public void ActivateModule()
411413
{
412414
MethodInfo assignDefaultMethod = newInput.GetType()
413415
.GetMethod("AssignDefaultActions");
414-
assignDefaultMethod.Invoke(newInput.TryCast(assignDefaultMethod.DeclaringType), new object[0]);
416+
if (assignDefaultMethod != null)
417+
assignDefaultMethod.Invoke(newInput.TryCast(assignDefaultMethod.DeclaringType), new object[0]);
418+
else
419+
Universe.Log("AssignDefaultActions method is null!");
415420
}
416421
}
417422
catch (Exception ex)

src/Reflection/Il2CppReflection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,12 +640,13 @@ internal bool DoLoadModule(string fullPath)
640640

641641
try
642642
{
643+
//Universe.Log($"Loading assembly '{Path.GetFileName(fullPath)}'");
643644
Assembly.LoadFile(fullPath);
644645
return true;
645646
}
646-
catch //(Exception e)
647+
catch
647648
{
648-
//UniverseLib.LogWarning($"Failed loading module '{Path.GetFileName(fullPath)}'! {e.ReflectionExToString()}");
649+
//Universe.LogWarning($"Failed loading module '{Path.GetFileName(fullPath)}'! {e.ReflectionExToString()}");
649650
return false;
650651
}
651652
}

src/Reflection/ReflectionUtility.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void ForceLoadManagedAssemblies()
114114
}
115115
}
116116

117-
static void CacheTypes(Assembly asm)
117+
internal static void CacheTypes(Assembly asm)
118118
{
119119
foreach (Type type in asm.GetTypes())
120120
{
@@ -159,6 +159,10 @@ internal virtual Type Internal_GetTypeByName(string fullName)
159159
return shorthand;
160160

161161
AllTypes.TryGetValue(fullName, out Type type);
162+
163+
if (type == null)
164+
type = Type.GetType(fullName);
165+
162166
return type;
163167
}
164168

src/Runtime/Il2Cpp/Il2CppManagedEnumerator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ static Il2CppManagedEnumerator()
4242
// This method is just obsoleted in BepInEx's branch, but still works.
4343

4444
// ClassInjector.RegisterTypeInIl2CppWithInterfaces(typeof(Il2CppManagedEnumerator), true, typeof(Il2CppIEnumerator));
45+
#if UNHOLLOWER
4546
AccessTools.Method(typeof(ClassInjector), "RegisterTypeInIl2CppWithInterfaces", new Type[] { typeof(Type), typeof(bool), typeof(Type[]) })
4647
.Invoke(null, new object[] { typeof(Il2CppManagedEnumerator), true, new[] { typeof(Il2CppSystem.Collections.IEnumerator) } });
48+
#else
49+
ClassInjector.RegisterTypeInIl2Cpp<Il2CppManagedEnumerator>(new RegisterTypeOptions
50+
{
51+
Interfaces = new[] { typeof(Il2CppIEnumerator) }
52+
});
53+
#endif
54+
4755
}
4856
catch (System.Exception ex)
4957
{

src/Universe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public enum GlobalState
3232
}
3333

3434
public const string NAME = "UniverseLib";
35-
public const string VERSION = "1.5.0";
35+
public const string VERSION = "1.5.1";
3636
public const string AUTHOR = "Sinai";
3737
public const string GUID = "com.sinai.universelib";
3838

0 commit comments

Comments
 (0)