Decompiled source of Drunk Arab v1.0.0

plugins/Drunk_Arab.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using ArabicSupport;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LibArbUnity;
using LibArbUnity.Docs;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Drunk_Arab")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+690f72dd45b55ccaac821dfbd4f5ecb165c93487")]
[assembly: AssemblyProduct("Drunk_Arab")]
[assembly: AssemblyTitle("Drunk_Arab")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal enum IsolatedArabicLetters
{
	Hamza = 65152,
	Alef = 65165,
	AlefHamza = 65155,
	WawHamza = 65157,
	AlefMaksoor = 65159,
	AlefMaksora = 64508,
	HamzaNabera = 65161,
	Ba = 65167,
	Ta = 65173,
	Tha2 = 65177,
	Jeem = 65181,
	H7aa = 65185,
	Khaa2 = 65189,
	Dal = 65193,
	Thal = 65195,
	Ra2 = 65197,
	Zeen = 65199,
	Seen = 65201,
	Sheen = 65205,
	S9a = 65209,
	Dha = 65213,
	T6a = 65217,
	T6ha = 65221,
	Ain = 65225,
	Gain = 65229,
	Fa = 65233,
	Gaf = 65237,
	Kaf = 65241,
	Lam = 65245,
	Meem = 65249,
	Noon = 65253,
	Ha = 65257,
	Waw = 65261,
	Ya = 65265,
	AlefMad = 65153,
	TaMarboota = 65171,
	PersianPe = 64342,
	PersianChe = 64378,
	PersianZe = 64394,
	PersianGaf = 64402,
	PersianGaf2 = 64398,
	PersianYeh = 64508
}
internal enum GeneralArabicLetters
{
	Hamza = 1569,
	Alef = 1575,
	AlefHamza = 1571,
	WawHamza = 1572,
	AlefMaksoor = 1573,
	AlefMagsora = 1609,
	HamzaNabera = 1574,
	Ba = 1576,
	Ta = 1578,
	Tha2 = 1579,
	Jeem = 1580,
	H7aa = 1581,
	Khaa2 = 1582,
	Dal = 1583,
	Thal = 1584,
	Ra2 = 1585,
	Zeen = 1586,
	Seen = 1587,
	Sheen = 1588,
	S9a = 1589,
	Dha = 1590,
	T6a = 1591,
	T6ha = 1592,
	Ain = 1593,
	Gain = 1594,
	Fa = 1601,
	Gaf = 1602,
	Kaf = 1603,
	Lam = 1604,
	Meem = 1605,
	Noon = 1606,
	Ha = 1607,
	Waw = 1608,
	Ya = 1610,
	AlefMad = 1570,
	TaMarboota = 1577,
	PersianPe = 1662,
	PersianChe = 1670,
	PersianZe = 1688,
	PersianGaf = 1711,
	PersianGaf2 = 1705,
	PersianYeh = 1740
}
internal struct ArabicMapping
{
	public int from;

	public int to;

	public ArabicMapping(int from, int to)
	{
		this.from = from;
		this.to = to;
	}
}
internal class ArabicTable
{
	private static ArabicMapping[] mapList;

	private static ArabicTable arabicMapper;

	internal static ArabicTable ArabicMapper
	{
		get
		{
			if (arabicMapper == null)
			{
				arabicMapper = new ArabicTable();
			}
			return arabicMapper;
		}
	}

	private ArabicTable()
	{
		mapList = new ArabicMapping[42]
		{
			new ArabicMapping(1569, 65152),
			new ArabicMapping(1575, 65165),
			new ArabicMapping(1571, 65155),
			new ArabicMapping(1572, 65157),
			new ArabicMapping(1573, 65159),
			new ArabicMapping(1609, 64508),
			new ArabicMapping(1574, 65161),
			new ArabicMapping(1576, 65167),
			new ArabicMapping(1578, 65173),
			new ArabicMapping(1579, 65177),
			new ArabicMapping(1580, 65181),
			new ArabicMapping(1581, 65185),
			new ArabicMapping(1582, 65189),
			new ArabicMapping(1583, 65193),
			new ArabicMapping(1584, 65195),
			new ArabicMapping(1585, 65197),
			new ArabicMapping(1586, 65199),
			new ArabicMapping(1587, 65201),
			new ArabicMapping(1588, 65205),
			new ArabicMapping(1589, 65209),
			new ArabicMapping(1590, 65213),
			new ArabicMapping(1591, 65217),
			new ArabicMapping(1592, 65221),
			new ArabicMapping(1593, 65225),
			new ArabicMapping(1594, 65229),
			new ArabicMapping(1601, 65233),
			new ArabicMapping(1602, 65237),
			new ArabicMapping(1603, 65241),
			new ArabicMapping(1604, 65245),
			new ArabicMapping(1605, 65249),
			new ArabicMapping(1606, 65253),
			new ArabicMapping(1607, 65257),
			new ArabicMapping(1608, 65261),
			new ArabicMapping(1610, 65265),
			new ArabicMapping(1570, 65153),
			new ArabicMapping(1577, 65171),
			new ArabicMapping(1662, 64342),
			new ArabicMapping(1670, 64378),
			new ArabicMapping(1688, 64394),
			new ArabicMapping(1711, 64402),
			new ArabicMapping(1705, 64398),
			new ArabicMapping(1740, 64508)
		};
	}

	internal int Convert(int toBeConverted)
	{
		for (int i = 0; i < mapList.Length; i++)
		{
			ArabicMapping arabicMapping = mapList[i];
			if (arabicMapping.from == toBeConverted)
			{
				return arabicMapping.to;
			}
		}
		return toBeConverted;
	}
}
internal class TashkeelLocation
{
	public char tashkeel;

	public int position;

	public TashkeelLocation(char tashkeel, int position)
	{
		this.tashkeel = tashkeel;
		this.position = position;
	}
}
internal class ArabicFixerTool
{
	internal static bool showTashkeel = true;

	internal static bool combineTashkeel = true;

	internal static bool useHinduNumbers = false;

	internal static StringBuilder internalStringBuilder = new StringBuilder();

	internal static void RemoveTashkeel(ref string str, out List<TashkeelLocation> tashkeelLocation)
	{
		tashkeelLocation = new List<TashkeelLocation>();
		int lastSplitIndex = 0;
		internalStringBuilder.Clear();
		internalStringBuilder.EnsureCapacity(str.Length);
		int num = 0;
		for (int j = 0; j < str.Length; j++)
		{
			if (str[j] == '\u064b')
			{
				tashkeelLocation.Add(new TashkeelLocation('\u064b', j));
				num++;
				IncrementSB(ref str, j);
			}
			else if (str[j] == '\u064c')
			{
				tashkeelLocation.Add(new TashkeelLocation('\u064c', j));
				num++;
				IncrementSB(ref str, j);
			}
			else if (str[j] == '\u064d')
			{
				tashkeelLocation.Add(new TashkeelLocation('\u064d', j));
				num++;
				IncrementSB(ref str, j);
			}
			else if (str[j] == '\u064e')
			{
				if (num > 0 && combineTashkeel && tashkeelLocation[num - 1].tashkeel == '\u0651')
				{
					tashkeelLocation[num - 1].tashkeel = 'ﱠ';
					IncrementSB(ref str, j);
				}
				else
				{
					tashkeelLocation.Add(new TashkeelLocation('\u064e', j));
					num++;
					IncrementSB(ref str, j);
				}
			}
			else if (str[j] == '\u064f')
			{
				if (num > 0 && combineTashkeel && tashkeelLocation[num - 1].tashkeel == '\u0651')
				{
					tashkeelLocation[num - 1].tashkeel = 'ﱡ';
					IncrementSB(ref str, j);
				}
				else
				{
					tashkeelLocation.Add(new TashkeelLocation('\u064f', j));
					num++;
					IncrementSB(ref str, j);
				}
			}
			else if (str[j] == '\u0650')
			{
				if (num > 0 && combineTashkeel && tashkeelLocation[num - 1].tashkeel == '\u0651')
				{
					tashkeelLocation[num - 1].tashkeel = 'ﱢ';
					IncrementSB(ref str, j);
				}
				else
				{
					tashkeelLocation.Add(new TashkeelLocation('\u0650', j));
					num++;
					IncrementSB(ref str, j);
				}
			}
			else if (str[j] == '\u0651')
			{
				if (num > 0 && combineTashkeel)
				{
					if (tashkeelLocation[num - 1].tashkeel == '\u064e')
					{
						tashkeelLocation[num - 1].tashkeel = 'ﱠ';
						IncrementSB(ref str, j);
						continue;
					}
					if (tashkeelLocation[num - 1].tashkeel == '\u064f')
					{
						tashkeelLocation[num - 1].tashkeel = 'ﱡ';
						IncrementSB(ref str, j);
						continue;
					}
					if (tashkeelLocation[num - 1].tashkeel == '\u0650')
					{
						tashkeelLocation[num - 1].tashkeel = 'ﱢ';
						IncrementSB(ref str, j);
						continue;
					}
				}
				tashkeelLocation.Add(new TashkeelLocation('\u0651', j));
				num++;
				IncrementSB(ref str, j);
			}
			else if (str[j] == '\u0652')
			{
				tashkeelLocation.Add(new TashkeelLocation('\u0652', j));
				num++;
				IncrementSB(ref str, j);
			}
			else if (str[j] == '\u0653')
			{
				tashkeelLocation.Add(new TashkeelLocation('\u0653', j));
				num++;
				IncrementSB(ref str, j);
			}
			else if (str[j] == 'ﱠ')
			{
				IncrementSB(ref str, j);
			}
			else if (str[j] == 'ﱡ')
			{
				IncrementSB(ref str, j);
			}
			else if (str[j] == 'ﱢ')
			{
				IncrementSB(ref str, j);
			}
		}
		if (lastSplitIndex != 0)
		{
			IncrementSB(ref str, str.Length);
			str = internalStringBuilder.ToString();
		}
		void IncrementSB(ref string str, int i)
		{
			if (i - lastSplitIndex > 0)
			{
				internalStringBuilder.Append(str, lastSplitIndex, i - lastSplitIndex);
			}
			lastSplitIndex = i + 1;
		}
	}

	internal static void ReturnTashkeel(ref char[] letters, List<TashkeelLocation> tashkeelLocation)
	{
		Array.Resize(ref letters, letters.Length + tashkeelLocation.Count);
		for (int i = 0; i < tashkeelLocation.Count; i++)
		{
			TashkeelLocation tashkeelLocation2 = tashkeelLocation[i];
			for (int num = letters.Length - 1; num > tashkeelLocation2.position; num--)
			{
				letters[num] = letters[num - 1];
			}
			letters[tashkeelLocation2.position] = tashkeelLocation2.tashkeel;
		}
	}

	internal static string FixLine(string str)
	{
		RemoveTashkeel(ref str, out var tashkeelLocation);
		char[] array = new char[str.Length];
		char[] letters = str.ToCharArray();
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = (char)ArabicTable.ArabicMapper.Convert(str[i]);
		}
		for (int j = 0; j < array.Length; j++)
		{
			bool flag = false;
			if (array[j] == 'ﻝ' && j < array.Length - 1)
			{
				if (array[j + 1] == 'ﺇ')
				{
					array[j] = 'ﻷ';
					letters[j + 1] = '\uffff';
					flag = true;
				}
				else if (array[j + 1] == 'ﺍ')
				{
					array[j] = 'ﻹ';
					letters[j + 1] = '\uffff';
					flag = true;
				}
				else if (array[j + 1] == 'ﺃ')
				{
					array[j] = 'ﻵ';
					letters[j + 1] = '\uffff';
					flag = true;
				}
				else if (array[j + 1] == 'ﺁ')
				{
					array[j] = 'ﻳ';
					letters[j + 1] = '\uffff';
					flag = true;
				}
			}
			if (!IsIgnoredCharacter(array[j]))
			{
				if (IsMiddleLetter(array, j))
				{
					letters[j] = (char)(array[j] + 3);
				}
				else if (IsFinishingLetter(array, j))
				{
					letters[j] = (char)(array[j] + 1);
				}
				else if (IsLeadingLetter(array, j))
				{
					letters[j] = (char)(array[j] + 2);
				}
			}
			if (flag)
			{
				j++;
			}
			if (useHinduNumbers)
			{
				letters[j] = (char)HandleInduNumber(array[j], letters[j]);
			}
		}
		if (showTashkeel && tashkeelLocation.Count > 0)
		{
			ReturnTashkeel(ref letters, tashkeelLocation);
		}
		internalStringBuilder.Clear();
		internalStringBuilder.EnsureCapacity(letters.Length);
		List<char> numberList = null;
		for (int num = letters.Length - 1; num >= 0; num--)
		{
			if (char.IsPunctuation(letters[num]) && num > 0 && num < letters.Length - 1 && (char.IsPunctuation(letters[num - 1]) || char.IsPunctuation(letters[num + 1])))
			{
				if (letters[num] == '(')
				{
					internalStringBuilder.Append(')');
				}
				else if (letters[num] == ')')
				{
					internalStringBuilder.Append('(');
				}
				else if (letters[num] == '<')
				{
					internalStringBuilder.Append('>');
				}
				else if (letters[num] == '>')
				{
					internalStringBuilder.Append('<');
				}
				else if (letters[num] == '[')
				{
					internalStringBuilder.Append(']');
				}
				else if (letters[num] == ']')
				{
					internalStringBuilder.Append('[');
				}
				else if (letters[num] != '\uffff')
				{
					internalStringBuilder.Append(letters[num]);
				}
			}
			else if (letters[num] == ' ' && num > 0 && num < letters.Length - 1 && (char.IsLower(letters[num - 1]) || char.IsUpper(letters[num - 1]) || char.IsNumber(letters[num - 1])) && (char.IsLower(letters[num + 1]) || char.IsUpper(letters[num + 1]) || char.IsNumber(letters[num + 1])))
			{
				AddNumber(letters[num]);
			}
			else if (char.IsNumber(letters[num]) || char.IsLower(letters[num]) || char.IsUpper(letters[num]) || char.IsSymbol(letters[num]) || char.IsPunctuation(letters[num]))
			{
				if (letters[num] == '(')
				{
					AddNumber(')');
				}
				else if (letters[num] == ')')
				{
					AddNumber('(');
				}
				else if (letters[num] == '<')
				{
					AddNumber('>');
				}
				else if (letters[num] == '>')
				{
					AddNumber('<');
				}
				else if (letters[num] == '[')
				{
					internalStringBuilder.Append(']');
				}
				else if (letters[num] == ']')
				{
					internalStringBuilder.Append('[');
				}
				else
				{
					AddNumber(letters[num]);
				}
			}
			else if ((letters[num] >= '\ud800' && letters[num] <= '\udbff') || (letters[num] >= '\udc00' && letters[num] <= '\udfff'))
			{
				AddNumber(letters[num]);
			}
			else
			{
				AppendNumbers();
				if (letters[num] != '\uffff')
				{
					internalStringBuilder.Append(letters[num]);
				}
			}
		}
		AppendNumbers();
		return internalStringBuilder.ToString();
		void AddNumber(char value)
		{
			if (numberList == null)
			{
				numberList = new List<char>();
			}
			numberList.Add(value);
		}
		void AppendNumbers()
		{
			if (numberList != null && numberList.Count > 0)
			{
				for (int k = 0; k < numberList.Count; k++)
				{
					internalStringBuilder.Append(numberList[numberList.Count - 1 - k]);
				}
				numberList.Clear();
			}
		}
	}

	internal static ushort HandleInduNumber(ushort letterOrigin, ushort letterFinal)
	{
		return letterOrigin switch
		{
			48 => 1632, 
			49 => 1633, 
			50 => 1634, 
			51 => 1635, 
			52 => 1636, 
			53 => 1637, 
			54 => 1638, 
			55 => 1639, 
			56 => 1640, 
			57 => 1641, 
			_ => letterFinal, 
		};
	}

	internal static bool IsIgnoredCharacter(char ch)
	{
		bool flag = char.IsPunctuation(ch);
		bool flag2 = char.IsNumber(ch);
		bool flag3 = char.IsLower(ch);
		bool flag4 = char.IsUpper(ch);
		bool flag5 = char.IsSymbol(ch);
		bool flag6 = ch == 'ﭖ' || ch == 'ﭺ' || ch == 'ﮊ' || ch == 'ﮒ' || ch == 'ﮎ';
		bool flag7 = ch <= '\ufeff' && ch >= 'ﹰ';
		bool flag8 = flag7 || flag6 || ch == 'ﯼ';
		return flag || flag2 || flag3 || flag4 || flag5 || !flag8 || ch == 'a' || ch == '>' || ch == '<' || ch == '؛';
	}

	internal static bool IsLeadingLetter(char[] letters, int index)
	{
		bool flag = index == 0 || letters[index - 1] == ' ' || letters[index - 1] == '*' || letters[index - 1] == 'A' || char.IsPunctuation(letters[index - 1]) || letters[index - 1] == '>' || letters[index - 1] == '<' || letters[index - 1] == 'ﺍ' || letters[index - 1] == 'ﺩ' || letters[index - 1] == 'ﺫ' || letters[index - 1] == 'ﺭ' || letters[index - 1] == 'ﺯ' || letters[index - 1] == 'ﮊ' || letters[index - 1] == 'ﻭ' || letters[index - 1] == 'ﺁ' || letters[index - 1] == 'ﺃ' || letters[index - 1] == 'ﺀ' || letters[index - 1] == 'ﺇ' || letters[index - 1] == 'ﺅ';
		bool flag2 = letters[index] != ' ' && letters[index] != 'ﺩ' && letters[index] != 'ﺫ' && letters[index] != 'ﺭ' && letters[index] != 'ﺯ' && letters[index] != 'ﮊ' && letters[index] != 'ﺍ' && letters[index] != 'ﺃ' && letters[index] != 'ﺇ' && letters[index] != 'ﺁ' && letters[index] != 'ﺅ' && letters[index] != 'ﻭ' && letters[index] != 'ﺀ';
		bool flag3 = index < letters.Length - 1 && letters[index + 1] != ' ' && letters[index + 1] != '\n' && letters[index + 1] != '\r' && !char.IsPunctuation(letters[index + 1]) && !char.IsNumber(letters[index + 1]) && !char.IsSymbol(letters[index + 1]) && !char.IsLower(letters[index + 1]) && !char.IsUpper(letters[index + 1]) && letters[index + 1] != 'ﺀ';
		return flag && flag2 && flag3;
	}

	internal static bool IsFinishingLetter(char[] letters, int index)
	{
		bool flag = index != 0 && letters[index - 1] != ' ' && letters[index - 1] != 'ﺩ' && letters[index - 1] != 'ﺫ' && letters[index - 1] != 'ﺭ' && letters[index - 1] != 'ﺯ' && letters[index - 1] != 'ﮊ' && letters[index - 1] != 'ﻭ' && letters[index - 1] != 'ﺍ' && letters[index - 1] != 'ﺁ' && letters[index - 1] != 'ﺃ' && letters[index - 1] != 'ﺇ' && letters[index - 1] != 'ﺅ' && letters[index - 1] != 'ﺀ' && !char.IsPunctuation(letters[index - 1]) && !char.IsSymbol(letters[index - 1]) && letters[index - 1] != '>' && letters[index - 1] != '<';
		bool flag2 = letters[index] != ' ' && letters[index] != 'ﺀ';
		return flag && flag2;
	}

	internal static bool IsMiddleLetter(char[] letters, int index)
	{
		bool flag = index != 0 && letters[index] != 'ﺍ' && letters[index] != 'ﺩ' && letters[index] != 'ﺫ' && letters[index] != 'ﺭ' && letters[index] != 'ﺯ' && letters[index] != 'ﮊ' && letters[index] != 'ﻭ' && letters[index] != 'ﺁ' && letters[index] != 'ﺃ' && letters[index] != 'ﺇ' && letters[index] != 'ﺅ' && letters[index] != 'ﺀ';
		bool flag2 = index != 0 && letters[index - 1] != 'ﺍ' && letters[index - 1] != 'ﺩ' && letters[index - 1] != 'ﺫ' && letters[index - 1] != 'ﺭ' && letters[index - 1] != 'ﺯ' && letters[index - 1] != 'ﮊ' && letters[index - 1] != 'ﻭ' && letters[index - 1] != 'ﺁ' && letters[index - 1] != 'ﺃ' && letters[index - 1] != 'ﺇ' && letters[index - 1] != 'ﺅ' && letters[index - 1] != 'ﺀ' && !char.IsPunctuation(letters[index - 1]) && letters[index - 1] != '>' && letters[index - 1] != '<' && letters[index - 1] != ' ' && letters[index - 1] != '*';
		bool flag3 = index < letters.Length - 1 && letters[index + 1] != ' ' && letters[index + 1] != '\r' && letters[index + 1] != 'ﺀ' && !char.IsNumber(letters[index + 1]) && !char.IsSymbol(letters[index + 1]) && !char.IsPunctuation(letters[index + 1]);
		return flag3 && flag2 && flag && !char.IsPunctuation(letters[index + 1]);
	}
}
namespace Drunk_Arab
{
	[BepInPlugin("Drunk_Arab", "Drunk_Arab", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Logger;

		private static TMP_FontAsset arfont;

		internal static ConfigEntry<bool> dumpStringTables;

		internal static ConfigEntry<bool> debug;

		private void Start()
		{
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)ArabicFixer.Fix("أداة  Drunk_Arab : إصدار 1.0.0 الأن محملة!"));
			string text = Paths.PluginPath + "/DrunkArab-Drunk_Arab/notosansarabic-regular sdf";
			AssetBundle val = AssetBundle.LoadFromFile(text);
			arfont = val.LoadAsset<TMP_FontAsset>("NotoSansArabic-Regular SDF");
			if ((Object)(object)arfont == (Object)null)
			{
				Logger.LogError((object)ArabicFixer.Fix("خطأ تحميل ملف الخط من حزمة الموارد"));
			}
			Services.Setup(Logger, arfont);
			dumpStringTables = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Dump String Tables", false, "Controls creation of dump files for translation");
			debug = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Debug", false, "Controls debug logging");
			if (dumpStringTables.Value)
			{
				DumpStringTables();
			}
			injectTranslations(Paths.PluginPath + "/DrunkArab-Drunk_Arab/arabic.md");
		}

