Skip to content

Commit f5eef66

Browse files
authored
cleanup and output (#32)
1 parent 40804dd commit f5eef66

File tree

8 files changed

+27
-55
lines changed

8 files changed

+27
-55
lines changed

OWML.Common/IModBehaviour.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

OWML.Common/OWML.Common.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
<Compile Include="IHarmonyHelper.cs" />
5858
<Compile Include="IModAssets.cs" />
5959
<Compile Include="IModAsset.cs" />
60-
<Compile Include="IModBehaviour.cs" />
6160
<Compile Include="IModConfig.cs" />
6261
<Compile Include="IModEvents.cs" />
6362
<Compile Include="IModFinder.cs" />

OWML.ModHelper.Events/HarmonyHelper.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public void AddPrefix<T>(string methodName, Type patchType, string patchMethodNa
2121
var prefix = patchType.GetAnyMethod(patchMethodName);
2222
if (prefix == null)
2323
{
24-
_logger.Log("prefix is null");
2524
_console.WriteLine("prefix is null");
2625
return;
2726
}
@@ -33,7 +32,6 @@ public void AddPostfix<T>(string methodName, Type patchType, string patchMethodN
3332
var postfix = patchType.GetAnyMethod(patchMethodName);
3433
if (postfix == null)
3534
{
36-
_logger.Log("postfix is null");
3735
_console.WriteLine("postfix is null");
3836
return;
3937
}
@@ -50,7 +48,6 @@ public void Transpile<T>(string methodName, Type patchType, string patchMethodNa
5048
var patchMethod = patchType.GetAnyMethod(patchMethodName);
5149
if (patchMethod == null)
5250
{
53-
_logger.Log("patchMethod is null");
5451
_console.WriteLine("patchMethod is null");
5552
return;
5653
}
@@ -70,7 +67,6 @@ private void Patch<T>(string methodName, MethodInfo prefix, MethodInfo postfix,
7067
}
7168
catch (Exception ex)
7269
{
73-
_logger.Log($"Exception while creating harmony instance: {ex}");
7470
_console.WriteLine($"Exception while creating harmony instance: {ex}");
7571
return;
7672
}
@@ -83,13 +79,11 @@ private void Patch<T>(string methodName, MethodInfo prefix, MethodInfo postfix,
8379
}
8480
catch (Exception ex)
8581
{
86-
_logger.Log($"Exception while getting method {methodName} of {targetType.Name}: {ex}");
8782
_console.WriteLine($"Exception while getting method {methodName} of {targetType.Name}: {ex}");
8883
return;
8984
}
9085
if (original == null)
9186
{
92-
_logger.Log("original is null");
9387
_console.WriteLine("original is null");
9488
return;
9589
}
@@ -103,7 +97,6 @@ private void Patch<T>(string methodName, MethodInfo prefix, MethodInfo postfix,
10397
}
10498
catch (Exception ex)
10599
{
106-
_logger.Log($"Exception while patching {targetType.Name}: {ex}");
107100
_console.WriteLine($"Exception while patching {targetType.Name}: {ex}");
108101
}
109102
}

OWML.ModHelper.Events/TypeExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public static void SetValue(this object obj, string name, object value)
5757
if (property != null)
5858
{
5959
property.SetValue(obj, value, null);
60-
return;
6160
}
6261
}
6362

OWML.ModHelper/ModBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace OWML.ModHelper
55
{
6-
public class ModBehaviour : MonoBehaviour, IModBehaviour
6+
public class ModBehaviour : MonoBehaviour
77
{
88
public static IModHelper ModHelper;
99

OWML.ModHelper/ModConsole.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ namespace OWML.ModHelper
88
public class ModConsole : IModConsole
99
{
1010
private readonly FileStream _writer;
11+
private readonly IModLogger _logger;
1112

12-
public ModConsole(IModConfig config)
13+
public ModConsole(IModConfig config, IModLogger logger)
1314
{
15+
_logger = logger;
1416
_writer = File.Open(config.OutputFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
1517
}
1618

1719
public void WriteLine(string s)
1820
{
21+
_logger.Log(s);
1922
var bytes = Encoding.UTF8.GetBytes(s + Environment.NewLine);
2023
_writer.Write(bytes, 0, bytes.Length);
2124
_writer.Flush();

OWML.ModLoader/ModLoader.cs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,23 @@ namespace OWML.ModLoader
1111
public class ModLoader
1212
{
1313
private static readonly string ConfigPath = $"{Application.dataPath}/Managed/OWML.Config.json";
14-
private static readonly string SecondaryLogPath = $"{Application.dataPath}/Resources/OWML.Output.txt";
1514

1615
public static void LoadMods()
1716
{
18-
SecondaryLog($"In {nameof(ModLoader)}.{nameof(LoadMods)}!");
19-
SecondaryLog("Getting config...");
2017
var config = GetConfig();
2118
if (config == null)
2219
{
23-
SecondaryLog("Config is null");
2420
return;
2521
}
26-
SecondaryLog("Got config!");
27-
SecondaryLog("Loading mods...");
28-
try
29-
{
30-
var logger = new ModLogger(config);
31-
var console = new ModConsole(config);
32-
var harmonyHelper = new HarmonyHelper(logger, console);
33-
var events = new ModEvents(harmonyHelper);
34-
var modFinder = new ModFinder(config);
35-
var owo = new Owo(modFinder, logger, console, config, harmonyHelper, events);
36-
owo.LoadMods();
37-
SecondaryLog("Loaded mods");
38-
}
39-
catch (Exception ex)
40-
{
41-
SecondaryLog("Error while loading mods: " + ex);
42-
}
22+
var logger = new ModLogger(config);
23+
logger.Log("Got config!");
24+
var console = new ModConsole(config, logger);
25+
console.WriteLine("Mod loader has been initialized.");
26+
var harmonyHelper = new HarmonyHelper(logger, console);
27+
var events = new ModEvents(harmonyHelper);
28+
var modFinder = new ModFinder(config);
29+
var owo = new Owo(modFinder, logger, console, config, harmonyHelper, events);
30+
owo.LoadMods();
4331
}
4432

4533
private static IModConfig GetConfig()
@@ -49,17 +37,11 @@ private static IModConfig GetConfig()
4937
var json = File.ReadAllText(ConfigPath);
5038
return JsonConvert.DeserializeObject<ModConfig>(json);
5139
}
52-
catch (Exception ex)
40+
catch (Exception)
5341
{
54-
SecondaryLog("Error while loading config: " + ex);
5542
return null;
5643
}
5744
}
5845

59-
private static void SecondaryLog(string s)
60-
{
61-
File.AppendAllText(SecondaryLogPath, $"{DateTime.Now}: {s}{Environment.NewLine}");
62-
}
63-
6446
}
6547
}

OWML.ModLoader/Owo.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public Owo(IModFinder modFinder, IModLogger logger, IModConsole console, IModCon
2929

3030
public void LoadMods()
3131
{
32-
_logger.Log($"{nameof(Owo)}: {nameof(LoadMods)}");
3332
if (_config.Verbose)
3433
{
34+
_console.WriteLine("Verbose mod is enabled");
3535
Application.logMessageReceived += OnLogMessageReceived;
3636
}
3737
var manifests = _modFinder.GetManifests();
@@ -69,11 +69,18 @@ private void LoadMod(IModHelper helper)
6969
_logger.Log($"Loading {helper.Manifest.UniqueName} ({helper.Manifest.Version})...");
7070
_logger.Log("Adding mod behaviour...");
7171
var go = new GameObject(helper.Manifest.UniqueName);
72-
var mod = (ModBehaviour)go.AddComponent(modType);
73-
_logger.Log("Added! Initializing...");
74-
mod.Init(helper);
72+
try
73+
{
74+
var mod = (ModBehaviour)go.AddComponent(modType);
75+
_logger.Log("Added! Initializing...");
76+
mod.Init(helper);
77+
}
78+
catch (Exception ex)
79+
{
80+
_console.WriteLine($"Error while adding/initializing {helper.Manifest.UniqueName}: {ex}");
81+
return;
82+
}
7583
_console.WriteLine($"Loaded {helper.Manifest.UniqueName} ({helper.Manifest.Version}).");
76-
_logger.Log($"Loaded {helper.Manifest.UniqueName} ({helper.Manifest.Version}).");
7784
}
7885

7986
private Type LoadModType(IModManifest manifest)
@@ -92,7 +99,6 @@ private Type LoadModType(IModManifest manifest)
9299
}
93100
catch (Exception ex)
94101
{
95-
_logger.Log($"Error while trying to get {typeof(ModBehaviour)}: {ex.Message}");
96102
_console.WriteLine($"Error while trying to get {typeof(ModBehaviour)}: {ex.Message}");
97103
return null;
98104
}

0 commit comments

Comments
 (0)