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

namespace Decal.Interop.Core;

internal sealed class IACHooksEvents_EventProvider : IACHooksEvents_Event, IDisposable
{
	private IConnectionPointContainer m_ConnectionPointContainer;

	private ArrayList m_aEventSinkHelpers;

	private IConnectionPoint m_ConnectionPoint;

	private void Init()
	{
		IConnectionPoint ppCP = null;
		Guid riid = new Guid(new byte[16]
		{
			229, 47, 40, 235, 112, 113, 55, 74, 162, 110,
			146, 175, 54, 56, 93, 44
		});
		m_ConnectionPointContainer.FindConnectionPoint(ref riid, out ppCP);
		m_ConnectionPoint = ppCP;
		m_aEventSinkHelpers = new ArrayList();
	}

	event IACHooksEvents_ObjectDestroyedEventHandler IACHooksEvents_Event.ObjectDestroyed
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_ObjectDestroyedDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_ObjectDestroyedDelegate != null && ((iACHooksEvents_SinkHelper.m_ObjectDestroyedDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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);
				}
			}
	
		}
	}

	event IACHooksEvents_ChatTextInterceptEventHandler IACHooksEvents_Event.ChatTextIntercept
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_ChatTextInterceptDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_ChatTextInterceptDelegate != null && ((iACHooksEvents_SinkHelper.m_ChatTextInterceptDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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);
				}
			}
	
		}
	}

	event IACHooksEvents_ChatParserInterceptEventHandler IACHooksEvents_Event.ChatParserIntercept
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_ChatParserInterceptDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_ChatParserInterceptDelegate != null && ((iACHooksEvents_SinkHelper.m_ChatParserInterceptDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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);
				}
			}
	
		}
	}

	event IACHooksEvents_StatusTextInterceptEventHandler IACHooksEvents_Event.StatusTextIntercept
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_StatusTextInterceptDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_StatusTextInterceptDelegate != null && ((iACHooksEvents_SinkHelper.m_StatusTextInterceptDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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);
				}
			}
	
		}
	}

	event IACHooksEvents_ObjectSelectedEventHandler IACHooksEvents_Event.ObjectSelected
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_ObjectSelectedDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_ObjectSelectedDelegate != null && ((iACHooksEvents_SinkHelper.m_ObjectSelectedDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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);
				}
			}
	
		}
	}

	event IACHooksEvents_MessageProcessedEventHandler IACHooksEvents_Event.MessageProcessed
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_MessageProcessedDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_MessageProcessedDelegate != null && ((iACHooksEvents_SinkHelper.m_MessageProcessedDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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);
				}
			}
	
		}
	}

	event IACHooksEvents_AC3DRegionChangedEventHandler IACHooksEvents_Event.AC3DRegionChanged
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_AC3DRegionChangedDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_AC3DRegionChangedDelegate != null && ((iACHooksEvents_SinkHelper.m_AC3DRegionChangedDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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);
				}
			}
	
		}
	}

	event IACHooksEvents_ContainerOpenedEventHandler IACHooksEvents_Event.ContainerOpened
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_ContainerOpenedDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_ContainerOpenedDelegate != null && ((iACHooksEvents_SinkHelper.m_ContainerOpenedDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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);
				}
			}
	
		}
	}

	event IACHooksEvents_ChatClickInterceptEventHandler IACHooksEvents_Event.ChatClickIntercept
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_ChatClickInterceptDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_ChatClickInterceptDelegate != null && ((iACHooksEvents_SinkHelper.m_ChatClickInterceptDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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);
				}
			}
	
		}
	}

	event IACHooksEvents_RenderPreUIEventHandler IACHooksEvents_Event.RenderPreUI
	{
		add
		{

			bool lockTaken = default(bool);
			try
			{
				Monitor.Enter(this, ref lockTaken);
				if (m_ConnectionPoint == null)
				{
					Init();
				}
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = new IACHooksEvents_SinkHelper();
				int pdwCookie = 0;
				m_ConnectionPoint.Advise(iACHooksEvents_SinkHelper, out pdwCookie);
				iACHooksEvents_SinkHelper.m_dwCookie = pdwCookie;
				iACHooksEvents_SinkHelper.m_RenderPreUIDelegate = value;
				m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
			}
			finally
			{
				if (lockTaken)
				{
					Monitor.Exit(this);
				}
			}
	
		}
		remove
		{

			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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					if (iACHooksEvents_SinkHelper.m_RenderPreUIDelegate != null && ((iACHooksEvents_SinkHelper.m_RenderPreUIDelegate.Equals(value) ? 1u : 0u) & 0xFFu) != 0)
					{
						m_aEventSinkHelpers.RemoveAt(num);
						m_ConnectionPoint.Unadvise(iACHooksEvents_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 IACHooksEvents_EventProvider(object P_0)
	{
		//Error decoding local variables: Signature type sequence must have at least one element.
		m_ConnectionPointContainer = (IConnectionPointContainer)P_0;
	}

	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
				{
					IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
					m_ConnectionPoint.Unadvise(iACHooksEvents_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);
	}
}
