News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Dragon Warrior hacking help needed  (Read 4339 times)

Camerupt

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Dragon Warrior hacking help needed
« on: April 12, 2016, 07:38:10 pm »
So i'm making a hack of Dragon Warrior.

I have TownEdit and DW1:Mass Data Editor running in DosBox, they seem to work good so far aside from a major malfunction in DW1MDE where a SEGMENTATION FAULT crashes the program upon trying to load the Red Slime's data.

Aside from those two things, i also want to edit all the game's text including dialogue, item/enemy names, etc., as well as graphics, how do i accomplish this?

dougeff

  • Sr. Member
  • ****
  • Posts: 358
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #1 on: April 12, 2016, 08:22:43 pm »
Make a table file...(the bottom of this page, where it says 'Text Table')
http://datacrystal.romhacking.net/wiki/Dragon_Warrior:TBL
(A table file is just a .txt file, use Notepad to copy/paste)

Use FCEUX with debugging tools. Open DEBUG/Hex editor.

Set view = ROM.

File, open TBL file. Find that table file.

Scroll down through the ROM. You should see text. Edit it as you like. File, save ROM.

(I think that's right, I didn't test it myself).

EDIT: I tested it. Seems to work fine for me.

« Last Edit: April 12, 2016, 11:03:02 pm by dougeff »
nesdoug.com -- blog/tutorial on programming for the NES

Sliver X

  • Hero Member
  • *****
  • Posts: 1085
  • der Wille zur Macht
    • View Profile
    • Panicus - A Fragment of Memory
Re: Dragon Warrior hacking help needed
« Reply #2 on: April 12, 2016, 11:57:19 pm »
Quote
I have TownEdit and DW1:Mass Data Editor running in DosBox, they seem to work good so far aside from a major malfunction in DW1MDE where a SEGMENTATION FAULT crashes the program upon trying to load the Red Slime's data.

I remember the DW1MDE crashing under pure DOS on the Windows 98SE machine I ran when doing Dragoon X Omega, so it's not a DOSBox problem. It ran fine under a Windows DOS session, however.

Looking into this, it appears to not SEGFAULT when ran under Windows 3.11 as well.

Ever since I went 64 bit with Windows 7 in 2009 I've maintained a DOSBox build that integrates into CMD.EXE and Windows Explorer, with full Windows 3.11 support and a ton of other things you'll probably never use like TCP/IP support.

It should allow you to do this.

Camerupt

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #3 on: April 13, 2016, 04:08:02 pm »
Ayy it's Silver X!

I have the tbl stuff all set up and checked out but the documentation on data crystal lacks info on other macros that cue the player name, sentence end, and what the correct space is.

As for the enemy and item names, is there some way to repoint them and make them longer? Same for the other text too.

And for enemy sprites it seems like a jumble of tiles in the rom, how did you replace those properly?

Sliver X

  • Hero Member
  • *****
  • Posts: 1085
  • der Wille zur Macht
    • View Profile
    • Panicus - A Fragment of Memory
Re: Dragon Warrior hacking help needed
« Reply #4 on: April 13, 2016, 04:41:24 pm »
Quote
I have the tbl stuff all set up and checked out but the documentation on data crystal lacks info on other macros that cue the player name, sentence end, and what the correct space is.
As for the enemy and item names, is there some way to repoint them and make them longer? Same for the other text too.

I don't know about enemy names, but I wrote a document detailing some stuff about Dragon Warrior. Section II of the document is as follows:

Code: [Select]
II: Text
~~~~~~~~
Dragon Warrior doesn't use pointers in the text itself, so you can resize the blocks
of text to a fair degree (Although if you go too far, it will mess things up. How the
game determines that you've gone beyond the boundery is something I don't understand).
All you'd have to do is insert your longer line, and put the control code FC at the end of it
(This will, of course, shorten the following line).
Here's a breakdown of some of the control codes:

FB=Line Break
FC=End of line
FD=Line Break + Pause for Input

Other codes:

F8=Player's Name
F1=Monster, as in "A <$F1> draws near!
F4=Monster's Name while you're fighting it
F5=Numerical Data: i.e., Damage amount, Stat increases at level up, etc.

Some of the information in the document can be handled directly by TownEdit and DW1MDE, other information is useful for doing things in conjunction with them.

