Skip to content

Commit

Permalink
Release 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidev committed Mar 24, 2023
0 parents commit 1c15188
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build_release_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Logless Release

on:
push:
tags:
- v*

env:
LIB_NAME: Logless

jobs:
build-and-release:

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.102

- name: Restore NuGet Packages
run: dotnet restore

- name: Build Library
run: dotnet build --configuration Release

- name: Zip Artifact
run: zip -rjD ${{ env.LIB_NAME }}_${{ github.ref_name }}.zip ${{ github.workspace }}/bin/Release/**/${{ env.LIB_NAME }}.dll

- name: Create Release
uses: ncipollo/release-action@v1
with:
name: ${{ env.LIB_NAME }} ${{ github.ref_name }}
artifacts: ${{ env.LIB_NAME }}_${{ github.ref_name }}.zip
body: |
Release of ${{ env.LIB_NAME }} ${{ github.ref_name }}
generateReleaseNotes: true
makeLatest: true
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.*
bin/*
obj/*
libs/*.dll
*.user
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Alexandre Poumaroux

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
135 changes: 135 additions & 0 deletions Logless.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;

namespace Logless
{
using P = Plugin;

[BepInProcess("Legion TD 2.exe")]
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
// Using GUID for the Harmony instance, so that we can unpatch just this plugin if needed
private readonly Assembly _assembly = Assembly.GetExecutingAssembly();
private readonly Harmony _harmony = new(PluginInfo.PLUGIN_GUID);

internal new static ManualLogSource Logger;

// When the plugin is loaded
public void Awake() {
// Create masking Logger as internal to use more easily in code
Logger = base.Logger;

// Inject custom js and patch c#
try {
Patch();
}
catch (Exception e) {
Logger.LogError($"Error while injecting or patching: {e}");
throw;
}

// All done!
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
}

// Unpatch if plugin is destroyed to handle in-game plugin reloads
// Remove files we created
public void OnDestroy() {
UnPatch();
}

private void Patch() {
_harmony.PatchAll(_assembly);
}

// Undoes what Patch() did
private void UnPatch() {
_harmony.UnpatchSelf();
}
}

[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "UnusedMember.Local")]
[HarmonyPatch]
internal static class PatchDeveloperApiHtmlLogger
{
private static Type _typeDeveloperApi;

[HarmonyPrepare]
private static void Prepare() {
_typeDeveloperApi = AccessTools.TypeByName("aag.Natives.Api.DeveloperApi");
}

[HarmonyTargetMethods]
private static IEnumerable<MethodBase> TargetMethods()
{
return AccessTools.Inner(_typeDeveloperApi, "HtmlLogger")
.GetMethods()
.Where(method => method.ReturnType == typeof(void));
}

[HarmonyPrefix]
private static bool Prefix(MethodBase __originalMethod) {
return false;
}
}

[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "UnusedMember.Local")]
[HarmonyPatch]
internal static class PatchDeveloperApi
{
private static Type _typeDeveloperApi;

[HarmonyPrepare]
private static void Prepare() {
_typeDeveloperApi = AccessTools.TypeByName("aag.Natives.Api.DeveloperApi");
}

[HarmonyTargetMethods]
private static IEnumerable<MethodBase> TargetMethods()
{
return _typeDeveloperApi
.GetMethods()
.Where(method => method.ReturnType == typeof(void));
}

[HarmonyPrefix]
private static bool Prefix(MethodBase __originalMethod) {
return false;
}
}

[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "UnusedMember.Local")]
[HarmonyPatch]
internal static class PatchLogSaver
{
private static Type _typeLogSaver;

[HarmonyPrepare]
private static void Prepare() {
_typeLogSaver = AccessTools.TypeByName("Assets.Features.Dev.LogSaver");
}

[HarmonyTargetMethods]
private static IEnumerable<MethodBase> TargetMethods()
{
return _typeLogSaver
.GetMethods()
.Where(method => method.ReturnType == typeof(void));
}

[HarmonyPrefix]
private static bool Prefix() {
return false;
}
}
}
26 changes: 26 additions & 0 deletions Logless.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Logless</AssemblyName>
<Description>This Logless mod</Description>
<Version>1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<PackageId>ltd2.mods.Kidev.Logless</PackageId>
<Title>Logless</Title>
<Authors>Kidev</Authors>
<NoWarn>$(NoWarn);CS0436</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
<PackageReference Include="UnityEngine.Modules" Version="2020.3.16" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
</packageSources>
</configuration>
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Logless

Bye bye logs

0 comments on commit 1c15188

Please sign in to comment.