Skip to content

Commit

Permalink
Cleanup remaining IL2CPP related code
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmachine committed Dec 5, 2023
1 parent b558bad commit 1c57d6e
Show file tree
Hide file tree
Showing 18 changed files with 19 additions and 1,742 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
This is a fork of [UnityExplorer](https://github.com/sinai-dev/UnityExplorer), modified to work as a standalone Kerbal Space Program plugin :
- Uses Harmony instead of HarmonyX
- Uses a forked version of UniverseLib wich also uses Harmony instead of HarmonyX
- All dependencies, and notably `Mono.Cecil` are packed in the assembly to avoid conflicts with the outdated `Mono.Cecil` bundled with KSP.
- All dependencies, and notably `Mono.Cecil` are IL-packed and internalized in the assembly to avoid conflicts with the outdated `Mono.Cecil` bundled with KSP.
- Removed unused code (IL2CPP support, bepinex/melon loaders...)

### Dependencies
- [HarmonyKSP](https://github.com/KSPModdingLibs/HarmonyKSP)

# Features

<p align="center">
Expand Down
Binary file modified lib_notpacked/UniverseLibKSP.dll
Binary file not shown.
1,462 changes: 0 additions & 1,462 deletions lib_notpacked/UniverseLibKSP.xml

This file was deleted.

6 changes: 1 addition & 5 deletions src/CSConsole/ConsoleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ public static class ConsoleController
"System.Collections.Generic",
"System.Reflection",
"UnityEngine",
"UniverseLib",
#if CPP
"UnhollowerBaseLib",
"UnhollowerRuntimeLib",
#endif
"UniverseLib"
};

const int CSCONSOLE_LINEHEIGHT = 18;
Expand Down
2 changes: 0 additions & 2 deletions src/Config/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public static void Init(ConfigHandler configHandler)
Handler.LoadConfig();
InternalHandler.LoadConfig();

#if STANDALONE
Loader.Standalone.ExplorerEditorBehaviour.Instance?.LoadConfigs();
#endif
}

internal static void RegisterConfigElement<T>(ConfigElement<T> configElement)
Expand Down
15 changes: 0 additions & 15 deletions src/ExplorerBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
using UnityExplorer.UI;
#if CPP
#if UNHOLLOWER
using UnhollowerRuntimeLib;
#else
using Il2CppInterop.Runtime.Injection;
#endif
#endif

