Skip to content

Commit

Permalink
feat: Interop with Dynamic Trade Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyvion committed May 15, 2024
1 parent 1a49d30 commit 4fcad8d
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 5 deletions.
1 change: 1 addition & 0 deletions .deps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ For reference:

- 1541408076: We Had a Trader?
- 2695164414: Tweaks Galore
- 3020706506: Dynamic Trade Interface
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ jobs:
dotnet build --configuration Release .vscode/mod.csproj
dotnet build --configuration Release .vscode/wehadatrader.interop.csproj
dotnet build --configuration Release .vscode/tweaksgalore.interop.csproj
dotnet build --configuration Release .vscode/dynamictradeinterface.interop.csproj
- name: Build Mod for 1.4
env:
RimWorldVersion: 1.4
run: |
dotnet build .vscode --configuration Release
dotnet build --configuration Release .vscode/wehadatrader.interop.csproj
dotnet build --configuration Release .vscode/dynamictradeinterface.interop.csproj
- name: Upload Mod Artifacts
uses: actions/upload-artifact@v4
Expand All @@ -48,6 +50,8 @@ jobs:
1.5_WeHadATrader/
1.4_WeHadATrader/
1.5_TweaksGalore/
1.5_DynamicTradeInterface/
1.4_DynamicTradeInterface/
Common/
UpdateLog/
Defs/
Expand Down
13 changes: 13 additions & 0 deletions .vscode/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ dotnet build --configuration $Configuration .vscode/tweaksgalore.interop.csproj
if ($LASTEXITCODE -gt 0) {
throw "Build failed"
}
dotnet build --configuration $Configuration .vscode/dynamictradeinterface.interop.csproj
if ($LASTEXITCODE -gt 0) {
throw "Build failed"
}

$env:RimWorldVersion = "1.4"
dotnet build --configuration $Configuration .vscode/mod.csproj
Expand All @@ -31,6 +35,10 @@ dotnet build --configuration $Configuration .vscode/wehadatrader.interop.csproj
if ($LASTEXITCODE -gt 0) {
throw "Build failed"
}
dotnet build --configuration $Configuration .vscode/dynamictradeinterface.interop.csproj
if ($LASTEXITCODE -gt 0) {
throw "Build failed"
}

# remove pdbs (for release)
if ($Configuration -eq "Release") {
Expand All @@ -41,6 +49,9 @@ if ($Configuration -eq "Release") {
Remove-Item -Path .\1.4_WeHadATrader\Assemblies\RealisticOrbitalTrade.WeHadATrader.pdb -ErrorAction SilentlyContinue

Remove-Item -Path .\1.5_TweaksGalore\Assemblies\RealisticOrbitalTrade.TweaksGalore.pdb -ErrorAction SilentlyContinue

Remove-Item -Path .\1.5_DynamicTradeInterface\Assemblies\RealisticOrbitalTrade.DynamicTradeInterface.pdb -ErrorAction SilentlyContinue
Remove-Item -Path .\1.4_DynamicTradeInterface\Assemblies\RealisticOrbitalTrade.DynamicTradeInterface.pdb -ErrorAction SilentlyContinue
}

# remove mod folder
Expand All @@ -54,6 +65,8 @@ Copy-Item -Path 1.4 $Target\1.4 -Recurse
Copy-Item -Path 1.5_WeHadATrader $Target\1.5_WeHadATrader -Recurse
Copy-Item -Path 1.4_WeHadATrader $Target\1.4_WeHadATrader -Recurse
Copy-Item -Path 1.5_TweaksGalore $Target\1.5_TweaksGalore -Recurse
Copy-Item -Path 1.5_DynamicTradeInterface $Target\1.5_DynamicTradeInterface -Recurse
Copy-Item -Path 1.4_DynamicTradeInterface $Target\1.4_DynamicTradeInterface -Recurse

Copy-Item -Path Common $Target\Common -Recurse
Copy-Item -Path UpdateLog $Target\UpdateLog -Recurse
Expand Down
77 changes: 77 additions & 0 deletions .vscode/dynamictradeinterface.interop.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net48</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>

<RootNamespace>RealisticOrbitalTrade.DynamicTradeInterface</RootNamespace>
<AssemblyName>RealisticOrbitalTrade.DynamicTradeInterface</AssemblyName>
<VersionPrefix>0.4.0</VersionPrefix>

<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

<!-- Intellisense doesn't work without specifying these explicitly -->
<!-- !! Don't check in with these uncommented !! -->
<!-- <RimWorldSteamWorkshopFolderPath>C:\Program Files (x86)\Steam\steamapps\workshop\content\294100</RimWorldSteamWorkshopFolderPath>
<RimWorldVersion>1.5</RimWorldVersion> -->
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<Optimize>true</Optimize>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<!-- Mod -->
<Compile Include="../Source/RealisticOrbitalTrade.DynamicTradeInterface/**" />
</ItemGroup>

<Choose>
<When Condition="'$(RimWorldVersion)' == '1.5'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);v1_5</DefineConstants>
<OutputPath>../1.5_DynamicTradeInterface/Assemblies</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.5.*-*">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
</ItemGroup>
</When>
<When Condition="'$(RimWorldVersion)' == '1.4'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);v1_4</DefineConstants>
<OutputPath>../1.4_DynamicTradeInterface/Assemblies</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.4.*-*">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
</ItemGroup>
</When>
</Choose>

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.2.2">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<ProjectReference Include=".\mod.csproj">
<CopyLocal>False</CopyLocal>
<Private>false</Private>
</ProjectReference>
<Reference Include="DynamicTradeInterface">
<HintPath>$(RimWorldSteamWorkshopFolderPath)\3020706506\$(RimWorldVersion)\Assemblies\DynamicTradeInterface.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>false</Private>
</Reference>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ This is version 0.4.0 for RimWorld 1.5 and 1.4
<li>Ludeon.RimWorld.Royalty</li>
<li>Mlie.WeHadATrader</li>
<li>Neronix17.TweaksGalore</li>
<li>zeracronius.dynamictradeinterface</li>
</loadAfter>
</ModMetaData>
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

- Added a compatibility layer for [Dynamic Trade Interface](https://steamcommunity.com/sharedfiles/filedetails/?id=3020706506). This is required because Dynamic Trade Interface uses a custom trade dialog instead of modifying the original, so Realistic Orbital Trade wasn't notified when a trade was cancelled when using it, leading to Realistic Orbital Trade thinking a trader had an active trade agreement when there wasn't any. This has now been corrected.

### Fixed

- The fix for minified items from last version had a bug where it would show items with multiple counts as "ItemName x<stackCountInStorage> x<stackCountNeeded>" in the shuttle's "Content" tab. This has now been fixed to be just "ItemName x<stackCountNeeded>" as it should be.
Expand Down
2 changes: 2 additions & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
<li>Common</li>
<li>1.4</li>
<li IfModActive="Mlie.WeHadATrader">1.4_WeHadATrader</li>
<li IfModActive="zeracronius.dynamictradeinterface">1.4_DynamicTradeInterface</li>
</v1.4>
<v1.5>
<li>Common</li>
<li>1.5</li>
<li IfModActive="Mlie.WeHadATrader">1.5_WeHadATrader</li>
<li IfModActive="Neronix17.TweaksGalore">1.5_TweaksGalore</li>
<li IfModActive="zeracronius.dynamictradeinterface">1.5_DynamicTradeInterface</li>
<li IfModActive="neronix17.toolbox">UpdateLog</li>
</v1.5>
</loadFolders>
6 changes: 6 additions & 0 deletions RealisticOrbitalTrade.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wehadatrader.interop", ".vs
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tweaksgalore.interop", ".vscode\tweaksgalore.interop.csproj", "{7825084C-72F7-46DB-8E54-A8F3A373C819}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dynamictradeinterface.interop", ".vscode\dynamictradeinterface.interop.csproj", "{60801FAF-2AAE-4497-A80D-9E8FD7F5B093}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{7825084C-72F7-46DB-8E54-A8F3A373C819}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7825084C-72F7-46DB-8E54-A8F3A373C819}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7825084C-72F7-46DB-8E54-A8F3A373C819}.Release|Any CPU.Build.0 = Release|Any CPU
{60801FAF-2AAE-4497-A80D-9E8FD7F5B093}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60801FAF-2AAE-4497-A80D-9E8FD7F5B093}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60801FAF-2AAE-4497-A80D-9E8FD7F5B093}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60801FAF-2AAE-4497-A80D-9E8FD7F5B093}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using HarmonyLib;
using Verse;
using System.Reflection;

