This commit is contained in:
Federico Cecchetto 2021-09-07 00:40:37 +02:00
parent ada61c942d
commit 87545c31d7
166 changed files with 13918 additions and 316 deletions

18
.gitmodules vendored
View File

@ -22,3 +22,21 @@
[submodule "deps/asmjit"]
path = deps/asmjit
url = https://github.com/asmjit/asmjit.git
[submodule "deps/protobuf"]
path = deps/protobuf
url = https://github.com/google/protobuf.git
[submodule "deps/udis86"]
path = deps/udis86
url = https://github.com/vmt/udis86.git
[submodule "deps/WinToast"]
path = deps/WinToast
url = https://github.com/mohabouje/WinToast.git
[submodule "deps/libtomcrypt"]
path = deps/libtomcrypt
url = https://github.com/libtom/libtomcrypt.git
[submodule "deps/libtommath"]
path = deps/libtommath
url = https://github.com/libtom/libtommath.git
[submodule "deps/zlib"]
path = deps/zlib
url = https://github.com/madler/zlib.git

1
deps/WinToast vendored Submodule

@ -0,0 +1 @@
Subproject commit 5e441fd03543b999edb663caf8df7be37c0d575c

5946
deps/extra/udis86/libudis86/itab.c vendored Normal file

File diff suppressed because it is too large Load Diff

939
deps/extra/udis86/libudis86/itab.h vendored Normal file
View File

@ -0,0 +1,939 @@
#ifndef UD_ITAB_H
#define UD_ITAB_H
/* itab.h -- generated by udis86:scripts/ud_itab.py, do no edit */
/* ud_table_type -- lookup table types (see decode.c) */
enum ud_table_type {
UD_TAB__OPC_VEX,
UD_TAB__OPC_TABLE,
UD_TAB__OPC_X87,
UD_TAB__OPC_MOD,
UD_TAB__OPC_RM,
UD_TAB__OPC_OSIZE,
UD_TAB__OPC_MODE,
UD_TAB__OPC_VEX_L,
UD_TAB__OPC_3DNOW,
UD_TAB__OPC_REG,
UD_TAB__OPC_ASIZE,
UD_TAB__OPC_VEX_W,
UD_TAB__OPC_SSE,
UD_TAB__OPC_VENDOR
};
/* ud_mnemonic -- mnemonic constants */
enum ud_mnemonic_code {
UD_Iaaa,
UD_Iaad,
UD_Iaam,
UD_Iaas,
UD_Iadc,
UD_Iadd,
UD_Iaddpd,
UD_Iaddps,
UD_Iaddsd,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UD_Iminsd,
UD_Iminss,
UD_Imonitor,
UD_Imontmul,
UD_Imov,
UD_Imovapd,
UD_Imovaps,
UD_Imovbe,
UD_Imovd,
UD_Imovddup,
UD_Imovdq2q,
UD_Imovdqa,
UD_Imovdqu,
UD_Imovhlps,
UD_Imovhpd,
UD_Imovhps,
UD_Imovlhps,
UD_Imovlpd,
UD_Imovlps,
UD_Imovmskpd,
UD_Imovmskps,
UD_Imovntdq,
UD_Imovntdqa,
UD_Imovnti,
UD_Imovntpd,
UD_Imovntps,
UD_Imovntq,
UD_Imovq,
UD_Imovq2dq,
UD_Imovsb,
UD_Imovsd,
UD_Imovshdup,
UD_Imovsldup,
UD_Imovsq,
UD_Imovss,
UD_Imovsw,
UD_Imovsx,
UD_Imovsxd,
UD_Imovupd,
UD_Imovups,
UD_Imovzx,
UD_Impsadbw,
UD_Imul,
UD_Imulpd,
UD_Imulps,
UD_Imulsd,
UD_Imulss,
UD_Imwait,
UD_Ineg,
UD_Inop,
UD_Inot,
UD_Ior,
UD_Iorpd,
UD_Iorps,
UD_Iout,
UD_Ioutsb,
UD_Ioutsd,
UD_Ioutsw,
UD_Ipabsb,
UD_Ipabsd,
UD_Ipabsw,
UD_Ipackssdw,
UD_Ipacksswb,
UD_Ipackusdw,
UD_Ipackuswb,
UD_Ipaddb,
UD_Ipaddd,
UD_Ipaddq,
UD_Ipaddsb,
UD_Ipaddsw,
UD_Ipaddusb,
UD_Ipaddusw,
UD_Ipaddw,
UD_Ipalignr,
UD_Ipand,
UD_Ipandn,
UD_Ipavgb,
UD_Ipavgusb,
UD_Ipavgw,
UD_Ipblendvb,
UD_Ipblendw,
UD_Ipclmulqdq,
UD_Ipcmpeqb,
UD_Ipcmpeqd,
UD_Ipcmpeqq,
UD_Ipcmpeqw,
UD_Ipcmpestri,
UD_Ipcmpestrm,
UD_Ipcmpgtb,
UD_Ipcmpgtd,
UD_Ipcmpgtq,
UD_Ipcmpgtw,
UD_Ipcmpistri,
UD_Ipcmpistrm,
UD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ipause,
UD_MAX_MNEMONIC_CODE
};
extern const char * ud_mnemonics_str[];
#endif /* UD_ITAB_H */

1
deps/libtomcrypt vendored Submodule

@ -0,0 +1 @@
Subproject commit 165c795b65e3281040be2edc41be38cf3536d8cd

1
deps/libtommath vendored Submodule

@ -0,0 +1 @@
Subproject commit eda0bd6ae5705ab90b866dfb52c5f15c23687f81

61
deps/premake/libtomcrypt.lua vendored Normal file
View File

@ -0,0 +1,61 @@
libtomcrypt = {
source = path.join(dependencies.basePath, "libtomcrypt"),
}
function libtomcrypt.import()
links {
"libtomcrypt"
}
libtomcrypt.includes()
end
function libtomcrypt.includes()
includedirs {
path.join(libtomcrypt.source, "src/headers")
}
defines {
"LTC_NO_FAST",
"LTC_NO_PROTOTYPES",
"LTC_NO_RSA_BLINDING",
}
end
function libtomcrypt.project()
project "libtomcrypt"
language "C"
libtomcrypt.includes()
libtommath.import()
files {
path.join(libtomcrypt.source, "src/**.c"),
}
removefiles {
path.join(libtomcrypt.source, "src/**/*tab.c"),
path.join(libtomcrypt.source, "src/encauth/ocb3/**.c"),
}
defines {
"_CRT_SECURE_NO_WARNINGS",
"LTC_SOURCE",
"_LIB",
"USE_LTM"
}
removedefines {
"_DLL",
"_USRDLL"
}
linkoptions {
"-IGNORE:4221"
}
warnings "Off"
kind "StaticLib"
end
table.insert(dependencies, libtomcrypt)

52
deps/premake/libtommath.lua vendored Normal file
View File

@ -0,0 +1,52 @@
libtommath = {
source = path.join(dependencies.basePath, "libtommath"),
}
function libtommath.import()
links {
"libtommath"
}
libtommath.includes()
end
function libtommath.includes()
includedirs {
libtommath.source
}
defines {
"LTM_DESC",
"__STDC_IEC_559__",
"MP_NO_DEV_URANDOM",
}
end
function libtommath.project()
project "libtommath"
language "C"
libtommath.includes()
files {
path.join(libtommath.source, "*.c"),
}
defines {
"_LIB"
}
removedefines {
"_DLL",
"_USRDLL"
}
linkoptions {
"-IGNORE:4221"
}
warnings "Off"
kind "StaticLib"
end
table.insert(dependencies, libtommath)

43
deps/premake/minizip.lua vendored Normal file
View File

@ -0,0 +1,43 @@
minizip = {
source = path.join(dependencies.basePath, "zlib/contrib/minizip"),
}
function minizip.import()
links { "minizip" }
zlib.import()
minizip.includes()
end
function minizip.includes()
includedirs {
minizip.source
}
zlib.includes()
end
function minizip.project()
project "minizip"
language "C"
minizip.includes()
files {
path.join(minizip.source, "*.h"),
path.join(minizip.source, "*.c"),
}
removefiles {
path.join(minizip.source, "miniunz.c"),
path.join(minizip.source, "minizip.c"),
}
defines {
"_CRT_SECURE_NO_DEPRECATE",
}
warnings "Off"
kind "StaticLib"
end
table.insert(dependencies, minizip)

60
deps/premake/protobuf.lua vendored Normal file
View File

@ -0,0 +1,60 @@
protobuf = {
source = path.join(dependencies.basePath, "protobuf"),
}
function protobuf.import()
links {
"protobuf"
}
protobuf.includes()
end
function protobuf.includes()
includedirs {
path.join(protobuf.source, "src"),
}
end
function protobuf.project()
project "protobuf"
language "C++"
protobuf.includes()
files {
path.join(protobuf.source, "src/**.cc"),
"./src/**.proto",
}
removefiles {
path.join(protobuf.source, "src/**/*test.cc"),
path.join(protobuf.source, "src/google/protobuf/*test*.cc"),
path.join(protobuf.source, "src/google/protobuf/testing/**.cc"),
path.join(protobuf.source, "src/google/protobuf/compiler/**.cc"),
path.join(protobuf.source, "src/google/protobuf/arena_nc.cc"),
path.join(protobuf.source, "src/google/protobuf/util/internal/error_listener.cc"),
path.join(protobuf.source, "**/*_gcc.cc"),
}
rules {
"ProtobufCompiler"
}
defines {
"_SCL_SECURE_NO_WARNINGS",
"_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS",
"_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS",
}
linkoptions {
"-IGNORE:4221"
}
warnings "Off"
kind "StaticLib"
end
table.insert(dependencies, protobuf)