		private void injectTranslations(string path)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Dictionary<long, Dictionary<string, string>>> dictionary = Services.LoadTranslations(path);
			LocalizationSettings instance = LocalizationSettings.Instance;
			foreach (string key in dictionary.Keys)
			{
				if (key.Contains("default"))
				{
					continue;
				}
				if (debug.Value)
				{
					Logger.LogInfo((object)("Injecting Table " + key));
				}
				StringTable table = ((LocalizedDatabase<StringTable, StringTableEntry>)(object)instance.GetStringDatabase()).GetTable(TableReference.op_Implicit(key), instance.GetSelectedLocale());
				foreach (TableEntryData tableDatum in ((LocalizationTable)table).m_TableData)
				{
					try
					{
						if (dictionary[key].Keys.Contains(tableDatum.Id))
						{
							if (debug.Value)
							{
								Logger.LogInfo((object)("Injecting " + tableDatum.m_Localized + " to " + dictionary[key][tableDatum.m_Id].Values.ToArray()[1]));
							}
							tableDatum.m_Localized = dictionary[key][tableDatum.m_Id].Values.ToArray()[1];
						}
						else
						{
							Logger.LogWarning((object)($"String |{tableDatum.m_Id}|" + ((LocalizationTable)table).m_SharedData.GetEntry(tableDatum.Id).m_Key + "| is not translated.|"));
						}
					}
					catch (Exception ex)
					{
						Logger.LogError((object)ex);
					}
				}
			}
		}

		private static void DumpStringTables()
		{
			LanguageDoc languageDoc = new LanguageDoc(Paths.PluginPath + "/DrunkArab-Drunk_Arab/Dump/");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TextMeshProUGUI), "Awake")]
		private static void patchTextMeshProUGUI(ref TextMeshProUGUI __instance)
		{
			Services.patchTextMeshProUGUI(ref __instance);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Drunk_Arab";

		public const string PLUGIN_NAME = "Drunk_Arab";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LibArbUnity
{
	public class Doc
	{
		private StreamWriter writer;

		public bool Generated { get; private set; }

		public Doc(string filePath)
		{
			if (!filePath.EndsWith(".md"))
			{
				filePath += ".md";
			}
			new FileInfo(filePath).Directory.Create();
			writer = File.CreateText(filePath);
		}

		public void AddText(string text)
		{
			writer.WriteLine(text);
			writer.Flush();
		}

		public void AddHeader(int size, string headerText)
		{
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < size; i++)
			{
				stringBuilder.Append("#");
			}
			stringBuilder.Append(" " + headerText);
			writer.WriteLine((object?)stringBuilder);
			writer.Flush();
		}

		public void AddTableHeader(params string[] columns)
		{
			StringBuilder stringBuilder = new StringBuilder("|");
			foreach (string text in columns)
			{
				stringBuilder.Append(text + " |");
			}
			stringBuilder.Append("\n|");
			for (int j = 0; j < columns.Length; j++)
			{
				stringBuilder.Append("---|");
			}
			writer.WriteLine((object?)stringBuilder);
			writer.Flush();
		}

		public void AddTableRow(params string[] vals)
		{
			StringBuilder stringBuilder = new StringBuilder("|");
			foreach (string text in vals)
			{
				stringBuilder.Append(text + "|");
			}
			writer.WriteLine((object?)stringBuilder);
			writer.Flush();
		}

		public void Save()
		{
			writer.Flush();
			writer.Close();
			Generated = true;
		}

		internal static string RangeString(float m_min, float m_max)
		{
			if (m_min == m_max)
			{
				return m_min.ToString();
			}
			return $"{m_min} - {m_max}";
		}
	}
	public static class Services
	{
		public static ManualLogSource Logger;

		public static bool debug;

		private static LanguageDoc ld;

		private static TMP_FontAsset arfont;

		public static void Setup(ManualLogSource logSource, TMP_FontAsset font)
		{
			if (logSource == null)
			{
				throw new Exception(ArabicFixer.Fix("وفر مخرج سطر أوامر للمكتبة"));
			}
			Logger = logSource;
			if ((Object)(object)font == (Object)null)
			{
				Logger.LogError((object)ArabicFixer.Fix("خطأ تحميل ملف الخط من حزمة الموارد"));
			}
			arfont = font;
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			Logger.LogInfo((object)ArabicFixer.Fix("الخطوط المثبتة حاليا\u064b: \n" + Utils.ToStringSeq((Array)array)));
			Logger.LogInfo((object)ArabicFixer.Fix("تم تفعيل مكتبة التعريب!"));
		}

		public static Dictionary<string, Dictionary<long, Dictionary<string, string>>> LoadTranslations(string filePath)
		{
			Dictionary<string, Dictionary<long, Dictionary<string, string>>> dictionary = new Dictionary<string, Dictionary<long, Dictionary<string, string>>>();
			StreamReader streamReader;
			try
			{
				streamReader = new StreamReader(filePath);
			}
			catch (Exception)
			{
				Logger.LogError((object)ArabicFixer.Fix("خطأ في تحميل ملف الترجمة من التخزين"));
				return null;
			}
			int num = 0;
			string key = "default";
			dictionary[key] = new Dictionary<long, Dictionary<string, string>>();
			try
			{
				string text;
				while ((text = streamReader.ReadLine()) != null)
				{
					num++;
					if (text.Contains("Template") || text.Contains("|-"))
					{
						continue;
					}
					if (text.Contains("Table:"))
					{
						string text2 = text.Split(":")[1].Split("_")[0].Trim();
						dictionary[text2] = new Dictionary<long, Dictionary<string, string>>();
						key = text2;
						if (debug)
						{
							Logger.LogInfo((object)("New table: " + text2));
						}
					}
					else if (!text.Contains("Table:") && text.Split("|")[1].Length > 2 && !text.Contains("#"))
					{
						string[] array = text.Split("|");
						if (debug)
						{
							Logger.LogInfo((object)("Adding " + array[0] + " " + array[1] + " " + array[2] + " " + array[3]));
						}
						long key2 = long.Parse(array[1].Trim());
						dictionary[key][key2] = new Dictionary<string, string>
						{
							{
								"Key",
								array[2].Trim()
							},
							{
								"Value",
								ArabicFixer.Fix(array[3].Trim())
							}
						};
					}
				}
			}
			catch (Exception ex2)
			{
				Logger.LogError((object)ex2);
			}
			finally
			{
				streamReader.Close();
			}
			return dictionary;
		}

		public static void patchTextMeshProUGUI(ref TextMeshProUGUI __instance)
		{
			if (Object.op_Implicit((Object)(object)arfont))
			{
				((Component)__instance).GetComponent<TMP_Text>().font = arfont;
			}
			((TMP_Text)__instance).m_isMaterialDirty = true;
			((TMP_Text)__instance).overflowMode = (TextOverflowModes)0;
			((TMP_Text)__instance).SetOutlineThickness(0f);
		}
	}
}
namespace LibArbUnity.Docs
{
	internal class LanguageDoc : Doc
	{
		private class TranslationListDoc : Doc
		{
			public LocalizationSettings ls = LocalizationSettings.s_Instance;

