Skip to content

Commit

Permalink
start the game without the .exe
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanamr committed Dec 22, 2022
1 parent 76bf7a5 commit 92fdfa4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Constants } from "./constants";
import { CdnService } from "./cdnService";
import { Updater } from "./updater";
import { exec } from "child_process";
import { Utils } from "./utils";

export namespace IPC {
export function registerEvents(mainWindow: BrowserWindow) {
Expand Down Expand Up @@ -45,9 +46,12 @@ export namespace IPC {
});

ipcMain.on("launchGame", (_event) => {
const javaArgs = Utils.buildJavaArgs(process.platform);
console.log(`Launching game with args: ${javaArgs}`);

switch (process.platform) {
case "win32":
exec("start DofusArena.exe", { cwd: Constants.GAME_PATH });
exec(`..\\jre\\bin\\java.exe ${javaArgs}`, { cwd: path.join(Constants.GAME_PATH, "game") });
break;
}
});
Expand Down
17 changes: 13 additions & 4 deletions src/main/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,20 @@ export namespace Updater {
}

async function downloadAndSave(fileUrl: string, filePath: string) {
const fileBuf = await got.get(fileUrl).buffer();
if (!fs.existsSync(path.dirname(filePath))) {
fs.mkdirSync(path.dirname(filePath), { recursive: true });
try {
const fileBuf = await got.get(fileUrl).buffer();
if (!fs.existsSync(path.dirname(filePath))) {
fs.mkdirSync(path.dirname(filePath), { recursive: true });
}
fs.writeFileSync(filePath, fileBuf);
} catch (err) {
console.error(err);
dialog.showErrorBox(
"Une erreur est survenue",
"Erreur lors du téléchargement d'un fichier !\nVérifiez votre connexion internet et réessayez.\n\nSi le problème persiste, contactez nous sur Discord."
);
app.quit();
}
fs.writeFileSync(filePath, fileBuf);
}

async function downloadFiles(files: Array<FileManifest>) {
Expand Down
56 changes: 56 additions & 0 deletions src/main/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Constants } from "./constants";
import path from "path";
import fs from "fs";

export namespace Utils {
export const buildJavaArgs = (platform: NodeJS.Platform) => {
const javaArgs: Array<string> = [];

// Library Path
switch (platform) {
case "win32":
javaArgs.push(`-Djava.library.path=..\\natives\\win32\\x86;..\\jre\\bin`);
break;
}

// Game related args
javaArgs.push("-client");

// JVM Args
javaArgs.push("-Xmx384M");
javaArgs.push("-Xms192M");
javaArgs.push("-Dsun.awt.noerasebackground=true");
javaArgs.push("-XX:MaxDirectMemorySize=92m");
javaArgs.push("-XX:+ForceTimeHighResolution");
javaArgs.push("-XX:MinHeapFreeRatio=10");
javaArgs.push("-XX:MaxHeapFreeRatio=20");
javaArgs.push("-Xss256k");

// Classpath
const classPath = [];
const libPath = path.join(Constants.GAME_PATH, "lib");
const libFiles = fs.readdirSync(libPath);
switch (platform) {
case "win32":
classPath.push("core.jar");
libFiles.forEach((file) => {
classPath.push(`..\\lib\\${file}`);
});
javaArgs.push(`-Djava.class.path=${classPath.join(";")}`);
break;
}

// Main class
javaArgs.push("com.ankamagames.dofusarena.client.DofusArenaClient");

// Logs path
switch (platform) {
case "win32":
javaArgs.push("error.log");
javaArgs.push("output.log");
break;
}

return javaArgs.join(" ");
};
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"baseUrl": ".",
"outDir": "dist",
"jsx": "react-jsx",
"target": "es2021",
"moduleResolution": "node",
"resolveJsonModule": true,
"paths": {
Expand Down

0 comments on commit 92fdfa4

Please sign in to comment.