Skip to content

Commit fbb97cf

Browse files
author
Balint66
committed
using the game as a framework
1 parent 017088c commit fbb97cf

14 files changed

Lines changed: 183 additions & 129 deletions

File tree

BugReportDisablerPlugin/BugReportDisablerPlugin.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void start(MonoBehaviour root)
3030
try
3131
{
3232
// disable the bug reporter
33-
Logger.getInstance().info("Disabling error reports ...");
33+
Logger.Instance.info("Disabling error reports ...");
3434

3535
var bugReporterManager = UnityEngine.GameObject.FindObjectOfType<BugReporterManager>();
3636
Traverse.Create(bugReporterManager).Field("exceptionCaught").SetValue(true);
@@ -39,7 +39,7 @@ public void start(MonoBehaviour root)
3939
}
4040
catch (Exception e)
4141
{
42-
Logger.getInstance().info(e.ToString());
42+
Logger.Instance.info(e.ToString());
4343
throw;
4444
}
4545

@@ -56,7 +56,7 @@ public void disable(MonoBehaviour root)
5656
try
5757
{
5858
// disable the bug reporter
59-
Logger.getInstance().info("Disabling error reports ...");
59+
Logger.Instance.info("Disabling error reports ...");
6060

6161
var bugReporterManager = UnityEngine.GameObject.FindObjectOfType<BugReporterManager>();
6262
Traverse.Create(bugReporterManager).Field("exceptionCaught").SetValue(false);
@@ -65,7 +65,7 @@ public void disable(MonoBehaviour root)
6565
}
6666
catch (Exception e)
6767
{
68-
Logger.getInstance().info(e.ToString());
68+
Logger.Instance.info(e.ToString());
6969
throw;
7070
}
7171
}

BugReportDisablerPlugin/BugReportDisablerPlugin.csproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<DebugSymbols>false</DebugSymbols>
1818
<DebugType>none</DebugType>
1919
<Optimize>false</Optimize>
20-
<OutputPath>C:\dev\steam\steamapps\common\Going Medieval\Mods\</OutputPath>
20+
<OutputPath>d:\Games\Steam\steamapps\common\Going Medieval\mods\</OutputPath>
2121
<DefineConstants>DEBUG;TRACE</DefineConstants>
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
@@ -26,7 +26,7 @@
2626
<PlatformTarget>AnyCPU</PlatformTarget>
2727
<DebugType>pdbonly</DebugType>
2828
<Optimize>true</Optimize>
29-
<OutputPath>bin\Release\</OutputPath>
29+
<OutputPath>d:\Games\Steam\steamapps\common\Going Medieval\mods\</OutputPath>
3030
<DefineConstants>TRACE</DefineConstants>
3131
<ErrorReport>prompt</ErrorReport>
3232
<WarningLevel>4</WarningLevel>
@@ -37,16 +37,14 @@
3737
<Private>False</Private>
3838
</Reference>
3939
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
40-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\Assembly-CSharp.dll</HintPath>
41-
<Private>False</Private>
40+
<HintPath>..\libs\Assembly-CSharp.dll</HintPath>
4241
</Reference>
4342
<Reference Include="System" />
4443
<Reference Include="System.Core" />
4544
<Reference Include="System.Data" />
4645
<Reference Include="System.Xml" />
4746
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
48-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
49-
<Private>False</Private>
47+
<HintPath>..\libs\UnityEngine.CoreModule.dll</HintPath>
5048
</Reference>
5149
</ItemGroup>
5250
<ItemGroup>

CameraSettingsPlusPlusPlugin/CameraSettingsPlusPlus.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void update(MonoBehaviour root)
5858
}
5959
catch (Exception e)
6060
{
61-
Logger.getInstance().info(e.ToString());
61+
Logger.Instance.info(e.ToString());
6262
throw;
6363
}
6464

@@ -81,7 +81,7 @@ public void disable(MonoBehaviour root)
8181
}
8282
catch (Exception e)
8383
{
84-
Logger.getInstance().info(e.ToString());
84+
Logger.Instance.info(e.ToString());
8585
throw;
8686
}
8787

