-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathAFix.py
198 lines (173 loc) · 6.77 KB
/
AFix.py
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
from shapely.geometry import Point
from FFxivPythonTrigger import *
from FFxivPythonTrigger.Utils import sector
from FFxivPythonTrigger.memory.StructFactory import *
from shapely.ops import cascaded_union, nearest_points
import math
command = "@afix"
FRONT = 1
SIDE = 2
BACK = 3
DEFAULT_DISTANCE = 5
skills = {
7481: BACK, # 月光,背
7482: SIDE, # 花车,侧
53: BACK, # 连击,背,武僧
54: BACK, # 正拳,背,武僧
56: SIDE, # 崩拳,侧,武僧
74: SIDE, # 双龙脚,侧,武僧
61: SIDE, # 双掌打,侧,武僧
66: BACK, # 破碎拳,背,武僧
2255: BACK, # 旋风刃,背
3563: SIDE, # 强甲破点突,侧
2258: BACK, # 攻其不备,背
88: BACK, # 樱花怒放,背
3556: BACK, # 龙尾,背
3554: SIDE, # 龙牙,侧
}
Vector3 = OffsetStruct({
'x': c_float,
'z': c_float,
'y': c_float,
})
PositionSetPack = OffsetStruct({
'r': (c_float, 0),
'unk0': (c_ushort, 0x4),
'unk1': (c_ushort, 0x6),
'pos': (Vector3, 0x8),
'unk2': (c_uint, 0x14),
}, 24)
ActionSend = OffsetStruct({
'_unk_ushort0': (c_ushort, 0x0),
'_unk_ushort1': (c_ushort, 0x2),
'skill_id': (c_uint, 0x4),
'cnt': (c_ushort, 0x8),
'_unk_ushort4': (c_ushort, 0xa),
'_unk_ushort5': (c_ushort, 0xc),
'_unk_ushort6': (c_ushort, 0xe),
'target_id': (c_uint, 0x10),
}, 32)
PositionAdjustPack = OffsetStruct({
'old_r': (c_float, 0x0),
'new_r': (c_float, 0x4),
'unk0': (c_ushort, 0x8),
'unk1': (c_ushort, 0xA),
'old_pos': (Vector3, 0xC),
'new_pos': (Vector3, 0x18),
'unk2': (c_uint, 0x24),
}, 40)
angle = math.pi / 2 - 0.1
def get_skill_data(skill_id):
if isinstance(skills[skill_id], int):
return skills[skill_id], lambda x: True
return skills[skill_id]
def get_nearest(me_pos, target, mode, dis=3):
radius = target.HitboxRadius + dis - 0.5
if mode == SIDE:
area1 = sector(target.pos.x, target.pos.y, radius, angle, target.pos.r + math.pi / 2)
area2 = sector(target.pos.x, target.pos.y, radius, angle, target.pos.r - math.pi / 2)
area = cascaded_union([area1, area2])
elif mode == FRONT:
area = sector(target.pos.x, target.pos.y, radius, angle, target.pos.r)
elif mode == BACK:
area = sector(target.pos.x, target.pos.y, radius, angle, target.pos.r - math.pi)
else:
area = target.hitbox
area = area.difference(Point(target.pos.x, target.pos.y).buffer(0.5))
me = Point(me_pos.x, me_pos.y)
if area.contains(me):
return None
p1 = nearest_points(area, me)[0]
return p1.x, p1.y
def distance(xy1, xy2):
return math.sqrt((xy1[0] - xy2[0]) ** 2 + (xy1[1] - xy2[1]) ** 2)
class AFix(PluginBase):
name = "AFix"
git_repo = 'nyouoG/fpt_plugins'
repo_path = 'AFix.py'
hash_path = __file__
def __init__(self):
super().__init__()
self.last_reset = perf_counter()
api.XivNetwork.register_makeup("ActionSend", self.makeup_action)
self.register_event(f'network/action_effect', self.coor_return)
self._enable = False
self.work = False
self.adjust_mode = True
self.adjust_sig = 0
self.set_sig = 0x93
self.register_event('network/position_adjust', self.deal_adjust)
self.register_event('network/position_set', self.deal_set)
self.storage.data.setdefault('distance', DEFAULT_DISTANCE)
self.storage.save()
api.command.register(command, self.process_command)
def _onunload(self):
api.XivNetwork.unregister_makeup("ActionSend", self.makeup_action)
api.command.unregister(command)
def deal_adjust(self, evt):
self.adjust_mode = True
self.adjust_sig = evt.raw_msg.unk1 & 0xf
def deal_set(self, evt):
self.adjust_mode = False
if not (evt.raw_msg.unk0 or evt.raw_msg.unk1) and 0x10000 > evt.raw_msg.unk2 > 0:
self.set_sig = evt.raw_msg.unk2
def goto(self, new_x=None, new_y=None, new_r=None, stop=False):
c = api.Coordinate()
if new_r is None:
new_r = c.r
target = Vector3(x=new_x if new_x is not None else c.x, y=new_y if new_y is not None else c.y, z=c.z)
if self.adjust_mode:
msg = PositionAdjustPack(
old_r=c.r,
new_r=new_r,
old_pos=target,
new_pos=target,
unk0=(0x4000 if stop else 0),
unk1=(0x40 if stop else 0) | self.adjust_sig
)
code = "UpdatePositionInstance"
else:
msg = PositionSetPack(r=new_r, pos=target, unk2=self.set_sig if stop else 0)
code = "UpdatePositionHandler"
self.logger.debug(f'goto x:{target.x:.2f} y:{target.y:.2f} z:{target.z:.2f} r:{new_r:.2f}', hex(msg.unk0), hex(msg.unk1), hex(msg.unk2))
api.XivNetwork.send_messages([(code, bytearray(msg))], False)
def coor_return(self, evt):
if not self.work or evt.source_id != api.XivMemory.actor_table.get_me().id or evt.action_type != 'action' or evt.action_id not in skills:
return
self.goto(stop=True)
self.work = False
def process_command(self, args):
if args:
if args[0] == 'on':
self._enable = True
elif args[0] == 'off':
self._enable = False
elif args[0] == 'set':
self.storage.data['distance'] = float(args[1])
else:
api.Magic.echo_msg("unknown args: %s" % args[0])
else:
self._enable = not self._enable
api.Magic.echo_msg("AFix: [%s][%s]" % (('enable' if self._enable else 'disable'), self.storage.data['distance']))
self.storage.save()
def makeup_action(self, header, raw):
d = ActionSend.from_buffer(raw)
me = api.XivMemory.actor_table.get_me()
me_effects = me.effects.get_dict()
if self._enable and d.skill_id in skills and 1250 not in me_effects and 1179 not in me_effects:
t = api.XivMemory.actor_table.get_actor_by_id(d.target_id)
if t is not None and t.is_positional:
pos, statement = get_skill_data(d.skill_id)
if statement(d.skill_id):
c = api.Coordinate()
xy = get_nearest(c, t, pos)
if xy is not None :
dis=distance(xy, (c.x, c.y))
if dis>=self.storage.data['distance']:
self.logger.debug(f"too far to fix: {dis}")
else:
new_r = api.Coordinate().r
new_r = new_r + (-math.pi if new_r > 0 else math.pi)
self.work = True
self.goto(*xy, new_r)
return header, bytearray(d)