			public TranslationListDoc(string languageKey, string baseDir)
				: base(baseDir + "localization/translations/" + languageKey + ".md")
			{
				//IL_0121: Unknown result type (might be due to invalid IL or missing references)
				//IL_0126: Unknown result type (might be due to invalid IL or missing references)
				if (base.Generated)
				{
					return;
				}
				Locale[] array = ls.GetAvailableLocales().Locales.ToArray();
				Locale val = array[0];
				Locale[] array2 = array;
				foreach (Locale val2 in array2)
				{
					if (val2.LocaleName == languageKey)
					{
						val = val2;
					}
				}
				MonoBehaviour.print((object)("Setting " + ((Object)val).name + " Locale"));
				LocalizationSettings.SelectedLocale = val;
				MonoBehaviour.print((object)("Documenting " + languageKey + " translations"));
				AddHeader(1, languageKey + " translations list");
				AddText("All of the translation keys and " + languageKey + " text currently in the game.");
				AddText("This file is automatically generated.");
				AddTableHeader("Key(Or ID)", languageKey + " Text");
				IList<StringTable> list = ((LocalizedDatabase<StringTable, StringTableEntry>)(object)ls.GetStringDatabase()).GetAllTables(val).WaitForCompletion();
				MonoBehaviour.print((object)("Got ALL " + languageKey + " Tables"));
				foreach (StringTable item in list)
				{
					foreach (TableEntryData tableDatum in ((LocalizationTable)item).m_TableData)
					{
						long id = tableDatum.Id;
						string localized = tableDatum.Localized;
						MonoBehaviour.print((object)("Adding " + localized + " "));
						AddTableRow(id.ToString(), localized.Replace("\n", "<br/>"));
					}
				}
				Save();
			}
		}

