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();
	}

	public void add_ObjectDestroyed(IACHooksEvents_ObjectDestroyedEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_ObjectDestroyed(IACHooksEvents_ObjectDestroyedEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_ObjectDestroyedDelegate != null && ((iACHooksEvents_SinkHelper.m_ObjectDestroyedDelegate.Equals(P_0) ? 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 void add_ChatTextIntercept(IACHooksEvents_ChatTextInterceptEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_ChatTextIntercept(IACHooksEvents_ChatTextInterceptEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_ChatTextInterceptDelegate != null && ((iACHooksEvents_SinkHelper.m_ChatTextInterceptDelegate.Equals(P_0) ? 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 void add_ChatParserIntercept(IACHooksEvents_ChatParserInterceptEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_ChatParserIntercept(IACHooksEvents_ChatParserInterceptEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_ChatParserInterceptDelegate != null && ((iACHooksEvents_SinkHelper.m_ChatParserInterceptDelegate.Equals(P_0) ? 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 void add_StatusTextIntercept(IACHooksEvents_StatusTextInterceptEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_StatusTextIntercept(IACHooksEvents_StatusTextInterceptEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_StatusTextInterceptDelegate != null && ((iACHooksEvents_SinkHelper.m_StatusTextInterceptDelegate.Equals(P_0) ? 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 void add_ObjectSelected(IACHooksEvents_ObjectSelectedEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_ObjectSelected(IACHooksEvents_ObjectSelectedEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_ObjectSelectedDelegate != null && ((iACHooksEvents_SinkHelper.m_ObjectSelectedDelegate.Equals(P_0) ? 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 void add_MessageProcessed(IACHooksEvents_MessageProcessedEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_MessageProcessed(IACHooksEvents_MessageProcessedEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_MessageProcessedDelegate != null && ((iACHooksEvents_SinkHelper.m_MessageProcessedDelegate.Equals(P_0) ? 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 void add_AC3DRegionChanged(IACHooksEvents_AC3DRegionChangedEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_AC3DRegionChanged(IACHooksEvents_AC3DRegionChangedEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_AC3DRegionChangedDelegate != null && ((iACHooksEvents_SinkHelper.m_AC3DRegionChangedDelegate.Equals(P_0) ? 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 void add_ContainerOpened(IACHooksEvents_ContainerOpenedEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_ContainerOpened(IACHooksEvents_ContainerOpenedEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_ContainerOpenedDelegate != null && ((iACHooksEvents_SinkHelper.m_ContainerOpenedDelegate.Equals(P_0) ? 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 void add_ChatClickIntercept(IACHooksEvents_ChatClickInterceptEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_ChatClickIntercept(IACHooksEvents_ChatClickInterceptEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_ChatClickInterceptDelegate != null && ((iACHooksEvents_SinkHelper.m_ChatClickInterceptDelegate.Equals(P_0) ? 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 void add_RenderPreUI(IACHooksEvents_RenderPreUIEventHandler P_0)
	{
		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 = P_0;
			m_aEventSinkHelpers.Add(iACHooksEvents_SinkHelper);
		}
		finally
		{
			if (lockTaken)
			{
				Monitor.Exit(this);
			}
		}
	}

	public void remove_RenderPreUI(IACHooksEvents_RenderPreUIEventHandler 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
			{
				IACHooksEvents_SinkHelper iACHooksEvents_SinkHelper = (IACHooksEvents_SinkHelper)m_aEventSinkHelpers[num];
				if (iACHooksEvents_SinkHelper.m_RenderPreUIDelegate != null && ((iACHooksEvents_SinkHelper.m_RenderPreUIDelegate.Equals(P_0) ? 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);
	}
}
