This repository has been archived by the owner on Jan 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processmemory.cpp
204 lines (193 loc) · 3.67 KB
/
processmemory.cpp
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
#include "processmemory.h"
#include "engine.h"
int _memCurrent;
void WriteMem(DWORD dwOffset, DWORD dwValue, int len){
unsigned long Protection;
VirtualProtect((void*)dwOffset, 1, PAGE_READWRITE, &Protection);
memcpy((void*)dwOffset, (const void*)dwValue, len);
VirtualProtect((void*)dwOffset, 1, Protection, 0);
}
BYTE Read(DWORD address, int length){ //this is completeyl broken
LPVOID buffer = LPVOID(length - 1);
LPCVOID adr = LPCVOID(address);
int _read = 0;
int _read2 = 0;
int _Position;
ReadProcessMemory(GetCurrentProcess(), adr, buffer, length, (SIZE_T *)_read2);
_read = _read2;
_Position = (int)address + _read;
return (BYTE)buffer;
}
std::string ReadCharArray(DWORD Address, int length){
//BYTE data = Read(Address, length);
char value[512] = {0};
int count = 0;
while ( count < length ){
if ( *(BYTE*)Address == 0x00) {
length = count;
} else {
value[count] = *(CHAR*)Address;
Address ++;
count++;
}
}
std::string ret(value);
return ret;
}
void WriteCharArray(DWORD Address, char * string, bool ZeroTheEnd){
DWORD AddressBkp = Address;
int max_length = 1024;
int pos = 0;
while ( pos < max_length ){
if(string[pos] == 0x00){
break;
}
*(char*)Address = string[pos];
Address++;
pos++;
}
if ( ZeroTheEnd ){
Address++;
*(char*)Address = 0x00; //this didnt work
}
}
//enums
void memOpen(int ptr){
_memStack stack;
stack.push(_memCurrent);
memSetPtr(memGetInt(ptr));
}
void memClose(){
//TODO: THIS NEEDS A TRY STATEMENT TO AVOID CRASHES
_memStack stack;
_memCurrent = stack.pop();
}
//server
void WRITE_BYTE(int value){
DWORD func = ADR_WRITE_BYTE;
__asm {
push value
call func
add esp,4
}
}
void WRITE_SHORT(int value){
DWORD func = ADR_WRITE_SHORT;
__asm {
push value
call func
add esp,4
}
}
void WRITE_LONG(int value){
DWORD func = ADR_WRITE_LONG;
__asm {
push value
call func
add esp,4
}
}
void WRITE_CHAR(int value){
DWORD func = ADR_WRITE_CHAR;
__asm {
push value
call func
add esp,4
}
}
void WRITE_COORD(float value){
DWORD func = ADR_WRITE_COORD;
__asm {
push value
call func
add esp,4
}
}
void WRITE_ANGLE(Vector value){
DWORD func = ADR_WRITE_ANGLE;
__asm {
push value
call func
add esp,4
}
}
void WRITE_STRING(char *value){
DWORD func = ADR_WRITE_STRING;
__asm {
push value
call func
add esp,4
}
}
void WRITE_ENTITY(int value){
DWORD func = ADR_WRITE_ENTITY;
__asm {
push value
call func
add esp,4
}
}
void MESSAGE_BEGIN(int edictptr, int unknown, int msgtype, int towho){
DWORD func = ADR_MESSAGE_BEGIN;
__asm {
push edictptr
push unknown
push msgtype
push towho
call func
add esp,0x10
}
}
/*
int UserMessageBegin(int edictptr, int broadcast, int unknown2, char* msgtype) {
DWORD func = ADR_USERMESSAGEBEGIN;
DWORD ret;
__asm {
push edictptr
push broadcast
push unknown2
push msgtype
call func
add esp, 0x10
mov ret, eax;
}
return (int)ret;
}
*/
int UserMessageBegin(int towho, char* msgtype) {
DWORD func = ADR_USERMESSAGEBEGIN; //this is supposed to be usermessagebegin
DWORD ret;
__asm {
push towho //msg_broadcast, msg_one, etc
push msgtype //SayText
call func
mov ret, eax;
add esp,0x8
}
return (int)ret;
}
void MESSAGE_END(){
DWORD func = ADR_MESSAGE_END;
__asm {
call func
}
}
unsigned short FixedUnsigned16( float value, float scale )
{
int output;
output = value * scale;
if ( output < 0 )
output = 0;
if ( output > 0xFFFF )
output = 0xFFFF;
return (unsigned short)output;
}
short FixedSigned16(float value, float scale)
{
int output = (int)(value * scale);
if (output > 32767)
output = 32767;
else if (output < -32768)
output = -32768;
return (short)output;
}