Beispiel #1
0
        public string getValue(string key)
        {
            KeyValue child = getChildByKey(key);

            if (child != null)
            {
                return(child.getValue());
            }

            return(string.Empty);
        }
Beispiel #2
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;
                }
            }
        }
Beispiel #3
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();
            }
        }
Beispiel #4
0
        private static List <string> writeChunkFileTraverse(KeyValue node, int level, bool quotes)
        {
            List <string> lines = new List <string>();

            string tabs = string.Empty;

            for (int i = 0; i < level; i++)
            {
                tabs = tabs + "\t";
            }

            if (node.isParentKey()) // It's a parent key
            {
                if (node.key != string.Empty)
                {
                    lines.Add(tabs + (quotes ? "\"" : string.Empty) + node.key + (quotes ? "\"" : string.Empty));
                    lines.Add(tabs + "{");
                }

                foreach (KeyValue entry in node.getChildren())
                {
                    lines.AddRange(writeChunkFileTraverse(entry, level + 1, quotes));
                }

                if (node.key != string.Empty)
                {
                    lines.Add(tabs + "}");
                }
            }
            else if (node.getKey() != string.Empty && node.getValue() != null)   // It's a value key
            {
                string line = tabs;
                if (node.key != string.Empty)
                {
                    line = line +
                           (quotes ? "\"" : string.Empty) +
                           node.key +
                           (quotes ? "\"" : string.Empty) +
                           "\t\"" +
                           node.value +
                           "\"";
                }
                if (node.comment != string.Empty)
                {
                    if (node.key != string.Empty)
                    {
                        line = line + "\t";
                    }

                    line = line + "//" + node.comment;
                }

                lines.Add(line);
            }
            else if (node.comment != string.Empty)   // Comment line
            {
                string line = tabs + "//" + node.comment;
                lines.Add(line);
            }
            else if (node.key == string.Empty)      // Blank line
            {
                lines.Add("");
            }

            return(lines);
        }
        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;
            }
        }