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

Commit 9e99681

Browse files
committed
starting work on a cleanup/rewrite
1 parent 9665753 commit 9e99681

File tree

13 files changed

+147
-95
lines changed

13 files changed

+147
-95
lines changed

src/Config/ExplorerConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static ExplorerConfig()
2525
public KeyCode Main_Menu_Toggle = KeyCode.F7;
2626
public bool Force_Unlock_Mouse = true;
2727
public int Default_Page_Limit = 25;
28-
public string Default_Output_Path = Path.Combine(ExplorerCore.ExplorerFolder, "Output");
28+
public string Default_Output_Path = Path.Combine(ExplorerCore.EXPLORER_FOLDER, "Output");
2929
public bool Log_Unity_Debug = false;
3030
public bool Hide_On_Startup = false;
3131
public string Window_Anchors = DEFAULT_WINDOW_ANCHORS;

src/ExplorerCore.cs

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using UnityExplorer.Helpers;
88
using UnityExplorer.Input;
99
using UnityExplorer.Inspectors;
10+
using UnityExplorer.Runtime;
1011
using UnityExplorer.UI;
1112
using UnityExplorer.UI.Modules;
1213

@@ -21,17 +22,16 @@ public class ExplorerCore
2122

2223
public static ExplorerCore Instance { get; private set; }
2324

24-
private static IExplorerLoader s_loader;
25-
public static IExplorerLoader Loader => s_loader
25+
public static IExplorerLoader Loader =>
2626
#if ML
27-
?? (s_loader = ExplorerMelonMod.Instance);
27+
ExplorerMelonMod.Instance;
2828
#elif BIE
29-
?? (s_loader = ExplorerBepInPlugin.Instance);
29+
ExplorerBepInPlugin.Instance;
3030
#elif STANDALONE
31-
?? (s_loader = ExplorerStandalone.Instance);
31+
ExplorerStandalone.Instance;
3232
#endif
3333

34-
public static string ExplorerFolder => Loader.ExplorerFolder;
34+
public static string EXPLORER_FOLDER => Loader.ExplorerFolder;
3535

3636
public ExplorerCore()
3737
{
@@ -43,19 +43,16 @@ public ExplorerCore()
4343

4444
Instance = this;
4545

46-
#if CPP
47-
ReflectionHelpers.TryLoadGameModules();
48-
#endif
46+
RuntimeProvider.Init();
4947

50-
if (!Directory.Exists(ExplorerFolder))
51-
Directory.CreateDirectory(ExplorerFolder);
48+
if (!Directory.Exists(EXPLORER_FOLDER))
49+
Directory.CreateDirectory(EXPLORER_FOLDER);
5250

5351
ExplorerConfig.OnLoad();
5452

5553
InputManager.Init();
56-
ForceUnlockCursor.Init();
5754

58-
SetupEvents();
55+
ForceUnlockCursor.Init();
5956

6057
UIManager.ShowMenu = true;
6158

@@ -72,33 +69,7 @@ public static void Update()
7269
UIManager.Update();
7370
}
7471

75-
private void SetupEvents()
76-
{
77-
#if CPP
78-
try
79-
{
80-
Application.add_logMessageReceived(new Action<string, string, LogType>(OnUnityLog));
81-
82-
SceneManager.add_sceneLoaded(new Action<Scene, LoadSceneMode>((Scene a, LoadSceneMode b) => { OnSceneLoaded(); }));
83-
SceneManager.add_activeSceneChanged(new Action<Scene, Scene>((Scene a, Scene b) => { OnSceneLoaded(); }));
84-
}
85-
catch
86-
{
87-
// exceptions here are non-fatal, just ignore.
88-
}
89-
#else
90-
Application.logMessageReceived += OnUnityLog;
91-
SceneManager.sceneLoaded += (Scene a, LoadSceneMode b) => { OnSceneLoaded(); };
92-
SceneManager.activeSceneChanged += (Scene a, Scene b) => { OnSceneLoaded(); };
93-
#endif
94-
}
95-
96-
internal void OnSceneLoaded()
97-
{
98-
UIManager.OnSceneChange();
99-
}
100-
101-
private void OnUnityLog(string message, string stackTrace, LogType type)
72+
public void OnUnityLog(string message, string stackTrace, LogType type)
10273
{
10374
if (!DebugConsole.LogUnity)
10475
return;

src/Helpers/EventHelper.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static Type GetIValueForType(Type type)
3535
else if (typeof(Enum).IsAssignableFrom(type))
3636
{
3737
// NET 3.5 doesn't have "GetCustomAttribute", gotta use the multiple version.
38-
if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] fa && fa.Length > 0)
38+
if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] fa && fa.Any())
3939
return typeof(InteractiveFlags);
4040
else
4141
return typeof(InteractiveEnum);

