Skip to content

Commit 79f35b6

Browse files
committed
Build two editions of launcher; Improve script extender compatability.
1 parent 17ac451 commit 79f35b6

11 files changed

Lines changed: 134 additions & 67 deletions

File tree

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11

22
#include <BuildInfo.h>
3+
#include <MinHook.h>
34
#include <TiltedCore/Initializer.hpp>
45

56
#include "Launcher.h"
67
#include "TargetConfig.h"
8+
79
#include "loader/ExeLoader.h"
10+
#include "loader/PathRerouting.h"
811

12+
#include "Utils/Error.h"
913
#include "oobe/InstallCheckFlow.h"
1014
#include "oobe/ViabilityChecks.h"
1115
#include "steam/SteamLoader.h"
12-
#include "Utils/Error.h"
1316

1417
static LaunchContext* g_context = nullptr;
1518

@@ -21,27 +24,11 @@ LaunchContext* GetLaunchContext()
2124
return g_context;
2225
}
2326

24-
static void InitEnvironment()
25-
{
26-
auto& gamePath = g_context->gamePath;
27-
auto appPath = TiltedPhoques::GetPath();
28-
29-
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_USER_DIRS);
30-
AddDllDirectory(appPath.c_str());
31-
AddDllDirectory(gamePath.c_str());
32-
SetCurrentDirectoryW(gamePath.c_str());
33-
34-
std::wstring pathBuf;
35-
pathBuf.resize(32768);
36-
GetEnvironmentVariableW(L"PATH", pathBuf.data(), static_cast<DWORD>(pathBuf.length()));
37-
38-
// append bin & game directories
39-
std::wstring newPath = appPath.native() + L";" + gamePath.native() + L";" + pathBuf;
40-
SetEnvironmentVariableW(L"PATH", newPath.c_str());
41-
}
42-
4327
void Bootstrap()
4428
{
29+
//LdrGetKnownDllSectionHandle = reinterpret_cast<decltype(LdrGetKnownDllSectionHandle)>(
30+
// GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "LdrGetKnownDllSectionHandle"));
31+
4532
auto LC = std::make_unique<LaunchContext>();
4633
g_context = LC.get();
4734

@@ -57,22 +44,30 @@ void Bootstrap()
5744
}
5845

5946
// Bind path environment.
60-
InitEnvironment();
61-
steam::Load(g_context->gamePath);
47+
loader::InstallPathRouting(LC->gamePath);
48+
steam::Load(LC->gamePath);
6249

6350
{
6451
ExeLoader loader(CurrentTarget.loadLimit, GetProcAddress);
65-
if (!loader.Load(g_context->exePath))
52+
if (!loader.Load(LC->exePath))
6653
return;
6754

68-
g_context->gameMain = loader.GetEntryPoint();
55+
LC->gameMain = loader.GetEntryPoint();
6956
}
7057

7158
TiltedPhoques::Initializer::RunAll();
72-
g_context->gameMain();
59+
LC->gameMain();
7360
}
7461

7562
void RunClient()
7663
{
77-
// LdrLoadDll at fixed address
64+
LoadLibraryA(
65+
R"(C:\Users\vince\Documents\Development\Tilted\TiltedEvolution\build\windows\x64\debug\SkyrimTogether.dll)");
66+
67+
#if 0
68+
__debugbreak();
69+
LoadLibraryA(
70+
R"(C:\Users\vince\Documents\Development\Tilted\TiltedEvolution\build\windows\x64\debug\SkyrimTogether.dll)");
71+
__debugbreak();
72+
#endif
7873
}

Code/immersive_launcher/Main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ struct ComScope
2828

