Skip to content

Commit

Permalink
Merge pull request #119 from h1-mod/develop
Browse files Browse the repository at this point in the history
v1.0.3
  • Loading branch information
alicealys authored Jun 27, 2022
2 parents 78a48f9 + 35e2540 commit 4a44785
Show file tree
Hide file tree
Showing 25 changed files with 471 additions and 86 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@
path = deps/zlib
url = https://github.com/madler/zlib.git
branch = develop
[submodule "deps/curl"]
path = deps/curl
url = https://github.com/curl/curl.git
1 change: 1 addition & 0 deletions data/ui_scripts/patches/__init__.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ end

if (Engine.InFrontend()) then
require("shaderdialog")
require("gamemodes")
end

-- defined in mp_hud/hudutils.lua
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
if (game:issingleplayer() or not Engine.InFrontend()) then
return
end

Cac.GameModes.Data = {
Standard = {
Label = Engine.Localize("@MPUI_STANDARD_CAPS"),
Expand Down
27 changes: 27 additions & 0 deletions data/ui_scripts/server_list/serverlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ end

game:addlocalizedstring("MENU_NUMPLAYERS", "Players")
game:addlocalizedstring("MENU_PING", "Ping")
game:addlocalizedstring("SERVERLIST_PLAYER_COUNT", "&&1 Players")
game:addlocalizedstring("SERVERLIST_SERVER_COUNT", "&&1 Servers")

local columns = {
{
Expand Down Expand Up @@ -195,8 +197,33 @@ function menu_systemlink_join(f19_arg0, f19_arg1)
SystemLinkJoinMenu.UpdateCounterText(menu, nil)
Lobby.BuildServerList(Engine.GetFirstActiveController())

local playercount = LUI.UIText.new({
rightAnchor = true,
topAnchor = true,
height = 18,
bottom = 58,
font = CoD.TextSettings.BodyFont.Font,
width = 300,
alignment = LUI.Alignment.Right,
})
menu:addElement(playercount)

local servercount = LUI.UIText.new({
rightAnchor = true,
topAnchor = true,
height = 18,
bottom = 58 - 25,
font = CoD.TextSettings.BodyFont.Font,
width = 300,
alignment = LUI.Alignment.Right,
})
menu:addElement(servercount)

menu.list:registerEventHandler(LUI.UIScrollIndicator.UpdateEvent, function(element, event)
SystemLinkJoinMenu.UpdateCounterText(menu, event)

playercount:setText(Engine.Localize("@SERVERLIST_PLAYER_COUNT", serverlist:getplayercount()))
servercount:setText(Engine.Localize("@SERVERLIST_SERVER_COUNT", serverlist:getservercount()))
end)

SystemLinkJoinMenu.UpdateGameList(menu)
Expand Down
2 changes: 1 addition & 1 deletion deps/asmjit
1 change: 1 addition & 0 deletions deps/curl
Submodule curl added at e2e7f5
73 changes: 73 additions & 0 deletions deps/premake/curl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
curl = {
source = path.join(dependencies.basePath, "curl"),
}

function curl.import()
links { "curl" }

filter "toolset:msc*"
links { "Crypt32.lib" }
filter {}

curl.includes()
end

function curl.includes()
filter "toolset:msc*"
includedirs {
path.join(curl.source, "include"),
}

defines {
"CURL_STRICTER",
"CURL_STATICLIB",
"CURL_DISABLE_LDAP",
}
filter {}
end

function curl.project()
if not os.istarget("windows") then
return
end

project "curl"
language "C"

curl.includes()

includedirs {
path.join(curl.source, "lib"),
}

files {
path.join(curl.source, "lib/**.c"),
path.join(curl.source, "lib/**.h"),
}

defines {
"BUILDING_LIBCURL",
}

filter "toolset:msc*"

defines {
"USE_SCHANNEL",
"USE_WINDOWS_SSPI",
"USE_THREADS_WIN32",
}

filter "toolset:not msc*"

defines {
"USE_GNUTLS",
"USE_THREADS_POSIX",
}

filter {}

warnings "Off"
kind "StaticLib"
end

table.insert(dependencies, curl)
2 changes: 1 addition & 1 deletion deps/sol2
Submodule sol2 updated 348 files
2 changes: 1 addition & 1 deletion src/client/component/auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace auth

std::string get_protected_data()
{
std::string input = "X-Labs-H1Mod-Auth";
std::string input = "H1Mod-Auth";

DATA_BLOB data_in{}, data_out{};
data_in.pbData = reinterpret_cast<uint8_t*>(input.data());
Expand Down
26 changes: 21 additions & 5 deletions src/client/component/discord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,37 @@ namespace discord
{
const auto data = utils::http::get_data(
utils::string::va(AVATAR_URL, id.data(), avatar.data()));
if (data.has_value())
if (!data.has_value())
{
materials::add(utils::string::va(AVATAR, id.data()), data.value());
return;
}

const auto& value = data.value();
if (value.code != CURLE_OK)
{
return;
}

materials::add(utils::string::va(AVATAR, id.data()), value.buffer);
}

bool has_default_avatar = false;
void download_default_avatar()
{
const auto data = utils::http::get_data(DEFAULT_AVATAR_URL);
if (data.has_value())
if (!data.has_value())
{
has_default_avatar = true;
materials::add(DEFAULT_AVATAR, data.value());
return;
}

const auto& value = data.value();
if (value.code != CURLE_OK)
{
return;
}

has_default_avatar = true;
materials::add(DEFAULT_AVATAR, value.buffer);
}
}

Expand Down
51 changes: 51 additions & 0 deletions src/client/component/lui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,67 @@

#include "command.hpp"
#include "console.hpp"
#include "scheduler.hpp"

#include <utils/hook.hpp>

namespace lui
{
namespace
{
uint64_t event_count{};
bool begin_game_message_event_stub(int a1, const char* name, void* a3)
{
if (event_count > 30)
{
return false;
}
else
{
event_count++;
}

return utils::hook::invoke<bool>(0x2655A0_b, a1, name, a3);
}
}

class component final : public component_interface
{
public:
void post_unpack() override
{
if (game::environment::is_mp())
{
// Patch game message overflow
utils::hook::call(0x266E6B_b, begin_game_message_event_stub);

scheduler::loop([]()
{
if (event_count > 0)
{
event_count--;
}
}, scheduler::pipeline::lui, 50ms);
}

// Increase max extra LUI memory
/*const auto max_memory = 0x900000 * 2;
utils::hook::set<uint32_t>(0x278E61_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27A2C5_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27A993_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27AB3A_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27AB35_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27C002_b - 4, max_memory);*/

// Increase max extra frontend memory
/*const auto max_frontend_memory = 0x180000 * 2;
utils::hook::set<uint32_t>(0x278EA6_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x278F01_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x27A2D4_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x27A2E3_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x27F9E9_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x27FA84_b - 4, max_frontend_memory);*/

command::add("lui_open", [](const command::params& params)
{
if (params.size() <= 1)
Expand Down
85 changes: 71 additions & 14 deletions src/client/component/patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ namespace patches
const auto menu_id = atoi(params.get(1));
const auto client = &svs_clients[ent->s.entityNum];

// 22 => "end_game"
if (menu_id == 22 && client->header.remoteAddress.type != game::NA_LOOPBACK)
// 32 => "end_game"
if (menu_id == 32 && client->header.remoteAddress.type != game::NA_LOOPBACK)
{
game::SV_DropClient_Internal(client, "PLATFORM_STEAM_KICK_CHEAT", true);
return;
}

Expand Down Expand Up @@ -158,7 +159,7 @@ namespace patches

void missing_content_error_stub(int, const char*)
{
game::Com_Error(game::ERR_DROP, utils::string::va("MISSING FILE\n%s.ff",
game::Com_Error(game::ERR_DROP, utils::string::va("MISSING FILE\n%s.ff",
fastfiles::get_current_fastfile().data()));
}

Expand Down Expand Up @@ -194,15 +195,74 @@ namespace patches

char buffer[2048];

va_list ap;
va_start(ap, fmt);
{
va_list ap;
va_start(ap, fmt);

vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap);

va_end(ap);
va_end(ap);
}

return utils::hook::invoke<int>(SELECT_VALUE(0x429200_b, 0x5AF0F0_b), dest, size, "%s", buffer);
}

void create_2d_texture_stub_1(const char* fmt, ...)
{
fmt = "Create2DTexture( %s, %i, %i, %i, %i ) failed\n\n"
"Disable shader caching, lower graphic settings, free up RAM, or update your GPU drivers.";

char buffer[2048];

{
va_list ap;
va_start(ap, fmt);

vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap);

va_end(ap);
}

game::Sys_Error("%s", buffer);
}

void create_2d_texture_stub_2(game::errorParm code, const char* fmt, ...)
{
fmt = "Create2DTexture( %s, %i, %i, %i, %i ) failed\n\n"
"Disable shader caching, lower graphic settings, free up RAM, or update your GPU drivers.";

char buffer[2048];

{
va_list ap;
va_start(ap, fmt);

vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap);

va_end(ap);
}

game::Com_Error(code, "%s", buffer);
}

void swap_chain_stub(game::errorParm code, const char* fmt, ...)
{
fmt = "IDXGISwapChain::Present failed: %s\n\n"
"Disable shader caching, lower graphic settings, free up RAM, or update your GPU drivers.";

char buffer[2048];

{
va_list ap;
va_start(ap, fmt);

vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap);

va_end(ap);
}

game::Com_Error(code, "%s", buffer);
}
}

class component final : public component_interface
Expand Down Expand Up @@ -242,13 +302,10 @@ namespace patches
utils::hook::call(SELECT_VALUE(0x376EB5_b, 0x156D41_b), db_read_raw_file_stub);

// Remove useless information from errors + add additional help to common errors
utils::hook::set<const char*>(SELECT_VALUE(0x7E3DF0_b, 0x937B80_b),
"Create2DTexture( %s, %i, %i, %i, %i ) failed\n\n"
"Disable shader caching, lower graphic settings, free up RAM, or update your GPU drivers.");
utils::hook::set<const char*>(SELECT_VALUE(0x800EA8_b, 0x954FF0_b),
"IDXGISwapChain::Present failed: %s\n\n"
"Disable shader caching, lower graphic settings, free up RAM, or update your GPU drivers.");
utils::hook::call(SELECT_VALUE(0x457BC9_b, 0x1D8E09_b), out_of_memory_text_stub); // "Out of memory. You are probably low on disk space."
utils::hook::call(SELECT_VALUE(0x55E919_b, 0x681A69_b), create_2d_texture_stub_1); // Sys_Error for "Create2DTexture( %s, %i, %i, %i, %i ) failed"
utils::hook::call(SELECT_VALUE(0x55EACB_b, 0x681C1B_b), create_2d_texture_stub_2); // Com_Error for ^
utils::hook::call(SELECT_VALUE(0x5B35BA_b, 0x6CB1BC_b), swap_chain_stub); // Com_Error for "IDXGISwapChain::Present failed: %s"
utils::hook::call(SELECT_VALUE(0x457BC9_b, 0x1D8E09_b), out_of_memory_text_stub); // Com_sprintf for "Out of memory. You are probably low on disk space."

// "fix" for rare 'Out of memory error' error
// this will *at least* generate the configs for mp/sp, which is the #1 issue
Expand Down
Loading

0 comments on commit 4a44785

Please sign in to comment.