Skip to content

Commit

Permalink
add support to version 2.24.14.xx
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev4Mod committed Jul 17, 2024
1 parent 72a72b7 commit 540a437
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void receiverBroadcastBusiness(Context context, Intent intent) {
binding.statusTitle3.setText(R.string.business_in_background);
var version = intent.getStringExtra("VERSION");
var supported_list = Arrays.asList(context.getResources().getStringArray(R.array.supported_versions_business));
if (supported_list.contains(version)) {
if (version != null && supported_list.stream().anyMatch(s -> version.startsWith(s.replace(".xx", "")))) {
binding.statusSummary3.setText(getString(R.string.version_s, version));
binding.status3.setCardBackgroundColor(context.getColor(R.color.material_state_green));
} else {
Expand All @@ -114,7 +114,7 @@ private void receiverBroadcastWpp(Context context, Intent intent) {
var version = intent.getStringExtra("VERSION");
var supported_list = Arrays.asList(context.getResources().getStringArray(R.array.supported_versions_wpp));

if (supported_list.contains(version)) {
if (version != null && supported_list.stream().anyMatch(s -> version.startsWith(s.replace(".xx", "")))) {
binding.statusSummary1.setText(getString(R.string.version_s, version));
binding.status2.setCardBackgroundColor(context.getColor(R.color.material_state_green));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import androidx.annotation.NonNull;

import com.wmods.wppenhacer.adapter.IGStatusAdapter;
import com.wmods.wppenhacer.xposed.utils.Utils;

public class IGStatusView extends FrameLayout {
public HorizontalListView mStatusListView;
Expand All @@ -22,7 +21,7 @@ public IGStatusView(@NonNull Context context) {
private void init(Context context) {
mStatusListView = new HorizontalListView(context);
var layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(Utils.dipToPixels(4), Utils.dipToPixels(10), 0, 0);
// layoutParams.setMargins(Utils.dipToPixels(4), Utils.dipToPixels(10), 0, 0);
mStatusListView.setLayoutParams(layoutParams);
addView(mStatusListView);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
SharedPreferencesWrapper.hookInit(mApp.getClassLoader());
UnobfuscatorCache.init(mApp, pref);
WppCore.Initialize(loader);
if (!supportedVersions.contains(packageInfo.versionName) && !pref.getBoolean("bypass_version_check", false)) {
if (supportedVersions.stream().noneMatch(s -> packageInfo.versionName.startsWith(s.replace(".xx", ""))) && !pref.getBoolean("bypass_version_check", false)) {
throw new Exception("Unsupported version: " + packageInfo.versionName);
}
DesignUtils.setPrefs(pref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1656,18 +1656,18 @@ public static Method loadTextStatusComposer(ClassLoader classLoader) throws Exce
var method1 = Activity.class.getDeclaredMethod("getWindow");
var method2 = View.class.getDeclaredMethod("setBackground", Drawable.class);
var clazz = classLoader.loadClass("com.whatsapp.textstatuscomposer.TextStatusComposerActivity");
var field1 = clazz.getDeclaredField("A02");
var fieldInt = ReflectionUtils.findFieldUsingFilter(clazz, field -> field.getType() == int.class);
var classData = dexkit.getClassData(clazz);
if (classData == null) throw new RuntimeException("TextStatusComposer class not found");
var methods = classData.findMethod(new FindMethod().matcher(new MethodMatcher()
.addInvoke(DexSignUtil.getMethodDescriptor(method1))
.addInvoke(DexSignUtil.getMethodDescriptor(method2))
.addUsingField(DexSignUtil.getFieldDescriptor(field1))
.addUsingField(DexSignUtil.getFieldDescriptor(fieldInt))
.modifiers(Modifier.PUBLIC | Modifier.STATIC)
));
if (methods.isEmpty())
throw new RuntimeException("TextStatusComposer method not found");
return methods.get(0).getMethodInstance(classLoader);
return methods.get(methods.size() - 1).getMethodInstance(classLoader);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package com.wmods.wppenhacer.xposed.features.customization;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.ListView;

import androidx.annotation.NonNull;

import com.wmods.wppenhacer.adapter.IGStatusAdapter;
import com.wmods.wppenhacer.views.IGStatusView;
import com.wmods.wppenhacer.xposed.core.Feature;
import com.wmods.wppenhacer.xposed.core.WppCore;
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
import com.wmods.wppenhacer.xposed.utils.Utils;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
Expand All @@ -31,9 +24,7 @@

public class IGStatus extends Feature {
public static ArrayList<Object> itens = new ArrayList<>();
@SuppressLint("StaticFieldLeak")
private static IGStatusView mStatusContainer;
private WeakReference<Activity> homeActivity;
private static final ArrayList<IGStatusView> mListStatusContainer = new ArrayList<>();

public IGStatus(@NonNull ClassLoader loader, @NonNull XSharedPreferences preferences) {
super(loader, preferences);
Expand All @@ -45,50 +36,6 @@ public void doHook() throws Throwable {
if (!prefs.getBoolean("igstatus", false) || Utils.getApplication().getPackageName().equals("com.whatsapp.w4b"))
return;

var clazz = XposedHelpers.findClass("com.whatsapp.HomeActivity", classLoader);

XposedHelpers.findAndHookMethod(clazz.getSuperclass(), "onCreate", android.os.Bundle.class, new XC_MethodHook() {
@Override
@SuppressLint("DiscouragedApi")
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
homeActivity = new WeakReference<>((Activity) param.thisObject);
// create status container
mStatusContainer = new IGStatusView(homeActivity.get());
var layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, Utils.dipToPixels(105));
layoutParams.gravity = Gravity.TOP;

if (Objects.equals(prefs.getString("chatfilter", null), "2") && prefs.getBoolean("topnav", false)) {
layoutParams.topMargin = Utils.dipToPixels(168);
} else if (prefs.getBoolean("topnav", false)) {
layoutParams.topMargin = Utils.dipToPixels(112);
} else if (Objects.equals(prefs.getString("chatfilter", null), "2")) {
layoutParams.topMargin = Utils.dipToPixels(112);
} else {
layoutParams.topMargin = Utils.dipToPixels(56);
}

mStatusContainer.setLayoutParams(layoutParams);
mStatusContainer.setBackgroundColor(Color.TRANSPARENT);
var mainContainer = homeActivity.get().findViewById(Utils.getID("main_container", "id"));
var pagerView = (ViewGroup) mainContainer.findViewById(Utils.getID("pager", "id"));
var pager_holder = (ViewGroup) pagerView.getParent();
pager_holder.addView(mStatusContainer);

}
});

// fix scroll
var onScrollPagerMethod = Unobfuscator.loadScrollPagerMethod(classLoader);

XposedBridge.hookMethod(onScrollPagerMethod, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
var scroll = -(float) XposedHelpers.getIntField(homeActivity.get(), "A02");
if (mStatusContainer.isShown())
mStatusContainer.setTranslationY(scroll);
}
});

var getViewConversationMethod = Unobfuscator.loadGetViewConversationMethod(classLoader);
XposedBridge.hookMethod(getViewConversationMethod, new XC_MethodHook() {
@Override
Expand All @@ -101,41 +48,14 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (view == null) return;
var mainView = (ListView) view.findViewById(android.R.id.list);
mainView.setNestedScrollingEnabled(true);
var paddingView = new View(homeActivity.get());
paddingView.setClickable(true);
var layoutParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, Utils.dipToPixels(105));
paddingView.setLayoutParams(layoutParams);
mainView.addHeaderView(paddingView);
}
});

// hide on tab

var onMenuItemSelected = Unobfuscator.loadOnMenuItemSelected(classLoader);
var separateGroups = prefs.getBoolean("separategroups", false);
var onMenuItemClick = Unobfuscator.loadOnMenuItemClickClass(classLoader);
var onMenuItemClick2 = Unobfuscator.loadOnMenuItemClickClass2(classLoader);

XposedBridge.hookMethod(onMenuItemSelected, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!Unobfuscator.isCalledFromClass(clazz) && !Unobfuscator.isCalledFromClass(onMenuItemClick2) && !Unobfuscator.isCalledFromClass(onMenuItemClick))
return;
var index = (int) param.args[0];
homeActivity.get().runOnUiThread(() -> {
XposedHelpers.setObjectField(homeActivity.get(), "A02", 0);
var visible = View.GONE;
if (index == SeparateGroup.tabs.indexOf(SeparateGroup.CHATS) || (separateGroups && index == SeparateGroup.tabs.indexOf(SeparateGroup.GROUPS))) {
visible = View.VISIBLE;
}
if (mStatusContainer.getVisibility() != visible)
mStatusContainer.setVisibility(visible);
if (visible == View.VISIBLE) mStatusContainer.setTranslationY(0);
});
var mStatusContainer = new IGStatusView(WppCore.getCurrentActivity());
var layoutParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, Utils.dipToPixels(88));
mStatusContainer.setLayoutParams(layoutParams);
mainView.addHeaderView(mStatusContainer);
mListStatusContainer.add(mStatusContainer);
}
});


var clazz2 = XposedHelpers.findClass("com.whatsapp.updates.viewmodels.UpdatesViewModel", classLoader);
var onUpdateStatusChanged = Unobfuscator.loadOnUpdateStatusChanged(classLoader);
logDebug(Unobfuscator.getMethodDescriptor(onUpdateStatusChanged));
Expand All @@ -146,9 +66,11 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
itens.add(0, null);
IGStatusAdapter mStatusAdapter = new IGStatusAdapter(homeActivity.get(), statusInfoClass);
mStatusContainer.setAdapter(mStatusAdapter);
mStatusContainer.updateList();
for (var mStatusContainer : mListStatusContainer) {
IGStatusAdapter mStatusAdapter = new IGStatusAdapter(WppCore.getCurrentActivity(), statusInfoClass);
mStatusContainer.setAdapter(mStatusAdapter);
mStatusContainer.updateList();
}
}
});

Expand All @@ -164,7 +86,8 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
itens.add(0, null);
itens.addAll(list1);
itens.addAll(list2);
mStatusContainer.updateList();
for (var mStatusContainer : mListStatusContainer)
mStatusContainer.updateList();
}
});

