Skip to content

Commit

Permalink
1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bwiggins10 committed Oct 31, 2020
1 parent 2fccc13 commit 2795749
Show file tree
Hide file tree
Showing 66 changed files with 31,779 additions and 0 deletions.
19 changes: 19 additions & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<ModMetaData>
<name>Automatic Night Owl</name>
<author>Ben</author>
<supportedVersions>
<li>1.1</li>
<li>1.2</li>
</supportedVersions>
<packageId>ben.automaticnightowl</packageId>
<description>Automatically assigns the sleep schedule for pawns with the night owl trait.
</description>
<modDependencies>
<li>
<packageId>brrainz.harmony</packageId>
<displayName>Harmony</displayName>
<steamWorkshopUrl>steam://url/CommunityFilePage/2009463077</steamWorkshopUrl>
</li>
</modDependencies>
</ModMetaData>
Binary file added About/Preview.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions About/PublishedFileId.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2056012179
Binary file added Assemblies/AutomaticNightOwl.dll
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
87 changes: 87 additions & 0 deletions Source/AutomaticNightOwl/AutomaticNightOwl.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E6538693-ADAF-4C2C-A666-0281E61658AE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AutomaticNightOwl</RootNamespace>
<AssemblyName>AutomaticNightOwl</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Assemblies\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.0.9, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Lib.Harmony.2.0.0.9\lib\net472\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.NonGeneric, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Collections.NonGeneric.4.3.0\lib\net46\System.Collections.NonGeneric.dll</HintPath>
<Private>False</Private>
<Private>False</Private>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions Source/AutomaticNightOwl/AutomaticNightOwl.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomaticNightOwl", "AutomaticNightOwl.csproj", "{E6538693-ADAF-4C2C-A666-0281E61658AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E6538693-ADAF-4C2C-A666-0281E61658AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6538693-ADAF-4C2C-A666-0281E61658AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6538693-ADAF-4C2C-A666-0281E61658AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6538693-ADAF-4C2C-A666-0281E61658AE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BFE7A5F9-D29D-4A23-8067-EDF02E6F1E48}
EndGlobalSection
EndGlobal
116 changes: 116 additions & 0 deletions Source/AutomaticNightOwl/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using HarmonyLib;
using RimWorld;
using RimWorld.Planet;
using System;
using System.Collections.Generic;
using System.Reflection;
using Verse;

