-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
147 lines (130 loc) · 5.76 KB
/
Plugin.cs
File metadata and controls
147 lines (130 loc) · 5.76 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System.IO;
using System.Windows.Controls;
using Torch;
using Torch.API;
using Torch.API.Plugins;
using Torch.Views;
using VRage.ModAPI;
using Sandbox.ModAPI;
using VRage.Game.ModAPI;
using Sandbox.Game;
using System.Windows.Documents;
using Sandbox.Game.Entities;
using System;
using System.Collections.Generic;
using Sandbox.Game.World;
using VRage.Game;
using VRage.Game.Components;
using VRage.ObjectBuilders;
using VRageMath;
using HarmonyLib;
using Sandbox.Engine.Utils;
using Sandbox.Game.GameSystems;
using VRage.Utils;
namespace JumpDisable
{
public class Plugin : TorchPluginBase, IWpfPlugin
{
private Persistent<Config> _config = null!;
static List<IMyFunctionalBlock> _turrets = new List<IMyFunctionalBlock>();
static MyCubeGrid grid;
static bool OnOffTimer = false;
public int counter = 0;
public override void Init(ITorchBase torch)
{
new Harmony("JumpDisable").PatchAll();
base.Init(torch);
_config = Persistent<Config>.Load(Path.Combine(StoragePath, "JumpDisable.cfg"));
Config._subtypes.Add("LargeRailgun");
Config._subtypes.Add("SmallRailgun");
Config._subtypes.Add("SmallGatlingGun");
Config._subtypes.Add("SmallGatlingGunWarfare2");
Config._subtypes.Add("LargeGatlingTurret");
Config._subtypes.Add("SmallGatlingTurret");
Config._subtypes.Add("LargeInteriorTurret");
Config._subtypes.Add("SmallBlockAutocannon");
Config._subtypes.Add("AutoCannonTurret");
Config._subtypes.Add("SmallMissileLauncher");
Config._subtypes.Add("LargeMissileLauncher");
Config._subtypes.Add("SmallMissileLauncherWarfare2");
Config._subtypes.Add("SmallRocketLauncherReload");
Config._subtypes.Add("SmallMissileTurret");
Config._subtypes.Add("SmallBlockMediumCalibreGun");
Config._subtypes.Add("SmallBlockMediumCalibreTurret");
Config._subtypes.Add("LargeBlockMediumCalibreTurret");
Config._subtypes.Add("LargeBlockLargeCalibreGun");
Config._subtypes.Add("LargeCalibreTurret");
}
public override void Update()
{
//runs every 10 seconds
if (counter % 600 == 0)
{
}
counter++;
}
public static void Turret(MyCubeGrid grid)
{
foreach (var block in grid.GetFatBlocks())
{
if (block != null && Config._subtypes.Contains(block.DefinitionId.Value.SubtypeId.ToString()))
{
_turrets.Add((IMyFunctionalBlock)block);
}
}
foreach (var turret in _turrets)
{
turret.Enabled = false;
if (OnOffTimer)
{
turret.Enabled = true;
OnOffTimer = false;
}
}
}
public UserControl GetControl() => new PropertyGrid
{
Margin = new(3),
DataContext = _config.Data
};
[HarmonyPatch]
public class Patch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(MyGridJumpDriveSystem), "PerformJump")]
static void PerformJump(Vector3D __jumpTarget, ref MyGridJumpDriveSystem __instance)
{
var m_jumpdir = __jumpTarget - ((MyCubeGrid)AccessTools.Field(typeof(MyUpdateableGridSystem), "Grid").GetValue(__instance)).WorldMatrix.Translation;
AccessTools.Field(typeof(MyGridJumpDriveSystem), "m_jumpDirection").SetValue(__instance, m_jumpdir);
Vector3D m_jumpDirNorm;
AccessTools.Field(typeof(MyGridJumpDriveSystem), "m_jumpDirectionnorm").GetValue(__instance);
Vector3D.Normalize(ref m_jumpdir, out m_jumpDirNorm);
AccessTools.Field(typeof(MyGridJumpDriveSystem), "m_jumpDirectionnorm").SetValue(__instance, m_jumpDirNorm);
var m_userId = AccessTools.Field(typeof(MyGridJumpDriveSystem), "m_userId").GetValue(__instance);
AccessTools.Method(typeof(MyGridJumpDriveSystem), "DepleteJumpDrives").Invoke(__instance, new object[] { m_jumpdir, m_userId });
bool flag = false;
if ((bool)AccessTools.Method(typeof(MyGridJumpDriveSystem), "IsLocalCharacterAffectedByJump").Invoke(__instance, new Object[] { false }))
{
flag = true;
}
if (flag)
{
MyThirdPersonSpectator.Static.ResetViewerAngle(null);
MyThirdPersonSpectator.Static.ResetViewerDistance(null);
MyThirdPersonSpectator.Static.RecalibrateCameraPosition(false);
}
AccessTools.Field(typeof(MyGridJumpDriveSystem), "m_jumped").SetValue(__instance, true);
MatrixD worldMatrix = ((MyCubeGrid)AccessTools.Field(typeof(MyUpdateableGridSystem), "Grid").GetValue(__instance)).WorldMatrix;
worldMatrix.Translation = ((MyCubeGrid)AccessTools.Field(typeof(MyUpdateableGridSystem), "Grid").GetValue(__instance)).WorldMatrix.Translation + m_jumpdir;
((MyCubeGrid)AccessTools.Field(typeof(MyUpdateableGridSystem), "Grid").GetValue(__instance)).Teleport(worldMatrix, null, false);
if (flag)
{
MyThirdPersonSpectator.Static.ResetViewerAngle(null);
MyThirdPersonSpectator.Static.ResetViewerDistance(null);
MyThirdPersonSpectator.Static.RecalibrateCameraPosition(false);
}
Turret(grid);
}
}
}
}