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

Commit

Permalink
REPL console
Browse files Browse the repository at this point in the history
  • Loading branch information
sinai-dev committed Aug 7, 2020
1 parent df3b416 commit 28ba5af
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 412 deletions.
Binary file modified Release/CppExplorer.dll
Binary file not shown.
Binary file added Release/CppExplorer.zip
Binary file not shown.
Binary file added Release/mcs.dll
Binary file not shown.
35 changes: 17 additions & 18 deletions src/CppExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,31 @@ public override void OnApplicationStart()

Instance = this;

LoadMCS();

new MainMenu();
new WindowManager();

//LoadMCS();

//// init debugging hooks
//var harmony = HarmonyInstance.Create(ID);
//harmony.PatchAll();
var harmony = HarmonyInstance.Create(ID);
harmony.PatchAll();

// done init
ShowMenu = true;
}

//private void LoadMCS()
//{
// var mcsPath = @"Mods\mcs.dll";
// if (File.Exists(mcsPath))
// {
// Assembly.Load(File.ReadAllBytes(mcsPath));
// MelonLogger.Log("Loaded mcs.dll");
// }
// else
// {
// MelonLogger.LogError("Could not find mcs.dll!");
// }
//}
private void LoadMCS()
{
var mcsPath = @"Mods\mcs.dll";
if (File.Exists(mcsPath))
{
Assembly.Load(File.ReadAllBytes(mcsPath));
MelonLogger.Log("Loaded mcs.dll");
}
else
{
MelonLogger.LogError("Could not find mcs.dll!");
}
}

public override void OnLevelWasLoaded(int level)
{
Expand Down
23 changes: 14 additions & 9 deletions src/CppExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\Il2CppSystem.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="mcs, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Release\mcs.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MelonLoader.ModHandler">
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\MelonLoader.ModHandler.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -114,16 +119,16 @@
<ItemGroup>
<Compile Include="ILBehaviour.cs" />
<Compile Include="CppExplorer.cs" />
<Compile Include="Menu\MainMenu\ConsolePage.cs" />
<Compile Include="Menu\MainMenu\Console\REPL.cs" />
<Compile Include="Menu\MainMenu\Console\REPLHelper.cs" />
<Compile Include="MainMenu\Pages\ConsolePage.cs" />
<Compile Include="MainMenu\Pages\Console\REPL.cs" />
<Compile Include="MainMenu\Pages\Console\REPLHelper.cs" />
<Compile Include="WindowManager.cs" />
<Compile Include="Menu\MainMenu.cs" />
<Compile Include="Menu\Inspectors\GameObjectWindow.cs" />
<Compile Include="Menu\Inspectors\ReflectionWindow.cs" />
<Compile Include="Menu\MainMenu\ScenePage.cs" />
<Compile Include="Menu\MainMenu\SearchPage.cs" />
<Compile Include="Menu\UIStyles.cs" />
<Compile Include="MainMenu\MainMenu.cs" />
<Compile Include="Inspectors\GameObjectWindow.cs" />
<Compile Include="Inspectors\ReflectionWindow.cs" />
<Compile Include="MainMenu\Pages\ScenePage.cs" />
<Compile Include="MainMenu\Pages\SearchPage.cs" />
<Compile Include="UIStyles.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="utils\AccessTools.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Menu/MainMenu.cs → src/MainMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public MainMenu()

Pages.Add(new ScenePage());
Pages.Add(new SearchPage());
//Pages.Add(new ConsolePage());
Pages.Add(new ConsolePage());

foreach (var page in Pages)
{
Expand Down
131 changes: 131 additions & 0 deletions src/MainMenu/Pages/Console/REPL.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Mono.CSharp;
using UnityEngine;
using Attribute = System.Attribute;
using Object = UnityEngine.Object;

namespace Explorer
{
public class REPL : InteractiveBase
{
static REPL()
{
var go = new GameObject("UnityREPL");
GameObject.DontDestroyOnLoad(go);
//go.transform.parent = HPExplorer.Instance.transform;
MB = go.AddComponent<ReplHelper>();
}

[Documentation("MB - A dummy MonoBehaviour for accessing Unity.")]
public static ReplHelper MB { get; }

[Documentation("find<T>() - find a UnityEngine.Object of type T.")]
public static T find<T>() where T : Object
{
return MB.Find<T>();
}

[Documentation("findAll<T>() - find all UnityEngine.Object of type T.")]
public static T[] findAll<T>() where T : Object
{
return MB.FindAll<T>();
}

[Documentation("runCoroutine(enumerator) - runs an IEnumerator as a Unity coroutine.")]
public static object runCoroutine(IEnumerator i)
{
return MB.RunCoroutine(i);
}

[Documentation("endCoroutine(co) - ends a Unity coroutine.")]
public static void endCoroutine(Coroutine c)
{
MB.EndCoroutine(c);
}

////[Documentation("type<T>() - obtain type info about a type T. Provides some Reflection helpers.")]
////public static TypeHelper type<T>()
////{
//// return new TypeHelper(typeof(T));
////}

////[Documentation("type(obj) - obtain type info about object obj. Provides some Reflection helpers.")]
////public static TypeHelper type(object instance)
////{
//// return new TypeHelper(instance);
////}

//[Documentation("dir(obj) - lists all available methods and fiels of a given obj.")]
//public static string dir(object instance)
//{
// return type(instance).info();
//}

//[Documentation("dir<T>() - lists all available methods and fields of type T.")]
//public static string dir<T>()
//{
// return type<T>().info();
//}

//[Documentation("findrefs(obj) - find references to the object in currently loaded components.")]
//public static Component[] findrefs(object obj)
//{
// if (obj == null) throw new ArgumentNullException(nameof(obj));

// var results = new List<Component>();
// foreach (var component in Object.FindObjectsOfType<Component>())
// {
// var type = component.GetType();

// var nameBlacklist = new[] { "parent", "parentInternal", "root", "transform", "gameObject" };
// var typeBlacklist = new[] { typeof(bool) };

// foreach (var prop in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
// .Where(x => x.CanRead && !nameBlacklist.Contains(x.Name) && !typeBlacklist.Contains(x.PropertyType)))
// {
// try
// {
// if (Equals(prop.GetValue(component, null), obj))
// {
// results.Add(component);
// goto finish;
// }
// }
// catch { }
// }
// foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
// .Where(x => !nameBlacklist.Contains(x.Name) && !typeBlacklist.Contains(x.FieldType)))
// {
// try
// {
// if (Equals(field.GetValue(component), obj))
// {
// results.Add(component);
// goto finish;
// }
// }
// catch { }
// }
// finish:;
// }

// return results.ToArray();
//}

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
private class DocumentationAttribute : Attribute
{
public DocumentationAttribute(string doc)
{
Docs = doc;
}

public string Docs { get; }
}
}
}
34 changes: 34 additions & 0 deletions src/MainMenu/Pages/Console/REPLHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections;
//using Il2CppSystem;
using MelonLoader;
using UnityEngine;
using System;
using Object = UnityEngine.Object;

namespace Explorer
{
public class ReplHelper : MonoBehaviour
{
public ReplHelper(IntPtr intPtr) : base(intPtr) { }

public T Find<T>() where T : Object
{
return FindObjectOfType<T>();
}

public T[] FindAll<T>() where T : Object
{
return FindObjectsOfType<T>();
}

public object RunCoroutine(IEnumerator enumerator)
{
return MelonCoroutines.Start(enumerator);
}

public void EndCoroutine(Coroutine c)
{
StopCoroutine(c);
}
}
}
Loading

0 comments on commit 28ba5af

Please sign in to comment.