CadEditor. Two new plugins

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@pinkwonder·
0.000 HBD
CadEditor. Two new plugins
#### Repository
https://github.com/spiiin/CadEditor

CadEditor is the universal level editor for NES/SMD/SNES/Game Boy games, the introduction of the project was [here](https://busy.org/@pinkwonder/cadeditor-universal-level-editor-for-nes-smd-snes-games)

#### Introduction

New update of CadEditor project:

- Tool for search levels data in GameBoy ROM files. It's implemented as Lua-script for emulator [Bizhawk](http://tasvideos.org/BizHawk.html), as the best emulator for Game Boy supporting scripting. ([commit](https://github.com/spiiin/CadEditor/commit/d364f10650eaabeef411a0754ed34d4d4917c698))

- Plugin for building GameBoy graphics - now CadEditor supports configs for Game Boy games ([pull request](https://github.com/spiiin/CadEditor/pull/9)). Example of the config file for ***Darkwing Duck*** [Game Boy version] [included](https://github.com/spiiin/CadEditor/blob/master/CadEditor/settings_gb/darkwing_duck/Settings_DarkwingDuck-1.cs).

- ***Battletoads*** Race Editor plugin added. This is an example of the plugin for the specific level of the game, but it can be upgraded to generic table editor, with the ability to choose, how data can be saved, loaded, displayed and edited ([pull request](https://github.com/spiiin/CadEditor/pull/11)).

#### Post Body

###  Game Boy graphics
CadEditor supported graphics for NES/SMD platforms before, and now it supports Game Boy graphics also.

Game Boy has pretty simple graphics format, described [here](http://www.romhacking.net/documents/457/), it supports only four colors (2 bits per pixel). It was not very hard to create the plugin, that will build tiles of this types from a predefined palette and dump of PPU memory, made with emulator Bizhawk (almost every modern emulator allows to create memory dumps).

For example, there is dump of PPU memory for game ***Darkwing Duck***, level 1.
![chr.png](https://ipfs.busy.org/ipfs/QmWQQBkoNzWKnn7nZV63bbjKPVdYmM5GPffVzi6bhQKUNN)

Dump starts from 0x8800 address of PPU and contains 128 8x8 tiles (at top half), used for building level background. It can be viewed with console graphics editors, like [Tile Layer Pro](http://www.romhacking.net/utilities/108/)

Real games rarely used only tiles, more ofter they describe **blocks** - structures from several tiles. One way to find it - disassemble the game code and analyze, how blocks built.

But I choose another method with no need to use debugger and disassembler. With modern emulators, the user can automate actions with lua scripts, so I decide to make lua script, that will corrupt every byte of ROM-file and see, does it change the picture on the screen or not.

I already checked this method with NES emulators like [Fceux](http://www.fceux.com/web/home.html) and [Mesen](https://www.mesen.ca/). Example of usage this method:
https://www.youtube.com/watch?v=21xjfEBDkJM

So I ported [Autocorrupter](https://github.com/spiiin/CadEditor/blob/master/Stuff/gb_lua/bizhawk_corrupter/autocorrupter.lua) script for [Bizhawk](http://tasvideos.org/BizHawk.html) emulator with Game Boy core.

The big disadvantage of this emulator is the impossibility to checks exactly bytes in ROM changed between two saves. Because of this, the script needs to check every byte in ROM - it takes 10-15 minutes until it finished on an average machine, instead of 1-2 minutes for emulators, that supports code-data logging from lua-scripts. I hope, this feature will be added in the next version of Bizhawk (I contacted one of the developers, so they inform about the problem).

But even without optimization, it's not a problem to wait 15 minutes, you can just drink a cup of tea, before checking results. The script saves them in "*snaps*" folder. Each screenshot has a name with the address of the corrupted byte.

Often, it's enough to see on these screenshots for the understanding level format of the game. For example, there are 3 screenshots from corrupting results of the ***Darkwing Duck*** game:
![08490.png](https://ipfs.busy.org/ipfs/QmfLzbRWLJ2aaNJjAVLDZudJTkBdyQLUbHXfRynjHrrJ87)

Here, we can see, that game describe level with blocks of size 16x16 (2x2 tiles). One byte change leads to change one block, and blocks are described per rows. With the analyze of the neighboring screenshots, we also can calculate, that game describe level by screens of size 10x8 blocks and address of the first screen is **0x8453**

What is really good is that the description of the blocks themselves also found with **Autocorrupter**. Looks at the screenshot made after corrupting byte **0xB7EB**:
![gb_dwd_clock2.png](https://ipfs.busy.org/ipfs/QmWYhBVewNGuXuP3nc2nRrMoArWEEJpVbkFb499gGEMqM6)

One byte change leads to a change of every the same block of the screens. If you can't see block here, wait to the next screenshot from CadEditor, where this blocks can be marked with the axis.

For now, it's all required information for made [config](https://github.com/spiiin/CadEditor/blob/master/CadEditor/settings_gb/darkwing_duck/Settings_DarkwingDuck-1.cs) file:
```using CadEditor;
using System;
//css_include shared_settings/BlockUtils.cs;

public class Data 
{
  public OffsetRec getScreensOffset()  { return new OffsetRec(0x8453, 20 , 10*8, 10, 8);   } //address of the first screen, screens count and sizes
//...
  
  public bool isUseGbGraphics()      { return true; } // we use plugin for building Game Boy graphics
  public bool isBuildScreenFromSmallBlocks() { return true; } //no macro blocks defined, screen built with blocks 2x2
  
  public OffsetRec getBlocksOffset()    { return new OffsetRec(0xB7E7, 1  , 0x1000);  } //offset of blocks' description
  public int getBlocksCount()           { return 256; } //blocks count
  
//standard function for saving/loading block in ROM file (linear description, not additional information bytes)
  public GetBlocksFunc        getBlocksFunc() { return BlockUtils.getBlocksLinear2x2WithoutAttribs;}
  public SetBlocksFunc        setBlocksFunc() { return BlockUtils.setBlocksLinear2x2WithoutAttribs;}
//...
// read palette and video chunk from dump files
  public byte[] getPallete(int palId)
  {
      return Utils.readBinFile("pal1.bin");
  }

  public byte[] getVideoChunk(int videoPageId)
  {
     return Utils.readVideoBankFromFile("chr1.bin", videoPageId);
  }
}
```

...And edit game in CadEditor (blocks and screens described in the standard way, so no additional code is needed): 
![cad_dwd_gb.png](https://ipfs.busy.org/ipfs/QmWNmdQy1reVb1q5WU26jbyFvmoUHLJVPgd8k7Tox1zgvS)

Now, the game background can be changed:
https://www.youtube.com/watch?v=AtCG21_j78E

### Battletoads Race Editor
Another plugin, added with this update, is ***Battletoads*** Race Editor plugin. 
![cad_bt.png](https://ipfs.busy.org/ipfs/Qma6KwHnZdAK3iFzb8xN1UFrbx54z5EK7A68Cj1WCy72Qp)

It's very specific, created for only one level of the game, but it can be upgraded for being a highly configurable plugin for editing table data, defined in config files (with the ability to change save/load methods, rendering, formatting and editing methods).

This types of plugins not loaded on the editor start but included only from specific configs. For example, this plugin included only in the [config](https://github.com/spiiin/CadEditor/blob/master/CadEditor/settings_nes/battletoads/Settings_Battletoads-3.cs) for Battletoads, level 3:
```
  public string[] getPluginNames() 
  {
    return new string[] 
    {
      "PluginBattletoadsRaceEditor.dll",
    };
  }
```

The plugin is used for editing positions and types of obstacles for racing in level "**Turbo Tunnel**" in NES ***Battletoads*** game. Obstacles have 7 parameters:
```
type - type of the obstacle, icon represent pictures of object in the game.
x - position on the track, then obstacle showed to the player.
x1 - position on the track, when obstacle starts moving to the player.
y - position of the bottom of the obstacle. Two standard positions - on the ground and on the height of jump of the player.
z - position on the track. Three standard positions - on the top part, on the bottom part, on the middle part
blinkTime - time to blink. By default, synced to the x1 position - object stops blink, when start moving.
jumpPower - only for trampolines. Defines power of jump after touching the trampoline.
```

X, y, z positions described on the screen:
![bt_coords.png](https://ipfs.busy.org/ipfs/QmPjLKqAkUBA768U9asQ6CxbLD1t8fW3CBYrA299WFtQTQ)

This plugin was made is a separate utility, but rewritten as CadEditor plugin for the ability to create other Tables Editors for other games (in ideal, according to the CadEditor philosophy, there is only one universal Table Editor, configurable from config files by games). For now, only the address of objects can be changed from scripts (for editing other regional versions of ***Battletoads*** game).

Example of the track, built with the old version of this plugin:
https://www.youtube.com/watch?v=rX4iSEg3wmQ


#### Resources

CadEditor-related resources:
- [CadEditor plugins list](https://spiiin.github.io/CadEditor/cadeditor-modules.html) - description of CadEditor plugins (in Russian)
- [CadEditor on fundition.io](https://fundition.io/#!/@pinkwonder/94dye4s9a) - project's page on Fundition.io

External docs and tools:
- [Bizhawk](http://tasvideos.org/BizHawk.html)  - the emulator of Game Boy (and other consoles) with lua scripting support.
- [Displaying a 2BPP Tile](http://www.romhacking.net/documents/457/) - description of Game Boy graphics format
- [Tile Layer Pro](http://www.romhacking.net/utilities/108/) - graphics editor for editing PPU dumps.
- [Battletoads disasm](https://github.com/feos-tas/DisAssemble/tree/master/Battletoads) - disassembled sources of the ***Battletoads*** game.

#### Similar projects

Basically, there are no other universal level editors. 

- Almost all level editors for Game Boy specific games listed on [romhacking.net](http://www.romhacking.net/?page=utilities&category=12&platform=8&perpage=20&startpage=1).

- ***Battletoads*** also has no level editor. One attempt with predefined pictures [made](http://www.emu-land.net/forum/index.php/topic,56894.msg1009696.html#msg1009696) with GameMaker by  romhacker Ti_ (old forum post in Russian).

#### Roadmap

- Adding support for graphics for other consoles by Nintendo - Super Nintendo, Game Boy Advance.

#### Series Backlinks

Previously I described CadEditor in articles:

- [CadEditor - Universal level editor for NES/SMD/SNES games](https://steemit.com/utopian-io/@pinkwonder/cadeditor-universal-level-editor-for-nes-smd-snes-games)
- [CadEditor. Support levels with mixed screens](https://steemit.com/utopian-io/@pinkwonder/cadeditor-support-levels-with-mixed-screens)
- [CadEditor. Release 5.1](https://steemit.com/utopian-io/@pinkwonder/cadeditor-release-5-1)
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,