Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to .net sdk, refactoring #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
484 changes: 484 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file removed .vs/HDLethalCompany/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
467 changes: 27 additions & 440 deletions HDLethalCompanyRemake/HDLethalCompany.cs

Large diffs are not rendered by default.

149 changes: 47 additions & 102 deletions HDLethalCompanyRemake/HDLethalCompany.csproj
Original file line number Diff line number Diff line change
@@ -1,102 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7F379BC1-1FD4-4C72-9247-A181862EEC6B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HDLethalCompanyRemake</RootNamespace>
<AssemblyName>HDLethalCompanyRemake</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\Libraries\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\Libraries\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\Libraries\BepInEx.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Unity.InputSystem">
<HintPath>..\Libraries\Unity.InputSystem.dll</HintPath>
</Reference>
<Reference Include="Unity.Netcode.Runtime">
<HintPath>..\Libraries\Unity.Netcode.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.Core.Runtime">
<HintPath>..\Libraries\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.Core.ShaderLibrary">
<HintPath>..\Libraries\Unity.RenderPipelines.Core.ShaderLibrary.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.HighDefinition.Config.Runtime">
<HintPath>..\Libraries\Unity.RenderPipelines.HighDefinition.Config.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.HighDefinition.Runtime">
<HintPath>..\Libraries\Unity.RenderPipelines.HighDefinition.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary">
<HintPath>..\Libraries\Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>..\Libraries\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\Libraries\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule">
<HintPath>..\Libraries\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule">
<HintPath>..\Libraries\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\Libraries\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\Libraries\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputModule">
<HintPath>..\Libraries\UnityEngine.InputModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\Libraries\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="HDLethalCompany.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>HDLethalCompany</AssemblyName>
<Product>HDLethalCompany-Sligili</Product>
<Version>1.5.2</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<RestoreAdditionalProjectSources>
https://api.nuget.org/v3/index.json;
https://nuget.bepinex.dev/v3/index.json;
https://nuget.samboy.dev/v3/index.json
</RestoreAdditionalProjectSources>
<RootNamespace>HDLethalCompany</RootNamespace>
</PropertyGroup>

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

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

<PropertyGroup>
<ManagedPath>..\Libraries</ManagedPath>
</PropertyGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp" Private="false">
<HintPath>$(ManagedPath)\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Unity.Netcode.Runtime" Private="false">
<HintPath>$(ManagedPath)\Unity.Netcode.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.Core.Runtime" Private="false">
<HintPath>$(ManagedPath)\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.HighDefinition.Runtime" Private="false">
<HintPath>$(ManagedPath)\Unity.RenderPipelines.HighDefinition.Runtime.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
142 changes: 142 additions & 0 deletions HDLethalCompanyRemake/ModConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using System;
using BepInEx.Configuration;
using UnityEngine.Device;

namespace HDLethalCompany;

