Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Discord Backend URLs #187

Closed
1 task done
NurMarvin opened this issue Aug 26, 2021 · 1 comment
Closed
1 task done

Custom Discord Backend URLs #187

NurMarvin opened this issue Aug 26, 2021 · 1 comment
Labels
rejected (not possible) Not possible due to technical limiations rejected (other) This doesn't seem right

Comments

@NurMarvin
Copy link

Discord Account

NurMarvin#1337

Plugin Description

Basically swaps out the URLs to Discord's backend, e.g. the REST API or Gateway to something else of your choice, like a self hosted Litecord instance or similar.

Go into more detail...

As already mentioned, this plugin should let you change the URLs to each individual Discord backend URL, e.g. the REST API, which is https://discord.com/api normally, or the gateway URL, which wss://gateway.discord.gg normally, to something of your choice via a config file. Changing it via inputs in the app would probably also be nice, but shouldn't be the only way, since changing it to something invalid could render the app useless and the inputs to change the URLs back inaccessible.

Request Agreement

  • I did indeed check to make sure my plugin request is original!
@NurMarvin NurMarvin added the up for grabs A plugin that has been passed on for plugin developers to pick up and make! label Aug 26, 2021
@Juby210
Copy link
Member

Juby210 commented Aug 26, 2021

Sadly plugins load too late which makes it not possible.
However I made a patch for injector that should work (not tested cuz all current backend implementations suck and don't work with slightly different mobile client)

diff --git a/Injector/src/main/java/com/aliucord/injector/Injector.java b/Injector/src/main/java/com/aliucord/injector/Injector.java
index 035b56d..33c4f2e 100644
--- a/Injector/src/main/java/com/aliucord/injector/Injector.java
+++ b/Injector/src/main/java/com/aliucord/injector/Injector.java
@@ -13,6 +13,9 @@ import android.util.Log;
 import android.widget.Toast;
 
 import com.discord.app.AppActivity;
+import com.discord.gateway.rest.RestConfig;
+import com.discord.restapi.RequiredHeadersInterceptor;
+import com.discord.restapi.RestAPIBuilder;
 import com.discord.stores.StoreClientVersion;
 import com.discord.stores.StoreStream;
 
@@ -22,6 +25,7 @@ import org.json.JSONTokener;
 import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import dalvik.system.BaseDexClassLoader;
@@ -37,6 +41,9 @@ public final class Injector {
 
     private static MethodHook.Unhook unhook;
 
+    private static final String host = "http://192.168.0.101:8000";
+    private static final String hostApi = host + "/api/";
+
     public static void init() {
         PineConfig.debug = new File(BASE_DIRECTORY, ".pine_debug").exists();
         PineConfig.debuggable = new File(BASE_DIRECTORY, ".debuggable").exists();
@@ -54,6 +61,30 @@ public final class Injector {
                     unhook = null;
                 }
             });
+
+            var buildConfig = com.discord.BuildConfig.class;
+            var hostField = buildConfig.getDeclaredField("HOST");
+            hostField.setAccessible(true);
+            hostField.set(null, host);
+            var hostApiField = buildConfig.getDeclaredField("HOST_API");
+            hostApiField.setAccessible(true);
+            hostApiField.set(null, hostApi);
+
+            var aField = c.a.d.m0.b.class.getDeclaredField("a");
+            aField.setAccessible(true);
+            aField.set(null, host);
+
+            Pine.hook(RestConfig.class.getDeclaredConstructor(String.class, RequiredHeadersInterceptor.HeadersProvider.class, List.class), new MethodHook() {
+                public void beforeCall(Pine.CallFrame callFrame) {
+                    callFrame.args[0] = hostApi;
+                }
+            });
+
+            Pine.hook(RestAPIBuilder.class.getDeclaredConstructor(String.class, f0.p.class), new MethodHook() {
+                public void beforeCall(Pine.CallFrame callFrame) {
+                    if (callFrame.args[0].equals("https://discord.com/api/")) callFrame.args[0] = hostApi;
+                }
+            });
         } catch (Throwable th) {
             Log.e(LOG_TAG, "Failed to initialize Aliucord", th);
         }

@Juby210 Juby210 closed this as completed Aug 26, 2021
@Juby210 Juby210 added rejected (not possible) Not possible due to technical limiations rejected (other) This doesn't seem right and removed up for grabs A plugin that has been passed on for plugin developers to pick up and make! labels Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rejected (not possible) Not possible due to technical limiations rejected (other) This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants