refactor: switch to wide string
This commit is contained in:
@@ -62,9 +62,9 @@ private:
|
||||
JsonSerializer m_Serializer;
|
||||
NamedPipeTransport m_Transport;
|
||||
|
||||
static const std::string PIPE_NAME;
|
||||
static const std::wstring PIPE_NAME;
|
||||
static const uint16_t RADIUS;
|
||||
};
|
||||
|
||||
const std::string Application::PIPE_NAME = std::string("PipeL2Bot");
|
||||
const std::wstring Application::PIPE_NAME = std::wstring(L"PipeL2Bot");
|
||||
const uint16_t Application::RADIUS = 2000;
|
@@ -5,14 +5,7 @@
|
||||
#include <Rpc.h>
|
||||
#pragma comment(lib, "Rpcrt4.lib")
|
||||
|
||||
std::string ConvertFromWideChar(const wchar_t* str)
|
||||
{
|
||||
std::wstring ws(str);
|
||||
std::string result(ws.begin(), ws.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string GenerateUUID()
|
||||
std::wstring GenerateUUID()
|
||||
{
|
||||
UUID uuid;
|
||||
::ZeroMemory(&uuid, sizeof(UUID));
|
||||
@@ -24,7 +17,7 @@ std::string GenerateUUID()
|
||||
|
||||
if (wszUuid == NULL)
|
||||
{
|
||||
return "";
|
||||
return L"";
|
||||
}
|
||||
|
||||
std::wstring ws = wszUuid;
|
||||
@@ -32,5 +25,5 @@ std::string GenerateUUID()
|
||||
::RpcStringFree((RPC_WSTR*)&wszUuid);
|
||||
wszUuid = NULL;
|
||||
|
||||
return std::string(ws.begin(), ws.end());
|
||||
return ws;
|
||||
}
|
@@ -3,5 +3,4 @@
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
std::string ConvertFromWideChar(const wchar_t* str);
|
||||
std::string GenerateUUID();
|
||||
std::wstring GenerateUUID();
|
@@ -7,6 +7,6 @@ struct ChatMessage
|
||||
{
|
||||
const uint32_t objectId = 0;
|
||||
const uint8_t channel = 0;
|
||||
const std::string name = "";
|
||||
const std::string text = "";
|
||||
const std::wstring name = L"";
|
||||
const std::wstring text = L"";
|
||||
};
|
@@ -8,15 +8,15 @@ using namespace L2Bot::Domain;
|
||||
class JsonSerializer : public Serializers::SerializerInterface
|
||||
{
|
||||
public:
|
||||
const std::string Serialize(std::vector<Serializers::Node> nodes, const bool isArray = false) const override
|
||||
const std::wstring Serialize(std::vector<Serializers::Node> nodes, const bool isArray = false) const override
|
||||
{
|
||||
std::string result = isArray ? "[" : "{";
|
||||
std::wstring result = isArray ? L"[" : L"{";
|
||||
|
||||
for (auto it = nodes.begin(); it != nodes.end(); ++it)
|
||||
{
|
||||
if (!isArray)
|
||||
{
|
||||
result += "\"" + it->name + "\":";
|
||||
result += L"\"" + it->name + L"\":";
|
||||
}
|
||||
if (it->isContainer)
|
||||
{
|
||||
@@ -24,15 +24,15 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
result += "\"" + it->value + "\"";
|
||||
result += L"\"" + it->value + L"\"";
|
||||
}
|
||||
if (std::next(it) != nodes.end())
|
||||
{
|
||||
result += ",";
|
||||
result += L",";
|
||||
}
|
||||
}
|
||||
|
||||
result += isArray ? "]" : "}";
|
||||
result += isArray ? L"]" : L"}";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -98,8 +98,8 @@ private:
|
||||
{
|
||||
if (m_Transport.IsConnected())
|
||||
{
|
||||
const std::string& response = m_Transport.Receive();
|
||||
if (response == "invalidate")
|
||||
const std::wstring& response = m_Transport.Receive();
|
||||
if (response == L"invalidate")
|
||||
{
|
||||
Invalidate();
|
||||
}
|
||||
@@ -124,13 +124,13 @@ private:
|
||||
{
|
||||
std::vector<Serializers::SerializableStateContainer> items
|
||||
{
|
||||
Serializers::SerializableStateContainer{m_HeroService.GetEntities(), "hero"},
|
||||
Serializers::SerializableStateContainer{m_DropService.GetEntities(), "drop"},
|
||||
Serializers::SerializableStateContainer{m_NPCService.GetEntities(), "npc"},
|
||||
Serializers::SerializableStateContainer{m_PlayerService.GetEntities(), "player"},
|
||||
Serializers::SerializableStateContainer{m_SkillService.GetEntities(), "skill"},
|
||||
Serializers::SerializableStateContainer{m_ItemService.GetEntities(), "item"},
|
||||
Serializers::SerializableStateContainer{m_AbnormalEffectService.GetEntities(), "abnormalEffect"},
|
||||
Serializers::SerializableStateContainer{m_HeroService.GetEntities(), L"hero"},
|
||||
Serializers::SerializableStateContainer{m_DropService.GetEntities(), L"drop"},
|
||||
Serializers::SerializableStateContainer{m_NPCService.GetEntities(), L"npc"},
|
||||
Serializers::SerializableStateContainer{m_PlayerService.GetEntities(), L"player"},
|
||||
Serializers::SerializableStateContainer{m_SkillService.GetEntities(), L"skill"},
|
||||
Serializers::SerializableStateContainer{m_ItemService.GetEntities(), L"item"},
|
||||
Serializers::SerializableStateContainer{m_AbnormalEffectService.GetEntities(), L"abnormalEffect"},
|
||||
};
|
||||
|
||||
std::vector<Serializers::Node> result;
|
||||
@@ -144,7 +144,7 @@ private:
|
||||
|
||||
for (const auto& message : m_ChatMessageService.GetMessages())
|
||||
{
|
||||
result.push_back(Serializers::Node{ "chat", message.BuildSerializationNodes() });
|
||||
result.push_back(Serializers::Node{ L"chat", message.BuildSerializationNodes() });
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -18,15 +18,15 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
const void Send(const std::string& data) override
|
||||
const void Send(const std::wstring& data) override
|
||||
{
|
||||
OutputDebugStringA(data.c_str());
|
||||
OutputDebugStringW(data.c_str());
|
||||
}
|
||||
const std::string Receive() override
|
||||
const std::wstring Receive() override
|
||||
{
|
||||
// delay imitation
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
return "";
|
||||
return L"";
|
||||
}
|
||||
|
||||
DebugViewTransport() = default;
|
||||
|
@@ -10,7 +10,7 @@
|
||||
class NamedPipe
|
||||
{
|
||||
public:
|
||||
const bool Connect(const std::string& pipeName)
|
||||
const bool Connect(const std::wstring& pipeName)
|
||||
{
|
||||
if (m_Pipe == NULL || m_PipeName != pipeName)
|
||||
{
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
CreateOverlapped(m_WritingOverlapped);
|
||||
}
|
||||
|
||||
m_Pipe = CreateNamedPipeA(("\\\\.\\pipe\\" + pipeName).c_str(),
|
||||
m_Pipe = CreateNamedPipeW((L"\\\\.\\pipe\\" + pipeName).c_str(),
|
||||
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
|
||||
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
|
||||
PIPE_UNLIMITED_INSTANCES,
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
return m_Connected;
|
||||
}
|
||||
|
||||
void Send(const std::string& message)
|
||||
void Send(const std::wstring& message)
|
||||
{
|
||||
if (!m_Connected)
|
||||
{
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
}
|
||||
|
||||
DWORD written;
|
||||
const auto result = WriteFile(m_Pipe, message.c_str(), message.size() + 1, &written, &m_WritingOverlapped);
|
||||
const auto result = WriteFile(m_Pipe, message.c_str(), (message.size() + 1) * sizeof(wchar_t), &written, &m_WritingOverlapped);
|
||||
|
||||
const auto lastError = GetLastError();
|
||||
if (!result)
|
||||
@@ -88,16 +88,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const std::string Receive()
|
||||
const std::wstring Receive()
|
||||
{
|
||||
if (!m_Connected)
|
||||
{
|
||||
return "";
|
||||
return L"";
|
||||
}
|
||||
|
||||
DWORD dwRead;
|
||||
std::unique_ptr<char[]> buffer = std::make_unique<char[]>(BUFFER_SIZE);
|
||||
const auto result = ReadFile(m_Pipe, buffer.get(), BUFFER_SIZE * sizeof(char), &dwRead, &m_ReadingOverlapped);
|
||||
std::unique_ptr<wchar_t[]> buffer = std::make_unique<wchar_t[]>(BUFFER_SIZE);
|
||||
const auto result = ReadFile(m_Pipe, buffer.get(), BUFFER_SIZE * sizeof(wchar_t), &dwRead, &m_ReadingOverlapped);
|
||||
|
||||
const auto lastError = GetLastError();
|
||||
if (!result)
|
||||
@@ -110,17 +110,17 @@ public:
|
||||
if (!overlappedResult)
|
||||
{
|
||||
m_Connected = false;
|
||||
return "";
|
||||
return L"";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Connected = false;
|
||||
return "";
|
||||
return L"";
|
||||
}
|
||||
}
|
||||
|
||||
std::string message = std::string(buffer.get());
|
||||
std::wstring message = std::wstring(buffer.get());
|
||||
|
||||
return message;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_PipeName = "";
|
||||
std::wstring m_PipeName = L"";
|
||||
HANDLE m_Pipe = NULL;
|
||||
bool m_Connected = false;
|
||||
OVERLAPPED m_ConntectingOverlapped = OVERLAPPED();
|
||||
|
@@ -11,7 +11,7 @@ class NamedPipeTransport : public Transports::TransportInterface
|
||||
public:
|
||||
const bool Connect() override
|
||||
{
|
||||
OutputDebugStringA(m_PipeName.c_str());
|
||||
OutputDebugStringW(m_PipeName.c_str());
|
||||
if (!m_ConnectionPipe.Connect(m_PipeName))
|
||||
{
|
||||
return false;
|
||||
@@ -19,9 +19,9 @@ public:
|
||||
|
||||
OutputDebugStringA("Client connected to connection pipe");
|
||||
|
||||
const std::string mainPipeName = GenerateUUID();
|
||||
const auto mainPipeName = GenerateUUID();
|
||||
|
||||
m_ConnectionPipe.Send("\\\\.\\pipe\\" + mainPipeName);
|
||||
m_ConnectionPipe.Send(L"\\\\.\\pipe\\" + mainPipeName);
|
||||
|
||||
OutputDebugStringA("Name of main pipe sended");
|
||||
|
||||
@@ -32,12 +32,12 @@ public:
|
||||
}
|
||||
OutputDebugStringA("Client connected to main pipe");
|
||||
|
||||
m_Pipe.Send("Hello!");
|
||||
m_Pipe.Send(L"Hello!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const void Send(const std::string& data) override
|
||||
const void Send(const std::wstring& data) override
|
||||
{
|
||||
if (!m_Pipe.IsConnected())
|
||||
{
|
||||
@@ -46,11 +46,11 @@ public:
|
||||
|
||||
m_Pipe.Send(data);
|
||||
}
|
||||
const std::string Receive() override
|
||||
const std::wstring Receive() override
|
||||
{
|
||||
if (!m_Pipe.IsConnected())
|
||||
{
|
||||
return "";
|
||||
return L"";
|
||||
}
|
||||
|
||||
return m_Pipe.Receive();
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
return m_Pipe.IsConnected();
|
||||
}
|
||||
|
||||
NamedPipeTransport(const std::string& pipeName) :
|
||||
NamedPipeTransport(const std::wstring& pipeName) :
|
||||
m_PipeName(pipeName)
|
||||
{
|
||||
}
|
||||
@@ -72,5 +72,5 @@ public:
|
||||
private:
|
||||
NamedPipe m_ConnectionPipe;
|
||||
NamedPipe m_Pipe;
|
||||
std::string m_PipeName = "";
|
||||
std::wstring m_PipeName = L"";
|
||||
};
|
@@ -35,9 +35,9 @@ namespace Interlude
|
||||
return std::make_unique<Entities::AbnormalEffect>(
|
||||
skillId,
|
||||
static_cast<uint8_t>(level),
|
||||
ConvertFromWideChar(name),
|
||||
ConvertFromWideChar(description),
|
||||
iconEntry ? ConvertFromWideChar(iconEntry->value) : ""
|
||||
std::wstring(name),
|
||||
std::wstring(description),
|
||||
iconEntry ? std::wstring(iconEntry->value) : L""
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -41,8 +41,8 @@ namespace Interlude
|
||||
),
|
||||
item->itemId,
|
||||
item->amount,
|
||||
nameEntry ? ConvertFromWideChar(nameEntry->value) : "",
|
||||
iconEntry ? ConvertFromWideChar(iconEntry->value) : ""
|
||||
nameEntry ? std::wstring(nameEntry->value) : L"",
|
||||
iconEntry ? std::wstring(iconEntry->value) : L""
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -30,8 +30,8 @@ namespace Interlude
|
||||
ValueObjects::Vector3(item->pawn->Acceleration.x, item->pawn->Acceleration.y, item->pawn->Acceleration.z)
|
||||
),
|
||||
ValueObjects::FullName(
|
||||
ConvertFromWideChar(item->nickname),
|
||||
ConvertFromWideChar(item->title)
|
||||
std::wstring(item->nickname),
|
||||
std::wstring(item->title)
|
||||
),
|
||||
ValueObjects::VitalStats(
|
||||
item->maxHp, item->hp,
|
||||
|
@@ -35,10 +35,10 @@ namespace Interlude
|
||||
const auto data = m_L2GameData.GetItemData(itemInfo.itemId);
|
||||
|
||||
const auto nameEntry = data ? m_FName.GetEntry(data->nameIndex) : nullptr;
|
||||
const auto name = nameEntry ? ConvertFromWideChar(nameEntry->value) : "";
|
||||
const auto name = nameEntry ? std::wstring(nameEntry->value) : L"";
|
||||
const auto iconEntry = data ? m_FName.GetEntry(data->iconNameIndex) : nullptr;
|
||||
const auto icon = iconEntry ? ConvertFromWideChar(iconEntry->value) : "";
|
||||
const auto description = data && data->description ? ConvertFromWideChar(data->description) : "";
|
||||
const auto icon = iconEntry ? std::wstring(iconEntry->value) : L"";
|
||||
const auto description = data && data->description ? std::wstring(data->description) : L"";
|
||||
|
||||
if (data)
|
||||
{
|
||||
@@ -92,9 +92,9 @@ namespace Interlude
|
||||
std::unique_ptr<Entities::BaseItem> CreateEtc(
|
||||
const ItemData& itemInfo,
|
||||
const FL2ItemDataBase* itemData,
|
||||
const std::string& name,
|
||||
const std::string& icon,
|
||||
const std::string& description
|
||||
const std::wstring& name,
|
||||
const std::wstring& icon,
|
||||
const std::wstring& description
|
||||
) const
|
||||
{
|
||||
return std::make_unique<Entities::EtcItem>(
|
||||
@@ -113,16 +113,16 @@ namespace Interlude
|
||||
std::unique_ptr<Entities::BaseItem> CreateArmor(
|
||||
const ItemData& itemInfo,
|
||||
const FL2ItemDataBase* itemData,
|
||||
const std::string& name,
|
||||
const std::string& icon,
|
||||
const std::string& description
|
||||
const std::wstring& name,
|
||||
const std::wstring& icon,
|
||||
const std::wstring& description
|
||||
) const
|
||||
{
|
||||
const auto casted = static_cast<const FL2ArmorItemData*>(itemData);
|
||||
|
||||
const auto setEffect = casted && casted->setEffect ? ConvertFromWideChar(casted->setEffect) : "";
|
||||
const auto addSetEffect = casted && casted->setEffect ? ConvertFromWideChar(casted->setEffect) : "";
|
||||
const auto enchantEffect = casted && casted->enchantEffect ? ConvertFromWideChar(casted->enchantEffect) : "";
|
||||
const auto setEffect = casted && casted->setEffect ? std::wstring(casted->setEffect) : L"";
|
||||
const auto addSetEffect = casted && casted->setEffect ? std::wstring(casted->setEffect) : L"";
|
||||
const auto enchantEffect = casted && casted->enchantEffect ? std::wstring(casted->enchantEffect) : L"";
|
||||
|
||||
return std::make_unique<Entities::ArmorItem>(
|
||||
itemInfo.objectId,
|
||||
@@ -147,9 +147,9 @@ namespace Interlude
|
||||
std::unique_ptr<Entities::BaseItem> CreateWeaponOrShield(
|
||||
const ItemData& itemInfo,
|
||||
const FL2ItemDataBase* itemData,
|
||||
const std::string& name,
|
||||
const std::string& icon,
|
||||
const std::string& description
|
||||
const std::wstring& name,
|
||||
const std::wstring& icon,
|
||||
const std::wstring& description
|
||||
) const
|
||||
{
|
||||
const auto casted = static_cast<const FL2WeaponItemData*>(itemData);
|
||||
|
@@ -30,8 +30,8 @@ namespace Interlude
|
||||
item->npcId,
|
||||
spoiledState,
|
||||
ValueObjects::FullName(
|
||||
ConvertFromWideChar(item->nickname),
|
||||
ConvertFromWideChar(item->title)
|
||||
std::wstring(item->nickname),
|
||||
std::wstring(item->title)
|
||||
),
|
||||
ValueObjects::VitalStats(
|
||||
item->maxHp, item->hp,
|
||||
|
@@ -27,8 +27,8 @@ namespace Interlude
|
||||
ValueObjects::Vector3(item->pawn->Acceleration.x, item->pawn->Acceleration.y, item->pawn->Acceleration.z)
|
||||
),
|
||||
ValueObjects::FullName(
|
||||
ConvertFromWideChar(item->nickname),
|
||||
ConvertFromWideChar(item->title)
|
||||
std::wstring(item->nickname),
|
||||
std::wstring(item->title)
|
||||
),
|
||||
ValueObjects::Phenotype(
|
||||
(Enums::RaceEnum)item->raceId,
|
||||
|
@@ -40,9 +40,9 @@ namespace Interlude
|
||||
isActive != 1,
|
||||
static_cast<uint8_t>(cost),
|
||||
static_cast<int16_t>(range),
|
||||
ConvertFromWideChar(name),
|
||||
ConvertFromWideChar(description),
|
||||
iconEntry ? ConvertFromWideChar(iconEntry->value) : "",
|
||||
std::wstring(name),
|
||||
std::wstring(description),
|
||||
iconEntry ? std::wstring(iconEntry->value) : L"",
|
||||
false,
|
||||
false,
|
||||
false
|
||||
|
@@ -177,8 +177,8 @@ namespace Interlude
|
||||
{
|
||||
buffer[0],
|
||||
static_cast<uint8_t>(buffer[1]),
|
||||
ConvertFromWideChar(reinterpret_cast<wchar_t*>(buffer[2])),
|
||||
ConvertFromWideChar(reinterpret_cast<wchar_t*>(buffer[3]))
|
||||
std::wstring(reinterpret_cast<wchar_t*>(buffer[2])),
|
||||
std::wstring(reinterpret_cast<wchar_t*>(buffer[3]))
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@@ -30,6 +30,4 @@
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
|
||||
std::string ConvertFromWideChar(const wchar_t* str);
|
||||
|
||||
#endif //PCH_H
|
||||
|
Reference in New Issue
Block a user