How To Edit Bad Piggies Levels & Get A Larger Building Grid (Editing The Source Code) - H3XED
How To Edit Bad Piggies Levels & Get A Larger Building Grid (Editing The Source Code) - H3XED
This is a lengthy and technical post about editing the Bad Piggies application code in order to
edit levels, enlarge the building grid, and make other tweaks to the gameplay. This covers the
Windows and Android versions only, but the process will be similar for Mac and iOS if you can
get access to the game application les.
Note: This guide currently only works with version 1.6.0 and earlier.
First, here is a screenshot showing what you can accomplish with these edits. This is the
Fields Of Dreams level (on Android) with a larger building grid and nearly unlimited items:
Disclaimer
Following this guide could lead to breaking your game and losing your progress. Continue at
your own risk. I will not provide pre-modded les; you'll have to edit your own les by following
this guide.
Requirements
Here is what you'll need to get started:
- A good text-editor with UTF-8 support like Notepad++
Basic Information
Bad Piggies is made with the Unity game engine and utilizes numerous assets les to control
the game. These les usually have the extension .assets, but not always.
You can edit assets les directly using a good text editor. There are tons of different assets
les and most contain what looks like a massive pile of gibberish characters. Hidden among
this gibberish are little blocks of code that are human-readable, and which contain variables
that affect the gameplay.
File Size
While editing assets les, they must always end up the same le size that they were originally.
This is to pass a le size validity check that the game performs. Always make a backup of the
assets le before editing and make a note of its Size in bytes. For example, if you change
"count = 5" to "count = 150", you've added two characters, increasing the le size by two bytes,
and so must remove two characters elsewhere to offset this. Addition and removal of
characters must be done within the same parent GameObject.
Whitespace
The assets les are strictly-typed and whitespace matters. You must preserve tabs, newlines,
and whitespace or you may run into errors. These les also use \r\n (carriage return & line
feed) for every line break, which is the Windows standard. That's two characters per line break.
It may seem counter-intuitive that a line break is two characters and not one. Read more about
that here.
Level Editing
This guide will show you how to edit the Field Of Dreams level (seen in the screenshot above),
which is called Sandbox_06 internally by the game. View the Level Number Cross Reference at
the bottom of this post to nd out the internal names for each of the other sandbox levels. You
can use what you learn in this guide to edit any of the other levels in the game.
Assets File
The assets le you need to edit is in a different location on each platform.
PC/Windows
The assets le that you want to edit is called resources.assets and resides in the data folder
of your Bad Piggies PC installation.
Open it in your text editor. Keep in mind that it may run slow; it has over 300,000 lines of code.
This large assets le contains numerous levels. To get to the Field Of Dreams level, search for
the rst occurrence of "Level_Sandbox_06_data".
Android
Open up the APK with 7-Zip. You'll see this:
Go into the assets folder, then bin, then Data. In there are hundreds of les, some without
extensions. The le that contains the Field Of Dreams level is called
746ee37fafe29a34ba3f2032ea011e0a (no extension). Extract just that le out and open it in
your text editor.
Go down about 33 lines and you'll nd Array m_controlPoints. This controls the points that the
camera pans and zooms to when you rst start a level. It contains 8 elements (Element 0
through Element 7). The nal element (7) is also the position of the camera during building. Its
default zoom level is "Float zoom = 5.5". Change that to "Float zoom = 6.0". This will allow for
more visible area for a larger build grid. It will look like this when you're done:
Note: Since we only changed "5.5" to "6.0", we didn't change the total number of characters or
le size of the assets le.
Now the curious thing about the Field Of Dreams level is that it only lists Element 6 (the last
element) and none of the ones before it (0 through 5):
If an element is not listed it defaults to 10 boxes in the row. So that means Elements 0 through
5 (not listed) default to 10. That's 6 rows of 10 boxes each, which is correct (you can con rm
this by playing the Field Of Dreams level). The nal seventh element that is listed has its data
set to 0, which means nothing in that row.
We want to add additional building rows as well as make each row contain more boxes, so we
have to manually add in the missing Elements. This gets a little tricky but isn't too hard.
Change the ArraySize to 8 (for 8 rows) and then copy and paste the Element 6 seven times
until you end up with this:
Make sure you retain the same tab, space, and line breaks used in the le.
Now edit each of them to put them in sequence and change the data attribute to 8191 (not 0).
Why 8191? I'll explain in a moment. Here is what you should end up with:
You now have 8 building rows, each with the value 8191, which means each row will have 13
build boxes. The reason 8191 means 13 is because the game uses the formula boxes = 2^n - 1
on the value (n) to determine the number of boxes in the row. If you just wanted 10 boxes per
row (the default max), you would use 1023. Please look at this chart to get an idea why:
0 = 2^0 - 1
1 = 2^1 - 1
3 = 2^2 - 1
7 = 2^3 - 1
15 = 2^4 - 1
31 = 2^5 - 1
63 = 2^6 - 1
127 = 2^7 - 1
255 = 2^8 - 1
511 = 2^9 - 1
1023 = 2^10 - 1
2047 = 2^11 - 1
4095 = 2^12 - 1
8191 = 2^13 - 1
16383 = 2^14 - 1
32767 = 2^15 - 1
65535 = 2^16 - 1
It might be confusing, but just know that 8191 means you'll get 13 boxes per build row. You
can change it to something else, but just stick with it for now until you fully understand it.
Float m_previewZoomOut = 8
Float m_previewMoveTime = 4
Float m_previewWaitTime = 1
Integer m_DessertsCount = 40
Boolean m_SuperBluePrintsAllowed = False
Integer m_tutorialBookPage = 65
ObjectReference m_tutorialBookPagePrefab = 4
You can then adjust some of the oat numbers to ne tune the le size. For example, you can
add zeros to the end of a oat (decimal) without changing what it means.
Just keep working with it until you've got the le size back to the original amount. Be careful
not to delete any spaces or tabs (whitespace) in front of variables that you want to keep.
Once you're done, open up the game and try it out! If it gives you an error, you may have
accidentally deleted something important, or the le size may be different. Double-check that
the size is the same (not size on disk, but the actual size in bytes).
1. Make a backup of your save les, which is the folder named les in
Android/data/com.rovio.BadPiggiesHD/. Copy the les folder to a safe location (maybe keep a
backup on your PC).
2. Uninstall Bad Piggies from your device, and delete the folder
Android/data/com.rovio.BadPiggiesHD completely.
3. Now copy your modi ed base.apk le over to your device, using your File Manager,
somewhere easy to access like your downloads folder.
4. Install Zip Signer from the Google Play Store and open it. Hit the "Choose In/Out..." button
and navigate to the base.apk. Then hit "Sign The File". The app will take a few moments and
then generate a new APK that is signed.
5. If you haven't yet, you'll need to allow installations from unknown sources. Enable the option
at Settings > Security > Unknown Sources.
6. Navigate to your signed APK using your File Manager and tap it to install it. Once done, you
will now have the installed Bad Piggies with your modi cations. Do not use the Play store to
update Bad Piggies or it may overwrite your edits.
If you're on Android it can be di cult to nd out which of the hundreds of les contains the
sandbox level you want to edit. I recommend using the Find in Files functionality of
Notepad++.
Comments (54)
Add a Comment