DeveloperConsoleEnablerPlugin/DeveloperConsoleEnablerPlugin.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@
3737
<Private>False</Private>
3838
</Reference>
3939
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
40-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\Assembly-CSharp.dll</HintPath>
41-
<Private>False</Private>
40+
<HintPath>..\libs\Assembly-CSharp.dll</HintPath>
4241
</Reference>
4342
<Reference Include="System" />
4443
<Reference Include="System.Core" />
4544
<Reference Include="System.Data" />
4645
<Reference Include="System.Xml" />
4746
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
48-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
49-
<Private>False</Private>
47+
<HintPath>..\libs\UnityEngine.CoreModule.dll</HintPath>
5048
</Reference>
5149
<Reference Include="UnityEngine.InputLegacyModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
52-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
53-
<Private>False</Private>
50+
<HintPath>..\libs\UnityEngine.InputLegacyModule.dll</HintPath>
51+
</Reference>
52+
<Reference Include="UnityEngine.InputModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
53+
<HintPath>..\libs\UnityEngine.InputModule.dll</HintPath>
5454
</Reference>
5555
</ItemGroup>
5656
<ItemGroup>

GoingMedievalModLauncher/GoingMedievalModLauncher.csproj

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<DebugSymbols>false</DebugSymbols>
1818
<DebugType>full</DebugType>
1919
<Optimize>false</Optimize>
20-
<OutputPath>C:\dev\steam\steamapps\common\Going Medieval\Mods\</OutputPath>
20+
<OutputPath>D:\Games\Steam\steamapps\common\Going Medieval\mods</OutputPath>
2121
<DefineConstants>DEBUG;TRACE</DefineConstants>
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
@@ -26,7 +26,7 @@
2626
<PlatformTarget>AnyCPU</PlatformTarget>
2727
<DebugType>pdbonly</DebugType>
2828
<Optimize>true</Optimize>
29-
<OutputPath>C:\dev\steam\steamapps\common\Going Medieval\Mods\</OutputPath>
29+
<OutputPath>D:\Games\Steam\steamapps\common\Going Medieval\mods</OutputPath>
3030
<DefineConstants>TRACE</DefineConstants>
3131
<ErrorReport>prompt</ErrorReport>
3232
<WarningLevel>4</WarningLevel>
@@ -36,46 +36,25 @@
3636
<HintPath>libs\0Harmony.dll</HintPath>
3737
</Reference>
3838
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
39-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\Assembly-CSharp.dll</HintPath>
40-
<Private>False</Private>
41-
</Reference>
42-
<Reference Include="System" />
43-
<Reference Include="System.Core" />
44-
<Reference Include="Unity.TextMeshPro, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
45-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\Unity.TextMeshPro.dll</HintPath>
46-
<Private>False</Private>
39+
<HintPath>..\libs\Assembly-CSharp.dll</HintPath>
4740
</Reference>
4841
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
49-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.dll</HintPath>
50-
<Private>False</Private>
42+
<HintPath>..\libs\UnityEngine.dll</HintPath>
5143
</Reference>
5244
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
53-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
54-
<Private>False</Private>
45+
<HintPath>..\libs\UnityEngine.CoreModule.dll</HintPath>
5546
</Reference>
5647
<Reference Include="UnityEngine.IMGUIModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
57-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
58-
<Private>False</Private>
48+
<HintPath>..\libs\UnityEngine.IMGUIModule.dll</HintPath>
5949
</Reference>
6050
<Reference Include="UnityEngine.InputLegacyModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
61-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
62-
<Private>False</Private>
51+
<HintPath>..\libs\UnityEngine.InputLegacyModule.dll</HintPath>
6352
</Reference>
6453
<Reference Include="UnityEngine.InputModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
65-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.InputModule.dll</HintPath>
66-
<Private>False</Private>
54+
<HintPath>..\libs\UnityEngine.InputModule.dll</HintPath>
6755
</Reference>
6856
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
69-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.UI.dll</HintPath>
70-
<Private>False</Private>
71-
</Reference>
72-
<Reference Include="UnityEngine.UIElementsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
73-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.UIElementsModule.dll</HintPath>
74-
<Private>False</Private>
75-
</Reference>
76-
<Reference Include="UnityEngine.UIModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
77-
<HintPath>C:\dev\steam\steamapps\common\Going Medieval\Going Medieval_Data\Managed\UnityEngine.UIModule.dll</HintPath>
78-
<Private>False</Private>
57+
<HintPath>..\libs\UnityEngine.UI.dll</HintPath>
7958
</Reference>
8059
</ItemGroup>
8160
<ItemGroup>
@@ -85,18 +64,21 @@
8564
<Compile Include="src\plugins\IPlugin.cs" />
8665
<Compile Include="src\plugins\PluginComponent.cs" />
8766
<Compile Include="src\plugins\PluginManager.cs" />
67+
<Compile Include="src\ui\MainMennuPatch.cs" />
8868
<Compile Include="src\ui\ModManagerLogWindow.cs" />
8969
<Compile Include="src\ui\ModManagerWindow.cs" />
70+
<Compile Include="src\ui\PromptQueue.cs" />
9071
<Compile Include="src\ui\UIWindow.cs" />
9172
<Compile Include="src\util\Logger.cs" />
9273
</ItemGroup>
9374
<ItemGroup>
9475
<Content Include="dist\doorstop_config.ini" />
9576
<Content Include="dist\winhttp.dll" />
77+
<Content Include="libs\0Harmony.dll" />
78+
<Content Include="libs\0Harmony.xml" />
9679
</ItemGroup>
9780
<ItemGroup>
9881
<Folder Include="dist\mods" />
99-
<Folder Include="libs" />
10082
</ItemGroup>
10183
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
10284
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