		private List<Doc> subDocs = new List<Doc>();

		public LocalizationSettings ls = LocalizationSettings.s_Instance;

		internal string baseDir;

		public LanguageDoc(string basedir)
			: base(basedir + "Languages.md")
		{
			baseDir = basedir;
			docLanguages();
		}

		private void docLanguages()
		{
			if (base.Generated)
			{
				return;
			}
			MonoBehaviour.print((object)"Documenting languages");
			AddHeader(1, "Locales list");
			AddText("All of the locales currently in the game, each with link to it's document holding string translations.");
			AddText("This file is automatically generated.");
			AddTableHeader("Folder Name", "Localized Name", "Translations");
			Locale selectedLocale = ls.GetSelectedLocale();
			foreach (Locale locale in ls.GetAvailableLocales().Locales)
			{
				string text = ((Object)locale).name.ToLower();
				string text2 = $"[Translations](translations/{locale}.md)";
				AddTableRow(((Object)locale).name, text, text2);
				subDocs.Add(new TranslationListDoc(((Object)locale).name, baseDir));
			}
			LocalizationSettings.SelectedLocale = selectedLocale;
			Save();
		}
	}
}
namespace ArabicSupport
{
	public class ArabicFixer
	{
		public static string Fix(string str)
		{
			return Fix(str, showTashkeel: false, useHinduNumbers: true);
		}

