using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using WildSkies.Service;
using WildSkies.Service.Data;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("OldSaveDataFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Nines (Natives)")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("OldSaveDataFix")]
[assembly: AssemblyTitle("OldSaveDataFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace OldSaveDataFix
{
[BepInPlugin("OldSaveDataFix", "OldSaveDataFix", "1.1.0")]
public class Plugin : BasePlugin
{
private class InventoryItemSaveDataJsonConverter : JsonConverter
{
private IItemService _itemService = SceneContextInstaller.ResolveObject<IItemService>();
public InventoryItemSaveDataJsonConverter(IntPtr ptr)
: base(ptr)
{
}
public InventoryItemSaveDataJsonConverter()
: base(ClassInjector.DerivedConstructorPointer<InventoryItemSaveDataJsonConverter>())
{
ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
}
public override bool CanConvert(Type objectType)
{
return objectType == Il2CppType.Of<InventoryItemSaveData>();
}
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
JObject val = JObject.Load(reader);
val["Id"] = JToken.op_Implicit(_itemService.GetUniqueIdFromItemId((string)val["Id"]));
val["CreatorName"] = JToken.op_Implicit(0);
return (Object)(object)((JToken)val).ToObject<InventoryItemSaveData>();
}
}
internal static ManualLogSource Log;
internal static Harmony harmonyInstance;
public override void Load()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("OldSaveDataFix");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
}
log.LogInfo(val);
ClassInjector.RegisterTypeInIl2Cpp<InventoryItemSaveDataJsonConverter>();
harmonyInstance = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
}
public override bool Unload()
{
Harmony obj = harmonyInstance;
if (obj != null)
{
obj.UnpatchSelf();
}
return true;
}
[HarmonyPatch(typeof(PlatformService), "GetAllSavedCharacters")]
[HarmonyPrefix]
public static void PlatformService_GetAllSavedCharacters(PlatformService __instance)
{
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Expected O, but got Unknown
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
foreach (string item in (Il2CppArrayBase<string>)(object)__instance.GetFilesInPathSortedByLastWriteTime(__instance.GetSaveDataRootPath(), "SaveData_Character_*.sav", int.MaxValue))
{
string text = File.ReadAllText(item);
try
{
text = PlatformService.AesDec(text);
}
catch
{
}
CharacterSaveData val;
try
{
val = ((Il2CppObjectBase)JsonConvert.DeserializeObject(text, Il2CppType.Of<CharacterSaveData>())).Cast<CharacterSaveData>();
}
catch
{
continue;
}
if (val.Version == 2)
{
val.Version = 4;
Enumerator<string, string> enumerator2 = ((Dictionary<string, string>)(object)val.PerWorldDatas).GetEnumerator();
while (enumerator2.MoveNext())
{
KeyValuePair<string, string> current2 = enumerator2.Current;
JObject val2 = JObject.Parse(current2.value);
JObject val3 = val2["PlayerPositionData"].ToObject<JObject>();
val3["TrackedShipId"] = val3["TrackedObjectId"];
current2.value = JsonConvert.SerializeObject((Object)(object)((JToken)val2).ToObject<PerWorldData>());
}
JsonSerializerSettings val4 = new JsonSerializerSettings();
((Il2CppObjectBase)val4.Converters).Cast<List<JsonConverter>>().Add((JsonConverter)(object)new InventoryItemSaveDataJsonConverter());
PlayerInventoryStructureSaveData val5 = ((Il2CppObjectBase)JsonConvert.DeserializeObject(((Dictionary<string, string>)(object)val.CharacterSaveDatas)["PlayerInventory"], Il2CppType.Of<PlayerInventoryStructureSaveData>(), val4)).Cast<PlayerInventoryStructureSaveData>();
((Dictionary<string, string>)(object)val.CharacterSaveDatas)["PlayerInventory"] = JsonConvert.SerializeObject((Object)(object)val5);
val.LastSaved = val.TimeStamp;
__instance.SaveCharacterData(__instance.GetFullSavePathForCharacter(val.CharacterName), val);
DirectoryInfo directoryInfo = Directory.CreateDirectory(Path.Combine(__instance.GetSaveDataRootPath(), Path.GetFileNameWithoutExtension(item) + "-BACKUP"));
string fullName = directoryInfo.FullName;
DateTime now = DateTime.Now;
File.Move(item, Path.Combine(fullName, "[" + ((DateTime)(ref now)).ToString("yyyy-MM-dd HH-mm-ss") + "] " + Path.GetFileName(item)), overwrite: true);
}
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "OldSaveDataFix";
public const string PLUGIN_NAME = "OldSaveDataFix";
public const string PLUGIN_VERSION = "1.1.0";
}
}