-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsource.cpp
More file actions
92 lines (76 loc) · 2.38 KB
/
source.cpp
File metadata and controls
92 lines (76 loc) · 2.38 KB
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
#include "plugin.h"
#include <filesystem>
#include <iostream>
#include <string>
#include <fstream>
using namespace plugin;
std::string getdate()
{
std::time_t t = std::time(nullptr);
std::tm tm{};
#ifdef _WIN32
localtime_s(&tm, &t);
#else
localtime_r(&t, &tm);
#endif
std::ostringstream oss;
oss << std::put_time(&tm, "%Y-%m-%d");
return oss.str();
}
class ChatLog
{
public:
int initialized = false;
bool IsMultiplayer()
{
return GetModuleHandleA("samp.dll") != nullptr ||
GetModuleHandleA("omp.dll") != nullptr;
}
~ChatLog()
{
if (!instance.IsMultiplayer()) return;
const char* path = R"(C:\Users\Administrator\Documents\GTA San Andreas User Files\SAMP\chatlog.txt)";
if (std::filesystem::exists(path))
{
std::string hoje = getdate();
std::ifstream chatlog(path);
std::ofstream new_chatlog(("C:\\Users\\Administrator\\Documents\\GTA San Andreas User Files\\SAMP\\ChatLogs\\chatlog " + hoje + ".txt"), std::ios::app);
if (!chatlog.is_open() || !new_chatlog.is_open())
return;
std::string line;
while (std::getline(chatlog, line))
{
if (line.size() >= 11 && line[0] == '[' && line[9] == ']')
{
std::string time = line.substr(1, 8);
std::string rest = line.substr(9);
new_chatlog << "[" << hoje << " " << time << "]" << rest.substr(1) << "\n";
}
}
new_chatlog.close();
chatlog.close();
}
}
ChatLog()
{
Events::initScriptsEvent += []
{
instance.initialized = false;
};
Events::processScriptsEvent += []
{
if (!instance.initialized)
{
instance.initialized = true;
}
else
{
if (instance.IsMultiplayer())
{
const char* path = R"(C:\Users\Administrator\Documents\GTA San Andreas User Files\SAMP\ChatLogs)";
if (!std::filesystem::exists(path)) std::filesystem::create_directory(path);
}
}
};
}
} instance;