-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSurface.cs
266 lines (231 loc) · 13.4 KB
/
Surface.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
using DynamicPatcher;
using PatcherYRpp.FileFormats;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace PatcherYRpp
{
[StructLayout(LayoutKind.Explicit, Size = 36)]
public struct Surface
{
private static IntPtr ppTile = new IntPtr(0x8872FC);
private static IntPtr ppSidebar = new IntPtr(0x887300);
private static IntPtr ppPrimary = new IntPtr(0x887308);
private static IntPtr ppHidden = new IntPtr(0x88730C);
private static IntPtr ppAlternate = new IntPtr(0x887310);
private static IntPtr ppCurrent = new IntPtr(0x887314);
private static IntPtr ppComposite = new IntPtr(0x88731C);
public static Pointer<Surface> Tile { get => ((Pointer<Pointer<Surface>>)ppTile).Data; set => ((Pointer<Pointer<Surface>>)ppTile).Ref = value; }
public static Pointer<Surface> Sidebar { get => ((Pointer<Pointer<Surface>>)ppSidebar).Data; set => ((Pointer<Pointer<Surface>>)ppSidebar).Ref = value; }
public static Pointer<Surface> Primary { get => ((Pointer<Pointer<Surface>>)ppPrimary).Data; set => ((Pointer<Pointer<Surface>>)ppPrimary).Ref = value; }
public static Pointer<Surface> Hidden { get => ((Pointer<Pointer<Surface>>)ppHidden).Data; set => ((Pointer<Pointer<Surface>>)ppHidden).Ref = value; }
public static Pointer<Surface> Alternate { get => ((Pointer<Pointer<Surface>>)ppAlternate).Data; set => ((Pointer<Pointer<Surface>>)ppAlternate).Ref = value; }
public static Pointer<Surface> Current { get => ((Pointer<Pointer<Surface>>)ppCurrent).Data; set => ((Pointer<Pointer<Surface>>)ppCurrent).Ref = value; }
public static Pointer<Surface> Composite { get => ((Pointer<Pointer<Surface>>)ppComposite).Data; set => ((Pointer<Pointer<Surface>>)ppComposite).Ref = value; }
private static IntPtr pViewBound = new IntPtr(0x886FA0);
public static ref RectangleStruct ViewBound => ref pViewBound.Convert<RectangleStruct>().Ref;
public unsafe bool BlitWhole(Pointer<Surface> pSrc, bool unk1, bool unk2)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, IntPtr, Bool, Bool, Bool>)this.GetVirtualFunctionPointer(1);
return func(ref this, pSrc, unk1, unk2);
}
public unsafe bool BlitPart(RectangleStruct clipRect, Pointer<Surface> pSrc, RectangleStruct srcRect, bool unk1, bool unk2)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref RectangleStruct, IntPtr, ref RectangleStruct, Bool, Bool, Bool>)this.GetVirtualFunctionPointer(2);
return func(ref this, ref clipRect, pSrc, ref srcRect, unk1, unk2);
}
public unsafe bool Blit(RectangleStruct clipRect, RectangleStruct clipRect2, Pointer<Surface> pSrc, RectangleStruct destRect, RectangleStruct srcRect, bool unk1, bool unk2)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref RectangleStruct, ref RectangleStruct, IntPtr, ref RectangleStruct, ref RectangleStruct, Bool, Bool, Bool>)this.GetVirtualFunctionPointer(3);
return func(ref this, ref clipRect, ref clipRect2, pSrc, ref destRect, ref srcRect, unk1, unk2);
}
public unsafe bool FillRectEx(RectangleStruct clipRect, RectangleStruct fillRect, int dwColor)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref RectangleStruct, ref RectangleStruct, int, Bool>)this.GetVirtualFunctionPointer(4);
return func(ref this, ref clipRect, ref fillRect, dwColor);
}
public unsafe bool FillRect(RectangleStruct fillRect, int dwColor)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref RectangleStruct, int, Bool>)this.GetVirtualFunctionPointer(5);
return func(ref this, ref fillRect, dwColor);
}
public unsafe bool FillRect(int dwColor)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, int, Bool>)this.GetVirtualFunctionPointer(6);
return func(ref this, dwColor);
}
public unsafe bool SetPixel(Point2D point, int dwColor)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref Point2D, int, Bool>)this.GetVirtualFunctionPointer(9);
return func(ref this, ref point, dwColor);
}
public unsafe int GetPixel(Point2D point)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref Point2D, int>)this.GetVirtualFunctionPointer(10);
return func(ref this, ref point);
}
public unsafe bool DrawLineEx(RectangleStruct clipRect, Point2D point1, Point2D point2, int dwColor)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref RectangleStruct, ref Point2D, ref Point2D, int, Bool>)this.GetVirtualFunctionPointer(11);
return func(ref this, ref clipRect, ref point1, ref point2, dwColor);
}
public unsafe bool DrawLine(Point2D point1, Point2D point2, int dwColor)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref Point2D, ref Point2D, int, Bool>)this.GetVirtualFunctionPointer(12);
return func(ref this, ref point1, ref point2, dwColor);
}
public unsafe bool DrawRibbon(RectangleStruct clipRect, Point2D srcPoint, Point2D destPoint, ColorStruct color, float intensity, int srcZAdjust, int destZAdjust)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref RectangleStruct, ref Point2D, ref Point2D, ref ColorStruct, float, int, int, Bool>)this.GetVirtualFunctionPointer(16);
return func(ref this, ref clipRect, ref srcPoint, ref destPoint, ref color, intensity, srcZAdjust, destZAdjust);
}
public unsafe bool DrawRectEx(RectangleStruct clipRect, RectangleStruct drawRect, int dwColor)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref RectangleStruct, ref RectangleStruct, int, Bool>)this.GetVirtualFunctionPointer(21);
return func(ref this, ref clipRect, ref drawRect, dwColor);
}
public unsafe bool DrawRect(RectangleStruct drawRect, int dwColor)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref RectangleStruct, int, Bool>)this.GetVirtualFunctionPointer(22);
return func(ref this, ref drawRect, dwColor);
}
public unsafe IntPtr Lock(int X, int Y)
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, int, int, IntPtr>)this.GetVirtualFunctionPointer(23);
return func(ref this, X, Y);
}
public unsafe bool Unlock()
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, Bool>)this.GetVirtualFunctionPointer(24);
return func(ref this);
}
public unsafe int GetBytesPerPixel()
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, int>)this.GetVirtualFunctionPointer(28);
return func(ref this);
}
public unsafe int GetPitch()
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, int>)this.GetVirtualFunctionPointer(29);
return func(ref this);
}
public unsafe RectangleStruct GetRect()
{
RectangleStruct ret = default;
var func = (delegate* unmanaged[Thiscall]<ref Surface, ref RectangleStruct, IntPtr>)this.GetVirtualFunctionPointer(30);
func(ref this, ref ret);
return ret;
}
public unsafe int GetWidth()
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, int>)this.GetVirtualFunctionPointer(31);
return func(ref this);
}
public unsafe int GetHeight()
{
var func = (delegate* unmanaged[Thiscall]<ref Surface, int>)this.GetVirtualFunctionPointer(32);
return func(ref this);
}
public unsafe void DrawSHP(Pointer<SHPStruct> pSHP, int nFrame, Pointer<ConvertClass> pPalette, int X, int Y)
{
DrawSHP(pSHP, nFrame, pPalette, new Point2D(X, Y));
}
public unsafe void DrawSHP(Pointer<SHPStruct> pSHP, int nFrame, Pointer<ConvertClass> pPalette, Point2D point)
{
RectangleStruct rect = this.GetRect();
DrawSHP(pPalette, pSHP, nFrame, point, rect, BlitterFlags.None, 0, 0, 0, 0x3E8, 0, IntPtr.Zero, 0, 0, 0);
}
public unsafe void DrawSHP(Pointer<ConvertClass> Palette, Pointer<SHPStruct> SHP, int frameIdx,
Point2D pos, RectangleStruct boundingRect, BlitterFlags flags, uint arg7,
int zAdjust, uint arg9, uint bright, int TintColor, Pointer<SHPStruct> BUILDINGZ_SHA, uint argD, int ZS_X, int ZS_Y)
{
DrawSHP(Palette, SHP, frameIdx, Pointer<Point2D>.AsPointer(ref pos), Pointer<RectangleStruct>.AsPointer(ref boundingRect), flags, arg7, zAdjust, arg9, bright, TintColor, BUILDINGZ_SHA, argD, ZS_X, ZS_Y);
}
public unsafe void DrawSHP(Pointer<ConvertClass> Palette, Pointer<SHPStruct> SHP, int frameIdx,
Pointer<Point2D> pos, Pointer<RectangleStruct> boundingRect, BlitterFlags flags, uint arg7,
int zAdjust, uint arg9, uint bright, int TintColor, Pointer<SHPStruct> BUILDINGZ_SHA, uint argD, int ZS_X, int ZS_Y)
{
var func = (delegate* unmanaged[Thiscall]<int, ref Surface, IntPtr, IntPtr, int, IntPtr, IntPtr, BlitterFlags, uint, int, uint, uint, int, IntPtr, uint, int, int, void>)ASM.FastCallTransferStation;
func(0x4AED70, ref this, Palette, SHP, frameIdx, pos, boundingRect, flags, arg7, zAdjust, arg9, bright, TintColor, BUILDINGZ_SHA, argD, ZS_X, ZS_Y);
}
[FieldOffset(0)] public int Vfptr;
[FieldOffset(4)] public int Width; /*| BSurface->*/
[FieldOffset(8)] public int Height; /*| BSurface->*/
[FieldOffset(12)] public int LockLevel; /*| BSurface->*/
[FieldOffset(16)] public int BytesPerPixel; /*| BSurface->*/
[FieldOffset(20)] public Pointer<byte> Buffer; /*| BSurface->*/
[FieldOffset(24)] public Bool Allocated; /*| BSurface->*/ [FieldOffset(24)] public int BufferSize;
[FieldOffset(25)] public Bool VRAMmed; /*| BSurface->*/
[FieldOffset(26)] public byte unknown_1A; /*| BSurface->*/
[FieldOffset(27)] public byte unknown_1B; /*| BSurface->*/
[FieldOffset(28)] public Pointer<IDirectDrawSurface> Surf; /*| BSurface->*/ [FieldOffset(28)] public Bool BufferAllocated;
[FieldOffset(32)] public Pointer<DDSURFACEDESC2> SurfDesc; /*| BSurface->*/
}
[StructLayout(LayoutKind.Explicit, Size = 36)]
public struct DSurface
{
public static unsafe void Constructor(Pointer<DSurface> pThis, int Width, int Height, bool BackBuffer, bool Force3D)
{
var func = (delegate* unmanaged[Thiscall]<ref DSurface, int, int, Bool, Bool, IntPtr>)0x4BA5A0;
func(ref pThis.Ref, Width, Height, BackBuffer, Force3D);
}
public static unsafe void Destructor(Pointer<DSurface> pThis)
{
var func = (delegate* unmanaged[Thiscall]<ref DSurface, void>)Helpers.GetVirtualFunctionPointer(pThis, 0);
func(ref pThis.Ref);
}
[FieldOffset(0)] public Surface Base;
}
[StructLayout(LayoutKind.Explicit, Size = 36)]
public struct XSurface
{
public static unsafe void Constructor(Pointer<XSurface> pThis, int Width, int Height)
{
var func = (delegate* unmanaged[Thiscall]<ref XSurface, int, int, IntPtr>)0x4AEC60;
func(ref pThis.Ref, Width, Height);
}
public static unsafe void Destructor(Pointer<XSurface> pThis)
{
var func = (delegate* unmanaged[Thiscall]<ref XSurface, void>)Helpers.GetVirtualFunctionPointer(pThis, 0);
func(ref pThis.Ref);
}
[FieldOffset(0)] public Surface Base;
}
[StructLayout(LayoutKind.Explicit, Size = 36)]
public struct BSurface
{
public static unsafe void Constructor(Pointer<BSurface> pThis, int width, int height)
{
var func = (delegate* unmanaged[Thiscall]<ref BSurface, int, int, IntPtr>)0x4AEC60;
func(ref pThis.Ref, width, height);
pThis.Ref.BaseSurface.Vfptr = 0x7E2070;
pThis.Ref.BaseSurface.LockLevel = 0;
}
public static unsafe void Destructor(Pointer<BSurface> pThis)
{
var func = (delegate* unmanaged[Thiscall]<ref BSurface, void>)Helpers.GetVirtualFunctionPointer(pThis, 0);
func(ref pThis.Ref);
}
public void Allocate(int bytesPerPixel)
{
int bufferSize = 2 * BaseSurface.Width * BaseSurface.Height;
BaseSurface.Buffer = Marshal.AllocHGlobal(bufferSize);
BaseSurface.BufferSize = bufferSize;
BaseSurface.BytesPerPixel = bytesPerPixel;
BaseSurface.BufferAllocated = true;
}
public void Deallocate()
{
Marshal.FreeHGlobal(BaseSurface.Buffer);
BaseSurface.Buffer = Pointer<byte>.Zero;
BaseSurface.BufferSize = 0;
BaseSurface.BytesPerPixel = 0;
BaseSurface.BufferAllocated = false;
}
[FieldOffset(0)] public XSurface Base;
[FieldOffset(0)] public Surface BaseSurface;
}
}