Skip to content

Commit 074ae73

Browse files
committed
Add undo delete enemies cheat
1 parent 0901d9d commit 074ae73

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Windows;
3+
4+
using SatisfactorySaveEditor.Model;
5+
using SatisfactorySaveEditor.ViewModel.Property;
6+
using SatisfactorySaveEditor.ViewModel.Struct;
7+
8+
using SatisfactorySaveParser;
9+
using SatisfactorySaveParser.PropertyTypes;
10+
11+
using Vector = SatisfactorySaveParser.PropertyTypes.Structs.Vector;
12+
using Vector3 = SatisfactorySaveParser.Structures.Vector3;
13+
14+
namespace SatisfactorySaveEditor.Cheats
15+
{
16+
public class UndoDeleteEnemiesCheat : ICheat
17+
{
18+
public string Name => "Undo Delete enemies";
19+
20+
private SaveObjectModel FindOrCreatePath(SaveObjectModel start, string[] path, int index = 0)
21+
{
22+
if (index == path.Length)
23+
return start;
24+
if (start.FindChild(path[index], false) == null)
25+
start.Items.Add(new SaveObjectModel(path[index]));
26+
return FindOrCreatePath(start.FindChild(path[index], false), path, index + 1);
27+
}
28+
29+
public bool Apply(SaveObjectModel rootItem, SatisfactorySave save)
30+
{
31+
var animalSpawners = rootItem.FindChild("BP_CreatureSpawner.BP_CreatureSpawner_C", false);
32+
if (animalSpawners == null)
33+
{
34+
MessageBox.Show("This save does not contain animals or it is corrupt.", "Cannot find animals", MessageBoxButton.OK, MessageBoxImage.Error);
35+
return false;
36+
}
37+
38+
float offset = -50000;
39+
var hostPlayerModel = rootItem.FindChild("Char_Player.Char_Player_C", false);
40+
if (hostPlayerModel == null || hostPlayerModel.Items.Count < 1)
41+
{
42+
MessageBox.Show("This save does not contain a host player or it is corrupt.", "Cannot find host player", MessageBoxButton.OK, MessageBoxImage.Error);
43+
return false;
44+
}
45+
Vector3 playerPosition = ((SaveEntityModel)hostPlayerModel.Items[0]).Position;
46+
47+
foreach (SaveObjectModel animalSpawner in animalSpawners.DescendantSelfViewModel)
48+
{
49+
var probablyEdited = ((SaveEntityModel)animalSpawner).Position.Z < -14200f;
50+
51+
// Some crab hatchers are marked as CreatureSpawner instead of EnemySpawner and there is no other trace of the difference between enemy and friendly in the savefile
52+
//if (animalSpawner.Title.ToLower().Contains("enemy"))
53+
//{
54+
if (probablyEdited)
55+
((SaveEntityModel)animalSpawner).Position.Z -= offset; // Move the spawn under the map
56+
57+
animalSpawner.FindField("mSpawnData", (ArrayPropertyViewModel arrayProperty) =>
58+
{
59+
foreach (StructPropertyViewModel elem in arrayProperty.Elements)
60+
{
61+
if (probablyEdited)
62+
((Vector)((StructProperty)((DynamicStructDataViewModel)elem.StructData).Fields[0].Model).Data).Data.Z -= offset; // Move the spawn point under the map
63+
64+
// Set WasKilled to true so they don't respawn after deleting them
65+
((BoolPropertyViewModel)((DynamicStructDataViewModel)elem.StructData).Fields[2]).Value = false;
66+
// Set KilledOnDayNumber to a huge number (some far away animals respawn if the number is too small)
67+
((IntPropertyViewModel)((DynamicStructDataViewModel)elem.StructData).Fields[3]).Value = (int)0;
68+
}
69+
});
70+
}
71+
72+
return true;
73+
}
74+
}
75+
}

SatisfactorySaveEditor/SatisfactorySaveEditor.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<Compile Include="Cheats\CouponChangerCheat.cs" />
118118
<Compile Include="Cheats\CrateSummonCheat.cs" />
119119
<Compile Include="Cheats\EverythingBoxCheat.cs" />
120+
<Compile Include="Cheats\UndoDeleteEnemiesCheat.cs" />
120121
<Compile Include="Cheats\ICheat.cs" />
121122
<Compile Include="Cheats\DeleteEnemiesCheat.cs" />
122123
<Compile Include="Cheats\KillPlayersCheat.cs" />
@@ -425,4 +426,4 @@
425426
del "$(TargetDir)SatisfactorySave*.xml", "$(TargetDir)SatisfactorySave*.pdb"
426427
)</PostBuildEvent>
427428
</PropertyGroup>
428-
</Project>
429+
</Project>

SatisfactorySaveEditor/ViewModel/MainViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public MainViewModel()
146146
CheatMenuItems.Add(new CouponChangerCheat());
147147
DeleteEnemiesCheat deleteEnemiesCheat = new DeleteEnemiesCheat();
148148
CheatMenuItems.Add(deleteEnemiesCheat);
149+
CheatMenuItems.Add(new UndoDeleteEnemiesCheat());
149150
CheatMenuItems.Add(new SpawnDoggoCheat(deleteEnemiesCheat));
150151
CheatMenuItems.Add(new MassDismantleCheat());
151152
CheatMenuItems.Add(new EverythingBoxCheat());

0 commit comments

Comments
 (0)