feat: add some info and app logging messages
This commit is contained in:
parent
ab85800275
commit
a2428bb0d1
@ -15,7 +15,7 @@ namespace Client.Application.ViewModels
|
||||
{
|
||||
get
|
||||
{
|
||||
return message.Name + ": " + message.Text;
|
||||
return (message.Name != "" ? message.Name + ": " : "") + message.Text;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,10 @@ namespace L2Bot::Domain::Entities
|
||||
{
|
||||
return "hero";
|
||||
}
|
||||
const ValueObjects::FullName& GetFullName() const
|
||||
{
|
||||
return m_FullName;
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
|
@ -11,6 +11,10 @@
|
||||
#include "Versions/VersionAbstractFactory.h"
|
||||
#include "Domain/Services/ServiceLocator.h"
|
||||
#include "Domain/Events/EventDispatcher.h"
|
||||
#include "Domain/Logger/Logger.h"
|
||||
#include "Logger/ChatLogChannel.h"
|
||||
#include "Logger/FileLogChannel.h"
|
||||
#include "Logger/OutputDebugLogChannel.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
|
@ -28,7 +28,7 @@ protected:
|
||||
0,
|
||||
static_cast<uint8_t>(m_ChatChannel),
|
||||
L"",
|
||||
GetCurrentDateTime() + logEntry
|
||||
logEntry
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -14,6 +14,6 @@ public:
|
||||
protected:
|
||||
void DoSendToChannel(const std::wstring& logEntry) override
|
||||
{
|
||||
OutputDebugStringW((GetCurrentDateTime() + logEntry).c_str());
|
||||
OutputDebugStringW(logEntry.c_str());
|
||||
}
|
||||
};
|
@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include "Domain/Services/ServiceLocator.h"
|
||||
|
||||
#define BUFFER_SIZE 16384
|
||||
|
||||
@ -37,7 +38,7 @@ public:
|
||||
|
||||
if (m_Pipe == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
OutputDebugStringA(std::to_string(GetLastError()).c_str());
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Error(L"cannot connect to the pipe ""{}""", m_PipeName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -80,11 +81,13 @@ public:
|
||||
const auto overlappedResult = GetOverlappedResult(m_Pipe, &m_WritingOverlapped, &ret, false);
|
||||
if (!overlappedResult)
|
||||
{
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Error(L"cannot get overlapped result for the pipe ""{}"" when writing", m_PipeName);
|
||||
m_Connected = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Error(L"cannot write to the pipe ""{}"": {}", m_PipeName, lastError);
|
||||
m_Connected = false;
|
||||
}
|
||||
}
|
||||
@ -111,12 +114,14 @@ public:
|
||||
const auto overlappedResult = GetOverlappedResult(m_Pipe, &m_ReadingOverlapped, &ret, false);
|
||||
if (!overlappedResult)
|
||||
{
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Error(L"cannot get overlapped result for the pipe ""{}"" when reading", m_PipeName);
|
||||
m_Connected = false;
|
||||
return L"";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Error(L"cannot read from the pipe ""{}"": {}", m_PipeName, lastError);
|
||||
m_Connected = false;
|
||||
return L"";
|
||||
}
|
||||
@ -147,7 +152,7 @@ private:
|
||||
const bool connected = ConnectNamedPipe(m_Pipe, &m_ConntectingOverlapped) == 0;
|
||||
if (!connected)
|
||||
{
|
||||
OutputDebugStringA(std::to_string(GetLastError()).c_str());
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Error(L"cannot connect to the pipe ""{}"": {}", m_PipeName, GetLastError());
|
||||
}
|
||||
|
||||
switch (GetLastError())
|
||||
@ -155,16 +160,12 @@ private:
|
||||
// The overlapped connection in progress.
|
||||
case ERROR_IO_PENDING:
|
||||
break;
|
||||
|
||||
// Client is already connected, so signal an event.
|
||||
|
||||
case ERROR_PIPE_CONNECTED:
|
||||
if (SetEvent(m_ConntectingOverlapped.hEvent))
|
||||
break;
|
||||
|
||||
// If an error occurs during the connect operation...
|
||||
default:
|
||||
OutputDebugStringA(std::to_string(GetLastError()).c_str());
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Error(L"an error has occurred when connecting to the pipe ""{}"": {}", m_PipeName, GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +176,7 @@ private:
|
||||
overlapped.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
|
||||
if (overlapped.hEvent == NULL)
|
||||
{
|
||||
OutputDebugStringA(std::to_string(GetLastError()).c_str());
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Error(L"cannot create overlapped for the pipe ""{}"": {}", m_PipeName, GetLastError());
|
||||
return;
|
||||
}
|
||||
overlapped.Offset = 0;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <Windows.h>
|
||||
#include "NamedPipe.h"
|
||||
#include "../Common/Common.h"
|
||||
#include "Domain/Services/ServiceLocator.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -11,26 +12,24 @@ class NamedPipeTransport : public Transports::TransportInterface
|
||||
public:
|
||||
const bool Connect() override
|
||||
{
|
||||
OutputDebugStringW(m_PipeName.c_str());
|
||||
if (!m_ConnectionPipe.Connect(m_PipeName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OutputDebugStringA("Client connected to connection pipe");
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"client connected to the connection pipe ""{}""", m_PipeName);
|
||||
|
||||
const auto mainPipeName = GenerateUUID();
|
||||
|
||||
m_ConnectionPipe.Send(mainPipeName);
|
||||
|
||||
OutputDebugStringA("Name of main pipe sended");
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"name ""{}"" of the main pipe sended", mainPipeName);
|
||||
|
||||
if (!m_Pipe.Connect(mainPipeName))
|
||||
{
|
||||
OutputDebugStringA(std::to_string(GetLastError()).c_str());
|
||||
return false;
|
||||
}
|
||||
OutputDebugStringA("Client connected to main pipe");
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"client connected to the main pipe ""{}""", mainPipeName);
|
||||
|
||||
m_Pipe.Send(L"Hello!");
|
||||
|
||||
|
@ -180,6 +180,7 @@ namespace Interlude
|
||||
if (_target == 0)
|
||||
{
|
||||
_target = This;
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"UGameEngine {:#010x} obtained", (int)_target);
|
||||
}
|
||||
|
||||
(*__Tick)(This, deltaTime);
|
||||
|
@ -2,6 +2,9 @@
|
||||
#include "../../../Common/apihook.h"
|
||||
#include "L2GameDataWrapper.h"
|
||||
#include "ProcessManipulation.h"
|
||||
#include "Domain/Services/ServiceLocator.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -53,6 +56,7 @@ namespace Interlude
|
||||
restore(originalInitAddress);
|
||||
InjectLibrary::StartCurrentProcess();
|
||||
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"FL2GameData {:#010x} obtained", (int)_target);
|
||||
return (*__Init)(This, unk, unk1);
|
||||
}
|
||||
|
||||
|
@ -166,6 +166,7 @@ namespace Interlude
|
||||
restore(originalInitAddress);
|
||||
InjectLibrary::StartCurrentProcess();
|
||||
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"UNetworkHandler {:#010x} obtained", (int)_target);
|
||||
(*__Init)(This, unk);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ namespace Interlude
|
||||
if (!m_Hero) {
|
||||
m_Hero = m_Factory.Create(hero);
|
||||
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::HeroCreatedEvent{});
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->App(L"{} enter in the world", m_Hero->GetFullName().GetNickname());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -34,6 +35,7 @@ namespace Interlude
|
||||
result[hero->objectId] = m_Hero;
|
||||
}
|
||||
else if (m_Hero) {
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->App(L"{} leave the world", m_Hero->GetFullName().GetNickname());
|
||||
m_Hero = nullptr;
|
||||
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::HeroDeletedEvent{});
|
||||
}
|
||||
|
@ -7,20 +7,50 @@
|
||||
InjectLibrary::Injector injector("L2BotHookMutex", WH_CALLWNDPROC);
|
||||
Application application(VersionAbstractFactory::Version::interlude);
|
||||
|
||||
void ConfigLogger(HMODULE hModule)
|
||||
{
|
||||
wchar_t buf[MAX_PATH];
|
||||
GetModuleFileNameW(hModule, buf, MAX_PATH);
|
||||
const std::wstring libName(buf);
|
||||
|
||||
std::wstring directory;
|
||||
const size_t lastSlashIndex = libName.rfind(L"\\");
|
||||
if (std::string::npos != lastSlashIndex)
|
||||
{
|
||||
directory = libName.substr(0, lastSlashIndex);
|
||||
}
|
||||
|
||||
std::vector <std::unique_ptr<Logger::LogChannel>> channels;
|
||||
channels.push_back(std::make_unique<OutputDebugLogChannel>(std::vector<Logger::LogLevel>{}));
|
||||
channels.push_back(std::make_unique<FileLogChannel>(directory + L"\\error.log", std::vector<Logger::LogLevel>{
|
||||
Logger::LogLevel::error,
|
||||
Logger::LogLevel::warning
|
||||
}));
|
||||
channels.push_back(std::make_unique<ChatLogChannel>(Enums::ChatChannelEnum::log, std::vector<Logger::LogLevel>{
|
||||
Logger::LogLevel::app
|
||||
}));
|
||||
Services::ServiceLocator::GetInstance().SetLogger(std::make_unique<Logger::Logger>(std::move(channels)));
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
const int processId = GetCurrentProcessId();
|
||||
const std::string& processName = InjectLibrary::GetCurrentProcessName();
|
||||
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
injector.SetHook(hModule);
|
||||
if (processName == "l2.exe") {
|
||||
ConfigLogger(hModule);
|
||||
|
||||
InjectLibrary::StopCurrentProcess();
|
||||
application.Start();
|
||||
InjectLibrary::StartCurrentProcess();
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"attached to Lineage 2 client {:#010x}", processId);
|
||||
}
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
@ -28,6 +58,7 @@ BOOL APIENTRY DllMain(HMODULE hModule,
|
||||
InjectLibrary::StopCurrentProcess();
|
||||
application.Stop();
|
||||
InjectLibrary::StartCurrentProcess();
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"detached from Lineage 2 client {:#010x}", processId);
|
||||
}
|
||||
injector.SetHook();
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user