hlPackageGetRoot() public static method

public static hlPackageGetRoot ( ) : IntPtr
return IntPtr
Ejemplo n.º 1
0
        public static void ReadScriptFromVPK <T>(string filePath, List <T> ListToInsert) where T : DotaDataObject
        {
            IntPtr root = HLLib.hlPackageGetRoot();

            IntPtr file = HLLib.hlFolderGetItemByPath(root, filePath, HLLib.HLFindType.HL_FIND_FILES);

            IntPtr stream;

            ErrorCheck(HLLib.hlPackageCreateStream(file, out stream));

            string unitsText = ReadTextFromHLLibStream(stream);

            KeyValue rootkv = KVLib.KVParser.KV1.Parse(unitsText);

            foreach (KeyValue kv in rootkv.Children)
            {
                if (!kv.HasChildren)
                {
                    continue;                  //Get rid of that pesky "Version" "1" key
                }
                T unit = typeof(T).GetConstructor(new Type[] { typeof(KeyValue) }).Invoke(new object[] { kv }) as T;

                unit.ObjectInfo.FromVPK         = true;
                unit.ObjectInfo.ObjectClass     = DotaDataObject.DataObjectInfo.ObjectDataClass.Default;
                unit.ObjectInfo.OriginatingFile = filePath;

                ListToInsert.Add(unit);
            }
            return;
        }
Ejemplo n.º 2
0
        protected void PopulateFromVPK()
        {
            TreeNode rootNode = treeView1.Nodes["vpk"];

            rootNode.Tag  = "/";
            rootNode.Text = "Dota 2 VPK";
            rootNode.Nodes.Clear();
            IntPtr rootptr = HLLib.hlPackageGetRoot();

            RecursivePopulateFromVPK(ref rootNode, rootptr);

            rootNode.Expand();
        }
Ejemplo n.º 3
0
        public static string ReadAllText(string filePath)
        {
            IntPtr root = HLLib.hlPackageGetRoot();

            IntPtr file = HLLib.hlFolderGetItemByPath(root, filePath, HLLib.HLFindType.HL_FIND_FILES);

            IntPtr stream;

            ErrorCheck(HLLib.hlPackageCreateStream(file, out stream));

            string text = ReadTextFromHLLibStream(stream);

            return(text);
        }
Ejemplo n.º 4
0
        public ProjectFolder BuildDotaVPKNode()
        {
            ProjectFolder folder = (new DomNode(DotaObjectsSchema.FolderType.Type)).As <ProjectFolder>();

            folder.Name  = "root";
            folder.Path  = "root";
            folder.InGCF = true;

            IntPtr root = HLLib.hlPackageGetRoot();

            RecursiveBuildFromVPK(ref folder, root);

            folder.As <DomNode>().InitializeExtensions();

            return(folder);
        }
