Skip to content

Commit 0e602e3

Browse files
ComputerEliteComputerElite
authored andcommitted
What tf is sanity
1 parent 26d3fc3 commit 0e602e3

6 files changed

Lines changed: 156 additions & 20 deletions

File tree

Assets/html/index.html

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@
1313
Backing <div class="inline packageName">some game</div> up
1414
</div>
1515
</div>
16-
<div class="menuItem" section="backup">Backup</div>
16+
<div class="menuItem selected" section="backup">Backup</div>
1717
<div class="menuItem" section="downgrade">Downgrade</div>
1818
<div class="menuItem" section="download">Download progress</div>
19-
<div class="menuItem selected" section="tools">Tools & Options</div>
19+
<div class="menuItem" section="tools">Tools & Options</div>
2020
</div>
2121
<div class="content">
22-
<div class="contentItem hidden" id="backup">
22+
<div class="contentItem" id="backup">
2323
<div class="contentHeader">
2424
Backup
2525
<div class="contentHeaderDescription">Backup your game and restore backups</div>
2626
</div>
27+
<div class="buttonContainer">
28+
<div class="button" id="changeApp2">Change app</div>
29+
<div class="buttonLabel">Change the app you want to manage</div>
30+
</div>
2731
<div>Backups of <div class="inline packageName">some game</div> (<div id="size" class="inline"></div>)</div>
2832
<div class="smallListContainer">
2933
<div id="backupList" class="list">
@@ -60,6 +64,7 @@
6064
</div>
6165
</div>
6266
<div class="contentItem hidden" id="downgrade" style="padding: 0px;">
67+
<b style="font-size: 4em;" id="downgradeLoginMsg">To downgrade you must first log in in the tools & options tab!</b>
6368
<iframe src="https://oculusdb.rui2015.me/search?query=Beat+Saber&headsets=MONTEREY%2CHOLLYWOOD&isqavs=true" style="width: 100%; height: 100%; border: none; overflow-y: visible;"></iframe>
6469
</div>
6570
<div class="contentItem hidden" id="download">
@@ -68,7 +73,7 @@
6873
</div>
6974

7075
</div>
71-
<div class="contentItem" id="tools">
76+
<div class="contentItem hiddeb" id="tools">
7277
<div class="contentHeader">
7378
Tools
7479
<div class="contentHeaderDescription">Useful for troubleshooting and managing your install</div>
@@ -87,6 +92,7 @@
8792
Token Section
8893
<div class="contentHeaderDescription">Set your token for downgrading games</div>
8994
</div>
95+
<b id="loggedInMsg">You are logged in. You can login again if you want</b>
9096
<div class="buttonContainer">
9197
<div class="button" id="login">Login</div>
9298
<div class="buttonLabel">Log in with your Oculus/Facebook account to downgrade games (<b>ONLY WORKS ON QUEST, NOT ON PC</b>)</div>
@@ -104,7 +110,7 @@
104110
<div class="buttonLabel">Exists QuestAppVersionSwitcher</div>
105111
</div>
106112
<div class="buttonContainer">
107-
<input type="number" placeholder="50001" id="port" class="buttonLabel" value="50001" style="width: 100px;">
113+
<input type="number" placeholder="50002" id="port" class="buttonLabel" value="50002" style="width: 100px;">
108114
<div class="button" id="confirmPort">Change port</div>
109115
<div class="buttonLabel">Changes the WebServer port</div>
110116
</div>
@@ -145,6 +151,33 @@
145151
</div>
146152
</div>
147153
</div>
154+
<div class="restoreStep" id="step9">
155+
<div class="contentHeader headerMargin">
156+
Login info
157+
</div>
158+
To login we'll open oculus.com for you. Accept the cookies when Oculus ask you to. We'll then redirect you to the login. Consenting to cookies is needed so you are allowed to log in.
159+
<div id="step9box" class="textBox"></div>
160+
<div class="buttonSelectionContainer">
161+
<div class="buttonContainer">
162+
<div class="button" id="confirmLogin">Login</div>
163+
</div>
164+
<div class="buttonContainer buttonMargin">
165+
<div class="button" id="abortLogin">Abort Login</div>
166+
</div>
167+
</div>
168+
</div>
169+
<div class="restoreStep" id="step10">
170+
<div class="contentHeader headerMargin">
171+
Almost there
172+
</div>
173+
To finish logging in you must restart QuestAppVersionSwitcher. Do that now.
174+
<div id="step10box" class="textBox"></div>
175+
<div class="buttonSelectionContainer">
176+
<div class="buttonContainer">
177+
<div class="button" id="closeApp">Close App</div>
178+
</div>
179+
</div>
180+
</div>
148181
</div>
149182

