summaryrefslogtreecommitdiff
path: root/macosx/plugins/DFNet/macsrc
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-11-18 04:46:20 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-11-18 04:46:20 +0000
commita4f36118dc3781fcee3e633d2db99127de919c68 (patch)
treeaca2b0c5e96609da798acb5b2bae696ee45444fd /macosx/plugins/DFNet/macsrc
parent8a299835645bef784c8c468def91031e2e5e4400 (diff)
downloadpcsxr-a4f36118dc3781fcee3e633d2db99127de919c68.tar.gz
DFNet for Mac OS X.
Note that DFNet is disabled by default, and there are still a few rough edges. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@72400 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/plugins/DFNet/macsrc')
-rw-r--r--macosx/plugins/DFNet/macsrc/PluginConfigController.h16
-rw-r--r--macosx/plugins/DFNet/macsrc/PluginConfigController.m145
-rw-r--r--macosx/plugins/DFNet/macsrc/SockDialog.h16
-rw-r--r--macosx/plugins/DFNet/macsrc/SockDialog.m85
-rw-r--r--macosx/plugins/DFNet/macsrc/cfg.c51
5 files changed, 313 insertions, 0 deletions
diff --git a/macosx/plugins/DFNet/macsrc/PluginConfigController.h b/macosx/plugins/DFNet/macsrc/PluginConfigController.h
new file mode 100644
index 00000000..f0986e76
--- /dev/null
+++ b/macosx/plugins/DFNet/macsrc/PluginConfigController.h
@@ -0,0 +1,16 @@
+#define PluginConfigController DFNetPlayPluginConfigController
+
+#import <Cocoa/Cocoa.h>
+
+@interface PluginConfigController : NSWindowController
+{
+ IBOutlet NSTextField *ipAddress;
+ IBOutlet NSTextField *portNum;
+ IBOutlet NSTextField *playerNum;
+}
+- (IBAction)cancel:(id)sender;
+- (IBAction)ok:(id)sender;
+
+- (void)loadValues;
+
+@end
diff --git a/macosx/plugins/DFNet/macsrc/PluginConfigController.m b/macosx/plugins/DFNet/macsrc/PluginConfigController.m
new file mode 100644
index 00000000..39ff984f
--- /dev/null
+++ b/macosx/plugins/DFNet/macsrc/PluginConfigController.m
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2010, Wei Mingzhi <whistler@openoffice.org>.
+ * All Rights Reserved.
+ *
+ * Based on: Cdrom for Psemu Pro like Emulators
+ * By: linuzappz <linuzappz@hotmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, see <http://www.gnu.org/licenses>.
+ */
+
+#import "PluginConfigController.h"
+#include "dfnet.h"
+
+#define kIPADDRKEY @"IP Address"
+#define kIPPORT @"IP Port"
+#define kPLAYERNUM @"Player Number"
+
+#define APP_ID @"net.codeplex.pcsxr.DFNet"
+#define PrefsKey APP_ID @" Settings"
+
+static PluginConfigController *windowController;
+
+void AboutDlgProc()
+{
+ // Get parent application instance
+ NSApplication *app = [NSApplication sharedApplication];
+ NSBundle *bundle = [NSBundle bundleWithIdentifier:APP_ID];
+
+ // Get Credits.rtf
+ NSString *path = [bundle pathForResource:@"Credits" ofType:@"rtf"];
+ NSAttributedString *credits;
+ if (path) {
+ credits = [[[NSAttributedString alloc] initWithPath: path
+ documentAttributes:NULL] autorelease];
+ } else {
+ credits = [[[NSAttributedString alloc] initWithString:@""] autorelease];
+ }
+
+ // Get Application Icon
+ NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[bundle bundlePath]];
+ [icon setSize:NSMakeSize(64, 64)];
+
+ [app orderFrontStandardAboutPanelWithOptions:[NSDictionary dictionaryWithObjectsAndKeys:
+ [bundle objectForInfoDictionaryKey:@"CFBundleName"], @"ApplicationName",
+ icon, @"ApplicationIcon",
+ [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"ApplicationVersion",
+ [bundle objectForInfoDictionaryKey:@"CFBundleVersion"], @"Version",
+ [bundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"], @"Copyright",
+ credits, @"Credits",
+ nil]];
+}
+
+void ConfDlgProc()
+{
+ NSWindow *window;
+
+ if (windowController == nil) {
+ windowController = [[PluginConfigController alloc] initWithWindowNibName:@"DFNet"];
+ }
+ window = [windowController window];
+
+ [windowController loadValues];
+
+ [window center];
+ [window makeKeyAndOrderFront:nil];
+}
+
+void ReadConfig()
+{
+ NSDictionary *keyValues;
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ [defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"127.0.0.1",kIPADDRKEY,
+ [NSNumber numberWithInt:33306], kIPPORT,
+ [NSNumber numberWithInt:1], kPLAYERNUM,
+ nil], PrefsKey, nil]];
+
+ keyValues = [defaults dictionaryForKey:PrefsKey];
+
+ conf.PortNum = [[keyValues objectForKey:kIPPORT] intValue];
+ conf.PlayerNum = [[keyValues objectForKey:kPLAYERNUM] intValue];
+ strcpy(conf.ipAddress, [[keyValues objectForKey:kIPADDRKEY] cString]);
+}
+
+@implementation PluginConfigController
+
+- (IBAction)cancel:(id)sender
+{
+ [self close];
+}
+
+- (IBAction)ok:(id)sender
+{
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ NSMutableDictionary *writeDic = [NSMutableDictionary dictionaryWithDictionary:[defaults dictionaryForKey:PrefsKey]];
+ [writeDic setObject:[NSNumber numberWithInt:[portNum intValue]] forKey:kIPPORT];
+ [writeDic setObject:[NSNumber numberWithInt:[playerNum intValue]] forKey:kPLAYERNUM];
+ [writeDic setObject:[ipAddress stringValue] forKey:kIPADDRKEY];
+
+ // write to defaults
+ [defaults setObject:writeDic forKey:PrefsKey];
+ [defaults synchronize];
+
+ // and set global values accordingly
+ ReadConfig();
+
+ [self close];
+}
+
+- (void)loadValues
+{
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ ReadConfig();
+ NSDictionary *keyValues = [defaults dictionaryForKey:PrefsKey];
+
+ [ipAddress setStringValue:[keyValues objectForKey:kIPADDRKEY]];
+ [portNum setStringValue:[[keyValues objectForKey:kIPPORT] stringValue]];
+ [playerNum setStringValue:[[keyValues objectForKey:kPLAYERNUM] stringValue]];
+}
+
+@end
+
+char* PLUGLOC(char *toloc)
+{
+ NSBundle *mainBundle = [NSBundle bundleForClass:[PluginConfigController class]];
+ NSString *origString = nil, *transString = nil;
+ origString = [NSString stringWithCString:toloc encoding:NSUTF8StringEncoding];
+ transString = [mainBundle localizedStringForKey:origString value:nil table:nil];
+ return [transString cStringUsingEncoding:NSUTF8StringEncoding];
+}
+
diff --git a/macosx/plugins/DFNet/macsrc/SockDialog.h b/macosx/plugins/DFNet/macsrc/SockDialog.h
new file mode 100644
index 00000000..2898ceec
--- /dev/null
+++ b/macosx/plugins/DFNet/macsrc/SockDialog.h
@@ -0,0 +1,16 @@
+//
+// SockDialog.h
+// DFNet
+//
+// Created by C.W. Betts on 2/18/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface SockDialog : NSWindowController {
+
+}
+- (IBAction)cancel:(id)sender;
+@end
diff --git a/macosx/plugins/DFNet/macsrc/SockDialog.m b/macosx/plugins/DFNet/macsrc/SockDialog.m
new file mode 100644
index 00000000..e49ffc3d
--- /dev/null
+++ b/macosx/plugins/DFNet/macsrc/SockDialog.m
@@ -0,0 +1,85 @@
+//
+// SockDialog.m
+// DFNet
+//
+// Created by C.W. Betts on 2/18/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "SockDialog.h"
+#include "dfnet.h"
+
+void SysMessage(const char *fmt, ...) {
+ va_list list;
+ char msg[512];
+ //char cmd[512];
+
+ va_start(list, fmt);
+ vsprintf(msg, fmt, list);
+ va_end(list);
+
+ //sprintf(cmd, "message %s\n", msg);
+ NSString *errString = [NSString stringWithUTF8String:msg];
+ fprintf(stderr, "%s", msg);
+ NSAlert *alert = [NSAlert alertWithMessageText:nil defaultButton:@"Exit" alternateButton:nil otherButton:nil informativeTextWithFormat:errString];
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ //NSInteger result = NSRunAlertPanel(errString, nil, @"Okay", nil, nil);
+ NSInteger result = [alert runModal];
+ if (result == NSAlertDefaultReturn)
+ {
+ //TODO: Handle closing the emulator, but not quitting the program.
+ }
+}
+
+
+static SockDialog *globalSock = nil;
+
+void sockCreateWaitDlg() {
+ if (globalSock == nil) {
+ globalSock = [[SockDialog alloc] init];
+ }
+ [globalSock showWindow:nil];
+ NSWindow *tempWindow = [globalSock window];
+ [tempWindow center];
+ [tempWindow makeKeyAndOrderFront:nil];
+
+}
+
+void sockDlgUpdate() {
+
+}
+
+long sockOpen()
+{
+ return 0;
+}
+
+void sockDestroyWaitDlg() {
+ if (globalSock != nil) {
+ [globalSock close];
+ [globalSock release];
+ globalSock = nil;
+ }
+}
+
+@implementation SockDialog
+- (IBAction)cancel:(id)sender {
+ WaitCancel = 1;
+
+}
+
+- (id)init {
+ if ((self = [super initWithWindowNibName:@"SockDialog"])) {
+ return self;
+ } else {
+ [self autorelease];
+ return nil;
+ }
+}
+
+-(void)dealloc {
+
+ [super dealloc];
+}
+
+@end
diff --git a/macosx/plugins/DFNet/macsrc/cfg.c b/macosx/plugins/DFNet/macsrc/cfg.c
new file mode 100644
index 00000000..a61e6cd8
--- /dev/null
+++ b/macosx/plugins/DFNet/macsrc/cfg.c
@@ -0,0 +1,51 @@
+//
+// DF Netplay Plugin
+//
+// Based on netSock 0.2 by linuzappz.
+// The Plugin is free source code.
+//
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dfnet.h"
+
+#define CFG_FILENAME "dfnet.cfg"
+
+void AboutDlgProc();
+void ConfDlgProc();
+
+void NETabout() {
+ AboutDlgProc();
+}
+
+long NETconfigure() {
+ ConfDlgProc();
+
+ return 0;
+}
+
+void SaveConf() {
+ FILE *f;
+
+ f = fopen(CFG_FILENAME, "w");
+ if (f == NULL) return;
+ fwrite(&conf, 1, sizeof(conf), f);
+ fclose(f);
+}
+
+void LoadConf() {
+ FILE *f;
+
+ f = fopen(CFG_FILENAME, "r");
+ if (f == NULL) {
+ conf.PlayerNum = 1;
+ conf.PortNum = 33306;
+ strcpy(conf.ipAddress, "127.0.0.1");
+ return;
+ }
+
+ fread(&conf, 1, sizeof(conf), f);
+ fclose(f);
+}