1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Diagnostics . CodeAnalysis ;
4+ using System . Linq ;
5+ using System . Reflection ;
6+ using BepInEx ;
7+ using BepInEx . Logging ;
8+ using HarmonyLib ;
9+
10+ namespace Logless
11+ {
12+ using P = Plugin ;
13+
14+ [ BepInProcess ( "Legion TD 2.exe" ) ]
15+ [ BepInPlugin ( PluginInfo . PLUGIN_GUID , PluginInfo . PLUGIN_NAME , PluginInfo . PLUGIN_VERSION ) ]
16+ public class Plugin : BaseUnityPlugin
17+ {
18+ // Using GUID for the Harmony instance, so that we can unpatch just this plugin if needed
19+ private readonly Assembly _assembly = Assembly . GetExecutingAssembly ( ) ;
20+ private readonly Harmony _harmony = new ( PluginInfo . PLUGIN_GUID ) ;
21+
22+ internal new static ManualLogSource Logger ;
23+
24+ // When the plugin is loaded
25+ public void Awake ( ) {
26+ // Create masking Logger as internal to use more easily in code
27+ Logger = base . Logger ;
28+
29+ // Inject custom js and patch c#
30+ try {
31+ Patch ( ) ;
32+ }
33+ catch ( Exception e ) {
34+ Logger . LogError ( $ "Error while injecting or patching: { e } ") ;
35+ throw ;
36+ }
37+
38+ // All done!
39+ Logger . LogInfo ( $ "Plugin { PluginInfo . PLUGIN_GUID } is loaded!") ;
40+ }
41+
42+ // Unpatch if plugin is destroyed to handle in-game plugin reloads
43+ // Remove files we created
44+ public void OnDestroy ( ) {
45+ UnPatch ( ) ;
46+ }
47+
48+ private void Patch ( ) {
49+ _harmony . PatchAll ( _assembly ) ;
50+ }
51+
52+ // Undoes what Patch() did
53+ private void UnPatch ( ) {
54+ _harmony . UnpatchSelf ( ) ;
55+ }
56+ }
57+
58+ [ SuppressMessage ( "ReSharper" , "InconsistentNaming" ) ]
59+ [ SuppressMessage ( "ReSharper" , "UnusedMember.Local" ) ]
60+ [ HarmonyPatch ]
61+ internal static class PatchDeveloperApiHtmlLogger
62+ {
63+ private static Type _typeDeveloperApi ;
64+
65+ [ HarmonyPrepare ]
66+ private static void Prepare ( ) {
67+ _typeDeveloperApi = AccessTools . TypeByName ( "aag.Natives.Api.DeveloperApi" ) ;
68+ }
69+
70+ [ HarmonyTargetMethods ]
71+ private static IEnumerable < MethodBase > TargetMethods ( )
72+ {
73+ return AccessTools . Inner ( _typeDeveloperApi , "HtmlLogger" )
74+ . GetMethods ( )
75+ . Where ( method => method . ReturnType == typeof ( void ) ) ;
76+ }
77+
78+ [ HarmonyPrefix ]
79+ private static bool Prefix ( MethodBase __originalMethod ) {
80+ return false ;
81+ }
82+ }
83+
84+ [ SuppressMessage ( "ReSharper" , "InconsistentNaming" ) ]
85+ [ SuppressMessage ( "ReSharper" , "UnusedMember.Local" ) ]
86+ [ HarmonyPatch ]
87+ internal static class PatchDeveloperApi
88+ {
89+ private static Type _typeDeveloperApi ;
90+
91+ [ HarmonyPrepare ]
92+ private static void Prepare ( ) {
93+ _typeDeveloperApi = AccessTools . TypeByName ( "aag.Natives.Api.DeveloperApi" ) ;
94+ }
95+
96+ [ HarmonyTargetMethods ]
97+ private static IEnumerable < MethodBase > TargetMethods ( )
98+ {
99+ return _typeDeveloperApi
100+ . GetMethods ( )
101+ . Where ( method => method . ReturnType == typeof ( void ) ) ;
102+ }
103+
104+ [ HarmonyPrefix ]
105+ private static bool Prefix ( MethodBase __originalMethod ) {
106+ return false ;
107+ }
108+ }
109+
110+ [ SuppressMessage ( "ReSharper" , "InconsistentNaming" ) ]
111+ [ SuppressMessage ( "ReSharper" , "UnusedMember.Local" ) ]
112+ [ HarmonyPatch ]
113+ internal static class PatchLogSaver
114+ {
115+ private static Type _typeLogSaver ;
116+
117+ [ HarmonyPrepare ]
118+ private static void Prepare ( ) {
119+ _typeLogSaver = AccessTools . TypeByName ( "Assets.Features.Dev.LogSaver" ) ;
120+ }
121+
122+ [ HarmonyTargetMethods ]
123+ private static IEnumerable < MethodBase > TargetMethods ( )
124+ {
125+ return _typeLogSaver
126+ . GetMethods ( )
127+ . Where ( method => method . ReturnType == typeof ( void ) ) ;
128+ }
129+
130+ [ HarmonyPrefix ]
131+ private static bool Prefix ( ) {
132+ return false ;
133+ }
134+ }
135+ }
0 commit comments