LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

How to know if a DAT file is a GRP before load it?

Root / Programming Questions / [.]

Javo118Created:
Just that, I am trying to maje a list of all of the GRP of all the projects but dunno how to filter the list

There's no way to tell. :(

Mmmm so there is something that "load" it and if is not a GRP don't close my app? Something like "if load-error then show dialog"

perhaps you could emulate the loading system? would be slow and require lots of setup, but it would work

perhaps you could emulate the loading system? would be slow and require lots of setup, but it would work
Can you explain it a little more? Please

perhaps you could emulate the loading system? would be slow and require lots of setup, but it would work
Can you explain it a little more? Please
As in trying to pretend to load it as if it was a GRP. But the loading is not done by SB's internal tools, it's done by your code.

Don't listen to ProgrammingChicken. It's impossible to do this.

Don't listen to ProgrammingChicken. It's impossible to do this.
*not feasible

You can't load a file without using LOAD, and LOADing into an array with the wrong number of dimensions causes an error. Therefor it is impossible to load a random DAT/GRP file.

You can't load a file without using LOAD, and LOADing into an array with the wrong number of dimensions causes an error. Therefor it is impossible to load a random DAT/GRP file.
give us catch error pls smileboom

Yeah, i want a catch error T_T, well, this make my project a little buggy, i will continue it anyway, thanks both

I'd think you can always load a DAT into an empty array and it will auto-expand to the length of the file's elements. If the array you're using is already too large, use POP() repeatedly into a dummy variable to empty the array.
WHILE LEN(ARRAY)
DUMMY=POP(ARRAY)
WEND
Then, you can perform tests on the data to see if it's really a GRP. The three tests I can think of that would be the easiest to run and most reliable are these, sorted from simple and fast to slow and more complex. Number one: Check the length of the array with pre-chosen resolutions.
  • 512*512=262144
  • 400*240=96000
  • 320*240=76800
You can check for as many resolutions as you want. Number two: Check the bits. GRP's are always 16-bit, and we're loading we're loading them into a 32-bit or 64-bit array. Use a FOR loop to check the entire array for elements that don't fit into this bitmask. "0000FFFF"
FOR I=0 TO LEN(ARRAY)-1
IF (ARRAY[I])!=(ARRAY[I] AND &H0000FFFF) THEN ISGRP=0
NEXT
Number 3: The noise test. If you don't trust the tests before, this might be the last one you need. Pick a resolution/aspect ratio to test, then run a test on all of the rows and columns of the array as an image. For row, calculate each pixel's difference in color with the pixel to its left with subtraction and ABS(). Average all of the resulting values for every pixel in the image into one value. We'll call it "HN". Repeat this process vertically, checking every pixel with their pixel above. average these values into the variable "VN". Now, if VN is significantly higher than HN, that might mean the horizontal resolution is wrong. you can test a bunch until VN is closest to the value of HN. Now, you can average VN and HN yet again into "TN". Now you have a heuristic to truly test if the data is coherent enough to be an image. You can run tests on GRPs and other data to find the threshold value to separate GRP's and other data. Awesome! Let's test the code!
Type mismatch in 0:6(LOAD)

I've thought for months about how to make an auto-preview image viewer with these tests and i just find out now that they never would've worked

LOAD will automatically RESIZE the array, not just expand it so you don't have to empty it first