-
Notifications
You must be signed in to change notification settings - Fork 1
/
HookHandle.cs
307 lines (259 loc) · 9.09 KB
/
HookHandle.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#region Copyright(c) 2006 ZO, All right reserved.
// -----------------------------------------------------------------------------
// Copyright(c) 2006 ZO, All right reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistribution of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistribution in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. The name of the author may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -----------------------------------------------------------------------------
#endregion
#region Using directives
using System;
using System.Globalization;
using System.Runtime.InteropServices;
#endregion
namespace ZO.SmartCore.Interop.Windows
{
/// <summary>
/// Represent a Handle to a hook.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct HookHandle
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="HookHandle"/> class.
/// </summary>
/// <param name="value">The value.</param>
public HookHandle(int value)
{
this._Hook = new IntPtr(value);
}
/// <summary>
/// Initializes a new instance of the <see cref="HookHandle"/> class.
/// </summary>
/// <param name="value">The value.</param>
public HookHandle(IntPtr value)
{
this._Hook = value;
}
#endregion
#region Destructor
#endregion
#region Fields
private IntPtr _Hook;
#endregion
#region Events
#endregion
#region Operators
/// <summary>
/// Operator ==s the specified hook1.
/// </summary>
/// <param name="hook1">The hook1.</param>
/// <param name="hook2">The hook2.</param>
/// <returns></returns>
public static bool operator ==(HookHandle hook1, HookHandle hook2)
{
if (!hook1.IsEmpty)
{
return hook1.Equals(hook2);
}
return (hook2.IsEmpty);
}
/// <summary>
/// Operator ==s the specified hook.
/// </summary>
/// <param name="hook">The hook.</param>
/// <param name="ptrHook">The PTR hook.</param>
/// <returns></returns>
public static bool operator ==(HookHandle hook, IntPtr ptrHook)
{
if (!hook.IsEmpty)
{
return hook.Equals(ptrHook);
}
return (ptrHook == IntPtr.Zero);
}
/// <summary>
/// Operator ==s the specified PTR hook.
/// </summary>
/// <param name="ptrHook">The PTR hook.</param>
/// <param name="hook">The hook.</param>
/// <returns></returns>
public static bool operator ==(IntPtr ptrHook, HookHandle hook)
{
if (ptrHook != IntPtr.Zero)
{
return hook.Equals(ptrHook);
}
return (hook.IsEmpty);
}
/// <summary>
/// Implicit operators the specified hook.
/// </summary>
/// <param name="hook">The hook.</param>
/// <returns></returns>
public static implicit operator IntPtr(HookHandle hook)
{
return hook.Handle;
}
/// <summary>
/// Implicit operators the specified PTR hook.
/// </summary>
/// <param name="ptrHook">The PTR hook.</param>
/// <returns></returns>
public static implicit operator HookHandle(IntPtr ptrHook)
{
return new HookHandle(ptrHook);
}
/// <summary>
/// Operator !=s the specified hook1.
/// </summary>
/// <param name="hook1">The hook1.</param>
/// <param name="hook2">The hook2.</param>
/// <returns></returns>
public static bool operator !=(HookHandle hook1, HookHandle hook2)
{
return !(hook1 == hook2);
}
/// <summary>
/// Operator !=s the specified hook.
/// </summary>
/// <param name="hook">The hook.</param>
/// <param name="ptrHook">The PTR hook.</param>
/// <returns></returns>
public static bool operator !=(HookHandle hook, IntPtr ptrHook)
{
return !(hook == ptrHook);
}
/// <summary>
/// Operator !=s the specified PTR hook.
/// </summary>
/// <param name="ptrHook">The PTR hook.</param>
/// <param name="hook">The hook.</param>
/// <returns></returns>
public static bool operator !=(IntPtr ptrHook, HookHandle hook)
{
return !(ptrHook == hook);
}
#endregion
#region Properties
/// <summary>
/// Represents the empty Hook. This field is read-only.
/// </summary>
public static readonly HookHandle Empty = new HookHandle(0);
/// <summary>
/// Gets the handle.
/// </summary>
/// <value>The handle.</value>
public IntPtr Handle
{
get
{
return this._Hook;
}
}
/// <summary>
/// Gets a value indicating whether this instance is empty.
/// </summary>
/// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
public bool IsEmpty
{
get
{
return (this._Hook == IntPtr.Zero);
}
}
#endregion
#region Methods
/// <summary>
/// Equalses the specified hook.
/// </summary>
/// <param name="hook">The hook.</param>
/// <returns></returns>
public bool Equals(HookHandle hook)
{
if (this._Hook.Equals(hook._Hook))
{
return true;
}
return false;
}
/// <summary>
/// Equalses the specified PTR hook.
/// </summary>
/// <param name="ptrHook">The PTR hook.</param>
/// <returns></returns>
public bool Equals(IntPtr ptrHook)
{
if (this._Hook.Equals(ptrHook))
{
return true;
}
return false;
}
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
/// <param name="obj">Another object to compare to.</param>
/// <returns>
/// true if obj and this instance are the same type and represent the same value; otherwise, false.
/// </returns>
public override bool Equals(object obj)
{
if (obj != null)
{
if (obj is HookHandle)
{
return this.Equals((HookHandle)obj);
}
if (!(obj is IntPtr))
{
return false;
}
return this.Equals((IntPtr)obj);
}
return false;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
public override int GetHashCode()
{
return this._Hook.GetHashCode();
}
/// <summary>
/// Returns the fully qualified type name of this instance.
/// </summary>
/// <returns>
/// A <see cref="T:System.String"></see> containing a fully qualified type name.
/// </returns>
public override string ToString()
{
int num1 = this._Hook.ToInt32();
return ("{Handle=0x" + num1.ToString("X8", CultureInfo.CurrentCulture) + "}");
}
#endregion
}
}