Skip to content

Commit

Permalink
new console host using imgui
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=b60c6fe9824d0aab4fa9ef39c841e008ab052727
  • Loading branch information
cuprum authored and blattersturm committed Apr 17, 2017
1 parent ab84947 commit 796663f
Show file tree
Hide file tree
Showing 14 changed files with 916 additions and 2 deletions.
3 changes: 2 additions & 1 deletion DEPS
Expand Up @@ -24,7 +24,8 @@ deps = {
"vendor/libuv": "https://github.com/libuv/libuv.git@7639dd510ec13dd577677dce2a673f5046432903",
"vendor/fmtlib": "https://github.com/fmtlib/fmt.git",
"vendor/nghttp2": "https://github.com/nghttp2/nghttp2@v1.20.0",
"vendor/cpr": "https://github.com/whoshuu/cpr.git@master"
"vendor/cpr": "https://github.com/whoshuu/cpr.git@master",
"vendor/imgui": "https://github.com/ocornut/imgui.git@v1.49"
}

hooks = [
Expand Down
2 changes: 1 addition & 1 deletion components/config.lua
Expand Up @@ -21,7 +21,7 @@ component 'gta-core-ny'
--component 'scrt-mono'
--component 'voip-mumble'
component 'font-renderer'
component 'conhost-posh'
component 'conhost-v2'
component 'rage-allocator-payne'
component 'rage-device-payne'
component 'rage-graphics-payne'
Expand Down
11 changes: 11 additions & 0 deletions components/conhost-v2/component.json
@@ -0,0 +1,11 @@
{
"name": "conhost:v2",
"version": "0.1.0",
"dependencies": [
"fx[2]",
"rage:input",
"rage:graphics",
"vendor:imgui"
],
"provides": []
}
Empty file.
1 change: 1 addition & 0 deletions components/conhost-v2/component.rc
@@ -0,0 +1 @@
fxComponent 115 component.json
21 changes: 21 additions & 0 deletions components/conhost-v2/include/ConsoleHost.h
@@ -0,0 +1,21 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#pragma once

#ifdef COMPILING_CONHOST_POSH
#define CONHOST_EXPORT DLL_EXPORT
#else
#define CONHOST_EXPORT DLL_IMPORT
#endif

namespace ConHost
{
extern CONHOST_EXPORT fwEvent<const char*, const char*> OnInvokeNative;

CONHOST_EXPORT void Print(int channel, const std::string& message);
}
34 changes: 34 additions & 0 deletions components/conhost-v2/include/ConsoleHostImpl.h
@@ -0,0 +1,34 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#pragma once

enum ConsoleModifiers
{
ConsoleModifierNone = 0,
ConsoleModifierAlt = 1,
ConsoleModifierShift = 2,
ConsoleModifierControl = 4
};

// THANKS MICROSOFT
DEFINE_ENUM_FLAG_OPERATORS(ConsoleModifiers);

void ConHost_Run();

void ConHost_KeyEnter(uint32_t vKey, wchar_t character, ConsoleModifiers modifiers);

// private
void ConHost_AddInternalCalls();

void ConHost_WaitForKey(uint32_t& vKey, wchar_t& character, ConsoleModifiers& modifiers);

void ConHost_GetCursorPos(int& x, int& y);

void ConHost_NewBuffer(int width, int height);

void* ConHost_GetBuffer();
1 change: 1 addition & 0 deletions components/conhost-v2/include/Local.h
@@ -0,0 +1 @@
#pragma once
43 changes: 43 additions & 0 deletions components/conhost-v2/src/Component.cpp
@@ -0,0 +1,43 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#include "StdInc.h"
#include "ComponentLoader.h"

class ComponentInstance : public Component
{
public:
virtual bool Initialize();

virtual bool DoGameLoad(void* module);

virtual bool Shutdown();
};

bool ComponentInstance::Initialize()
{
InitFunctionBase::RunAll();

return true;
}

bool ComponentInstance::DoGameLoad(void* module)
{
HookFunction::RunAll();

return true;
}

bool ComponentInstance::Shutdown()
{
return true;
}

extern "C" __declspec(dllexport) Component* CreateComponent()
{
return new ComponentInstance();
}
63 changes: 63 additions & 0 deletions components/conhost-v2/src/ConsoleHost.cpp
@@ -0,0 +1,63 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#include "StdInc.h"
#include "ConsoleHostImpl.h"
#include "InputHook.h"
#include <thread>
#include <condition_variable>

static std::thread g_consoleThread;
static std::once_flag g_consoleInitialized;
bool g_consoleFlag;
extern int g_scrollTop;
extern int g_bufferHeight;

static InitFunction initFunction([] ()
{
InputHook::OnWndProc.Connect([] (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, bool& pass, LRESULT& lresult)
{
if (g_consoleFlag)
{
static bool g_consoleClosing = false;

// should the console be closed?
if (wParam == VK_F8)
{
if (msg == WM_KEYDOWN)
{
g_consoleClosing = true;
return;
}

if (g_consoleClosing)
{
if (msg == WM_KEYUP)
{
g_consoleClosing = false;
g_consoleFlag = false;

return;
}
}
}
}
else
{
// check if the console should be opened
if (msg == WM_KEYUP && wParam == VK_F8)
{
g_consoleFlag = true;

pass = false;
lresult = 0;

return;
}
}
}, -10);
});

0 comments on commit 796663f

Please sign in to comment.