Expand All @@ -187,7 +110,8 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
itens.add(0, null);
itens.addAll(list1);
itens.addAll(list2);
mStatusContainer.updateList();
for (var mStatusContainer : mListStatusContainer)
mStatusContainer.updateList();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
import com.wmods.wppenhacer.xposed.utils.Utils;

import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicReference;

import de.robv.android.xposed.XC_MethodHook;
Expand All @@ -19,7 +20,7 @@
import de.robv.android.xposed.XposedHelpers;

public class TextStatusComposer extends Feature {
private static AtomicReference<ColorData> colorData = new AtomicReference<>();
private static final AtomicReference<ColorData> colorData = new AtomicReference<>();

public TextStatusComposer(@NonNull ClassLoader classLoader, @NonNull XSharedPreferences preferences) {
super(classLoader, preferences);
Expand All @@ -42,8 +43,13 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {

pickerColor.setOnLongClickListener(v -> {
var dialog = new SimpleColorPickerDialog(activity, color -> {
XposedHelpers.setObjectField(param.thisObject, "A02", color);
ReflectionUtils.callMethod(setColorTextComposer, null, param.thisObject);
try {
Field fieldInt = ReflectionUtils.findFieldUsingFilter(param.thisObject.getClass(), field -> field.getType() == int.class);
fieldInt.setInt(param.thisObject, color);
ReflectionUtils.callMethod(setColorTextComposer, null, param.thisObject);
} catch (Exception e) {
log(e);
}
});
dialog.create().setCanceledOnTouchOutside(false);
dialog.show();
Expand Down
13 changes: 3 additions & 10 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,9 @@
<item>2</item>
</string-array>
<string-array name="supported_versions_wpp">
<item>2.24.12.71</item>
<item>2.24.12.73</item>
<item>2.24.12.78</item>
<item>2.24.13.71</item>
<item>2.24.13.72</item>
<item>2.24.13.73</item>
<item>2.24.13.74</item>
<item>2.24.13.75</item>
<item>2.24.13.77</item>
<item>2.24.13.78</item>
<item>2.24.12.xx</item>
<item>2.24.13.xx</item>
<item>2.24.14.xx</item>
</string-array>
<string-array name="supported_versions_business">
<item>2.24.11.83</item>
Expand Down

0 comments on commit 540a437

Please sign in to comment.