internal static string GetUnityVersion() { string exepath = Imports.GetExePath(); string ggm_path = Path.Combine(Imports.GetGameDataDirectory(), "globalgamemanagers"); if (!File.Exists(ggm_path)) { FileVersionInfo versioninfo = FileVersionInfo.GetVersionInfo(exepath); if ((versioninfo == null) || string.IsNullOrEmpty(versioninfo.FileVersion)) { return("UNKNOWN"); } return(versioninfo.FileVersion.Substring(0, versioninfo.FileVersion.LastIndexOf('.'))); } else { byte[] ggm_bytes = File.ReadAllBytes(ggm_path); if ((ggm_bytes == null) || (ggm_bytes.Length <= 0)) { return("UNKNOWN"); } int start_position = 0; for (int i = 10; i < ggm_bytes.Length; i++) { byte pos_byte = ggm_bytes[i]; if ((pos_byte <= 0x39) && (pos_byte >= 0x30)) { start_position = i; break; } } if (start_position == 0) { return("UNKNOWN"); } int end_position = 0; for (int i = start_position; i < ggm_bytes.Length; i++) { byte pos_byte = ggm_bytes[i]; if ((pos_byte != 0x2E) && ((pos_byte > 0x39) || (pos_byte < 0x30))) { end_position = (i - 1); break; } } if (end_position == 0) { return("UNKNOWN"); } int verstr_byte_pos = 0; byte[] verstr_byte = new byte[((end_position - start_position) + 1)]; for (int i = start_position; i <= end_position; i++) { verstr_byte[verstr_byte_pos] = ggm_bytes[i]; verstr_byte_pos++; } return(Encoding.UTF8.GetString(verstr_byte, 0, verstr_byte.Length)); } }
private static bool Initialize() { string GeneratorProcessPath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Imports.GetGameDirectory(), "MelonLoader"), "Dependencies"), "AssemblyGenerator"), "MelonLoader.AssemblyGenerator.exe"); if (!File.Exists(GeneratorProcessPath)) { MelonLogger.LogError("MelonLoader.AssemblyGenerator.exe does not Exist!"); return(false); } var generatorProcessInfo = new ProcessStartInfo(GeneratorProcessPath); generatorProcessInfo.Arguments = $"\"{MelonLoaderBase.UnityVersion}\" {"\"" + Regex.Replace(Imports.GetGameDirectory(), @"(\\+)$", @"$1$1") + "\""} {"\"" + Regex.Replace(Imports.GetGameDataDirectory(), @"(\\+)$", @"$1$1") + "\""} {(Force_Regenerate() ? "true" : "false")} {(string.IsNullOrEmpty(Force_Version_Unhollower()) ? "" : Force_Version_Unhollower())}"; generatorProcessInfo.UseShellExecute = false; generatorProcessInfo.RedirectStandardOutput = true; generatorProcessInfo.CreateNoWindow = true; Process process = null; try { process = Process.Start(generatorProcessInfo); } catch (Exception e) { MelonLogger.LogError(e.ToString()); MelonLogger.LogError("Unable to Start Assembly Generator!"); return(false); } var stdout = process.StandardOutput; while (!stdout.EndOfStream) { MelonLogger.Log(stdout.ReadLine()); } while (!process.HasExited) { Thread.Sleep(100); } if (process.ExitCode != 0) { MelonLogger.Native_ThrowInternalError($"Assembly Generator exited with code {process.ExitCode}"); return(false); } if (Imports.IsDebugMode()) { MelonLogger.Log($"Assembly Generator ran Successfully!"); } return(true); }