aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/dedicated.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDedicatedTest/dedicated.cpp')
-rw-r--r--NorthstarDedicatedTest/dedicated.cpp75
1 files changed, 60 insertions, 15 deletions
diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp
index 83a9950a..1359a33e 100644
--- a/NorthstarDedicatedTest/dedicated.cpp
+++ b/NorthstarDedicatedTest/dedicated.cpp
@@ -6,13 +6,14 @@
bool IsDedicated()
{
- return CommandLine()->CheckParm("-dedicated");
+ //return CommandLine()->CheckParm("-dedicated");
+ return strstr(GetCommandLineA(), "-dedicated");
}
// CDedidcatedExports defs
struct CDedicatedExports; // forward declare
-typedef void (*DedicatedSys_PrintfType)(CDedicatedExports* dedicated, char* msg);
+typedef void (*DedicatedSys_PrintfType)(CDedicatedExports* dedicated, const char* msg);
typedef void (*DedicatedRunServerType)(CDedicatedExports* dedicated);
// would've liked to just do this as a class but have not been able to get it to work
@@ -26,7 +27,7 @@ struct CDedicatedExports
DedicatedRunServerType RunServer;
};
-void Sys_Printf(CDedicatedExports* dedicated, char* msg)
+void Sys_Printf(CDedicatedExports* dedicated, const char* msg)
{
spdlog::info("[DEDICATED PRINT] {}", msg);
}
@@ -35,7 +36,7 @@ typedef void(*CHostState__InitType)(CHostState* self);
void RunServer(CDedicatedExports* dedicated)
{
- Sys_Printf(dedicated, (char*)"CDedicatedExports::RunServer(): starting");
+ Sys_Printf(dedicated, "CDedicatedExports::RunServer(): starting");
// init hoststate, if we don't do this, we get a crash later on
CHostState__InitType CHostState__Init = (CHostState__InitType)((char*)GetModuleHandleA("engine.dll") + 0x16E110);
@@ -76,6 +77,32 @@ bool IsGameActiveWindowHook()
return true;
}
+HANDLE consoleInputThreadHandle = NULL;
+
+DWORD WINAPI ConsoleInputThread(PVOID pThreadParameter)
+{
+ while (!g_pEngine || !g_pHostState || g_pHostState->m_iCurrentState != HostState_t::HS_RUN)
+ Sleep(1000);
+
+ // Bind stdin to receive console input.
+ FILE* fp = nullptr;
+ freopen_s(&fp, "CONIN$", "r", stdin);
+
+ spdlog::info("Ready to receive console commands.");
+
+ {
+ // Process console input
+ std::string input;
+ while (g_pEngine && g_pEngine->m_nQuitting == EngineQuitState::QUIT_NOTQUITTING && std::getline(std::cin, input))
+ {
+ input += "\n";
+ Cbuf_AddText(Cbuf_GetCurrentPlayer(), input.c_str(), cmd_source_t::kCommandSrcCode);
+ }
+ }
+
+ return 0;
+}
+
void InitialiseDedicated(HMODULE engineAddress)
{
if (!IsDedicated())
@@ -209,7 +236,7 @@ void InitialiseDedicated(HMODULE engineAddress)
TempReadWrite rw(ptr);
// remove call to Shader_Connect
- *ptr = 0x90;
+ *ptr = (char)0x90;
*(ptr + 1) = (char)0x90;
*(ptr + 2) = (char)0x90;
*(ptr + 3) = (char)0x90;
@@ -246,7 +273,7 @@ void InitialiseDedicated(HMODULE engineAddress)
TempReadWrite rw(ptr);
// remove call to ui loading stuff
- *ptr = 0x90;
+ *ptr = (char)0x90;
*(ptr + 1) = (char)0x90;
*(ptr + 2) = (char)0x90;
*(ptr + 3) = (char)0x90;
@@ -380,25 +407,43 @@ void InitialiseDedicated(HMODULE engineAddress)
CommandLine()->AppendParm("+host_preload_shaders", "0");
CommandLine()->AppendParm("+net_usesocketsforloopback", "1");
CommandLine()->AppendParm("+exec", "autoexec_ns_server");
+
+ // Disable Quick Edit mode to reduce chance of user unintentionally hanging their server by selecting something.
+ if (!CommandLine()->CheckParm("-bringbackquickedit"))
+ {
+ HANDLE stdIn = GetStdHandle(STD_INPUT_HANDLE);
+ DWORD mode = 0;
+
+ if (GetConsoleMode(stdIn, &mode)) {
+ if (mode & ENABLE_QUICK_EDIT_MODE) {
+ mode &= ~ENABLE_QUICK_EDIT_MODE;
+ mode &= ~ENABLE_MOUSE_INPUT;
+
+ mode |= ENABLE_PROCESSED_INPUT;
+
+ SetConsoleMode(stdIn, mode);
+ }
+ }
+ } else spdlog::info("Quick Edit enabled by user request");
+
+ // create console input thread
+ if (!CommandLine()->CheckParm("-noconsoleinput"))
+ consoleInputThreadHandle = CreateThread(0, 0, ConsoleInputThread, 0, 0, NULL);
+ else spdlog::info("Console input disabled by user request");
}
-typedef void(*Tier0_InitOriginType)();
-Tier0_InitOriginType Tier0_InitOrigin;
-void Tier0_InitOriginHook()
+void InitialiseDedicatedOrigin(HMODULE baseAddress)
{
// disable origin on dedicated
// for any big ea lawyers, this can't be used to play the game without origin, game will throw a fit if you try to do anything without an origin id as a client
// for dedi it's fine though, game doesn't care if origin is disabled as long as there's only a server
- Tier0_InitOrigin();
-}
-void InitialiseDedicatedOrigin(HMODULE baseAddress)
-{
if (!IsDedicated())
return;
- HookEnabler hook;
- ENABLER_CREATEHOOK(hook, GetProcAddress(GetModuleHandleA("tier0.dll"), "Tier0_InitOrigin"), &Tier0_InitOriginHook, reinterpret_cast<LPVOID*>(&Tier0_InitOrigin));
+ char* ptr = (char*)GetProcAddress(GetModuleHandleA("tier0.dll"), "Tier0_InitOrigin");
+ TempReadWrite rw(ptr);
+ *ptr = (char)0xC3; // ret
}
typedef void(*PrintFatalSquirrelErrorType)(void* sqvm);