add temp console support

This commit is contained in:
BobTheBob 2021-07-11 20:17:11 +01:00
parent 4c4d605d10
commit 51d3d4a40c
8 changed files with 53 additions and 25 deletions

View File

@ -170,6 +170,7 @@
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="concommand.h" />
<ClInclude Include="context.h" />
<ClInclude Include="dedicated.h" />
<ClInclude Include="hooks.h" />
@ -199,7 +200,6 @@
</ClCompile>
<ClCompile Include="sigscanning.cpp" />
<ClCompile Include="sourceconsole.cpp" />
<ClCompile Include="sourceinterface.cpp" />
<ClCompile Include="squirrel.cpp" />
<ClCompile Include="tier0.cpp" />
</ItemGroup>

View File

@ -40,6 +40,9 @@
<Filter Include="Header Files\Client">
<UniqueIdentifier>{ca657be5-c2d8-4322-a689-1154aaafe57b}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Shared\ConVar">
<UniqueIdentifier>{9751b551-5886-45d4-a039-cbd10445263d}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
@ -81,6 +84,9 @@
<ClInclude Include="sourceinterface.h">
<Filter>Header Files\Shared</Filter>
</ClInclude>
<ClInclude Include="concommand.h">
<Filter>Header Files\Shared\ConVar</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
@ -116,8 +122,5 @@
<ClCompile Include="context.cpp">
<Filter>Source Files\Shared</Filter>
</ClCompile>
<ClCompile Include="sourceinterface.cpp">
<Filter>Source Files\Shared</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

View File

@ -7,6 +7,7 @@
bool IsDedicated()
{
// temp: should get this from commandline
//return true;
return false;
}
@ -69,6 +70,12 @@ void InitialiseDedicated(HMODULE engineAddress)
// ptr to ptr
*ptr = (intptr_t)doublePtr;
// extra potential patches:
// nop engine.dll+1c67cd1 and +1c67d8 to skip videomode creategamewindow
// also look into launcher.dll+d381, seems to cause renderthread to get made
// this crashes HARD if no window which makes sense tbh
// also look into materialsystem + 5B344 since it seems to be the base of all the renderthread stuff
}
void Sys_Printf(CDedicatedExports* dedicated, char* msg)

View File

@ -1,14 +1,37 @@
#include "pch.h"
#include "sourceconsole.h"
#include "sourceinterface.h"
#include "hookutils.h"
#include <iostream>
SourceInterface<CGameConsole>* g_SourceGameConsole;
SourceInterface<CGameConsole>* g_pSourceGameConsole;
typedef void(*weaponlisttype)();
weaponlisttype weaponlist;
void CommandWeaponListHook()
{
std::cout << "TEMP: toggling console... REPLACE THIS WITH ACTUAL CONCOMMAND SUPPORT SOON" << std::endl;
(*g_pSourceGameConsole)->Activate();
}
CreateInterfaceFn createInterface;
void* __fastcall InitialiseConsoleOnUIInit(const char* pName, int* pReturnCode)
{
std::cout << pName << std::endl;
void* ret = createInterface(pName, pReturnCode);
if (!strcmp(pName, "GameClientExports001"))
(*g_pSourceGameConsole)->Initialize();
return ret;
}
void InitialiseSourceConsole(HMODULE baseAddress)
{
SourceInterface<CGameConsole> console = SourceInterface<CGameConsole>("client.dll", "CGameConsole");
console->Initialize();
console->Activate();
g_pSourceGameConsole = new SourceInterface<CGameConsole>("client.dll", "GameConsole004");
g_SourceGameConsole = &console;
HookEnabler hook;
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x73BA00, &InitialiseConsoleOnUIInit, reinterpret_cast<LPVOID*>(&createInterface));
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x10C080, &CommandWeaponListHook, reinterpret_cast<LPVOID*>(&weaponlist));
}

View File

@ -87,4 +87,4 @@ public:
CConsoleDialog* m_pConsole;
};
extern SourceInterface<CGameConsole>* g_SourceGameConsole;
extern SourceInterface<CGameConsole>* g_pSourceGameConsole;

View File

@ -1,13 +0,0 @@
#include "pch.h"
#include "sourceinterface.h"
#include <string>
#include "tier0.h"
template<typename T> SourceInterface<T>::SourceInterface(const std::string& moduleName, const std::string& interfaceName)
{
HMODULE handle = GetModuleHandleA(moduleName.c_str());
CreateInterfaceFn createInterface = (CreateInterfaceFn)GetProcAddress(handle, interfaceName.c_str());
m_interface = (T*)createInterface(interfaceName.c_str(), NULL);
if (m_interface == nullptr)
Error("Failed to call CreateInterface for %s in %s", interfaceName, moduleName);
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <string>
#include "tier0.h"
// literally just copied from ttf2sdk definition
typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode);
@ -10,7 +11,14 @@ private:
T* m_interface;
public:
SourceInterface(const std::string& moduleName, const std::string& interfaceName);
SourceInterface(const std::string& moduleName, const std::string& interfaceName)
{
HMODULE handle = GetModuleHandleA(moduleName.c_str());
CreateInterfaceFn createInterface = (CreateInterfaceFn)GetProcAddress(handle, "CreateInterface");
m_interface = (T*)createInterface(interfaceName.c_str(), NULL);
if (m_interface == nullptr)
Error("Failed to call CreateInterface for %s in %s", interfaceName, moduleName);
}
T* operator->() const
{
@ -21,4 +29,4 @@ public:
{
return m_interface;
}
};
};