Exemple #1
0
        static void HandleRoot(L4D2Mod o, SharpVPK.VpkDirectory dir)
        {
            bool isFindImage = o.ImageMemoryStream != null;

            foreach (var entry in dir.Entries)
            {
                if (!isFindImage && entry.Filename == "addonimage")
                {
                    if (ImageExtensions.Contains(entry.Extension))
                    {
                        o.ImageMemoryStream = new MemoryStream();
                        byte[] data = entry.Data;
                        o.ImageMemoryStream.Write(data, 0, data.Length);
                        o.Image     = Image.FromStream(o.ImageMemoryStream);
                        isFindImage = true;
                        o.Image.Save(dir.ParentArchive.ArchivePath.Replace(".vpk", '.' + entry.Extension));
                    }
                }
                if (entry.Filename == "addoninfo" && entry.Extension == "txt")
                {
                    HandleAddonInfoTxt(o, entry);
                    //Logging.Error();
                }
            }
        }
Exemple #2
0
        private void LoadSteamWorkshop()
        {
            if (m_steam != null)
            {
                WindowCallbacks.OperationEnable(this.GetType().ToString(), false);
                WindowCallbacks.Print(StringAdapter.GetInfo("LoadSteamWorkshop"));
                WindowCallbacks.Process(0, 1, StringAdapter.GetInfo("LoadSteamWorkshop"));

                var list = m_steam.Workshop.GetSubscribedItemIds();
                if (list.Length > 0)
                {
                    if (Configure.DelegateSteam)
                    {
                        GetDelegateSteamResult(list.ToList(), ModSource.Workshop, true);
                    }
                    else
                    {
                        var query = m_steam.Workshop.CreateQuery();
                        query.FileId = list.ToList();
                        query.Run();
                        query.Block();
                        Logging.Assert(!query.IsRunning);
                        //Logging.Assert(query.TotalResults > 0);
                        //Logging.Assert(query.Items.Length > 0);
                        int total = query.Items.Length;
                        int count = 0;
                        foreach (var item in query.Items)
                        {
                            ulong id = item.Id;
                            //Facepunch.Steamworks.Workshop.Item item = m_steam.Workshop.GetItem(v);
                            if (id > 0)
                            {
                                WindowCallbacks.Process(count++, total, StringAdapter.GetInfo("LoadSteamWorkshop") + " : " + id.ToString());
                                string key = @"workshop\" + id.ToString() + ".vpk";
                                if (!m_modStates.ContainsKey(key))
                                {
                                    L4D2Mod mod = new L4D2Mod(item);
                                    if (mod.Title != null && mod.Title.Length > 0)
                                    {
                                        m_modStates.Add(key, new ModInfo(this, key, ModState.On, ModSource.Workshop, mod));
                                    }
                                }
                                else
                                {
                                    m_modStates[key].Mod.LoadItem(item);
                                }
                                Logging.Log("load from Steam workshop " + id.ToString());
                            }
                        }
                    }
                }
                WindowCallbacks.Process(1, 1, "");
                WindowCallbacks.Print(StringAdapter.GetInfo("LoadComplete"));
                WindowCallbacks.OperationEnable(this.GetType().ToString(), true);
            }
        }
Exemple #3
0
            public ModInfo(L4D2MM manager, string key, ModState state, ModSource source, L4D2Mod mod)
            {
                Manager         = manager;
                Key             = key;
                ModState        = state;
                Source          = source;
                Mod             = mod;
                IsHaveCollision = false;

                base.CollisionCountChangeHandler = (count) => { IsHaveCollision = count > 0; };
                RefreshResources();
            }
Exemple #4
0
        static void HandleAddonInfoTxt(L4D2Mod o, SharpVPK.VpkEntry entry)
        {
            bool         AddDescription = o.Description.Length <= 0;
            MemoryStream ms             = new MemoryStream();

            byte[] data = entry.Data;
            ms.Write(data, 0, data.Length);
            ms.Seek(0, SeekOrigin.Begin);
            L4D2TxtReader reader = new L4D2TxtReader(ms, L4D2TxtReader.TxtType.AddonInfo);

            foreach (var item in reader.Values)
            {
                var key = item.Key.ToLower();
                if (key.Contains("title") && o.Title.Length <= 0)
                {
                    o.Title = item.Value.Replace('\r', ' ').Replace('\n', ' ');
                }
                else if (key.Contains("author") && o.Author.Length <= 0)
                {
                    o.Author = item.Value;
                }
                else if (key.Contains("description") && AddDescription)
                {
                    o.Description = o.Description + item.Value + "\r\n";
                }
                else if (key.Contains("version") && o.Version.Length <= 0)
                {
                    o.Version = item.Value;
                }
                else if (key.Contains("url") && o.URL.Length <= 0)
                {
                    o.URL = item.Value;
                }
                else if (key.Contains("ownerid") && o.OwnerId <= 0)
                {
                    try { o.OwnerId = Convert.ToUInt64(item.Value); }
                    catch { }
                }
            }
        }
