2010-01-09 01:26:52 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2010-01-09 01:26:52 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
#ifndef PS2EEXT_H_INCLUDED
|
|
|
|
#define PS2EEXT_H_INCLUDED
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string>
|
|
|
|
#include <cstdarg>
|
|
|
|
|
2015-11-17 17:35:02 +00:00
|
|
|
#if defined(_MSC_VER)
|
2016-02-26 11:05:50 +00:00
|
|
|
#ifndef _WIN32_WINNT
|
|
|
|
#define _WIN32_WINNT 0x0600
|
|
|
|
#endif
|
2010-01-09 01:26:52 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <windowsx.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
|
|
|
|
#define EXPORT_C_(type) extern "C" type CALLBACK
|
2015-11-17 17:35:02 +00:00
|
|
|
|
2016-05-01 09:26:18 +00:00
|
|
|
#elif defined(__unix__)
|
2015-11-17 17:35:02 +00:00
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <cstring>
|
|
|
|
|
2016-09-08 17:20:24 +00:00
|
|
|
#define EXPORT_C_(type) extern "C" __attribute__((stdcall, externally_visible, visibility("default"))) type
|
2015-11-17 17:35:02 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2016-09-08 17:20:24 +00:00
|
|
|
#define EXPORT_C_(type) extern "C" __attribute__((stdcall, externally_visible, visibility("default"))) type
|
2015-11-17 17:35:02 +00:00
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
#endif
|
|
|
|
|
2018-07-13 23:55:54 +00:00
|
|
|
#include <PluginCompatibility.h>
|
2010-01-09 01:26:52 +00:00
|
|
|
//#include "PS2Edefs.h"
|
|
|
|
|
2015-11-25 19:04:05 +00:00
|
|
|
#if !defined(_MSC_VER) || !defined(UNICODE)
|
2010-05-08 01:51:29 +00:00
|
|
|
static void SysMessage(const char *fmt, ...);
|
2010-01-09 01:26:52 +00:00
|
|
|
static void __forceinline PluginNullConfigure(std::string desc, s32 &log);
|
2015-11-25 19:04:05 +00:00
|
|
|
#else
|
|
|
|
static void SysMessage(const wchar_t *fmt, ...);
|
|
|
|
static void __forceinline PluginNullConfigure(std::wstring desc, s32 &log);
|
|
|
|
#endif
|
2010-01-09 01:26:52 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
enum FileMode {
|
2010-01-09 01:26:52 +00:00
|
|
|
READ_FILE = 0,
|
|
|
|
WRITE_FILE
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PluginLog
|
|
|
|
{
|
|
|
|
bool WriteToFile, WriteToConsole;
|
|
|
|
FILE *LogFile;
|
|
|
|
|
|
|
|
bool Open(std::string logname)
|
|
|
|
{
|
2018-07-13 23:55:54 +00:00
|
|
|
LogFile = px_fopen(logname, "w");
|
2010-01-09 01:26:52 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
if (LogFile) {
|
|
|
|
setvbuf(LogFile, NULL, _IONBF, 0);
|
2010-01-09 01:26:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Close()
|
|
|
|
{
|
2010-08-20 11:13:40 +00:00
|
|
|
if (LogFile) {
|
|
|
|
fclose(LogFile);
|
|
|
|
LogFile = NULL;
|
|
|
|
}
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Write(const char *fmt, ...)
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
if (LogFile == NULL)
|
|
|
|
return;
|
2010-01-09 01:26:52 +00:00
|
|
|
|
2018-06-22 00:20:40 +00:00
|
|
|
va_list list;
|
|
|
|
if (WriteToFile) {
|
|
|
|
va_start(list, fmt);
|
2016-11-12 15:28:37 +00:00
|
|
|
vfprintf(LogFile, fmt, list);
|
2018-06-22 00:20:40 +00:00
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
if (WriteToConsole) {
|
|
|
|
va_start(list, fmt);
|
2016-11-12 15:28:37 +00:00
|
|
|
vfprintf(stdout, fmt, list);
|
2018-06-22 00:20:40 +00:00
|
|
|
va_end(list);
|
|
|
|
}
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WriteLn(const char *fmt, ...)
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
if (LogFile == NULL)
|
|
|
|
return;
|
2010-01-09 01:26:52 +00:00
|
|
|
|
2018-06-22 00:20:40 +00:00
|
|
|
va_list list;
|
|
|
|
if (WriteToFile) {
|
|
|
|
va_start(list, fmt);
|
2016-11-12 15:28:37 +00:00
|
|
|
vfprintf(LogFile, fmt, list);
|
2018-06-22 00:20:40 +00:00
|
|
|
va_end(list);
|
2016-11-12 15:28:37 +00:00
|
|
|
fprintf(LogFile, "\n");
|
2018-06-22 00:20:40 +00:00
|
|
|
}
|
|
|
|
if (WriteToConsole) {
|
|
|
|
va_start(list, fmt);
|
|
|
|
vfprintf(stdout, fmt, list);
|
|
|
|
va_end(list);
|
2016-11-12 15:28:37 +00:00
|
|
|
fprintf(stdout, "\n");
|
2018-06-22 00:20:40 +00:00
|
|
|
}
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 19:04:05 +00:00
|
|
|
#if !defined(_MSC_VER) || !defined(UNICODE)
|
2010-01-09 01:26:52 +00:00
|
|
|
void Message(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char buf[256];
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
if (LogFile == NULL)
|
|
|
|
return;
|
2010-01-09 01:26:52 +00:00
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(buf, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
SysMessage(buf);
|
|
|
|
}
|
2015-11-25 19:04:05 +00:00
|
|
|
#else
|
2016-11-12 15:28:37 +00:00
|
|
|
void Message(const wchar_t *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
wchar_t buf[256];
|
2015-11-25 19:04:05 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
if (LogFile == NULL)
|
|
|
|
return;
|
2015-11-25 19:04:05 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
va_start(list, fmt);
|
|
|
|
vswprintf(buf, 256, fmt, list);
|
|
|
|
va_end(list);
|
2015-11-25 19:04:05 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
SysMessage(buf);
|
|
|
|
}
|
2015-11-25 19:04:05 +00:00
|
|
|
#endif
|
2010-01-09 01:26:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PluginConf
|
|
|
|
{
|
|
|
|
FILE *ConfFile;
|
|
|
|
char *PluginName;
|
|
|
|
|
|
|
|
bool Open(std::string name, FileMode mode = READ_FILE)
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
if (mode == READ_FILE) {
|
2018-07-13 23:55:54 +00:00
|
|
|
ConfFile = px_fopen(name, "r");
|
2016-11-12 15:28:37 +00:00
|
|
|
} else {
|
2018-07-13 23:55:54 +00:00
|
|
|
ConfFile = px_fopen(name, "w");
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
if (ConfFile == NULL)
|
|
|
|
return false;
|
2010-01-09 01:26:52 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Close()
|
|
|
|
{
|
2010-08-20 11:13:40 +00:00
|
|
|
if (ConfFile) {
|
|
|
|
fclose(ConfFile);
|
|
|
|
ConfFile = NULL;
|
|
|
|
}
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
int ReadInt(const std::string &item, int defval)
|
2010-01-09 01:26:52 +00:00
|
|
|
{
|
2010-01-14 00:57:01 +00:00
|
|
|
int value = defval;
|
2010-01-09 01:26:52 +00:00
|
|
|
std::string buf = item + " = %d\n";
|
|
|
|
|
2014-04-18 21:21:27 +00:00
|
|
|
if (ConfFile)
|
2016-11-12 15:28:37 +00:00
|
|
|
if (fscanf(ConfFile, buf.c_str(), &value) < 0)
|
|
|
|
fprintf(stderr, "Error reading %s\n", item.c_str());
|
2010-01-09 01:26:52 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteInt(std::string item, int value)
|
|
|
|
{
|
|
|
|
std::string buf = item + " = %d\n";
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
if (ConfFile)
|
|
|
|
fprintf(ConfFile, buf.c_str(), value);
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-01 09:26:18 +00:00
|
|
|
#if defined(__unix__)
|
2010-01-09 01:26:52 +00:00
|
|
|
|
2010-05-08 01:51:29 +00:00
|
|
|
static void SysMessage(const char *fmt, ...)
|
2010-01-09 01:26:52 +00:00
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char msg[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(msg, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
if (msg[strlen(msg) - 1] == '\n')
|
|
|
|
msg[strlen(msg) - 1] = 0;
|
2010-01-09 01:26:52 +00:00
|
|
|
|
|
|
|
GtkWidget *dialog;
|
2016-11-12 15:28:37 +00:00
|
|
|
dialog = gtk_message_dialog_new(NULL,
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_INFO,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
"%s", msg);
|
|
|
|
gtk_dialog_run(GTK_DIALOG(dialog));
|
|
|
|
gtk_widget_destroy(dialog);
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
static void __forceinline set_logging(GtkToggleButton *check, int &log)
|
2010-01-09 01:26:52 +00:00
|
|
|
{
|
2014-12-07 21:07:55 +00:00
|
|
|
log = gtk_toggle_button_get_active(check);
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullConfigure(std::string desc, int &log)
|
|
|
|
{
|
2014-12-07 21:07:55 +00:00
|
|
|
GtkWidget *dialog, *label, *check_box;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
/* Create the widgets */
|
|
|
|
dialog = gtk_dialog_new();
|
2016-11-12 15:28:37 +00:00
|
|
|
label = gtk_label_new(desc.c_str());
|
2010-01-09 01:26:52 +00:00
|
|
|
check_box = gtk_check_button_new_with_label("Logging");
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), (log != 0));
|
|
|
|
|
|
|
|
/* Ensure that the dialog box is destroyed when the user clicks ok, and that we get the check box value. */
|
2014-12-07 21:07:55 +00:00
|
|
|
g_signal_connect(check_box, "toggled", G_CALLBACK(set_logging), &log);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
/* Add all our widgets, and show everything we've added to the dialog. */
|
2016-11-12 15:28:37 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label);
|
|
|
|
gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), check_box);
|
2014-12-07 21:07:55 +00:00
|
|
|
gtk_dialog_add_button(GTK_DIALOG(dialog), "Ok", 0);
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
gtk_widget_show_all(dialog);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
gtk_dialog_run(GTK_DIALOG(dialog));
|
|
|
|
gtk_widget_destroy(dialog);
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ENTRY_POINT /* We don't need no stinkin' entry point! */
|
|
|
|
|
2015-11-17 17:35:02 +00:00
|
|
|
|
|
|
|
#elif defined(__WXMAC__) || defined(__APPLE__)
|
|
|
|
|
|
|
|
static void SysMessage(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char msg[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(msg, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
if (msg[strlen(msg) - 1] == '\n')
|
|
|
|
msg[strlen(msg) - 1] = 0;
|
2015-11-17 17:35:02 +00:00
|
|
|
|
|
|
|
// TODO OSX can we use WX MessageBox here or should Cocoa MessageBox used?
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SysMessage(const wchar_t *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
wchar_t msg[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
//vsprintf(msg, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
// TODO OSX can we use WX MessageBox here or should Cocoa MessageBox used?
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullConfigure(std::string desc, int &log)
|
|
|
|
{
|
2016-02-14 08:30:49 +00:00
|
|
|
SysMessage("This space is intentionally left blank.");
|
2015-11-17 17:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ENTRY_POINT /* We don't need no stinkin' entry point! */ // TODO OSX WTF is this anyway?
|
|
|
|
|
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
#else
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
#define usleep(x) Sleep(x / 1000)
|
2010-01-22 05:07:34 +00:00
|
|
|
|
2015-11-25 19:04:05 +00:00
|
|
|
#ifndef UNICODE
|
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
static void __forceinline SysMessage(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char tmp[512];
|
2016-11-12 15:28:37 +00:00
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(tmp, fmt, list);
|
2010-01-09 01:26:52 +00:00
|
|
|
va_end(list);
|
2016-11-12 15:28:37 +00:00
|
|
|
MessageBox(GetActiveWindow(), tmp, "Message", MB_SETFOREGROUND | MB_OK);
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullConfigure(std::string desc, s32 &log)
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
/* To do: Write a dialog box that displays a dialog box with the text in desc,
|
2010-04-25 00:31:27 +00:00
|
|
|
and a check box that says "Logging", checked if log !=0, and set log to
|
2010-01-09 01:26:52 +00:00
|
|
|
1 if it is checked on return, and 0 if it isn't. */
|
2016-02-18 12:49:56 +00:00
|
|
|
SysMessage("This space is intentionally left blank.");
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 19:04:05 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
static void __forceinline SysMessage(const wchar_t *fmt, ...)
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
va_list list;
|
|
|
|
wchar_t tmp[512];
|
|
|
|
va_start(list, fmt);
|
|
|
|
vswprintf(tmp, 512, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
MessageBox(GetActiveWindow(), tmp, L"Message", MB_SETFOREGROUND | MB_OK);
|
2015-11-25 19:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullConfigure(std::string desc, s32 &log)
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
/* To do: Write a dialog box that displays a dialog box with the text in desc,
|
2015-11-25 19:04:05 +00:00
|
|
|
and a check box that says "Logging", checked if log !=0, and set log to
|
|
|
|
1 if it is checked on return, and 0 if it isn't. */
|
2016-11-12 15:28:37 +00:00
|
|
|
SysMessage(L"This space is intentionally left blank.");
|
2015-11-25 19:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2010-01-09 01:26:52 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
#define ENTRY_POINT \
|
|
|
|
HINSTANCE hInst; \
|
|
|
|
\
|
|
|
|
BOOL APIENTRY DllMain(HANDLE hModule, /* DLL INIT*/ \
|
|
|
|
DWORD dwReason, \
|
|
|
|
LPVOID lpReserved) \
|
|
|
|
{ \
|
|
|
|
hInst = (HINSTANCE)hModule; \
|
|
|
|
return TRUE; /* very quick :)*/ \
|
|
|
|
}
|
2010-01-09 01:26:52 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif // PS2EEXT_H_INCLUDED
|