This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisableCustomConnectPoint.cs
78 lines (66 loc) · 2.94 KB
/
DisableCustomConnectPoint.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
using HarmonyLib;
using NeosModLoader;
using FrooxEngine.LogiX;
using System;
using System.Reflection;
using System.Collections.Generic;
namespace DisableCustomConnectPoint
{
public class DisableCustomConnectPoint : NeosMod
{
public override string Name => BuildInfo.Name;
public override string Author => BuildInfo.Author;
public override string Version => BuildInfo.Version;
public override string Link => BuildInfo.Link;
[AutoRegisterConfigKey]
private static readonly ModConfigurationKey<bool> Key_Enable = new("enabled", "Enables this mod.", () => true);
[AutoRegisterConfigKey]
private static readonly ModConfigurationKey<bool> Key_Input = new("Joke_InputAll", "Joke config. Force input all.", () => false);
[AutoRegisterConfigKey]
private static readonly ModConfigurationKey<bool> Key_Output = new("Joke_OutputAll", "Joke config. Force output all.", () => false);
[AutoRegisterConfigKey]
private static readonly ModConfigurationKey<bool> Key_Abekonbe = new("Joke_Abekonbe", "Joke config. Force replace from input to/from output all.", () => false);
private static ModConfiguration Config;
public override void OnEngineInit()
{
Config = GetConfiguration();
Config.Save(true);
if (!Config.GetValue(Key_Enable)) return;
Harmony harmony = new Harmony(BuildInfo.GUID);
harmony.PatchAll();
}
[HarmonyPatch(typeof(LogixHelper), "GetSide")]
class Patch
{
static bool Prefix(LogixNode node, IConnectionElement member, ref ConnectPointSide __result)
{
if (member is LogixNode)
{
__result = ConnectPointSide.Output;
if(Config.GetValue(Key_Input) || Config.GetValue(Key_Abekonbe))
__result = ConnectPointSide.Input;
return false;
}
FieldInfo fieldInfo = null;
if (member.PointName != null)
fieldInfo = node.GetType().GetField(member.PointName);
Type type = member.GetType();
if (typeof(IInputElement).IsAssignableFrom(type))
{
__result = ConnectPointSide.Input;
if(Config.GetValue(Key_Output) || Config.GetValue(Key_Abekonbe))
__result = ConnectPointSide.Output;
return false;
}
if (typeof(IOutputElement).IsAssignableFrom(type))
{
__result = ConnectPointSide.Output;
if(Config.GetValue(Key_Input) || Config.GetValue(Key_Abekonbe))
__result = ConnectPointSide.Output;
return false;
}
throw new Exception("Invalid element: " + type?.ToString());
}
}
}
}