37
deps/premake/udis86.lua vendored Normal file
View File

@ -0,0 +1,37 @@
udis86 = {
source = path.join(dependencies.basePath, "udis86"),
}
function udis86.import()
links {
"udis86"
}
udis86.includes()
end
function udis86.includes()
includedirs {
udis86.source,
path.join(udis86.source, "libudis86"),
path.join(dependencies.basePath, "extra/udis86"),
path.join(dependencies.basePath, "extra/udis86/libudis86"),
}
end
function udis86.project()
project "udis86"
language "C"
udis86.includes()
files {
path.join(udis86.source, "libudis86/*.c"),
path.join(dependencies.basePath, "extra/udis86/libudis86/*.c"),
}
warnings "Off"
kind "StaticLib"
end
table.insert(dependencies, udis86)

32
deps/premake/wintoast.lua vendored Normal file
View File

@ -0,0 +1,32 @@
wintoast = {
source = path.join(dependencies.basePath, "WinToast"),
}
function wintoast.import()
links { "WinToast" }
wintoast.includes()
end
function wintoast.includes()
includedirs {
path.join(wintoast.source, "src"),
}
end
function wintoast.project()
project "WinToast"
language "C++"
wintoast.includes()
rapidjson.import();
files {
path.join(wintoast.source, "src/*.h"),
path.join(wintoast.source, "src/*.cpp"),
}
warnings "Off"
kind "StaticLib"
end
table.insert(dependencies, wintoast)

39
deps/premake/zlib.lua vendored Normal file
View File

@ -0,0 +1,39 @@
zlib = {
source = path.join(dependencies.basePath, "zlib"),
}
function zlib.import()
links { "zlib" }
zlib.includes()
end
function zlib.includes()
includedirs {
zlib.source
}
defines {
"ZLIB_CONST",
}
end
function zlib.project()
project "zlib"
language "C"
zlib.includes()
files {
path.join(zlib.source, "*.h"),
path.join(zlib.source, "*.c"),
}
defines {
"_CRT_SECURE_NO_DEPRECATE",
}
warnings "Off"
kind "StaticLib"
end
table.insert(dependencies, zlib)

1
deps/protobuf vendored Submodule

@ -0,0 +1 @@
Subproject commit 7956ad20d6a1a43d2b2f7758636b72d4427681c7

1
deps/udis86 vendored Submodule

@ -0,0 +1 @@
Subproject commit 56ff6c87c11de0ffa725b14339004820556e343d

1
deps/zlib vendored Submodule

@ -0,0 +1 @@
Subproject commit cacf7f1d4e3d44d871b605da3b647f07d718623f

View File

@ -1,3 +1,3 @@
@echo off
git submodule update --init --recursive
tools\windows\premake5.exe vs2019
tools\premake5 %* vs2019

View File