GoingMedievalModLauncher/src/Launcher.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using System;
2+
using System.Reflection;
23
using System.Threading;
4+
using GoingMedievalModLauncher.ui;
35
using HarmonyLib;
6+
using NSEipix.Base;
47
using NSMedieval.Tools.Debug;
8+
using NSMedieval.UI;
59
using UnityEngine;
610
using UnityEngine.SceneManagement;
711

@@ -29,30 +33,40 @@ public static void Main()
2933
*/
3034
public static void startup(Scene arg0, LoadSceneMode arg1)
3135
{
32-
Logger.getInstance().info("Initializing mod-loader!");
36+
Logger.Instance.info("Initializing mod-loader!");
3337

3438
if (startupFinished) return;
3539

3640
new Thread(() =>
3741
{
3842
try
3943
{
44+
45+
var harmony = new Harmony("com.modloader.nsmeadival");
46+
47+
var orig = typeof(MainMenuView).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic);
48+
var post = typeof(MainMenuPatch).GetMethod("Start", BindingFlags.Static | BindingFlags.Public);
49+
harmony.Patch(orig, postfix: new HarmonyMethod(post));
50+
51+
Singleton<PluginManager>.Instance.loadAssemblies();
52+
4053
// wait a short amount of time in order to let the game initialize itself
4154
Thread.Sleep(2500);
55+
4256

43-
Logger.getInstance().info("Mod-loader thread is running ...");
57+
Logger.Instance.info("Mod-loader thread is running ...");
4458

4559
// create a gameObject which we can use as a root reference to the scene-graph
4660
var modLoaderObject = new GameObject {name = "ModLoader"};
4761
modLoaderObject.AddComponent<EngineLauncher>();
4862

4963
// print out a nice little confirmation message that the plugin has been loaded
50-
Logger.getInstance().info("... initialization thread has been finished!");
64+
Logger.Instance.info("... initialization thread has been finished!");
5165
}
5266
catch (Exception e)
5367
{
54-
Logger.getInstance().info("An error occured: \n");
55-
Logger.getInstance().info(e.ToString());
68+
Logger.Instance.info("An error occured: \n");
69+
Logger.Instance.info(e.ToString());
5670
throw;
5771
}
5872
}).Start();

GoingMedievalModLauncher/src/engine/EngineLauncher.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Reflection;
23
using GoingMedievalModLauncher.ui;
34
using HarmonyLib;
45
using NSEipix.Base;
@@ -15,6 +16,7 @@
1516
using NSMedieval.Tools;
1617
using NSMedieval.Tools.BugReporting;
1718
using NSMedieval.Types;
19+
using NSMedieval.UI;
1820
using UnityEngine;
1921
using Object = System.Object;
2022

