Woofing Giraffe
Активный
- 402
- 49
Я не умею с памятью работать, можно код?
Код:
#include <windows.h>
#include <string>
#include <assert.h>
#include <process.h>
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"
SAMPFUNCS *SF = new SAMPFUNCS();
bool Status;
char newtime[28];
DWORD ThreadID;
HANDLE hThread;
void __stdcall AnotherThread(void)
{
HANDLE ProcessHandle = GetCurrentProcess();
while (true)
{
if (Status)
{
WriteProcessMemory(ProcessHandle, (LPVOID)0xB70153, newtime, 1, 0);
}
}
TerminateThread(hThread, 0);
CloseHandle(hThread);
}
void CALLBACK cmd(std::string param)
{
if (param.empty()) return;
int time;
if (!sscanf(param.c_str(), "%d", &time) || time > 23 || time < 0) return SF->getSAMP()->getChat()->AddChatMessage(0xB0B0B0, "Используй: /settime [Время (От 0 до 23)].");
sprintf(newtime, "%d", time);
Status = true;
}
void CALLBACK mainloop()
{
static bool init = false;
if (!init)
{
if (GAME == nullptr)
return;
if (GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME)
return;
if (!SF->getSAMP()->IsInitialized())
return;
SF->getSAMP()->registerChatCommand("settime", cmd);
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AnotherThread, NULL, 0, &ThreadID);
init = true;
}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
switch (dwReasonForCall)
{
case DLL_PROCESS_ATTACH:
SF->initPlugin(mainloop, hModule);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Последнее редактирование: