diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4b9955f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,128 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +*.sln merge=binary +*.csproj merge=binary +*.vbproj merge=binary +*.vcxproj merge=binary +*.vcproj merge=binary +*.dbproj merge=binary +*.fsproj merge=binary +*.lsproj merge=binary +*.wixproj merge=binary +*.modelproj merge=binary +*.sqlproj merge=binary +*.wwaproj merge=binary +*.user merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +*.jpg binary +*.jpeg binary +*.png binary +*.gif binary +*.tif binary +*.tiff binary +*.ico binary +# SVG treated as an asset (binary) by default. +# *.svg text +# If you want to treat it as binary, +# use the following line instead. +*.svg binary +*.eps binary +*.webp binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain +*.bibtex text diff=bibtex +*.md text +*.tex text diff=tex +*.adoc text +*.textile text +*.mustache text +*.csv text +*.tab text +*.tsv text +*.txt text +*.sql text +*.ps1 text +*.props text +*.config text +.DotSettings text +LICENSE text + +# Scripts +*.bash text eol=lf +*.fish text eol=lf +*.sh text eol=lf +# These are explicitly windows files and should use crlf +*.bat text eol=crlf +*.cmd text eol=crlf + +# Serialisation +*.json text +*.toml text +*.xml text +*.yaml text +*.yml text + +# Archives +*.7z binary +*.gz binary +*.tar binary +*.tgz binary +*.zip binary +*.rar binary + +# Unity +*.unitypackage binary +*.manifest merge=binary + +# Text files where line endings should be preserved +*.patch -text + +# +# Exclude files from exporting +# +.gitattributes export-ignore +.gitignore export-ignore +.gitkeep export-ignore diff --git a/docs/LICENSE b/LICENSE similarity index 100% rename from docs/LICENSE rename to LICENSE diff --git a/src/Digitalroot.Valheim.Common.Utils.sln b/src/Digitalroot.Valheim.Common.Utils.sln index 30a3c39..dd5ed9f 100644 --- a/src/Digitalroot.Valheim.Common.Utils.sln +++ b/src/Digitalroot.Valheim.Common.Utils.sln @@ -1,13 +1,15 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31515.178 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Digitalroot.Valheim.Common.Utils", "Digitalroot.Valheim.Common.Utils\Digitalroot.Valheim.Common.Utils.csproj", "{0471A9E8-849B-4CF8-9F9C-509A52DFDCDE}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{538AE9FE-4607-4E9E-84AD-F9BDC01941FE}" ProjectSection(SolutionItems) = preProject + ..\.gitattributes = ..\.gitattributes ..\.gitignore = ..\.gitignore + ..\LICENSE = ..\LICENSE EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{BCAE0D15-8650-4F22-85DD-CB0257FBB5DE}" @@ -19,7 +21,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{AEF35CB5-96F3-4E94-969F-45FB4AF9DD50}" ProjectSection(SolutionItems) = preProject - ..\docs\LICENSE = ..\docs\LICENSE ..\docs\README.md = ..\docs\README.md EndProjectSection EndProject diff --git a/src/Digitalroot.Valheim.Common.Utils/Digitalroot.Valheim.Common.Utils.csproj b/src/Digitalroot.Valheim.Common.Utils/Digitalroot.Valheim.Common.Utils.csproj index 49c4b38..edda294 100644 --- a/src/Digitalroot.Valheim.Common.Utils/Digitalroot.Valheim.Common.Utils.csproj +++ b/src/Digitalroot.Valheim.Common.Utils/Digitalroot.Valheim.Common.Utils.csproj @@ -36,11 +36,6 @@ false - - - - - True @@ -48,4 +43,14 @@ + + + all + + + + + + + diff --git a/src/Digitalroot.Valheim.Common.Utils/GlobalSuppressions.cs b/src/Digitalroot.Valheim.Common.Utils/GlobalSuppressions.cs new file mode 100644 index 0000000..6b326af --- /dev/null +++ b/src/Digitalroot.Valheim.Common.Utils/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "", Scope = "member", Target = "~M:Digitalroot.Valheim.Common.Utils.Spawn(System.String,UnityEngine.GameObject,UnityEngine.Vector3,UnityEngine.Transform)~UnityEngine.GameObject")] diff --git a/src/Digitalroot.Valheim.Common.Utils/Utils.cs b/src/Digitalroot.Valheim.Common.Utils/Utils.cs index d41064a..83eeb7a 100644 --- a/src/Digitalroot.Valheim.Common.Utils/Utils.cs +++ b/src/Digitalroot.Valheim.Common.Utils/Utils.cs @@ -28,8 +28,8 @@ public static DirectoryInfo AssemblyDirectory { get { - string codeBase = Assembly.GetExecutingAssembly().CodeBase; - UriBuilder uri = new UriBuilder(codeBase); + var codeBase = Assembly.GetExecutingAssembly().CodeBase; + UriBuilder uri = new(codeBase); var fileInfo = new FileInfo(Uri.UnescapeDataString(uri.Path)); return fileInfo.Directory; } @@ -97,7 +97,7 @@ public static IEnumerable AllNames(Type type) public static Vector3 GetLocalPlayersPosition() => Player.m_localPlayer.transform.position; [UsedImplicitly] - public static ObjectDB GetObjectDB() => ObjectDB.instance != null ? ObjectDB.instance : null; + public static ObjectDB GetObjectDB() => ObjectDB.instance; [UsedImplicitly] public static string GetPluginPath(Type modPluginType) => Path.GetDirectoryName(modPluginType.Assembly.Location); @@ -111,25 +111,22 @@ public static IEnumerable AllNames(Type type) [UsedImplicitly] public static T GetPrivateField(object instance, string name) { - FieldInfo var = instance.GetType().GetField(name, BindingFlags.NonPublic | BindingFlags.Instance); + var var = instance.GetType().GetField(name, BindingFlags.NonPublic | BindingFlags.Instance); - if (var == null) - { - Log.Error(Logger,"Variable " + name + " does not exist on type: " + instance.GetType()); - return default(T); - } + if (var != null) return (T)var.GetValue(instance); + Log.Error(Logger,"Variable " + name + " does not exist on type: " + instance.GetType()); + return default; - return (T) var.GetValue(instance); } [UsedImplicitly] public static object InvokePrivate(object instance, string name, object[] args = null) { - MethodInfo method = instance.GetType().GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance); + var method = instance.GetType().GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance); if (method == null) { - Type[] types = args == null ? Type.EmptyTypes : args.Select(arg => arg.GetType()).ToArray(); + var types = args == null ? Type.EmptyTypes : args.Select(arg => arg.GetType()).ToArray(); method = instance.GetType().GetMethod(name, types); } @@ -183,7 +180,7 @@ public static string Localize(string value) [UsedImplicitly] public static Vector3 GetStartTemplesPosition() { - if (ZoneSystem.instance.FindClosestLocation("StartTemple", Vector3.zero, out ZoneSystem.LocationInstance locationInstance)) + if (ZoneSystem.instance.FindClosestLocation("StartTemple", Vector3.zero, out var locationInstance)) { Log.Trace(Logger, $"[GetStartTemplesPosition] StartTemple at {locationInstance.m_position}"); return locationInstance.m_position; @@ -196,7 +193,7 @@ public static Vector3 GetStartTemplesPosition() [UsedImplicitly] public static void SetPrivateField(object instance, string name, object value) { - FieldInfo var = instance.GetType().GetField(name, BindingFlags.NonPublic | BindingFlags.Instance); + var var = instance.GetType().GetField(name, BindingFlags.NonPublic | BindingFlags.Instance); if (var == null) { diff --git a/src/Digitalroot.Valheim.Common.Utils/packages.lock.json b/src/Digitalroot.Valheim.Common.Utils/packages.lock.json index 13b6367..16c978a 100644 --- a/src/Digitalroot.Valheim.Common.Utils/packages.lock.json +++ b/src/Digitalroot.Valheim.Common.Utils/packages.lock.json @@ -2,41 +2,40 @@ "version": 1, "dependencies": { ".NETFramework,Version=v4.6.2": { - "Digitalroot.Valheim.Common.Log": { + "BepInEx.Core": { "type": "Direct", - "requested": "[1.1.12, )", - "resolved": "1.1.12", - "contentHash": "B3hSoUf7LmO5kRdmn4Wi2NLFkAve24LSpTTFAL1F8DfoDPWE5m6jqqhH46H0wtTq/nGcqCTwNZ01GNQWncoKPw==", + "requested": "[5.4.16, )", + "resolved": "5.4.16", + "contentHash": "ywMFKW0SInV5U8h3mluStFI2xTJdrIaL8PLgrUMMhEA17NUZOKj8ZdlTu1Qoz6QJQslhp7b6KtwTOJXuAy9D+Q==", "dependencies": { "BepInEx.BaseLib": "5.4.16", - "BepInEx.Core": "5.4.16", - "Digitalroot.Valheim.Common.Json": "1.0.13" + "HarmonyX": "2.5.5" + } + }, + "Digitalroot.Valheim.Common.Log": { + "type": "Direct", + "requested": "[1.1.14, )", + "resolved": "1.1.14", + "contentHash": "+w/4bla2r6TRvFagSjxfozcnqDiH/xPfD33QtTECkQj6LZPQtZOM8IA1zeV/77mIECpbMyomJAHTVURtFFlF0w==", + "dependencies": { + "Digitalroot.Valheim.Common.Json": "1.0.14" } }, "Digitalroot.Valheim.Common.References": { "type": "Direct", - "requested": "[0.204.5, )", - "resolved": "0.204.5", - "contentHash": "5+E+7FDWDKAYzL8A1GfBFWmxu2p6LLbd+D5PR79RCAVmJTn/b2cPXdTCiNNe5/msrcpdyaGT3GFra1AjY/V+aA==" + "requested": "[0.205.6, )", + "resolved": "0.205.6", + "contentHash": "zXSnFD/lHssUcRpM/gciECcTNW5CXa/GyWXaqHM5labGjLW4ALui5cxuZuoD5N2pjt98bHLKdGFIm1xGIfO+IA==" }, "BepInEx.BaseLib": { "type": "Transitive", "resolved": "5.4.16", "contentHash": "DydXiAQqbb1mqC++WlwYqwJ5DN7o+jM8LSQ8P43t82WCAkJFny0ode48brrD6vilDQuxZ621SOK9uuI3xo3Gyg==" }, - "BepInEx.Core": { - "type": "Transitive", - "resolved": "5.4.16", - "contentHash": "ywMFKW0SInV5U8h3mluStFI2xTJdrIaL8PLgrUMMhEA17NUZOKj8ZdlTu1Qoz6QJQslhp7b6KtwTOJXuAy9D+Q==", - "dependencies": { - "BepInEx.BaseLib": "5.4.16", - "HarmonyX": "2.5.5" - } - }, "Digitalroot.Valheim.Common.Json": { "type": "Transitive", - "resolved": "1.0.13", - "contentHash": "OQAKK7D9+HHYSy8wi87C7s++6TFiTlE6oFPe1oqnO737ZUEQ1Ja0hb5AKjucaES9NdT9di7mk3sg48ajmv4RIQ==", + "resolved": "1.0.14", + "contentHash": "4ogco1dwkUwExMfr23rV69SH6KqgyUA4P+Vtims8K53WPg8+5IIf6vHfcnk9HMrKxMm53CA83BVYlemL0grwkg==", "dependencies": { "UnityEngine.Modules": "[2019.4.32]", "fastJSON": "2.4.0.4"