template
This commit is contained in:
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
* text=auto
|
||||
*.cs text eol=crlf
|
||||
*.csproj text eol=crlf
|
||||
*.md text eol=crlf
|
||||
|
||||
47
MyFirstMod/MyFirstMod.cs
Normal file
47
MyFirstMod/MyFirstMod.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using BepInEx;
|
||||
using BepInEx.Logging;
|
||||
using HarmonyLib;
|
||||
using LobbyCompatibility.Attributes;
|
||||
using LobbyCompatibility.Enums;
|
||||
|
||||
namespace MyFirstMod;
|
||||
|
||||
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
|
||||
[BepInDependency("BMX.LobbyCompatibility", BepInDependency.DependencyFlags.HardDependency)]
|
||||
[LobbyCompatibility(CompatibilityLevel.ClientOnly, VersionStrictness.None)]
|
||||
public class MyFirstMod : BaseUnityPlugin
|
||||
{
|
||||
public static MyFirstMod Instance { get; private set; } = null!;
|
||||
internal new static ManualLogSource Logger { get; private set; } = null!;
|
||||
internal static Harmony? Harmony { get; set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Logger = base.Logger;
|
||||
Instance = this;
|
||||
|
||||
Patch();
|
||||
|
||||
Logger.LogInfo($"{MyPluginInfo.PLUGIN_GUID} v{MyPluginInfo.PLUGIN_VERSION} has loaded!");
|
||||
}
|
||||
|
||||
internal static void Patch()
|
||||
{
|
||||
Harmony ??= new Harmony(MyPluginInfo.PLUGIN_GUID);
|
||||
|
||||
Logger.LogDebug("Patching...");
|
||||
|
||||
Harmony.PatchAll();
|
||||
|
||||
Logger.LogDebug("Finished patching!");
|
||||
}
|
||||
|
||||
internal static void Unpatch()
|
||||
{
|
||||
Logger.LogDebug("Unpatching...");
|
||||
|
||||
Harmony?.UnpatchSelf();
|
||||
|
||||
Logger.LogDebug("Finished unpatching!");
|
||||
}
|
||||
}
|
||||
56
MyFirstMod/MyFirstMod.csproj
Normal file
56
MyFirstMod/MyFirstMod.csproj
Normal file
@ -0,0 +1,56 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!-- BepInEx Properties -->
|
||||
<PropertyGroup>
|
||||
<AssemblyName>LMod.MyFirstMod</AssemblyName>
|
||||
<Product>MyFirstMod</Product>
|
||||
<!-- Change to whatever version you're currently on. -->
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Project Properties -->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<RootNamespace>MyFirstMod</RootNamespace>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Enable Nullable for better IDE null-checking -->
|
||||
<PropertyGroup>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Set NuGet Sources -->
|
||||
<PropertyGroup>
|
||||
<RestoreAdditionalProjectSources>
|
||||
https://api.nuget.org/v3/index.json;
|
||||
https://nuget.bepinex.dev/v3/index.json
|
||||
</RestoreAdditionalProjectSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Embed Debug Symbols for Easier Debugging -->
|
||||
<PropertyGroup>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>embedded</DebugType>
|
||||
<!--
|
||||
Trim the project path to prevent players from potentially
|
||||
viewing Private Information in stack traces.
|
||||
-->
|
||||
<PathMap>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=./</PathMap>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Primary Package References -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all"/>
|
||||
<PackageReference Include="BepInEx.Core" Version="5.*" PrivateAssets="all"/>
|
||||
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.*" PrivateAssets="all"/>
|
||||
<PackageReference Include="LethalCompany.GameLibs.Steam" Version="*-*" PrivateAssets="all"/>
|
||||
<PackageReference Include="UnityEngine.Modules" Version="2022.3.9" IncludeAssets="compile" PrivateAssets="all"/>
|
||||
<PackageReference Include="TeamBMX.LobbyCompatibility" Version="1.*" PrivateAssets="all"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
21
MyFirstMod/Patches/ExampleTVPatch.cs
Normal file
21
MyFirstMod/Patches/ExampleTVPatch.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using HarmonyLib;
|
||||
|
||||
namespace MyFirstMod.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(TVScript))]
|
||||
public class ExampleTVPatch
|
||||
{
|
||||
[HarmonyPatch("SwitchTVLocalClient")]
|
||||
[HarmonyPrefix]
|
||||
private static void SwitchTVPrefix(TVScript __instance)
|
||||
{
|
||||
/*
|
||||
* When the method is called, the TV will be turning off when we want to
|
||||
* turn the lights on and vice-versa. At that time, the TV's tvOn field
|
||||
* will be the opposite of what it's doing, ie it'll be on when turning off.
|
||||
* So, we want to set the lights to what the tv's state was
|
||||
* when this method is called.
|
||||
*/
|
||||
StartOfRound.Instance.shipRoomLights.SetShipLightsBoolean(__instance.tvOn);
|
||||
}
|
||||
}
|
||||
93
MyFirstMod/README.md
Normal file
93
MyFirstMod/README.md
Normal file
@ -0,0 +1,93 @@
|
||||
# Lethal Company Mod Template
|
||||
|
||||
Thank you for using the mod template! Here are a few tips to help you on your journey:
|
||||
|
||||
## Versioning
|
||||
|
||||
BepInEx uses [semantic versioning, or semver](https://semver.org/), for the mod's version info.
|
||||
To increment it, you can either modify the version tag in the `.csproj` file directly, or use your IDE's UX to increment the version. Below is an example of modifying the `.csproj` file directly:
|
||||
|
||||
```xml
|
||||
<!-- BepInEx Properties -->
|
||||
<PropertyGroup>
|
||||
<AssemblyName>LMod.MyFirstMod</AssemblyName>
|
||||
<Product>MyFirstMod</Product>
|
||||
<!-- Change to whatever version you're currently on. -->
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
```
|
||||
|
||||
Your IDE will have the setting in `Package` or `NuGet` under `General` or `Metadata`, respectively.
|
||||
|
||||
## Logging
|
||||
|
||||
A logger is provided to help with logging to the console.
|
||||
You can access it by doing `Plugin.Logger` in any class outside the `Plugin` class.
|
||||
|
||||
***Please use*** `LogDebug()` ***whenever possible, as any other log method
|
||||
will be displayed to the console and potentially cause performance issues for users.***
|
||||
|
||||
If you chose to do so, make sure you change the following line in the `BepInEx.cfg` file to see the Debug messages:
|
||||
|
||||
```toml
|
||||
[Logging.Console]
|
||||
|
||||
# ... #
|
||||
|
||||
## Which log levels to show in the console output.
|
||||
# Setting type: LogLevel
|
||||
# Default value: Fatal, Error, Warning, Message, Info
|
||||
# Acceptable values: None, Fatal, Error, Warning, Message, Info, Debug, All
|
||||
# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning)
|
||||
LogLevels = All
|
||||
```
|
||||
|
||||
## Harmony
|
||||
|
||||
This template uses harmony. For more specifics on how to use it, look at
|
||||
[the HarmonyX GitHub wiki](https://github.com/BepInEx/HarmonyX/wiki) and
|
||||
[the Harmony docs](https://harmony.pardeike.net/).
|
||||
|
||||
To make a new harmony patch, just use `[HarmonyPatch]` before any class you make that has a patch in it.
|
||||
|
||||
Then in that class, you can use
|
||||
`[HarmonyPatch(typeof(ClassToPatch), "MethodToPatch")]`
|
||||
where `ClassToPatch` is the class you're patching (ie `TVScript`), and `MethodToPatch` is the method you're patching (ie `SwitchTVLocalClient`).
|
||||
|
||||
Then you can use
|
||||
[the appropriate prefix, postfix, transpiler, or finalizer](https://harmony.pardeike.net/articles/patching.html) attribute.
|
||||
|
||||
_While you can use_ `return false;` _in a prefix patch,
|
||||
it is **HIGHLY DISCOURAGED** as it can **AND WILL** cause compatibility issues with other mods._
|
||||
|
||||
For example, we want to add a patch that will debug log the current players' position.
|
||||
We have the following postfix patch patching the `SwitchTVLocalClient` method
|
||||
in `TVScript`:
|
||||
|
||||
```csharp
|
||||
using HarmonyLib;
|
||||
|
||||
namespace MyFirstMod.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(TVScript))]
|
||||
public class ExampleTVPatch
|
||||
{
|
||||
[HarmonyPatch("SwitchTVLocalClient")]
|
||||
[HarmonyPrefix]
|
||||
private static void SwitchTvPrefix(TVScript __instance)
|
||||
{
|
||||
/*
|
||||
* When the method is called, the TV will be turning off when we want to
|
||||
* turn the lights on and vice-versa. At that time, the TV's tvOn field
|
||||
* will be the opposite of what it's doing, ie it'll be on when turning off.
|
||||
* So, we want to set the lights to what the tv's state was
|
||||
* when this method is called.
|
||||
*/
|
||||
StartOfRound.Instance.shipRoomLights.SetShipLightsBoolean(__instance.tvOn);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In this case we include the type of the class we're patching in the attribute
|
||||
before our `ExampleTVPatch` class,
|
||||
as our class will only patch the `TVScript` class.
|
||||
Reference in New Issue
Block a user