SCI: Fix the console's hexgrep command
This commit is contained in:
parent
87e832809b
commit
15b3bffb7f
1 changed files with 10 additions and 10 deletions
|
@ -773,17 +773,16 @@ bool Console::cmdResourceTypes(int argc, const char **argv) {
|
||||||
|
|
||||||
bool Console::cmdHexgrep(int argc, const char **argv) {
|
bool Console::cmdHexgrep(int argc, const char **argv) {
|
||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
DebugPrintf("Searches some resources for a particular sequence of bytes, represented as hexadecimal numbers.\n");
|
DebugPrintf("Searches some resources for a particular sequence of bytes, represented as decimal or hexadecimal numbers.\n");
|
||||||
DebugPrintf("Usage: %s <resource type> <resource number> <search string>\n", argv[0]);
|
DebugPrintf("Usage: %s <resource type> <resource number> <search string>\n", argv[0]);
|
||||||
DebugPrintf("<resource number> can be a specific resource number, or \"all\" for all of the resources of the specified type\n");
|
DebugPrintf("<resource number> can be a specific resource number, or \"all\" for all of the resources of the specified type\n");
|
||||||
DebugPrintf("EXAMPLES:\n hexgrep script all e8 03 c8 00\n hexgrep pic 042 fe");
|
DebugPrintf("EXAMPLES:\n hexgrep script all 0xe8 0x03 0xc8 0x00\n hexgrep pic 0x42 0xfe\n");
|
||||||
cmdResourceTypes(argc, argv);
|
cmdResourceTypes(argc, argv);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceType restype = parseResourceType(argv[1]);
|
ResourceType restype = parseResourceType(argv[1]);
|
||||||
int resNumber = 0, resMax = 0;
|
int resNumber = 0, resMax = 0;
|
||||||
char seekString[500];
|
|
||||||
Resource *script = NULL;
|
Resource *script = NULL;
|
||||||
|
|
||||||
if (restype == kResourceTypeInvalid) {
|
if (restype == kResourceTypeInvalid) {
|
||||||
|
@ -798,12 +797,13 @@ bool Console::cmdHexgrep(int argc, const char **argv) {
|
||||||
resNumber = resMax = atoi(argv[2]);
|
resNumber = resMax = atoi(argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(seekString, argv[3]);
|
// Convert the bytes
|
||||||
|
Common::Array<int> byteString;
|
||||||
|
byteString.resize(argc - 3);
|
||||||
|
|
||||||
// Construct the seek string
|
for (uint i = 0; i < byteString.size(); i++)
|
||||||
for (int i = 4; i < argc; i++) {
|
if (!parseInteger(argv[i + 3], byteString[i]))
|
||||||
strcat(seekString, argv[i]);
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
for (; resNumber <= resMax; resNumber++) {
|
for (; resNumber <= resMax; resNumber++) {
|
||||||
script = _engine->getResMan()->findResource(ResourceId(restype, resNumber), 0);
|
script = _engine->getResMan()->findResource(ResourceId(restype, resNumber), 0);
|
||||||
|
@ -813,13 +813,13 @@ bool Console::cmdHexgrep(int argc, const char **argv) {
|
||||||
int output_script_name = 0;
|
int output_script_name = 0;
|
||||||
|
|
||||||
while (seeker < script->size) {
|
while (seeker < script->size) {
|
||||||
if (script->data[seeker] == seekString[comppos]) {
|
if (script->data[seeker] == byteString[comppos]) {
|
||||||
if (comppos == 0)
|
if (comppos == 0)
|
||||||
seekerold = seeker;
|
seekerold = seeker;
|
||||||
|
|
||||||
comppos++;
|
comppos++;
|
||||||
|
|
||||||
if (comppos == strlen(seekString)) {
|
if (comppos == byteString.size()) {
|
||||||
comppos = 0;
|
comppos = 0;
|
||||||
seeker = seekerold + 1;
|
seeker = seekerold + 1;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue