diff --git a/README.md b/README.md index b4fb490..7030fd1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # T8-Mod + ![code](https://raw.githubusercontent.com/project-bo4/shield-development/master/assets/readme_header.jpg) ## SHIELD @@ -11,26 +12,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. @@ -46,7 +49,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 5eca082..748c202 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,3 +1,41 @@ +gitVersioningCommand = "git describe --tags --dirty --always" +gitCurrentBranchCommand = "git symbolic-ref -q --short HEAD" + +-- Quote the given string input as a C string +function cstrquote(value) + if value == nil then + return "\"\"" + end + result = value:gsub("\\", "\\\\") + result = result:gsub("\"", "\\\"") + result = result:gsub("\n", "\\n") + result = result:gsub("\t", "\\t") + result = result:gsub("\r", "\\r") + result = result:gsub("\a", "\\a") + result = result:gsub("\b", "\\b") + result = "\"" .. result .. "\"" + return result +end + +-- Converts tags in "vX.X.X" format and given revision number Y to an array of numbers {X,X,X,Y}. +-- In the case where the format does not work fall back to padding with zeroes and just ending with the revision number. +-- partscount can be either 3 or 4. +function vertonumarr(value, vernumber, partscount) + vernum = {} + for num in string.gmatch(value or "", "%d+") do + if #vernum < 3 then + table.insert(vernum, tonumber(num)) + end + end + while #vernum < 3 do + table.insert(vernum, 0) + end + if #vernum < partscount then + table.insert(vernum, tonumber(vernumber)) + end + return vernum +end + dependencies = { basePath = "./deps" } @@ -44,93 +82,270 @@ newoption { description = "Enable CI builds of the client." } +newaction { + trigger = "version", + description = "Returns the version string for the current commit of the source code.", + onWorkspace = function(wks) + -- get current version via git + local proc = assert(io.popen(gitVersioningCommand, "r")) + local gitDescribeOutput = assert(proc:read('*a')):gsub("%s+", "") + proc:close() + local version = gitDescribeOutput + + proc = assert(io.popen(gitCurrentBranchCommand, "r")) + local gitCurrentBranchOutput = assert(proc:read('*a')):gsub("%s+", "") + local gitCurrentBranchSuccess = proc:close() + if gitCurrentBranchSuccess then + -- We got a branch name, check if it is a feature branch + if gitCurrentBranchOutput ~= "develop" and gitCurrentBranchOutput ~= "master" then + version = version .. "-" .. gitCurrentBranchOutput + end + end + + print(version) + os.exit(0) + end +} + +newaction { + trigger = "generate-buildinfo", + description = "Sets up build information file like version.h.", + onWorkspace = function(wks) + -- get old version number from version.hpp if any + local oldVersion = "(none)" + local oldVersionHeader = io.open(wks.location .. "/s/version.h", "r") + if oldVersionHeader ~= nil then + local oldVersionHeaderContent = assert(oldVersionHeader:read('*l')) + while oldVersionHeaderContent do + m = string.match(oldVersionHeaderContent, "#define GIT_DESCRIBE (.+)%s*$") + if m ~= nil then + oldVersion = m + end + + oldVersionHeaderContent = oldVersionHeader:read('*l') + end + end + + -- get current version via git + local proc = assert(io.popen(gitVersioningCommand, "r")) + local gitDescribeOutput = assert(proc:read('*a')):gsub("%s+", "") + proc:close() + + -- generate version.hpp with a revision number if not equal + gitDescribeOutputQuoted = cstrquote(gitDescribeOutput) + if oldVersion ~= gitDescribeOutputQuoted then + -- get current git hash and write to version.txt (used by the preliminary updater) + -- TODO - remove once proper updater and release versioning exists + local proc = assert(io.popen("git rev-parse HEAD", "r")) + local gitCommitHash = assert(proc:read('*a')):gsub("%s+", "") + proc:close() + + -- get whether this is a clean revision (no uncommitted changes) + proc = assert(io.popen("git status --porcelain", "r")) + local revDirty = (assert(proc:read('*a')) ~= "") + if revDirty then revDirty = 1 else revDirty = 0 end + proc:close() + + -- get current tag name + proc = assert(io.popen("git describe --tags --abbrev=0")) + local tagName = proc:read('*l') + + -- get current branch name + proc = assert(io.popen("git branch --show-current")) + local branchName = proc:read('*l') + + -- branch for ci + if branchName == nil or branchName == '' then + proc = assert(io.popen("git show -s --pretty=%d HEAD")) + local branchInfo = proc:read('*l') + m = string.match(branchInfo, ".+,.+, ([^)]+)") + if m ~= nil then + branchName = m + end + end + + if branchName == nil then + branchName = "develop" + end + + print("Detected branch: " .. branchName) + + -- get revision number via git + local proc = assert(io.popen("git rev-list --count HEAD", "r")) + local revNumber = assert(proc:read('*a')):gsub("%s+", "") + + print ("Update " .. oldVersion .. " -> " .. gitDescribeOutputQuoted) + + -- write to version.txt for preliminary updater + -- NOTE - remove this once we have a proper updater and proper release versioning + local versionFile = assert(io.open(wks.location .. "/version.txt", "w")) + versionFile:write(gitCommitHash) + versionFile:close() + + -- write version header + local versionHeader = assert(io.open(wks.location .. "/src/version.h", "w")) + versionHeader:write("/*\n") + versionHeader:write(" * Automatically generated by premake5.\n") + versionHeader:write(" * Do not touch!\n") + versionHeader:write(" */\n") + versionHeader:write("\n") + versionHeader:write("#define GIT_DESCRIBE " .. gitDescribeOutputQuoted .. "\n") + versionHeader:write("#define GIT_DIRTY " .. revDirty .. "\n") + versionHeader:write("#define GIT_HASH " .. cstrquote(gitCommitHash) .. "\n") + versionHeader:write("#define GIT_TAG " .. cstrquote(tagName) .. "\n") + versionHeader:write("#define GIT_BRANCH " .. cstrquote(branchName) .. "\n") + versionHeader:write("\n") + versionHeader:write("// Version transformed for RC files\n") + versionHeader:write("#define VERSION_PRODUCT_RC " .. table.concat(vertonumarr(tagName, revNumber, 3), ",") .. "\n") + versionHeader:write("#define VERSION_PRODUCT " .. cstrquote(table.concat(vertonumarr(tagName, revNumber, 3), ".")) .. "\n") + versionHeader:write("#define VERSION_FILE_RC " .. table.concat(vertonumarr(tagName, revNumber, 4), ",") .. "\n") + versionHeader:write("#define VERSION_FILE " .. cstrquote(table.concat(vertonumarr(tagName, revNumber, 4), ".")) .. "\n") + versionHeader:write("\n") + versionHeader:write("// Alias definitions\n") + versionHeader:write("#define VERSION GIT_DESCRIBE\n") + versionHeader:write("#define SHORTVERSION VERSION_PRODUCT\n") + versionHeader:close() + local versionHeader = assert(io.open(wks.location .. "/src/version.hpp", "w")) + versionHeader:write("/*\n") + versionHeader:write(" * Automatically generated by premake5.\n") + versionHeader:write(" * Do not touch!\n") + versionHeader:write(" *\n") + versionHeader:write(" * This file exists for reasons of complying with our coding standards.\n") + versionHeader:write(" *\n") + versionHeader:write(" * The Resource Compiler will ignore any content from C++ header files if they're not from STDInclude.hpp.\n") + versionHeader:write(" * That's the reason why we now place all version info in version.h instead.\n") + versionHeader:write(" */\n") + versionHeader:write("\n") + versionHeader:write("#include \".\\version.h\"\n") + versionHeader:close() + end + end +} + +--DEFUALT + +dependencies = { + basePath = "./deps" +} + +function dependencies.load() + dir = path.join(dependencies.basePath, "premake/*.lua") + deps = os.matchfiles(dir) + + for i, dep in pairs(deps) do + dep = dep:gsub(".lua", "") + require(dep) + end +end + +function dependencies.imports() + for i, proj in pairs(dependencies) do + if type(i) == 'number' then + proj.import() + end + end +end + +function dependencies.projects() + for i, proj in pairs(dependencies) do + if type(i) == 'number' then + proj.project() + end + end +end dependencies.load() + workspace "shield-development" - startproject "proxy-dll" - location "./build" - objdir "%{wks.location}/obj" - targetdir "%{wks.location}/bin/%{cfg.platform}/%{cfg.buildcfg}" + startproject "proxy-dll" + location "./build" + objdir "%{wks.location}/obj" + targetdir "%{wks.location}/bin/%{cfg.platform}/%{cfg.buildcfg}" - configurations {"Debug", "Release"} + configurations {"Debug", "Release"} - language "C++" - cppdialect "C++20" + language "C++" + cppdialect "C++20" - architecture "x86_64" - platforms "x64" + architecture "x86_64" + platforms "x64" - systemversion "latest" - symbols "On" - staticruntime "On" - editandcontinue "Off" - warnings "Extra" - characterset "ASCII" + systemversion "latest" + symbols "On" + staticruntime "On" + editandcontinue "Off" + warnings "Extra" + characterset "ASCII" - if _OPTIONS["dev-build"] then - defines {"DEV_BUILD"} - end + if _OPTIONS["dev-build"] then + defines {"DEV_BUILD"} + end - if _OPTIONS["ci-build"] then - defines {"CI"} - end + if _OPTIONS["ci-build"] then + defines {"CI"} + end - flags {"NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks"} + flags {"NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks"} - filter "platforms:x64" - defines {"_WINDOWS", "WIN32"} - filter {} + filter "platforms:x64" + defines {"_WINDOWS", "WIN32"} + filter {} - filter "configurations:Release" - optimize "Size" - buildoptions {"/GL"} - linkoptions { "/IGNORE:4702", "/LTCG" } - defines {"NDEBUG"} - flags {"FatalCompileWarnings"} - warnings "off" - filter {} + filter "configurations:Release" + optimize "Size" + buildoptions {"/GL"} + linkoptions { "/IGNORE:4702", "/LTCG" } + defines {"NDEBUG"} + flags {"FatalCompileWarnings"} + warnings "off" + filter {} - filter "configurations:Debug" - optimize "Debug" - defines {"DEBUG", "_DEBUG"} - filter {} + filter "configurations:Debug" + optimize "Debug" + defines {"DEBUG", "_DEBUG"} + filter {} project "shared-code" - kind "StaticLib" - language "C++" + kind "StaticLib" + language "C++" - files {"./source/shared-code/**.hpp", "./source/shared-code/**.cpp"} + files {"./source/shared-code/**.hpp", "./source/shared-code/**.cpp"} - includedirs {"./source/shared-code", "%{prj.location}/src"} + includedirs {"./source/shared-code", "%{prj.location}/src"} - resincludedirs {"$(ProjectDir)src"} + resincludedirs {"$(ProjectDir)src"} - dependencies.imports() + dependencies.imports() + + disablewarnings { "4244" } project "proxy-dll" - kind "SharedLib" - language "C++" + kind "SharedLib" + language "C++" - targetname "d3d11" + targetname "XInput9_1_0" - pchheader "std_include.hpp" - pchsource "source/proxy-dll/std_include.cpp" + pchheader "std_include.hpp" + pchsource "source/proxy-dll/std_include.cpp" - files {"./source/proxy-dll/**.rc", "./source/proxy-dll/**.hpp", "./source/proxy-dll/**.cpp", "./source/proxy-dll/resources/**.*"} + files {"./source/proxy-dll/**.rc", "./source/proxy-dll/**.hpp", "./source/proxy-dll/**.cpp", "./source/proxy-dll/resources/**.*"} - includedirs {"./source/proxy-dll", "./source/shared-code", "%{prj.location}/src"} + includedirs {"./source/proxy-dll", "./source/shared-code", "%{prj.location}/src"} - resincludedirs {"$(ProjectDir)src"} + resincludedirs {"$(ProjectDir)src"} - links {"shared-code"} + links {"shared-code"} - if _OPTIONS["copy-to"] then - postbuildcommands {"copy /y \"$(TargetPath)\" \"" .. _OPTIONS["copy-to"] .. "\""} - end - - dependencies.imports() + if _OPTIONS["copy-to"] then + postbuildcommands {"copy /y \"$(TargetPath)\" \"" .. _OPTIONS["copy-to"] .. "\""} + end + dependencies.imports() + + disablewarnings { "4244" } group "Dependencies" - dependencies.projects() + dependencies.projects() + +prebuildcommands {"pushd %{_MAIN_SCRIPT_DIR}", "tools\\premake5 generate-buildinfo", "popd"} \ No newline at end of file diff --git a/source/proxy-dll/component/console.cpp b/source/proxy-dll/component/console.cpp index 57e8150..fe55905 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 = "T8-Mod >"; - 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/debugging.cpp b/source/proxy-dll/component/debugging.cpp index 1fe2cee..6d7bc66 100644 --- a/source/proxy-dll/component/debugging.cpp +++ b/source/proxy-dll/component/debugging.cpp @@ -1,6 +1,7 @@ #include #include "definitions/game.hpp" #include "component/scheduler.hpp" +#include "component/gsc_custom.hpp" #include "loader/component_loader.hpp" #include @@ -73,6 +74,12 @@ namespace debugging void sys_error_stub(uint32_t code, const char* message) { + if (code == gsc_custom::linking_error) + { + gsc_custom::find_linking_issues(); + return; // converted to runtime error to avoid the crash + } + const char* error_message = runtime_errors::get_error_message(code); if (error_message) diff --git a/source/proxy-dll/component/game_console.cpp b/source/proxy-dll/component/game_console.cpp index a7f590f..1a12739 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/gsc_custom.cpp b/source/proxy-dll/component/gsc_custom.cpp index 65708d3..81b598a 100644 --- a/source/proxy-dll/component/gsc_custom.cpp +++ b/source/proxy-dll/component/gsc_custom.cpp @@ -1,10 +1,13 @@ #include #include "gsc_custom.hpp" #include "gsc_funcs.hpp" +#include "hashes.hpp" #include "definitions/game.hpp" +#include "definitions/xassets.hpp" #include "loader/component_loader.hpp" #include #include +#include namespace gsc_custom { @@ -208,6 +211,20 @@ namespace gsc_custom inst_data.emplace_back(info); } + void vm_op_custom_devblock(game::scriptInstance_t inst, game::function_stack_t* fs_0, game::ScrVmContext_t* vmc, bool* terminate) + { + byte* base = align_ptr(fs_0->pos); + int16_t delta = *(int16_t*)base; + + fs_0->pos = base + 2; + + if (!gsc_funcs::enable_dev_blocks) { + // default action, jump after the dev block + fs_0->pos = fs_0->pos + delta; + } + } + + void vm_op_custom_lazylink(game::scriptInstance_t inst, game::function_stack_t* fs_0, game::ScrVmContext_t* vmc, bool* terminate) { byte* base = align_ptr(fs_0->pos); @@ -290,7 +307,212 @@ namespace gsc_custom } + void find_linking_issues() + { + logger::write(logger::LOG_TYPE_ERROR, "Linking error detected, searching cause..."); + + std::unordered_map> availables{}; + for (size_t _inst = 0; _inst < game::SCRIPTINSTANCE_MAX; _inst++) + { + size_t error{}; + game::scriptInstance_t inst = (game::scriptInstance_t)_inst; + for (size_t obj = 0; obj < game::gObjFileInfoCount[inst]; obj++) + { + game::objFileInfo_t& info = (*game::gObjFileInfo)[inst][obj]; + + if (!info.activeVersion) + { + continue; + } + + game::GSC_OBJ* prime_obj = info.activeVersion; + + availables.clear(); + + // load exports + game::GSC_EXPORT_ITEM* exports = (game::GSC_EXPORT_ITEM*)(prime_obj->magic + prime_obj->exports_offset); + + for (size_t i = 0; i < prime_obj->exports_count; i++) + { + availables[exports[i].name_space].insert(exports[i].name); + } + + // load using exports + int64_t* usings = (int64_t*)(prime_obj->magic + prime_obj->include_offset); + + for (size_t i = 0; i < prime_obj->include_count; i++) + { + game::BO4_AssetRef_t ref{ usings[i], 0 }; + xassets::scriptparsetree_header* spt = xassets::DB_FindXAssetHeader(xassets::ASSET_TYPE_SCRIPTPARSETREE, &ref, false, -1).scriptparsetree; + + if (!spt || !spt->buffer) + { + error++; + logger::write(logger::LOG_TYPE_ERROR, "[%s] Can't find #using %s in %s", inst ? "CSC" : "GSC", hashes::lookup_tmp("script", ref.hash), hashes::lookup_tmp("script", prime_obj->name)); + continue; + } + + game::GSC_EXPORT_ITEM* exports_using = (game::GSC_EXPORT_ITEM*)(spt->buffer->magic + spt->buffer->exports_offset); + + for (size_t j = 0; j < spt->buffer->exports_count; j++) + { + if (exports_using[j].flags & game::GSC_EXPORT_FLAGS::GEF_PRIVATE) + { + continue; // can't import private exports + } + availables[exports_using[j].name_space].insert(exports_using[j].name); + } + } + + game::GSC_IMPORT_ITEM* imports = (game::GSC_IMPORT_ITEM*)(prime_obj->magic + prime_obj->imports_offset); + + for (size_t i = 0; i < prime_obj->imports_count; i++) + { + game::GSC_IMPORT_ITEM* imp = imports; + + uint32_t* locations = reinterpret_cast(imp + 1); + imports = reinterpret_cast(locations + imp->num_address); + + if (imp->flags & game::GSC_IMPORT_FLAGS::GIF_DEV_CALL) + { + // ignore dev calls + continue; + } + + auto itn = availables.find(imp->name_space); + + if (itn != availables.end() && itn->second.contains(imp->name)) + { + continue; + } + + byte import_type = imp->flags & game::GSC_IMPORT_FLAGS::GIF_CALLTYPE_MASK; + + // search builtin calls + if ((imp->flags & game::GSC_IMPORT_FLAGS::GIF_GET_CALL) != 0 || imp->name_space == 0xC1243180 || imp->name_space == 0x222276A9) + { + + int type{}; + int ignored{}; + if (import_type == game::GSC_IMPORT_FLAGS::GIF_FUNC_METHOD || import_type == game::GSC_IMPORT_FLAGS::GIF_FUNCTION) + { + // &func or func() + if (inst) + { + if (game::CScr_GetFunction(imp->name, &type, &ignored, &ignored) && !type) + { + continue; + } + } + else + { + if (game::Scr_GetFunction(imp->name, &type, &ignored, &ignored) && !type) + { + continue; + } + } + } + + if (import_type == game::GSC_IMPORT_FLAGS::GIF_FUNC_METHOD || import_type == game::GSC_IMPORT_FLAGS::GIF_METHOD) + { + // &meth or meth() + if (inst) + { + if (game::CScr_GetMethod(imp->name, &type, &ignored, &ignored) && !type) + { + continue; + } + } + else + { + if (game::Scr_GetMethod(imp->name, &type, &ignored, &ignored) && !type) + { + continue; + } + } + } + } + + const char* func; + + if ((imp->flags & game::GSC_IMPORT_FLAGS::GIF_GET_CALL) != 0 || imp->name_space == 0xC1243180 || imp->name_space == 0x222276A9) + { + func = hashes::lookup_tmp("function", imp->name); + } + else + { + func = utilities::string::va("%s::%s", hashes::lookup_tmp("namespace", imp->name_space), hashes::lookup_tmp("function", imp->name)); + } + + const char* prefix; + + switch (import_type) + { + case game::GIF_FUNC_METHOD: + prefix = "&"; + break; + case game::GIF_FUNCTION: + case game::GIF_METHOD: + prefix = ""; + break; + case game::GIF_FUNCTION_THREAD: + case game::GIF_METHOD_THREAD: + prefix = "thread "; + break; + case game::GIF_FUNCTION_CHILDTHREAD: + case game::GIF_METHOD_CHILDTHREAD: + prefix = "childthread "; + break; + default: + prefix = ""; + break; + } + + logger::write(logger::LOG_TYPE_ERROR, "[%s] Unknown import %s%s in %s", + inst ? "CSC" : "GSC", prefix, func, hashes::lookup_tmp("script", prime_obj->name) + ); + for (size_t j = 0; j < imp->num_address; j++) + { + const char* scriptname{}; + int32_t sloc{}; + int32_t crc{}; + int32_t vm{}; + game::Scr_GetGscExportInfo(inst, prime_obj->magic + locations[j], &scriptname, &sloc, &crc, &vm); + if (scriptname) + { + logger::write(logger::LOG_TYPE_ERROR, "[%s] at %s", inst ? "CSC" : "GSC", scriptname); + } + else + { + logger::write(logger::LOG_TYPE_ERROR, "[%s] at %s@%lx", inst ? "CSC" : "GSC", hashes::lookup_tmp("script", prime_obj->name), locations[j]); + } + } + } + } + + if (error) + { + // convert the error to a terminal error to avoid a game crash + gsc_funcs::gsc_error("Find %lld GSC Linking error(s), see logs for more details", inst, true, error); + break; + } + } + // Can't find the error, we crash the server by default + gsc_funcs::gsc_error("GSC Linking error, see logs for more details", game::SCRIPTINSTANCE_SERVER, true); + } + + void patch_linking_sys_error() + { + auto scr_get_gsc_obj = 0x142748BB0_g; + + // skip the error and the autoexec + // 1C1 = syserr start + // 19F = end + utilities::hook::jump(scr_get_gsc_obj + 0x1C1, scr_get_gsc_obj + 0x19F); + } + utilities::hook::detour scr_get_gsc_obj_hook; + utilities::hook::detour gsc_obj_resolve_hook; void scr_get_gsc_obj_stub(game::scriptInstance_t inst, game::BO4_AssetRef_t* name, bool runScript) { if (game::gObjFileInfoCount[inst] == 0) @@ -305,16 +527,63 @@ namespace gsc_custom gsc_custom::link_detours(inst); } + int32_t gsc_obj_resolve_stub(game::scriptInstance_t inst, game::GSC_OBJ* prime_obj) + { + game::GSC_IMPORT_ITEM* import_item = prime_obj->get_imports(); + + for (size_t i = 0; i < prime_obj->imports_count; i++) + { + if ((import_item->flags & game::GIF_SHIELD_DEV_BLOCK_FUNC) != 0) + { + // enable or disable this dev import + if (gsc_funcs::enable_dev_blocks) + { + import_item->flags &= ~game::GIF_DEV_CALL; + } + else + { + import_item->flags |= game::GIF_DEV_CALL; + } + } + + // goto to the next element after the addresses + uint32_t* addresses = reinterpret_cast(import_item + 1); + import_item = reinterpret_cast(addresses + import_item->num_address); + } + + bool dv_func_back = gsc_funcs::enable_dev_func; + + if (gsc_funcs::enable_dev_blocks) + { + gsc_funcs::enable_dev_func = true; + } + + int32_t ret = gsc_obj_resolve_hook.invoke(inst, prime_obj); + + gsc_funcs::enable_dev_func = dv_func_back; + + return ret; + } + class component final : public component_interface { public: void post_unpack() override { // t8compiler custom opcode - game::gVmOpJumpTable[0x16] = vm_op_custom_lazylink; + game::gVmOpJumpTable[lazylink_opcode] = vm_op_custom_lazylink; + game::gVmOpJumpTable[shield_devblock_opcode] = vm_op_custom_devblock; // group gsc link scr_get_gsc_obj_hook.create(0x142748BB0_g, scr_get_gsc_obj_stub); + + if (gsc_funcs::enable_dev_blocks) + { + gsc_obj_resolve_hook.create(0x142746A30_g, gsc_obj_resolve_stub); + } + + + patch_linking_sys_error(); } }; } diff --git a/source/proxy-dll/component/gsc_custom.hpp b/source/proxy-dll/component/gsc_custom.hpp index af5e549..5b73477 100644 --- a/source/proxy-dll/component/gsc_custom.hpp +++ b/source/proxy-dll/component/gsc_custom.hpp @@ -3,6 +3,10 @@ namespace gsc_custom { + constexpr uint32_t linking_error = 1670707254; + constexpr uint16_t lazylink_opcode = 0x16; + constexpr uint16_t shield_devblock_opcode = 0x21; + enum gsic_field_type { GSIC_FIELD_DETOUR = 0 @@ -22,8 +26,10 @@ namespace gsc_custom struct gsic_info { bool sync{}; + bool dev_blocks{}; std::vector detours{}; }; void sync_gsic(game::scriptInstance_t inst, gsic_info& info); + void find_linking_issues(); } \ No newline at end of file diff --git a/source/proxy-dll/component/gsc_funcs.cpp b/source/proxy-dll/component/gsc_funcs.cpp index ff75819..dc38c5e 100644 --- a/source/proxy-dll/component/gsc_funcs.cpp +++ b/source/proxy-dll/component/gsc_funcs.cpp @@ -947,6 +947,59 @@ namespace gsc_funcs shield_from_json_push_struct(inst, doc); } + + void add_debug_command(game::scriptInstance_t inst) + { + int localclientnum; + const char* cmd; + + if (inst == game::SCRIPTINSTANCE_CLIENT) + { + // client, using param + localclientnum = (int)game::ScrVm_GetInt(inst, 0); + cmd = game::ScrVm_GetString(inst, 1); + } + else + { + // server, using primary + localclientnum = game::Com_LocalClients_GetPrimary(); + cmd = game::ScrVm_GetString(inst, 0); + } + + game::Cbuf_AddText(localclientnum, cmd); + } + + void hash_lookup(game::scriptInstance_t inst) + { + game::ScrVarType_t type = game::ScrVm_GetType(inst, 0); + + switch (type) + { + case game::TYPE_STRING: + game::ScrVm_AddConstString(inst, game::ScrVm_GetConstString(inst, 0)); + return; + case game::TYPE_HASH: + { + game::BO4_AssetRef_t hash; + const char* lookup = hashes::lookup(game::ScrVm_GetHash(&hash, inst, 0)->hash); + + if (lookup) + { + game::ScrVm_AddString(inst, lookup); + } + else + { + // can't find value, return base hash + game::ScrVm_AddHash(inst, &hash); + } + return; + } + default: + gsc_error("invalid hash param, a hash or a string should be used, received: %s", inst, false, game::var_typename[type]); + return; + } + } + game::BO4_BuiltinFunctionDef custom_functions_gsc[] = { @@ -1047,6 +1100,13 @@ namespace gsc_funcs .max_args = 2, .actionFunc = shield_to_json, .type = 0 + }, + {// ShieldHashLookup(hash hash) -> string + .canonId = canon_hash("ShieldHashLookup"), + .min_args = 1, + .max_args = 1, + .actionFunc = hash_lookup, + .type = 0 } }; game::BO4_BuiltinFunctionDef custom_functions_csc[] = @@ -1141,6 +1201,13 @@ namespace gsc_funcs .max_args = 2, .actionFunc = shield_to_json, .type = 0 + }, + {// ShieldHashLookup(hash hash) -> string + .canonId = canon_hash("ShieldHashLookup"), + .min_args = 1, + .max_args = 1, + .actionFunc = hash_lookup, + .type = 0 } }; @@ -1175,6 +1242,7 @@ namespace gsc_funcs bool enable_dev_func = false; + bool enable_dev_blocks = false; utilities::hook::detour scr_get_function_reverse_lookup; utilities::hook::detour cscr_get_function_reverse_lookup; @@ -1394,7 +1462,7 @@ namespace gsc_funcs game::GSC_OBJ* obj = info.activeVersion; - if (codepos >= obj->magic + obj->start_data && codepos < obj->magic + obj->start_data + obj->data_length) + if (codepos >= obj->magic + obj->cseg_offset && codepos < obj->magic + obj->cseg_offset + obj->cseg_size) { script_obj = obj; break; @@ -1461,10 +1529,19 @@ namespace gsc_funcs class component final : public component_interface { public: + void pre_start() override + { + // enable dev functions + enable_dev_func = utilities::json_config::ReadBoolean("gsc", "dev_funcs", false); + // enable custom compiled dev blocks + enable_dev_blocks = utilities::json_config::ReadBoolean("gsc", "dev_blocks", false); + } + void post_unpack() override { - // enable dev functions still available in the game - enable_dev_func = utilities::json_config::ReadBoolean("gsc", "dev_funcs", false); + // replace nulled function references + reinterpret_cast(0x144ED5D90_g)->actionFunc = add_debug_command; // csc + reinterpret_cast(0x1449BAD60_g)->actionFunc = add_debug_command; // gsc scr_get_function_reverse_lookup.create(0x1433AF8A0_g, scr_get_function_reverse_lookup_stub); cscr_get_function_reverse_lookup.create(0x141F132A0_g, cscr_get_function_reverse_lookup_stub); diff --git a/source/proxy-dll/component/gsc_funcs.hpp b/source/proxy-dll/component/gsc_funcs.hpp index 91d4b97..13286ef 100644 --- a/source/proxy-dll/component/gsc_funcs.hpp +++ b/source/proxy-dll/component/gsc_funcs.hpp @@ -7,6 +7,7 @@ namespace gsc_funcs constexpr auto serious_custom_func_name = "SeriousCustom"; extern bool enable_dev_func; + extern bool enable_dev_blocks; uint32_t canon_hash(const char* str); uint32_t canon_hash_pattern(const char* str); diff --git a/source/proxy-dll/component/logger.cpp b/source/proxy-dll/component/logger.cpp index 140975e..b64d1a8 100644 --- a/source/proxy-dll/component/logger.cpp +++ b/source/proxy-dll/component/logger.cpp @@ -18,9 +18,8 @@ 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; game_console::print(str); if (type == type::LOG_TYPE_CONSOLE) return; @@ -39,8 +38,10 @@ namespace logger fs.open("t8-mod.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/mods.cpp b/source/proxy-dll/component/mods.cpp index 10d69ec..67e4124 100644 --- a/source/proxy-dll/component/mods.cpp +++ b/source/proxy-dll/component/mods.cpp @@ -6,8 +6,9 @@ #include "command.hpp" #include "loader/component_loader.hpp" -#include "definitions/xassets.hpp" #include "definitions/game.hpp" +#include "definitions/xassets.hpp" +#include "definitions/scripting.hpp" #include #include @@ -22,6 +23,13 @@ namespace mods { std::filesystem::path mod_dir = "t8-mod/mods"; namespace { + template + inline byte* align_ptr(byte* ptr) + { + return reinterpret_cast((reinterpret_cast(ptr) + sizeof(T) - 1) & ~(sizeof(T) - 1)); + } + + struct raw_file { xassets::raw_file_header header{}; @@ -144,6 +152,89 @@ namespace mods { return true; } + + bool load_acts_debug() + { + if ((data.length() < sizeof(game::GSC_OBJ) + sizeof(game::acts_debug::MAGIC)) + || *reinterpret_cast(&data[sizeof(game::GSC_OBJ)]) != game::acts_debug::MAGIC) + { + return true; // too small to be a debug file + } + game::acts_debug::GSC_ACTS_DEBUG& dbg = *reinterpret_cast(data.data() + sizeof(game::GSC_OBJ)); + + + logger::write(logger::LOG_TYPE_DEBUG, "loading acts debug file v%x.%llx", dbg.version, dbg.actsVersion); + + byte* ptr = (byte*)data.data(); + + if (dbg.has_feature(game::acts_debug::ADF_STRING)) + { + char* start = data.data(); + for (uint32_t* strs = dbg.get_strings(ptr); strs != dbg.get_strings_end(ptr); strs++) + { + const char* val = data.data() + *strs; + hashes::add_hash(fnv1a::generate_hash(val), val); + hashes::add_hash(gsc_funcs::canon_hash(val), val); + } + } + + if (dbg.has_feature(game::acts_debug::ADF_DETOUR)) + { + for (game::acts_debug::GSC_ACTS_DETOUR* detours = dbg.get_detours(ptr); detours != dbg.get_detours_end(ptr); detours++) + { + gsc_custom::gsic_detour& detour = gsic.detours.emplace_back(); + + detour.fixup_name = 0; + detour.replace_namespace = detours->name_space; + detour.replace_function = detours->name; + detour.fixup_offset = detours->location; + detour.fixup_size = detours->size; + detour.target_script = detours->script; + + logger::write(logger::LOG_TYPE_DEBUG, std::format( + "read detour : namespace_{:x}::function_{:x} / offset=0x{:x}+0x{:x}", + detour.replace_namespace, detour.target_script, detour.replace_function, + detour.fixup_offset, detour.fixup_size + )); + } + } + + if (gsc_funcs::enable_dev_blocks) + { + if (dbg.has_feature(game::acts_debug::ADF_DEVBLOCK_BEGIN)) + { + if (dbg.devblock_count) + { + gsic.dev_blocks = true; + + // we need to patch the dev function imports to load them + + game::GSC_OBJ* prime_obj = (game::GSC_OBJ*)data.data(); + + game::GSC_IMPORT_ITEM* import_item = prime_obj->get_imports(); + + for (size_t i = 0; i < prime_obj->imports_count; i++) + { + // mark this function for the custom linker + if ((import_item->flags & game::GIF_DEV_CALL) != 0) + { + import_item->flags |= game::GIF_SHIELD_DEV_BLOCK_FUNC; + } + + // goto to the next element after the addresses + uint32_t* addresses = reinterpret_cast(import_item + 1); + import_item = reinterpret_cast(addresses + import_item->num_address); + } + } + for (uint32_t* devblock = dbg.get_devblocks(ptr); devblock != dbg.get_devblocks_end(ptr); devblock++) + { + byte* base = align_ptr(ptr + *devblock); + *(uint16_t*)base = gsc_custom::shield_devblock_opcode; + } + } + } + return true; + } }; struct lua_file { @@ -427,17 +518,23 @@ namespace mods { return false; } - if (tmp.gsic.detours.size()) - { - logger::write(logger::LOG_TYPE_DEBUG, std::format("loaded {} detours", tmp.gsic.detours.size())); - } - if (tmp.data.length() < sizeof(game::GSC_OBJ) || *reinterpret_cast(tmp.data.data()) != gsc_magic) { logger::write(logger::LOG_TYPE_ERROR, std::format("bad scriptparsetree magic in {} for mod {}", spt_path.string(), mod_name)); return false; } + if (!tmp.load_acts_debug()) + { + logger::write(logger::LOG_TYPE_ERROR, std::format("error when reading ACTS DEBUG header of {} for mod {}", spt_path.string(), mod_name)); + return false; + } + + if (tmp.gsic.detours.size()) + { + logger::write(logger::LOG_TYPE_DEBUG, std::format("loaded {} detours", tmp.gsic.detours.size())); + } + // after this point we assume that the GSC file is well formatted game::GSC_OBJ* script_obj = reinterpret_cast(tmp.data.data()); diff --git a/source/proxy-dll/component/unlockall.cpp b/source/proxy-dll/component/unlockall.cpp index 7e0f9a2..dba5d2e 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 @@ -99,7 +99,10 @@ namespace unlockall return result; } - + + bool return_false() { return false; } + + bool bg_unlockedgetchallengeunlockedforindex(game::eModes mode, int32_t controller, uint16_t index, int32_t itemIndex) { return true; @@ -146,7 +149,9 @@ namespace unlockall public: void post_unpack() override { - utilities::hook::jump(0x1437F6ED0_g, liveinventory_getitemquantity); + utilities::hook::jump(0x1438AE2F0_g, return_false); // patch LiveStats data source + + utilities::hook::jump(0x1437F6ED0_g, liveinventory_getitemquantity); // grant every loot item utilities::hook::jump(0x1406BB410_g, bg_unlockedgetchallengeunlockedforindex); utilities::hook::jump(0x1406B5530_g, bg_unlockablesitemoptionlocked); diff --git a/source/proxy-dll/component/watermark.cpp b/source/proxy-dll/component/watermark.cpp new file mode 100644 index 0000000..93f7f50 --- /dev/null +++ b/source/proxy-dll/component/watermark.cpp @@ -0,0 +1,42 @@ +#include +#include "version.hpp" +#include "scheduler.hpp" +#include "definitions/game.hpp" +#include "loader/component_loader.hpp" + +namespace watermark +{ + namespace + { + void draw_version() + { + auto* font = reinterpret_cast(game::sharedUiInfo->assets.bigFont); + constexpr auto scale = 0.4f; + constexpr const char* text = "Project-BO4: " VERSION; + + if (!font /*|| *game::keyCatchers & 1*/) return; + + auto screenWidth = game::ScrPlace_GetView(0)->realViewportSize[0]; + auto textWidth = game::UI_TextWidth(0, text, 0x7FFFFFFF, font, scale); + + auto x = screenWidth - (textWidth + 14.0f); + auto y = game::UI_TextHeight(font, scale) + 12.0f; + + float color[4] = { 0.666f, 0.666f, 0.666f, 0.666f }; + + game::R_AddCmdDrawText(text, 0x7FFFFFFF, font, x, y, scale, scale, 0.0f, color, + game::ITEM_TEXTSTYLE_NORMAL); + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + scheduler::loop(draw_version, scheduler::renderer); + } + }; +} + +REGISTER_COMPONENT(watermark::component) diff --git a/source/proxy-dll/definitions/game.hpp b/source/proxy-dll/definitions/game.hpp index c1e58e4..e2c7723 100644 --- a/source/proxy-dll/definitions/game.hpp +++ b/source/proxy-dll/definitions/game.hpp @@ -491,6 +491,7 @@ namespace game // Cmd WEAK symbol Cbuf_AddText{ 0x143CDE880_g }; WEAK symbol Cbuf_ExecuteBuffer{ 0x143CDEBE0_g }; + WEAK symbol Com_LocalClients_GetPrimary{ 0x142893AF0_g }; WEAK symbol Cmd_AddCommandInternal{ 0x143CDEE80_g }; WEAK symbol Cbuf_AddServerText_f{ 0x143CDE870_g }; @@ -569,6 +570,7 @@ namespace game WEAK symbol Scr_GetFunction{ 0x1433AF840_g }; WEAK symbol CScr_GetMethod{ 0x141F13650_g }; WEAK symbol Scr_GetMethod{ 0x1433AFC20_g }; + WEAK symbol Scr_GetGscExportInfo{ 0x142748550_g }; WEAK symbol ScrVm_Error{ 0x142770330_g }; WEAK symbol scrVarPub{ 0x148307880_g }; diff --git a/source/proxy-dll/definitions/scripting.hpp b/source/proxy-dll/definitions/scripting.hpp index d2f722f..0267c8a 100644 --- a/source/proxy-dll/definitions/scripting.hpp +++ b/source/proxy-dll/definitions/scripting.hpp @@ -34,7 +34,7 @@ namespace game int32_t include_offset; uint16_t string_count; uint16_t exports_count; - int32_t start_data; + int32_t cseg_offset; int32_t string_offset; int16_t imports_count; uint16_t fixup_count; @@ -48,7 +48,7 @@ namespace game int32_t script_size; int32_t requires_implements_offset; int32_t ukn50; - int32_t data_length; + int32_t cseg_size; uint16_t include_count; byte ukn5a; byte requires_implements_count; @@ -283,4 +283,157 @@ namespace game int refCount; uint32_t groupId; }; + + enum GSC_EXPORT_FLAGS : byte + { + GEF_LINKED = 0x01, + GEF_AUTOEXEC = 0x02, + GEF_PRIVATE = 0x04, + GEF_CLASS_MEMBER = 0x08, + GEF_CLASS_DESTRUCTOR = 0x10, + GEF_VE = 0x20, + GEF_EVENT = 0x40, + GEF_CLASS_LINKED = 0x80, + GEF_CLASS_VTABLE = 0x86 + }; + + enum GSC_IMPORT_FLAGS : byte + { + GIF_FUNC_METHOD = 0x1, + GIF_FUNCTION = 0x2, + GIF_FUNCTION_THREAD = 0x3, + GIF_FUNCTION_CHILDTHREAD = 0x4, + GIF_METHOD = 0x5, + GIF_METHOD_THREAD = 0x6, + GIF_METHOD_CHILDTHREAD = 0x7, + GIF_CALLTYPE_MASK = 0xF, + GIF_DEV_CALL = 0x10, + GIF_GET_CALL = 0x20, + + GIF_SHIELD_DEV_BLOCK_FUNC = 0x80, + }; + + namespace acts_debug + { + constexpr uint64_t MAGIC = 0x0d0a42444124; + constexpr byte CURRENT_VERSION = 0x12; + + enum GSC_ACTS_DEBUG_FEATURES : byte + { + ADF_STRING = 0x10, + ADF_DETOUR = 0x11, + ADF_DEVBLOCK_BEGIN = 0x12, + ADF_LAZYLINK = 0x12, + ADF_CRC_LOC = 0x13, + ADF_DEVSTRING = 0x14, + ADF_LINES = 0x15, + ADF_FILES = 0x15, + ADF_FLAGS = 0x15, + }; + + enum GSC_ACTS_DEBUG_FLAGS : uint32_t + { + ADFG_OBFUSCATED = 1 << 0, + ADFG_DEBUG = 1 << 1, + ADFG_CLIENT = 1 << 2, + ADFG_PLATFORM_SHIFT = 3, + ADFG_PLATFORM_MASK = 0xF << ADFG_PLATFORM_SHIFT, + }; + + struct GSC_ACTS_DETOUR + { + uint64_t name_space; + uint64_t name; + uint64_t script; + uint32_t location; + uint32_t size; + }; + + struct GSC_ACTS_LAZYLINK + { + uint64_t name_space; + uint64_t name; + uint64_t script; + uint32_t num_address; + }; + + struct GSC_ACTS_DEVSTRING + { + uint32_t string; + uint32_t num_address; + }; + + struct GSC_ACTS_LINES + { + uint32_t start; + uint32_t end; + size_t lineNum; + }; + + struct GSC_ACTS_FILES + { + uint32_t filename; + size_t lineStart; + size_t lineEnd; + }; + + + struct GSC_ACTS_DEBUG + { + byte magic[sizeof(MAGIC)]; + byte version; + uint32_t flags; + uint64_t actsVersion; + uint32_t strings_offset{}; + uint32_t strings_count{}; + uint32_t detour_offset{}; + uint32_t detour_count{}; + uint32_t devblock_offset{}; + uint32_t devblock_count{}; + uint32_t lazylink_offset{}; + uint32_t lazylink_count{}; + uint32_t crc_offset{}; + uint32_t devstrings_offset{}; + uint32_t devstrings_count{}; + uint32_t lines_offset{}; + uint32_t lines_count{}; + uint32_t files_offset{}; + uint32_t files_count{}; + + constexpr bool has_feature(GSC_ACTS_DEBUG_FEATURES feature) const + { + return version >= feature; + } + + inline GSC_ACTS_DETOUR* get_detours(byte* start) + { + return reinterpret_cast(start + detour_offset); + } + + inline GSC_ACTS_DETOUR* get_detours_end(byte* start) + { + return get_detours(start) + detour_count; + } + + inline uint32_t* get_devblocks(byte* start) + { + return reinterpret_cast(start + devblock_offset); + } + + inline uint32_t* get_devblocks_end(byte* start) + { + return get_devblocks(start) + devblock_count; + } + + inline uint32_t* get_strings(byte* start) + { + return reinterpret_cast(start + strings_offset); + } + + inline uint32_t* get_strings_end(byte* start) + { + return get_strings(start) + strings_count; + } + }; + } } \ No newline at end of file diff --git a/source/proxy-dll/definitions/variables.cpp b/source/proxy-dll/definitions/variables.cpp index 44ae31c..713a7fc 100644 --- a/source/proxy-dll/definitions/variables.cpp +++ b/source/proxy-dll/definitions/variables.cpp @@ -6529,7 +6529,127 @@ namespace variables "quit", "Shutdown the Game [Com_Quit_f]", 0x1DEE6107B26F8BB6 - } + }, + { + "gts", + "Set gametype setting, Usage: gts []", + 0x55155818fad5c0df + }, + { + "gametype_setting", + "Set gametype setting, Usage: gametype_setting []", + 0x46fb4ee1a7c51bcc + }, + { + "set", + "Set dvar value, Usage: set ", + 0x23b87195ce20e23 + }, + { + "setdvartotime", + "Set dvar value to time, Usage: setdvartotime ", + 0x1cc7ab7a4c8a4e7a + }, + { + "reset", + "Reset dvar value, Usage: reset ", + 0xf136ff2c086b760 + }, + { + "lobby_errorshutdown", + "Shutdown lobby with error", + 0x6a3a118a63f519a4 + }, + { + "lobby_reload", + "Reload lobby", + 0x67ac003bb1f9cfc9 + }, + { + "map", + "Load map, Usage: map ", + 0x80f5919176d2d91 + }, + { + "devmap", + "Load map in dev mode, Usage: devmap ", + 0x7e4ea29057c5f962 + }, + { + "gametype", + "Set the gametype, Usage: gametype ", + 0x6792c1f90c3a5c7f + }, + { + "exec", + "Exec file, Usage: exec ", + 0x67c75e608ea39b5c + }, + { + "disconnect", + "Disconnect from server", + 0x5926cb82738c446b + }, + { + "reconnect", + "Reconnect to localhost", + 0x31ab1e1fcc28efe6 + }, + { + "hostmigration_start", + "Start host migration", + 0x6bf6f7867a2b3202 + }, + { + "setperk", + "Set a perk, Usage: setperk ", + 0x262eebca5ebf646b + }, + { + "killserver", + "Shutdown the server", + 0x64fb81c94800815e + }, + { + "switchmaps", + "Switch now to the map", + 0x182ae2b46edd075a + }, + { + "msload", + "Start loading map switch, Usage: msload ", + 0xddcb9fb38629fcd + }, + { + "mspreload", + "Start loading map switch, Usage: mspreload ", + 0x291b1ea6866a7cfa + }, + { + "fast_restart", + "Fast restart", + 0x506e7e29c6d674bb + }, + { + "full_restart", + "Full restart", + 0x7cba6d063fbd73d0 + }, + { + "clientkick_for_reason", + "Kick client with a reason, Usage: clientkick_for_reason ", + 0x7086b005b6eb2871 + }, + { + "clientkick", + "Kick client, Usage: clientkick ", + 0x3e30e01add5a0b78 + }, + { + "clearpsdata", + "Clear PS data", + 0x2e8816c78dd363c7 + }, }; std::vector get_dvars_list() 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 94312a3..b429ae2 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..39c09b4 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) @@ -285,4 +285,4 @@ namespace utilities::string if (text.find(substr) != std::string::npos) return true; return false; } -} +} \ No newline at end of file diff --git a/source/shared-code/utilities/string.hpp b/source/shared-code/utilities/string.hpp index 711131e..97d30a6 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); -} +} \ No newline at end of file