public static void ExeSelected(this InstallerWindow ins, string path, string suffix = null) { ins.Invoke(delegate() { ins.ExeStatusLabel.Text = path == null ? "No FEZ.exe selected" : "FEZ [checking version]"; if (path != null && suffix != null) { ins.ExeStatusLabel.Text += suffix; } ins.ExeStatusLabel.BackColor = path == null ? Color.FromArgb(127, 255, 63, 63) : Color.FromArgb(127, 255, 255, 63); ins.ExePathBox.Text = path ?? ""; ins.InstallButton.Enabled = false; }); if (path != null) { ins.ExeMod = new MonoMod.MonoMod(path); } else { ins.ExeMod = null; ins.FezVersion = null; ins.FezModVersion = null; return; } //We want to read the EXE now already. Writing is also handled manually. try { ins.ExeMod.Read(true); } catch (BadImageFormatException) { //this is not FEZ.exe... ins.ExeSelected(null); return; } TypeDefinition FezType = ins.ExeMod.Module.GetType("FezGame.Fez"); if (FezType == null) { ins.ExeSelected(null); return; } MethodDefinition FezCctor = null; for (int i = 0; i < FezType.Methods.Count; i++) { if (FezType.Methods[i].IsStatic && FezType.Methods[i].IsConstructor) { FezCctor = FezType.Methods[i]; break; } } if (FezCctor == null) { ins.ExeSelected(null); return; } ins.FezVersion = null; for (int i = 0; i < FezCctor.Body.Instructions.Count; i++) { if (!(FezCctor.Body.Instructions[i].Operand is FieldReference)) { continue; } if (((FieldReference)FezCctor.Body.Instructions[i].Operand).Name == "Version") { ins.FezVersion = getString(FezCctor.Body.Instructions, i - 1); } } TypeDefinition FezModType = ins.ExeMod.Module.GetType("FezGame.Mod.FEZMod"); if (FezModType != null) { MethodDefinition FezModCctor = null; for (int i = 0; i < FezModType.Methods.Count; i++) { if (FezModType.Methods[i].IsStatic && FezModType.Methods[i].IsConstructor) { FezModCctor = FezModType.Methods[i]; break; } } if (FezModCctor == null) { ins.ExeSelected(null); return; } ins.FezModVersion = null; for (int i = 0; i < FezModCctor.Body.Instructions.Count; i++) { if (!(FezModCctor.Body.Instructions[i].Operand is FieldReference)) { continue; } if (((FieldReference)FezModCctor.Body.Instructions[i].Operand).Name == "Version") { ins.FezModVersion = getString(FezModCctor.Body.Instructions, i - 1); break; } } } ins.Invoke(delegate() { if (ins.FezVersion == null) { ins.ExeStatusLabel.Text = "FEZ [unknown version]"; ins.ExeStatusLabel.BackColor = Color.FromArgb(127, 255, 255, 63); } else { ins.ExeStatusLabel.Text = "FEZ "; ins.ExeStatusLabel.Text += ins.FezVersion; ins.ExeStatusLabel.BackColor = Color.FromArgb(127, 63, 255, 91); } if (ins.FezModVersion != null) { ins.ExeStatusLabel.Text += " [Mod:"; ins.ExeStatusLabel.Text += ins.FezModVersion; ins.ExeStatusLabel.Text += "]"; } if (suffix != null) { ins.ExeStatusLabel.Text += suffix; } ins.InstallButton.Enabled = true; }); }
private static void Install_(this InstallerWindow ins) { ins.Invoke(() => ins.LogBox.Visible = true).SetMainEnabled(false); Directory.SetCurrentDirectory(ins.ExeMod.Dir.FullName); ins.Log("FEZ ").LogLine(ins.FezVersion); //Clean FEZ from any previous FEZMod installation ins.Uninstall(); ins.Backup("Common.dll"); ins.Backup("EasyStorage.dll"); int v = int.Parse(ins.FezVersion.Substring(2)); if (12 <= v) { ins.Backup("FNA.dll"); } else { ins.Backup("MonoGame.Framework.dll"); } ins.Backup("FezEngine.dll"); ins.Backup("FEZ.exe"); //Setup the files and MonoMod instances if (ins.VersionTabs.SelectedIndex == 0) { Tuple <string, string> t = ins.StableVersions[ins.StableVersionList.SelectedIndex]; ins.Log("FEZMod Stable ").LogLine(t.Item1); if (!ins.UnzipMod(ins.DownloadCached(t.Item2, "stable" + t.Item1 + ".zip"))) { return; } } else if (ins.VersionTabs.SelectedIndex == 1) { Tuple <string, string> t = ins.NightlyVersions[ins.NightlyVersionList.SelectedIndex]; ins.Log("FEZMod Nightly ").LogLine(t.Item1); if (!ins.UnzipMod(ins.DownloadCached(t.Item2, "devbuild" + t.Item1 + ".zip"))) { return; } } else if (ins.VersionTabs.SelectedIndex == 2) { string path = ins.ManualPathBox.Text; if (path.ToLower().EndsWith(".zip")) { ins.LogLine("FEZMod Manual ZIP"); if (!ins.UnzipMod(File.OpenRead(path))) { return; } } else { ins.LogLine("FEZMod Manual Folder"); string pathFez = ins.ExeMod.Dir.FullName; string[] files = Directory.GetFiles(path); ins.InitProgress("Copying FEZMod", files.Length); for (int i = 0; i < files.Length; i++) { string file = Path.GetFileName(files[i]); if (!file.Contains(".mm.")) { ins.SetProgress("Skipping: " + file, i); continue; } ins.Log("Copying: ").LogLine(file); ins.SetProgress("Copying: " + file, i); string origPath = Path.Combine(pathFez, file); File.Copy(files[i], origPath, true); } ins.EndProgress("Copying FEZMod complete."); } } if (Blacklist.Count != 0) { ins.LogLine(); ins.Log(Blacklist.Count.ToString()).LogLine(" mods on the blacklist - removing them!"); for (int i = 0; i < Blacklist.Count; i++) { string blacklisted = Blacklist[i]; string pathFez = ins.ExeMod.Dir.FullName; string blacklistedPath = Path.Combine(pathFez, blacklisted); ins.Log(blacklisted).Log(" blacklisted - "); if (!File.Exists(blacklistedPath)) { ins.LogLine("Not found though."); continue; } ins.LogLine("BURN THE WITCH!"); File.Delete(blacklistedPath); } ins.LogLine(); } LogPath = Path.Combine(ins.ExeMod.Dir.FullName, "FEZModInstallLog.txt"); if (File.Exists(LogPath)) { File.Delete(LogPath); } ins.LogLine(); ins.LogLine("Now comes the real \"modding\" / patching process."); ins.LogLine("It may seem like the Installer may be stuck sometimes. Go make"); ins.LogLine("yourself a coffee in the meantime - it doesn't get stuck."); ins.LogLine("It may *crash*, though - and in this case, debug stuff appears"); ins.LogLine("here. Please put that debug stuff onto http://hastebin.com/ and"); ins.LogLine("send it to @0x0ade on Twitter or FEZMod on GitHub."); ins.LogLine(); ins.LogLine("Modding Common.dll").InitProgress("Modding Common.dll", 5); ins.LogLine("Common.dll is not that huge - not much to say here."); ins.LogLine(); if (!ins.Mod("Common.dll")) { return; } ins.LogLine("Modding EasyStorage.dll").SetProgress("Modding EasyStorage.dll", 1); ins.LogLine("EasyStorage.dll also isn't huge - most probably Steam and Android stuff."); ins.LogLine(); if (!ins.Mod("EasyStorage.dll")) { return; } if (12 <= v) { ins.LogLine("Modding FNA.dll").SetProgress("Modding FNA.dll", 2); ins.LogLine("Future versions may replace \"modding\" with replacing."); ins.LogLine("FNA is the \"framework\" below FEZ and powering some other games, too."); ins.LogLine("It replaces MonoGame in FEZ 1.12+."); ins.LogLine(); if (!ins.Mod("FNA.dll")) { return; } } else { ins.LogLine("Modding MonoGame.Framework.dll").SetProgress("Modding MonoGame.Framework.dll", 2); ins.LogLine("Wait... where's FNA? Well, I guess you're using old FEZ."); ins.LogLine(); if (!ins.Mod("MonoGame.Framework.dll")) { return; } } ins.LogLine("Modding FezEngine.dll").SetProgress("Modding FezEngine.dll", 3); ins.LogLine("The Trixel Engine also becomes the \"FEZMod Engine.\""); ins.LogLine("If something low-level happens, for example loading textures,"); ins.LogLine("music, handling geometry, inter-mod-communication,... it's here."); ins.LogLine(); if (!ins.Mod("FezEngine.dll")) { return; } ins.LogLine("Modding FEZ.exe").SetProgress("Modding FEZ.exe", 4); ins.LogLine("This process will take the longest of all."); ins.LogLine("You won't see anything happening here, but don't panic:"); ins.LogLine("If the installer crashes, an error log appears here."); ins.LogLine(); if (!ins.Mod()) { return; } ins.EndProgress("Modding complete."); ins.LogLine("Back with the coffee? We're done! Look at the top-right!"); ins.LogLine("You should see [just installed]. Feel free to start FEZ."); ins.LogLine("If FEZ crashes with FEZMod, go to the FEZ folder (that one"); ins.LogLine("where FEZ.exe is, basically the path at the top-right),"); ins.LogLine("upload JAFM Log.txt somewhere and give it @0x0ade."); ins.LogLine("Good luck - Have fun!"); ins.ExeSelected(ins.ExeMod.In.FullName, " [just installed]"); ins.SetMainEnabled(true); }