mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
Support motd image
This commit is contained in:
parent
5a67d0a9c5
commit
b1c574e2ab
@ -1,17 +1,20 @@
|
|||||||
#include <std_include.hpp>
|
#include <std_include.hpp>
|
||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
#include "game/game.hpp"
|
#include "game/game.hpp"
|
||||||
|
#include "images.hpp"
|
||||||
|
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
#include <utils/string.hpp>
|
#include <utils/string.hpp>
|
||||||
#include <utils/image.hpp>
|
#include <utils/image.hpp>
|
||||||
#include <utils/io.hpp>
|
#include <utils/io.hpp>
|
||||||
|
#include <utils/concurrency.hpp>
|
||||||
|
|
||||||
namespace images
|
namespace images
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
utils::hook::detour load_texture_hook;
|
utils::hook::detour load_texture_hook;
|
||||||
|
utils::concurrency::container<std::unordered_map<std::string, std::string>> overriden_textures;
|
||||||
|
|
||||||
static_assert(sizeof(game::GfxImage) == 104);
|
static_assert(sizeof(game::GfxImage) == 104);
|
||||||
static_assert(offsetof(game::GfxImage, name) == (sizeof(game::GfxImage) - sizeof(void*)));
|
static_assert(offsetof(game::GfxImage, name) == (sizeof(game::GfxImage) - sizeof(void*)));
|
||||||
@ -20,10 +23,16 @@ namespace images
|
|||||||
|
|
||||||
std::optional<std::string> load_image(game::GfxImage* image)
|
std::optional<std::string> load_image(game::GfxImage* image)
|
||||||
{
|
{
|
||||||
printf("Loading: %s\n", image->name);
|
|
||||||
|
|
||||||
std::string data{};
|
std::string data{};
|
||||||
if(!utils::io::read_file(utils::string::va("s1x/images/%s.png", image->name), &data))
|
overriden_textures.access([&](const std::unordered_map<std::string, std::string>& textures)
|
||||||
|
{
|
||||||
|
if (const auto i = textures.find(image->name); i != textures.end())
|
||||||
|
{
|
||||||
|
data = i->second;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data.empty() && !utils::io::read_file(utils::string::va("s1x/images/%s.png", image->name), &data))
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -34,7 +43,7 @@ namespace images
|
|||||||
std::optional<utils::image> load_raw_image_from_file(game::GfxImage* image)
|
std::optional<utils::image> load_raw_image_from_file(game::GfxImage* image)
|
||||||
{
|
{
|
||||||
const auto image_file = load_image(image);
|
const auto image_file = load_image(image);
|
||||||
if(!image_file)
|
if (!image_file)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -51,7 +60,7 @@ namespace images
|
|||||||
texture->GetDesc(&desc);
|
texture->GetDesc(&desc);
|
||||||
texture->GetDevice(&device);
|
texture->GetDevice(&device);
|
||||||
|
|
||||||
if(device)
|
if (device)
|
||||||
{
|
{
|
||||||
device->GetImmediateContext(&context);
|
device->GetImmediateContext(&context);
|
||||||
device->Release();
|
device->Release();
|
||||||
@ -59,7 +68,7 @@ namespace images
|
|||||||
|
|
||||||
auto _ = gsl::finally([&]()
|
auto _ = gsl::finally([&]()
|
||||||
{
|
{
|
||||||
if(context)
|
if (context)
|
||||||
{
|
{
|
||||||
context->Release();
|
context->Release();
|
||||||
}
|
}
|
||||||
@ -95,7 +104,7 @@ namespace images
|
|||||||
bool load_custom_texture(game::GfxImage* image)
|
bool load_custom_texture(game::GfxImage* image)
|
||||||
{
|
{
|
||||||
const auto raw_image = load_raw_image_from_file(image);
|
const auto raw_image = load_raw_image_from_file(image);
|
||||||
if(!raw_image)
|
if (!raw_image)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -113,20 +122,38 @@ namespace images
|
|||||||
|
|
||||||
void load_texture_stub(game::GfxImageLoadDef** load_def, game::GfxImage* image)
|
void load_texture_stub(game::GfxImageLoadDef** load_def, game::GfxImage* image)
|
||||||
{
|
{
|
||||||
if(!load_custom_texture(image))
|
printf("Loading: %s\n", image->name);
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
load_texture_hook.invoke(load_def, image);
|
if (load_custom_texture(image))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch(std::exception&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
load_texture_hook.invoke(load_def, image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void override_texture(std::string name, std::string data)
|
||||||
|
{
|
||||||
|
overriden_textures.access([&](std::unordered_map<std::string, std::string>& textures)
|
||||||
|
{
|
||||||
|
textures[std::move(name)] = std::move(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void post_unpack() override
|
||||||
{
|
{
|
||||||
if (!game::environment::is_mp()) return;
|
if (!game::environment::is_mp()) return;
|
||||||
|
|
||||||
load_texture_hook.create(0x1405A21F0, load_texture_stub);
|
load_texture_hook.create(0x1405A21F0, load_texture_stub);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
6
src/client/component/images.hpp
Normal file
6
src/client/component/images.hpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace images
|
||||||
|
{
|
||||||
|
void override_texture(std::string name, std::string data);
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#include <std_include.hpp>
|
#include <std_include.hpp>
|
||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
#include "motd.hpp"
|
#include "motd.hpp"
|
||||||
|
#include "images.hpp"
|
||||||
|
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
#include <utils/http.hpp>
|
#include <utils/http.hpp>
|
||||||
@ -35,6 +36,14 @@ namespace motd
|
|||||||
void post_load() override
|
void post_load() override
|
||||||
{
|
{
|
||||||
motd_future = utils::http::get_data_async("https://xlabs.dev/s1/motd.txt");
|
motd_future = utils::http::get_data_async("https://xlabs.dev/s1/motd.txt");
|
||||||
|
std::thread([]()
|
||||||
|
{
|
||||||
|
auto data = utils::http::get_data("https://xlabs.dev/s1/motd.png");
|
||||||
|
if(data)
|
||||||
|
{
|
||||||
|
images::override_texture("iotd_image", data.value());
|
||||||
|
}
|
||||||
|
}).detach();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -66,4 +66,9 @@ namespace utils
|
|||||||
|
|
||||||
return this->path_;
|
return this->path_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& binary_resource::get_data() const
|
||||||
|
{
|
||||||
|
return this->resource_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ namespace utils
|
|||||||
binary_resource(int id, std::string file);
|
binary_resource(int id, std::string file);
|
||||||
|
|
||||||
std::string get_extracted_file();
|
std::string get_extracted_file();
|
||||||
|
const std::string& get_data() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string resource_;
|
std::string resource_;
|
||||||
|
Loading…
Reference in New Issue
Block a user