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

Commit be635e4

Browse files
committed
Swapping to INI instead of XML config, including an AssetBundle for old (5.6.1) Unity versions.
1 parent 687f56e commit be635e4

File tree

9 files changed

+63
-25
lines changed

9 files changed

+63
-25
lines changed

lib/INIFileParser.dll

28 KB
Binary file not shown.

resources/Older Unity bundle/THIS BUNDLE IS FOR UNITY 5.6.1 AND OLDER.txt

Whitespace-only changes.
213 KB
Binary file not shown.

resources/explorerui.bundle

-422 Bytes
Binary file not shown.

src/Config/ModConfig.cs

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
using System;
22
using System.IO;
3-
using System.Xml.Serialization;
43
using UnityEngine;
4+
using IniParser;
5+
using IniParser.Parser;
56

67
namespace UnityExplorer.Config
78
{
89
public class ModConfig
910
{
10-
[XmlIgnore] public static readonly XmlSerializer Serializer = new XmlSerializer(typeof(ModConfig));
11+
public static ModConfig Instance;
1112

12-
//[XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\UnityExplorer";
13-
[XmlIgnore] private const string SETTINGS_PATH = ExplorerCore.EXPLORER_FOLDER + @"\config.xml";
13+
internal static readonly IniDataParser _parser = new IniDataParser();
14+
internal const string INI_PATH = ExplorerCore.EXPLORER_FOLDER + @"\config.ini";
1415

15-
[XmlIgnore] public static ModConfig Instance;
16+
static ModConfig()
17+
{
18+
_parser.Configuration.CommentString = "#";
19+
}
1620

1721
// Actual configs
1822
public KeyCode Main_Menu_Toggle = KeyCode.F7;
@@ -31,38 +35,66 @@ internal static void InvokeConfigChanged()
3135

3236
public static void OnLoad()
3337
{
38+
Instance = new ModConfig();
39+
3440
if (LoadSettings())
3541
return;
3642

37-
Instance = new ModConfig();
3843
SaveSettings();
3944
}
4045

4146
public static bool LoadSettings()
4247
{
43-
if (!File.Exists(SETTINGS_PATH))
48+
if (!File.Exists(INI_PATH))
4449
return false;
4550

46-
try
47-
{
48-
using (var file = File.OpenRead(SETTINGS_PATH))
49-
Instance = (ModConfig)Serializer.Deserialize(file);
50-
}
51-
catch
51+
string ini = File.ReadAllText(INI_PATH);
52+
53+
var data = _parser.Parse(ini);
54+
55+
foreach (var config in data.Sections["Config"])
5256
{
53-
return false;
57+
switch (config.KeyName)
58+
{
59+
case "Main_Menu_Toggle":
60+
Instance.Main_Menu_Toggle = (KeyCode)Enum.Parse(typeof(KeyCode), config.Value);
61+
break;
62+
case "Force_Unlock_Mouse":
63+
Instance.Force_Unlock_Mouse = bool.Parse(config.Value);
64+
break;
65+
case "Default_Page_Limit":
66+
Instance.Default_Page_Limit = int.Parse(config.Value);
67+
break;
68+
case "Log_Unity_Debug":
69+
Instance.Log_Unity_Debug = bool.Parse(config.Value);
70+
break;
71+
case "Save_Logs_To_Disk":
72+
Instance.Save_Logs_To_Disk = bool.Parse(config.Value);
73+
break;
74+
case "Default_Output_Path":
75+
Instance.Default_Output_Path = config.Value;
76+
break;
77+
}
5478
}
5579

56-
return Instance != null;
80+
return true;
5781
}
5882

5983
public static void SaveSettings()
6084
{
61-
if (File.Exists(SETTINGS_PATH))
62-
File.Delete(SETTINGS_PATH);
85+
var data = new IniParser.Model.IniData();
86+
87+
data.Sections.AddSection("Config");
88+
89+
var sec = data.Sections["Config"];
90+
sec.AddKey("Main_Menu_Toggle", Instance.Main_Menu_Toggle.ToString());
91+
sec.AddKey("Force_Unlock_Mouse", Instance.Force_Unlock_Mouse.ToString());
92+
sec.AddKey("Default_Page_Limit", Instance.Default_Page_Limit.ToString());
93+
sec.AddKey("Log_Unity_Debug", Instance.Log_Unity_Debug.ToString());
94+
sec.AddKey("Save_Logs_To_Disk", Instance.Save_Logs_To_Disk.ToString());
95+
sec.AddKey("Default_Output_Path", Instance.Default_Output_Path);
6396

64-
using (var file = File.Create(SETTINGS_PATH))
65-
Serializer.Serialize(file, Instance);
97+
File.WriteAllText(INI_PATH, data.ToString());
6698
}
6799
}
68100
}

