private static bool TryLoadNewTexture(string section, U::UnityEngine.Texture2D texture2D, string path, ref Texture2DOverrideData overrideData, bool flip = false)
        {
            U::UnityEngine.Texture2D texture2D1;
            bool   flag;
            object dataLock = Texture2DOverride.DataLock;

            Monitor.Enter(dataLock);
            try
            {
                if (!Texture2DOverride.LoadTextureData(path, out texture2D1))
                {
                    flag = false;
                }
                else
                {
                    if (flip)
                    {
                        texture2D1 = Texture2DOverride.FlipTextureY(texture2D1);
                    }
                    texture2D1.name       = texture2D.name;
                    texture2D1.anisoLevel = texture2D.anisoLevel;
                    texture2D1.filterMode = texture2D.filterMode;
                    texture2D1.mipMapBias = texture2D.mipMapBias;
                    texture2D1.wrapMode   = texture2D.wrapMode;
                    overrideData          = new Texture2DOverrideData(texture2D, path, texture2D1);
                    Texture2DOverride.loaded.Add(texture2D.GetInstanceID(), new Texture2DCacheData(section, overrideData));
                    flag = true;
                }
            }
            finally
            {
                Monitor.Exit(dataLock);
            }
            return(flag);
        }
        private static bool TryLoadCacheTexture(U::UnityEngine.Texture2D texture2D, ref Texture2DOverrideData overrideData)
        {
            Texture2DCacheData texture2DCacheDatum;
            bool   flag;
            object dataLock = Texture2DOverride.DataLock;

            Monitor.Enter(dataLock);
            try
            {
                int instanceID = texture2D.GetInstanceID();
                if (!Texture2DOverride.loaded.TryGetValue(instanceID, out texture2DCacheDatum))
                {
                    flag = false;
                }
                else
                {
                    if (!Texture2DOverride.unused.Remove(instanceID))
                    {
                        texture2DCacheDatum.IncreaseAmount((long)1);
                    }
                    overrideData = texture2DCacheDatum.OverrideData;
                    flag         = true;
                }
            }
            finally
            {
                Monitor.Exit(dataLock);
            }
            return(flag);
        }
        internal static void UnloadTexture2D(ref Texture2DOverrideData overrideData)
        {
            Texture2DCacheData texture2DCacheDatum;
            object             dataLock = Texture2DOverride.DataLock;

            Monitor.Enter(dataLock);
            try
            {
                try
                {
                    try
                    {
                        if (overrideData.OriginalTexture2D != null)
                        {
                            int instanceID = overrideData.InstanceID;
                            if (Texture2DOverride.loaded.TryGetValue(instanceID, out texture2DCacheDatum))
                            {
                                if (texture2DCacheDatum.Count <= (long)0)
                                {
                                    Texture2DOverride.unused.Add(instanceID, DateTime.Now);
                                }
                                else
                                {
                                    texture2DCacheDatum.DecreaseAmount((long)1);
                                }
                            }
                        }
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        IniSettings.Error(string.Concat(new object[] { "UnloadTexture2D[", overrideData.InstanceID, "]:\n", exception.ToString() }));
                    }
                }
                finally
                {
                    overrideData = new Texture2DOverrideData();
                }
            }
            finally
            {
                Monitor.Exit(dataLock);
            }
        }
        internal static void LoadTexture2D(string objectName, U::UnityEngine.Texture2D texture2D, out Texture2DOverrideData overrideData)
        {
            string        str;
            Texture2DData texture2DDatum;
            string        texturePath;

            overrideData = new Texture2DOverrideData();
            try
            {
                if (!string.IsNullOrEmpty(texture2D.name))
                {
                    if (string.IsNullOrEmpty(objectName))
                    {
                        objectName = string.Empty;
                    }
                    str = (string.IsNullOrEmpty(objectName) || objectName == texture2D.name ? texture2D.name : string.Format("{0}:{1}", objectName, texture2D.name));
                    str = Texture2DOverride.Encode(str);
                    if (!Texture2DOverride.inidata.TryGetValue(str, out texture2DDatum))
                    {
                        if (Texture2DOverride.TryLoadCacheTexture(texture2D, ref overrideData))
                        {
                            texturePath = overrideData.TexturePath;
                        }
                        else if (!Texture2DOverride.uniqueimagesdata.TryGetValue(texture2D.name, out texturePath))
                        {
                            texturePath = texture2D.name;
                        }
                        else
                        {
                            bool   flag  = false;
                            string lower = Path.GetExtension(texturePath).ToLower();
                            if (lower == ".dds" || lower == ".psd")
                            {
                                flag = true;
                            }
                            Texture2DOverride.TryLoadNewTexture(str, texture2D, texturePath, ref overrideData, flag);
                        }
                        Texture2DOverride.inidata.Add(str, new Texture2DData(texturePath, false));
                        if (IniSettings.FindImage)
                        {
                            object writerLock = Texture2DOverride.WriterLock;
                            Monitor.Enter(writerLock);
                            try
                            {
                                Texture2DOverride.writerdata.Add(new Texture2DDumpData(str, texturePath, texture2D.format));
                                Texture2DOverride.writertimer.Start();
                            }
                            finally
                            {
                                Monitor.Exit(writerLock);
                            }
                        }
                    }
                    else if (texture2DDatum.Exists && !Texture2DOverride.TryLoadCacheTexture(texture2D, ref overrideData))
                    {
                        bool   flag1  = false;
                        string lower1 = Path.GetExtension(texture2DDatum.Path).ToLower();
                        if (lower1 == ".dds" || lower1 == ".psd")
                        {
                            flag1 = true;
                        }
                        Texture2DOverride.TryLoadNewTexture(str, texture2D, texture2DDatum.Path, ref overrideData, flag1);
                    }
                }
            }
            catch (Exception exception)
            {
                IniSettings.Error(string.Concat("LoadTexture2D:\n", exception.ToString()));
            }
        }
        private static void Load()
        {
            Texture2DCacheData texture2DCacheDatum;
            object             dataLock = Texture2DOverride.DataLock;

            Monitor.Enter(dataLock);
            try
            {
                Texture2DOverride.StopWatchTextFiles();
                Dictionary <int, Texture2DCacheData> nums = new Dictionary <int, Texture2DCacheData>(Texture2DOverride.loaded);
                Texture2DOverride.unused.Clear();
                Texture2DOverride.loaded.Clear();
                Texture2DOverride.LoadMainIniFile();
                Texture2DOverride.inidata          = Texture2DOverride.ParseIniData(Texture2DOverride.mainini);
                Texture2DOverride.uniqueimagesdata = Texture2DOverride.GetUniqueImageFiles(Texture2DOverride.TranslationImageDir);
                if (Texture2DOverride.GlobalTranslationImageIniFilePath != Texture2DOverride.TranslationImageDir)
                {
                    Dictionary <string, Texture2DData> strs = Texture2DOverride.ParseIniData(new IniFile(Texture2DOverride.GlobalTranslationImageIniFilePath));
                    foreach (KeyValuePair <string, Texture2DData> keyValuePair in strs)
                    {
                        if (Texture2DOverride.inidata.ContainsKey(keyValuePair.Key))
                        {
                            continue;
                        }
                        Texture2DOverride.inidata.Add(keyValuePair.Key, keyValuePair.Value);
                    }
                    strs.Clear();
                    strs = null;
                    Dictionary <string, string> uniqueImageFiles = Texture2DOverride.GetUniqueImageFiles(Texture2DOverride.GlobalTranslationImageDir);
                    foreach (KeyValuePair <string, string> uniqueImageFile in uniqueImageFiles)
                    {
                        if (Texture2DOverride.uniqueimagesdata.ContainsKey(uniqueImageFile.Key))
                        {
                            continue;
                        }
                        Texture2DOverride.uniqueimagesdata.Add(uniqueImageFile.Key, uniqueImageFile.Value);
                    }
                    uniqueImageFiles.Clear();
                    uniqueImageFiles = null;
                }
                Texture2DOverride.WatchTextFiles();
                foreach (KeyValuePair <int, Texture2DCacheData> num in nums)
                {
                    Texture2DOverrideData overrideData = num.Value.OverrideData;
                    Texture2DOverride.LoadTexture2D(num.Value.ObjectName, overrideData.OriginalTexture2D, out overrideData);
                    if (!Texture2DOverride.loaded.TryGetValue(overrideData.InstanceID, out texture2DCacheDatum))
                    {
                        continue;
                    }
                    texture2DCacheDatum.IncreaseAmount(num.Value.Count);
                }
                if (IniSettings.DebugMode || IniSettings.FindImage)
                {
                    int count = Texture2DOverride.inidata.Count;
                    IniSettings.Log(string.Concat("ImageSettingsLoaded: ", count.ToString()));
                }
            }
            finally
            {
                Monitor.Exit(dataLock);
            }
        }