The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 895 - File: showthread.php PHP 7.3.33 (Linux)
File Line Function
/showthread.php 895 errorHandler->error




Users browsing this thread: 1 Guest(s)
Making a Weapon Deal 2x Damage to a New Monster Type

#1
Posts: 61
Threads: 18
Thanks Received: 1
Thanks Given: 47
Joined: May 2014
Status
None
Note that this thread is tagged for the OpCodes that it highlights or explains (BIT, BEQ, LDA, INC)
This post has been edited due to replies to this post.

Here's what I labored over today to try and figure out some hacking (any criticisms or corrections welcome).  For this episode of newbie coding, we are looking at having a new special weapon attack that allows the weapon deal 2x damage to a new monster type that we want to add to the game.  The monsters in the game can be marked (aka "flagged") for certain properties/traits/types and then other actions are based from what traits the monster has for those special flags.  In this case we'll be looking at special byte 3, which is where a group of the flags for monsters is stored.  For instance, monsters in the game can already be marked human or undead.

Here is the result of my code on how to do this, by reverse engineering Ghost XIII's "dragonslayer" patch, which uses a copy of the code from the "2x human" effect in the C2 bank.
==========================================================================
$3C95 = Special Byte 3:
Dies at 0 MP, No name, Human, Auto critical if Imp, Undead

Note: Technically the bits of this Byte are:
Bit 1: Dies at 0 MP
Bit 2: nothing (replaced with ignore-ignore defense flag if patched)
Bit 3: No name (used by something, it sounds like)
Bit 4:
Bit 5: Human
Bit 6:
Bit 7: Auto critical if Imp
Bit 8: Undead


Meaning $3C95 is the address for some special byte that, depending on the individual bits (0s or 1s) in each space of the byte (8 bits = byte) acts as a flag, and other effects in the game act based on those identifying flags.  In this code, $3C95 is monster data, letting us know if the monster is human or undead, etc.


The code for dealing 2x damage to Human:
Code:
C2/38F2: B9 95 3C     LDA $3C95,Y
Loads the special byte into the A register, indexed by Y.  This means that whatever is in the Y register will increase the address, looking at bytes after $3C95.  Why would we look at different bytes?  Each special byte will be different for each monster, which allows for each monster to have its own flags.  What is probably happening is that the special bytes are all sitting in a line, with each byte corresponding to a different monster.  The indexed search allows the Y register to be a trigger that changes the search from $3C95 (just one special byte for monster 1) to whichever monster is being targeted. 

Now that we've grabbed the special byte for weapon we're using, we'll compare what's loaded in A (the special byte, a.k.a. the flags) to the desired flags within the byte via BIT below.
Code:
C2/38F5: 89 10        BIT #$10
This is checking to see if the 4th bit, the human flag, is set, because 10h (10 in hexidecimal) is 16 in decimal and in bit form, this is literally and physically 00010000.  But wait!  Why do we call that bit with a 1 the 4th bit?  We call it the 4th bit not because it's 4th from the left, but instead the 5th from the right!  The order is REVERSED for all 8 bits based on how hexadecimal progresses (01h = 00000001, 02h = 00000010, etc.) and the first bit is called "bit 0".  If the byte at $3C95,Y was 10000001, then the 4th bit isn't set, the 0th bit and 7th bit are, so the BIT function would.  Checking for both 10000001 would be done via BIT #$81.  Technically, any matches of bits from the compared bytes results in a non-zero amount, meaning the Z flag isn't "set."  The Z flag is a special tracking device during calculations that is set to 1 when a zero occurs.  If we check 10000001 against 0001000 then no matches occur, so because of the BIT functionality, the Z flag is set.
Code:
C2/38F7: F0 04        BEQ $38FD   (Exit if target not human)
BEQ doesn't branch if "equal", it branches if something is ZERO, or more technically, if the zero flag is set.  Since previously using BIT, if the Z flag wasn't set from a comparison of two similar properties, we wouldn't get zero!  So this branches if the comparison fails.  If the comparison succeeds, then a non-zero amount would occur and the Z flag isn't set, and we keep going.

Code:
C2/38F9: E6 BC        INC $BC
C2/38FB: E6 BC        INC $BC     (Double damage dealt)
C2/38FD: 60           RTS
This doubles the damage and returns out of the routine.

Now if we wanted to make 2x damage to something other than human, then we just enter this code into another special weapon attack that we'd like to replace (such as the ogre nix breaks code at C2/3ECA).  This is limited to certain areas because there are only 15 possible special attack effects (other than normal attack) according to the way the ROM currently refers to this data.

This code must be then changed with the BIT function to a different comparison that represents the new bit of the Special Byte 3 which will be marked onto your monsters.  Bit 4 is unused, for example, so BIT #$08
Code:
C2/38F5: 89 08        BIT #$08
would compare 00001000, or the 4th bit from the right (the "3rd" bit), and in the FF3USME editor, we can go to any monster and check on the 4th box for that section, 3rd below from the 0mp=death checkbox.
  Find
Quote  



Messages In This Thread
Making a Weapon Deal 2x Damage to a New Monster Type - by ReturnerScum - 01-30-2016, 09:45 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite