Skip to content

Commit

Permalink
Replace various Mt types with types from System.Numerics and System.D…
Browse files Browse the repository at this point in the history
…rawing namespaces
  • Loading branch information
Fexty12573 committed Feb 17, 2024
1 parent 27317af commit bea1094
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 545 deletions.
19 changes: 10 additions & 9 deletions Examples/ExperimentalTesting/InternalCalls.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SharpPluginLoader.InternalCallGenerator;
using System.Numerics;
using SharpPluginLoader.InternalCallGenerator;
using SharpPluginLoader.Core.MtTypes;
using SharpPluginLoader.Core;

Expand All @@ -7,7 +8,7 @@ namespace ExperimentalTesting;
public struct HasRefTypes
{
public string str;
public MtVector2 vec;
public Vector2 vec;
}

[InternalCallManager]
Expand All @@ -27,7 +28,7 @@ public partial class InternalCalls

// Test with array and pointer types
[InternalCall]
public static unsafe partial void TransformCoordinates(float[] coords, MtVector3* transformMatrix);
public static unsafe partial void TransformCoordinates(float[] coords, Vector3* transformMatrix);

// Test with InternalCallOptions and ref parameter
[InternalCall(InternalCallOptions.Unsafe)]
Expand All @@ -39,27 +40,27 @@ public partial class InternalCalls

// Test with complex struct return type and primitive parameters
[InternalCall]
public static partial MtMatrix4X4 ComputeStruct(int param1, float param2);
public static partial Matrix4x4 ComputeStruct(int param1, float param2);

// Test with pointer to struct and primitive types
[InternalCall]
public static unsafe partial MtVector2* CreateVector(int x, int y);
public static unsafe partial Vector2* CreateVector(int x, int y);

// Test with multiple ref and out parameters
[InternalCall]
public static partial void TestRefOutParameters(ref float a, out double b, ref MtVector2 vec);
public static partial void TestRefOutParameters(ref float a, out double b, ref Vector2 vec);

// Test with mixed array, pointer, and primitive types
[InternalCall]
public static unsafe partial void ProcessBuffers(byte[] inputBuffer, float* outputBuffer, int bufferSize);

// Test with strings
[InternalCall]
public static partial MtVector2 Parse(string str);
public static partial Vector2 Parse(string str);

[InternalCall]
[return: WideString]
public static partial string Format(MtVector2 vec, [WideString] string str);
public static partial string Format(Vector2 vec, [WideString] string str);

[InternalCall]
public static partial void EnumTest(PropType type);
Expand Down Expand Up @@ -92,5 +93,5 @@ public partial class InternalCalls
public static partial void DisplayFatalErrorMessage(string message);

[InternalCall]
public static partial void InParameterTest(in MtVector2 vec);
public static partial void InParameterTest(in Vector2 vec);
}
3 changes: 2 additions & 1 deletion SharpPluginLoader.Core/Collision/CollisionNodeObject.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using SharpPluginLoader.Core.MtTypes;
Expand Down Expand Up @@ -28,5 +29,5 @@ public CollisionNodeObject() { }
/// <summary>
/// The move vector of the node.
/// </summary>
public ref MtVector4 MoveVector => ref GetRef<MtVector4>(0xA0);
public ref Vector4 MoveVector => ref GetRef<Vector4>(0xA0);
}
3 changes: 2 additions & 1 deletion SharpPluginLoader.Core/Components/CollisionComponentTypes.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using SharpPluginLoader.Core.Collision;
Expand All @@ -19,7 +20,7 @@ public Node() { }
/// <summary>
/// Gets the world matrix of this node.
/// </summary>
public ref MtMatrix4X4 WorldMatrix => ref GetRef<MtMatrix4X4>(0x10);
public ref Matrix4x4 WorldMatrix => ref GetRef<Matrix4x4>(0x10);

