Elin Modding Docs Doc
Loading...
Searching...
No Matches
TextureData.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using UnityEngine;
5
6// Token: 0x02000130 RID: 304
7public class TextureData : EScriptable
8{
9 // Token: 0x0600081D RID: 2077 RVA: 0x0003536C File Offset: 0x0003356C
10 public void TryRefresh()
11 {
12 DateTime lastWriteTime = File.GetLastWriteTime(this.path);
13 bool flag = this.date.DateTime.Year != 1 && this.date.DateTime.Equals(lastWriteTime);
14 if (this.dictReplace.Count > 0)
15 {
16 List<int> list = new List<int>();
17 foreach (TextureReplace textureReplace in this.dictReplace.Values)
18 {
19 if (!File.Exists(textureReplace.file.FullName))
20 {
21 this.forceRefresh = true;
22 list.Add(textureReplace.index);
23 }
24 }
25 foreach (int index in list)
26 {
27 this.RemoveDeletedReplace(index);
28 }
29 }
30 if (this.forceRefresh)
31 {
32 this.forceRefresh = false;
33 flag = false;
34 }
35 if (!flag || !this.IsValid())
36 {
37 this.Load(flag);
38 }
39 foreach (TextureReplace textureReplace2 in this.dictReplace.Values)
40 {
41 textureReplace2.TryRefresh(!flag);
42 }
43 this.date.DateTime = lastWriteTime;
44 }
45
46 // Token: 0x0600081E RID: 2078 RVA: 0x000354F0 File Offset: 0x000336F0
47 public void ForceRefresh()
48 {
49 this.forceRefresh = true;
50 this.TryRefresh();
51 }
52
53 // Token: 0x0600081F RID: 2079 RVA: 0x00035500 File Offset: 0x00033700
54 public static void RefreshAll()
55 {
56 if (!EClass.core.IsGameStarted)
57 {
58 return;
59 }
60 foreach (TextureData textureData in EClass.core.textures.texMap.Values)
61 {
62 textureData.ForceRefresh();
63 }
64 }
65
66 // Token: 0x06000820 RID: 2080 RVA: 0x0003556C File Offset: 0x0003376C
67 public virtual bool IsValid()
68 {
69 TextureData.Type type = this.type;
70 if (type != TextureData.Type.Pass)
71 {
72 return type != TextureData.Type.World || EClass.scene.tileset.AtlasTexture;
73 }
74 using (List<MeshPass>.Enumerator enumerator = this.listPass.GetEnumerator())
75 {
76 while (enumerator.MoveNext())
77 {
78 if (!enumerator.Current.mat.GetTexture(this.texName))
79 {
80 return false;
81 }
82 }
83 }
84 return true;
85 }
86
87 // Token: 0x06000821 RID: 2081 RVA: 0x000355FC File Offset: 0x000337FC
88 public void Load(bool dateMatched)
89 {
90 if (!dateMatched)
91 {
92 Texture2D texture2D = IO.LoadPNG(this.path, FilterMode.Point);
93 if (!texture2D)
94 {
95 Debug.Log(this.path);
96 }
97 if (this.tex.width != texture2D.width || this.tex.height != texture2D.height)
98 {
99 Debug.Log(string.Concat(new string[]
100 {
101 this.id,
102 "/",
103 texture2D.width.ToString(),
104 "/",
105 texture2D.height.ToString(),
106 "/",
107 this.path
108 }));
109 }
110 this.tex.SetPixels32(texture2D.GetPixels32());
111 this.tex.Apply();
112 UnityEngine.Object.Destroy(texture2D);
113 Debug.Log("Reloaded Texture:" + this.path);
114 }
115 TextureData.Type type = this.type;
116 if (type != TextureData.Type.Pass)
117 {
118 if (type != TextureData.Type.World)
119 {
120 return;
121 }
122 }
123 else
124 {
125 using (List<MeshPass>.Enumerator enumerator = this.listPass.GetEnumerator())
126 {
127 while (enumerator.MoveNext())
128 {
129 MeshPass meshPass = enumerator.Current;
130 meshPass.mat.SetTexture(this.texName, this.tex);
131 if (meshPass.haveShadowPass)
132 {
133 meshPass.shadowPass.mat.SetTexture(this.texName, this.tex);
134 }
135 }
136 return;
137 }
138 }
139 EClass.scene.tileset.AtlasTexture = this.tex;
140 }
141
142 // Token: 0x06000822 RID: 2082 RVA: 0x0003578C File Offset: 0x0003398C
143 public void CreateReplace(int index, string path, TextureReplace.Source source, int sizeX, int sizeY)
144 {
145 string str = this.id + "_" + index.ToString() + ".png";
146 Texture2D texture2D = new Texture2D(this.tileW * sizeX, this.tileH * sizeY);
147 int srcX = index % 100 * this.tileW;
148 int srcY = this.tex.height - index / 100 * this.tileH - texture2D.height;
149 Graphics.CopyTexture(this.tex, 0, 0, srcX, srcY, this.tileW * sizeX, this.tileH * sizeY, texture2D, 0, 0, 0, 0);
150 byte[] bytes = texture2D.EncodeToPNG();
151 try
152 {
153 File.WriteAllBytes(path + str, bytes);
154 EClass.core.textures.TryAddReplace(new FileInfo(path + str), source, true, true);
155 }
156 catch
157 {
158 }
159 UnityEngine.Object.Destroy(texture2D);
160 }
161
162 // Token: 0x06000823 RID: 2083 RVA: 0x00035870 File Offset: 0x00033A70
163 public void AddReplace(TextureReplace r)
164 {
165 TextureReplace textureReplace = this.dictReplace.TryGetValue(r.index, null);
166 if (textureReplace != null)
167 {
168 if (r.source == TextureReplace.Source.Local && textureReplace.source != TextureReplace.Source.Local)
169 {
170 r.original = textureReplace;
171 }
172 else
173 {
174 textureReplace.DestoryTex();
175 }
176 }
177 if (r.source == TextureReplace.Source.Local)
178 {
179 this.listReplaceLocal.Add(r);
180 }
181 this.dictReplace[r.index] = r;
182 }
183
184 // Token: 0x06000824 RID: 2084 RVA: 0x000358DB File Offset: 0x00033ADB
185 public void DeleteReplace(TextureReplace r)
186 {
187 r.file.Delete();
188 this.RemoveDeletedReplace(r.index);
189 }
190
191 // Token: 0x06000825 RID: 2085 RVA: 0x000358F4 File Offset: 0x00033AF4
192 public void RemoveDeletedReplace(int index)
193 {
194 TextureReplace textureReplace = this.dictReplace.TryGetValue(index, null);
195 if (textureReplace == null)
196 {
197 return;
198 }
199 textureReplace.DestoryTex();
200 if (textureReplace.original != null && textureReplace.original.file.Exists)
201 {
202 this.dictReplace[index] = textureReplace.original;
203 return;
204 }
205 this.dictReplace.Remove(index);
206 }
207
208 // Token: 0x04000881 RID: 2177
209 public string id;
210
211 // Token: 0x04000882 RID: 2178
212 public TextureData.Type type;
213
214 // Token: 0x04000883 RID: 2179
215 public TextureData.Date date;
216
217 // Token: 0x04000884 RID: 2180
218 public Texture2D tex;
219
220 // Token: 0x04000885 RID: 2181
221 public bool forceRefresh;
222
223 // Token: 0x04000886 RID: 2182
224 public int tileW;
225
226 // Token: 0x04000887 RID: 2183
227 public int tileH;
228
229 // Token: 0x04000888 RID: 2184
230 [NonSerialized]
231 public string path;
232
233 // Token: 0x04000889 RID: 2185
234 [NonSerialized]
235 public string texName;
236
237 // Token: 0x0400088A RID: 2186
238 [NonSerialized]
239 public List<MeshPass> listPass = new List<MeshPass>();
240
241 // Token: 0x0400088B RID: 2187
242 [NonSerialized]
243 public Dictionary<int, TextureReplace> dictReplace = new Dictionary<int, TextureReplace>();
244
245 // Token: 0x0400088C RID: 2188
246 [NonSerialized]
247 public List<TextureReplace> listReplaceLocal = new List<TextureReplace>();
248
249 // Token: 0x02000856 RID: 2134
250 [Serializable]
251 public class Date
252 {
253 // Token: 0x17001147 RID: 4423
254 // (get) Token: 0x06003A01 RID: 14849 RVA: 0x00133E61 File Offset: 0x00132061
255 // (set) Token: 0x06003A02 RID: 14850 RVA: 0x00133E6E File Offset: 0x0013206E
256 public DateTime DateTime
257 {
258 get
259 {
260 return new DateTime(this.ticks);
261 }
262 set
263 {
264 this.ticks = value.Ticks;
265 }
266 }
267
268 // Token: 0x040023A6 RID: 9126
269 public long ticks;
270 }
271
272 // Token: 0x02000857 RID: 2135
273 public enum Type
274 {
275 // Token: 0x040023A8 RID: 9128
276 Pass,
277 // Token: 0x040023A9 RID: 9129
278 World,
279 // Token: 0x040023AA RID: 9130
280 DestTex
281 }
282}
Definition World.cs:6