src/ILRepack.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<ItemGroup>
66
<InputAssemblies Include="$(OutputPath)$(AssemblyName).dll" />
77
<InputAssemblies Include="..\lib\mcs.dll" />
8+
<InputAssemblies Include="..\lib\INIFileParser.dll" />
89
</ItemGroup>
910

1011
<ILRepack

src/UI/UIManager.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using UnityExplorer.Inspectors;
55
using UnityExplorer.UI.Modules;
66
using System.IO;
7-
//using TMPro;
87
using System.Reflection;
98
using UnityExplorer.Helpers;
109
using UnityExplorer.UI.Shared;
@@ -20,9 +19,11 @@ public static class UIManager
2019
public static GameObject CanvasRoot { get; private set; }
2120
public static EventSystem EventSys { get; private set; }
2221

23-
internal static Sprite ResizeCursor { get; private set; }
2422
internal static Font ConsoleFont { get; private set; }
2523

24+
internal static Sprite ResizeCursor { get; private set; }
25+
internal static Shader BackupShader { get; private set; }
26+
2627
public static void Init()
2728
{
2829
LoadBundle();
@@ -100,11 +101,13 @@ private static void LoadBundle()
100101
{
101102
var bundle = AssetBundle.LoadFromFile(bundlePath);
102103

104+
BackupShader = bundle.LoadAsset<Shader>("DefaultUI");
105+
103106
// Fix for games which don't ship with 'UI/Default' shader.
104107
if (Graphic.defaultGraphicMaterial.shader?.name != "UI/Default")
105108
{
106109
ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader...");
107-
Graphic.defaultGraphicMaterial.shader = bundle.LoadAsset<Shader>("DefaultUI");
110+
Graphic.defaultGraphicMaterial.shader = BackupShader;
108111
}
109112

110113
ResizeCursor = bundle.LoadAsset<Sprite>("cursor");

src/UnityExplorer.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424
<PlatformTarget>x64</PlatformTarget>
2525
<Prefer32Bit>false</Prefer32Bit>
2626
<RootNamespace>UnityExplorer</RootNamespace>
27-
2827
<!-- Set this to the BepInEx Il2Cpp Game folder, without the ending '\' character. -->
2928
<BIECppGameFolder>D:\source\Unity Projects\Test\_BUILD</BIECppGameFolder>
30-
3129
<!-- Set this to the MelonLoader Il2Cpp Game folder, without the ending '\' character. -->
3230
<MLCppGameFolder>D:\source\Unity Projects\Test\_BUILD</MLCppGameFolder>
33-
3431
<NuGetPackageImportStamp>
3532
</NuGetPackageImportStamp>
3633
</PropertyGroup>
@@ -72,6 +69,10 @@
7269
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7370
</PropertyGroup>
7471
<ItemGroup>
72+
<Reference Include="INIFileParser, Version=2.5.2.0, Culture=neutral, PublicKeyToken=79af7b307b65cf3c, processorArchitecture=MSIL">
73+
<HintPath>packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll</HintPath>
74+
<Private>False</Private>
75+
</Reference>
7576
<Reference Include="System" />
7677
<Reference Include="System.Core" />
7778
<Reference Include="System.Xml.Linq" />

src/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.1" targetFramework="net472" />
4+
<package id="ini-parser" version="2.5.2" targetFramework="net35" />
45
</packages>

0 commit comments

Comments
 (0)