diff --git a/README.md b/README.md index f2f7a9e..75bf96b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ + ![code](https://raw.githubusercontent.com/project-bo4/shield-development/master/assets/readme_header.jpg) ## SHIELD @@ -10,26 +11,28 @@ As of May 11, 2023, we have merged the 'demonware' branch into 'master'. It incl ## INSTRUCTIONS - > You should already have the publisher files required for playing online (found under the LPC folder of your game directory). -> If this is not the case, then run Black Ops 4 through Battle.NET Launcher once to get those files downloaded. +> If this is not the case, then start Black Ops 4 through Battle.NET launcher once to get those files downloaded. -1- Clone repository with its sub-modules and use ```generate.bat``` to make a Visual Studio solution, then compile project and copy ``d3d11.dll`` into your BO4 folder. +1- Clone repository with its sub-modules using git bash and run **``generate.bat``** to make a visual studio solution which you will find inside build folder named **``shield-development.sln``**, then you will have to bring up the vs project with it and compile the project with **release configuration**. -2- Start BlackOps4.exe +2- Find and copy the compiled **``XInput9_1_0.dll``** from the build output folder into your BlackOps4 folder. + +3- Start the game with **``BlackOps4.exe``**. you will know if you got it correctly if you see a ( ͡❛ ͜ʖ ͡❛) splash screen. + +*In case you wanted to revert the game back to the original Battle.NET servers, just remove the proxy dll ``XInput9_1_0.dll`` from your game folder. You can put it back whenever you want to re-install the client.* -*In case you wanted to revert back to using the original Battle.NET servers, just delete the generated ``d3d11.dll`` file from your game folder. You can re-generate and copy ```d3d11.dll``` back later whenever you want to re-install the client.* ## SHIELD DOCUMENTATION +Documentation with some more information regarding client's features and user manual can be found [here](https://shield-bo4.gitbook.io/). -Documentation on shield can be found [here](https://shield-bo4.gitbook.io/). ## SUBMITTING ISSUES The Github Issues section is only for reporting programmatical errors related to the client. Please don't use it for requesting features or seeking help with personal issues such as experiencing faulty game data or similar problems. Use Battle.NET's 'Scan And Repair' feature to fix those problems. ## NOTES -- Base SDK (well kinda...) used by this project is developed by [Maurice Heumann](https://github.com/momo5502); Thanks to the guy. +- Base Software Framework used by this project is initially authored by [Maurice Heumann](https://github.com/momo5502). furthermore its been improved and refined by us to support feature expansions. - There are some 3rd-party project/tools that have influenced and helped the project in particular ways; If you belive there is something originated from you and want to be credited, please contact any of our social media accounts. @@ -45,7 +48,6 @@ The Github Issues section is only for reporting programmatical errors related to - [x] GSC & Lua Modding Support - [ ] Enable Aim-Assist for Game Controllers - [ ] Miscellaneous Features such as 1st-Person View FOV -- [ ] Fix *uncommon* Runtime "Black Screen" issue along other instabilities ### SERVER-SIDE: - [x] Fully Functional Online Server Emulator diff --git a/premake5.lua b/premake5.lua index 6e2748c..13a1455 100644 --- a/premake5.lua +++ b/premake5.lua @@ -318,11 +318,13 @@ project "shared-code" dependencies.imports() + disablewarnings { "4244" } + project "proxy-dll" kind "SharedLib" language "C++" - targetname "d3d11" + targetname "XInput9_1_0" pchheader "std_include.hpp" pchsource "source/proxy-dll/std_include.cpp" @@ -340,7 +342,8 @@ project "proxy-dll" end dependencies.imports() - + + disablewarnings { "4244" } group "Dependencies" dependencies.projects() diff --git a/source/proxy-dll/component/console.cpp b/source/proxy-dll/component/console.cpp index 0bcc814..7776846 100644 --- a/source/proxy-dll/component/console.cpp +++ b/source/proxy-dll/component/console.cpp @@ -13,7 +13,7 @@ namespace console namespace { const char* branding_str = "shield> "; - size_t branding_length = std::strlen(branding_str); + int branding_length = static_cast(std::strlen(branding_str)); utilities::hook::detour printf_hook; std::recursive_mutex print_mutex; diff --git a/source/proxy-dll/component/game_console.cpp b/source/proxy-dll/component/game_console.cpp index 16b5258..9ff8e0a 100644 --- a/source/proxy-dll/component/game_console.cpp +++ b/source/proxy-dll/component/game_console.cpp @@ -129,7 +129,7 @@ namespace game_console con.screen_max[1] = game::ScrPlace_GetView(0)->realViewportSize[1] - 6.0f; con.font_height = static_cast(game::UI_TextHeight(R_DrawTextFont, con.font_scale)); - con.visible_line_count = static_cast((con.screen_max[1] - con.screen_min[1] - (con.font_height * 2)) - 24.0f) / con.font_height; + con.visible_line_count = static_cast(((con.screen_max[1] - con.screen_min[1] - (con.font_height * 2)) - 24.0f) / con.font_height); } void draw_box(const float x, const float y, const float w, const float h, float* color) @@ -376,9 +376,9 @@ namespace game_console auto height = ((con.screen_max[1] - con.screen_min[1]) - 32.0f) - 12.0f; char sysinfo_version[256]; - bool result1 = utilities::hook::invoke(game::Live_SystemInfo, 0, 0, sysinfo_version, 256); + utilities::hook::invoke(game::Live_SystemInfo, 0, 0, sysinfo_version, 256); char sysinfo_livebits[256]; - bool result2 = utilities::hook::invoke(game::Live_SystemInfo, 0, 1, sysinfo_livebits, 256); + utilities::hook::invoke(game::Live_SystemInfo, 0, 1, sysinfo_livebits, 256); const char* info = utilities::string::va("Project-BO4 1.0.0, Engine Version: %s, LiveBits: %s", sysinfo_version, sysinfo_livebits); game::R_AddCmdDrawText(info, 0x7FFFFFFF, R_DrawTextFont, x, ((height - 16.0f) + y) + con.font_height, con.font_scale, con.font_scale, 0.0f, con_outputVersionStringColor, 0); diff --git a/source/proxy-dll/component/logger.cpp b/source/proxy-dll/component/logger.cpp index 38a5ddc..2af2b9a 100644 --- a/source/proxy-dll/component/logger.cpp +++ b/source/proxy-dll/component/logger.cpp @@ -18,10 +18,6 @@ namespace logger void write(const int type, std::string str) { -#ifndef _DEBUG - if (type == LOG_TYPE_DEBUG) return; -#endif // _DEBUG - game_console::print(str); if (type == type::LOG_TYPE_CONSOLE) return; @@ -39,8 +35,10 @@ namespace logger fs.open("project-bo4.log", std::ios_base::app); time_t now = time(0); - std::tm* t = std::localtime(&now); - fs << "" << std::put_time(t, "%Y-%m-%d %H:%M:%S") << "\t" << text; + std::tm time; + localtime_s(&time, &now); + + fs << "" << std::put_time(&time, "%Y-%m-%d %H:%M:%S") << "\t" << text; } void write(const int type, const char* fmt, ...) diff --git a/source/proxy-dll/component/unlockall.cpp b/source/proxy-dll/component/unlockall.cpp index 7e0f9a2..7091840 100644 --- a/source/proxy-dll/component/unlockall.cpp +++ b/source/proxy-dll/component/unlockall.cpp @@ -10,7 +10,7 @@ namespace unlockall { namespace { - uint32_t zm_loot_table[] = + int zm_loot_table[] = { 1000001, // zm_bgb_ctrl_z 1000002, // zm_bgb_dead_of_nuclear_winter diff --git a/source/proxy-dll/demonware/byte_buffer.hpp b/source/proxy-dll/demonware/byte_buffer.hpp index 50c4e22..e0da15c 100644 --- a/source/proxy-dll/demonware/byte_buffer.hpp +++ b/source/proxy-dll/demonware/byte_buffer.hpp @@ -111,7 +111,7 @@ namespace demonware const auto using_types = this->is_using_data_types(); this->set_use_data_types(false); - auto result = write_array_header(type, vec.size(), sizeof(T)); + auto result = write_array_header(type, INT(vec.size()), sizeof(T)); for (size_t i = 0; i < vec.size(); i++) { @@ -128,7 +128,7 @@ namespace demonware const auto using_types = this->is_using_data_types(); this->set_use_data_types(false); - auto result = write_array_header(type, map.size() * 2, sizeof(T)); + auto result = write_array_header(type, INT(map.size()) * 2, sizeof(T)); for (const auto& item : map) { diff --git a/source/proxy-dll/demonware/fileshare.cpp b/source/proxy-dll/demonware/fileshare.cpp index b0b6071..a713db4 100644 --- a/source/proxy-dll/demonware/fileshare.cpp +++ b/source/proxy-dll/demonware/fileshare.cpp @@ -73,17 +73,17 @@ namespace demonware::fileshare rapidjson::Document jsonDocument(rapidjson::kObjectType); rapidjson::Document::AllocatorType& allocator = jsonDocument.GetAllocator(); - jsonDocument.AddMember("status", this->status, allocator); + jsonDocument.AddMember("status", this->state, allocator); jsonDocument.AddMember("category", this->category, allocator); - jsonDocument.AddMember("fileName", this->fileName, allocator); - if (this->status == FILE_STATUS_UPLOADED || this->status == FILE_STATUS_DESCRIBED) { - jsonDocument.AddMember("fileSize", this->fileSize, allocator); + jsonDocument.AddMember("fileName", this->ioFileName, allocator); + if (this->state == FILE_STATE_UPLOADED || this->state == FILE_STATE_DESCRIBED) { + jsonDocument.AddMember("fileSize", this->ioFileSize, allocator); } rapidjson::Value fileInfo(rapidjson::kObjectType); fileInfo.AddMember("id", this->file.id, allocator); fileInfo.AddMember("name", this->file.name, allocator); - if (this->status == FILE_STATUS_UPLOADED || this->status == FILE_STATUS_DESCRIBED) { + if (this->state == FILE_STATE_UPLOADED || this->state == FILE_STATE_DESCRIBED) { fileInfo.AddMember("size", this->file.size, allocator); } fileInfo.AddMember("timestamp", this->file.timestamp, allocator); @@ -94,7 +94,7 @@ namespace demonware::fileshare fileAuthor.AddMember("xuid", this->author.xuid, allocator); jsonDocument.AddMember("author", fileAuthor, allocator); - if (this->status == FILE_STATUS_DESCRIBED) { + if (this->state == FILE_STATE_DESCRIBED) { rapidjson::Value fileTags(rapidjson::kObjectType); for (const auto& tag : this->tags) { @@ -103,7 +103,7 @@ namespace demonware::fileshare } jsonDocument.AddMember("tags", fileTags, allocator); - jsonDocument.AddMember("metadata", utilities::cryptography::base64::encode(ddl_metadata), allocator); + jsonDocument.AddMember("metadata", utilities::cryptography::base64::encode(ddlMetadata), allocator); } rapidjson::StringBuffer strbuf; @@ -119,7 +119,7 @@ namespace demonware::fileshare jsonDocument.Parse(MetaDoc); if (jsonDocument.HasMember("status") && jsonDocument["status"].IsInt()) { - this->status = static_cast(jsonDocument["status"].GetInt()); + this->state = static_cast(jsonDocument["status"].GetInt()); } if (jsonDocument.HasMember("category") && jsonDocument["category"].IsInt()) { @@ -127,13 +127,13 @@ namespace demonware::fileshare } if (jsonDocument.HasMember("fileName") && jsonDocument["fileName"].IsString()) { - this->fileName = jsonDocument["fileName"].GetString(); + this->ioFileName = jsonDocument["fileName"].GetString(); } - if ((this->status == FILE_STATUS_UPLOADED || this->status == FILE_STATUS_DESCRIBED) - && jsonDocument.HasMember("fileSize") && jsonDocument["fileSize"].IsUint64()) + if ((this->state == FILE_STATE_UPLOADED || this->state == FILE_STATE_DESCRIBED) + && jsonDocument.HasMember("fileSize") && jsonDocument["fileSize"].IsUint()) { - this->fileSize = jsonDocument["fileSize"].GetUint64(); + this->ioFileSize = jsonDocument["fileSize"].GetUint(); } if (jsonDocument.HasMember("file") && jsonDocument["file"].IsObject()) @@ -147,7 +147,7 @@ namespace demonware::fileshare this->file.name = fileInfo["name"].GetString(); this->file.timestamp = fileInfo["timestamp"].GetUint(); } - if ((this->status == FILE_STATUS_UPLOADED || this->status == FILE_STATUS_DESCRIBED) + if ((this->state == FILE_STATE_UPLOADED || this->state == FILE_STATE_DESCRIBED) && fileInfo.HasMember("size") && fileInfo["size"].IsUint()) { this->file.size = fileInfo["size"].GetUint(); @@ -165,7 +165,7 @@ namespace demonware::fileshare } } - if (this->status == FILE_STATUS_DESCRIBED) { + if (this->state == FILE_STATE_DESCRIBED) { if (jsonDocument.HasMember("tags") && jsonDocument["tags"].IsObject()) { rapidjson::Value& fileTags = jsonDocument["tags"]; @@ -181,39 +181,39 @@ namespace demonware::fileshare { rapidjson::Value& ddl_field = jsonDocument["metadata"]; std::string metadata_b64(ddl_field.GetString(), ddl_field.GetStringLength()); - this->ddl_metadata = utilities::cryptography::base64::decode(metadata_b64); + this->ddlMetadata = utilities::cryptography::base64::decode(metadata_b64); } } - if (this->status == FILE_STATUS_DESCRIBED) { - return (this->fileName.size() && this->file.id && this->ddl_metadata.size()); + if (this->state == FILE_STATE_DESCRIBED) { + return (this->ioFileName.size() && this->file.id && this->ddlMetadata.size()); } - else if (this->status == FILE_STATUS_UPLOADED) { - return (this->fileName.size() && this->file.id && this->fileSize); + else if (this->state == FILE_STATE_UPLOADED) { + return (this->ioFileName.size() && this->file.id && this->ioFileSize); } else { - return (this->fileName.size() && this->file.id && this->file.name.size()); + return (this->ioFileName.size() && this->file.id && this->file.name.size()); } } bool FileMetadata::MetadataTaskResult(bdFileMetaData* output, bool download) { - if (this->status == FILE_STATUS_DESCRIBED) + if (this->state == FILE_STATE_DESCRIBED) { output->m_fileID = this->file.id; output->m_createTime = this->file.timestamp; output->m_modifedTime = output->m_createTime; - output->m_fileSize = this->fileSize; + output->m_fileSize = this->ioFileSize; output->m_ownerID = this->author.xuid; output->m_ownerName = this->author.name; output->m_fileSlot = 0; output->m_fileName = this->file.name; output->m_category = this->category; - output->m_metaData = this->ddl_metadata; + output->m_metaData = this->ddlMetadata; output->m_summaryFileSize = 0; // what!? if (download) { - output->m_url = get_file_url(this->fileName); + output->m_url = get_file_url(this->ioFileName); } else { output->m_tags = this->tags; @@ -226,23 +226,23 @@ namespace demonware::fileshare } } - bool FileMetadata::ReadMetaDataJson(const std::string& file, file_status expect) + bool FileMetadata::ReadMetaDataJson(const std::string& path, file_state expect) { std::string json; - if (utilities::io::read_file(file, &json)) + if (utilities::io::read_file(path, &json)) { return (this->ParseMetaJSON(json) - && (this->status == expect || expect == FILE_STATUS_UNKNOWN)); + && (this->state == expect || expect == FILE_STATE_UNKNOWN)); } else { return false; } } - bool FileMetadata::WriteMetaDataJson(const std::string& file, file_status status) + bool FileMetadata::WriteMetaDataJson(const std::string& path, file_state _state) { - if(status != FILE_STATUS_UNKNOWN) this->status = status; - return utilities::io::write_file(file, this->SerializeMetaJSON()); + if(_state != FILE_STATE_UNKNOWN) this->state = _state; + return utilities::io::write_file(path, this->SerializeMetaJSON()); } std::vector fileshare_list_demo_ids() diff --git a/source/proxy-dll/demonware/fileshare.hpp b/source/proxy-dll/demonware/fileshare.hpp index 2064b96..5f9fbcf 100644 --- a/source/proxy-dll/demonware/fileshare.hpp +++ b/source/proxy-dll/demonware/fileshare.hpp @@ -5,7 +5,7 @@ namespace demonware::fileshare { const char* get_fileshare_host_name(); - enum fileshareCategory_e + enum fileshareCategory_e : uint16_t { FILESHARE_CATEGORY_ALL = 0, FILESHARE_CATEGORY_CONTENT_SERVER_START = 1, @@ -38,7 +38,7 @@ namespace demonware::fileshare FILESHARE_CATEGORY_MDLC_LAST = 1999, FILESHARE_CATEGORY_AVI = 32768, FILESHARE_CATEGORY_EXEMONITOR = 32769, - FILESHARE_CATEGORY_INVALID = -1 + FILESHARE_CATEGORY_INVALID = 0xFFFF }; const char* get_category_extension(fileshareCategory_e cat); @@ -59,14 +59,14 @@ namespace demonware::fileshare FileMetadata() = default; ~FileMetadata() = default; - enum file_status + enum file_state { - FILE_STATUS_UNKNOWN = 0, - FILE_STATUS_INVALID = -1, - FILE_STATUS_UPLOADING = 1, - FILE_STATUS_UPLOADED = 2, - FILE_STATUS_DESCRIBED = 3 - } status{}; + FILE_STATE_UNKNOWN = 0, + FILE_STATE_INVALID = -1, + FILE_STATE_UPLOADING = 1, + FILE_STATE_UPLOADED = 2, + FILE_STATE_DESCRIBED = 3 + } state{}; struct file_info { @@ -83,20 +83,19 @@ namespace demonware::fileshare } author{}; fileshareCategory_e category = FILESHARE_CATEGORY_ALL; - std::string fileName = ""; - size_t fileSize = 0; - std::string ddl_metadata = ""; + std::string ioFileName = ""; + uint32_t ioFileSize = 0; + std::string ddlMetadata = ""; std::map tags; bool MetadataTaskResult(bdFileMetaData* output, bool download); - bool ReadMetaDataJson(const std::string& file, file_status expect = FILE_STATUS_UNKNOWN); - bool WriteMetaDataJson(const std::string& file, file_status status = FILE_STATUS_UNKNOWN); + bool ReadMetaDataJson(const std::string& path, file_state expect = FILE_STATE_UNKNOWN); + bool WriteMetaDataJson(const std::string& path, file_state _state = FILE_STATE_UNKNOWN); private: std::string SerializeMetaJSON(); bool ParseMetaJSON(const std::string& input); - }; std::vector fileshare_list_demo_ids(); diff --git a/source/proxy-dll/demonware/objects.cpp b/source/proxy-dll/demonware/objects.cpp index 1ad0e78..9ef5c88 100644 --- a/source/proxy-dll/demonware/objects.cpp +++ b/source/proxy-dll/demonware/objects.cpp @@ -1,7 +1,7 @@ #include #include "objects.hpp" -#include "protobuf_helper.hpp" +#include "protobuf.hpp" #include "resource.hpp" #include diff --git a/source/proxy-dll/demonware/protobuf.cpp b/source/proxy-dll/demonware/protobuf.cpp new file mode 100644 index 0000000..e45a1e0 --- /dev/null +++ b/source/proxy-dll/demonware/protobuf.cpp @@ -0,0 +1,73 @@ +#include +#include "protobuf.hpp" + +bool bdProtobufHelper::encodeVarInt(uint64_t value) { + char valuea[16]; + size_t index = 0; + + if (value) { + while (value >= 0x80 && index < 10) { + valuea[index++] = static_cast(value | 0x80); + value >>= 7; + } + valuea[index++] = static_cast(value); + } + else { + valuea[index++] = 0; + } + + this->buffer.append(valuea, index); + this->length += index; + return true; +} + +bool bdProtobufHelper::encodeVarInt(int64_t value) { + uint64_t encodedValue = 2 * static_cast(value); + if (value < 0) { + encodedValue = ~encodedValue; + } + return encodeVarInt(encodedValue); +} + +bool bdProtobufHelper::encodeString(const char* value, uint32_t len) { + bool result = encodeVarInt(static_cast(len)); + if (result) { + this->buffer.append(value, len); + this->length += len; + } + return result; +} + +bool bdProtobufHelper::encodeTag(uint32_t tagId, eWireType wireType) { + uint64_t tag = static_cast(wireType) | (static_cast(tagId) << 3); + return encodeVarInt(tag); +} + +bool bdProtobufHelper::writeInt64(uint32_t tag, int64_t value) { + return encodeTag(tag, WIRETYPE_VARINT) && encodeVarInt(value); +} + +bool bdProtobufHelper::writeUInt64(uint32_t tag, uint64_t value) { + return encodeTag(tag, WIRETYPE_VARINT) && encodeVarInt(value); +} + +bool bdProtobufHelper::writeInt32(uint32_t tag, int32_t value) { + return encodeTag(tag, WIRETYPE_VARINT) && encodeVarInt(static_cast(value)); +} + +bool bdProtobufHelper::writeUInt32(uint32_t tag, uint32_t value) { + return encodeTag(tag, WIRETYPE_VARINT) && encodeVarInt(static_cast(value)); +} + +bool bdProtobufHelper::writeString(uint32_t tag, const char* value, uint32_t size) { + uint32_t actualSize = size; + const void* nullPos = memchr(value, 0, size); + if (nullPos) { + actualSize = static_cast(static_cast(nullPos) - value); + } + return encodeTag(tag, WIRETYPE_STRING) && encodeString(value, actualSize); +} + +bool bdProtobufHelper::writeBlob(uint32_t tag, void* data, uint32_t size) { + return encodeTag(tag, WIRETYPE_STRING) && encodeString(reinterpret_cast(data), size); +} diff --git a/source/proxy-dll/demonware/protobuf_helper.hpp b/source/proxy-dll/demonware/protobuf.hpp similarity index 73% rename from source/proxy-dll/demonware/protobuf_helper.hpp rename to source/proxy-dll/demonware/protobuf.hpp index b49ceae..89d55e0 100644 --- a/source/proxy-dll/demonware/protobuf_helper.hpp +++ b/source/proxy-dll/demonware/protobuf.hpp @@ -10,29 +10,24 @@ enum eWireType WIRETYPE_INVALID = -1 }; -class bdProtobufHelper -{ +class bdProtobufHelper { public: - std::string buffer{}; - uint32_t length{}; + std::string buffer; + size_t length = 0; - bdProtobufHelper(); - ~bdProtobufHelper(); + bdProtobufHelper() = default; + ~bdProtobufHelper() = default; - bool write(const void* value, uint32_t byteCount); - bool writeString(uint32_t tag, const char* value, uint32_t size); - bool writeBlob(uint32_t tag, void* buffer, uint32_t size); + bool encodeString(const char* value, uint32_t len); + bool encodeTag(uint32_t tagId, eWireType wireType); bool writeInt64(uint32_t tag, int64_t value); bool writeUInt64(uint32_t tag, uint64_t value); bool writeInt32(uint32_t tag, int32_t value); bool writeUInt32(uint32_t tag, uint32_t value); - + bool writeString(uint32_t tag, const char* value, uint32_t size); + bool writeBlob(uint32_t tag, void* data, uint32_t size); private: - bool encodeTag(uint32_t tagId, eWireType wireType); - bool encodeVarInt(int64_t value); bool encodeVarInt(uint64_t value); - bool encodeString(const char* value, uint32_t len); - - + bool encodeVarInt(int64_t value); }; \ No newline at end of file diff --git a/source/proxy-dll/demonware/protobuf_helper.cpp b/source/proxy-dll/demonware/protobuf_helper.cpp deleted file mode 100644 index 7f18d35..0000000 --- a/source/proxy-dll/demonware/protobuf_helper.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include -#include "protobuf_helper.hpp" -#include "ida_defs.h" - -bdProtobufHelper::bdProtobufHelper() {} -bdProtobufHelper::~bdProtobufHelper() {} - -/* Yes we unlocked next level of copy-pasta; someone bring the trophy :) */ - -bool bdProtobufHelper::encodeVarInt(uint64_t value) -{ - __int64 v2; // rbx - unsigned __int64 v4; // rax - char v5; // cl - char valuea[16]; // [rsp+20h] [rbp-28h] BYREF - - v2 = 0i64; - if (value) - { - do - { - if ((unsigned int)v2 >= 0xA) - break; - v4 = value; - v5 = value | 0x80; - value >>= 7; - valuea[v2] = v5; - v2 = (unsigned int)(v2 + 1); - } while (v4 >= 0x80); - valuea[(unsigned int)(v2 - 1)] &= 0x7Fu; - } - else - { - valuea[0] = 0; - LODWORD(v2) = 1; - } - //return bdStructSerializationOutputStream::write(stream, valuea, v2) == (_DWORD)v2; - this->buffer.append(std::string(valuea, v2)); - this->length += v2; - - return true; -} - -bool bdProtobufHelper::encodeVarInt(int64_t value) -{ - unsigned __int64 v2; // rax - - v2 = 2 * value; - if (value < 0) - v2 = ~v2; - return bdProtobufHelper::encodeVarInt(v2); -} - -bool bdProtobufHelper::encodeString(const char* value, uint32_t len) -{ - bool result; // al - - result = bdProtobufHelper::encodeVarInt(static_cast(len)); - if (result) - { - this->buffer.append(std::string(value, len)); - this->length += len; - } - //result = bdStructSerializationOutputStream::write(stream, value, len) == len; - - return result; -} - -bool bdProtobufHelper::encodeTag(uint32_t tagId, eWireType wireType) -{ - unsigned __int64 tag = (int)wireType | (8i64 * tagId); - return bdProtobufHelper::encodeVarInt(tag); -} - -bool bdProtobufHelper::writeInt64(uint32_t tag, int64_t value) -{ - return bdProtobufHelper::encodeTag(tag, WIRETYPE_VARINT) && bdProtobufHelper::encodeVarInt(value); -} - -bool bdProtobufHelper::writeUInt64(uint32_t tag, uint64_t value) -{ - return bdProtobufHelper::encodeTag(tag, WIRETYPE_VARINT) && bdProtobufHelper::encodeVarInt(value); -} - -bool bdProtobufHelper::writeInt32(uint32_t tag, int32_t value) -{ - return bdProtobufHelper::encodeTag(tag, WIRETYPE_VARINT) && bdProtobufHelper::encodeVarInt(static_cast(value)); -} - -bool bdProtobufHelper::writeUInt32(uint32_t tag, uint32_t value) -{ - return bdProtobufHelper::encodeTag(tag, WIRETYPE_VARINT) && bdProtobufHelper::encodeVarInt(static_cast(value)); -} - -bool bdProtobufHelper::writeString(uint32_t tag, const char* value, uint32_t size) -{ - unsigned int v5; // edi - const void* v8; // rax - - v5 = size; - v8 = memchr(value, 0, size); - if (v8) - v5 = (_DWORD)v8 - (_DWORD)value; - return bdProtobufHelper::encodeTag(tag, WIRETYPE_STRING) && bdProtobufHelper::encodeString(value, v5); -} - -bool bdProtobufHelper::writeBlob(uint32_t tag, void* buffer, uint32_t size) -{ - return bdProtobufHelper::encodeTag(tag, WIRETYPE_STRING) && bdProtobufHelper::encodeString(reinterpret_cast(buffer), size); -} \ No newline at end of file diff --git a/source/proxy-dll/demonware/services/bdObjectStore.cpp b/source/proxy-dll/demonware/services/bdObjectStore.cpp index 12a5dca..7b3b841 100644 --- a/source/proxy-dll/demonware/services/bdObjectStore.cpp +++ b/source/proxy-dll/demonware/services/bdObjectStore.cpp @@ -141,11 +141,10 @@ namespace demonware std::vector uploaded_objects_list; const rapidjson::Value& objects = vectorized_upload_json["objects"]; - for (rapidjson::SizeType i = 0; i < objects.Size(); i++) // Uses SizeType instead of size_t + for (rapidjson::SizeType i = 0; i < objects.Size(); i++) { const rapidjson::Value& content = objects[i]["content"]; const rapidjson::Value& name = objects[i]["metadata"]["name"]; - const rapidjson::Value& checksum = objects[i]["metadata"]["checksum"]; std::string data = utilities::cryptography::base64::decode(content.GetString()); const auto path = std::format("{}/{}", platform::get_userdata_directory(), name.GetString()); diff --git a/source/proxy-dll/demonware/services/bdPooledStorage.cpp b/source/proxy-dll/demonware/services/bdPooledStorage.cpp index 39835bc..849de19 100644 --- a/source/proxy-dll/demonware/services/bdPooledStorage.cpp +++ b/source/proxy-dll/demonware/services/bdPooledStorage.cpp @@ -34,8 +34,8 @@ namespace demonware std::string metafile = fileshare::get_metadata_path(fileshare::get_file_name(fileID)); fileshare::FileMetadata metadata; - if (metadata.ReadMetaDataJson(metafile, metadata.FILE_STATUS_DESCRIBED) - && utilities::io::file_exists(fileshare::get_file_path(metadata.fileName))) + if (metadata.ReadMetaDataJson(metafile, metadata.FILE_STATE_DESCRIBED) + && utilities::io::file_exists(fileshare::get_file_path(metadata.ioFileName))) { auto taskResult = new bdFileMetaData; metadata.MetadataTaskResult(taskResult, false); @@ -64,14 +64,14 @@ namespace demonware metadata.author.name = platform::bnet_get_username(); metadata.category = static_cast(category); - metadata.fileName = fileshare::get_file_name(metadata.file.id, metadata.category); + metadata.ioFileName = fileshare::get_file_name(metadata.file.id, metadata.category); - metadata.WriteMetaDataJson(fileshare::get_metadata_path(metadata.fileName), metadata.FILE_STATUS_UPLOADING); + metadata.WriteMetaDataJson(fileshare::get_metadata_path(metadata.ioFileName), metadata.FILE_STATE_UPLOADING); auto reply = server->create_reply(this->task_id()); auto result = new bdURL; - result->m_url = fileshare::get_file_url(metadata.fileName); + result->m_url = fileshare::get_file_url(metadata.ioFileName); result->m_serverType = 8; result->m_serverIndex = "fs"; result->m_fileID = metadata.file.id; @@ -94,10 +94,11 @@ namespace demonware fileshare::FileMetadata metadata; if (metadata.ReadMetaDataJson(metafile)) { + auto ioSize = utilities::io::file_size(fileshare::get_file_path(metadata.ioFileName)); metadata.file.size = fileSize; - metadata.fileSize = utilities::io::file_size(fileshare::get_file_path(metadata.fileName)); + metadata.ioFileSize = static_cast(ioSize); - metadata.WriteMetaDataJson(metafile, metadata.FILE_STATUS_UPLOADED); + metadata.WriteMetaDataJson(metafile, metadata.FILE_STATE_UPLOADED); } auto reply = server->create_reply(this->task_id()); @@ -124,8 +125,8 @@ namespace demonware std::string metafile = fileshare::get_metadata_path(fileshare::get_file_name(fileID)); fileshare::FileMetadata metadata; - if (metadata.ReadMetaDataJson(metafile, metadata.FILE_STATUS_DESCRIBED) - && utilities::io::file_exists(fileshare::get_file_path(metadata.fileName))) + if (metadata.ReadMetaDataJson(metafile, metadata.FILE_STATE_DESCRIBED) + && utilities::io::file_exists(fileshare::get_file_path(metadata.ioFileName))) { auto reply = server->create_reply(this->task_id()); @@ -145,7 +146,6 @@ namespace demonware void bdPooledStorage::_preUploadSummary(service_server* server, byte_buffer* buffer) const { uint64_t fileID{}; uint32_t fileSize{}; - //std::string DDL_MetaData; buffer->read_uint64(&fileID); buffer->read_uint32(&fileSize); @@ -153,10 +153,10 @@ namespace demonware fileshare::FileMetadata metadata; if (metadata.ReadMetaDataJson(metafile)) { - buffer->read_blob(&metadata.ddl_metadata); + buffer->read_blob(&metadata.ddlMetadata); buffer->read_array(10, &metadata.tags); - metadata.WriteMetaDataJson(metafile, metadata.FILE_STATUS_DESCRIBED); + metadata.WriteMetaDataJson(metafile, metadata.FILE_STATE_DESCRIBED); } auto reply = server->create_reply(this->task_id(), 108/*BD_SERVICE_NOT_AVAILABLE*/); diff --git a/source/proxy-dll/ida_defs.h b/source/proxy-dll/ida_defs.h deleted file mode 100644 index 2763084..0000000 --- a/source/proxy-dll/ida_defs.h +++ /dev/null @@ -1,380 +0,0 @@ -/* - - This file contains definitions used by the Hex-Rays decompiler output. - It has type definitions and convenience macros to make the - output more readable. - - Copyright (c) 2007-2017 Hex-Rays - -*/ - -#ifndef HEXRAYS_DEFS_H -#define HEXRAYS_DEFS_H - -#if defined(__GNUC__) -typedef long long ll; -typedef unsigned long long ull; -#define __int64 long long -#define __int32 int -#define __int16 short -#define __int8 char -#define MAKELL(num) num ## LL -#define FMT_64 "ll" -#elif defined(_MSC_VER) -typedef __int64 ll; -typedef unsigned __int64 ull; -#define MAKELL(num) num ## i64 -#define FMT_64 "I64" -#elif defined (__BORLANDC__) -typedef __int64 ll; -typedef unsigned __int64 ull; -#define MAKELL(num) num ## i64 -#define FMT_64 "L" -#else -#error "unknown compiler" -#endif -typedef unsigned int uint; -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef unsigned long ulong; - -typedef char int8; -typedef signed char sint8; -typedef unsigned char uint8; -typedef short int16; -typedef signed short sint16; -typedef unsigned short uint16; -typedef int int32; -typedef signed int sint32; -typedef unsigned int uint32; -typedef ll int64; -typedef ll sint64; -typedef ull uint64; - -// Partially defined types. They are used when the decompiler does not know -// anything about the type except its size. -#define _BYTE uint8 -#define _WORD uint16 -#define _DWORD uint32 -#define _QWORD uint64 -#if !defined(_MSC_VER) -#define _LONGLONG __int128 -#endif - -// Non-standard boolean types. They are used when the decompiler can not use -// the standard "bool" type because of the size mistmatch but the possible -// values are only 0 and 1. See also 'BOOL' type below. -typedef int8 _BOOL1; -typedef int16 _BOOL2; -typedef int32 _BOOL4; - -#ifndef _WINDOWS_ -typedef int8 BYTE; -typedef int16 WORD; -typedef int32 DWORD; -typedef int32 LONG; -typedef int BOOL; // uppercase BOOL is usually 4 bytes -#endif -typedef int64 QWORD; -#ifndef __cplusplus -typedef int bool; // we want to use bool in our C programs -#endif - -#define __pure // pure function: always returns the same value, has no - // side effects - -// Non-returning function -#if defined(__GNUC__) -#define __noreturn __attribute__((noreturn)) -#else -#define __noreturn __declspec(noreturn) -#endif - - -#ifndef NULL -#define NULL 0 -#endif - -// Some convenience macros to make partial accesses nicer -#define LAST_IND(x,part_type) (sizeof(x)/sizeof(part_type) - 1) -#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN -# define LOW_IND(x,part_type) LAST_IND(x,part_type) -# define HIGH_IND(x,part_type) 0 -#else -# define HIGH_IND(x,part_type) LAST_IND(x,part_type) -# define LOW_IND(x,part_type) 0 -#endif -// first unsigned macros: -#define BYTEn(x, n) (*((_BYTE*)&(x)+n)) -#define WORDn(x, n) (*((_WORD*)&(x)+n)) -#define DWORDn(x, n) (*((_DWORD*)&(x)+n)) - -#define LOBYTE(x) BYTEn(x,LOW_IND(x,_BYTE)) -#define LOWORD(x) WORDn(x,LOW_IND(x,_WORD)) -#define LODWORD(x) DWORDn(x,LOW_IND(x,_DWORD)) -#define HIBYTE(x) BYTEn(x,HIGH_IND(x,_BYTE)) -#define HIWORD(x) WORDn(x,HIGH_IND(x,_WORD)) -#define HIDWORD(x) DWORDn(x,HIGH_IND(x,_DWORD)) -#define BYTE1(x) BYTEn(x, 1) // byte 1 (counting from 0) -#define BYTE2(x) BYTEn(x, 2) -#define BYTE3(x) BYTEn(x, 3) -#define BYTE4(x) BYTEn(x, 4) -#define BYTE5(x) BYTEn(x, 5) -#define BYTE6(x) BYTEn(x, 6) -#define BYTE7(x) BYTEn(x, 7) -#define BYTE8(x) BYTEn(x, 8) -#define BYTE9(x) BYTEn(x, 9) -#define BYTE10(x) BYTEn(x, 10) -#define BYTE11(x) BYTEn(x, 11) -#define BYTE12(x) BYTEn(x, 12) -#define BYTE13(x) BYTEn(x, 13) -#define BYTE14(x) BYTEn(x, 14) -#define BYTE15(x) BYTEn(x, 15) -#define WORD1(x) WORDn(x, 1) -#define WORD2(x) WORDn(x, 2) // third word of the object, unsigned -#define WORD3(x) WORDn(x, 3) -#define WORD4(x) WORDn(x, 4) -#define WORD5(x) WORDn(x, 5) -#define WORD6(x) WORDn(x, 6) -#define WORD7(x) WORDn(x, 7) - -// now signed macros (the same but with sign extension) -#define SBYTEn(x, n) (*((int8*)&(x)+n)) -#define SWORDn(x, n) (*((int16*)&(x)+n)) -#define SDWORDn(x, n) (*((int32*)&(x)+n)) - -#define SLOBYTE(x) SBYTEn(x,LOW_IND(x,int8)) -#define SLOWORD(x) SWORDn(x,LOW_IND(x,int16)) -#define SLODWORD(x) SDWORDn(x,LOW_IND(x,int32)) -#define SHIBYTE(x) SBYTEn(x,HIGH_IND(x,int8)) -#define SHIWORD(x) SWORDn(x,HIGH_IND(x,int16)) -#define SHIDWORD(x) SDWORDn(x,HIGH_IND(x,int32)) -#define SBYTE1(x) SBYTEn(x, 1) -#define SBYTE2(x) SBYTEn(x, 2) -#define SBYTE3(x) SBYTEn(x, 3) -#define SBYTE4(x) SBYTEn(x, 4) -#define SBYTE5(x) SBYTEn(x, 5) -#define SBYTE6(x) SBYTEn(x, 6) -#define SBYTE7(x) SBYTEn(x, 7) -#define SBYTE8(x) SBYTEn(x, 8) -#define SBYTE9(x) SBYTEn(x, 9) -#define SBYTE10(x) SBYTEn(x, 10) -#define SBYTE11(x) SBYTEn(x, 11) -#define SBYTE12(x) SBYTEn(x, 12) -#define SBYTE13(x) SBYTEn(x, 13) -#define SBYTE14(x) SBYTEn(x, 14) -#define SBYTE15(x) SBYTEn(x, 15) -#define SWORD1(x) SWORDn(x, 1) -#define SWORD2(x) SWORDn(x, 2) -#define SWORD3(x) SWORDn(x, 3) -#define SWORD4(x) SWORDn(x, 4) -#define SWORD5(x) SWORDn(x, 5) -#define SWORD6(x) SWORDn(x, 6) -#define SWORD7(x) SWORDn(x, 7) - - -// Helper functions to represent some assembly instructions. - -#ifdef __cplusplus - -// compile time assertion -#define __CASSERT_N0__(l) COMPILE_TIME_ASSERT_ ## l -#define __CASSERT_N1__(l) __CASSERT_N0__(l) -#define CASSERT(cnd) typedef char __CASSERT_N1__(__LINE__) [(cnd) ? 1 : -1] - -// check that unsigned multiplication does not overflow -template bool is_mul_ok(T count, T elsize) -{ - CASSERT((T)(-1) > 0); // make sure T is unsigned - if (elsize == 0 || count == 0) - return true; - return count <= ((T)(-1)) / elsize; -} - -// multiplication that saturates (yields the biggest value) instead of overflowing -// such a construct is useful in "operator new[]" -template bool saturated_mul(T count, T elsize) -{ - return is_mul_ok(count, elsize) ? count * elsize : T(-1); -} - -#include // for size_t - -// memcpy() with determined behavoir: it always copies -// from the start to the end of the buffer -// note: it copies byte by byte, so it is not equivalent to, for example, rep movsd -inline void* qmemcpy(void* dst, const void* src, size_t cnt) -{ - char* out = (char*)dst; - const char* in = (const char*)src; - while (cnt > 0) - { - *out++ = *in++; - --cnt; - } - return dst; -} - -// Generate a reference to pair of operands -template int16 __PAIR__(int8 high, T low) { return (((int16)high) << sizeof(high) * 8) | uint8(low); } -template int32 __PAIR__(int16 high, T low) { return (((int32)high) << sizeof(high) * 8) | uint16(low); } -template int64 __PAIR__(int32 high, T low) { return (((int64)high) << sizeof(high) * 8) | uint32(low); } -template uint16 __PAIR__(uint8 high, T low) { return (((uint16)high) << sizeof(high) * 8) | uint8(low); } -template uint32 __PAIR__(uint16 high, T low) { return (((uint32)high) << sizeof(high) * 8) | uint16(low); } -template uint64 __PAIR__(uint32 high, T low) { return (((uint64)high) << sizeof(high) * 8) | uint32(low); } - -// rotate left -template T __ROL__(T value, int count) -{ - const uint nbits = sizeof(T) * 8; - - if (count > 0) - { - count %= nbits; - T high = value >> (nbits - count); - if (T(-1) < 0) // signed value - high &= ~((T(-1) << count)); - value <<= count; - value |= high; - } - else - { - count = -count % nbits; - T low = value << (nbits - count); - value >>= count; - value |= low; - } - return value; -} - -inline uint8 __ROL1__(uint8 value, int count) { return __ROL__((uint8)value, count); } -inline uint16 __ROL2__(uint16 value, int count) { return __ROL__((uint16)value, count); } -inline uint32 __ROL4__(uint32 value, int count) { return __ROL__((uint32)value, count); } -inline uint64 __ROL8__(uint64 value, int count) { return __ROL__((uint64)value, count); } -inline uint8 __ROR1__(uint8 value, int count) { return __ROL__((uint8)value, -count); } -inline uint16 __ROR2__(uint16 value, int count) { return __ROL__((uint16)value, -count); } -inline uint32 __ROR4__(uint32 value, int count) { return __ROL__((uint32)value, -count); } -inline uint64 __ROR8__(uint64 value, int count) { return __ROL__((uint64)value, -count); } - -// carry flag of left shift -template int8 __MKCSHL__(T value, uint count) -{ - const uint nbits = sizeof(T) * 8; - count %= nbits; - - return (value >> (nbits - count)) & 1; -} - -// carry flag of right shift -template int8 __MKCSHR__(T value, uint count) -{ - return (value >> (count - 1)) & 1; -} - -// sign flag -template int8 __SETS__(T x) -{ - if (sizeof(T) == 1) - return int8(x) < 0; - if (sizeof(T) == 2) - return int16(x) < 0; - if (sizeof(T) == 4) - return int32(x) < 0; - return int64(x) < 0; -} - -// overflow flag of subtraction (x-y) -template int8 __OFSUB__(T x, U y) -{ - if (sizeof(T) < sizeof(U)) - { - U x2 = x; - int8 sx = __SETS__(x2); - return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2 - y)); - } - else - { - T y2 = y; - int8 sx = __SETS__(x); - return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x - y2)); - } -} - -// overflow flag of addition (x+y) -template int8 __OFADD__(T x, U y) -{ - if (sizeof(T) < sizeof(U)) - { - U x2 = x; - int8 sx = __SETS__(x2); - return ((1 ^ sx) ^ __SETS__(y)) & (sx ^ __SETS__(x2 + y)); - } - else - { - T y2 = y; - int8 sx = __SETS__(x); - return ((1 ^ sx) ^ __SETS__(y2)) & (sx ^ __SETS__(x + y2)); - } -} - -// carry flag of subtraction (x-y) -template int8 __CFSUB__(T x, U y) -{ - int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U); - if (size == 1) - return uint8(x) < uint8(y); - if (size == 2) - return uint16(x) < uint16(y); - if (size == 4) - return uint32(x) < uint32(y); - return uint64(x) < uint64(y); -} - -// carry flag of addition (x+y) -template int8 __CFADD__(T x, U y) -{ - int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U); - if (size == 1) - return uint8(x) > uint8(x + y); - if (size == 2) - return uint16(x) > uint16(x + y); - if (size == 4) - return uint32(x) > uint32(x + y); - return uint64(x) > uint64(x + y); -} - -#else -// The following definition is not quite correct because it always returns -// uint64. The above C++ functions are good, though. -#define __PAIR__(high, low) (((uint64)(high)<>y) -#define __CFADD__(x, y) invalid_operation // Generate carry flag for (x+y) -#define __CFSUB__(x, y) invalid_operation // Generate carry flag for (x-y) -#define __OFADD__(x, y) invalid_operation // Generate overflow flag for (x+y) -#define __OFSUB__(x, y) invalid_operation // Generate overflow flag for (x-y) -#endif - -// No definition for rcl/rcr because the carry flag is unknown -#define __RCL__(x, y) invalid_operation // Rotate left thru carry -#define __RCR__(x, y) invalid_operation // Rotate right thru carry -#define __MKCRCL__(x, y) invalid_operation // Generate carry flag for a RCL -#define __MKCRCR__(x, y) invalid_operation // Generate carry flag for a RCR -#define __SETP__(x, y) invalid_operation // Generate parity flag for (x-y) - -// In the decompilation listing there are some objects declarared as _UNKNOWN -// because we could not determine their types. Since the C compiler does not -// accept void item declarations, we replace them by anything of our choice, -// for example a char: - -#define _UNKNOWN char - -#ifdef _MSC_VER -#define snprintf _snprintf -#define vsnprintf _vsnprintf -#endif - -#endif // HEXRAYS_DEFS_H \ No newline at end of file diff --git a/source/proxy-dll/main.cpp b/source/proxy-dll/main.cpp index 188dcb9..ad3adb6 100644 --- a/source/proxy-dll/main.cpp +++ b/source/proxy-dll/main.cpp @@ -215,22 +215,47 @@ BOOL WINAPI DllMain(HINSTANCE, const DWORD reason, LPVOID) return TRUE; } -extern "C" __declspec(dllexport) -HRESULT D3D11CreateDevice(void* adapter, const uint64_t driver_type, - const HMODULE software, const UINT flags, - const void* p_feature_levels, const UINT feature_levels, - const UINT sdk_version, void** device, void* feature_level, - void** immediate_context) +extern "C" { - static auto func = [] + __declspec(dllexport) DWORD XInputGetCapabilities(DWORD dwUserIndex, DWORD dwFlags, struct XINPUT_CAPABILITIES* pCapabilities) { - char dir[MAX_PATH]{ 0 }; - GetSystemDirectoryA(dir, sizeof(dir)); + static auto func = [] + { + char dir[MAX_PATH]{ 0 }; + GetSystemDirectoryA(dir, sizeof(dir)); - const auto d3d11 = utilities::nt::library::load(dir + "/d3d11.dll"s); - return d3d11.get_proc("D3D11CreateDevice"); - }(); + const auto d3d12 = utilities::nt::library::load(dir + "/XInput9_1_0.dll"s); + return d3d12.get_proc("XInputGetCapabilities"); + }(); - return func(adapter, driver_type, software, flags, p_feature_levels, feature_levels, sdk_version, device, - feature_level, immediate_context); + return func(dwUserIndex, dwFlags, pCapabilities); + } + + __declspec(dllexport) DWORD XInputSetState(DWORD dwUserIndex, struct XINPUT_VIBRATION* pVibration) + { + static auto func = [] + { + char dir[MAX_PATH]{ 0 }; + GetSystemDirectoryA(dir, sizeof(dir)); + + const auto d3d12 = utilities::nt::library::load(dir + "/XInput9_1_0.dll"s); + return d3d12.get_proc("XInputSetState"); + }(); + + return func(dwUserIndex, pVibration); + } + + __declspec(dllexport) DWORD XInputGetState(DWORD dwUserIndex, struct XINPUT_STATE* pState) + { + static auto func = [] + { + char dir[MAX_PATH]{ 0 }; + GetSystemDirectoryA(dir, sizeof(dir)); + + const auto d3d12 = utilities::nt::library::load(dir + "/XInput9_1_0.dll"s); + return d3d12.get_proc("XInputGetState"); + }(); + + return func(dwUserIndex, pState); + } } diff --git a/source/shared-code/utilities/string.cpp b/source/shared-code/utilities/string.cpp index 8ba1cfe..80dacc3 100644 --- a/source/shared-code/utilities/string.cpp +++ b/source/shared-code/utilities/string.cpp @@ -262,17 +262,17 @@ namespace utilities::string return StringMatch::Mismatch; } - double match(const std::string& input, const std::string& text) + float match(const std::string& input, const std::string& text) { if (text == input) return 1.00; // identical - size_t offset = to_lower(text).find(to_lower(input)); + auto offset = to_lower(text).find(to_lower(input)); if (offset == std::string::npos) return 0.00; // mismatch - int len_variance = text.length() - input.length(); - int match_percent = 100 - (1 + len_variance + offset); + auto len_variance = text.length() - input.length(); + size_t match_percent = 100 - (1 + len_variance + offset); - return ((double)match_percent / 100); + return (static_cast(match_percent) / 100); } bool contains(std::string text, std::string substr, bool sensetive) diff --git a/source/shared-code/utilities/string.hpp b/source/shared-code/utilities/string.hpp index 711131e..1989a39 100644 --- a/source/shared-code/utilities/string.hpp +++ b/source/shared-code/utilities/string.hpp @@ -122,6 +122,6 @@ namespace utilities::string }; StringMatch compare(const std::string& s1, const std::string& s2); - double match(const std::string& input, const std::string& text); + float match(const std::string& input, const std::string& text); bool contains(std::string text, std::string substr, bool sensetive = false); }