HKBuildUtils 0.6.1

dotnet add package HKBuildUtils --version 0.6.1
NuGet\Install-Package HKBuildUtils -Version 0.6.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HKBuildUtils" Version="0.6.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HKBuildUtils --version 0.6.1
#r "nuget: HKBuildUtils, 0.6.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HKBuildUtils as a Cake Addin
#addin nuget:?package=HKBuildUtils&version=0.6.1

// Install HKBuildUtils as a Cake Tool
#tool nuget:?package=HKBuildUtils&version=0.6.1

Hollow Knight Mod Build Utils

Build Nuget

A nuget package to help make the Hollow Knight Mod

Features

Automatically Pack Mods

Automatically pack the mod into a zip file and calculate the SHA256 value after the build.

Configuration
  • $(ExportDir): Specifies the directory for the packaged output. Defaults to "$(ProjectDir)\bin\Publish"
  • $(PublishZipPath): Specify the save path of the ZIP output after packaging. Defaults to "$(ExportDir)\Publish.zip"
  • $(ReleaseInfoPath): Specifies the output location of the ReleaseInfo information constructed after packaging. Currently, only SHA256 is included. Default is "$([System.IO.Path]::GetDirectoryName('$(PublishZipPath)'))\ReleaseInfo.txt"

Mods References Helper

Automatically download HKMAPI and other mods that depend on it when building.

How to use

Add the names of the mods you want to depend on to the <ItemGroup> in the following way

<ModReference Include="<Mod Name in ModLinks>" AssemblyName="[Assembly Name]" />

Among them, AssemblyName is optional, but due to the limitation of MSBuild, if the Mod assembly file name does not match its name on ModLinks, you need to fill in AssemblyName by yourself.

For example, Custom Knight, its assembly file name is CustomKnight.dll instead of Custom Knight.dll, therefore, it needs to be referenced as follows

<ModReference Include="Custom Knight" AssemblyName="CustomKnight" />
Set game path

Set game paths to use game files directly instead of downloading them again.

HKBuildUtils will look for the game directory in the following order

(1.) The contents of hkpath.txt under the project folder or its ancestor folder

(2.) HollowKnightRefs defined in the project file

Note:

  1. (1.) will be used if both (1.) and (2.) are found, you can disable (1.) and use (2.) by using <DisableOverwriteHollowKnightRefs>true</DisableOverwriteHollowKnightRefs>
  2. If neither of them exists or the directory they specify does not exist, it will be considered as a build in CI, and the dependent mods and HKMAPI will be downloaded to the ~ModLibrary folder under the project folder during the build

Reflect Helper

Used to replace the Reflect Helper of HKMirror

Allows developers to directly access private fields and private types

If you need to use this feature, please add a reference to the Fody package

Use <ReflectHelper Include="<AssemblyName>" /> to indicate which assemblies need to construct Reflect Helper

<AssemblyName> can use assemblies explicitly referenced in project files using <Reference> and MAPI assemblies and other Mods assemblies inserted by HKBU

For example:

<ReflectHelper Include="UnityEngine.CoreModule" />
<ReflectHelper Include="Assembly-CSharp" />

They indicate the Reflect Helper that generates UnityEngine.CoreModule and Assembly-CSharp

They can be used like

HeroControllerR reflect = HeroController.instance.Reflect(); 
//or HeroControllerR reflect = (HeroControllerR)HeroController.instance;

Log(reflect.rb2d.name);

ModLoaderR.TryAddModInstance(typeof(TestModMod), new ModInstanceR()
{
   Enabled = true,
   Mod = this,
   Name = "Hello, World!This is Test Mod"
}); 
Compare with HKMirror

Advantage:

  • No need to add additional references
  • Can be used with almost any assembly
  • Has most of the private types
  • Custom operator operations with primitive types
  • Primitive object instances can be created directly using new. For example, new ModInstanceR() will create an instance of ModLoader.ModInstance
  • Supports generics

Mono Mod Hooks Helper

Allow developers to use MonoModHooks outside of MMHOOK_Assembly-CSharp and MMHOOK_PlayMaker.dll

They are automatically generated and automatically referenced at build

If you need to use this feature, please add a reference to the Fody package

Use <MonoModHook Include="<AssemblyName>" /> to indicate which assemblies need to construct MonoModHookHelper

<AssemblyName> can use assemblies explicitly referenced in project files using <Reference> and MAPI assemblies and other Mods assemblies inserted by HKBU

For example:

<MonoModHook Include="UnityEngine.CoreModule" />
<MonoModHook Include="Assembly-CSharp" />

They indicate the MonoHookHelper that generates UnityEngine.CoreModule and Assembly-CSharp

To avoid errors, this automatically disables the reference to MMHOOK_Assembly-CSharp that comes with MAPI

MonoModHookHelper (including those that come with MAPI) will be merged into the mod assembly by Fody in the build, no need to publish additional files

Merger with HKMirror

Use ILRepack to merge mods with HKMirror and eliminate unused types in HKMirror.

It is recommended to use Reflect Helper

How to enable

Add <MergeHKMirror>true</MergeHKMirror> to PropertyGroup and reference HKMirror. The rest will take care of it for you.

Mod Resources

Using <ModResource></ModResource> instead of <EmbeddedResource></EmbeddedResource> automatically generates the type ModResources for use

Example

Add the following to the project file

<ItemGroup>
    <ModResource Include="Test1.txt"></ModResource>
    <ModResource Include="a/Test2.txt"></ModResource>
    <ModResource Include="b/c/Test3.txt"></ModResource>
</ItemGroup>

Then you can get them like this in your code

Modding.Logger.Log(ModResources.TEST1.Length);

Modding.Logger.Log(ModResources.TEST2.Length);

Modding.Logger.Log(ModResources.TEST3.Length);

You can add Default="true" to <ModResource> to use user-defined content.Like this

<ItemGroup>
    <ModResource Include="a/b/c" Default="true"></ModResource>
</ItemGroup>

You can get it through ModResources.C, just like mentioned above.

If ModResources.C is used, the file $(ModDir)/a/b/c is checked for existence first. If present, the file contents are returned, and if they are not, read from the assembly and written to the $(ModDir)/a/b/c file

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.6.1 264 5/28/2023
0.5.56 298 3/12/2023
0.5.55 258 3/12/2023
0.5.54 240 3/10/2023
0.5.53 214 3/10/2023
0.5.52 355 3/4/2023
0.5.35 260 3/4/2023
0.5.33 220 3/4/2023
0.5.4 200 3/3/2023
0.5.1 221 3/3/2023
0.5.0 229 3/2/2023
0.4.51 258 3/2/2023
0.4.46 218 3/2/2023
0.4.45 262 2/26/2023
0.4.0 239 2/25/2023
0.3.16 254 2/23/2023
0.3.4 251 2/22/2023
0.3.3 260 2/22/2023
0.3.2 292 2/22/2023
0.3.1 266 2/22/2023
0.3.0 257 2/21/2023
0.2.0 266 2/20/2023
0.1.4 315 1/28/2023
0.1.3 297 1/28/2023
0.1.2 303 1/28/2023
0.1.0 322 1/28/2023