Skip to content

Commit

Permalink
Temporary patch 1.3 compatibility fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Deweh committed Aug 19, 2021
1 parent e132349 commit 9a2d430
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 38 deletions.
22 changes: 19 additions & 3 deletions CP2077SaveEditor/Views/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public partial class Form1 : Form
private bool cancelLoad = false;
private int saveType = 0;
private Random globalRand = new Random();
public static bool psDataEnabled = true;
public static bool psDataEnabled = false;
public static bool statsSystemEnabled = false;
public static bool wipEnabled = false;

//GUI
Expand Down Expand Up @@ -521,14 +522,19 @@ private void openSaveButton_Click(object sender, EventArgs e)
parsers.AddRange(new INodeParser[] {
new CharacterCustomizationAppearancesParser(), new InventoryParser(), new ItemDataParser(), new FactsDBParser(),
new FactsTableParser(), new GameSessionConfigParser(), new ItemDropStorageManagerParser(), new ItemDropStorageParser(),
new StatsSystemParser(), new ScriptableSystemsContainerParser()
new ScriptableSystemsContainerParser()
});

if (psDataEnabled)
{
parsers.Add(new PSDataParser());
}

if (statsSystemEnabled)
{
parsers.Add(new StatsSystemParser());
}

var newSave = new SaveFileHelper(parsers);
editorPanel.Enabled = false;
optionsPanel.Enabled = false;
Expand Down Expand Up @@ -758,14 +764,19 @@ private void saveChangesButton_Click(object sender, EventArgs e)
parsers.AddRange(new INodeParser[] {
new CharacterCustomizationAppearancesParser(), new InventoryParser(), new ItemDataParser(), new FactsDBParser(),
new FactsTableParser(), new GameSessionConfigParser(), new ItemDropStorageManagerParser(), new ItemDropStorageParser(),
new StatsSystemParser(), new ScriptableSystemsContainerParser()
new ScriptableSystemsContainerParser()
});

if (psDataEnabled)
{
parsers.Add(new PSDataParser());
}

if (statsSystemEnabled)
{
parsers.Add(new StatsSystemParser());
}

var testFile = new SaveFileHelper(parsers);
try
{
Expand Down Expand Up @@ -1142,6 +1153,11 @@ private void clearQuestFlagsButton_Click(object sender, EventArgs e)

private void additionalPlayerStatsButton_Click(object sender, EventArgs e)
{
if (!statsSystemEnabled)
{
MessageBox.Show("Stats system disabled.");
return;
}
var i = Array.FindIndex(activeSaveFile.GetStatsMap().Keys, x => x.EntityHash == 1);
var details = new ItemDetails();
details.LoadStatsOnly(activeSaveFile.GetStatsMap().Values[i].Seed, activeSaveFile, "Player");
Expand Down
85 changes: 50 additions & 35 deletions CP2077SaveEditor/Views/ItemDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,50 +110,59 @@ public bool ReloadData()
}

//Stats parsing
if (activeSaveFile.GetItemStatData(activeItem) == null)
{
detailsTabControl.TabPages.Remove(statsTab);
}
else
if (Form1.statsSystemEnabled)
{
detailsTabControl.TabPages.Remove(statsPlaceholderTab);
statsListView.Items.Clear();
var listRows = new List<ListViewItem>();
var statsData = activeSaveFile.GetItemStatData(activeItem);
if (statsData.StatModifiers != null)
if (activeSaveFile.GetItemStatData(activeItem) == null)
{
foreach (Handle<GameStatModifierData> modifier in statsData.StatModifiers)
detailsTabControl.TabPages.Remove(statsTab);
}
else
{
detailsTabControl.TabPages.Remove(statsPlaceholderTab);
statsListView.Items.Clear();
var listRows = new List<ListViewItem>();
var statsData = activeSaveFile.GetItemStatData(activeItem);
if (statsData.StatModifiers != null)
{
var row = new string[] { "Constant", modifier.Value.ModifierType.ToString(), modifier.Value.StatType.ToString(), "" };

if (modifier.Value is GameCombinedStatModifierData combinedData)
{
row[0] = "Combined";
row[3] = combinedData.Value.ToString();
}
else if (modifier.Value is GameConstantStatModifierData constantData)
foreach (Handle<GameStatModifierData> modifier in statsData.StatModifiers)
{
row[3] = constantData.Value.ToString();
}
else
{
row[0] = "Curve";
var row = new string[] { "Constant", modifier.Value.ModifierType.ToString(), modifier.Value.StatType.ToString(), "" };

if (modifier.Value is GameCombinedStatModifierData combinedData)
{
row[0] = "Combined";
row[3] = combinedData.Value.ToString();
}
else if (modifier.Value is GameConstantStatModifierData constantData)
{
row[3] = constantData.Value.ToString();
}
else
{
row[0] = "Curve";
}

var newItem = new ListViewItem(row);
newItem.Tag = modifier;
listRows.Add(newItem);
}

var newItem = new ListViewItem(row);
newItem.Tag = modifier;
listRows.Add(newItem);
statsListView.BeginUpdate();
statsListView.Items.AddRange(listRows.ToArray());
statsListView.EndUpdate();
}
else
{
statsData.StatModifiers = new Handle<GameStatModifierData>[0];
}

statsListView.BeginUpdate();
statsListView.Items.AddRange(listRows.ToArray());
statsListView.EndUpdate();
}
else
{
statsData.StatModifiers = new Handle<GameStatModifierData>[0];
}
}
else
{
detailsTabControl.TabPages.Remove(statsTab);
detailsTabControl.TabPages.Remove(statsPlaceholderTab);
}


if (!statsOnly)
{
Expand All @@ -176,6 +185,12 @@ public void LoadItem(ItemData item, object _saveFile, Func<bool> callback1, Rand

public void LoadStatsOnly(uint seed, object _saveFile, string name)
{
if (!Form1.statsSystemEnabled)
{
MessageBox.Show("Stats system disabled.");
this.Close();
}

callbackFunc1 = delegate{ return true; };
var dummyItem = new ItemData();
dummyItem.Header.Seed = seed;
Expand Down

0 comments on commit 9a2d430

Please sign in to comment.