namespace RealisticOrbitalTrade.DynamicTradeInterface;

public class DynamicTradeInterfaceMod : Mod
{
public DynamicTradeInterfaceMod(ModContentPack content)
: base(content)
{
new Harmony(Constants.Id).PatchAll(Assembly.GetExecutingAssembly());

RealisticOrbitalTradeMod.Message("\"Dynamic Trade Interface\" interop loaded successfully!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using HarmonyLib;
using System.Reflection;

namespace RealisticOrbitalTrade.DynamicTradeInterface.Patch;

[HarmonyPatch]
internal static class DynamicTradeInterface_UserInterface_Window_DynamicTrade_PostClose
{
private static MethodInfo TargetMethod()
{
return AccessTools.Method("DynamicTradeInterface.UserInterface.Window_DynamicTrade:PostClose");
}

private static void Postfix()
{
TradeShipData.EndTradeAgreementIfExists();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

[assembly: InternalsVisibleTo("RealisticOrbitalTrade.TweaksGalore")]
[assembly: InternalsVisibleTo("RealisticOrbitalTrade.WeHadATrader")]
[assembly: InternalsVisibleTo("RealisticOrbitalTrade.DynamicTradeInterface")]

namespace RealisticOrbitalTrade;

Expand Down
9 changes: 9 additions & 0 deletions Source/RealisticOrbitalTrade/Core/TradeShipData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public TradeShipData(TradeShip tradeShip, bool getting)

public bool HasActiveTradeAgreement { get => activeTradeAgreement != null; }

public static void EndTradeAgreementIfExists()
{
if (tradeAgreementForQuest != null)
{
RealisticOrbitalTradeGameComponent.Current.EndTradeAgreement(tradeAgreementForQuest);
tradeAgreementForQuest = null;
}
}

public void ExposeData()
{
Scribe_Values.Look(ref ticksUntilCommsClosed, "ticksUntilCommsClosed", 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ internal static class Rimworld_Dialog_Trade_Close
{
private static void Postfix()
{
if (TradeShipData.tradeAgreementForQuest != null)
{
RealisticOrbitalTradeGameComponent.Current.EndTradeAgreement(TradeShipData.tradeAgreementForQuest);
TradeShipData.tradeAgreementForQuest = null;
}
TradeShipData.EndTradeAgreementIfExists();
}
}

0 comments on commit 4fcad8d

Please sign in to comment.