commit 355844980a72cc3977bb71a211d3bbe853406ddc Author: CGFighter Date: Tue Jul 20 05:10:38 2021 +0300 1.0 diff --git a/1.3/Assemblies/ResearchWhatever.dll b/1.3/Assemblies/ResearchWhatever.dll new file mode 100644 index 0000000..2097a2e Binary files /dev/null and b/1.3/Assemblies/ResearchWhatever.dll differ diff --git a/About/About.xml b/About/About.xml new file mode 100644 index 0000000..1f7521c --- /dev/null +++ b/About/About.xml @@ -0,0 +1,19 @@ + + + Research Whatever + avilmask + +
  • 1.2
  • +
  • 1.3
  • +
    + none + avilmask.ResearchWhatever + +
  • + brrainz.harmony + Harmony + steam://url/CommunityFilePage/2009463077 +
  • +
    + When research subject is not selected, pawns just choose the cheapest one on their own. This option is accessible from research bench. +
    \ No newline at end of file diff --git a/About/preview.png b/About/preview.png new file mode 100644 index 0000000..621fe57 Binary files /dev/null and b/About/preview.png differ diff --git a/Languages/English/Keyed/strings.xml b/Languages/English/Keyed/strings.xml new file mode 100644 index 0000000..c7bbe76 --- /dev/null +++ b/Languages/English/Keyed/strings.xml @@ -0,0 +1,8 @@ + + + Research whatever + Active - colonists will choose something to research on their own. + Inactive - colonists will not choose something to research on their own. + {0} has nothing left to research + {0} have started a new research: {1} + diff --git a/README.md b/README.md new file mode 100644 index 0000000..bd02d1d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# RimWorld_AnimalControls + +Research Whatever - is a mod for videogame RimWorld. diff --git a/Source/ResearchWhatever13/Patches/StaticConstructorOnStartupUtilityPatch.cs b/Source/ResearchWhatever13/Patches/StaticConstructorOnStartupUtilityPatch.cs new file mode 100644 index 0000000..2deb420 --- /dev/null +++ b/Source/ResearchWhatever13/Patches/StaticConstructorOnStartupUtilityPatch.cs @@ -0,0 +1,46 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using Verse; +using HarmonyLib; +using System.Reflection; +using RimWorld; + + +namespace ResearchWhatever +{ + public static class StaticConstructorOnStartupUtility_Patch + { + //[HarmonyPatch(typeof(StaticConstructorOnStartupUtility), "CallAll")] + [HarmonyPatch] + static class StaticConstructorOnStartupUtility_CallAll_NonUnoPinataPatch + { + internal static MethodBase TargetMethod() + { + MethodBase LCallAll = AccessTools.Method("BetterLoading.Stage.InitialLoad.StageRunStaticCctors:PreCallAll"); + if (LCallAll == null) + { + LCallAll = AccessTools.Method("Verse.StaticConstructorOnStartupUtility:CallAll"); + if (LCallAll == null) + throw new Exception("Couldn't find StaticConstructorOnStartupUtility.CallAll()"); + } + else + Log.Message("[ResearchWhatever] BetterLoading detected, workaround initiated"); + return LCallAll; + } + // + static void Postfix() + { + List list = new List( + from x in DefDatabase.AllDefsListForReading + where x.thingClass == typeof(Building_ResearchBench) || x.thingClass.IsSubclassOf(typeof(Building_ResearchBench)) + select x); + + foreach (var thing in list) + { + thing?.comps.Add(new CompProperties(typeof(ResearchWhateverComp))); + } + } + } + } +} diff --git a/Source/ResearchWhatever13/Patches/WorkGiver_ResearcherPatch.cs b/Source/ResearchWhatever13/Patches/WorkGiver_ResearcherPatch.cs new file mode 100644 index 0000000..efcebbd --- /dev/null +++ b/Source/ResearchWhatever13/Patches/WorkGiver_ResearcherPatch.cs @@ -0,0 +1,84 @@ +using System.Linq; +using System.Collections.Generic; +using HarmonyLib; +using RimWorld; +using Verse; +using Verse.Sound; + +namespace ResearchWhatever.Patches +{ + [HarmonyPatch(typeof(WorkGiver_Researcher), "ShouldSkip")] + static class WorkGiver_Researcher_ShouldSkip_ResearchWhateverPatch + { + static bool Prefix(ref bool __result) + { + __result = false; + //Log.Message($"ShouldSkip={__result}"); + return false; + } + } + + [HarmonyPatch(typeof(WorkGiver_Researcher), "PotentialWorkThingRequest", MethodType.Getter)] + static class WorkGiver_PotentialWorkThingRequest_ResearchWhateverPatch + { + static bool Prefix(ref ThingRequest __result) + { + __result = ThingRequest.ForGroup(ThingRequestGroup.ResearchBench); + return false; + } + } + + [HarmonyPatch(typeof(WorkGiver_Researcher), "HasJobOnThing")] + static class WorkGiver_Researcher_HasJobOnThing_ResearchWhateverPatch + { + private static bool hasFacilities(this Building_ResearchBench bench, List requiredFacilities) + { + if (requiredFacilities.NullOrEmpty()) return true; + CompAffectedByFacilities comp = bench.TryGetComp(); + if (comp == null) return false; + + foreach (var rf in requiredFacilities) + if (comp.LinkedFacilitiesListForReading.FirstOrDefault(x => x.def == rf && comp.IsFacilityActive(x)) == null) + return false; + + return true; + } + + static void Prefix(Pawn pawn, Thing t, bool forced) + { + + ResearchProjectDef currentProj = Find.ResearchManager.currentProj; + if (currentProj != null) return; + Building_ResearchBench bench = t as Building_ResearchBench; + if (bench == null) return; + + ResearchWhateverComp comp = bench.TryGetComp(); + + if (comp == null || !comp.Active) return; + + List projects = new List( + from x in DefDatabase.AllDefsListForReading + where Find.Storyteller.difficulty.AllowedBy(x.hideWhen) + && !x.IsFinished + && x.TechprintRequirementMet + && x.PrerequisitesCompleted + && (x.requiredResearchBuilding == null || x.requiredResearchBuilding == bench.def && bench.hasFacilities(x.requiredResearchFacilities)) + select x); + + if (projects.NullOrEmpty()) + { + comp.Active = false; + Messages.Message("ResearchWhateverNothingLeftToResearch".Translate(bench.Label).CapitalizeFirst(), new TargetInfo(bench.Position, bench.Map, false), MessageTypeDefOf.NeutralEvent); + return; + } + projects.SortBy(x => x.CostApparent); + + ResearchProjectDef def = projects.First(); + projects.TryRandomElementByWeight(x => x.CostApparent == def.CostApparent ? 1f : 0f, out def); + SoundDefOf.ResearchStart.PlayOneShotOnCamera(null); + Find.ResearchManager.currentProj = def; + TutorSystem.Notify_Event("StartResearchProject"); + Messages.Message( "ResearchWhateverNewResearch".Translate(pawn.Name.ToStringFull, def.label).CapitalizeFirst(), new TargetInfo(bench.Position, bench.Map, false), MessageTypeDefOf.SilentInput); + } + } +} diff --git a/Source/ResearchWhatever13/ResearchWhatever.cs b/Source/ResearchWhatever13/ResearchWhatever.cs new file mode 100644 index 0000000..a196a80 --- /dev/null +++ b/Source/ResearchWhatever13/ResearchWhatever.cs @@ -0,0 +1,16 @@ +using HarmonyLib; +using System.Reflection; +using Verse; + +namespace ResearchWhatever +{ + [StaticConstructorOnStartup] + public class ResearchWhatever : Mod + { + public ResearchWhatever(ModContentPack content) : base(content) + { + var harmony = new Harmony("net.avilmask.rimworld.mod.ResearchWhatever"); + harmony.PatchAll(Assembly.GetExecutingAssembly()); + } + } +} diff --git a/Source/ResearchWhatever13/ResearchWhatever.csproj b/Source/ResearchWhatever13/ResearchWhatever.csproj new file mode 100644 index 0000000..2f75999 --- /dev/null +++ b/Source/ResearchWhatever13/ResearchWhatever.csproj @@ -0,0 +1,74 @@ + + + + + Debug + AnyCPU + {B08C8BAF-9849-4317-B2BE-639354820A7D} + Library + Properties + ResearchWhatever + ResearchWhatever + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\1.3\Assemblies\ + TRACE + prompt + 4 + + + + packages\Lib.Harmony.2.1.0\lib\net472\0Harmony.dll + False + + + ..\..\..\..\..\..\..\Games\steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll + False + + + + + + + + + + + ..\..\..\..\..\..\..\Games\steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.dll + False + + + ..\..\..\..\..\..\..\Games\steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll + False + + + ..\..\..\..\..\..\..\Games\steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.IMGUIModule.dll + False + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/ResearchWhatever13/ResearchWhatever.sln b/Source/ResearchWhatever13/ResearchWhatever.sln new file mode 100644 index 0000000..fc599ea --- /dev/null +++ b/Source/ResearchWhatever13/ResearchWhatever.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.1062 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResearchWhatever", "ResearchWhatever.csproj", "{B08C8BAF-9849-4317-B2BE-639354820A7D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B08C8BAF-9849-4317-B2BE-639354820A7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B08C8BAF-9849-4317-B2BE-639354820A7D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B08C8BAF-9849-4317-B2BE-639354820A7D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B08C8BAF-9849-4317-B2BE-639354820A7D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0D207634-209F-4992-A31F-77B17C0ED417} + EndGlobalSection +EndGlobal diff --git a/Source/ResearchWhatever13/ResearchWhateverComp.cs b/Source/ResearchWhatever13/ResearchWhateverComp.cs new file mode 100644 index 0000000..ba880e9 --- /dev/null +++ b/Source/ResearchWhatever13/ResearchWhateverComp.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using Verse; +using RimWorld; + +namespace ResearchWhatever +{ + public class ResearchWhateverComp : ThingComp + { + public bool Active + { + get + { + return active; + } + set + { + if (value == active) + { + return; + } + this.active = value; + } + } + + public override void PostExposeData() + { + Scribe_Values.Look(ref active, "active", true, false); + } + + public override IEnumerable CompGetGizmosExtra() + { + Command_Toggle command_Toggle = new Command_Toggle(); + command_Toggle.hotKey = KeyBindingDefOf.Command_TogglePower; + command_Toggle.defaultLabel = "CommandResearchWhateverToggleLabel".Translate(); + command_Toggle.icon = TexCommand.OpenLinkedQuestTex; + command_Toggle.isActive = (() => this.Active); + command_Toggle.toggleAction = delegate () + { + this.Active = !this.Active; + }; + if (this.Active) + { + command_Toggle.defaultDesc = "CommandResearchWhateverToggleDescActive".Translate(); + } + else + { + command_Toggle.defaultDesc = "CommandResearchWhateverToggleDescInactive".Translate(); + } + yield return command_Toggle; + yield break; + } + + private bool active = true; + } + +} diff --git a/change.log b/change.log new file mode 100644 index 0000000..20500b1 --- /dev/null +++ b/change.log @@ -0,0 +1,2 @@ +1.0.0 +- :T \ No newline at end of file