Thursday, January 23, 2014

Python Script to Remove Unbreakable Blocks in Robominer


Robominer is an Android game where you use a robot to drill around searching for a diamond. There are blocks that can't be drilled, so you have to either go around them or use dynamite to blow them up. After a while, I got really annoyed dealing with these blocks. So I poked around and found a way to replace them with other blocks.

Basically, when you save a game, it saves the entire map too. This includes the types and locations of all of the blocks. The save file can be modified to remove the unbreakable blocks.

I have SL4A and Python installed on my Android device, so I wrote a Python script I can run on my device to make the changes for me. If needed, you can also copy the file to a PC, run the script, and then copy it back. Note, however, that the script has to be run on every new level. Being able to run the script on the device is a lot more convenient.

Here is the script. It assumes your saved game file is on the SD card. I don't think you can modify the save file in the "Phone" slot unless your device is rooted.



#!/usr/bin/python
# Replace gray blocks with regular blocks on Android app Robominer
#
# 01-15-2013: Created by BitJunkie
# 01-16-2013: For gray blocks, generate random mineral type
# 01-22-2013: Block info starts 3 bytes before 0x3f80, adjust file pointer info
import random 

count=0
random.seed()
# Open the file in binary mode for reading and writing
fh=open("/sdcard/Android/data/com.rnet.robominer/files/last_1.sav","rb+")

# Go to the beginning of the block info +3 bytes, from the beginning of the file
fh.seek(0x30, 0)
header = fh.read(2)

while header == b"\x3f\x80": 
  fh.seek(-4,1)  # Move file pointer to start of block info
  blk = fh.read(1)
  if blk == b"\x01": # if block is gray
    fh.seek(-1,1)
    fh.write(b"\x02")  # Make it regular 
    r = random.sample(["\x01","\x02","\x03","\x04","\x05","\x06","\x07","\x08","\x09","\x0a","\x0b","\x0c","\x0d","\x0e","\x0f","\x10","\x11","\x12"],1)
    fh.write(r[0])  # Add random mineral/element
    fh.seek(13,1)  # Go to next block
    count+=1  # Count how many blocks are changed
  else:
  # Go to next block header
    fh.seek(14,1)
  header = fh.read(2)

print "Blocks changed: %d" % count

I have only used this for games on the "Easy" level. I'm sure the script would have to be modified for the higher difficulties.

Have fun!

4 comments:

  1. I really did try before asking here.

    I dont know python but I do know powershell

    So i can read ot and know what's going on

    Problem is once I past this into a new script and run it i get nothing showing at all in the terminal window

    As I understand ot should be printing out the result at the end

    I add in some dialog block and it doesn't show that either.

    I past that dialog block into the hello world script and it shows the dialog fine.

    I replaced the text within the hello world script with the text from yours and again I get nothing from the terminal.

    What am i missing
    Im thinking I must have copied some invalid characters or something but if think of see at least an error message.

    ReplyDelete
    Replies
    1. When it runs successfully, it will print out the number of blocks changed. I have only tried this on Android and Linux. I haven't tried on Windows or Mac. Maybe a problem with the Python interpreter you're using. Sorry, I don't know how to help.

      Delete
    2. I finally noticed what the problem is, I think.

      My phone doesn't have an SD card so the path to my file is different.

      It saves it at /Internal Storage/Android/data/com.rnet.robominer/files/last_1.sav

      I tried editing it so that it has that inside the quotes instead but I get the same result.

      Does python not kick an error if it doesn't fine the file?

      Does the space in the path mess it up?

      Is it maybe just running along and Im not being patient enough?

      I let the script run for several minutes which I would think would be long enough to parse through each byte of the BIN file.

      Delete
    3. Hmm... I would think python would give an error if it can't find the file or the space in the file name was an issue. The script shouldn't take long to run, a few seconds max. My only guess is that you need root access to change the file on internal storage.

      Delete