150183
<div class="listContainer darken hidden" id="tokenPasswordContainer">
@@ -270,6 +303,19 @@
270303
</div>
271304
</div>
272305
<script>
306+
fetch("/questappversionswitcher/loggedinstatus").then(res => {
307+
res.text().then(res => {
308+
if(res == "2") {
309+
// Logged in#
310+
document.getElementById("loggedInMsg").style.visibility = "visible"
311+
document.getElementById("downgradeLoginMsg").style.visibility = "hidden"
312+
} else {
313+
// Not logged in
314+
document.getElementById("loggedInMsg").style.visibility = "hidden"
315+
document.getElementById("downgradeLoginMsg").style.visibility = "visible"
316+
}
317+
})
318+
})
273319
UpdateUI()
274320
const params = new URLSearchParams(window.location.search)
275321
var config = {}
@@ -329,8 +375,14 @@
329375
OpenTokenPasswordPopup()
330376
}
331377

378+
if(params.get("restart")) {
379+
OpenGetPasswordPopup()
380+
GotoStep(10)
381+
}
382+
332383
document.getElementById("login").onclick = () => {
333-
location = "https://auth.oculus.com/login/?redirect_uri=https%3A%2F%2Fsecure.oculus.com%2F&reason=page_require_login"
384+
OpenGetPasswordPopup()
385+
GotoStep(9)
334386
}
335387

