-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShaderAnalysis.cs
130 lines (119 loc) · 5.7 KB
/
ShaderAnalysis.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
namespace ShaderAnalysis
{
[BepInPlugin(ID, title, version)]
public class ShaderAnalysisMod : BaseUnityPlugin
{
public const string ID = "mixone.valheim.shaderanalysis";
public const string version = "0.0.0.1";
public const string title = "Shader Analysis";
public Harmony harmony;
public static BepInEx.Logging.ManualLogSource harmonyLog;
public static GameObject intellion;
public void Awake()
{
harmony = new Harmony(ID);
harmony.PatchAll();
harmonyLog = Logger;
harmonyLog.LogDebug("Shader Analysis loaded.");
}
}
#region Utils
public static class Utils
{
public static void OutputStructure(Transform trans, int level=0)
{
if(level == 0)
{
ShaderAnalysisMod.harmonyLog.LogDebug($"\nParent : {trans.name}");
}
ShaderAnalysisMod.harmonyLog.LogDebug($"\n{String.Concat(Enumerable.Repeat("-", level + 1))}> {trans.name}");
if (trans.GetComponents<Component>().Length > 1)
{
ShaderAnalysisMod.harmonyLog.LogDebug($"\n{String.Concat(Enumerable.Repeat("-", level + 1))}> {trans.name} Components :");
foreach (Component comp in trans.GetComponents<Component>())
{
ShaderAnalysisMod.harmonyLog.LogDebug($"\n{String.Concat(Enumerable.Repeat(" ", level + 2))} {comp.GetType()}");
}
} else
{
ShaderAnalysisMod.harmonyLog.LogDebug($"\n{String.Concat(Enumerable.Repeat("-", level + 1))}> {trans.name} has no components.");
}
foreach (Transform child in trans)
{
OutputStructure(child, level+1);
}
}
}
#endregion
#region Patches
public static class FejdStartup_Patches
{
[HarmonyPatch(typeof(FejdStartup), nameof(FejdStartup.Awake))]
public static class FejdStartup_Awake_Patch
{
public static void Postfix(ref FejdStartup __instance)
{
ItemDrop[] allItems = Resources.FindObjectsOfTypeAll<ItemDrop>();
List<Shader> foundShaders = new List<Shader>();
ShaderAnalysisMod.harmonyLog.LogDebug("\n########## Item Data ##########");
foreach (string itemType in Enum.GetNames(typeof(ItemDrop.ItemData.ItemType)))
{
ShaderAnalysisMod.harmonyLog.LogDebug($"\n##### {itemType} Items #####");
foreach (ItemDrop item in allItems.Where<ItemDrop>(itm => itm.m_itemData.m_shared.m_itemType == (ItemDrop.ItemData.ItemType)Enum.Parse(typeof(ItemDrop.ItemData.ItemType), itemType)))
{
ShaderAnalysisMod.harmonyLog.LogDebug($"\n### { Localization.instance.Localize(item.m_itemData.m_shared.m_name)} ###");
ShaderAnalysisMod.harmonyLog.LogDebug($"\nItem keyword : {item.m_itemData.m_shared.m_name}");
if (item.m_itemData.m_shared.m_variants > 0)
{
ShaderAnalysisMod.harmonyLog.LogDebug("\nVariants: { item.m_itemData.m_shared.m_variants}");
} else
{
ShaderAnalysisMod.harmonyLog.LogDebug("\nItem has no variants");
}
if (item.gameObject.GetComponentInChildren<Renderer>(true) != null)
{
foreach (Renderer rendy in item.gameObject.GetComponentsInChildren<Renderer>(true)) {
ShaderAnalysisMod.harmonyLog.LogDebug($"Shader : {rendy.material.shader.name}");
if (!foundShaders.Contains(rendy.material.shader))
foundShaders.Add(rendy.material.shader);
}
} else
{
ShaderAnalysisMod.harmonyLog.LogDebug($"Item has no Renderer");
}
ShaderAnalysisMod.harmonyLog.LogDebug($"\n# GameObject Structure #");
Utils.OutputStructure(item.gameObject.transform);
}
}
ShaderAnalysisMod.harmonyLog.LogDebug("\n########## Shader Data ##########");
foreach (Shader shade in foundShaders)
{
ShaderAnalysisMod.harmonyLog.LogDebug($"\n{shade.name} Properties :");
for (int i = 0; i < shade.GetPropertyCount(); i++)
{
ShaderAnalysisMod.harmonyLog.LogDebug($"-> {shade.GetPropertyName(i)}");
ShaderAnalysisMod.harmonyLog.LogDebug($"-> {shade.GetPropertyDescription(i)}");
if (shade.GetPropertyAttributes(i).Length > 0)
{
ShaderAnalysisMod.harmonyLog.LogDebug($"-> {shade.GetPropertyName(i)} Property Attributes:");
foreach (string attr in shade.GetPropertyAttributes(i))
{
ShaderAnalysisMod.harmonyLog.LogDebug($"--> {attr}");
}
} else
{
ShaderAnalysisMod.harmonyLog.LogDebug($"-> {shade.GetPropertyName(i)} property has no attributes.");
}
}
}
}
}
}
#endregion
}