SF API | DATE&TIME SOURCE

  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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include <windows.h>
#include <string>
#include <assert.h>
#include "CSAMPFUNCS.h"
#include <time.h>
#include <stdio.h>
CSAMPFUNCS *SF = new CSAMPFUNCS();
stFontInfo *pFont = nullptr;
int coordX;
int coordY;
int textColor;
int fontFlags;
int fontSize;
bool rState = true;
std::string fontName;
bool ini_file_exist(std::string ini_file_name)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFindIni;
hFindIni = FindFirstFile(ini_file_name.c_str(), &FindFileData);
if (hFindIni != INVALID_HANDLE_VALUE)
{
return true;
}
return false;
}
std::string get_path(std::string &path, std::string &ini_file_name)
{
char ppath[MAX_PATH];
GetCurrentDirectory(MAX_PATH, ppath);
strcat(ppath, "\\");
path = ppath + ini_file_name;
return path;
}
bool create_ini_file(std::string new_ini_file_name)
{
if (!ini_file_exist(new_ini_file_name))
{
FILE *fp = fopen(new_ini_file_name.c_str(), "w");
if (fp != NULL)
fclose(fp);
return true;
}
return false;
}
bool delete_ini_file(std::string ini_file_name)
{
if (!ini_file_exist(ini_file_name)) return true;
return remove(ini_file_name.c_str());
}
int get_int_from_ini(std::string ini_file_name, std::string section, std::string key)
{
if (!ini_file_exist(ini_file_name)) return 0x80000000;
std::string ini_path;
get_path(ini_path, ini_file_name);
return GetPrivateProfileInt(section.c_str(), key.c_str(), 0, ini_path.c_str());
}
float get_float_from_ini(std::string ini_file_name, std::string section, std::string key)
{
if (!ini_file_exist(ini_file_name)) return 0.0f;
char str_value[100];
std::string ini_path;
get_path(ini_path, ini_file_name);
if (GetPrivateProfileString(section.c_str(), key.c_str(), NULL, str_value, sizeof(str_value), ini_path.c_str()))
return std::stof(str_value);
return 0.0f;
}
std::string get_string_from_ini(std::string ini_file_name, std::string section, std::string key)
{
if (!ini_file_exist(ini_file_name)) return " ";
char buff[1024];
std::string ini_path;
get_path(ini_path, ini_file_name);
if (GetPrivateProfileString(section.c_str(), key.c_str(), NULL, buff, sizeof(buff), ini_path.c_str()))
return buff;
return " ";
}
void set_int_to_ini(std::string ini_file_name, std::string section, std::string key, DWORD value)
{
if (!ini_file_exist(ini_file_name)) return;
std::string ini_path;
std::string str_value = std::to_string(value);
get_path(ini_path, ini_file_name);
WritePrivateProfileString(section.c_str(), key.c_str(), str_value.c_str(), ini_path.c_str());
}
void set_float_to_ini(std::string ini_file_name, std::string section, std::string key, float value)
{
if (!ini_file_exist(ini_file_name)) return;
std::string ini_path;
std::string str_value = std::to_string(value);
get_path(ini_path, ini_file_name);
WritePrivateProfileString(section.c_str(), key.c_str(), str_value.c_str(), ini_path.c_str());
}
void set_string_to_ini(std::string ini_file_name, std::string section, std::string key, std::string text)
{
if (!ini_file_exist(ini_file_name)) return;
std::string ini_path;
get_path(ini_path, ini_file_name);
WritePrivateProfileString(section.c_str(), key.c_str(), text.c_str(), ini_path.c_str());
}
void _stdcall cmd_datetime_set(std::string param)
{
if (param.empty())
{
SF->getSAMP()->getChat()->AddChatMessage(0xFFCC00, "[BLASTHACK]: {EAEAEA}Допустимые параметры: {FFCC00}color | posx | posy | font | flags | size" );
return;
};
if (param.find("color") != std::string::npos)
{
param.erase(0, 6);
sscanf(param.c_str(), "%x", &textColor);
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "COLOR", textColor);
};
if (param.find("posx") != std::string::npos)
{
param.erase(0, 5);
sscanf(param.c_str(), "%d", &coordX);
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "POSITION", "POSX", coordX);
};
if (param.find("posy") != std::string::npos)
{
param.erase(0, 5);
sscanf(param.c_str(), "%d", &coordY);
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "POSITION", "POSY", coordY);
};
if (param.find("font") != std::string::npos)
{
param.erase(0, 5);
fontName = param;
set_string_to_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "NAME", fontName.c_str());
SF->getRender()->ReleaseFont(pFont);
int fontFlags = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "FLAGS");
char fontNameBuf[64];
sprintf(fontNameBuf, "%s", fontName.c_str());
pFont = SF->getRender()->CreateNewFont(fontNameBuf, 8, fontFlags);
};
if (param.find("flags") != std::string::npos)
{
param.erase(0, 6);
sscanf(param.c_str(), "%d", &fontFlags);
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "FLAGS", fontFlags);
SF->getRender()->ReleaseFont(pFont);
std::string fontName = get_string_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "NAME");
int fontSize = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "Size");
int fontFlags = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "FLAGS");
char fontNameBuf[64];
sprintf(fontNameBuf, "%s", fontName.c_str());
pFont = SF->getRender()->CreateNewFont(fontNameBuf, 8, fontFlags);
};
if (param.find("size") != std::string::npos)
{
param.erase(0, 5);
sscanf(param.c_str(), "%d", &fontSize);
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "SIZE", fontSize);
SF->getRender()->ReleaseFont(pFont);
std::string fontName = get_string_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "NAME");
int fontSize = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "Size");
int fontFlags = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "FLAGS");
char fontNameBuf[64];
sprintf(fontNameBuf, "%s", fontName.c_str());
pFont = SF->getRender()->CreateNewFont(fontNameBuf, fontSize, fontFlags);
};
//iState ^= true;
};
bool CALLBACK Present(CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride,
CONST RGNDATA *pDirtyRegion)
{
if (SUCCEEDED(SF->getRender()->BeginRender()) && rState == true) // если девайс готов к рисованию
{
// рисуем
SYSTEMTIME time;
textColor = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "COLOR");
coordX = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "POSITION", "POSX");
coordY = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "POSITION", "POSY");
GetLocalTime(&time);
char buf[128];
sprintf(buf, "[%d.%d.%d %.2d:%.2d:%.2d]", time.wDay, time.wMonth, time.wYear, time.wHour, time.wMinute, time.wSecond);
pFont->Print(buf, textColor, coordX, coordY, false);
SF->getRender()->EndRender(); // завершаем рисование
};
return true; // возвращаем положительный результат
};
void CALLBACK mainloop( void )
{
static bool init = false;
if( !init )
{
if( !SF->getSAMP()->IsInitialized() )
return;
SF->getSAMP()->getChat()->AddChatMessage(0xFFCC00, "[BLASTHACK] {EAEAEA}Date&Time plugin loaded // by hnnssy.");
SF->getSAMP()->registerChatCommand("dtset", cmd_datetime_set);
bool configExist = ini_file_exist("SAMPFUNCS\\Date&Time.ini");
if (configExist == 0)
{
create_ini_file("SAMPFUNCS\\Date&Time.ini");
set_string_to_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "NAME", "Comic Sans MS");
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "FLAGS", 5);
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "COLOR", 0xFFFFCC00);
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "SIZE", 8);
//SF->getGame()->convertGameCoordsToWindow(20.0, 160.0, &coordX, &coordY);
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "POSITION", "POSX", 0);
set_int_to_ini("SAMPFUNCS\\Date&Time.ini", "POSITION", "POSY", 0);
}
std::string fontName = get_string_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "NAME");
int fontFlags = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "FLAGS");
int fontSize = get_int_from_ini("SAMPFUNCS\\Date&Time.ini", "FONT", "SIZE");
char fontNameBuf[64];
sprintf(fontNameBuf, "%s", fontName.c_str());
pFont = SF->getRender()->CreateNewFont(fontNameBuf, fontSize, fontFlags);
SF->getRender()->registerD3DCallback(eDirect3DDeviceMethods::D3DMETHOD_PRESENT, Present);
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;
}