using BrewMonster; using CSNetwork.GPDataType; using System; using System.Collections; using System.Runtime.InteropServices; using UnityEngine; using static EC_Player; public static class EC_Utility { public static byte glb_CompressDirH(float x, float z) { const float fInvInter = 256.0f / 360.0f; if (Math.Abs(x) < 0.00001f) { if (z > 0.0f) return 64; else return 192; } else { // atan2 trong C# trả về radian, cần đổi sang độ float fDeg = (float)(Math.Atan2(z, x) * (180.0 / Math.PI)); // đảm bảo góc nằm trong [0, 360) if (fDeg < 0) fDeg += 360.0f; return (byte)(fDeg * fInvInter); } } public static float FIX8TOFLOAT(int x) => x / 256.0f; public static T ByteArrayToStructure(byte[] bytes) where T : struct { GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { return Marshal.PtrToStructure(handle.AddrOfPinnedObject()); } finally { handle.Free(); } } public static Vector3 glb_DecompressDirH(byte byDir) { const float fInter = 360.0f / 256.0f; float fRad = Mathf.Deg2Rad * (byDir * fInter); Vector3 v; v.x = Mathf.Cos(fRad); v.z = Mathf.Sin(fRad); v.y = 0.0f; return v; } public static System.Numerics.Vector3 ToNumerics(this UnityEngine.Vector3 v) { return new System.Numerics.Vector3(v.x, v.y, v.z); } public static A3DVECTOR3 ToA3DVECTOR3(this UnityEngine.Vector3 v) { return new A3DVECTOR3(v.x, v.y, v.z); } public static Vector3 ToVector3(A3DVECTOR3 a3DVECTOR3) { return new Vector3(a3DVECTOR3.x, a3DVECTOR3.y, a3DVECTOR3.z); } public static float MagnitudeH(this Vector3 v) { return Mathf.Sqrt(v.x * v.x + v.z * v.z); } public static string BuildActionName(PLAYER_ACTION action, int weaponType) { string prefix = action.data.ActionPrefix ?? string.Empty; string suffix = string.Empty; if (action.data.action_weapon_suffix != null && weaponType >= 0 && weaponType < action.data.action_weapon_suffix.Length) { suffix = action.data.action_weapon_suffix[weaponType].Suffix ?? string.Empty; } return $"{prefix}_{suffix}"; } }