Пример #1
0
        private void saveChangesButton_Click(object sender, EventArgs e)
        {
            var saveWindow = new SaveFileDialog();

            saveWindow.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Saved Games\\CD Projekt Red\\Cyberpunk 2077\\";
            saveWindow.Filter           = "Cyberpunk 2077 Save File|*.dat";
            if (saveWindow.ShowDialog() == DialogResult.OK)
            {
                statusLabel.Text = "Saving changes...";
                this.Refresh();
                if (File.Exists(saveWindow.FileName) && !File.Exists(Path.GetDirectoryName(saveWindow.FileName) + "\\" + Path.GetFileNameWithoutExtension(saveWindow.FileName) + ".old"))
                {
                    File.Copy(saveWindow.FileName, Path.GetDirectoryName(saveWindow.FileName) + "\\" + Path.GetFileNameWithoutExtension(saveWindow.FileName) + ".old");
                }
                byte[] saveBytes;
                if (saveType == 0)
                {
                    saveBytes = activeSaveFile.SaveToPCSaveFile();
                }
                else
                {
                    saveBytes = activeSaveFile.SaveToPS4SaveFile();
                }


                var parsers = new List <INodeParser>();
                parsers.AddRange(new INodeParser[] {
                    new CharacterCustomizationAppearancesParser(), new InventoryParser(), new ItemDataParser(), new FactsDBParser(),
                    new FactsTableParser(), new GameSessionConfigParser(), new ItemDropStorageManagerParser(), new ItemDropStorageParser(),
                    new StatsSystemParser(), new ScriptableSystemsContainerParser()
                });

                var testFile = new SaveFileHelper(parsers);
                try
                {
                    if (saveType == 0)
                    {
                        testFile.LoadPCSaveFile(new MemoryStream(saveBytes));
                    }
                    else
                    {
                        testFile.LoadPS4SaveFile(new MemoryStream(saveBytes));
                    }
                } catch (Exception ex) {
                    statusLabel.Text = "Save cancelled.";
                    File.WriteAllText("error.txt", ex.Message + '\n' + ex.TargetSite + '\n' + ex.StackTrace);
                    MessageBox.Show("Corruption has been detected in the edited save file. No data has been written. Please report this issue on github.com/Deweh/CyberCAT-SimpleGUI with the generated error.txt file.");
                    return;
                }

                File.WriteAllBytes(saveWindow.FileName, saveBytes);
                activeSaveFile   = testFile;
                statusLabel.Text = "File saved.";
            }
        }