@ -66,56 +66,300 @@ function dependencies.projects()
end
end
newoption {
trigger = "copy-to",
description = "Optional, copy the EXE to a custom folder after build, define the path here if wanted.",
value = "PATH"
}
newoption {
trigger = "dev-build",
description = "Enable development 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 .. "/src/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
}
dependencies.load()
workspace "h2-mod"
location "./build"
objdir "%{wks.location}/obj/%{cfg.buildcfg}"
targetdir "%{wks.location}/bin/%{cfg.buildcfg}"
targetname "%{prj.name}"
startproject "client"
location "./build"
objdir "%{wks.location}/obj"
targetdir "%{wks.location}/bin/%{cfg.platform}/%{cfg.buildcfg}"
language "C++"
configurations {"Debug", "Release"}
architecture "x64"
platforms "x64"
architecture "x64"
platforms "x64"
buildoptions "/std:c++latest"
systemversion "latest"
buildoptions "/std:c++latest"
systemversion "latest"
symbols "On"
staticruntime "On"
editandcontinue "Off"
warnings "Extra"
characterset "ASCII"
flags
{
"NoIncrementalLink",
"MultiProcessorCompile",
}
if _OPTIONS["dev-build"] then
defines {"DEV_BUILD"}
end
configurations { "Debug", "Release", }
if os.getenv("CI") then
defines {"CI"}
end
symbols "On"
configuration "Release"
optimize "Full"
defines { "NDEBUG" }
configuration{}
flags {"NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks"}
configuration "Debug"
optimize "Debug"
defines { "DEBUG", "_DEBUG" }
configuration {}
startproject "h2-mod"
configuration "windows"
defines {"_WINDOWS", "WIN32"}
project "h2-mod"
kind "SharedLib"
language "C++"
configuration "Release"
optimize "Size"
buildoptions {"/GL"}
linkoptions { "/IGNORE:4702", "/LTCG" }
pchheader "stdinc.hpp"
pchsource "src/stdinc.cpp"
defines {"NDEBUG"}
includedirs { "src" }
files { "src/**.h", "src/**.hpp", "src/**.cpp" }
dependencies.imports()
group "Dependencies"
dependencies.projects()
flags {"FatalCompileWarnings"}
configuration "Debug"
optimize "Debug"
defines {"DEBUG", "_DEBUG"}
configuration {}
project "common"
kind "StaticLib"
language "C++"
files {"./src/common/**.hpp", "./src/common/**.cpp"}
includedirs {"./src/common", "%{prj.location}/src"}
resincludedirs {"$(ProjectDir)src"}
dependencies.imports()
project "runner"
kind "WindowedApp"
language "C++"
files {"./src/runner/**.rc", "./src/runner/**.hpp", "./src/runner/**.cpp", "./src/runner/resources/**.*"}
includedirs {"./src/runner", "./src/common", "%{prj.location}/src"}
resincludedirs {"$(ProjectDir)src"}
links {"common"}
dependencies.imports()
project "client"
kind "ConsoleApp"
language "C++"
targetname "h2-mod"
pchheader "std_include.hpp"
pchsource "src/client/std_include.cpp"
linkoptions {"/IGNORE:4254", "/DYNAMICBASE:NO", "/SAFESEH:NO", "/LARGEADDRESSAWARE", "/LAST:.main", "/PDBCompress"}
files {"./src/client/**.rc", "./src/client/**.hpp", "./src/client/**.cpp", "./src/client/resources/**.*"}
includedirs {"./src/client", "./src/common", "%{prj.location}/src"}
resincludedirs {"$(ProjectDir)src"}
dependson {"tlsdll", "runner"}
links {"common"}
prebuildcommands {"pushd %{_MAIN_SCRIPT_DIR}", "tools\\premake5 generate-buildinfo", "popd"}
if _OPTIONS["copy-to"] then
postbuildcommands {"copy /y \"$(TargetPath)\" \"" .. _OPTIONS["copy-to"] .. "\""}
end
dependencies.imports()
project "tlsdll"
kind "SharedLib"
language "C++"
files {"./src/tlsdll/**.rc", "./src/tlsdll/**.hpp", "./src/tlsdll/**.cpp", "./src/tlsdll/resources/**.*"}
includedirs {"./src/tlsdll", "%{prj.location}/src"}
links {"common"}
resincludedirs {"$(ProjectDir)src"}
project "runner"
kind "WindowedApp"
language "C++"
files {"./src/runner/**.rc", "./src/runner/**.hpp", "./src/runner/**.cpp", "./src/runner/resources/**.*"}
includedirs {"./src/runner", "./src/common", "%{prj.location}/src"}
links {"common"}
resincludedirs {"$(ProjectDir)src"}
links {"common"}
dependencies.imports()
group "Dependencies"
dependencies.projects()
rule "ProtobufCompiler"
display "Protobuf compiler"
location "./build"
fileExtension ".proto"
buildmessage "Compiling %(Identity) with protoc..."
buildcommands {'@echo off', 'path "$(SolutionDir)\\..\\tools"',
'if not exist "$(ProjectDir)\\src\\proto" mkdir "$(ProjectDir)\\src\\proto"',
'protoc --error_format=msvs -I=%(RelativeDir) --cpp_out=src\\proto %(Identity)'}
buildoutputs {'$(ProjectDir)\\src\\proto\\%(Filename).pb.cc', '$(ProjectDir)\\src\\proto\\%(Filename).pb.h'}

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "localized_strings.hpp"
#include "scheduler.hpp"
@ -15,14 +15,14 @@ namespace branding
public:
void post_unpack() override
{
localized_strings::override("MENU_SP_CAMPAIGN", "Campaign [h2-mod]");
localized_strings::override("MENU_SP_CAMPAIGN", "H2-Mod");
scheduler::loop([]()
{
const auto x = 4;
const auto y = 4;
const auto x = 15.f;
const auto y = 15.f;
const auto scale = 1.0f;
float color[4] = {0.9f, 0.9f, 0.5f, 1.0f};
float color[4] = {0.9f, 0.9f, 0.5f, 1.f};
const auto* text = "h2-mod";
auto* font = game::R_RegisterFont("fonts/defaultBold.otf", 22);

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"

View File

@ -0,0 +1,41 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game_console.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include <utils/hook.hpp>
namespace console
{
namespace
{
DWORD WINAPI console(LPVOID)
{
ShowWindow(GetConsoleWindow(), SW_SHOW);
std::string cmd;
while (true)
{
std::getline(std::cin, cmd);
game_console::execute(cmd.data());
}
return 0;
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
CreateThread(0, 0, console, 0, 0, 0);
}
};
}
REGISTER_COMPONENT(console::component)

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"

View File

@ -0,0 +1,244 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
#include <utils/io.hpp>
#include <utils/string.hpp>
#include <utils/thread.hpp>
#include <utils/compression.hpp>
#include <exception/minidump.hpp>
#include <version.hpp>
#include "game/dvars.hpp"
namespace exception
{
namespace
{
thread_local struct
{
DWORD code = 0;
PVOID address = nullptr;
} exception_data;
struct
{
std::chrono::time_point<std::chrono::high_resolution_clock> last_recovery{};
std::atomic<int> recovery_counts = {0};
} recovery_data;
bool is_game_thread()
{
static std::vector<int> allowed_threads =
{
game::THREAD_CONTEXT_MAIN,
};
const auto self_id = GetCurrentThreadId();
for (const auto& index : allowed_threads)
{
if (game::threadIds[index] == self_id)
{
return true;
}
}
return false;
}
bool is_exception_interval_too_short()
{
const auto delta = std::chrono::high_resolution_clock::now() - recovery_data.last_recovery;
return delta < 1min;
}
bool too_many_exceptions_occured()
{
return recovery_data.recovery_counts >= 3;
}
volatile bool& is_initialized()
{
static volatile bool initialized = false;
return initialized;
}
bool is_recoverable()
{
return is_initialized()
&& is_game_thread()
&& !is_exception_interval_too_short()
&& !too_many_exceptions_occured();
}
void show_mouse_cursor()
{
while (ShowCursor(TRUE) < 0);
}
void display_error_dialog()
{
std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p.\n"
"A minidump has been written.\n\n",
exception_data.code, (uint64_t)exception_data.address - game::base_address);
error_str += "Make sure to update your graphics card drivers and install operating system updates!";
utils::thread::suspend_other_threads();
show_mouse_cursor();
MessageBoxA(nullptr, error_str.data(), "H2-Mod ERROR", MB_ICONERROR);
TerminateProcess(GetCurrentProcess(), exception_data.code);
}
void reset_state()
{
if (dvars::cg_legacyCrashHandling && dvars::cg_legacyCrashHandling->current.enabled)
{
display_error_dialog();
}
if (is_recoverable())
{
recovery_data.last_recovery = std::chrono::high_resolution_clock::now();
++recovery_data.recovery_counts;
game::Com_Error(game::ERR_DROP, "Fatal error (0x%08X) at 0x%p.\nA minidump has been written.\n\n"
"H2-Mod has tried to recover your game, but it might not run stable anymore.\n\n"
"Make sure to update your graphics card drivers and install operating system updates!\n",
exception_data.code, exception_data.address);
}
else
{
display_error_dialog();
}
}
size_t get_reset_state_stub()
{
static auto* stub = utils::hook::assemble([](utils::hook::assembler& a)
{
a.sub(rsp, 0x10);
a.or_(rsp, 0x8);
a.jmp(reset_state);
});
return reinterpret_cast<size_t>(stub);
}
std::string get_timestamp()
{
tm ltime{};
char timestamp[MAX_PATH] = {0};
const auto time = _time64(nullptr);
_localtime64_s(&ltime, &time);
strftime(timestamp, sizeof(timestamp) - 1, "%Y-%m-%d-%H-%M-%S", &ltime);
return timestamp;
}
std::string generate_crash_info(const LPEXCEPTION_POINTERS exceptioninfo)
{
std::string info{};
const auto line = [&info](const std::string& text)
{
info.append(text);
info.append("\r\n");
};
line("H2-MOD Crash Dump");
line("");
line("Version: "s + VERSION);
line("Environment: "s + game::environment::get_string());
line("Timestamp: "s + get_timestamp());
line(utils::string::va("Exception: 0x%08X", exceptioninfo->ExceptionRecord->ExceptionCode));
line(utils::string::va("Address: 0x%llX", (uint64_t)exceptioninfo->ExceptionRecord->ExceptionAddress - game::base_address));
line(utils::string::va("Base: 0x%llX", game::base_address));
#pragma warning(push)
#pragma warning(disable: 4996)
OSVERSIONINFOEXA version_info;
ZeroMemory(&version_info, sizeof(version_info));
version_info.dwOSVersionInfoSize = sizeof(version_info);
GetVersionExA(reinterpret_cast<LPOSVERSIONINFOA>(&version_info));
#pragma warning(pop)
line(utils::string::va("OS Version: %u.%u", version_info.dwMajorVersion, version_info.dwMinorVersion));
return info;
}
void write_minidump(const LPEXCEPTION_POINTERS exceptioninfo)
{
const std::string crash_name = utils::string::va("minidumps/h2-mod-crash-%d-%s.zip",
game::environment::get_real_mode(),
get_timestamp().data());
utils::compression::zip::archive zip_file{};
zip_file.add("crash.dmp", create_minidump(exceptioninfo));
zip_file.add("info.txt", generate_crash_info(exceptioninfo));
zip_file.write(crash_name, "H2-Mod Crash Dump");
}
bool is_harmless_error(const LPEXCEPTION_POINTERS exceptioninfo)
{
const auto code = exceptioninfo->ExceptionRecord->ExceptionCode;
return code == STATUS_INTEGER_OVERFLOW || code == STATUS_FLOAT_OVERFLOW || code == STATUS_SINGLE_STEP;
}
LONG WINAPI exception_filter(const LPEXCEPTION_POINTERS exceptioninfo)
{
if (is_harmless_error(exceptioninfo))
{
return EXCEPTION_CONTINUE_EXECUTION;
}
write_minidump(exceptioninfo);
exception_data.code = exceptioninfo->ExceptionRecord->ExceptionCode;
exception_data.address = exceptioninfo->ExceptionRecord->ExceptionAddress;
exceptioninfo->ContextRecord->Rip = get_reset_state_stub();
return EXCEPTION_CONTINUE_EXECUTION;
}
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI set_unhandled_exception_filter_stub(LPTOP_LEVEL_EXCEPTION_FILTER)
{
// Don't register anything here...
return &exception_filter;
}
}
class component final : public component_interface
{
public:
component()
{
SetUnhandledExceptionFilter(exception_filter);
}
void post_load() override
{
SetUnhandledExceptionFilter(exception_filter);
utils::hook::jump(SetUnhandledExceptionFilter, set_unhandled_exception_filter_stub, true);
scheduler::on_game_initialized([]()
{
is_initialized() = true;
});
}
void post_unpack() override
{
dvars::cg_legacyCrashHandling = dvars::register_bool("cg_legacyCrashHandling", false,
game::DVAR_FLAG_SAVED, "Disable new crash handling");
}
};
}
REGISTER_COMPONENT(exception::component)

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "fastfiles.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
@ -18,7 +18,6 @@ namespace fps
{
namespace
{
std::chrono::nanoseconds frametime;
auto lastframe = std::chrono::high_resolution_clock::now();
game::dvar_t* cg_drawfps;
@ -128,7 +127,7 @@ namespace fps
const auto frametime = now - lastframe;
lastframe = now;
const int fps = 1000000000 / frametime.count();
const int fps = (int)(1000000000 / (int)frametime.count());
if (index >= history_count)
{

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
@ -710,8 +710,6 @@ namespace game_console
history.clear();
});
char a2[1] = {};
// add our dvars
dvars::con_inputBoxColor = dvars::register_vec4(
"con_inputBoxColor",

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "images.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "localized_strings.hpp"
#include <utils/hook.hpp>

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"

View File

@ -1,8 +1,6 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
@ -21,6 +19,18 @@ namespace patches
pm_crashland_hook.invoke<void>(ps, pm);
}
}
uint64_t off_11C52460;
void* sub_46148()
{
off_11C52460 = game::base_address + 0xAD0C58;
return &off_11C52460;
}
bool _true()
{
return true;
}
}
class component final : public component_interface
@ -28,23 +38,16 @@ namespace patches
public:
void post_unpack() override
{
// Not sure but it works
utils::hook::jump(game::base_address + 0x633080, _true, true);
utils::hook::jump(game::base_address + 0x272F70, _true, true);
utils::hook::jump(game::base_address + 0x46148, sub_46148, true);
// Unlock fps in main menu
utils::hook::set<BYTE>(game::base_address + 0x3D8E1B, 0xEB);
// Disable battle net popup
utils::hook::set(game::base_address + 0xBE7F83C, true);
// Allow kbam input when gamepad is enabled
utils::hook::nop(game::base_address + 0x3D2F8E, 2);
utils::hook::nop(game::base_address + 0x3D0C9C, 6);
scheduler::once([]()
{
if (game::Menu_IsMenuOpenAndVisible(0, "bnet_error_popup"))
{
game::LUI_OpenMenu(0, "", 1, 0, 0);
}
}, scheduler::pipeline::main);
utils::hook::nop(game::base_address + 0x5F4496, 5);
pm_crashland_hook.create(game::base_address + 0x688A20, pm_crashland_stub);
dvars::jump_enableFallDamage = dvars::register_bool("jump_enableFallDamage", 1, game::DVAR_FLAG_REPLICATED);

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
@ -145,6 +145,21 @@ namespace scheduler
}, type, delay);
}
void on_game_initialized(const std::function<void()>& callback, const pipeline type,
const std::chrono::milliseconds delay)
{
schedule([=]()
{
if (game::Sys_IsDatabaseReady2())
{
once(callback, type, delay);
return cond_end;
}
return cond_continue;
}, pipeline::main);
}
class component final : public component_interface
{
public:

View File

@ -28,4 +28,6 @@ namespace scheduler
std::chrono::milliseconds delay = 0ms);
void once(const std::function<void()>& callback, pipeline type = pipeline::async,
std::chrono::milliseconds delay = 0ms);
void on_game_initialized(const std::function<void()>& callback, pipeline type = pipeline::async,
std::chrono::milliseconds delay = 0ms);
}

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include <utils/string.hpp>
#include "game.hpp"
@ -18,7 +18,8 @@ namespace dvars
game::dvar_t* jump_enableFallDamage;
game::dvar_t* r_fullbright;
game::dvar_t* r_chams;
game::dvar_t* cg_legacyCrashHandling;
std::string dvar_get_vector_domain(const int components, const game::dvar_limits& domain)
{

View File

@ -19,7 +19,8 @@ namespace dvars
extern game::dvar_t* jump_enableFallDamage;
extern game::dvar_t* r_fullbright;
extern game::dvar_t* r_chams;
extern game::dvar_t* cg_legacyCrashHandling;
extern std::vector<std::string> dvar_list;

81
src/client/game/game.cpp Normal file
View File

@ -0,0 +1,81 @@
#include <std_include.hpp>
#include "game.hpp"
namespace game
{
uint64_t base_address;
void load_base_address()
{
const auto module = GetModuleHandle(NULL);
base_address = uint64_t(module);
}
namespace environment
{
launcher::mode mode = launcher::mode::none;
launcher::mode translate_surrogate(const launcher::mode _mode)
{
switch (_mode)
{
case launcher::mode::survival:
case launcher::mode::zombies:
return launcher::mode::multiplayer;
default:
return _mode;
}
}
launcher::mode get_real_mode()
{
if (mode == launcher::mode::none)
{
throw std::runtime_error("Launcher mode not valid. Something must be wrong.");
}
return mode;
}
launcher::mode get_mode()
{
return translate_surrogate(get_real_mode());
}
bool is_sp()
{
return get_mode() == launcher::mode::singleplayer;
}
bool is_mp()
{
return get_mode() == launcher::mode::multiplayer;
}
bool is_dedi()
{
return get_mode() == launcher::mode::server;
}
void set_mode(const launcher::mode _mode)
{
mode = _mode;
}
std::string get_string()
{
const auto current_mode = get_real_mode();
switch (current_mode)
{
case launcher::mode::singleplayer:
return "Singleplayer";
case launcher::mode::none:
return "None";
default:
return "Unknown (" + std::to_string(static_cast<int>(mode)) + ")";
}
}
}
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "structs.hpp"
#include "launcher/launcher.hpp"
namespace game
{
@ -8,6 +9,20 @@ namespace game
void load_base_address();
namespace environment
{
launcher::mode get_mode();
launcher::mode get_real_mode();
bool is_sp();
bool is_mp();
bool is_dedi();
void set_mode(launcher::mode mode);
std::string get_string();
}
template <typename T>
class symbol
{

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "entity.hpp"
#include "script_value.hpp"
#include "execution.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "execution.hpp"
#include "safe_execution.hpp"
#include "stack_isolation.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
// This file has been generated.
// Do not touch!

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "functions.hpp"
#include <utils/string.hpp>

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "context.hpp"
#include "error.hpp"
#include "value_conversion.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "engine.hpp"
#include "context.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "error.hpp"
#include "../execution.hpp"

View File

@ -1,4 +1,4 @@
#include "stdinc.hpp"
#include "std_include.hpp"
#include "context.hpp"
#include "error.hpp"
#include "value_conversion.hpp"

View File

@ -1,4 +1,4 @@
#include "stdinc.hpp"
#include "std_include.hpp"
#include "context.hpp"
#include "error.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "value_conversion.hpp"
#include "../functions.hpp"
#include "../execution.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "safe_execution.hpp"
#pragma warning(push)

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "script_value.hpp"
#include "entity.hpp"

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "stack_isolation.hpp"
namespace scripting

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "variable_value.hpp"
namespace scripting

View File

@ -1,4 +1,4 @@
#include <stdinc.hpp>
#include <std_include.hpp>
#include "vector.hpp"
namespace scripting

View File

@ -239,6 +239,41 @@ namespace game
K_LAST_KEY = 0xDF
};
enum errorParm
{
ERR_FATAL = 0,
ERR_DROP = 1,
ERR_SERVERDISCONNECT = 2,
ERR_DISCONNECT = 3,
ERR_SCRIPT = 4,
ERR_SCRIPT_DROP = 5,
ERR_LOCALIZATION = 6,
ERR_MAPLOADERRORSUMMARY = 7,
};
enum threadType
{
THREAD_CONTEXT_MAIN = 0x0,
THREAD_CONTEXT_BACKEND = 0x1,
THREAD_CONTEXT_WORKER0 = 0x2,
THREAD_CONTEXT_WORKER1 = 0x3,
THREAD_CONTEXT_WORKER2 = 0x4,
THREAD_CONTEXT_WORKER3 = 0x5,
THREAD_CONTEXT_WORKER4 = 0x6,
THREAD_CONTEXT_WORKER5 = 0x7,
THREAD_CONTEXT_WORKER6 = 0x8,
THREAD_CONTEXT_WORKER7 = 0x9,
THREAD_CONTEXT_SERVER = 0xA,
THREAD_CONTEXT_TRACE_COUNT = 0xB,
THREAD_CONTEXT_TRACE_LAST = 0xA,
THREAD_CONTEXT_CINEMATIC = 0xB,
THREAD_CONTEXT_DATABASE = 0xC,
THREAD_CONTEXT_STREAM = 0xD,
THREAD_CONTEXT_SNDSTREAMPACKETCALLBACK = 0xE,
THREAD_CONTEXT_STATS_WRITE = 0xF,
THREAD_CONTEXT_COUNT = 0x10,
};
struct KeyState
{
int down;

View File

@ -20,6 +20,7 @@ namespace game
WEAK symbol<void(const char* cmdName, void(), cmd_function_s* allocedCmd)> Cmd_AddCommandInternal{0x59A5F0};
WEAK symbol<void(int localClientNum, int controllerIndex, const char* text)> Cmd_ExecuteSingleCommand{0x59ABA0};
WEAK symbol<void(errorParm code, const char* message, ...)> Com_Error{0x5A2D80};
WEAK symbol<void()> Com_Quit_f{0x5A50D0};
WEAK symbol<void(XAssetType type, void(__cdecl* func)(game::XAssetHeader, void*), const void* inData, bool includeOverride)>
@ -95,6 +96,7 @@ namespace game
WEAK symbol<bool()> SV_Loaded{0x6B3860};
WEAK symbol<void()> Sys_ShowConsole{0x633080};
WEAK symbol<bool()> Sys_IsDatabaseReady2{0x5A9FE0};
WEAK symbol<const char*(const char* string)> UI_SafeTranslateString{0x5A2930};
@ -111,6 +113,8 @@ namespace game
WEAK symbol<gentity_s> g_entities{0x52DDDA0};
WEAK symbol<DWORD> threadIds{0xB11DC80};
WEAK symbol<GfxDrawMethod_s> gfxDrawMethod{0xEDF9E00};
WEAK symbol<int> keyCatchers{0x203F3C0};

View File

@ -0,0 +1,115 @@
#include <std_include.hpp>
#include "html_frame.hpp"
doc_host_ui_handler::doc_host_ui_handler(html_frame* frame): frame_(frame)
{
}
HRESULT doc_host_ui_handler::QueryInterface(REFIID riid, LPVOID* ppvObj)
{
auto client_site = this->frame_->get_client_site();
if (client_site)
{
return client_site->QueryInterface(riid, ppvObj);
}
return E_NOINTERFACE;
}
ULONG doc_host_ui_handler::AddRef()
{
return 1;
}
ULONG doc_host_ui_handler::Release()
{
return 1;
}
HRESULT doc_host_ui_handler::ShowContextMenu(DWORD /*dwID*/, POINT* /*ppt*/, IUnknown* /*pcmdtReserved*/,
IDispatch* /*pdispReserved*/)
{
return S_OK;
}
HRESULT doc_host_ui_handler::ShowUI(DWORD /*dwID*/, IOleInPlaceActiveObject* /*pActiveObject*/,
IOleCommandTarget* /*pCommandTarget*/,
IOleInPlaceFrame* /*pFrame*/, IOleInPlaceUIWindow* /*pDoc*/)
{
return S_OK;
}
HRESULT doc_host_ui_handler::HideUI()
{
return S_OK;
}
HRESULT doc_host_ui_handler::UpdateUI()
{
return S_OK;
}
HRESULT doc_host_ui_handler::EnableModeless(BOOL /*fEnable*/)
{
return S_OK;
}
HRESULT doc_host_ui_handler::OnDocWindowActivate(BOOL /*fActivate*/)
{
return S_OK;
}
HRESULT doc_host_ui_handler::OnFrameWindowActivate(BOOL /*fActivate*/)
{
return S_OK;
}
HRESULT doc_host_ui_handler::ResizeBorder(LPCRECT /*prcBorder*/, IOleInPlaceUIWindow* /*pUIWindow*/,
BOOL /*fRameWindow*/)
{
return S_OK;
}
HRESULT doc_host_ui_handler::TranslateAcceleratorA(LPMSG /*lpMsg*/, const GUID* pguidCmdGroup, DWORD /*nCmdID*/)
{
pguidCmdGroup = nullptr;
return S_FALSE;
}
HRESULT doc_host_ui_handler::GetOptionKeyPath(LPOLESTR* /*pchKey*/, DWORD /*dw*/)
{
return S_FALSE;
}
HRESULT doc_host_ui_handler::GetDropTarget(IDropTarget* /*pDropTarget*/, IDropTarget** /*ppDropTarget*/)
{
return S_FALSE;
}
HRESULT doc_host_ui_handler::GetExternal(IDispatch** ppDispatch)
{
*ppDispatch = this->frame_->get_html_dispatch();
return (*ppDispatch) ? S_OK : S_FALSE;
}
HRESULT doc_host_ui_handler::FilterDataObject(IDataObject* /*pDO*/, IDataObject** ppDORet)
{
*ppDORet = nullptr;
return S_FALSE;
}
HRESULT STDMETHODCALLTYPE doc_host_ui_handler::TranslateUrl(DWORD /*dwTranslate*/, OLECHAR __RPC_FAR* /*pchURLIn*/,
OLECHAR __RPC_FAR* __RPC_FAR* ppchURLOut)
{
*ppchURLOut = nullptr;
return S_FALSE;
}
HRESULT doc_host_ui_handler::GetHostInfo(DOCHOSTUIINFO __RPC_FAR * pInfo)
{
pInfo->cbSize = sizeof(DOCHOSTUIINFO);
pInfo->dwFlags = DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_DPI_AWARE /*| DOCHOSTUIFLAG_SCROLL_NO*/;
pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT;
return S_OK;
}

View File

@ -0,0 +1,47 @@
#pragma once
class html_frame;
class doc_host_ui_handler final : public IDocHostUIHandler
{
public:
doc_host_ui_handler(html_frame* frame);
virtual ~doc_host_ui_handler() = default;
private:
html_frame* frame_;
public: // IDocHostUIHandler interface
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID* ppvObj) override;
ULONG STDMETHODCALLTYPE AddRef() override;
ULONG STDMETHODCALLTYPE Release() override;
HRESULT STDMETHODCALLTYPE ShowContextMenu(
DWORD dwID,
POINT __RPC_FAR * ppt,
IUnknown __RPC_FAR * pcmdtReserved,
IDispatch __RPC_FAR * pdispReserved) override;
HRESULT STDMETHODCALLTYPE ShowUI(
DWORD dwID,
IOleInPlaceActiveObject __RPC_FAR * pActiveObject,
IOleCommandTarget __RPC_FAR * pCommandTarget,
IOleInPlaceFrame __RPC_FAR * pFrame,
IOleInPlaceUIWindow __RPC_FAR * pDoc) override;
HRESULT STDMETHODCALLTYPE GetHostInfo(DOCHOSTUIINFO __RPC_FAR * pInfo) override;
HRESULT STDMETHODCALLTYPE HideUI() override;
HRESULT STDMETHODCALLTYPE UpdateUI() override;
HRESULT STDMETHODCALLTYPE EnableModeless(BOOL fEnable) override;
HRESULT STDMETHODCALLTYPE OnDocWindowActivate(BOOL fActivate) override;
HRESULT STDMETHODCALLTYPE OnFrameWindowActivate(BOOL fActivate) override;
HRESULT STDMETHODCALLTYPE ResizeBorder(LPCRECT prcBorder, IOleInPlaceUIWindow __RPC_FAR * pUIWindow,
BOOL fRameWindow) override;
HRESULT STDMETHODCALLTYPE TranslateAccelerator(LPMSG lpMsg, const GUID __RPC_FAR * pguidCmdGroup, DWORD nCmdID)
override;
HRESULT STDMETHODCALLTYPE GetOptionKeyPath(LPOLESTR __RPC_FAR * pchKey, DWORD dw) override;
HRESULT STDMETHODCALLTYPE GetDropTarget(IDropTarget __RPC_FAR * pDropTarget,
IDropTarget __RPC_FAR *__RPC_FAR * ppDropTarget) override;
HRESULT STDMETHODCALLTYPE GetExternal(IDispatch __RPC_FAR *__RPC_FAR * ppDispatch) override;
HRESULT STDMETHODCALLTYPE TranslateUrl(DWORD dwTranslate, OLECHAR __RPC_FAR * pchURLIn,
OLECHAR __RPC_FAR *__RPC_FAR * ppchURLOut) override;
HRESULT STDMETHODCALLTYPE FilterDataObject(IDataObject __RPC_FAR * pDO, IDataObject __RPC_FAR *__RPC_FAR * ppDORet)
override;
};

View File

@ -0,0 +1,48 @@
#include <std_include.hpp>
#include "html_argument.hpp"
html_argument::html_argument(VARIANT* val) : value_(val)
{
}
bool html_argument::is_empty() const
{
return this->value_ == nullptr || this->value_->vt == VT_EMPTY;
}
bool html_argument::is_string() const
{
if (this->is_empty()) return false;
return this->value_->vt == VT_BSTR;
}
bool html_argument::is_number() const
{
if (this->is_empty()) return false;
return this->value_->vt == VT_I4;
}
bool html_argument::is_bool() const
{
if (this->is_empty()) return false;
return this->value_->vt == VT_BOOL;
}
std::string html_argument::get_string() const
{
if (!this->is_string()) return {};
std::wstring wide_string(this->value_->bstrVal);
return std::string(wide_string.begin(), wide_string.end());
}
int html_argument::get_number() const
{
if (!this->is_number()) return 0;
return this->value_->intVal;
}
bool html_argument::get_bool() const
{
if (!this->is_bool()) return false;
return this->value_->boolVal != FALSE;
}

View File

@ -0,0 +1,20 @@
#pragma once
class html_argument final
{
public:
html_argument(VARIANT* val);
bool is_empty() const;
bool is_string() const;
bool is_number() const;
bool is_bool() const;
std::string get_string() const;
int get_number() const;
bool get_bool() const;
private:
VARIANT* value_;
};

View File

@ -0,0 +1,61 @@
#include <std_include.hpp>
#include "html_frame.hpp"
html_dispatch::html_dispatch(html_frame* frame) : frame_(frame)
{
}
HRESULT html_dispatch::QueryInterface(const IID& riid, LPVOID* ppvObj)
{
if (!memcmp(&riid, &IID_IUnknown, sizeof(GUID)) ||
!memcmp(&riid, &IID_IDispatch, sizeof(GUID)))
{
*ppvObj = this;
this->AddRef();
return S_OK;
}
*ppvObj = nullptr;
return E_NOINTERFACE;
}
ULONG html_dispatch::AddRef()
{
return 1;
}
ULONG html_dispatch::Release()
{
return 1;
}
HRESULT html_dispatch::GetTypeInfoCount(UINT* pctinfo)
{
return S_FALSE;
}
HRESULT html_dispatch::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
{
return S_FALSE;
}
HRESULT html_dispatch::GetIDsOfNames(const IID& riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
{
for (unsigned int i = 0; i < cNames; ++i)
{
std::wstring wide_name(rgszNames[i]);
std::string name(wide_name.begin(), wide_name.end());
rgDispId[i] = this->frame_->get_callback_id(name);
}
return S_OK;
}
HRESULT html_dispatch::Invoke(DISPID dispIdMember, const IID& riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
html_frame::callback_params params(pDispParams, pVarResult);
this->frame_->invoke_callback(dispIdMember, &params);
return S_OK;
}

View File

@ -0,0 +1,24 @@
#pragma once
class html_frame;
class html_dispatch final : public IDispatch
{
public:
html_dispatch(html_frame* frame);
virtual ~html_dispatch() = default;
private:
html_frame* frame_;
public: // IDispatch interface
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID FAR* ppvObj) override;
ULONG STDMETHODCALLTYPE AddRef() override;
ULONG STDMETHODCALLTYPE Release() override;
HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT* pctinfo) override;
HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) override;
HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
override;
HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) override;
};