internal static class ModConfig
{
// Graphics Settings
internal static bool EnablePostProcessing { get; private set; }
internal static bool EnableFog { get; private set; }
internal static bool EnableAntiAliasing { get; private set; }

internal static bool EnableResolutionFix { get; private set; }

internal static bool EnableFoliage { get; private set; }

internal static FogQuality SetFogQuality { get; private set; }
internal static TextureQuality SetTextureResolution { get; private set; }
internal static LOD SetLOD { get; private set; }
internal static ShadowQuality SetShadowQuality { get; private set; }

// Resolution
internal static int WidthResolution { get; private set; }
internal static int HeightResolution { get; private set; }

internal static void Init(ConfigFile configFile)
{
ConfigEntries.EnableResolutionFix = configFile.Bind("RESOLUTION", "EnableFix", true,
"Resolution Fix - In case you wanna use another resolution mod or apply any widescreen mod while keeping the graphics settings");
ConfigEntries.FromWindowWidth = configFile.Bind("RESOLUTION", "FromWindowWidth", false,
"Resolution Scale From Window Size. Overrides TargetWidth");
ConfigEntries.ResolutionWidth = configFile.Bind("RESOLUTION", "TargetWidth", 1920,
"Resolution Scale Target Width. For example 1920. Game default is 860");

ConfigEntries.EnableAntiAliasing = configFile.Bind("EFFECTS", "EnableAA", false,
"Anti-Aliasing (Unity's SMAA)");
ConfigEntries.EnablePostProcessing = configFile.Bind("EFFECTS", "EnablePP", true,
"Post-Processing (Color grading)");
ConfigEntries.EnableFog = configFile.Bind("EFFECTS", "EnableFOG", true,
"Volumetric Fog Toggle - Use this as a last resource in case lowering the fog quality is not enough to get decent performance");
ConfigEntries.FogQuality = configFile.Bind("EFFECTS", "FogQuality", FogQuality.Low,
"Volumetric Fog Quality - <Low => Vanilla>");
ConfigEntries.TextureQuality = configFile.Bind("EFFECTS", "TextureQuality", TextureQuality.High,
"Texture Resolution Quality - <VeryLow => 1/8 | Low => 1/4 | Medium => 1/2 | High => 1/1 Vanilla>");
ConfigEntries.LOD = configFile.Bind("EFFECTS", "LOD", LOD.Medium,
"Level Of Detail - <Low => half distance | Medium => Vanilla | High => twice distance>");
ConfigEntries.ShadowQuality = configFile.Bind("EFFECTS", "ShadowQuality", ShadowQuality.High,
"Shadows Resolution - <VeryLow => shadows disabled | Low => 256 | Medium => 1024 | High => 2048 Vanilla> - Shadowmap max resolution");
ConfigEntries.EnableFoliage = configFile.Bind("EFFECTS", "EnableF", true,
"Foliage Toggle - If the game camera should or not render bushes/grass (trees won't be affected)");

LegacyPostInit(configFile);

WidthResolution = ConfigEntries.FromWindowWidth.Value ? Screen.width : ConfigEntries.ResolutionWidth.Value;
HeightResolution = (int)MathF.Round(520f * (WidthResolution / 860f), 0);
EnableResolutionFix = ConfigEntries.EnableResolutionFix.Value && WidthResolution != 860;

EnablePostProcessing = ConfigEntries.EnablePostProcessing.Value;
EnableFog = ConfigEntries.EnableFog.Value;
EnableAntiAliasing = ConfigEntries.EnableAntiAliasing.Value;

EnableFoliage = ConfigEntries.EnableFoliage.Value;

SetFogQuality = ConfigEntries.FogQuality.Value;
SetTextureResolution = ConfigEntries.TextureQuality.Value;
SetLOD = ConfigEntries.LOD.Value;
SetShadowQuality = ConfigEntries.ShadowQuality.Value;
}

private static void LegacyPostInit(ConfigFile configFile)
{
configFile.SaveOnConfigSet = false;

// Old config file used to have this value - Back Compat to old Very Low value
if (ConfigEntries.FogQuality.Value == (FogQuality)(-1)) ConfigEntries.FogQuality.Value = FogQuality.VeryLow;

var enableResEntry = new ConfigDefinition("RESOLUTION", "EnableRes");
var enableRes = configFile.Bind(enableResEntry, true).Value;
if (!enableRes)
ConfigEntries.EnableResolutionFix.Value = false;
configFile.Remove(enableResEntry);

var valueEntry = new ConfigDefinition("RESOLUTION", "Value");
var resolutionValue = configFile.Bind(valueEntry, 0f).Value;
if (resolutionValue != 0f)
ConfigEntries.ResolutionWidth.Value = (int)MathF.Round(860f * resolutionValue, 0);
configFile.Remove(valueEntry);

configFile.SaveOnConfigSet = true;
configFile.Save();
}

internal enum FogQuality
{
VeryLow = 0,
Low = 1,
Medium = 2,
High = 3
}

internal enum TextureQuality
{
VeryLow = 0,
Low = 1,
Medium = 2,
High = 3
}

internal enum LOD
{
Low = 0,
Medium = 1,
High = 2
}

internal enum ShadowQuality
{
VeryLow = 0,
Low = 1,
Medium = 2,
High = 3
}

private static class ConfigEntries
{
internal static ConfigEntry<bool>
FromWindowWidth,
EnablePostProcessing,
EnableFog,
EnableAntiAliasing,
EnableResolutionFix,
EnableFoliage;

internal static ConfigEntry<int> ResolutionWidth;

internal static ConfigEntry<FogQuality> FogQuality;
internal static ConfigEntry<TextureQuality> TextureQuality;
internal static ConfigEntry<LOD> LOD;
internal static ConfigEntry<ShadowQuality> ShadowQuality;
}
}
28 changes: 28 additions & 0 deletions HDLethalCompanyRemake/Patch/Camera__Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using HarmonyLib;
using UnityEngine;

