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: provide a list of valid object names when decomping #79

Merged
merged 1 commit into from
Sep 3, 2022
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
48 changes: 45 additions & 3 deletions src/decomp/decomp-tools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exec, execFile } from "child_process";
import { existsSync, promises as fs } from "fs";
import { existsSync, promises as fs, readFileSync } from "fs";
import * as vscode from "vscode";
import { determineGameFromPath, GameName, openFile } from "../utils/file-utils";
import { open_in_pdf } from "./man-page";
Expand Down Expand Up @@ -237,6 +237,39 @@ async function decompFiles(decompConfig: string, fileNames: string[]) {
updateStatus(DecompStatus.Idle);
}

async function getValidObjectNames(gameName: string) {
if (projectRoot === undefined) {
projectRoot = getWorkspaceFolderByName("jak-project");
if (projectRoot === undefined) {
return undefined;
}
}

// Look for the `all_objs.json` file
const objsPath = path.join(
projectRoot.fsPath,
"goal_src",
gameName,
"build",
"all_objs.json"
);
if (!existsSync(objsPath)) {
return undefined;
}
const objsData = await fs.readFile(objsPath, {
encoding: "utf-8",
});
const objs = JSON.parse(objsData);
const names = [];
for (const obj of objs) {
if (obj[2] != 3) {
continue;
}
names.push(obj[0]);
}
return names;
}

async function decompSpecificFile() {
// Prompt the user for the game name
let gameName;
Expand All @@ -258,8 +291,17 @@ async function decompSpecificFile() {
gameName = GameName.Jak2;
}
}
// Prompt the user for the file name
const fileName = await vscode.window.showInputBox({ title: "Object Name?" });
const validNames = await getValidObjectNames(gameNameSelection);
let fileName;
if (validNames === undefined || validNames.length <= 0) {
// Prompt the user for the file name
fileName = await vscode.window.showInputBox({ title: "Object Name?" });
} else {
fileName = await vscode.window.showQuickPick(validNames, {
title: "File to Decompile?",
});
}

if (fileName === undefined) {
await vscode.window.showErrorMessage(
"OpenGOAL - can't decompile, didn't provide an object name"
Expand Down
13 changes: 1 addition & 12 deletions src/decomp/type-caster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,8 @@
import { getExtensionContext } from "../context";
import * as vscode from "vscode";
import { basename, join } from "path";
import { getWorkspaceFolderByName } from "../utils/workspace";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { readFileSync, writeFileSync } from "fs";
import { parse, stringify } from "comment-json";
import {
getConfig,
updateJak1DecompConfigDirectory,
updateJak2DecompConfigDirectory,
} from "../config/config";
import {
determineGameFromPath,
GameName,
getDirectoriesInDir,
} from "../utils/file-utils";
import { getDecompilerConfigDirectory } from "../utils/decomp-tools";

enum CastKind {
Expand Down