Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CopyOrRestoreData()

unsafe int Microsoft.Xna.Framework.Graphics.Texture2D.CopyOrRestoreData ( [MarshalAs(UnmanagedType.U1)] bool isStoring)
inlinepackage

Definition at line 770 of file Texture2D.cs.

771 {
772 IDirect3DTexture9* ptr = pComPtr;
773 if (ptr == null)
774 {
775 return 0;
776 }
777 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DSURFACE_DESC d3DSURFACE_DESC);
778 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DSURFACE_DESC*, int>)(int)(*(uint*)(*(int*)ptr + 68)))((nint)ptr, 0u, &d3DSURFACE_DESC);
779 if (num >= 0)
780 {
781 if (isStoring)
782 {
784 }
785 uint num2 = System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 24));
786 uint num3 = System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 28));
787 bool flag = Texture.CheckCompressedTexture(*(_D3DFORMAT*)(&d3DSURFACE_DESC));
788 byte b = ((!flag) ? Texture.GetExpectedByteSizeFromFormat(*(_D3DFORMAT*)(&d3DSURFACE_DESC)) : ((byte)((*(int*)(&d3DSURFACE_DESC) == 827611204) ? 8u : 16u)));
789 int num4 = 0;
790 int num5 = 0;
791 if (0 < _levelCount)
792 {
793 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DLOCKED_RECT d3DLOCKED_RECT);
794 do
795 {
796 byte* ptr2 = null;
797 int num6;
798 if (!isStoring)
799 {
800 ref IntPtr reference = ref pFaceData[num4];
801 num4++;
802 ptr2 = (byte*)reference.ToPointer();
803 num6 = 0;
804 }
805 else
806 {
807 num6 = 16;
808 }
809 ptr = pComPtr;
810 num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DLOCKED_RECT*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr + 76)))((nint)ptr, (uint)num5, &d3DLOCKED_RECT, null, (uint)num6);
811 if (num < 0)
812 {
813 break;
814 }
815 uint num7 = num2;
816 uint num8 = num3;
817 if (flag)
818 {
819 num7 = num2 + 3 >> 2;
820 num8 = num3 + 3 >> 2;
821 }
822 uint num9 = b * num7;
823 byte* ptr3 = (byte*)(int)System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_RECT, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_RECT, 4));
824 if (isStoring)
825 {
826 ptr2 = (byte*)_003CModule_003E.new_005B_005D(num9 * num8);
827 }
828 byte* ptr4 = ptr2;
829 if (0 < num8)
830 {
831 uint num10 = num8;
832 do
833 {
834 if (isStoring)
835 {
836 _003CModule_003E.memcpy_s(ptr4, num9 * num8, ptr3, num9);
837 }
838 else
839 {
840 _003CModule_003E.memcpy_s(ptr3, *(uint*)(&d3DLOCKED_RECT), ptr4, num9);
841 }
842 ptr3 = *(int*)(&d3DLOCKED_RECT) + ptr3;
843 ptr4 = (int)num9 + ptr4;
844 num10--;
845 }
846 while (num10 != 0);
847 }
848 ptr = pComPtr;
849 num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, int>)(int)(*(uint*)(*(int*)ptr + 80)))((nint)ptr, (uint)num5);
850 if (num < 0)
851 {
852 break;
853 }
854 if (isStoring)
855 {
856 IntPtr intPtr = (IntPtr)ptr2;
857 ref IntPtr reference2 = ref pFaceData[num4];
858 num4++;
859 reference2 = intPtr;
860 }
861 num2 = ((num2 <= 1) ? 1u : (num2 >> 1));
862 num3 = ((num3 <= 1) ? 1u : (num3 >> 1));
863 num5++;
864 }
865 while (num5 < _levelCount);
866 }
867 }
868 return num;
869 }
unsafe IDirect3DTexture9 * pComPtr
Definition Texture2D.cs:22

References Microsoft.Xna.Framework.Graphics.Texture._levelCount, Microsoft.Xna.Framework.Graphics.Texture.CheckCompressedTexture(), Microsoft.Xna.Framework.Graphics.Texture.GetExpectedByteSizeFromFormat(), Microsoft.Xna.Framework.Graphics.Texture2D.pComPtr, and Microsoft.Xna.Framework.Graphics.Texture2D.pFaceData.

Referenced by Microsoft.Xna.Framework.Graphics.Texture2D.RecreateAndPopulateObject(), and Microsoft.Xna.Framework.Graphics.Texture2D.SaveDataForRecreation().