View File

@ -0,0 +1,295 @@
#include <std_include.hpp>
#include "html_frame.hpp"
#include <utils/nt.hpp>
std::atomic<int> html_frame::frame_count_ = 0;
html_frame::callback_params::callback_params(DISPPARAMS* params, VARIANT* res) : result(res)
{
for (auto i = params->cArgs; i > 0; --i)
{
auto* param = &params->rgvarg[i - 1];
this->arguments.emplace_back(param);
}
}
html_frame::html_frame()
: in_place_frame_(this)
, in_place_site_(this)
, ui_handler_(this)
, client_site_(this)
, html_dispatch_(this)
{
if (frame_count_++ == 0 && OleInitialize(nullptr) != S_OK)
{
throw std::runtime_error("Unable to initialize the OLE library");
}
auto needs_restart = false;
needs_restart |= set_browser_feature("FEATURE_BROWSER_EMULATION", 11000);
needs_restart |= set_browser_feature("FEATURE_GPU_RENDERING", 1);
if (needs_restart)
{
utils::nt::relaunch_self();
utils::nt::terminate(0);
}
}
html_frame::~html_frame()
{
if (--frame_count_ <= 0)
{
frame_count_ = 0;
OleUninitialize();
}
}
void html_frame::object_deleter(IUnknown* object)
{
if (object)
{
object->Release();
}
}
HWND html_frame::get_window() const
{
return this->window_;
}
std::shared_ptr<IOleObject> html_frame::get_browser_object() const
{
return this->browser_object_;
}
ole_in_place_frame* html_frame::get_in_place_frame()
{
return &this->in_place_frame_;
}
ole_in_place_site* html_frame::get_in_place_site()
{
return &this->in_place_site_;
}
doc_host_ui_handler* html_frame::get_ui_handler()
{
return &this->ui_handler_;
}
ole_client_site* html_frame::get_client_site()
{
return &this->client_site_;
}
html_dispatch* html_frame::get_html_dispatch()
{
return &this->html_dispatch_;
}
std::shared_ptr<IWebBrowser2> html_frame::get_web_browser() const
{
if (!this->browser_object_) return {};
IWebBrowser2* web_browser = nullptr;
if (FAILED(this->browser_object_->QueryInterface(IID_IWebBrowser2, reinterpret_cast<void**>(&web_browser)))
|| !web_browser)
return {};
return std::shared_ptr<IWebBrowser2>(web_browser, object_deleter);
}
std::shared_ptr<IDispatch> html_frame::get_dispatch() const
{
const auto web_browser = this->get_web_browser();
if (!web_browser) return {};
IDispatch* dispatch = nullptr;
if (FAILED(web_browser->get_Document(&dispatch)) || !dispatch) return {};
return std::shared_ptr<IDispatch>(dispatch, object_deleter);
}
std::shared_ptr<IHTMLDocument2> html_frame::get_document() const
{
const auto dispatch = this->get_dispatch();
if (!dispatch) return {};
IHTMLDocument2* document = nullptr;
if (FAILED(dispatch->QueryInterface(IID_IHTMLDocument2, reinterpret_cast<void**>(&document)))
|| !document)
return {};
return std::shared_ptr<IHTMLDocument2>(document, object_deleter);
}
void html_frame::initialize(const HWND window)
{
if (this->window_) return;
this->window_ = window;
this->create_browser();
this->initialize_browser();
}
void html_frame::create_browser()
{
LPCLASSFACTORY class_factory = nullptr;
if (FAILED(
CoGetClassObject(CLSID_WebBrowser, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, nullptr, IID_IClassFactory,
reinterpret_cast<void **>(&class_factory))) || !class_factory)
{
throw std::runtime_error("Unable to get the class factory");
}
IOleObject* browser_object = nullptr;
class_factory->CreateInstance(nullptr, IID_IOleObject, reinterpret_cast<void**>(&browser_object));
class_factory->Release();
if (!browser_object)
{
throw std::runtime_error("Unable to create browser object");
}
this->browser_object_ = std::shared_ptr<IOleObject>(browser_object, [](IOleObject* browser_object)
{
if (browser_object)
{
browser_object->Close(OLECLOSE_NOSAVE);
object_deleter(browser_object);
}
});
}
void html_frame::initialize_browser()
{
this->browser_object_->SetClientSite(this->get_client_site());
this->browser_object_->SetHostNames(L"Hostname", nullptr);
RECT rect;
GetClientRect(this->get_window(), &rect);
OleSetContainedObject(this->browser_object_.get(), TRUE);
this->browser_object_->DoVerb(OLEIVERB_SHOW, nullptr, this->get_client_site(), -1, this->get_window(), &rect);
this->resize(rect.right, rect.bottom);
}
bool html_frame::set_browser_feature(const std::string& feature, DWORD value)
{
const auto registry_path = R"(SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\)" + feature;
HKEY key = nullptr;
if (RegCreateKeyA(HKEY_CURRENT_USER, registry_path.data(), &key) == ERROR_SUCCESS)
{
RegCloseKey(key);
}
key = nullptr;
if (RegOpenKeyExA(
HKEY_CURRENT_USER, registry_path.data(), 0,
KEY_ALL_ACCESS, &key) != ERROR_SUCCESS)
{
return false; // Error :(
}
const utils::nt::library self;
const auto name = self.get_name();
DWORD type{};
auto is_new = true;
if (RegQueryValueExA(key, name.data(), nullptr, &type, nullptr, nullptr) == ERROR_SUCCESS)
{
is_new = false;
}
RegSetValueExA(key, name.data(), 0, REG_DWORD, reinterpret_cast<const BYTE*>(&value), sizeof(value));
RegCloseKey(key);
return is_new;
}
void html_frame::resize(const DWORD width, const DWORD height) const
{
auto web_browser = this->get_web_browser();
if (web_browser)
{
web_browser->put_Left(0);
web_browser->put_Top(0);
web_browser->put_Width(width);
web_browser->put_Height(height);
}
}
bool html_frame::load_url(const std::string& url) const
{
auto web_browser = this->get_web_browser();
if (!web_browser) return false;
std::wstring wide_url(url.begin(), url.end());
VARIANT my_url;
VariantInit(&my_url);
my_url.vt = VT_BSTR;
my_url.bstrVal = SysAllocString(wide_url.data());
const auto _ = gsl::finally([&my_url]() { VariantClear(&my_url); });
if (!my_url.bstrVal) return false;
return SUCCEEDED(web_browser->Navigate2(&my_url, nullptr, nullptr, nullptr, nullptr));
}
bool html_frame::load_html(const std::string& html) const
{
if (!this->load_url("about:blank")) return false;
const auto document = this->get_document();
if (!document) return false;
SAFEARRAYBOUND safe_array_bound = {1, 0};
auto safe_array = SafeArrayCreate(VT_VARIANT, 1, &safe_array_bound);
if (!safe_array) return false;
const auto _ = gsl::finally([safe_array]() { SafeArrayDestroy(safe_array); });
VARIANT* variant = nullptr;
if (FAILED(SafeArrayAccessData(safe_array, reinterpret_cast<void**>(&variant))) || !variant) return false;
std::wstring wide_html(html.begin(), html.end());
variant->vt = VT_BSTR;
variant->bstrVal = SysAllocString(wide_html.data());
if (!variant->bstrVal) return false;
document->write(safe_array);
document->close();
return true;
}
int html_frame::get_callback_id(const std::string& name)
{
for (auto i = 0u; i < this->callbacks_.size(); ++i)
{
if (this->callbacks_[i].first == name)
{
return i;
}
}
return -1;
}
void html_frame::invoke_callback(const int id, callback_params* params)
{
if (id >= 0 && static_cast<unsigned int>(id) < this->callbacks_.size())
{
this->callbacks_[id].second(params);
}
}
void html_frame::register_callback(const std::string& name, const std::function<void(callback_params*)>& callback)
{
this->callbacks_.emplace_back(name, callback);
}

