예제 #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));
        }
예제 #2
0
        /// <summary>
        /// Creates a particles_manifest.txt with the particles included in the base game plus the ones found in the particles folder.
        /// </summary>
        /// <param name="launcher">An instance of the Source SDK lib</param>
        public static void CreateManifest(Launcher launcher)
        {
            if (launcher == null)
            {
                return;
            }

            VPKManager vpkManager = new VPKManager(launcher);

            vpkManager.extractFile("particles/particles_manifest.txt");

            string modPath = launcher.GetCurrentMod().installPath;

            KeyValue manifest = KeyValue.readChunkfile(launcher.GetCurrentMod().installPath + "\\particles\\particles_manifest.txt");

            foreach (string file in Directory.GetFiles(launcher.GetCurrentMod().installPath + "\\particles",
                                                       "*.pcf",
                                                       SearchOption.AllDirectories))
            {
                Uri path1 = new Uri(modPath + "\\");
                Uri path2 = new Uri(file);
                Uri diff  = path1.MakeRelativeUri(path2);

                manifest.addChild(new KeyValue("file", diff.OriginalString));
            }
            KeyValue.writeChunkFile(launcher.GetCurrentMod().installPath + "\\particles\\particles_manifest.txt", manifest);
        }
        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);
        }
예제 #5
0
        public static KeyValue readChunkfile(String path)
        {
            // Parse Valve chunkfile format
            KeyValue list = new KeyValue("root");

            if (File.Exists(path))
            {
                //try
                //{
                using (StreamReader r = new StreamReader(path))
                {
                    while (r.Peek() >= 0)
                    {
                        String line = r.ReadLine();
                        line = line.Trim();
                        line = Regex.Replace(line, @"\s+", " ");

                        // Ignore the commented part of the line
                        if (line.StartsWith("//"))
                        {
                            continue;
                        }

                        string[] words = splitByWords(line);

                        if (words.Length >= 1)
                        {
                            string   key   = words[0].Replace("\"", string.Empty).ToLower();
                            KeyValue value = new KeyValue(key, words[1]);
                            list.addChild(value);
                        }
                    }
                }
                //}
                //catch (Exception e)
                //{
                // Debugger.Break();
                //  XtraMessageBox.Show("Could not read file \"" + path + "\". It's structure is broken.");
                // return null;
                //}
            }
            else
            {
                XtraMessageBox.Show("Could not find file \"" + path + "\" to read.");
                return(null);
            }

            return(list);
        }
예제 #6
0
        public static KeyValue readChunkfile(String path, bool hasOSInfo)
        {
            // Parse Valve chunkfile format
            KeyValue        root = null;
            List <KeyValue> list = new List <KeyValue>();
            Stack <KeyValuePair <string, KeyValue> > stack = new Stack <KeyValuePair <string, KeyValue> >();

            if (File.Exists(path))
            {
                try
                {
                    using (StreamReader r = new StreamReader(path))
                    {
                        while (r.Peek() >= 0)
                        {
                            String line = r.ReadLine();
                            line = line.Trim();
                            line = Regex.Replace(line, @"\s+", " ");

                            string[] words = splitByWords(line);

                            if (line.StartsWith("//"))  // It's a standalone comment line
                            {
                                KeyValue comment = new KeyValue("");
                                comment.comment = line.Substring(2);
                                stack.Peek().Value.addChild(comment);
                            }
                            else if (words.Length == 0)     // It's a blank line
                            {
                                KeyValue blank = new KeyValue("");
                                stack.Peek().Value.addChild(blank);
                            }
                            else if (words.Length > 0 && words[0].Contains("{"))   // It opens a group
                            {
                                // We actually don't need to do anything.
                            }
                            else if (words.Length > 0 && words[0].Contains("}"))    // It closes a group
                            {
                                KeyValuePair <string, KeyValue> child = stack.Pop();
                                if (stack.Count > 0)
                                {
                                    stack.Peek().Value.addChild(child.Key, child.Value);
                                }
                                else
                                {
                                    list.Add(child.Value);
                                }
                                //root = child.Value;
                            }
                            else if (words.Length == 1 || words.Length > 1 && words[1].StartsWith("//"))    // It's a parent key
                            {
                                line = line.Replace("\"", string.Empty).ToLower();
                                KeyValue parent = new KeyValue(line);
                                stack.Push(new KeyValuePair <string, KeyValue>(line, new KeyValue(line)));
                            }
                            else if (words.Length >= 2)
                            {
                                // Workaround: Valve decided to use spaces in some .res files to identify the OS the key is used by.
                                // So, this code will result in a false positive. Right now, the only example I have is of this kind:
                                // HudHealth [$WIN32]
                                // So, the workaround will be if the second word starts and ends with brackets
                                if (hasOSInfo && words[1].StartsWith("[") && words[1].EndsWith("]")) // It's a parent key with a target OS
                                {
                                    line = line.Replace("\"", string.Empty);
                                    KeyValue parent = new KeyValue(line);
                                    stack.Push(new KeyValuePair <string, KeyValue>(line, new KeyValue(line)));
                                }
                                else // It's a value key
                                {
                                    string   key   = words[0].Replace("\"", string.Empty).ToLower();
                                    KeyValue value = new KeyValue(key, words[1]);
                                    stack.Peek().Value.addChild(key, value);
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    XtraMessageBox.Show("Could not read file \"" + path + "\". It's structure is broken.");
                    return(null);
                }
            }
            else
            {
                XtraMessageBox.Show("Could not find file \"" + path + "\" to read.");
                return(null);
            }

            if (list.Count > 1)
            {
                root = new KeyValue(string.Empty);
                foreach (KeyValue keyValue in list)
                {
                    root.addChild(keyValue);
                }

                return(root);
            }
            else
            {
                return(list[0]);
            }
        }
        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));
        }
예제 #8
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();
        }