From 6382f8da2adcf2e735e2046e90e693d522efda3c Mon Sep 17 00:00:00 2001 From: acooler15 Date: Wed, 3 Jul 2024 20:00:52 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=88=E7=A7=8D-?= =?UTF-8?q?=E6=B5=87=E6=B0=B4=E6=80=BB=E9=87=8F=E9=99=90=E5=88=B6=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/task/antCooperate/AntCooperate.java | 34 +++++++++++++++++-- .../antCooperate/AntCooperateRpcCall.java | 11 ++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperate.java b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperate.java index c7cc562f..5ee4f4c1 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperate.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperate.java @@ -23,12 +23,13 @@ public String getName() { private final BooleanModelField cooperateWater = new BooleanModelField("cooperateWater", "合种浇水", false); private final SelectModelField cooperateWaterList = new SelectModelField("cooperateWaterList", "合种浇水列表", new KVNode<>(new LinkedHashMap<>(), true), CooperateUser::getList); - + private final SelectModelField cooperateWaterTotalLimitList = new SelectModelField("cooperateWaterTotalLimitList", "浇水总量限制列表", new KVNode<>(new LinkedHashMap<>(), true), CooperateUser::getList); @Override public ModelFields getFields() { ModelFields modelFields = new ModelFields(); modelFields.addField(cooperateWater); modelFields.addField(cooperateWaterList); + modelFields.addField(cooperateWaterTotalLimitList); return modelFields; } @@ -64,12 +65,16 @@ public void run() { continue; Integer num = cooperateWaterList.getValue().getKey().get(cooperationId); if (num != null) { + Integer limitNum = cooperateWaterTotalLimitList.getValue().getKey().get(cooperationId); + if (limitNum != null) + num = calculatedWaterNum(UserIdMap.getCurrentUid(), cooperationId, num, limitNum); if (num > waterDayLimit) num = waterDayLimit; if (num > userCurrentEnergy) num = userCurrentEnergy; - if (num > 0) + if (num > 0) { cooperateWater(UserIdMap.getCurrentUid(), cooperationId, num, name); + } } } } else { @@ -99,4 +104,29 @@ private static void cooperateWater(String uid, String coopId, int count, String } } + private static int calculatedWaterNum(String uid, String coopId, int num, int limitNum) { + try{ + String s = AntCooperateRpcCall.queryCooperateRank("A", coopId); + JSONObject jo = new JSONObject(s); + if (jo.optBoolean("success", false)) { + JSONArray jaList = jo.getJSONArray("cooperateRankInfos"); + for (int i = 0; i < jaList.length(); i++) { + JSONObject joItem = jaList.getJSONObject(i); + String userId = joItem.getString("userId"); + if (userId.equals(uid)) { + int energySummation = joItem.optInt("energySummation", 0); + if (num > limitNum - energySummation) + num = limitNum - energySummation; + break; + } + } + } + } catch (Throwable t) { + Log.i(TAG, "calculatedWaterNum err:"); + Log.printStackTrace(TAG, t); + } finally { + return num; + } + + } } diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperateRpcCall.java b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperateRpcCall.java index 98c1c3c1..80f7e449 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperateRpcCall.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperateRpcCall.java @@ -21,4 +21,15 @@ public static String cooperateWater(String uid, String coopId, int count) { + "\"}]"); } + /** + * 获取合种浇水量排行 + * @param bizType 参数:D/A,“D”为查询当天,“A”为查询所有 + * @param coopId 合种ID + * @return + */ + public static String queryCooperateRank(String bizType, String coopId) { + return ApplicationHook.requestString("alipay.antmember.forest.h5.queryCooperateRank", + "[{\"bizType\":\""+ bizType + "\",\"cooperationId\":\"" + coopId + "\",\"source\":\"chInfo_ch_url-https://render.alipay.com/p/yuyan/180020010001247580/home.html\"}]"); + + } } From 14978fe5d35c4a9dca3d23826125cfdf2d26e377 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Thu, 4 Jul 2024 23:09:10 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=90=88=E5=B9=B6=20=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tkaxv7s/xposed/sesame/data/ModelTask.java | 2 +- .../model/task/antCooperate/AntCooperate.java | 17 ++++++++++++----- .../tkaxv7s/xposed/sesame/util/ThreadUtil.java | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/data/ModelTask.java b/app/src/main/java/tkaxv7s/xposed/sesame/data/ModelTask.java index cbd72326..a0fb6448 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/data/ModelTask.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/data/ModelTask.java @@ -232,7 +232,7 @@ public synchronized Boolean startTask(Boolean force) { public synchronized void stopTask() { for (ThreadPoolExecutor childThreadPool : childGroupThreadPoolMap.values()) { - ThreadUtil.shutdownAndAwaitTermination(childThreadPool, 10, TimeUnit.SECONDS); + ThreadUtil.shutdownAndAwaitTermination(childThreadPool, 3, TimeUnit.SECONDS); } childGroupThreadPoolMap.clear(); childTaskMap.clear(); diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperate.java b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperate.java index 5ee4f4c1..6bfe0ff9 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperate.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antCooperate/AntCooperate.java @@ -61,17 +61,21 @@ public void run() { String name = jo.getString("name"); int waterDayLimit = jo.getInt("waterDayLimit"); CooperationIdMap.add(cooperationId, name); - if (!Status.canCooperateWaterToday(UserIdMap.getCurrentUid(), cooperationId)) + if (!Status.canCooperateWaterToday(UserIdMap.getCurrentUid(), cooperationId)) { continue; + } Integer num = cooperateWaterList.getValue().getKey().get(cooperationId); if (num != null) { Integer limitNum = cooperateWaterTotalLimitList.getValue().getKey().get(cooperationId); - if (limitNum != null) + if (limitNum != null) { num = calculatedWaterNum(UserIdMap.getCurrentUid(), cooperationId, num, limitNum); - if (num > waterDayLimit) + } + if (num > waterDayLimit) { num = waterDayLimit; - if (num > userCurrentEnergy) + } + if (num > userCurrentEnergy) { num = userCurrentEnergy; + } if (num > 0) { cooperateWater(UserIdMap.getCurrentUid(), cooperationId, num, name); } @@ -101,6 +105,8 @@ private static void cooperateWater(String uid, String coopId, int count, String } catch (Throwable t) { Log.i(TAG, "cooperateWater err:"); Log.printStackTrace(TAG, t); + } finally { + TimeUtil.sleep(500); } } @@ -115,9 +121,10 @@ private static int calculatedWaterNum(String uid, String coopId, int num, int li String userId = joItem.getString("userId"); if (userId.equals(uid)) { int energySummation = joItem.optInt("energySummation", 0); - if (num > limitNum - energySummation) + if (num > limitNum - energySummation) { num = limitNum - energySummation; break; + } } } } diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/util/ThreadUtil.java b/app/src/main/java/tkaxv7s/xposed/sesame/util/ThreadUtil.java index 681e2cf0..09c224ef 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/util/ThreadUtil.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/util/ThreadUtil.java @@ -36,7 +36,7 @@ public static void shutdownAndAwaitTermination(ExecutorService pool, long timeou if (pool != null && !pool.isShutdown()) { pool.shutdown(); try { - if (!pool.awaitTermination(3, TimeUnit.SECONDS)) { + if (!pool.awaitTermination(1, TimeUnit.SECONDS)) { pool.shutdownNow(); if (!pool.awaitTermination(timeout, unit)) { Log.i(TAG, "thread pool can't close"); From 79615c49771f7c197d422423309428b2b8fdf457 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Thu, 4 Jul 2024 23:35:13 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E6=8D=90=E8=9B=8B?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sesame/model/task/antFarm/AntFarm.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antFarm/AntFarm.java b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antFarm/AntFarm.java index 188f42f8..cb4721a4 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antFarm/AntFarm.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antFarm/AntFarm.java @@ -258,11 +258,8 @@ public void run() { harvestProduce(ownerFarmId); } - if (donation.getValue() && harvestBenevolenceScore >= 1) { - Integer donationCountValue = donationCount.getValue(); - if (donationCountValue == DonationCount.ALL || Status.canDonationEgg(userId)) { - handleDonation(donationCountValue); - } + if (donation.getValue() && Status.canDonationEgg(userId) && harvestBenevolenceScore >= 1) { + handleDonation(donationCount.getValue()); } if (answerQuestion.getValue() && Status.canAnswerQuestionToday(UserIdMap.getCurrentUid())) { @@ -296,19 +293,21 @@ public void run() { enterFarm(); } - try { - Long startEatTime = ownerAnimal.startEatTime; - double allFoodHaveEatten = 0d; - double allConsumeSpeed = 0d; - for (Animal animal : animals) { - allFoodHaveEatten += animal.foodHaveEatten; - allConsumeSpeed += animal.consumeSpeed; + if (feedAnimal.getValue()) { + try { + Long startEatTime = ownerAnimal.startEatTime; + double allFoodHaveEatten = 0d; + double allConsumeSpeed = 0d; + for (Animal animal : animals) { + allFoodHaveEatten += animal.foodHaveEatten; + allConsumeSpeed += animal.consumeSpeed; + } + long nextFeedTime = startEatTime + (long) ((180 - (allFoodHaveEatten)) / (allConsumeSpeed)) * 1000; + addChildTask(new ChildModelTask("FA|" + ownerFarmId, "FA", () -> feedAnimal(ownerFarmId), nextFeedTime)); + Log.record("添加蹲点投喂🥣[" + UserIdMap.getCurrentMaskName() + "]在[" + DateFormat.getDateTimeInstance().format(nextFeedTime) + "]执行"); + } catch (Exception e) { + Log.printStackTrace(e); } - long nextFeedTime = startEatTime + (long) ((180 - (allFoodHaveEatten)) / (allConsumeSpeed)) * 1000; - addChildTask(new ChildModelTask("FA|" + ownerFarmId, "FA", () -> feedAnimal(ownerFarmId), nextFeedTime)); - Log.record("添加蹲点投喂🥣[" + UserIdMap.getCurrentMaskName() + "]在[" + DateFormat.getDateTimeInstance().format(nextFeedTime) + "]执行"); - } catch (Exception e) { - Log.printStackTrace(e); } if (unreceiveTaskAward > 0) { @@ -637,19 +636,23 @@ private void handleDonation(int donationType) { if ("SUCCESS".equals(memo)) { JSONArray jaActivityInfos = jo.getJSONArray("activityInfos"); String activityId = null, activityName = null; + boolean isDonation = false; for (int i = 0; i < jaActivityInfos.length(); i++) { jo = jaActivityInfos.getJSONObject(i); if (!jo.get("donationTotal").equals(jo.get("donationLimit"))) { activityId = jo.getString("activityId"); activityName = jo.optString("projectName", activityId); if (performDonation(activityId, activityName)) { + isDonation = true; if (donationType == DonationCount.ONE) { - Status.donationEgg(userId); break; } } } } + if (isDonation) { + Status.donationEgg(userId); + } if (activityId == null) { Log.record("今日已无可捐赠的活动"); } From 41444065fce41f654a50ecda3d5bf3c81310bee3 Mon Sep 17 00:00:00 2001 From: TKaxv_7S <954067342@qq.com> Date: Thu, 4 Jul 2024 23:52:44 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=97=B6=E9=85=8D=E7=BD=AE=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tkaxv7s/xposed/sesame/data/ConfigV2.java | 24 +++++++++---------- .../xposed/sesame/hook/ApplicationHook.java | 3 ++- .../xposed/sesame/hook/FriendManager.java | 2 +- .../model/task/antForest/AntForestV2.java | 2 +- .../xposed/sesame/util/CooperationIdMap.java | 8 +++---- .../tkaxv7s/xposed/sesame/util/UserIdMap.java | 8 +++---- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/data/ConfigV2.java b/app/src/main/java/tkaxv7s/xposed/sesame/data/ConfigV2.java index 787d53d5..81d123d0 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/data/ConfigV2.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/data/ConfigV2.java @@ -111,16 +111,6 @@ public T getModelFieldExt(String modelCode, String fieldC return (T) getModelField(modelCode, fieldCode); }*/ - public void reset() { - for (ModelFields modelFields : modelFieldsMap.values()) { - for (ModelField modelField : modelFields.values()) { - if (modelField != null) { - modelField.reset(); - } - } - } - } - public static Boolean isModify(String userId) { String json = null; File configV2File; @@ -194,7 +184,7 @@ public static synchronized ConfigV2 load(String userId) { Log.system(TAG, "复制新配置: " + userName); FileUtil.write2File(json, configV2File); } else { - INSTANCE.reset(); + unload(); Log.i(TAG, "初始新配置: " + userName); Log.system(TAG, "初始新配置: " + userName); FileUtil.write2File(JsonUtil.toJsonString(INSTANCE), configV2File); @@ -205,7 +195,7 @@ public static synchronized ConfigV2 load(String userId) { Log.i(TAG, "重置配置: " + userName); Log.system(TAG, "重置配置: " + userName); try { - INSTANCE.reset(); + unload(); if (configV2File != null) { FileUtil.write2File(JsonUtil.toJsonString(INSTANCE), configV2File); } @@ -218,4 +208,14 @@ public static synchronized ConfigV2 load(String userId) { return INSTANCE; } + public static synchronized void unload() { + for (ModelFields modelFields : INSTANCE.modelFieldsMap.values()) { + for (ModelField modelField : modelFields.values()) { + if (modelField != null) { + modelField.reset(); + } + } + } + } + } diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/hook/ApplicationHook.java b/app/src/main/java/tkaxv7s/xposed/sesame/hook/ApplicationHook.java index 80363c92..d3d25379 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/hook/ApplicationHook.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/hook/ApplicationHook.java @@ -531,12 +531,13 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable { private static void destroyHandler(Boolean force) { try { if (force) { - ModelTask.destroyAllModel(); if (context != null) { stopHandler(); BaseModel.destroyData(); Status.unload(); Statistics.unload(); + ConfigV2.unload(); + ModelTask.destroyAllModel(); } if (rpcResponseUnhook != null) { rpcResponseUnhook.unhook(); diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/hook/FriendManager.java b/app/src/main/java/tkaxv7s/xposed/sesame/hook/FriendManager.java index 4ab002cf..858c51c6 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/hook/FriendManager.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/hook/FriendManager.java @@ -30,7 +30,7 @@ public void run() { return; } try { - UserIdMap.clear(); + UserIdMap.unload(); String selfId = ApplicationHook.getUserId(); Class clsUserIndependentCache = loader.loadClass("com.alipay.mobile.socialcommonsdk.bizdata.UserIndependentCache"); Class clsAliAccountDaoOp = loader.loadClass("com.alipay.mobile.socialcommonsdk.bizdata.contact.data.AliAccountDaoOp"); diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antForest/AntForestV2.java b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antForest/AntForestV2.java index 9f373998..10dc01b2 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antForest/AntForestV2.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/model/task/antForest/AntForestV2.java @@ -979,7 +979,7 @@ private void collectEnergy(CollectEnergyEntity collectEnergyEntity, Boolean join Log.i(TAG, "collectUserBatchEnergy err:"); Log.printStackTrace(TAG, e); } finally { - NotificationUtil.updateLastExecText("收:" + totalCollected + ",帮:" + totalHelpCollected); + NotificationUtil.updateLastExecText("收:" + totalCollected + " 帮:" + totalHelpCollected); notifyMain(); } }); diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/util/CooperationIdMap.java b/app/src/main/java/tkaxv7s/xposed/sesame/util/CooperationIdMap.java index b6653700..81c86840 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/util/CooperationIdMap.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/util/CooperationIdMap.java @@ -16,15 +16,15 @@ public static Map getMap() { return readOnlyIdMap; } - public synchronized static void add(String key, String value) { + public static synchronized void add(String key, String value) { idMap.put(key, value); } - public synchronized static void remove(String key) { + public static synchronized void remove(String key) { idMap.remove(key); } - public synchronized static void load(String userId) { + public static synchronized void load(String userId) { idMap.clear(); try { String body = FileUtil.readFromFile(FileUtil.getCooperationIdMapFile(userId)); @@ -38,7 +38,7 @@ public synchronized static void load(String userId) { } } - public synchronized static boolean save(String userId) { + public static synchronized boolean save(String userId) { return FileUtil.write2File(JsonUtil.toNoFormatJsonString(idMap), FileUtil.getCooperationIdMapFile(userId)); } diff --git a/app/src/main/java/tkaxv7s/xposed/sesame/util/UserIdMap.java b/app/src/main/java/tkaxv7s/xposed/sesame/util/UserIdMap.java index 497461e9..7aeabad8 100644 --- a/app/src/main/java/tkaxv7s/xposed/sesame/util/UserIdMap.java +++ b/app/src/main/java/tkaxv7s/xposed/sesame/util/UserIdMap.java @@ -97,6 +97,10 @@ public synchronized static void load(String userId) { } } + public synchronized static void unload() { + userMap.clear(); + } + public synchronized static boolean save(String userId) { return FileUtil.write2File(JsonUtil.toNoFormatJsonString(userMap), FileUtil.getFriendIdMapFile(userId)); } @@ -119,8 +123,4 @@ public synchronized static boolean saveSelf(UserEntity userEntity) { return FileUtil.write2File(JsonUtil.toNoFormatJsonString(userEntity), FileUtil.getSelfIdFile(userEntity.getUserId())); } - public synchronized static void clear() { - userMap.clear(); - } - }