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); }
private static U::UnityEngine.Texture2D FlipTextureY(U::UnityEngine.Texture2D original) { U::UnityEngine.Texture2D texture2D; try { texture2D = new U::UnityEngine.Texture2D(original.width, original.height, original.format, false); int num = original.width; int num1 = original.height; for (int i = 0; i < num1; i++) { for (int j = 0; j < num; j++) { texture2D.SetPixel(j, num1 - i - 1, original.GetPixel(j, i)); } } texture2D.Apply(); } catch (Exception exception1) { Exception exception = exception1; texture2D = original; IniSettings.Error(string.Concat("FlipTextureY:\n", exception.ToString())); } return(texture2D); }
public static bool LoadTGA(Stream TGAStream, out U::UnityEngine.Texture2D texture) { bool flag; try { using (BinaryReader reader = new BinaryReader(TGAStream)) { Texture2D textured; reader.BaseStream.Seek(12L, SeekOrigin.Begin); short width = reader.ReadInt16(); short height = reader.ReadInt16(); int num3 = reader.ReadByte(); reader.BaseStream.Seek(1L, SeekOrigin.Current); Color32[] colors = new Color32[width * height]; if (num3 == 0x20) { textured = new Texture2D(width, height, TextureFormat.RGBA32, false); for (int i = 0; i < (width * height); i++) { byte b = reader.ReadByte(); byte g = reader.ReadByte(); byte r = reader.ReadByte(); byte a = reader.ReadByte(); colors[i] = new Color32(r, g, b, a); } } else { if (num3 != 0x18) { throw new Exception("TGA texture had non 32/24 bit depth."); } textured = new Texture2D(width, height, TextureFormat.RGB24, false); for (int j = 0; j < (width * height); j++) { byte num10 = reader.ReadByte(); byte num11 = reader.ReadByte(); byte num12 = reader.ReadByte(); colors[j] = new Color32(num12, num11, num10, 0xff); } } textured.SetPixels32(colors); textured.Apply(); texture = textured; flag = true; } } catch { texture = null; flag = false; } return(flag); }
public static bool LoadDXT(string fileName, out U::UnityEngine.Texture2D texture) { try { return(LoadDXT(File.ReadAllBytes(fileName), out texture)); } catch { texture = null; return(false); } }
private static bool LoadTextureData(string path, out U::UnityEngine.Texture2D texture2D) { bool flag; texture2D = null; try { path = string.Concat(Texture2DOverride.TranslationImageDir, path); string extension = Path.GetExtension(path); if (extension == ".dds") { flag = DXTLoader.LoadDXT(path, out texture2D); } else if (extension == ".jpeg" || extension == ".jpg") { texture2D = new Texture2D(2, 2, TextureFormat.RGB24, false); flag = texture2D.LoadImage(File.ReadAllBytes(path)); } else if (extension == ".png") { texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false); flag = texture2D.LoadImage(File.ReadAllBytes(path)); } else if (extension == ".psd") { flag = PSDLoader.LoadPSD(path, out texture2D); } else if (extension == ".tga") { flag = TGALoader.LoadTGA(path, out texture2D); } else { return(false); } } catch (Exception exception) { IniSettings.Error(string.Concat("LoadImage:\n", exception.ToString())); return(false); } return(flag); }
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())); } }