This commit is contained in:
erik 2025-06-09 02:03:11 +02:00
parent 01151e679b
commit 57b2f0400e
265 changed files with 22828 additions and 6 deletions

View file

@ -0,0 +1,56 @@
using System;
namespace Decal.Adapter.NetParser;
internal class MemberParser : MarshalByRefObject
{
public MemberParser Next;
public MemberParser Child;
public MemberParserType MemberType;
public string MemberName;
public MemberParserCondition Condition;
public string ConditionField;
public long ConditionXor;
public long ConditionAnd;
public long ConditionResult;
public string LengthField;
public long LengthMask;
public int LengthDelta;
public int PreAlignment;
public int PostAlignment;
public MemberParser()
{
}
public MemberParser(MemberParser Source)
{
Next = Source.Next;
Child = Source.Child;
MemberType = Source.MemberType;
MemberName = Source.MemberName;
Condition = Source.Condition;
ConditionField = Source.ConditionField;
ConditionXor = Source.ConditionXor;
ConditionAnd = Source.ConditionAnd;
ConditionResult = Source.ConditionResult;
LengthField = Source.LengthField;
LengthMask = Source.LengthMask;
LengthDelta = Source.LengthDelta;
PreAlignment = Source.PreAlignment;
PostAlignment = Source.PostAlignment;
}
}

View file

@ -0,0 +1,12 @@
namespace Decal.Adapter.NetParser;
internal enum MemberParserCondition
{
None,
EQ,
NE,
GE,
GT,
LE,
LT
}

View file

@ -0,0 +1,18 @@
namespace Decal.Adapter.NetParser;
internal enum MemberParserType
{
BYTE,
WORD,
PackedWORD,
DWORD,
PackedDWORD,
QWORD,
@float,
@double,
String,
WString,
Struct,
Vector,
Case
}

View file

@ -0,0 +1,41 @@
using System;
using System.Runtime.InteropServices;
using Decal.Interop.Net;
namespace Decal.Adapter.NetParser;
/// <summary>
/// Decal Message Factory Implementation
/// </summary>
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IMessageFactory))]
[ProgId("DecalAdapter.MessageFactory")]
[Guid("59D7815E-6716-4bd7-B264-69B6A9382701")]
public class MessageFactory : IMessageFactory
{
/// <summary>
/// Construct a new MessageFacytory instance
/// </summary>
public MessageFactory()
{
}
/// <summary>
/// Creates an IMessage2 instance from the provided raw packet data
/// </summary>
/// <param name="pData">Pointer to the raw packet bytes</param>
/// <param name="size">Size of pData in bytes</param>
/// <param name="outgoing">Packet direction</param>
/// <returns>IMessage2 instance to navigate the packet</returns>
IMessage2 IMessageFactory.CreateMessage(int pData, int size, bool outgoing)
{
if (pData != 0 && size != 0)
{
byte[] array = (byte[])Array.CreateInstance(typeof(byte), size);
Marshal.Copy(new IntPtr(pData), array, 0, size);
return new MessageWrapper(new Message(array, Message.GetParser(BitConverter.ToInt32(array, 0), outgoing ? MessageDirection.Outbound : MessageDirection.Inbound)));
}
return null;
}
}

View file

@ -0,0 +1,57 @@
using System.Runtime.InteropServices;
using Decal.Interop.Net;
namespace Decal.Adapter.NetParser;
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IMessageMember))]
[ProgId("DecalAdapter.MessageMemberWrapper")]
[Guid("BD22CFC5-0950-4ab3-9752-5053EE934BE6")]
public class MessageMemberWrapper : MessageRootImpl, IMessageMember
{
public int BeginOffset => Data.mOffset;
public int Count => Data.Count;
public int EndOffset => Data.mOffset + Data.mLength;
public MessageMemberWrapper()
{
}
internal MessageMemberWrapper(MessageStruct msg, MessageWrapper wrapper)
: base(msg, wrapper)
{
}
public string get_FieldName(int Index)
{
return Data.Name(Index);
}
public byte[] get_RawValue(object vIndex)
{
return Data.RawValue(Data.ObjectToIndex(vIndex));
}
public IMessageMember get_Struct(object vIndex)
{
int num = Data.ObjectToIndex(vIndex);
if (num < 0)
{
throw new COMHResultException((HResults)(-2147352571));
}
return new MessageMemberWrapper(Data.Struct(num), Wrapped);
}
public object get_Value(object vIndex)
{
int num = Data.ObjectToIndex(vIndex);
if (num >= 0)
{
return Data.Value<object>(num);
}
throw new COMHResultException((HResults)(-2147352571));
}
}

View file

