Add warning for unknown opcodes
This commit is contained in:
parent
ead87c78e7
commit
59d8674e93
|
@ -1,6 +1,7 @@
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <filesystem>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
@ -2516,12 +2517,6 @@ void checkScriptsOpcodes()
|
||||||
|
|
||||||
std::map<opcode_t, std::set<std::string>> unknown_opcodes;
|
std::map<opcode_t, std::set<std::string>> unknown_opcodes;
|
||||||
|
|
||||||
// char path[COMPAT_MAX_PATH] = { 0 };
|
|
||||||
// strcpy(path, _cd_path_base);
|
|
||||||
// strcat(path, gScriptsBasePath);
|
|
||||||
// strcat(path, filename);
|
|
||||||
// strcat(path, ".int");
|
|
||||||
|
|
||||||
auto check_file = [&unknown_opcodes](std::string fName) {
|
auto check_file = [&unknown_opcodes](std::string fName) {
|
||||||
File* stream = fileOpen(fName.c_str(), "rb");
|
File* stream = fileOpen(fName.c_str(), "rb");
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
|
@ -2537,12 +2532,12 @@ void checkScriptsOpcodes()
|
||||||
fileClose(stream);
|
fileClose(stream);
|
||||||
|
|
||||||
{
|
{
|
||||||
auto check_data = [&fName, &unknown_opcodes](unsigned char* data, size_t len) {
|
auto check_data = [&fName, &unknown_opcodes](unsigned char* data, size_t start_pos, size_t max_len) {
|
||||||
size_t i = 0;
|
size_t i = start_pos;
|
||||||
while (i < len) {
|
while (i < max_len) {
|
||||||
opcode_t opcode = stackReadInt16(data, i);
|
opcode_t opcode = stackReadInt16(data, i);
|
||||||
if (!((opcode >> 8) & 0x80)) {
|
if (!((opcode >> 8) & 0x80)) {
|
||||||
printf("ERROR\n");
|
printf("ERROR: Wrong opcode %x in file %s at pos=0x%x\n", opcode, fName.c_str(), i);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
unsigned int opcodeIndex = opcode & 0x3FF;
|
unsigned int opcodeIndex = opcode & 0x3FF;
|
||||||
|
@ -2560,19 +2555,33 @@ void checkScriptsOpcodes()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
check_data(data, 0);
|
check_data(data, 0, 24);
|
||||||
|
|
||||||
auto identifiers = data + 24 * stackReadInt32(data, 42) + 42 + 4;
|
auto identifiers_pos = 24 * stackReadInt32(data, 42) + 42 + 4;
|
||||||
auto static_strings = identifiers + stackReadInt32(identifiers, 0) + 4 + 4;
|
auto static_strings_pos = identifiers_pos + stackReadInt32(data + identifiers_pos, 0) + 4 + 4;
|
||||||
auto code_pos = static_strings + stackReadInt32(static_strings, 0) + 4 + 4;
|
auto code_pos = static_strings_pos + stackReadInt32(data + static_strings_pos, 0) + 4 + 4;
|
||||||
|
|
||||||
check_data(code_pos, fileSize - (code_pos - data));
|
check_data(data, code_pos, fileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
check_file(std::string("master.dat/scripts/OBJ_DUDE.int"));
|
for (auto dirEntry : std::filesystem::directory_iterator("master.dat/scripts")) {
|
||||||
|
if (!dirEntry.is_regular_file()) {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
auto file = dirEntry.path();
|
||||||
|
auto ext = file.extension().string();
|
||||||
|
for (char& ch : ext) {
|
||||||
|
ch = std::tolower(ch);
|
||||||
|
};
|
||||||
|
if (ext != ".int") {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
check_file(file.string());
|
||||||
|
};
|
||||||
|
|
||||||
if (unknown_opcodes.size() == 0) {
|
if (unknown_opcodes.size() == 0) {
|
||||||
printf("Everything is ok, all opcodes are known\n");
|
printf("Everything is ok, all opcodes are known\n");
|
||||||
|
|
Loading…
Reference in New Issue