Ejemplo n.º 1
0
        private void BtnLowerQuality_Click(object sender, EventArgs e)
        {
            var lodLevels = new LODLevels
            {
                LvlCollectables     = rbLODColl0.Checked ? 0 : rbLODColl1.Checked ? 1 : rbLODColl2.Checked ? 2 : 3,
                LvlEnvironment      = rbLODEnv0.Checked ? 0 : rbLODEnv1.Checked ? 1 : rbLODEnv2.Checked ? 2 : 3,
                LvlShipExteriors    = rbLODShipE0.Checked ? 0 : rbLODShipE1.Checked ? 1 : rbLODShipE2.Checked ? 2 : 3,
                LvlShipInteriors    = rbLODShipI0.Checked ? 0 : rbLODShipI1.Checked ? 1 : rbLODShipI2.Checked ? 2 : 3,
                LvlStationExteriors = rbLODStationE0.Checked ? 0 : rbLODStationE1.Checked ? 1 : rbLODStationE2.Checked ? 2 : 3,
                LvlStationInteriors = rbLODStationI0.Checked ? 0 : rbLODStationI1.Checked ? 1 : rbLODStationI2.Checked ? 2 : 3
            };

            var texLevels = new TextureLevels
            {
                MinTextureSize      = (int)numTexMinSize.Value,
                LvlFonts            = rbTexFont0.Checked ? 0 : rbTexFont1.Checked ? 1 : rbTexFont2.Checked ? 2 : 3,
                LvlGUI              = rbTexGUI0.Checked ? 0 : rbTexGUI1.Checked ? 1 : rbTexGUI2.Checked ? 2 : 3,
                LvlNPCs             = rbTexNPC0.Checked ? 0 : rbTexNPC1.Checked ? 1 : rbTexNPC2.Checked ? 2 : 3,
                LvlFX               = rbTexFX0.Checked ? 0 : rbTexFX1.Checked ? 1 : rbTexFX2.Checked ? 2 : 3,
                LvlEnvironments     = rbTexEnv0.Checked ? 0 : rbTexEnv1.Checked ? 1 : rbTexEnv2.Checked ? 2 : 3,
                LvlStationExteriors = rbTexStationE0.Checked ? 0 : rbTexStationE1.Checked ? 1 : rbTexStationE2.Checked ? 2 : 3,
                LvlStationInteriors = rbTexStationI0.Checked ? 0 : rbTexStationI1.Checked ? 1 : rbTexStationI2.Checked ? 2 : 3,
                LvlShips            = rbTexShips0.Checked ? 0 : rbTexShips1.Checked ? 1 : rbTexShips2.Checked ? 2 : 3,
                LvlMisc             = rbTexMisc0.Checked ? 0 : rbTexMisc1.Checked ? 1 : rbTexMisc2.Checked ? 2 : 3
            };

            if (lodLevels.AllZero() && texLevels.AllZero())
            {
                MessageBox.Show(
                    "You set all quality settings to \"unchanged\", so no changes to the game's files will be made.\n" +
                    "Are you trying to restore those to a previous state right now ?\n" +
                    "Oh dear, i told you to back them up ..",
                    "Lowering quality",
                    MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }

            lbResults.Clear();

            if (!cbSimulate.Checked)
            {
                if (MessageBox.Show(
                        string.Format(
                            "Did you make backups of all .cat-files AND .dat-files in\n\"{0}\" ?\n" +
                            "This little app currently can't restore any changes made to those files, " +
                            "so you would most likely have to reinstall X4 if you wanted to restore them.", path_),
                        "Last reminder",
                        MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                {
                    return;
                }
            }

            if (!cbSimulate.Checked)
            {
                AddLogLineInfo("Worsening X4's graphics ...");
            }
            else
            {
                AddLogLineInfo("[SIMULATION] Worsening X4's graphics ...");
            }

            if (!texLevels.AllZero())
            {
                AddLogLineInfo(">> Modifying textures is enabled, this can take a couple of minutes.");
            }

            AddLogLineInfo();

            btnOpen.Enabled         = false;
            btnLowerQuality.Enabled = false;
            gbMeshes.Enabled        = false;
            gbTextures.Enabled      = false;
            cbSimulate.Enabled      = false;

            progressBar.Maximum = catFiles_.Count * 2;
            progressBar.Value   = 0;

            var task = Task.Factory.StartNew(() =>
            {
                var totalRes = new CatIndex.Res();

                foreach (var file in catFiles_)
                {
                    progressBar.InvokeIfRequired(() => { ++progressBar.Value; });

                    var finfoCat = new FileInfo(file);
                    var finfoDat = new FileInfo(file.Substring(0, file.Length - 3) + "dat");

                    if (finfoCat.Exists && finfoDat.Exists)
                    {
                        var catIndex       = new CatIndex();
                        bool processingDat = false;

                        try
                        {
                            catIndex.Load(finfoCat.FullName, finfoDat.FullName);

                            if (!lodLevels.AllZero())
                            {
                                var res = catIndex.ProcessMeshes(lodLevels);
                                if (res.Count > 0)
                                {
                                    totalRes.Count        += res.Count;
                                    totalRes.RemovedBytes += res.RemovedBytes;
                                    totalRes.AddeddBytes  += res.AddeddBytes;

                                    AddLogLineInfo(string.Format("{0}:", finfoCat.Name));
                                    AddLogLineInfo(string.Format(
                                                       "\tMeshes: Modified {0} entries / removed {1:F3} MB / added {2:F3} MB",
                                                       res.Count,
                                                       res.RemovedBytes / (1024.0 * 1024.0),
                                                       res.AddeddBytes / (1024.0 * 1024.0)));
                                    AddLogLineInfo();
                                }
                            }

                            if (!finfoDat.FullName.EndsWith("_sig.dat") && !texLevels.AllZero())
                            {
                                processingDat = true;

                                var res = catIndex.ProcessTextures(texLevels);
                                if (res.Count > 0)
                                {
                                    totalRes.Count        += res.Count;
                                    totalRes.RemovedBytes += res.RemovedBytes;
                                    totalRes.AddeddBytes  += res.AddeddBytes;

                                    AddLogLineInfo(string.Format("{0}:", finfoDat.Name));
                                    AddLogLineInfo(string.Format(
                                                       "\tTextures: Modified {0} entries / removed {1:F3} MB (uncompressed)",
                                                       res.Count,
                                                       res.RemovedBytes / (1024.0 * 1024.0)));
                                    AddLogLineInfo();
                                }
                            }
                        }
                        catch (UnauthorizedAccessException)
                        {
                            AddLogLineError(string.Format("{0}:", processingDat ? finfoDat.Name : finfoCat.Name));
                            AddLogLineError("\tCould not open file to write (check write permissions)");
                            AddLogLineError();
                        }
                        catch (Exception ex)
                        {
                            totalRes.Count = 0;

                            AddLogLineError(string.Format("{0}:", processingDat ? finfoDat.Name : finfoCat.Name));
                            AddLogLineError(string.Format("\tException occured: {0}", ex));
                            AddLogLineError();

                            if (!cbSimulate.Checked)
                            {
                                AddLogLineError("Canceled further processing (contact developer ?)");
                            }
                            else
                            {
                                AddLogLineError("Canceled further processing, please restore using your backed up files (and contact developer ?)");
                            }

                            catIndex.Close(false);
                            break;
                        }

                        catIndex.Close(!cbSimulate.Checked);
                    }
                }

                lbResults.Invoke(new Action(() =>
                {
                    progressBar.Value = progressBar.Maximum;

                    AddLogLineInfo();
                    AddLogLineInfo(" ***************************************************************************** ");
                    AddLogLineInfo("                                       DONE.                                   ");

                    if (totalRes.Count > 0)
                    {
                        AddLogLineInfo(string.Format(
                                           "    Total: Modified {0} entries / removed {1:F3} MB / added {2:F3} MB",
                                           totalRes.Count,
                                           totalRes.RemovedBytes / (1024.0 * 1024.0),
                                           totalRes.AddeddBytes / (1024.0 * 1024.0)));
                    }

                    AddLogLineInfo(" ***************************************************************************** ");

                    if (!cbSimulate.Checked)
                    {
                        lblFolder.Text = "Please don't attempt to modify the same files again, restore them before that";
                        path_          = null;
                        catFiles_.Clear();
                    }
                    else
                    {
                        btnLowerQuality.Enabled = true;
                    }

                    gbMeshes.Enabled   = true;
                    gbTextures.Enabled = true;
                    cbSimulate.Enabled = true;
                    btnOpen.Enabled    = true;
                }));
            });
        }
Ejemplo n.º 2
0
        public Res ProcessTextures(TextureLevels levels)
        {
            long currentPos = 0;
            var  res        = new Res();

            foreach (var e in _entries)
            {
                var cat    = TextureEntry.GetCategory(e.Path);
                int qlevel = 0;

                switch (cat)
                {
                case TextureEntry.TECategory.Unset:
                    currentPos += e.OrigSize;
                    continue;

                case TextureEntry.TECategory.Fonts:
                    qlevel = levels.LvlFonts;
                    break;

                case TextureEntry.TECategory.GUI:
                    qlevel = levels.LvlGUI;
                    break;

                case TextureEntry.TECategory.NPCs:
                    qlevel = levels.LvlNPCs;
                    break;

                case TextureEntry.TECategory.FX:
                    qlevel = levels.LvlFX;
                    break;

                case TextureEntry.TECategory.Environments:
                    qlevel = levels.LvlEnvironments;
                    break;

                case TextureEntry.TECategory.StationExteriors:
                    qlevel = levels.LvlStationExteriors;
                    break;

                case TextureEntry.TECategory.StationInteriors:
                    qlevel = levels.LvlStationInteriors;
                    break;

                case TextureEntry.TECategory.Ships:
                    qlevel = levels.LvlShips;
                    break;

                case TextureEntry.TECategory.Misc:
                    qlevel = levels.LvlMisc;
                    break;
                }

                if (e.OrigSize >= levels.MinTextureSize)
                {
                    if (DoReduceDDS(e, cat, currentPos, qlevel, res))
                    {
                        _updateCat = true;
                        _updateDat = true;
                    }
                }

                currentPos += e.OrigSize;
            }

            return(res);
        }