View File

@ -0,0 +1,67 @@
#pragma once
#include "ole_in_place_frame.hpp"
#include "ole_in_place_site.hpp"
#include "doc_host_ui_handler.hpp"
#include "ole_client_site.hpp"
#include "html_dispatch.hpp"
#include "html_argument.hpp"
class html_frame
{
public:
class callback_params final
{
public:
callback_params(DISPPARAMS* params, VARIANT* res);
std::vector<html_argument> arguments;
html_argument result;
};
html_frame();
virtual ~html_frame();
void initialize(HWND window);
void resize(DWORD width, DWORD height) const;
bool load_url(const std::string& url) const;
bool load_html(const std::string& html) const;
HWND get_window() const;
std::shared_ptr<IOleObject> get_browser_object() const;
std::shared_ptr<IWebBrowser2> get_web_browser() const;
std::shared_ptr<IDispatch> get_dispatch() const;
std::shared_ptr<IHTMLDocument2> get_document() const;
ole_in_place_frame* get_in_place_frame();
ole_in_place_site* get_in_place_site();
doc_host_ui_handler* get_ui_handler();
ole_client_site* get_client_site();
html_dispatch* get_html_dispatch();
int get_callback_id(const std::string& name);
void invoke_callback(int id, callback_params* params);
void register_callback(const std::string& name, const std::function<void(callback_params*)>& callback);
private:
HWND window_ = nullptr;
std::shared_ptr<IOleObject> browser_object_;
ole_in_place_frame in_place_frame_;
ole_in_place_site in_place_site_;
doc_host_ui_handler ui_handler_;
ole_client_site client_site_;
html_dispatch html_dispatch_;
std::vector<std::pair<std::string, std::function<void(callback_params*)>>> callbacks_;
void create_browser();
void initialize_browser();
static bool set_browser_feature(const std::string& feature, DWORD value);
static void object_deleter(IUnknown* object);
static std::atomic<int> frame_count_;
};

