User File #23966124716712977

Upload All User Files

#23966124716712977 - DS Freedom Wings - DeSmuME script

FreedomStats.lua
717 downloads
Uploaded 7/7/2015 7:16 AM by FatRatKnight (see all 245)
Fifth exhibit.
Ah, another old script of mine. I'm not sure if I'll set myself up for DS TASing again, but here's one game I was analyzing and never told anyone about here.
Since I don't have things set up, I can't say with certainty what it was about. I do remember being able to switch between individual stats of individual planes, and I also remember tweaking the script to display my missile data and the closest distance to a particular target it managed to reach. Fun stuff to mini-TAS a part and hit something with a not-homing missile from very far away. No, I do not have it recorded.
Freedom Wings is another one of those games that aren't the greatest out there. Or even all that wonderful, really. You're not missing much by never picking up this game.

local AirVal= {addr=0x020F9F88,size=111, CT= 0, CS= 0, ref="Air"}
local GndVal= {addr=0x020FD778,size= 60, CT= 0, CS= 0, ref="Gnd"}
local ObjVal= {addr=0x020CD984,size= 63, CT= 0, CS= 0, ref="Obj"}
local MslVal= {addr=0x02092808,size= 38, CT= 0, CS= 0, ref="Msl"}

AirVal.names= {
 [  0]= "Do I exist?"    ,
                                                   [  8]= "Clock?"         ,
 [  9]= "Gun cooldown"   ,[ 10]= "Secondary Cd"   ,
                                                   [ 14]= "Altitude"       ,
 [ 15]= "Velocity(East)" ,[ 16]= "Velocity(Up)"   ,[ 17]= "Velocity(South)",
 [ 21]= "Twist(Up)"      ,[ 22]= "Twist(Left)"    ,[ 23]= "Twist(CCW)"     ,
                                                   [ 29]= "Throttle"       ,
 [ 30]= "Control(Up)"    ,[ 31]= "Control(Left)"  ,[ 32]= "Control(CCW)"   ,
                                                   [ 80]= "Max HP"         ,
 [ 81]= "HP"             ,[ 82]= "Armor"          ,[ 83]= "Engine power"   ,
 [ 84]= "Maneuver"       ,[ 85]= "Weight"         ,
                                                   [ 89]= "Fuel"           ,
 [ 90]= "Gun type"       ,[ 91]= "2nd Wpn type"   ,[ 92]= "Bullets"        ,
 [ 93]= "2nd Wpn ammo"   ,
                          [ 94]= "Gold on defeat" ,[ 95]= "EXP on defeat"  ,
 [ 99]= "Level"
}
GndVal.names= {
 [  9]= "Gun Timer"      ,
 [ 12]= "Weapon Damage"  ,                         [ 14]= "Weapon Delay"   ,
                                                   [ 44]= "HP"             ,
 [ 45]= "Max HP"         ,[ 46]= "Armor"          ,
 [ 53]= "Gold on defeat" ,[ 54]= "EXP on defeat"
}


local keys= input.get()
local lastkeys= keys
local function UpdateKeys() lastkeys= keys; keys= input.get() end
local function Press(k) return keys[k] and (not lastkeys[k]) end
--*****************************************************************************
local function ReadDoubleWordSigned(addr)
--*****************************************************************************
    return (memory.readbyte(addr  )
           +memory.readbyte(addr+1)      *    0x100
           +memory.readbyte(addr+2)      *  0x10000
           +memory.readbytesigned(addr+3)*0x1000000)
end

--*****************************************************************************
local function GetPosPlane(i)
--*****************************************************************************
-- Returns East, Up, South
-- Takes from a special, unidentified array
    return ReadDoubleWordSigned(0x020CD984+0xFC*i),
           ReadDoubleWordSigned(0x020CD988+0xFC*i),
           ReadDoubleWordSigned(0x020CD98C+0xFC*i)
end

--*****************************************************************************
local function GetVelPlane(i)
--*****************************************************************************
-- Currently garbage
    return ReadDoubleWordSigned(0x020CD984+0xFC*i),
           ReadDoubleWordSigned(0x020CD988+0xFC*i),
           ReadDoubleWordSigned(0x020CD98C+0xFC*i)
end

--*****************************************************************************
local function GetFuelTime(i)
--*****************************************************************************
    local a= AirVal.addr + 4*AirVal.size*i
    local FuelLeft= ReadDoubleWordSigned(a + 89*4)
    local FuelUse= math.floor(ReadDoubleWordSigned(a + 29*4)
                             *ReadDoubleWordSigned(a + 83*4)/102400)

    if FuelLeft == 0 then return "Empty" end
    if FuelUse < 1 then return "INF" end

    FuelLeft= math.floor(FuelLeft/FuelUse)

    local timer= ""

    a= math.floor(FuelLeft/30)
    FuelUse= math.floor(a/60)
    a= a%60
    FuelLeft= FuelLeft%30
    a= math.floor((a + FuelLeft/30)*100)/100

    if FuelUse >= 1 then
        timer= FuelUse .. "m "
    end

    return timer .. string.format("%2d",a) .. "s"
