using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;

namespace HIVECOMKERNELLib;

internal sealed class _IHKernelEvents_EventProvider : _IHKernelEvents_Event, IDisposable
{
	private WeakReference m_wkConnectionPointContainer;

	private ArrayList m_aEventSinkHelpers;

	private IConnectionPoint m_ConnectionPoint;

	private void Init()
	{
		IConnectionPoint ppCP = null;
		Guid riid = new Guid(new byte[16]
		{
			210, 192, 126, 79, 252, 125, 148, 75, 182, 41,
			78, 254, 139, 87, 28, 150
		});
		((IConnectionPointContainer)m_wkConnectionPointContainer.Target).FindConnectionPoint(ref riid, out ppCP);
		m_ConnectionPoint = ppCP;
		m_aEventSinkHelpers = new ArrayList();
	}

	public void add_TestDone(_IHKernelEvents_TestDoneEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_ConnectionPoint == null)
			{
				Init();
			}
			_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = new _IHKernelEvents_SinkHelper();
			int pdwCookie = 0;
			m_ConnectionPoint.Advise(iHKernelEvents_SinkHelper, out pdwCookie);
			iHKernelEvents_SinkHelper.m_dwCookie = pdwCookie;
			iHKernelEvents_SinkHelper.m_TestDoneDelegate = P_0;
			m_aEventSinkHelpers.Add(iHKernelEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_TestDone(_IHKernelEvents_TestDoneEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_aEventSinkHelpers == null)
			{
				return;
			}
			int count = m_aEventSinkHelpers.Count;
			int num = 0;
			if (0 >= count)
			{
				return;
			}
			do
			{
				_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = (_IHKernelEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iHKernelEvents_SinkHelper.m_TestDoneDelegate != null && ((iHKernelEvents_SinkHelper.m_TestDoneDelegate.Equals(P_0) ? 1u : 0u) & 0xFFu) != 0)
				{
					m_aEventSinkHelpers.RemoveAt(num);
					m_ConnectionPoint.Unadvise(iHKernelEvents_SinkHelper.m_dwCookie);
					if (count <= 1)
					{
						Marshal.ReleaseComObject(m_ConnectionPoint);
						m_ConnectionPoint = null;
						m_aEventSinkHelpers = null;
					}
					break;
				}
				num++;
			}
			while (num < count);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void add_OnTextOut(_IHKernelEvents_OnTextOutEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_ConnectionPoint == null)
			{
				Init();
			}
			_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = new _IHKernelEvents_SinkHelper();
			int pdwCookie = 0;
			m_ConnectionPoint.Advise(iHKernelEvents_SinkHelper, out pdwCookie);
			iHKernelEvents_SinkHelper.m_dwCookie = pdwCookie;
			iHKernelEvents_SinkHelper.m_OnTextOutDelegate = P_0;
			m_aEventSinkHelpers.Add(iHKernelEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_OnTextOut(_IHKernelEvents_OnTextOutEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_aEventSinkHelpers == null)
			{
				return;
			}
			int count = m_aEventSinkHelpers.Count;
			int num = 0;
			if (0 >= count)
			{
				return;
			}
			do
			{
				_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = (_IHKernelEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iHKernelEvents_SinkHelper.m_OnTextOutDelegate != null && ((iHKernelEvents_SinkHelper.m_OnTextOutDelegate.Equals(P_0) ? 1u : 0u) & 0xFFu) != 0)
				{
					m_aEventSinkHelpers.RemoveAt(num);
					m_ConnectionPoint.Unadvise(iHKernelEvents_SinkHelper.m_dwCookie);
					if (count <= 1)
					{
						Marshal.ReleaseComObject(m_ConnectionPoint);
						m_ConnectionPoint = null;
						m_aEventSinkHelpers = null;
					}
					break;
				}
				num++;
			}
			while (num < count);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void add_OnPrintMsg(_IHKernelEvents_OnPrintMsgEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_ConnectionPoint == null)
			{
				Init();
			}
			_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = new _IHKernelEvents_SinkHelper();
			int pdwCookie = 0;
			m_ConnectionPoint.Advise(iHKernelEvents_SinkHelper, out pdwCookie);
			iHKernelEvents_SinkHelper.m_dwCookie = pdwCookie;
			iHKernelEvents_SinkHelper.m_OnPrintMsgDelegate = P_0;
			m_aEventSinkHelpers.Add(iHKernelEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_OnPrintMsg(_IHKernelEvents_OnPrintMsgEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_aEventSinkHelpers == null)
			{
				return;
			}
			int count = m_aEventSinkHelpers.Count;
			int num = 0;
			if (0 >= count)
			{
				return;
			}
			do
			{
				_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = (_IHKernelEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iHKernelEvents_SinkHelper.m_OnPrintMsgDelegate != null && ((iHKernelEvents_SinkHelper.m_OnPrintMsgDelegate.Equals(P_0) ? 1u : 0u) & 0xFFu) != 0)
				{
					m_aEventSinkHelpers.RemoveAt(num);
					m_ConnectionPoint.Unadvise(iHKernelEvents_SinkHelper.m_dwCookie);
					if (count <= 1)
					{
						Marshal.ReleaseComObject(m_ConnectionPoint);
						m_ConnectionPoint = null;
						m_aEventSinkHelpers = null;
					}
					break;
				}
				num++;
			}
			while (num < count);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void add_OnTPLWindowMsg(_IHKernelEvents_OnTPLWindowMsgEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_ConnectionPoint == null)
			{
				Init();
			}
			_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = new _IHKernelEvents_SinkHelper();
			int pdwCookie = 0;
			m_ConnectionPoint.Advise(iHKernelEvents_SinkHelper, out pdwCookie);
			iHKernelEvents_SinkHelper.m_dwCookie = pdwCookie;
			iHKernelEvents_SinkHelper.m_OnTPLWindowMsgDelegate = P_0;
			m_aEventSinkHelpers.Add(iHKernelEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_OnTPLWindowMsg(_IHKernelEvents_OnTPLWindowMsgEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_aEventSinkHelpers == null)
			{
				return;
			}
			int count = m_aEventSinkHelpers.Count;
			int num = 0;
			if (0 >= count)
			{
				return;
			}
			do
			{
				_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = (_IHKernelEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iHKernelEvents_SinkHelper.m_OnTPLWindowMsgDelegate != null && ((iHKernelEvents_SinkHelper.m_OnTPLWindowMsgDelegate.Equals(P_0) ? 1u : 0u) & 0xFFu) != 0)
				{
					m_aEventSinkHelpers.RemoveAt(num);
					m_ConnectionPoint.Unadvise(iHKernelEvents_SinkHelper.m_dwCookie);
					if (count <= 1)
					{
						Marshal.ReleaseComObject(m_ConnectionPoint);
						m_ConnectionPoint = null;
						m_aEventSinkHelpers = null;
					}
					break;
				}
				num++;
			}
			while (num < count);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void add_OnHTMLWindowMsg(_IHKernelEvents_OnHTMLWindowMsgEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_ConnectionPoint == null)
			{
				Init();
			}
			_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = new _IHKernelEvents_SinkHelper();
			int pdwCookie = 0;
			m_ConnectionPoint.Advise(iHKernelEvents_SinkHelper, out pdwCookie);
			iHKernelEvents_SinkHelper.m_dwCookie = pdwCookie;
			iHKernelEvents_SinkHelper.m_OnHTMLWindowMsgDelegate = P_0;
			m_aEventSinkHelpers.Add(iHKernelEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_OnHTMLWindowMsg(_IHKernelEvents_OnHTMLWindowMsgEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_aEventSinkHelpers == null)
			{
				return;
			}
			int count = m_aEventSinkHelpers.Count;
			int num = 0;
			if (0 >= count)
			{
				return;
			}
			do
			{
				_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = (_IHKernelEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iHKernelEvents_SinkHelper.m_OnHTMLWindowMsgDelegate != null && ((iHKernelEvents_SinkHelper.m_OnHTMLWindowMsgDelegate.Equals(P_0) ? 1u : 0u) & 0xFFu) != 0)
				{
					m_aEventSinkHelpers.RemoveAt(num);
					m_ConnectionPoint.Unadvise(iHKernelEvents_SinkHelper.m_dwCookie);
					if (count <= 1)
					{
						Marshal.ReleaseComObject(m_ConnectionPoint);
						m_ConnectionPoint = null;
						m_aEventSinkHelpers = null;
					}
					break;
				}
				num++;
			}
			while (num < count);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void add_SetSUITETestParamDetails(_IHKernelEvents_SetSUITETestParamDetailsEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_ConnectionPoint == null)
			{
				Init();
			}
			_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = new _IHKernelEvents_SinkHelper();
			int pdwCookie = 0;
			m_ConnectionPoint.Advise(iHKernelEvents_SinkHelper, out pdwCookie);
			iHKernelEvents_SinkHelper.m_dwCookie = pdwCookie;
			iHKernelEvents_SinkHelper.m_SetSUITETestParamDetailsDelegate = P_0;
			m_aEventSinkHelpers.Add(iHKernelEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_SetSUITETestParamDetails(_IHKernelEvents_SetSUITETestParamDetailsEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_aEventSinkHelpers == null)
			{
				return;
			}
			int count = m_aEventSinkHelpers.Count;
			int num = 0;
			if (0 >= count)
			{
				return;
			}
			do
			{
				_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = (_IHKernelEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iHKernelEvents_SinkHelper.m_SetSUITETestParamDetailsDelegate != null && ((iHKernelEvents_SinkHelper.m_SetSUITETestParamDetailsDelegate.Equals(P_0) ? 1u : 0u) & 0xFFu) != 0)
				{
					m_aEventSinkHelpers.RemoveAt(num);
					m_ConnectionPoint.Unadvise(iHKernelEvents_SinkHelper.m_dwCookie);
					if (count <= 1)
					{
						Marshal.ReleaseComObject(m_ConnectionPoint);
						m_ConnectionPoint = null;
						m_aEventSinkHelpers = null;
					}
					break;
				}
				num++;
			}
			while (num < count);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void add_OnSetGlobalVariable(_IHKernelEvents_OnSetGlobalVariableEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_ConnectionPoint == null)
			{
				Init();
			}
			_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = new _IHKernelEvents_SinkHelper();
			int pdwCookie = 0;
			m_ConnectionPoint.Advise(iHKernelEvents_SinkHelper, out pdwCookie);
			iHKernelEvents_SinkHelper.m_dwCookie = pdwCookie;
			iHKernelEvents_SinkHelper.m_OnSetGlobalVariableDelegate = P_0;
			m_aEventSinkHelpers.Add(iHKernelEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_OnSetGlobalVariable(_IHKernelEvents_OnSetGlobalVariableEventHandler P_0)
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_aEventSinkHelpers == null)
			{
				return;
			}
			int count = m_aEventSinkHelpers.Count;
			int num = 0;
			if (0 >= count)
			{
				return;
			}
			do
			{
				_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = (_IHKernelEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iHKernelEvents_SinkHelper.m_OnSetGlobalVariableDelegate != null && ((iHKernelEvents_SinkHelper.m_OnSetGlobalVariableDelegate.Equals(P_0) ? 1u : 0u) & 0xFFu) != 0)
				{
					m_aEventSinkHelpers.RemoveAt(num);
					m_ConnectionPoint.Unadvise(iHKernelEvents_SinkHelper.m_dwCookie);
					if (count <= 1)
					{
						Marshal.ReleaseComObject(m_ConnectionPoint);
						m_ConnectionPoint = null;
						m_aEventSinkHelpers = null;
					}
					break;
				}
				num++;
			}
			while (num < count);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public _IHKernelEvents_EventProvider(object P_0)
	{
		//Error decoding local variables: Signature type sequence must have at least one element.
		m_wkConnectionPointContainer = new WeakReference((IConnectionPointContainer)P_0, trackResurrection: false);
	}

	public void Finalize()
	{
		bool lockTaken = default(bool);
		try
		{
			Monitor.Enter(this, ref lockTaken);
			if (m_ConnectionPoint == null)
			{
				return;
			}
			int count = m_aEventSinkHelpers.Count;
			int num = 0;
			if (0 < count)
			{
				do
				{
					_IHKernelEvents_SinkHelper iHKernelEvents_SinkHelper = (_IHKernelEvents_SinkHelper)m_aEventSinkHelpers[num];
					m_ConnectionPoint.Unadvise(iHKernelEvents_SinkHelper.m_dwCookie);
					num++;
				}
				while (num < count);
			}
			Marshal.ReleaseComObject(m_ConnectionPoint);
		}
		catch (Exception)
		{
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void Dispose()
	{
		//Error decoding local variables: Signature type sequence must have at least one element.
		Finalize();
		GC.SuppressFinalize(this);
	}
}
