Príklady
FAKE OE-A Source
Tu dávam source code FAKE OE-A, ktorý som robil asi pred dvoma týždňami.
Neskôr prihodím popisky.
-- Fake 3.03 OE-A updater by myschoo
-- Its just joke dont take it too serious :D
--colors
red = Color.new(217,26,117)
error = Color.new(255,0,0)
white = Color.new(255,255,255)
rsod = Image.load("load.dat")
fakenum = 20
counter = Timer.new(0)
counter:stop()
timer = Timer.new(0)
timer:stop()
function update()
currentTime = counter:time()
if pad:cross() then
counter:start()
end
if currentTime > 0 then
screen:print(5, 55, "Opening and validating dxar file...", red)
end
end
function timerfun()
curTimeinsecs = math.floor(timer:time()/1000)
currentTime = counter:time()
if currentTime > 2000 then
screen:print(290, 55, "done.", red)
end
if currentTime > 3000 then
screen:print(5, 65, "Logical formating flash0...", red)
end
if currentTime > 5000 then
screen:print(230, 65, "done.", red)
end
if currentTime > 6000 then
screen:print(5, 75, "Creating directories...", red)
end
if currentTime > 8000 then
screen:print(200, 75, "done.", red)
end
if currentTime > 9000 then
screen:print(5, 85, "Writing 1.50 subset...", red)
end
if currentTime > 11000 then
timer:start()
screen:print(190, 85, curTimeinsecs .. "%", red)
end
if timer:time() > 0 then
cfg = io.open("cfg.dat","r")
mem = cfg:read("*n")
cfg:close()
if fakenum >= mem then
cfg = io.open("cfg.dat","w+")
cfg:write(fakenum)
cfg:close()
end
if timer:time() >= 94000 then
timer:stop()
fakenum = fakenum - 1
end
end
if currentTime > 110000 then
screen:print(5, 105, "FATAL ERROR OCCURED", error)
end
if currentTime > 111000 then
screen:print(5, 115, "FATAL ERROR OCCURED", error)
end
if currentTime > 112000 then
screen:print(5, 125, "FATAL ERROR OCCURED", error)
end
if currentTime > 113000 then
screen:print(5, 135, "FATAL ERROR OCCURED", error)
end
if currentTime > 114000 then
screen:print(5, 145, "FATAL ERROR OCCURED", error)
end
if currentTime > 115000 then
screen:print(5, 155, "FATAL ERROR OCCURED", error)
end
if currentTime > 116000 then
screen:print(5, 165, "FATAL ERROR OCCURED", error)
end
if currentTime > 117000 then
screen:print(5, 175, "FATAL ERROR OCCURED", error)
end
end
------------main loop
while true do
screen:clear()
pad = Controls.read()
screen:print(5, 5, "You are about to flash your PSP to custom firm 3.03 OE-A.", red)
screen:print(5, 15, "Press X to start. By doing it, you accept the risk and ALL", red)
screen:print(5, 25, "the responsability of what happens.", red)
screen:print(5, 35, "If you don't agree press R button.", red)
update()
timerfun()
if currentTime > 122000 then
screen:clear()
end
if currentTime > 124000 then
screen:blit(0, 0, rsod)
end
if currentTime > 134000 then
screen:clear()
screen:print(5, 5, "Lol to bol len VTIP !! :D", white)
end
if currentTime > 136000 then
screen:print(5, 15, "Aplikacia sa vypne za 5 sek. Cakajte.", white)
end
if currentTime > 138000 then
screen:print(5, 25, "Bye Bye", white)
end
if currentTime > 141000 then
System.Quit()
end
if pad:r() then
System.Quit()
end
screen.waitVblankStart()
screen.flip()
end
Source code obsahuje nejaké chybky atď., a niektoré veci by sa dali vyriešíť jednoduchšie.
Full Download
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
Prečitaj PSP prezívku a vypíš na obrazovku
Urobil som jednoduchý kód, ktorý prečíta s PSP flash1:/registry/system.dreg nickname užívatela a vypíše ho na obrazovku.
-- Print PSP's name on screen
-- by myschoo
-- definujem farby
white = Color.new(255,255,255)
-- nájdi meno
-- toto nesmiem dat do LOOPu, pretoze ten je citany 60x za sek. musim
-- to teda dat do prvej casti
-- funkcia pre otvorenie suboru, "r" znamena "read", este existuje
-- funkcia"w+" cize write
meno = io.open("flash1:/registry/system.dreg","r")
-- musim precita IBA urcity riadok, ten najdem podla offsetu riadku
-- proste pozrite si system.dreg v hex editore :) (0x2380 - offset)
meno:seek("set", 0x2380)
-- precitam data, 27 znamena pocet znakov, max. dlzka nicku je 27
-- znakov
precitajmeno = meno:read(27)
-- zavriem subor
meno:close()
while true do
screen:clear()
pad = Controls.read()
--pisem na obrazovku
screen:print(5, 5, "Find Name by myschoo", white)
screen:print(100,100, "Tvoje PSP meno je:" , white)
screen:print(100,115, precitajmeno , white)
if pad:cross() then
System.Quit()
end
screen.waitVblankStart()
screen.flip()
end
Popísané sú najdôležitejšie časti.
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
Funkcie Batérie
-- Funkcie Baterie
-- by myschoo
--definujem farby
biela = Color.new(255,255,255)
cervena = Color.new(255,0,0)
zelena = Color.new(0,255,0)
-- definujem ciselne premenne
batstat = System.powerGetBatteryLifePercent() -- stav baterie v %
battime = System.powerGetBatteryLifeTime() / 60 -- kolko este vydrzi bat. v hod.
teplota = System.powerGetBatteryTemp() -- teplota baterie v °C
volt = System.powerGetBatteryVolt() -- napatie v milivoltoch
-- funkcia "battery"
function battery()
if System.powerIsBatteryCharging() then -- ak sa nabija tak
screen:print(10,110, "Nabijanie baterie: ON", zelena) -- napis
else -- inak
screen:print(10,110, "Nabijanie baterie: OFF", zelena) -- napis
end
if System.powerIsLowBattery() then -- zisti ci je baterka slaba
screen:print(10,120, "Bateria je slaba", cervena)
end
-- napisem premenne na obrazovku
screen:print(10, 60, "Stav baterie: " .. batstat .. "%", zelena)
screen:print(10, 70, "Bateria vydrzi este: " .. battime .. " hod.", zelena)
screen:print(10, 80, "Teplota baterie je: " .. teplota .. " stupnov C", zelena)
screen:print(10, 90, "Napatie baterie je: " .. volt .. " mV", zelena)
screen:print(10, 150, "Stlac (X) pre vypnutie", biela)
end
while true do
screen:clear()
screen:print(175, 5, "MyBatt by myschoo", biela)
screen:print(175, 12, "-----------------", biela)
-- vlozim funkciu
battery()
pad = Controls.read()
if pad:cross() then
break
end
screen.waitVblankStart()
screen.flip()
end
Popísané sú najdôležitejšie časti.
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
Pixel Fixer
Pamätáte sa na rôzne programy, ktoré preblikávali 3 farby a maly Vám opraviť "stuck" pixely? Tu je jednoduchý kód ako na to...
-- Pixel Fixer for Tutorial
-- by myschoo
-- definujem farby, zakladnu cervenu, zelenu a modru ( R G B )
red = Color.new(255,0,0)
green = Color.new(0,255,0)
blue = Color.new(0,0,255)
white = Color.new(255,255,255)
-- pod premennu "timer" si dam novy timer
timer = Timer.new(0)
-- ten sa ale hned zapne takze ho musim stopnut
timer:stop()
-- funckia bliknutia
function Blick()
-- zapne sa timer
timer:start()
-- ak je cas vacsi/nanajvys rovny 0 a mensi ako 200milisekund potom
if timer:time() >= 0 and timer:time() < 200 then
-- pouzijeme prikaz screen:clear(farba)
screen:clear(red)
end
-- takto isto aj dalej
if timer:time() >= 200 and timer:time() < 400 then
screen:clear(green)
end
if timer:time() >= 400 and timer:time() < 600 then
screen:clear(blue)
end
-- ak je cas vacsi ako 600milisekund potom sa timer stopne a resetuje a
-- funkcia bezi od zaciatku
if timer:time() >= 600 then
timer:stop()
timer:reset(0)
end
end
while true do
-- vlozim funkciu
Blick()
screen:print(5,5, "Pixel Fixer by myschoo", white)
screen.waitVblankStart()
screen.flip()
end
Popísané sú najdôležitejšie časti.
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
Funkcie MP3
LUA Player Mod od cools, má pár nových funkcii ako prehrávanie MP3 a OGG. Tu je príklad použitia MP3 funkcii...
--MP3 Player test by myschoo
-- definujem farby
white = Color.new(255,255,255)
gray = Color.new(192,192,192)
-- definujem si status hrania
playing = "false"
-- zlozka v PSP, z ktorej sa nacita MP3
System.currentDirectory("ms0:/PSP/MUSIC")
-- nacita MP3 do RAM
Mp3.load("03-lostprophets-last_train_home-rns.mp3")
while true do
-- vycistim obrazovku a napisem nejake texty
screen:clear()
screen:print(5,5, "MP3 Player Test by myschoo", white)
screen:print(5,90, "Last Train Home - Lostprophets" , gray)
screen:print(5, 130, "Stlac (X) pre hranie", white)
screen:print(5, 140, "Stlac (O) pre pauznutie", white)
screen:print(5, 150, "Stlac START pre navrat do LUA Player", white)
screen:print(5, 160, "Stlac SELECT pre navrat do XMB menu", white)
pad = Controls.read()
if pad:cross() then
-- zacne prehravat MP3
Mp3.play()
-- zmenim status
playing = "true"
end
-- funcia streamovania
if Mp3.EndOfStream() == "false" and playing == "true" then
-- Mp3.getTime ziska cas prehravania vo forme 00 : 00 : 00
screen:print(5,100, Mp3.getTime() , gray)
end
-- toto zaruci ze jednym stlacenim (O) sa vysle len 1 signal
if pad:circle() and oldpad:circle() ~= pad:circle() then
-- pauzne MP3
Mp3.pause()
end
if pad:start() then
break
end
if pad:select() then
-- nova funckia, funguje iba v najnovsom lua playeri, po vyvolani funckie
-- sa aplikacia vypne a dostanete XMB
System.Quit()
end
-- ukoncenie
screen.waitVblankStart()
screen.flip()
-- toto tam musi byt
oldpad = pad
end
Popísané sú najdôležitejšie časti.
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
Jednoduché Menu
-- Ukazka Menu
-- by myschoo
-- farby
biela = Color.new(255,255,255)
selector = Color.new(0,128,255)
zelena = Color.new(20,150,147)
-- definujem premennu
selY = 44
while true do
screen:clear()
-- vytvorim tzv. "selector" (vid. obrazok)
Image:fillRect(4, selY, 120, 10, selector)
-- nejake texty + polozky v menu
screen:print(140,5, "Testovacie menu by myschoo", biela)
screen:print(140,12, "--------------------------", zelena)
screen:print(5,45, "Nova hra", biela)
screen:print(5,55, "Pokracuj v hre", biela)
screen:print(5,65, "Ovladanie", biela)
screen:print(5,75, "O hre", biela)
screen:print(5,85, "Koniec", biela)
screen:print(5,115, "---------------------------------------", biela)
screen:print(5,135, "Pouzi sipky pre pohyb v menu", biela)
screen:print(5,145, "Pouzi (X) pre potvrdenie", biela)
pad = Controls.read()
-- pohyb selectora za pomoci premmennej selY
if pad:down() and oldpad:down() ~= pad:down() then
selY = selY + 10
end
if pad:up() and oldpad:up() ~= pad:up() then
selY = selY - 10
end
-- toto zaisti, ze selector bude kruzit v cykle, ak ste na 5. polozke a
-- stlacite dole, selector bude na 1. polozke a naopak
if selY == 94 then
selY = 44
end
if selY == 34 then
selY = 84
end
-- vykona jednotlive funkcie
if selY == 44 and pad:cross() and oldpad:cross() ~= pad:cross() then
-- vykona 1. funkciu
end
if selY == 54 and pad:cross() and oldpad:cross() ~= pad:cross() then
-- vykona 2. funckiu
end
if selY == 64 and pad:cross() and oldpad:cross() ~= pad:cross() then
-- vykona 3. funckiu
end
if selY == 74 then
screen:print(5,250, "Moja Prva Hra by myschoo", biela)
screen:print(5,260, "Vsetky prava vyhradene :D", biela)
end
if selY == 84 and pad:cross() and oldpad:cross() ~= pad:cross() then
System.Quit()
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
end
Popísané sú najdôležitejšie časti.
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
Analóg
Jednoduchý skript, ktorý ukazuje použitie analógu a pohyb objektu pomocou neho...
red = Color.new(255,0,0)
black = Color.new(0,0,0)
white = Color.new(255,255,255)
-- vytvorim si prazdny cerveny obrazok
player = Image.createEmpty(32,32)
player:clear(red)
-- vytvorim si table z vlastnostami
Player = { x = 100, y = 100, img = player }
-- funkcia analogoveho pohybu
function analogMove()
pad = Controls.read()
-- anaX a anaY su premenne
anaX = pad:analogX()
anaY = pad:analogY()
-- ak je anaX cislo vacie ako 50 potom
if anaX > 50 then
-- hrac sa pohne po X osi o 5 pixelov
Player.x = Player.x + 5
end
if anaX < -50 then
Player.x = Player.x - 5
end
-- ak je anaYcislo vacie ako 50 potom
if anaY > 50 then
-- hrac sa pohne po Y osi o 5 pixelov
Player.y = Player.y + 5
end
if anaY < -50 then
Player.y = Player.y - 5
end
end
while true do
screen:clear()
-- vykreslim hraca
screen:blit(Player.x,Player.y,Player.img)
-- vlozim funkciu
analogMove()
-- vypisem koordinaty (nie je porebne skor pre info)
screen:print(5,5,"analogX: " .. anaX, white)
screen:print(5,15,"analogY: " .. anaY, white)
if pad:cross() then
break
end
screen.flip()
screen.waitVblankStart()
end