src/Inspectors/SceneExplorer.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ public void Update()
9696
}
9797
}
9898

99-
internal void OnSceneChange()
100-
{
101-
m_sceneDropdown.OnCancel(null);
102-
RefreshSceneSelector();
103-
}
99+
//internal void OnSceneChange()
100+
//{
101+
// m_sceneDropdown.OnCancel(null);
102+
// RefreshSceneSelector();
103+
//}
104104

105105
private void RefreshSceneSelector()
106106
{
@@ -138,8 +138,11 @@ private void RefreshSceneSelector()
138138

139139
if (anyChange)
140140
{
141+
m_sceneDropdown.OnCancel(null);
141142
m_sceneDropdownText.text = newNames[0];
142143
SetTargetScene(newScenes[0]);
144+
145+
SearchPage.Instance.OnSceneChange();
143146
}
144147

145148
m_currentScenes = newScenes.ToArray();

src/Loader/ExplorerMelonMod.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public override void OnUpdate()
3030
ExplorerCore.Update();
3131
}
3232

33-
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
34-
{
35-
ExplorerCore.Instance.OnSceneLoaded();
36-
}
33+
//public override void OnSceneWasLoaded(int buildIndex, string sceneName)
34+
//{
35+
// ExplorerCore.Instance.OnSceneLoaded();
36+
//}
3737
}
3838
}
3939
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#if CPP
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using UnityEngine;
7+
using UnityEngine.Events;
8+
using UnityEngine.SceneManagement;
9+
using UnityExplorer.Helpers;
10+
11+
namespace UnityExplorer.Runtime.Il2Cpp
12+
{
13+
public class Il2CppProvider : RuntimeProvider
14+
{
15+
public override void Initialize()
16+
{
17+
ReflectionHelpers.TryLoadGameModules();
18+
}
19+
20+
public override void SetupEvents()
21+
{
22+
Application.add_logMessageReceived(
23+
new Action<string, string, LogType>(ExplorerCore.Instance.OnUnityLog));
24+
25+
//SceneManager.add_sceneLoaded(
26+
// new Action<Scene, LoadSceneMode>(ExplorerCore.Instance.OnSceneLoaded1));
27+
28+
//SceneManager.add_activeSceneChanged(
29+
// new Action<Scene, Scene>(ExplorerCore.Instance.OnSceneLoaded2));
30+
}
31+
}
32+
}
33+
34+
public static class UnityEventExtensions
35+
{
36+
public static void AddListener(this UnityEvent action, Action listener)
37+
{
38+
action.AddListener(listener);
39+
}
40+
41+
public static void AddListener<T>(this UnityEvent<T> action, Action<T> listener)
42+
{
43+
action.AddListener(listener);
44+
}
45+
}
46+
47+
#endif

src/Runtime/Mono/MonoProvider.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if MONO
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using UnityEngine;
7+
using UnityEngine.SceneManagement;
8+
9+
namespace UnityExplorer.Runtime.Mono
10+
{
11+
public class MonoProvider : RuntimeProvider
12+
{
13+
public override void Initialize()
14+
{
15+
}
16+
17+
public override void SetupEvents()
18+
{
19+
Application.logMessageReceived += ExplorerCore.Instance.OnUnityLog;
20+
//SceneManager.sceneLoaded += ExplorerCore.Instance.OnSceneLoaded1;
21+
//SceneManager.activeSceneChanged += ExplorerCore.Instance.OnSceneLoaded2;
22+
}
23+
}
24+
}
25+
26+
#endif

src/Runtime/RuntimeProvider.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace UnityExplorer.Runtime
7+
{
8+
// Work in progress, this will be used to replace all the "if CPP / if MONO"
9+
// pre-processor directives all over the codebase.
10+
11+
public abstract class RuntimeProvider
12+
{
13+
public static RuntimeProvider Instance;
14+
15+
public RuntimeProvider()
16+
{
17+
Initialize();
18+
19+
SetupEvents();
20+
}
21+
22+
public static void Init() =>
23+
#if CPP
24+
Instance = new Il2Cpp.Il2CppProvider();
25+
#else
26+
Instance = new Mono.MonoProvider();
27+
#endif
28+
29+
30+
public abstract void Initialize();
31+
32+
public abstract void SetupEvents();
33+
34+
}
35+
}

src/Tests/Tests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ private void TextureSpriteTest()
198198
}
199199
}
200200

201-
public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2) where T : Component
202-
{
203-
arg2 = "this is arg2";
201+
//public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2) where T : Component
202+
//{
203+
// arg2 = "this is arg2";
204204

205-
return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'";
206-
}
205+
// return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'";
206+
//}
207207

208208
// test a non-generic dictionary
209209

0 commit comments

Comments
 (0)