-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcl_main.cpp
138 lines (119 loc) · 3.38 KB
/
cl_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "stdheader.h"
#include "gl33.h"
#include "imgui.h"
#include "cg_public.h"
#include "chakracore.h"
//#include "cg_local.h"
dvar_t *con_restricted = (dvar_t*)0x5E132C;
dvar_t *cl_imguiEnabled;
dvar_t *discord;
int *cls_keyCatchers = (int*)0x96B654;
#define KEYCATCH_CONSOLE (1)
bool imgui_enabled(dvar_t*);
void Cbuf_AddText_(const char *s)
{
__asm
{
mov eax, s
lea edx, Cbuf_AddText
call edx
}
}
void handleImGuiWindows()
{
static char serverCommand[4096] = { 0 };
if (ImGui::Begin("haha"))
{
ImGui::InputText("server cmd", serverCommand, sizeof(serverCommand));
if (ImGui::Button("send"))
{
Cbuf_AddText(serverCommand);
}
ImGui::End();
}
}
void SetWndCapture(bool);
int *renderThreadId = (int*)0xD528D8;
void *devFont = (void*)0x14EB4FC;
float *font_xscale = (float*)0xC94C08;
float *font_yscale = (float*)0xC94C0C;
void *consoleFont = (void*)0x966C04;
//our own kind of cl_frame to handle things each frame / tick
void CL_Frame()
{
void(*o)() = (void(*)())0x040F850;
o();
imgui_enabled(cl_imguiEnabled);
extern bool preventMouseGrab;
bool prev = preventMouseGrab;
preventMouseGrab = (*cls_keyCatchers & KEYCATCH_CONSOLE) == KEYCATCH_CONSOLE;
if (prev)
{
if (!preventMouseGrab)
{
//closing console
SetWndCapture(false);
}
}
else
{
if(preventMouseGrab)
SetWndCapture(true);
}
//if (!CL_DrawText)
//{
// CL_DrawText = (void(*)(float* scrPlace, const char* text, int maxChars, float* font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, float color, int style)) (*(void**)0x68A31C);
//}
//float clr[] = { 255,255,255,255 };
//CL_DrawText("CoD2 1.4 Developer Edition", 1000, (int)consoleFont, 100, 100, *font_xscale, *font_yscale, clr, 0);
//CL_DrawText("AAAAAAAAAAAAAAAA", 0x7FFFFFFF, consoleFont, 1.f, 1.f, 1065353216, 1065353216, (float*)0x59BCA8, 0);
//Com_Printf("frame!\n");
}
// eating a lot of memory probably but cba to think on a better check
bool imgui_enabled(dvar_t *cl_imguiEnabled) {
return cl_imguiEnabled->current.enabled ? true : false;
}
int Com_PrintString(const char *str) {
Com_Printf("%s", str);
return 0;
}
void CL_UpdateInfoPacket(netadr_t adr)
{
//this works, but UDP unreliable bs and it's loading the game and it wont do the udp packets, so scrap this, and using http file now yay, TODO
#if 0
for (int i = 0; i < CG_Argc(); ++i)
{
Com_Printf("^6%d: %s", i, CG_Argv(i));
//MessageBoxA(NULL, CG_Argv(i), "", 0);
}
#endif
}
void CL_Init( void )
{
void(*o)(void) = (void(*)(void))0x411650;
o();
Dvar_SetFromStringByName("moto", "yes");
cl_imguiEnabled = Dvar_RegisterBool("cl_imguiEnabled", false, CVAR_ARCHIVE); // by default it's false because not everyone wants to use an imgui, Flag set to Archive because why not
discord = Dvar_RegisterBool("discord", false, CVAR_LATCH | CVAR_ARCHIVE);
Com_Printf(MOD_NAME " loaded!\n");
if (discord->current.enabled) {
int CL_StartDiscord();
if (CL_StartDiscord() == -1) {
MessageBoxA(NULL, "Could not start discord integration", "Discord integration error", NULL);
}
}
CG_InitConsoleCommands();
chakracore_prepare(Com_PrintString);
chakracore_eval("console.log(\"^3Loaded ChakraCore\");");
const char *eval_repl =
"eval_repl = function(code) {"\
" try { "\
" var ret = eval(code);"\
" console.log(ret) "\
" } "\
" catch (e) { "\
" console.log(e); "\
" } "\
"}; ";
chakracore_eval(eval_repl);
}