Skip to content

Commit

Permalink
almost there update
Browse files Browse the repository at this point in the history
  • Loading branch information
rheirman committed Oct 24, 2022
1 parent 886be32 commit 8435462
Show file tree
Hide file tree
Showing 46 changed files with 31,544 additions and 0 deletions.
Binary file added 1.4/Assemblies/AlmostThere.dll
Binary file not shown.
165 changes: 165 additions & 0 deletions 1.4/Source/AlmostThere/AlmostThere.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?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>{EB0FDC31-0570-42FC-A3C9-3E9248B62858}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AlmostThere</RootNamespace>
<AssemblyName>AlmostThere</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</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>
<Prefer32Bit>false</Prefer32Bit>
</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>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.2.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Lib.Harmony.2.2.2\lib\net472\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HugsLib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\UnlimitedHugs.Rimworld.HugsLib.10.0.1\lib\net472\HugsLib.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TerrainPhysicsModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.TerrainPhysicsModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TextCoreModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.TextCoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TilemapModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.TilemapModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TLSModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.TLSModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UIElementsModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UIElementsModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UIModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UmbraModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UmbraModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UNETModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UNETModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityAnalyticsModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UnityAnalyticsModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityConnectModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UnityConnectModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityTestProtocolModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UnityTestProtocolModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestAssetBundleModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UnityWebRequestAssetBundleModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestAudioModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UnityWebRequestAudioModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestTextureModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UnityWebRequestTextureModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestWWWModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.UnityWebRequestWWWModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.VehiclesModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.VehiclesModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.VFXModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.VFXModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.VideoModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.VideoModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.VRModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.VRModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.WindModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.WindModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.XRModule">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.XRModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Base.cs" />
<Compile Include="Harmony\Caravan.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Storage\ExtendedDataStorage.cs" />
<Compile Include="Storage\ExtendedCaravanData.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions 1.4/Source/AlmostThere/AlmostThere.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.30104.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlmostThere", "AlmostThere.csproj", "{EB0FDC31-0570-42FC-A3C9-3E9248B62858}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EB0FDC31-0570-42FC-A3C9-3E9248B62858}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB0FDC31-0570-42FC-A3C9-3E9248B62858}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB0FDC31-0570-42FC-A3C9-3E9248B62858}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB0FDC31-0570-42FC-A3C9-3E9248B62858}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {98B38534-D9C2-4DF7-BE94-EE3833EC6B51}
EndGlobalSection
EndGlobal
47 changes: 47 additions & 0 deletions 1.4/Source/AlmostThere/Base.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using HugsLib;
using HugsLib.Utils;
using AlmostThere.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using HugsLib.Settings;

namespace AlmostThere
{
public class Base : ModBase
{
public override string ModIdentifier => "AlmostThere";
public static Base Instance { get; private set; }
private ExtendedDataStorage _extendedDataStorage;
internal static SettingHandle<int> almostThereHours;

public bool cachedResult = false;

public Base()
{
Instance = this;
}
public ExtendedDataStorage GetExtendedDataStorage()
{
return _extendedDataStorage;
}
public override void WorldLoaded()
{
if (_extendedDataStorage == null)
{
_extendedDataStorage = Find.World.GetComponent<ExtendedDataStorage>();
}
base.WorldLoaded();
}

public override void DefsLoaded()
{
almostThereHours = Settings.GetHandle<int>("AlmostThereHours", "AT_AlmostThereHours_Title".Translate(), "AT_AlmostThereHours_Description".Translate(), 4, Validators.IntRangeValidator(0, 1000));
base.DefsLoaded();
}
}


}
133 changes: 133 additions & 0 deletions 1.4/Source/AlmostThere/Harmony/Caravan.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using AlmostThere;
using AlmostThere.Storage;
using HarmonyLib;
using RimWorld;
using RimWorld.Planet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;

