aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-12-21 17:07:17 +0000
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-12-21 17:07:17 +0000
commit246d058c2c9e1dddff3072f0293de5b5e361b8c7 (patch)
treea2f71b4091999542d53028305284fe0654fd60ef
parent34aaaf1ce6819e9a5fdd2c0cd04259d89e085052 (diff)
downloadNorthstarLauncher-246d058c2c9e1dddff3072f0293de5b5e361b8c7.tar.gz
NorthstarLauncher-246d058c2c9e1dddff3072f0293de5b5e361b8c7.zip
dedi cleanup and d3d hooks
-rw-r--r--NorthstarDedicatedTest/dedicated.cpp129
-rw-r--r--NorthstarDedicatedTest/dedicated.h1
-rw-r--r--NorthstarDedicatedTest/dedicatedmaterialsystem.cpp111
3 files changed, 32 insertions, 209 deletions
diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp
index 524deb9f..83a9950a 100644
--- a/NorthstarDedicatedTest/dedicated.cpp
+++ b/NorthstarDedicatedTest/dedicated.cpp
@@ -9,11 +9,6 @@ bool IsDedicated()
return CommandLine()->CheckParm("-dedicated");
}
-bool DisableDedicatedWindowCreation()
-{
- return !CommandLine()->CheckParm("-windoweddedi");
-}
-
// CDedidcatedExports defs
struct CDedicatedExports; // forward declare
@@ -343,118 +338,19 @@ void InitialiseDedicated(HMODULE engineAddress)
*(ptr + 15) = (char)0x90;
}
- // stuff that disables renderer/window creation: unstable atm
- if (DisableDedicatedWindowCreation())
+ // note: previously had DisableDedicatedWindowCreation patches here, but removing those rn since they're all shit and unstable and bad and such
+ // check commit history if any are needed for reimplementation
{
- {
- // CEngineAPI::Init
- char* ptr = (char*)engineAddress + 0x1C60CE;
- TempReadWrite rw(ptr);
-
- // remove call to something or other that reads video settings
- *ptr = (char)0x90;
- *(ptr + 1) = (char)0x90;
- *(ptr + 2) = (char)0x90;
- *(ptr + 3) = (char)0x90;
- *(ptr + 4) = (char)0x90;
- }
-
- {
- // some inputsystem bullshit
- char* ptr = (char*)engineAddress + 0x1CEE28;
- TempReadWrite rw(ptr);
-
- // nop an accessviolation: temp because we still create game window atm
- *ptr = (char)0x90;
- *(ptr + 1) = (char)0x90;
- *(ptr + 2) = (char)0x90;
- }
-
- {
- // no clue what this is
- char* ptr = (char*)engineAddress + 0x1CD146;
- TempReadWrite rw(ptr);
-
- // nop a crashing call
- *ptr = (char)0x90;
- *(ptr + 1) = (char)0x90;
- *(ptr + 2) = (char)0x90;
- *(ptr + 3) = (char)0x90;
- *(ptr + 4) = (char)0x90;
- }
-
- //{
- // // CEngineAPI::ModInit
- // char* ptr = (char*)engineAddress + 0x1C67D1;
- // TempReadWrite rw(ptr);
- //
- // // prevent game window from being created
- // *ptr = (char)0x90;
- // *(ptr + 1) = (char)0x90;
- // *(ptr + 2) = (char)0x90;
- // *(ptr + 3) = (char)0x90;
- // *(ptr + 4) = (char)0x90;
- //
- // *(ptr + 7) = (char)0xEB; // jnz => jmp
- //}
-
- // note: this is a different way of nopping window creation, i'm assuming there are like a shitload of inits here we shouldn't skip
- // i know at the very least it registers datatables which are important
- {
- // IVideoMode::CreateGameWindow
- char* ptr = (char*)engineAddress + 0x1CD0ED;
- TempReadWrite rw(ptr);
-
- // prevent game window from being created
- *ptr = (char)0x90;
- *(ptr + 1) = (char)0x90;
- *(ptr + 2) = (char)0x90;
- *(ptr + 3) = (char)0x90;
- *(ptr + 4) = (char)0x90;
- }
-
- {
- // IVideoMode::CreateGameWindow
- char* ptr = (char*)engineAddress + 0x1CD146;
- TempReadWrite rw(ptr);
-
- // prevent game from calling a matsystem function that will crash here
- //*ptr = (char)0x90;
- //*(ptr + 1) = (char)0x90;
- //*(ptr + 2) = (char)0x90;
- //*(ptr + 3) = (char)0x90;
- //*(ptr + 4) = (char)0x90;
- }
-
- {
- // IVideoMode::CreateGameWindow
- char* ptr = (char*)engineAddress + 0x1CD160;
- TempReadWrite rw(ptr);
-
- // prevent game from complaining about window not being created
- *ptr = (char)0x90;
- *(ptr + 1) = (char)0x90;
- }
-
- CommandLine()->AppendParm("-noshaderapi", 0);
- }
- else
- {
- // for dedis where we still create a window, we can at least hide the window we create
- // not great since we still run renderthread etc, but better than nothing
-
- {
- // IVideoMode::CreateGameWindow
- char* ptr = (char*)engineAddress + 0x1CD146;
- TempReadWrite rw(ptr);
-
- // nop call to ShowWindow
- *ptr = (char)0x90;
- *(ptr + 1) = (char)0x90;
- *(ptr + 2) = (char)0x90;
- *(ptr + 3) = (char)0x90;
- *(ptr + 4) = (char)0x90;
- }
+ // IVideoMode::CreateGameWindow
+ char* ptr = (char*)engineAddress + 0x1CD146;
+ TempReadWrite rw(ptr);
+
+ // nop call to ShowWindow
+ *ptr = (char)0x90;
+ *(ptr + 1) = (char)0x90;
+ *(ptr + 2) = (char)0x90;
+ *(ptr + 3) = (char)0x90;
+ *(ptr + 4) = (char)0x90;
}
CDedicatedExports* dedicatedExports = new CDedicatedExports;
@@ -480,6 +376,7 @@ void InitialiseDedicated(HMODULE engineAddress)
// add cmdline args that are good for dedi
CommandLine()->AppendParm("-nomenuvid", 0);
CommandLine()->AppendParm("-nosound", 0);
+ CommandLine()->AppendParm("-windowed", 0);
CommandLine()->AppendParm("+host_preload_shaders", "0");
CommandLine()->AppendParm("+net_usesocketsforloopback", "1");
CommandLine()->AppendParm("+exec", "autoexec_ns_server");
diff --git a/NorthstarDedicatedTest/dedicated.h b/NorthstarDedicatedTest/dedicated.h
index 3b958203..0b4d9188 100644
--- a/NorthstarDedicatedTest/dedicated.h
+++ b/NorthstarDedicatedTest/dedicated.h
@@ -1,7 +1,6 @@
#pragma once
bool IsDedicated();
-bool DisableDedicatedWindowCreation();
void InitialiseDedicated(HMODULE moduleAddress);
void InitialiseDedicatedOrigin(HMODULE baseAddress);
diff --git a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp
index 804e35cf..a05eb8de 100644
--- a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp
+++ b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp
@@ -3,17 +3,31 @@
#include "dedicated.h"
#include "dedicatedmaterialsystem.h"
#include "hookutils.h"
+#include "gameutils.h"
+
+typedef HRESULT(*__stdcall D3D11CreateDeviceType)(void* pAdapter, int DriverType, HMODULE Software, UINT Flags, int* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, void** ppDevice, int* pFeatureLevel, void** ppImmediateContext);
+D3D11CreateDeviceType D3D11CreateDevice;
+
+HRESULT __stdcall D3D11CreateDeviceHook(void* pAdapter, int DriverType, HMODULE Software, UINT Flags, int* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, void** ppDevice, int* pFeatureLevel, void** ppImmediateContext)
+{
+ // note: this is super duper temp pretty much just messing around with it
+ // does run surprisingly well on dedi for a software driver tho if you ignore the +1gb ram usage at times, seems like dedi doesn't really call gpu much even with renderthread still being a thing
+ // will be using this hook for actual d3d stubbing and stuff later
+ if (CommandLine()->CheckParm("-softwared3d11"))
+ DriverType = 5; // D3D_DRIVER_TYPE_WARP
+
+ return D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext);
+}
void InitialiseDedicatedMaterialSystem(HMODULE baseAddress)
{
if (!IsDedicated())
return;
- //while (!IsDebuggerPresent())
- // Sleep(100);
+ HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xD9A0E, &D3D11CreateDeviceHook, reinterpret_cast<LPVOID*>(&D3D11CreateDevice));
// not using these for now since they're related to nopping renderthread/gamewindow i.e. very hard
- // we use -noshaderapi instead now
//{
// // function that launches renderthread
// char* ptr = (char*)baseAddress + 0x87047;
@@ -49,90 +63,8 @@ void InitialiseDedicatedMaterialSystem(HMODULE baseAddress)
*(ptr + 3) = (char)0x00;
}
- if (DisableDedicatedWindowCreation())
- {
- {
- // materialsystem rpak type registrations
- char* ptr = (char*)baseAddress + 0x22B5;
- TempReadWrite rw(ptr);
-
- // nop a call that crashes, not needed on dedi
- *ptr = 0x90;
- *(ptr + 1) = (char)0x90;
- *(ptr + 2) = (char)0x90;
- *(ptr + 3) = (char)0x90;
- *(ptr + 4) = (char)0x90;
- }
-
- {
- // some renderthread stuff
- char* ptr = (char*)baseAddress + 0x8C10;
- TempReadWrite rw(ptr);
-
- // call => nop
- *ptr = (char)0x90;
- *(ptr + 1) = (char)0x90;
- }
-
- // rpak type callbacks
- // these need to be nopped for dedi
- {
- // materialsystem rpak type: shader
- char* ptr = (char*)baseAddress + 0x2850;
- TempReadWrite rw(ptr);
-
- // ret
- *ptr = (char)0xC3;
- }
-
- {
- // materialsystem rpak type: texture
- char* ptr = (char*)baseAddress + 0x2B00;
- TempReadWrite rw(ptr);
-
- // ret
- *ptr = (char)0xC3;
- }
-
- {
- // materialsystem rpak type: material
- char* ptr = (char*)baseAddress + 0x50AA0;
- TempReadWrite rw(ptr);
-
- // ret
- *ptr = (char)0xC3;
- }
- }
-}
-
-// rpak pain
-struct RpakTypeDefinition
-{
- int64_t magic;
- char* longName;
-
- // more fields but they don't really matter for what we use them for
-};
-
-typedef void*(*RegisterRpakTypeType)(RpakTypeDefinition* rpakStruct, unsigned int a1, unsigned int a2);
-RegisterRpakTypeType RegisterRpakType;
-
-typedef void(*RegisterMaterialSystemRpakTypes)();
-
-void* RegisterRpakTypeHook(RpakTypeDefinition* rpakStruct, unsigned int a1, unsigned int a2)
-{
- // make sure this prints right
- char magicName[5];
- memcpy(magicName, &rpakStruct->magic, 4);
- magicName[4] = 0; // null terminator
-
- spdlog::info("rpak type {} {} registered", magicName, rpakStruct->longName);
-
- // reregister rpak types that aren't registered on a windowless dedi
- if (rpakStruct->magic == 0x64636C72) // rlcd magic, this one is registered last
- ((RegisterMaterialSystemRpakTypes)((char*)GetModuleHandleA("materialsystem_dx11.dll") + 0x22A0))(); // slightly hellish call, registers materialsystem rpak types
-
- return RegisterRpakType(rpakStruct, a1, a2);
+ // previously had DisableDedicatedWindowCreation stuff here, removing for now since shit and unstable
+ // check commit history if needed
}
typedef void*(*PakLoadAPI__LoadRpakType)(char* filename, void* unknown, int flags);
@@ -174,9 +106,4 @@ void InitialiseDedicatedRtechGame(HMODULE baseAddress)
// unfortunately this is unstable, seems to freeze when changing maps
//ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xB0F0, &PakLoadAPI__LoadRpakHook, reinterpret_cast<LPVOID*>(&PakLoadAPI__LoadRpak));
//ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xB170, &PakLoadAPI__LoadRpak2Hook, reinterpret_cast<LPVOID*>(&PakLoadAPI__LoadRpak2));
-
- if (DisableDedicatedWindowCreation())
- {
- ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x7BE0, &RegisterRpakTypeHook, reinterpret_cast<LPVOID*>(&RegisterRpakType));
- }
} \ No newline at end of file