namespace AutomaticNightOwl
{
[StaticConstructorOnStartup]
public static class AutomaticNightOwl
{
private static void AutoNightOwl(Pawn pawn)
{
if (pawn?.story?.traits?.HasTrait(TraitDefOf.NightOwl) == true &&
pawn.timetable != null &&
!WorldComp.PawnsWithNightOwl.Contains(pawn))
{
pawn.timetable.times = new List<TimeAssignmentDef>(GenDate.HoursPerDay);
for (int i = 0; i < GenDate.HoursPerDay; i++)
{
TimeAssignmentDef setNightOwlHours = i >= 11 && i <= 18 ? TimeAssignmentDefOf.Sleep : TimeAssignmentDefOf.Anything;
pawn.timetable.times.Add(setNightOwlHours);
}
WorldComp.PawnsWithNightOwl.Add(pawn);
}
}

[HarmonyPatch(typeof(Thing), nameof(Thing.SpawnSetup))]
public static class Patch_Thing_SpawnSetup
{
public static void Postfix(Thing __instance)
{
if (__instance is Pawn p && p.Faction?.IsPlayer == true && p.def?.race?.Humanlike == true)
{
AutoNightOwl(p);
}
}
}

[HarmonyPatch(typeof(InteractionWorker_RecruitAttempt), nameof(InteractionWorker_RecruitAttempt.DoRecruit), new Type[] { typeof(Pawn), typeof(Pawn), typeof(float), typeof(string), typeof(string), typeof(bool), typeof(bool)}, new ArgumentType[] { ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Out, ArgumentType.Out, ArgumentType.Normal, ArgumentType.Normal })]
public static class Patch_InteractionWorker_RecruitAttempt
{
// Patching for recruited prisoners
public static void Postfix(Pawn recruiter, Pawn recruitee, float recruitChance)
{
if (recruitee is Pawn p && p.Faction?.IsPlayer == true && p.def?.race?.Humanlike == true)
{
AutoNightOwl(p);
}
}
}
static AutomaticNightOwl()
{
Harmony harmony = new Harmony("AutomaticNightOwl_Ben");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}

[DefOf]
public static class TraitDefOf
{
public static TraitDef NightOwl;
}
}

class WorldComp : WorldComponent
{
// Using a HashSet for quick lookup
public static HashSet<Pawn> PawnsWithNightOwl = new HashSet<Pawn>();
// I've found it easier to have a null list for use when exposing data
// This shouldn't be needed but mods will remove Pawns from the game completely (RuntimeGC for instance)
// and HashSet will fail if more than one null value is added.
private List<Pawn> usedForExposingData = null;

public WorldComp(World w) : base(w)
{
// Make sure the static HashSet is cleared whenever a game is created or loaded.
PawnsWithNightOwl.Clear();
}

public override void ExposeData()
{
base.ExposeData();
if (Scribe.mode == LoadSaveMode.Saving)
{
// When saving, populate the list
usedForExposingData = new List<Pawn>(PawnsWithNightOwl);
}

Scribe_Collections.Look(ref usedForExposingData, "pawnsWithNightOwl", LookMode.Reference);

if (Scribe.mode == LoadSaveMode.PostLoadInit)
{
// When loading, clear the HashSet then populate it with the loaded data
PawnsWithNightOwl.Clear();
foreach (var v in usedForExposingData)
{
// Remove any null records
if (v != null)
{
PawnsWithNightOwl.Add(v);
}
}
}

if (Scribe.mode == LoadSaveMode.Saving ||
Scribe.mode == LoadSaveMode.PostLoadInit)
{
// Add hints to the garbage collector that this memory can be collected
usedForExposingData?.Clear();
usedForExposingData = null;
}
}
}
}
35 changes: 35 additions & 0 deletions Source/AutomaticNightOwl/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AutoOwl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoOwl")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e6538693-adaf-4c2c-a666-0281e61658ae")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutoOwl\Assemblies\AutoOwl.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutoOwl\Source\AutoOwl\obj\Debug\AutoOwl.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutoOwl\Source\AutoOwl\obj\Debug\AutoOwl.csprojAssemblyReference.cache
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5ad072922e92a8d167d96af7bae12a4e1736af99
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutoOwl\Source\AutoOwl\obj\Debug\AutomaticNightOwl.csprojAssemblyReference.cache
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutoOwl\Assemblies\AutomaticNightOwl.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutoOwl\Source\AutoOwl\obj\Debug\AutomaticNightOwl.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutomaticNightOwl\Assemblies\AutomaticNightOwl.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutomaticNightOwl\Source\AutoOwl\obj\Debug\AutomaticNightOwl.csprojAssemblyReference.cache
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutomaticNightOwl\Source\AutoOwl\obj\Debug\AutomaticNightOwl.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutomaticNightOwl\Source\AutomaticNightOwl\obj\Debug\AutomaticNightOwl.csprojAssemblyReference.cache
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutomaticNightOwl\Source\AutomaticNightOwl\obj\Debug\AutomaticNightOwl.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AutomaticNightOwl\Source\AutomaticNightOwl\obj\Debug\AutomaticNightOwl.csproj.CoreCompileInputs.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions Source/AutomaticNightOwl/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Lib.Harmony" version="2.0.0.9" targetFramework="net472" />
<package id="System.Collections.NonGeneric" version="4.3.0" targetFramework="net472" />
</packages>
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Source/AutomaticNightOwl/packages/Lib.Harmony.2.0.0.9/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Andreas Pardeike

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 2795749

Please sign in to comment.