#include <windows.h>
#include <assert.h>
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"
#pragma comment(lib, "User32.lib")
SAMPFUNCS *SF = new SAMPFUNCS();
char* AddChar(char * sourse, const char mustAdd) {
static int sizeSource, i;
static char * newCH;
sizeSource = strlen(sourse);
newCH = new char[sizeSource + 2];
if (sourse != nullptr) for (i = 0; i < sizeSource; i++) newCH[i] = sourse[i];
newCH[sizeSource] = mustAdd;
newCH[sizeSource + 1] = '\0';
delete[] sourse;
return newCH;
}
char ** AddNewStr(char ** source, int &size, const char * toAdd) {
static char ** newSCH, *ss;
static int i;
newSCH = new char*[size + 1];
ss = new char[strlen(toAdd) + 1];
strcpy_s(ss, strlen(toAdd) + 1, toAdd);
for (i = 0; i < size; i++) newSCH[i] = source[i];
newSCH[size] = ss;
delete[] source;
size++;
return newSCH;
}
char** split(const std::string &str, const char mustFind, int &size) {
static char **mezdu;
static unsigned int i, sz;
mezdu = nullptr;
size = 0;
sz = str.size();
i = 0;
while (i < sz) {
if (i + 1 < sz && str[i] == mustFind && str[i + 1] != mustFind || size == 0) mezdu = AddNewStr(mezdu, size, "");
if (mustFind != str[i]) mezdu[size - 1] = AddChar(mezdu[size - 1], str[i]);
i++;
}
return mezdu;
}
struct Resourse {
private:
unsigned int countMined;
char * name;
char * isThisRes;
char * output;
public:
Resourse(const char * name, const char * isThisRes, const char * output) {
this->name = new char[strlen(name) + 1];
this->isThisRes = new char[strlen(isThisRes) + 1];
this->output = new char[strlen(output) + 1];
strcpy(this->name, name);
strcpy(this->isThisRes, isThisRes);
strcpy(this->output, output);
countMined = 0;
}
const char* GetIsThisRes() const {
return isThisRes;
}
const char* GetOutput() const {
return output;
}
void ResetCounter() {
countMined = 0;
}
const unsigned int& GetCounter() const {
return countMined;
}
void IncCounter() {
countMined++;
}
const char* PrintCount() {
static char T[256];
sprintf(T, "{87CEFA}%s: {FFFFFF}%u{FFFFFF}", name, countMined);
return T;
}
~Resourse() {
delete[] name;
delete[] isThisRes;
delete[] output;
}
};
class ResAuto {
private:
BYTE state;
unsigned short curTimeout;
unsigned short ramki[2];
unsigned long long timer;
/*bool freeze;
HKEY key;
DWORD val;*/
/*bool RegReadFreeze()
{
if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\SAMPFUNCS\\ResAuto", 0, KEY_ALL_ACCESS, &key) == ERROR_SUCCESS) {
static DWORD type = REG_DWORD, size = 4;
val = 0;
RegQueryValueExA(key, "Freeze", NULL, &type, (byte *)&val, &size);
RegCloseKey(key);
return val != 0;
}
else return false;
}*/
/*void RegWriteState()
{
if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\SAMPFUNCS\\ResAuto", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS) {
val = freeze;
RegSetValueExA(key, "Freeze", 0, REG_DWORD, (byte *)&val, 1);
RegCloseKey(key);
}
}*/
unsigned short RandomTimeout(const unsigned short &start, const unsigned short &stop) {
if (start != stop) return start + rand() % (stop - start);
else return stop;
}
void RefreshTimeOut() {
curTimeout = RandomTimeout(ramki[0], ramki[1]);
SF->getSAMP()->setSendRate(eSendrateType::ONFOOTSENDRATE, curTimeout);
}
public:
enum {
countRes = 5
};
stLocalPlayer **a_info;
Resourse *mnr[countRes];
ResAuto(stLocalPlayer **a_info) {
timer = state = 0;
//freeze = RegReadFreeze();
this->a_info = a_info;
curTimeout = ramki[0] = ramki[1] = 1;
mnr[0] = new Resourse("Stone", "stone", "stone = %u");
mnr[1] = new Resourse("Bronze", "bronze", "bronze = %u");
mnr[2] = new Resourse("Metal", "metal", "metal = %u");
mnr[3] = new Resourse("Silver", "silver", "silver = %u");
mnr[4] = new Resourse("Gold", "gold", "gold = %u");
}
void SetState(const BYTE &state_) {
/*if (freeze) {
if (state < 2 && state_ == 2)
a_info->pSAMP_Actor->pGTA_Ped->flags |= 0x10;
else if (state_ < 2 && state == 2)
a_info->pSAMP_Actor->pGTA_Ped->flags &= ~0x10;
}*/
if (state_ == 1) RefreshTimeOut();
else if (state_ == 0) SF->getSAMP()->setSendRate(eSendrateType::ONFOOTSENDRATE, 50);
//SF->getSAMP()->getChat()->AddChatMessage(-1, "state %hu", (unsigned short)state_);
state = state_;
}
BYTE GetState() const {
return state;
}
/*const bool& GetFreeze() const {
return freeze;
}*/
/*void SetFreeze(const bool &freeze) {
this->freeze = freeze;
RegWriteState();
}*/
void ToggleState(std::string params = "") {
if (state == 0) {
if (params.size() > 0) {
static char ** results;
static int size;
results = split(params, ' ', size);
if (size > 0) {
ramki[0] = atoi(results[0]);
if (ramki[0] < 1 || ramki[0] > 10000) ramki[0] = 1;
if (size > 1) {
ramki[1] = atoi(results[1]);
if (ramki[1] < ramki[0] || ramki[1] > 10000) ramki[1] = ramki[0];
}
else ramki[1] = ramki[0];
}
else {
ramki[0] = 1;
ramki[1] = 1;
}
delete[] results;
}
else {
ramki[0] = 1;
ramki[1] = 1;
}
}
SF->getCLEO()->callOpcode("0ACD: \"~y~ResAuto: %s~n~~g~Timeout: ~y~%hu ~w~- ~y~%hu\" 2000", (state > 0 ? false : true) ? "~g~ON" : "~r~OFF", ramki[0], ramki[1]);
SetState(state > 0 ? 0 : 1);
}
bool IsOkGo() const {
if ((*a_info) != nullptr &&
(*a_info)->pSAMP_Actor != nullptr &&
(*a_info)->pSAMP_Actor->pGTA_Ped != nullptr) {
static unsigned long long timer = 0;
static unsigned int goIs = (*a_info)->pSAMP_Actor->pGTA_Ped->state;
//SF->getSAMP()->getChat()->AddChatMessage(-1, "%u %u", goIs, (*a_info)->pSAMP_Actor->pGTA_Ped->state);
if (goIs != (*a_info)->pSAMP_Actor->pGTA_Ped->state) {
if ((*a_info)->pSAMP_Actor->pGTA_Ped->state == 1) timer = GetTickCount();
goIs = (*a_info)->pSAMP_Actor->pGTA_Ped->state;
}
return timer + 300 < GetTickCount() && goIs == 1;
}
return false;
};
void ResetCounters() {
static size_t i;
for (i = 0; i < countRes; i++)
mnr[i]->ResetCounter();
}
void GetResoures() {
static char T[256];
static size_t i;
T[0] = '\0';
for (i = 0; i < countRes; i++)
{
strcat(T, mnr[i]->PrintCount());
if (i != countRes - 1) {
if (strlen(T) + strlen(mnr[i + 1]->PrintCount()) > 128) {
SF->getSAMP()->getChat()->AddChatMessage(-1, T);
T[0] = '\0';
}
else strcat(T, " | ");
}
}
SF->getSAMP()->getChat()->AddChatMessage(-1, T);
}
const unsigned short * GetRamki() const {
return ramki;
}
void mainloop() {
if (state > 0) {
if (!(GetKeyState(VK_ADD) & 0x8000)) {
if (timer + curTimeout < GetTickCount())
{
if (IsOkGo() &&
state < 2 &&
(*a_info)->onFootData.fMoveSpeed[0] == 0 &&
(*a_info)->onFootData.fMoveSpeed[1] == 0) {
static BitStream bsOnfootSync;
static stOnFootData ofSync;
memset(&ofSync, 0, sizeof(stOnFootData));
ofSync = (*a_info)->onFootData;
ofSync.sKeys = rand() % 4 > 0 ? 8 : 0;
bsOnfootSync.ResetWritePointer();
bsOnfootSync.Write((BYTE)ID_PLAYER_SYNC);
bsOnfootSync.Write((PCHAR)&ofSync, sizeof(stOnFootData));
SF->getRakNet()->SendPacket(&bsOnfootSync);
//SF->getSAMP()->getChat()->AddChatMessage(-1, "puss 1");
}
timer = GetTickCount();
}
}
else ToggleState();
}
}
~ResAuto() {
SetState(0);
for (size_t i = 0; i < countRes; i++)
if (mnr[i] != nullptr) delete mnr[i];
}
};
ResAuto *plugin = nullptr;
void CALLBACK EnableBot(std::string params) {
plugin->ToggleState(params);
}
void CALLBACK GetCout(std::string params) {
plugin->GetResoures();
}
void CALLBACK ResetCout(std::string params) {
plugin->ResetCounters();
plugin->GetResoures();
}
//void CALLBACK Freeze(std::string params) {
// plugin->SetFreeze(!plugin->GetFreeze());
// SF->getCLEO()->callOpcode("0ACD: \"~y~ResAuto~g~[~w~FREEZE~g~]~w~: %s\" 2000", plugin->GetFreeze() ? "~g~ON" : "~r~OFF");
//}
bool CALLBACK OnSetAnim(stRakNetHookParams *params) {
// BASEBALL // Bat_4 // CARRY
// BOMBER // BOM_Plant_Loop // CARRY
if (plugin->GetState() > 0) {
static char temp[256];
static short actID;
static BYTE tempLen;
if (params->packetId == ScriptRPCEnumeration::RPC_ScrApplyAnimation) {
params->bitStream->ResetReadPointer();
params->bitStream->Read(actID);
if (actID == SF->getSAMP()->getPlayers()->sLocalPlayerID) {
params->bitStream->Read(tempLen);
params->bitStream->Read(temp, tempLen);
temp[tempLen] = '\0';
if (plugin->GetState() == 1 && !strcmp(temp, "BASEBALL")) {
params->bitStream->Read(tempLen);
params->bitStream->Read(temp, tempLen);
temp[tempLen] = '\0';
if (!strcmp(temp, "Bat_4")) plugin->SetState(2);
}
else if (plugin->GetState() == 2 && !strcmp(temp, "CARRY")) plugin->SetState(1);
}
}
else if (params->packetId == ScriptRPCEnumeration::RPC_ScrDisplayGameText) {
static int style, time;
params->bitStream->ResetReadPointer();
params->bitStream->Read(style);
if (style == 1) {
params->bitStream->Read(time);
params->bitStream->Read(style);
params->bitStream->Read(temp, style);
temp[style] = '\0';
for (actID = 0; actID < ResAuto::countRes; actID++)
{
if (strstr(temp, plugin->mnr[actID]->GetIsThisRes())) {
plugin->mnr[actID]->IncCounter();
sprintf(temp, plugin->mnr[actID]->GetOutput(), plugin->mnr[actID]->GetCounter());
params->bitStream->ResetWritePointer();
params->bitStream->Write(4);
params->bitStream->Write(time + 3000);
params->bitStream->Write(int(strlen(temp)));
params->bitStream->Write(temp, strlen(temp));
if (plugin->GetState() == 2) plugin->SetState(1);
break;
}
}
}
}
}
return true;
}
bool CALLBACK OnPlayyerZbor(stRakNetHookParams *params) {
if (plugin->GetState() > 0 && plugin->IsOkGo() && params->packetId == ID_PLAYER_SYNC) {
static stOnFootData ofSync;
params->bitStream->ResetReadPointer();
params->bitStream->SetReadOffset(8);
params->bitStream->Read((PCHAR)&ofSync, sizeof(stOnFootData));
if (ofSync.sKeys == 8 || ofSync.sKeys == 0) ofSync.sKeys = plugin->GetState() > 1 || rand() % 4 > 0 ? 8 : 0;
params->bitStream->ResetWritePointer();
params->bitStream->Write((BYTE)ID_PLAYER_SYNC);
params->bitStream->Write((PCHAR)&ofSync, sizeof(stOnFootData));
/* params->bitStream->ResetWritePointer();
params->bitStream->Write((BYTE)ID_PLAYER_SYNC);
params->bitStream->Write((PCHAR)&ofSync, sizeof(stOnFootData));*/
//SF->getSAMP()->getChat()->AddChatMessage(-1, "puss");
/*static unsigned long long tmr = GetTickCount();
static unsigned short count = 0;
count++;
if (tmr + 1000 < GetTickCount()) {
SF->getSAMP()->getChat()->AddChatMessage(-1, "%hu", count);
count = 0;
tmr = GetTickCount();
}*/
}
return true;
}
void CALLBACK Destructor() {
if (plugin != nullptr) delete plugin;
}
void CALLBACK mainloop(void)
{
if (plugin == nullptr)
{
if (GAME == nullptr || GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME || SF->getSAMP() == nullptr || !SF->getSAMP()->IsInitialized()) return;
plugin = new ResAuto(&SF->getSAMP()->getPlayers()->pLocalPlayer);
SF->getGame()->registerGameDestructorCallback(Destructor);
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_INCOMING_RPC, OnSetAnim);
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_OUTCOMING_PACKET, OnPlayyerZbor);
SF->getSAMP()->registerChatCommand("mine", EnableBot);
SF->getSAMP()->registerChatCommand("rudres", ResetCout);
SF->getSAMP()->registerChatCommand("grud", GetCout);
SF->LogConsole("[{87CEFA}ResAuto{FFFFFF} by {87CEFA}Stiopko {FFFFFF}]{87CEFA}: {FFFFFF}loaded{87CEFA}!");
}
else plugin->mainloop();
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
if (dwReasonForCall == DLL_PROCESS_ATTACH) SF->initPlugin(mainloop, hModule);
return TRUE;
}