Skip to content

Commit

Permalink
Updated to Eco 0.11.1.3 release build. Updated to .net 8. Removed use…
Browse files Browse the repository at this point in the history
… of harmony for power grid detour.
  • Loading branch information
thomasfn committed Dec 4, 2024
1 parent 8fd6095 commit 58d0081
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 199 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
name: Build Mod
runs-on: ubuntu-latest
env:
MODKIT_VERSION: 0.11.1.1-beta-release-758
MODKIT_VERSION: 0.11.1.3-beta-release-795
ECO_BRANCH: staging
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core 7.0
uses: actions/setup-dotnet@v1
- name: Setup .NET Core 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'
- name: Fetch dependencies
run: dotnet restore ./EcoLawExtensionsMod/EcoLawExtensionsMod.csproj
env:
Expand All @@ -38,7 +38,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: mod-binaries-${{github.event.release.tag_name}}
path: EcoLawExtensionsMod/bin/Release/net7.0/EcoLawExtensionsMod.*
path: EcoLawExtensionsMod/bin/Release/net8.0/EcoLawExtensionsMod.*
deploy:
name: Upload Release Assets
needs:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
name: Build Mod
runs-on: ubuntu-latest
env:
MODKIT_VERSION: 0.11.1.1-beta-release-758
MODKIT_VERSION: 0.11.1.3-beta-release-795
ECO_BRANCH: staging
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core 7.0
uses: actions/setup-dotnet@v1
- name: Setup .NET Core 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'
- name: Fetch dependencies
run: dotnet restore ./EcoLawExtensionsMod/EcoLawExtensionsMod.csproj
env:
Expand All @@ -39,4 +39,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: mod-binaries-staging
path: EcoLawExtensionsMod/bin/Release/net7.0/EcoLawExtensionsMod.*
path: EcoLawExtensionsMod/bin/Release/net8.0/EcoLawExtensionsMod.*
13 changes: 3 additions & 10 deletions EcoLawExtensionsMod/EcoLawExtensionsMod.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Eco.Mods.LawExtensions</RootNamespace>
</PropertyGroup>

Expand Down Expand Up @@ -38,16 +38,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Costura.Fody" Version="5.7.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Fody" Version="6.6.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Lib.Harmony" Version="2.2.1" />
<PackageReference Include="NetFabric.Hyperlinq.Abstractions" Version="1.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
</ItemGroup>

</Project>
9 changes: 0 additions & 9 deletions EcoLawExtensionsMod/FodyWeavers.xml

This file was deleted.

141 changes: 0 additions & 141 deletions EcoLawExtensionsMod/FodyWeavers.xsd

This file was deleted.

20 changes: 0 additions & 20 deletions EcoLawExtensionsMod/HarmonyPatches/PowerGridComponentTickPatch.cs

This file was deleted.

34 changes: 28 additions & 6 deletions EcoLawExtensionsMod/LawExtensionsPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using System.Collections.Generic;

using HarmonyLib;

namespace Eco.Mods.LawExtensions
{
using Core.Plugins.Interfaces;
Expand All @@ -24,7 +23,7 @@ namespace Eco.Mods.LawExtensions
using Gameplay.Items;
using Gameplay.Components;
using Gameplay.Objects;

using Gameplay.PowerGrids;

[Serialized]
public class LawExtensionsData : Singleton<LawExtensionsData>, IStorage
Expand Down Expand Up @@ -60,7 +59,6 @@ public class LawExtensionsPlugin : Singleton<LawExtensionsPlugin>, IModKitPlugin

static LawExtensionsPlugin()
{
CosturaUtility.Initialize();
var dynamicTagsField = typeof(TagManager).GetField("dynamicTags", BindingFlags.Static | BindingFlags.NonPublic);
if (dynamicTagsField != null)
{
Expand Down Expand Up @@ -92,8 +90,14 @@ public LawExtensionsPlugin()
public void Initialize(TimedTask timer)
{
data.Initialize();
var harmony = new Harmony("Eco.Mods.LawExtensions");
harmony.PatchAll();
try
{
SetupPowerGridManagerDetour();
}
catch (Exception ex)
{
Logger.Error($"Failed to setup power grid manager detour ({ex.Message}) - power related law triggers will not work!");
}
// Modded tags as filters for law trigger parameters don't seem to be supported for now (or maybe it's just my crazy way of making a tag...)
// SetupPoweredTag();
}
Expand All @@ -114,6 +118,24 @@ public void OnEditObjectChanged(object o, string param)
this.SaveConfig();
}

private void SetupPowerGridManagerDetour()
{
var tickWorkerField = typeof(PowerGridManager).GetField("tickWorker", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new Exception($"Failed to reflect PowerGridManager.tickWorker");
var tickWorker = tickWorkerField.GetValue(PowerGridManager.Obj) as EventDrivenWorker ?? throw new Exception($"Failed to retrieve PowerGridManager.tickWorker");
var repeatableActionField = typeof(EventDrivenWorker).GetField("repeatableAction", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new Exception($"Failed to reflect EventDrivenWorker.repeatableAction");
var oldRepeatableAction = repeatableActionField.GetValue(tickWorker) as Func<CancellationToken, Task<int>> ?? throw new Exception($"Failed to retrieve EventDrivenWorker.repeatableAction");
Func<CancellationToken, Task<int>> newRepeatableAction = (token) =>
{
PowerGridLawManager.PowerGridManagerPreTick(PowerGridManager.Obj);
return oldRepeatableAction(token).ContinueWith(t =>
{
PowerGridLawManager.PowerGridManagerPostTick(PowerGridManager.Obj);
return t.Result;
});
};
repeatableActionField.SetValue(tickWorker, newRepeatableAction);
}

private void SetupPoweredTag()
{
TagDefinition.Register(poweredTagDefinition);
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Eco Law Extensions Mod
A server mod for Eco 11.0 that extends the law system with a number of helpful utility game values and legal actions.
A server mod for Eco 11.1 that extends the law system with a number of helpful utility game values and legal actions.

Added game values:
- Citizen Population - the current citizen count of a title or demographic
Expand Down Expand Up @@ -180,15 +180,15 @@ Note that the `PowerAvailable` and `PowerProduced` values are measured in Joules
2. Extract the modkit and copy the dlls from `ReferenceAssemblies` to `eco-dlls` in the root directory (create the folder if it doesn't exist)
3. Open `EcoLawExtensionsMod.sln` in Visual Studio 2019/2022
4. Build the `EcoLawExtensionsMod` project in Visual Studio
5. Find the artifact in `EcoLawExtensionsMod\bin\{Debug|Release}\net7.0`
5. Find the artifact in `EcoLawExtensionsMod\bin\{Debug|Release}\net8.0`

### Linux

1. Run `ECO_BRANCH="release" MODKIT_VERSION="0.11.0.0-beta" fetch-eco-reference-assemblies.sh` (change the modkit branch and version as needed)
2. Enter the `EcoLawExtensionsMod` directory and run:
`dotnet restore`
`dotnet build`
3. Find the artifact in `EcoLawExtensionsMod/bin/{Debug|Release}/net7.0`
3. Find the artifact in `EcoLawExtensionsMod/bin/{Debug|Release}/net8.0`

## License
[MIT](https://choosealicense.com/licenses/mit/)

0 comments on commit 58d0081

Please sign in to comment.