Consistency pass and small tweaks

**Formatting going forward**
Variables: camelCase (capitalization of two letter abbreviations is OK, e.g. playerID)
Classes: PascalCase
CSS: kebab-case
Files: kebab-case

**Other miscellaneous changes**
* The WebPlayer crashing as well as failing to load the config file are now fatal  errors and will quit the app
* Moved some style attributes from index.html into openfusion.css
This commit is contained in:
CakeLancelot 2023-09-03 04:56:24 -05:00
parent 7131026b2f
commit 043bf219e7
12 changed files with 145 additions and 137 deletions

View File

@ -47,6 +47,11 @@ img {
}
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
clear: both;
user-select: none;
background-color: #000;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
@ -129,3 +134,12 @@ button > i {
#server-table .server-listing-entry {
cursor: pointer;
}
#client {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background: #000;
clear: both;
}

View File

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

Before

Width:  |  Height:  |  Size: 176 B

After

Width:  |  Height:  |  Size: 176 B

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -5,7 +5,7 @@ var gameRunning = false;
// Uncomment and enter credentials to skip login screen
function authDoCallback(param) {
/*var unity = document.getElementById('Unity_embed');
/*var unity = document.getElementById('unityEmbed');
unity.SendMessage("GlobalManager", "SetTEGid", "player");
unity.SendMessage("GlobalManager", "SetAuthid", "0");
unity.SendMessage("GlobalManager", "DoAuth", 0);*/
@ -33,7 +33,7 @@ function PayPage(param) {
function onResize() {
if (gameRunning == true) {
var unity = document.getElementById("Unity_embed");
var unity = document.getElementById("unityEmbed");
unity.style.width = window.innerWidth + "px";
unity.style.height = window.innerHeight + "px";
}
@ -56,7 +56,7 @@ function launchGame() {
"codebase",
"undefined/UnityWebPlayer.cab#version=2,0,0,0"
);
object.setAttribute("id", "Unity_object");
object.setAttribute("id", "unityObject");
object.setAttribute("width", "1264");
object.setAttribute("height", "661");
@ -66,20 +66,19 @@ function launchGame() {
"pluginspage",
"http://www.unity3d.com/unity-web-player-2.x"
);
embed.setAttribute("id", "Unity_embed");
embed.setAttribute("id", "unityEmbed");
embed.setAttribute("width", "1280");
embed.setAttribute("height", "680");
embed.setAttribute("src", window.asseturl + "main.unity3d");
embed.setAttribute("disablecontdparaextmenu", "true");
embed.setAttribute("src", window.assetUrl + "main.unity3d");
embed.setAttribute("bordercolor", "000000");
embed.setAttribute("backgroundcolor", "000000");
embed.setAttribute("disableContextMenu", true);
embed.setAttribute("textcolor", "ccffff");
embed.setAttribute("logoimage", "assets/img/unity_dexlabs.png");
embed.setAttribute("progressbarimage", "assets/img/unity_loadingbar.png");
embed.setAttribute("logoimage", "assets/img/unity-dexlabs.png");
embed.setAttribute("progressbarimage", "assets/img/unity-loadingbar.png");
embed.setAttribute(
"progressframeimage",
"assets/img/unity_loadingframe.png"
"assets/img/unity-loadingframe.png"
);
embed.setAttribute(
"autoupdateurlsignature",

View File

@ -2,9 +2,9 @@ var remote = require("remote");
var remotefs = remote.require("fs-extra");
var dns = remote.require("dns");
var userdir = remote.require("app").getPath("userData");
var versionarray;
var serverarray;
var userDir = remote.require("app").getPath("userData");
var versionArray;
var serverArray;
var config;
function enableServerListButtons() {
@ -26,14 +26,14 @@ function disableServerListButtons() {
}
function getAppVersion() {
appversion = remote.require("app").getVersion();
appVersion = remote.require("app").getVersion();
// simplify version, ex. 1.4.0 -> 1.4,
// but only if a revision number isn't present
if (appversion.endsWith(".0")) {
return appversion.substr(0, appversion.length - 2);
if (appVersion.endsWith(".0")) {
return appVersion.substr(0, appVersion.length - 2);
} else {
return appversion;
return appVersion;
}
}
@ -43,8 +43,8 @@ function setAppVersionText() {
}
function addServer() {
var jsontomodify = JSON.parse(
remotefs.readFileSync(userdir + "\\servers.json")
var jsonToModify = JSON.parse(
remotefs.readFileSync(userDir + "\\servers.json")
);
var server = {};
@ -60,20 +60,20 @@ function addServer() {
server["version"] = $("#addserver-versionselect option:selected").text();
//server['endpoint'] =
jsontomodify["servers"].push(server);
jsonToModify["servers"].push(server);
remotefs.writeFileSync(
userdir + "\\servers.json",
JSON.stringify(jsontomodify, null, 4)
userDir + "\\servers.json",
JSON.stringify(jsonToModify, null, 4)
);
loadServerList();
}
function editServer() {
var jsontomodify = JSON.parse(
remotefs.readFileSync(userdir + "\\servers.json")
var jsonToModify = JSON.parse(
remotefs.readFileSync(userDir + "\\servers.json")
);
$.each(jsontomodify["servers"], function (key, value) {
$.each(jsonToModify["servers"], function (key, value) {
if (value["uuid"] == getSelectedServer()) {
value["description"] =
$("#editserver-descinput").val().length == 0
@ -90,27 +90,27 @@ function editServer() {
});
remotefs.writeFileSync(
userdir + "\\servers.json",
JSON.stringify(jsontomodify, null, 4)
userDir + "\\servers.json",
JSON.stringify(jsonToModify, null, 4)
);
loadServerList();
}
function deleteServer() {
var jsontomodify = JSON.parse(
remotefs.readFileSync(userdir + "\\servers.json")
var jsonToModify = JSON.parse(
remotefs.readFileSync(userDir + "\\servers.json")
);
var result = jsontomodify["servers"].filter(function (obj) {
var result = jsonToModify["servers"].filter(function (obj) {
return obj.uuid === getSelectedServer();
})[0];
var resultindex = jsontomodify["servers"].indexOf(result);
var resultindex = jsonToModify["servers"].indexOf(result);
jsontomodify["servers"].splice(resultindex, 1);
jsonToModify["servers"].splice(resultindex, 1);
remotefs.writeFileSync(
userdir + "\\servers.json",
JSON.stringify(jsontomodify, null, 4)
userDir + "\\servers.json",
JSON.stringify(jsonToModify, null, 4)
);
loadServerList();
}
@ -118,17 +118,17 @@ function deleteServer() {
function restoreDefaultServers() {
remotefs.copySync(
__dirname + "\\defaults\\servers.json",
userdir + "\\servers.json"
userDir + "\\servers.json"
);
loadServerList();
}
function loadGameVersions() {
var versionjson = JSON.parse(
remotefs.readFileSync(userdir + "\\versions.json")
var versionJson = JSON.parse(
remotefs.readFileSync(userDir + "\\versions.json")
);
versionarray = versionjson["versions"];
$.each(versionarray, function (key, value) {
versionArray = versionJson["versions"];
$.each(versionArray, function (key, value) {
$(new Option(value.name, "val")).appendTo("#addserver-versionselect");
$(new Option(value.name, "val")).appendTo("#editserver-versionselect");
});
@ -136,22 +136,22 @@ function loadGameVersions() {
function loadConfig() {
// load config object globally
config = JSON.parse(remotefs.readFileSync(userdir + "\\config.json"));
config = JSON.parse(remotefs.readFileSync(userDir + "\\config.json"));
}
function loadServerList() {
var serverjson = JSON.parse(
remotefs.readFileSync(userdir + "\\servers.json")
var serverJson = JSON.parse(
remotefs.readFileSync(userDir + "\\servers.json")
);
serverarray = serverjson["servers"];
serverArray = serverJson["servers"];
$(".server-listing-entry").remove(); // Clear out old stuff, if any
disableServerListButtons(); // Disable buttons until another server is selected
if (serverarray.length > 0) {
if (serverArray.length > 0) {
// Servers were found in the JSON
$("#server-listing-placeholder").attr("hidden", true);
$.each(serverarray, function (key, value) {
$.each(serverArray, function (key, value) {
// Create the row, and populate the cells
var row = document.createElement("tr");
row.className = "server-listing-entry";
@ -172,25 +172,25 @@ function loadServerList() {
}
}
function performCacheSwap(newversion) {
var cacheroot = userdir + "\\..\\..\\LocalLow\\Unity\\Web Player\\Cache";
var currentcache = cacheroot + "\\Fusionfall";
var newcache = cacheroot + "\\" + newversion;
var record = userdir + "\\.lastver";
function performCacheSwap(newVersion) {
var cacheRoot = userDir + "\\..\\..\\LocalLow\\Unity\\Web Player\\Cache";
var currentCache = cacheRoot + "\\Fusionfall";
var newCache = cacheRoot + "\\" + newVersion;
var record = userDir + "\\.lastver";
// if cache renaming would result in a no-op (ex. launching the same version
// two times), then skip it. this avoids permissions errors with multiple clients
// (file/folder is already open in another process)
var skip = false;
if (remotefs.existsSync(currentcache)) {
if (remotefs.existsSync(currentCache)) {
// cache already exists, find out what version it belongs to
if (remotefs.existsSync(record)) {
lastversion = remotefs.readFileSync(record);
if (lastversion != newversion) {
lastVersion = remotefs.readFileSync(record);
if (lastVersion != newVersion) {
remotefs.renameSync(
currentcache,
cacheroot + "\\" + lastversion
currentCache,
cacheRoot + "\\" + lastVersion
);
} else {
console.log(
@ -198,7 +198,7 @@ function performCacheSwap(newversion) {
);
skip = true;
}
console.log("Current cache is " + lastversion);
console.log("Current cache is " + lastVersion);
} else {
console.log(
"Couldn't find last version record; cache may get overwritten"
@ -206,29 +206,29 @@ function performCacheSwap(newversion) {
}
}
if (remotefs.existsSync(newcache) || !skip) {
if (remotefs.existsSync(newCache) || !skip) {
// rename saved cache to FusionFall
remotefs.renameSync(newcache, currentcache);
console.log("Current cache swapped to " + newversion);
remotefs.renameSync(newCache, currentCache);
console.log("Current cache swapped to " + newVersion);
}
// make note of what version we are launching for next launch
remotefs.writeFileSync(record, newversion);
remotefs.writeFileSync(record, newVersion);
}
// For writing loginInfo.php, assetInfo.php, etc.
function setGameInfo(serverUUID) {
var result = serverarray.filter(function (obj) {
var result = serverArray.filter(function (obj) {
return obj.uuid === serverUUID;
})[0];
var gameversion = versionarray.filter(function (obj) {
var gameVersion = versionArray.filter(function (obj) {
return obj.name === result.version;
})[0];
// if cache swapping property exists AND is `true`, run cache swapping logic
if (config["cache-swapping"]) {
try {
performCacheSwap(gameversion.name);
performCacheSwap(gameVersion.name);
} catch (ex) {
console.log(
"Error when swapping cache, it may get overwritten:\n" + ex
@ -236,23 +236,23 @@ function setGameInfo(serverUUID) {
}
}
window.asseturl = gameversion.url; // gameclient.js needs to access this
window.assetUrl = gameVersion.url; // game-client.js needs to access this
remotefs.writeFileSync(__dirname + "\\assetInfo.php", asseturl);
remotefs.writeFileSync(__dirname + "\\assetInfo.php", assetUrl);
if (result.hasOwnProperty("endpoint")) {
var httpendpoint = result.endpoint.replace("https://", "http://");
var httpEndpoint = result.endpoint.replace("https://", "http://");
remotefs.writeFileSync(
__dirname + "\\rankurl.txt",
httpendpoint + "getranks"
httpEndpoint + "getranks"
);
// Write these out too
remotefs.writeFileSync(
__dirname + "\\sponsor.php",
httpendpoint + "upsell/sponsor.png"
httpEndpoint + "upsell/sponsor.png"
);
remotefs.writeFileSync(
__dirname + "\\images.php",
httpendpoint + "upsell/"
httpEndpoint + "upsell/"
);
} else {
// Remove/default the endpoint related stuff, this server won't be using it
@ -341,10 +341,10 @@ $("#server-table").on("dblclick", ".server-listing-entry", function (event) {
});
$("#of-editservermodal").on("show.bs.modal", function (e) {
var jsontomodify = JSON.parse(
remotefs.readFileSync(userdir + "\\servers.json")
var jsonToModify = JSON.parse(
remotefs.readFileSync(userDir + "\\servers.json")
);
$.each(jsontomodify["servers"], function (key, value) {
$.each(jsonToModify["servers"], function (key, value) {
if (value["uuid"] == getSelectedServer()) {
$("#editserver-descinput")[0].value = value["description"];
$("#editserver-ipinput")[0].value = value["ip"];
@ -361,7 +361,7 @@ $("#of-editservermodal").on("show.bs.modal", function (e) {
});
$("#of-deleteservermodal").on("show.bs.modal", function (e) {
var result = serverarray.filter(function (obj) {
var result = serverArray.filter(function (obj) {
return obj.uuid === getSelectedServer();
})[0];
$("#deleteserver-servername").html(result.description);

View File

@ -1,16 +1,16 @@
const fs = require('fs');
const defaultdir = './dist/win-ia32-unpacked/resources/default_app'
const exefile = './dist/win-ia32-unpacked/OpenFusionClient.exe'
const defaultDir = './dist/win-ia32-unpacked/resources/default_app'
const exeFile = './dist/win-ia32-unpacked/OpenFusionClient.exe'
exports.default = function() {
// remove leftover files from default electron app
fs.rm(defaultdir, { recursive: true }, (err) => {
fs.rm(defaultDir, { recursive: true }, (err) => {
if (err) {
throw err;
}
});
// patch executable for large address awareness
fs.open(exefile, "r+", (err, fd) => {
fs.open(exeFile, "r+", (err, fd) => {
if(!err) {
fs.write(
fd, new Uint8Array([0x22]), 0, 1, 0x166,

View File

@ -2,10 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, shrink-to-fit=no"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OpenFusion: Server Selector</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/fonts/fontawesome-all.min.css" />
@ -13,17 +10,7 @@
<link rel="stylesheet" href="assets/css/styles.css" />
</head>
<body
style="
background: rgb(0, 0, 0);
width: 100%;
height: 100%;
margin: 0;
padding: 0;
clear: both;
"
onresize="onResize()"
>
<body onresize="onResize()">
<section id="of-serverselector">
<div class="container" id="serverselector-container">
<div class="row text-center mt-3" id="of-logoheader">
@ -464,17 +451,7 @@
</div>
</section>
<section>
<div
id="client"
style="
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background: #000;
clear: both;
"
></div>
<div id="client"></div>
</section>
<script
src="assets/js/jquery.min.js"
@ -483,9 +460,9 @@
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/bs-init.js"></script>
<script src="assets/js/uuidv4.min.js"></script>
<script src="assets/js/serverselector.js"></script>
<script src="assets/js/gameclient.js"></script>
<script src="assets/js/server-selector.js"></script>
<script src="assets/js/game-client.js"></script>
<script src="assets/js/snowflakes.min.js"></script>
<script src="assets/js/eastereggs.js"></script>
<script src="assets/js/easter-eggs.js"></script>
</body>
</html>

View File

@ -7,46 +7,55 @@ var BrowserWindow = require("browser-window");
var mainWindow = null;
app.commandLine.appendSwitch("--enable-npapi");
app.commandLine.appendSwitch("enable-npapi");
function verifyUnity() {
var dllpath =
app.getPath("appData") +
"\\..\\LocalLow\\Unity\\WebPlayer\\player\\fusion-2.x.x\\webplayer_win.dll";
if (fs.existsSync(dllpath)) {
var buff = fs.readFileSync(dllpath);
var hash = require("crypto")
function verifyMD5Hash(file, hash) {
if (fs.existsSync(file)) {
var buffer = fs.readFileSync(file);
var computedHash = require("crypto")
.createHash("md5")
.update(buff)
.update(buffer)
.digest("hex");
if (hash == "e5028405b4483de9e5e5fe9cd5f1e98f") {
if (hash == computedHash) {
return true;
}
}
return false;
}
function verifyUnity() {
var loaderPath =
app.getPath("appData") +
"\\..\\LocalLow\\Unity\\WebPlayer\\loader\\npUnity3D32.dll";
var playerPath =
app.getPath("appData") +
"\\..\\LocalLow\\Unity\\WebPlayer\\player\\fusion-2.x.x\\webplayer_win.dll";
return (
verifyMD5Hash(loaderPath, "dbbac62d8379d2d870479b04b8157b99") &&
verifyMD5Hash(playerPath, "e5028405b4483de9e5e5fe9cd5f1e98f")
);
}
function installUnity(callback) {
var utilsdir = __dirname + "\\..\\..\\utils";
var utilsDir = __dirname + "\\..\\..\\utils";
// if running in non-packaged / development mode, this dir will be slightly different
if (process.env.npm_node_execpath) {
utilsdir = app.getAppPath() + "\\build\\utils";
utilsDir = app.getAppPath() + "\\build\\utils";
}
// run the installer silently
var child = require("child_process").spawn(
utilsdir + "\\UnityWebPlayer.exe",
utilsDir + "\\UnityWebPlayer.exe",
["/quiet", "/S"]
);
child.on("exit", function () {
// overwrite 3.5.2 loader/player with FF's custom version
var dstfolder =
app.getPath("appData") + "\\..\\LocalLow\\Unity\\WebPlayer";
fs.copySync(utilsdir + "\\WebPlayer", dstfolder, { clobber: true });
var dest = app.getPath("appData") + "\\..\\LocalLow\\Unity\\WebPlayer";
fs.copySync(utilsDir + "\\WebPlayer", dest, { clobber: true });
// avoids error reporter popping up when closing Electron
fs.removeSync(dstfolder + "\\UnityBugReporter.exe");
fs.removeSync(dest + "\\UnityBugReporter.exe");
console.log("Unity Web Player installed successfully.");
callback();
});
@ -61,7 +70,7 @@ function initialSetup(firstTime) {
center: true,
frame: false,
});
setupWindow.loadUrl("file://" + __dirname + "/initialsetup.html");
setupWindow.loadUrl("file://" + __dirname + "/initial-setup.html");
installUnity(function () {
if (!firstTime) {
// migration from pre-1.4
@ -114,12 +123,12 @@ app.on("window-all-closed", function () {
app.on("ready", function () {
// Check just in case the user forgot to extract the zip.
zip_check = app.getPath("exe").includes(os.tmpdir());
if (zip_check) {
errormsg =
zipCheck = app.getPath("exe").includes(os.tmpdir());
if (zipCheck) {
var errorMessage =
"It has been detected that OpenFusionClient is running from the TEMP folder.\n\n" +
"Please extract the entire Client folder to a location of your choice before starting OpenFusionClient.";
dialog.showErrorBox("Error!", errormsg);
dialog.showErrorBox("Error!", errorMessage);
return;
}
@ -152,12 +161,16 @@ app.on("ready", function () {
}
}
} catch (ex) {
console.log("An error occurred while checking for the config");
dialog.showErrorBox(
"Error!",
"An error occurred while checking for the config. Make sure you have sufficent permissions."
);
app.quit();
}
// Makes it so external links are opened in the system browser, not Electron
mainWindow.webContents.on("new-window", function (e, url) {
e.preventDefault();
mainWindow.webContents.on("new-window", function (event, url) {
event.preventDefault();
require("shell").openExternal(url);
});
@ -181,19 +194,24 @@ function showMainWindow() {
});
mainWindow.webContents.on("plugin-crashed", function () {
console.log("Unity Web Player crashed.");
var errorMessage =
"Unity Web Player has crashed - please re-open the application.\n" +
"If this error persists, please read the FAQ or ask for support in our Discord server.";
dialog.showErrorBox("Error!", errorMessage);
mainWindow.destroy();
app.quit();
});
mainWindow.webContents.on("will-navigate", function (evt, url) {
evt.preventDefault();
mainWindow.webContents.on("will-navigate", function (event, url) {
event.preventDefault();
// TODO: showMessageBox rather than showErrorBox?
switch (url) {
case "https://audience.fusionfall.com/ff/regWizard.do?_flowId=fusionfall-registration-flow":
errormsg =
var errorMessage =
"The register page is currently unimplemented.\n\n" +
'You can still create an account: type your desired username and password into the provided boxes and click "Log In". ' +
"Your account will then be automatically created on the server. \nBe sure to remember these details!";
dialog.showErrorBox("Sorry!", errormsg);
dialog.showErrorBox("Sorry!", errorMessage);
break;
case "https://audience.fusionfall.com/ff/login.do":
dialog.showErrorBox(

View File

@ -67,7 +67,7 @@
"to": "utils"
}
],
"afterPack": "./build/afterpack.js"
"afterPack": "./build/after-pack.js"
},
"dependencies": {
"fs-extra": "2.0.0"