-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_select_nearest_camp.lua
More file actions
245 lines (210 loc) · 13.1 KB
/
auto_select_nearest_camp.lua
File metadata and controls
245 lines (210 loc) · 13.1 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
local Constants = _G.require("Constants/Constants");
local find_type_definition = Constants.find_type_definition;
local hook = Constants.hook;
local to_ptr = Constants.to_ptr;
local SKIP_ORIGINAL = Constants.SKIP_ORIGINAL;
local get_hook_storage = Constants.get_hook_storage;
local GenericList_get_Count_method = Constants.GenericList_get_Count_method;
local GenericList_get_Item_method = Constants.GenericList_get_Item_method;
local distance_method = find_type_definition("via.MathEx"):get_method("distance(via.vec3, via.vec3)"); -- static
local getFloorNumFromAreaNum_method = find_type_definition("app.GUIUtilApp.MapUtil"):get_method("getFloorNumFromAreaNum(app.FieldDef.STAGE, System.Int32)"); -- static
local AreaIconData_type_def = find_type_definition("app.user_data.MapStageDrawData.cAreaIconData");
local get_AreaIconPos_method = AreaIconData_type_def:get_method("get_AreaIconPos");
local get_AreaNum_method = AreaIconData_type_def:get_method("get_AreaNum");
local Int32_value_field = get_AreaNum_method:get_return_type():get_field("m_value");
local GUI050001_AcceptList_type_def = find_type_definition("app.GUI050001_AcceptList");
local QuestAcceptUI_field = GUI050001_AcceptList_type_def:get_field("_QuestAcceptUI");
local GUI050001_type_def = QuestAcceptUI_field:get_type();
local get_CurrentStartPointList_method = GUI050001_type_def:get_method("get_CurrentStartPointList");
local get_QuestOrderParam_method = GUI050001_type_def:get_method("get_QuestOrderParam");
local setCurrentSelectStartPointIndex_method = GUI050001_type_def:get_method("setCurrentSelectStartPointIndex(System.Int32)");
local StartPointList_field = GUI050001_type_def:get_field("_StartPointList");
local get_BeaconGimmick_method = find_type_definition("app.cStartPointInfo"):get_method("get_BeaconGimmick");
local GUIBeaconGimmick_type_def = get_BeaconGimmick_method:get_return_type();
local getPos_method = GUIBeaconGimmick_type_def:get_method("getPos");
local getExistAreaInfo_method = GUIBeaconGimmick_type_def:get_method("getExistAreaInfo");
local FieldAreaInfo_type_def = getExistAreaInfo_method:get_return_type();
local get_MapAreaNumSafety_method = FieldAreaInfo_type_def:get_method("get_MapAreaNumSafety");
local get_MapFloorNumSafety_method = FieldAreaInfo_type_def:get_method("get_MapFloorNumSafety");
local QuestOrderParam_type_def = get_QuestOrderParam_method:get_return_type();
local get_IsSameStageDeclaration_method = QuestOrderParam_type_def:get_method("get_IsSameStageDeclaration");
local QuestViewData_field = QuestOrderParam_type_def:get_field("QuestViewData");
local GUIQuestViewData_type_def = QuestViewData_field:get_type();
local get_TargetEmStartArea_method = GUIQuestViewData_type_def:get_method("get_TargetEmStartArea");
local get_Stage_method = GUIQuestViewData_type_def:get_method("get_Stage");
local InputCtrl_field = StartPointList_field:get_type():get_field("_InputCtrl");
local requestSelectIndexCore_method = find_type_definition("ace.cGUIInputCtrl_FluentScrollList`2<app.GUIID.ID,app.GUIFunc.TYPE>"):get_method("requestSelectIndexCore(System.Int32, System.Int32)");
local get_Camera_method = Constants.get_Camera_method;
local MasterPlCamera_field = get_Camera_method:get_return_type():get_field("_MasterPlCamera");
local get_LockTarget_method = MasterPlCamera_field:get_type():get_method("get_LockTarget");
local Context_field = get_LockTarget_method:get_return_type():get_field("_Context");
local get_Em_method = Context_field:get_type():get_method("get_Em");
local Area_field = get_Em_method:get_return_type():get_field("Area");
local get_CurrentAreaMoveSchedule_method = Area_field:get_type():get_method("get_CurrentAreaMoveSchedule");
local AreaMoveSchedule_type_def = get_CurrentAreaMoveSchedule_method:get_return_type();
local get_CurrentTargetPos_method = AreaMoveSchedule_type_def:get_method("get_CurrentTargetPos");
local get_RelayInfoList_method = AreaMoveSchedule_type_def:get_method("get_RelayInfoList");
local isInRelay_method = AreaMoveSchedule_type_def:get_method("isInRelay");
local RelayInfoPoint_getPos_method = find_type_definition("app.mcEnemyAreaMoveCoordinator.cSchedule.cRelayInfoPoint"):get_method("getPos");
local GUI060101CommonList_type_def = find_type_definition("app.cGUI060101CommonList");
local FastTravelList_field = GUI060101CommonList_type_def:get_field("_FastTravelList");
local BeaconGimmick_field = find_type_definition("app.cFastTravelInfo"):get_field("BeaconGimmick");
local STAGES = Constants.STAGES;
local DrawDatas = {};
local StartPointIdx = nil;
local shouldFocusFloorNum = nil;
local function setVars(GUI050001, startPointIdx)
StartPointIdx = startPointIdx;
setCurrentSelectStartPointIndex_method:call(GUI050001, startPointIdx);
requestSelectIndexCore_method:call(InputCtrl_field:get_data(StartPointList_field:get_data(GUI050001)), startPointIdx, 0);
end
hook(GUI050001_AcceptList_type_def:get_method("updateStartPointText"), function(args)
local GUI050001 = QuestAcceptUI_field:get_data(args[2]);
local QuestOrderParam = get_QuestOrderParam_method:call(GUI050001);
if get_IsSameStageDeclaration_method:call(QuestOrderParam) == false then
local startPointlist = get_CurrentStartPointList_method:call(GUI050001);
local startPointlist_size = GenericList_get_Count_method:call(startPointlist);
if startPointlist_size > 1 then
local QuestViewData = QuestViewData_field:get_data(QuestOrderParam);
local TargetEmStartArea_array = get_TargetEmStartArea_method:call(QuestViewData);
local TargetEmStartArea_array_size = TargetEmStartArea_array:get_size();
if TargetEmStartArea_array_size > 0 then
local Stage = get_Stage_method:call(QuestViewData);
local areaIconPosList = nil;
local sameFloor_shortest_distance, sameFloor_idx, sameFloor_FloorNum = nil, nil, nil;
local diffFloor_shortest_distance, diffFloor_idx, diffFloor_FloorNum = nil, nil, nil;
for i = 0, TargetEmStartArea_array_size - 1 do
local targetEmAreaNum = Int32_value_field:get_data(TargetEmStartArea_array:get_element(i));
if targetEmAreaNum ~= nil then
local areaIconPos, targetEmFloorNum = nil, nil;
for j = 0, startPointlist_size - 1 do
local BeaconGimmick = get_BeaconGimmick_method:call(GenericList_get_Item_method:call(startPointlist, j));
local FieldAreaInfo = getExistAreaInfo_method:call(BeaconGimmick);
if targetEmAreaNum == get_MapAreaNumSafety_method:call(FieldAreaInfo) then
if j > 0 then
setVars(GUI050001, j);
shouldFocusFloorNum = get_MapFloorNumSafety_method:call(FieldAreaInfo);
end
return;
end
if areaIconPos == nil then
if areaIconPosList == nil then
areaIconPosList = DrawDatas[Stage];
end
areaIconPos = areaIconPosList[targetEmAreaNum];
end
if areaIconPos ~= nil then
if targetEmFloorNum == nil then
targetEmFloorNum = getFloorNumFromAreaNum_method:call(nil, Stage, targetEmAreaNum);
end
local distance = distance_method:call(nil, areaIconPos, getPos_method:call(BeaconGimmick));
local Beacon_FloorNum = get_MapFloorNumSafety_method:call(FieldAreaInfo);
if Beacon_FloorNum == targetEmFloorNum then
if sameFloor_idx == nil or distance < sameFloor_shortest_distance then
sameFloor_shortest_distance, sameFloor_idx, sameFloor_FloorNum = distance, j, Beacon_FloorNum;
end
elseif diffFloor_idx == nil or distance < diffFloor_shortest_distance then
diffFloor_shortest_distance, diffFloor_idx, diffFloor_FloorNum = distance, j, Beacon_FloorNum;
end
end
end
end
end
if sameFloor_shortest_distance ~= nil and diffFloor_shortest_distance ~= nil and diffFloor_shortest_distance < (sameFloor_shortest_distance * 0.45) then
if diffFloor_idx > 0 then
setVars(GUI050001, diffFloor_idx);
shouldFocusFloorNum = diffFloor_FloorNum;
end
elseif sameFloor_idx ~= nil then
if sameFloor_idx > 0 then
setVars(GUI050001, sameFloor_idx);
shouldFocusFloorNum = sameFloor_FloorNum;
end
elseif diffFloor_idx ~= nil then
if diffFloor_idx > 0 then
setVars(GUI050001, diffFloor_idx);
shouldFocusFloorNum = diffFloor_FloorNum;
end
end
end
end
end
end);
hook(GUI050001_type_def:get_method("mapForceSelectFloor"), function(args)
if StartPointIdx ~= nil then
get_hook_storage().this_ptr = args[2];
end
if shouldFocusFloorNum ~= nil then
return SKIP_ORIGINAL;
end
end, function(retval)
if StartPointIdx ~= nil then
setVars(get_hook_storage().this_ptr, StartPointIdx);
StartPointIdx = nil;
end
if shouldFocusFloorNum ~= nil then
local dummy_retval = to_ptr(shouldFocusFloorNum);
shouldFocusFloorNum = nil;
return dummy_retval;
end
return retval;
end);
local hasEmTarget = nil;
hook(GUI060101CommonList_type_def:get_method("getFastTravelIndexNearestTarget"), function(args)
local LockTarget = get_LockTarget_method:call(MasterPlCamera_field:get_data(get_Camera_method:call(nil)));
if LockTarget ~= nil then
local storage = get_hook_storage();
storage.this_ptr = args[2];
storage.LockTarget = LockTarget;
hasEmTarget = true;
return SKIP_ORIGINAL;
end
end, function(retval)
if hasEmTarget then
hasEmTarget = nil;
local storage = get_hook_storage();
local AreaMoveSchedule = get_CurrentAreaMoveSchedule_method:call(Area_field:get_data(get_Em_method:call(Context_field:get_data(storage.LockTarget))));
local FastTravelList = FastTravelList_field:get_data(storage.this_ptr);
local destPos = nil;
local nearestIdx, nearestDist = nil, nil;
if isInRelay_method:call(AreaMoveSchedule) then
local RelayInfoList = get_RelayInfoList_method:call(AreaMoveSchedule);
destPos = RelayInfoPoint_getPos_method:call(GenericList_get_Item_method:call(RelayInfoList, GenericList_get_Count_method:call(RelayInfoList) - 1));
else
destPos = get_CurrentTargetPos_method:call(AreaMoveSchedule);
end
for i = 0, GenericList_get_Count_method:call(FastTravelList) - 1 do
local distance = distance_method:call(nil, destPos, getPos_method:call(BeaconGimmick_field:get_data(GenericList_get_Item_method:call(FastTravelList, i))));
if nearestDist == nil or distance < nearestDist then
nearestIdx, nearestDist = i, distance;
end
end
if nearestIdx ~= nil then
return to_ptr(nearestIdx);
end
end
return retval;
end);
do
local MapStageDrawData = Constants.call_object_func(Constants.call_native_func(Constants.GUIManager, Constants.GUIManager_type_def, "get_MAP3D"), "get_MapStageDrawData");
if MapStageDrawData ~= nil then
local getDrawData_method = MapStageDrawData:get_type_definition():get_method("getDrawData(app.FieldDef.STAGE)");
local get_AreaIconPosList_method = getDrawData_method:get_return_type():get_method("get_AreaIconPosList");
for _, stageID in Constants.pairs(STAGES) do
local DrawData = getDrawData_method:call(MapStageDrawData, stageID);
if DrawData ~= nil then
local AreaIconPosList = get_AreaIconPosList_method:call(DrawData);
if AreaIconPosList ~= nil then
DrawDatas[stageID] = {};
local thisStage = DrawDatas[stageID];
for i = 0, GenericList_get_Count_method:call(AreaIconPosList) - 1 do
local AreaIconData = GenericList_get_Item_method:call(AreaIconPosList, i);
if AreaIconData ~= nil then
thisStage[get_AreaNum_method:call(AreaIconData)] = get_AreaIconPos_method:call(AreaIconData);
end
end
end
end
end
end
end