Decompiled source of Baby Got Build v1.0.0

Plugins/VentureValheim.BabyGotBuild.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Splatform;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("VentureValheim.BabyGotBuild")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VentureValheim.BabyGotBuild")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("DAD409CD-A59B-4381-9F15-49E0E5D02B18")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace VentureValheim.BabyGotBuild
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.orianaventure.mod.BabyGotBuild", "BabyGotBuild", "1.0.0")]
	public class BabyGotBuildPlugin : BaseUnityPlugin
	{
		private const string ModName = "BabyGotBuild";

		private const string ModVersion = "1.0.0";

		private const string Author = "com.orianaventure.mod";

		private const string ModGUID = "com.orianaventure.mod.BabyGotBuild";

		private readonly Harmony HarmonyInstance = new Harmony("com.orianaventure.mod.BabyGotBuild");

		public static readonly ManualLogSource BabyGotBuildLogger = Logger.CreateLogSource("BabyGotBuild");

		public void Awake()
		{
			BabyGotBuildLogger.LogInfo((object)"I like big builds and I cannot lie!");
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			HarmonyInstance.PatchAll(executingAssembly);
		}
	}
	public static class BabyGotBuild
	{
		[HarmonyPatch(typeof(PlayerProfile), "Load")]
		public static class Patch_PlayerProfile_Load
		{
			private static void Prefix(PlayerProfile __instance)
			{
				_profile = __instance;
			}
		}

		[HarmonyPatch(typeof(Player), "Load")]
		public static class Patch_Player_Load
		{
			private static void Postfix()
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (IsInTheMainScene() && _profile != null)
				{
					LoadFile(_profile.m_fileSource);
				}
			}
		}

		[HarmonyPatch(typeof(Player), "Save")]
		public static class Patch_Player_Save
		{
			private static void Prefix()
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (IsInTheMainScene() && _profile != null)
				{
					SaveFile(_profile.m_fileSource);
				}
			}
		}

		private static PlayerProfile _profile;

		private static string _filepath;

		private static string GetFilePath(string original)
		{
			return original + ".extras";
		}

		private static string GetNewFilePath(string original)
		{
			return original + ".newextras";
		}

		private static string GetOldFilePath(string original)
		{
			return original + ".oldextras";
		}

		private static void SaveFile(FileSource filesource)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			if (Hud.instance?.m_buildUi.m_favoritePieceList == null)
			{
				BabyGotBuildPlugin.BabyGotBuildLogger.LogWarning((object)"Favorite Pieces could not be found, cannot save.");
				return;
			}
			SetFilePath(filesource);
			ZPackage val = new ZPackage();
			UTF8Encoding uTF8Encoding = new UTF8Encoding();
			Hud.instance.m_buildUi.m_recentPieceList.Serialize(val, (Encoding)uTF8Encoding);
			Hud.instance.m_buildUi.m_favoritePieceList.Serialize(val, (Encoding)uTF8Encoding);
			FileWriter val2 = new FileWriter(GetNewFilePath(_filepath), (CloudStorageFileGrouping)2, (FileHelperType)0, filesource);
			byte[] array = val.GenerateHash();
			byte[] array2 = val.GetArray();
			val2.m_binary.Write(array2.Length);
			val2.m_binary.Write(array2);
			val2.m_binary.Write(array.Length);
			val2.m_binary.Write(array);
			val2.Finish();
			FileHelpers.ReplaceOldFile(GetFilePath(_filepath), GetNewFilePath(_filepath), GetOldFilePath(_filepath), (CloudStorageFileGrouping)2, filesource);
		}

		private static void LoadFile(FileSource filesource)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			if (Hud.instance?.m_buildUi.m_favoritePieceList == null)
			{
				BabyGotBuildPlugin.BabyGotBuildLogger.LogWarning((object)"Favorite Pieces could not be found, cannot load.");
				return;
			}
			SetFilePath(filesource);
			FileReader val = null;
			try
			{
				val = new FileReader(GetFilePath(_filepath), filesource, (FileHelperType)0);
				BinaryReader binary = val.m_binary;
				int count = binary.ReadInt32();
				byte[] array = binary.ReadBytes(count);
				int count2 = binary.ReadInt32();
				binary.ReadBytes(count2);
				Hud.instance.m_buildUi.LoadFromBinary(array);
				val.Dispose();
			}
			catch
			{
				BabyGotBuildPlugin.BabyGotBuildLogger.LogWarning((object)$"Failed to load Source: {filesource}, Path: {GetFilePath(_filepath)}");
				if (val != null)
				{
					val.Dispose();
				}
			}
		}

		public static bool IsInTheMainScene()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			return ((Scene)(ref activeScene)).name.Equals("main");
		}

		private static void SetFilePath(FileSource filesource)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if (Utility.IsNullOrWhiteSpace(_filepath))
			{
				_filepath = SaveSystem.GetCharacterFolderPath(filesource) + "BabyGotBuildData";
			}
		}
	}
}