View File

@ -0,0 +1,29 @@
#include <std_include.hpp>
#include "html_window.hpp"
window* html_window::get_window()
{
return this;
}
html_frame* html_window::get_html_frame()
{
return this;
}
LRESULT html_window::processor(const UINT message, const WPARAM w_param, const LPARAM l_param)
{
if (message == WM_SIZE)
{
this->resize(LOWORD(l_param), HIWORD(l_param));
return 0;
}
if (message == WM_CREATE)
{
this->initialize(*this);
return 0;
}
return window::processor(message, w_param, l_param);
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "../window.hpp"
#include "html_frame.hpp"
class html_window final : public window, public html_frame
{
public:
~html_window() = default;
window* get_window();
html_frame* get_html_frame();
private:
LRESULT processor(UINT message, WPARAM w_param, LPARAM l_param) override;
};

View File

@ -0,0 +1,77 @@
#include <std_include.hpp>
#include "html_frame.hpp"
ole_client_site::ole_client_site(html_frame* frame): frame_(frame)
{
}
HRESULT ole_client_site::QueryInterface(REFIID riid, LPVOID* ppvObject)
{
if (!memcmp(&riid, &IID_IUnknown, sizeof(GUID)) ||
!memcmp(&riid, &IID_IOleClientSite, sizeof(GUID)))
{
*ppvObject = this;
this->AddRef();
return S_OK;
}
if (!memcmp(&riid, &IID_IOleInPlaceSite, sizeof(GUID)))
{
auto in_place_site = this->frame_->get_in_place_site();
in_place_site->AddRef();
*ppvObject = in_place_site;
return S_OK;
}
if (!memcmp(&riid, &IID_IDocHostUIHandler, sizeof(GUID)))
{
auto ui_handler = this->frame_->get_ui_handler();
ui_handler->AddRef();
*ppvObject = ui_handler;
return S_OK;
}
*ppvObject = nullptr;
return E_NOINTERFACE;
}
ULONG ole_client_site::AddRef()
{
return 1;
}
ULONG ole_client_site::Release()
{
return 1;
}
HRESULT ole_client_site::SaveObject()
{
return E_NOTIMPL;
}
HRESULT ole_client_site::GetMoniker(DWORD /*dwAssign*/, DWORD /*dwWhichMoniker*/, IMoniker** /*ppmk*/)
{
return E_NOTIMPL;
}
HRESULT ole_client_site::GetContainer(LPOLECONTAINER* ppContainer)
{
*ppContainer = nullptr;
return E_NOINTERFACE;
}
HRESULT ole_client_site::ShowObject()
{
return NOERROR;
}
HRESULT ole_client_site::OnShowWindow(BOOL /*fShow*/)
{
return E_NOTIMPL;
}
HRESULT ole_client_site::RequestNewObjectLayout()
{
return E_NOTIMPL;
}

View File

@ -0,0 +1,24 @@
#pragma once
class html_frame;
class ole_client_site final : public IOleClientSite
{
public:
ole_client_site(html_frame* frame);
virtual ~ole_client_site() = default;
private:
html_frame* frame_;
public:
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID* ppvObject) override;
ULONG STDMETHODCALLTYPE AddRef() override;
ULONG STDMETHODCALLTYPE Release() override;
HRESULT STDMETHODCALLTYPE SaveObject() override;
HRESULT STDMETHODCALLTYPE GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker** ppmk) override;
HRESULT STDMETHODCALLTYPE GetContainer(LPOLECONTAINER FAR* ppContainer) override;
HRESULT STDMETHODCALLTYPE ShowObject() override;
HRESULT STDMETHODCALLTYPE OnShowWindow(BOOL fShow) override;
HRESULT STDMETHODCALLTYPE RequestNewObjectLayout() override;
};

