Log in

Coding FAQs

Q: Where would I find cards that are not in the /src/cards c files? I want to look at some other already exsisting cards in their raw c format. Take for instance Ancestrial recall where would I find it decompiled into raw c text? or how do I decompile it?

A: From the tutorial, you should know how to find the ASM code for any card. (look on the Magic.exe tab for the code pointer, and then click the '...' button to view the code.

There is also a version of Manalink 2.01 decompiled into C. It can be found here: http://www.savefile.com/files/2088274

To find the code for a specific card, search for the address of the code pointer. You'll find a sub with that name. That's the code. Of course, since decompiling saves no symbolic information, such as variable names, the code isn't always too helpful.

The .c file can be useful for figuring out where to inject code (injecting code). For example, there used to be a bug that the shock lands did not count as basic lands for Kird Ape, land walk, etc. This was strange, since the code for Template Garden was directly copied from the code for Savannah. So we suspected that there was some hard-coded id's of the dual lands somewhere else in the code. I searched the .c file for the ids of the dual lands, and found one sub that referred to the 10 id's, one after another. So I was able to look at the name of the sub that the code was in, and that name is the same as the address in Magic.exe. From there I was able to inject some code to also look for the ids of the shock lands.

Q: My C code is perfect, but the card doesn't work ! Why ?:
A: for some type of cards, the Reserved Infos field is vital, otherwise they will not work or crash the game. Check other similar cards and paste their Reserved Infos on your.
Also, for Regeneration and Indestructible, setting On "Instant Ability" from the "Extra Abilities" is required.

Plus, usually cards that employ the Rules Engine to work needs a specifical number to be putted on the "cc[2]" field of Magic.exe. Here's a table of the values curretly used :
1 -> Casting cost can be modified (Hybrids, pitch spells and so on). Also used for cards that enable you to "play a spell for free from some zone" or "copy a spell".
2 -> Static Graveyard Abilities (Anger). It's also used for Bloodghast-like cards and cards that auto-reshuffle in the deck (like Darksteel Colossus or the Eldrazis).
3 -> Vanguar Avatars
4 -> Cards that activates in hand (Cycling, Landcycling, Transmute and so on)
5 -> Cards that triggers in the upkeep when are in the graveyard ( Graveyard Upkeep Trigger ), like Nether Shadow, Ichorid and so on.
6 -> Cards that can be Dredged
9 -> Planeswalkers (if Enchantment) or Cards with Flashback (if not creature) / Unearth (if creature)
10 -> Cards with Retrace
11 -> Cards that generate an effect when discarded.
12 -> Cards that need the Storm Count (Dragonstorm, Vengevine and so on).
13 -> Trap cards, cards with Bloodthirst and in general cards that needs specific counts to be performed in order to work (check "zendikar.c" to see what counts are available).
If your card fill more of one of these cathegories, you'll need to alter the "rules_engine.c" file in order to make it recognizes them (look at the "check_decks_for_rules_engine" function).

Lastly, some cards use the special Rules card named Deadbox, that takes care of counting the permanents that goes in the graveyard from play in each turn and their types. For enabling the Deadbox, put "14" in the cc[2] field above mentioned.