Telemetry

This commit is contained in:
erikn 2025-04-26 16:55:48 +02:00
parent e010b9d126
commit 78a2479d6c
8 changed files with 446 additions and 6 deletions

76
MosswartMassacre/Utils.cs Normal file
View file

@ -0,0 +1,76 @@
using System;
using Decal.Adapter;
using Decal.Adapter.Wrappers;
using System.Numerics;
namespace MosswartMassacre
{
/// <summary>
/// Misc. helpers shared across the plugin.
/// Add new utilities here as your project grows.
/// </summary>
public static class Utils
{
/* ----------------------------------------------------------
* 1) Direct-memory physics helpers
* -------------------------------------------------------- */
/// <summary>
/// Return the players raw world position by reading the
/// physics-object pointer (same offsets UB uses: +0x84/88/8C).
/// </summary>
public static unsafe Vector3 GetPlayerPosition()
{
try
{
int id = CoreManager.Current.CharacterFilter.Id;
if (!CoreManager.Current.Actions.IsValidObject(id))
return new Vector3();
byte* p = (byte*)CoreManager.Current.Actions.Underlying.GetPhysicsObjectPtr(id);
return new Vector3(
*(float*)(p + 0x84), // X
*(float*)(p + 0x88), // Y
*(float*)(p + 0x8C)); // Z
}
catch
{
return new Vector3();
}
}
/// <summary>
/// Convenience: returns the current landcell (upper 16 bits of landblock).
/// </summary>
public static uint GetPlayerLandcell() =>
(uint)CoreManager.Current.Actions.Landcell;
/* ----------------------------------------------------------
* 2) High-level wrappers around Geometry / Coordinates
* -------------------------------------------------------- */
/// <summary>
/// Get AC-style coordinates (EW/NS) for the player in one call.
/// </summary>
public static Coordinates GetPlayerCoordinates()
{
Vector3 pos = GetPlayerPosition();
uint landcell = GetPlayerLandcell();
double ew = Geometry.LandblockToEW(landcell, pos.X);
double ns = Geometry.LandblockToNS(landcell, pos.Y);
return new Coordinates(ew, ns, pos.Z);
}
/* ----------------------------------------------------------
* 3) Generic math helpers you may want later
* -------------------------------------------------------- */
public static double Clamp(double value, double min, double max) =>
value < min ? min : (value > max ? max : value);
public static double DegToRad(double deg) => deg * Math.PI / 180.0;
public static double RadToDeg(double rad) => rad * 180.0 / Math.PI;
}
}