Exemple #1
0
        private void writeGameMenu()
        {
            string path = modPath + "\\resource\\gamemenu.res";

            SourceSDK.KeyValue gameMenu = new SourceSDK.KeyValue("gamemenu");

            for (int i = 0; i < actions.Count; i++)
            {
                MenuAction         action   = actions[i];
                SourceSDK.KeyValue actionKV = new SourceSDK.KeyValue(i.ToString());
                actionKV.addChild(new SourceSDK.KeyValue("label", action.label));
                actionKV.addChild(new SourceSDK.KeyValue("command", action.command));
                actionKV.addChild(new SourceSDK.KeyValue("ingameorder", i.ToString()));
                if (action.inGame)
                {
                    actionKV.addChild(new SourceSDK.KeyValue("onlyingame", "1"));
                }
                if (action.onlySingle)
                {
                    actionKV.addChild(new SourceSDK.KeyValue("nomulti", "1"));
                }
                if (action.onlyMulti)
                {
                    actionKV.addChild(new SourceSDK.KeyValue("nosingle", "1"));
                }

                gameMenu.addChild(actionKV);
            }

            SourceSDK.KeyValue.writeChunkFile(path, gameMenu, true, new UTF8Encoding(false));
        }
        public void LoadSteamLibraries()
        {
            String steamPath = Launcher.GetInstallPath();

            steamLibs = new List <string>();
            if (Directory.Exists(steamPath))
            {
                steamLibs.Add(steamPath);

                if (File.Exists(steamPath + "\\steamapps\\libraryfolders.vdf"))
                {
                    SourceSDK.KeyValue root = SourceSDK.KeyValue
                                              .readChunkfile(steamPath + "\\steamapps\\libraryfolders.vdf");

                    foreach (SourceSDK.KeyValue child in root.getChildren())
                    {
                        string dir = child.getValue().Replace("\\\\", "\\");
                        if (Directory.Exists(dir))
                        {
                            steamLibs.Add(dir);
                        }
                    }
                }
                else
                {
                    XtraMessageBox.Show("Could not find file \"" + steamPath + "\\steamapps\\libraryfolders.vdf\".");
                }
            }
            else
            {
                //XtraMessageBox.Show("Could not find Steam install directory.");
            }
        }
Exemple #3
0
        private void readGameMenu()
        {
            string path = modPath + "\\resource\\gamemenu.res";

            Directory.CreateDirectory(Path.GetDirectoryName(path));

            if (!File.Exists(path))
            {
                MessageBox.Show("File does not exist. Creating new one");
                createGameMenu();
            }

            SourceSDK.KeyValue gameMenu = SourceSDK.KeyValue.readChunkfile(path);
            actions.Clear();
            foreach (SourceSDK.KeyValue actionKv in gameMenu.getChildren())
            {
                string label      = actionKv.getValue("label");
                string command    = actionKv.getValue("command");
                bool   inGame     = (actionKv.getValue("onlyingame") == "1");
                bool   onlySingle = (actionKv.getValue("nomulti") == "1");
                bool   onlyMulti  = (actionKv.getValue("nosingle") == "1");

                MenuAction action = new MenuAction(label, command)
                {
                    inGame = inGame, onlySingle = onlySingle, onlyMulti = onlyMulti
                };
                actions.Add(action);
            }
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            string modPath = launcher.GetCurrentMod().installPath;

            Game game  = launcher.GetGamesList()[comboGames.EditValue.ToString()];
            int  appID = game.GetAppId();

            gameinfo.getChildByKey("filesystem").setValue("steamappid", appID.ToString());

            searchPaths.Add(new string[] { "platform", "|all_source_engine_paths|platform/platform_misc.vpk" });
            searchPaths.Add(new string[] { "platform", "|all_source_engine_paths|platform" });

            SourceSDK.KeyValue searchPathsKV = gameinfo.getChildByKey("filesystem").getChildByKey("searchpaths");
            searchPathsKV.clearChildren();
            foreach (String[] searchPath in searchPaths)
            {
                searchPathsKV.addChild(new SourceSDK.KeyValue(searchPath[0], searchPath[1]));
            }

            string path = modPath + "\\gameinfo.txt";

            SourceSDK.KeyValue.writeChunkFile(path, gameinfo, false, new UTF8Encoding(false));

            Close();
        }
        public void SaveUserLibraries()
        {
            string userPath = AppDomain.CurrentDomain.BaseDirectory + "/libraryfolders.vdf";

            SourceSDK.KeyValue root = new SourceSDK.KeyValue("LibraryFolders");

            for (int i = 0; i < userLibs.Count; i++)
            {
                root.addChild(new SourceSDK.KeyValue(i.ToString(), userLibs[i]));
            }

            SourceSDK.KeyValue.writeChunkFile(userPath, root);
        }
