Files
Nebula-Auth/SteamLibForked/Utility/MafileSerialization/MafileSerializer_Write.cs
T
achiez 8ff960189e 1.5.6 Bug fixes and code clean-ups
- Update: Added "Copy Password" to Mafile context menu (if available)
- Update: "Save Password" now pre-fills the current password in the "Login Again" dialog when encryption is enabled
- Fix: Prevented overlapping confirmation cycles in AutoConfirmer
- Fix: Added a Snackbar notification when a confirmation cycle is skipped due to a too frequent timer interval
- Fix: Fixed a rare bug where the previous proxy was used instead of the current one during session refresh
- Fix: Corrected "Session Permanently Expired" message showing on unrelated errors (e.g. network issues)
- UI-Fix: Fixed visual glitch where proxy input appeared non-empty when switching to a mafile-specific proxy
- Cleanup: Refactored and cleaned up codebase, improved styling and formatting via ReSharper
2025-05-02 23:29:24 +03:00

110 lines
3.6 KiB
C#

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace SteamLib.Utility.MafileSerialization;
public partial class MafileSerializer //Write
{
private const string CREDITS_PROPERTY_NAME = "Credits";
public static string Serialize(MobileDataExtended mobileData, Formatting formatting = Formatting.Indented,
bool sign = true, MafileCredits? credits = null)
{
using var w = new StringWriter();
using var write = new JsonTextWriter(w);
write.Formatting = formatting;
var j = JObject.FromObject(mobileData);
j.Add(SIGNATURE_PROPERTY_NAME, MAFILE_VERSION);
if (sign)
{
credits ??= MafileCredits.Instance;
var obj = JObject.FromObject(credits);
j.Add(CREDITS_PROPERTY_NAME, obj);
}
j.WriteTo(write);
return w.ToString();
}
public static async Task<string> SerializeAsync(MobileDataExtended mobileData,
Formatting formatting = Formatting.Indented, bool sign = true, MafileCredits? credits = null)
{
await using var w = new StringWriter();
await using var write = new JsonTextWriter(w);
write.Formatting = formatting;
var j = JObject.FromObject(mobileData);
j.Add(SIGNATURE_PROPERTY_NAME, j);
if (sign)
{
credits ??= MafileCredits.Instance;
var obj = JObject.FromObject(credits);
j.Add(CREDITS_PROPERTY_NAME, obj);
}
await j.WriteToAsync(write);
return w.ToString();
}
public static string SerializeLegacy(MobileData mobileData, Formatting formatting,
Dictionary<string, object?>? additionalProperties = null, bool sign = true, MafileCredits? credits = null)
{
var result = new LegacyMafile
{
SharedSecret = mobileData.SharedSecret,
IdentitySecret = mobileData.IdentitySecret,
DeviceId = mobileData.DeviceId
};
if (mobileData is MobileDataExtended ext)
{
result.RevocationCode = ext.RevocationCode ?? string.Empty;
result.AccountName = ext.AccountName;
result.SessionData = ext.SessionData == null
? null
: new
{
AccessToken = ext.SessionData?.MobileToken?.Token,
steamLoginSecure = ext.SessionData?.MobileToken?.SignedToken,
RefreshToken = ext.SessionData?.RefreshToken.Token,
SteamID = ext.SessionData?.SteamId.Steam64.Id,
SessionID = ext.SessionData?.SessionId
};
result.ServerTime = ext.ServerTime;
result.SerialNumber = ext.SerialNumber.ToString();
result.Uri = ext.Uri;
result.TokenGid = ext.TokenGid;
result.Secret1 = ext.Secret1;
result.SteamId = ext.SteamId.Steam64.Id;
}
using var w = new StringWriter();
using var write = new JsonTextWriter(w);
write.Formatting = formatting;
var j = JObject.FromObject(result);
if (additionalProperties != null)
{
foreach (var (name, value) in additionalProperties)
{
JToken? jToken = null;
if (value != null)
{
jToken = JToken.FromObject(value);
}
j.Add(name, jToken);
}
}
if (sign)
{
credits ??= MafileCredits.Instance;
var obj = JObject.FromObject(credits);
j.Add(CREDITS_PROPERTY_NAME, obj);
}
j.WriteTo(write);
return w.ToString();
}
}