end


local Msl= {[0]={}, [1]={}, [2]={}, [3]={}, [4]={}, [5]={}}
--*****************************************************************************
local function TrackMissile()
--*****************************************************************************
    for i= 0, 5 do
        if ReadDoubleWordSigned(MslVal.addr + 4*MslVal.size*i) ~= 0 then
            Msl[i].E = ReadDoubleWordSigned(MslVal.addr + 4*MslVal.size*i + 4*2)
            Msl[i].U = ReadDoubleWordSigned(MslVal.addr + 4*MslVal.size*i + 4*3)
            Msl[i].S = ReadDoubleWordSigned(MslVal.addr + 4*MslVal.size*i + 4*4)
            local tE, tU, tS= GetPosPlane(AirVal.CT)

            local dE, dU, dS= Msl[i].E-tE , Msl[i].U-tU , Msl[i].S-tS

            local dist= math.floor(math.sqrt(dE*dE + dU*dU + dS*dS))

            if not Msl[i].exist then Msl[i].shortest= dist
            else   Msl[i].shortest= math.min(dist,Msl[i].shortest)
            end

            gui.text(1,-180+10*i, dist)
            Msl[i].exist= true
        else
            Msl[i].exist= false
        end
        if Msl[i].shortest then gui.text(120,-180+10*i, Msl[i].shortest,0xFF8000FF) end
    end
end

local Su,Sd= "numpad9","numpad3"
local Tu,Td= "numpad7","numpad1"
local Swappy="numpad5"


local Tbl= AirVal
--*****************************************************************************
local function Fn()
--*****************************************************************************
    UpdateKeys()
    if Press(Swappy) then
        if Tbl == AirVal then
            Tbl= GndVal
        else
            Tbl= AirVal
        end
    end
    if Press(Sd) then  Tbl.CS= (Tbl.CS+(Tbl.size-1))%Tbl.size end
    if Press(Su) then  Tbl.CS= (Tbl.CS+ 1          )%Tbl.size end
    if Press(Td) then  Tbl.CT= math.max(Tbl.CT-1,0) end
    if Press(Tu) then  Tbl.CT= Tbl.CT+1 end

    local addr= Tbl.addr + 4*Tbl.size*Tbl.CT + 4*Tbl.CS
    local val= ReadDoubleWordSigned(addr)
    local color= 0xFFFFFFFF
    if ReadDoubleWordSigned(Tbl.addr + 4*Tbl.size*Tbl.CT) == 0 then
        color= 0xC08080FF
    end

    gui.text(25,1,Tbl.ref,color)
    gui.text(1, 1,Tbl.CT ,color)
    gui.text(1, 9,val    ,color)
    gui.text(1,17,Tbl.CS ,color)
--    gui.text(1,50,string.format("%x",addr),0x40FF40FF)
    if Tbl.names[Tbl.CS] then gui.text(25,17,Tbl.names[Tbl.CS],color) end


    addr= 0x020F9F88 + 4*29
    val=ReadDoubleWordSigned(addr)

    addr= 0x020F9F88 + 4*83
    val=val*ReadDoubleWordSigned(addr)
    gui.text(140,7,val/102400)


    addr= 0x020F9F88 + 4*81
    val=ReadDoubleWordSigned(addr)
    addr= 0x020F9F88 + 4*82
    local val2=ReadDoubleWordSigned(addr)
    if val2 >= 100 then
        gui.text(60,1,"INV")
    else
        local dispval= math.floor(val / (100-val2)*10)/10
        gui.text(60,1,dispval)
    end

    TrackMissile()

    if Tbl == AirVal then
        gui.text(1,40,GetFuelTime(Tbl.CT))
    end

    local E,U,S= GetPosPlane(0)

    gui.text(120,40,string.format("%9d",E))
    gui.text(120,52,string.format("%9d",U))
    gui.text(120,64,string.format("%9d",S))
    gui.text(120,76,string.format("%9d",ReadDoubleWordSigned(0x0208AC20)))
end

gui.register(Fn)

--local T= {down= true}
local T= {left= true}
local Zib= 0
--*****************************************************************************
local function AutoLift()
--*****************************************************************************
--    local Z= ReadDoubleWordSigned(AirVal.addr + 4*21)
--    if Z <= 10 then  joypad.set(T) end
    local Z= ReadDoubleWordSigned(AirVal.addr + 4*23)
    local Y= ReadDoubleWordSigned(0x020CD9AC)
    if (Y < 0) and (Z < 0) and (Zib < 2) then  joypad.set(T); Zib= Zib+1
    else Zib= 0
    end
end
--emu.registerbefore(AutoLift)

--while true do
--    emu.frameadvance()
--end