Lab into Com Tower Patch with a Tutorial

Discussion of hacking, editing and developments in Advance Wars games.
Remember, no Rom Requests
Post Reply
Taelith

Lab into Com Tower Patch with a Tutorial

Post by Taelith » Fri Apr 18, 2014 6:11 am

Here is my Turning Labs into Com Towers Patch. Right now it makes use of the Temp Attack Bonus location, it does not take into account PoM. Will add that at another time.

I will also post a tutorial on thumb/asm for how I did this.

Three thumb codes have to be changed in order to make this work. 1 is removing the forced animation/victory condition set for the Lab property. 2 is updating RAM with a count on Labs the current player owns. And 3 is load into temp attack an attack value dependent on the number of Labs the current player owns. This should also update every time Lab changes ownership or a new map is initialized.

Here is the important snippet for the first part (original code).

Code: Select all

1. 08042724 231F     mov r3,#0x1F
2. 08042726 403B     and r3,r7
3. 08042728 2B08     cmp r3,#0x8
4. 0804272A D001     beq #0x08042730
5. 0804272C 2B14     cmp r3,#0x14
6. 0804272E D131     bne #0x08042794
7. 08042730 4916     ldr r1,#0x0804278C
line 1: r3 is set to a hex value that is used to do a bit mask to check if the terrain is a certain tile ID.
line 2: the and does the bitmask, r7 holds the tile being compared.
line 3: cmp compares the result of the mask with #0x8 which is the ID for the HQ tile.
line 4: beq is branch if the previous compare is true, the branch goes to line 7. Check the Address after the beq, this equals the address being jumped to.
line 5: if the cmp in line 3 is false the code continues here. the next compare, checks with #0x14 which is the ID for Lab tiles.
line 6: if neither compares return true then the code jumps to #0x08042794 (we wont worry about this location).
line 7: ldr r1#=, loads an offset into r1. This offset will be used to force display capture animation.

Code: Select all

1. 08042724 231F     mov r3,#0x1F
2. 08042726 403B     and r3,r7
3. 08042728 2B08     cmp r3,#0x8
4. 0804272A D001     beq #0x08042730
5. 0804272C E032     b #0x08042794
6. 0804272E 0000     nop
7. 08042730 4916     ldr r1,#0x0804278C
lines 5 and 6 are changed so that labs don't force capture animation. b # jumps the code to the same address that the original line 6 did. this bypassing any check done against the Lab property.
line 6 is nopped so that the offsets are still alined for the branches that are relative.

Here is the original code for team defeat when certain properties are captured.

Code: Select all

08042816 201F     mov r0,#0x1F
08042818 4038     and r0,r7
0804281A 2808     cmp r0,#0x8
0804281C D001     beq #0x08042822
0804281E 2814     cmp r0,#0x14
08042820 D108     bne #0x08042834
08042822 480E     ldr r0,#0x0804285C
What needs to be changed here to remove this condition for our lab tiles?

Update to v3. Note that this is prepatched with Xen's Defense Patch and Lambda's Default COP Boost over that. Unit Stat screen correctly shows the boost from labs. Bonus from labs retained after turn finishes, and PoM and Default global effects are working properly.
Attachments
AW2 - Towers into Labs v3.zip
(701 Bytes) Downloaded 36 times
Last edited by Taelith on Sat Apr 19, 2014 2:12 pm, edited 3 times in total.

Taelith

Re: Lab into Com Tower Patch with a Tutorial

Post by Taelith » Fri Apr 18, 2014 6:40 am

Part II (Updating Property count for Labs)

Surprisingly the code already exist that counts up the number of Labs exist for each player.

Code: Select all

