Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <tlhelp32.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
BYTE *Bufor;
//---------------------------------------------------------------------------
DWORD GetSniperEliteProcessId(void)
{
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
AnsiString ProcessName;
DWORD result = -1;
hProcessSnap= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
pe32.dwSize =sizeof(PROCESSENTRY32);
Process32First(hProcessSnap,&pe32);
do
{
ProcessName = pe32.szExeFile;
if (!strcmp (ProcessName.LowerCase().c_str() ,"sniperelite.exe"))
{
result = pe32.th32ProcessID;
}
} while (Process32Next(hProcessSnap,&pe32));
CloseHandle(hProcessSnap);
return result;
}
//---------------------------------------------------------------------------
int ReadFromSE(int Adr,char* Buffer,unsigned long Len)
{
HANDLE hwnd;
DWORD SeId;
int result=false;
SeId = GetSniperEliteProcessId();
// SeId zawiera id procesu SniperElite.exe ,jesli -1 to nie uruchomiono procesu
if ((int)SeId != -1)
{
hwnd =OpenProcess(PROCESS_VM_READ,false,SeId);
if (hwnd ==NULL ) return 0;
result = ReadProcessMemory(hwnd, (LPVOID)Adr, Buffer, Len, &Len);
CloseHandle(hwnd);
}
return result;
}
//---------------------------------------------------------------------------
int WriteToSE(int Adr,char* Buffer,unsigned long Len)
{
HANDLE hwnd;
DWORD SeId;
int result=false;
SeId = GetSniperEliteProcessId();
// SeId zawiera id procesu SniperElite.exe ,jesli -1 to nie uruchomiono procesu if ((int)SeId != -1)
{
hwnd =OpenProcess(PROCESS_ALL_ACCESS,false,SeId);
if (hwnd == NULL) return 0;
result = WriteProcessMemory(hwnd, (LPVOID)Adr, Buffer, Len, &Len);
CloseHandle(hwnd);
}
return result;
}
int GetPlayerPositionMemoryPointer()
{
DWORD a,b;
if ( ReadFromSE(0x744540,(char*)&a,4)==0) return 0;
if ( ReadFromSE(0x73413c,(char*)&b,4)==0) return 0;
a--;
a&= 0x3e8;
a=(a*4)+b;
if ( ReadFromSE(a,(char*)&b,4)==0) return 0;
if ( ReadFromSE(b,(char*)&a,4)==0) return 0;
if ( ReadFromSE(a+4,(char*)&b,4)==0) return 0;
if ( ReadFromSE(b+8,(char*)&b,4)==0) return 0;
a=a+b+4;
if ( ReadFromSE(a+1x0c,(char*)&a,4)==0) return 0;
a+=8;
return a;
}
//---------------------------------------------------------------------------
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
float x,y,z;
DWORD a;
a=GetPlayerPositionMemoryPointer();
if (a != 0)
{
ReadFromSE(a,(char*)&x,4);
ReadFromSE(a+4,(char*)&y,4);
ReadFromSE(a+8,(char*)&z,4);
Edit1->Text = FloatToStr(x);
Edit2->Text = FloatToStr(y);
Edit3->Text = FloatToStr(z);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
DWORD d;
BYTE b;
WORD w;
char c;
short s;
int i;
long l;
double db;
long double ld;
int array[ 20 ];
unsigned short us;
if (!OpenDialog1->Execute()) return;
int plik=FileOpen(OpenDialog1->FileName,fmOpenRead);
if (plik==-1) return;
int iFileLength = FileSeek(plik,0,2);
FileSeek(plik,0,0);
char *Bufor = new char[iFileLength+1];
*(Bufor+iFileLength)=0;
int iBytesRead = FileRead(plik,Bufor,iFileLength);
if (iFileLength!=iBytesRead)
{delete Bufor;return;}
Edit4->Clear();
Edit5->Text= FloatToStr( *(FLOAT*)(Bufor+0x0000001c));
Edit6->Text= FloatToStr( *(FLOAT*)&Bufor[0x00000020]);
Edit4->Text= FloatToStr( *(FLOAT*)&Bufor[0x00000024]);
Edit7->Text= FloatToStr( *(FLOAT*)&Bufor[0x00000030]);
Edit8->Text= BYTE (b,&Bufor[0x0000003C]);
Edit9->Text= BYTE (b,&Bufor[0x00000040]);
delete Bufor;
FileClose(plik);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int iFileHandle;
int iFileLength;
int iBytesRead;
PAnsiChar Buffer;
if (SaveDialog1->Execute())
try
{
iFileHandle = FileOpen(SaveDialog1->FileName, fmOpenRead);
if (iFileHandle > 0) {
iFileLength = FileSeek(iFileHandle, 0, 2);
FileSeek(iFileHandle,0,0);
Buffer = new AnsiChar[iFileLength+1];
iBytesRead = FileRead(iFileHandle, Buffer, iFileLength);
FileClose(iFileHandle);
for (int i = 0; i < iBytesRead; i++)
{
float v1, v2, v3;
Edit1->Text = (String)v1;
Edit2->Text = (String)v2;
Edit3->Text = (String)v3;
v1 = StrToFloat( Edit1->Text );
v2 = StrToFloat( Edit2->Text );
v3 = StrToFloat( Edit3->Text );
}
}
}
}
try
{
}
catch (...)
{
Application->MessageBox(
L"Can't perform one of the following file operations: Open, Seek, Read, Close.",
L"File Error", IDOK);
}
//---------------------------------------------------------------------------