This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TitleFix.cs
54 lines (47 loc) · 2.73 KB
/
TitleFix.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using HarmonyLib;
using Microsoft.Xbox;
using System.Reflection;
using XGamingRuntime;
namespace TaikoTitleFix
{
internal class TitleFix
{
private static GdkHelpers instancedClass;
[HarmonyPatch(typeof(GdkHelpers), "SignInImpl")]
[HarmonyPrefix]
static bool PrefixSignIn()
{
return false;
}
[HarmonyPatch(typeof(GdkHelpers), "SignInImpl")]
[HarmonyPrefix]
static void CustomSignInImpl(GdkHelpers __instance, bool isSilently)
{
Traverse gdkHelpers = Traverse.CreateWithType("Microsoft.Xbox.GdkHelpers");
instancedClass = __instance;
// A copy of the original method, but reflected back as is intended
if (!gdkHelpers.Field<bool>("_isSingInRunning").Value)
{
gdkHelpers.Field<bool>("_isSingInRunning").Value = true;
gdkHelpers.Field<bool>("_isSingInFailure").Value = false;
gdkHelpers.Field<bool>("_isUserChangeCancel").Value = false;
gdkHelpers.Field<bool>("_isReady").Value = false;
// This is where the actual fix is in. Namco's intention was to do silent sign in, so they used XUserAddOptions.AddDefaultUserSilently.
// All good and stuff, however, there's a flaw. To login for the first time, you have to agree to the login, because of Microsoft reasons.
// Which means this well intended action backfires, because AddDefaultUserSilently doesn't show the "Welcome to Xbox" dialog thing, even if
// there's a need to show it, such as the "Do you agree to give T Tablet(what is this name????????) access to your Xbox Live data?" dialog,
// which is needed to login in the first place!
//
// The actual fix is a literal one-liner: Change AddDefaultUserSilently to AddDefaultUserAllowingUI, which allows showing the dialog, AND
// does the silent login Namco wanted _AFTER_ the initial login. Everything else here is there to replicate the original method's coding.
SDK.XUserAddAsync(isSilently ? XUserAddOptions.AddDefaultUserAllowingUI : XUserAddOptions.None, new XUserAddCompleted(customXAddUserCompleted));
}
}
private static void customXAddUserCompleted(int hresult, XUserHandle userHandle)
{
// Call the original method here, to make sure the game does return properly to the title screen.
// I couldn't do this with just Traverse, so I used good old reflection.
typeof(GdkHelpers).GetMethod("AddUserComplete", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(instancedClass, new object[] { hresult, userHandle });
}
}
}