From 3ec02a11fb1bc72fad4027d89ed3ae4066de78e6 Mon Sep 17 00:00:00 2001 From: T3M8029 <102697658+T3M8029@users.noreply.github.com> Date: Sat, 3 May 2025 18:59:17 +0200 Subject: [PATCH 1/2] Update to make mod work on B99.4. --- Patch.cs | 11 +++ RadioJobControl.cs | 8 +- dvRadioJobControl.csproj | 179 +++++++++++++++++++++++++++------------ 3 files changed, 139 insertions(+), 59 deletions(-) diff --git a/Patch.cs b/Patch.cs index 4ebc275..79966f1 100644 --- a/Patch.cs +++ b/Patch.cs @@ -75,4 +75,15 @@ static void Postfix(CommsRadioController __instance, List ___al ___allModes.Add(jobControl); } } + + //set booklet distance slightly smaller than job distance to ensure the booklets exist no matter where in the station the player is, so the mod can accept a job + [HarmonyPatch(typeof(StationJobGenerationRange), "Awake")] + public static class StationJobGenerationRange_Awake_Patch + { + static void Postfix(StationJobGenerationRange __instance) + { + __instance.jobOverviewBookletGenerationSqrDistance = 249000f; + } + } + } diff --git a/RadioJobControl.cs b/RadioJobControl.cs index b949d6d..729e543 100644 --- a/RadioJobControl.cs +++ b/RadioJobControl.cs @@ -137,7 +137,7 @@ public void OnUse() if (PointedCar != null) { CommsRadioController.PlayAudioFromRadio(selectedCarSound, transform); SetState(State.SelectCar); - Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar); + Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar.logicCar); if (jobOfCar == null) { selectedAction = PersistentJobsInstalled ? Act.reassign : Act.exit; } else { @@ -148,7 +148,7 @@ public void OnUse() break; case State.SelectCar: if (PointedCar != null) { - Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar); + Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar.logicCar); switch (selectedAction) { case Act.accept: @@ -229,7 +229,7 @@ private void UpdateDisplay() string displayText = "manage jobs remotely"; if (PointedCar != null) { displayText = "Car: " + PointedCar.ID.ToString(); - Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar); + Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar.logicCar); if (jobOfCar != null) { displayText += "\nJob: " + jobOfCar.ID.ToString() + "\nState: " + jobOfCar.State.ToString(); @@ -251,7 +251,7 @@ private void UpdateDisplay() } private bool IsValidAction(Act action) { - bool hasJob = PointedCar != null && SingletonBehaviour.Instance.GetJobOfCar(PointedCar) != null; + bool hasJob = PointedCar != null && SingletonBehaviour.Instance.GetJobOfCar(PointedCar.logicCar) != null; switch (action) { case Act.reassign: return !hasJob && PersistentJobsInstalled; diff --git a/dvRadioJobControl.csproj b/dvRadioJobControl.csproj index 48d42a8..a455780 100644 --- a/dvRadioJobControl.csproj +++ b/dvRadioJobControl.csproj @@ -1,56 +1,125 @@ - - - - net48 - dvRadioJobControlMod - Disable Steam or Diesel for more immersion! - 0.2.0 - true - latest - dvRadioJobControl - E:\Steam\steamapps\common\Derail Valley\DerailValley_Data\Managed - - - - - $(AssemblySearchPaths); - $(ReferencePath); - - - - - enable - - - - - - - - - + + + + net481 + dvRadioJobControlMod + 0.2.0 + true + latest + dvRadioJobControl + + + + + $(AssemblySearchPaths); + $(ReferencePath); + $(DVInstallPath) + + + + + enable + + + + + + + + + + + + + + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + + + + + + - E:\Steam\SteamApps\common\Derail Valley\DerailValley_Data\Managed\Unity.TextMeshPro.dll - - - - - - - - - $(ReferencePath)\..\..\Mods\PersistentJobs\PersistentJobsMod.dll - - - - - - - - - - - - - - + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + + + + + + + + + + From 261cd2c404af63c17d5bef6c022896043fa8ab3a Mon Sep 17 00:00:00 2001 From: T3M8029 <102697658+T3M8029@users.noreply.github.com> Date: Sat, 2 May 2026 16:38:26 +0200 Subject: [PATCH 2/2] Add job validation, reserve tracks via PersJobs if installed --- RadioJobControl.cs | 17 ++++++++++++++++- dvRadioJobControl.csproj | 3 --- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/RadioJobControl.cs b/RadioJobControl.cs index 729e543..d8dea9e 100644 --- a/RadioJobControl.cs +++ b/RadioJobControl.cs @@ -2,11 +2,13 @@ using DV; using DV.Booklets; using DV.Logic.Job; +using DV.ServicePenalty; using DV.ThingTypes; using DV.Utils; using System.Collections.Generic; using System.Linq; using System.Reflection; +using Unity.Jobs; using UnityEngine; using UnityModManagerNet; @@ -152,7 +154,7 @@ public void OnUse() switch (selectedAction) { case Act.accept: - if (jobOfCar != null && jobOfCar.State == JobState.Available) { + if (IsValidJob(jobOfCar)) { CommsRadioController.PlayAudioFromRadio(confirmSound, transform); //SingletonBehaviour.Instance.TakeJob(jobOfCar, true); @@ -162,6 +164,7 @@ public void OnUse() List spawnedJobOverviews = (List)typeof(StationController).GetField("spawnedJobOverviews", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(startingStation); JobOverview jobOverview = spawnedJobOverviews.Find(jo => jo.job == jobOfCar); + if (PersistentJobsInstalled) PersistentJobsMod.HarmonyPatches.JobValidators.JobValidator_ProcessJobOverview_Patch.ReserveSpacePJ(jobOfCar, out bool shuntingJobOnWarehouseTrack); startingStation.TakeJobFromStation(jobOverview); BookletCreator.CreateJobBooklet(jobOfCar, valueTuple.Item1, valueTuple.Item2, (Transform)null); @@ -264,6 +267,18 @@ private bool IsValidAction(Act action) { return true; } + private bool IsValidJob(Job job) + { + if (job != null && job.State == JobState.Available) + { + if (SingletonBehaviour.Instance.currentJobs.Count >= SingletonBehaviour.Instance.GetNumberOfAllowedConcurrentJobs()) return false; + if (!SingletonBehaviour.Instance.IsLicensedForJob(JobLicenseType_v2.ToV2List(job.requiredLicenses))) return false; + if (!SingletonBehaviour.Instance.IsPlayerAllowedToTakeJob()) return false; + return true; + } + return false; + } + public bool ButtonACustomAction() { if (selectedAction != Act.complete) { diff --git a/dvRadioJobControl.csproj b/dvRadioJobControl.csproj index a455780..8380ad8 100644 --- a/dvRadioJobControl.csproj +++ b/dvRadioJobControl.csproj @@ -36,9 +36,6 @@ False - - False - False