Exemple #6
0
        private void readChapterBackgrounds()
        {
            string modFolder = new DirectoryInfo(modPath).Name;
            string filePath  = modPath + "\\scripts\\chapterbackgrounds.txt";

            if (File.Exists(filePath))
            {
                SourceSDK.KeyValue chapters = SourceSDK.KeyValue.readChunkfile(filePath);
                for (int i = 0; i < this.chapters.Count; i++)
                {
                    string background = chapters.getValue((i + 1).ToString());
                    this.chapters[i].background = background;
                }
            }
        }
        public void LoadUserLibraries()
        {
            userLibs = new List <string>();
            string userPath = AppDomain.CurrentDomain.BaseDirectory + "/libraryfolders.vdf";

            if (File.Exists(userPath))
            {
                SourceSDK.KeyValue root = SourceSDK.KeyValue.readChunkfile(userPath);

                foreach (SourceSDK.KeyValue child in root.getChildren())
                {
                    string dir = child.getValue().Replace("\\\\", "\\");
                    if (Directory.Exists(dir))
                    {
                        userLibs.Add(dir);
                    }
                }
            }
        }
Exemple #8
0
        private void readChapterTitles()
        {
            string modFolder = new DirectoryInfo(modPath).Name;
            string filePath  = modPath + "\\resource\\" + modFolder + "_english.txt";

            if (File.Exists(filePath))
            {
                lang = SourceSDK.KeyValue.readChunkfile(filePath);
                SourceSDK.KeyValue tokens = lang.getChildByKey("tokens");
                for (int i = 0; i < chapters.Count; i++)
                {
                    string title = tokens.getValue(modFolder + "_chapter" + (i + 1) + "_title");
                    chapters[i].title = title;
                }
            }
            else
            {
                createChapterTitles();
                readChapterTitles();
            }
        }
        public void SaveMaterial(string path, string shader)
        {
            SourceSDK.KeyValue vmt = new SourceSDK.KeyValue(shader);

            string relativePath = path;
            string fullPath     = (launcher.GetCurrentMod().installPath + "\\materials\\" + relativePath).Replace("/", "\\");

            Directory.CreateDirectory(fullPath.Substring(0, fullPath.LastIndexOf("\\")));

            bool hasNormalMap   = false;
            bool hasSpecularMap = false;

            foreach (KeyValuePair <string, Texture> texture in textures)
            {
                if (texture.Value.bitmap != null)
                {
                    switch (texture.Key)
                    {
                    case "tooltexture":
                        if (texture.Value.bytes == textures["basetexture"].bytes)
                        {
                            vmt.addChild(new KeyValue("$" + texture.Key, relativePath + "_basetexture"));
                        }
                        else
                        {
                            vmt.addChild(new KeyValue("$" + texture.Key, relativePath + "_" + texture.Key));
                            File.WriteAllBytes(fullPath + "_" + texture.Key + ".vtf", texture.Value.bytes);
                        }
                        break;

                    case "envmapmask":
                        hasSpecularMap = true;
                        break;

                    case "bumpmap":
                        hasNormalMap = true;
                        break;

                    default:
                        vmt.addChild(new KeyValue("$" + texture.Key, relativePath + "_" + texture.Key));
                        File.WriteAllBytes(fullPath + "_" + texture.Key + ".vtf", texture.Value.bytes);
                        break;
                    }
                }
            }

            if (hasNormalMap && hasSpecularMap)
            {
                Bitmap normalBitmap   = textures["bumpmap"].bitmap;
                Bitmap specularBitmap = new Bitmap(textures["envmapmask"].bitmap,
                                                   normalBitmap.Width,
                                                   normalBitmap.Height);

                for (int i = 0; i < normalBitmap.Width; i++)
                {
                    for (int j = 0; j < normalBitmap.Height; j++)
                    {
                        Color normalColor   = normalBitmap.GetPixel(i, j);
                        Color specularColor = specularBitmap.GetPixel(i, j);
                        normalBitmap.SetPixel(i,
                                              j,
                                              Color.FromArgb(specularColor.R,
                                                             normalColor.R,
                                                             normalColor.G,
                                                             normalColor.B));
                    }
                }
                textures["bumpmap"].bytes = VTF.FromBitmap(textures["bumpmap"].bitmap, launcher);
                vmt.addChild(new KeyValue("$bumpmap", relativePath + "_bumpmap"));
                vmt.addChild(new KeyValue("$normalmapalphaenvmapmask", "1"));
                vmt.addChild(new KeyValue("$envmap", "env_cubemap"));
                File.WriteAllBytes(fullPath + "_bumpmap.vtf", textures["bumpmap"].bytes);
            }
            else if (hasNormalMap)
            {
                vmt.addChild(new KeyValue("$bumpmap", relativePath + "_bumpmap"));
                File.WriteAllBytes(fullPath + "_bumpmap.vtf", textures["bumpmap"].bytes);
            }
            else if (hasSpecularMap)
            {
                vmt.addChild(new KeyValue("$envmap", "env_cubemap"));
                vmt.addChild(new KeyValue("$envmapmask", relativePath + "_envmapmask"));
                File.WriteAllBytes(fullPath + "_envmapmask.vtf", textures["envmapmask"].bytes);
            }

            if (detail != null)
            {
                vmt.addChild(new KeyValue("$detail", detail[0]));
                vmt.addChild(new KeyValue("$detailscale", detail[0]));
                vmt.addChild(new KeyValue("$detailblendfactor", detail[0]));
                vmt.addChild(new KeyValue("$detailblendmode", detail[0]));
            }

            vmt.addChild(new KeyValue("$surfaceprop", comboSurfaceProp.EditValue.ToString()));
            vmt.addChild(new KeyValue("$surfaceprop2", comboSurfaceProp2.EditValue.ToString()));

            SourceSDK.KeyValue.writeChunkFile(fullPath + ".vmt", vmt, false, new UTF8Encoding(false));
        }
        public void LoadMaterial(string fullPath)
        {
            SourceSDK.KeyValue vmt = null;
            if (File.Exists(fullPath))
            {
                vmt = SourceSDK.KeyValue.readChunkfile(fullPath);
            }

            string relativePath = GetRelativePath(launcher, fullPath);

            this.relativePath = relativePath.Substring("\\materials\\".Length);

            VPKManager vpkManager = null;

            if (vmt != null)
            {
                vpkManager = new VPKManager(launcher);
            }

            foreach (KeyValuePair <string, PictureEdit> kv in pictureEdits)
            {
                if (vmt != null)
                {
                    string value = vmt.getValue("$" + kv.Key);
                    if (value != null)
                    {
                        string texturePath = vpkManager.getExtractedPath("materials/" + value + ".vtf");
                        if (texturePath != "" && File.Exists(texturePath))
                        {
                            textures[kv.Key].relativePath = value;
                            textures[kv.Key].bytes        = File.ReadAllBytes(texturePath);
                            textures[kv.Key].bitmap       = VTF.ToBitmap(textures[kv.Key].bytes, launcher);
                            kv.Value.Image = textures[kv.Key].bitmap;
                        }
                        else
                        {
                            ClearTexture(kv.Value);
                        }
                    }
                }
                else
                {
                    ClearTexture(kv.Value);
                }
            }

            if (vmt != null && vmt.getValue("$normalmapalphaenvmapmask") == "1" && textures["bumpmap"].bitmap != null)
            {
                textures["envmapmask"].bitmap = new Bitmap(textures["bumpmap"].bitmap.Width, textures["bumpmap"].bitmap.Height);
                for (int i = 0; i < textures["bumpmap"].bitmap.Width; i++)
                {
                    for (int j = 0; j < textures["bumpmap"].bitmap.Height; j++)
                    {
                        int alpha = textures["bumpmap"].bitmap.GetPixel(i, j).A;
                        textures["envmapmask"].bitmap.SetPixel(i, j, Color.FromArgb(alpha, alpha, alpha));
                    }
                }
                textures["envmapmask"].bytes        = VTF.FromBitmap(textures["envmapmask"].bitmap, launcher);
                textures["envmapmask"].relativePath = "";
                pictureEnvMapMask.Image             = textures["envmapmask"].bitmap;
            }
        }
