Skip to content

Commit

Permalink
Changed .NET Framework version to 4.7.2 as those APIs do exist in BT.…
Browse files Browse the repository at this point in the history
… Removed Harmony1 example and updated versions in the only surviving mod template. Updates publicizer version.
  • Loading branch information
CptMoore committed Dec 11, 2024
1 parent d5f64b7 commit 2bc266e
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 152 deletions.
14 changes: 2 additions & 12 deletions Common.props
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
<Project InitialTargets="ValidateBattleTechGameDir">
<!-- Check if the BattleTechGameDir variable is correctly set -->
<Target Name="ValidateBattleTechGameDir" Condition="'$(BattleTechGameDir)' == '' Or !Exists('$(BattleTechGameDir)')">
<Error Text="BattleTechGameDir variable not set properly" />
</Target>

<PropertyGroup>
<!-- All mods and utilites are libraries and produce a dll -->
<OutputType>Library</OutputType>
<!-- The latest BattleTech game version uses .NET Framework 4.7.1, newer target frameworks are more likely to be incompatible -->
<TargetFramework>net471</TargetFramework>
<!-- Set to a modern version, some newer language feature are not available in combination with .NET Framework, PolySharp helps with backports -->
<TargetFramework>net472</TargetFramework>
<LangVersion>13</LangVersion>
<!-- We ask msbuild to only use reference DLLs found the BattleTech Managed directory -->
<AssemblySearchPaths>
{HintPathFromItem};
$(BattleTechGameDir)\BattleTech_Data\Managed
</AssemblySearchPaths>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<!-- embed symbols into the dll -->
<DebugType>embedded</DebugType>
<!-- ignore some warning -->
<NoWarn>CS0436</NoWarn> <!-- CS0436: same namespace+classname warning, e.g. happens due to GitVersion generated classes not having distinct namespaces -->
<NoWarn>CS0436</NoWarn>
</PropertyGroup>

<PropertyGroup>
<ModTekLibDir>$(BattleTechGameDir)\Mods\ModTek\lib\</ModTekLibDir>
</PropertyGroup>

