Init
This commit is contained in:
7
Assets/MindPowerSdk/Base/GlobalDefiens.cs
Normal file
7
Assets/MindPowerSdk/Base/GlobalDefiens.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace MindPowerSdk
|
||||
{
|
||||
public static class GlobalDefine
|
||||
{
|
||||
public static string ClientDir = "";
|
||||
}
|
||||
}
|
||||
3
Assets/MindPowerSdk/Base/GlobalDefiens.cs.meta
generated
Normal file
3
Assets/MindPowerSdk/Base/GlobalDefiens.cs.meta
generated
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fc62595d74a4f958f1aaed2f48adb47
|
||||
timeCreated: 1727962264
|
||||
51
Assets/MindPowerSdk/Base/StructReader.cs
Normal file
51
Assets/MindPowerSdk/Base/StructReader.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MindPowerSdk
|
||||
{
|
||||
public static class StructReader
|
||||
{
|
||||
public static T ReadStruct<T>(BinaryReader reader)
|
||||
{
|
||||
byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(T)));
|
||||
|
||||
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
|
||||
handle.Free();
|
||||
|
||||
return theStructure;
|
||||
}
|
||||
|
||||
public static T ReadStructFromArray<T>(byte[] bytes)
|
||||
{
|
||||
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
|
||||
handle.Free();
|
||||
return theStructure;
|
||||
}
|
||||
|
||||
public static T[] ReadStructArray<T>(BinaryReader reader, int size)
|
||||
{
|
||||
T[] theStructures = new T[size];
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
theStructures[i] = ReadStruct<T>(reader);
|
||||
}
|
||||
|
||||
return theStructures;
|
||||
}
|
||||
|
||||
public static T[] ReadStructArray<T>(BinaryReader reader, uint size)
|
||||
{
|
||||
T[] theStructures = new T[size];
|
||||
|
||||
for (uint i = 0; i < size; i++)
|
||||
{
|
||||
theStructures[i] = ReadStruct<T>(reader);
|
||||
}
|
||||
|
||||
return theStructures;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/MindPowerSdk/Base/StructReader.cs.meta
generated
Normal file
3
Assets/MindPowerSdk/Base/StructReader.cs.meta
generated
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 635ded6c26144e1b85bd47293dd9409d
|
||||
timeCreated: 1727962573
|
||||
Reference in New Issue
Block a user