Skip to content

Cleaning Code

Anders Jenbo edited this page Mar 30, 2019 · 7 revisions

You can get an overview of what functions need to be cleaned up on the Binary identical functions milestone.

Tools you will need

The gold compiler

Visual Studio 6 Pro/Enterprise

If you have a copy of VC 6 Pro or Enterprise you can use the Diablo.dsp project file, or simply set MAKE_BUILD=pdb in your environment and run make from the project root (Visual Studio must be installed in your home folder as VC6).

Docker

If VC is not available to you we have a Docker image that can be used instead. On Debian/Ubuntu Docker can be installed by running the following commands:

sudo apt install docker
docker adduser ${USER} docker
reboot

After installing you must create a docker hub account, and then sign in to Docker on your machine:

docker login

To compile you then run the following command from the project root:

docker run --rm -v $(pwd):/root/devilution -e MAKE_BUILD=pdb diasurgical/riivaaja

Note: Windows users must replace $(pwd) with the full path to the project root.

Compare the generated code

If you are not on Windows you need a Wine, if you are already using the docker image it can be used instead of installing the full version of wine: Create a file called wine and place it in your executable path:

#!/bin/sh
docker run -v $(pwd):/root/devilution --entrypoint "/usr/bin/wine" diasurgical/riivaaja:stable $(basename $1) $2 $3

Mark it as executable chmod +x wine and move it sudo mv wine /usr/local/bin/

Helpful resources

The clean up process

Cleaning up the code

Guide to x86 Assembly

Comparing to the original

docker run -ti --rm -v $(pwd):/root/devilution -e MAKE_BUILD=pdb diasurgical/riivaaja If you are on Windows you will have to replace $(pwd) with the project path.

./devilution-comparer Diablo_109.exe Diablo.exe mpqapi_reg_store_modification_time

diff orig.asm compare.asm

Memory addresses are expected to differ as they are currently not aligned.

Handling Git

If you are somewhat unfamiliar with Git here are some easy steps to follow.

Start by making your own fork of Devilution: https://github.com/diasurgical/devilution

Clone your repo to your local machine and link it to the upstream Diasurgical:

git clone https://github.com/YOURNAME/devilution.git
git remote add devilution https://github.com/diasurgical/devilution.git

Each time you start working on a function:

git fetch --all -p
git checkout -b FUNCTION_NAME devilution/master

Each time you're done:

git commit -am "FUNCTION_NAME bin exact"
git push origin FUNCTION_NAME

Then go to https://github.com/diasurgical/devilution/pulls and open a new pull request based on your branch.

Clone this wiki locally