-
Notifications
You must be signed in to change notification settings - Fork 0
/
SphereOpt.cs
97 lines (84 loc) · 3.2 KB
/
SphereOpt.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
using System.Collections.Generic;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using System.IO;
using System.Reflection;
using UnityEngine;
namespace SphereOpt
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class SphereOpt : BaseUnityPlugin
{
public static ManualLogSource logger;
private static AssetBundle bundle;
private static readonly string AssemblyPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(SphereOpt)).Location);
private static Dictionary<int, InstDysonShellRenderer> instRenderers = new Dictionary<int, InstDysonShellRenderer>();
private static AssetBundle Bundle
{
get
{
if (bundle == null)
{
var path = Path.Combine(AssemblyPath, "sphereopt-bundle");
if (File.Exists(path))
{
bundle = AssetBundle.LoadFromFile(path);
}
else
{
logger.LogError("Failed to load AssetBundle!".Translate());
return null;
}
}
return bundle;
}
}
private void Awake()
{
logger = Logger;
CustomShaderManager.InitWithBundle(Bundle);
CustomShaderManager.AddCustomShaderDesc(
"dysonshell-inst",
"VF Shaders/Dyson Sphere/Dyson Shell Unlit Instanced"
);
CustomShaderManager.AddCustomShaderDesc(
"dysonframe",
"VF Shaders/Dyson Sphere/Frame Inst REPLACE",
"VF Shaders/Dyson Sphere/Frame Inst"
);
CustomShaderManager.AddCustomShaderDesc(
"instFrameLOD2",
"VF Shaders/Dyson Sphere/Frame Inst REPLACE LOD2"
);
CustomShaderManager.AddCustomShaderDesc(
"dysonnode",
"VF Shaders/Dyson Sphere/Node Inst REPLACE",
"VF Shaders/Dyson Sphere/Node Inst"
);
Harmony.CreateAndPatchAll(typeof(Patch_VFPreload));
Harmony.CreateAndPatchAll(typeof(Patch_DysonShell));
Harmony.CreateAndPatchAll(typeof(Patch_DysonSphereSegmentRenderer));
Harmony.CreateAndPatchAll(typeof(Patch_DEBUG));
}
public static InstDysonShellRenderer getInstDysonShellRendererForSphere(DysonSphere ds)
{
if (!instRenderers.TryGetValue(ds.starData.id, out InstDysonShellRenderer renderer))
{
renderer = new InstDysonShellRenderer(ds);
instRenderers[ds.starData.id] = renderer;
}
return renderer;
}
public static void RemoveRenderer(DysonSphere ds)
{
instRenderers.Remove(ds.starData.id);
}
public static void UpdateColor(DysonShell shell)
{
var dsRenderer = getInstDysonShellRendererForSphere(shell.dysonSphere);
var layer = dsRenderer.getInstShellLayer(shell.layerId);
layer.UpdateColor(shell.id, shell.color);
}
}
}