Skip to content

Commit

Permalink
Add 1.5 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVillageGuy committed Aug 16, 2024
1 parent 50d3ef7 commit e1cbd87
Show file tree
Hide file tree
Showing 29 changed files with 416 additions and 0 deletions.
Binary file not shown.
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")]
Binary file not shown.
Binary file not shown.
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")]
Binary file not shown.
Binary file not shown.
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")]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"RootPath":"C:\\Users\\Michael\\Source\\Repos\\better-bed-assignment\\1.5\\Source\\BetterBedAssign","ProjectFileName":"BetterBedAssign.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"AssignDialogSearchBar.cs"},{"SourceFile":"Mod.cs"},{"SourceFile":"Properties\\AssemblyInfo.cs"},{"SourceFile":"obj\\Debug\\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs"}],"References":[{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\Microsoft.CSharp.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\mscorlib.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\System.Core.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\System.Data.DataSetExtensions.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\System.Data.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\System.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\System.Net.Http.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\System.Xml.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.2\\System.Xml.Linq.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""}],"Analyzers":[],"Outputs":[{"OutputItemFullPath":"C:\\Users\\Michael\\Source\\Repos\\better-bed-assignment\\1.5\\Assemblies\\BetterBedAssign.dll","OutputItemRelativePath":"BetterBedAssign.dll"},{"OutputItemFullPath":"C:\\Users\\Michael\\Source\\Repos\\better-bed-assignment\\1.5\\Assemblies\\BetterBedAssign.pdb","OutputItemRelativePath":"BetterBedAssign.pdb"}],"CopyToOutputEntries":[]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\Michael\\source\\repos\\better-bed-assignment\\1.5\\Source\\BetterBedAssign\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}|BetterBedAssign.csproj|c:\\users\\michael\\source\\repos\\better-bed-assignment\\1.5\\source\\betterbedassign\\mod.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}|BetterBedAssign.csproj|solutionrelative:mod.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}|BetterBedAssign.csproj|C:\\Users\\Michael\\source\\repos\\better-bed-assignment\\1.5\\Source\\BetterBedAssign\\assigndialogsearchbar.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}|BetterBedAssign.csproj|solutionrelative:assigndialogsearchbar.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 2,
"Children": [
{
"$type": "Bookmark",
"Name": "ST:128:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "AssignDialogSearchBar.cs",
"DocumentMoniker": "C:\\Users\\Michael\\source\\repos\\better-bed-assignment\\1.5\\Source\\BetterBedAssign\\AssignDialogSearchBar.cs",
"RelativeDocumentMoniker": "AssignDialogSearchBar.cs",
"ToolTip": "C:\\Users\\Michael\\source\\repos\\better-bed-assignment\\1.5\\Source\\BetterBedAssign\\AssignDialogSearchBar.cs",
"RelativeToolTip": "AssignDialogSearchBar.cs",
"ViewState": "AQIAACoAAAAAAAAAAAAUwEUAAAAiAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-08-16T13:49:30.685Z"
},
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "Mod.cs",
"DocumentMoniker": "C:\\Users\\Michael\\source\\repos\\better-bed-assignment\\1.5\\Source\\BetterBedAssign\\Mod.cs",
"RelativeDocumentMoniker": "Mod.cs",
"ToolTip": "C:\\Users\\Michael\\source\\repos\\better-bed-assignment\\1.5\\Source\\BetterBedAssign\\Mod.cs",
"RelativeToolTip": "Mod.cs",
"ViewState": "AQIAAAAAAAAAAAAAAAAAABEAAAAJAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-08-16T13:49:30.869Z",
"EditorCaption": ""
}
]
}
]
}
]
}
106 changes: 106 additions & 0 deletions 1.5/Source/BetterBedAssign/AssignDialogSearchBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using HarmonyLib;
using RimWorld;
using RimWorld.Planet;
using UnityEngine;
using Verse;

namespace BetterBedAssign;

