-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_collect.lua
More file actions
365 lines (309 loc) · 19.2 KB
/
auto_collect.lua
File metadata and controls
365 lines (309 loc) · 19.2 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
local Constants = _G.require("Constants/Constants");
local ipairs = Constants.ipairs;
local tinsert = Constants.tinsert;
local hook = Constants.hook;
local find_type_definition = Constants.find_type_definition;
local to_int64 = Constants.to_int64;
local to_ptr = Constants.to_ptr;
local set_native_field = Constants.set_native_field;
local get_hook_storage = Constants.get_hook_storage;
local getThisPtr = Constants.getThisPtr;
local GenericList_get_Count_method = Constants.GenericList_get_Count_method;
local GenericList_get_Item_method = Constants.GenericList_get_Item_method;
local GenericList_Clear_method = Constants.GenericList_Clear_method;
local getGimmickContextHolder_method = find_type_definition("app.StoryUtil"):get_method("getGimmickContextHolder(app.GimmickDef.ID)"); -- static
local getRewardItemData_method = find_type_definition("app.GimmickRewardUtil"):get_method("getRewardItemData(app.GimmickDef.ID, app.FieldDef.STAGE, System.Boolean, System.Int32)"); -- static
local FacilityUtil_type_def = find_type_definition("app.FacilityUtil");
local isEnoughItem_method = FacilityUtil_type_def:get_method("isEnoughItem(app.ItemDef.ID, System.Int16, app.ItemUtil.STOCK_TYPE)"); -- static
local payItem_method = FacilityUtil_type_def:get_method("payItem(app.ItemDef.ID, System.Int16, app.ItemUtil.STOCK_TYPE)"); -- static
local isEnoughPoint_method = FacilityUtil_type_def:get_method("isEnoughPoint(System.Int32)"); -- static
local payPoint_method = FacilityUtil_type_def:get_method("payPoint(System.Int32)"); -- static
local Shikyu_method = find_type_definition("app.ItemDef"):get_method("Shikyu(app.ItemDef.ID)"); -- static
local ItemUtil_type_def = Constants.ItemUtil_type_def;
local changeItemNumFromDialogue_method = ItemUtil_type_def:get_method("changeItemNumFromDialogue(app.ItemDef.ID, System.Int16, app.ItemUtil.STOCK_TYPE, System.Boolean)"); -- static
local getSellItem_method = ItemUtil_type_def:get_method("getSellItem(app.ItemDef.ID, System.Int16, app.ItemUtil.STOCK_TYPE)"); -- static
local WeaponUtil_type_def = find_type_definition("app.WeaponUtil");
local getWeaponData_method = WeaponUtil_type_def:get_method("getWeaponData(System.Int32, app.WeaponDef.TYPE)"); -- static
local getWeaponEnumId_method = WeaponUtil_type_def:get_method("getWeaponEnumId(app.WeaponDef.TYPE, System.Int32)"); -- static
local get_Facility_method = Constants.get_Facility_method;
local FacilityManager_type_def = get_Facility_method:get_return_type();
local get_Dining_method = FacilityManager_type_def:get_method("get_Dining")
local get_Moriver_method = FacilityManager_type_def:get_method("get_Moriver");
local FacilityDining_type_def = get_Dining_method:get_return_type();
local getSuppliableFoodNum_method = FacilityDining_type_def:get_method("getSuppliableFoodNum");
local supplyFood_method = FacilityDining_type_def:get_method("supplyFood");
local getSuppliableFoodNumEx_method = FacilityDining_type_def:get_method("getSuppliableFoodNumEx");
local isSuppliableFoodMaxEx_method = FacilityDining_type_def:get_method("isSuppliableFoodMaxEx");
local supplyFoodEx_method = FacilityDining_type_def:get_method("supplyFoodEx");
local isSuppliableTicketSide_method = FacilityDining_type_def:get_method("isSuppliableTicketSide");
local supplyTicketSide_method = FacilityDining_type_def:get_method("supplyTicketSide");
local isSuppliableTicketMain_method = FacilityDining_type_def:get_method("isSuppliableTicketMain");
local supplyTicketMain_method = FacilityDining_type_def:get_method("supplyTicketMain");
local SettingData_field = FacilityDining_type_def:get_field("_SettingData");
local get_SupplyFoodMax_method = SettingData_field:get_type():get_method("get_SupplyFoodMax");
local FacilityMoriver_type_def = get_Moriver_method:get_return_type();
local get__HavingCampfire_method = FacilityMoriver_type_def:get_method("get__HavingCampfire");
local executedSharing_method = FacilityMoriver_type_def:get_method("executedSharing(app.FacilityMoriver.MoriverInfo)");
local MoriverInfos_field = FacilityMoriver_type_def:get_field("_MoriverInfos");
local MoriverInfo_type_def = find_type_definition("app.FacilityMoriver.MoriverInfo");
local FacilityId_field = MoriverInfo_type_def:get_field("_FacilityId");
local ItemFromMoriver_field = MoriverInfo_type_def:get_field("ItemFromMoriver");
local ItemFromPlayer_field = MoriverInfo_type_def:get_field("ItemFromPlayer");
local ItemWork_type_def = ItemFromMoriver_field:get_type();
local ItemWork_get_ItemId_method = ItemWork_type_def:get_method("get_ItemId");
local ItemWork_Num_field = ItemWork_type_def:get_field("Num");
local UserSaveParam_type_def = Constants.UserSaveParam_type_def;
local get_Equip_method = UserSaveParam_type_def:get_method("get_Equip");
local get_Collection_method = UserSaveParam_type_def:get_method("get_Collection");
local get_LargeWorkshop_method = UserSaveParam_type_def:get_method("get_LargeWorkshop");
local addEquipBoxWeapon_method = get_Equip_method:get_return_type():get_method("addEquipBoxWeapon(app.user_data.WeaponData.cData, app.EquipDef.WeaponRecipeInfo)");
local CollectionParam_type_def = get_Collection_method:get_return_type();
local get_CollectionNPC_method = CollectionParam_type_def:get_method("get_CollectionNPC");
local COLLECTION_NPC_NUM = CollectionParam_type_def:get_field("COLLECTION_NPC_NUM"):get_data(nil); -- static
local CollectionNPCParam_type_def = find_type_definition("app.savedata.cCollectionNPCParam");
local get_CollectionItem_method = CollectionNPCParam_type_def:get_method("get_CollectionItem");
local clearAllCollectionItem_method = CollectionNPCParam_type_def:get_method("clearAllCollectionItem");
local NPCFixedId_field = CollectionNPCParam_type_def:get_field("NPCFixedId");
local NPCFixedId_INIT_VALUE = CollectionNPCParam_type_def:get_field("NPCFixedId_INIT_VALUE"):get_data(nil); -- static
local Collection_MAX_ITEM_NUM = CollectionNPCParam_type_def:get_field("MAX_ITEM_NUM"):get_data(nil); -- static
local LargeWorkshopParam_type_def = get_LargeWorkshop_method:get_return_type();
local get_Rewards_method = LargeWorkshopParam_type_def:get_method("get_Rewards");
local clearRewardItem_method = LargeWorkshopParam_type_def:get_method("clearRewardItem(System.Int32)");
local LargeWorkshop_MAX_ITEM_NUM = LargeWorkshopParam_type_def:get_field("MAX_ITEM_NUM"):get_data(nil); -- static
local FacilityPugee_type_def = find_type_definition("app.FacilityPugee");
local stroke_method = FacilityPugee_type_def:get_method("stroke(System.Boolean)");
local FacilityRallus_type_def = find_type_definition("app.FacilityRallus");
local get_SupplyNum_method = FacilityRallus_type_def:get_method("get_SupplyNum");
local resetSupplyNum_method = FacilityRallus_type_def:get_method("resetSupplyNum");
local getSupplyItem_method = FacilityRallus_type_def:get_method("getSupplyItem(app.cGimmickContext)");
local Event_field = FacilityRallus_type_def:get_field("_Event");
local Element_field = Event_field:get_type():get_field("_Element");
local execute_method = Element_field:get_type():get_method("execute");
local get_Gimmick_method = find_type_definition("app.cGimmickContextHolder"):get_method("get_Gimmick");
local ReceiveItemInfo_get_ItemId_method = Constants.get_ItemId_method;
local ReceiveItemInfo_get_Num_method = Constants.ReceiveItemInfo_type_def:get_method("get_Num");
local GM262_000_00 = find_type_definition("app.GimmickDef.ID"):get_field("GM262_000_00"):get_data(nil);
local ST502 = Constants.STAGES.ST502;
local SupportShipData_type_def = find_type_definition("app.user_data.SupportShipData.cData");
local SupportShipData_get_ItemId_method = SupportShipData_type_def:get_method("get_ItemId");
local SupportShipData_get_WeaponType_method = SupportShipData_type_def:get_method("get_WeaponType");
local SupportShipData_get_ParamId_method = SupportShipData_type_def:get_method("get_ParamId");
local SupportShipData_get_StockNum_method = SupportShipData_type_def:get_method("get_StockNum");
local SupportShipData_get_Point_method = SupportShipData_type_def:get_method("get_Point");
local ItemID_type_def = ItemWork_get_ItemId_method:get_return_type();
local ItemID = {
NONE = ItemID_type_def:get_field("NONE"):get_data(nil),
MAX = ItemID_type_def:get_field("MAX"):get_data(nil)
};
local FacilityID_type_def = FacilityId_field:get_type();
local SHARING = FacilityID_type_def:get_field("SHARING"):get_data(nil);
local SWOP = FacilityID_type_def:get_field("SWOP"):get_data(nil);
local WeaponType_type_def = SupportShipData_get_WeaponType_method:get_return_type();
local WeaponType = {
INVALID = WeaponType_type_def:get_field("INVALID"):get_data(nil),
MAX = WeaponType_type_def:get_field("MAX"):get_data(nil)
};
local BOTH_BOX_POUCH = find_type_definition("app.ItemUtil.STOCK_TYPE"):get_field("BOTH_BOX_POUCH"):get_data(nil);
local BOTH_BOX_POUCH_ptr = to_ptr(BOTH_BOX_POUCH);
local TRUE_ptr = to_ptr(true);
hook(changeItemNumFromDialogue_method, function(args)
args[4] = BOTH_BOX_POUCH_ptr;
args[5] = TRUE_ptr;
end);
hook(find_type_definition("app.FacilityCollection"):get_method("lotItem"), nil, function()
local NPCParam_array = get_CollectionNPC_method:call(get_Collection_method:call(Constants.UserSaveData));
for i = 0, COLLECTION_NPC_NUM - 1 do
local NPCParam = NPCParam_array:get_element(i);
if NPCFixedId_field:get_data(NPCParam) ~= NPCFixedId_INIT_VALUE then
local CollectionItem = get_CollectionItem_method:call(NPCParam);
for j = 0, Collection_MAX_ITEM_NUM - 1 do
local ItemWork = CollectionItem:get_element(j);
local ItemId = ItemWork_get_ItemId_method:call(ItemWork);
if ItemId > ItemID.NONE and ItemId < ItemID.MAX then
local Num = ItemWork_Num_field:get_data(ItemWork);
if Num > 0 then
getSellItem_method:call(nil, ItemId, Num, BOTH_BOX_POUCH);
end
end
end
clearAllCollectionItem_method:call(NPCParam);
end
end
end);
hook(find_type_definition("app.FacilityLargeWorkshop"):get_method("endFestival"), nil, function()
local LargeWorkshopParam = get_LargeWorkshop_method:call(Constants.UserSaveData);
local Rewards = get_Rewards_method:call(LargeWorkshopParam);
for i = 0, LargeWorkshop_MAX_ITEM_NUM - 1 do
local Reward = Rewards:get_element(i);
local ItemId = ItemWork_get_ItemId_method:call(Reward);
if ItemId > ItemID.NONE and ItemId < ItemID.MAX then
local Num = ItemWork_Num_field:get_data(Reward);
if Num > 0 then
getSellItem_method:call(nil, ItemId, Num, BOTH_BOX_POUCH);
clearRewardItem_method:call(LargeWorkshopParam, i);
end
end
end
end);
hook(FacilityPugee_type_def:get_method("isEnableCoolTimer"), getThisPtr, function(retval)
if (to_int64(retval) & 1) == 0 then
stroke_method:call(get_hook_storage().this_ptr, true);
return TRUE_ptr;
end
return retval;
end);
local SupplyFoodMax = nil;
local function getSupplyFoodMax(FacilityDining)
if SupplyFoodMax == nil then
SupplyFoodMax = get_SupplyFoodMax_method:call(SettingData_field:get_data(FacilityDining));
end
return SupplyFoodMax;
end
local function getSuppliedFoods(FacilityDining)
if getSuppliableFoodNum_method:call(FacilityDining) - getSuppliableFoodNumEx_method:call(FacilityDining) >= getSupplyFoodMax(FacilityDining) then
supplyFood_method:call(FacilityDining);
end
end
local function getSuppliedFoodsEx(FacilityDining)
if isSuppliableFoodMaxEx_method:call(FacilityDining) then
supplyFoodEx_method:call(FacilityDining);
end
end
local function getSuppliedSideTicket(FacilityDining)
if isSuppliableTicketSide_method:call(FacilityDining) then
supplyTicketSide_method:call(FacilityDining);
end
end
local function getSuppliedMainTicket(FacilityDining)
if isSuppliableTicketMain_method:call(FacilityDining) then
supplyTicketMain_method:call(FacilityDining);
end
end
local function getItemFromMoriver(moriverInfo, completedTbl)
local ItemFromMoriver = ItemFromMoriver_field:get_data(moriverInfo);
local gettingItemId = ItemWork_get_ItemId_method:call(ItemFromMoriver);
if gettingItemId > ItemID.NONE and gettingItemId < ItemID.MAX then
local gettingNum = ItemWork_Num_field:get_data(ItemFromMoriver);
if gettingNum > 0 then
changeItemNumFromDialogue_method:call(nil, gettingItemId, gettingNum, BOTH_BOX_POUCH, true);
end
end
tinsert(completedTbl, moriverInfo);
end
local function execMoriver(facilityMoriver)
local MoriverInfos = MoriverInfos_field:get_data(facilityMoriver);
local moriverCount = GenericList_get_Count_method:call(MoriverInfos);
if moriverCount > 0 then
local completedMoriverInfos = {};
for i = 0, moriverCount - 1 do
local MoriverInfo = GenericList_get_Item_method:call(MoriverInfos, i);
local FacilityId = FacilityId_field:get_data(MoriverInfo);
if FacilityId == SHARING then
getItemFromMoriver(MoriverInfo, completedMoriverInfos);
elseif FacilityId == SWOP then
local ItemFromPlayer = ItemFromPlayer_field:get_data(MoriverInfo);
local givingItemId = ItemWork_get_ItemId_method:call(ItemFromPlayer);
if givingItemId > ItemID.NONE and givingItemId < ItemID.MAX then
local givingNum = ItemWork_Num_field:get_data(ItemFromPlayer);
if isEnoughItem_method:call(nil, givingItemId, givingNum, BOTH_BOX_POUCH) then
payItem_method:call(nil, givingItemId, givingNum, BOTH_BOX_POUCH);
getItemFromMoriver(MoriverInfo, completedMoriverInfos);
end
end
end
end
if #completedMoriverInfos > 0 then
for _, completedMoriverInfo in ipairs(completedMoriverInfos) do
executedSharing_method:call(facilityMoriver, completedMoriverInfo);
end
end
end
end
hook(find_type_definition("app.IngameState"):get_method("enter"), nil, function()
local FacilityManager = get_Facility_method:call(nil);
local FacilityMoriver = get_Moriver_method:call(FacilityManager);
if get__HavingCampfire_method:call(FacilityMoriver) then
execMoriver(FacilityMoriver);
end
local FacilityDining = get_Dining_method:call(FacilityManager);
getSuppliedFoods(FacilityDining);
getSuppliedFoodsEx(FacilityDining);
getSuppliedSideTicket(FacilityDining);
getSuppliedMainTicket(FacilityDining);
end);
hook(FacilityDining_type_def:get_method("addSupplyNum"), getThisPtr, function()
getSuppliedFoods(get_hook_storage().this_ptr);
end);
hook(FacilityDining_type_def:get_method("addSupplyEx(System.Int32)"), getThisPtr, function()
getSuppliedFoodsEx(get_hook_storage().this_ptr);
end);
hook(FacilityDining_type_def:get_method("isMaxTicketSide"), getThisPtr, function(retval)
getSuppliedSideTicket(get_hook_storage().this_ptr);
return retval;
end);
hook(FacilityDining_type_def:get_method("isMaxTicketMain"), getThisPtr, function(retval)
getSuppliedMainTicket(get_hook_storage().this_ptr);
return retval;
end);
hook(FacilityMoriver_type_def:get_method("startCampfire(System.Boolean)"), getThisPtr, function()
execMoriver(get_hook_storage().this_ptr);
end);
hook(FacilityRallus_type_def:get_method("supplyTimerGoal(app.cFacilityTimer)"), getThisPtr, function()
local GimmickContextHolder_list = getGimmickContextHolder_method:call(nil, GM262_000_00);
if GenericList_get_Count_method:call(GimmickContextHolder_list) > 0 then
getSupplyItem_method:call(get_hook_storage().this_ptr, get_Gimmick_method:call(GenericList_get_Item_method:call(GimmickContextHolder_list, 0)));
else
local this_ptr = get_hook_storage().this_ptr;
execute_method:call(Element_field:get_data(Event_field:get_data(this_ptr)));
set_native_field(this_ptr, FacilityRallus_type_def, "_IsGetting", true);
for i = 1, get_SupplyNum_method:call(this_ptr) do
local SendItemInfo = GenericList_get_Item_method:call(getRewardItemData_method:call(nil, GM262_000_00, ST502, false, 0), 0);
changeItemNumFromDialogue_method:call(nil, ReceiveItemInfo_get_ItemId_method:call(SendItemInfo), ReceiveItemInfo_get_Num_method:call(SendItemInfo), BOTH_BOX_POUCH, true);
end
resetSupplyNum_method:call(this_ptr);
set_native_field(this_ptr, FacilityRallus_type_def, "_IsGetting", false);
end
end);
local ItemID_Invalid_ptr = to_ptr(ItemID_type_def:get_field("INVALID"):get_data(nil));
local Int_Zero_ptr = to_ptr(0);
hook(Constants.FacilitySupplyItems_type_def:get_method("addItem(System.Collections.Generic.List`1<app.cSupplyInfo>, app.ItemDef.ID, System.Int16)"), function(args)
local ItemId = to_int64(args[3]) & 0xFFFFFFFF;
if Shikyu_method:call(nil, ItemId) == false then
getSellItem_method:call(nil, ItemId, to_int64(args[4]) & 0xFFFF, BOTH_BOX_POUCH);
args[3] = ItemID_Invalid_ptr;
args[4] = Int_Zero_ptr;
end
end);
hook(find_type_definition("app.savedata.cShipParam"):get_method("setItems(System.Collections.Generic.List`1<app.user_data.SupportShipData.cData>)"), function(args)
local dataList_ptr = args[3];
local EquipParam = nil;
for i = 0, GenericList_get_Count_method:call(dataList_ptr) - 1 do
local ShipData = GenericList_get_Item_method:call(dataList_ptr, i);
local StockNum = SupportShipData_get_StockNum_method:call(ShipData);
if StockNum > 0 then
local cost = SupportShipData_get_Point_method:call(ShipData);
for j = StockNum, 1, -1 do
local totalCost = cost * j;
if isEnoughPoint_method:call(nil, totalCost) then
local ItemId = SupportShipData_get_ItemId_method:call(ShipData);
if ItemId > ItemID.NONE and ItemId < ItemID.MAX then
getSellItem_method:call(nil, ItemId, j, BOTH_BOX_POUCH);
payPoint_method:call(nil, totalCost);
set_native_field(ShipData, SupportShipData_type_def, "_StockNum", StockNum - j);
else
local weaponType = SupportShipData_get_WeaponType_method:call(ShipData);
if weaponType > WeaponType.INVALID and weaponType < WeaponType.MAX then
if EquipParam == nil then
EquipParam = get_Equip_method:call(Constants.UserSaveData);
end
addEquipBoxWeapon_method:call(EquipParam, getWeaponData_method:call(nil, getWeaponEnumId_method:call(nil, weaponType, SupportShipData_get_ParamId_method:call(ShipData)), weaponType), nil);
payPoint_method:call(nil, totalCost);
set_native_field(ShipData, SupportShipData_type_def, "_StockNum", StockNum - j);
end
end
break;
end
end
end
end
end);