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

Commit 28ba5af

Browse files
committed
REPL console
1 parent df3b416 commit 28ba5af

File tree

17 files changed

+424
-412
lines changed

17 files changed

+424
-412
lines changed

Release/CppExplorer.dll

6.5 KB
Binary file not shown.

Release/CppExplorer.zip

544 KB
Binary file not shown.

Release/mcs.dll

1.47 MB
Binary file not shown.

src/CppExplorer.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,31 @@ public override void OnApplicationStart()
6565

6666
Instance = this;
6767

68+
LoadMCS();
69+
6870
new MainMenu();
6971
new WindowManager();
7072

71-
//LoadMCS();
72-
73-
//// init debugging hooks
74-
//var harmony = HarmonyInstance.Create(ID);
75-
//harmony.PatchAll();
73+
var harmony = HarmonyInstance.Create(ID);
74+
harmony.PatchAll();
7675

7776
// done init
7877
ShowMenu = true;
7978
}
8079

81-
//private void LoadMCS()
82-
//{
83-
// var mcsPath = @"Mods\mcs.dll";
84-
// if (File.Exists(mcsPath))
85-
// {
86-
// Assembly.Load(File.ReadAllBytes(mcsPath));
87-
// MelonLogger.Log("Loaded mcs.dll");
88-
// }
89-
// else
90-
// {
91-
// MelonLogger.LogError("Could not find mcs.dll!");
92-
// }
93-
//}
80+
private void LoadMCS()
81+
{
82+
var mcsPath = @"Mods\mcs.dll";
83+
if (File.Exists(mcsPath))
84+
{
85+
Assembly.Load(File.ReadAllBytes(mcsPath));
86+
MelonLogger.Log("Loaded mcs.dll");
87+
}
88+
else
89+
{
90+
MelonLogger.LogError("Could not find mcs.dll!");
91+
}
92+
}
9493