		public static string Fix(string str, bool rtl)
		{
			if (rtl)
			{
				return Fix(str);
			}
			string[] array = str.Split(' ');
			string text = "";
			string text2 = "";
			string[] array2 = array;
			foreach (string text3 in array2)
			{
				if (char.IsLower(text3.ToLower()[text3.Length / 2]))
				{
					text = text + Fix(text2) + text3 + " ";
					text2 = "";
				}
				else
				{
					text2 = text2 + text3 + " ";
				}
			}
			if (text2 != "")
			{
				text += Fix(text2);
			}
			return text;
		}

		public static string Fix(string str, bool showTashkeel, bool useHinduNumbers)
		{
			ArabicFixerTool.showTashkeel = showTashkeel;
			ArabicFixerTool.useHinduNumbers = useHinduNumbers;
			if (str.Contains("\n"))
			{
				str = str.Replace("\n", Environment.NewLine);
			}
			if (str.Contains(Environment.NewLine))
			{
				string[] separator = new string[1] { Environment.NewLine };
				string[] array = str.Split(separator, StringSplitOptions.None);
				if (array.Length == 0)
				{
					return ArabicFixerTool.FixLine(str);
				}
				if (array.Length == 1)
				{
					return ArabicFixerTool.FixLine(str);
				}
				string text = ArabicFixerTool.FixLine(array[0]);
				int i = 1;
				if (array.Length > 1)
				{
					for (; i < array.Length; i++)
					{
						text = text + Environment.NewLine + ArabicFixerTool.FixLine(array[i]);
					}
				}
				return text;
			}
			return ArabicFixerTool.FixLine(str);
		}

		public static string Fix(string str, bool showTashkeel, bool combineTashkeel, bool useHinduNumbers)
		{
			ArabicFixerTool.combineTashkeel = combineTashkeel;
			return Fix(str, showTashkeel, useHinduNumbers);
		}
	}
}