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

Commit 4bcf82c

Browse files
committed
separate Bep5 and Bep6 support. Fix enums not backed by ints.
1 parent ce38e8a commit 4bcf82c

File tree

11 files changed

+462
-346
lines changed

11 files changed

+462
-346
lines changed

README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424

2525
| Mod Loader | IL2CPP | Mono |
2626
| ----------- | ------ | ---- |
27-
| [BepInEx](https://github.com/BepInEx/BepInEx) | ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.BepInEx.Il2Cpp.zip) | ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.BepInEx.Mono.zip) |
28-
| [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) | ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.MelonLoader.Il2Cpp.zip) | ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.MelonLoader.Mono.zip) |
27+
| [BepInEx](https://github.com/BepInEx/BepInEx) 6.X | ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.BepInEx.Il2Cpp.zip) |[link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.BepInEx6.Mono.zip) |
28+
| [BepInEx](https://github.com/BepInEx/BepInEx) 5.X || ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.BepInEx5.Mono.zip) |
29+
| [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) 0.3 | ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.MelonLoader.Il2Cpp.zip) | ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.MelonLoader.Mono.zip) |
2930
| Standalone | ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Standalone.Il2Cpp.zip) | ✔️ [link](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Standalone.Mono.zip) |
3031

3132
## Features
@@ -47,13 +48,17 @@
4748

4849
### BepInEx
4950

