Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GuideRenderer.cs
Go to the documentation of this file.
1using System;
6using Microsoft.Xna.Framework.GamerServices;
7using std;
8
10
11internal class GuideRenderer : IDisposable
12{
13 private IGuideRendererProxySource proxySource;
14
16
18
19 private int deviceResetCount;
20
22
24
25 public GuideRenderer(IGuideRendererProxySource proxySource)
26 {
27 this.proxySource = proxySource;
31 {
33 }
34 graphicsDeviceService.DeviceCreated += GraphicsDeviceCreated;
35 graphicsDeviceService.DeviceResetting += GraphicsDeviceResetting;
36 graphicsDeviceService.DeviceReset += GraphicsDeviceReset;
37 graphicsDeviceService.DeviceDisposing += GraphicsDeviceDisposing;
39 {
41 }
42 }
43
44 private void _007EGuideRenderer()
45 {
46 if (graphicsDeviceService != null)
47 {
48 graphicsDeviceService.DeviceCreated -= GraphicsDeviceCreated;
49 graphicsDeviceService.DeviceResetting -= GraphicsDeviceResetting;
50 graphicsDeviceService.DeviceReset -= GraphicsDeviceReset;
51 graphicsDeviceService.DeviceDisposing -= GraphicsDeviceDisposing;
52 }
54 if (graphicsDevice != null)
55 {
56 graphicsDevice.DrawGuide -= DrawGuide;
57 graphicsDevice = null;
58 }
60 }
61
62 private void _0021GuideRenderer()
63 {
65 }
66
67 private unsafe void DestroyResources()
68 {
70 if (ptr != null)
71 {
72 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr + 8)))((nint)ptr);
73 pStateBlock = null;
74 }
76 if (dictionary == null)
77 {
78 return;
79 }
81 if (enumerator.MoveNext())
82 {
83 do
84 {
85 IUnknown* ptr2 = (IUnknown*)enumerator.Current.ToPointer();
86 if (ptr2 != null)
87 {
88 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr2 + 8)))((nint)ptr2);
89 }
90 }
91 while (enumerator.MoveNext());
92 }
94 }
95
96 private void GraphicsDeviceCreated(object sender, EventArgs e)
97 {
99 {
101 }
102 GraphicsDeviceReset(sender, e);
103 graphicsDevice.DrawGuide += DrawGuide;
104 }
105
106 private void GraphicsDeviceResetting(object sender, EventArgs e)
107 {
109 }
110
111 private unsafe void GraphicsDeviceReset(object sender, EventArgs e)
112 {
116 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DSTATEBLOCKTYPE, IDirect3DStateBlock9**, int>)(int)(*(uint*)(*(int*)pComPtr + 236)))((nint)pComPtr, (_D3DSTATEBLOCKTYPE)1, &ptr);
117 if (num < 0)
118 {
120 }
122 }
123
124 private void GraphicsDeviceDisposing(object sender, EventArgs e)
125 {
126 if (graphicsDevice != null)
127 {
128 graphicsDevice.DrawGuide -= DrawGuide;
129 graphicsDevice = null;
130 }
132 }
133
134 private unsafe void DrawGuide(object sender, EventArgs e)
135 {
136 if (!object.ReferenceEquals(sender, graphicsDevice))
137 {
138 return;
139 }
140 IntPtr commandData = default(IntPtr);
142 if (proxySource.GetDrawingCommandsFromProxy(deviceResetCount, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, out commandData, out var commandDataSize))
143 {
145 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr + 16)))((nint)intPtr);
146 try
147 {
150 }
151 finally
152 {
154 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 20)))((nint)intPtr2);
155 }
156 }
157 }
158
160 {
162 Viewport viewport = default(Viewport);
163 viewport.X = 0;
164 viewport.Y = 0;
165 viewport.Width = presentationParameters.BackBufferWidth;
166 viewport.Height = presentationParameters.BackBufferHeight;
167 viewport.MinDepth = 0f;
168 viewport.MaxDepth = 1f;
169 graphicsDevice.Viewport = viewport;
170 }
171
173 {
175 byte* ptr = (byte*)commandData.ToPointer();
176 byte* ptr2 = ptr + commandDataSize;
185 while (ptr < ptr2)
186 {
187 int num = *(int*)ptr;
188 ptr += 4;
189 switch (num)
190 {
191 case 1:
192 {
193 int num38 = *(int*)ptr;
194 ptr += 4;
196 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)resource_003CIUnknown_003E + 8)))((nint)resource_003CIUnknown_003E);
198 break;
199 }
200 case 2:
201 {
202 int key2 = *(int*)ptr;
203 ptr += 4;
204 int num10 = *(int*)ptr;
205 ptr += 4;
207 ptr = ((num10 * 8 + 3) & -4) + ptr;
208 _D3DVERTEXELEMENT9* ptr6 = (_D3DVERTEXELEMENT9*)_003CModule_003E.new_005B_005D(((uint)(num10 + 1) > 536870911u) ? uint.MaxValue : ((uint)(num10 + 1 << 3)), (nothrow_t*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref _003CModule_003E.std_002Enothrow));
209 if (ptr6 == null)
210 {
211 throw new OutOfMemoryException();
212 }
213 try
214 {
215 for (int i = 0; i < num10; i++)
216 {
217 // IL cpblk instruction
218 System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(i * 8 + (byte*)ptr6, i * 8 + (byte*)ptr5, 8);
219 }
220 *(short*)(&d3DVERTEXELEMENT) = 255;
226 // IL cpblk instruction
228 int num11 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DVERTEXELEMENT9*, IDirect3DVertexDeclaration9**, int>)(int)(*(uint*)(*(int*)pComPtr + 344)))((nint)pComPtr, ptr6, &value3);
229 if (num11 < 0)
230 {
232 }
233 IntPtr value4 = new IntPtr(value3);
235 }
236 finally
237 {
238 _003CModule_003E.delete_005B_005D(ptr6);
239 }
240 break;
241 }
242 case 3:
243 {
244 int key4 = *(int*)ptr;
245 ptr += 4;
246 int num16 = *(int*)ptr;
247 ptr += 4;
248 byte* ptr9 = ptr;
249 ptr = ((num16 + 3) & -4) + ptr;
250 int num17 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint*, IDirect3DVertexShader9**, int>)(int)(*(uint*)(*(int*)pComPtr + 364)))((nint)pComPtr, (uint*)ptr9, &value7);
251 if (num17 < 0)
252 {
254 }
255 IntPtr value8 = new IntPtr(value7);
257 break;
258 }
259 case 4:
260 {
261 int key3 = *(int*)ptr;
262 ptr += 4;
263 int num14 = *(int*)ptr;
264 ptr += 4;
265 byte* ptr8 = ptr;
266 ptr = ((num14 + 3) & -4) + ptr;
267 int num15 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint*, IDirect3DPixelShader9**, int>)(int)(*(uint*)(*(int*)pComPtr + 424)))((nint)pComPtr, (uint*)ptr8, &value5);
268 if (num15 < 0)
269 {
271 }
272 IntPtr value6 = new IntPtr(value5);
274 break;
275 }
276 case 5:
277 {
278 int key = *(int*)ptr;
279 ptr += 4;
280 int num6 = *(int*)ptr;
281 ptr += 4;
282 int num7 = *(int*)ptr;
283 ptr += 4;
284 int num8 = *(int*)ptr;
285 ptr += 4;
287 ptr += 4;
288 int num9 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, uint, uint, _D3DFORMAT, _D3DPOOL, IDirect3DTexture9**, void**, int>)(int)(*(uint*)(*(int*)pComPtr + 92)))((nint)pComPtr, (uint)num6, (uint)num7, (uint)num8, 0u, d3DFORMAT2, (_D3DPOOL)1, &value, null);
289 if (num9 < 0)
290 {
292 }
293 IntPtr value2 = new IntPtr(value);
295 break;
296 }
297 case 6:
298 {
299 int handle5 = *(int*)ptr;
300 ptr += 4;
301 int num30 = *(int*)ptr;
302 ptr += 4;
303 // IL cpblk instruction
305 ptr += 16;
306 int num31 = *(int*)ptr;
307 ptr += 4;
308 byte* ptr12 = ptr;
309 ptr = ((num31 + 3) & -4) + ptr;
312 if (num32 < 0)
313 {
315 }
317 if (num33 < 0)
318 {
320 }
322 if (*(int*)(&d3DSURFACE_DESC) == 827611204 || *(int*)(&d3DSURFACE_DESC) == 844388420 || *(int*)(&d3DSURFACE_DESC) == 861165636 || *(int*)(&d3DSURFACE_DESC) == 877942852 || *(int*)(&d3DSURFACE_DESC) == 894720068)
323 {
324 num34 /= 4;
325 }
326 int num35 = num31 / num34;
327 if (0 < num34)
328 {
329 int num36 = num34;
330 do
331 {
334 ptr12 = num35 + ptr12;
335 num36--;
336 }
337 while (num36 != 0);
338 }
339 int num37 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, int>)(int)(*(uint*)(*(int*)resource_003CIDirect3DTexture9_003E + 80)))((nint)resource_003CIDirect3DTexture9_003E, (uint)num30);
340 if (num37 < 0)
341 {
343 }
344 break;
345 }
346 case 7:
347 {
348 int handle4 = *(int*)ptr;
349 ptr += 4;
350 int num29 = *(int*)pComPtr + 348;
352 break;
353 }
354 case 8:
355 {
356 int handle3 = *(int*)ptr;
357 ptr += 4;
358 int num28 = *(int*)pComPtr + 368;
360 break;
361 }
362 case 9:
363 {
364 int handle2 = *(int*)ptr;
365 ptr += 4;
366 int num27 = *(int*)pComPtr + 428;
368 break;
369 }
370 case 10:
371 {
372 int num25 = *(int*)ptr;
373 ptr += 4;
374 int handle = *(int*)ptr;
375 ptr += 4;
376 int num26 = *(int*)pComPtr + 260;
378 break;
379 }
380 case 11:
381 {
383 ptr += 4;
384 uint num24 = *(uint*)ptr;
385 ptr += 4;
386 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr + 228)))((nint)pComPtr, d3DRENDERSTATETYPE, num24);
387 break;
388 }
389 case 12:
390 {
391 uint num22 = *(uint*)ptr;
392 ptr += 4;
394 ptr += 4;
395 uint num23 = *(uint*)ptr;
396 ptr += 4;
397 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DSAMPLERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr + 276)))((nint)pComPtr, num22, d3DSAMPLERSTATETYPE, num23);
398 break;
399 }
400 case 13:
401 {
402 uint num20 = *(uint*)ptr;
403 ptr += 4;
404 uint num21 = *(uint*)ptr;
405 ptr += 4;
406 float* ptr11 = (float*)ptr;
407 ptr = ((int)(num21 * 16 + 3) & -4) + ptr;
408 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, float*, uint, int>)(int)(*(uint*)(*(int*)pComPtr + 376)))((nint)pComPtr, num20, ptr11, num21);
409 break;
410 }
411 case 14:
412 {
413 uint num18 = *(uint*)ptr;
414 ptr += 4;
415 uint num19 = *(uint*)ptr;
416 ptr += 4;
417 float* ptr10 = (float*)ptr;
418 ptr = ((int)(num19 * 16 + 3) & -4) + ptr;
419 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, float*, uint, int>)(int)(*(uint*)(*(int*)pComPtr + 436)))((nint)pComPtr, num18, ptr10, num19);
420 break;
421 }
422 case 15:
423 {
425 ptr += 4;
426 int num12 = *(int*)ptr;
427 ptr += 4;
428 int num13 = *(int*)ptr;
429 ptr += 4;
430 byte* ptr7 = ptr;
431 ptr = ((GetVertexCount(d3DPRIMITIVETYPE2, num12) * num13 + 3) & -4) + ptr;
433 {
434 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)pComPtr + 164)))((nint)pComPtr);
435 graphicsDevice._insideScene = true;
436 }
437 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DPRIMITIVETYPE, uint, void*, uint, int>)(int)(*(uint*)(*(int*)pComPtr + 332)))((nint)pComPtr, d3DPRIMITIVETYPE2, (uint)num12, ptr7, (uint)num13);
438 break;
439 }
440 case 16:
441 {
443 ptr += 4;
444 int num2 = *(int*)ptr;
445 ptr += 4;
446 int num3 = *(int*)ptr;
447 ptr += 4;
448 int num4 = *(int*)ptr;
449 ptr += 4;
450 int num5 = *(int*)ptr;
451 ptr += 4;
453 ptr += 4;
454 byte* ptr3 = ptr;
455 ptr = ((GetVertexCount(d3DPRIMITIVETYPE, num2) * num4 + 3) & -4) + ptr;
456 byte* ptr4 = ptr;
457 ptr = ((num5 * num3 + 3) & -4) + ptr;
459 {
460 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)pComPtr + 164)))((nint)pComPtr);
461 graphicsDevice._insideScene = true;
462 }
463 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DPRIMITIVETYPE, uint, uint, uint, void*, _D3DFORMAT, void*, uint, int>)(int)(*(uint*)(*(int*)pComPtr + 336)))((nint)pComPtr, d3DPRIMITIVETYPE, 0u, (uint)num3, (uint)num2, ptr3, d3DFORMAT, ptr4, (uint)num5);
464 break;
465 }
466 default:
467 throw new InvalidOperationException();
468 }
469 }
470 if (ptr > ptr2)
471 {
472 throw new ArgumentOutOfRangeException("commandDataSize");
473 }
474 }
475
476 private static int GetVertexCount(_D3DPRIMITIVETYPE primitiveType, int primitiveCount)
477 {
478 if (primitiveCount == 0)
479 {
480 return 0;
481 }
482 return primitiveType switch
483 {
484 (_D3DPRIMITIVETYPE)1 => primitiveCount,
485 (_D3DPRIMITIVETYPE)2 => primitiveCount << 1,
486 (_D3DPRIMITIVETYPE)3 => primitiveCount + 1,
487 (_D3DPRIMITIVETYPE)4 => primitiveCount * 3,
488 (_D3DPRIMITIVETYPE)5 => primitiveCount + 2,
489 (_D3DPRIMITIVETYPE)6 => primitiveCount + 2,
490 _ => 0,
491 };
492 }
493
495 protected virtual void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
496 {
497 if (P_0)
498 {
500 return;
501 }
502 try
503 {
505 }
506 finally
507 {
508 base.Finalize();
509 }
510 }
511
512 public virtual sealed void Dispose()
513 {
514 Dispose(true);
515 GC.SuppressFinalize(this);
516 }
517
519 {
520 Dispose(false);
521 }
522
524 {
525 if (handle == 0)
526 {
527 return null;
528 }
529 return (IUnknown*)resourceTable[handle].ToPointer();
530 }
531
533 {
534 if (handle == 0)
535 {
536 return null;
537 }
538 return (IDirect3DTexture9*)resourceTable[handle].ToPointer();
539 }
540
542 {
543 if (handle == 0)
544 {
545 return null;
546 }
548 }
549
551 {
552 if (handle == 0)
553 {
554 return null;
555 }
556 return (IDirect3DVertexShader9*)resourceTable[handle].ToPointer();
557 }
558
560 {
561 if (handle == 0)
562 {
563 return null;
564 }
565 return (IDirect3DPixelShader9*)resourceTable[handle].ToPointer();
566 }
567}
static Exception GetExceptionFromResult(uint result)
unsafe IDirect3DVertexDeclaration9 * GetResource_003CIDirect3DVertexDeclaration9_003E(int handle)
unsafe IDirect3DStateBlock9 * pStateBlock
unsafe void GraphicsDeviceReset(object sender, EventArgs e)
void GraphicsDeviceCreated(object sender, EventArgs e)
unsafe IDirect3DVertexShader9 * GetResource_003CIDirect3DVertexShader9_003E(int handle)
unsafe IUnknown * GetResource_003CIUnknown_003E(int handle)
unsafe IDirect3DTexture9 * GetResource_003CIDirect3DTexture9_003E(int handle)
unsafe void ReplayDrawingCommands(IntPtr commandData, int commandDataSize)
unsafe void DrawGuide(object sender, EventArgs e)
GuideRenderer(IGuideRendererProxySource proxySource)
static int GetVertexCount(_D3DPRIMITIVETYPE primitiveType, int primitiveCount)
virtual void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
void GraphicsDeviceDisposing(object sender, EventArgs e)
unsafe IDirect3DPixelShader9 * GetResource_003CIDirect3DPixelShader9_003E(int handle)
void GraphicsDeviceResetting(object sender, EventArgs e)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static readonly EventArgs Empty
Definition EventArgs.cs:9
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static unsafe void CopyBlock(void *destination, void *source, uint byteCount)
Definition Unsafe.cs:85
static unsafe void CopyBlockUnaligned(void *destination, void *source, uint byteCount)
Definition Unsafe.cs:101