Quote
And for enemy sprites it seems like a jumble of tiles in the rom, how did you replace those properly?

That's normal. You can either use a program like YY-CHR, Tile Layer Pro, etc to arrange tiles while editing or take the easy route and edit the graphics in NESticle (Which is what I did for my DW hacks).

Camerupt

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #5 on: April 13, 2016, 06:03:37 pm »
Sounds good, do you know what the limitations are for the enemy sprites before I ask my buddy to make them?

April 13, 2016, 07:19:27 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Also what's the deal with enemy groupings on the overworld map and in dungeons?
« Last Edit: April 13, 2016, 07:19:27 pm by Camerupt »

Sliver X

  • Hero Member
  • *****
  • Posts: 1085
  • der Wille zur Macht
    • View Profile
    • Panicus - A Fragment of Memory
Re: Dragon Warrior hacking help needed
« Reply #6 on: April 13, 2016, 08:50:41 pm »
Your first question would be answered by finding the tile definitions for each enemy, something covered in Section V of my document. I leave it up to you to find the enemies aside from the Red Slime example I wrote about. Going by my now ancient memories of DW's data structure, enemies should be stored in the order DW1MDE lists them as for this data.

Your second question is something I never learned about due to my lack of ROM hacking experience at the time I hacked Dragon Warrior.

You have a vast amount of information and some decent tools to start this endeavor with: You're in a perfect position to start learning how to ROM hack at a deeper level with this project.

If you have questions about things you're attempting to discover yourself I will be more than happy to help. Until then, I have offered everything I can to assist you.


« Last Edit: April 13, 2016, 09:12:05 pm by Sliver X »

zonk47

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #7 on: April 14, 2016, 03:29:48 am »
The zoning is an attribute of the enemies. There are a series of rectangular zones (defined as ranges) for each of these. I believe there are 16 such zones on the overworld map... there is a map available somewhere which describes the zones... it's on one of the DW fan sites or at Gamefaqs....

To redefine the zones, you'll have to find the ranges. The zone is recalculated at every step, so starting at the overworld map, step through the code (use FCEUX) until you find a series of branch instructions (they begin with J or B). Trace through these instructions, using breakpoints, until you find a "LD"-type instruction, particularly one involving a calculation. Expect two of these in a row, probably after an instruction that begins with "CM". Somewhere around these is an "LD" instruction which loads either the X or Y coordinate of the zone test (it's probably "LDY" or "LDX").
A good slave does not realize he is one; the best slave will not accept that he has become one.

