From 785c0e5df6bc5e97da0c8fb853dc61a7c9e6ea48 Mon Sep 17 00:00:00 2001 From: Joelrau Date: Wed, 20 Jan 2021 03:16:11 +0200 Subject: [PATCH] Add videos component --- src/client/component/videos.cpp | 78 +++++++++++++++++++++++++++++++++ src/client/component/videos.hpp | 7 +++ 2 files changed, 85 insertions(+) create mode 100644 src/client/component/videos.cpp create mode 100644 src/client/component/videos.hpp diff --git a/src/client/component/videos.cpp b/src/client/component/videos.cpp new file mode 100644 index 0000000..a05dc9e --- /dev/null +++ b/src/client/component/videos.cpp @@ -0,0 +1,78 @@ +#include +#include "loader/component_loader.hpp" +#include "videos.hpp" + +#include "game/game.hpp" + +#include +#include +#include + +namespace videos +{ + class video_replace + { + public: + const char* replace; + const char* with; + }; + + namespace + { + template + T* find_vid(std::vector* vec, const char* name) + { + for (auto i = 0; i < vec->size(); i++) + { + if (!strcmp(name, vec->at(i).replace)) + { + return &vec->at(i); + } + } + return nullptr; + } + } + + static std::vector replaces; + + void replace(const char* what, const char* with) + { + video_replace vid; + vid.replace = what; + vid.with = with; + replaces.push_back(std::move(vid)); + } + + namespace + { + utils::hook::detour playvid_hook; + + void playvid(const char* name, int a2, int a3) + { + auto* vid = find_vid(&replaces, name); + if (vid && utils::io::file_exists(utils::string::va("raw\\video\\%s.bik", vid->with))) + { + name = vid->with; + } + + return playvid_hook.invoke(name, a2, a3); + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + playvid_hook.create(SELECT_VALUE(0x1404591C0, 0x140575AA0), &playvid); + + if (game::environment::is_mp()) + { + replace("menus_bg_comp2", "menus_bg_s1-mod"); + replace("mp_menus_bg_options", "menus_bg_s1-mod_blur"); + } + } + }; +} + +REGISTER_COMPONENT(videos::component) \ No newline at end of file diff --git a/src/client/component/videos.hpp b/src/client/component/videos.hpp new file mode 100644 index 0000000..567c351 --- /dev/null +++ b/src/client/component/videos.hpp @@ -0,0 +1,7 @@ +#pragma once +#include + +namespace videos +{ + void replace(const char* what, const char* with); +}