Skip to content
Open
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
35 changes: 30 additions & 5 deletions OCDheim/Keybindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace OCDheim
{
[HarmonyPatch(typeof(ZInput), "Load")]
public static class Keybindings
public class Keybindings
{
public const string GridMode = "GridMode";
public const string NoSnapMode = "AltPlace";
Expand Down Expand Up @@ -32,25 +32,50 @@ public static class Keybindings
public static bool SnapModeEnabled { get { return !ZInput.GetButton(NoSnapMode) && !ZInput.GetButton(JoyNoSnapMode); } }
public static bool SnapModeDisabled { get { return !SnapModeEnabled; } }

public static KeyCode PrecisionModeKeycode;
public static KeyCode PrecisionModeJoycode;
public static KeyCode GridModeKeycode;
public static KeyCode GridModeJoycode;
public static ZInput ZInstance;

public static void Postfix(ZInput __instance)
{
__instance.AddButton(PrecisionMode, KeyCode.Z);
__instance.AddButton(GridMode, KeyCode.LeftAlt);
__instance.AddButton(JoyGridMode, KeyCode.JoystickButton5);
__instance.AddButton(JoyPrecisionMode, KeyCode.JoystickButton2);
ZInstance = __instance;
__instance.AddButton(PrecisionMode, OCDheim.configPrecisionModeKeybind.Value.MainKey);
__instance.AddButton(JoyPrecisionMode, OCDheim.configPrecisionModeJoybind.Value.MainKey);
__instance.AddButton(GridMode, OCDheim.configGridModeKeybind.Value.MainKey);
__instance.AddButton(JoyGridMode, OCDheim.configGridModeJoybind.Value.MainKey);
}

public static void Refresh()
{
if (
ZInstance.GetButtonDef(PrecisionMode).m_key != OCDheim.configPrecisionModeKeybind.Value.MainKey
|| ZInstance.GetButtonDef(JoyPrecisionMode).m_key != OCDheim.configPrecisionModeJoybind.Value.MainKey
|| ZInstance.GetButtonDef(GridMode).m_key != OCDheim.configGridModeKeybind.Value.MainKey
|| ZInstance.GetButtonDef(JoyGridMode).m_key != OCDheim.configGridModeJoybind.Value.MainKey
)
{
Debug.Log("Keybind change detected, updating to use new value");
ZInstance.Setbutton(PrecisionMode, OCDheim.configPrecisionModeKeybind.Value.MainKey);
ZInstance.Setbutton(JoyPrecisionMode, OCDheim.configPrecisionModeJoybind.Value.MainKey);
ZInstance.Setbutton(GridMode, OCDheim.configGridModeKeybind.Value.MainKey);
ZInstance.Setbutton(JoyGridMode, OCDheim.configGridModeJoybind.Value.MainKey);
}

if (ZInput.GetButtonDown(GridMode) || ZInput.GetButtonDown(JoyGridMode))
{
GridModeEnabled = !GridModeEnabled;
gridModeFreshlyEnabled = GridModeEnabled;
gridModeFreshlyDisabled = GridModeDisabled;
Debug.Log("Grid Mode Toggle: " + GridModeEnabled);
Player.m_localPlayer.Message(MessageHud.MessageType.TopLeft,"Grid Mode: " + GridModeEnabled);
}
if (ZInput.GetButtonDown(PrecisionMode) || ZInput.GetButtonDown(JoyPrecisionMode))
{
PrecisionModeEnabled = !PrecisionModeEnabled;
Debug.Log("Precision Mode Toggle: " + PrecisionModeEnabled);
Player.m_localPlayer.Message(MessageHud.MessageType.TopLeft, "Precision Mode: " + PrecisionModeEnabled);
}
}

Expand Down
26 changes: 25 additions & 1 deletion OCDheim/OCDheim.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
Expand All @@ -10,7 +11,7 @@
namespace OCDheim
{
[BepInDependency(Jotunn.Main.ModGuid)]
[BepInPlugin("dymek.dev.OCDheim", "OCDheim", "0.1.2")]
[BepInPlugin("dymek.dev.OCDheim", "OCDheim", "0.1.4")]
[NetworkCompatibility(CompatibilityLevel.EveryoneMustHaveMod, VersionStrictness.Minor)]
public class OCDheim : BaseUnityPlugin
{
Expand All @@ -21,15 +22,30 @@ public class OCDheim : BaseUnityPlugin
private Harmony harmony { get; } = new Harmony("dymek.OCDheim");
private static OCDheim ocdheim { get; set; }

public static ConfigEntry<KeyboardShortcut> configPrecisionModeKeybind;
public static ConfigEntry<KeyboardShortcut> configPrecisionModeJoybind;
public static ConfigEntry<KeyboardShortcut> configGridModeKeybind;
public static ConfigEntry<KeyboardShortcut> configGridModeJoybind;

private void OCDHeimCreateConfigValues()
{
configPrecisionModeKeybind = Config.Bind("Keybinds", "PrecisionModeKeybind", new KeyboardShortcut(KeyCode.Z), "The keyboard binding for Precision Mode");
configPrecisionModeJoybind = Config.Bind("Keybinds", "PrecisionModeJoybind", new KeyboardShortcut(KeyCode.JoystickButton2), "The joystick binding for Precision Mode");
configGridModeKeybind = Config.Bind("Keybinds", "GridModeKeybind", new KeyboardShortcut(KeyCode.LeftAlt), "The keyboard binding for Grid Mode");
configGridModeJoybind = Config.Bind("Keybinds", "GridModeJoybind", new KeyboardShortcut(KeyCode.JoystickButton5), "The joystick binding for Grid Mode");
}

public static Texture2D LoadTextureFromDisk(string fileName) => AssetUtils.LoadTexture(Path.Combine(Path.GetDirectoryName(ocdheim.Info.Location), fileName));

public void Awake()
{
ocdheim = this;
harmony.PatchAll();
OCDHeimCreateConfigValues();
PrefabManager.OnVanillaPrefabsAvailable += AddOCDheimToolPieces;
PrefabManager.OnVanillaPrefabsAvailable += AddOCDheimBuildPieces;
PrefabManager.OnVanillaPrefabsAvailable += ModVanillaValheimTools;

}

private void AddOCDheimToolPieces()
Expand All @@ -41,6 +57,10 @@ private void AddOCDheimToolPieces()

private void AddToolPiece<TOverlayVisualizer>(string pieceName, string basePieceName, string pieceTable, Texture2D iconTexture, bool level = false, bool raise = false, bool smooth = false, bool paint = false) where TOverlayVisualizer: OverlayVisualizer
{
var pieceExists = PieceManager.Instance.GetPiece(pieceName) != null;
if (pieceExists)
return;

var pieceIcon = Sprite.Create(iconTexture, new Rect(0, 0, iconTexture.width, iconTexture.height), Vector2.zero);
var piece = new CustomPiece(pieceName, basePieceName, new PieceConfig
{
Expand Down Expand Up @@ -71,6 +91,10 @@ private void AddOCDheimBuildPieces()

private void AddBrickBuildPiece(string brickSuffix, Vector3 brickScale, int brickPrice, Texture2D iconTexture)
{
var pieceExists = PieceManager.Instance.GetPiece($"stone_floor_{brickSuffix}") != null;
if (pieceExists)
return;

var brick = PrefabManager.Instance.CreateClonedPrefab($"stone_floor_{brickSuffix}", "stone_floor_2x2");
var brickIcon = Sprite.Create(iconTexture, new Rect(0, 0, iconTexture.width, iconTexture.height), Vector2.zero);
brick.transform.localScale = brickScale;
Expand Down
63 changes: 57 additions & 6 deletions OCDheim/OCDheim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<WarningLevel>0</WarningLevel>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
Expand All @@ -34,7 +34,7 @@
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<WarningLevel>0</WarningLevel>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
Expand All @@ -45,11 +45,32 @@
<StartWorkingDirectory>$(VALHEIM_INSTALL)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.10.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HarmonyX.2.10.1\lib\net45\0Harmony.dll</HintPath>
<Reference Include="0Harmony">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\BepInEx\core\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Jotunn, Version=2.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\JotunnLib.2.10.0\lib\net462\Jotunn.dll</HintPath>
<Reference Include="assembly_utils">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_utils.dll</HintPath>
</Reference>
<Reference Include="assembly_utils_publicized">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\valheim_Data\Managed\publicized_assemblies\assembly_utils_publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_valheim">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_valheim.dll</HintPath>
</Reference>
<Reference Include="assembly_valheim_publicized">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\valheim_Data\Managed\publicized_assemblies\assembly_valheim_publicized.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<Reference Include="BepInEx.Harmony">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\BepInEx\core\BepInEx.Harmony.dll</HintPath>
</Reference>
<Reference Include="BepInEx.Preloader">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\BepInEx\core\BepInEx.Preloader.dll</HintPath>
</Reference>
<Reference Include="Jotunn">
<HintPath>D:\ValheimMods\Jotunn\Jotunn.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil, Version=0.11.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.4\lib\net40\Mono.Cecil.dll</HintPath>
Expand All @@ -74,11 +95,41 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Unity.Abstractions, Version=5.11.7.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\Unity.5.11.10\lib\net48\Unity.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Unity.Container, Version=5.11.11.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\Unity.5.11.10\lib\net48\Unity.Container.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\unstripped_corlib\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule">
<HintPath>..\..\..\..\..\..\steam\steamapps\common\Valheim\unstripped_corlib\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\unstripped_corlib\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\unstripped_corlib\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ParticleSystemModule">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\unstripped_corlib\UnityEngine.ParticleSystemModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\unstripped_corlib\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>..\..\..\..\..\..\Steam\steamapps\common\Valheim\unstripped_corlib\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="PreciseBuildPieceSnapper.cs" />
Expand Down
13 changes: 12 additions & 1 deletion OCDheim/PreciseBuildPieceSnapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public static void Postfix(bool flashGuardStone, Player __instance, GameObject _
}
}

public static void GetAllPiecesInRadius(Vector3 p, float radius, List<Piece> pieces)
{
if (Piece.s_ghostLayer == 0)
Piece.s_ghostLayer = LayerMask.NameToLayer("ghost");
foreach (Piece allPiece in Piece.s_allPieces)
{
if (allPiece.gameObject.layer != Piece.s_ghostLayer && (double)Vector3.Distance(p, allPiece.transform.position) < (double)radius)
pieces.Add(allPiece);
}
}

private static void SnapToNeighbourPiece(Piece buildPiece, int layerMask)
{
var playerPoV = DeterminePlayerPoV(layerMask);
Expand Down Expand Up @@ -114,7 +125,7 @@ private static List<Piece> FindNeighbourPieces(Vector3 playerPoV)
{
neighbourPieces.Clear();
snappableNeighbourPieces.Clear();
Piece.GetAllPiecesInRadius(playerPoV, NeighbourhoodSize, neighbourPieces);
GetAllPiecesInRadius(playerPoV, NeighbourhoodSize, neighbourPieces);
foreach (var neighbourPiece in neighbourPieces)
{
if (neighbourPiece.IsSnappablePiece())
Expand Down
2 changes: 1 addition & 1 deletion OCDheim/Visualization/HoverInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public HoverInfo(Transform parentTransform)

public void RotateToPlayer()
{
var playerXAxisDirection = new Vector3(GameCamera.m_instance.transform.position.x, transform.position.y, GameCamera.m_instance.transform.position.z);
var playerXAxisDirection = new Vector3(GameCamera.instance.transform.position.x, transform.position.y, GameCamera.instance.transform.position.z);
transform.LookAt(playerXAxisDirection, Vector3.up);
transform.Rotate(90f, 180f, 0f);
}
Expand Down
16 changes: 8 additions & 8 deletions OCDheim/app.config
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Mono.Cecil" publicKeyToken="50cebf1cceb9d05e" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-0.11.4.0" newVersion="0.11.4.0"/>
<assemblyIdentity name="Mono.Cecil" publicKeyToken="50cebf1cceb9d05e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.11.4.0" newVersion="0.11.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Mono.Cecil.Mdb" publicKeyToken="50cebf1cceb9d05e" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-0.10.4.0" newVersion="0.10.4.0"/>
<assemblyIdentity name="Mono.Cecil.Mdb" publicKeyToken="50cebf1cceb9d05e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.10.4.0" newVersion="0.10.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Mono.Cecil.Pdb" publicKeyToken="50cebf1cceb9d05e" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-0.10.4.0" newVersion="0.10.4.0"/>
<assemblyIdentity name="Mono.Cecil.Pdb" publicKeyToken="50cebf1cceb9d05e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.10.4.0" newVersion="0.10.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup></configuration>
2 changes: 2 additions & 0 deletions OCDheim/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<package id="MonoMod" version="22.5.1.1" targetFramework="net462" />
<package id="MonoMod.RuntimeDetour" version="22.5.1.1" targetFramework="net462" />
<package id="MonoMod.Utils" version="22.5.1.1" targetFramework="net462" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net48" />
<package id="Unity" version="5.11.10" targetFramework="net48" />
</packages>
2 changes: 1 addition & 1 deletion environment.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Needs to be your path to the base Valheim folder -->
<VALHEIM_INSTALL>C:\Program Files (x86)\Steam\steamapps\common\Valheim</VALHEIM_INSTALL>
<VALHEIM_INSTALL>C:\steam\steamapps\common\Valheim</VALHEIM_INSTALL>
<!-- This is the folder where your build gets copied to when using the post-build automations -->
<MOD_DEPLOYPATH>$(VALHEIM_INSTALL)\BepInEx\plugins</MOD_DEPLOYPATH>
</PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions environment.props.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Needs to be your path to the base Valheim folder -->
<VALHEIM_INSTALL>C:\Program Files (x86)\Steam\steamapps\common\Valheim</VALHEIM_INSTALL>
<!-- This is the folder where your build gets copied to when using the post-build automations -->
<MOD_DEPLOYPATH>$(VALHEIM_INSTALL)\BepInEx\plugins</MOD_DEPLOYPATH>
</PropertyGroup>
</Project>