Optimizations
- Increase warning level - Use proper casting - Fix some more warnings.
This commit is contained in:
@ -9,7 +9,7 @@ namespace Utils
|
||||
unsigned long length = (data.size() * 2);
|
||||
char* buffer = Utils::Memory::AllocateArray<char>(length);
|
||||
|
||||
if (compress2((Bytef*)buffer, &length, (Bytef*)data.data(), data.size(), Z_BEST_COMPRESSION) != Z_OK)
|
||||
if (compress2(reinterpret_cast<Bytef*>(buffer), &length, reinterpret_cast<Bytef*>(const_cast<char*>(data.data())), data.size(), Z_BEST_COMPRESSION) != Z_OK)
|
||||
{
|
||||
Utils::Memory::Free(buffer);
|
||||
return "";
|
||||
|
@ -12,12 +12,12 @@ namespace Utils
|
||||
|
||||
Hook* Hook::Initialize(DWORD place, void(*stub)(), bool useJump)
|
||||
{
|
||||
return Hook::Initialize(place, (void*)stub, useJump);
|
||||
return Hook::Initialize(place, reinterpret_cast<void*>(stub), useJump);
|
||||
}
|
||||
|
||||
Hook* Hook::Initialize(DWORD place, void* stub, bool useJump)
|
||||
{
|
||||
return Hook::Initialize((void*)place, stub, useJump);
|
||||
return Hook::Initialize(reinterpret_cast<void*>(place), stub, useJump);
|
||||
}
|
||||
|
||||
Hook* Hook::Initialize(void* place, void* stub, bool useJump)
|
||||
@ -29,7 +29,7 @@ namespace Utils
|
||||
Hook::Place = place;
|
||||
Hook::Stub = stub;
|
||||
|
||||
Hook::Original = (char*)Hook::Place + 5 + *(DWORD*)((DWORD)Hook::Place + 1);
|
||||
Hook::Original = static_cast<char*>(Hook::Place) + 5 + *reinterpret_cast<DWORD*>((static_cast<char*>(Hook::Place) + 1));
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -46,15 +46,14 @@ namespace Utils
|
||||
|
||||
Hook::Installed = true;
|
||||
|
||||
DWORD d = 1;
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), PAGE_EXECUTE_READWRITE, &this->Protection);
|
||||
memcpy(Hook::Buffer, Hook::Place, sizeof(Hook::Buffer));
|
||||
|
||||
char* Code = (char*)Hook::Place;
|
||||
char* code = static_cast<char*>(Hook::Place);
|
||||
|
||||
*Code = (char)(Hook::UseJump ? 0xE9 : 0xE8);
|
||||
*code = static_cast<char>(Hook::UseJump ? 0xE9 : 0xE8);
|
||||
|
||||
*(size_t*)&Code[1] = (size_t)Hook::Stub - ((size_t)Hook::Place + 5);
|
||||
*reinterpret_cast<size_t*>(code + 1) = reinterpret_cast<size_t>(Hook::Stub) - (reinterpret_cast<size_t>(Hook::Place) + 5);
|
||||
|
||||
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), Hook::Protection, &this->Protection);
|
||||
|
||||
@ -110,26 +109,26 @@ namespace Utils
|
||||
|
||||
void Hook::Nop(DWORD place, size_t length)
|
||||
{
|
||||
Nop((void*)place, length);
|
||||
Nop(reinterpret_cast<void*>(place), length);
|
||||
}
|
||||
|
||||
void Hook::SetString(void* place, const char* string, size_t length)
|
||||
{
|
||||
strncpy((char*)place, string, length);
|
||||
strncpy(static_cast<char*>(place), string, length);
|
||||
}
|
||||
|
||||
void Hook::SetString(DWORD place, const char* string, size_t length)
|
||||
{
|
||||
Hook::SetString((void*)place, string, length);
|
||||
Hook::SetString(reinterpret_cast<void*>(place), string, length);
|
||||
}
|
||||
|
||||
void Hook::SetString(void* place, const char* string)
|
||||
{
|
||||
Hook::SetString(place, string, strlen((char*)place));
|
||||
Hook::SetString(place, string, strlen(static_cast<char*>(place)));
|
||||
}
|
||||
|
||||
void Hook::SetString(DWORD place, const char* string)
|
||||
{
|
||||
Hook::SetString((void*)place, string);
|
||||
Hook::SetString(reinterpret_cast<void*>(place), string);
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ namespace Utils
|
||||
public:
|
||||
Hook() : Place(nullptr), Stub(nullptr), Initialized(false), Installed(false), UseJump(false), Protection(0) { ZeroMemory(Hook::Buffer, sizeof(Hook::Buffer)); }
|
||||
Hook(void* place, void* stub, bool useJump = true) : Hook() { Hook::Initialize(place, stub, useJump); }
|
||||
Hook(DWORD place, void* stub, bool useJump = true) : Hook((void*)place, stub, useJump) {}
|
||||
Hook(DWORD place, DWORD stub, bool useJump = true) : Hook((void*)place, (void*)stub, useJump) {}
|
||||
Hook(DWORD place, void(*stub)(), bool useJump = true) : Hook((void*)place, (void*)stub, useJump) {}
|
||||
Hook(DWORD place, void* stub, bool useJump = true) : Hook(reinterpret_cast<void*>(place), stub, useJump) {}
|
||||
Hook(DWORD place, DWORD stub, bool useJump = true) : Hook(reinterpret_cast<void*>(place), reinterpret_cast<void*>(stub), useJump) {}
|
||||
Hook(DWORD place, void(*stub)(), bool useJump = true) : Hook(reinterpret_cast<void*>(place), reinterpret_cast<void*>(stub), useJump) {}
|
||||
|
||||
~Hook();
|
||||
|
||||
@ -27,12 +27,12 @@ namespace Utils
|
||||
|
||||
template <typename T> static std::function<T> Call(DWORD function)
|
||||
{
|
||||
return std::function<T>((T*)function);
|
||||
return std::function<T>(reinterpret_cast<T*>(function));
|
||||
}
|
||||
|
||||
template <typename T> static std::function<T> Call(FARPROC function)
|
||||
{
|
||||
return Call<T>((DWORD)function);
|
||||
return Call<T>(reinterpret_cast<DWORD>(function));
|
||||
}
|
||||
|
||||
static void SetString(void* place, const char* string, size_t length);
|
||||
@ -46,56 +46,56 @@ namespace Utils
|
||||
|
||||
template <typename T> static void Set(void* place, T value)
|
||||
{
|
||||
*(T*)place = value;
|
||||
*static_cast<T*>(place) = value;
|
||||
FlushInstructionCache(GetCurrentProcess(), place, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T> static void Set(DWORD place, T value)
|
||||
{
|
||||
return Set<T>((void*)place, value);
|
||||
return Set<T>(reinterpret_cast<void*>(place), value);
|
||||
}
|
||||
|
||||
template <typename T> static void Xor(void* place, T value)
|
||||
{
|
||||
*(T*)place ^= value;
|
||||
*static_cast<T*>(place) ^= value;
|
||||
FlushInstructionCache(GetCurrentProcess(), place, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T> static void Xor(DWORD place, T value)
|
||||
{
|
||||
return Xor<T>((void*)place, value);
|
||||
return Xor<T>(reinterpret_cast<void*>(place), value);
|
||||
}
|
||||
|
||||
template <typename T> static void Or(void* place, T value)
|
||||
{
|
||||
*(T*)place |= value;
|
||||
*static_cast<T*>(place) |= value;
|
||||
FlushInstructionCache(GetCurrentProcess(), place, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T> static void Or(DWORD place, T value)
|
||||
{
|
||||
return Or<T>((void*)place, value);
|
||||
return Or<T>(reinterpret_cast<void*>(place), value);
|
||||
}
|
||||
|
||||
template <typename T> static void And(void* place, T value)
|
||||
{
|
||||
*(T*)place &= value;
|
||||
*static_cast<T*>(place) &= value;
|
||||
FlushInstructionCache(GetCurrentProcess(), place, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T> static void And(DWORD place, T value)
|
||||
{
|
||||
return And<T>((void*)place, value);
|
||||
return And<T>(reinterpret_cast<void*>(place), value);
|
||||
}
|
||||
|
||||
template <typename T> static T Get(void* place)
|
||||
{
|
||||
return *(T*)place;
|
||||
return *static_cast<T*>(place);
|
||||
}
|
||||
|
||||
template <typename T> static T Get(DWORD place)
|
||||
{
|
||||
return Get<T>((void*)place);
|
||||
return Get<T>(reinterpret_cast<void*>(place));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -28,6 +28,6 @@ namespace Utils
|
||||
|
||||
void Memory::Free(const void* data)
|
||||
{
|
||||
Memory::Free((void*)data);
|
||||
Memory::Free(const_cast<void*>(data));
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace Utils
|
||||
}
|
||||
template <typename T> T* AllocateArray(size_t count = 1)
|
||||
{
|
||||
return (T*)this->Allocate(count * sizeof(T));
|
||||
return static_cast<T*>(this->Allocate(count * sizeof(T)));
|
||||
}
|
||||
|
||||
char* DuplicateString(std::string string)
|
||||
@ -64,7 +64,7 @@ namespace Utils
|
||||
static void* Allocate(size_t length);
|
||||
template <typename T> static T* AllocateArray(size_t count = 1)
|
||||
{
|
||||
return (T*)Allocate(count * sizeof(T));
|
||||
return static_cast<T*>(Allocate(count * sizeof(T)));
|
||||
}
|
||||
|
||||
static char* DuplicateString(std::string string);
|
||||
|
@ -32,7 +32,7 @@ namespace Utils
|
||||
return Stream::Buffer.capacity();
|
||||
}
|
||||
|
||||
char* Stream::Save(const void * _str, size_t size, size_t count)
|
||||
char* Stream::Save(const void* _str, size_t size, size_t count)
|
||||
{
|
||||
return Stream::Save(Stream::GetCurrentBlock(), _str, size, count);
|
||||
}
|
||||
@ -50,7 +50,7 @@ namespace Utils
|
||||
__debugbreak();
|
||||
}
|
||||
|
||||
Stream::Buffer.append((char*)_str, size * count);
|
||||
Stream::Buffer.append(static_cast<const char*>(_str), size * count);
|
||||
|
||||
if (Stream::Data() != data && Stream::IsCriticalSection())
|
||||
{
|
||||
@ -123,7 +123,7 @@ namespace Utils
|
||||
|
||||
char* Stream::SaveMax(size_t count)
|
||||
{
|
||||
return Stream::SaveByte(-1, count);
|
||||
return Stream::SaveByte(static_cast<unsigned char>(-1), count);
|
||||
}
|
||||
|
||||
void Stream::Align(Stream::Alignment align)
|
||||
@ -185,12 +185,12 @@ namespace Utils
|
||||
|
||||
char* Stream::At()
|
||||
{
|
||||
return (char*)(Stream::Data() + Stream::Length());
|
||||
return reinterpret_cast<char*>(Stream::Data() + Stream::Length());
|
||||
}
|
||||
|
||||
char* Stream::Data()
|
||||
{
|
||||
return (char*)Stream::Buffer.data();
|
||||
return const_cast<char*>(Stream::Buffer.data());
|
||||
}
|
||||
|
||||
unsigned int Stream::GetBlockSize(Game::XFILE_BLOCK_TYPES stream)
|
||||
|
@ -59,8 +59,12 @@ namespace Utils
|
||||
|
||||
DWORD GetPackedOffset();
|
||||
|
||||
char* At();
|
||||
char* Data();
|
||||
char* At();
|
||||
template <typename T> T* Dest()
|
||||
{
|
||||
return reinterpret_cast<T*>(this->At());
|
||||
}
|
||||
|
||||
void ToBuffer(std::string& outBuffer);
|
||||
std::string ToBuffer();
|
||||
@ -102,16 +106,16 @@ namespace Utils
|
||||
|
||||
uint32_t GetUnpackedOffset()
|
||||
{
|
||||
Offset offset = *this;
|
||||
offset.packed--;
|
||||
return offset.offset;
|
||||
Offset lOffset = *this;
|
||||
lOffset.packed--;
|
||||
return lOffset.offset;
|
||||
};
|
||||
|
||||
int GetUnpackedBlock()
|
||||
{
|
||||
Offset offset = *this;
|
||||
offset.packed--;
|
||||
return offset.block;
|
||||
Offset lOffset = *this;
|
||||
lOffset.packed--;
|
||||
return lOffset.block;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -39,22 +39,22 @@ namespace Utils
|
||||
void Parse(std::string buffer);
|
||||
};
|
||||
|
||||
template <typename T> void Merge(std::vector<T> &target, T* source, size_t length)
|
||||
template <typename T> void Merge(std::vector<T>* target, T* source, size_t length)
|
||||
{
|
||||
if (source)
|
||||
{
|
||||
for (size_t i = 0; i < length; i++)
|
||||
{
|
||||
target.push_back(source[i]);
|
||||
target->push_back(source[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> void Merge(std::vector<T> &target, std::vector<T> &source)
|
||||
template <typename T> void Merge(std::vector<T>* target, std::vector<T> source)
|
||||
{
|
||||
for (auto &entry : source)
|
||||
{
|
||||
target.push_back(entry);
|
||||
target->push_back(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace Utils
|
||||
|
||||
void WebIO::OpenSession(std::string useragent)
|
||||
{
|
||||
WebIO::m_hSession = InternetOpen(useragent.c_str(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
|
||||
WebIO::m_hSession = InternetOpen(useragent.data(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
void WebIO::CloseSession()
|
||||
@ -56,14 +56,14 @@ namespace Utils
|
||||
|
||||
PARSEDURLA pURL;
|
||||
pURL.cbSize = sizeof(pURL);
|
||||
ParseURLA(url.c_str(), &pURL);
|
||||
ParseURLA(url.data(), &pURL);
|
||||
|
||||
// Parse protocol
|
||||
if (pURL.cchProtocol && pURL.cchProtocol != 0xCCCCCCCC && pURL.pszProtocol)
|
||||
{
|
||||
for (UINT i = 0; i < pURL.cchProtocol; i++)
|
||||
{
|
||||
char lChar = tolower(pURL.pszProtocol[i]);
|
||||
char lChar = static_cast<char>(tolower(pURL.pszProtocol[i]));
|
||||
WebIO::m_sUrl.protocol.append(&lChar, 1);
|
||||
}
|
||||
}
|
||||
@ -183,9 +183,9 @@ namespace Utils
|
||||
wPort = INTERNET_DEFAULT_HTTPS_PORT;
|
||||
}
|
||||
|
||||
const char* username = (WebIO::m_username.size() ? WebIO::m_username.c_str() : NULL);
|
||||
const char* password = (WebIO::m_password.size() ? WebIO::m_password.c_str() : NULL);
|
||||
WebIO::m_hConnect = InternetConnect(WebIO::m_hSession, WebIO::m_sUrl.server.c_str(), wPort, username, password, dwService, dwFlag, 0);
|
||||
const char* username = (WebIO::m_username.size() ? WebIO::m_username.data() : NULL);
|
||||
const char* password = (WebIO::m_password.size() ? WebIO::m_password.data() : NULL);
|
||||
WebIO::m_hConnect = InternetConnect(WebIO::m_hSession, WebIO::m_sUrl.server.data(), wPort, username, password, dwService, dwFlag, 0);
|
||||
|
||||
return (WebIO::m_hConnect && WebIO::m_hConnect != INVALID_HANDLE_VALUE);
|
||||
}
|
||||
@ -216,7 +216,7 @@ namespace Utils
|
||||
//InternetSetOption(WebIO::m_hConnect, INTERNET_OPTION_RECEIVE_TIMEOUT, &m_timeout, sizeof(m_timeout));
|
||||
//InternetSetOption(WebIO::m_hConnect, INTERNET_OPTION_SEND_TIMEOUT, &m_timeout, sizeof(m_timeout));
|
||||
|
||||
WebIO::m_hFile = HttpOpenRequest(WebIO::m_hConnect, command, WebIO::m_sUrl.document.c_str(), NULL, NULL, acceptTypes, dwFlag, 0);
|
||||
WebIO::m_hFile = HttpOpenRequest(WebIO::m_hConnect, command, WebIO::m_sUrl.document.data(), NULL, NULL, acceptTypes, dwFlag, 0);
|
||||
|
||||
if (!WebIO::m_hFile || WebIO::m_hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@ -225,7 +225,7 @@ namespace Utils
|
||||
}
|
||||
|
||||
const char* headers = "Content-type: application/x-www-form-urlencoded";
|
||||
HttpSendRequest(WebIO::m_hFile, headers, strlen(headers), (char*)body.c_str(), body.size() + 1);
|
||||
HttpSendRequest(WebIO::m_hFile, headers, strlen(headers), const_cast<char*>(body.data()), body.size() + 1);
|
||||
|
||||
std::string returnBuffer;
|
||||
|
||||
@ -260,7 +260,7 @@ namespace Utils
|
||||
|
||||
bool WebIO::SetDirectory(std::string directory)
|
||||
{
|
||||
return (FtpSetCurrentDirectoryA(WebIO::m_hConnect, directory.c_str()) == TRUE);
|
||||
return (FtpSetCurrentDirectoryA(WebIO::m_hConnect, directory.data()) == TRUE);
|
||||
}
|
||||
|
||||
bool WebIO::SetRelativeDirectory(std::string directory)
|
||||
@ -273,7 +273,7 @@ namespace Utils
|
||||
WebIO::FormatPath(currentDir, true);
|
||||
|
||||
char path[MAX_PATH] = { 0 };
|
||||
PathCombineA(path, currentDir.c_str(), directory.c_str());
|
||||
PathCombineA(path, currentDir.data(), directory.data());
|
||||
|
||||
std::string newPath(path);
|
||||
WebIO::FormatPath(newPath, false);
|
||||
@ -320,7 +320,7 @@ namespace Utils
|
||||
|
||||
bool WebIO::CreateDirectory(std::string directory)
|
||||
{
|
||||
return (FtpCreateDirectoryA(WebIO::m_hConnect, directory.c_str()) == TRUE);
|
||||
return (FtpCreateDirectoryA(WebIO::m_hConnect, directory.data()) == TRUE);
|
||||
}
|
||||
|
||||
// Recursively delete a directory
|
||||
@ -341,12 +341,12 @@ namespace Utils
|
||||
|
||||
WebIO::SetDirectory(tempDir);
|
||||
|
||||
return (FtpRemoveDirectoryA(WebIO::m_hConnect, directory.c_str()) == TRUE);
|
||||
return (FtpRemoveDirectoryA(WebIO::m_hConnect, directory.data()) == TRUE);
|
||||
}
|
||||
|
||||
bool WebIO::RenameDirectory(std::string directory, std::string newDir)
|
||||
{
|
||||
return (FtpRenameFileA(WebIO::m_hConnect, directory.c_str(), newDir.c_str()) == TRUE); // According to the internetz, this should work
|
||||
return (FtpRenameFileA(WebIO::m_hConnect, directory.data(), newDir.data()) == TRUE); // According to the internetz, this should work
|
||||
}
|
||||
|
||||
bool WebIO::ListElements(std::string directory, std::vector<std::string> &list, bool files)
|
||||
@ -399,33 +399,33 @@ namespace Utils
|
||||
|
||||
bool WebIO::UploadFile(std::string file, std::string localfile)
|
||||
{
|
||||
return (FtpPutFileA(WebIO::m_hConnect, localfile.c_str(), file.c_str(), FTP_TRANSFER_TYPE_BINARY, NULL) == TRUE);
|
||||
return (FtpPutFileA(WebIO::m_hConnect, localfile.data(), file.data(), FTP_TRANSFER_TYPE_BINARY, NULL) == TRUE);
|
||||
}
|
||||
|
||||
bool WebIO::DeleteFile(std::string file)
|
||||
{
|
||||
return (FtpDeleteFileA(WebIO::m_hConnect, file.c_str()) == TRUE);
|
||||
return (FtpDeleteFileA(WebIO::m_hConnect, file.data()) == TRUE);
|
||||
}
|
||||
|
||||
bool WebIO::RenameFile(std::string file, std::string newFile)
|
||||
{
|
||||
return (FtpRenameFileA(WebIO::m_hConnect, file.c_str(), newFile.c_str()) == TRUE);
|
||||
return (FtpRenameFileA(WebIO::m_hConnect, file.data(), newFile.data()) == TRUE);
|
||||
}
|
||||
|
||||
bool WebIO::DownloadFile(std::string file, std::string localfile)
|
||||
{
|
||||
return (FtpGetFileA(WebIO::m_hConnect, file.c_str(), localfile.c_str(), FALSE, NULL, FTP_TRANSFER_TYPE_BINARY, 0) == TRUE);
|
||||
return (FtpGetFileA(WebIO::m_hConnect, file.data(), localfile.data(), FALSE, NULL, FTP_TRANSFER_TYPE_BINARY, 0) == TRUE);
|
||||
}
|
||||
|
||||
bool WebIO::UploadFileData(std::string file, std::string data)
|
||||
{
|
||||
bool result = false;
|
||||
WebIO::m_hFile = FtpOpenFileA(WebIO::m_hConnect, file.c_str(), GENERIC_WRITE, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
|
||||
WebIO::m_hFile = FtpOpenFileA(WebIO::m_hConnect, file.data(), GENERIC_WRITE, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
|
||||
|
||||
if (WebIO::m_hFile)
|
||||
{
|
||||
DWORD size = 0;
|
||||
if (InternetWriteFile(WebIO::m_hFile, data.c_str(), data.size(), &size) == TRUE)
|
||||
if (InternetWriteFile(WebIO::m_hFile, data.data(), data.size(), &size) == TRUE)
|
||||
{
|
||||
result = (size == data.size());
|
||||
}
|
||||
@ -440,7 +440,7 @@ namespace Utils
|
||||
{
|
||||
data.clear();
|
||||
|
||||
WebIO::m_hFile = FtpOpenFileA(WebIO::m_hConnect, file.c_str(), GENERIC_READ, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
|
||||
WebIO::m_hFile = FtpOpenFileA(WebIO::m_hConnect, file.data(), GENERIC_READ, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
|
||||
|
||||
if (WebIO::m_hFile)
|
||||
{
|
||||
|
Reference in New Issue
Block a user