So here's an improved version of the previous script. This one fixes the oversized minimap projection, properly locates all of the units on the map, successfully identifying which are your own, gives units their proper clan colour, draws proper sized boxes around them, gives a tidier information box, and has far more decoded info.
Download War2.LuaLanguage: Lua
--[[Each Map entity takes up 0x9C=156 blocks, and count DOWN from the Offset Location.
Here are decoded values:
-00 X Coord, each square treated as 32x32.
-02 Y Coord, same as X.
-04 increases by +5 +4 Mod 54, don't know why.
-06 Existence? 0=yes, 16=In training? 32=no, 48=Dead, or skeleton? Seems to keep changing to 32 while alive though, weird.
-08 Animation: 2=stop, 3=move, 4=attack.
-09 Animation frame
-10 Direction, 0=N, 1=NE, 2=E, ...., 7=NW.
-12 Graphic displacement (Y), used for sea/air units, which bob up
and down periodically thus alternating 0, 1.
-13 Graphic Displacement (Y) Timer. Controls when to bob.
-16 X Coord, each square being 1x1
-18 Y Coord.
-20 Movement type. 0=Land, 6=Flying, 8=Transport on Coast, 10=Ship.
Dictates where/how unit travels. IE Flying creatures move 2
squares at a time. Also affects their shadow on ground.
-22 Possible to select. 128=Yes, 136=No.
-23 Selected: 0=No, 1=Building<50%, 32=Yes, 64=issued command, 128=selected by enemy.
These values get added to each other.
-26 HP
-28 Countdowns from 200 when attacking/attacked. Possible RNG?
-29 Unit Type. See values below, this merely controls actions available to it.
-30 Mana. Also functions as construction/upgrade progress (0-256).
Also, summoned units use Mana as duration countdown.
-31 Unit Stats. Uses same values as Unit Type, but this changes Unit's Portrait Icon/stats etc.
-32 Visiblity: 0=Yes, 1=Inside another Unit, 2=No
-35 Unit Graphic. Uses same values as Unit Type, but a few extra
values for 'peon with lumber' etc.
-36 Owner. Players 0-7, 15 if just critter/GM etc
-37 Clan Colour. 0-7. IE a player may control another clan
-38 Current Action. See below tables
-39 Next upcoming Action.
-40 Route Plan. 40-59 shows the upcoming path a unit takes, using
values 0-7 to desribe the direction to travel after taking
each step. Directions will be -1 if unused, and if path is more
than 20 steps these values will update themselves, according to
Step Counter below.
-59 End of Route Plan.
-60 Invisibility Timer
-62 Unholy Armour Timer
-64 Bloodlust Timer
-66 Slow/Haste Timer. Haste starts positive value, Slow starts negative,
both countdown to 0.
-70 Flame Shield Timer
-72 Targetted by somebody? 0=No 7=Yes. Doesn't reset at all?
-73 Attack countdown? 0 by default, quickly decreases from 31 after somebody targets attack?
-76-80 Change to bloody weird values when under attack. No clue why.
-100 Next Patrol X. Previous location to patrol back to.
-102 Next Patrol Y. Updates after each journey. Also functions as Tower Upgrade progress.
-104 Start of Personal Info. See data below
-115 End of Personal info
-134 Step Counter. 20 by default, keeps counting down to 0, on when to update
Route Plan.
-138 Gold inside GM.
-142 Destination X Coord. Not subsquare values, each square treated as 1x1.
-144 Destination Y Coord.
-Unit Types. Also shares same values for graphic/stats.
-0 Footman
-1 Grunt
-2 Peasant
-3 Peon
-4 Ballista
-5 Catapult
-6 Knight
-7 Ogre
-8 High Elven Archer
-9 Axe Thrower
-10 Mage
-11 DK
-12 Paladin
-13 Ogre-Mage
-14 Dwarf Demolishen Squad
-15 Sappers
-16 Alterac Traitors
-17 Useless Peons (Horde equiv of traitors?)
-18 High Ranger
-19 Beserker
-20 Alleria
-21 Teron Gorefiend
-22 Kurdran And Sky'ree
-23 Dentarg
-24 Khadgar
-25 Grom Hellscream
-26 Oil Tanker
-27 Oil Tanker
-28 Transport
-29 Transport
-30 Elven Destroyer
-31 Troll Destroyer
-32 Battleship
-33 Juggernaut
-35 Deathwing
-38 Gnomish Submarine
-39 Giant Turtle
-40 Flying Machine
-41 Zeppelin
-42 Gryphon Rider
-43 Dragon
-44 Turalyon
-45 Eye of Killrog
-46 Danath
-47 Korgath Bladefist
-49 Cho'gall
-50 Lord Lothar
-51 Gul'Dan
-52 Uther Lightbringer
-53 Zul'jin
-55 skeleton
-56 Daemon
-57 Critter
-58 Farm
-59 Pig Farm
-60 Barracks
-61 Barracks
-62 Church
-63 Altar of Storms
-64 Watch Tower
-65 Watch Tower
-66 Stables
-67 Ogre Mound
-68 Gnomish Inventor
-69 Goblin Alchemist
-70 Gryphon Aviary
-71 Dragon Roost
-72 Shipyard
-73 Shipyard
-74 Town Hall
-75 Great Hall
-76 Elven Lumber Mill
-77 Troll Lumber Mill
-78 Foundry
-79 Foundry
-80 Mage Tower
-81 Temple of the Damned
-82 Blacksmith
-83 Blacksmith
-84 Oil Refinery
-85 Oil Refinery
-86 Oil Platform
-87 Oil Platform
-89 Keep
-89 Stronghold
-90 Castle
-91 Fortress
-92 Gold Mine
-93 Oil Patch
-96 Guard Tower (IE non upgraded, was like this originally)
-97 Guard Tower (IE was already upgraded at start)
-98 Cannon Tower
-99 Cannon Tower
-100 Circle of Power
-101 Dark Portal
-102 Runestone
-103 Wall
-104 Wall
-105 Corpse
-106 Flame
-107 2x2 Rubble
-108 3x3 Rubble
-109 3x3 Rubble
-110 Peasant with Lumber
-111 Peon with Lumber
-112 Peasant with Gold
-113 Peon with Gold
-114 Full Oil Tanker (A)
-115 Full Oil Tanker (H)
-116 Construction site part 1+2
-117 Construction site/Upgrading or Researching Building
-118 Contruction (H)
-Further values used for progressive construction graphics, but cba finding all.
-Current Actions:
0=Not Existing, 1=dieing, 2=stop, 3=move, 4=Flying 5=patrol, 6=Catching up to follow 7=follow, 9=attack
12=Attacking during patrol, 13=stand ground, 14=Idle Tower, 17=Attack Ground
20=Demolish, 22=In construction, 23=harvest, 24=return goods, 27=repair, 28=going to build
30=Moving to coast, 32=Waiting on coast, 33=Idle building, 34=Going into Transport, 36=In transport, 37=Upgrading/Researching/Training, 38=Holy Vision, 39=Heal
41=Exorcism 42=Fire Shield, 43=Fireball, 44=Slow, 45=Invis, 46=Polymorph, 47=Blizzard, 48=Eye of Kilrog, 49=Bloodlust
50=Raise Dead, 51=Death Coil, 52=Whirlwind, 53=Haste, 54=Unholy Armour, 55=Runes, 56=DnD
-Personal Info. 104-115.
-Transport units: Six pairs of 2 bytes, for type/size? of unit.
First byte: 87-Item number
Second byte: -1=Empty, 1=1x1 unit, 2=2x2 unit? Repeat 6 times.
-Mana Units: 105 functions as Mana Regenation timer
-Peasants: 104-107 Go weird inside GM.
108 Chop Count for peasants/peons
109 88=Returning LM inside building, 90=Chopping, 120=with Lumber, lots of weird values.
-Towers: 105 Upgrade Status
106
-Obviously more for other units, but don't care.]]--
while true do
Start=0x011EBF8
Sz=0x9C
MpSz=memory.readbyte(0x01031E) --Map size, each square treated as 1x1
XCa=memory.readwordsigned(0x1616D8)
YCa=memory.readwordsigned(0x1616DC)
Player=memory.readbyte(0x010328)
keys = {}
last_keys = {}
clickhappen = false
keys = input.get()
emu.frameadvance()
for i= 0,400,1 do
XC=memory.readword(Start-i*Sz)
YC=memory.readword(Start-i*Sz+2)
Ex=memory.readbyte(Start-i*Sz+6)
HP=memory.readbyte(Start-i*Sz+26)
Ty=memory.readbyte(Start-i*Sz+29)
Pl=memory.readbyte(Start-i*Sz+36)
CC=memory.readbyte(Start-i*Sz+37)
Xd=memory.readword(Start-i*Sz+140)*32
Yd=memory.readword(Start-i*Sz+142)*32
An=memory.readbyte(Start-i*Sz+38)
Cx=XC-XCa
Cy=YC-YCa
Cxd=Xd-XCa
Cyd=Yd-YCa
Xm=XC/(MpSz*32)*63 --X minimap. Divide by total Map Size, then stretch to size of minimap, 63x63.
Ym=YC/(MpSz*32)*63 --Y minimap.
if Pl == 0 then PlC = 'red' --Player colours.
elseif Pl == 1 then PlC = 'blue'
elseif Pl == 2 then PlC = 'cyan'
elseif Pl == 3 then PlC = 'purple'
elseif Pl == 4 then PlC = 'orange'
elseif Pl == 5 then PlC = 'red' --Player 5 is Black, but draw Red on map instead.
elseif Pl == 6 then PlC = 'white'
elseif Pl == 7 then PlC = 'orange'
else PlC ='white'
end
if Ty < 4 then size = 15 --Trying to draw appropriate size boxes around stuff.
elseif Ty < 6 then size = 31 --But their graphic size, and space occupancy on map don't neccesarily match.
elseif Ty < 8 then size = 21 --EG Ogres classed as 1x1, yet graphic is nearly 2x2, so script
elseif Ty == 8 then size = 17 --also needs some displacement on box for certain units.
elseif Ty == 9 then size = 18
elseif Ty == 10 then size = 17
elseif Ty == 11 then size = 19
elseif Ty < 14 then size = 21
elseif Ty == 14 then size = 16
elseif Ty == 15 then size = 19
elseif Ty < 18 then size = 15
elseif Ty == 18 then size = 17
elseif Ty == 19 then size = 18
elseif Ty == 20 then size = 17
elseif Ty == 21 then size = 19
elseif Ty == 22 then size = 31
elseif Ty == 23 then size = 21
elseif Ty == 24 then size = 17
elseif Ty == 25 then size = 15
elseif Ty < 32 then size = 31
elseif Ty < 36 then size = 35
elseif Ty < 43 then size = 31
elseif Ty == 43 then size = 35
elseif Ty == 44 then size = 21
elseif Ty < 48 then size = 15
elseif Ty < 49 then size = 22
elseif Ty < 51 then size = 21
elseif Ty == 51 then size = 17
elseif Ty == 52 then size = 21
elseif Ty == 53 then size = 18
elseif Ty < 58 then size = 15
elseif Ty < 60 then size = 31
elseif Ty < 64 then size = 47
elseif Ty < 66 then size = 31
elseif Ty < 74 then size = 47
elseif Ty < 76 then size = 63
elseif Ty < 88 then size = 47
elseif Ty < 92 then size = 63
elseif Ty < 94 then size = 47
elseif Ty < 101 then size = 31
elseif Ty == 101 then size = 63
elseif Ty == 102 then size = 31
else size = 47
end
if Ty < 4 then DV = 0 --Displacement Values, since not every graphic
elseif Ty < 6 then DV = 8 --appears on the top left corner of the square.
elseif Ty < 8 then DV = 3 --so need to shift it along a bit.
elseif Ty == 8 then DV = 1
elseif Ty == 9 then DV = 2
elseif Ty == 10 then DV = 1
elseif Ty == 11 then DV = 2
elseif Ty < 14 then DV = 3
elseif Ty == 14 then DV = 1
elseif Ty == 15 then DV = 2
elseif Ty < 18 then DV = 0
elseif Ty == 18 then DV = 1
elseif Ty == 19 then DV = 2
elseif Ty == 20 then DV = 1
elseif Ty == 21 then DV = 2
elseif Ty == 22 then DV = 8
elseif Ty == 23 then DV = 3
elseif Ty == 24 then DV = 1
elseif Ty == 25 then DV = 0
elseif Ty < 32 then DV = 8
elseif Ty < 36 then DV = 10
elseif Ty < 42 then DV = 8
elseif Ty == 42 then DV = 8
elseif Ty == 43 then DV = 10
elseif Ty == 44 then DV = 3
elseif Ty < 48 then DV = 0
elseif Ty < 51 then DV = 3
elseif Ty == 51 then DV = 1
elseif Ty == 52 then DV = 3
elseif Ty == 53 then DV = 2
else DV = 0
end
if (Pl ~= Player) and (An ~=0) then --Reveal non-player stuff only, and those which actually exist...
gui.drawbox(Cx/2-DV, Cy/2-DV, Cx/2-DV+size, Cy/2-DV+size,white,PlC) --Lua equivalent size box is 16x16, thus need /2, then translate along by DV.
gui.drawbox(17+Xm, 33+Ym, 18+Xm, 34+Ym, PlC)
end
if clickhappen == true then --Hmmm, have to do all calculations a 2nd time? Can't just reference previous ones? Stupid Lua stuff.
gui.drawbox(230,20,275,65,'black','white')
gui.text(233, 22, "Item: "..item,'white')
gui.text(233, 32, "Type: "..memory.readbyte(Start-item*Sz+29) ,'white');
gui.text(233, 42, "HP: "..memory.readword(Start-item*Sz+26) ,'white');
gui.text(233, 52, "Action: "..memory.readbyte(Start-item*Sz+38) ,'white');
end
if keys['leftclick'] and clickhappen == false then
if keys.xmouse > Cx/2-DV and keys.ymouse > Cy/2-DV and keys.xmouse < Cx/2-DV+size and keys.ymouse < Cy/2-DV+size then
clickhappen = true
item = i
end
end
last_keys = keys
end
end
But if you really want to know where stuff is on the map, just use the built in cheat 'nscrn', makes it a lot easier.