08026E84 1C10     mov r0,r2
08026E86 F7FFFEF1 bl #0x08026C6C
08026E8A 68A1     ldr r1,[r4,#0x2]
08026E8C 1809     add r1,r1,r0
08026E8E 60A1     str r1,[r4,#0x2]
08026E90 7C20     ldrb r0,[r4,#0x10]
08026E92 3001     add r0,#0x1
08026E94 7420     strb r0,[r4,#0x10]
08026E96 E01C     b #0x08026ED2
So why doesn't the number of Labs owned for each player show up on RAM? Really simple actually. The code that initializes the count for each property that is run and the beginning of this code segment does not account for Labs therefore the number shown in RAM does not reflect the actual Lab count.

Here is the code in question.

Code: Select all

08026D78 2300     mov r3,#0x0
08026D7A 2200     mov r2,#0x0
08026D7C 2680     mov r6,#0x80
08026D7E 2504     mov r5,#0x4
08026D80 6820     ldr r0,[r4]
08026D82 1810     add r0,r2,r0
08026D84 6083     str r3,[r0,#0x2]
08026D86 7303     strb r3,[r0,#0xC]
08026D88 6820     ldr r0,[r4]
08026D8A 1810     add r0,r2,r0
08026D8C 7343     strb r3,[r0,#0xD]
08026D8E 6820     ldr r0,[r4]
08026D90 1810     add r0,r2,r0
08026D92 7383     strb r3,[r0,#0xE]
08026D94 6820     ldr r0,[r4]
08026D96 1810     add r0,r2,r0
08026D98 73C3     strb r3,[r0,#0xF]
08026D9A 6821     ldr r1,[r4]
08026D9C 1851     add r1,r2,r1
08026D9E 312D     add r1,#0x2D
08026DA0 7808     ldrb r0,[r1]
See the lines with strb r3,[r0,#0x??]. These lines saves to the RAM location where the property counts are kept. r0 is updated to match the current player and their space in RAM. The ?? is the offset from the r0 offset to save to. strb is the code to store the byte in r3 to the Offset r0+#0x??. The first line mov r3,#0x0 initializes r3 with a 0 value. This is what the property counts are set to before actually starting the count.

#0xC = Base Count, #0xD = City Count, #0xE = Airport Count, #0xF = Port Count. We just need to add in an initial value for Labs. In the previous code snipet we saw a ldrb r0,[r4,#0x10] and a strb r0,[r4,#0x10]. The r4+#0x10 is the location in RAM for the owned labs count.

Fortunately for us there is quite a bit redundancy here which will allow us to compress the code and make room for some new code. The two lines "ldr r0,[r4]" and "add r0,r2,r0" are repeated for each property type listed here. We really only need to run this once since we are using [r,#] to offset from one address.

Here is lines 6-17 (12 lines) reduced to 6 lines

Code: Select all

08026D82 1810     add r0,r2,r0
08026D84 6083     str r3,[r0,#0x2]
08026D86 7303     strb r3,[r0,#0xC]
08026D88 7343     strb r3,[r0,#0xD]
08026D8A 7383     strb r3,[r0,#0xE]
08026D8C 73C3     strb r3,[r0,#0xF]
And to initialize for Labs we just add this line after the condensed code.

Code: Select all

08026D8E 7403     strb r3,[r0,#0x10]
To be continued...

Taelith

Re: Lab into Com Tower Patch with a Tutorial

Post by Taelith » Fri Apr 18, 2014 7:18 am

Part III (Adding in the Damage Boost)

To make this a little easier, we insert the new code where the number of owned labs are update so that when it updates, the damage boost is updated at the same time. And unlike before there isn't any room to fit the new code so we have to to insert a code jump to a new location.

Code: Select all

08026E84 1C10     mov r0,r2
08026E86 F7FFFEF1 bl #0x08026C6C
08026E8A 68A1     ldr r1,[r4,#0x2]
08026E8C 1809     add r1,r1,r0
08026E8E 60A1     str r1,[r4,#0x2]
08026E90 7C20     ldrb r0,[r4,#0x10]
08026E92 3001     add r0,#0x1
08026E94 7420     strb r0,[r4,#0x10]
08026E96 E01C     b #0x08026ED2
So here is the code from part II that we are going to modify. and here is the modified code below.

Code: Select all

08026E84 1C10     mov r0,r2
08026E86 F7FFFEF1 bl #0x08026C6C
08026E8A 68A1     ldr r1,[r4,#0x2]
08026E8C 1809     add r1,r1,r0
08026E8E 60A1     str r1,[r4,#0x2]
08026E90 4800     ldr r0,#0x08026E94
08026E92 4700     bx r0
08026E94 00010870 :=#0x08700001
ldr r0,#0x08026E94 will load an offset into r0 from "#0x08026E94" this location and bx r0 will jump the code to the new location. #0x08700001 is the location of the new code. The 1 at the end is to keep things in thumb mode.

Before we go into the new code we have to update the initializer to set the temp attack boost value to 0 each time the property count code is initiated.

Code: Select all

08026D82 1810     add r0,r2,r0
08026D84 6083     str r3,[r0,#0x2]
08026D86 7303     strb r3,[r0,#0xC]
08026D88 7343     strb r3,[r0,#0xD]
08026D8A 7383     strb r3,[r0,#0xE]
08026D8C 73C3     strb r3,[r0,#0xF]
08026D8E 7403     strb r3,[r0,#0x10]
08026D90 84C3     strh r3,[r0,#0x26]
The last line here saves 0 at r0,#0x26 this location in RAM which is the location of the temp attack boost.

Finally the last code snipet.

Code: Select all

08700000 7C20     ldrb r0,[r4,#0x10]
08700002 3001     add r0,#0x1
08700004 7420     strb r0,[r4,#0x10]
08700006 8CE0     ldrh r0,[r4,#0x26]
08700008 300A     add r0,#0xA
0870000A 84E0     strh r0,[r4,#0x26]
0870000C 4800     ldr r0,#0x08700010
0870000E 4700     bx r0
08700010 6ED30802 :=#0x08026ED3
The first 3 lines are code we moved from part II in order to make room for the new function call. "ldrh r0,[r4,#0x26]" This loads the value (ldrh is for loading half-words) at the temp attack boost RAM location. The next line "add r0,#0xA" adds 10 to r0 (hex value 0xA). This is what provides 10% attack boost per lab owned. "strh r0,[r4,#0x26]" saves this new value back into RAM. and finally the last two lines jump back execution to the original code location.

Tutorial Complete!

You will need Xen's Defense Patch in order to see the Temp Attack Boost show up in the Unit Stats screen. Colin's PoM is broken since that also uses the Temp attack boost RAM location and we didn't take that into account r any other mod that uses that RAM location.

Lambda

Re: Lab into Com Tower Patch with a Tutorial

Post by Lambda » Fri Apr 18, 2014 7:33 am

That's really nice from you to make some tutorials, nice job Taelith.

I haven't read everything, but I don't understand why you don't just load the temp firepower bonus, add whatever attack bonus you calculated, and re-insert it into RAM. This way, you'll keep already existant bonusses stored in this location.

Taelith

Re: Lab into Com Tower Patch with a Tutorial

Post by Taelith » Fri Apr 18, 2014 7:55 am

Thanks. It's because of where this code is inserted. It will run every time a property change occurs and then it will be iterated for each property owned. Originally I had inserted it where the temp bonus is added to the damage formula. Which worked but did not display on the unit stat screen. This is a temporary measure until I can get that working with the unit stat screen. So still a WIP. but I have so many other things I want to try before I probably come back to this.

Lambda

Re: Lab into Com Tower Patch with a Tutorial

Post by Lambda » Fri Apr 18, 2014 8:21 am

What you can do then is hooking the code when the routine finishes counting how many labs the player owns. Then you load the temp firepower bonus, you remove the old "com tower" attack bonus and you add the new one.

Also, that's a long time I haven't played with temp firepowers, but iirc it is reset each turn, so if there is no capture a turn the temp firepower will stay at 0 without being updated. You'll have to correct that.

User avatar
Xenesis
Tri-Star CO
Tri-Star CO
Rank: Hydrocarbon Inspector
3DS Code: 2535-4646-7163
Location: 0x020232DD
Contact:

Re: Lab into Com Tower Patch with a Tutorial

Post by Xenesis » Fri Apr 18, 2014 4:24 pm

Lambda wrote:Also, that's a long time I haven't played with temp firepowers, but iirc it is reset each turn, so if there is no capture a turn the temp firepower will stay at 0 without being updated. You'll have to correct that.
Yeah, that's correct. As part of the start of turn upkeep, the value in that field is zeroed.
Taelith wrote:Which worked but did not display on the unit stat screen.
Annoyingly enough, the original version of the game's stat screen will only ever consider the base firepower boost that a CO has. Hence why things like Colin's Power of Money don't show up in it. Trust me, the original code for those stat screens is really, really crappy. It won't even take value ranges - it only displays values that are absolutely -30/-20/-10/0/+10/+15/+20/+30/+40/+50/+60/+75.
IST wrote:Even the worst individual needs to discover the joys of a chicken statue that is also a pregnant blonde housewife.

Lambda

Re: Lab into Com Tower Patch with a Tutorial

Post by Lambda » Fri Apr 18, 2014 4:32 pm

Code: Select all


Annoyingly enough, the original version of the game's stat screen will only ever consider the base firepower boost that a CO has. Hence why things like Colin's Power of Money don't show up in it. Trust me, the original code for those stat screens is really, really crappy. It won't even take value ranges - it only displays values that are absolutely -30/-20/-10/0/+10/+15/+20/+30/+40/+50/+60/+75.

Game's code isn't the problem here, since Taelith uses your defense display patch that can display temp values, though defense value is taken one bit too early (Corrected it in some St3rn's topic below).
Last edited by Lambda on Fri Apr 18, 2014 4:44 pm, edited 3 times in total.

User avatar
Xenesis
Tri-Star CO
Tri-Star CO
Rank: Hydrocarbon Inspector
3DS Code: 2535-4646-7163
Location: 0x020232DD
Contact:

Re: Lab into Com Tower Patch with a Tutorial

Post by Xenesis » Fri Apr 18, 2014 4:34 pm

Ah, can you make a note of that in its topic?

That way I can remember to actually fix it. And yeah, if you want more graphics ranges, you'd have to design custom graphics and play with the tiles. The way they're loaded into RAM means that you can't really have many more than are currently already there but you could redefine a few.
IST wrote:Even the worst individual needs to discover the joys of a chicken statue that is also a pregnant blonde housewife.

Taelith

Re: Lab into Com Tower Patch with a Tutorial

Post by Taelith » Fri Apr 18, 2014 10:00 pm

Thanks for the input. Alright reverted the code to load the temp value, do the labs count calc thing and then reinsert back into temp value. This occurs in the damage formula when temp attack boost is obtained. So now PoM is working and you retain the tower boost on turns with no capture, etc. Only thing not working now is the boost from lab showing up on the unit stat screen. Since that is just a graphical thing, I will leave this how it is until I come back to it later.

I also did a mod on your code Xen for the unit stat screen with some graphics modded to match.
so now the new values are in intervals of 10 from -30 up to +90 (-30,-20,-10,0,+10,+20,+30,+40,+50,+60,+70,+80,+90).

Taelith

Re: Lab into Com Tower Patch with a Tutorial

Post by Taelith » Sat Apr 19, 2014 2:12 pm

Update to v3. Note that this is prepatched with Xen's Defense Patch and Lambda's Default COP Boost over that. Unit Stat screen correctly shows the boost from labs. Bonus from labs retained after turn finishes, and PoM and Default global effects are working properly.

Post Reply

Who is online

Users browsing this forum: Kim Jong-un [Bot] and 1 guest