1
1
using Dalamud . Game . ClientState . Keys ;
2
2
using Dalamud . Plugin . Services ;
3
- using BossMod . Util ;
4
3
using Dalamud . Bindings . ImGui ;
5
4
using FFXIVClientStructs . FFXIV . Client . System . Framework ;
5
+ using CSGameObject = FFXIVClientStructs . FFXIV . Client . Game . Object . GameObject ;
6
+ using FFXIVClientStructs . FFXIV . Client . Game . Control ;
6
7
7
8
namespace BossMod ;
8
9
9
10
sealed class DebugTeleport
10
11
{
11
12
private bool EnableNoClip ;
12
- private float NoClipSpeed = 0.001f ;
13
+ private float NoClipSpeed = 0.0001f ;
13
14
private Vector3 inputCoordinates ;
14
15
15
16
public unsafe void Draw ( )
@@ -20,20 +21,22 @@ public unsafe void Draw()
20
21
{
21
22
Enable ( ) ;
22
23
ImGui . SameLine ( ) ;
23
- ImGui . SetNextItemWidth ( 150 ) ;
24
- ImGui . InputFloat ( "No Clip Speed" , ref NoClipSpeed , 0.001f ) ;
24
+ ImGui . SetNextItemWidth ( 150f ) ;
25
+ ImGui . InputFloat ( "No Clip Speed" , ref NoClipSpeed , 0.0001f , default , "%.4f" ) ;
25
26
}
26
27
else
27
28
{
28
29
Disable ( ) ;
29
30
}
31
+ var localPlayer = Service . ClientState . LocalPlayer ;
32
+ var pos = localPlayer != null ? localPlayer . Position : Vector3 . Zero ;
30
33
ImGui . Separator ( ) ;
31
34
ImGui . EndGroup ( ) ;
32
35
ImGui . BeginGroup ( ) ;
33
36
ImGui . Text ( "Current Player Coordinates:" ) ;
34
- ImGui . Text ( "X: " + PlayerEx . Position . X . ToString ( "F3" ) ) ;
35
- ImGui . Text ( "Y: " + PlayerEx . Position . Y . ToString ( "F3" ) ) ;
36
- ImGui . Text ( "Z: " + PlayerEx . Position . Z . ToString ( "F3" ) ) ;
37
+ ImGui . Text ( "X: " + pos . X . ToString ( "F3" ) ) ;
38
+ ImGui . Text ( "Y: " + pos . Y . ToString ( "F3" ) ) ;
39
+ ImGui . Text ( "Z: " + pos . Z . ToString ( "F3" ) ) ;
37
40
ImGui . EndGroup ( ) ;
38
41
ImGui . Separator ( ) ;
39
42
ImGui . BeginGroup ( ) ;
@@ -42,33 +45,22 @@ public unsafe void Draw()
42
45
{
43
46
SetPlayerPosition ( inputCoordinates ) ;
44
47
}
45
- ImGui . SetNextItemWidth ( 150 ) ;
48
+ ImGui . SetNextItemWidth ( 150f ) ;
46
49
ImGui . InputFloat ( "X Coordinate" , ref inputCoordinates . X , 1f ) ;
47
- ImGui . SetNextItemWidth ( 150 ) ;
50
+ ImGui . SetNextItemWidth ( 150f ) ;
48
51
ImGui . InputFloat ( "Y Coordinate" , ref inputCoordinates . Y , 1f ) ;
49
- ImGui . SetNextItemWidth ( 150 ) ;
52
+ ImGui . SetNextItemWidth ( 150f ) ;
50
53
ImGui . InputFloat ( "Z Coordinate" , ref inputCoordinates . Z , 1f ) ;
51
54
ImGui . EndGroup ( ) ;
52
55
}
53
56
54
- private void SetPlayerPosition ( Vector3 position )
57
+ private unsafe void SetPlayerPosition ( Vector3 position )
55
58
{
56
- try
59
+ var p = Service . ClientState . LocalPlayer ;
60
+ if ( p != null )
57
61
{
58
- if ( Service . ClientState . LocalPlayer != null )
59
- {
60
- // Assuming PlayerEx.SetPosition accepts a Vector3
61
- PlayerEx . SetPosition = position ;
62
- Service . Log ( $ "Player position set to: X = { position . X } , Y = { position . Y } , Z = { position . Z } ") ;
63
- }
64
- else
65
- {
66
- Service . Log ( "LocalPlayer is null. Unable to set position." ) ;
67
- }
68
- }
69
- catch ( Exception ex )
70
- {
71
- Service . Log ( $ "An error occurred while setting position: { ex . Message } ") ;
62
+ var obj = ( CSGameObject * ) p . Address ;
63
+ obj ->SetPosition ( position . X , position . Y , position . Z ) ;
72
64
}
73
65
}
74
66
@@ -86,41 +78,79 @@ private unsafe void OnUpdate(IFramework framework)
86
78
{
87
79
if ( EnableNoClip && ! Framework . Instance ( ) ->WindowInactive )
88
80
{
89
- if ( Service . KeyState . GetRawValue ( VirtualKey . SPACE ) != 0 || Utils . IsKeyPressed ( LimitedKeys . Space ) )
81
+ var p = Service . ClientState . LocalPlayer ;
82
+ if ( p == null )
83
+ {
84
+ return ;
85
+ }
86
+ var obj = ( CSGameObject * ) p . Address ;
87
+ var cameraDirH = CameraManager . Instance ( ) ->GetActiveCamera ( ) ->DirH ;
88
+
89
+ if ( IsKeyPressed ( 32 ) ) // space to go up
90
90
{
91
91
Service . KeyState . SetRawValue ( VirtualKey . SPACE , 0 ) ;
92
- PlayerEx . SetPosition = ( PlayerEx . Object . Position . X , PlayerEx . Object . Position . Y + NoClipSpeed , PlayerEx . Object . Position . Z ) . ToVector3 ( ) ;
92
+ var pos = p . Position ;
93
+ obj ->SetPosition ( pos . X , pos . Y + NoClipSpeed , pos . Z ) ;
93
94
}
94
- if ( Service . KeyState . GetRawValue ( VirtualKey . LSHIFT ) != 0 || Utils . IsKeyPressed ( LimitedKeys . LeftShiftKey ) )
95
+ else if ( IsKeyPressed ( 160 ) ) // left shift to go down
95
96
{
96
97
Service . KeyState . SetRawValue ( VirtualKey . LSHIFT , 0 ) ;
97
- PlayerEx . SetPosition = ( PlayerEx . Object . Position . X , PlayerEx . Object . Position . Y - NoClipSpeed , PlayerEx . Object . Position . Z ) . ToVector3 ( ) ;
98
+ var pos = p . Position ;
99
+ obj ->SetPosition ( pos . X , pos . Y - NoClipSpeed , pos . Z ) ;
98
100
}
99
- if ( Service . KeyState . GetRawValue ( VirtualKey . W ) != 0 || Utils . IsKeyPressed ( LimitedKeys . W ) )
101
+ if ( IsKeyPressed ( 87 ) ) // W to go forward
100
102
{
101
- var newPoint = Utils . RotatePoint ( PlayerEx . Object . Position . X , PlayerEx . Object . Position . Z , MathF . PI - PlayerEx . CameraEx ->DirH , PlayerEx . Object . Position + new Vector3 ( 0 , 0 , NoClipSpeed ) ) ;
102
103
Service . KeyState . SetRawValue ( VirtualKey . W , 0 ) ;
103
- PlayerEx . SetPosition = newPoint ;
104
+ var pos = p . Position ;
105
+ var newPos = RotatePoint ( pos . X , pos . Z , MathF . PI - cameraDirH , pos + new Vector3 ( 0f , 0f , NoClipSpeed ) ) ;
106
+ SetPosition ( ref newPos ) ;
104
107
}
105
- if ( Service . KeyState . GetRawValue ( VirtualKey . S ) != 0 || Utils . IsKeyPressed ( LimitedKeys . S ) )
108
+ else if ( IsKeyPressed ( 83 ) ) // S to go backwards
106
109
{
107
- var newPoint = Utils . RotatePoint ( PlayerEx . Object . Position . X , PlayerEx . Object . Position . Z , MathF . PI - PlayerEx . CameraEx ->DirH , PlayerEx . Object . Position + new Vector3 ( 0 , 0 , - NoClipSpeed ) ) ;
108
110
Service . KeyState . SetRawValue ( VirtualKey . S , 0 ) ;
109
- PlayerEx . SetPosition = newPoint ;
111
+ var pos = p . Position ;
112
+ var newPos = RotatePoint ( pos . X , pos . Z , MathF . PI - cameraDirH , pos + new Vector3 ( 0f , 0f , - NoClipSpeed ) ) ;
113
+ SetPosition ( ref newPos ) ;
110
114
}
111
- if ( Service . KeyState . GetRawValue ( VirtualKey . A ) != 0 || Utils . IsKeyPressed ( LimitedKeys . A ) )
115
+ if ( IsKeyPressed ( 65 ) ) // A to go left
112
116
{
113
- var newPoint = Utils . RotatePoint ( PlayerEx . Object . Position . X , PlayerEx . Object . Position . Z , MathF . PI - PlayerEx . CameraEx ->DirH , PlayerEx . Object . Position + new Vector3 ( NoClipSpeed , 0 , 0 ) ) ;
114
117
Service . KeyState . SetRawValue ( VirtualKey . A , 0 ) ;
115
- PlayerEx . SetPosition = newPoint ;
118
+ var pos = p . Position ;
119
+ var newPos = RotatePoint ( pos . X , pos . Z , MathF . PI - cameraDirH , pos + new Vector3 ( NoClipSpeed , 0f , 0f ) ) ;
120
+ SetPosition ( ref newPos ) ;
116
121
}
117
- if ( Service . KeyState . GetRawValue ( VirtualKey . D ) != 0 || Utils . IsKeyPressed ( LimitedKeys . D ) )
122
+ else if ( IsKeyPressed ( 68 ) ) // D to go right
118
123
{
119
- var newPoint = Utils . RotatePoint ( PlayerEx . Object . Position . X , PlayerEx . Object . Position . Z , MathF . PI - PlayerEx . CameraEx ->DirH , PlayerEx . Object . Position + new Vector3 ( - NoClipSpeed , 0 , 0 ) ) ;
120
124
Service . KeyState . SetRawValue ( VirtualKey . D , 0 ) ;
121
- PlayerEx . SetPosition = newPoint ;
125
+ var pos = p . Position ;
126
+ var newPos = RotatePoint ( pos . X , pos . Z , MathF . PI - cameraDirH , pos + new Vector3 ( - NoClipSpeed , 0f , 0f ) ) ;
127
+ SetPosition ( ref newPos ) ;
128
+ }
129
+
130
+ void SetPosition ( ref Vector3 pos ) => obj ->SetPosition ( pos . X , pos . Y , pos . Z ) ;
131
+ static Vector3 RotatePoint ( float cx , float cy , float angle , Vector3 p )
132
+ {
133
+ if ( angle == default )
134
+ {
135
+ return p ;
136
+ }
137
+ var ( sin , cos ) = MathF . SinCos ( angle ) ;
138
+
139
+ p . X -= cx ;
140
+ p . Z -= cy ;
141
+
142
+ var xnew = p . X * cos - p . Z * sin ;
143
+ var ynew = p . X * sin + p . Z * cos ;
144
+
145
+ p . X = xnew + cx ;
146
+ p . Z = ynew + cy ;
147
+ return p ;
148
+ }
149
+ static bool IsKeyPressed ( int key )
150
+ {
151
+ static bool IsBitSet ( short b , int pos ) => ( b & ( 1 << pos ) ) != 0 ;
152
+ return key != 0 && IsBitSet ( PInvoke . User32 . GetAsyncKeyState ( key ) , 15 ) ;
122
153
}
123
154
}
124
155
}
125
156
}
126
-
0 commit comments