--[[ ICO WS Patcher Credits: - lua trainer form base partially taken from atom0s ([Wiccaan] of CE forums) example trainer based on minesweeper, ^couse it's very clear, readable and I really wish to learn to keep it like that;] - NTSC US/JP adresses and main testing by Synce, ^hardworker ;3 Everything else, meaning an awfully trashed code which I had to clear and comment before releasing by me - Miseru99 Feel free to use it as template for a trainer/patcher or just to learn something. I made some additional code wrapers based on one existing, just to show, with small steps that anyone can easily create ones for his own needs. ]]-- local SmallPatcher = { } ---------------------------------------------------------------------------------- -- func: InitButton( .. ) -- desc: Wraps button creation and setup functions for smaller code. ---------------------------------------------------------------------------------- function InitButton( form, caption, x, y, w, h, func ) local button = createButton( form ); if( button == nil ) then return nil; end control_setCaption( button, caption ); control_setPosition( button, x, y ); control_setSize( button, w, h ); control_onClick( button, func ); return button; end ---------------------------------------------------------------------------------- -- func: InitLabel( .. ) -- desc: Wraps label creation and setup functions for smaller code. ---------------------------------------------------------------------------------- function InitLabel( form, x, y, text ) local label = createLabel( form ); if( label == nil ) then return nil; end control_setCaption( label, text ); control_setPosition( label, x, y ); return label; end ---The above code wrappers were in trainer_example, ---I'll add more with just small edits, ---to show how easily one can make such code wrappers ---------------------------------------------------------------------------------- -- func: InitColorLabel( .. ) -- desc: Same as above, just include font size, color and style ---------------------------------------------------------------------------------- function InitColorLabel( form, x, y, fontSize, style, color, text ) local label = createLabel( form ); if( label == nil ) then return nil; end control_setCaption( label, text ); control_setPosition( label, x, y ); font=control_getFont( label ); font_setSize(font, fontSize) setProperty(font, 'Style', style) --ie. 'fsBold,fsUnderline' font_setColor(font, color)--BBGGRR ie. 0x00ffff -- yellow return label; end ---------------------------------------------------------------------------------- -- func: InitHyperlinkLabel( .. ) -- desc: Similar to above, but include function on click ---------------------------------------------------------------------------------- function InitHyperlinkLabel( form, x, y, fontSize, style, color, func, text ) local label = createLabel( form ); if( label == nil ) then return nil; end control_setCaption( label, text ); control_setPosition( label, x, y ); font=control_getFont( label ); font_setSize(font, fontSize) setProperty(font, 'Style', style) --ie. 'fsBold,fsUnderline' font_setColor(font, color)--BBGGRR ie. 0x00ffff -- yellow control_onClick( label, func ); return label; end ---------------------------------------------------------------------------------- -- func: SmallPatcher.Main( .. ) -- desc: Prepares script for overall actions. ---------------------------------------------------------------------------------- function SmallPatcher.Main( ) t=createTimer(nil) -- initiating timers I'll use t2=createTimer(nil) path=TrainerOrigin -- sets trainer directory to a variable SL02=createStringlist() SL01=createStringlist() strings_loadFromFile(SL02, path.."ICO WS Patcher.ini") sl2=strings_getCount(SL02) if sl2~=8 then --load defaults for ini file strings_add(SL01, "PCSX2 process name: -- if your pcsx2 executable has different name, you can set it here") strings_add(SL01, "pcsx2.exe") strings_add(SL01, "GUI: -- set to true to enable GUI, false10 to disable it with 16:10, false(or anything else) to disable it for 16:9") strings_add(SL01, "true") strings_add(SL01, "Delay: -- set in seconds, used only in Non-Gui version to avoid setting stuff before game runs") strings_add(SL01, "10") strings_add(SL01, "Game-Code Adress: --bios dependant, no need to edit manually, it'll be found at first run;3") strings_add(SL01, "0x200155D0") strings_saveToFile(SL01, path.."ICO WS Patcher.ini") SL02=createStringlist() strings_loadFromFile(SL02, path.."ICO WS Patcher.ini") end GUIenabled=strings_getString(SL02, 3) -- make note it counts from 0 soo 3 in here = 4th line ProcessName=strings_getString(SL02, 1) delayItTime=strings_getString(SL02, 5) BiosFound=strings_getString(SL02, 7) if GUIenabled == "true" then -- it it's gui version, build a form here -- Main trainer form pointer. SmallPatcher.Form = createForm( true ); -- Auto attach al=getAutoAttachList() strings_add(al,ProcessName) -- close CE when exiting trainer form_onClose(SmallPatcher.Form, close) -- set window size control_setSize( SmallPatcher.Form, 150, 155 ); -- Create buttons. SmallPatcher.btnWS9 = InitButton( SmallPatcher.Form, "16:9", 0, 15, 150, 30, SmallPatcher.OnWS9Clicked ); --second row SmallPatcher.btnWS10 = InitButton( SmallPatcher.Form, "16:10", 0, 45, 150, 30, SmallPatcher.OnWS10Clicked ); -- Create info label. SmallPatcher.lblInfo = InitLabel( SmallPatcher.Form, 10, 0, "ICO Widescreen Patcher\n" .. "\n" .. "\n" ..-- like shown here \n means going to next line "\n" ..-- you don't always need to create two labels "\n" ..-- for two different text "\n" .. "\n" .. "\n" .. "\n" .. " Made by" ); SmallPatcher.lblInfo2 = InitLabel( SmallPatcher.Form, 40, 97, "Thanks to \n" .. "for NTSC versions" ); SmallPatcher.lblName1 = InitHyperlinkLabel( SmallPatcher.Form, 95, 95, 10, 'fsBold,fsUnderline', 0x000000, nameURLfunc, "Synce" ) SmallPatcher.lblName2 = InitHyperlinkLabel( SmallPatcher.Form, 77, 133, 10, 'fsBold,fsUnderline', 0x000000, nameURLfunc2, "Miseru99" ) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 47, 75, 10, 'fsBold', 0xdA1f1f, "WAITING" ) line = createLabel(SmallPatcher.Form) -- and here an example of simple label without any code wrapper control_setCaption( line, "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _" ); control_setPosition( line, 0, 79 ); -- Create option booleans. SmallPatcher.bWS9Enabled = false; SmallPatcher.bWS10Enabled = false; -- Set form caption. control_setCaption( SmallPatcher.Form, "ICO Widescreen patcher" ); else -- omg no gui? What should I do: Delay=tonumber(strings_getString(SL02, 5),10) -- reads delay from file if Delay~=nil then j=0 timer_setInterval(t2, 1000) timer_onTimer(t2, DelayF) --sets delay function on timer which will countdown every 1000ms(1s) timer_setEnabled(t2, true); else --if delay doesn't exist just run noGui function noGui() end end return true; end -- just setting up the url functions for hyperlink labels function nameURLfunc() shellExecute("http://forums.pcsx2.net/User-synce") end function nameURLfunc2() shellExecute("http://forums.pcsx2.net/User-miseru99") end --setting up a very basic close function, nothing more for this patcher needed function close() closeCE() end --and here's my delay function, no need for more comment, it's very easy function DelayF() if j.< --works now, but if bios is not v2.00 this aob scan makes a slight --delay on activation function BiosDoMatters() BiosCheck=readString(BiosFound, 1) if BiosCheck~="S" then aobbios=createMemScan() memscan_firstScan(aobbios,soExactValue ,vtByteArray ,rtTruncated ,"53 ?? ?? ?? 5F ?? ?? ?? 2E ?? ?? 3B ??" ,"" , "20010000", "2001ffff", "", fsmNotAligned, "", true, false, false, false); memscan_waitTillDone(aobbios) flbios=createFoundList(aobbios) foundlist_initialize(flbios) countbios=foundlist_getCount(flbios) if countbios>0 then BiosFound=foundlist_getAddress(flbios, 0) strings_clear(SL01) strings_add(SL01, "PCSX2 process name: -- if your pcsx2 executable has different name, you can set it here") strings_add(SL01, ProcessName) strings_add(SL01, "GUI: -- set to true to enable GUI, false10 to disable it with 16:10, false(or anything else) to disable it for 16:9") strings_add(SL01, GUIenabled) strings_add(SL01, "Delay: -- set in seconds, used only in Non-Gui version to avoid setting stuff before game runs") strings_add(SL01, delayItTime) strings_add(SL01, "Game-Code Adress: --bios dependant, no need to edit manually, it'll be found at first run;3") strings_add(SL01, BiosFound) strings_saveToFile(SL01, path.."ICO WS Patcher.ini") --that should save the game-code adress if bios version was different soo it doesn't need to find it each time end end GameCode=readString(BiosFound, 11) end function noGui() openProcess(ProcessName) --attaches patcher to choosen processname ~ pcsx2.exe here BiosDoMatters() if GUIenabled=="false10" then --sets WS type wsType=0x3F555555 else wsType=0x3F400000 end i=10 var2=0 timer_setInterval(t, 100) timer_onTimer(t, wsActivate) timer_setEnabled(t, true); end --this is basically my Ico script function IcoScript() var1=readInteger(WScheck) if i<10 then check1=readInteger(WScheck2) i=i+1 sleep(400) end if var1==var2 then -- if still same stage then do writeInteger(WSadress, wsType) if GUIenabled == "true" then checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="ACTIVATED" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 41, 75, 10, 'fsBold', 0x2Aaf5f, "ACTIVATED" ) end end else -- when stage changes then do if i==10 then writeInteger(WSadress, 0x3F800000) --restores original value if GUIenabled == "true" then checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="STAGE CHANGE" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 28, 75, 10, 'fsBold', 0x0A0fff, "STAGE CHANGE" ) end end i=0 end check2=readInteger(WScheck2) if i>0 and check2~=check1 then var2=readInteger(WScheck) i=10 end end end function wsActivate() if GUIenabled ~= "true" or (WS9==1 or WS10==1) then GameCode=readString(BiosFound, 11) -- checks for game version if GameCode=="SCES_507.60" then --if eu version of ICO then set vars and run script WSadress=0x2028FF80 WScheck=0x2028FE74 WScheck2=0x2029B9D8 IcoScript() end if GameCode=="SCUS_971.13" then -- us version of ICO WSadress=0x202758E0 WScheck=0x202757D4 WScheck2=0x20280F7C IcoScript() end if GameCode=="SCPS_110.03" then -- jp version of ICO WSadress=0x2028DE80 WScheck=0x2028DD74 WScheck2=0x202998C8 IcoScript() end if GameCode~="SCES_507.60" and GameCode~="SCUS_971.13" and GameCode~="SCPS_110.03" then --if none of the above if GameCode==nil then if GUIenabled ~= "true" then closeCE() -- turns off CE for no gui version if pcsx2.exe was closed(or rather when string from it's memory doesn't exist, works exactly same through) else getPCSX2ID=getProcessIDFromProcessName(ProcessName) getProcess=getOpenedProcessID() checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="ATTACHING" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 37, 75, 10, 'fsBold', 0xdAcf1f, "ATTACHING" ) end if getProcess~=getPCSX2ID then openProcess(ProcessName) end end else if GUIenabled == "true" then checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="WRONG GAME" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 33, 75, 10, 'fsBold', 0xdAcf1f, "WRONG GAME" ) end end end end end end ---------------------------------------------------------------------------------- function SmallPatcher.OnWS9Clicked() SmallPatcher.bWS9Enabled = not SmallPatcher.bWS9Enabled; if( SmallPatcher.bWS9Enabled == true ) then BiosDoMatters() if GameCode~="SCES_507.60" and GameCode~="SCUS_971.13" and GameCode~="SCPS_110.03" then checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="WRONG GAME" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 33, 75, 10, 'fsBold', 0xdAcf1f, "WRONG GAME" ) end else checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="ACTIVATED" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 41, 75, 10, 'fsBold', 0x2Aaf5f, "ACTIVATED" ) end SmallPatcher.bWS10Enabled = false; control_setCaption(SmallPatcher.btnWS9, "16:9(ON)") control_setCaption(SmallPatcher.btnWS10, "16:10") end wsType=0x3F400000 beep() WS9=1 i=10 var2=readInteger(WScheck) timer_setInterval(t, 100) timer_onTimer(t, wsActivate) timer_setEnabled(t, true); else beep() if WS9==1 then writeInteger(WSadress, 0x3F800000) control_setCaption(SmallPatcher.btnWS9, "16:9") checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="WAITING" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 47, 75, 10, 'fsBold', 0xdA1f1f, "WAITING" ) end WS9=0 end end end ---------------------------------------------------------------------------------- function SmallPatcher.OnWS10Clicked() SmallPatcher.bWS10Enabled = not SmallPatcher.bWS10Enabled; if( SmallPatcher.bWS10Enabled == true ) then BiosDoMatters() if GameCode~="SCES_507.60" and GameCode~="SCUS_971.13" and GameCode~="SCPS_110.03" then checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="WRONG GAME" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 33, 75, 10, 'fsBold', 0xdAcf1f, "WRONG GAME" ) end else checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="ACTIVATED" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 41, 75, 10, 'fsBold', 0x2Aaf5f, "ACTIVATED" ) end SmallPatcher.bWS10Enabled = false; control_setCaption(SmallPatcher.btnWS10, "16:10(ON)") control_setCaption(SmallPatcher.btnWS9, "16:9") end wsType=0x3F555555 beep() WS10=1 i=10 var2=readInteger(WScheck) timer_setInterval(t, 100) timer_onTimer(t, wsActivate) timer_setEnabled(t, true); else beep() if WS10==1 then writeInteger(WSadress, 0x3F800000) control_setCaption(SmallPatcher.btnWS10, "16:10") checkStatus=control_getCaption(SmallPatcher.lblStatus) if checkStatus~="WAITING" then object_destroy(SmallPatcher.lblStatus) SmallPatcher.lblStatus = InitColorLabel( SmallPatcher.Form, 47, 75, 10, 'fsBold', 0xdA1f1f, "WAITING" ) end WS10=0 end end end -- Execute our script. SmallPatcher.Main();