@ -0,0 +1,124 @@
using System.Diagnostics;
using Decal.Interop.Net;
namespace Decal.Adapter.NetParser;
/// <summary>
/// IMessageIterator base implementation
/// </summary>
public class MessageRootImpl : MessageRoot, IMessageIterator
{
protected MessageWrapper Wrapped;
protected MessageStruct Data;
protected int FieldIndex;
protected const int Error = -1;
public object Current => Data.Value<object>(FieldIndex);
public string FieldName => Data.Name(FieldIndex);
public int Index => FieldIndex;
public IMessage Message => Wrapped;
public MessageRoot NextObjectIndex
{
[DebuggerNonUserCode]
get
{
if (FieldIndex < Data.mCount)
{
MessageMemberWrapper result = new MessageMemberWrapper(Data.Struct(FieldIndex), Wrapped);
FieldIndex++;
return result;
}
throw new COMHResultException(HResults.E_FAIL);
}
}
protected MessageRootImpl()
{
}
protected MessageRootImpl(MessageStruct data, MessageWrapper wrapper)
: this()
{
Wrapped = wrapper;
Data = data;
if (!Data.mParsed)
{
Data.Parse();
}
}
public void Reset()
{
FieldIndex = 0;
}
[DebuggerNonUserCode]
private T GetNext<T>(string name)
{
FieldIndex = Data.IndexFromName(name);
if (FieldIndex != -1)
{
return Data.Value<T>(FieldIndex);
}
throw new COMHResultException(HResults.E_FAIL);
}
[DebuggerNonUserCode]
private T GetNext<T>(int index)
{
if (index >= 0 && index < Data.mCount)
{
FieldIndex = index;
return Data.Value<T>(FieldIndex);
}
throw new COMHResultException(HResults.E_FAIL);
}
[DebuggerNonUserCode]
public object get_Next(object vIndex)
{
return GetNext<object>(Data.ObjectToIndex(vIndex));
}
[DebuggerNonUserCode]
public double get_NextFloat(string Name)
{
return GetNext<double>(Name);
}
[DebuggerNonUserCode]
public int get_NextInt(string Name)
{
return GetNext<int>(Name);
}
[DebuggerNonUserCode]
public MessageRoot get_NextObject(string Name)
{
FieldIndex = Data.IndexFromName(Name);
if (FieldIndex != -1)
{
return new MessageMemberWrapper(Data.Struct(FieldIndex), Wrapped);
}
throw new COMHResultException(HResults.E_FAIL);
}
[DebuggerNonUserCode]
public ulong get_NextQWord(string Name)
{
return GetNext<ulong>(Name);
}
[DebuggerNonUserCode]
public string get_NextString(string Name)
{
return GetNext<string>(Name);
}
}

View file

@ -0,0 +1,21 @@
using System.Runtime.InteropServices;
using Decal.Interop.Net;
namespace Decal.Adapter.NetParser;
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(MessageRoot))]
[ProgId("DecalAdapter.MessageRootWrapper")]
[Guid("E33FBF17-B6C5-471e-9ED6-A394DEDEBFE5")]
public class MessageRootWrapper : MessageRootImpl
{
public MessageRootWrapper()
{
}
internal MessageRootWrapper(MessageWrapper msg)
: base(msg.Wrapped.mStruct, msg)
{
}
}

View file

@ -0,0 +1,109 @@
using System.Runtime.InteropServices;
using Decal.Interop.Net;
namespace Decal.Adapter.NetParser;
/// <summary>
/// IMessage2 Implementation
/// </summary>
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IMessage2))]
[ProgId("DecalAdapter.MessageWrapper")]
[Guid("76142307-98E3-494d-8320-3C801010221D")]
public class MessageWrapper : IMessage2, IMessage
{
private Message msg;
internal Message Wrapped => msg;
/// <summary>
/// Return an IMessageIterator instance for this packet
/// </summary>
public MessageRoot Begin => new MessageRootWrapper(this);
/// <summary>
/// Return the number of items within this structure
/// </summary>
public int Count => msg.Count;
/// <summary>
/// Return the raw bytes of this structure
/// </summary>
public byte[] RawData => msg.RawData;
/// <summary>
/// Return the message type
/// </summary>
public int Type => msg.Type;
/// <summary>
/// Public constructor...
/// </summary>
public MessageWrapper()
{
}
/// <summary>
/// Internal constructor to wrap the Adapter parser
/// </summary>
/// <param name="msg">Adapter Message instance</param>
internal MessageWrapper(Message msg)
{
this.msg = msg;
if (!this.msg.mStruct.mParsed)
{
this.msg.mStruct.Parse();
}
}
/// <summary>
/// Get the field name for the specified index
/// </summary>
/// <param name="Index">message member index</param>
/// <returns>field name</returns>
public string get_FieldName(int Index)
{
return msg.Name(Index);
}
/// <summary>
/// Return the raw bytes for the specified member
/// </summary>
/// <param name="vElement">Member index (string or int)</param>
/// <returns>Byte array containing the member data</returns>
public byte[] get_RawValue(object vElement)
{
return msg.RawValue(msg.mStruct.ObjectToIndex(vElement));
}
/// <summary>
/// Return the specified member struct
/// </summary>
/// <param name="vElement">Member index (string or int)</param>
/// <returns>Member data</returns>
public IMessageMember get_Struct(object vElement)
{
int num = msg.mStruct.ObjectToIndex(vElement);
if (num < 0)
{
throw new COMHResultException((HResults)1);
}
return new MessageMemberWrapper(msg.Struct(num), this);
}
/// <summary>
/// Return the specified member data
/// </summary>
/// <param name="vElement">Member index (string or int)</param>
/// <returns>Member data</returns>
public object get_Value(object vElement)
{
int num = msg.mStruct.ObjectToIndex(vElement);
if (num >= 0)
{
return msg.Value<object>(num);
}
return null;
}
}