/// <summary>
/// Gets the geometry of this node.
Expand Down
17 changes: 9 additions & 8 deletions SharpPluginLoader.Core/Entities/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SharpPluginLoader.Core.Actions;
using System.Numerics;
using SharpPluginLoader.Core.Actions;
using SharpPluginLoader.Core.Components;
using SharpPluginLoader.Core.Memory;
using SharpPluginLoader.Core.Models;
Expand Down Expand Up @@ -81,7 +82,7 @@ public unsafe void CreateEffect(MtObject effect)
/// <param name="shlpIndex">The index of the shlp in the shll</param>
/// <param name="target">The position the shell should travel towards</param>
/// <param name="origin">The origin of the shell (or null for the entity itself)</param>
public virtual unsafe void CreateShell(int shllIndex, int shlpIndex, MtVector3 target, MtVector3? origin = null)
public virtual unsafe void CreateShell(int shllIndex, int shlpIndex, Vector3 target, Vector3? origin = null)
{
var shellParams = ShellCreationParams.Create(target, origin ?? Position);
CreateShellFunc.Invoke(ShllArray.Address, shllIndex, shlpIndex, Instance, Instance, MemoryUtil.AddressOf(ref shellParams));
Expand Down Expand Up @@ -110,7 +111,7 @@ public virtual unsafe void CreateShell(int shllIndex, int shlpIndex)
/// <param name="index">The index of the shell in the entities shell list (shll)</param>
/// <param name="target">The position the shell should travel towards</param>
/// <param name="origin">The origin of the shell (or null for the entity itself)</param>
public virtual void CreateShell(uint index, MtVector3 target, MtVector3? origin = null)
public virtual void CreateShell(uint index, Vector3 target, Vector3? origin = null)
{
throw new NotImplementedException();
}
Expand All @@ -123,7 +124,7 @@ public virtual void CreateShell(uint index, MtVector3 target, MtVector3? origin
/// <param name="target">The position the shell should travel towards</param>
/// <param name="origin">The origin of the shell (or null for the entity itself)</param>
/// <remarks><b>Tip:</b> You can load any shll file using <see cref="ResourceManager.GetResource{T}"/></remarks>
public virtual void CreateShell(ShellParamList shll, uint index, MtVector3 target, MtVector3? origin = null)
public virtual void CreateShell(ShellParamList shll, uint index, Vector3 target, Vector3? origin = null)
{
throw new NotImplementedException();
}
Expand All @@ -134,7 +135,7 @@ public virtual void CreateShell(ShellParamList shll, uint index, MtVector3 targe
/// <param name="shell">The shell to spawn</param>
/// <param name="target">The target position of the shell</param>
/// <param name="origin">The origin position of the shell (or null for the entity itself)</param>
public virtual void CreateShell(ShellParam shell, MtVector3 target, MtVector3? origin = null)
public virtual void CreateShell(ShellParam shell, Vector3 target, Vector3? origin = null)
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -234,7 +235,7 @@ public unsafe bool RegisterShll(string path, int index = -1)
internal unsafe struct ShellCreationParams
{
public static ref ShellCreationParams Default() => ref MemoryUtil.GetRef<ShellCreationParams>(0x143f939e0);
public static ShellCreationParams Create(MtVector3 target, MtVector3 origin)
public static ShellCreationParams Create(Vector3 target, Vector3 origin)
{
ShellCreationParams defaultParams = Default();
defaultParams.Populate(target, origin);
Expand All @@ -250,7 +251,7 @@ public static ShellCreationParams Create(MtVector3 target, MtVector3 origin)
return (T*)((nint)ptr + offset);
}

public ShellCreationParams(MtVector3 target, MtVector3 origin)
public ShellCreationParams(Vector3 target, Vector3 origin)
{
Values[0] = origin.X;
Values[1] = origin.Y;
Expand All @@ -271,7 +272,7 @@ public ShellCreationParams(MtVector3 target, MtVector3 origin)
ivals[2] = -1;
}

private void Populate(MtVector3 target, MtVector3 origin)
private void Populate(Vector3 target, Vector3 origin)
{
Values[0] = origin.X;
Values[1] = origin.Y;
Expand Down
5 changes: 3 additions & 2 deletions SharpPluginLoader.Core/Entities/Monster.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SharpPluginLoader.Core.Memory;
using System.Numerics;
using SharpPluginLoader.Core.Memory;
using SharpPluginLoader.Core.MtTypes;

namespace SharpPluginLoader.Core.Entities
Expand Down Expand Up @@ -123,7 +124,7 @@ public void SetTarget(nint target)
public nint AiData => Get<nint>(0x12278);

/// <inheritdoc/>
public override void CreateShell(uint index, MtVector3 target, MtVector3? origin = null)
public override void CreateShell(uint index, Vector3 target, Vector3? origin = null)
{
base.CreateShell(index, target, origin);
}
Expand Down
9 changes: 5 additions & 4 deletions SharpPluginLoader.Core/Entities/Player.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SharpPluginLoader.Core.Memory;
using System.Numerics;
using SharpPluginLoader.Core.Memory;
using SharpPluginLoader.Core.MtTypes;
using SharpPluginLoader.Core.Resources;
using SharpPluginLoader.Core.Weapons;
Expand Down Expand Up @@ -38,7 +39,7 @@ public static unsafe Player? MainPlayer
public WeaponType CurrentWeaponType => CurrentWeapon?.Type ?? WeaponType.None;

/// <inheritdoc/>
public override void CreateShell(uint index, MtVector3 target, MtVector3? origin = null)
public override void CreateShell(uint index, Vector3 target, Vector3? origin = null)
{
var shll = CurrentWeaponType < WeaponType.Bow
? CurrentWeapon?.GetObject<ShellParamList>(0x1D90) // Weapon shll
Expand All @@ -50,7 +51,7 @@ public override void CreateShell(uint index, MtVector3 target, MtVector3? origin
CreateShell(shll, index, target, origin);
}

public override void CreateShell(ShellParamList shll, uint index, MtVector3 target, MtVector3? origin = null)
public override void CreateShell(ShellParamList shll, uint index, Vector3 target, Vector3? origin = null)
{
var shell = shll.GetShell(index);
if (shell == null)
Expand All @@ -59,7 +60,7 @@ public override void CreateShell(ShellParamList shll, uint index, MtVector3 targ
CreateShell(shell, target, origin);
}

public override unsafe void CreateShell(ShellParam shell, MtVector3 target, MtVector3? origin = null)
public override unsafe void CreateShell(ShellParam shell, Vector3 target, Vector3? origin = null)
{
var shellParams = new ShellCreationParams(target, origin ?? Position);
CreateShellFunc.Invoke(shell.Instance, Instance, Instance, (nint)(&shellParams));
Expand Down
3 changes: 2 additions & 1 deletion SharpPluginLoader.Core/Gui.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Numerics;
using System.Runtime.InteropServices;
using SharpPluginLoader.Core.Memory;
using SharpPluginLoader.Core.MtTypes;
Expand Down Expand Up @@ -66,7 +67,7 @@ public static void DisplayYesNoDialog(string message, DialogCallback callback)
InternalCalls.QueueYesNoDialog(msgPtr);
}

public static unsafe void DisplayMessageWindow(string message, MtVector2 offset = new())
public static unsafe void DisplayMessageWindow(string message, Vector2 offset = new())
{
var msgPtr = Marshal.StringToHGlobalAnsi(message);
var offsetPtr = &offset;
Expand Down
13 changes: 7 additions & 6 deletions SharpPluginLoader.Core/Models/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using SharpPluginLoader.Core.Resources;
Expand All @@ -20,17 +21,17 @@ public Model() { }
/// <summary>
/// The position of the model
/// </summary>
public ref MtVector3 Position => ref GetRef<MtVector3>(0x160);
public ref Vector3 Position => ref GetRef<Vector3>(0x160);

/// <summary>
/// The size of the model
/// </summary>
public ref MtVector3 Size => ref GetRef<MtVector3>(0x180);
public ref Vector3 Size => ref GetRef<Vector3>(0x180);

/// <summary>
/// The position of the model's collision box
/// </summary>
public ref MtVector3 CollisionPosition => ref GetRef<MtVector3>(0xA50);
public ref Vector3 CollisionPosition => ref GetRef<Vector3>(0xA50);

/// <summary>
/// The rotation of the model
Expand All @@ -40,7 +41,7 @@ public Model() { }
/// <summary>
/// The model's forward vector
/// </summary>
public MtVector3 Forward => Rotation * MtVector3.Forward;
public Vector3 Forward => Rotation * Vector3.UnitZ;

/// <summary>
/// Freezes the model and pauses all processing
Expand All @@ -56,7 +57,7 @@ public bool Frozen
/// </summary>
/// <remarks>Use this function if you need to move a model and ignore walls.</remarks>
/// <param name="position">The target position</param>
public void Teleport(MtVector3 position)
public void Teleport(Vector3 position)
{
Position = position;
CollisionPosition = position;
Expand All @@ -68,7 +69,7 @@ public void Teleport(MtVector3 position)
/// <param name="size">The new size of the model</param>
public void Resize(float size)
{
Size = new MtVector3(size, size, size);
Size = new Vector3(size, size, size);
}

/// <summary>
Expand Down
40 changes: 6 additions & 34 deletions SharpPluginLoader.Core/MtTypes/MtMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,27 @@

namespace SharpPluginLoader.Core.MtTypes
{
public struct MtMatrix3X3 // TODO: Finish this
public unsafe struct MtMatrix3X3 // TODO: Finish this
{
public unsafe fixed float Data[9];

public unsafe float this[int index]
public fixed float Data[9];
public float this[int index]
{
get => Data[index];
set => Data[index] = value;
}

public unsafe float this[int row, int col]
public float this[int row, int col]
{
get => Data[row * 3 + col];
set => Data[row * 3 + col] = value;
}

public static MtMatrix3X3 Identity => new MtMatrix3X3
public static MtMatrix3X3 Identity => new()
{
[0, 0] = 1,
[1, 1] = 1,
[2, 2] = 1
};
}

public struct MtMatrix4X4 // TODO: Finish this
{
public unsafe fixed float Data[16];

public unsafe float this[int index]
{
get => Data[index];
set => Data[index] = value;
}

public unsafe float this[int row, int col]
{
get => Data[row * 4 + col];
set => Data[row * 4 + col] = value;
}

public static implicit operator Matrix4x4(MtMatrix4X4 m) => Unsafe.As<MtMatrix4X4, Matrix4x4>(ref m);
public static implicit operator MtMatrix4X4(Matrix4x4 m) => Unsafe.As<Matrix4x4, MtMatrix4X4>(ref m);

public static MtMatrix4X4 Identity => new()
{
[0, 0] = 1,
[1, 1] = 1,
[2, 2] = 1,
[3, 3] = 1
};
}
}
Loading

0 comments on commit bea1094

Please sign in to comment.