public class AssignDialogSearchBar
{
private static readonly QuickSearchWidget searchWidget = new();

public static void DoPatches(Harmony harm)
{
harm.Patch(AccessTools.Method(typeof(Dialog_AssignBuildingOwner), "DoWindowContents"),
transpiler: new HarmonyMethod(typeof(AssignDialogSearchBar), nameof(Transpiler)));
}

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var codes = instructions.ToList();
var info1 = AccessTools.PropertySetter(typeof(Rect), nameof(Rect.width));
var idx1 = codes.FindIndex(ins => ins.Calls(info1));
codes.InsertRange(idx1 + 1, new[]
{
new CodeInstruction(OpCodes.Ldloca, 0),
CodeInstruction.Call(typeof(AssignDialogSearchBar), nameof(RenderSearchBar))
});
var idx2 = codes.FindIndex(ins => ins.opcode == OpCodes.Stloc_S && ins.operand is LocalBuilder { LocalIndex: 31 });
codes.InsertRange(idx2 + 1, new[]
{
new CodeInstruction(OpCodes.Ldloca, 29),
new CodeInstruction(OpCodes.Ldloca, 28),
new CodeInstruction(OpCodes.Ldloc, 25),
CodeInstruction.LoadField(AccessTools.Inner(typeof(Dialog_AssignBuildingOwner), "<>c__DisplayClass12_0"), "pawn"),
new CodeInstruction(OpCodes.Ldarg_0),
CodeInstruction.LoadField(typeof(Dialog_AssignBuildingOwner), "assignable"),
new CodeInstruction(OpCodes.Ldarg_0),
CodeInstruction.Call(typeof(AssignDialogSearchBar), nameof(DoAssignDouble))
});
var info2 = AccessTools.PropertyGetter(typeof(CompAssignableToPawn), nameof(CompAssignableToPawn.AssignedPawnsForReading));
var info3 = AccessTools.PropertyGetter(typeof(CompAssignableToPawn), nameof(CompAssignableToPawn.AssigningCandidates));
foreach (var code in codes)
{
yield return code;
if (code.Calls(info3) || code.Calls(info2))
{
yield return CodeInstruction.Call(typeof(AssignDialogSearchBar), nameof(Check));
if (code.Calls(info2)) yield return CodeInstruction.Call(typeof(Enumerable), nameof(Enumerable.ToList), generics: new[] { typeof(Pawn) });
}
}
}


public static void DoAssignDouble(ref RectDivider buttonRect, ref RectDivider parentRect, Pawn pawn, CompAssignableToPawn catp,
Dialog_AssignBuildingOwner dialog)
{
var rel = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(pawn, false);
var lover = rel?.otherPawn;
if (catp.Props.maxAssignedPawnsCount >= 2 && lover != null && lover.IsColonist && !lover.IsWorldPawn() &&
lover.relations.everSeenByPlayer && pawn.relations.OpinionOf(lover) > 0)
{
var rect1 = parentRect.NewCol(95f, HorizontalJustification.Right).Rect;
var rect2 = buttonRect.NewCol(buttonRect.Rect.width * 0.5f).Rect;
var rect3 = new Rect
{
xMin = rect1.xMin,
yMin = rect1.yMin,
xMax = rect2.xMax,
yMax = rect2.yMax
};
if (Widgets.ButtonText(rect3, "BBA.AssignWith".Translate(rel.def.label)))
{
catp.TryAssignPawn(pawn);
catp.TryAssignPawn(lover);
if (catp.Props.maxAssignedPawnsCount == 2) dialog.Close();
}
}
}

public static void RenderSearchBar(ref Rect inRect)
{
if (KeyBindingDefOf.Cancel.IsDownEvent && searchWidget.CurrentlyFocused())
{
searchWidget.Reset();
searchWidget.Unfocus();
Event.current.Use();
}
else if (Event.current.type == EventType.KeyDown && !searchWidget.CurrentlyFocused()) searchWidget.Focus();

var rect = new Rect(inRect.x + 5f, inRect.y, inRect.width - 5f, 20f);
inRect.yMin += 20f;
searchWidget.OnGUI(rect);
inRect.yMin += 5f;
Widgets.DrawLineHorizontal(inRect.x, inRect.y, inRect.width);
inRect.yMin += 5f;
}