namespace HDLethalCompany.Patch;

[HarmonyPatch(typeof(Camera))]
public class Camera__Patch
{
[HarmonyPatch("targetTexture", MethodType.Setter)]
[HarmonyPrefix]
private static void TargetTexture__Prefix(Camera __instance, ref RenderTexture value)
{
if (value == null)
return;

var width = ModConfig.EnableResolutionFix ? ModConfig.WidthResolution : 860;
var height = ModConfig.EnableResolutionFix ? ModConfig.HeightResolution : 520;
if (value.width == width && value.height == height)
return;

__instance.targetTexture = null;

value.Release();
value.width = width;
value.height = height;
value.Create();
}
}
40 changes: 40 additions & 0 deletions HDLethalCompanyRemake/Patch/HUDManager__Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;

namespace HDLethalCompany.Patch;

[HarmonyPatch(typeof(HUDManager))]
internal static class HUDManager__Patch
{
private static readonly AccessTools.FieldRef<HUDManager, Dictionary<RectTransform, ScanNodeProperties>>
ScanNodesRef =
AccessTools.FieldRefAccess<HUDManager, Dictionary<RectTransform, ScanNodeProperties>>("scanNodes");

[HarmonyPatch("UpdateScanNodes")]
[HarmonyPostfix]
private static void UpdateScanNodes__Postfix(PlayerControllerB playerScript, HUDManager __instance)
{
if (!ModConfig.EnableResolutionFix)
return;

var scanNodes = ScanNodesRef(__instance);
var halfWidth = ModConfig.WidthResolution / 2f;
var halfHeight = ModConfig.HeightResolution / 2f;
var widthMultiplier = ModConfig.WidthResolution / 860f;
var heightMultiplier = ModConfig.HeightResolution / 520f;
foreach (var scanElement in __instance.scanElements)
{
if (!scanNodes.TryGetValue(scanElement, out var scanNodeProperties))
continue;

var vector = playerScript.gameplayCamera.WorldToScreenPoint(scanNodeProperties.transform.position);
scanElement.anchoredPosition = vector with
{
x = (vector.x - halfWidth) / widthMultiplier,
y = (vector.y - halfHeight) / heightMultiplier
};
}
}
}
31 changes: 31 additions & 0 deletions HDLethalCompanyRemake/Patch/RoundManager__Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using HarmonyLib;
using UnityEngine;

namespace HDLethalCompany.Patch;

[HarmonyPatch(typeof(RoundManager))]
internal class RoundManager__Patch
{
[HarmonyPatch("GenerateNewFloor")]
[HarmonyPostfix]
private static void GenerateNewFloor__Postfix()
{
//The weather system overrides the fog settings without this
QualitySettingsPatch.SetFogQuality();

if (ModConfig.SetLOD != 0)
return;
RemoveLodFromGameObject("CatwalkStairs");
}

private static void RemoveLodFromGameObject(string name)
{
foreach (var lodGroup in Resources.FindObjectsOfTypeAll<LODGroup>())
{
if (lodGroup.gameObject.name != name)
continue;

lodGroup.enabled = false;
}
}
}
Loading