void wrongVersion(string name, string version, string settings, PolyTechMod currMod) { ptfInstance.ptfLogger.LogWarning("Mod in layout present, but not the correct version."); PopUpMessage.Display( $"Mod ({name}) in layout present, but not the correct version. (Made with {version}, Currently has {cheatMods.Where(p => p.Info.Metadata.Name == name).First().Info.Metadata.Version.ToString()})", () => checkMods(2, name, version, settings, currMod) ); }
void missingMod(string name, string version, string settings, PolyTechMod currMod) { ptfInstance.ptfLogger.LogWarning("Mod in layout not present."); PopUpMessage.Display( $"Mod ({name}) in layout not present.", () => {} ); }
public static void checkForModUpdate(PolyTechMod plugin) { if (plugin.repositoryUrl == null) { return; } var client = new WebClient(); client.Headers.Add("User-Agent", "Nothing"); // get latest release version string repoReleaseUri = "https://api.github.com/repos" + new Uri(plugin.repositoryUrl).AbsolutePath + "releases"; string content; try { content = client.DownloadString(repoReleaseUri); } catch (Exception e) { ptfInstance.ptfLogger.LogError(e.Message); return; } // deserialize incoming JSON from repo api List <Release> releases = null; using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(content))) { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(List <Release>)); releases = (List <Release>)jsonSerializer.ReadObject(ms); } if (releases == null) { return; } if (releases.Count <= 0) { return; } Release latestRelease = releases[0]; if (latestRelease.GetVersion().CompareTo(plugin.Info.Metadata.Version) > 0) { ModUpdate modUpdate = new ModUpdate(plugin, latestRelease); if (patchGameStart.game_started) { modUpdatePopup(modUpdate); } else { patchGameStart.modUpdates.Add(modUpdate); } } }
public void onCheatsChanged(object sender, ListChangedEventArgs e) { if (e.ListChangedType == ListChangedType.ItemDeleted) { return; } PolyTechMod mod = cheatMods[cheatMods.Count - 1]; string nameAndVers = $"{mod.Info.Metadata.Name} v{mod.Info.Metadata.Version}"; Logger.LogInfo("Registered cheat mod: " + nameAndVers); }
public static void registerMod(PolyTechMod plugin) { if (plugin.isCheat) { cheatMods.Add(plugin); } else { noncheatMods.Add(plugin); } checkForModUpdate(plugin); }
void wrongSettings(string name, string version, string settings, PolyTechMod currMod) { ptfInstance.ptfLogger.LogWarning("Mod in layout but settings are not correct."); PopUpTwoChoices.Display( $"Mod ({name}) but settings are not correct.", "Fix Settings Automatically", "Ignore Warning", () => { currMod.setSettings(settings); }, () => { ptfInstance.ptfLogger.LogWarning("Ignored the mod being disabled"); } ); }
public static void setCheat(PolyTechMod plugin, bool isCheat) { if (plugin.isCheat == isCheat) { return; } if (isCheat) { noncheatMods.Remove(plugin); cheatMods.Add(plugin); } else { cheatMods.Remove(plugin); noncheatMods.Add(plugin); } plugin.isCheat = isCheat; }
void notEnabled(string name, string version, string settings, PolyTechMod currMod) { ptfInstance.ptfLogger.LogWarning("Mod in layout present but not enabled."); PopUpTwoChoices.Display( $"Mod ({name}) in layout present but not enabled.", "Enable Mod", "Ignore Warning", () => { currMod.enableMod(); checkMods(3, name, version, settings, currMod); }, () => { ptfInstance.ptfLogger.LogWarning("Ignored the mod being disabled"); checkMods(3, name, version, settings, currMod); } ); }
void checkMods(int step, string name, string version, string settings, PolyTechMod currMod) { if (currMod == null || (step <= 0 && currMod.Info.Metadata.Name != name)) { missingMod(name, version, settings, currMod); } else if (step <= 1 && currMod.Info.Metadata.Version.ToString() != version) { wrongVersion(name, version, settings, currMod); } else if (step <= 2 && !currMod.isEnabled) { notEnabled(name, version, settings, currMod); } else if (step <= 3 && currMod.getSettings() != settings) { wrongSettings(name, version, settings, currMod); } }
public ModUpdate(PolyTechMod mod, Release latest_release) { this.mod = mod; this.latest_release = latest_release; }