VicVergil

  • Hero Member
  • *****
  • Posts: 727
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #8 on: April 14, 2016, 06:54:55 am »
The zone is recalculated at every step, so starting at the overworld map, step through the code (use FCEUX) until you find a series of branch instructions (they begin with J or B). Trace through these instructions, using breakpoints, until you find a "LD"-type instruction, particularly one involving a calculation. Expect two of these in a row, probably after an instruction that begins with "CM". Somewhere around these is an "LD" instruction which loads either the X or Y coordinate of the zone test (it's probably "LDY" or "LDX").

 :huh: :huh: :huh:

Why... If you're not sure beforehand, you're doing whoever you're misinforming a huge disservice. Not to mention how needlessly confusing your post is.

The X and Y coordinates have nothing to do with the "X" and "Y" the instructions LDX and LDY refer to.
X, Y, and A, are memory registers used extensively to move data around.
The X and Y (and while we're at it, Z for altitude) coordinates Dragon Quest in particular uses (and they may not exist at all in other games) are just regular ram values just like Loto's HP or whatever.

I don't know where you got the "two LDA in a row" thing from.
STA spits the contents of A (there's STX and STY for X and Y too) to whatever address needing to be changed.
The contents of A came from an LDA instruction before it, or from transfer instructions (copying A, X, Y contents to each other), or some logical operation (AND, OR, XOR...) or a PLA instruction pulling stuff from a memory area called the stack to dump it in the A register....
They don't need to be directly following each other.

The "CM- instruction" which can only be CMP since there's no other opcode beginning with CM,
has absolutely no relationship with LDA/STA instructions after it.

CMP compares two values: the one it takes as an argument written in front of the opcode, and whatever is stored in the A register (that stuff in A could have come from an LDA or transfer etc ...)
The branching instructions which begin with a B (and aren't BRK, the instruction telling the CPU to commit sudoku) takes the result of that comparison and if it satisfies their condition they go to a given address, else they just go to the next line.

Oh btw they're called branching because it's can branch in two possible outcomes depending on the outcome.
The jumping instructions (JMP/JSR..) and maybe BRA (branch always) have only one outcome and don't really qualify as branching.

I don't see how the "some sort of calculation" is a decisive factor in knowing which LDA instructions are relevant.
For the love of God, please practice what you preach.
Try getting your hand dirty with the stuff you're talking about to get more familiar about it.

dougeff

  • Sr. Member
  • ****
  • Posts: 358
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #9 on: April 14, 2016, 08:12:44 am »
I agree with GHANMI, please disregard zonk47s post as mostly gibberish. No offense.
« Last Edit: April 14, 2016, 08:20:02 am by dougeff »
nesdoug.com -- blog/tutorial on programming for the NES

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #10 on: April 14, 2016, 12:26:32 pm »
Note I haven't looked at the game and am making a LOT of assumptions in this post -- but this how I would intuitively expect the game to do this kind of thing:

=================

Final Fantasy had a 256x256 tile world... and it divided that world into an 8x8 grid of "domains" where each domain was assigned a group of enemies you could encounter.

It's a really simple thing to accomplish in code... and I can't help but think DW1 would do something similar, but I can't say for sure.

If looking for this data, the first thing I would do is figure out what numerical value is associated with what enemies.  Ex:

00 = Slime
01 = Red Slime
...etc

(note:  those numbers are just a guess).

This should be pretty easy to figure out, as it's almost certainly the same order as the enemy names are laid out in the ROM.

Once you have that, look at a guide or something to see how many different enemies can appear in a domain.  It's probably a power-of-2 size since those are easy to work with... for DW1 I'd guess it's 4.  (But again I'm guessing, it could be any number).  Then just Ctrl+F to search the ROM for one of the domains and see if you can find it.

Once you find that, you can change what enemies are assigned to what domains... but changing the SIZE of the domains is much more difficult and would probably involve a bit of code rewriting.

zonk47

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #11 on: April 14, 2016, 07:24:10 pm »
The formula is probably a loop which continually subtracts the size of the zone (32 tiles I think... 128x128 map) from the Y position of the player until CMP between these two is negative. A counter in the loop indicates the vertical component of the zone. Then the same is done with the X coordinate. I'd imagine most of the rest would be hardcoded stuff.

Seriously though this where you're better off moving your project to RPG maker or something. This is not a simple hack and DW uses all sorts of clever techniques to draw that map in spite of the NES' teensy weensy address space.
A good slave does not realize he is one; the best slave will not accept that he has become one.

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #12 on: April 14, 2016, 08:03:17 pm »
The formula is probably a loop which continually subtracts the size of the zone (32 tiles I think... 128x128 map) from the Y position of the player until CMP between these two is negative.

It almost certainly is just a series of right-shifts (LSRs) to chop off the low bits.  There likely isn't any subtraction or CMP involved.

I hate to jump on the bandwagon here zonk, but I urge you to not give asm advice until you learn more about asm. :-\   It's great that you want to help, but asm is hard enough for people to learn without having someone steer them in the wrong direction.

zonk47

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #13 on: April 14, 2016, 08:20:52 pm »
I am familiar with computer architecture and I've read most of the docs on these things. However I am indeed not familiar with the use of binary operations in the context of games. It would help if there was a good doc on these.
A good slave does not realize he is one; the best slave will not accept that he has become one.

VicVergil

  • Hero Member
  • *****
  • Posts: 727
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #14 on: April 14, 2016, 09:59:06 pm »
I'll try.
So, let's just assume editing the monster formation is good enough for you for now.
First of all you'll need to find the addresses in the RAM where the game stores the current monster formation.

I found this from some cheat site, for the DQ1 part of the DQ1+2 SNES compilation.
I think the values are probably the same for the NES version.

Quote
ドラゴンクエスト1 (DQ1 part)

7E0F2Bgg   
遭遇するモンスター変更   (current monster encounter)
ggは各種リストのモンスターリストを参照 (replace gg with a value from these lists)

gg=
00=
01=スライム (slime)
02=スライムベス
03=ドラキー
04=ゴースト
05=まほうつかい
06=メイジドラキー
07=おおさそり
08=メーダ
09=メトロゴースト
0A=ドロル
0B=ドラキーマ
0C=がいこつ
0D=まどうし
0E=てつのさそり
0F=リカント
10=しりょう
11=メタルスライム
12=ヘルゴースト
13=リカントマムル
14=メーダロード
15=ドロルメイジ
16=キメラ
17=しのさそり
18=しりょうのきし
19=ゴーレム
1A=ゴールドマン
1B=よろいのきし
1C=メイジキメラ
1D=かげのきし
1E=キラーリカント
1F=ドラゴン
20=スターキメラ
21=だいまどう
22=あくまのきし
23=キースドラゴン
24=ストーンマン
25=しにがみのきし
26=ダースドラゴン
27=りゅうおう(変身前)
28=りゅうおう(変身後)
29=


Well... that was useless considering we have a datacrystal page for DQ1 NES with a rom map for the NES version.
Still, if you ever felt like hacking the SNES version instead you could give it a try.

Quote
RAM MAP:
0x00e0   
Terrain / Enemy pointer
In battle, is a pointer to the current enemy type.
Out of battle, is a pointer to the current terrain type. Enemy list below.

Enemy IDs:
00 = slime
01 = red slime
02 = drakee
03 = ghost
04 = magician
05 = magidrakee
06 = scorpion
07 = druin
08 = poltergeist
09 = droll
0a = drameema
0b = skeleton
0c = warlock
0d = metal scorpion
0e = wolf
0f = wraith
10 = metal slime
11 = specter
12 = wolflord
13 = druinlord
14 = drollmagi
15 = wyvern
16 = rogue scorpion
17 = wraith knight
18 = golem
19 = goldman
1a = knight
1b = magiwyvern
1c = demon knight
1d = werewolf
1e = green dragon
1f = starwyvern
20 = wizard
21 = axe knight
22 = blue dragon
23 = stoneman
24 = armored knight
25 = red dragon
26 = dragonlord form 1
27 = dragonlord form 2 * setting this outside of battle will freeze all NPCs, make movement impossible, black out parts of the screen, etc.

You simply need to set a write breakpoint on this address 00E0, and keep the trace logger window open, and you'll get what exactly changed it.

Chances are outside of battle it will break constantly as you walk (it's tied to the terrain type after all) so use it just before a random encounter because that's the change you're actually interested in.
You could give the "conditional breakpoints" article at baddesthacks a read too if you find that a nuisance.

I never played the NES original, just the rereleases, and I'm stuck in the beginning under leveled so I couldn't test this as much as I'd have liked before posting this (a mandatory boss battle would be the ideal place to test it).
That,
and the breakpoint triggering with each step. And what's worse is that I can't just put a breakpoint eliminating cases where the accumulator gets the value 00 (regular ground type) because that value happens to be the slime's too.
and last but not least I f'ing hate the controls more than anything else I have ever had the misfortune of playing (no offense).

If it can help in any way, this is the instruction updating the "terrain type" with each step Loto makes:
00:CDB0:A5 3C     LDA $003C = #$00
00:CDB2:85 E0     STA $00E0 = #$00
It's NOT the one you're after. (unless you felt like making the whole game world a swampy hell)

You want the instructions triggering just before an encounter (and the encounters are truly randomized here, not just a simple counter like other RPGs like DQ6 SFC/TMZ/MM:R... so forcing an encounter isn't as easy as I've wanted here - maybe looking at TAS'ers findings could help?)

Just try doing a trace combined with this breakpoint when there's an encounter, and figure out where it's pulled from in the ROM.

Right before an encounter with a slime (value 00), breakpoints trigger here:
00:E4DF:85 E0     STA $00E0 = #$00
and
00:E509:85 E0     STA $00E0 = #$00
and
00:E50F:85 E0     STA $00E0 = #$00
and
00:E532:A9 00     LDA #$00
00:E534:85 E0     STA $00E0 = #$00
and
00:E539:68        PLA
00:E53A:85 E0     STA $00E0 = #$00

Testing with another enemy should certainly give better results.

Camerupt

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: Dragon Warrior hacking help needed
« Reply #15 on: April 16, 2016, 04:38:00 pm »
Thank you for helping me figure it out a bit, things are going well and text hacking has been easy enough, everything else should be okay to do, i have friends who know a bit more about this sort of stuff if i need more help with breakpoints and such.