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)
|
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
|
|
|
|
|
|
|
#elif defined(GTK_MAJOR_VERSION)
|
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <cstring>
|
|
|
|
|
2015-04-17 16:33:26 +00:00
|
|
|
#define EXPORT_C_(type) extern "C" __attribute__((stdcall,externally_visible,visibility("default"))) type
|
2015-11-17 17:35:02 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define EXPORT_C_(type) extern "C" __attribute__((stdcall,externally_visible,visibility("default"))) type
|
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//#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);
|
|
|
|
static void __forceinline PluginNullAbout(const char *aboutText);
|
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);
|
|
|
|
static void __forceinline PluginNullAbout(const wchar_t *aboutText);
|
|
|
|
#endif
|
2010-01-09 01:26:52 +00:00
|
|
|
|
|
|
|
enum FileMode
|
|
|
|
{
|
|
|
|
READ_FILE = 0,
|
|
|
|
WRITE_FILE
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PluginLog
|
|
|
|
{
|
|
|
|
bool WriteToFile, WriteToConsole;
|
|
|
|
FILE *LogFile;
|
|
|
|
|
|
|
|
bool Open(std::string logname)
|
|
|
|
{
|
|
|
|
LogFile = fopen(logname.c_str(), "w");
|
|
|
|
|
|
|
|
if (LogFile)
|
|
|
|
{
|
|
|
|
setvbuf(LogFile, NULL, _IONBF, 0);
|
|
|
|
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, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
if (LogFile == NULL) return;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
if (WriteToFile) vfprintf(LogFile, fmt, list);
|
|
|
|
if (WriteToConsole) vfprintf(stdout, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteLn(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
if (LogFile == NULL) return;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
if (WriteToFile) vfprintf(LogFile, fmt, list);
|
|
|
|
if (WriteToConsole) vfprintf(stdout, fmt, list);
|
|
|
|
va_end(list);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
if (WriteToFile) fprintf(LogFile, "\n");
|
|
|
|
if (WriteToConsole) fprintf(stdout, "\n");
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
if (LogFile == NULL) return;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(buf, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
SysMessage(buf);
|
|
|
|
}
|
2015-11-25 19:04:05 +00:00
|
|
|
#else
|
|
|
|
void Message(const wchar_t *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
wchar_t buf[256];
|
|
|
|
|
|
|
|
if (LogFile == NULL) return;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vswprintf(buf, 256, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
SysMessage(buf);
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-09 01:26:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PluginConf
|
|
|
|
{
|
|
|
|
FILE *ConfFile;
|
|
|
|
char *PluginName;
|
|
|
|
|
|
|
|
bool Open(std::string name, FileMode mode = READ_FILE)
|
|
|
|
{
|
|
|
|
if (mode == READ_FILE)
|
|
|
|
{
|
|
|
|
ConfFile = fopen(name.c_str(), "r");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfFile = fopen(name.c_str(), "w");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ConfFile == NULL) return false;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-01-14 00:57:01 +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)
|
|
|
|
if (fscanf(ConfFile, buf.c_str(), &value) < 0)
|
2015-11-25 19:04:05 +00:00
|
|
|
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";
|
|
|
|
|
2013-04-14 10:48:50 +00:00
|
|
|
if (ConfFile) fprintf(ConfFile, buf.c_str(), value);
|
2010-01-09 01:26:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-17 17:35:02 +00:00
|
|
|
#if defined(GTK_MAJOR_VERSION)
|
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);
|
|
|
|
|
|
|
|
if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
|
|
|
|
|
|
|
|
GtkWidget *dialog;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-12-07 21:07:55 +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();
|
|
|
|
label = gtk_label_new (desc.c_str());
|
|
|
|
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. */
|
2010-12-24 23:58:56 +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);
|
|
|
|
|
2010-01-09 01:26:52 +00:00
|
|
|
gtk_widget_show_all (dialog);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2014-12-07 21:07:55 +00:00
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
2010-01-09 01:26:52 +00:00
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullAbout(const char *aboutText)
|
|
|
|
{
|
|
|
|
SysMessage(aboutText);
|
|
|
|
}
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
|
|
|
if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
SysMessage("This space intentionally left blank.");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullAbout(const char *aboutText)
|
|
|
|
{
|
|
|
|
SysMessage(aboutText);
|
|
|
|
}
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2010-01-22 05:07:34 +00:00
|
|
|
#define usleep(x) Sleep(x / 1000)
|
|
|
|
|
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];
|
|
|
|
va_start(list,fmt);
|
|
|
|
vsprintf(tmp,fmt,list);
|
|
|
|
va_end(list);
|
|
|
|
MessageBox( GetActiveWindow(), tmp, "Message", MB_SETFOREGROUND | MB_OK );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullConfigure(std::string desc, s32 &log)
|
|
|
|
{
|
|
|
|
/* 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. */
|
|
|
|
SysMessage("This space intentionally left blank.");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullAbout(const char *aboutText)
|
|
|
|
{
|
|
|
|
SysMessage(aboutText);
|
|
|
|
}
|
2015-11-25 19:04:05 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
static void __forceinline SysMessage(const wchar_t *fmt, ...)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullConfigure(std::string desc, s32 &log)
|
|
|
|
{
|
|
|
|
/* To do: Write a dialog box that displays a dialog box with the text in desc,
|
|
|
|
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. */
|
|
|
|
SysMessage(L"This space intentionally left blank.");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __forceinline PluginNullAbout(const wchar_t *aboutText)
|
|
|
|
{
|
|
|
|
SysMessage(aboutText);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2010-01-09 01:26:52 +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 :)*/ \
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif // PS2EEXT_H_INCLUDED
|