Decompiled source of Highlights v1.0.1

BepInEx/plugins/LC_Highlights.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using NVIDIA;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("LC_Highlights")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Source moment")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LC_Highlights")]
[assembly: AssemblyTitle("LC_Highlights")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace LC_Highlights
{
	internal class Highlight
	{
		private static DateTime _startTime;

		private static string _lastName;

		public static void LogCallback(Highlights.ReturnCode ret, int id)
		{
			Plugin.Log.LogDebug((object)$"Callback from NVIDIA SDK with code {ret} for ID {id}.");
		}

		public static void SaveRecording(string name)
		{
			_lastName = name;
			if (Plugin.cfgEnabled.Value)
			{
				DateTime dateTime = DateTime.Now.AddSeconds(-15.0);
				TimeSpan timeSpan = DateTime.Now - dateTime;
				Highlights.VideoHighlightParams videoHighlightParams = default(Highlights.VideoHighlightParams);
				videoHighlightParams.highlightId = "MAP_PLAY";
				videoHighlightParams.groupId = "MAP_PLAY_GROUP";
				videoHighlightParams.startDelta = (int)(0.0 - timeSpan.TotalMilliseconds);
				videoHighlightParams.endDelta = 0;
				ref int startDelta = ref videoHighlightParams.startDelta;
				startDelta = startDelta;
				videoHighlightParams.endDelta += Plugin.cfgAfterDeathDelta.Value;
				Highlights.SetVideoHighlight(videoHighlightParams, LogCallback);
			}
		}

		public static void ShowSummary()
		{
			if (Plugin.cfgEnabled.Value)
			{
				Highlights.OpenSummary(new Highlights.GroupView[1]
				{
					new Highlights.GroupView
					{
						GroupId = "MAP_PLAY_GROUP",
						SignificanceFilter = Highlights.HighlightSignificance.Good,
						TagFilter = Highlights.HighlightType.Achievement
					}
				}, LogCallback);
			}
		}
	}
	public static class Convert
	{
		public static string GetCauseOfDeathString(int causeOfDeathValue)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected I4, but got Unknown
			CauseOfDeath val = (CauseOfDeath)causeOfDeathValue;
			return (int)val switch
			{
				0 => "Unknown", 
				1 => "Bludgeoning", 
				2 => "Gravity", 
				3 => "Blast", 
				4 => "Strangulation", 
				5 => "Suffocation", 
				6 => "Mauling", 
				7 => "Gunshots", 
				8 => "Crushing", 
				9 => "Drowning", 
				10 => "Abandoned", 
				11 => "Electrocution", 
				12 => "Kicking", 
				_ => "Unknown", 
			};
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	[HarmonyPatch("KillPlayer")]
	internal class PlayerKillPatch
	{
		public static void Prefix(PlayerControllerB __instance, ref CauseOfDeath causeOfDeath)
		{
			string text = DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_" + Convert.GetCauseOfDeathString((int)causeOfDeath);
			Highlight.SaveRecording(text);
			Plugin.Log.LogMessage((object)("Saved recording " + text + " because player died!"));
			if (Plugin.cfgShowOverlayImmediately.Value)
			{
				Highlight.ShowSummary();
			}
		}
	}
	[BepInPlugin("mnc.highlights", "GeForce Highlights", "2024.03.23")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony thisHarmony;

		public static ManualLogSource Log;

		public static ConfigEntry<bool> cfgEnabled;

		public static ConfigEntry<int> cfgAfterDeathDelta;

		public static ConfigEntry<bool> cfgShowOverlayImmediately;

		private void Awake()
		{
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Expected O, but got Unknown
			cfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable this plugin (Will take a video)", true, "Enables this mod to take videos using NVIDIA Highlights.");
			cfgAfterDeathDelta = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Time after death (millis)", 2000, "This setting determines the length, in milliseconds, of the video segment captured after the player's character has died.");
			cfgShowOverlayImmediately = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Show overlay immediately after death", true, "If the GeForce Experience overlay should be shown immediately after death.");
			Log = ((BaseUnityPlugin)this).Logger;
			Highlights.HighlightScope[] requiredScopes = new Highlights.HighlightScope[2]
			{
				Highlights.HighlightScope.Highlights,
				Highlights.HighlightScope.HighlightsRecordVideo
			};
			Highlights.ReturnCode returnCode = Highlights.CreateHighlightsSDK("LethalCompany Highlights", requiredScopes);
			if (returnCode != 0)
			{
				Log.LogError((object)$"Failed to set up Highlights (Are you using NVIDIA GeForce?) - CODE: {returnCode}");
				Highlights.UpdateLog();
				return;
			}
			Highlights.RequestPermissions(Highlight.LogCallback);
			Highlights.HighlightDefinition[] array = new Highlights.HighlightDefinition[1];
			array[0].Id = "MAP_PLAY";
			array[0].HighlightTags = Highlights.HighlightType.Achievement;
			array[0].Significance = Highlights.HighlightSignificance.Good;
			array[0].UserDefaultInterest = true;
			array[0].NameTranslationTable = new Highlights.TranslationEntry[1]
			{
				new Highlights.TranslationEntry("en-US", "Player Death")
			};
			Highlights.ConfigureHighlights(array, "en-US", Highlight.LogCallback);
			Highlights.OpenGroupParams openGroupParams = default(Highlights.OpenGroupParams);
			openGroupParams.Id = "MAP_PLAY_GROUP";
			openGroupParams.GroupDescriptionTable = new Highlights.TranslationEntry[1]
			{
				new Highlights.TranslationEntry("en-US", "Player Death group")
			};
			Highlights.OpenGroup(openGroupParams, Highlight.LogCallback);
			Log.LogInfo((object)"Success.");
			thisHarmony = new Harmony("mnc.highlights");
			thisHarmony.PatchAll();
		}
	}
	internal class PluginMeta
	{
		public const string PLUGIN_GUID = "mnc.highlights";

		public const string PLUGIN_NAME = "GeForce Highlights";

		public const string PLUGIN_VERSION = "2024.03.23";
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LC_Highlights";

		public const string PLUGIN_NAME = "LC_Highlights";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace NVIDIA
{
	public class Highlights
	{
		public enum HighlightScope
		{
			Highlights,
			HighlightsRecordVideo,
			HighlightsRecordScreenshot,
			Ops,
			MAX
		}

		public enum HighlightType
		{
			None = 0,
			Milestone = 1,
			Achievement = 2,
			Incident = 4,
			StateChange = 8,
			Unannounced = 0x10,
			MAX = 0x20
		}

		public enum HighlightSignificance
		{
			None = 0,
			ExtremelyBad = 1,
			VeryBad = 2,
			Bad = 4,
			Neutral = 0x10,
			Good = 0x100,
			VeryGood = 0x200,
			ExtremelyGood = 0x400,
			MAX = 0x800
		}

		public enum Permission
		{
			Granted,
			Denied,
			MustAsk,
			Unknown,
			MAX
		}

		public enum LogLevel
		{
			None,
			Error,
			Info,
			Debug,
			Verbose,
			MAX
		}

		public enum ReturnCode
		{
			SUCCESS = 0,
			SUCCESS_VERSION_OLD_SDK = 1001,
			SUCCESS_VERSION_OLD_GFE = 1002,
			SUCCESS_PENDING = 1003,
			SUCCESS_USER_NOT_INTERESTED = 1004,
			SUCCESS_PERMISSION_GRANTED = 1005,
			ERR_GENERIC = -1001,
			ERR_GFE_VERSION = -1002,
			ERR_SDK_VERSION = -1003,
			ERR_NOT_IMPLEMENTED = -1004,
			ERR_INVALID_PARAMETER = -1005,
			ERR_NOT_SET = -1006,
			ERR_SHADOWPLAY_IR_DISABLED = -1007,
			ERR_SDK_IN_USE = -1008,
			ERR_GROUP_NOT_FOUND = -1009,
			ERR_FILE_NOT_FOUND = -1010,
			ERR_HIGHLIGHTS_SETUP_FAILED = -1011,
			ERR_HIGHLIGHTS_NOT_CONFIGURED = -1012,
			ERR_HIGHLIGHTS_SAVE_FAILED = -1013,
			ERR_UNEXPECTED_EXCEPTION = -1014,
			ERR_NO_HIGHLIGHTS = -1015,
			ERR_NO_CONNECTION = -1016,
			ERR_PERMISSION_NOT_GRANTED = -1017,
			ERR_PERMISSION_DENIED = -1018,
			ERR_INVALID_HANDLE = -1019,
			ERR_UNHANDLED_EXCEPTION = -1020,
			ERR_OUT_OF_MEMORY = -1021,
			ERR_LOAD_LIBRARY = -1022,
			ERR_LIB_CALL_FAILED = -1023,
			ERR_IPC_FAILED = -1024,
			ERR_CONNECTION = -1025,
			ERR_MODULE_NOT_LOADED = -1026,
			ERR_LIB_CALL_TIMEOUT = -1027,
			ERR_APPLICATION_LOOKUP_FAILED = -1028,
			ERR_APPLICATION_NOT_KNOWN = -1029,
			ERR_FEATURE_DISABLED = -1030,
			ERR_APP_NO_OPTIMIZATION = -1031,
			ERR_APP_SETTINGS_READ = -1032,
			ERR_APP_SETTINGS_WRITE = -1033
		}

		public struct TranslationEntry
		{
			public string Language;

			public string Translation;

			public TranslationEntry(string _Language, string _Translation)
			{
				Language = _Language;
				Translation = _Translation;
			}
		}

		[Serializable]
		private struct Scope
		{
			[MarshalAs(UnmanagedType.SysInt)]
			public int value;
		}

		[Serializable]
		private struct HighlightDefinitionInternal
		{
			[MarshalAs(UnmanagedType.LPStr)]
			public string id;

			[MarshalAs(UnmanagedType.I1)]
			public bool userDefaultInterest;

			[MarshalAs(UnmanagedType.SysInt)]
			public int highlightTags;

			[MarshalAs(UnmanagedType.SysInt)]
			public int significance;

			[MarshalAs(UnmanagedType.LPStr)]
			public string languageTranslationStrings;
		}

		public struct HighlightDefinition
		{
			public string Id;

			public bool UserDefaultInterest;

			public HighlightType HighlightTags;

			public HighlightSignificance Significance;

			public TranslationEntry[] NameTranslationTable;
		}

		[Serializable]
		private struct OpenGroupParamsInternal
		{
			[MarshalAs(UnmanagedType.LPStr)]
			public string id;

			[MarshalAs(UnmanagedType.LPStr)]
			public string groupDescriptionTable;
		}

		public struct OpenGroupParams
		{
			public string Id;

			public TranslationEntry[] GroupDescriptionTable;
		}

		[Serializable]
		public struct CloseGroupParams
		{
			[MarshalAs(UnmanagedType.LPStr)]
			public string id;

			[MarshalAs(UnmanagedType.I1)]
			public bool destroyHighlights;
		}

		[Serializable]
		public struct ScreenshotHighlightParams
		{
			[MarshalAs(UnmanagedType.LPStr)]
			public string groupId;

			[MarshalAs(UnmanagedType.LPStr)]
			public string highlightId;
		}

		[Serializable]
		public struct VideoHighlightParams
		{
			[MarshalAs(UnmanagedType.LPStr)]
			public string groupId;

			[MarshalAs(UnmanagedType.LPStr)]
			public string highlightId;

			[MarshalAs(UnmanagedType.SysInt)]
			public int startDelta;

			[MarshalAs(UnmanagedType.SysInt)]
			public int endDelta;
		}

		[Serializable]
		private struct GroupViewInternal
		{
			[MarshalAs(UnmanagedType.LPStr)]
			public string groupId;

			[MarshalAs(UnmanagedType.SysInt)]
			public int tagFilter;

			[MarshalAs(UnmanagedType.SysInt)]
			public int significanceFilter;
		}

		public struct GroupView
		{
			public string GroupId;

			public HighlightType TagFilter;

			public HighlightSignificance SignificanceFilter;
		}

		public struct RequestPermissionsParams
		{
			public HighlightScope ScopesFlags;
		}

		[Serializable]
		private struct RequestPermissionsParamsInternal
		{
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
			public int scopesFlags;
		}

		[Serializable]
		private struct EmptyCallbackId
		{
			[MarshalAs(UnmanagedType.SysInt)]
			public int id;

			[MarshalAs(UnmanagedType.FunctionPtr)]
			public EmptyCallbackDelegate callback;
		}

		[Serializable]
		private struct GetNumberOfHighlightsCallbackId
		{
			[MarshalAs(UnmanagedType.SysInt)]
			public int id;

			[MarshalAs(UnmanagedType.FunctionPtr)]
			public GetNumberOfHighlightsCallbackDelegate callback;
		}

		[Serializable]
		private struct UserSettingsInternal
		{
			[MarshalAs(UnmanagedType.SysInt)]
			public IntPtr highlightSettingTable;

			[MarshalAs(UnmanagedType.SysInt)]
			public int highlightSettingTableSize;
		}

		public struct UserSettings
		{
			public List<UserSetting> highlightSettingTable;
		}

		[Serializable]
		private struct UserSettingInternal
		{
			[MarshalAs(UnmanagedType.LPStr)]
			public string id;

			[MarshalAs(UnmanagedType.I1)]
			public bool enabled;
		}

		public struct UserSetting
		{
			public string id;

			public bool enabled;
		}

		[Serializable]
		private struct GetUserSettingsCallbackId
		{
			[MarshalAs(UnmanagedType.SysInt)]
			public int id;

			[MarshalAs(UnmanagedType.FunctionPtr)]
			public GetUserSettingsCallbackDelegate callback;

			[MarshalAs(UnmanagedType.FunctionPtr)]
			public IntermediateCallbackDelegateInternal intermediateCallback;
		}

		[Serializable]
		private struct UILanguageInternal
		{
			[MarshalAs(UnmanagedType.LPStr)]
			public string cultureCode;
		}

		public struct UILanguage
		{
			public string cultureCode;
		}

		[Serializable]
		private struct GetUILanguageCallbackId
		{
			[MarshalAs(UnmanagedType.SysInt)]
			public int id;

			[MarshalAs(UnmanagedType.FunctionPtr)]
			public GetUILanguageCallbackDelegate callback;

			[MarshalAs(UnmanagedType.FunctionPtr)]
			public IntermediateCallbackDelegateInternal intermediateCallback;
		}

		public delegate void GetNumberOfHighlightsCallbackDelegate(ReturnCode ret, int number, int id);

		private delegate void IntermediateCallbackDelegateInternal(ReturnCode ret, IntPtr blob, IntPtr callbackWithId);

		public delegate void EmptyCallbackDelegate(ReturnCode ret, int id);

		public delegate void GetUserSettingsCallbackDelegate(ReturnCode ret, UserSettings settings, int id);

		public delegate void GetUILanguageCallbackDelegate(ReturnCode ret, string cultureCode, int id);

		public delegate void LogListenerDelegate(LogLevel level, string message);

		public static bool instanceCreated;

		private const string DLL64Name = "HighlightsPlugin64";

		private static int CallbackId;

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern int Create([MarshalAs(UnmanagedType.LPStr)] string appName, int n, IntPtr scopes);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern bool Release();

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_RequestPermissionsAsync(IntPtr asyncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_GetUILanguageAsync(IntPtr asyncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void SetDefaultLocale([MarshalAs(UnmanagedType.LPStr)] string defaultLocale);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_ConfigureAsync(int n, IntPtr highlightDefinitions, IntPtr asyncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_GetUserSettingsAsync(IntPtr asyncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_OpenGroupAsync(IntPtr openGroupParams, IntPtr asyncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_CloseGroupAsync(IntPtr closeGroupParams, IntPtr asyncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_SetScreenshotHighlightAsync(IntPtr screenshotHighlightParams, IntPtr asyncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_SetVideoHighlightAsync(IntPtr videoHighlightParams, IntPtr asyncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_OpenSummaryAsync(int n, IntPtr summaryParams, IntPtr asyncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern void Highlights_GetNumberOfHighlightsAsync(IntPtr groupView, IntPtr ayncOp);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		[return: MarshalAs(UnmanagedType.BStr)]
		public static extern string GetInfoLog();

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		[return: MarshalAs(UnmanagedType.BStr)]
		public static extern string GetErrorLog();

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern int Log_SetLevel(int level);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern int Log_AttachListener([MarshalAs(UnmanagedType.FunctionPtr)] LogListenerDelegate listener);

		[DllImport("HighlightsPlugin64", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
		private static extern int Log_SetListenerLevel(int level);

		public static int PeekCallbackId()
		{
			return CallbackId;
		}

		private static int GetCallbackId()
		{
			return CallbackId++;
		}

		public static ReturnCode CreateHighlightsSDK(string AppName, HighlightScope[] RequiredScopes)
		{
			List<IntPtr> list = new List<IntPtr>();
			IntPtr intPtr = Marshal.AllocHGlobal(RequiredScopes.Length * Marshal.SizeOf(typeof(IntPtr)));
			for (int i = 0; i < RequiredScopes.Length; i++)
			{
				IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Scope)));
				list.Add(intPtr2);
				Scope structure = default(Scope);
				structure.value = (int)RequiredScopes[i];
				Marshal.StructureToPtr(structure, intPtr2, fDeleteOld: false);
				Marshal.WriteIntPtr(intPtr, i * Marshal.SizeOf(typeof(IntPtr)), intPtr2);
			}
			ReturnCode returnCode = (ReturnCode)Create(AppName, RequiredScopes.Length, intPtr);
			if (returnCode == ReturnCode.SUCCESS)
			{
				Debug.Log((object)"Highlights SDK initialized successfully");
				instanceCreated = true;
			}
			else
			{
				Debug.LogError((object)"Failed to initialize Highlights SDK");
			}
			Marshal.FreeHGlobal(intPtr);
			foreach (IntPtr item in list)
			{
				Marshal.FreeHGlobal(item);
			}
			return returnCode;
		}

		public static void ReleaseHighlightsSDK()
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"Highlights release failed as no running instance was found");
				return;
			}
			if (Release())
			{
				Debug.Log((object)"Highlights SDK released successfully");
			}
			else
			{
				Debug.LogError((object)"Failed to release Highlights SDK");
			}
			instanceCreated = false;
		}

		public static void UpdateLog()
		{
			string infoLog = GetInfoLog();
			if (infoLog != "")
			{
				Debug.Log((object)infoLog);
			}
			string errorLog = GetErrorLog();
			if (errorLog != "")
			{
				Debug.LogError((object)errorLog);
			}
		}

		public static void ConfigureHighlights(HighlightDefinition[] highlightDefinitions, string defaultLocale, EmptyCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot configure Highlights. The SDK has not been initialized.");
				return;
			}
			SetDefaultLocale(defaultLocale);
			List<IntPtr> list = new List<IntPtr>();
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * highlightDefinitions.Length);
			EmptyCallbackId structure = default(EmptyCallbackId);
			structure.id = GetCallbackId();
			structure.callback = callback;
			IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			try
			{
				for (int i = 0; i < highlightDefinitions.Length; i++)
				{
					IntPtr intPtr3 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HighlightDefinitionInternal)));
					HighlightDefinitionInternal structure2 = default(HighlightDefinitionInternal);
					structure2.id = highlightDefinitions[i].Id;
					structure2.highlightTags = (int)highlightDefinitions[i].HighlightTags;
					structure2.significance = (int)highlightDefinitions[i].Significance;
					structure2.userDefaultInterest = highlightDefinitions[i].UserDefaultInterest;
					StringBuilder stringBuilder = new StringBuilder();
					TranslationEntry[] nameTranslationTable = highlightDefinitions[i].NameTranslationTable;
					for (int j = 0; j < nameTranslationTable.Length; j++)
					{
						TranslationEntry translationEntry = nameTranslationTable[j];
						stringBuilder.Append(translationEntry.Language).Append("\a").Append(translationEntry.Translation)
							.Append("\a");
					}
					structure2.languageTranslationStrings = stringBuilder.ToString();
					list.Add(intPtr3);
					Marshal.StructureToPtr(structure2, intPtr3, fDeleteOld: false);
					Marshal.WriteIntPtr(intPtr, i * Marshal.SizeOf(typeof(IntPtr)), intPtr3);
				}
				Marshal.StructureToPtr(structure, intPtr2, fDeleteOld: false);
				Highlights_ConfigureAsync(highlightDefinitions.Length, intPtr, intPtr2);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
				Marshal.FreeHGlobal(intPtr2);
				foreach (IntPtr item in list)
				{
					Marshal.FreeHGlobal(item);
				}
			}
		}

		public static void OpenGroup(OpenGroupParams openGroupParams, EmptyCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot open a group. The SDK has not been initialized.");
				return;
			}
			OpenGroupParamsInternal structure = default(OpenGroupParamsInternal);
			structure.id = openGroupParams.Id;
			StringBuilder stringBuilder = new StringBuilder();
			TranslationEntry[] groupDescriptionTable = openGroupParams.GroupDescriptionTable;
			for (int i = 0; i < groupDescriptionTable.Length; i++)
			{
				TranslationEntry translationEntry = groupDescriptionTable[i];
				stringBuilder.Append(translationEntry.Language).Append("\a").Append(translationEntry.Translation)
					.Append("\a");
			}
			structure.groupDescriptionTable = stringBuilder.ToString();
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			EmptyCallbackId structure2 = default(EmptyCallbackId);
			structure2.id = GetCallbackId();
			structure2.callback = callback;
			IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(structure2));
			try
			{
				Marshal.StructureToPtr(structure, intPtr, fDeleteOld: false);
				Marshal.StructureToPtr(structure2, intPtr2, fDeleteOld: false);
				Highlights_OpenGroupAsync(intPtr, intPtr2);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
				Marshal.FreeHGlobal(intPtr2);
			}
		}

		public static void CloseGroup(CloseGroupParams closeGroupParams, EmptyCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot close a group. The SDK has not been initialized.");
				return;
			}
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(closeGroupParams));
			EmptyCallbackId structure = default(EmptyCallbackId);
			structure.id = GetCallbackId();
			structure.callback = callback;
			IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			try
			{
				Marshal.StructureToPtr(closeGroupParams, intPtr, fDeleteOld: false);
				Marshal.StructureToPtr(structure, intPtr2, fDeleteOld: false);
				Highlights_CloseGroupAsync(intPtr, intPtr2);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
				Marshal.FreeHGlobal(intPtr2);
			}
		}

		public static void SetScreenshotHighlight(ScreenshotHighlightParams screenshotHighlightParams, EmptyCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot take a screenshot. The SDK has not been initialized.");
				return;
			}
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(screenshotHighlightParams));
			EmptyCallbackId structure = default(EmptyCallbackId);
			structure.id = GetCallbackId();
			structure.callback = callback;
			IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			try
			{
				Marshal.StructureToPtr(screenshotHighlightParams, intPtr, fDeleteOld: false);
				Marshal.StructureToPtr(structure, intPtr2, fDeleteOld: false);
				Highlights_SetScreenshotHighlightAsync(intPtr, intPtr2);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
				Marshal.FreeHGlobal(intPtr2);
			}
		}

		public static void SetVideoHighlight(VideoHighlightParams videoHighlightParams, EmptyCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot record a video. The SDK has not been initialized.");
				return;
			}
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(videoHighlightParams));
			EmptyCallbackId structure = default(EmptyCallbackId);
			structure.id = GetCallbackId();
			structure.callback = callback;
			IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			try
			{
				Marshal.StructureToPtr(videoHighlightParams, intPtr, fDeleteOld: false);
				Marshal.StructureToPtr(structure, intPtr2, fDeleteOld: false);
				Highlights_SetVideoHighlightAsync(intPtr, intPtr2);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
				Marshal.FreeHGlobal(intPtr2);
			}
		}

		public static void OpenSummary(GroupView[] summaryParams, EmptyCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot open summary. The SDK has not been initialized.");
				return;
			}
			List<IntPtr> list = new List<IntPtr>();
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * summaryParams.Length);
			EmptyCallbackId structure = default(EmptyCallbackId);
			structure.id = GetCallbackId();
			structure.callback = callback;
			IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			try
			{
				for (int i = 0; i < summaryParams.Length; i++)
				{
					GroupViewInternal structure2 = default(GroupViewInternal);
					structure2.groupId = summaryParams[i].GroupId;
					structure2.significanceFilter = (int)summaryParams[i].SignificanceFilter;
					structure2.tagFilter = (int)summaryParams[i].TagFilter;
					IntPtr intPtr3 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GroupViewInternal)));
					list.Add(intPtr3);
					Marshal.StructureToPtr(structure2, intPtr3, fDeleteOld: false);
					Marshal.WriteIntPtr(intPtr, Marshal.SizeOf(typeof(IntPtr)) * i, intPtr3);
				}
				Marshal.StructureToPtr(structure, intPtr2, fDeleteOld: false);
				Highlights_OpenSummaryAsync(summaryParams.Length, intPtr, intPtr2);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
				Marshal.FreeHGlobal(intPtr2);
				foreach (IntPtr item in list)
				{
					Marshal.FreeHGlobal(item);
				}
			}
		}

		public static void GetNumberOfHighlights(GroupView groupView, GetNumberOfHighlightsCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot get number of highlights. The SDK has not been initialized.");
				return;
			}
			GroupViewInternal structure = default(GroupViewInternal);
			structure.groupId = groupView.GroupId;
			structure.significanceFilter = (int)groupView.SignificanceFilter;
			structure.tagFilter = (int)groupView.TagFilter;
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			GetNumberOfHighlightsCallbackId structure2 = default(GetNumberOfHighlightsCallbackId);
			structure2.id = GetCallbackId();
			structure2.callback = callback;
			IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(structure2));
			try
			{
				Marshal.StructureToPtr(structure, intPtr, fDeleteOld: false);
				Marshal.StructureToPtr(structure2, intPtr2, fDeleteOld: false);
				Highlights_GetNumberOfHighlightsAsync(intPtr, intPtr2);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
				Marshal.FreeHGlobal(intPtr2);
			}
		}

		public static void GetUserSettings(GetUserSettingsCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot get highlights user setting. The SDK has not been initialized.");
				return;
			}
			GetUserSettingsCallbackId structure = default(GetUserSettingsCallbackId);
			structure.id = GetCallbackId();
			structure.callback = callback;
			structure.intermediateCallback = GetUserSettingsCallbackInternal;
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			try
			{
				Marshal.StructureToPtr(structure, intPtr, fDeleteOld: false);
				Highlights_GetUserSettingsAsync(intPtr);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
			}
		}

		private static void GetUserSettingsCallbackInternal(ReturnCode ret, IntPtr blob, IntPtr callbackId)
		{
			UserSettings settings = default(UserSettings);
			settings.highlightSettingTable = new List<UserSetting>();
			if (ret == ReturnCode.SUCCESS)
			{
				UserSettingsInternal userSettingsInternal = default(UserSettingsInternal);
				userSettingsInternal = (UserSettingsInternal)Marshal.PtrToStructure(blob, typeof(UserSettingsInternal));
				for (int i = 0; i < userSettingsInternal.highlightSettingTableSize; i++)
				{
					UserSettingInternal userSettingInternal = (UserSettingInternal)Marshal.PtrToStructure(new IntPtr(userSettingsInternal.highlightSettingTable.ToInt64() + i * Marshal.SizeOf(default(UserSettingInternal))), typeof(UserSettingInternal));
					UserSetting item = default(UserSetting);
					item.enabled = userSettingInternal.enabled;
					item.id = userSettingInternal.id;
					settings.highlightSettingTable.Add(item);
				}
			}
			GetUserSettingsCallbackId obj = (GetUserSettingsCallbackId)Marshal.PtrToStructure(callbackId, typeof(GetUserSettingsCallbackId));
			GetUserSettingsCallbackDelegate callback = obj.callback;
			int id = obj.id;
			callback(ret, settings, id);
		}

		public static void GetUILanguage(GetUILanguageCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot get highlights UI language. The SDK has not been initialized.");
				return;
			}
			GetUILanguageCallbackId structure = default(GetUILanguageCallbackId);
			structure.id = GetCallbackId();
			structure.callback = callback;
			structure.intermediateCallback = GetUILanguageCallbackInternal;
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			try
			{
				Marshal.StructureToPtr(structure, intPtr, fDeleteOld: false);
				Highlights_GetUILanguageAsync(intPtr);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
			}
		}

		private static void GetUILanguageCallbackInternal(ReturnCode ret, IntPtr blob, IntPtr callbackId)
		{
			UILanguage uILanguage = default(UILanguage);
			if (ret == ReturnCode.SUCCESS)
			{
				UILanguageInternal uILanguageInternal = default(UILanguageInternal);
				uILanguage.cultureCode = ((UILanguageInternal)Marshal.PtrToStructure(blob, typeof(UILanguageInternal))).cultureCode;
			}
			GetUILanguageCallbackId obj = (GetUILanguageCallbackId)Marshal.PtrToStructure(callbackId, typeof(GetUILanguageCallbackId));
			GetUILanguageCallbackDelegate callback = obj.callback;
			int id = obj.id;
			callback(ret, uILanguage.cultureCode, id);
		}

		public static void RequestPermissions(EmptyCallbackDelegate callback)
		{
			if (!instanceCreated)
			{
				Debug.LogError((object)"ERROR: Cannot request permissions. The SDK has not been initialized.");
				return;
			}
			EmptyCallbackId structure = default(EmptyCallbackId);
			structure.id = GetCallbackId();
			structure.callback = callback;
			IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
			try
			{
				Marshal.StructureToPtr(structure, intPtr, fDeleteOld: false);
				Highlights_RequestPermissionsAsync(intPtr);
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
			}
		}

		public static ReturnCode SetLogLevel(LogLevel level)
		{
			return (ReturnCode)Log_SetLevel((int)level);
		}

		public static ReturnCode AttachLogListener(LogListenerDelegate listener)
		{
			return (ReturnCode)Log_AttachListener(listener);
		}

		public static ReturnCode SetListenerLogLevel(LogLevel level)
		{
			return (ReturnCode)Log_SetListenerLevel((int)level);
		}

		public static void DefaultLogListener(LogLevel level, string message)
		{
			string[] array = new string[5] { "None", "Error", "Info", "Debug", "Verbose" };
			Debug.Log((object)("Highlights LogListener " + array[(int)level] + ": " + message));
		}

		public static void DefaultGetNumberOfHighlightsCallback(ReturnCode ret, int number, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("GetNumberOfHighlightsCallback " + id + " returns " + number));
			}
			else
			{
				Debug.LogError((object)("GetNumberOfHighlightsCallback " + id + " returns unsuccess"));
			}
		}

		public static void DefaultGetUserSettingsCallback(ReturnCode ret, UserSettings settings, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("GetUserSettingsCallback " + id + " returns table count " + settings.highlightSettingTable.Count));
				{
					foreach (UserSetting item in settings.highlightSettingTable)
					{
						Debug.Log((object)("GetUserSettingsCallback " + id + " " + item.id + " " + item.enabled));
					}
					return;
				}
			}
			Debug.LogError((object)("GetUserSettingsCallback " + id + " returns unsuccess"));
		}

		public static void DefaultGetUILanguageCallback(ReturnCode ret, string langueage, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("GetUILanguageCallback " + id + " returns " + langueage));
			}
			else
			{
				Debug.LogError((object)("GetUILanguageCallback " + id + " returns unsuccess"));
			}
		}

		public static void DefaultRequestPermissionsCallback(ReturnCode ret, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("RequestPermissionsCallback " + id + " returns success"));
			}
			else
			{
				Debug.LogError((object)("RequestPermissionsCallback " + id + " returns unsuccess"));
			}
		}

		public static void DefaultConfigureCallback(ReturnCode ret, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("ConfigureCallback " + id + " returns success"));
			}
			else
			{
				Debug.LogError((object)("ConfigureCallback " + id + " returns unsuccess"));
			}
		}

		public static void DefaultSetScreenshotCallback(ReturnCode ret, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("SetScreenshotCallback " + id + " returns success"));
			}
			else
			{
				Debug.LogError((object)("SetScreenshotCallback " + id + " returns unsuccess"));
			}
		}

		public static void DefaultSetVideoCallback(ReturnCode ret, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("SetVideoCallback " + id + " returns success"));
			}
			else
			{
				Debug.LogError((object)("SetVideoCallback " + id + " returns unsuccess"));
			}
		}

		public static void DefaultOpenSummaryCallback(ReturnCode ret, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("OpenSummaryCallback " + id + " returns success"));
			}
			else
			{
				Debug.LogError((object)("OpenSummaryCallback " + id + " returns unsuccess"));
			}
		}

		public static void DefaultOpenGroupCallback(ReturnCode ret, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("OpenGroupCallback " + id + " returns success"));
			}
			else
			{
				Debug.LogError((object)("OpenGroupCallback " + id + " returns unsuccess"));
			}
		}

		public static void DefaultCloseGroupCallback(ReturnCode ret, int id)
		{
			if (ret == ReturnCode.SUCCESS)
			{
				Debug.Log((object)("CloseGroupCallback " + id + " returns success"));
			}
			else
			{
				Debug.LogError((object)("CloseGroupCallback " + id + " returns unsuccess"));
			}
		}
	}
}