View File

@ -0,0 +1,82 @@
#include <std_include.hpp>
#include "html_frame.hpp"
ole_in_place_frame::ole_in_place_frame(html_frame* frame): frame_(frame)
{
}
HRESULT ole_in_place_frame::QueryInterface(REFIID /*riid*/, LPVOID* /*ppvObj*/)
{
return E_NOTIMPL;
}
ULONG ole_in_place_frame::AddRef()
{
return 1;
}
ULONG ole_in_place_frame::Release()
{
return 1;
}
HRESULT ole_in_place_frame::GetWindow(HWND* lphwnd)
{
*lphwnd = this->frame_->get_window();
return S_OK;
}
HRESULT ole_in_place_frame::ContextSensitiveHelp(BOOL /*fEnterMode*/)
{
return E_NOTIMPL;
}
HRESULT ole_in_place_frame::GetBorder(LPRECT /*lprectBorder*/)
{
return E_NOTIMPL;
}
HRESULT ole_in_place_frame::RequestBorderSpace(LPCBORDERWIDTHS /*pborderwidths*/)
{
return E_NOTIMPL;
}
HRESULT ole_in_place_frame::SetBorderSpace(LPCBORDERWIDTHS /*pborderwidths*/)
{
return E_NOTIMPL;
}
HRESULT ole_in_place_frame::SetActiveObject(IOleInPlaceActiveObject* /*pActiveObject*/, LPCOLESTR /*pszObjName*/)
{
return S_OK;
}
HRESULT ole_in_place_frame::InsertMenus(HMENU /*hmenuShared*/, LPOLEMENUGROUPWIDTHS /*lpMenuWidths*/)
{
return E_NOTIMPL;
}
HRESULT ole_in_place_frame::SetMenu(HMENU /*hmenuShared*/, HOLEMENU /*holemenu*/, HWND /*hwndActiveObject*/)
{
return S_OK;
}
HRESULT ole_in_place_frame::RemoveMenus(HMENU /*hmenuShared*/)
{
return E_NOTIMPL;
}
HRESULT ole_in_place_frame::SetStatusText(LPCOLESTR /*pszStatusText*/)
{
return S_OK;
}
HRESULT ole_in_place_frame::EnableModeless(BOOL /*fEnable*/)
{
return S_OK;
}
HRESULT ole_in_place_frame::TranslateAcceleratorA(LPMSG /*lpmsg*/, WORD /*wID*/)
{
return E_NOTIMPL;
}

View File

@ -0,0 +1,30 @@
#pragma once
class html_frame;
class ole_in_place_frame final : public IOleInPlaceFrame
{
public:
ole_in_place_frame(html_frame* frame);
virtual ~ole_in_place_frame() = default;
private:
html_frame* frame_;
public: // IOleInPlaceFrame interface
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID FAR* ppvObj) override;
ULONG STDMETHODCALLTYPE AddRef() override;
ULONG STDMETHODCALLTYPE Release() override;
HRESULT STDMETHODCALLTYPE GetWindow(HWND FAR* lphwnd) override;
HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode) override;
HRESULT STDMETHODCALLTYPE GetBorder(LPRECT lprectBorder) override;
HRESULT STDMETHODCALLTYPE RequestBorderSpace(LPCBORDERWIDTHS pborderwidths) override;
HRESULT STDMETHODCALLTYPE SetBorderSpace(LPCBORDERWIDTHS pborderwidths) override;
HRESULT STDMETHODCALLTYPE SetActiveObject(IOleInPlaceActiveObject* pActiveObject, LPCOLESTR pszObjName) override;
HRESULT STDMETHODCALLTYPE InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths) override;
HRESULT STDMETHODCALLTYPE SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject) override;
HRESULT STDMETHODCALLTYPE RemoveMenus(HMENU hmenuShared) override;
HRESULT STDMETHODCALLTYPE SetStatusText(LPCOLESTR pszStatusText) override;
HRESULT STDMETHODCALLTYPE EnableModeless(BOOL fEnable) override;
HRESULT STDMETHODCALLTYPE TranslateAccelerator(LPMSG lpmsg, WORD wID) override;
};

View File

@ -0,0 +1,105 @@
#include <std_include.hpp>
#include "html_frame.hpp"
ole_in_place_site::ole_in_place_site(html_frame* frame) : frame_(frame)
{
}
HRESULT ole_in_place_site::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
{
auto client_site = this->frame_->get_client_site();
if (client_site)
{
return client_site->QueryInterface(riid, ppvObj);
}
return E_NOINTERFACE;
}
ULONG ole_in_place_site::AddRef()
{
return 1;
}
ULONG ole_in_place_site::Release()
{
return 1;
}
HRESULT ole_in_place_site::GetWindow(HWND* lphwnd)
{
*lphwnd = this->frame_->get_window();
return S_OK;
}
HRESULT ole_in_place_site::ContextSensitiveHelp(BOOL /*fEnterMode*/)
{
return E_NOTIMPL;
}
HRESULT ole_in_place_site::CanInPlaceActivate()
{
return S_OK;
}
HRESULT ole_in_place_site::OnInPlaceActivate()
{
return S_OK;
}
HRESULT ole_in_place_site::OnUIActivate()
{
return S_OK;
}
HRESULT ole_in_place_site::GetWindowContext(LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc,
LPRECT /*lprcPosRect*/, LPRECT /*lprcClipRect*/,
LPOLEINPLACEFRAMEINFO lpFrameInfo)
{
*lplpFrame = this->frame_->get_in_place_frame();
*lplpDoc = nullptr;
lpFrameInfo->fMDIApp = FALSE;
lpFrameInfo->hwndFrame = this->frame_->get_window();
lpFrameInfo->haccel = nullptr;
lpFrameInfo->cAccelEntries = 0;
return S_OK;
}
HRESULT ole_in_place_site::Scroll(SIZE /*scrollExtent*/)
{
return E_NOTIMPL;
}
HRESULT ole_in_place_site::OnUIDeactivate(BOOL /*fUndoable*/)
{
return S_OK;
}
HRESULT ole_in_place_site::OnInPlaceDeactivate()
{
return S_OK;
}
HRESULT ole_in_place_site::DiscardUndoState()
{
return E_NOTIMPL;
}
HRESULT ole_in_place_site::DeactivateAndUndo()
{
return E_NOTIMPL;
}
HRESULT ole_in_place_site::OnPosRectChange(LPCRECT lprcPosRect)
{
IOleInPlaceObject* in_place = nullptr;
if (!this->frame_->get_browser_object()->QueryInterface(IID_IOleInPlaceObject, reinterpret_cast<void**>(&in_place)))
{
in_place->SetObjectRects(lprcPosRect, lprcPosRect);
in_place->Release();
}
return S_OK;
}