Exemple #11
0
        public List <string> GetMountedPaths()
        {
            List <string> result = new List <string>();

            string gamePath = game.installPath;
            string modPath  = installPath;

            SourceSDK.KeyValue gameInfo    = null;
            SourceSDK.KeyValue searchPaths = null;
            switch (game.engine)
            {
            case Engine.SOURCE:
                gameInfo    = SourceSDK.KeyValue.readChunkfile(modPath + "\\gameinfo.txt");
                searchPaths = gameInfo.findChildByKey("searchpaths");
                break;

            case Engine.SOURCE2:
                gameInfo    = SourceSDK.KeyValue.readChunkfile(modPath + "\\gameinfo.gi");
                searchPaths = gameInfo.findChildByKey("searchpaths");
                break;

            case Engine.GOLDSRC:
                searchPaths = new SourceSDK.KeyValue("searchpaths");
                searchPaths.addChild(new SourceSDK.KeyValue("game", new DirectoryInfo(installPath).Name));
                searchPaths.addChild(new SourceSDK.KeyValue("game", "valve"));
                break;
            }

            foreach (SourceSDK.KeyValue searchPath in searchPaths.getChildren())
            {
                string[] keys = searchPath.getKey().Split('+');

                if (!keys.Contains("game"))
                {
                    continue;
                }

                string value = searchPath.getValue();

                switch (game.engine)
                {
                case Engine.SOURCE:
                    value = value.Replace("/", "\\");
                    if (value.Contains("|all_source_engine_paths|"))
                    {
                        value = value.Replace("|all_source_engine_paths|", gamePath + "\\");
                    }
                    else if (value.Contains("|gameinfo_path|"))
                    {
                        value = value.Replace("|gameinfo_path|", modPath + "\\");
                    }
                    else if (!Directory.Exists(value))
                    {
                        value = gamePath + "\\" + value;
                    }
                    value = value.Replace("\\\\", "\\");
                    if (value.EndsWith("/"))
                    {
                        value = value.Substring(0, value.Length - 1);
                    }

                    break;

                case Engine.SOURCE2:
                    value = gamePath + "\\game\\" + value;
                    // We can't mount the vpks because we have no vpk.exe

                    /*foreach(string file in Directory.GetFiles(value, "*.vpk", SearchOption.AllDirectories))
                     * {
                     *  string fileName = Path.GetFileNameWithoutExtension(file);
                     *  if (int.TryParse(fileName.Substring(fileName.Length - 3), out _))
                     *      continue;
                     *
                     *      result.Add(file.Replace("_dir.vpk", ".vpk"));
                     * }*/
                    break;

                case Engine.GOLDSRC:
                    value = gamePath + "\\" + value;
                    break;
                }

                result.Add(value);
            }



            return(result.Distinct().ToList());
        }
        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();
        }
Exemple #13
0
        /// <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);
        }