Skip to content

Commit

Permalink
more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Feb 13, 2020
1 parent 3069fe1 commit de55e31
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
20 changes: 14 additions & 6 deletions WebVersion/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ function patch(view, fileNumber) {
var version = readString(view.buffer, 0x00, 0x06);
var validVersions = ["G8MJ01" /* JP */, "G8ME01" /* US */, "G8MP01" /* EU */];
if (!validVersions.includes(version))
return 1 /* InvalidSaveFile */;
return 2 /* WrongSaveFileGameID */;
var internalFilename = readString(view.buffer, 0x08, 0x11);
if (internalFilename !== 'mariost_save_file')
return 1 /* InvalidSaveFile */;
return 3 /* WrongSaveFileInternalName */;
if (fileNumber < 1 || fileNumber > 4)
return 2 /* InvalidFileNumber */;
return 4 /* InvalidFileNumber */;
var offsetFile0 = ((fileNumber - 1) * 0x4000) + 0x2040;
var offsetFile1 = offsetFile0 + 0x10000;
function patchFilesU16(offset, value) {
Expand Down Expand Up @@ -122,11 +122,19 @@ function displayResult(e) {
errorMessage.textContent = '';
return true;
}
else if (e === 1 /* InvalidSaveFile */) {
else if (e === 1 /* NotSaveFile */) {
errorMessage.textContent = 'The file you specified was not a valid .gci save file';
return false;
}
else if (e === 2 /* InvalidFileNumber */) {
else if (e === 2 /* WrongSaveFileGameID */) {
errorMessage.textContent = 'This save file is not for Paper Mario: The Thousand Year Door';
return false;
}
else if (e === 3 /* WrongSaveFileInternalName */) {
errorMessage.textContent = 'This save file has the wrong internal ID. Please make sure you are using a normal Paper Mario: The Thousand Year Door save file.';
return false;
}
else if (e === 4 /* InvalidFileNumber */) {
// should not happen
throw "whoops";
}
Expand All @@ -135,7 +143,7 @@ function fileSubmitted() {
var input = document.querySelector('input#fileupload');
var file = input.files[0];
if (!file.name.endsWith('.gci')) {
if (!displayResult(1 /* InvalidSaveFile */))
if (!displayResult(1 /* NotSaveFile */))
return;
}
var fileNumberInput = document.querySelector('select#filenumber');
Expand Down
18 changes: 13 additions & 5 deletions WebVersion/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function decodeBinaryData(S: string): ArrayBuffer {

const enum PatchErrorCode {
Success,
InvalidSaveFile,
NotSaveFile,
WrongSaveFileGameID,
WrongSaveFileInternalName,
InvalidFileNumber,
}

Expand All @@ -51,11 +53,11 @@ function patch(view: DataView, fileNumber: number): PatchErrorCode {

const validVersions = [GameVersion.JP, GameVersion.US, GameVersion.EU];
if (!validVersions.includes(version))
return PatchErrorCode.InvalidSaveFile;
return PatchErrorCode.WrongSaveFileGameID;

const internalFilename = readString(view.buffer, 0x08, 0x11);
if (internalFilename !== 'mariost_save_file')
return PatchErrorCode.InvalidSaveFile;
return PatchErrorCode.WrongSaveFileInternalName;

if (fileNumber < 1 || fileNumber > 4)
return PatchErrorCode.InvalidFileNumber;
Expand Down Expand Up @@ -153,9 +155,15 @@ function displayResult(e: PatchErrorCode): boolean {
if (e === PatchErrorCode.Success) {
errorMessage.textContent = '';
return true;
} else if (e === PatchErrorCode.InvalidSaveFile) {
} else if (e === PatchErrorCode.NotSaveFile) {
errorMessage.textContent = 'The file you specified was not a valid .gci save file';
return false;
} else if (e === PatchErrorCode.WrongSaveFileGameID) {
errorMessage.textContent = 'This save file is not for Paper Mario: The Thousand Year Door';
return false;
} else if (e === PatchErrorCode.WrongSaveFileInternalName) {
errorMessage.textContent = 'This save file has the wrong internal ID. Please make sure you are using a normal Paper Mario: The Thousand Year Door save file.';
return false;
} else if (e === PatchErrorCode.InvalidFileNumber) {
// should not happen
throw "whoops";
Expand All @@ -167,7 +175,7 @@ function fileSubmitted(): void {
const file = input.files[0];

if (!file.name.endsWith('.gci')) {
if (!displayResult(PatchErrorCode.InvalidSaveFile))
if (!displayResult(PatchErrorCode.NotSaveFile))
return;
}

Expand Down

0 comments on commit de55e31

Please sign in to comment.