Exemplo n.º 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)
            {
                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");
                }
                var saveBytes = activeSaveFile.SaveToPCSaveFile();
                File.WriteAllBytes(saveWindow.FileName, saveBytes);

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

                activeSaveFile = new SaveFileHelper(parsers);
                activeSaveFile.LoadPCSaveFile(new MemoryStream(saveBytes));
                statusLabel.Text = "File saved.";
            }
        }
Exemplo n.º 2
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.";
            }
        }
Exemplo n.º 3
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;
                //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);
                newSave.LoadPCSaveFile(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 profics = activeSaveFile.GetPlayerDevelopmentData().Value.Proficiencies;

                levelUpDown.Value      = profics[Array.FindIndex(profics, x => x.Type == CyberCAT.Core.DumpedEnums.gamedataProficiencyType.Level)].CurrentLevel;
                streetCredUpDown.Value = profics[Array.FindIndex(profics, x => x.Type == CyberCAT.Core.DumpedEnums.gamedataProficiencyType.StreetCred)].CurrentLevel;

                var attrs = activeSaveFile.GetPlayerDevelopmentData().Value.Attributes;

                bodyUpDown.Value             = attrs[Array.FindIndex(attrs, x => x.AttributeName == CyberCAT.Core.DumpedEnums.gamedataStatType.Strength)].Value;
                reflexesUpDown.Value         = attrs[Array.FindIndex(attrs, x => x.AttributeName == CyberCAT.Core.DumpedEnums.gamedataStatType.Reflexes)].Value;
                technicalAbilityUpDown.Value = attrs[Array.FindIndex(attrs, x => x.AttributeName == CyberCAT.Core.DumpedEnums.gamedataStatType.TechnicalAbility)].Value;
                intelligenceUpDown.Value     = attrs[Array.FindIndex(attrs, x => x.AttributeName == CyberCAT.Core.DumpedEnums.gamedataStatType.Intelligence)].Value;
                coolUpDown.Value             = attrs[Array.FindIndex(attrs, x => x.AttributeName == CyberCAT.Core.DumpedEnums.gamedataStatType.Cool)].Value;

                if (activeSaveFile.GetPlayerDevelopmentData().Value.LifePath == CyberCAT.Core.DumpedEnums.gamedataLifePath.Nomad)
                {
                    lifePathBox.SelectedIndex = 0;
                }
                else if (activeSaveFile.GetPlayerDevelopmentData().Value.LifePath == CyberCAT.Core.DumpedEnums.gamedataLifePath.StreetKid)
                {
                    lifePathBox.SelectedIndex = 1;
                }
                else
                {
                    lifePathBox.SelectedIndex = 2;
                }

                var points = activeSaveFile.GetPlayerDevelopmentData().Value.DevPoints;

                perkPointsUpDown.Value = points[Array.FindIndex(points, x => x.Type == CyberCAT.Core.DumpedEnums.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);
            }
        }