Skip to content

Commit

Permalink
Add support for node-webkit and firefox os
Browse files Browse the repository at this point in the history
Work in progress.
  • Loading branch information
vthibault committed Oct 4, 2014
1 parent 4cc90c2 commit 670ec11
Show file tree
Hide file tree
Showing 19 changed files with 348 additions and 32 deletions.
2 changes: 1 addition & 1 deletion chrome-app/index.js → applications/chrome-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ chrome.app.runtime.onLaunched.addListener(function() {
var width = 800;
var height = 600;

chrome.app.window.create('chrome-app/window.html', {
chrome.app.window.create('applications/window.html', {
bounds: {
width: width,
height: height,
Expand Down
File renamed without changes
File renamed without changes
14 changes: 14 additions & 0 deletions applications/node-webkit/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ROConfig.saveFiles = false;
ROConfig.skipIntro = true;
ROConfig.grfList = 'DATA.INI';
ROConfig.servers = 'data/clientinfo.xml';
ROConfig.packetver = 20141223;
ROConfig.packetKeys = true;

// Add support for node.js + requirejs
window.gui = require('nw.gui');
window.requireNode = window.require;
delete window.require;

window.requireNode.version = process.versions.node;
delete process.versions.node;
16 changes: 16 additions & 0 deletions applications/node-webkit/window.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>ROBrowser - Ragnarok Online in the Browser</title>
<base href="../../"/>
<style type="text/css">
body { overflow:hidden; }
html, body { width:100%; height:100%; background-color:black; }
</style>
</head>
<body>
<script src="applications/settings.js"></script>
<script src="applications/node-webkit/bootstrap.js"></script>
<script data-main="src/App/Online" src="src/Vendors/require.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion chrome-app/readme.md → applications/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ It give access to some useful API and so, do not depend on JAVA for the socket c

###Configuration###

Open **chrome-app/settings.js** and add your own configurations: *packetver*, *width*, *height*, *quality*, *remoteClient*, *grfList*, *servers*, ...
Open **applications/settings.js** and add your own configurations: *packetver*, *width*, *height*, *quality*, *remoteClient*, *grfList*, *servers*, ...
You can see a list of availables parameters [in the getting started guide](http://www.robrowser.com/getting-started#API)

###Creation###
Expand Down
2 changes: 1 addition & 1 deletion chrome-app/window.html → applications/window.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</style>
</head>
<body>
<script src="chrome-app/settings.js"></script>
<script src="applications/settings.js"></script>
<script data-main="src/App/Online" src="src/Vendors/require.js"></script>
</body>
</html>
5 changes: 0 additions & 5 deletions chrome-app/settings.js

This file was deleted.

9 changes: 5 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@

"minimum_chrome_version": "23",
"icons": {
"16": "chrome-app/icon_16.png",
"128": "chrome-app/icon_128.png"
"16": "applications/icon_16.png",
"128": "applications/icon_128.png"
},

"app": {
"background": {
"scripts": ["chrome-app/index.js"]
"scripts": ["applications/chrome-app/index.js"]
}
},

"permissions": [
{ "socket": ["tcp-connect:*:*"] },
"storage",
"http://*/*"
"http://*/*",
"https://*/*"
],

"requirements": {
Expand Down
19 changes: 19 additions & 0 deletions manifest.webapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.1",
"name": "roBrowser",
"description": "Ragnarok Online Custom Client",
"launch_path": "/applications/window.html",
"icons": {
"16": "/applications/icon_16.png",
"128": "/applications/icon_128.png"
},
"developer": {
"name": "Vincent Thibault",
"url": "http://www.robrowser.com/"
},
"permissions": {
"tcp-socket":{}
},
"orientation": ["landscape"],
"type": "privileged"
}
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "roBrowser",
"main": "applications/node-webkit/window.html",
"window": {
"title": "Ragnarok Online",

"width": 1024,
"height": 768,

"min_width": 1024,
"max_width": 1024,

"min_height": 768,
"max_height": 768,

"fullscreen": false,
"frame": true,
"icon": "applications/icon_128.png",
"toolbar": true
},
"chromium-args": "--enable-webgl --ignore-gpu-blacklist"
}
52 changes: 35 additions & 17 deletions src/Core/FileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ define(function( require )
var Action = require('Loaders/Action');
var Str = require('Loaders/Str');
var FileSystem = require('Core/FileSystem');
var fs = self.requireNode && self.requireNode('fs');


/**
Expand Down Expand Up @@ -59,19 +60,24 @@ define(function( require )
*/
FileManager.init = function Init( grfList )
{

var i, count;
var content, files, result, regex;
var i, count, sortBySize = true;
var list = [];

// load GRFs from a file (DATA.INI)
if (typeof grfList === 'string') {
var files = FileSystem.search( grfList );

if (files.length) {
var content = (new FileReaderSync()).readAsText(files[0]);
if (fs) {
content = fs.readFileSync(grfList);
}
else if ((files = FileSystem.search(grfList)).length) {
content = (new FileReaderSync()).readAsText(files[0]);
}
else {
grfList = /\.grf$/i;
}

var result;
var regex = /(\d+)=([^\s]+)/g;
if (content) {
regex = /(\d+)=([^\s]+)/g;

// Get a list of GRF
while ((result = regex.exec(content))) {
Expand All @@ -88,31 +94,38 @@ define(function( require )
i++;
}

grfList = list;
}

else {
grfList = /\.grf$/i;
grfList = list;
sortBySize = false;
}
}

// Load grfs from a list defined by the user
if (grfList instanceof Array) {
list = grfList;
for (i = 0, count = list.length; i < count; ++i) {
if (fs && fs.existsSync(list[i])) {
list[i] = {
name: list[i],
size: fs.statSync(list[i]).size,
fd: fs.openSync(list[i], 'r')
};
continue;
}
list[i] = FileSystem.getFileSync( list[i] );
}

list.sort(function(a,b){
return a.size - b.size;
});
}

// Search GRF from a regex
if (grfList instanceof RegExp) {
list = FileSystem.search( grfList );
}

if (sortBySize) {
list.sort(function(a,b){
return a.size - b.size;
});
}

// Load Game files
for (i = 0, count = list.length; i < count; ++i) {
FileManager.addGameFile(list[i]);
Expand Down Expand Up @@ -205,6 +218,11 @@ define(function( require )
// Trim the path
filename = filename.replace(/^\s+|\s+$/g, '');

if (fs && fs.existsSync(filename)) {
callback(fs.readFileSync(filename));
return;
}

// Search in filesystem
FileSystem.getFile(
filename,
Expand Down
7 changes: 7 additions & 0 deletions src/Core/ThreadEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
* @author Vincent Thibault
*/

// Node-webkit
if (self.require) {
self.requireNode = self.require;
delete self.require;
self.requireNode.version = process.versions.node;
delete process.versions.node;
}

importScripts('../Vendors/require.js');
requirejs.config({
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/GameEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ define(function( require )
// Start Intro, wait the user to add files
q.add(function(){
Client.onFilesLoaded = function(count){
if (!Configs.get('remoteClient') && !count) {
if (!Configs.get('remoteClient') && !count && !window.requireNode) {
if (!Context.Is.APP) {
alert( 'No client to initialize roBrowser');
}
Expand Down
21 changes: 21 additions & 0 deletions src/Loaders/GameFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ function( GameFileDecrypt, BinaryReader, Struct, Infl
}


/**
* @var {File System} Nodejs
*/
var fs = self.requireNode && self.requireNode('fs');


/**
* GRF Constants
*/
Expand Down Expand Up @@ -94,6 +100,13 @@ function( GameFileDecrypt, BinaryReader, Struct, Infl
// Helper
file.slice = file.slice || file.webkitSlice || file.mozSlice;
reader.load = function( start, len ) {
// node.js
if (fs && file.fd) {
var buffer = new Buffer(len);
fs.readSync(file.fd, buffer, 0, len, start);
return (new Uint8Array(buffer)).buffer;
}

return reader.readAsArrayBuffer(
file.slice( start, start+len )
);
Expand Down Expand Up @@ -303,6 +316,14 @@ function( GameFileDecrypt, BinaryReader, Struct, Infl
return false;
}

// node.js
if (fs && file.fd) {
var buffer = new Buffer(entry.length_aligned);
fs.readSync(this.file.fd, buffer, 0, entry.length_aligned, entry.offset + GRF.struct_header.size);
grf.decodeEntry( (new Uint8Array(buffer)).buffer, entry, callback);
return true;
}

blob = this.file.slice(
entry.offset + GRF.struct_header.size,
entry.offset + GRF.struct_header.size + entry.length_aligned
Expand Down
16 changes: 14 additions & 2 deletions src/Network/NetworkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ define(function( require )
var ChromeSocket = require('./SocketHelpers/ChromeSocket');
var JavaSocket = require('./SocketHelpers/JavaSocket');
var WebSocket = require('./SocketHelpers/WebSocket');
var TCPSocket = require('./SocketHelpers/TCPSocket');
var NodeSocket = require('./SocketHelpers/NodeSocket');
var getModule = require;


Expand All @@ -47,7 +49,7 @@ define(function( require )
* Buffer to use to read packets
* @var buffer
*/
var _save_buffer = null;
var _save_buffer = null;


/**
Expand Down Expand Up @@ -88,11 +90,21 @@ define(function( require )
var socket, Socket;
var proxy = Configs.get('socketProxy', null);

// Native socket
// Chrome App
if (Context.Is.APP) {
Socket = ChromeSocket;
}

// Firefox OS App
else if (TCPSocket.isSupported()) {
Socket = TCPSocket;
}

// node-webkit
else if (NodeSocket.isSupported()) {
Socket = NodeSocket;
}

// Web Socket with proxy
else if (proxy) {
Socket = WebSocket;
Expand Down
Loading

0 comments on commit 670ec11

Please sign in to comment.