From 8512e81601c8c193072bd4006b639ecf33ac0fc4 Mon Sep 17 00:00:00 2001 From: Florian Kroiss Date: Sat, 23 Nov 2024 16:18:43 +0100 Subject: [PATCH] + Minor fixes to vs code settings + Patch ModSystemOreMap instead of ItemProspectingPick + Bump version --- .vscode/launch.json | 34 ++++++++++-------- ProspectTogether.sln | 25 +++++++++++++ resources/modinfo.json | 2 +- ...ngPickPatch.cs => ModSystemOreMapPatch.cs} | 36 +++++++++---------- src/Server/ServerStorage.cs | 2 +- 5 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 ProspectTogether.sln rename src/Server/{ProspectingPickPatch.cs => ModSystemOreMapPatch.cs} (51%) diff --git a/.vscode/launch.json b/.vscode/launch.json index f900243..d4393d5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,17 +1,23 @@ { "version": "0.2.0", - "configurations": [{ - "name": "Launch Client (.NET)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "Build (Debug)", - "program": "${env:VINTAGE_STORY}/Vintagestory.exe", - "args": [ - "--playStyle" , "preset-surviveandbuild", - "--openWorld" , "Strip World", - "--addModPath", "${workspaceFolder}/bin/Debug/Mods" - ], - "console": "internalConsole", - "internalConsoleOptions": "openOnSessionStart" - }] + "configurations": [ + { + "name": "Launch Client (.NET)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "Build (Debug)", + "program": "${env:VINTAGE_STORY}/Vintagestory.exe", + "args": [ + "--playStyle", + "preset-surviveandbuild", + "--openWorld", + "Strip World", + "--addModPath", + "${workspaceFolder}/bin/Debug/Mods" + ], + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart", + "justMyCode": false, + } + ] } \ No newline at end of file diff --git a/ProspectTogether.sln b/ProspectTogether.sln new file mode 100644 index 0000000..cfd6462 --- /dev/null +++ b/ProspectTogether.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProspectTogether", "ProspectTogether.csproj", "{27075B78-F64F-493A-93B8-E171E843AB8B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {27075B78-F64F-493A-93B8-E171E843AB8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {27075B78-F64F-493A-93B8-E171E843AB8B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {27075B78-F64F-493A-93B8-E171E843AB8B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {27075B78-F64F-493A-93B8-E171E843AB8B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FDF42B19-AAF3-4F35-B030-6C821FCD3264} + EndGlobalSection +EndGlobal diff --git a/resources/modinfo.json b/resources/modinfo.json index 47c34a9..c3fc4cd 100644 --- a/resources/modinfo.json +++ b/resources/modinfo.json @@ -5,7 +5,7 @@ "author": "Wooza", "side": "Universal", "description": "Stores and displays prospecting data on the map and allows sharing data between players. Based on ProspectoInfo by P3t3rix.", - "version": "1.4.0-rc.2", + "version": "1.4.0", "dependencies": { "game": "1.19.8" } diff --git a/src/Server/ProspectingPickPatch.cs b/src/Server/ModSystemOreMapPatch.cs similarity index 51% rename from src/Server/ProspectingPickPatch.cs rename to src/Server/ModSystemOreMapPatch.cs index 87e6f9d..90c581b 100644 --- a/src/Server/ProspectingPickPatch.cs +++ b/src/Server/ModSystemOreMapPatch.cs @@ -1,31 +1,30 @@ -using HarmonyLib; +using HarmonyLib; using ProspectTogether.Shared; using System.Collections.Generic; using System.Reflection; using Vintagestory.API.Common; using Vintagestory.API.MathTools; using Vintagestory.API.Server; +using Vintagestory.API.Util; using Vintagestory.GameContent; namespace ProspectTogether.Server { - [HarmonyPatch(typeof(ItemProspectingPick), "PrintProbeResults")] - class PrintProbeResultsPatch + [HarmonyPatch(typeof(ModSystemOreMap), "DidProbe")] + class ModSystemOreMapPatch { - static void Postfix(ItemProspectingPick __instance, IWorldAccessor world, IServerPlayer splr, ItemSlot itemslot, BlockPos pos) + static void Postfix(ModSystemOreMap __instance, PropickReading results, IServerPlayer splr) { - if (world.Side != EnumAppSide.Server) - return; - - // Some reflection to get access to some protected stuff - ProPickWorkSpace ppws = (ProPickWorkSpace)typeof(ItemProspectingPick).GetField("ppws", BindingFlags.NonPublic | + ICoreAPI api = (ICoreAPI)typeof(ModSystemOreMap).GetField("api", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); - MethodInfo GenProbeResultsMethod = typeof(ItemProspectingPick).GetMethod("GenProbeResults", BindingFlags.NonPublic | - BindingFlags.Instance); - PropickReading results = (PropickReading)GenProbeResultsMethod.Invoke(__instance, new object[] { world, pos }); - if (results == null) + // Obtain proPickWorkSpace to get page codes + ProPickWorkSpace proPickWorkSpace = ObjectCacheUtil.TryGet(api, "propickworkspace"); + + if (proPickWorkSpace is null) { + // We can't do much without it. + api.World.Logger.Error("propickworkspace is null"); return; } @@ -33,7 +32,7 @@ static void Postfix(ItemProspectingPick __instance, IWorldAccessor world, IServe var occurences = new List(); foreach (var reading in results.OreReadings) { - string pageCode = ppws.pageCodes[reading.Key]; + string pageCode = proPickWorkSpace.pageCodes[reading.Key]; if (reading.Value.TotalFactor > 0.025) { // +2 to offset for our Enum @@ -45,11 +44,12 @@ static void Postfix(ItemProspectingPick __instance, IWorldAccessor world, IServe } } + var pos = results.Position; + // Send information to Player - ProspectTogetherModSystem mod = world.Api.ModLoader.GetModSystem(); - IBlockAccessor blockAccess = world.BlockAccessor; - int chunksize = blockAccess.ChunkSize; - ProspectInfo info = new(new ChunkCoordinate(pos.X / chunksize, pos.Z / chunksize), occurences); + ProspectTogetherModSystem mod = api.ModLoader.GetModSystem(); + int chunksize = api.World.BlockAccessor.ChunkSize; + ProspectInfo info = new(new ChunkCoordinate(pos.XInt / chunksize, pos.ZInt / chunksize), occurences); mod.ServerStorage.UserProspected(info, splr); } } diff --git a/src/Server/ServerStorage.cs b/src/Server/ServerStorage.cs index bd4381f..0c11547 100644 --- a/src/Server/ServerStorage.cs +++ b/src/Server/ServerStorage.cs @@ -15,7 +15,7 @@ public class ServerStorage : CommonStorage private IServerNetworkChannel ServerChannel; - // Group id to to chunk to prospecting data + // Group id to chunk to prospecting data public Dictionary> Data = new(); public ServerStorage(ICoreServerAPI api, ServerModConfig config, string fileName) : base(api, config, fileName)