-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoardControllerPatch.cs
210 lines (185 loc) · 8.99 KB
/
BoardControllerPatch.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
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
208
209
210
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using System.Reflection;
using UnityModManagerNet;
using SkaterXL.Core;
using Dreamteck.Splines;
namespace fro_mod
{
[HarmonyPatch(typeof(EventManager), nameof(EventManager.OnCatched), new Type[] { typeof(bool), typeof(bool) })]
class OnCatchedPatch
{
static bool Prefix(bool caughtRight, bool caughtLeft)
{
return Main.controller.shouldRunCatch();
}
}
[HarmonyPatch(typeof(StickInput), nameof(StickInput.OnStickPressed), new Type[] { typeof(bool) })]
class OnStickPressedPatch
{
static bool Prefix(bool p_right)
{
return Main.controller.shouldRunCatch();
}
}
[HarmonyPatch(typeof(IKController), nameof(IKController.SetIK), new Type[] { })]
class SetIKPatch
{
static bool Prefix()
{
return Main.controller.shouldRunCatch() && Main.controller.IsGrounded();
}
}
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.SetTargetToMaster), new Type[] { })]
class SetTargetToMasterPatch
{
static bool Prefix()
{
PlayerController.Instance.skaterController.skaterRigidbody.angularVelocity = PlayerController.Instance.boardController.boardRigidbody.angularVelocity;
PlayerController.Instance.skaterController.skaterRigidbody.velocity = PlayerController.Instance.boardController.boardRigidbody.velocity;
if (!Main.controller.IsGrabbing() && !Main.controller.was_leaning) PlayerController.Instance.boardController.boardRigidbody.angularVelocity = Vector3.zero;
PlayerController.Instance.movementMaster = PlayerController.MovementMaster.Target;
return false;
}
}
/*[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.GetNollie), new Type[] { typeof(bool) })]
class GetNolliePatch
{
static void Postfix(bool p_isRight, ref float __result)
{
if (MonoBehaviourSingleton<SettingsManager>.Instance.stance == Stance.Regular)
{
if (p_isRight)
{
if (PlayerController.Instance.inputController.RightStick.rawInput.pos.y <= -0.1f) __result = 0f;
}
else
{
if (PlayerController.Instance.inputController.LeftStick.rawInput.pos.y >= 0.1f) __result = 1f;
}
}
else
{
if (!p_isRight)
{
if (PlayerController.Instance.inputController.LeftStick.rawInput.pos.y <= -0.1f) __result = 0f;
}
else
{
if (PlayerController.Instance.inputController.RightStick.rawInput.pos.y >= 0.1f) __result = 1f;
}
}
Utils.Log(p_isRight + " " + PlayerController.Instance.inputController.LeftStick.rawInput.pos.y.ToString("N2") + " " + PlayerController.Instance.inputController.RightStick.rawInput.pos.y.ToString("N2") + " " + __result);
}
}*/
[HarmonyPatch(typeof(BoardController), nameof(BoardController.LerpCopingTarget), new Type[] { })]
class LerpCopingTargetPatch
{
static bool Prefix()
{
if (Main.settings.enabled && Main.settings.alternative_coping)
{
Traverse t = Traverse.Create(PlayerController.Instance.boardController);
Transform targetLerp = (Transform)t.Field("_copingTargetLerp").GetValue();
Transform target = (Transform)t.Field("_copingTarget").GetValue();
targetLerp.position = Vector3.SmoothDamp(targetLerp.position, target.position, ref Main.controller.copingTargetVelocity, Main.settings.coping_part_speed);
return false;
}
else return true;
}
}
[HarmonyPatch(typeof(BoardController), nameof(BoardController.AddTurnTorque), new Type[] { typeof(float) })]
class AddTurnTorquetPatch
{
static bool Prefix(float p_value, BoardController __instance)
{
if (Main.settings.enabled && Main.settings.customTurn)
{
p_value *= Main.settings.customSkateTurnMultiplier;
__instance.TurnTarget = p_value;
Traverse.Create(__instance).Field("removingTorque").SetValue(false);
float num = ((Mathf.Sign(p_value) < 0f) ? (-Main.settings.maxAngleClamp) : 0f);
float num2 = ((Mathf.Sign(p_value) > 0f) ? Main.settings.maxAngleClamp : 0f);
Vector3 vector = __instance.boardTransform.InverseTransformDirection(__instance.boardRigidbody.angularVelocity);
vector.y = Mathf.MoveTowards(vector.y, 3f * p_value, Time.deltaTime * Main.settings.customSkateTurnSpeed);
vector.y = Mathf.Clamp(vector.y, num, num2);
__instance.boardRigidbody.angularVelocity = __instance.boardTransform.TransformDirection(vector);
return false;
}
else return true;
}
}
[HarmonyPatch(typeof(BoardController), nameof(BoardController.SetCopingTargetLerp), new Type[] { typeof(Vector3) })]
class SetCopingTargetLerpPatch
{
static bool Prefix(Vector3 _pos)
{
if (Main.settings.enabled && Main.settings.alternative_coping)
{
Traverse t = Traverse.Create(PlayerController.Instance.boardController);
Transform targetLerp = (Transform)t.Field("_copingTargetLerp").GetValue();
float num = Main.settings.coping_part_distance;
for (int j = 0; j < 6; j++)
{
Vector3 closest = PlayerController.Instance.boardController.GetClosestCopingTarget(j);
float diff = Vector3.Distance(closest, _pos);
if (diff <= num)
{
num = diff;
targetLerp.position = closest;
}
}
return false;
}
else return true;
}
}
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.CheckForCopingGrind), new Type[] { typeof(SplineComputer), typeof(Vector2), typeof(Vector2) })]
class CheckForCopingGrindPatch
{
static bool Prefix(SplineComputer _splineComputer, Vector2 _leftStick, Vector2 _rightStick, PlayerController __instance)
{
if (Main.settings.enabled && Main.settings.alternative_coping)
{
if (_leftStick.magnitude > 0.15f || _rightStick.magnitude > 0.15f)
{
if (_splineComputer == null) return true;
Traverse t = Traverse.Create(PlayerController.Instance);
double percent = (double)t.Field("percent").GetValue();
SplineResult _splineResult = (SplineResult)t.Field("_splineResult").GetValue();
percent = _splineComputer.Project(__instance.boardController.boardTransform.position, 6, 0.01f, .99f);
_splineResult = _splineComputer.Evaluate(percent);
Vector3 direction = _splineResult.direction;
if (__instance.boardController.boardRigidbody.velocity.magnitude > 10f)
{
return false;
}
float _x = (float)t.Field("_x").GetValue();
float _y = (float)t.Field("_y").GetValue();
_x = Mathf.Clamp(_leftStick.x - _rightStick.x, -1f, 1f);
_y = Mathf.Clamp(_leftStick.y + _rightStick.y, -1f, 1f);
float _yAngle = (float)t.Field("_yAngle").GetValue();
_yAngle = _x * 90f;
Vector3 from = Vector3.ProjectOnPlane(__instance.boardController.GetClosestBoardForwardToVelocity(), _splineResult.normal);
float _angleToSpline = (float)t.Field("_angleToSpline").GetValue();
_angleToSpline = Vector3.Angle(from, direction);
Quaternion _newRot = (Quaternion)t.Field("_newRot").GetValue();
_newRot = Quaternion.AngleAxis(_yAngle, _splineResult.normal) * __instance.boardController.boardTransform.rotation;
Vector3 from2 = _newRot * Vector3.forward;
t.Field("_newAngleToGrindDir").SetValue(Vector3.Angle(from2, direction));
if (Vector3.Distance(__instance.boardController.SetCopingTarget(_y, Vector3.Angle(__instance.boardController.boardTransform.forward, direction)), _splineResult.position) < Main.settings.coping_part_distance)
{
__instance.playerSM.TransitionToEnterCopingStateSM(__instance.boardController._copingTarget, _newRot, _splineComputer, direction);
}
}
return false;
}
else return true;
}
}
}