public static IEnumerable<Pawn> Check(IEnumerable<Pawn> pawns)
{
return pawns.Where(p => searchWidget.filter.Matches(p.LabelCap));
}
}
71 changes: 71 additions & 0 deletions 1.5/Source/BetterBedAssign/BetterBedAssign.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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>{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BetterBedAssign</RootNamespace>
<AssemblyName>BetterBedAssign</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</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>
<LangVersion>latest</LangVersion>
</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>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\workshop\content\294100\2009463077\Current\Assemblies\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<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.CoreModule">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AssignDialogSearchBar.cs" />
<Compile Include="Mod.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
7 changes: 7 additions & 0 deletions 1.5/Source/BetterBedAssign/BetterBedAssign.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files %28x86%29\Steam\steamapps\common\RimWorld\RimWorldWin64.exe</StartProgram>
</PropertyGroup>
</Project>
25 changes: 25 additions & 0 deletions 1.5/Source/BetterBedAssign/BetterBedAssign.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.31005.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterBedAssign", "BetterBedAssign.csproj", "{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CECDAF9F-200B-4F66-BDEF-C5A47AE77874}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {778F17E9-C549-42AF-AD62-699B9A2FCD28}
EndGlobalSection
EndGlobal
78 changes: 78 additions & 0 deletions 1.5/Source/BetterBedAssign/Mod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using HarmonyLib;
using RimWorld;
using UnityEngine;
using Verse;

namespace BetterBedAssign
{
public class BetterBedAssignMod : Mod
{
public static MethodInfo ShouldShowAssignmentGizmo;

public static Harmony Harm;

public BetterBedAssignMod(ModContentPack content) : base(content)
{
Harm = new Harmony("tvg.BetterBedAssign");
Harm.Patch(AccessTools.Method(typeof(FloatMenuMakerMap), "AddHumanlikeOrders"),
postfix: new HarmonyMethod(GetType(), nameof(AddOwnerAssign)));
Harm.Patch(AccessTools.Method(typeof(CompAssignableToPawn), "CompGetGizmosExtra"),
postfix: new HarmonyMethod(GetType(), nameof(AddGizmos)));
ShouldShowAssignmentGizmo = AccessTools.Method(typeof(CompAssignableToPawn), "ShouldShowAssignmentGizmo");
AssignDialogSearchBar.DoPatches(Harm);
}

public static void AddOwnerAssign(Vector3 clickPos, Pawn pawn, List<FloatMenuOption> opts)
{
var c = IntVec3.FromVector3(clickPos);
foreach (var thing in c.GetThingList(pawn.Map))
if (thing.TryGetComp<CompAssignableToPawn>() is CompAssignableToPawn catp &&
catp.AssigningCandidates.Contains(pawn))
{
var res = catp.CanAssignTo(pawn);
var text = (catp.AssignedAnything(pawn)
? "BuildingReassign".Translate()
: "BuildingAssign".Translate()) + " " + "BBA.To".Translate(pawn, thing);
opts.Add(res.Accepted
? new FloatMenuOption(text, () => catp.TryAssignPawn(pawn))
: new FloatMenuOption(text + " (" + res.Reason.StripTags() + ")", null));
}
}

public static IEnumerable<Gizmo> AddGizmos(IEnumerable<Gizmo> gizmos, CompAssignableToPawn __instance)
{
foreach (var gizmo in gizmos) yield return gizmo;

if (__instance.AssignedPawns.Any() && (bool)ShouldShowAssignmentGizmo.Invoke(__instance, null))
yield return new Command_Action
{
defaultLabel = "BuildingUnassign".Translate() + " " + "BBA.All".Translate(),
icon = ContentFinder<Texture2D>.Get("UI/UnassignAll"),
activateSound = SoundDefOf.Click,
action = () =>
{
var pawns = __instance.AssignedPawns.ToList();
foreach (var pawn in pawns) __instance.TryUnassignPawn(pawn);
}
};

if (__instance.AssignedPawns.Any())
foreach (var pawn in __instance.AssignedPawns)
yield return new Command_Action
{
defaultLabel = "BBA.GoTo".Translate(pawn),
icon = ContentFinder<Texture2D>.Get("UI/GoToOwner"),
activateSound = SoundDefOf.Click,
action = () =>
{
Find.Selector.ClearSelection();
Find.Selector.Select(pawn);
Find.CameraDriver.JumpToCurrentMapLoc(pawn.Position);
}
};
}
}
}
Loading

0 comments on commit e1cbd87

Please sign in to comment.