51+
Note: For IL2CPP you should use [BepInEx 6 (Bleeding Edge)](https://builds.bepis.io/projects/bepinex_be), for Mono you should use [BepInEx 5](https://github.com/BepInEx/BepInEx/releases) (until Mono support stabilizes in BepInEx 6).
52+
5053
0. Install [BepInEx](https://github.com/BepInEx/BepInEx) for your game.
5154
1. Download the UnityExplorer release for BepInEx IL2CPP or Mono above.
5255
2. Take the `UnityExplorer.BIE.___.dll` file and put it in `[GameFolder]\BepInEx\plugins\`
5356
3. In IL2CPP, it is highly recommended to get the base Unity libs for the game's Unity version and put them in the `BepInEx\unity-libs\` folder.
5457

5558
### MelonLoader
5659

60+
Note: You must use version 0.3 of MelonLoader or greater. Version 0.3 is currently in pre-release, so you must opt-in from your MelonLoader installer (enable alpha releases).
61+
5762
0. Install [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) for your game.
5863
1. Download the UnityExplorer release for MelonLoader IL2CPP or Mono above.
5964
2. Take the contents of the release and put it in the `[GameFolder]\Mods\` folder. It should look like `[GameFolder]\Mods\UnityExplorer.ML.___.dll`
@@ -62,12 +67,12 @@
6267

6368
0. Load the DLL from your mod or inject it.
6469
1. Create an instance of Unity Explorer with `new ExplorerCore();`
65-
2. You will need to call ExplorerCore.Update() (static method) from your Update method.
70+
2. You will need to call `ExplorerCore.Update()` (static method) from your Update method.
6671
3. Subscribe to the `ExplorerCore.OnLog__` methods for logging.
6772

68-
## Mod Config
73+
## Settings
6974

70-
You can access the settings via the "Options" page of the main menu, or directly from the config at `Mods\UnityExplorer\config.ini` (generated after first launch).
75+
You can change the settings via the "Options" page of the main menu, or directly from the config file (generated after first launch). The config file will be found either inside a "UnityExplorer" folder in the same directory as where you put the DLL file, or for BepInEx it will be at `BepInEx\config\UnityExplorer\`.
7176

7277
`Main Menu Toggle` (KeyCode)
7378
* Default: `F7`
@@ -91,17 +96,24 @@ You can access the settings via the "Options" page of the main menu, or directly
9196
* Default: `false`
9297
* Listens for Unity `Debug.Log` messages and prints them to UnityExplorer's log.
9398

99+
`Hide on Startup` (bool)
100+
* Default: `false`
101+
* If true, UnityExplorer will be hidden when you start the game, you must open it via the keybind.
102+
94103
## Building
95104

96-
If you'd like to build this yourself, you will need to have installed BepInEx and/or MelonLoader for at least one Unity game. If you want to build all 4 versions, you will need at least one IL2CPP and one Mono game, with BepInEx and MelonLoader installed for both.
105+
If you'd like to build this yourself, all you need to do is download this repository and build from Visual Studio. If you want to build for BepInEx or MelonLoader IL2CPP then you will need to install the mod loader for a game and set the directory in the `csproj` file.
97106

98-
1. Install BepInEx or MelonLoader for your game, or use the standalone build.
107+
For IL2CPP:
108+
1. Install BepInEx or MelonLoader for your game.
99109
2. Open the `src\UnityExplorer.csproj` file in a text editor.
100-
3. For IL2CPP builds, make sure you set `BIECppGameFolder` (for BepInEx) and/or `MLCppGameFolder` (for MelonLoader) so the project can locate the necessary references.
101-
4. Open the `src\UnityExplorer.sln` project.
102-
5. Select `Solution 'UnityExplorer' (1 of 1 project)` in the Solution Explorer panel, and set the <b>Active config</b> property to the version you want to build, then build it.
103-
5. The DLLs are built to the `Release\` folder in the root of the repository.
104-
6. If ILRepack fails or is missing, use the NuGet package manager to re-install `ILRepack.Lib.MSBuild.Task`, then re-build.
110+
3. Set `BIECppGameFolder` (for BepInEx) and/or `MLCppGameFolder` (for MelonLoader) so the project can locate the necessary references.
111+
112+
For all builds:
113+
1. Open the `src\UnityExplorer.sln` project.
114+
2. Select `Solution 'UnityExplorer' (1 of 1 project)` in the Solution Explorer panel, and set the <b>Active config</b> property to the version you want to build, then build it.
115+
3. The DLLs are built to the `Release\` folder in the root of the repository.
116+
4. If ILRepack fails or is missing, use the NuGet package manager to re-install `ILRepack.Lib.MSBuild.Task`, then re-build.
105117

106118
## Credits
107119

lib/BepInEx.Unity.dll

25.5 KB
Binary file not shown.

src/ExplorerBepIn5Plugin.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#if BIE5
2+
using System;
3+
using System.IO;
4+
using System.Reflection;
5+
using BepInEx;
6+
using BepInEx.Logging;
7+
using HarmonyLib;
8+
9+
namespace UnityExplorer
10+
{
11+
[BepInPlugin(ExplorerCore.GUID, "UnityExplorer", ExplorerCore.VERSION)]
12+
public class ExplorerBepInPlugin : BaseUnityPlugin
13+
{
14+
public static ExplorerBepInPlugin Instance;
15+
16+
public static ManualLogSource Logging => Instance?.Logger;
17+
18+
public static readonly Harmony HarmonyInstance = new Harmony(ExplorerCore.GUID);
19+
20+
internal void Awake()
21+
{
22+
Instance = this;
23+
24+
new ExplorerCore();
25+
26+
// HarmonyInstance.PatchAll();
27+
}
28+
29+
internal void Update()
30+
{
31+
ExplorerCore.Update();
32+
}
33+
}
34+
}
35+
#endif

src/ExplorerBepInPlugin.cs renamed to src/ExplorerBepIn6Plugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if BIE
1+
#if BIE6
22
using System;
33
using System.IO;
44
using System.Reflection;

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace UnityExplorer
1515
public class ExplorerCore
1616
{
1717
public const string NAME = "UnityExplorer";
18-
public const string VERSION = "3.1.12";
18+
public const string VERSION = "3.2.0";
1919
public const string AUTHOR = "Sinai";
2020
public const string GUID = "com.sinai.unityexplorer";
2121

src/Inspectors/Reflection/InteractiveValue/InteractiveEnum.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,34 @@ internal void GetNames()
4747

4848
var list = new List<KeyValuePair<int, string>>();
4949
var set = new HashSet<string>();
50+
5051
foreach (var value in values)
5152
{
5253
var name = value.ToString();
54+
5355
if (set.Contains(name))
5456
continue;
57+
5558
set.Add(name);
56-
list.Add(new KeyValuePair<int, string>((int)value, name));
59+
60+
var backingType = Enum.GetUnderlyingType(type);
61+
int intValue;
62+
try
63+
{
64+
// this approach is necessary, a simple '(int)value' is not sufficient.
65+
66+
var unbox = Convert.ChangeType(value, backingType);
67+
68+
intValue = (int)Convert.ChangeType(unbox, typeof(int));
69+
}
70+
catch (Exception ex)
71+
{
72+
ExplorerCore.LogWarning("[InteractiveEnum] Could not Unbox underlying type " + backingType.Name + " from " + type.FullName);
73+
ExplorerCore.Log(ex.ToString());
74+
continue;
75+
}
76+
77+
list.Add(new KeyValuePair<int, string>(intValue, name));
5778
}
5879

5980
s_enumNamesCache.Add(type, list.ToArray());

src/Inspectors/Reflection/ReflectionInspector.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private static void OnContainerResized()
4343
"Collider2D.Cast",
4444
"Collider2D.Raycast",
4545
"Texture2D.SetPixelDataImpl",
46+
"Camera.CalculateProjectionMatrixFromPhysicalProperties",
4647
#endif
4748
};
4849
private static readonly HashSet<string> bl_memberNameStartsWith = new HashSet<string>
@@ -172,11 +173,11 @@ public void CacheMembers(Type type)
172173
{
173174
try
174175
{
176+
var sig = GetSig(member);
177+
175178
//ExplorerCore.Log($"Trying to cache member {sig}...");
176179
//ExplorerCore.Log(member.DeclaringType.FullName + "." + member.Name);
177180

178-
var sig = GetSig(member);
179-
180181
var mi = member as MethodInfo;
181182
var pi = member as PropertyInfo;
182183
var fi = member as FieldInfo;

src/Tests/Tests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313

1414
namespace UnityExplorer.Tests
1515
{
16+
internal enum TestByteEnum : byte
17+
{
18+
One,
19+
Two,
20+
Three,
21+
TwoFiftyFive = 255,
22+
}
23+
1624
public static class StaticTestClass
1725
{
1826
public static int StaticProperty => 5;
@@ -28,6 +36,8 @@ public static void StaticMethod() { }
2836

2937
public class TestClass
3038
{
39+
internal static TestByteEnum testingByte = TestByteEnum.One;
40+
3141
public string AAALongString = @"1
3242
2
3343
3

src/UI/ForceUnlockCursor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private static void TryPatch(Type type, string property, HarmonyMethod patch, bo
104104
{
105105
var harmony =
106106
#if ML
107-
ExplorerMelonMod.Instance.harmonyInstance;
107+
ExplorerMelonMod.Instance.Harmony;
108108
#elif BIE
109109
ExplorerBepInPlugin.HarmonyInstance;
110110
#elif STANDALONE

0 commit comments

Comments
 (0)