Exemple #5
0
        private void LoadLocalFiles(string path)
        {
            WindowCallbacks.OperationEnable(this.GetType().ToString(), false);
            WindowCallbacks.Print(StringAdapter.GetInfo("LoadLocalFile"));
            int total = new DirectoryInfo(path + m_dirWorkshop).GetFiles("*.vpk").Length;

            if (Configure.EnableAddons)
            {
                total += new DirectoryInfo(path + m_dirAddons).GetFiles("*.vpk").Length;
            }
            int current = 0;

            foreach (FileInfo vpkFile in new DirectoryInfo(path + m_dirWorkshop).GetFiles("*.vpk")) //from workshop
            {
                //update process bar
                WindowCallbacks.Process(current, total, StringAdapter.GetInfo("LoadLocalFile") + " : workshop/" + vpkFile.Name);
                string key = @"workshop\" + vpkFile.Name;
                if (!m_modStates.ContainsKey(key))
                {
                    //continue; //local file not valid in this path
                    L4D2Mod mod  = new L4D2Mod(vpkFile, true);
                    ModInfo info = new ModInfo(this, key, SteamEnabled ? ModState.Unsubscribed : ModState.On, ModSource.Workshop, mod);
                    m_modStates.Add(key, info);
                }
                else
                {
                    m_modStates[key].Mod.LoadLocalFile(vpkFile, Configure.EnableReadVpk);
                }
                current++;
                Logging.Log("load from workshop : " + vpkFile.Name);
            }
            //for addons
            if (Configure.EnableAddons)
            {
                List <ulong> fileIds = new List <ulong>();
                foreach (FileInfo vpkFile in new DirectoryInfo(path + m_dirAddons).GetFiles("*.vpk")) //from addons
                {
                    //update process bar
                    WindowCallbacks.Process(current, total, StringAdapter.GetInfo("LoadLocalFile") + " : " + vpkFile.Name);
                    string  key  = vpkFile.Name;
                    L4D2Mod mod  = new L4D2Mod(vpkFile, true);
                    ModInfo info = new ModInfo(this, key, ModState.On, ModSource.Player, mod);
                    m_modStates.Add(key, info);
                    current++;
                    Logging.Log("load from addons : " + vpkFile.Name);
                    //check if it is a workshop item
                    string name = key.Replace(".vpk", "");
                    if (name.IsNumber() && name.Length >= 8 && name.Length <= 11)
                    {
                        fileIds.Add(ulong.Parse(name));
                    }
                }
                if (m_steam != null && fileIds.Count > 0)
                {
                    if (Configure.DelegateSteam)
                    {
                        GetDelegateSteamResult(fileIds, ModSource.Player, false, fileIds.Count);
                    }
                    else
                    {
                        var query = m_steam.Workshop.CreateQuery();
                        query.FileId = fileIds;
                        query.Run();
                        query.Block();
                        Logging.Assert(!query.IsRunning);
                        foreach (var item in query.Items)
                        {
                            if (item.Id > 0)
                            {
                                string key = item.Id.ToString() + ".vpk";
                                Logging.Assert(m_modStates.ContainsKey(key));
                                m_modStates[key].Mod.LoadItem(item);
                            }
                        }
                    }
                }
            }
            WindowCallbacks.Process(1, 1, StringAdapter.GetInfo("LoadComplete"));
            WindowCallbacks.Print(StringAdapter.GetInfo("LoadComplete"));
            WindowCallbacks.OperationEnable(this.GetType().ToString(), true);
        }
Exemple #6
0
 static void HandleOthers(L4D2Mod o, SharpVPK.VpkDirectory dir)
 {
 }
Exemple #7
0
 static void HandleModelVItem(L4D2Mod o, SharpVPK.VpkDirectory dir)
 {
 }
Exemple #8
0
 static void HandleSurvivor(L4D2Mod o, SharpVPK.VpkDirectory dir)
 {
 }
Exemple #9
0
 static void HandleInfected(L4D2Mod o, SharpVPK.VpkDirectory dir)
 {
 }
Exemple #10
0
 static void HandleProps(L4D2Mod o, SharpVPK.VpkDirectory dir)
 {
 }