Skip to content

Commit

Permalink
Merge pull request constanline#544 from TKaxv-7S/1.2.3-bate14-fix
Browse files Browse the repository at this point in the history
修复 闪屏异常等
  • Loading branch information
constanline authored Jun 7, 2024
2 parents 83f8e32 + c821ad8 commit 4ec8b83
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public static void start() {
@Override
public void run() {
try {
while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty())
Thread.sleep(101);
FriendIdMap.waitingCurrentUid();
ancientTree(Config.getAncientTreeCityCodeList()); // 二次检查 有时会返回繁忙漏保护
} catch (Throwable t) {
Log.i(TAG, "start.run err:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public static void start() {
@Override
public void run() {
try {
while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty())
Thread.sleep(100);
FriendIdMap.waitingCurrentUid();
String s = AntCooperateRpcCall.queryUserCooperatePlantList();
if (s == null) {
Thread.sleep(RandomUtils.delay());
Expand Down
24 changes: 15 additions & 9 deletions app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

import org.json.JSONArray;
import org.json.JSONObject;
import pansong291.xposed.quickenergy.hook.AntFarmRpcCall;
import pansong291.xposed.quickenergy.util.*;
import pansong291.xposed.quickenergy.hook.DadaDailyRpcCall;

import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import pansong291.xposed.quickenergy.hook.AntFarmRpcCall;
import pansong291.xposed.quickenergy.hook.DadaDailyRpcCall;
import pansong291.xposed.quickenergy.util.Config;
import pansong291.xposed.quickenergy.util.FriendIdMap;
import pansong291.xposed.quickenergy.util.Log;
import pansong291.xposed.quickenergy.util.PluginUtils;
import pansong291.xposed.quickenergy.util.RandomUtils;
import pansong291.xposed.quickenergy.util.Statistics;
import pansong291.xposed.quickenergy.util.StringUtil;
import pansong291.xposed.quickenergy.util.TimeUtil;

public class AntFarm {
private static final String TAG = AntFarm.class.getCanonicalName();
Expand Down Expand Up @@ -124,12 +132,10 @@ public static void start() {
@Override
public void run() {
try {
while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty())
Thread.sleep(100);
FriendIdMap.waitingCurrentUid();
String s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid());
if (s == null) {
Thread.sleep(RandomUtils.delay());
s = AntFarmRpcCall.enterFarm("", FriendIdMap.getCurrentUid());
throw new RuntimeException("庄园加载失败");
}
JSONObject jo = new JSONObject(s);
if ("SUCCESS".equals(jo.getString("memo"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ private static void canCollectSelfEnergy() {
try {
boolean hasMore = false;
long start = System.currentTimeMillis();
//TODO 修复 6秒拼手速活动导致数据错误,目前只能关闭该活动
String s = AntForestRpcCall.queryHomePage();
long end = System.currentTimeMillis();
if (s == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public static void receivePoint() {
@Override
public void run() {
try {
while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty())
Thread.sleep(100);
FriendIdMap.waitingCurrentUid();
if (Statistics.canMemberSignInToday(FriendIdMap.getCurrentUid())) {
String s = AntMemberRpcCall.queryMemberSigninCalendar();
JSONObject jo = new JSONObject(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public static void start() {
@Override
public void run() {
try {
while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty())
Thread.sleep(100);
FriendIdMap.waitingCurrentUid();
String s = AntOceanRpcCall.queryOceanStatus();
JSONObject jo = new JSONObject(s);
if ("SUCCESS".equals(jo.getString("resultCode"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public Thread setData(ClassLoader cl) {
@Override
public void run() {
try {
while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty())
Thread.sleep(100);
FriendIdMap.waitingCurrentUid();
if (Config.openTreasureBox())
queryMyHomePage(loader);

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/pansong291/xposed/quickenergy/Reserve.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public static void start() {
@Override
public void run() {
try {
while (FriendIdMap.getCurrentUid() == null || FriendIdMap.getCurrentUid().isEmpty())
Thread.sleep(100);
FriendIdMap.waitingCurrentUid();
if (Config.reserve()) {
animalReserve();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

import pansong291.xposed.quickenergy.util.RandomUtils;

public class AntFarmRpcCall {
Expand Down
126 changes: 76 additions & 50 deletions app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package pansong291.xposed.quickenergy.hook;

import de.robv.android.xposed.XposedHelpers;
import org.json.JSONObject;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DateFormat;

import de.robv.android.xposed.XposedHelpers;
import pansong291.xposed.quickenergy.AntForestNotification;
import pansong291.xposed.quickenergy.AntForestToast;
import pansong291.xposed.quickenergy.data.RuntimeInfo;
import pansong291.xposed.quickenergy.util.Config;
import pansong291.xposed.quickenergy.util.Log;
import pansong291.xposed.quickenergy.util.RandomUtils;
import pansong291.xposed.quickenergy.util.StringUtil;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DateFormat;

public class RpcUtil {
private static final String TAG = RpcUtil.class.getCanonicalName();
private static Method rpcCallMethod;
Expand Down Expand Up @@ -65,61 +67,85 @@ public static String request(String args0, String args1) {
if (isInterrupted) {
return null;
}
try {
Object o;
if (rpcCallMethod.getParameterTypes().length == 12) {
o = rpcCallMethod.invoke(
null, args0, args1, "", true, null, null, false, curH5PageImpl, 0, "", false, -1);
} else {
o = rpcCallMethod.invoke(
null, args0, args1, "", true, null, null, false, curH5PageImpl, 0, "", false, -1, "");
}
String str = getResponse(o);
Log.i(TAG, "argument: " + args0 + ", " + args1);
Log.i(TAG, "response: " + str);
String result = null;
int count = 0;
while (count < 3) {
count++;
try {
JSONObject jo = new JSONObject(str);
if (jo.optString("memo", "").contains("系统繁忙")) {
isInterrupted = true;
AntForestNotification.setContentText("系统繁忙,可能需要滑动验证");
Log.recordLog("系统繁忙,可能需要滑动验证");
return str;
Object o;
if (rpcCallMethod.getParameterTypes().length == 12) {
o = rpcCallMethod.invoke(
null, args0, args1, "", true, null, null, false, curH5PageImpl, 0, "", false, -1);
} else {
o = rpcCallMethod.invoke(
null, args0, args1, "", true, null, null, false, curH5PageImpl, 0, "", false, -1, "");
}
} catch (Throwable ignored) { }
return str;
} catch (Throwable t) {
Log.i(TAG, "invoke err:");
Log.printStackTrace(TAG, t);
if (t instanceof InvocationTargetException) {
String msg = t.getCause().getMessage();
if (!StringUtil.isEmpty(msg)) {
if (msg.contains("登录超时")) {
String str = getResponse(o);
Log.i(TAG, "argument: " + args0 + ", " + args1);
Log.i(TAG, "response: " + str);
try {
JSONObject jo = new JSONObject(str);
if (jo.optString("memo", "").contains("系统繁忙")) {
isInterrupted = true;
AntForestNotification.setContentText("登录超时");
if (AntForestToast.context != null) {
if (Config.timeoutRestart()) {
Log.recordLog("尝试重启!");
if (Config.timeoutType() == XposedHook.StayAwakeType.ALARM) {
XposedHook.alarmHook(AntForestToast.context, 3000, true);
} else {
XposedHook.alarmBroadcast(AntForestToast.context, 3000, true);
AntForestNotification.setContentText("系统繁忙,可能需要滑动验证");
Log.recordLog("系统繁忙,可能需要滑动验证");
return str;
}
} catch (Throwable ignored) {
}
return str;
} catch (Throwable t) {
Log.i(TAG, "rpc [" + args0 + "] err:");
Log.printStackTrace(TAG, t);
result = null;
if (t instanceof InvocationTargetException) {
String msg = t.getCause().getMessage();
if (!StringUtil.isEmpty(msg)) {
if (msg.contains("登录超时")) {
if (!isInterrupted && !XposedHook.getIsRestart()) {
isInterrupted = true;
AntForestNotification.setContentText("登录超时");
if (AntForestToast.context != null) {
if (Config.timeoutRestart()) {
Log.recordLog("尝试重启!");
XposedHook.restartHook(AntForestToast.context, Config.timeoutType(), 500, true);
}
}
}
try {
Thread.sleep(3000 + RandomUtils.delay());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
continue;
} else if (msg.contains("[1004]") && "alipay.antmember.forest.h5.collectEnergy".equals(args0)) {
if (Config.waitWhenException() > 0) {
long waitTime = System.currentTimeMillis() + Config.waitWhenException();
RuntimeInfo.getInstance().put(RuntimeInfo.RuntimeInfoKey.ForestPauseTime, waitTime);
AntForestNotification.setContentText("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime));
Log.recordLog("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime));
}
try {
Thread.sleep(900 + RandomUtils.delay());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
continue;
} else if (msg.contains("MMTPException")) {
result = "{\"resultCode\":\"FAIL\",\"memo\":\"MMTPException\",\"resultDesc\":\"MMTPException\"}";
try {
Thread.sleep(900 + RandomUtils.delay());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
continue;
}
} else if (msg.contains("[1004]") && "alipay.antmember.forest.h5.collectEnergy".equals(args0)) {
if (Config.waitWhenException() > 0) {
long waitTime = System.currentTimeMillis() + Config.waitWhenException();
RuntimeInfo.getInstance().put(RuntimeInfo.RuntimeInfoKey.ForestPauseTime, waitTime);
AntForestNotification.setContentText("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime));
Log.recordLog("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime));
}
} else if (msg.contains("MMTPException")) {
return "{\"resultCode\":\"FAIL\",\"memo\":\"MMTPException\",\"resultDesc\":\"MMTPException\"}";
}
}
return result;
}
}
return null;
return result;
}

public static String getResponse(Object resp) throws Throwable {
Expand Down
Loading

0 comments on commit 4ec8b83

Please sign in to comment.