336388
setInterval(() => {
@@ -389,6 +441,9 @@
389441
document.getElementById("exit").onclick = () => {
390442
fetch("questappversionswitcher/kill")
391443
}
444+
document.getElementById("closeApp").onclick = () => {
445+
fetch("questappversionswitcher/kill")
446+
}
392447
document.getElementById("confirmPort").onclick = () => {
393448
fetch("questappversionswitcher/changeport?body=" + document.getElementById("port").value).then(res => {
394449
res.text().then(text => {
@@ -461,6 +516,7 @@
461516
}
462517

463518
document.getElementById("changeApp").onclick = () => ShowAppList()
519+
document.getElementById("changeApp2").onclick = () => ShowAppList()
464520

465521
document.getElementById("abort").onclick = () => CloseRestorePopup()
466522

@@ -644,6 +700,13 @@
644700
})
645701
}
646702

703+
document.getElementById("abortLogin").onclick = () => {
704+
CloseGetPasswordPopup()
705+
}
706+
document.getElementById("confirmLogin").onclick = () => {
707+
location = "https://auth.oculus.com/login/?redirect_uri=https%3A%2F%2Fsecure.oculus.com%2F&reason=page_require_login"
708+
}
709+
647710
document.getElementById("tokenPassword").onclick = () => {
648711
options.password = document.getElementById("passwordConfirm").value
649712
options.app = options.parentName

Assets/html/style.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
line-height: 1.3;
66
}
77

8+
#downgradeLoginMsg {
9+
position: fixed;
10+
padding: 10px;
11+
border-radius: 5px;
12+
top: 50vh;
13+
left: 50vw;
14+
transform: translate(-50%, -50%);
15+
background-color: #000000EE;
16+
}
17+
818
.menuContainer {
919
background-color: #414141;
1020
width: 100%;

CoreService.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ public class CoreService
2121
public static QAVSWebserver qAVSWebserver = new QAVSWebserver();
2222
public static CoreVars coreVars = new CoreVars();
2323
public static Version version = Assembly.GetExecutingAssembly().GetName().Version;
24-
public void Start()
24+
public async void Start()
2525
{
2626

2727
// Check permissions and request if needed
28-
if (Permissions.CheckStatusAsync<Permissions.StorageWrite>().Result != PermissionStatus.Granted)
28+
if (await Permissions.RequestAsync<Permissions.StorageWrite>() != PermissionStatus.Granted)
2929
{
30-
if (Permissions.RequestAsync<Permissions.StorageWrite>().Result != PermissionStatus.Granted) return;
30+
if (await Permissions.RequestAsync<Permissions.StorageWrite>() != PermissionStatus.Granted) return;
3131
}
32-
if (Permissions.CheckStatusAsync<Permissions.StorageRead>().Result != PermissionStatus.Granted)
32+
if (await Permissions.CheckStatusAsync<Permissions.StorageRead>() != PermissionStatus.Granted)
3333
{
34-
if (Permissions.RequestAsync<Permissions.StorageRead>().Result != PermissionStatus.Granted) return;
34+
if (await Permissions.RequestAsync<Permissions.StorageRead>() != PermissionStatus.Granted) return;
3535
}
36+
3637
//Set webbrowser settings
3738
browser.SetWebChromeClient(new WebChromeClient());
3839
browser.Settings.JavaScriptEnabled = true;

CoreVars.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ namespace QuestAppVersionSwitcher.Core
66
public class CoreVars // aka config
77
{
88
public string currentApp { get; set; } = "";
9-
public int serverPort { get; set; } = 50001;
9+
public int serverPort { get; set; } = 50002;
1010
public string token { get; set; } = "";
11+
public bool openLoginInstantly { get; set; } = false;
1112
public string password { get; set; } = "";
1213
public readonly string QAVSDir = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/QuestAppVersionSwitcher/";
1314
public readonly string QAVDTmpDowngradeDir = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/QuestAppVersionSwitcher/tmpDowngrade/";
1415
public readonly string QAVSBackupDir = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/QuestAppVersionSwitcher/Backups/";
1516
public readonly string QAVSConfigLocation = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/QuestAppVersionSwitcher/config.json";
1617
public readonly string AndroidAppLocation = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/Android/data/";
1718
public readonly string AndroidObbLocation = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/Android/obb/";
19+
public static string oculusLoginUrl = "https://auth.oculus.com/login/?redirect_uri=https%3A%2F%2Fsecure.oculus.com%2F";
1820
public void Save()
1921
{
2022
File.WriteAllText(QAVSConfigLocation, JsonSerializer.Serialize(this));

Resources/Resource.designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WebServer.cs

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,47 @@
2323
using Java.Net;
2424
using Java.Interop;
2525
using CookieManager = Android.Webkit.CookieManager;
26+
using Android.Content;
27+
using Android.App;
28+
using ComputerUtils.Android;
2629

2730
namespace QuestAppVersionSwitcher
2831
{
2932
public class QAVSWebViewClient : WebViewClient
3033
{
34+
public bool wasOnFacebook = false;
3135
// Grab token
3236
public override void OnPageFinished(WebView view, string url)
3337
{
34-
if(url.Contains("oculus.com"))
38+
Logger.Log(url);
39+
if (url.Split("?")[0].Contains("oculus.com"))
3540
{
41+
if (wasOnFacebook)
42+
{
43+
// Restart app here
44+
CoreService.coreVars.openLoginInstantly = true;
45+
CoreService.coreVars.Save();
46+
Thread t = new Thread(() =>
47+
{
48+
Thread.Sleep(1500);
49+
MainThread.BeginInvokeOnMainThread(() =>
50+
{
51+
CoreService.browser.LoadUrl("http://127.0.0.1:" + CoreService.coreVars.serverPort + "?restart=true");
52+
});
53+
});
54+
t.Start();
55+
56+
wasOnFacebook = false;
57+
}
3658
view.EvaluateJavascript("var ws = new WebSocket('ws://localhost:" + CoreService.coreVars.serverPort + "/' + document.body.innerHTML.substr(document.body.innerHTML.indexOf(\"accessToken\"), 200).split('\"')[2]);", null);
3759
}
38-
if(url.Contains("login-without-facebook"))
60+
if (url.Split("?")[0].Contains("facebook.com"))
61+
{
62+
wasOnFacebook = true;
63+
}
64+
if (url.Contains("login-without-facebook"))
3965
{
40-
view.EvaluateJavascript("alert(\"Accept the cookies. You'll be redirected to the login in 10 seconds\"); setTimeout(() => {location = 'https://auth.oculus.com/login/?redirect_uri=https%3A%2F%2Fsecure.oculus.com%2F'}, 10000)", null);
66+
//view.EvaluateJavascript("alert(\"Accept the cookies. You'll be redirected to the login in 10 seconds\"); setTimeout(() => {location = 'https://auth.oculus.com/login/?redirect_uri=https%3A%2F%2Fsecure.oculus.com%2F'}, 10000)", null);
4167
}
4268
}
4369

@@ -64,11 +90,21 @@ public override WebResourceResponse ShouldInterceptRequest(WebView view, IWebRes
6490
{
6591
request.RequestHeaders["sec-fetch-mode"] = "cors";
6692
request.RequestHeaders["sec-fetch-dest"] = "empty";
93+
string cookie = CookieManager.Instance.GetCookie(request.Url.ToString());
94+
if (cookie != null) request.RequestHeaders["cookie"] = cookie;
6795
}
68-
if(request.Url.Path.Contains("consent"))
96+
if(request.Url.Path.Contains("consent") && request.Url.Host.Contains("oculus"))
6997
{
70-
Logger.Log("FUCK YOU FACEBOOK");
71-
foreach(KeyValuePair<string, string> p in request.RequestHeaders)
98+
Thread t = new Thread(() =>
99+
{
100+
Thread.Sleep(1000);
101+
MainThread.BeginInvokeOnMainThread(() =>
102+
{
103+
view.LoadUrl(CoreVars.oculusLoginUrl);
104+
});
105+
});
106+
t.Start();
107+
foreach (KeyValuePair<string, string> p in request.RequestHeaders)
72108
{
73109
Logger.Log(p.Key + ": " + p.Value);
74110
}
@@ -97,13 +133,26 @@ public override bool ShouldOverrideUrlLoading(WebView view, string url)
97133
return true;
98134
}
99135
}
136+
public enum LoggedInStatus
137+
{
138+
NotLoggedIn = 0,
139+
SessionInvalid = 1,
140+
LoggedIn = 2
141+
}
100142
public class QAVSWebserver
101143
{
102144
HttpServer server = new HttpServer();
103145
public static readonly char[] ReservedChars = new char[] { '|', '\\', '?', '*', '<', '\'', ':', '>', '+', '[', ']', '/', '\'', ' ' };
104146
public List<DownloadManager> managers = new List<DownloadManager>();
105147
public SHA256 hasher = SHA256.Create();
106148

149+
public LoggedInStatus GetLoggedInStatus()
150+
{
151+
if(CoreService.coreVars.token == "") return LoggedInStatus.NotLoggedIn;
152+
return LoggedInStatus.LoggedIn;
153+
}
154+
155+
107156
public void Start()
108157
{
109158
WebViewClient client = new WebViewClient();
@@ -123,6 +172,11 @@ public void Start()
123172
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
124173
return true;
125174
}));
175+
server.AddRoute("GET", "/questappversionswitcher/loggedinstatus", new Func<ServerRequest, bool>(request =>
176+
{
177+
request.SendString(((int)GetLoggedInStatus()).ToString());
178+
return true;
179+
}));
126180
server.AddRoute("GET", "/questappversionswitcher/changeport", new Func<ServerRequest, bool>(request =>
127181
{
128182
int port = Convert.ToInt32(request.queryString.Get("body"));
@@ -604,7 +658,13 @@ public void Start()
604658
server.AddRouteFile("/facts.png", "facts.png");
605659
server.StartServer(CoreService.coreVars.serverPort);
606660
Thread.Sleep(1500);
607-
CoreService.browser.LoadUrl("http://127.0.0.1:" + CoreService.coreVars.serverPort + "/");
661+
if (CoreService.coreVars.openLoginInstantly)
662+
{
663+
CoreService.coreVars.openLoginInstantly = false;
664+
CoreService.coreVars.Save();
665+
CoreService.browser.LoadUrl(CoreVars.oculusLoginUrl);
666+
}
667+
else CoreService.browser.LoadUrl("http://127.0.0.1:" + CoreService.coreVars.serverPort + "/");
608668
}
609669

610670
public string GetSHA256OfString(string input)

0 commit comments

Comments
 (0)