-
-
Notifications
You must be signed in to change notification settings - Fork 611
Add saving of cheats #7088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add saving of cheats #7088
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| using SharedBase.Archive; | ||
|
|
||
| /// <summary> | ||
| /// Serializable state of all cheats managed by <see cref="CheatManager"/> | ||
| /// </summary> | ||
| public class CheatManagerState : IArchivable | ||
| { | ||
| public const ushort SERIALIZATION_VERSION = 1; | ||
|
|
||
| public CheatManagerState() | ||
| { | ||
| } | ||
|
|
||
| public CheatManagerState(bool infiniteCompounds, bool godMode, bool noAI, bool unlimitedGrowthSpeed, | ||
| bool lockTime, bool manuallySetTime, float speed, bool infiniteMP, bool moveToAnyPatch, | ||
| float dayNightFraction) | ||
| { | ||
| InfiniteCompounds = infiniteCompounds; | ||
| GodMode = godMode; | ||
| NoAI = noAI; | ||
| UnlimitedGrowthSpeed = unlimitedGrowthSpeed; | ||
| LockTime = lockTime; | ||
| ManuallySetTime = manuallySetTime; | ||
| Speed = speed; | ||
| InfiniteMP = infiniteMP; | ||
| MoveToAnyPatch = moveToAnyPatch; | ||
| DayNightFraction = dayNightFraction; | ||
| } | ||
|
|
||
| public bool InfiniteCompounds { get; set; } | ||
| public bool GodMode { get; set; } | ||
| public bool NoAI { get; set; } | ||
| public bool UnlimitedGrowthSpeed { get; set; } | ||
| public bool LockTime { get; set; } | ||
| public bool ManuallySetTime { get; set; } | ||
| public float Speed { get; set; } = 1.0f; | ||
| public bool InfiniteMP { get; set; } | ||
| public bool MoveToAnyPatch { get; set; } | ||
| public float DayNightFraction { get; set; } | ||
|
|
||
| public ushort CurrentArchiveVersion => SERIALIZATION_VERSION; | ||
| public ArchiveObjectType ArchiveObjectType => (ArchiveObjectType)ThriveArchiveObjectType.CheatManagerState; | ||
| public bool CanBeReferencedInArchive => false; | ||
|
|
||
| public static CheatManagerState ReadFromArchive(ISArchiveReader reader, ushort version, int referenceId) | ||
| { | ||
| if (version is > SERIALIZATION_VERSION or <= 0) | ||
| throw new InvalidArchiveVersionException(version, SERIALIZATION_VERSION); | ||
|
|
||
| var instance = new CheatManagerState | ||
| { | ||
| InfiniteCompounds = reader.ReadBool(), | ||
| GodMode = reader.ReadBool(), | ||
| NoAI = reader.ReadBool(), | ||
| UnlimitedGrowthSpeed = reader.ReadBool(), | ||
| LockTime = reader.ReadBool(), | ||
| ManuallySetTime = reader.ReadBool(), | ||
| Speed = reader.ReadFloat(), | ||
| InfiniteMP = reader.ReadBool(), | ||
| MoveToAnyPatch = reader.ReadBool(), | ||
| DayNightFraction = reader.ReadFloat(), | ||
| }; | ||
|
|
||
| return instance; | ||
| } | ||
|
|
||
| public void WriteToArchive(ISArchiveWriter writer) | ||
| { | ||
| writer.Write(InfiniteCompounds); | ||
| writer.Write(GodMode); | ||
| writer.Write(NoAI); | ||
| writer.Write(UnlimitedGrowthSpeed); | ||
| writer.Write(LockTime); | ||
| writer.Write(ManuallySetTime); | ||
| writer.Write(Speed); | ||
| writer.Write(InfiniteMP); | ||
| writer.Write(MoveToAnyPatch); | ||
| writer.Write(DayNightFraction); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| uid://bdt6hwmh2mt8y |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| /// </summary> | ||
| public class GameProperties : IArchivable | ||
| { | ||
| public const int SERIALIZATION_VERSION = 2; | ||
| public const int SERIALIZATION_VERSION = 3; | ||
|
|
||
| private readonly Dictionary<string, bool> setBoolStatuses; | ||
|
|
||
|
|
@@ -47,6 +47,11 @@ private GameProperties(GameWorld gameWorld, TutorialState tutorialState, Diction | |
| /// </summary> | ||
| public bool CheatsUsed { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Holds the state of all cheats used in this game | ||
| /// </summary> | ||
| public CheatManagerState SavedCheats { get; set; } = new(); | ||
|
|
||
| /// <summary> | ||
| /// True when the player is currently ascended and should be allowed to do anything | ||
| /// </summary> | ||
|
|
@@ -324,6 +329,12 @@ public static GameProperties ReadFromArchive(ISArchiveReader reader, ushort vers | |
| if (version > 1) | ||
| instance.ThriveopediaData = reader.ReadObject<ThriveopediaGameData>(); | ||
|
|
||
| if (version > 2) | ||
| { | ||
| instance.SavedCheats = reader.ReadObject<CheatManagerState>(); | ||
| CheatManager.RestoreState(instance.SavedCheats); | ||
| } | ||
|
|
||
| return instance; | ||
| } | ||
|
|
||
|
|
@@ -345,6 +356,9 @@ public void WriteToArchive(ISArchiveWriter writer) | |
| // writer.WriteObject(TechWeb); | ||
|
|
||
| writer.WriteObject(ThriveopediaData); | ||
|
|
||
| SavedCheats = CheatManager.CaptureState(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this is also an unsafe assumption, so again the save capturing code should snapshot the cheats when it starts to make a save. |
||
| writer.WriteObject(SavedCheats); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,7 +176,6 @@ public partial class MainMenu : NodeWithInput | |
|
|
||
| public static void OnEnteringGame(bool cheatsUsed, bool freebuild) | ||
| { | ||
| CheatManager.OnCheatsDisabled(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is not safe to remove... at least I expect there to be a chance to "smuggle" cheat state into a save without getting marked as having cheated in the game. |
||
| SaveHelper.ClearLastSaveTime(); | ||
| LastPlayedVersion.MarkCurrentVersionAsPlayed(); | ||
| AchievementsManager.ReportNewGameStarted(cheatsUsed); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't apply here, there are situations to load a save's data without immediately loading it. So the cheats state should be reapplied in
InProgressLoadI think.