Пример #2
0
        private void openSaveButton_Click(object sender, EventArgs e)
        {
            var fileWindow = new OpenFileDialog();

            fileWindow.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Saved Games\\CD Projekt Red\\Cyberpunk 2077\\";
            fileWindow.Filter           = "Cyberpunk 2077 Save File|*.dat";
            if (fileWindow.ShowDialog() == DialogResult.OK)
            {
                loadingSave      = true;
                statusLabel.Text = "Loading save...";
                this.Refresh();
                //Initialize NameResolver & FactResolver dictionaries, build parsers list & load save file
                NameResolver.UseDictionary(JsonConvert.DeserializeObject <Dictionary <ulong, NameResolver.NameStruct> >(CP2077SaveEditor.Properties.Resources.ItemNames));
                FactResolver.UseDictionary(JsonConvert.DeserializeObject <Dictionary <ulong, string> >(CP2077SaveEditor.Properties.Resources.Facts));

                var parsers = new List <INodeParser>();
                parsers.AddRange(new INodeParser[] {
                    new CharacterCustomizationAppearancesParser(), new InventoryParser(), new ItemDataParser(), new FactsDBParser(),
                    new FactsTableParser(), new GameSessionConfigParser(), new ItemDropStorageManagerParser(), new ItemDropStorageParser(),
                    new StatsSystemParser(), new ScriptableSystemsContainerParser()
                });

                var newSave = new SaveFileHelper(parsers);
                if (saveType == 0)
                {
                    newSave.LoadPCSaveFile(new MemoryStream(File.ReadAllBytes(fileWindow.FileName)));
                }
                else
                {
                    newSave.LoadPS4SaveFile(new MemoryStream(File.ReadAllBytes(fileWindow.FileName)));
                }

                activeSaveFile = newSave;

                //Appearance parsing
                RefreshAppearanceValues();

                //Inventory parsing
                moneyUpDown.Enabled = false;
                moneyUpDown.Value   = 0;

                containersListBox.Items.Clear();
                foreach (Inventory.SubInventory container in activeSaveFile.GetInventoriesContainer().SubInventories)
                {
                    var containerID = container.InventoryId.ToString(); if (containerID == "1")
                    {
                        containerID = "Player Inventory";
                    }
                    containersListBox.Items.Add(containerID);
                }

                if (containersListBox.Items.Count > 0)
                {
                    containersListBox.SelectedIndex = 0;
                }

                //Facts parsing
                RefreshFacts();
                //These lines may look redundant, but they initialize the factsListView so that the render thread doesn't freeze when selecting the Quest Facts tab for the first time.
                //Since the render thread will be frozen here anyways while everything loads, it's best to do this here.
                factsSaveButton.Visible = false;
                factsPanel.Visible      = true;
                factsPanel.Visible      = false;
                factsSaveButton.Visible = true;

                //Player stats parsing
                var playerData = activeSaveFile.GetPlayerDevelopmentData();
                foreach (gamedataProficiencyType proficType in proficFields.Keys)
                {
                    CyberCAT.Core.Classes.DumpedClasses.SProficiency profic;
                    if (proficType == gamedataProficiencyType.Invalid)
                    {
                        profic = playerData.Value.Proficiencies[Array.FindIndex(playerData.Value.Proficiencies, x => x.Type == null)];
                    }
                    else
                    {
                        profic = playerData.Value.Proficiencies[Array.FindIndex(playerData.Value.Proficiencies, x => x.Type == proficType)];
                    }
                    if (profic.CurrentLevel > (int)proficFields[proficType].Maximum)
                    {
                        proficFields[proficType].Maximum = profic.CurrentLevel;
                    }

                    proficFields[proficType].Value = profic.CurrentLevel;
                }

                foreach (gamedataStatType attrType in attrFields.Keys)
                {
                    CyberCAT.Core.Classes.DumpedClasses.SAttribute attr = playerData.Value.Attributes[Array.FindIndex(playerData.Value.Attributes, x => x.AttributeName == attrType)];
                    if (attr.Value > (int)attrFields[attrType].Maximum)
                    {
                        attrFields[attrType].Maximum = attr.Value;
                    }

                    attrFields[attrType].Value = attr.Value;
                }

                switch (activeSaveFile.GetPlayerDevelopmentData().Value.LifePath)
                {
                case gamedataLifePath.Nomad:
                    lifePathBox.SelectedIndex = 0;
                    break;

                case gamedataLifePath.StreetKid:
                    lifePathBox.SelectedIndex = 1;
                    break;

                default:
                    lifePathBox.SelectedIndex = 2;
                    break;
                }

                var points = activeSaveFile.GetPlayerDevelopmentData().Value.DevPoints;
                perkPointsUpDown.Value = points[Array.FindIndex(points, x => x.Type == gamedataDevelopmentPointType.Primary)].Unspent;
                attrPointsUpDown.Value = points[Array.FindIndex(points, x => x.Type == null)].Unspent;

                //Update controls
                loadingSave          = false;
                editorPanel.Enabled  = true;
                optionsPanel.Enabled = true;
                filePathLabel.Text   = Path.GetFileName(Path.GetDirectoryName(fileWindow.FileName));
                statusLabel.Text     = "Save file loaded.";
                SwapTab(statsButton, statsPanel);
            }
        }