<ItemGroup>
<!-- Makes sure dll versions are using commits and tags found in the git repo -->
<PackageReference Include="GitVersion.MsBuild">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<!-- Allows to use many modern language features in older .NET frameworks -->
<PackageReference Include="PolySharp">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<!-- Common libraries that are really used everywhere -->
<Reference Include="System">
<Private>False</Private>
</Reference>
Expand Down
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project>
<PropertyGroup>
<!-- use centrally managed versions, see PackageVersion -->
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Krafs.Publicizer" Version="2.2.1" />
<PackageVersion Include="Krafs.Publicizer" Version="2.3.0" />
<PackageVersion Include="GitVersion.MsBuild" Version="5.12.0" />
<PackageVersion Include="HarmonyX" Version="2.13.0" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
Expand Down
9 changes: 1 addition & 8 deletions ModTek.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Harmony12Interop", "Harmony
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{6480C6DD-C6E7-4D8C-9220-37FB34162CF8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModTemplateWithHarmonyX", "examples\ModTemplateWithHarmonyX\ModTemplateWithHarmonyX.csproj", "{C0839FDC-E835-40B5-831A-E4EB5D9040D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModTemplateWithOldHarmony1", "examples\ModTemplateWithOldHarmony1\ModTemplateWithOldHarmony1.csproj", "{253B7E45-1D8E-450E-AA00-F79818D707C5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModTemplate", "examples\ModTemplate\ModTemplate.csproj", "{C0839FDC-E835-40B5-831A-E4EB5D9040D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModTek.Common", "ModTek.Common\ModTek.Common.csproj", "{67588F2A-B438-407C-AD16-ED6F4C9D12FC}"
EndProject
Expand Down Expand Up @@ -68,10 +66,6 @@ Global
{C0839FDC-E835-40B5-831A-E4EB5D9040D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0839FDC-E835-40B5-831A-E4EB5D9040D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0839FDC-E835-40B5-831A-E4EB5D9040D5}.Release|Any CPU.Build.0 = Release|Any CPU
{253B7E45-1D8E-450E-AA00-F79818D707C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{253B7E45-1D8E-450E-AA00-F79818D707C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{253B7E45-1D8E-450E-AA00-F79818D707C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{253B7E45-1D8E-450E-AA00-F79818D707C5}.Release|Any CPU.Build.0 = Release|Any CPU
{67588F2A-B438-407C-AD16-ED6F4C9D12FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67588F2A-B438-407C-AD16-ED6F4C9D12FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67588F2A-B438-407C-AD16-ED6F4C9D12FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -95,6 +89,5 @@ Global
{D309E43C-CEEC-4BE6-BB5E-8A5C90BA5462} = {2095443E-5ECB-4187-878D-E4DDD3ABF9D2}
{183EB195-CC72-4667-AA2F-FECA210F776F} = {2095443E-5ECB-4187-878D-E4DDD3ABF9D2}
{C0839FDC-E835-40B5-831A-E4EB5D9040D5} = {6480C6DD-C6E7-4D8C-9220-37FB34162CF8}
{253B7E45-1D8E-450E-AA00-F79818D707C5} = {6480C6DD-C6E7-4D8C-9220-37FB34162CF8}
EndGlobalSection
EndGlobal
6 changes: 3 additions & 3 deletions doc/DEVELOPMENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ it is heavily focused on DLL mods but some parts can still be applied to the JSO

## .NET Development

BattleTech is based on Unity 2018.4.2 with Mono based on .NET Framework 4.7.1 .
BattleTech is based on Unity 2018.4.2 with Mono based on .NET Framework 4.7.2 .
Microsoft still supports the mentioned .NET version with its latest development tools.

### Rider or Visual Studio with Resharper

Use the latest and greatest Visual Studio you can find. As of this writing it is Visual Studio 2022.
- Visual Studio 2022 community is for free. Do not even think about using Visual Studio Code, its not worth it.
- Newer Visual Studios and newer C# versions can be used, as long as they can target the old .NET Framework 4.7.1 used by the game.
- Newer Visual Studios and newer C# versions can be used, as long as they can target the old .NET Framework 4.7.2 used by the game.
- If you have the money, use Resharper from JetBrains.

Rider is the C# IDE of the JetBrains that integrates similar functionality as Resharper. It still requires the build tools from MS to be installed.
Expand Down Expand Up @@ -60,7 +60,7 @@ Many older mods still use the old style csproj files. Don't copy those, use SDK

### C# Latest:

While .NET Framework 4.7.1 came with C# 7.3, you can use the latest C# (as of this writing 11) with albeit less features. Here are the highlights:
While .NET Framework 4.7.2 came with C# 7.3, you can use the latest C# (as of this writing 11) with albeit less features. Here are the highlights:
- Nullable reference types: When enabled, all reference types (e.g. string) are assumed to be wanted to be not-null.
Assigning null or not initializing a field variable will lead to compiler warnings. Modern languages (Kotlin/Swift) have this already, C# has it too.
Only caveat is that while we can use this, they are some language improvements regarding this feature that are not available in our old .NET Framework version.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using HarmonyLib;
using HBS.Logging;

namespace ModTemplateWithHarmonyX;
namespace ModTemplate;

public static class Main
{
private static readonly ILog s_log = Logger.GetLogger(nameof(ModTemplateWithHarmonyX));
private static readonly ILog s_log = Logger.GetLogger(nameof(ModTemplate));
public static void Start()
{
s_log.Log("Starting");
Expand All @@ -25,6 +25,6 @@ public static void Start()
static void GetReleaseVersion(ref string __result)
{
var old = __result;
__result = old + "\nHTWHX(2)";
__result = old + "\nMy Mod Template shows up!";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<PropertyGroup>
<!-- All mods and utilites are libraries and produce a dll -->
<OutputType>Library</OutputType>
<!-- The latest BattleTech game version uses .NET Framework 4.7.1, newer target frameworks won't work -->
<TargetFramework>net471</TargetFramework>
<!-- The latest BattleTech game version uses .NET Framework 4.7.2, newer target frameworks won't work -->
<TargetFramework>net472</TargetFramework>
<!-- Set to a modern version, some newer language feature are not available in combination with .NET Framework -->
<LangVersion>11</LangVersion>
<LangVersion>13</LangVersion>
<!-- We ask msbuild to only use reference DLLs found the BattleTech Managed directory -->
<AssemblySearchPaths>
{HintPathFromItem};
Expand All @@ -20,11 +20,17 @@
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<!-- embed symbols into the dll -->
<DebugType>embedded</DebugType>
<!-- ignore some warning -->
<NoWarn>CS0436</NoWarn> <!-- CS0436: same namespace+classname warning, e.g. happens due to GitVersion generated classes not having distinct namespaces -->
</PropertyGroup>

<!-- helpful direct access to resources in BT, might trigger IDE indexing and can introduce lag/stutter -->
<!--
<ItemGroup>
<Link Include="$(BattleTechGameDir)\Mods\.modtek\*.log*" />
<None Include="$(BattleTechGameDir)\Mods\.modtek\*.txt;$(BattleTechGameDir)\Mods\.modtek\*.log" LinkBase=".modtek" />
<None Include="$(BattleTechGameDir)\BattleTech_Data\StreamingAssets\data\**\*.json;$(BattleTechGameDir)\BattleTech_Data\StreamingAssets\data\**\*.csv" LinkBase="BattleTech_Data"/>
</ItemGroup>
-->

<!-- Copy the mod dll to the BT game dir if the mod directory exists there -->
<Target Condition="Exists('$(BattleTechGameDir)\Mods\$(ProjectName)\')" Name="CopyFilesToGame" AfterTargets="CopyFilesToOutputDirectory">
Expand All @@ -38,7 +44,7 @@
</PropertyGroup>
<ItemGroup>
<!-- Allows to access internal and private members without Harmony Traverse, do not use if inheriting from classes made public -->
<PackageReference Include="Krafs.Publicizer" Version="2.2.1" />
<PackageReference Include="Krafs.Publicizer" Version="2.3.0" />
<!-- Main game library, best to publicize it to access internals easily and efficiently -->
<Publicize Include="Assembly-CSharp" />
</ItemGroup>
Expand All @@ -50,13 +56,13 @@
</PackageReference>

<!-- Harmony is needed to hook into the game -->
<PackageReference Include="HarmonyX" Version="2.10.1">
<PackageReference Include="HarmonyX" Version="2.10.2">
<PrivateAssets>All</PrivateAssets>
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>

<!-- Enables many newer language features for .NET Framework -->
<PackageReference Include="PolySharp" Version="1.13.2">
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HarmonyLib;

namespace ModTemplateWithHarmonyX.Patches;
namespace ModTemplate.Patches;

[HarmonyPatch(typeof(VersionInfo), nameof(VersionInfo.GetReleaseVersion))]
static class VersionInfo_GetReleaseVersion_Patch
Expand Down
5 changes: 5 additions & 0 deletions examples/ModTemplate/mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Name": "ModTemplate",
"DLL": "ModTemplate.dll",
"DLLEntryPoint": "ModTemplate.Main.Start"
}
5 changes: 0 additions & 5 deletions examples/ModTemplateWithHarmonyX/mod.json

This file was deleted.

20 changes: 0 additions & 20 deletions examples/ModTemplateWithOldHarmony1/Main.cs

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions examples/ModTemplateWithOldHarmony1/mod.json

This file was deleted.

0 comments on commit 2bc266e

Please sign in to comment.