From 5e35a61473fdccbb0ac46da2e03b7e199220f2eb Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:52:29 +0300 Subject: [PATCH] refactored profile buttons injector --- .../ru/vtosters/lite/hooks/JsonInjectors.java | 122 ------------------ .../java/ru/vtosters/lite/ssfs/Handler.java | 7 +- .../ru/vtosters/lite/ssfs/ProfileButtons.java | 95 ++++++++++++++ .../ru/vtosters/lite/ssfs/ProfileHider.java | 4 +- .../vtosters/lite/utils/VTVerifications.java | 6 + .../lite/api/execute/GetFullProfile.smali | 2 +- 6 files changed, 110 insertions(+), 126 deletions(-) create mode 100644 app/src/main/java/ru/vtosters/lite/ssfs/ProfileButtons.java diff --git a/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java b/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java index f0141e702..22a2b28f6 100644 --- a/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java +++ b/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java @@ -34,124 +34,6 @@ import ru.vtosters.lite.utils.AccountManagerUtils; import ru.vtosters.lite.utils.AndroidUtils; public class JsonInjectors { - public static JSONObject profileButton(JSONObject orig) { - try { - int id = orig.getInt("id"); - - var newItem = new JSONArray(); - - if (orig.has("buttons")) { - newItem = orig.getJSONArray("buttons"); - } - - if (!haveDonateButton() && id == AccountManagerUtils.getUserId()) { - newItem.put(donateRecomm()); - } - - if (!orig.has("type") && AccountManagerUtils.isVKTester()) { - newItem.put(vktesters(id)); - } - - orig.put("buttons", newItem); - } catch (JSONException e) { - e.printStackTrace(); - } - - return orig; - } - - public static JSONObject donateRecomm() { - try { - var title = AndroidUtils.getString(R.string.donate_to_vtl); - var link = "https://vk.com/vtosters_official"; - var text_color = "2D81E0"; - - var json = new JSONObject(); - var icons = new JSONArray(); - - var action = new JSONObject().put("target", "internal"); - action.put("type", "open_url"); // may be open_url, open_internal_vkui, open_game, help_hint, show_full_post, open_vkapp, show_recommendations_for_post and groups_advertisement - action.put("url", link); - json.put("action", action); - - json.put("title", title); - - var icon1 = new JSONObject(); - icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png"); - icon1.put("width", "20"); - icon1.put("height", "20"); - icons.put(icon1); - - var icon2 = new JSONObject(); - icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png"); - icon2.put("width", "40"); - icon2.put("height", "40"); - icons.put(icon2); - - var icon3 = new JSONObject(); - icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png"); - icon3.put("width", "80"); - icon3.put("height", "80"); - icons.put(icon3); - - json.put("icons", icons); - - json.put("text_color", text_color); - - return json; - } catch (JSONException e) { - e.printStackTrace(); - } - - return null; - } - - public static JSONObject vktesters(int id) { - try { - var title = AndroidUtils.getString(R.string.tester_profile); - var text_color = "2D81E0"; - var link = "https://" + getStatic() + "/bugs?lang=" + LangUtils.a() + "#/reporter" + id; - - var json = new JSONObject(); - var icons = new JSONArray(); - - var action = new JSONObject(); - action.put("target", "internal"); - action.put("type", "open_internal_vkui"); - action.put("url", link); - json.put("action", action); - - json.put("title", title); - - var icon1 = new JSONObject(); - icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png"); - icon1.put("width", "20"); - icon1.put("height", "20"); - icons.put(icon1); - - var icon2 = new JSONObject(); - icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png"); - icon2.put("width", "40"); - icon2.put("height", "40"); - icons.put(icon2); - - var icon3 = new JSONObject(); - icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png"); - icon3.put("width", "80"); - icon3.put("height", "80"); - icons.put(icon3); - - json.put("icons", icons); - - json.put("text_color", text_color); - return json; - } catch (Exception e) { - e.printStackTrace(); - } - - return null; - } - public static JSONObject menu(JSONObject orig) throws JSONException { var Special = orig.optJSONArray("special"); var Main = orig.getJSONArray("main"); @@ -371,8 +253,4 @@ public class JsonInjectors { return json; } - - public static boolean haveDonateButton() { - return hasVerification() || new Random().nextInt(6) != 1; - } } diff --git a/app/src/main/java/ru/vtosters/lite/ssfs/Handler.java b/app/src/main/java/ru/vtosters/lite/ssfs/Handler.java index 6049263cf..b18a6d4d7 100644 --- a/app/src/main/java/ru/vtosters/lite/ssfs/Handler.java +++ b/app/src/main/java/ru/vtosters/lite/ssfs/Handler.java @@ -1,5 +1,6 @@ package ru.vtosters.lite.ssfs; +import android.util.Log; import okhttp3.Request; import org.json.JSONException; import org.json.JSONObject; @@ -8,6 +9,8 @@ import ru.vtosters.lite.di.singleton.VtOkHttpClient; import java.io.IOException; public class Handler { + private static final String TAG = "SSFSHandler"; + public static JSONObject getBanner(int id) { Request request = new Request.a() .b("https://ssfs.vtosters.app/api/getChatBanner" + "?user_id=" + id) @@ -16,7 +19,7 @@ public class Handler { try { return new JSONObject(VtOkHttpClient.getInstance().a(request).execute().a().g()).getJSONObject("response"); } catch (JSONException | IOException e) { - e.printStackTrace(); + Log.d(TAG, e.getMessage()); return null; } } @@ -29,7 +32,7 @@ public class Handler { try { return new JSONObject(VtOkHttpClient.getInstance().a(request).execute().a().g()).getString("response"); } catch (JSONException | IOException e) { - e.printStackTrace(); + Log.d(TAG, e.getMessage()); return null; } } diff --git a/app/src/main/java/ru/vtosters/lite/ssfs/ProfileButtons.java b/app/src/main/java/ru/vtosters/lite/ssfs/ProfileButtons.java new file mode 100644 index 000000000..7c4c1e990 --- /dev/null +++ b/app/src/main/java/ru/vtosters/lite/ssfs/ProfileButtons.java @@ -0,0 +1,95 @@ +package ru.vtosters.lite.ssfs; + +import com.vk.core.util.LangUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import ru.vtosters.lite.utils.AccountManagerUtils; +import ru.vtosters.lite.utils.AndroidUtils; +import ru.vtosters.lite.utils.VTVerifications; + +import java.util.HashMap; + +import static ru.vtosters.lite.proxy.ProxyUtils.getStatic; + +public class ProfileButtons { + public static JSONObject profileButton(JSONObject orig) { + try { + int id = orig.getInt("id"); + + var newItem = new JSONArray(); + + if (orig.has("buttons")) { + newItem = orig.getJSONArray("buttons"); + } + + if (!VTVerifications.haveDonateButton() && id == AccountManagerUtils.getUserId()) { + var map = new HashMap<>(); + map.put("20", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png"); + map.put("40", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png"); + map.put("80", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png"); + + newItem.put(generateJsonObject( + AndroidUtils.getString(com.vtosters.lite.R.string.donate_to_vtl), + "https://vk.com/vtosters_official", + "2D81E0", + "open_url", + map + )); + } + + if (!orig.has("type") && AccountManagerUtils.isVKTester()) { + var map = new HashMap<>(); + map.put("20", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png"); + map.put("40", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png"); + map.put("80", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png"); + + newItem.put(generateJsonObject( + AndroidUtils.getString(com.vtosters.lite.R.string.tester_profile), + "https://" + getStatic() + "/bugs?lang=" + LangUtils.a() + "#/reporter" + id, + "2D81E0", + "open_internal_vkui", + map + )); + } + + orig.put("buttons", newItem); + } catch (JSONException e) { + e.printStackTrace(); + } + + return orig; + } + + public static JSONObject generateJsonObject(String title, String link, String text_color, String url_type, HashMap iconsList) { + try { + var json = new JSONObject(); + var icons = new JSONArray(); + + var action = new JSONObject().put("target", "internal"); + action.put("type", url_type); // may be open_url, open_internal_vkui, open_game, help_hint, show_full_post, open_vkapp, show_recommendations_for_post and groups_advertisement + action.put("url", link); + json.put("action", action); + + json.put("title", title); + + for (var entry : iconsList.entrySet()) { + var icon = new JSONObject(); + icon.put("url", entry.getValue()); + icon.put("width", entry.getKey()); + icon.put("height", entry.getKey()); + icons.put(icon); + } + + json.put("icons", icons); + + json.put("text_color", text_color); + + return json; + } catch (JSONException e) { + e.printStackTrace(); + } + + return null; + } +} diff --git a/app/src/main/java/ru/vtosters/lite/ssfs/ProfileHider.java b/app/src/main/java/ru/vtosters/lite/ssfs/ProfileHider.java index a35710845..46d20b911 100644 --- a/app/src/main/java/ru/vtosters/lite/ssfs/ProfileHider.java +++ b/app/src/main/java/ru/vtosters/lite/ssfs/ProfileHider.java @@ -10,6 +10,8 @@ import static ru.vtosters.lite.utils.AccountManagerUtils.getUserID; import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext; public class ProfileHider { + private static final String TAG = "ProfileHider"; + public static boolean isService(Integer id) { return UsersList.hasDescription(id) || id == 100 || id == 101 || id == 333; } @@ -21,7 +23,7 @@ public class ProfileHider { try { extendedUserProfile.z2 = Handler.getDescription(userID); } catch (NullPointerException e) { - Log.e("ProfileHide", "null \"profiles\" node\n" + e); + Log.e(TAG, "null \"profiles\" node\n" + e); } } } diff --git a/app/src/main/java/ru/vtosters/lite/utils/VTVerifications.java b/app/src/main/java/ru/vtosters/lite/utils/VTVerifications.java index 79970fbb1..58624bc41 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/VTVerifications.java +++ b/app/src/main/java/ru/vtosters/lite/utils/VTVerifications.java @@ -1,6 +1,7 @@ package ru.vtosters.lite.utils; import static ru.vtosters.lite.utils.Preferences.getBoolValue; +import static ru.vtosters.lite.utils.Preferences.hasVerification; import android.content.Context; import android.util.Log; @@ -15,6 +16,7 @@ import org.json.JSONObject; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Random; import okhttp3.Call; import okhttp3.Callback; @@ -158,4 +160,8 @@ public class VTVerifications { public static VerifyInfo VerifyInfo(JSONObject jSONObject) { return new VerifyInfo(isVerified(jSONObject), hasPrometheus(jSONObject)); } + + public static boolean haveDonateButton() { + return hasVerification() || new Random().nextInt(6) != 1; + } } diff --git a/smali/smali_classes4/com/vtosters/lite/api/execute/GetFullProfile.smali b/smali/smali_classes4/com/vtosters/lite/api/execute/GetFullProfile.smali index db305b199..394247119 100644 --- a/smali/smali_classes4/com/vtosters/lite/api/execute/GetFullProfile.smali +++ b/smali/smali_classes4/com/vtosters/lite/api/execute/GetFullProfile.smali @@ -1513,7 +1513,7 @@ iput-object v0, v15, Lcom/vtosters/lite/api/ExtendedUserProfile;->l1:Ljava/util/ArrayList; :cond_22 - invoke-static {v14}, Lru/vtosters/lite/hooks/JsonInjectors;->profileButton(Lorg/json/JSONObject;)Lorg/json/JSONObject; + invoke-static {v14}, Lru/vtosters/lite/ssfs/ProfileButtons;->profileButton(Lorg/json/JSONObject;)Lorg/json/JSONObject; move-result-object v14