-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmruby_console.cpp
executable file
·126 lines (104 loc) · 3.7 KB
/
mruby_console.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
// console helper
BOOL console_spawned = false;
//void SetStdOutToNewConsole()
//{
// if (console_spawned == false) {
//
// int hConHandle;
// long lStdHandle;
// FILE *fp;
//
// HWND window_test = GetConsoleWindow();
// fprintf(stdout, "set_game_window window_test %i\n", window_test);
//
// // don't spawn if the console already exists, pipe reopening will cause a crash
// if (window_test != 0) return;
//
// // Allocate a console for this app
// AllocConsole();
// AttachConsole(GetCurrentProcessId());
//
// freopen("CON", "w", stdout);
// freopen("CONIN$", "r", stdin);
//
// // Redirect unbuffered STDOUT to the console
// lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
// hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
// fp = _fdopen(hConHandle, "w");
// *stdout = *fp;
//
// setvbuf(stdout, NULL, _IONBF, 0);
// setbuf(stdout, NULL);
//
// console_spawned = true;
//
// HWND window_game = FindWindow(NULL, "Grand Theft Auto V");
// SetWindowPos(window_game, NULL, 0, 0, 1920 + 4, 1080 + 25, 0);
//
// HWND window_console = GetConsoleWindow();
// SetWindowPos(window_console, NULL, 1920 - 5, 0, 650, 1080 + 25, 0);
//
// fprintf(stdout, "set_game_window window_test %i\n", window_test);
//
// }
//}
mrb_value mruby__gtav__spawn_console(mrb_state *mrb, mrb_value self) {
mrb_int a0, a1, a2, a3, a4, a5, a6, a7, a8, a9;
mrb_get_args(mrb, "iiiiiiiiii", &a0, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9);
//SetStdOutToNewConsole(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
HWND window_test = GetConsoleWindow();
fprintf(stdout, "set_game_window window_test %i\n", window_test);
int hConHandle;
long lStdHandle;
FILE *fp;
// don't spawn if the console already exists, pipe reopening will cause a crash
if (window_test != 0) {
//freopen("CON", "w", stdout);
//freopen("CONIN$", "r", stdin);
//lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
//hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
//fp = _fdopen(hConHandle, "w");
//*stdout = *fp;
//setvbuf(stdout, NULL, _IONBF, 0);
//setbuf(stdout, NULL);
// FIXME: console output is dropped after reloading .asi
return mrb_nil_value();
}
if (console_spawned == false) {
// Allocate a console for this app
AllocConsole();
AttachConsole(GetCurrentProcessId());
freopen("CON", "w", stdout);
freopen("CONIN$", "r", stdin);
// Redirect unbuffered STDOUT to the console
lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
setbuf(stdout, NULL);
console_spawned = true;
HWND window_game = FindWindow(NULL, "Grand Theft Auto V");
SetWindowPos(window_game, NULL, a0, a1, a2, a3, 0);
HWND window_console = GetConsoleWindow();
SetWindowPos(window_console, NULL, a5, a6, a7, a8, 0);
}
fprintf(stdout, "set_game_window window_test %i\n", window_test);
return mrb_nil_value();
}
mrb_value mruby__gtav__set_game_window(mrb_state *mrb, mrb_value self) {
mrb_int a0, a1, a2, a3, a4;
mrb_get_args(mrb, "iiiii", &a0, &a1, &a2, &a3, &a4);
fprintf(stdout, "set_game_window %i %i %i %i %i\n", a0, a1, a2, a3, a4);
HWND window = FindWindow(NULL, "Grand Theft Auto V");
fprintf(stdout, "set_game_window window %i\n", window);
SetWindowPos(window, NULL, a0, a1, a2, a3, a4);
return mrb_nil_value();
}
mrb_value mruby__gtav__set_console_window(mrb_state *mrb, mrb_value self) {
mrb_int a0, a1, a2, a3, a4;
mrb_get_args(mrb, "iiiii", &a0, &a1, &a2, &a3, &a4);
HWND window = GetConsoleWindow();
SetWindowPos(window, NULL, a0, a1, a2, a3, a4);
return mrb_nil_value();
}