Niko/Journal for windows
This commit is contained in:
parent
e80454a0d6
commit
78c4c3b9bf
|
|
@ -3,13 +3,16 @@
|
|||
*.bak
|
||||
*.xxd
|
||||
*.exe
|
||||
*.bmp
|
||||
|
||||
/Makefile*
|
||||
|
||||
/oneshot
|
||||
/steamshim_parent/steamshim
|
||||
|
||||
/build
|
||||
/build*
|
||||
/debug
|
||||
/release
|
||||
|
||||
object_script.*
|
||||
rpgscript.bat
|
||||
|
|
|
|||
|
|
@ -73,8 +73,9 @@ void graphicsBindingInit();
|
|||
|
||||
void fileIntBindingInit();
|
||||
|
||||
void screenBindingInit();
|
||||
void journalBindingInit();
|
||||
void wallpaperBindingInit();
|
||||
void nikoBindingInit();
|
||||
void oneshotBindingInit();
|
||||
void steamBindingInit();
|
||||
|
||||
|
|
@ -106,8 +107,9 @@ static void mriBindingInit()
|
|||
graphicsBindingInit();
|
||||
|
||||
fileIntBindingInit();
|
||||
screenBindingInit();
|
||||
journalBindingInit();
|
||||
wallpaperBindingInit();
|
||||
nikoBindingInit();
|
||||
oneshotBindingInit();
|
||||
steamBindingInit();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
#include "binding-util.h"
|
||||
#include "binding-types.h"
|
||||
#include "pipe.h"
|
||||
#include "debugwriter.h"
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#define OUT_BUFFER_SIZE 256
|
||||
|
||||
static SDL_Thread *thread = NULL;
|
||||
static SDL_mutex *mutex = NULL;
|
||||
static volatile char message_buffer[OUT_BUFFER_SIZE];
|
||||
static volatile int message_len = 0;
|
||||
|
||||
int server_thread(void *data)
|
||||
{
|
||||
(void)data;
|
||||
HANDLE pipe = CreateNamedPipeW(L"\\\\.\\pipe\\oneshot-journal-to-game",
|
||||
PIPE_ACCESS_OUTBOUND,
|
||||
PIPE_TYPE_BYTE | PIPE_WAIT,
|
||||
PIPE_UNLIMITED_INSTANCES,
|
||||
OUT_BUFFER_SIZE,
|
||||
OUT_BUFFER_SIZE,
|
||||
0,
|
||||
NULL);
|
||||
for (;;) {
|
||||
ConnectNamedPipe(pipe, NULL);
|
||||
SDL_LockMutex(mutex);
|
||||
WriteFile(pipe, (const void*)message_buffer, OUT_BUFFER_SIZE, NULL, NULL);
|
||||
SDL_UnlockMutex(mutex);
|
||||
FlushFileBuffers(pipe);
|
||||
DisconnectNamedPipe(pipe);
|
||||
}
|
||||
|
||||
CloseHandle(pipe);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
RB_METHOD(journalSet)
|
||||
{
|
||||
RB_UNUSED_PARAM;
|
||||
const char *name;
|
||||
int len;
|
||||
rb_get_args(argc, argv, "s", &name, &len RB_ARG_END);
|
||||
#ifdef _WIN32
|
||||
if (thread == NULL) {
|
||||
thread = SDL_CreateThread(server_thread, "journal", NULL);
|
||||
}
|
||||
HANDLE pipe = CreateFileW(L"\\\\.\\pipe\\oneshot-game-to-journal",
|
||||
GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
NULL);
|
||||
SDL_LockMutex(mutex);
|
||||
strcpy((char*)message_buffer, name);
|
||||
message_len = len;
|
||||
SDL_UnlockMutex(mutex);
|
||||
if (pipe != INVALID_HANDLE_VALUE) {
|
||||
WriteFile(pipe, (const void*)message_buffer, OUT_BUFFER_SIZE, NULL, NULL);
|
||||
FlushFileBuffers(pipe);
|
||||
CloseHandle(pipe);
|
||||
}
|
||||
#endif
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
void journalBindingInit()
|
||||
{
|
||||
mutex = SDL_CreateMutex();
|
||||
|
||||
VALUE module = rb_define_module("Journal");
|
||||
_rb_define_module_function(module, "set", journalSet);
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#include "binding-util.h"
|
||||
#include "binding-types.h"
|
||||
#include "sharedstate.h"
|
||||
#include "eventthread.h"
|
||||
#include "debugwriter.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <shlwapi.h>
|
||||
#endif
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
RB_METHOD(nikoStart)
|
||||
{
|
||||
RB_UNUSED_PARAM;
|
||||
// Calculate where to stick the window
|
||||
POINT pos;
|
||||
pos.x = (9 * 16 - 4) * 2;
|
||||
pos.y = (13 * 16) * 2;
|
||||
SDL_SysWMinfo syswindow;
|
||||
SDL_VERSION(&syswindow.version);
|
||||
SDL_GetWindowWMInfo(shState->rtData().window, &syswindow);
|
||||
ClientToScreen(syswindow.info.win.window, &pos);
|
||||
// Start process
|
||||
#ifdef _WIN32
|
||||
WCHAR path[MAX_PATH];
|
||||
WCHAR args[MAX_PATH];
|
||||
GetModuleFileNameW(NULL, path, MAX_PATH);
|
||||
PathRemoveFileSpecW(path);
|
||||
wcscat(path, L"\\journal.exe");
|
||||
wsprintfW(args, L"journal.exe %d %d", pos.x, pos.y);
|
||||
STARTUPINFOW si;
|
||||
memset(&si, 0, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
PROCESS_INFORMATION pi;
|
||||
CreateProcessW(path, args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
||||
#else
|
||||
#ifdef linux
|
||||
#else
|
||||
#endif
|
||||
#endif
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
void nikoBindingInit()
|
||||
{
|
||||
VALUE module = rb_define_module("Niko");
|
||||
|
||||
//Functions
|
||||
_rb_define_module_function(module, "do_your_thing", nikoStart);
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
#include <windows.h>
|
||||
|
||||
#define DEFAULT_WIDTH 800
|
||||
#define DEFAULT_HEIGHT 600
|
||||
#define IN_BUFFER_SIZE 256
|
||||
|
||||
static const WCHAR journal_classname[] = L"journal";
|
||||
|
||||
static HBITMAP image_handle = NULL;
|
||||
static HANDLE image_mutex = NULL;
|
||||
|
||||
static HWND window = NULL;
|
||||
|
||||
static void loadImage(const char *name) {
|
||||
if (image_handle) {
|
||||
DeleteObject(image_handle);
|
||||
}
|
||||
image_handle = LoadBitmapA(GetModuleHandleW(NULL), name);
|
||||
}
|
||||
|
||||
// Window procedure
|
||||
LRESULT CALLBACK journal_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (msg) {
|
||||
case WM_PAINT: {
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc;
|
||||
HDC hdcMem;
|
||||
|
||||
WaitForSingleObject(image_mutex, INFINITE);
|
||||
hdc = BeginPaint(hwnd, &ps);
|
||||
hdcMem = CreateCompatibleDC(hdc);
|
||||
HANDLE oldBitmap = SelectObject(hdcMem, image_handle);
|
||||
BitBlt(hdc, 0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT, hdcMem, 0, 0, SRCCOPY);
|
||||
SelectObject(hdcMem, oldBitmap);
|
||||
DeleteDC(hdcMem);
|
||||
EndPaint(hwnd, &ps);
|
||||
ReleaseMutex(image_mutex);
|
||||
} break;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// IPC thread
|
||||
#include <stdio.h>
|
||||
DWORD WINAPI ipc_thread(LPVOID lpParam)
|
||||
{
|
||||
(void)lpParam;
|
||||
|
||||
char message[IN_BUFFER_SIZE];
|
||||
DWORD len;
|
||||
|
||||
HANDLE pipe = CreateNamedPipeW(L"\\\\.\\pipe\\oneshot-game-to-journal",
|
||||
PIPE_ACCESS_INBOUND,
|
||||
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
|
||||
PIPE_UNLIMITED_INSTANCES,
|
||||
IN_BUFFER_SIZE,
|
||||
IN_BUFFER_SIZE,
|
||||
0,
|
||||
NULL);
|
||||
|
||||
for (;;) {
|
||||
if (!ConnectNamedPipe(pipe, NULL))
|
||||
continue;
|
||||
for (;;) {
|
||||
if (ReadFile(pipe, (void*)message, IN_BUFFER_SIZE, &len, NULL)
|
||||
&& len == IN_BUFFER_SIZE)
|
||||
{
|
||||
WaitForSingleObject(image_mutex, INFINITE);
|
||||
if (strcmp(message, "default") == 0) {
|
||||
exit(0);
|
||||
}
|
||||
loadImage(message);
|
||||
InvalidateRect(window, NULL, FALSE);
|
||||
ReleaseMutex(image_mutex);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
DisconnectNamedPipe(pipe);
|
||||
}
|
||||
|
||||
CloseHandle(pipe);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_journal()
|
||||
{
|
||||
// Create
|
||||
HINSTANCE module = GetModuleHandleW(NULL);
|
||||
|
||||
loadImage("default");
|
||||
|
||||
// Initial image
|
||||
char message[IN_BUFFER_SIZE];
|
||||
DWORD len;
|
||||
HANDLE pipe = CreateFileW(L"\\\\.\\pipe\\oneshot-journal-to-game",
|
||||
GENERIC_READ,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
NULL);
|
||||
if (pipe != INVALID_HANDLE_VALUE) {
|
||||
if (ReadFile(pipe, (void*)message, IN_BUFFER_SIZE, &len, NULL)
|
||||
&& len == IN_BUFFER_SIZE)
|
||||
{
|
||||
loadImage(message);
|
||||
}
|
||||
CloseHandle(pipe);
|
||||
}
|
||||
|
||||
WNDCLASSEXW wc;
|
||||
wc.cbSize = sizeof(wc);
|
||||
wc.style = 0;
|
||||
wc.lpfnWndProc = journal_proc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = module;
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = NULL;
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = journal_classname;
|
||||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
if (!RegisterClassEx(&wc))
|
||||
return 1;
|
||||
|
||||
if (!(window = CreateWindowExW(WS_EX_COMPOSITED | WS_EX_LAYERED | WS_EX_TOPMOST,
|
||||
journal_classname,
|
||||
L"",
|
||||
WS_OVERLAPPEDWINDOW ^ (WS_THICKFRAME | WS_MAXIMIZEBOX),
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
DEFAULT_WIDTH, DEFAULT_HEIGHT,
|
||||
NULL, NULL, module, NULL))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
SetLayeredWindowAttributes(window, RGB(0, 255, 0), 0, LWA_COLORKEY);
|
||||
|
||||
ShowWindow(window, SW_SHOWNOACTIVATE);
|
||||
UpdateWindow(window);
|
||||
|
||||
image_mutex = CreateMutexW(NULL, NULL, NULL);
|
||||
HANDLE thread = CreateThread(NULL, 0, ipc_thread, NULL, 0, NULL);
|
||||
|
||||
// Dispatch messages
|
||||
for (;;) {
|
||||
MSG msg;
|
||||
if (GetMessage(&msg, window, 0, 0) > 0) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO make this less messy?
|
||||
TerminateThread(thread, 0);
|
||||
|
||||
DestroyWindow(window);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
TEMPLATE = app
|
||||
CONFIG += c++11
|
||||
CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
||||
SOURCES += main.cpp \
|
||||
niko.cpp \
|
||||
journal.cpp
|
||||
|
||||
LIBS += -lgdi32
|
||||
|
||||
RC_FILE = resources.rc
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#include <windows.h>
|
||||
|
||||
extern int do_niko(int x, int y);
|
||||
extern int do_journal();
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
(void)hInstance;
|
||||
(void)hPrevInstance;
|
||||
(void)lpCmdLine;
|
||||
(void)nCmdShow;
|
||||
|
||||
int argc;
|
||||
LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||
|
||||
// argc == 3, assume niko
|
||||
if (argc == 3) {
|
||||
int x = _wtoi(argv[1]);
|
||||
int y = _wtoi(argv[2]);
|
||||
return do_niko(x, y);
|
||||
}
|
||||
// assume journal
|
||||
return do_journal();
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
#include <windows.h>
|
||||
|
||||
static const WCHAR niko_classname[] = L"niko";
|
||||
static HWND niko = NULL;
|
||||
static HBITMAP niko_bmps[3] = {NULL};
|
||||
static int niko_offset = 0;
|
||||
|
||||
// Window procedure
|
||||
LRESULT CALLBACK niko_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (msg) {
|
||||
case WM_CLOSE:
|
||||
return 0;
|
||||
|
||||
case WM_PAINT: {
|
||||
static int frame = 0;
|
||||
if (niko_offset % 32 >= 16) {
|
||||
frame = 1;
|
||||
} else {
|
||||
if ((niko_offset / 32) % 2)
|
||||
frame = 0;
|
||||
else
|
||||
frame = 2;
|
||||
}
|
||||
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc;
|
||||
BITMAP bitmap;
|
||||
HDC hdcMem;
|
||||
HGDIOBJ oldBitmap;
|
||||
|
||||
hdc = BeginPaint(hwnd, &ps);
|
||||
|
||||
hdcMem = CreateCompatibleDC(hdc);
|
||||
oldBitmap = SelectObject(hdcMem, niko_bmps[frame]);
|
||||
|
||||
GetObject(niko_bmps[frame], sizeof(bitmap), &bitmap);
|
||||
BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
|
||||
|
||||
SelectObject(hdcMem, oldBitmap);
|
||||
DeleteDC(hdcMem);
|
||||
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_niko(int x, int y)
|
||||
{
|
||||
// Create
|
||||
HINSTANCE module = GetModuleHandleW(NULL);
|
||||
niko_bmps[0] = LoadBitmapW(module, L"NIKO1");
|
||||
niko_bmps[1] = LoadBitmapW(module, L"NIKO2");
|
||||
niko_bmps[2] = LoadBitmapW(module, L"NIKO3");
|
||||
|
||||
WNDCLASSEXW wc;
|
||||
wc.cbSize = sizeof(wc);
|
||||
wc.style = 0;
|
||||
wc.lpfnWndProc = niko_proc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = module;
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = NULL;
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = niko_classname;
|
||||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
if (!RegisterClassEx(&wc))
|
||||
return 1;
|
||||
|
||||
if (!(niko = CreateWindowExW(WS_EX_COMPOSITED | WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
|
||||
niko_classname,
|
||||
L"Niko",
|
||||
WS_POPUP,
|
||||
x, y,
|
||||
24 * 2, 32 * 2,
|
||||
NULL, NULL, module, NULL))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
SetLayeredWindowAttributes(niko, RGB(0, 255, 0), 0, LWA_COLORKEY);
|
||||
|
||||
ShowWindow(niko, SW_SHOWNOACTIVATE);
|
||||
UpdateWindow(niko);
|
||||
|
||||
// Thread
|
||||
int screenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
||||
|
||||
// Get starting position
|
||||
RECT area;
|
||||
GetWindowRect(niko, &area);
|
||||
|
||||
// Just keep walking down
|
||||
for (;;) {
|
||||
// Dispatch messages
|
||||
unsigned long tick = GetTickCount();
|
||||
for (;;) {
|
||||
MSG msg;
|
||||
if (PeekMessage(&msg, niko, 0, 0, PM_REMOVE) > 0) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
} else {
|
||||
if (GetTickCount() - tick >= 1000 / 60)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
niko_offset += 2;
|
||||
if (area.top + niko_offset >= screenHeight)
|
||||
break;
|
||||
SetWindowPos(niko, NULL, area.left, area.top + niko_offset, 0, 0, SWP_NOSIZE);
|
||||
InvalidateRect(niko, NULL, FALSE);
|
||||
}
|
||||
|
||||
DestroyWindow(niko);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (niko_bmps[i])
|
||||
DeleteObject(niko_bmps[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#include <winuser.h>
|
||||
NIKO1 BITMAP "niko1.bmp"
|
||||
NIKO2 BITMAP "niko2.bmp"
|
||||
NIKO3 BITMAP "niko3.bmp"
|
||||
|
||||
default BITMAP "default.bmp"
|
||||
t1 BITMAP "t1.bmp"
|
||||
t2 BITMAP "t2.bmp"
|
||||
t3 BITMAP "t3.bmp"
|
||||
t4 BITMAP "t4.bmp"
|
||||
t5 BITMAP "t5.bmp"
|
||||
t6 BITMAP "t6.bmp"
|
||||
t7 BITMAP "t7.bmp"
|
||||
t8 BITMAP "t8.bmp"
|
||||
t9 BITMAP "t9.bmp"
|
||||
t10 BITMAP "t10.bmp"
|
||||
t11 BITMAP "t11.bmp"
|
||||
t12 BITMAP "t12.bmp"
|
||||
t13 BITMAP "t13.bmp"
|
||||
t14 BITMAP "t14.bmp"
|
||||
t15 BITMAP "t15.bmp"
|
||||
t16 BITMAP "t16.bmp"
|
||||
c1 BITMAP "c1.bmp"
|
||||
c2 BITMAP "c2.bmp"
|
||||
c3 BITMAP "c3.bmp"
|
||||
c4 BITMAP "c4.bmp"
|
||||
c5 BITMAP "c5.bmp"
|
||||
c6 BITMAP "c6.bmp"
|
||||
c7 BITMAP "c7.bmp"
|
||||
11
mkxp.pro
11
mkxp.pro
|
|
@ -55,6 +55,7 @@ unix {
|
|||
!macx: {
|
||||
PKGCONFIG += openal zlib
|
||||
INCLUDEPATH += /usr/include/AL /usr/local/include/AL
|
||||
SOURCES += src/xdg-user-dir-lookup.c
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,11 +195,8 @@ SOURCES += \
|
|||
src/rgssad.cpp \
|
||||
src/vorbissource.cpp \
|
||||
src/oneshot.cpp \
|
||||
binding-mri/steam-binding.cpp \
|
||||
src/xdg-user-dir-lookup.c \
|
||||
src/screen.cpp \
|
||||
binding-mri/screen-binding.cpp \
|
||||
binding-mri/wallpaper-binding.cpp
|
||||
binding-mri/journal-binding.cpp
|
||||
|
||||
STEAM {
|
||||
HEADERS += src/steam.h steamshim/steamshim_child.h
|
||||
|
|
@ -293,7 +291,10 @@ BINDING_MRI {
|
|||
binding-mri/audio-binding.cpp \
|
||||
binding-mri/module_rpg.cpp \
|
||||
binding-mri/filesystem-binding.cpp \
|
||||
binding-mri/oneshot-binding.cpp
|
||||
binding-mri/oneshot-binding.cpp \
|
||||
binding-mri/steam-binding.cpp \
|
||||
binding-mri/wallpaper-binding.cpp \
|
||||
binding-mri/niko-binding.cpp
|
||||
}
|
||||
|
||||
OTHER_FILES += $$EMBED
|
||||
|
|
|
|||
Loading…
Reference in New Issue