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 System.Text; using AssetRipper.VersionUtilities; using MonoMod.Utils; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: InternalsVisibleTo("BepInEx.Unity.Mono.Preloader")] [assembly: InternalsVisibleTo("BepInEx.Unity.Mono")] [assembly: InternalsVisibleTo("BepInEx.Unity.IL2CPP")] [assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")] [assembly: AssemblyCompany("BepInEx")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright © 2022 BepInEx Team")] [assembly: AssemblyDescription("BepInEx common code for Unity games")] [assembly: AssemblyFileVersion("6.0.0.0")] [assembly: AssemblyInformationalVersion("6.0.0-be.674+82077ec7c91c97f0e5f8ada5d178fd7ece6c0099")] [assembly: AssemblyProduct("BepInEx.Unity.Common")] [assembly: AssemblyTitle("BepInEx.Unity.Common")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/BepInEx/BepInEx")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("6.0.0.0")] [module: UnverifiableCode] namespace BepInEx.Unity.Common; public static class UnityInfo { private class ManagerLookup { private readonly string filePath; private readonly int[] lookupOffsets; public ManagerLookup(string filePath, params int[] lookupOffsets) { this.filePath = filePath; this.lookupOffsets = lookupOffsets; } public bool TryLookup(out UnityVersion version) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) string path = Path.Combine(GameDataPath, filePath); if (!File.Exists(path)) { version = default(UnityVersion); return false; } using FileStream fileStream = File.OpenRead(path); int[] array = lookupOffsets; foreach (int num in array) { StringBuilder stringBuilder = new StringBuilder(); fileStream.Position = num; byte value; while ((value = (byte)fileStream.ReadByte()) != 0) { stringBuilder.Append((char)value); } try { version = UnityVersion.Parse(stringBuilder.ToString()); return true; } catch (Exception) { } } version = default(UnityVersion); return false; } } private static readonly ManagerLookup[] ManagerVersionLookup = new ManagerLookup[3] { new ManagerLookup("globalgamemanagers", 20, 48), new ManagerLookup("data.unity3d", 18), new ManagerLookup("mainData", 20) }; private static bool initialized; public static string PlayerPath { get; private set; } public static string GameDataPath { get; private set; } public static UnityVersion Version { get; private set; } internal static void Initialize(string unityPlayerPath, string gameDataPath) { if (!initialized) { PlayerPath = Path.GetFullPath(unityPlayerPath ?? throw new ArgumentNullException("unityPlayerPath")); GameDataPath = Path.GetFullPath(gameDataPath ?? throw new ArgumentNullException("gameDataPath")); DetermineVersion(); initialized = true; } } internal static void SetRuntimeUnityVersion(string version) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) Version = UnityVersion.Parse(version); } private static void DetermineVersion() { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) ManagerLookup[] managerVersionLookup = ManagerVersionLookup; for (int i = 0; i < managerVersionLookup.Length; i++) { if (managerVersionLookup[i].TryLookup(out var version)) { Version = version; return; } } if (PlatformHelper.Is((Platform)37)) { try { Version version2 = new Version(FileVersionInfo.GetVersionInfo(PlayerPath).FileVersion); Version = new UnityVersion((ushort)version2.Major, (ushort)version2.Minor, (ushort)version2.Build); return; } catch (Exception) { } } if (File.Exists(Path.Combine(Path.Combine(GameDataPath, "Managed"), "UnityEngine.CoreModule.dll"))) { Version = new UnityVersion((ushort)2017, (ushort)0, (ushort)0, (UnityVersionType)5); } Version = default(UnityVersion); } }