2929
int main(int argc, char** argv)
3030
{
31-
CoreStubsInit();
32-
3331
// memory block for Script Extender reserved as early as we can
3432
script_extender::SEMemoryBlock b;
3533
if (!b.Good())
3634
{
37-
Die("Failed to initialize SE block zone.\nCannot continue!");
35+
Die("Failed to pre-reserve script extender zone.\nCannot continue!");
3836
return -1;
3937
}
38+
CoreStubsInit();
4039

4140
ComScope cs;
4241
TP_UNUSED(cs);

Code/immersive_launcher/TargetConfig.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ struct TargetConfig
2020

2121
#include <BranchInfo.h>
2222

23-
24-
#if (1)
25-
#define IS_SKYRIM_TYPE
26-
static const TargetConfig CurrentTarget{
23+
#if defined(TARGET_ST)
24+
static constexpr TargetConfig CurrentTarget{
2725
L"SkyrimTogether.dll",
2826
L"Skyrim Special Edition",
2927
L"Skyrim Special Edition",
3028
489830, kGenericLoadLimit};
29+
#elif defined(TARGET_FT)
30+
static constexpr TargetConfig CurrentTarget{
31+
L"FalloutTogether.dll",
32+
L"Fallout4",
33+
L"Fallout4",
34+
377160, kGenericLoadLimit};
3135
#endif
3236

3337
// clang-format on
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2021 TiltedPhoques SRL.
2+
// For licensing information see LICENSE at the root of this distribution.
3+
4+
#include "PathRerouting.h"
5+
#include <TiltedCore/Filesystem.hpp>
6+
#include <Windows.h>
7+
8+
namespace loader
9+
{
10+
void InstallPathRouting(const std::filesystem::path& gamePath)
11+
{
12+
auto appPath = TiltedPhoques::GetPath();
13+
14+
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_USER_DIRS);
15+
AddDllDirectory(appPath.c_str());
16+
AddDllDirectory(gamePath.c_str());
17+
SetCurrentDirectoryW(gamePath.c_str());
18+
19+
std::wstring pathBuf;
20+
pathBuf.resize(32768);
21+
GetEnvironmentVariableW(L"PATH", pathBuf.data(), static_cast<DWORD>(pathBuf.length()));
22+
23+
// append bin & game directories
24+
std::wstring newPath = appPath.native() + L";" + gamePath.native() + L";" + pathBuf;
25+
SetEnvironmentVariableW(L"PATH", newPath.c_str());
26+
}
27+
} // namespace loader
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (C) 2021 TiltedPhoques SRL.
2+
// For licensing information see LICENSE at the root of this distribution.
3+
#pragma once
4+
5+
#include <filesystem>
6+
7+
namespace loader
8+
{
9+
void InstallPathRouting(const std::filesystem::path&);
10+
}
467 KB
Binary file not shown.

Code/immersive_launcher/oobe/ViabilityChecks.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99

1010
namespace oobe
1111
{
12+
// D3D11 Test
13+
1214
bool TestPlatformViability(Policy apolicyLevel)
1315
{
1416
// Test hardware
15-
if (!IsWindows8OrGreater())
17+
if (!IsWindows8OrGreater() && apolicyLevel != Policy::kLax)
1618
{
1719
return false;
1820
}
1921

22+
// TODO: should also query hardware support for AES
23+
2024
// Test install
2125
auto cefDll = TiltedPhoques::GetPath() / L"libcef.dll";
2226
if (!std::filesystem::exists(cefDll))

Code/immersive_launcher/resources/launcher.rc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ END
3232

3333
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "launcher.manifest"
3434

35+
// THERE IS NO NICER WAY
36+
37+
#if defined(TARGET_ST)
3538
#if (IS_MASTER)
3639
102 ICON "st_logo.ico"
3740
#elif (IS_BRANCH_BETA)
@@ -41,3 +44,14 @@ CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "launcher.manifest"
4144
#else
4245
102 ICON "st_logo_dev.ico"
4346
#endif
47+
#elif defined(TARGET_FT)
48+
#if (IS_MASTER)
49+
102 ICON "ft_logo.ico"
50+
#elif (IS_BRANCH_BETA)
51+
102 ICON "ft_logo_beta.ico"
52+
#elif (IS_BRANCH_PREREL)
53+
102 ICON "ft_logo_pre.ico"
54+
#else
55+
102 ICON "ft_logo_dev.ico"
56+
#endif
57+
#endif
Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,45 @@
11
// Copyright (C) 2021 TiltedPhoques SRL.
22
// For licensing information see LICENSE at the root of this distribution.
33

4+
#include "SEMemoryBlock.h"
45
#include <Windows.h>
56
#include <cstdint>
6-
#include "SEMemoryBlock.h"
77

88
namespace script_extender
99
{
10-
static constexpr uint32_t kBlockLength = 1024 * 64;
10+
constexpr uintptr_t kLowRipZoneSize = 0x10000; // 1024 * 64
11+
constexpr uintptr_t kHighRipSize = 0x100000; // 1024 * 1024
12+
constexpr uintptr_t kLowRipStart = 0x80000000 + (kHighRipSize * 128);
1113

1214
SEMemoryBlock::SEMemoryBlock()
1315
{
14-
uintptr_t moduleBase = reinterpret_cast<uintptr_t>(GetModuleHandleW(nullptr));
15-
uintptr_t addr = moduleBase;
16-
uintptr_t maxDisplacement =
17-
0x80000000 - (1024 * 1024 * 128); // largest 32-bit displacement with 128MB scratch space
18-
uintptr_t lowestOKAddress = (moduleBase >= maxDisplacement) ? moduleBase - maxDisplacement : 0;
19-
addr--;
20-
21-
while (!m_pBlock)
16+
uintptr_t mainAddress = reinterpret_cast<uintptr_t>(GetModuleHandleW(nullptr)) - 1;
17+
18+
MEMORY_BASIC_INFORMATION info{};
19+
20+
// we go bottom to top
21+
uintptr_t ripAddress = kLowRipStart;
22+
while ((ripAddress + kLowRipZoneSize) < mainAddress)
2223
{
23-
MEMORY_BASIC_INFORMATION info;
24-
if (!VirtualQuery((void*)addr, &info, sizeof(info)))
25-
{
26-
break;
27-
}
24+
void* pRipSegment = reinterpret_cast<void*>(ripAddress);
25+
if (!VirtualQuery(pRipSegment, &info, sizeof(info)))
26+
return;
2827

2928
if (info.State == MEM_FREE)
3029
{
31-
if (info.RegionSize >= kBlockLength)
32-
{
33-
// try to allocate it
34-
addr = ((uintptr_t)info.BaseAddress) + info.RegionSize - kBlockLength;
35-
m_pBlock = (void*)VirtualAlloc((void*)addr, kBlockLength, MEM_RESERVE, PAGE_EXECUTE_READWRITE);
36-
}
30+
if (m_pBlock = VirtualAlloc(pRipSegment, kLowRipZoneSize, MEM_RESERVE, PAGE_EXECUTE_READWRITE))
31+
return;
3732
}
3833

39-
// move back and try again
40-
if (!m_pBlock)
41-
{
42-
addr = ((uintptr_t)info.BaseAddress) - 1;
43-
}
34+
ripAddress += kLowRipZoneSize;
4435
}
36+
37+
m_lastCanidate = ripAddress;
4538
}
4639

4740
SEMemoryBlock::~SEMemoryBlock()
4841
{
4942
if (m_pBlock)
50-
VirtualFree(m_pBlock, kBlockLength, MEM_RELEASE);
51-
}
43+
VirtualFree(m_pBlock, kLowRipZoneSize, MEM_RELEASE);
5244
}
45+
} // namespace script_extender

Code/immersive_launcher/script_extender/SEMemoryBlock.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// For licensing information see LICENSE at the root of this distribution.
33
#pragma once
44

5+
#include <cstdint>
6+
57
namespace script_extender
68
{
79
class SEMemoryBlock final
@@ -14,8 +16,14 @@ namespace script_extender
1416
{
1517
return m_pBlock;
1618
}
19+
20+
inline uintptr_t LastRip() const
21+
{
22+
return m_lastCanidate;
23+
}
1724

1825
private:
1926
void* m_pBlock = nullptr;
27+
uintptr_t m_lastCanidate = 0;
2028
};
2129
}

0 commit comments

Comments
 (0)