View File

@ -0,0 +1,32 @@
#pragma once
class html_frame;
class ole_in_place_site final : public IOleInPlaceSite
{
public:
ole_in_place_site(html_frame* frame);
virtual ~ole_in_place_site() = default;
private:
html_frame* frame_;
public: // IOleInPlaceSite interface
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID FAR* ppvObj) override;
ULONG STDMETHODCALLTYPE AddRef() override;
ULONG STDMETHODCALLTYPE Release() override;
HRESULT STDMETHODCALLTYPE GetWindow(HWND FAR* lphwnd) override;
HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode) override;
HRESULT STDMETHODCALLTYPE CanInPlaceActivate() override;
HRESULT STDMETHODCALLTYPE OnInPlaceActivate() override;
HRESULT STDMETHODCALLTYPE OnUIActivate() override;
HRESULT STDMETHODCALLTYPE GetWindowContext(LPOLEINPLACEFRAME FAR* lplpFrame, LPOLEINPLACEUIWINDOW FAR* lplpDoc,
LPRECT lprcPosRect, LPRECT lprcClipRect,
LPOLEINPLACEFRAMEINFO lpFrameInfo) override;
HRESULT STDMETHODCALLTYPE Scroll(SIZE scrollExtent) override;
HRESULT STDMETHODCALLTYPE OnUIDeactivate(BOOL fUndoable) override;
HRESULT STDMETHODCALLTYPE OnInPlaceDeactivate() override;
HRESULT STDMETHODCALLTYPE DiscardUndoState() override;
HRESULT STDMETHODCALLTYPE DeactivateAndUndo() override;
HRESULT STDMETHODCALLTYPE OnPosRectChange(LPCRECT lprcPosRect) override;
};

View File

@ -0,0 +1,66 @@
#include <std_include.hpp>
#include "launcher.hpp"
#include <utils/nt.hpp>
launcher::launcher()
{
this->create_main_menu();
}
void launcher::create_main_menu()
{
this->main_window_.register_callback("openUrl", [](html_frame::callback_params* params)
{
if (params->arguments.empty()) return;
const auto param = params->arguments[0];
if (!param.is_string()) return;
const auto url = param.get_string();
ShellExecuteA(nullptr, "open", url.data(), nullptr, nullptr, SW_SHOWNORMAL);
});
this->main_window_.register_callback("selectMode", [this](html_frame::callback_params* params)
{
if (params->arguments.empty()) return;
const auto param = params->arguments[0];
if (!param.is_number()) return;
const auto number = static_cast<mode>(param.get_number());
this->select_mode(number);
});
this->main_window_.set_callback(
[](window* window, const UINT message, const WPARAM w_param, const LPARAM l_param) -> LRESULT
{
if (message == WM_CLOSE)
{
window::close_all();
}
return DefWindowProcA(*window, message, w_param, l_param);
});
this->main_window_.create("H2-Mod", 750, 500);
this->main_window_.load_html(load_content(MENU_MAIN));
this->main_window_.show();
}
launcher::mode launcher::run() const
{
window::run();
return this->mode_;
}
void launcher::select_mode(const mode mode)
{
this->mode_ = mode;
this->main_window_.close();
}
std::string launcher::load_content(const int res)
{
return utils::nt::load_resource(res);
}

View File

@ -0,0 +1,32 @@
#pragma once
#include "html/html_window.hpp"
class launcher final
{
public:
enum class mode
{
none,
singleplayer,
multiplayer,
server,
// Surrogates
survival,
zombies,
};
launcher();
mode run() const;
private:
mode mode_ = mode::none;
html_window main_window_;
void select_mode(mode mode);
void create_main_menu();
static std::string load_content(int res);
};

View File

@ -0,0 +1,208 @@
#include <std_include.hpp>
#include "window.hpp"
#include <utils/nt.hpp>
std::mutex window::mutex_;
std::vector<window*> window::windows_;
window::window()
{
ZeroMemory(&this->wc_, sizeof(this->wc_));
this->classname_ = "window-base-" + std::to_string(time(nullptr));
this->wc_.cbSize = sizeof(this->wc_);
this->wc_.style = CS_HREDRAW | CS_VREDRAW;
this->wc_.lpfnWndProc = static_processor;
this->wc_.hInstance = GetModuleHandle(nullptr);
this->wc_.hCursor = LoadCursor(nullptr, IDC_ARROW);
this->wc_.hIcon = LoadIcon(this->wc_.hInstance, MAKEINTRESOURCE(102));
this->wc_.hIconSm = this->wc_.hIcon;
this->wc_.hbrBackground = HBRUSH(COLOR_WINDOW);
this->wc_.lpszClassName = this->classname_.data();
RegisterClassEx(&this->wc_);
}
void window::create(const std::string& title, const int width, const int height, const long flags)
{
{
std::lock_guard _(mutex_);
windows_.push_back(this);
}
const auto x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
const auto y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
this->handle_ = CreateWindowExA(NULL, this->wc_.lpszClassName, title.data(), flags, x, y, width, height, nullptr,
nullptr, this->wc_.hInstance, this);
SendMessageA(this->handle_, WM_DPICHANGED, 0, 0);
}
window::~window()
{
this->close();
UnregisterClass(this->wc_.lpszClassName, this->wc_.hInstance);
}
void window::close()
{
if (!this->handle_) return;
SendMessageA(this->handle_, WM_KILL_WINDOW, NULL, NULL);
this->handle_ = nullptr;
}
void window::run()
{
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
void window::close_all()
{
std::unique_lock lock(mutex_);
auto window_list = windows_;
lock.unlock();
const auto current_thread_id = GetCurrentThreadId();
for (auto& window : window_list)
{
const auto thread_id = GetWindowThreadProcessId(*window, nullptr);
if (thread_id == current_thread_id)
{
window->close();
}
}
}
void window::remove_window(const window* window)
{
std::lock_guard _(mutex_);
for (auto i = windows_.begin(); i != windows_.end(); ++i)
{
if (*i == window)
{
windows_.erase(i);
break;
}
}
}
int window::get_window_count()
{
std::lock_guard _(mutex_);
auto count = 0;
const auto current_thread_id = GetCurrentThreadId();
for (const auto& window : windows_)
{
const auto thread_id = GetWindowThreadProcessId(*window, nullptr);
if (thread_id == current_thread_id)
{
++count;
}
}
return count;
}
void window::show() const
{
ShowWindow(this->handle_, SW_SHOW);
UpdateWindow(this->handle_);
}
void window::hide() const
{
ShowWindow(this->handle_, SW_HIDE);
UpdateWindow(this->handle_);
}
void window::set_callback(const std::function<LRESULT(window*, UINT, WPARAM, LPARAM)>& callback)
{
this->callback_ = callback;
}
LRESULT window::processor(const UINT message, const WPARAM w_param, const LPARAM l_param)
{
if (message == WM_DPICHANGED)
{
const utils::nt::library user32{"user32.dll"};
const auto get_dpi = user32 ? user32.get_proc<UINT(WINAPI *)(HWND)>("GetDpiForWindow") : nullptr;
if (get_dpi)
{
const auto dpi = get_dpi(*this);
if (dpi != this->last_dpi_)
{
RECT rect;
GetWindowRect(*this, &rect);
const auto scale = dpi * 1.0 / this->last_dpi_;
this->last_dpi_ = dpi;
const auto width = rect.right - rect.left;
const auto height = rect.bottom - rect.top;
MoveWindow(*this, rect.left, rect.top, int(width * scale), int(height * scale), TRUE);
}
}
}
if (message == WM_DESTROY)
{
remove_window(this);
if (get_window_count() == 0)
{
PostQuitMessage(0);
}
return TRUE;
}
if (message == WM_KILL_WINDOW)
{
DestroyWindow(*this);
return 0;
}
if (this->callback_)
{
return this->callback_(this, message, w_param, l_param);
}
return DefWindowProc(*this, message, w_param, l_param);
}
LRESULT CALLBACK window::static_processor(HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param)
{
if (message == WM_CREATE)
{
auto data = reinterpret_cast<LPCREATESTRUCT>(l_param);
SetWindowLongPtrA(hwnd, GWLP_USERDATA, LONG_PTR(data->lpCreateParams));
static_cast<window*>(data->lpCreateParams)->handle_ = hwnd;
}
const auto self = reinterpret_cast<window*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
if (self) return self->processor(message, w_param, l_param);
return DefWindowProc(hwnd, message, w_param, l_param);
}
window::operator HWND() const
{
return this->handle_;
}

Some files were not shown because too many files have changed in this diff Show More