Skip to content

Commit

Permalink
feat: add support for Rimworld 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyvion committed May 4, 2024
1 parent a2cf340 commit 5cf2f3f
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ jobs:
RimWorldVersion: 1.5
run: dotnet build .vscode --configuration Release

- name: Build Mod for 1.4
env:
RimWorldVersion: 1.4
run: dotnet build .vscode --configuration Release

- name: Upload Mod Artifacts
uses: actions/upload-artifact@v4
with:
name: RealisticOrbitalTrade-${{ github.sha }}
path: |
About/
1.5/
1.4/
Common/
Defs/
Patches/
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ jobs:
RimWorldVersion: 1.5
run: dotnet build .vscode --configuration Release

- name: Build Mod for 1.4
env:
RimWorldVersion: 1.4
run: dotnet build .vscode --configuration Release

- name: Upload Mod Artifacts
uses: actions/upload-artifact@v4
with:
name: RealisticOrbitalTrade-Release
path: |
About/
1.5/
1.4/
Common/
Defs/
Patches/
Expand Down
11 changes: 11 additions & 0 deletions .vscode/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ dotnet build .vscode
if ($LASTEXITCODE -gt 0) {
throw "Build failed"
}
$env:RimWorldVersion = "1.4"
dotnet build .vscode
#dotnet build --configuration Release .vscode
if ($LASTEXITCODE -gt 0) {
throw "Build failed"
}

# remove pdbs (for release)
# Remove-Item -Path .\1.5\Assemblies\RealisticOrbitalTrade.pdb -ErrorAction SilentlyContinue
# Remove-Item -Path .\1.4\Assemblies\RealisticOrbitalTrade.pdb -ErrorAction SilentlyContinue

# remove mod folder
Remove-Item -Path $Target -Recurse -ErrorAction SilentlyContinue

# copy mod files
Copy-Item -Path 1.5 $Target\1.5 -Recurse
Copy-Item -Path 1.4 $Target\1.4 -Recurse

Copy-Item -Path Common $Target\Common -Recurse

Expand Down
13 changes: 12 additions & 1 deletion .vscode/mod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

<!-- Intellisense doesn't work without specifying this -->
<RimWorldVersion>1.5</RimWorldVersion>
<!-- <RimWorldVersion>1.5</RimWorldVersion> -->
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
Expand Down Expand Up @@ -45,6 +45,17 @@
</PackageReference>
</ItemGroup>
</When>
<When Condition="'$(RimWorldVersion)' == '1.4'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);v1_4</DefineConstants>
<OutputPath>../1.4/Assemblies</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.4.*-*">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
</ItemGroup>
</When>
</Choose>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ Mod compatibility is probably generally good, but there might be issues with mod

&lt;size=24&gt;Version&lt;/size&gt;

This is version 0.1.1 for RimWorld 1.5
This is version 0.1.1 for RimWorld 1.5 and 1.4
</description>
<supportedVersions>
<li>1.5</li>
<li>1.4</li>
</supportedVersions>
<modDependencies>
<li>
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Support for RimWorld 1.4

## [0.1.1] - 2024-05-01

### Changed
Expand Down
4 changes: 4 additions & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<li>Common</li>
<li>1.5</li>
</v1.5>
<v1.4>
<li>Common</li>
<li>1.4</li>
</v1.4>
</loadFolders>
6 changes: 3 additions & 3 deletions Source/RealisticOrbitalTrade/Comps/CompTradeShuttle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ internal static class Rimworld_CompShuttle_IsRequired
private static void Postfix(Thing thing, CompShuttle __instance, ref bool __result)
{
var compTradeShuttle = __instance.parent.TryGetComp<CompTradeShuttle>();
if (!__result && compTradeShuttle != null && compTradeShuttle.IsRequired(thing))
if (!__result && compTradeShuttle != null)
{
__result = true;
__result = compTradeShuttle.IsRequired(thing);
}
}
}
Expand Down Expand Up @@ -310,7 +310,7 @@ private static void InjectThingsLabel(CompShuttle __instance, StringBuilder stri
}
}

private static MethodInfo _methodInjectThingsLabel = SymbolExtensions.GetMethodInfo(() => InjectThingsLabel(new(), new()));
private static readonly MethodInfo _methodInjectThingsLabel = SymbolExtensions.GetMethodInfo(() => InjectThingsLabel(new(), new()));

private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This bug we're correcting is fixed in 1.5, so we only patch for 1.4
#if v1_4
using HarmonyLib;
using RimWorld;
using RimWorld.QuestGen;
using Verse;

[HarmonyPatch(typeof(QuestPart_SetupTransportShip), nameof(QuestPart_SetupTransportShip.Notify_QuestSignalReceived))]
internal static class QuestPart_SetupTransportShip_Notify_QuestSignalReceived
{
private static void Postfix(QuestPart_SetupTransportShip __instance, Signal signal)
{
if (!(signal.tag == __instance.inSignal))
{
return;
}
if (!__instance.pawns.NullOrEmpty())
{
__instance.pawns.Clear();
}
if (!__instance.items.NullOrEmpty())
{
__instance.items.Clear();
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using RealisticOrbitalTrade.Comps;
using RimWorld;
using Verse;
Expand Down Expand Up @@ -33,7 +34,7 @@ public override void Tick()
transportShip.TransporterComp.leftToLoad.Clear();

// End any jobs currently involved in loading the transport ship
foreach (var humanLike in transportShip.shipThing.Map.mapPawns.AllHumanlike)
foreach (var humanLike in transportShip.shipThing.Map.mapPawns.GetAllHumanLike())
{
if (humanLike.CurJobDef == JobDefOf.HaulToTransporter && humanLike.CurJob.targetB == transportShip.shipThing)
{
Expand All @@ -46,3 +47,27 @@ public override void Tick()
}
}
}

internal static class MapPawnsGetAllHumanLike
{
#if v1_4
private static List<Pawn> humanlikePawnsResult = new List<Pawn>();
#endif
public static List<Pawn> GetAllHumanLike(this MapPawns mapPawns)
{
#if v1_5
return mapPawns.AllHumanlike;
#elif v1_4
humanlikePawnsResult.Clear();
List<Pawn> allPawns = mapPawns.AllPawns;
for (int i = 0; i < allPawns.Count; i++)
{
if (allPawns[i].RaceProps.Humanlike)
{
humanlikePawnsResult.Add(allPawns[i]);
}
}
return humanlikePawnsResult;
#endif
}
}

0 comments on commit 5cf2f3f

Please sign in to comment.