GDK patch

This commit is contained in:
Mister_Nebula 2022-08-18 18:41:36 +01:00
parent b1768e7afb
commit 828aeac361
2 changed files with 48 additions and 9 deletions

View File

@ -0,0 +1,37 @@
using HarmonyLib;
using Microsoft.Xbox;
using QSB.Patches;
using QSB.Utility;
using System.Collections.Generic;
using UnityEngine;
namespace QSB.SaveSync.Patches;
[HarmonyPatch(typeof(Gdk))]
internal class GdkPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
public override GameVendor PatchVendor => GameVendor.Gamepass;
[HarmonyPrefix]
[HarmonyPatch("QueryBlobsCompleted")]
public static bool QueryBlobsCompleted(int hresult, Dictionary<string, uint> blobs)
{
if (!Gdk.Succeeded(hresult, "Query blobs"))
{
DebugLog.DebugWrite("[GDK] Query blobs failed!");
return false;
}
Debug.Log(string.Format("[GDK] Save system setup complete. Blobs returned: {0}", blobs.Count));
foreach (var keyValuePair in blobs)
{
DebugLog.DebugWrite(keyValuePair.Key);
}
QSBMSStoreProfileManager.SharedInstance.InvokeProfileSignInComplete();
QSBMSStoreProfileManager.SharedInstance.InvokeSaveSetupComplete();
SpinnerUI.Hide();
return false;
}
}

View File

@ -1,5 +1,6 @@
using Microsoft.Xbox;
using Newtonsoft.Json;
using QSB.Utility;
using System;
using System.IO;
using System.Runtime.Serialization;
@ -135,7 +136,7 @@ internal class QSBMSStoreProfileManager : IProfileManager
public void SaveGame(GameSave gameSave, SettingsSave settSave, GraphicSettings gfxSettings, string inputJSON)
{
Debug.Log("MSStoreProfileManager.SaveGame");
DebugLog.DebugWrite("MSStoreProfileManager.SaveGame");
if (isBusyWithFileOps || LoadManager.IsBusy())
{
_pendingGameSave = gameSave;
@ -215,13 +216,14 @@ internal class QSBMSStoreProfileManager : IProfileManager
private void LoadGame(string blobName)
{
DebugLog.DebugWrite($"LoadGame blobName:{blobName}");
_fileOpsBusyLocks++;
Gdk.Helpers.LoadSaveData(blobName);
}
private void WriteSaveToStorage(QSBX1SaveData saveData, string blobName)
{
Debug.Log("Saving to storage: " + blobName);
DebugLog.DebugWrite("Saving to storage: " + blobName);
_fileOpsBusyLocks++;
var memoryStream = new MemoryStream();
using (JsonWriter jsonWriter = new JsonTextWriter(new StreamWriter(memoryStream)))
@ -248,19 +250,19 @@ internal class QSBMSStoreProfileManager : IProfileManager
private void OnGameSaveComplete(object sender, string blobName)
{
_fileOpsBusyLocks--;
Debug.Log("[GDK] save to blob " + blobName + " complete");
DebugLog.DebugWrite("[GDK] save to blob " + blobName + " complete");
}
private void OnGameSaveFailed(object sender, string blobName)
{
_fileOpsBusyLocks--;
Debug.Log("[GDK] save to blob " + blobName + " failed");
DebugLog.DebugWrite("[GDK] save to blob " + blobName + " failed");
}
private void OnGameSaveLoaded(object sender, string blobName, GameSaveLoadedArgs saveData)
{
_fileOpsBusyLocks--;
Debug.Log("[GDK] save file load complete! blob name: " + blobName);
DebugLog.DebugWrite("[GDK] save file load complete! blob name: " + blobName);
var memoryStream = new MemoryStream(saveData.Data);
memoryStream.Seek(0L, SeekOrigin.Begin);
using (var jsonTextReader = new JsonTextReader(new StreamReader(memoryStream)))
@ -272,14 +274,14 @@ internal class QSBMSStoreProfileManager : IProfileManager
{
if (x1SaveData.gameSave == null)
{
Debug.Log("[GDK] tempSaveData.gameSave is null (oh no)");
DebugLog.DebugWrite("[GDK] tempSaveData.gameSave is null (oh no)");
}
_saveData.gameSave = x1SaveData.gameSave ?? new GameSave();
}
else
{
Debug.Log("[GDK] tempSaveData is null (oh no)");
DebugLog.DebugWrite("[GDK] tempSaveData is null (oh no)");
_saveData.gameSave = new GameSave();
}
}
@ -298,8 +300,8 @@ internal class QSBMSStoreProfileManager : IProfileManager
_saveData.inputActionsJson = ((InputManager)OWInput.SharedInputManager).commandManager.DefaultInputActions.ToJson();
}
Debug.Log(string.Format("after settings load, _saveData.gameSave is null: {0}", _saveData.gameSave == null));
Debug.Log(string.Format("_saveData loopCount: {0}", _saveData.gameSave.loopCount));
DebugLog.DebugWrite(string.Format("after settings load, _saveData.gameSave is null: {0}", _saveData.gameSave == null));
DebugLog.DebugWrite(string.Format("_saveData loopCount: {0}", _saveData.gameSave.loopCount));
}
}