Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting terrain data from the original slv files #1

Open
bertyhell opened this issue Mar 21, 2021 · 13 comments
Open

Extracting terrain data from the original slv files #1

bertyhell opened this issue Mar 21, 2021 · 13 comments

Comments

@bertyhell
Copy link
Owner

bertyhell commented Mar 21, 2021

I'm trying to recreate an old game from when I was young, since it doesn't run anymore on modern machines. And the emulator I've setup runs it at about 13 fps.

Here is a gameplay clip: https://www.youtube.com/watch?v=uH99WZHe3rk

I've recreated the first level of the game using minimap screenshotting and stitching, but this is a very laborious process and not very accurate. You essentially fly around with the chopper and record the screen. Then extract all the screenshots. Crop to the minimap area and stitch those minimaps back together to get a full top side view of the map.
minimap00300

frames:
image

stich attempt 1:
image

final texture
color-3

heightmap:
heightmap-3

This works fine as an initial version of the map:
image

But extracting the other 36 levels this way makes me want to pull my hair out.

The original game files have files that are clearly named after the levels:


https://github.com/bertyhell/swiv3d/tree/feature/extract-terrain/extract-terrain


image

These files must contain the heightmap and maybe also the texture map.
They are all very similar in size so I assume all level dimensions are the same. The small changes between the files are probably due to different textures/more/less mountains.

I've tried extracting the data using IDA Pro. But it all seems to be gibberish.
image
image

The exe file can be followed a little bit. eg: I find some references to DEMO.SLV and %.SLV where the levels are presumably loaded. But nothing indicating how the data is structured in those SLV files.
image

I'm not sure how to proceed with extracting the terrain data. Hopefully they haven't saved the terrain as a valley of points in between which a curved surface is calculated.

Any hints on how to proceed would be greatly appreciated.

@Andoryuuta
Copy link

Andoryuuta commented Mar 21, 2021

These files appear to just be raw image data. There isn't any file header, so I presume the image dimensions are hard-coded in the binary.

An example python PIL script showing this would be:

from PIL import Image

with open('TERRAN00.SLV', 'rb') as f:
    data = f.read()
    image = Image.frombytes('RGBA', (512,256), data)
    image.save('TERRAN00.png')

Which produces:
image

As you can see, there are duplicate regions here, so the mode/format ('RGBA'), and dimensions (512,256) are likely incorrect.

@J-T-de
Copy link

J-T-de commented Mar 21, 2021

I can also recommend using the kaitai web ide if it is not only a bitmap in some format. It won't view the bitmap, but it you can easily guess data structures...

@bertyhell
Copy link
Owner Author

@Andoryuuta Yes, looks like there might be rgb data in there but just each channel as a grayscale image next to each other. The top one looks like a heightmap. Since the long stream is a river. And the bottom image in your screenshot shows the water as white. In the top image the river is wider, so that's probably the river and the beach on the sides of the river being the same height.

Also the dots in the bottom image are colored, so I assume those are enemy locations and houses/trees indicated by a pixel.

I'll keep investigating.

with this setting I'm getting some airplane silhouettes at the bottom i think :p

width: 1024,
height: 1024,
channels: 1,

TERRAN00

@bertyhell
Copy link
Owner Author

bertyhell commented Mar 21, 2021

i extracted the 6 identifiable regions in the above image.

ive named them as followed:

col1 col2
row1 height1 height2
row2 color1 color2
row3 tree1 tree2

height1:
TERRAN00_height1

height2:
TERRAN00_height2

color1:
TERRAN00_color1

color2:
TERRAN00_color2

tree1:
TERRAN00_tree1

tree2:
TERRAN00_tree2

names are only for ease of reference, they do not reflect what is in the images.

Some interesting notes:
When you take the diff of the images in a row you get some interesting results:

diff of height images. my suspicion, these images are the same, the developer just shifted them over 1 px by accident?
height1-height2-diff

diff of color images.
color1-color2-diff
eg:
image

diff of tree images.
tree1-tree2-diff

@Wixely
Copy link

Wixely commented Mar 21, 2021

I've added some stuff to your reddit post but I'll just add some notes here.
You are getting duplicate maps because you don't have the correct width/height and are taking every second pixel to create a second map. Easiest way to tell this is that your map looks squished. I've identified 3 terrain maps so far.
1 the Heightmap,
2 the Unit map
3 coloured map
Since the colour map is just bytes that means there has to be a colour palette somewhere to match it to. Either in the map data or somewhere else in the game. You can tell this last map is using a colour palette by cycling through colours and seeing that specific shades would be consistant with specific colours.

637519572110543

@bertyhell
Copy link
Owner Author

bertyhell commented Mar 21, 2021

cool, Yes that makes more sense:
TERRAN00_01
TERRAN00_02
TERRAN00_03

The smaller images seem to be detailed maps of the main objectives in the game, since there are so many units there that they start to overlap in the world map:
ezgif-2-67facdd9b577

@bertyhell
Copy link
Owner Author

This image contains the color data:
TERRAN00_color

By using my old stitched image
TERRAN00_colored

i was able to decode with which color each greyscale value matched:
TERRAN00_recolored

@bpvarsity
Copy link

This is really great work so far. This is still my favorite game. Playing it on my old chromebook pixel running mint and dos emulator :) Have you been able to make any more progress or moved onto other things?

@bpvarsity
Copy link

I can start helping as well if needed.

@bertyhell
Copy link
Owner Author

i'd still like to continue it, but i lack the time.
Last thing i worked on was getting the buildings to explode into pieces when shot.

@bpvarsity
Copy link

I totally understand that.
Is your latest code uploaded? I didn't see any buildings or weapons when I tried the code here. I'm going to see if I can make sense of any of it and see what I can contribute

@bertyhell
Copy link
Owner Author

@bpvarsity I've added them to the main branch. If you want a tour of the code, let me know through email and we can go over it on a call.

@bpvarsity
Copy link

@bpvarsity I've added them to the main branch. If you want a tour of the code, let me know through email and we can go over it on a call.

Thank you will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants