-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFireForget.cs
More file actions
207 lines (177 loc) · 7.71 KB
/
FireForget.cs
File metadata and controls
207 lines (177 loc) · 7.71 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GHPC.Utility;
using GHPC;
using GHPC.Vehicle;
using GHPC.Weapons;
using UnityEngine;
using HarmonyLib;
using MelonLoader;
using static UnityEngine.GraphicsBuffer;
using GHPC.Camera;
using UnityEngine.UI;
namespace PactIncreasedLethality
{
public class FireForget
{
private static HashSet<string> ff_ammo = new HashSet<string>();
public class FireForgetTracker : MonoBehaviour
{
public class MGUHelper : MonoBehaviour
{
public FireControlSystem fcs;
}
private CameraManager camera_manager;
public FireControlSystem fcs;
public MissileGuidanceUnit mgu;
public Vehicle target = null;
private Vehicle current_target = null;
private float TIME_TO_LOCK = 3f;
private float current_lock_time = 3f;
private float cd = 0;
public bool fired = false;
Vector3 velocity = Vector3.zero;
void Awake()
{
camera_manager = GameObject.Find("_APP_GHPC_").GetComponent<CameraManager>();
fcs = GetComponent<FireControlSystem>();
mgu = fcs.CurrentWeaponSystem.MissileGuidance;
MGUHelper mgu_helper = mgu.gameObject.AddComponent<MGUHelper>();
mgu_helper.fcs = fcs;
}
public void ResetGuidance()
{
current_lock_time = TIME_TO_LOCK;
mgu.transform.localPosition = new Vector3(-1.1509f, 0.5546f, 0.0471f);
mgu.transform.localEulerAngles = new Vector3(0.1569f, 359.86f, 0f);
mgu.AimElement = fcs.AimTransform;
target = null;
current_target = null;
fcs.GetComponent<BLYAT>().square.SetActive(false);
fcs.GetComponent<BLYAT>().square.GetComponent<Image>().color = Color.green;
}
public void SetTarget(Vehicle _target)
{
mgu.AimElement = mgu.gameObject.transform;
fcs.GetComponent<BLYAT>().square.SetActive(true);
fcs.GetComponent<BLYAT>().square.GetComponent<Image>().color = Color.red;
target = _target;
}
void DoLockOn()
{
if (fired) return;
RaycastHit raycast_hit;
int mask = ConstantsAndInfoManager.Instance.LaserRangefinderLayerMask.value;
if
(
!Physics.Raycast(fcs.LaserOrigin.position, fcs.LaserOrigin.forward, out raycast_hit, fcs.MaxLaserRange, mask)
|| raycast_hit.transform.gameObject.GetComponent<IArmor>() == null
|| raycast_hit.transform.gameObject.GetComponent<IArmor>().Unit == null
)
{
ResetGuidance();
return;
}
Vehicle _target = (Vehicle)raycast_hit.transform.gameObject.GetComponent<IArmor>().Unit;
if (current_lock_time > 0f)
{
current_lock_time -= Time.deltaTime;
current_target = _target;
}
else
{
SetTarget(_target);
}
if (_target != null && current_target != null && current_target.GetInstanceID() != _target.GetInstanceID())
{
ResetGuidance();
}
}
void Update()
{
DoLockOn();
if (current_target == null) return;
Vector3 s = camera_manager.CameraFollow.BufferedCamera.WorldToScreenPoint(current_target.Center.position);
fcs.GetComponent<BLYAT>().square.transform.position = Vector3.ClampMagnitude(new Vector3(s.x, s.y, 1f), 50f);
fcs.GetComponent<BLYAT>().square.SetActive(true);
if (target == null) return;
Vector3 loc = target.transform.position;
loc.y = target.transform.position.y + 120f;
mgu.transform.position = loc;
mgu.transform.LookAt(target.transform);
}
}
public static void AddFireForgetAmmo(AmmoType ammo_type)
{
if (!ff_ammo.Contains(ammo_type.Name))
ff_ammo.Add(ammo_type.Name);
}
[HarmonyPatch(typeof(GHPC.Weapons.FireControlSystem), "DoLase")]
public static class LockTarget
{
private static void Postfix(GHPC.Weapons.FireControlSystem __instance)
{
return;
if (!ff_ammo.Contains(__instance.CurrentAmmoType.Name)) return;
FireForgetTracker ff_tracker = __instance.GetComponent<FireForgetTracker>();
int layerMask = 1 << CodeUtils.LAYER_MASK_VISIBILITYONLY;
Vector3 laser_origin = __instance.LaserOrigin.position;
Vector3 forward = __instance.LaserOrigin.forward;
float max_lase_range = __instance.MaxLaserRange;
RaycastHit raycastHit;
if (Physics.Raycast(laser_origin, forward, out raycastHit, max_lase_range, layerMask) && raycastHit.collider.tag == "Smoke")
{
ff_tracker.ResetGuidance();
return;
}
if (
Physics.Raycast(laser_origin, forward, out raycastHit, max_lase_range, ConstantsAndInfoManager.Instance.LaserRangefinderLayerMask.value)
&& raycastHit.transform.gameObject != null
&& raycastHit.transform.gameObject.GetComponent<IArmor>() != null
&& raycastHit.transform.gameObject.GetComponent<IArmor>().Unit != null
)
{
ff_tracker.SetTarget((Vehicle)raycastHit.transform.gameObject.GetComponent<IArmor>().Unit);
return;
}
ff_tracker.ResetGuidance();
}
}
[HarmonyPatch(typeof(GHPC.Weapons.MissileGuidanceUnit), "OnGuidanceStarted")]
public static class Fired
{
private static void Prefix(GHPC.Weapons.MissileGuidanceUnit __instance)
{
if (__instance.gameObject.GetComponent<FireForgetTracker.MGUHelper>() == null) return;
__instance.gameObject.GetComponent<FireForgetTracker.MGUHelper>().fcs.GetComponent<FireForgetTracker>().fired = true;
}
}
[HarmonyPatch(typeof(GHPC.Weapons.MissileGuidanceUnit), "OnGuidanceStopped")]
public static class ResetTargetGuidanceStopped
{
private static void Postfix(GHPC.Weapons.MissileGuidanceUnit __instance)
{
if (__instance.gameObject.GetComponent<FireForgetTracker.MGUHelper>() == null) return;
__instance.gameObject.GetComponent<FireForgetTracker.MGUHelper>().fcs.GetComponent<FireForgetTracker>().ResetGuidance();
__instance.gameObject.GetComponent<FireForgetTracker.MGUHelper>().fcs.GetComponent<FireForgetTracker>().fired = false;
}
}
[HarmonyPatch(typeof(GHPC.Weapons.MissileGuidanceUnit), "StopGuidance")]
public static class KeepTracking
{
private static bool Prefix(GHPC.Weapons.MissileGuidanceUnit __instance)
{
if (__instance.CurrentMissiles.Count > 0 && ff_ammo.Contains(__instance.CurrentMissiles[0].ShotInfo.TypeInfo.Name))
{
return false;
}
return true;
}
}
}
}
*/