9594
public override void OnLevelWasLoaded(int level)
9695
{

src/CppExplorer.csproj

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\Il2CppSystem.Core.dll</HintPath>
4545
<Private>False</Private>
4646
</Reference>
47+
<Reference Include="mcs, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
48+
<SpecificVersion>False</SpecificVersion>
49+
<HintPath>..\Release\mcs.dll</HintPath>
50+
<Private>False</Private>
51+
</Reference>
4752
<Reference Include="MelonLoader.ModHandler">
4853
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\MelonLoader.ModHandler.dll</HintPath>
4954
<Private>False</Private>
@@ -114,16 +119,16 @@
114119
<ItemGroup>
115120
<Compile Include="ILBehaviour.cs" />
116121
<Compile Include="CppExplorer.cs" />
117-
<Compile Include="Menu\MainMenu\ConsolePage.cs" />
118-
<Compile Include="Menu\MainMenu\Console\REPL.cs" />
119-
<Compile Include="Menu\MainMenu\Console\REPLHelper.cs" />
122+
<Compile Include="MainMenu\Pages\ConsolePage.cs" />
123+
<Compile Include="MainMenu\Pages\Console\REPL.cs" />
124+
<Compile Include="MainMenu\Pages\Console\REPLHelper.cs" />
120125
<Compile Include="WindowManager.cs" />
121-
<Compile Include="Menu\MainMenu.cs" />
122-
<Compile Include="Menu\Inspectors\GameObjectWindow.cs" />
123-
<Compile Include="Menu\Inspectors\ReflectionWindow.cs" />
124-
<Compile Include="Menu\MainMenu\ScenePage.cs" />
125-
<Compile Include="Menu\MainMenu\SearchPage.cs" />
126-
<Compile Include="Menu\UIStyles.cs" />
126+
<Compile Include="MainMenu\MainMenu.cs" />
127+
<Compile Include="Inspectors\GameObjectWindow.cs" />
128+
<Compile Include="Inspectors\ReflectionWindow.cs" />
129+
<Compile Include="MainMenu\Pages\ScenePage.cs" />
130+
<Compile Include="MainMenu\Pages\SearchPage.cs" />
131+
<Compile Include="UIStyles.cs" />
127132
<Compile Include="Properties\AssemblyInfo.cs" />
128133
<Compile Include="utils\AccessTools.cs" />
129134
</ItemGroup>
File renamed without changes.
File renamed without changes.

src/Menu/MainMenu.cs renamed to src/MainMenu/MainMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public MainMenu()
1919

2020
Pages.Add(new ScenePage());
2121
Pages.Add(new SearchPage());
22-
//Pages.Add(new ConsolePage());
22+
Pages.Add(new ConsolePage());
2323

2424
foreach (var page in Pages)
2525
{

src/MainMenu/Pages/Console/REPL.cs

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using Mono.CSharp;
8+
using UnityEngine;
9+
using Attribute = System.Attribute;
10+
using Object = UnityEngine.Object;
11+
12+
namespace Explorer
13+
{
14+
public class REPL : InteractiveBase
15+
{
16+
static REPL()
17+
{
18+
var go = new GameObject("UnityREPL");
19+
GameObject.DontDestroyOnLoad(go);
20+
//go.transform.parent = HPExplorer.Instance.transform;
21+
MB = go.AddComponent<ReplHelper>();
22+
}
23+
24+
[Documentation("MB - A dummy MonoBehaviour for accessing Unity.")]
25+
public static ReplHelper MB { get; }
26+
27+
[Documentation("find<T>() - find a UnityEngine.Object of type T.")]
28+
public static T find<T>() where T : Object
29+
{
30+
return MB.Find<T>();
31+
}
32+
33+
[Documentation("findAll<T>() - find all UnityEngine.Object of type T.")]
34+
public static T[] findAll<T>() where T : Object
35+
{
36+
return MB.FindAll<T>();
37+
}
38+
39+
[Documentation("runCoroutine(enumerator) - runs an IEnumerator as a Unity coroutine.")]
40+
public static object runCoroutine(IEnumerator i)
41+
{
42+
return MB.RunCoroutine(i);
43+
}
44+
45+
[Documentation("endCoroutine(co) - ends a Unity coroutine.")]
46+
public static void endCoroutine(Coroutine c)
47+
{
48+
MB.EndCoroutine(c);
49+
}
50+
51+
////[Documentation("type<T>() - obtain type info about a type T. Provides some Reflection helpers.")]
52+
////public static TypeHelper type<T>()
53+
////{
54+
//// return new TypeHelper(typeof(T));
55+
////}
56+
57+
////[Documentation("type(obj) - obtain type info about object obj. Provides some Reflection helpers.")]
58+
////public static TypeHelper type(object instance)
59+
////{
60+
//// return new TypeHelper(instance);
61+
////}
62+
63+
//[Documentation("dir(obj) - lists all available methods and fiels of a given obj.")]
64+
//public static string dir(object instance)
65+
//{
66+
// return type(instance).info();
67+
//}
68+
69+
//[Documentation("dir<T>() - lists all available methods and fields of type T.")]
70+
//public static string dir<T>()
71+
//{
72+
// return type<T>().info();
73+
//}
74+
75+
//[Documentation("findrefs(obj) - find references to the object in currently loaded components.")]
76+
//public static Component[] findrefs(object obj)
77+
//{
78+
// if (obj == null) throw new ArgumentNullException(nameof(obj));
79+
80+
// var results = new List<Component>();
81+
// foreach (var component in Object.FindObjectsOfType<Component>())
82+
// {
83+
// var type = component.GetType();
84+
85+
// var nameBlacklist = new[] { "parent", "parentInternal", "root", "transform", "gameObject" };
86+
// var typeBlacklist = new[] { typeof(bool) };
87+
88+
// foreach (var prop in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
89+
// .Where(x => x.CanRead && !nameBlacklist.Contains(x.Name) && !typeBlacklist.Contains(x.PropertyType)))
90+
// {
91+
// try
92+
// {
93+
// if (Equals(prop.GetValue(component, null), obj))
94+
// {
95+
// results.Add(component);
96+
// goto finish;
97+
// }
98+
// }
99+
// catch { }
100+
// }
101+
// foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
102+
// .Where(x => !nameBlacklist.Contains(x.Name) && !typeBlacklist.Contains(x.FieldType)))
103+
// {
104+
// try
105+
// {
106+
// if (Equals(field.GetValue(component), obj))
107+
// {
108+
// results.Add(component);
109+
// goto finish;
110+
// }
111+
// }
112+
// catch { }
113+
// }
114+
// finish:;
115+
// }
116+
117+
// return results.ToArray();
118+
//}
119+
120+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
121+
private class DocumentationAttribute : Attribute
122+
{
123+
public DocumentationAttribute(string doc)
124+
{
125+
Docs = doc;
126+
}
127+
128+
public string Docs { get; }
129+
}
130+
}
131+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections;
2+
//using Il2CppSystem;
3+
using MelonLoader;
4+
using UnityEngine;
5+
using System;
6+
using Object = UnityEngine.Object;
7+
8+
namespace Explorer
9+
{
10+
public class ReplHelper : MonoBehaviour
11+
{
12+
public ReplHelper(IntPtr intPtr) : base(intPtr) { }
13+
14+
public T Find<T>() where T : Object
15+
{
16+
return FindObjectOfType<T>();
17+
}
18+
19+
public T[] FindAll<T>() where T : Object
20+
{
21+
return FindObjectsOfType<T>();
22+
}
23+
24+
public object RunCoroutine(IEnumerator enumerator)
25+
{
26+
return MelonCoroutines.Start(enumerator);
27+
}
28+
29+
public void EndCoroutine(Coroutine c)
30+
{
31+
StopCoroutine(c);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)