Skip to content

Commit

Permalink
Fix colors in chats ballons
Browse files Browse the repository at this point in the history
Signed-off-by: Dev4Mod <[email protected]>
  • Loading branch information
Dev4Mod committed Jan 6, 2025
1 parent b6c9ee7 commit 74fdb7d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;
Expand Down Expand Up @@ -1656,11 +1657,23 @@ public synchronized static Method loadBubbleDrawableMethod(ClassLoader classLoad
});
}

public synchronized static Method loadDateWrapper(ClassLoader classLoader) throws Exception {
public synchronized static Method loadBallonDateDrawable(ClassLoader classLoader) throws Exception {
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> {
var methodData = dexkit.findMethod(FindMethod.create().matcher(MethodMatcher.create().name("getDateWrapperBackground")));
var methodData = dexkit.findMethod(FindMethod.create().matcher(MethodMatcher.create().addUsingString("Unreachable code: direction=").returnType(Rect.class)));
if (methodData.isEmpty()) throw new Exception("LoadDateWrapper method not found");
return methodData.get(0).getMethodInstance(classLoader);
var clazz = methodData.get(0).getMethodInstance(classLoader).getDeclaringClass();
var method = ReflectionUtils.findMethodUsingFilterIfExists(clazz, m -> List.of(1, 2).contains(m.getParameterCount()) && m.getParameterTypes()[0].equals(int.class) && m.getReturnType().equals(Drawable.class));
if (method == null) throw new RuntimeException("DateWrapper method not found");
return method;
});
}

public synchronized static Method loadBallonBorderDrawable(ClassLoader classLoader) throws Exception {
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> {
var clazz = loadBallonDateDrawable(classLoader).getDeclaringClass();
var method = ReflectionUtils.findMethodUsingFilterIfExists(clazz, m -> m.getParameterCount() == 3 && m.getReturnType().equals(Drawable.class));
if (method == null) throw new RuntimeException("Ballon Border method not found");
return method;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import androidx.annotation.NonNull;

import com.wmods.wppenhacer.xposed.core.Feature;
import com.wmods.wppenhacer.xposed.core.components.FMessageWpp;
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
import com.wmods.wppenhacer.xposed.utils.Utils;
Expand All @@ -21,7 +20,6 @@
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

public class BubbleColors extends Feature {
public BubbleColors(ClassLoader loader, XSharedPreferences preferences) {
Expand Down Expand Up @@ -90,25 +88,40 @@ public void doHook() throws Exception {
}
}

var dateWrapper = Unobfuscator.loadDateWrapper(classLoader);
var dateWrapper = Unobfuscator.loadBallonDateDrawable(classLoader);

XposedBridge.hookMethod(dateWrapper, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
var fmessageObject = XposedHelpers.callMethod(param.thisObject, "getFMessage");
if (fmessageObject == null) return;
var view = (Drawable) param.getResult();
var fmessage = new FMessageWpp(fmessageObject);
if (fmessage.getKey().isFromMe) {
var drawable = (Drawable) param.getResult();
var position = (int) param.args[0];
if (position == 3) {
if (bubbleRightColor == 0) return;
view.setColorFilter(new PorterDuffColorFilter(bubbleRightColor, PorterDuff.Mode.SRC_IN));
drawable.setColorFilter(new PorterDuffColorFilter(bubbleRightColor, PorterDuff.Mode.SRC_IN));
} else {
if (bubbleLeftColor == 0) return;
view.setColorFilter(new PorterDuffColorFilter(bubbleLeftColor, PorterDuff.Mode.SRC_IN));
drawable.setColorFilter(new PorterDuffColorFilter(bubbleLeftColor, PorterDuff.Mode.SRC_IN));
}
}
});

var babblon = Unobfuscator.loadBallonBorderDrawable(classLoader);
XposedBridge.hookMethod(babblon, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
var drawable = (Drawable) param.getResult();
var position = (int) param.args[1];
if (position == 3) {
if (bubbleRightColor == 0) return;
drawable.setColorFilter(new PorterDuffColorFilter(bubbleRightColor, PorterDuff.Mode.SRC_IN));
} else {
if (bubbleLeftColor == 0) return;
drawable.setColorFilter(new PorterDuffColorFilter(bubbleLeftColor, PorterDuff.Mode.SRC_IN));
}
}
});


var bubbleDrawableMethod = Unobfuscator.loadBubbleDrawableMethod(classLoader);

XposedBridge.hookMethod(bubbleDrawableMethod, new XC_MethodHook() {
Expand Down

0 comments on commit 74fdb7d

Please sign in to comment.