private void createButton_Click(object sender, EventArgs e) { modFolder = textFolder.EditValue.ToString(); Game game = launcher.GetGamesList()[gameName]; string appId = game.GetAppId().ToString(); string mod = modFolder + " (" + modFolder + ")"; string gamePath = game.installPath; string modPath = baseModPath + modFolder; // Copy the mod template string templatePath = AppDomain.CurrentDomain.BaseDirectory + "Templates\\" + game.name + "\\" + gameBranch + "\\"; foreach (string file in Directory.GetFiles(templatePath, "*", SearchOption.AllDirectories)) { string destinationPath = modPath + "\\" + file.Replace(templatePath, string.Empty); string destinationDirectory = new FileInfo(destinationPath).Directory.FullName; Directory.CreateDirectory(destinationDirectory); File.Copy(file, destinationPath); } switch (engine) { case Engine.SOURCE: { File.Move(modPath + "\\resource\\template_english.txt", modPath + "\\resource\\" + modFolder + "_english.txt"); SourceSDK.KeyValue gameInfo = SourceSDK.KeyValue.readChunkfile(modPath + "\\gameinfo.txt"); gameInfo.setValue("game", modFolder); gameInfo.setValue("title", modFolder); SourceSDK.KeyValue.writeChunkFile(modPath + "\\gameinfo.txt", gameInfo, false, new UTF8Encoding(false)); } break; case Engine.SOURCE2: { SourceSDK.KeyValue gameInfo = SourceSDK.KeyValue.readChunkfile(modPath + "\\gameinfo.gi"); gameInfo.setValue("game", modFolder); gameInfo.setValue("title", modFolder); SourceSDK.KeyValue searchPaths = gameInfo.getChildByKey("filesystem").getChildByKey("searchpaths"); searchPaths.clearChildren(); searchPaths.addChild("game", modFolder); searchPaths.addChild("game", "hlvr"); searchPaths.addChild("game", "core"); searchPaths.addChild("mod", modFolder); searchPaths.addChild("write", modFolder); SourceSDK.KeyValue.writeChunkFile(modPath + "\\gameinfo.gi", gameInfo, false, new UTF8Encoding(false)); } break; case Engine.GOLDSRC: { SourceSDK.KeyValue gameInfo = SourceSDK.Config.readChunkfile(modPath + "\\liblist.gam"); gameInfo.setValue("game", modFolder); SourceSDK.Config.writeChunkFile(modPath + "\\liblist.gam", gameInfo, false, new UTF8Encoding(false)); } break; } DialogResult = DialogResult.OK; Close(); }
/// <summary> /// Loads all the mods with the same game app id of the specified game /// </summary> /// <param name="game">The base game name (i.e. Source SDK Base 2013 Singleplayer)</param> /// <returns></returns> public Dictionary <string, Mod> LoadMods(Launcher launcher) { mods = new Dictionary <string, Mod>(); int gameAppId = GetAppId(); string gamePath = installPath; if ((gameAppId == -1 && engine != Engine.GOLDSRC) || gamePath == null) { return(mods); } List <string> paths = new List <string>(); switch (engine) { case Engine.SOURCE: paths.AddRange(GetAllModPaths(launcher)); foreach (string path in GetAllBaseGameinfoFolders()) { paths.Add(gamePath + "\\" + path); } break; case Engine.SOURCE2: foreach (string path in GetAllBaseGameinfoFolders()) { paths.Add(gamePath + "\\game\\" + path); } break; case Engine.GOLDSRC: foreach (string path in GetAllBaseGameinfoFolders()) { paths.Add(gamePath + "\\" + path); } break; } foreach (string path in paths) { switch (engine) { case Engine.SOURCE: { SourceSDK.KeyValue gameInfo = SourceSDK.KeyValue.readChunkfile(path + "\\gameinfo.txt"); if (gameInfo != null) { string name = gameInfo.getChildByKey("game").getValue() + " (" + new DirectoryInfo(path).Name + ")"; string modAppId = gameInfo.getChildByKey("filesystem").getChildByKey("steamappid").getValue(); if (int.Parse(modAppId) == gameAppId || path.Contains(gamePath) && !(mods.Values.Where(p => p.installPath == path).ToList().Count == 0)) { bool containsMod = false; string newModPath = new FileInfo(path).Name; foreach (Mod mod in mods.Values) { if (new FileInfo(mod.installPath).Name == newModPath) { containsMod = true; break; } } if (!containsMod) { while (mods.Keys.Contains(name)) { name = name + "_"; } mods.Add(name, new Mod(this, name, path)); } } } else { XtraMessageBox.Show("Could not load mod " + path + ". It's gameinfo.txt is broken."); } } break; case Engine.SOURCE2: { SourceSDK.KeyValue gameInfo = SourceSDK.KeyValue.readChunkfile(path + "\\gameinfo.gi"); if (gameInfo != null) { string name = gameInfo.getChildByKey("game").getValue() + " (" + new DirectoryInfo(path).Name + ")"; //string modAppId = gameInfo.getChildByKey("filesystem").getChildByKey("steamappid").getValue(); if (path.Contains(gamePath) && (mods.Values.Where(p => p.installPath == path).ToList().Count == 0)) { bool containsMod = false; string newModPath = new FileInfo(path).Name; foreach (Mod mod in mods.Values) { if (new FileInfo(mod.installPath).Name == newModPath) { containsMod = true; break; } } if (!containsMod) { while (mods.Keys.Contains(name)) { name = name + "_"; } mods.Add(name, new Mod(this, name, path)); } } } else { XtraMessageBox.Show("Could not load mod " + path + ". It's gameinfo.gi is broken."); } } break; case Engine.GOLDSRC: { SourceSDK.KeyValue gameInfo = SourceSDK.Config.readChunkfile(path + "\\liblist.gam"); if (gameInfo != null) { string name = gameInfo.getChildByKey("game").getValue() + " (" + new DirectoryInfo(path).Name + ")"; //string modAppId = gameInfo.getChildByKey("filesystem").getChildByKey("steamappid").getValue(); if (path.Contains(gamePath)) { bool containsMod = false; string newModPath = new FileInfo(path).Name; foreach (Mod mod in mods.Values) { if (new FileInfo(mod.installPath).Name == newModPath) { containsMod = true; break; } } if (!containsMod) { while (mods.Keys.Contains(name)) { name = name + "_"; } mods.Add(name, new Mod(this, name, path)); } } } else { XtraMessageBox.Show("Could not load mod " + path + ". It's liblist.gam is broken."); } } break; } } return(mods); }