All pastes #1236259 Raw Edit

Sonic 2 Object Scanner

public c v1 · immutable
#1236259 ·published 2008-10-25 05:44 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>typedef struct object_definition{    unsigned char x_hi;    unsigned char x_lo;    unsigned char y_hi;    unsigned char y_lo;    unsigned char id;    unsigned char subtype;} object_definition;int main(int argc, char *argv[]){    int total = 0;    if (argc > 1)    {        unsigned int id = 0;        fputs("Type the ID of the object (in hex): ", stdout);        if (scanf("%x", &id) == 1)        {            object_definition current_object;            FILE *f = fopen(argv[1], "rb");            puts("\n");            while (!feof(f))            {                current_object.x_hi = fgetc(f);                current_object.x_lo = fgetc(f);                current_object.y_hi = fgetc(f);                current_object.y_lo = fgetc(f);                current_object.id = fgetc(f);                current_object.subtype = fgetc(f);                if (feof(f))                {                    break;                }                if (current_object.id == id)                {                    printf("Object $%02X found: ", id);                    printf("Location: X = %02X%02X, Y = %02X%02X, subtype = %02X\n", current_object.x_hi, current_object.x_lo, current_object.y_hi, current_object.y_lo, current_object.subtype);                    ++total;                }            }            fclose(f);        }    }    printf("Total found: %d\n", total);    system("PAUSE");    return 0;}