mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
Add videos component
This commit is contained in:
parent
98b202bd4e
commit
785c0e5df6
78
src/client/component/videos.cpp
Normal file
78
src/client/component/videos.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "videos.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/io.hpp>
|
||||
|
||||
namespace videos
|
||||
{
|
||||
class video_replace
|
||||
{
|
||||
public:
|
||||
const char* replace;
|
||||
const char* with;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
T* find_vid(std::vector<T>* 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<video_replace> 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<void>(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)
|
7
src/client/component/videos.hpp
Normal file
7
src/client/component/videos.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <utils/nt.hpp>
|
||||
|
||||
namespace videos
|
||||
{
|
||||
void replace(const char* what, const char* with);
|
||||
}
|
Loading…
Reference in New Issue
Block a user