Skip to content

Commit

Permalink
Synced all research tab buttons, fixes rwmt#290
Browse files Browse the repository at this point in the history
This should sync stop research, dev finish now, and dev apply techprints. This required a sync worker delegate for `ResearchManager` to work.

I've left the current syncing for selecting research by using `MainTabWindow_Research.DoBeginResearch`, and made `ResearchManager.SetCurrentProject` debug-only. I've done this due to `ResearchManager.SetCurrentProject` being called by "Dev: Finish now" button, which would allow anyone without ability to execute debug-only methods to change their active research to any possible research, ignoring any prerequisites.

Alternative approach to this would be to drop the current sync method and make `ResearchManager.SetCurrentProject` synced normally, and then applying a Harmony patch to it which would check if the selected research is valid (and prevent it from being executed if not allowed).
  • Loading branch information
SokyranTheDragon committed Aug 21, 2024
1 parent f0221d0 commit 2254d2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Source/Client/Syncing/Dict/SyncDictRimWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,10 @@ public static class SyncDictRimWorld
}
}, true // implicit
},
{
(ByteWriter _, ResearchManager _) => { },
(ByteReader _) => Find.ResearchManager
},
#endregion

#region Areas
Expand Down
9 changes: 9 additions & 0 deletions Source/Client/Syncing/Game/SyncMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public static void Init()
SyncMethod.Register(typeof(AreaManager), nameof(AreaManager.TryMakeNewAllowed));
SyncMethod.Register(typeof(MainTabWindow_Research), nameof(MainTabWindow_Research.DoBeginResearch))
.TransformTarget(Serializer.SimpleReader(() => new MainTabWindow_Research()));
SyncMethod.Register(typeof(ResearchManager), nameof(ResearchManager.StopProject));
// ResearchManager.SetCurrentProject changes the current project and is synced by
// MainTabWindow_Research.DoBeginResearch. It will still be called when selecting
// "Debug: Finish now". The issue with this is that when triggered by a player who
// can't execute debug-only methods it may change the current project to a research
// project which cannot be research due to prerequisites, allowing to research them.
SyncMethod.Register(typeof(ResearchManager), nameof(ResearchManager.SetCurrentProject)).SetDebugOnly();
SyncMethod.Register(typeof(ResearchManager), nameof(ResearchManager.FinishProject)).SetDebugOnly();
SyncMethod.Register(typeof(ResearchManager), nameof(ResearchManager.ApplyTechprint)).SetDebugOnly();

SyncMethod.Register(typeof(DrugPolicyDatabase), nameof(DrugPolicyDatabase.MakeNewDrugPolicy));
SyncMethod.Register(typeof(DrugPolicyDatabase), nameof(DrugPolicyDatabase.TryDelete)).CancelIfAnyArgNull();
Expand Down

0 comments on commit 2254d2e

Please sign in to comment.