@@ -26,20 +28,22 @@ namespace GoingMedievalModLauncher
2628
// plugin within the unity-engine.
2729
public class EngineLauncher : MonoBehaviour
2830
{
29-
public void Start()
31+
public void Awake()
3032
{
31-
33+
3234
// update the game version to indicate this is a modded version
3335
var gameVersion = UnityEngine.GameObject.FindObjectOfType<GameVersion>();
3436
var t = Traverse.Create(gameVersion);
3537
t.Field("suffix").SetValue(" - mods active");
3638
t.Method("Start").GetValue();
37-
39+
40+
Logger.Instance.info("Start was patched with prefix");
41+
3842
// dont destroy the engines object when loading another scene, etc.
3943
DontDestroyOnLoad(this);
4044

4145
// Load all the mods / plugins / assemblies from the mods directory
42-
var loadedPlugins = PluginManager.getInstance().loadAssemblies();
46+
var loadedPlugins = Singleton<PluginManager>.Instance.GetPlugins();
4347

4448
// Initialize a new gameObject for each loaded plugin:
4549
// - set it up
@@ -52,7 +56,7 @@ public void Start()
5256
}
5357

5458
// Show a fancy ui to display and control every loaded mod at runtime
55-
Logger.getInstance().info("Showing mod-manager window...");
59+
Logger.Instance.info("Showing mod-manager window...");
5660
var modManagerWindow = gameObject.AddComponent<ModManagerWindow>();
5761

5862
}

GoingMedievalModLauncher/src/plugins/PluginManager.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
using System.IO;
44
using System.Linq;
55
using System.Reflection;
6+
using NSEipix.Base;
67
using UnityEngine;
78

89
namespace GoingMedievalModLauncher
910
{
10-
public class PluginManager
11+
public class PluginManager : Singleton<PluginManager>
1112
{
12-
private static PluginManager instance;
1313

1414
private ICollection<IPlugin> plugins;
1515

@@ -23,30 +23,20 @@ public ICollection<IPlugin> GetPlugins()
2323
return plugins;
2424
}
2525

26-
public static PluginManager getInstance()
27-
{
28-
if (instance == null)
29-
{
30-
instance = new PluginManager();
31-
}
32-
33-
return instance;
34-
}
35-
3626
/**
3727
* Loads all assemblies by a given path
3828
*/
3929
public ICollection<IPlugin> loadAssemblies()
4030
{
4131
// The directory where all assemblies / plugins / mods have to be stored
4232
DirectoryInfo dir = new DirectoryInfo(@"./mods");
43-
Logger.getInstance().info("Looking for plugins in " + dir.FullName + " ...");
33+
Logger.Instance.info("Looking for plugins in " + dir.FullName + " ...");
4434

4535
// load all the assemblies from the directory
4636
ICollection<Assembly> assemblies = new List<Assembly>();
4737
foreach (FileInfo dllFile in dir.GetFiles("*.dll"))
4838
{
49-
Logger.getInstance().info("Found dll: " + dllFile + " ...");
39+
Logger.Instance.info("Found dll: " + dllFile + " ...");
5040
AssemblyName an = AssemblyName.GetAssemblyName(dllFile.FullName);
5141
Assembly assembly = Assembly.Load(an);
5242
assemblies.Add(assembly);
@@ -87,7 +77,7 @@ public ICollection<IPlugin> loadAssemblies()
8777
IPlugin plugin = (IPlugin) Activator.CreateInstance(type);
8878
plugins.Add(plugin);
8979

90-
Logger.getInstance().info("Initializing plugin: " + plugin.Name + " - " + plugin.Version);
80+
Logger.Instance.info("Initializing plugin: " + plugin.Name + " - " + plugin.Version);
9181
plugin.initialize();
9282

9383
// TODO: plugin.start(doorstepGameObject);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace GoingMedievalModLauncher.ui
2+
{
3+
public class MainMenuPatch
4+
{
5+
6+
public delegate void onMenuStartPost();
7+
8+
public static event onMenuStartPost OnMenuStartPost = () => {};
9+
10+
public static void Start()
11+
{
12+
Logger.Instance.info("Start patch was executed.");
13+
14+
OnMenuStartPost();
15+
16+
}
17+
18+
}
19+
}

0 commit comments

Comments
 (0)