-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquest_panel.lua
More file actions
240 lines (213 loc) · 13.9 KB
/
quest_panel.lua
File metadata and controls
240 lines (213 loc) · 13.9 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
local Constants = _G.require("Constants/Constants");
local ipairs = Constants.ipairs;
local tinsert = Constants.tinsert;
local find_type_definition = Constants.find_type_definition;
local hook = Constants.hook;
local set_native_field = Constants.set_native_field;
local to_managed_object = Constants.to_managed_object;
local to_int64 = Constants.to_int64;
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 GenericList_set_Item_method = Constants.GenericList_set_Item_method;
local getThisPtr = Constants.getThisPtr;
local isContain = Constants.isContain;
local GUI050000_type_def = find_type_definition("app.GUI050000");
local get_QuestCounterContext_method = GUI050000_type_def:get_method("get_QuestCounterContext");
local QuestCounterContext_type_def = get_QuestCounterContext_method:get_return_type();
local QuestViewType_field = QuestCounterContext_type_def:get_field("QuestViewType");
local LIST = QuestViewType_field:get_type():get_field("LIST"):get_data(nil);
local GUI050000QuestListParts_type_def = find_type_definition("app.GUI050000QuestListParts");
local get_ViewCategory_method = GUI050000QuestListParts_type_def:get_method("get_ViewCategory");
local get_ViewQuestDataList_method = GUI050000QuestListParts_type_def:get_method("get_ViewQuestDataList");
local set_ViewQuestDataList_method = GUI050000QuestListParts_type_def:get_method("set_ViewQuestDataList(System.Collections.Generic.List`1<app.cGUIQuestViewData>)");
local get_IsCancel_method = GUI050000QuestListParts_type_def:get_method("get_IsCancel");
local setSortDifficulty_method = GUI050000QuestListParts_type_def:get_method("setSortDifficulty(System.Boolean, System.Boolean, System.Boolean, System.Boolean, System.Boolean, System.Boolean, System.Boolean)");
-- false, false, false, false, false, false, false = High difficulty first
-- true, false, false, false, false, false, false = Low difficulty first
-- false, false, false, false, false, true, false = Most Attempts left
-- false, false, false, false, false, false, true = Least Attempts left
-- false, false, true, false, false, false, false = No password
-- false, false, false, true, false, false, false = Newly started first
-- false, false, false, false, true false, false = Open member slots
local setSortNewest_method = GUI050000QuestListParts_type_def:get_method("setSortNewest(System.Boolean)"); -- true = old first, false = new first
local PNLChangeSortType_field = GUI050000QuestListParts_type_def:get_field("_PNLChangeSortType");
local set_Message_method = PNLChangeSortType_field:get_type():get_method("set_Message(System.String)");
local Remove_method = get_ViewQuestDataList_method:get_return_type():get_method("Remove(app.cGUIQuestViewData)");
local GUIQuestViewData_type_def = find_type_definition("app.cGUIQuestViewData");
local get_MissionID_method = GUIQuestViewData_type_def:get_method("get_MissionID");
local get_MissionType_method = GUIQuestViewData_type_def:get_method("get_MissionType");
local Session_field = GUIQuestViewData_type_def:get_field("Session");
local STREAM_EVENTQUEST = get_MissionType_method:get_return_type():get_field("STREAM_EVENTQUEST"):get_data(nil);
local get_SearchResult_method = Session_field:get_type():get_method("get_SearchResult");
local SearchResultQuest_type_def = get_SearchResult_method:get_return_type();
local isLocked_field = SearchResultQuest_type_def:get_field("isLocked");
local isAutoAccept_field = SearchResultQuest_type_def:get_field("isAutoAccept");
local memberNum_field = SearchResultQuest_type_def:get_field("memberNum");
local maxMemberNum_field = SearchResultQuest_type_def:get_field("maxMemberNum");
local multiplaySetting_field = SearchResultQuest_type_def:get_field("multiplaySetting");
local NPC_ONLY = multiplaySetting_field:get_type():get_field("NPC_ONLY"):get_data(nil);
local get_Mission_method = Constants.UserSaveParam_type_def:get_method("get_Mission");
local get_MissionClearFlag_method = get_Mission_method:get_return_type():get_method("get_MissionClearFlag");
local isOn_method = get_MissionClearFlag_method:get_return_type():get_method("isOn(System.Int32)");
local get_Enabled_method = Constants.get_Enabled_method;
local getObject_method = Constants.gui_Control_type_def:get_method("getObject(System.String)");
local set_Visible_method = Constants.gui_PlayObject_type_def:get_method("set_Visible(System.Boolean)");
local CATEGORY_type_def = get_ViewCategory_method:get_return_type();
local CATEGORY_FREE = CATEGORY_type_def:get_field("FREE"):get_data(nil);
local CATEGORY_DECLARATION_HISTORY = CATEGORY_type_def:get_field("DECLARATION_HISTORY"):get_data(nil);
local CATEGORY_KEEP_QUEST = CATEGORY_type_def:get_field("KEEP_QUEST"):get_data(nil);
local CATEGORY_EVENT = CATEGORY_type_def:get_field("EVENT"):get_data(nil);
local CATEGORY_RECRUITMENT_LOBBY = CATEGORY_type_def:get_field("RECRUITMENT_LOBBY"):get_data(nil);
local CATEGORY_LINK_MEMBER = CATEGORY_type_def:get_field("LINK_MEMBER"):get_data(nil);
local CATEGORY_SERCH_RESCUE_SIGNAL = CATEGORY_type_def:get_field("SERCH_RESCUE_SIGNAL"):get_data(nil);
local SortDifficulty = {
CATEGORY_type_def:get_field("STORY"):get_data(nil),
CATEGORY_type_def:get_field("ARENA"):get_data(nil),
CATEGORY_type_def:get_field("CHALLENGE"):get_data(nil)
};
local MissionClearFlag = nil;
local function setSortDifficulty(obj, sortType)
if sortType == 0 then
setSortDifficulty_method:call(obj, false, false, false, false, false, false, false);
set_Message_method:call(PNLChangeSortType_field:get_data(obj), "난이도 높은 순");
elseif sortType == 4 then
setSortDifficulty_method:call(obj, false, false, false, true, false, false, false);
set_Message_method:call(PNLChangeSortType_field:get_data(obj), "퀘스트 시작 최신 순");
elseif sortType == 7 then
setSortDifficulty_method:call(obj, false, false, false, false, false, false, true);
set_Message_method:call(PNLChangeSortType_field:get_data(obj), "수주 가능 수 적은 순");
end
end
hook(GUI050000_type_def:get_method("onOpen"), getThisPtr, function()
local QuestCounterContext = get_QuestCounterContext_method:call(get_hook_storage().this_ptr);
if QuestViewType_field:get_data(QuestCounterContext) ~= LIST then
set_native_field(QuestCounterContext, QuestCounterContext_type_def, "QuestViewType", LIST);
end
end);
local isUserRequest = nil;
hook(GUI050000QuestListParts_type_def:get_method("sortQuestDataList(System.Boolean)"), function(args)
if (to_int64(args[3]) & 1) == 0 then
local this_ptr = args[2];
local CATEGORY = get_ViewCategory_method:call(this_ptr);
if CATEGORY == CATEGORY_FREE or CATEGORY == CATEGORY_DECLARATION_HISTORY or CATEGORY == CATEGORY_KEEP_QUEST or CATEGORY == CATEGORY_EVENT or CATEGORY == CATEGORY_RECRUITMENT_LOBBY
or CATEGORY == CATEGORY_LINK_MEMBER or CATEGORY == CATEGORY_SERCH_RESCUE_SIGNAL or isContain(SortDifficulty, CATEGORY) then
local storage = get_hook_storage();
storage.this_ptr = this_ptr;
storage.CATEGORY = CATEGORY;
isUserRequest = false;
return SKIP_ORIGINAL;
end
end
end, function()
if isUserRequest == false then
isUserRequest = nil;
local storage = get_hook_storage();
local this_ptr = storage.this_ptr;
if get_IsCancel_method:call(this_ptr) == false then
local CATEGORY = storage.CATEGORY;
if CATEGORY == CATEGORY_FREE or CATEGORY == CATEGORY_EVENT then
setSortDifficulty(this_ptr, 0);
local ViewQuestDataList = get_ViewQuestDataList_method:call(this_ptr);
local ViewQuestDataList_size = GenericList_get_Count_method:call(ViewQuestDataList);
if ViewQuestDataList_size > 0 then
local cleared_quests = {};
local uncleared_quests = {};
if MissionClearFlag == nil then
MissionClearFlag = get_MissionClearFlag_method:call(get_Mission_method:call(Constants.UserSaveData));
end
for i = 0, ViewQuestDataList_size - 1 do
local quest_data = GenericList_get_Item_method:call(ViewQuestDataList, i);
tinsert(isOn_method:call(MissionClearFlag, get_MissionID_method:call(quest_data)) and cleared_quests or uncleared_quests, quest_data);
end
local unclearedCount = #uncleared_quests;
local clearedCount = #cleared_quests;
if unclearedCount > 0 and clearedCount > 0 then
for i = 0, unclearedCount - 1 do
GenericList_set_Item_method:call(ViewQuestDataList, i, uncleared_quests[i + 1]);
end
for i = 0, clearedCount - 1 do
GenericList_set_Item_method:call(ViewQuestDataList, unclearedCount + i, cleared_quests[i + 1]);
end
end
cleared_quests = nil;
uncleared_quests = nil;
end
elseif CATEGORY == CATEGORY_DECLARATION_HISTORY then
setSortNewest_method:call(this_ptr, false);
set_Message_method:call(PNLChangeSortType_field:get_data(this_ptr), "새로운 순");
elseif CATEGORY == CATEGORY_KEEP_QUEST then
setSortDifficulty(this_ptr, 7);
elseif CATEGORY == CATEGORY_SERCH_RESCUE_SIGNAL then
local ViewQuestDataList = get_ViewQuestDataList_method:call(this_ptr);
local ViewQuestDataList_size = GenericList_get_Count_method:call(ViewQuestDataList);
if ViewQuestDataList_size > 0 then
local shouldHideItems = {};
for i = 0, ViewQuestDataList_size - 1 do
local quest_data = GenericList_get_Item_method:call(ViewQuestDataList, i);
local SearchResult = get_SearchResult_method:call(Session_field:get_data(quest_data));
if isAutoAccept_field:get_data(SearchResult) == false or (memberNum_field:get_data(SearchResult) >= maxMemberNum_field:get_data(SearchResult)) then
tinsert(shouldHideItems, quest_data);
end
end
if #shouldHideItems > 0 then
for _, v in ipairs(shouldHideItems) do
Remove_method:call(ViewQuestDataList, v);
end
set_ViewQuestDataList_method:call(this_ptr, ViewQuestDataList);
end
shouldHideItems = nil;
setSortDifficulty(this_ptr, 4);
end
elseif CATEGORY == CATEGORY_RECRUITMENT_LOBBY or CATEGORY == CATEGORY_LINK_MEMBER then
local ViewQuestDataList = get_ViewQuestDataList_method:call(this_ptr);
local ViewQuestDataList_size = GenericList_get_Count_method:call(ViewQuestDataList);
if ViewQuestDataList_size > 0 then
local shouldHideItems = {};
for i = 0, ViewQuestDataList_size - 1 do
local quest_data = GenericList_get_Item_method:call(ViewQuestDataList, i);
local SearchResult = get_SearchResult_method:call(Session_field:get_data(quest_data));
if isLocked_field:get_data(SearchResult) or isAutoAccept_field:get_data(SearchResult) == false or (memberNum_field:get_data(SearchResult) >= maxMemberNum_field:get_data(SearchResult)) or multiplaySetting_field:get_data(SearchResult) == NPC_ONLY then
tinsert(shouldHideItems, quest_data);
end
end
if #shouldHideItems > 0 then
for _, v in ipairs(shouldHideItems) do
Remove_method:call(ViewQuestDataList, v);
end
set_ViewQuestDataList_method:call(this_ptr, ViewQuestDataList);
end
shouldHideItems = nil;
setSortDifficulty(this_ptr, 4);
end
else
setSortDifficulty(this_ptr, 0);
end
end
end
end);
local validPNL = nil;
local function preUpdateItem(args)
local selectItem = args[3];
if get_Enabled_method:call(selectItem) then
local QuestViewData = to_managed_object(args[4]);
if QuestViewData ~= nil and get_MissionType_method:call(QuestViewData) == STREAM_EVENTQUEST then
if MissionClearFlag == nil then
MissionClearFlag = get_MissionClearFlag_method:call(get_Mission_method:call(Constants.UserSaveData));
end
if isOn_method:call(MissionClearFlag, get_MissionID_method:call(QuestViewData)) then
get_hook_storage().PNL = getObject_method:call(getObject_method:call(getObject_method:call(selectItem, "PNL_icon"), "PNL_icon_R_bottom"), "PNL_clear");
validPNL = true;
end
end
end
end
local function postUpdateItem()
if validPNL then
validPNL = nil;
set_Visible_method:call(get_hook_storage().PNL, true);
end
end
hook(find_type_definition("app.GUI050000QuestListParts.cQuestList_GridViewParts"):get_method("updateItem(via.gui.SelectItem, app.cGUIQuestViewData)"), preUpdateItem, postUpdateItem);
hook(find_type_definition("app.GUI050000QuestListParts.cQuestList_ListViewParts"):get_method("updateItem(via.gui.SelectItem, app.cGUIQuestViewData)"), preUpdateItem, postUpdateItem);