namespace AlmostThere.Harmony
{
[HarmonyPatch(typeof(Caravan), "get_NightResting")]
class Caravan_get_NightResting
{
static void Postfix(Caravan __instance, ref bool __result)
{
if (!__instance.IsHashIntervalTick(60))
{
__result = Base.Instance.cachedResult;
return;
}
if(Base.Instance.GetExtendedDataStorage() is ExtendedDataStorage store)
{
if (store.GetExtendedDataFor(__instance) is ExtendedCaravanData data)
{
if (data.forceRest)
{
__result = true;

}
if (data.fullyIgnoreRest)
{
__result = false;
}
if (data.almostThere)
{
var estimatedTicks = (float)CaravanArrivalTimeEstimator.EstimatedTicksToArrive(__instance, allowCaching: true);
var restTicksLeft = CaravanNightRestUtility.LeftRestTicksAt(__instance.Tile, Find.TickManager.TicksAbs);
estimatedTicks -= restTicksLeft;
if (estimatedTicks/GenDate.TicksPerHour < Base.almostThereHours.Value)
{
__result = false;
}
}
}
}
Base.Instance.cachedResult = __result;
}
}


[HarmonyPatch(typeof(Caravan), "GetGizmos")]
class Caravan_GetGizmos
{
static void Postfix(Caravan __instance, ref IEnumerable<Gizmo> __result)
{
var gizmoList = __result.ToList();
var store = Base.Instance.GetExtendedDataStorage();
var caravanData = store.GetExtendedDataFor(__instance);
if(__instance.Faction == Faction.OfPlayer)
{
if(caravanData != null)
{
gizmoList.Add(CreateAlmostThereCommand(__instance, caravanData));
gizmoList.Add(CreateIgnoreRestCommand(__instance, caravanData));
gizmoList.Add(CreateForceRestCommand(__instance, caravanData));
}
}
__result = gizmoList;
}

private static Command_Toggle CreateIgnoreRestCommand(Caravan __instance, ExtendedCaravanData caravanData)
{
Command_Toggle command_Toggle = new Command_Toggle();
command_Toggle.isActive = (() => caravanData.fullyIgnoreRest);
command_Toggle.toggleAction = delegate
{
caravanData.fullyIgnoreRest = !caravanData.fullyIgnoreRest;
if (caravanData.fullyIgnoreRest)
{
caravanData.forceRest = false;
caravanData.almostThere = false;
}
};
command_Toggle.defaultDesc = "AT_Command_DontRest_Description".Translate();
command_Toggle.icon = ContentFinder<Texture2D>.Get(("UI/" + "DontRest"), true);
command_Toggle.defaultLabel = "AT_Command_DontRest_Label".Translate();
return command_Toggle;
}
private static Command_Toggle CreateAlmostThereCommand(Caravan __instance, ExtendedCaravanData caravanData)
{
Command_Toggle command_Toggle = new Command_Toggle();
command_Toggle.isActive = (() => caravanData.almostThere);
command_Toggle.toggleAction = delegate
{
caravanData.almostThere = !caravanData.almostThere;
if (caravanData.almostThere)
{
caravanData.forceRest = false;
caravanData.fullyIgnoreRest = false;
}
};
command_Toggle.defaultDesc = "AT_Command_AlmostThere_Description".Translate(Base.almostThereHours.Value);
command_Toggle.icon = ContentFinder<Texture2D>.Get(("UI/" + "AlmostThere"), true);
command_Toggle.defaultLabel = "AT_Command_AlmostThere_Label".Translate();
return command_Toggle;
}

private static Command_Toggle CreateForceRestCommand(Caravan __instance, ExtendedCaravanData caravanData)
{
Command_Toggle command_Toggle = new Command_Toggle();
command_Toggle.isActive = (() => caravanData.forceRest);
command_Toggle.toggleAction = delegate
{
caravanData.forceRest = !caravanData.forceRest;
if (caravanData.forceRest)
{
caravanData.almostThere = false;
caravanData.fullyIgnoreRest = false;
}
};
command_Toggle.defaultDesc = "AT_Command_ForceRest_Description".Translate();
command_Toggle.icon = ContentFinder<Texture2D>.Get(("UI/" + "ForceRest"), true);
command_Toggle.defaultLabel = "AT_Command_ForceRest_Title".Translate();
return command_Toggle;
}
}

}
Loading

0 comments on commit 8435462

Please sign in to comment.