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

Commit eee7d6b

Browse files
committed
Add ML 0.3.0 build
1 parent e270f20 commit eee7d6b

File tree

7 files changed

+542
-349
lines changed

7 files changed

+542
-349
lines changed
453 KB
Binary file not shown.

src/Core/Input/CursorUnlocker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using UnityExplorer.Core;
88
using UnityExplorer.UI;
99
using System.Collections;
10-
using HarmonyLib;
10+
1111

1212
namespace UnityExplorer.Core.Input
1313
{

src/ILRepack.targets

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

44
<Target Name="ILRepacker" AfterTargets="Build">
5+
<!-- Actual merged assemblies -->
56
<ItemGroup>
67
<InputAssemblies Include="$(OutputPath)$(AssemblyName).dll" />
78
<InputAssemblies Include="..\lib\mcs-unity\mcs\bin\Release\mcs.dll" />
89
<InputAssemblies Include="packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll" />
910
</ItemGroup>
11+
12+
<!-- MonoMod for MelonLoader 0.3.0 -->
13+
<ItemGroup Condition="'$(IsMelonLoaderLegacy)'=='true'">
14+
<InputAssemblies Include="..\lib\HarmonyX\Harmony\bin\Release\net45\Mono.Cecil.dll" />
15+
<InputAssemblies Include="..\lib\HarmonyX\Harmony\bin\Release\net45\Mono.Cecil.Mdb.dll" />
16+
<InputAssemblies Include="..\lib\HarmonyX\Harmony\bin\Release\net45\Mono.Cecil.Pdb.dll" />
17+
<InputAssemblies Include="..\lib\HarmonyX\Harmony\bin\Release\net45\Mono.Cecil.Rocks.dll" />
18+
<InputAssemblies Include="..\lib\HarmonyX\Harmony\bin\Release\net45\MonoMod.RuntimeDetour.dll" />
19+
<InputAssemblies Include="..\lib\HarmonyX\Harmony\bin\Release\net45\MonoMod.Utils.dll" />
20+
</ItemGroup>
21+
22+
<!-- Required references for ILRepack -->
1023
<ItemGroup>
1124
<ReferenceFolders Include="..\lib\" />
1225
<ReferenceFolders Include="..\lib\HarmonyX\Harmony\bin\Release\net35\" />
@@ -15,6 +28,7 @@
1528
<ReferenceFolders Include="..\lib\BepInEx.5\" />
1629
<ReferenceFolders Include="..\lib\MelonLoader\" />
1730
</ItemGroup>
31+
1832
<ILRepack
1933
Parallel="true"
2034
Internalize="true"

src/Loader/ML/ExplorerMelonMod.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
using UnityExplorer.Core.Config;
1010
using UnityExplorer.Core.Input;
1111
using UnityExplorer.Loader.ML;
12+
#if ML_LEGACY
13+
using Harmony;
14+
#else
1215
using HarmonyLib;
16+
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL)]
17+
#endif
1318

1419
[assembly: MelonInfo(typeof(ExplorerMelonMod), ExplorerCore.NAME, ExplorerCore.VERSION, ExplorerCore.AUTHOR)]
1520
[assembly: MelonGame(null, null)]
16-
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL)]
1721
[assembly: MelonColor(ConsoleColor.DarkCyan)]
1822

1923
namespace UnityExplorer
@@ -67,7 +71,11 @@ private void PrefixProperty(Type type, string property, HarmonyMethod prefix)
6771
try
6872
{
6973
var prop = type.GetProperty(property);
74+
#if ML_LEGACY
75+
this.Harmony.Patch(prop.GetSetMethod(), prefix: prefix);
76+
#else
7077
HarmonyInstance.Patch(prop.GetSetMethod(), prefix: prefix);
78+
#endif
7179
}
7280
catch (Exception e)
7381
{

src/Loader/ML/MelonLoaderConfigHandler.cs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#if ML
2+
3+
#if !ML_LEGACY // ML 0.3.1+ config handler
4+
25
using MelonLoader;
36
using System;
47
using System.Collections.Generic;
@@ -75,4 +78,129 @@ public override void SaveConfig()
7578
}
7679
}
7780

81+
#else // ML 0.3.0 config handler
82+
83+
using MelonLoader;
84+
using MelonLoader.Tomlyn.Model;
85+
using System;
86+
using System.Collections.Generic;
87+
using System.Linq;
88+
using System.Text;
89+
using UnityEngine;
90+
using UnityExplorer.Core;
91+
using UnityExplorer.Core.Config;
92+
93+
namespace UnityExplorer.Loader.ML
94+
{
95+
public class MelonLoaderConfigHandler : ConfigHandler
96+
{
97+
internal const string CTG_NAME = "UnityExplorer";
98+
99+
internal MelonPreferences_Category prefCategory;
100+
101+
public override void Init()
102+
{
103+
prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings");
104+
105+
try { MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter); } catch { }
106+
try { MelonPreferences.Mapper.RegisterMapper(AnchorReader, AnchorWriter); } catch { }
107+
}
108+
109+
public override void LoadConfig()
110+
{
111+
foreach (var entry in ConfigManager.ConfigElements)
112+
{
113+
var key = entry.Key;
114+
if (prefCategory.GetEntry(key) is MelonPreferences_Entry)
115+
{
116+
var config = entry.Value;
117+
config.BoxedValue = config.GetLoaderConfigValue();
118+
}
119+
}
120+
}
121+
122+
public override void RegisterConfigElement<T>(ConfigElement<T> config)
123+
{
124+
var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry<T>;
125+
126+
entry.OnValueChangedUntyped += () =>
127+
{
128+
if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value))
129+
return;
130+
131+
config.Value = entry.Value;
132+
};
133+
}
134+
135+
public override void SetConfigValue<T>(ConfigElement<T> config, T value)
136+
{
137+
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
138+
{
139+
entry.Value = value;
140+
entry.Save();
141+
}
142+
}
143+
144+
public override T GetConfigValue<T>(ConfigElement<T> config)
145+
{
146+
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
147+
return entry.Value;
148+
149+
return default;
150+
}
151+
152+
public override void OnAnyConfigChanged()
153+
{
154+
}
155+
156+
public override void SaveConfig()
157+
{
158+
MelonPreferences.Save();
159+
}
160+
161+
// Enum config handlers
162+
163+
public static KeyCode KeycodeReader(TomlObject value)
164+
{
165+
try
166+
{
167+
KeyCode kc = (KeyCode)Enum.Parse(typeof(KeyCode), (value as TomlString).Value);
168+
169+
if (kc == default)
170+
throw new Exception();
171+
172+
return kc;
173+
}
174+
catch
175+
{
176+
return KeyCode.F7;
177+
}
178+
}
179+
180+
public static TomlObject KeycodeWriter(KeyCode value)
181+
{
182+
return MelonPreferences.Mapper.ToToml(value.ToString());
183+
}
184+
185+
public static UI.UIManager.VerticalAnchor AnchorReader(TomlObject value)
186+
{
187+
try
188+
{
189+
return (UI.UIManager.VerticalAnchor)Enum.Parse(typeof(UI.UIManager.VerticalAnchor), (value as TomlString).Value);
190+
}
191+
catch
192+
{
193+
return UI.UIManager.VerticalAnchor.Top;
194+
}
195+
}
196+
197+
public static TomlObject AnchorWriter(UI.UIManager.VerticalAnchor anchor)
198+
{
199+
return MelonPreferences.Mapper.ToToml(anchor.ToString());
200+
}
201+
}
202+
}
203+
204+
#endif
205+
78206
#endif

0 commit comments

Comments
 (0)