namespace UnityExplorer
{
public class ExplorerBehaviour : MonoBehaviour
{
internal static ExplorerBehaviour Instance { get; private set; }

#if CPP
public ExplorerBehaviour(System.IntPtr ptr) : base(ptr) { }
#endif

internal static void Setup()
{
#if CPP
ClassInjector.RegisterTypeInIl2Cpp<ExplorerBehaviour>();
#endif

GameObject obj = new("ExplorerBehaviour");
DontDestroyOnLoad(obj);
obj.hideFlags = HideFlags.HideAndDontSave;
Expand Down
61 changes: 1 addition & 60 deletions src/ExplorerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class ExplorerCore

public static IExplorerLoader Loader { get; private set; }
public static string ExplorerFolder => Path.Combine(Loader.ExplorerFolderDestination, Loader.ExplorerFolderName);
public const string DEFAULT_EXPLORER_FOLDER_NAME = "sinai-dev-UnityExplorer";
public const string DEFAULT_EXPLORER_FOLDER_NAME = "PluginData";

public static HarmonyLib.Harmony Harmony { get; } = new HarmonyLib.Harmony(GUID);

Expand All @@ -41,7 +41,6 @@ public static void Init(IExplorerLoader loader)

Log($"{NAME} {VERSION} initializing...");

CheckLegacyExplorerFolder();
Directory.CreateDirectory(ExplorerFolder);
ConfigManager.Init(Loader.ConfigHandler);

Expand Down Expand Up @@ -127,63 +126,5 @@ private static void Log(object message, LogType logType)
}

#endregion


#region LEGACY FOLDER MIGRATION

// Can be removed eventually. For migration from <4.7.0
static void CheckLegacyExplorerFolder()
{
string legacyPath = Path.Combine(Loader.ExplorerFolderDestination, "UnityExplorer");
if (Directory.Exists(legacyPath))
{
LogWarning($"Attempting to migrate old 'UnityExplorer/' folder to 'sinai-dev-UnityExplorer/'...");

// If new folder doesn't exist yet, let's just use Move().
if (!Directory.Exists(ExplorerFolder))
{
try
{
Directory.Move(legacyPath, ExplorerFolder);
Log("Migrated successfully.");
}
catch (Exception ex)
{
LogWarning($"Exception migrating folder: {ex}");
}
}
else // We have to merge
{
try
{
CopyAll(new(legacyPath), new(ExplorerFolder));
Directory.Delete(legacyPath, true);
Log("Migrated successfully.");
}
catch (Exception ex)
{
LogWarning($"Exception migrating folder: {ex}");
}
}
}
}

public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
Directory.CreateDirectory(target.FullName);

// Copy each file into it's new directory.
foreach (FileInfo fi in source.GetFiles())
fi.MoveTo(Path.Combine(target.ToString(), fi.Name));

// Copy each subdirectory using recursion.
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}

#endregion
}
}
6 changes: 2 additions & 4 deletions src/Loader/Standalone/Editor/ExplorerEditorBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if STANDALONE
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -55,5 +54,4 @@ internal void LoadConfigs()
ConfigManager.Disable_EventSystem_Override.Value = this.Disable_EventSystem_Override;
}
}
}
#endif
}
6 changes: 2 additions & 4 deletions src/Loader/Standalone/Editor/ExplorerEditorLoader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if STANDALONE
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -39,5 +38,4 @@ protected override void CheckExplorerFolder()
explorerFolderDest = Path.GetDirectoryName(Application.dataPath);
}
}
}
#endif
}
9 changes: 2 additions & 7 deletions src/Loader/Standalone/ExplorerStandalone.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if STANDALONE
using HarmonyLib;
using HarmonyLib;
using System;
using System.IO;
using System.Reflection;
Expand All @@ -8,9 +7,6 @@
using UnityEngine.EventSystems;
using UniverseLib.Input;
using UnityExplorer.Loader.Standalone;
#if CPP
using UnhollowerRuntimeLib;
#endif

namespace UnityExplorer
{
Expand Down Expand Up @@ -102,5 +98,4 @@ protected virtual void CheckExplorerFolder()
}
}
}
}
#endif
}
7 changes: 2 additions & 5 deletions src/Loader/Standalone/StandaloneConfigHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if STANDALONE
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -98,6 +97,4 @@ public override void SaveConfig()
File.WriteAllText(CONFIG_PATH, document.SerializedValue);
}
}
}

#endif
}
2 changes: 1 addition & 1 deletion src/UEKSPLoader.cs → src/Loader/UEKSPLoader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace UnityExplorer
{
[KSPAddon(KSPAddon.Startup.Instantly, false)]
public class UEKSPLoader : MonoBehaviour
public class UnityExplorerKSPLoader : MonoBehaviour
{
void Start()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
[assembly: AssemblyVersion(ExplorerCore.VERSION)]
[assembly: AssemblyFileVersion(ExplorerCore.VERSION)]
[assembly: KSPAssembly("UnityExplorerKSP", 1, 0)]
[assembly: KSPAssemblyDependency("UniverseLibKSP", 1, 0)]
[assembly: KSPAssemblyDependency("UniverseLibKSP", 1, 0)]
[assembly: KSPAssemblyDependency("HarmonyKSP", 1, 0)]
8 changes: 2 additions & 6 deletions src/Runtime/MonoHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if MONO

namespace UnityExplorer.Runtime
namespace UnityExplorer.Runtime
{
public class MonoHelper : UERuntimeHelper
{
Expand All @@ -12,6 +10,4 @@ public override void SetupEvents()
private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
=> ExplorerCore.LogUnity(condition, type);
}
}

#endif
}
Loading

0 comments on commit 1c57d6e

Please sign in to comment.