1
+ using System . Reflection ;
2
+ using HarmonyLib ;
3
+ using NSMedieval . Construction ;
4
+ using NSMedieval . Pool ;
5
+ using UnityEngine ;
6
+
7
+ namespace GoingMedievalModLauncher . Engine
8
+ {
9
+ public static class DebbugingPatches
10
+ {
11
+
12
+ private static void SpawnBlueprintPre ( BuildingsManager __instance , BuildableBase model , Vector3 worldPosition ,
13
+ Transform transform )
14
+ {
15
+ Launcher . LOGGER . Info ( $ "{ model } ") ;
16
+ Launcher . LOGGER . Info ( $ "{ worldPosition } ") ;
17
+ Launcher . LOGGER . Info ( $ "{ transform } ") ;
18
+ var mat = transform . gameObject . GetComponentInChildren < MeshRenderer > ( ) . material ;
19
+ Launcher . LOGGER . Info ( $ "{ mat . shader . name } ") ;
20
+ var poolf = typeof ( BuildingsManager ) . GetField ( "pool" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
21
+ var pool = poolf . GetValue ( __instance ) as ObjectPool ;
22
+ var baseBuildableView = ( BaseBuildableView < BuildingInstance > ) pool . Take ( model . GetID ( ) ) ;
23
+ Launcher . LOGGER . Info ( $ "{ baseBuildableView } ") ;
24
+ }
25
+
26
+ private static void AddBuildablePre ( BuildingInstance instance , BaseBuildableView < BuildingInstance > view )
27
+ {
28
+ Launcher . LOGGER . Info ( $ "{ instance } ") ;
29
+ Launcher . LOGGER . Info ( $ "{ view } ") ;
30
+ var m = view . GetComponentsInChildren < MeshRenderer > ( ) ;
31
+ foreach ( var renderer in m )
32
+ {
33
+ Launcher . LOGGER . Info ( $ "{ renderer . material . shader . name } ") ;
34
+ }
35
+ }
36
+
37
+ public static void ApplyPatches ( Harmony harmony )
38
+ {
39
+ var orig = typeof ( BuildingsManager ) . GetMethod (
40
+ "SpawnBlueprint" , BindingFlags . Public | BindingFlags . Instance ) ;
41
+ var pre = typeof ( DebbugingPatches ) . GetMethod (
42
+ "SpawnBlueprintPre" , BindingFlags . NonPublic | BindingFlags . Static ) ;
43
+ var origA = typeof ( BuildingsManager ) . GetMethod (
44
+ "AddBuildable" , BindingFlags . Public | BindingFlags . Instance ) ;
45
+ var preA = typeof ( DebbugingPatches ) . GetMethod (
46
+ "AddBuildablePre" , BindingFlags . NonPublic | BindingFlags . Static ) ;
47
+ harmony . Patch ( orig , new HarmonyMethod ( pre ) ) ;
48
+ //harmony.Patch(origA, new HarmonyMethod(preA));
49
+ Launcher . LOGGER . Info ( "Debug patches were applied." ) ;
50
+ }
51
+
52
+ }
53
+ }
0 commit comments