Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <cstdlib>
- #include <cstdio>
- #include <cstring>
- #include "pstools.h"
- #define BAUD_RATE 9600
- using namespace std;
- class NFSUG2
- {
- ProcessTools ps;
- HANDLE hProc;
- string exeName = "SPEED2.EXE";
- static const int moneyAddr = 0x461e74;
- static const int speedAddr = 0x3f09e8;
- int baseAddr = 0;
- int money = 0;
- float speed = 0.0;
- public:
- NFSUG2()
- {
- hProc = ps.OpenProcess(exeName.c_str(), PROCESS_ALL_ACCESS);
- baseAddr = ps.GetProcessBaseAddress(ps.GetProcessId(exeName.c_str()));
- }
- void PrintInfo()
- {
- cout << "hProc: " << hex << hProc << endl;
- cout << "baseAddres: 0x" << hex << baseAddr << endl;
- }
- int ReadMoney()
- {
- ReadProcessMemory(hProc, (LPVOID)(baseAddr + moneyAddr), &money, sizeof(int), NULL);
- return money;
- }
- float ReadSpeed()
- {
- ReadProcessMemory(hProc, (LPVOID)(baseAddr + speedAddr), &speed, sizeof(float), NULL);
- return speed;
- }
- };
- class SerialPort
- {
- DCB dcbControl;
- HANDLE hPortHandle = NULL;
- char lpReadBuffer[256] = {0};
- char lpWriteBuffer[256] = {0};
- DWORD dwBaudRate = 9600;
- private:
- public:
- bool OpenPort(char* lpPortName, DWORD dwAttr)
- {
- hPortHandle = CreateFile(lpPortName, dwAttr, 0, NULL,
- OPEN_EXISTING, 0, NULL);
- if(!hPortHandle)
- {
- cerr << "Couldn't open port! " << lpPortName << endl;
- exit(1);
- }
- else
- {
- cout << "Port: " << lpPortName << " opened!\n";
- }
- }
- void SetupDCB()
- {
- if(!hPortHandle)
- {
- cerr << "Port not opened!\n";
- exit(1);
- }
- dcbControl.DCBlength = sizeof(dcbControl);
- dcbControl.BaudRate = BAUD_RATE;
- dcbControl.fParity = FALSE;
- dcbControl.Parity = NOPARITY;
- dcbControl.StopBits = ONESTOPBIT;
- dcbControl.ByteSize = 8;
- dcbControl.fDtrControl = DTR_CONTROL_DISABLE;
- dcbControl.fRtsControl = RTS_CONTROL_DISABLE;
- dcbControl.fOutxCtsFlow = FALSE;
- dcbControl.fOutxDsrFlow = FALSE;
- dcbControl.fDsrSensitivity = FALSE;
- dcbControl.fAbortOnError = FALSE;
- dcbControl.fOutX = FALSE;
- dcbControl.fInX = FALSE;
- dcbControl.fErrorChar = FALSE;
- dcbControl.fNull = FALSE;
- SetCommState(hPortHandle, &dcbControl);
- }
- DWORD WriteSerial(char text[256])
- {
- DWORD sent = 0;
- strcpy(lpWriteBuffer, text);
- //cout << "Write: " << text << endl;
- //cout << hPortHandle << endl;
- //cout << strlen(text);
- WriteFile(hPortHandle, text, strlen(text), &sent, 0);
- return sent;
- }
- };
- int main()
- {
- NFSUG2 nfs;
- SerialPort sp;
- sp.OpenPort("COM5", GENERIC_WRITE | GENERIC_READ);
- sp.SetupDCB();
- nfs.PrintInfo();
- char temp[256] = {0};
- string tempStr;
- int tmpMoney = 0;
- float tmpSpeed = 0;
- float tmpSpeed2 = 0;
- cout << nfs.ReadMoney() << endl;
- cout << nfs.ReadSpeed() << endl;
- for(;;Sleep(1))
- {
- //sp.WriteSerial("#");
- tmpSpeed = (nfs.ReadSpeed() * 1.6);
- if(tmpSpeed == tmpSpeed2)
- continue;
- sprintf(temp, "%d", (int)tmpSpeed);
- if(strlen(temp) == 1)
- {
- temp[2] = temp[0];
- temp[0] = ' ';
- temp[1] = ' ';
- }
- else if(strlen(temp) == 2)
- {
- temp[2] = temp[1];
- temp[1] = temp[0];
- temp[0] = ' ';
- }
- else if(strlen(temp) == 3)
- {
- }
- //tempStr = ss.str();
- //strcpy(temp, tempStr.c_str());
- cout << "BYTES: " << sp.WriteSerial(temp);
- sp.WriteSerial("#");
- cout << " Written: " << temp << endl;
- tmpSpeed2 = tmpSpeed;
- memset(temp, 0, 256);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement