/
General.cs
160 lines (140 loc) · 3.34 KB
/
General.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
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using GTA_Vice_City_kodai;
using MouseKeyboardLibrary;
class General {
public static Main MainForm;
public static readonly uint VC_BASE = 0x400000;
public static uint VCMP_BASE;
public const float PI = (float)Math.PI;
public const float HALF_PI = PI / 2;
internal static bool ByteCmp(byte[] In, byte[] Cmp) {
if (In.Length != Cmp.Length)
return false;
for (int x = 0; x < In.Length; x++) {
if (In[x] != Cmp[x]) {
return false;
}
}
return true;
}
public static void PromptWrite(string str) {
str = str + '\0';
Mem.WriteStringUnicode(ADDRESSES.TEXT1_ADDR, str);
Thread.Sleep(10);
Mem.WriteStringUnicode(ADDRESSES.TEXT2_ADDR, str);
}
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern short VkKeyScan(char ch);
public static Keys toKey(char ch) {
short vkey = VkKeyScan(ch);
var retval = (Keys)(vkey & 0xff);
int modifiers = vkey >> 8;
if ((modifiers & 1) != 0)
retval |= Keys.Shift;
if ((modifiers & 2) != 0)
retval |= Keys.Control;
if ((modifiers & 4) != 0)
retval |= Keys.Alt;
return retval;
}
public static void KeyPress(string keys) {
KeyEngine.KeyTimeout.Reset();
KeyEngine.DiscardKeys = true;
{
char[] chrs = keys.ToCharArray();
for (int x = 0; x < chrs.Length; x++) {
KeyboardSimulator.KeyPress(toKey(chrs[x]));
}
}
KeyEngine.KeyTimeout.Start();
KeyEngine.DiscardKeys = false;
}
}
class Vec3 {
private float[] vec;
public float X {
get { return vec[0]; }
set { vec[0] = value; }
}
public float Y {
get { return vec[1]; }
set { vec[1] = value; }
}
public float Z {
get { return vec[2]; }
set { vec[2] = value; }
}
public Vec3(float X, float Y, float Z) {
vec = new float[3];
this.X = X;
this.Y = Y;
this.Z = Z;
}
public Vec3() {
vec = new float[3];
X = 0.0f;
Y = 0.0f;
Z = 0.0f;
}
public Vec3(IntPtr Memory) {
vec = new float[3];
X = Mem.ReadFloat(Memory);
Y = Mem.ReadFloat((IntPtr)(Memory.ToInt32() + sizeof(float)));
Z = Mem.ReadFloat((IntPtr)(Memory.ToInt32() + (sizeof(float) * 2)));
}
public static Vec3 operator +(Vec3 a, Vec3 b) {
Vec3 ret = new Vec3();
ret.X = a.X + b.X;
ret.Y = a.Y + b.Y;
ret.Z = a.Z + b.Z;
return ret;
}
public static Vec3 operator -(Vec3 a, Vec3 b) {
Vec3 ret = new Vec3();
ret.X = a.X - b.X;
ret.Y = a.Y - b.Y;
ret.Z = a.Z - b.Z;
return ret;
}
public static Vec3 operator *(Vec3 a, Vec3 b) {
Vec3 ret = new Vec3();
ret.X = a.X * b.X;
ret.Y = a.Y * b.Y;
ret.Z = a.Z * b.Z;
return ret;
}
public static Vec3 operator *(Vec3 a, float b) {
Vec3 ret = new Vec3();
ret.X = a.X * b;
ret.Y = a.Y * b;
ret.Z = a.Z * b;
return ret;
}
public static Vec3 operator /(Vec3 a, Vec3 b) {
Vec3 ret = new Vec3();
ret.X = a.X / b.X;
ret.Y = a.Y / b.Y;
ret.Z = a.Z / b.Z;
return ret;
}
public float Length() {
return (float)Math.Sqrt((X * X) + (Y * Y) + (Z * Z));
}
public void Normalize() {
float len = Length();
X /= len;
Y /= len;
Z /= len;
}
public static float VecToAngle2D(float X, float Y) {
return (float)Math.Atan2(Y, X);
}
public void MemWrite(IntPtr Memory) {
Mem.WriteFloat(Memory, X);
Mem.WriteFloat((IntPtr)(Memory.ToInt32() + sizeof(float)), Y);
Mem.WriteFloat((IntPtr)(Memory.ToInt32() + (sizeof(float) * 2)), Z);
}
}