Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decomp: adjust decompiling to use new --version flag #218

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 11 additions & 59 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"publisher": "opengoal",
"version": "0.13.0",
"engines": {
"vscode": "^1.74.0"
"vscode": "^1.76.0"
},
"categories": [
"Programming Languages"
Expand All @@ -30,7 +30,7 @@
"@types/follow-redirects": "^1.14.1",
"@types/glob": "^8.0.1",
"@types/node": "^17.0.45",
"@types/vscode": "^1.74.0",
"@types/vscode": "^1.76.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.53.0",
"eslint": "^8.35.0",
Expand All @@ -45,33 +45,7 @@
"parinfer": "^3.13.1",
"vscode-languageclient": "^8.0.1"
},
"activationEvents": [
"onLanguage:opengoal",
"onLanguage:opengoal-goos",
"onLanguage:opengoal-ir",
"onCommand:opengoal.switchFile",
"onCommand:opengoal.decomp.openManPage",
"onCommand:opengoal.decomp.decompileSpecificFile",
"onCommand:opengoal.decomp.decompileCurrentFile",
"onCommand:opengoal.decomp.toggleAutoDecompilation",
"onCommand:opengoal.decomp.updateSourceFile",
"onCommand:opengoal.decomp.updateReferenceTest",
"onCommand:opengoal.decomp.casts.repeatLast",
"onCommand:opengoal.decomp.casts.labelCastSelection",
"onCommand:opengoal.decomp.casts.stackCastSelection",
"onCommand:opengoal.decomp.casts.typeCastSelection",
"onCommand:opengoal.decomp.misc.addToOffsets",
"onCommand:opengoal.decomp.misc.preserveBlock",
"onCommand:opengoal.decomp.misc.convertHexToDec",
"onCommand:opengoal.decomp.misc.convertDecToHex",
"onCommand:opengoal.decomp.misc.generateTypeFlags",
"onCommand:opengoal.decomp.misc.genTypeFields",
"onCommand:opengoal.decomp.misc.genMethodStubs",
"onCommand:opengoal.decomp.typeSearcher.open",
"onCommand:opengoal.lsp.start",
"onCommand:opengoal.lsp.stop",
"onCommand:opengoal.lsp.restart"
],
"activationEvents": [],
"contributes": {
"commands": [
{
Expand Down Expand Up @@ -230,37 +204,15 @@
"default": null,
"description": "File path to the type searcher executable"
},
"opengoal.decompilerJak1Config": {
"type": [
"string",
"null"
],
"default": null,
"description": "Config to use for decompiling jak 1 related files"
},
"opengoal.decompilerJak2Config": {
"type": [
"string",
"null"
],
"default": null,
"description": "Config to use for decompiling jak 2 related files"
},
"opengoal.decompilerJak1ConfigDirectory": {
"type": [
"string",
"null"
],
"default": null,
"description": "Directory containing cast files to use for decompiling jak 1 related files"
"opengoal.decompilerJak1ConfigVersion": {
"type": "string",
"default": "ntsc_v1",
"description": "Config version to use for decompiling jak 1 related files"
},
"opengoal.decompilerJak2ConfigDirectory": {
"type": [
"string",
"null"
],
"default": null,
"description": "Directory containing cast files to use for decompiling jak 2 related files"
"opengoal.decompilerJak2ConfigVersion": {
"type": "string",
"default": "ntsc_v1",
"description": "Config version to use for decompiling jak 2 related files"
}
}
},
Expand Down
48 changes: 6 additions & 42 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export function getConfig() {
vuManPagePath: configOptions.get<string>("vuManPagePath"),
decompilerPath: configOptions.get<string>("decompilerPath"),
typeSearcherPath: configOptions.get<string>("typeSearcherPath"),
jak1DecompConfig: configOptions.get<string>("decompilerJak1Config"),
jak2DecompConfig: configOptions.get<string>("decompilerJak2Config"),
decompilerJak1ConfigDirectory: configOptions.get<string>(
"decompilerJak1ConfigDirectory"
jak1DecompConfigVersion: configOptions.get<string>(
"decompilerJak1ConfigVersion",
"ntsc_v1"
),
decompilerJak2ConfigDirectory: configOptions.get<string>(
"decompilerJak2ConfigDirectory"
jak2DecompConfigVersion: configOptions.get<string>(
"decompilerJak2ConfigVersion",
"ntsc_v1"
),
colorsGoalGlobals: configOptions.get<string>("colors.goal.entity.global"),
colorsGoalStorageControl: configOptions.get<string>(
Expand Down Expand Up @@ -85,42 +85,6 @@ export async function updateTypeSearcherPath(path: string) {
);
}

export async function updateJak1DecompConfig(config: string) {
const userConfig = vscode.workspace.getConfiguration();
await userConfig.update(
"opengoal.decompilerJak1Config",
config,
vscode.ConfigurationTarget.Global
);
}

export async function updateJak2DecompConfig(config: string) {
const userConfig = vscode.workspace.getConfiguration();
await userConfig.update(
"opengoal.decompilerJak2Config",
config,
vscode.ConfigurationTarget.Global
);
}

export async function updateJak1DecompConfigDirectory(dir: string) {
const userConfig = vscode.workspace.getConfiguration();
await userConfig.update(
"opengoal.decompilerJak1ConfigDirectory",
dir,
vscode.ConfigurationTarget.Global
);
}

export async function updateJak2DecompConfigDirectory(dir: string) {
const userConfig = vscode.workspace.getConfiguration();
await userConfig.update(
"opengoal.decompilerJak2ConfigDirectory",
dir,
vscode.ConfigurationTarget.Global
);
}

export async function updateOpengoalParinferMode(mode: string) {
const userConfig = vscode.workspace.getConfiguration();
await userConfig.update(
Expand Down
146 changes: 56 additions & 90 deletions src/decomp/decomp-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import * as vscode from "vscode";
import { determineGameFromPath, GameName } from "../utils/file-utils";
import { open_in_pdf } from "./man-page";
import * as util from "util";
import {
getConfig,
updateDecompilerPath,
updateJak1DecompConfig,
updateJak2DecompConfig,
} from "../config/config";
import { getConfig, updateDecompilerPath } from "../config/config";
import * as path from "path";
import * as glob from "glob";
import { getExtensionContext, getProjectRoot } from "../context";
Expand Down Expand Up @@ -86,70 +81,38 @@ function defaultDecompPath() {
}
}

async function promptUserToSelectConfig(
projectRoot: vscode.Uri
): Promise<string | undefined> {
// Get all `.jsonc` files in ./decompiler/config
const configs = await globAsync("decompiler/config/*.jsonc", {
cwd: projectRoot.fsPath,
});
const options = [];
for (const config of configs) {
options.push(path.basename(config));
function getDecompilerConfig(gameName: GameName): string | undefined {
let decompConfigPath = undefined;
if (gameName == GameName.Jak1) {
decompConfigPath = vscode.Uri.joinPath(
getProjectRoot(),
`decompiler/config/jak1/jak1_config.jsonc`
).fsPath;
} else if (gameName == GameName.Jak2) {
decompConfigPath = vscode.Uri.joinPath(
getProjectRoot(),
`decompiler/config/jak2/jak2_config.jsonc`
).fsPath;
}
if (decompConfigPath === undefined || !existsSync(decompConfigPath)) {
return undefined;
} else {
return decompConfigPath;
}
return await vscode.window.showQuickPick(options, {
title: "Config?",
});
}

async function getDecompilerConfig(
gameName: GameName
): Promise<string | undefined> {
const config = getConfig();
function getDecompilerConfigVersion(gameName: GameName): string {
let version = undefined;
if (gameName == GameName.Jak1) {
const decompConfig = config.jak1DecompConfig;
if (
decompConfig === undefined ||
!existsSync(
vscode.Uri.joinPath(
getProjectRoot(),
`decompiler/config/${decompConfig}`
).fsPath
)
) {
const config = await promptUserToSelectConfig(getProjectRoot());
if (config === undefined) {
return;
} else {
updateJak1DecompConfig(config);
return config;
}
} else {
return decompConfig;
}
version = getConfig().jak1DecompConfigVersion;
} else if (gameName == GameName.Jak2) {
const decompConfig = config.jak2DecompConfig;
if (
decompConfig === undefined ||
!existsSync(
vscode.Uri.joinPath(
getProjectRoot(),
`decompiler/config/${decompConfig}`
).fsPath
)
) {
const config = await promptUserToSelectConfig(getProjectRoot());
if (config === undefined) {
return;
} else {
updateJak2DecompConfig(config);
return config;
}
} else {
return decompConfig;
}
version = getConfig().jak2DecompConfigVersion;
}
if (version === undefined) {
return "ntsc_v1";
} else {
return version;
}
return undefined;
}

async function checkDecompilerPath(): Promise<string | undefined> {
Expand Down Expand Up @@ -185,7 +148,11 @@ async function checkDecompilerPath(): Promise<string | undefined> {
return decompilerPath;
}

async function decompFiles(decompConfig: string, fileNames: string[]) {
async function decompFiles(
decompConfig: string,
gameName: GameName,
fileNames: string[]
) {
if (fileNames.length == 0) {
return;
}
Expand All @@ -197,24 +164,23 @@ async function decompFiles(decompConfig: string, fileNames: string[]) {
const allowed_objects = fileNames.map((name) => `"${name}"`).join(",");
updateStatus(DecompStatus.Running, {
objectNames: fileNames,
decompConfig: decompConfig,
decompConfig: path.parse(decompConfig).name,
});
try {
const { stdout, stderr } = await execFileAsync(
decompilerPath,
[
`./decompiler/config/${decompConfig}`,
"./iso_data",
"./decompiler_out",
"--config-override",
`{"decompile_code": true, "levels_extract": false, "allowed_objects": [${allowed_objects}]}`,
],
{
encoding: "utf8",
cwd: getProjectRoot()?.fsPath,
timeout: 20000,
}
);
const args = [
decompConfig,
"./iso_data",
"./decompiler_out",
"--version",
getDecompilerConfigVersion(gameName),
"--config-override",
`{"decompile_code": true, "levels_extract": false, "allowed_objects": [${allowed_objects}]}`,
];
const { stdout, stderr } = await execFileAsync(decompilerPath, args, {
encoding: "utf8",
cwd: getProjectRoot()?.fsPath,
timeout: 20000,
});
channel.append(stdout.toString());
channel.append(stderr.toString());
updateStatus(DecompStatus.Idle);
Expand Down Expand Up @@ -292,15 +258,15 @@ async function decompSpecificFile() {
}

// Determine what decomp config to use
const decompConfig = await getDecompilerConfig(gameName);
const decompConfig = getDecompilerConfig(gameName);
if (decompConfig === undefined) {
await vscode.window.showErrorMessage(
`OpenGOAL - Can't decompile no ${gameName.toString} config selected`
);
return;
}

await decompFiles(decompConfig, [fileName]);
await decompFiles(decompConfig, gameName, [fileName]);
}

async function decompCurrentFile() {
Expand All @@ -323,22 +289,22 @@ async function decompCurrentFile() {
}

// Determine what decomp config to use
const gameName = await determineGameFromPath(editor.document.uri);
const gameName = determineGameFromPath(editor.document.uri);
if (gameName === undefined) {
await vscode.window.showErrorMessage(
"OpenGOAL - Can't decompile, couldn't determine game from file"
);
return;
}
const decompConfig = await getDecompilerConfig(gameName);
const decompConfig = getDecompilerConfig(gameName);
if (decompConfig === undefined) {
await vscode.window.showErrorMessage(
`OpenGOAL - Can't decompile no ${gameName.toString} config selected`
);
return;
}

await decompFiles(decompConfig, [fileName]);
await decompFiles(decompConfig, gameName, [fileName]);
}

async function decompAllActiveFiles() {
Expand All @@ -352,25 +318,25 @@ async function decompAllActiveFiles() {
);

if (jak1ObjectNames.length > 0) {
const jak1Config = await getDecompilerConfig(GameName.Jak1);
const jak1Config = getDecompilerConfig(GameName.Jak1);
if (jak1Config === undefined) {
await vscode.window.showErrorMessage(
"OpenGOAL - Can't decompile no Jak 1 config selected"
);
return;
}
await decompFiles(jak1Config, jak1ObjectNames);
await decompFiles(jak1Config, GameName.Jak1, jak1ObjectNames);
}

if (jak2ObjectNames.length > 0) {
const jak2Config = await getDecompilerConfig(GameName.Jak2);
const jak2Config = getDecompilerConfig(GameName.Jak2);
if (jak2Config === undefined) {
await vscode.window.showErrorMessage(
"OpenGOAL - Can't decompile no Jak 2 config selected"
);
return;
}
await decompFiles(jak2Config, jak2ObjectNames);
await decompFiles(jak2Config, GameName.Jak2, jak2ObjectNames);
}
}

Expand Down
Loading