Skip to content
This repository was archived by the owner on Sep 14, 2022. It is now read-only.

Commit 34ba30e

Browse files
author
Michael P. Starkweather
committed
Add an ignore list of dlls, so BTML doesn't load itself. Remove harmony summary.
1 parent 4b74fef commit 34ba30e

File tree

6 files changed

+21
-80
lines changed

6 files changed

+21
-80
lines changed

BattleTechModLoader.sln

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documents", "Documents", "{
1515
EndProject
1616
Global
1717
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18-
Debug|Any CPU = Debug|Any CPU
1918
Release|Any CPU = Release|Any CPU
2019
EndGlobalSection
2120
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22-
{7F6FD594-C1BC-4F30-82F8-674D7EE7BF9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23-
{7F6FD594-C1BC-4F30-82F8-674D7EE7BF9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
2421
{7F6FD594-C1BC-4F30-82F8-674D7EE7BF9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
2522
{7F6FD594-C1BC-4F30-82F8-674D7EE7BF9D}.Release|Any CPU.Build.0 = Release|Any CPU
26-
{3DA1D634-AF82-4479-8EA3-580BA2F17BE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27-
{3DA1D634-AF82-4479-8EA3-580BA2F17BE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
2823
{3DA1D634-AF82-4479-8EA3-580BA2F17BE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
2924
{3DA1D634-AF82-4479-8EA3-580BA2F17BE7}.Release|Any CPU.Build.0 = Release|Any CPU
3025
EndGlobalSection

BattleTechModLoader/BTModLoader.cs

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
using System.Reflection;
77
using BattleTech;
88
using Harmony;
9-
using JetBrains.Annotations;
9+
10+
// ReSharper disable UnusedMember.Global
11+
// ReSharper disable MemberCanBePrivate.Global
1012

1113
namespace BattleTechModLoader
1214
{
1315
using static Logger;
1416

15-
[UsedImplicitly]
1617
public static class BTModLoader
1718
{
1819
private const BindingFlags PUBLIC_STATIC_BINDING_FLAGS = BindingFlags.Public | BindingFlags.Static;
20+
private static readonly List<string> IGNORE_FILE_NAMES = new List<string>()
21+
{
22+
"0Harmony.dll",
23+
"BattleTechModLoader.dll"
24+
};
1925

20-
[UsedImplicitly]
2126
public static string ModDirectory { get; private set; }
22-
23-
[UsedImplicitly]
27+
2428
public static void LoadDLL(string path, string methodName = "Init", string typeName = null,
2529
object[] prms = null, BindingFlags bFlags = PUBLIC_STATIC_BINDING_FLAGS)
2630
{
@@ -51,11 +55,14 @@ public static void LoadDLL(string path, string methodName = "Init", string typeN
5155
foreach (var type in types)
5256
{
5357
var entryMethod = type.GetMethod(methodName, bFlags);
54-
var methodParams = entryMethod.GetParameters();
58+
var methodParams = entryMethod?.GetParameters();
59+
60+
if (methodParams == null)
61+
continue;
5562

5663
if (methodParams.Length == 0)
5764
{
58-
LogWithDate($"{fileName}: Found and called entry point with void param: {type.Name}.{entryMethod.Name}");
65+
LogWithDate($"{fileName}: Found and called entry point \"{entryMethod}\" in type \"{type.FullName}\"");
5966
entryMethod.Invoke(null, null);
6067
}
6168
else
@@ -74,7 +81,7 @@ public static void LoadDLL(string path, string methodName = "Init", string typeN
7481

7582
if (paramsMatch)
7683
{
77-
LogWithDate($"{fileName}: Found and called entry point with params: {type.Name}.{entryMethod.Name}");
84+
LogWithDate($"{fileName}: Found and called entry point \"{entryMethod}\" in type \"{type.FullName}\"");
7885
entryMethod.Invoke(null, prms);
7986
continue;
8087
}
@@ -96,7 +103,7 @@ public static void LoadDLL(string path, string methodName = "Init", string typeN
96103
}
97104

98105
if (methodParams.Length == 0) continue;
99-
106+
100107
Log("\tMethod Params:");
101108
foreach (var prm in methodParams)
102109
{
@@ -111,7 +118,6 @@ public static void LoadDLL(string path, string methodName = "Init", string typeN
111118
}
112119
}
113120

114-
[UsedImplicitly]
115121
public static void Init()
116122
{
117123
var manifestDirectory = Path.GetDirectoryName(VersionManifestUtilities.MANIFEST_FILEPATH)
@@ -151,54 +157,13 @@ public static void Init()
151157
// load the dlls
152158
foreach (var dllPath in dllPaths)
153159
{
154-
Log($"Found DLL: {Path.GetFileName(dllPath)}");
155-
LoadDLL(dllPath);
160+
if (!IGNORE_FILE_NAMES.Contains(Path.GetFileName(dllPath)))
161+
LoadDLL(dllPath);
156162
}
157163

158164
// do some simple benchmarking
159165
sw.Stop();
160-
Log("");
161-
Log($"Took {sw.Elapsed.TotalSeconds} seconds to load mods");
162-
163-
// print out harmony summary
164-
var patchedMethods = harmony.GetPatchedMethods().ToArray();
165-
if (patchedMethods.Length == 0)
166-
{
167-
Log("No Harmony Patches loaded.");
168-
return;
169-
}
170-
171-
Log("");
172-
Log("Harmony Patched Methods (after mod loader startup):");
173-
174-
foreach (var method in patchedMethods)
175-
{
176-
var info = harmony.GetPatchInfo(method);
177-
178-
if (info == null) continue;
179-
180-
Log($"{method.ReflectedType.FullName}.{method.Name}:");
181-
182-
// prefixes
183-
if (info.Prefixes.Count != 0)
184-
Log("\tPrefixes:");
185-
foreach (var patch in info.Prefixes)
186-
Log($"\t\t{patch.owner}");
187-
188-
// transpilers
189-
if (info.Transpilers.Count != 0)
190-
Log("\tTranspilers:");
191-
foreach (var patch in info.Transpilers)
192-
Log($"\t\t{patch.owner}");
193-
194-
// postfixes
195-
if (info.Postfixes.Count != 0)
196-
Log("\tPostfixes:");
197-
foreach (var patch in info.Postfixes)
198-
Log($"\t\t{patch.owner}");
199-
}
200-
201-
Log("");
166+
Log($"\nTook {sw.Elapsed.TotalSeconds} seconds to load mods\n");
202167
}
203168
}
204169
}

BattleTechModLoader/BattleTechModLoader.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
<TargetFrameworkProfile />
1515
<LangVersion>7.2</LangVersion>
1616
</PropertyGroup>
17-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18-
<DebugSymbols>true</DebugSymbols>
19-
<DebugType>full</DebugType>
20-
<Optimize>false</Optimize>
21-
<OutputPath>bin\Debug\</OutputPath>
22-
<DefineConstants>DEBUG;TRACE;UNITY_ASSERTIONS</DefineConstants>
23-
<ErrorReport>prompt</ErrorReport>
24-
<WarningLevel>4</WarningLevel>
25-
</PropertyGroup>
2617
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2718
<DebugType>none</DebugType>
2819
<Optimize>true</Optimize>

BattleTechModLoader/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.2.1.*")]
35+
[assembly: AssemblyVersion("0.2.2.*")]

BattleTechModLoaderInjector/BattleTechModLoaderInjector.csproj

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@
3030
<BootstrapperEnabled>true</BootstrapperEnabled>
3131
<LangVersion>7.2</LangVersion>
3232
</PropertyGroup>
33-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
34-
<PlatformTarget>AnyCPU</PlatformTarget>
35-
<DebugSymbols>true</DebugSymbols>
36-
<DebugType>full</DebugType>
37-
<Optimize>false</Optimize>
38-
<OutputPath>bin\Debug\</OutputPath>
39-
<DefineConstants>DEBUG;TRACE</DefineConstants>
40-
<ErrorReport>prompt</ErrorReport>
41-
<WarningLevel>4</WarningLevel>
42-
</PropertyGroup>
4333
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4434
<PlatformTarget>AnyCPU</PlatformTarget>
4535
<DebugType>none</DebugType>

BattleTechModLoaderInjector/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.2.1.*")]
35+
[assembly: AssemblyVersion("0.2.2.*")]

0 commit comments

Comments
 (0)