aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/dedicated.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-08 15:33:31 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-08 15:33:31 +0100
commit4c4d605d10109e02708984755405bbe0947ef5c4 (patch)
tree1d5ffe7909b24b6c79fd444b420741e85f6c2b57 /NorthstarDedicatedTest/dedicated.cpp
parent8dfb8e866119f653802609b24165b0458149c4cc (diff)
downloadNorthstarLauncher-4c4d605d10109e02708984755405bbe0947ef5c4.tar.gz
NorthstarLauncher-4c4d605d10109e02708984755405bbe0947ef5c4.zip
initial commit
Diffstat (limited to 'NorthstarDedicatedTest/dedicated.cpp')
-rw-r--r--NorthstarDedicatedTest/dedicated.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp
new file mode 100644
index 00000000..ce4723cb
--- /dev/null
+++ b/NorthstarDedicatedTest/dedicated.cpp
@@ -0,0 +1,101 @@
+#include "pch.h"
+#include "dedicated.h"
+#include "hookutils.h"
+
+#include <iostream>
+
+bool IsDedicated()
+{
+ // temp: should get this from commandline
+ return false;
+}
+
+void InitialiseDedicated(HMODULE engineAddress)
+{
+ std::cout << "InitialiseDedicated()" << std::endl;
+
+ while (!IsDebuggerPresent())
+ Sleep(100);
+
+ // create binary patches
+ {
+ // CEngineAPI::SetStartupInfo
+ // prevents englishclient_frontend from loading
+
+ char* ptr = (char*)engineAddress + 0x1C7CBE;
+ TempReadWrite rw(ptr);
+
+ // je => jmp
+ *ptr = (char)0xEB;
+ }
+
+ {
+ // CModAppSystemGroup::Create
+ // force the engine into dedicated mode by changing the first comparison to IsServerOnly to an assignment
+ char* ptr = (char*)engineAddress + 0x1C4EBD;
+ TempReadWrite rw(ptr);
+
+ // cmp => mov
+ *(ptr + 1) = (char)0xC6;
+ *(ptr + 2) = (char)0x87;
+
+ // 00 => 01
+ *((char*)ptr + 7) = (char)0x01;
+ }
+
+ {
+ // Some init that i'm not sure of that crashes
+ char* ptr = (char*)engineAddress + 0x156A63;
+ TempReadWrite rw(ptr);
+
+ // nop the call to it
+ *ptr = (char)0x90;
+ *(ptr + 1) = (char)0x90;
+ *(ptr + 2) = (char)0x90;
+ *(ptr + 3) = (char)0x90;
+ *(ptr + 4) = (char)0x90;
+ }
+
+ CDedicatedExports* dedicatedApi = new CDedicatedExports;
+ dedicatedApi->Sys_Printf = Sys_Printf;
+ dedicatedApi->RunServer = RunServer;
+
+ // double ptr to dedicatedApi
+ intptr_t* ptr = (intptr_t*)((char*)engineAddress + 0x13F0B668);
+
+ // ptr to dedicatedApi
+ intptr_t* doublePtr = new intptr_t;
+ *doublePtr = (intptr_t)dedicatedApi;
+
+ // ptr to ptr
+ *ptr = (intptr_t)doublePtr;
+}
+
+void Sys_Printf(CDedicatedExports* dedicated, char* msg)
+{
+ std::cout << msg << std::endl;
+}
+
+void RunServer(CDedicatedExports* dedicated)
+{
+ Sys_Printf(dedicated, (char*)"CDedicatedServerAPI::RunServer(): starting");
+
+ HMODULE engine = GetModuleHandleA("engine.dll");
+ CEngine__Frame engineFrame = (CEngine__Frame)((char*)engine + 0x1C8650);
+ CEngineAPI__ActivateSimulation engineApiStartSimulation = (CEngineAPI__ActivateSimulation)((char*)engine + 0x1C4370);
+
+ void* cEnginePtr = (void*)((char*)engine + 0x7D70C8);
+
+ CEngineAPI__SetMap engineApiSetMap = (CEngineAPI__SetMap)((char*)engine + 0x1C7B30);
+
+ engineApiSetMap(nullptr, "mp_lobby; net_usesocketsforloopback 1");
+ Sys_Printf(dedicated, (char*)"CDedicatedServerAPI::RunServer(): map mp_lobby");
+
+ while (true)
+ {
+ engineFrame(cEnginePtr);
+ //engineApiStartSimulation(nullptr, true);
+ Sys_Printf(dedicated, (char*)"engine->Frame()");
+ Sleep(50);
+ }
+} \ No newline at end of file