AW2 Unit attack stat locations

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

AW2 Unit attack stat locations

Post by RenegadePenguin » Sat May 07, 2016 8:06 am

Hi there! I'm new to AW2 hacking but I'm an experienced coder. I'm having trouble finding where the units' attack stats are. For example: Infantry vs Infantry = 55%. Where is that attack value stored in memory? I tried loading up the Nightmare 2 tool and opened the unit .nmm file, but that file only has references to the unit's vision, fuel, etc.

A memory address would be enough to get me started on this, although more info (like the data structure layout) of the weapon stats would be helpful too!

Thanks. :)

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

Re: AW2 Unit attack stat locations

Post by Xenesis » Sat May 07, 2016 11:41 am

It's only ever stored in the ROM and basically just retrieved when required for damage calculations.

Each entry of unit data is 0x5C long, the firepower entries start at +0x1E for primary weapons and +0x38 for secondary weapons. The format is one byte per target, sorted by unit ID. A value of 0 means it is an invalid target, otherwise a value of 1-254% is a valid number.

You've got the NMM, you can use the offset from the "Unit Name" entry, as that's the first item in the data format (it displays the offset as a mouseover). The table starts at 0x(08)5D5B18 in the ROM.

As for the data structure? I'm working on some ASM macros for it, but it describes the structure pretty well of each entry:

Code: Select all

	;text ID for name
	.macro setUnitName,UnitID, textID
		.org 	UnitDataTable + (UnitID-1)*0x5C + 0
		.dh	textID
	.endmacro
	
	.macro setUnitUnknown,UnitID,Offset,Length,Value
		.org 	UnitDataTable + (UnitID-1)*0x5C + Offset
		.if Length == 1
		.db	Value
		.endif
		.if Length == 2
		.dh	Value
		.endif
		.if Length == 4
		.dw	Value
		.endif
	.endmacro
	
	;text ID for primary
	.macro setUnitPrimaryName,UnitID,textID
		.org 	UnitDataTable + (UnitID-1)*0x5C + 2
		.dh	textID
	.endmacro

	;text ID for name
	.macro setUnitSecondaryName,UnitID, textID
		.org 	UnitDataTable + (UnitID-1)*0x5C + 4
		.dh	textID
	.endmacro

	;Unit Price per HP
	.macro setUnitPrice,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 6
		.dh	EntryValue
	.endmacro

	;Movement
	.macro setUnitMove,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 10
		.db	EntryValue
	.endmacro

	;Ammo
	.macro setUnitAmmo,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 11
		.db	EntryValue
	.endmacro

	;Vision
	.macro setUnitVision,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 12
		.db	EntryValue
	.endmacro

	;Minimum Range
	.macro setUnitMinRange,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 14
		.db	EntryValue
		.if EntryValue > 1
			.org 	UnitDataTable + (UnitID-1)*0x5C + 17
			.db	BButtonIndirect
		.elseif EntryValue == 0
			.org 	UnitDataTable + (UnitID-1)*0x5C + 17
			.db	0
		.else
			.org 	UnitDataTable + (UnitID-1)*0x5C + 17
			.db	BButtonDirect
		.endif
	.endmacro

	;Max Range
	.macro setUnitMaxRange,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 15
		.db	EntryValue
	.endmacro

	;Fuel
	.macro setUnitFuel,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 16
		.db	EntryValue
	.endmacro

	;Transport Ability
	.macro setUnitTransport,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 20
		.dw	EntryValue
	.endmacro

	;Unit Class
	.macro setUnitClass,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 24
		.db	EntryValue
	.endmacro

	;Movement
	.macro setUnitMoveType,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 25
		.db	EntryValue
	.endmacro

	;Build Location
	.macro setUnitBuildLocation,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 26
		.db	EntryValue
	.endmacro

	;AI Type
	.macro setUnitAIType,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 27
		.db	EntryValue
	.endmacro

	;AI Preferential Targeting
	.macro setUnitAIPriorityTarget,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 28
		.db	EntryValue
	.endmacro

	;AI Unit Classification
	.macro setUnitAIUnitClass,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 29
		.db	EntryValue
	.endmacro

	;Weapon Damage
	.macro setUnitDamagePrimary,UnitID,Damage,TargetedID
		.org 	UnitDataTable + (UnitID-1)*0x5C + 30 + TargetedID
		.db	Damage
	.endmacro

	;Weapon Damage
	.macro setUnitDamageSecondary,UnitID,Damage,TargetedID
		.org 	UnitDataTable + (UnitID-1)* 0x5C + 56 + TargetedID
		.db	Damage
	.endmacro

	;Terrain Supplied On
	.macro setUnitSupplyTerrain,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)* 0x5C + 84 
		.dw	EntryValue
	.endmacro

	;Fuel Used On
	.macro setUnitFuelBurn,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)* 0x5C + 88
		.dw	EntryValue
	.endmacro

	;Range Display
	.macro setUnitBRangeDisplay,UnitID,EntryValue
		.org 	UnitDataTable + (UnitID-1)*0x5C + 17
		.db	EntryValue
	.endmacro
IST wrote:Even the worst individual needs to discover the joys of a chicken statue that is also a pregnant blonde housewife.

RenegadePenguin

Re: AW2 Unit attack stat locations

Post by RenegadePenguin » Tue May 10, 2016 4:26 am

Nice! I'll give this a shot when I get home. Thanks, Xenesis! :D

Who is online

Users browsing this forum: Multivac [Bot], onewaystreet, Thieves Guild [Bot] and 0 guests