Ejemplo n.º 5
0
        public PackageSystem(List <string> packages)
        {
            _rootNode = new PackageNode()
            {
                Name = "root", Directory = true
            };

            HLLib.hlInitialize();

            foreach (var package in packages)
            {
                if (Directory.Exists(package))
                {
                    FindDirFiles(package, _rootNode);
                    continue;
                }

                HLLib.HLPackageType type = HLLib.hlGetPackageTypeFromName(package);

                uint packagePointer;
                if (!HLLib.hlCreatePackage(type, out packagePointer))
                {
                    throw new Exception("Can't load package: " + HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
                }

                HLLib.hlBindPackage(packagePointer);

                if (!HLLib.hlPackageOpenFile(package, (uint)HLLib.HLFileMode.HL_MODE_READ))
                {
                    throw new Exception("Can't load package: " + HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
                }

                _rootNode.FileSize = 0;
                var rootItems = HLLib.hlFolderGetCount(HLLib.hlPackageGetRoot());
                for (uint i = 0; i < rootItems; i++)
                {
                    var  item = HLLib.hlFolderGetItem(HLLib.hlPackageGetRoot(), i);
                    uint size;
                    HLLib.hlItemGetSize(item, out size);
                    _rootNode.FileSize += size;
                }
                FindFiles(HLLib.hlPackageGetRoot(), _rootNode, packagePointer);

                //HLLib.hlPackageClose();
            }
        }
Ejemplo n.º 6
0
        public string ReadTextFromVPK(string path)
        {
            IntPtr root = HLLib.hlPackageGetRoot();

            IntPtr file = HLLib.hlFolderGetItemByPath(root, path, HLLib.HLFindType.HL_FIND_FILES);

            IntPtr stream;

            if (ErrorCheck(HLLib.hlPackageCreateStream(file, out stream)))
            {
                return("Unable to Load File".Localize());
            }

            string text = ReadTextFromHLLibStream(stream);

            return(text);
        }
Ejemplo n.º 7
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (radioGcf.Checked) //Extract from gcf
            {
                Cursor = Cursors.WaitCursor;
                Settings.Default.OpenFileSetting = 0;
                HLLib.hlInitialize();
                HLLib.HLPackageType ePackageType = HLLib.HLPackageType.HL_PACKAGE_GCF;
                uint uiMode = (uint)HLLib.HLFileMode.HL_MODE_READ | (uint)HLLib.HLFileMode.HL_MODE_VOLATILE;
                uint uiPackage;
                HLLib.hlCreatePackage(ePackageType, out uiPackage);
                HLLib.hlBindPackage(uiPackage);
                if (String.IsNullOrEmpty(Settings.Default.SteamFolder))
                {
showDia:
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        if (!File.Exists(folderBrowserDialog1.SelectedPath + @"\team fortress 2 content.gcf"))
                        {
                            Cursor = Cursors.Arrow;
                            var res = MessageBox.Show(
                                "team fortress 2 content.gcf could not be found in that folder!\r\nPlease select your SteamApps folder!",
                                "TF2 Items Editor",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Error);
                            if (res == DialogResult.OK)
                            {
                                goto showDia;
                            }
                            return;
                        }
                        Settings.Default.SteamFolder = folderBrowserDialog1.SelectedPath;
                        Settings.Default.Save();
                    }
                    else
                    {
                        return;
                    }
                }
                Cursor = Cursors.WaitCursor;
                string[] dirs = Directory.GetDirectories(Settings.Default.SteamFolder);
                if (string.IsNullOrEmpty(Settings.Default.SteamUser))
                {
                    var match = new List <string>();
                    foreach (string _dir in dirs)
                    {
                        string dir = (new DirectoryInfo(_dir)).Name;
                        if (dir != "common" && dir != "media" && dir != "SourceMods")
                        {
                            match.Add(dir);
                        }
                    }
                    if (match.Count > 1)
                    {
                        using (var win = new SteamFolderSelectWindow())
                        {
                            string ret = win.ShowWindow(match);
                            if (ret == "")
                            {
                                return;
                            }
                            Settings.Default.SteamUser = ret;
                            Settings.Default.Save();
                        }
                    }
                    else if (match.Count == 1)
                    {
                        Settings.Default.SteamUser = match[0];
                        Settings.Default.Save();
                    }
                    else
                    {
                        Cursor = Cursors.Arrow;
                        MessageBox.Show("No user folders found in steamapps!",
                                        "TF2 Items Editor",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                }
                Cursor = Cursors.WaitCursor;
                string p = Settings.Default.SteamFolder + @"\team fortress 2 content.gcf";
                HLLib.hlPackageOpenFile(p, uiMode);
                IntPtr pRoot = HLLib.hlPackageGetRoot();
                IntPtr pItem = HLLib.hlFolderGetItemByPath(pRoot, filePath + file, HLLib.HLFindType.HL_FIND_ALL);
                p = Settings.Default.SteamFolder + @"\" + Settings.Default.SteamUser +
                    @"\team fortress 2" + filePath;
                Directory.CreateDirectory(p);
                if (File.Exists(p + file))
                {
                    File.Delete(p + file);
                }
                if (!HLLib.hlItemExtract(pItem, p))
                {
                    Cursor = Cursors.Arrow;
                    MessageBox.Show("Error when extracting:\r\n" +
                                    HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
                    retVal = "";
                    Close();
                }
                Cursor = Cursors.WaitCursor;
                retVal = File.Exists(p + file) ? p + file : "";
                Close();
            }
            else if (radioSteamapps.Checked) //Find in steamapps
            {
                Cursor = Cursors.WaitCursor;
                Settings.Default.OpenFileSetting = 1;
                if (Settings.Default.SteamFolder == null || Settings.Default.SteamFolder.ToString() == "")
                {
showDia:
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        if (!File.Exists(folderBrowserDialog1.SelectedPath + @"\team fortress 2 content.gcf"))
                        {
                            Cursor = Cursors.Arrow;
                            var res = MessageBox.Show(
                                "team fortress 2 content.gcf could not be found in that folder!\r\nPlease select your steamapps folder!",
                                "TF2 Items Editor",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Error);
                            if (res == DialogResult.OK)
                            {
                                goto showDia;
                            }
                            return;
                        }
                        Settings.Default.SteamFolder = folderBrowserDialog1.SelectedPath;
                        Settings.Default.Save();
                    }
                    else
                    {
                        return;
                    }
                }
                Cursor = Cursors.WaitCursor;
                string[] dirs = Directory.GetDirectories(Settings.Default.SteamFolder);
                if (string.IsNullOrEmpty(Settings.Default.SteamUser))
                {
                    var match = new List <string>();
                    foreach (string _dir in dirs)
                    {
                        string dir = (new DirectoryInfo(_dir)).Name;
                        if (dir != "common" && dir != "media" && dir != "SourceMods")
                        {
                            match.Add(dir);
                        }
                    }
                    if (match.Count > 1)
                    {
                        using (var win = new SteamFolderSelectWindow())
                        {
                            string ret = win.ShowWindow(match);
                            if (ret == "")
                            {
                                return;
                            }
                            Settings.Default.SteamUser = ret;
                            Settings.Default.Save();
                        }
                    }
                    else if (match.Count == 1)
                    {
                        Settings.Default.SteamUser = match[0];
                        Settings.Default.Save();
                    }
                    else
                    {
                        Cursor = Cursors.Arrow;
                        MessageBox.Show("No user folders found in steamapps!",
                                        "TF2 Items Editor",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                }
                string p = Settings.Default.SteamFolder + @"\" + Settings.Default.SteamUser +
                           @"\team fortress 2" + filePath + file;
                retVal = File.Exists(p) ? p : "";
                if (!File.Exists(p))
                {
                    Cursor = Cursors.Arrow;
                    MessageBox.Show("Couldn't find " + file + "!\r\nPlease make sure it is present in " + p,
                                    "TF2 Items Editor",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
                Close();
            }
            else if (radioManual.Checked) //Find manually
            {
                Settings.Default.OpenFileSetting = 2;
                openFileDialog1.Filter           = file.Split('.')[1] + " files|*." + file.Split('.')[1];
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    retVal = openFileDialog1.FileName;
                    Close();
                }
                else
                {
                    retVal = "";
                    return;
                }
            }
        }