mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-07 08:07:18 +02:00
Use "await" keyword in interceptHttpRequests()
This commit is contained in:
parent
cdc64da95f
commit
6b12b4add4
@ -9985,36 +9985,33 @@ function interceptHttpRequests() {
|
|||||||
|
|
||||||
const consoleAddrs = {};
|
const consoleAddrs = {};
|
||||||
|
|
||||||
const patchIceCandidates = function(...arg) {
|
const patchIceCandidates = async (...arg) => {
|
||||||
// ICE server candidates
|
// ICE server candidates
|
||||||
const request = arg[0];
|
const request = arg[0];
|
||||||
const url = (typeof request === 'string') ? request : request.url;
|
const url = (typeof request === 'string') ? request : request.url;
|
||||||
|
|
||||||
if (url && url.endsWith('/ice') && url.includes('/sessions/') && request.method === 'GET') {
|
if (url && url.endsWith('/ice') && url.includes('/sessions/') && request.method === 'GET') {
|
||||||
const promise = NATIVE_FETCH(...arg);
|
const response = await NATIVE_FETCH(...arg);
|
||||||
|
const text = await response.clone().text();
|
||||||
|
|
||||||
return promise.then(response => {
|
if (!text.length) {
|
||||||
return response.clone().text().then(text => {
|
return response;
|
||||||
if (!text.length) {
|
}
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
preferIpv6Server: PREF_PREFER_IPV6_SERVER,
|
preferIpv6Server: PREF_PREFER_IPV6_SERVER,
|
||||||
consoleAddrs: consoleAddrs,
|
consoleAddrs: consoleAddrs,
|
||||||
};
|
};
|
||||||
|
|
||||||
const obj = JSON.parse(text);
|
const obj = JSON.parse(text);
|
||||||
let exchangeResponse = JSON.parse(obj.exchangeResponse);
|
let exchangeResponse = JSON.parse(obj.exchangeResponse);
|
||||||
exchangeResponse = updateIceCandidates(exchangeResponse, options)
|
exchangeResponse = updateIceCandidates(exchangeResponse, options)
|
||||||
obj.exchangeResponse = JSON.stringify(exchangeResponse);
|
obj.exchangeResponse = JSON.stringify(exchangeResponse);
|
||||||
|
|
||||||
response.json = () => Promise.resolve(obj);
|
response.json = () => Promise.resolve(obj);
|
||||||
response.text = () => Promise.resolve(JSON.stringify(obj));
|
response.text = () => Promise.resolve(JSON.stringify(obj));
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -10080,63 +10077,57 @@ function interceptHttpRequests() {
|
|||||||
|
|
||||||
// Get console IP
|
// Get console IP
|
||||||
if (url.includes('/configuration')) {
|
if (url.includes('/configuration')) {
|
||||||
const promise = NATIVE_FETCH(...arg);
|
const response = await NATIVE_FETCH(...arg);
|
||||||
|
|
||||||
return promise.then(response => {
|
const obj = await response.clone().json()
|
||||||
return response.clone().json().then(obj => {
|
console.log(obj);
|
||||||
console.log(obj);
|
|
||||||
|
|
||||||
const serverDetails = obj.serverDetails;
|
const serverDetails = obj.serverDetails;
|
||||||
if (serverDetails.ipV4Address) {
|
if (serverDetails.ipV4Address) {
|
||||||
consoleAddrs[serverDetails.ipV4Address] = serverDetails.ipV4Port;
|
consoleAddrs[serverDetails.ipV4Address] = serverDetails.ipV4Port;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverDetails.ipV6Address) {
|
if (serverDetails.ipV6Address) {
|
||||||
consoleAddrs[serverDetails.ipV6Address] = serverDetails.ipV6Port;
|
consoleAddrs[serverDetails.ipV6Address] = serverDetails.ipV6Port;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.json = () => Promise.resolve(obj);
|
response.json = () => Promise.resolve(obj);
|
||||||
response.text = () => Promise.resolve(JSON.stringify(obj));
|
response.text = () => Promise.resolve(JSON.stringify(obj));
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
});
|
|
||||||
});
|
|
||||||
} else if (PREF_STREAM_TOUCH_CONTROLLER === 'all' && url.includes('inputconfigs')) {
|
} else if (PREF_STREAM_TOUCH_CONTROLLER === 'all' && url.includes('inputconfigs')) {
|
||||||
const promise = NATIVE_FETCH(...arg);
|
const response = await NATIVE_FETCH(...arg);
|
||||||
|
const obj = await response.clone().json();
|
||||||
|
|
||||||
return promise.then(response => {
|
const xboxTitleId = JSON.parse(opts.body).titleIds[0];
|
||||||
return response.clone().json().then(obj => {
|
GAME_XBOX_TITLE_ID = xboxTitleId;
|
||||||
const xboxTitleId = JSON.parse(opts.body).titleIds[0];
|
|
||||||
GAME_XBOX_TITLE_ID = xboxTitleId;
|
|
||||||
|
|
||||||
const inputConfigs = obj[0];
|
const inputConfigs = obj[0];
|
||||||
|
|
||||||
let hasTouchSupport = inputConfigs.supportedTabs.length > 0;
|
let hasTouchSupport = inputConfigs.supportedTabs.length > 0;
|
||||||
if (!hasTouchSupport) {
|
if (!hasTouchSupport) {
|
||||||
const supportedInputTypes = inputConfigs.supportedInputTypes;
|
const supportedInputTypes = inputConfigs.supportedInputTypes;
|
||||||
hasTouchSupport = supportedInputTypes.includes('NativeTouch');
|
hasTouchSupport = supportedInputTypes.includes('NativeTouch');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasTouchSupport) {
|
if (hasTouchSupport) {
|
||||||
TouchController.disable();
|
TouchController.disable();
|
||||||
|
|
||||||
BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, {
|
BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, {
|
||||||
data: null,
|
data: null,
|
||||||
});
|
|
||||||
} else {
|
|
||||||
TouchController.enable();
|
|
||||||
TouchController.getCustomLayouts(xboxTitleId);
|
|
||||||
}
|
|
||||||
|
|
||||||
response.json = () => Promise.resolve(obj);
|
|
||||||
response.text = () => Promise.resolve(JSON.stringify(obj));
|
|
||||||
|
|
||||||
return response;
|
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
TouchController.enable();
|
||||||
|
TouchController.getCustomLayouts(xboxTitleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.json = () => Promise.resolve(obj);
|
||||||
|
response.text = () => Promise.resolve(JSON.stringify(obj));
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
return patchIceCandidates(...arg) || NATIVE_FETCH(...arg);
|
return await patchIceCandidates(...arg) || NATIVE_FETCH(...arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_REMOTE_PLAYING && url.includes('xhome') && url.includes('/login/user')) {
|
if (IS_REMOTE_PLAYING && url.includes('xhome') && url.includes('/login/user')) {
|
||||||
@ -10184,49 +10175,46 @@ function interceptHttpRequests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ICE server candidates
|
// ICE server candidates
|
||||||
const patchedIpv6 = patchIceCandidates(...arg);
|
const patchedIpv6 = await patchIceCandidates(...arg);
|
||||||
if (patchedIpv6) {
|
if (patchedIpv6) {
|
||||||
return patchedIpv6;
|
return patchedIpv6;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server list
|
// Server list
|
||||||
if (!url.includes('xhome.') && url.endsWith('/v2/login/user')) {
|
if (!url.includes('xhome.') && url.endsWith('/v2/login/user')) {
|
||||||
const promise = NATIVE_FETCH(...arg);
|
const response = await NATIVE_FETCH(...arg);
|
||||||
|
const obj = await response.clone().json();
|
||||||
|
|
||||||
return promise.then(response => {
|
// Preload Remote Play
|
||||||
return response.clone().json().then(obj => {
|
BX_FLAGS.PreloadRemotePlay && RemotePlay.preload();
|
||||||
// Preload Remote Play
|
|
||||||
BX_FLAGS.PreloadRemotePlay && RemotePlay.preload();
|
|
||||||
|
|
||||||
// Store xCloud token
|
// Store xCloud token
|
||||||
RemotePlay.XCLOUD_TOKEN = obj.gsToken;
|
RemotePlay.XCLOUD_TOKEN = obj.gsToken;
|
||||||
|
|
||||||
// Get server list
|
// Get server list
|
||||||
if (!Object.keys(SERVER_REGIONS).length) {
|
if (!Object.keys(SERVER_REGIONS).length) {
|
||||||
for (let region of obj.offeringSettings.regions) {
|
for (let region of obj.offeringSettings.regions) {
|
||||||
SERVER_REGIONS[region.name] = Object.assign({}, region);
|
SERVER_REGIONS[region.name] = Object.assign({}, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start rendering UI
|
// Start rendering UI
|
||||||
if (document.querySelector('div[class^=UnsupportedMarketPage]')) {
|
if (document.querySelector('div[class^=UnsupportedMarketPage]')) {
|
||||||
setTimeout(watchHeader, 2000);
|
setTimeout(watchHeader, 2000);
|
||||||
} else {
|
} else {
|
||||||
watchHeader();
|
watchHeader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const preferredRegion = getPreferredServerRegion();
|
const preferredRegion = getPreferredServerRegion();
|
||||||
if (preferredRegion in SERVER_REGIONS) {
|
if (preferredRegion in SERVER_REGIONS) {
|
||||||
const tmp = Object.assign({}, SERVER_REGIONS[preferredRegion]);
|
const tmp = Object.assign({}, SERVER_REGIONS[preferredRegion]);
|
||||||
tmp.isDefault = true;
|
tmp.isDefault = true;
|
||||||
|
|
||||||
obj.offeringSettings.regions = [tmp];
|
obj.offeringSettings.regions = [tmp];
|
||||||
}
|
}
|
||||||
|
|
||||||
response.json = () => Promise.resolve(obj);
|
response.json = () => Promise.resolve(obj);
|
||||||
return response;
|
return response;
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get region
|
// Get region
|
||||||
@ -10271,22 +10259,18 @@ function interceptHttpRequests() {
|
|||||||
|
|
||||||
// Get wait time
|
// Get wait time
|
||||||
if (PREF_UI_LOADING_SCREEN_WAIT_TIME && url.includes('xboxlive.com') && url.includes('/waittime/')) {
|
if (PREF_UI_LOADING_SCREEN_WAIT_TIME && url.includes('xboxlive.com') && url.includes('/waittime/')) {
|
||||||
const promise = NATIVE_FETCH(...arg);
|
const response = await NATIVE_FETCH(...arg);
|
||||||
return promise.then(response => {
|
|
||||||
return response.clone().json().then(json => {
|
|
||||||
if (json.estimatedAllocationTimeInSeconds > 0) {
|
|
||||||
// Setup wait time overlay
|
|
||||||
LoadingScreen.setupWaitTime(json.estimatedTotalWaitTimeInSeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
const json = await response.clone.json();
|
||||||
});
|
if (json.estimatedAllocationTimeInSeconds > 0) {
|
||||||
});
|
// Setup wait time overlay
|
||||||
|
LoadingScreen.setupWaitTime(json.estimatedTotalWaitTimeInSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.endsWith('/configuration') && url.includes('/sessions/cloud/') && request.method === 'GET') {
|
if (url.endsWith('/configuration') && url.includes('/sessions/cloud/') && request.method === 'GET') {
|
||||||
const promise = NATIVE_FETCH(...arg);
|
|
||||||
|
|
||||||
// Touch controller for all games
|
// Touch controller for all games
|
||||||
if (PREF_STREAM_TOUCH_CONTROLLER === 'all') {
|
if (PREF_STREAM_TOUCH_CONTROLLER === 'all') {
|
||||||
TouchController.disable();
|
TouchController.disable();
|
||||||
@ -10301,68 +10285,61 @@ function interceptHttpRequests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Intercept configurations
|
// Intercept configurations
|
||||||
return promise.then(response => {
|
const response = await NATIVE_FETCH(...arg);
|
||||||
return response.clone().text().then(text => {
|
const text = await response.clone().text();
|
||||||
if (!text.length) {
|
if (!text.length) {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
const obj = JSON.parse(text);
|
const obj = JSON.parse(text);
|
||||||
let overrides = JSON.parse(obj.clientStreamingConfigOverrides || '{}') || {};
|
let overrides = JSON.parse(obj.clientStreamingConfigOverrides || '{}') || {};
|
||||||
|
|
||||||
overrides.inputConfiguration = overrides.inputConfiguration || {};
|
overrides.inputConfiguration = overrides.inputConfiguration || {};
|
||||||
overrides.inputConfiguration.enableVibration = true;
|
overrides.inputConfiguration.enableVibration = true;
|
||||||
if (ENABLE_NATIVE_MKB_BETA) {
|
if (ENABLE_NATIVE_MKB_BETA) {
|
||||||
overrides.inputConfiguration.enableMouseAndKeyboard = true;
|
overrides.inputConfiguration.enableMouseAndKeyboard = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable touch controller
|
// Enable touch controller
|
||||||
if (TouchController.isEnabled()) {
|
if (TouchController.isEnabled()) {
|
||||||
overrides.inputConfiguration.enableTouchInput = true;
|
overrides.inputConfiguration.enableTouchInput = true;
|
||||||
overrides.inputConfiguration.maxTouchPoints = 10;
|
overrides.inputConfiguration.maxTouchPoints = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable mic
|
// Enable mic
|
||||||
if (PREF_AUDIO_MIC_ON_PLAYING) {
|
if (PREF_AUDIO_MIC_ON_PLAYING) {
|
||||||
overrides.audioConfiguration = overrides.audioConfiguration || {};
|
overrides.audioConfiguration = overrides.audioConfiguration || {};
|
||||||
overrides.audioConfiguration.enableMicrophone = true;
|
overrides.audioConfiguration.enableMicrophone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.clientStreamingConfigOverrides = JSON.stringify(overrides);
|
obj.clientStreamingConfigOverrides = JSON.stringify(overrides);
|
||||||
|
|
||||||
response.json = () => Promise.resolve(obj);
|
response.json = () => Promise.resolve(obj);
|
||||||
response.text = () => Promise.resolve(JSON.stringify(obj));
|
response.text = () => Promise.resolve(JSON.stringify(obj));
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// catalog.gamepass
|
// catalog.gamepass
|
||||||
if (url.startsWith('https://catalog.gamepass.com') && url.includes('/products')) {
|
if (url.startsWith('https://catalog.gamepass.com') && url.includes('/products')) {
|
||||||
const promise = NATIVE_FETCH(...arg);
|
const response = await NATIVE_FETCH(...arg);
|
||||||
return promise.then(response => {
|
const json = await response.clone().json()
|
||||||
return response.clone().json().then(json => {
|
|
||||||
for (let productId in json.Products) {
|
|
||||||
TitlesInfo.saveFromCatalogInfo(json.Products[productId]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
for (let productId in json.Products) {
|
||||||
});
|
TitlesInfo.saveFromCatalogInfo(json.Products[productId]);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PREF_STREAM_TOUCH_CONTROLLER === 'all' && (url.includes('/titles') || url.includes('/mru'))) {
|
if (PREF_STREAM_TOUCH_CONTROLLER === 'all' && (url.includes('/titles') || url.includes('/mru'))) {
|
||||||
const promise = NATIVE_FETCH(...arg);
|
const response = await NATIVE_FETCH(...arg);
|
||||||
return promise.then(response => {
|
const json = await response.clone().json()
|
||||||
return response.clone().json().then(json => {
|
for (let game of json.results) {
|
||||||
for (let game of json.results) {
|
TitlesInfo.saveFromTitleInfo(game);
|
||||||
TitlesInfo.saveFromTitleInfo(game);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NATIVE_FETCH(...arg);
|
return NATIVE_FETCH(...arg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user