88using PolytopiaBackendBase . Game . BindingModels ;
99using UnityEngine ;
1010using Newtonsoft . Json ;
11+ using PolytopiaBackendBase . Auth ;
1112
1213namespace PolyMod . Multiplayer ;
1314
@@ -27,10 +28,53 @@ internal static void Init()
2728 Harmony . CreateAndPatchAll ( typeof ( Client ) ) ;
2829 BuildConfig buildConfig = BuildConfigHelper . GetSelectedBuildConfig ( ) ;
2930 buildConfig . buildServerURL = BuildServerURL . Custom ;
30- buildConfig . customServerURL = LOCAL_SERVER_URL ;
31+ buildConfig . customServerURL = Plugin . config . backendUrl ;
32+
33+ // Update BackendUri and HttpClient.BaseAddress since PolytopiaBackendAdapter.Instance
34+ // was statically initialized before plugins load, so it still points to polytopia-prod.net
35+ var uri = new Il2CppSystem . Uri ( Plugin . config . backendUrl ) ;
36+ PolytopiaBackendAdapter . Instance . UseBackendUri ( uri ) ;
37+ PolytopiaBackendAdapter . Instance . BackendHttpClient . BaseAddress = uri ;
3138
3239 Plugin . logger . LogInfo ( $ "Multiplayer> Server URL set to: { Plugin . config . backendUrl } ") ;
33- Plugin . logger . LogInfo ( "Multiplayer> GLD patches applied" ) ;
40+ }
41+
42+ /// <summary>
43+ /// On Android, bypass multiplayer requirements that depend on
44+ /// Google Play login, push notifications, and purchases — none of which work
45+ /// when running as a wrapper app with a different package identity.
46+ /// </summary>
47+ [ HarmonyPrefix ]
48+ [ HarmonyPatch ( typeof ( GameManager ) , nameof ( GameManager . IsMultiplayerEnabled ) , MethodType . Getter ) ]
49+ public static bool GameManager_IsMultiplayerEnabled ( ref bool __result )
50+ {
51+ if ( Application . platform != RuntimePlatform . Android ) return true ;
52+ __result = true ;
53+ return false ;
54+ }
55+
56+ /// <summary>
57+ /// Replace the Android login flow to skip Google Play Games SDK entirely.
58+ /// Uses deviceUniqueIdentifier as the auth code for the Polydystopia backend.
59+ /// </summary>
60+ [ HarmonyPrefix ]
61+ [ HarmonyPatch ( typeof ( PolytopiaBackendAdapter ) , "LoginPlatformAndroid" ) ]
62+ public static bool LoginPlatformAndroid_Prefix (
63+ ref Il2CppSystem . Threading . Tasks . Task < ServerResponse < PolytopiaToken > > __result ,
64+ PolytopiaBackendAdapter __instance )
65+ {
66+ if ( Application . platform != RuntimePlatform . Android ) return true ;
67+
68+ // Mark social login as cached so the post-login flow doesn't bail out
69+ __instance . HasSocialLoginCached = true ;
70+
71+ var model = new LoginGooglePlayBindingModel ( ) ;
72+ model . AuthCode = SystemInfo . deviceUniqueIdentifier ;
73+ model . DeviceId = SystemInfo . deviceUniqueIdentifier ;
74+
75+ Plugin . logger . LogInfo ( $ "Multiplayer> Android login with DeviceId: { model . DeviceId } ") ;
76+ __result = __instance . LoginGooglePlay ( model ) ;
77+ return false ;
3478 }
3579
3680 [ HarmonyPostfix ]
@@ -192,6 +236,9 @@ private static bool BackendAdapter_StartLobbyGame_Modded(
192236 BackendAdapter __instance ,
193237 StartLobbyBindingModel model )
194238 {
239+ // On Android, let the game's original StartLobbyGame handle it
240+ if ( Application . platform == RuntimePlatform . Android ) return true ;
241+
195242 Plugin . logger . LogInfo ( "Multiplayer> BackendAdapter_StartLobbyGame_Modded" ) ;
196243 var taskCompletionSource = new Il2CppSystem . Threading . Tasks . TaskCompletionSource < ServerResponse < LobbyGameViewModel > > ( ) ;
197244
0 commit comments