Talk:PS2 Classics Emulator Compatibility List: Difference between revisions

From PS4 Developer wiki
Jump to navigation Jump to search
(Added fix for Ace Combat Zero: The Belkan War)
(47 intermediate revisions by 15 users not shown)
Line 27: Line 27:
--safe-area-min=1.0</pre>
--safe-area-min=1.0</pre>


====Samurai Shodown Anthology====
SLUS-21269
SLUS_216.29
<br>SLUS-21269_features.lua
<pre>This is a substantial file. Over 150 lines with an extensive performance fix. I'm sharing the file itself as a download link.
 
https://drive.google.com/file/d/12gt2fONqMP1rmEB9UMw3rIpEYbz1dQq8/view
 
#Official widescreen support.</pre>
 
====Destroy All Humans====
SLUS_209.45
<br>Text
<pre>--gs-use-mipmap=1
--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-ignore-dirty-page-border=1
--fpu-accurate-addsub-range=0x28bf00,0x28c100
#Fix for graphical glitches.</pre>
 
SLUS_209.45
<br>SLUS-20945_features.lua
<pre>-- Lua 5.3
-- Title:  Destroy All Humans! PS2 - SLUS-20945 (USA)
-- Author:  Ernesto Corvi, Adam McInnis
 
-- Changelog:
 
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
 
local eeObj = getEEObject()
local emuObj = getEmuObject()
local gpr = require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
 
-- Widescreen
eeObj.AddHook(0x308270, 0x3c0336c5, function() -- Graphics::Script::SetScreenRatio
local mode = eeObj.GetGpr(gpr.v0)
-- print(string.format("mode: %08x", mode))
if mode == 0x36c59d2b then -- widescreen
emuObj.SetDisplayAspectWide()
elseif mode == 0x855a87ef then -- standard
emuObj.SetDisplayAspectNormal()
end
end)
 
eeObj.AddHook(0x3078F4, 0xae0000f4, function() -- Graphics::Renderer::Renderer
local renderer = eeObj.GetGpr(gpr.s0)
eeObj.WriteMemFloat(renderer+0x200, 1.3333333)
eeObj.WriteMemFloat(renderer+0x204, 1.7777777)
eeObj.WriteMem32(renderer+0x208, 2)
end)
 
emuObj.SetDisplayAspectWide()
 
-- CRC "settings.display.widescreen" = 0xbcf14d81
-- $s2 = SaveType (1 = new save)
 
local overlay = InsnOverlay({
0x27bdffe0, -- addiu $sp, -0x20
0xffbf0010, -- sd $ra, 0x10($sp)
0x0c0d49d8, -- jal Core::Memset(void *,int,uint)
0x00000000, -- nop
0x24030001, -- li $v1, 1
0x1472000b, -- bne $s2, $v1, +11
0x00000000, -- nop
0x0c09dacc, -- jal UFO::Progress::Get(void)
0x00000000, -- nop
0x3c01bcf1, -- lui $at, 0xbcf1
0x34214d81, -- ori $at, $at, 0x4d81
0xafa10000, -- sw $at, 0($sp)
0x24030001, -- li $v1, 1
0xa3a30004, -- sb $v1, 4($sp)
0x03a0282d, -- move $a1, $sp
0x0c09dd4c, -- jal UFO::Progress::Record::AddKey(UFO::Progress::Content const&)
0x0040202d, -- move $a0, $v0
0xdfbf0010, -- ld $ra, 0x10($sp)
0x03e00008, -- jr $ra
0x27bd0020  -- addiu $sp, 0x20
})
local call_overlay = 0x0c000000 | (overlay >> 2)
eeInsnReplace(0x2789F8, 0x0c0d49d8, call_overlay) -- UFO::Progress::Storage::PrepareWrite
#Official widescreen support.</pre>
 
====Destroy All Humans 2====
SLUS_214.39
<br>Text
<pre>--gs-use-mipmap=1
--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
#Fix for graphical glitches.</pre>
 
SLUS_214.39
<br>SLUS-21439_features.lua
<pre>-- Lua 5.3
-- Title:  Destroy All Humans! 2 PS2 - SLUS-21439 (USA)
-- Author:  Ernesto Corvi, Adam McInnis
 
-- Changelog:
 
apiRequest(0.7) -- request version 0.1 API. Calling apiRequest() is mandatory.
 
local eeObj = getEEObject()
local emuObj = getEmuObject()
local gpr = require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
 
-- Widescreen
eeObj.AddHook(0x33ca98, 0x3c0436c5, function() -- Graphics::Script::SetScreenRatio
local mode = eeObj.GetGpr(gpr.v0)
-- print(string.format("mode: %08x", mode))
if mode == 0x36c59d2b then -- widescreen
emuObj.SetDisplayAspectWide()
elseif mode == 0x855a87ef then -- standard
emuObj.SetDisplayAspectNormal()
end
end)
 
eeObj.AddHook(0x33afac, 0x0000282d, function() -- Graphics::Renderer::Renderer
eeObj.SetGpr(gpr.a1, 2)
end)
 
emuObj.SetDisplayAspectWide()
 
-- CRC "settings.display.anamorphic" = 0x8b36afe9
-- $s2 = SaveType (1 = new save)
 
local overlay = InsnOverlay({
0x27bdffe0, -- addiu $sp, -0x20
0xffbf0010, -- sd $ra, 0x10($sp)
0x0c059d02, -- memset
0x00000000, -- nop
0x24030001, -- li $v1, 1
0x1472000b, -- bne $s2, $v1, +11
0x00000000, -- nop
0x0c09b400, -- jal UFO::Progress::Get(void)
0x00000000, -- nop
0x3c01bcf1, -- lui $at, 0x8b36
0x34214d81, -- ori $at, $at, 0xafe9
0xafa10000, -- sw $at, 0($sp)
0x24030001, -- li $v1, 1
0xa3a30004, -- sb $v1, 4($sp)
0x03a0282d, -- move $a1, $sp
0x0c09dd4c, -- jal UFO::Progress::Record::AddKey(UFO::Progress::Content const&)
0x0040202d, -- move $a0, $v0
0xdfbf0010, -- ld $ra, 0x10($sp)
0x03e00008, -- jr $ra
0x27bd0020  -- addiu $sp, 0x20
})
local call_overlay = 0x0c000000 | (overlay >> 2)
eeInsnReplace(0x271AD0, 0x0c059d02, call_overlay) -- UFO::Progress::Storage::PrepareWrite
 
-- Disable Progressive Scan and Adjust Screen Position
 
local overlay2 = InsnOverlay({
0x27bdfff0, -- addiu $sp, -0x10
0xffbf0000, -- sd $ra, 0(sp)
0xffb00008, -- sd $s0, 8(sp)
0x3c05000f, -- lui $a1, 0x000f
0x34a57000, -- ori $a1, 0x7000
0x0c0db8b6, -- jal Script::State::DoString
0x0080802d, -- move $s0, $a0
0x24050001, -- li $a1, 1
0x0c0dba4c, -- jal Script::State::IsNull(int)
0x0200202d, -- move $a0, $s0
0xdfb00008, -- ld $s0, 8(sp)
0xdfbf0000, -- ld $ra, 0(sp)
0x03e00008, -- jr ra
0x27bd0010  -- addiu $sp, 0x10
})
local call_overlay2 = 0x0c000000 | (overlay2 >> 2)
eeInsnReplace(0x2e5a14, 0x0c0dba4c, call_overlay2) -- Sim::Manager::ProcessScript near Sim::Manager::SetPauseFlag
 
eeObj.AddHook(0x2e5a10, 0x0240202d, function() -- Sim::Manager::ProcessScript near Sim::Manager::SetPauseFlag
local luaString = [[
-- disable progressive scan and adjust screen
gui.i.SMOptionsDisplay.table.slots[3] = nil
gui.i.SMOptionsDisplay.table.slots[4] = nil
]]
eeObj.WriteMemStrZ(0xf7000, luaString)
end)
#Official widescreen support.</pre>
 
====Everybody's Tennis/Hot Shots Tennis====
SCES_545.35
<br>Text
<br>Text
<pre>--gs-upscale=point
<pre>--gs-use-deferred-l2h=0
--gs-uprender=2x2
--l2h-2d-params=0x0000000800000010,0x00000000300a1400,256
--gs-motion-factor=25
--gs-motion-factor=50
--host-audio-latency=0.01
--mtap1=always
--gs-opt-frbuff-switch=1
--gs-ignore-dirty-page-border=1
--gs-ignore-dirty-page-border=1
--gs-ignore-rect-correction=1
--ee-native-function=memcpy,0x11e328
--ee-native-function=memset,0x11e4e0
#performance and visual fix(?)</pre>
SCES_545.35
<br>LUA
<pre>local gpr = require("ee-gpr-alias")
require( "ee-hwaddr" )
apiRequest(1.4)
local eeObj = getEEObject()
-- function dump(addr)
--    print(string.format("=== dump %x ===", addr))
--    for i=0,0x1e do
--   print(string.format("  %08x : %08x %08x %08x %08x",
--   addr + i*16,
--   eeObj.ReadMem32(addr + i*16 + 0),
--   eeObj.ReadMem32(addr + i*16 + 4),
--   eeObj.ReadMem32(addr + i*16 + 8),
--   eeObj.ReadMem32(addr + i*16 +12)))
--    end
-- end
-- Bug#8285
-- This patch changes the color of background on :
-- - Language selection
-- - Company logo
-- - Start screen
-- - Some menu
-- which are in menu.bin overlay. Nothing affected in the actual game.
eeObj.DmaAddHook( 1, function()
if eeObj.ReadMem32(vif1_hw.TADR) == 0x1fd1c0 then
-- On language select
if eeObj.ReadMem32(0x4c8ef0) == 0x00ff9090 then
  eeObj.WriteMem32(0x4c8ef0, 0)
end
if eeObj.ReadMem32(0x548f30) == 0x00ff9090 then
  eeObj.WriteMem32(0x548f30, 0)
end
-- On company logo
if eeObj.ReadMem32(0x4c6d70) == 0x00ff9090 then
  eeObj.WriteMem32(0x4c6d70, 0)
end
if eeObj.ReadMem32(0x546db0) == 0x00ff9090 then
  eeObj.WriteMem32(0x546db0, 0)
end
end
end)
eeInsnReplace(0x103d58, 0x27bdffc0, 0x03e00008)                -- <SyncDCache>
eeInsnReplace(0x103d5c, 0xffb20020, 0x00000000)
eeNativeHook (0x103d58, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x103dd8, 0x3c02ffff, 0x03e00008)                -- <iSyncDCache>
eeInsnReplace(0x103ddc, 0x3442ffc0, 0x00000000)
eeNativeHook (0x103dd8, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x103e98, 0x27bdffc0, 0x03e00008)                -- <InvalidDCache>
eeInsnReplace(0x103e9c, 0xffb20020, 0x00000000)
eeNativeHook (0x103e98, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x103f18, 0x3c02ffff, 0x03e00008)                -- <iInvalidDCache>
eeInsnReplace(0x103f1c, 0x3442ffc0, 0x00000000)
eeNativeHook (0x103f18, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x106970, 0x3c19ffff, 0x03e00008)                -- <sceSifWriteBackDCache>
eeInsnReplace(0x106974, 0x3739ffc0, 0x00000000)
eeNativeHook (0x106970, 0x03e00008,'AdvanceClock',0x1700)
</pre>
====Fahrenheit/Indigo Prophecy====
SLES_535.39
<br>Text
<pre>--ee-hook=0x002097d0,FastForwardClock,0x8c6261fc
--ee-hook=0x1a5570,AdvanceClock,,500000
--ee-hook=0x00223c48,AdvanceClock,0x0080382d,8000
--gs-kernel-cl="h2lpool"
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
--gs-kernel-cl-up="h2lpool2x2"
--gs-h2l-list-opt=1
#Performance fix.</pre>
--gs-h2l-accurate-hash=1
 
#fix for substantial slowdown during combat.</pre>
SLES_535.39
<br>LUA
<pre>This is a substantial file. Over 20,000 lines with an extensive performance fix. I'm sharing the file itself as a download link.
 
https://drive.google.com/file/d/1L2YxondID65KIAybKVCBH9KgFegqqOeQ/view
 
-- Performace fix (bug #9785 )
-- bug#8571
-- ignore 'no wait vsync' case.
-- unsyncv causes major slowness on loading screen, because the game pushes LOTS of identical frame data to GS.</pre>
 
SLES_535.39
<br>SLES-53539_features.lua
<pre>-- Lua 5.3
-- Title:  Fahrenheit PS2 - SLES-53539 (EUR)
-- Author:  Ernesto Corvi, Adam McInnis
 
-- Changelog:
 
require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
require( "ee-cpr0-alias" ) -- for EE CPR
 
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
 
local eeObj = getEEObject()
local emuObj = getEmuObject()
 
local L1 = function() -- QDT::SINT::SCRIPT_LOADING_SCREEN::EM::Run
emuObj.ThrottleMax()
end
local L2 = function() -- QDT::SINT::SCRIPT_LOADING_SCREEN::EM::Stop
emuObj.ThrottleNorm()
end
local load1 = eeObj.AddHook(0x387040, 0x3c02004b, L1) -- QDT::SINT::SCRIPT_LOADING_SCREEN::Run
local load2 = eeObj.AddHook(0x387090, 0x3c02004b, L2) -- QDT::SINT::SCRIPT_LOADING_SCREEN::Stop
 
-- Widescreen
eeInsnReplace(0x20a7c0, 0x3c013faa, 0x3c013fe3)
eeInsnReplace(0x20a7c4, 0x3421aaab, 0x34218e39)
emuObj.SetDisplayAspectWide()
 
-- Skip video mode options
local videomenuVM = { 0x04, 0x01, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00,
  0x3B, 0x0D, 0x00, 0x00, 0x3B, 0x0B, 0x00, 0x00,
  0x3B, 0x26, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 }
 
local visualmenuVM = { 0x04, 0x01, 0x00, 0x00, 0xA2, 0x00, 0x00, 0x00,
  0x3B, 0x19, 0x00, 0x00, 0x3B, 0x18, 0x00, 0x00 }
 
-- locates src chunk on (dst,cnt). -1 if not found, offset if found
local locateChunk = function(src, dst, count)
local offs = -1
for x = 0, count - #src do
if eeObj.ReadMem8(dst+x) == src[1] then
local found = true
for y = 1, #src do
if eeObj.ReadMem8(dst+x+y-1) ~= src[y] then
found = false
break
end
end
if found == true then
offs = x
break
end
end
end
return offs
end
 
eeObj.AddHook(0x2812b0, 0x27bdfff0, function() -- QDT::VM::BYTE_CODE::BYTE_CODE
local obj = eeObj.GetGpr(gpr.a1)
local bytecode = eeObj.ReadMem32(obj+0x18)
local count = eeObj.ReadMem32(obj+0x20)
if count > #videomenuVM then
local offs = locateChunk(videomenuVM, bytecode, count)
if offs >= 0 then
print("Skipping video mode menu")
eeObj.WriteMem8(bytecode+offs+4, 8) -- beq 0x44 -> beq 0x8
end
end
if count > #visualmenuVM then
local offs = locateChunk(visualmenuVM, bytecode, count)
if offs >= 0 then
print("Skipping visual mode video menu")
eeObj.WriteMem8(bytecode+offs+1, 2) -- beq 0xa2 -> bne 0xa2
end
end
end)
 
-- Force 60hz
eeInsnReplace(0x207ae0, 0x00a0802d, 0x24100001) -- move $s0, $a1 -> li $s0, 1
 
-- Fix for bug 9716, which is a bug in the game.
-- Trying to retrieve a COM handle in the game will cause an infinite
-- loop if the handle has been deallocated and the debug server is not
-- connected. There's apparently a small race condition in the Asylum
-- level that sometimes can trigger the bug.
-- The fix involves getting out of the loop.
-- It causes a small visual glitch but otherwise the game continues to work fine.
 
eeInsnReplace(0x1c5958, 0x10400005, 0) -- QDT::KCOM::COM_SERVICE::RetrieveComHandle
eeInsnReplace(0x1c5b6c, 0x10400005, 0) -- QDT::KCOM::COM_SERVICE::RetrieveComHandle
eeInsnReplace(0x1c5d24, 0x10400005, 0) -- QDT::KCOM::COM_SERVICE::RetrieveComHandle
#Official widescreen support, forced 60Hz/NTSC, along with a game crash bug fix.</pre>
 
====Fatal Fury: Battle Archives volume 2====
ALL
<br>Text
<pre>--gs-uprender=none
--gs-upscale=point
--host-audio-latency=0.010
--force-frame-blend=1
#Graphical fix.</pre>
 
SLUS_217.23
<br>SLUS-21723_features.lua
<pre>This is a substantial file. Over 500 lines with additional controller/fightstick support and various shader/bezel files. I'm sharing the file itself as a download link.
 
https://drive.google.com/file/d/1FPPPJiHOazTXaD-H6K3kLACYDSdDeAE1/view
 
#official widescreen support in the form of screen bezels, along with expanded fightstick support and scanline shaders.</pre>
 
====Fu'un Super Combo!!!====
SLPS_257.81
<br>Text
<pre>--gs-uprender=2x2
--gs-upscale=point
--host-audio-latency=0.3
--ee-hook=0x127050,AdvanceClock,0x2403002b,0x4000
--ee-hook=0x106734,FastForwardClock,0x0c04149c
--ee-native-function=memcpy,0x11fa9c,0x0080402d
--force-frame-blend=1
--vif1-ignore-cmd-ints=1
#Graphical and performance fixes.</pre>
 
SLPS_257.81
<br>LUA
<pre>
apiRequest(1.4)
 
eeNativeFunction(0x11fa9c, 0x0080402d, 'memcpy')
eeNativeFunction(0x11fb48, 0x2cc20008, 'memset')
 
eeInsnReplace(0x1279d0, 0x27bdffc0, 0x03e00008)                -- <SyncDCache>
eeInsnReplace(0x1279d4, 0xffb20020, 0x00000000)
eeNativeHook (0x1279d0, 0x03e00008,'AdvanceClock',0xa00)
eeInsnReplace(0x127b00, 0x27bdffc0, 0x03e00008)                -- <InvalidDCache>
eeInsnReplace(0x127b04, 0xffb20020, 0x00000000)
eeNativeHook (0x127b00, 0x03e00008,'AdvanceClock',0xa00)
eeInsnReplace(0x12a258, 0x3c19ffff, 0x03e00008)                -- <sceSifWriteBackDCache>
eeInsnReplace(0x12a25c, 0x3739ffc0, 0x00000000)
eeNativeHook (0x12a258, 0x03e00008,'AdvanceClock',0x1700)
 
require("ee-gpr-alias")
 
local eeObj = getEEObject()
local emuObj = getEmuObject()
 
-- *** viBufBeginPut (1)
--eeInsnReplace(0x105628, 0x0c049c78, 0) -- jal 1271e0 <WaitSema>
eeInsnReplace(0x1056c8, 0x0c049c70, 0) -- jal 1271c0 <SignalSema>
-- *** viBufEndPut (1)
eeInsnReplace(0x105708, 0x0c049c78, 0) -- jal 1271e0 <WaitSema>
--eeInsnReplace(0x105730, 0x0c049c70, 0) -- jal 1271c0 <SignalSema>
-- *** viBufFlush (1)
--eeInsnReplace(0x105a88, 0x0c049c78, 0) -- jal 1271e0 <WaitSema>
--eeInsnReplace(0x105ab8, 0x0c049c70, 0) -- jal 1271c0 <SignalSema>
-- *** viBufPutTs (1)
eeInsnReplace(0x105c10, 0x0c049c78, 0) -- jal 1271e0 <WaitSema>
eeInsnReplace(0x105cf4, 0x0c049c70, 0) -- jal 1271c0 <SignalSema>
 
-- it's redundant calling of _waitIpuIdle in libmpeg... not so huge impact tho.
eeInsnReplace(0x118620, 0x0c04672a, 0) -- jal 119ca8 <_waitIpuIdle>
 
-- bug# 9972
local emuObj = getEmuObject()
emuObj.SetGsTitleFix( "ignoreSubBuffCov", "reserved", { } )
#Crash/stall fixes.</pre>
 
====Grand Theft Auto III====
SLUS_200.62
<br>Text
<pre>--vu1-no-clamping=0
--gs-check-trans-rejection=1
--gs-kernel-cl-up="up2x2tc"
--gs-optimize-30fps=1
--ee-hook=0x27cea8,FastForwardClock
#Performance and graphical fix.</pre>
 
SLUS_200.62
<br>LUA
<pre>
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
 
-- Performace fix
local emuObj = getEmuObject()
local thresholdArea = 600
emuObj.SetGsTitleFix( "ignoreUpRender", thresholdArea , {alpha=0x80008068 , zmsk=1 } )
 
 
-- Bug#9133
-- workaround ... -16020(gp) value is something wrong. the value comes from CCamera::Process().
--                unfortunately accurate math or any other flags don't help for this problem,
--   even though it should be calculation error issue.
--   for here, it's just given 0 radian for CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension()
--   actually the cloud is a billboard, so it should have 0 degree in view-space.
--   so given 0 degree must be OK.... but could cause some corruption (wrong perspective or something)
eeInsnReplace(0x318344, 0xc792c16c, 0x44809000) -- lwc1 $f18,-16020(gp)
#Performance fix.</pre>
 
SLUS_200.62
<br>SLUS-20062_features.lua
<pre>-- Lua 5.3
-- Title:  Grand Theft Auto III PS2 - SLUS-20062 (USA) v1.40
-- Author: Nicola Salmoria
-- Date:  November 3, 2015
 
 
require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
 
apiRequest(0.7) -- need widescreen support
 
local eeObj = getEEObject()
local emuObj = getEmuObject()
 
 
local USEWIDESCREEN_ADDRESS = 0x416748
 
local H1 = -- start of main()
function()
eeObj.WriteMem8(USEWIDESCREEN_ADDRESS, 1) -- enable widescreen
end
 
local H2 = -- change widescreen flag
function()
local isWidescreen = eeObj.GetGpr(gpr.v0)
if isWidescreen == 0 then
emuObj.SetDisplayAspectNormal()
else
emuObj.SetDisplayAspectWide()
end
end
 
local hook1 = eeObj.AddHook(0x27ed04, 0x7fbf0000, H1) -- <main>:
local hook2 = eeObj.AddHook(0x270e50, 0xa382b8d8, H2) -- <CMenuManager::AnaliseMenuContents(void)>:
#Official widescreen support.</pre>
 
====Grand Theft Auto: San Andreas====
SLUS_209.46
<br>Text
<pre>--gs-optimize-30fps=1
--ee-hook=0x34dee8,FastForwardClock
--ee-hook=0x00245ee0,FastForwardClock
--cop2-no-clamping=1
--gs-flush-ad-xyz=safe
--vu1-clamp-range=0x04a,0x069
--gs-use-deferred-l2h=0
#Performance optimisation/fix.</pre>
 
SLUS_209.46
<br>LUA
<pre>apiRequest(0.6) -- request version 0.1 API. Calling apiRequest() is mandatory.
 
-- bug#8979
-- The game bugged.
-- CStreaming::StreamPedsIntoRandomSlots(int*) expects 8 integers arrray to process,
-- but CCheat::LoveConquersAllCheat() function copies just only 6 integers to the stack.
-- it seems the table of the source is correct, so using lq/sq instead of ld/sd to copy
-- the contents of the table correctly.
eeInsnReplace(0x59fbb0, 0xdca20010, 0x78a20010) -- ld v0,16(a1) => lq
eeInsnReplace(0x59fbb8, 0xfc820010, 0x7c820010) -- sd v0,16(a0) => sq
 
-- bug#8979, actually different one
-- the game has another bug... see https://pss.usrd.scea.com/bugzilla/show_bug.cgi?id=8979
eeInsnReplace(0x1abdd8, 0x102000d9, 0x102000cf) -- beqz at,1ac140 <CPopulation::AddPed(ePedType, unsigned int, CVector const &, bool)+0x3a0>
 
-- Performace fix
local emuObj = getEmuObject()
local thresholdArea = 700
emuObj.SetGsTitleFix( "ignoreUpRender", thresholdArea , {alpha=0x80000044 , zmsk=1 } )
#Performance and rendering fixes.</pre>
 
SLUS_209.46
<br>SLUS-20946_features.lua
<pre>-- Lua 5.3
-- Title: Grand Theft Auto: San Andreas - SLUS-20946 (USA) v3.00
-- Author: Nicola Salmoria
-- Date:  November 5, 2015
 
 
require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
 
apiRequest(0.7) -- need widescreen support
 
local eeObj = getEEObject()
local emuObj = getEmuObject()
 
 
local USEWIDESCREEN_ADDRESS = 0x7004ef
 
local H1 = -- init widescreen flag
function()
eeObj.WriteMem8(USEWIDESCREEN_ADDRESS, 1) -- enable widescreen
end
 
local H2 = -- main game loop
function()
local isWidescreen = eeObj.ReadMem8(USEWIDESCREEN_ADDRESS)
if isWidescreen == 0 then
emuObj.SetDisplayAspectNormal()
else
emuObj.SetDisplayAspectWide()
end
end
 
 
local hook1 = eeObj.AddHook(0x233584, 0xa200004f, H1) -- <CMenuManager::__ct(void)>:
local hook2 = eeObj.AddHook(0x246750, 0x24040012, H2) -- <TheGame(void)>:
#Official widescreen support.</pre>
 
====Grand Theft Auto: Vice City====
SLUS_205.52
<br>Text
<pre>--gs-check-trans-rejection=1
--gs-kernel-cl-up="up2x2tc"
--gs-optimize-30fps=1
--ee-hook=0x277b88,FastForwardClock
--ee-hook=0x279a18,FastForwardClock
#Performance fix.</pre>
 
SLUS_205.52
<br>LUA
<pre>
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
 
 
-- Performace fix
local emuObj = getEmuObject()
local thresholdArea = 600
emuObj.SetGsTitleFix( "ignoreUpRender", thresholdArea , {alpha=0x80008068 , zmsk=1 } )
 
 
-- Bug#9147
-- workaround ... -2104(gp) value is something wrong. the value comes from CCamera::Process().
--                unfortunately accurate math or any other flags don't help for this problem,
--   even though it should be calculation error issue.
--   for here, it's just given 0 radian for CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension()
--   actually the cloud is a billboard, so it should have 0 degree in view-space.
--   so given 0 degree must be OK.... but could cause some corruption (wrong perspective or something)
eeInsnReplace(0x334d64, 0xc792f7c8, 0x44809000) -- lwc1 $f18,-2104(gp)
#Performance fix.</pre>
 
SLUS_205.52
<br>SLUS-20552_features.lua
<pre>-- Lua 5.3
-- Title: Grand Theft Auto: Vice City - SLUS-20552 (USA) v3.00
-- Author: Nicola Salmoria
-- Date:  November 4, 2015
 
 
require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
 
apiRequest(0.7) -- need widescreen support
 
local eeObj = getEEObject()
local emuObj = getEmuObject()
 
 
local USEWIDESCREEN_ADDRESS = 0x4ba7bc
 
local H1 = -- start of main()
function()
eeObj.WriteMem8(USEWIDESCREEN_ADDRESS, 1) -- enable widescreen
end
 
local H2 = -- main game loop
function()
local isWidescreen = eeObj.ReadMem8(USEWIDESCREEN_ADDRESS)
if isWidescreen == 0 then
emuObj.SetDisplayAspectNormal()
else
emuObj.SetDisplayAspectWide()
end
end
 
 
local hook1 = eeObj.AddHook(0x279384, 0xffbf0000, H1) -- <main>:
local hook2 = eeObj.AddHook(0x277784, 0x00000000, H2) -- <TheGame(void)>:
 
 
-- Fix for bug #9161. The 'flying cars' cheat causes crashes when attempting to
-- fly an helicopter. We avoid that by disabling recognition of the cheat altogether.
-- The SLPM version comes with the cheat disabled out of the box.
eeInsnReplace(0x27db2c, 0x14400015, 0x10000015) -- bnez -> b
#Official widescreen support and removal of "flying cars" cheat due to game crash.</pre>
 
====Jak and Daxter: The Precursor Legacy====
SCES_503.61
<br>Text
<pre>--ee-jit-pagefault-threshold=20
--gs-frontend-opt-mode=1
--gs-use-mipmap=1
--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--vif-ignore-invalid-cmd=1
--vu1-mpg-cycles=144
--cop2-no-clamping=1
--host-audio-latency=0.040
#performance and graphical fix.</pre>
 
SCES_503.61
<br>LUA
<pre>-- Jak EU
apiRequest(2.2)
 
local gpr    = require("ee-gpr-alias")
local emuObj = getEmuObject()
local eeObj = getEEObject()
local gsObj = getGsObject()
local eeOverlay = eeObj.getOverlayObject()
 
-- Disable internal field shift compensation, part of post-process removal feature.
gsObj.SetDeinterlaceShift(0)
 
-- Fix shadow
emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", { texMode=1  } )
 
-- Reduce flush count
emuObj.SetGsTitleFix( "SetSelfRender", "reserved", { fbmask= 0x00FFFFFF , renderSelf=1 , zmsk=1 , alpha=0 , texMode=1  } )
 
-- Disable post-processing
-- update: removed due to occasional regression (bug#10608).  post-processing is now skipped in the EE via 'depth-cue'
-- emuObj.SetGsTitleFix( "ignoreSprite", "reserved", {  texType=1 , tw=5 , th=8, zmsk=1 , alpha=0x80000044  } )
 
-- ------------------------- OVERLAY MANAGER --------------------------
g_OnOverlayRegistered = function(filename, start, size)
-- global function provided for adding per-overlay callback handlers.
end
 
local DH8 = function()
local s0 = eeObj.GetGpr(gpr.s0)
local linkblock = eeObj.ReadMem32(s0+0x5c)
--print( string.format("--> PRELOAD %08x %08x",s0, linkblock) )
local linkblock_allocate_length = eeObj.ReadMem32 (linkblock + 0x00)
local linkblock_allocate_version = eeObj.ReadMem32 (linkblock + 0x04)
local linkblock_allocate_segment_count = eeObj.ReadMem32 (linkblock + 0x08)
local linkblock_allocate_name = eeObj.ReadMemStr(linkblock + 0x0c)
local linkblock_allocate_seg1_linkptr = eeObj.ReadMem32 (linkblock + 0x4C)
local linkblock_allocate_seg1_dataptr = eeObj.ReadMem32 (linkblock + 0x50)
local linkblock_allocate_seg1_size = eeObj.ReadMem32 (linkblock + 0x54)
local linkblock_allocate_seg1_flags = eeObj.ReadMem32 (linkblock + 0x58)
                                                             
local linkblock_allocate_seg2_linkptr = eeObj.ReadMem32 (linkblock + 0x5C)
local linkblock_allocate_seg2_dataptr = eeObj.ReadMem32 (linkblock + 0x60)
local linkblock_allocate_seg2_size = eeObj.ReadMem32 (linkblock + 0x64)
local linkblock_allocate_seg2_flags = eeObj.ReadMem32 (linkblock + 0x68)
                                                             
local linkblock_allocate_seg3_linkptr = eeObj.ReadMem32 (linkblock + 0x6C)
local linkblock_allocate_seg3_dataptr = eeObj.ReadMem32 (linkblock + 0x70)
local linkblock_allocate_seg3_size = eeObj.ReadMem32 (linkblock + 0x74)
local linkblock_allocate_seg3_flags = eeObj.ReadMem32 (linkblock + 0x78)
-- seg1 is equiv to main in Jak3
-- seg3 is equiv to top  in Jak3
-- seg2 appears to be unused ... ?  --jstine
 
if emuObj.IsToolingVerbose() then
print( string.format("--> LOADED SEGMENT alloc_len %08x ver %08x segcount %08x  name:\"%s\"", linkblock_allocate_length, linkblock_allocate_version, linkblock_allocate_segment_count, linkblock_allocate_name) )
print( string.format("    seg1linkptr %08x seg1dataptr %08x seg1size %08x seg1flags %08x", linkblock_allocate_seg1_linkptr, linkblock_allocate_seg1_dataptr, linkblock_allocate_seg1_size, linkblock_allocate_seg1_flags) )
print( string.format("    seg2linkptr %08x seg2dataptr %08x seg2size %08x seg2flags %08x", linkblock_allocate_seg2_linkptr, linkblock_allocate_seg2_dataptr, linkblock_allocate_seg2_size, linkblock_allocate_seg2_flags) )
print( string.format("    seg3linkptr %08x seg3dataptr %08x seg3size %08x seg3flags %08x", linkblock_allocate_seg3_linkptr, linkblock_allocate_seg3_dataptr, linkblock_allocate_seg3_size, linkblock_allocate_seg3_flags) )
end
 
if linkblock_allocate_seg1_size ~= 0 then eeOverlay.Register(linkblock_allocate_name .. ".seg1",  linkblock_allocate_seg1_dataptr, linkblock_allocate_seg1_size, false) end
if linkblock_allocate_seg3_size ~= 0 then eeOverlay.Register(linkblock_allocate_name .. ".seg3",  linkblock_allocate_seg3_dataptr, linkblock_allocate_seg3_size, true)  end
 
if (g_OnOverlayRegistered ~= nil) then
-- Make sure to execute any previously registered OnOverlay handler
if linkblock_allocate_seg1_size ~= 0 then g_OnOverlayRegistered(linkblock_allocate_name .. ".seg1", linkblock_allocate_seg1_dataptr, linkblock_allocate_seg1_size) end
if linkblock_allocate_seg1_size ~= 0 then g_OnOverlayRegistered(linkblock_allocate_name .. ".seg3", linkblock_allocate_seg3_dataptr, linkblock_allocate_seg3_size) end
end
end
 
assert(g_OnOverlayRegistered ~= nil)
local prev_OnOverlayRegistered = g_OnOverlayRegistered
 
g_OnOverlayRegistered = function(filename, start, size)
if filename == "depth-cue.seg1" then
-- Disable full-screen post process via depth-cue.
-- This also removes half-pixel shift during interlacing.
-- <depth-cue.seg1+00039c>
-- 00701DFC:67BDFFF0                daddiu      $sp,$sp,-0x10 (0xfffffff0) -> 03E00008                jr          $ra
-- 00701E00:FFBE0008                sd          $fp,8($sp)                    -> 00000000 nop
 
eeObj.WriteMem32(start + 0x39c, 0x03E00008)
eeObj.WriteMem32(start + 0x3a0, 0x00000000)
eeObj.WriteMem32(start + 0x004, 0x03E00008)
eeObj.WriteMem32(start + 0x008, 0x00000000)
end
 
if (prev_OnOverlayRegistered ~= nil) then
-- Make sure to execute any previously registered OnOverlay handler
prev_OnOverlayRegistered(filename, start, size)
end
end
 
-- hooked in link_control::finish(void)>:
eeObj.AddHook(0x0010ACF8, 0x040C825, DH8)  -- this is address US:0010abe0 JP:0010abd8 EU:0010ACF8
#Graphical fix, removal of intensive post process effects.</pre>
 
SCES-50361
<br>SCES-50361_features.lua
<pre>This is a substantial file. Over 700 lines with an extensive graphical and control fix. I'm sharing the file itself as a download link.
 
https://drive.google.com/file/d/1KppgZpiK5bgESrpSRKo6kKPTysZ-NAC9/view
 
#Shadows fix, control scheme changes, forced 60Hz/NTSC/Widescreen.</pre>
 
====King of Fighters 98 Ultimate Match====
ALL
<br>Text
<pre>--force-frame-blend=1
--gs-use-deferred-l2h=0
#Graphical fix.</pre>
 
SLES_552.80
<br>SLES-55280_features.lua
<pre>This is a substantial file. Over 800 lines with additional controller/fightstick support and various shader/bezel files. I'm sharing the file itself as a download link.
 
https://drive.google.com/file/d/1-lArL1Yqe079Ni3G-ZtHr8hqNPUsjQJy/view
 
#More stick support, shaders, bezels, widescreen fix.</pre>
 
====King of Fighters 2000====
ALL
<br>Text
<pre>--gs-uprender=none
--gs-upscale=point
--host-audio-latency=0.01
--hid-pad=1
#graphical fixes and support for further fightsticks.</pre>
 
SLUS_208.34
<br>LUA
<pre>-- The King of Fighters 2000
 
apiRequest(1.1)
 
 
local emuObj = getEmuObject()
--will fix sprite rendering artifact
ndx = 28
val = 0x86
-- spriteCorrectionTab[ndx] = val
emuObj.SetGsTitleFix( "globalSet",  "reserved", { fixSpriteDivTab = val | ( ndx<<16) })
#graphical fixes.</pre>
 
SLUS_208.34
<br>SLUS-20834_features.lua
<pre>This is a substantial file. Over 700 lines with additional controller/fightstick support and various shader/bezel files. I'm sharing the file itself as a download link.
 
https://drive.google.com/file/d/1FsPnuxgEa0ymnGdU6w2tdy-eamRN6l3e/view
 
#More stick support, shaders, bezels, widescreen fix.</pre>


====Manhunt====
====Manhunt====
Line 85: Line 922:
eeObj.AddHookJT(0x1d71f8, 0x10000036, FixBug9277)
eeObj.AddHookJT(0x1d71f8, 0x10000036, FixBug9277)
#Further bug fixes as well as fixing bloom/overglare from lightsources.</pre>
#Further bug fixes as well as fixing bloom/overglare from lightsources.</pre>
====Max Payne====
SLES_503.26
<br>Text
<pre>--gs-use-clut-merge=1
--gs-kernel-cl="clutmerge"
--gs-kernel-cl-up="clutmerge2x2"
--vu1-no-clamping=1
--vu0-no-clamping=1
--fpu-no-clamping=1
--force-pal-60hz=1
--vu1-mpg-cycles=1000
--safe-area-min=1.0
--fpu-accurate-mul-fast=1
--fpu-accurate-muldiv-range=0x2acce0,0x2acce0
#Graphics clean-up</pre>
SLES_503.26
<br> Features Lua
<pre>-- Max Payne [US]
-- Lua 5.3
-- Title: Max Payne - SLES-50326 (Europe FIGS) v1.00
require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
apiRequest(0.2) -- request version 0.2 API for throttling control.
local eeObj = getEEObject()
local emuObj = getEmuObject()
local TH1A = -- start of main()
function()
emuObj.ThrottleMax()
end
local TH1B = -- init loading screen
function()
local mode = eeObj.GetGpr(gpr.a0)
if mode ~= 4 then -- not sure what mode 4 is, but doesn't precede a real loading
emuObj.ThrottleMax()
end
end
local TH1C = -- advance progress bar
function()
local pct = eeObj.GetFpr(2)
if pct >= 1.0 then
emuObj.ThrottleNorm()
end
end
-- register hooks
local registeredHooks = {}
maxpayne_features_unregisterHooks = function() -- global function (called by trophy_data)
for _, hook in pairs(registeredHooks) do
eeObj.RemoveHook(hook)
end
registeredHooks = {}
end
maxpayne_features_registerHooks = function() -- global function (called by trophy_data)
registeredHooks = {
eeObj.AddHook(0x133dc8, 0x24030001, TH1A), -- <main>:
eeObj.AddHook(0x15ed7c, 0x24030003, TH1B), -- <MaxPayne_GameMode::initLoadingScreen(void)>:
eeObj.AddHook(0x133078, 0xc4a20000, TH1C), -- <UpdateProgressBarKH(void)>:
}
end</pre>
====Metal Slug Anthology====
ALL
<br>Text
<pre>--host-audio-latency=0.010
--gs-upscale=point
--gs-uprender=none
#fix for graphical glitches.</pre>
SLUS_215.50
<br>LUA
<pre>
-- Metal Slug Anthology PS2 - SLUS-21550 (USA)
apiRequest(1.2) -- request version 0.1 API. Calling apiRequest() is mandatory.
local eeObj = getEEObject()
local emuObj = getEmuObject()
-- Fix for black screen booting an elf. This is a game bug.
-- The v1.0 of the game suffered from an intermittent bug on the real PS2
-- where sometimes it would hang on a black screen trying to launch a new elf.
-- This is apparently due to a bad IOP state, which caused sceCdInit to hang.
-- Later versions of the game (1.1, 1.2) attempted to fix this in different ways.
-- On Olympus, v1.0 (USA) hangs always, while v1.2 (EUR/JPN) works always.
-- The fix implemented here replaces a call to FlushCache() to loadImageAndReboot(),
-- which is a function that reboots the IOP and resolves the hang.
eeInsnReplace(0x189c24, 0x0c08f7f8, 0x0c061dd2) -- FlushCache() -> loadImageAndReboot()
eeInsnReplace(0x117804, 0x0c0c1e08, 0x0c045e20) -- FlushCache() -> loadImageAndReboot()
</pre>
====Parappa the Rapper 2====
ALL
<br>Text
<pre>--host-audio-latency=0.01
#fix for audio off sync.</pre>
SCUS_971.67
<br>LUA
<pre>
-- Parappa the Rapper 2  [SCUS-97167]
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
require( "ee-gpr-alias" )
require( "ee-hwaddr" )
local eeObj = getEEObject()
-- ================================================================================================
-- Title issues racy combination of VIF1 and GIF transfers.  It expects GIF to finish ahead of VU
-- XGKICK (via VIF1), which is atypical among PS2 titles (XGKICK has HW priority over GIF, and so
-- GIF can only finish ahead of XGKICK in certain extreme cases).
--
-- Fixed by delaying the specific VIF1 transfer (identified by MADR) for a long time to ensure GIF
-- gains arbitration and finishes ahead of XGKICKs.
--
local fix01_dma_vif1 =
function()
local ee = eeObj
local tgtaddr = ee.GetGpr(gpr.s0)
-- print( string.format("success pt.1 : %x %x", vif1_hw.CHCR, tgtaddr ) )
if tgtaddr == vif1_hw.CHCR then
-- expected:
--  # DIR==1 and MOD==1  (chain)
--  # TADR==0x01C76AA0
local chcr = ee.GetGPR(gpr.v0)
if (chcr & 0x05) == 0x05 then
local tadr = ee.ReadMem32(vif1_hw.TADR);
if tadr == 0x01C76AA0 then
-- 0x6000 works fine, 0x6500 adds a little extra cushion.
ee.SchedulerDelayEvent("vif1.dma", 0x6500)
-- print( "Parappa fix applied!" )
end
end
end
end
-- ================================================================================================
eeObj.AddHook(0x0015A008, 0xAE020000, fix01_dma_vif1)
-- ================================================================================================
-- Our emulator has accuracy problems on so many places. In this title, we have problems on VU.
-- To be accurate on VU is quite painful (we won't be able to get reasonable performance with it)
-- So as workaround, we just disable bilinear textures on Render-To-Texture drawing.
-- Bug#8122
eeInsnReplace(0x118084, 0xde260008, 0x24060000) -- ld a2,8(s1)
eeInsnReplace(0x118798, 0xde260008, 0x24060000) -- ld a2,8(s1)
eeInsnReplace(0x118868, 0xde660008, 0x24060000) -- ld a2,8(s3)
eeInsnReplace(0x119d18, 0xdc460008, 0x24060000) -- ld a2,8(v0)
eeInsnReplace(0x119d18, 0xdc460008, 0x24060000) -- ld a2,8(v0)
</pre>
====Psychonauts====
SLUS_211.20
<br>Text
<pre>--vu1-jr-cache-policy=sameprog
--vu1-jalr-cache-policy=sameprog
--ee-hook=0x101fc0,FastForwardClock,0x3c0f0036
--ee-hook=0x110390,FastForwardClock,0x8d8f0000
--ee-hook=0x101c10,FastForwardClock,0x51cf0052
--gs-vert-precision=8
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
--gs-render-tile-threshold=300000
--vu-custom-min-max=0
--vu1-di-bits=0
--vu0-di-bits=0
--vu1-opt-vf00=2
--vu0-opt-vf00=2
--vu1-injection=1
--vu1-mpg-cycles=666
--vu1-mpg-cycles=1166,$000
--vu1-mpg-cycles=950,0xffffffff
--vu0-mpg-cycles=300,0xfc
--ee-hook=0x127630,AdvanceClock,0x27bdffd0,2100
--cdvd-sector-read-cycles=4000
--iop-cycle-scalar=1.6
#Seems like substantial performance fixes</pre>
SLUS_211.20
<br>LUA
<pre>-- psychonauts_slus21120
local gpr    = require("ee-gpr-alias")
local emuObj = getEmuObject()
apiRequest(1.0) -- request version 0.1 API. Calling apiRequest() is mandatory.
-- Bug#9174 -
emuObj.SetGsTitleFix( "ignoreSubBuffCov", "reserved", { } )
-- Bug#9240 (Light maps uprender)
-- Copy z-buffer for future use with light maps. psm = SCE_GS_PSMZ24 (49)
emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", {tw=9, th=9, psm=49, zmsk=1 } )
-- Apply light maps texMode=2 (bilinear)  psm= SCE_GS_PSMCT32 (0)
emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", {tw=8, th=8, psm=0, ztst=1, texMode=2 } )
-- Bug#9176
--
-- This bug seems GPUGS interpolation problem.
-- The game draws clouds as undiscovered area on the map, but
-- Z value is unstable --- sometimes 0x320, sometimes 0x321.
-- On drawing 'Highlight' object (which is missing one), it uses z=0x320 with
-- ZTST=GEQUAL. Therefore if the cloud renders with z=0x321, this highlighted object
-- doesn't appear. But it's OK on the real PS2 because of no-drawing right edge,
-- z=0x321 won't be available on the packet (interpolation differences between
-- the real PS2 and our gs)
-- it gives some values (50.0f) to get +1 on Z value for the highlighted object.
-- this value will be used later to create the packet in _sprite_ps2_push_data(ESprite*).
--
-- This old one causes a problem on some other scenes.
-- local eeObj = getEEObject()
-- eeObj.AddHook(0x1b276c, 0xe4400024, function()
-- local v0 = eeObj.GetGpr(gpr.v0)
-- local z  = eeObj.ReadMemFloat(v0+32)
-- eeObj.WriteMemFloat(v0+32, z+50.0)
-- end)
-- New one by Ernesto :
-- The idea is to apply the offset only on the marker.
local eeObj = getEEObject()
local adjustMapZHook = function() -- EMapRenderWindow::drawHighlightSprites
    eeObj.SetFpr(14, eeObj.GetFpr(14) + 50.0)
end
eeObj.AddHook(0x25d654, 0x8de40068, adjustMapZHook) -- \/
eeObj.AddHook(0x25d714, 0xe7b500cc, adjustMapZHook) -- /\
eeObj.AddHook(0x25d7d0, 0xe7b500cc, adjustMapZHook) -- <
eeObj.AddHook(0x25d894, 0x46000386, adjustMapZHook) -- >
-- bug#9423 - menus render 20+ times over again, causing very low fps.
-- The whole game in general has no concept of pacing and will re-draw frames multiple times
-- between vsync refreshes.  Hook placed on GameApp::EndFrame() measures time between frames and
-- if it's too short, the EE clock is advanced significantly to compensate.
local last_time = 0
local last_diff = 0
local advanceClockForAny = function()
local thistime = eeObj.GetClock()
local diff = thistime - last_time
local adv  = 0
if diff <= 0 then
-- sanity check, mostly for snapshot restore.
last_diff = diff
last_time = thistime
return
end
-- EE @ 30fps == roughly 10 million cycles
-- bug#9555 - We need to make a reasonable tally of VIF cycles across game display swaps.
--  Use a combination heuristic of EE and VIF1 cycles to gues at whether the title should
--  lock to 45fps, 30fps, or something worse.
local fastminEE = 1600000 -- less than this it's safe to run > 30 fps
local fastminVIF_30 = 2200000 -- VU1 total that merits 30hz throttle
local fastminVIF_45 = 1700000 -- VU1 total that merit 45hz throttle.
local baremin_wo_vif= 6100000 -- EE values below this get promoted to this value  (~50hz)
local forced30hz = 9330000
local forced45hz = 7820000
local vif1_cycles = eeObj.GetVif1Cycles()
if (vif1_cycles > forced30hz) then
vif1_cycles = forced30hz
end
local diff_vif = diff + vif1_cycles
adv = adv + vif1_cycles
-- Lock anything that seems like "Real Work" to either 30 or 45 FPS:
if diff_vif < fastminEE then
adv = adv + (fastminEE*2 - diff_vif)
elseif vif1_cycles > fastminVIF_30 and (diff+(fastminVIF_30)//2) < forced30hz then
adv = adv + (forced30hz  - diff - (fastminVIF_30)//2)
elseif vif1_cycles > fastminVIF_45 and (diff+(fastminVIF_45)//2) < forced45hz then
adv = adv + (forced45hz  - diff - (fastminVIF_45)//2)
elseif diff < baremin_wo_vif then
adv = adv + (baremin_wo_vif  - diff)
end
-- print (string.format("DELTA: %d  ADV: %d  VIF1: %d", diff, adv, vif1_cycles))
if adv ~= 0 then
eeObj.AdvanceClock(adv)
end
-- Ensure next frame's delta time takes into consideration this frame's advancement.
-- Otherwise each fraem delta time would get progressively worse.
thistime = thistime + adv
last_time = thistime
last_diff = diff
end
local advanceClockForGame = function() advanceClockForAny(5300000, 2700000) end
eeObj.AddHookJT(0x207cf8, 0x27bdfff0, advanceClockForGame)   -- <GameApp::EndFrame()>:
#Performance and optimisations</pre>
====Red Faction====
SLUS_200.73
<br>Text
<pre>--gs-use-deferred-l2h=1
--l2h-2d-params=0x0000000800000001,0x000000003a0a2300,512,2
--vu1=jit-sync
--ee-cycle-scalar=1.02
--ee-hook=0x00213370,FastForwardClock,0x8F8293A8
--ee-hook=0x24ce30,AdvanceClock,0x8c620000,20000
--ee-hook=0x272b44,FastForwardClock,0x3c0201ee
--ee-hook=0x272bc4,FastForwardClock,0x3c0201ee
--ee-hook=0x21b354,AdvanceClock,0x3c031000,0x1240
#performance fixes.</pre>
SLUS_200.73
<br>LUA
<pre>-- Red Faction [US]
apiRequest(1.6)
local gpr = require("ee-gpr-alias")
-- title uses memcpy() to write to VU1 memory, so some instances will be hotfixed to
-- use slowpath_memcpy() at runtime.
eeNativeFunction(0x259820, 0x0080402d, 'memcpy')
eeNativeFunction(0x2599d8, 0x2cc20008, 'memset')
eeNativeFunction(0x253870, 0x27bdffd0, 'ieee754_acosf')
eeNativeFunction(0x254620, 0x44026000, 'ieee754_sqrtf')
eeNativeFunction(0x255a50, 0x44026000, 'cosf')
eeNativeFunction(0x255df0, 0x44026000, 'sinf')
eeNativeFunction(0x256318, 0x27bdffa0, 'acosf')
eeInsnReplace(0x24d7e0, 0x24030064, 0x03e00008)                -- <FlushCache>
eeInsnReplace(0x24d7e4, 0x0000000c, 0x00000000)
eeNativeHook (0x24d7e0, 0x03e00008,'AdvanceClock',0xa00)
eeInsnReplace(0x24d810, 0x2403ff98, 0x03e00008)                -- <iFlushCache>
eeInsnReplace(0x24d814, 0x0000000c, 0x00000000)
eeNativeHook (0x24d810, 0x03e00008,'AdvanceClock',0xa00)
eeInsnReplace(0x24de20, 0x27bdffe0, 0x03e00008)                -- <SyncDCache>
eeInsnReplace(0x24de24, 0x0080302d, 0x00000000)
eeNativeHook (0x24de20, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x24de98, 0x3c02ffff, 0x03e00008)                -- <iSyncDCache>
eeInsnReplace(0x24de9c, 0x3442ffc0, 0x00000000)
eeNativeHook (0x24de98, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x24df58, 0x27bdffe0, 0x03e00008)                -- <InvalidDCache>
eeInsnReplace(0x24df5c, 0x0080302d, 0x00000000)
eeNativeHook (0x24df58, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x24dfd0, 0x3c02ffff, 0x03e00008)                -- <iInvalidDCache>
eeInsnReplace(0x24dfd4, 0x3442ffc0, 0x00000000)
eeNativeHook (0x24dfd0, 0x03e00008,'AdvanceClock',0x600)
local emuObj = getEmuObject()
local eeObj = getEEObject()
-- bug#10159 workaround
-- slowdown the jeep speed....
local jeepObj = 0
eeObj.AddHook(0x1376f0, 0xc6600174, function()
jeepObj = eeObj.GetGpr(gpr.s1)
end)
eeObj.AddHook(0x137a48, 0xc7ac00bc, function()
local s1 = eeObj.GetGpr(gpr.s1)
if s1 == jeepObj then
eeObj.SetFpr(12, eeObj.GetFpr(12)*0.90)
end
end)
-- bug#10249 workaround
-- forcibly calculate the jeep's suspension.
eeObj.AddHook(0x19ee08, 0x8ec2120c, function()
if jeepObj - 624 == eeObj.GetGpr(gpr.s6) then
eeObj.SetGpr(gpr.v0, 1)
end
end)
-- debug code for jeep movment target.
-- local px = 0.0
-- local pz = 0.0
-- eeObj.AddHook(0x1375bc, 0x26650174, function()
-- local s1 = eeObj.GetGpr(gpr.s1)
-- if s1 == jeepObj then
-- local s3 = eeObj.GetGpr(gpr.s3)
-- px = eeObj.ReadMemFloat(s3 + 372)
-- pz = eeObj.ReadMemFloat(s3 + 380)
-- end
-- end)
-- eeObj.AddHook(0x1375c8, 0xa2620170, function()
-- local s1 = eeObj.GetGpr(gpr.s1)
-- if s1 == 0x19a7a00 then
-- local s3 = eeObj.GetGpr(gpr.s3)
-- local x = eeObj.ReadMemFloat(s3 + 372)
-- local z = eeObj.ReadMemFloat(s3 + 380)
-- if px ~= x or pz ~= z then
--   print(string.format("[%f %f] => [%f %f] v0=%d",
--   px, pz, x, z, eeObj.GetGpr(gpr.v0)))
-- end
--  end
-- end)
#physics calculations and performance fix.</pre>
SLUS_200.73
<br>SLUS-20073_features.lua
<pre>-- Lua 5.3
-- Title:  Red Faction PS2 - SLUS-20073 (USA)
-- Author:  Ernesto Corvi, Adam McInnis
-- Changelog:
apiRequest(1.1) -- request version 1.1 API. Calling apiRequest() is mandatory.
local eeObj = getEEObject()
local emuObj = getEmuObject()
local L1 =  -- main
function()
emuObj.ThrottleMax()
end
local L2 =  -- main
function()
emuObj.ThrottleNorm()
end
local load1 = eeObj.AddHook(0x165590, 0x27bdffb0, L1) -- game_load_level
local load2 = eeObj.AddHook(0x16578C, 0x7bb10010, L2) -- game_load_level
-- Widescreen support --
eeInsnReplace(0x2071c4, 0x00000000, 0x3c013f40) -- gr_setup_3d
eeInsnReplace(0x2071d0, 0x00000000, 0x4481f000) -- gr_setup_3d
eeInsnReplace(0x2072e0, 0x00000000, 0x461ea502) -- gr_setup_3d
eeInsnReplace(0x2072e8, 0x00000000, 0x461ead43) -- gr_setup_3d
eeInsnReplace(0x23a34c, 0x44826000, 0x461e0303) -- shadow_ngps_render_and_copy
eeInsnReplace(0x23a444, 0x3c024334, 0x3c024309) -- shadow_ngps_render_and_copy
emuObj.SetDisplayAspectWide()
#Official widescreen support.</pre>
====Resident Evil Code: Veronica X====
ALL
<br>Text
<pre>--ee-jit-pagefault-threshold=30
#crash fix.</pre>
ALL
<br>LUA
<pre>-- VeronicaX
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
-- Bug# 9976
local emuObj = getEmuObject()
emuObj.SetGsTitleFix( "clipScissors", "reserved", {alpha = 0 , frameW = 4 , psm = 0} )
#graphical fix.</pre>
====Rogue Galaxy====
ALL
<br>Text
<pre>--gs-kernel-cl-up="up2x2skipinterp"
--gs-optimize-30fps=1
#visual fixes and performance optimisation.</pre>
SCUS_974_90
<br>LUA
<pre>require("ee-gpr-alias")
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
-- Bug#8404 WORKAROUND
-- See https://pss.usrd.scea.com/bugzilla/show_bug.cgi?id=8404
eeInsnReplace(0x124898, 0x3442ffff, 0x3442fffe) -- ori v0,v0,0xffff
#unsure what this fixes.</pre>
====Samurai Shodown Anthology====
SLUS_216.29
<br>Text
<pre>--gs-upscale=point
--gs-uprender=2x2
--gs-motion-factor=25
--host-audio-latency=0.01
--gs-ignore-dirty-page-border=1
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
--gs-h2l-list-opt=1
--gs-h2l-accurate-hash=1
#fix for substantial slowdown during combat.</pre>
====Star Wars Bounty Hunter====
ALL
<br>Text
<pre>--gs-kernel-cl-up="OptRightTri"
--gs-vert-precision=8</pre>
====Star Wars: Jedi Starfighter====
SLES_503.71
<br>Text
<pre>--gs-check-trans-rejection68=1
--gs-dirty-page-policy=1</pre>
SLES_503.71
<br>Lua
<pre>-- Star Wars: Jedi Starfighter [SLES-50371] [EU]
require("ee-gpr-alias")
require("pad-and-key")
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
local eeObj = getEEObject()
local emuObj = getEmuObject()
-- Bug#9013 - title calls PS2::Exit() at the end of a bonus stage.
eeInsnReplace(0x323398, 0x0c116bb4, 0x00000000) --  jal    Stop__12CTaskManagerFv
-- Bug#8905
-- The game sets a little bit big DH values for GS Display Register.
-- mimic overscan cropping (generic crop happens in GsScanoutArea::Populate)
local dump_display = function()
  local a5 = eeObj.GetGpr(gpr.t1)
  local ds1_h = eeObj.ReadMem32(a5+892)
  local ds2_h = eeObj.ReadMem32(a5+908)
  local dh1  = (ds1_h>>(44-32))&0x7ff
  local dh2  = (ds2_h>>(44-32))&0x7ff
  if dh1 >= 574 then
  dh1 = 558 -- 574-16
  ds1_h = (ds1_h & 0xfff) | (dh1 << (44-32))
  eeObj.WriteMem32(a5+892, ds1_h)
  end
  if dh2 >= 575 then
  dh2 = 559 -- 575-16
  ds2_h = (ds2_h & 0xfff) | (dh2 << (44-32))
  eeObj.WriteMem32(a5+908, ds2_h)
  end
end
eeObj.AddHook(0x4fc33c, 0x02084821, dump_display)
eeObj.AddHook(0x4fc068, 0x02084821, dump_display)
-- Bug#8944
-- The game doesn't clear the framebuffer on movie-startup and movie-display.
-- call clear functions at the appropriate points by using Replacement.
local Replace_CVideoDecoder_Draw = InsnOverlay( {
0x27bdfff0, -- addiu sp,sp,-16
0xffbf0000, -- sd ra,0(sp)
-- swap
0x0c13f044, -- jal 0x4fc110
0x00000000, -- nop
-- clear
0x0c13f228, -- jal 0x4fc8a0
0x24044000, -- li a0,16384
0xdfbf0000, -- ld ra,0(sp)
0x03e00008, -- jr ra
0x27bd0010, -- addiu sp,sp,16
})
eeInsnReplace(0x427fe0, 0x0c13f044,0x0c000000 | (Replace_CVideoDecoder_Draw>>2))
local Replace_CPS2MpegPlayer_Open = InsnOverlay( {
0x27bdfff0, -- addiu sp,sp,-16
0xffbf0000, -- sd ra,0(sp)
-- clear color
0x44806000, -- mtc1 zero,$f12
0x46006346, -- mov.s $f13,$f12
0x0c13f1d8, -- jal 0x4fc760
0x46006386, -- mov.s $f14,$f12
-- clear
0x0c13f228, -- jal 0x4fc8a0
0x24044000, --  li a0,16384
-- swap
0x0c13f044, --  jal 4fc110 <glSwapBuffersPSX2>
0x00000000, --  nop
-- restore some registers
0x0220302d, -- move a2,s1
0x0200382d, -- move a3,s0
0xdfbf0000, -- ld ra,0(sp)
0x03e00008, -- jr ra
0x27bd0010, -- addiu sp,sp,16
})
eeInsnReplace(0x423c3c, 0x0220302d, 0x0c000000 | (Replace_CPS2MpegPlayer_Open>>2))
--
-- Bug#8981 / Bug#9006
--
local std_string_c_str = function(ptr)
  return eeObj.ReadMemStr(eeObj.ReadMem32(eeObj.ReadMem32(ptr) + 12))
end
local player_obj_found_flag = 0
local player_obj = 0
eeObj.AddHook(0x464530, 0x27bdff90, function()
if std_string_c_str(eeObj.GetGpr(gpr.a1)) == "_player" then
--print(string.format("LookupGameObject %s", std_string_c_str(eeObj.GetGpr(gpr.a1))))
player_obj_found_flag = 1
end
end)
eeObj.AddHook(0x464720, 0x7bb10010, function()
if player_obj_found_flag == 1 then
player_obj = eeObj.ReadMem32(eeObj.GetGpr(gpr.v0)+92)
--print(string.format("    obj    = %x", eeObj.GetGpr(gpr.v0)))
--print(string.format("    92(v0) = %x", player_obj))
--print(string.format("    [%f, %f, %f]", eeObj.ReadMemFloat(player_obj+116), eeObj.ReadMemFloat(player_obj+120), eeObj.ReadMemFloat(player_obj+124)))
--print(string.format("    [%f, %f, %f]", eeObj.ReadMemFloat(player_obj+52), eeObj.ReadMemFloat(player_obj+56), eeObj.ReadMemFloat(player_obj+60)))
player_obj_found_flag = 0
end
end)
eeObj.AddHook(0x147444, 0x0040282d, function()
local strptr = eeObj.GetGpr(gpr.v0)
local str    = std_string_c_str(strptr)
if string.match(str, "ExplosionFire")
-- or string.match(str, "ExplosionSpark")
then
local explosion_object = eeObj.ReadMem32(eeObj.GetGpr(gpr.s0)+92)
local eo_x = eeObj.ReadMemFloat(explosion_object+116)
local eo_y = eeObj.ReadMemFloat(explosion_object+120)
local eo_z = eeObj.ReadMemFloat(explosion_object+124)
-- print(string.format("exp obj : %x", explosion_object))
-- print(string.format("        [%f, %f, %f]", eo_x, eo_y, eo_z))
-- print(string.format("        [%f, %f, %f]", eeObj.ReadMemFloat(explosion_object+52), eeObj.ReadMemFloat(explosion_object+56), eeObj.ReadMemFloat(explosion_object+60)))
local pl_x = eeObj.ReadMemFloat(player_obj+116)
local pl_y = eeObj.ReadMemFloat(player_obj+120)
local pl_z = eeObj.ReadMemFloat(player_obj+124)
-- print(string.format("pl  obj : %x", player_obj))
-- print(string.format("        [%f, %f, %f]", pl_x, pl_y, pl_z));
local len = (eo_x-pl_x)*(eo_x-pl_x) + (eo_y-pl_y)*(eo_y-pl_y) + (eo_z-pl_z)*(eo_z-pl_z)
-- print(string.format("lengh^2 = %f", len))
-- print(string.format("str : %s", std_string_c_str(strptr)))
if len < 960000.0 then
  -- print("    REMOVED")
  eeObj.SetPc(0x1474b0)
end
end
end)
local overlay_addr = InsnOverlay( {
0x8c700008, --  lw      $s0, 8($v1)
0x8e040000, --  lw      $a0, 0($s0)
0x8c840000, --  lw      $a0, 0($a0)
0x3c05006c, --  lui    $a1,0x6c
0x34a5ce28, --  ori    $a1,$a1,0xce28
0x14850002, --  bne    $a0, $a1, <ret>
0x00000000, --  nop
0xac600004, --  sw      zero, 4($v1)
0x03e00008, -- ret: jr      $ra
0x8c630004, --  lw      $v1, 4($v1)
} )
local call_insn = (overlay_addr >> 2) | 0x0c000000
eeInsnReplace( 0x267f84, 0x8c700008, call_insn ) -- lw $s0, 8($v1) -> jal overlay_addr
eeInsnReplace( 0x267f88, 0x8c630004, 0x00000000 ) -- lw $v1, 4($v1) -> nop
-- The game has a bug when you replay the last campaign mission in coop mode ("The Jedi Master").
-- Upon completing the mission successfully, the game asks to "Continue" or "Quit".
-- Selecting "Continue" causes the game to hang, as there's nothing to continue to (it's the last mission)
-- The following patch fixes this problem by changing to prompt to "Retry" or "Quit", as it behaves in 1p mode
eeObj.AddHook(0x39debc, 0x0220202d, function()
    local strptr = eeObj.GetGpr(gpr.v0)
    local str    = std_string_c_str(strptr)
    if string.match(str, "m16_fleet") then
    eeObj.SetGpr(gpr.s0, 1)
    end
end)
-- fix for a node corruption.
-- here's what happens (from Ernesto)
--
-- Well, I was finally able to track down the issue. It's actually difficult to explain and the actual trigger is still unknown to me, as it seems to be timing related somehow.
-- But, I found a way to reliably detect it and work around it. Basically, when the bug happens, CSGNode::AddChild will try to add a child node that's already a children of a different root node.
-- That causes all sorts of havok and it's what ends up causing the node child list to eventually be deallocated and the render to crash.
eeObj.AddHook(0x266A70, 0x27bdffc0, function()
--  local obj = eeObj.GetGpr(gpr.a0)
    local node = eeObj.GetGpr(gpr.a1)
    local parent = eeObj.ReadMem32(node+0x10)
--  local caller = eeObj.GetGpr(gpr.ra)
    if parent ~= 0 then
--      print(string.format("Node %08x already has a parent (%08x, caller: %08x)", node, parent, caller))
      eeObj.SetPC(0x266B80)
    end
end)
</pre>
====Star Wars Racer Revenge====
SLES_503.66
<br>Text
<pre>--ee-hook=0x0025b3b0,FastForwardClock
--ee-hook=0x0025b188,FastForwardClock
--ee-hook=0x00243274,FastForwardClock
--gs-vert-precision=8
--idec-cycles-per-qwc=768
--host-audio-latency=0.60
--fpu-no-clamping=1
--cop2-no-clamping=1
--vu1-di-bits=0
--gs-override-small-tri-area=1
--assert-path1-ad=0
--ee-ignore-segfault=Read</pre>
SLES_503.66
<br>Lua
<pre>require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
apiRequest(0.4)
-- Star Wars: Racer Revenge (SLES-50366) [US]
local eeObj = getEEObject()
local emuObj  = getEmuObject()
eeInsnReplace(0x13d7f0, 0x1000ffff, 0x0804f45d) -- retry FREAD() for fix #9025,
-- Track#
-- The Grand Reefs : 6
-- Ruins of Carnuss Gorgull : 9
eeObj.AddHook(0x187330, 0x3c010001, function()
local track = eeObj.GetGpr(gpr.a1)
print(string.format("Track : %d", track))
if track == 6 or track == 9 then
eeObj.Vu1MpgCycles(1000) -- makes it be 30fps.
else
eeObj.Vu1MpgCycles(100) -- default value.
end
end)
-- Small triangle rejection. Works in conjunction with CLI setting  gs-override-small-tri-area=1
-- keep default area for texture 256x256 ( no blend)  (Anakin face) 
emuObj.SetGsTitleFix( "setRejectionArea", 500,{twIsNot=8, thIsNot=8 } )
-- Set triangle rejection area= 1000  when alpha blend is not 0 ( i.e blend is On)
emuObj.SetGsTitleFix( "setRejectionArea", 1000, {alphaIsNot=0 } )</pre>
SLES_503.66
<br>Lua Features
<br>Seems to also include some game fix
<pre>-- Lua 5.3
-- Title:  Star Wars Racer Revenge PS2 - SLES-50366 (EUR)
-- Author:  Ernesto Corvi
-- Changelog:
apiRequest(0.2) -- request version 0.2 API. Calling apiRequest() is mandatory.
local eeObj = getEEObject()
local emuObj = getEmuObject()
local L1 =  -- PodUILoadingPage::PodUILoadingPage
function()
emuObj.ThrottleMax()
end
local L2 =  -- PodUILoadingPage::~PodUILoadingPage
function()
emuObj.ThrottleNorm()
end
local load1 = eeObj.AddHook(0x1caa30, 0x27bdffe0, L1) -- PodUILoadingPage::PodUILoadingPage
local load2 = eeObj.AddHook(0x1caa70, 0x27bdffd0, L2) -- PodUILoadingPage::~PodUILoadingPage
-- BUG 9244 - This title exhibits memory allocation problems as described on the
-- PS2 tech note titled "malloc() Issues". Overlay the FullAllocAndFree() and hook it to main()
local overlay_addr = InsnOverlay( {
0x27bdfff0, -- addiu $sp, -0x10
0x7fbf0000, -- sq $ra, 0($sp)
0x0c0c1710, --  jal malloc
0x3c0401e0, --  lui $a0, 0x01e0
0x0c0c171a, --  jal free
0x70402628, --  paddub $a0, $v0, 0
0x7bbf0000, --  lq $ra, 0($sp)
0x03e00008, --  jr $ra
0x27bd0010  --  addiu  $sp, 0x10
} )
local call_insn = (overlay_addr >> 2) | 0x0c000000
eeInsnReplace(0x23a020, 0x0c0be0a2, call_insn) -- jal scePrintf
-- BUG 9244 - move stack down to 0x01f80000 to free up an extra 512KB
eeInsnReplace(0x100038, 0x3c0501f0, 0x3c0501f8)
</pre>
====Twisted Metal Black====
ALL
<br>Text
<pre>--mtap1=always
--gs-use-deferred-l2h=0
--l2h-2d-params=0x0000000400000004,0x00000000300a0000,240
--vu1-di-bits=0
--vu1-opt-vf00=2
#performance fix.</pre>
SCUS_971.01
<br>LUA
<pre>require("ee-gpr-alias")
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
-- This game uses an old kernel which has a bug on _TerminateThread.
-- It is necessary to check the target thread is already in readyqueue or not.
iopObj = getIOPObject()
iopInsnReplace(0x0000C5C0, 0x0C004430, 0) -- jal        0x000110C0 // unlink_element (in TerminateThread)
iopInsnReplace(0x0000C6EC, 0x0C004430, 0) -- jal        0x000110C0 // unlink_element (in iTerminateThread)
local fix_TerminateThread = function()
  local TCB = iopObj.GetGpr(gpr.s0)
  local TCB_status = iopObj.ReadMem8(TCB + 0xc)
  local TCB_h_l = TCB
  if TCB_status == 0x2 then
  -- the target thread is on ready.
  local TCB_h_l_prev = iopObj.ReadMem32(TCB_h_l + 0)
  local TCB_h_l_next = iopObj.ReadMem32(TCB_h_l + 4)
  if TCB_h_l_prev == TCB_h_l_next then -- last_one_element(&tcb->h.l)
-- we need to maintain threadManCB.readymap.
-- print("WE NEED TO MAINTAIN threadManCB.readymap!")
local s0 = iopObj.ReadMem16(TCB + 0xe) -- prio
local s1 = TCB
local a0 = s0 >> 5
a0 = a0 << 2
local v1 = s0 & 0x1f
local v0 = 1 << v1
v1 = 0x10000 + a0
v1 = iopObj.ReadMem32(v1 + 0x1a08)
v0 = ~v0
v1 = v1 & v0
local at = 0x10000+a0
iopObj.WriteMem32(at+0x1a08, v1)
-- 0000B798  00102142 srl        a0,s0,5
-- 0000B79C  00042080 sll        a0,a0,2
-- 0000B7A0  3203001F andi        v1,s0,0x1F
-- 0000B7A4  24020001 li          v0,0x1
-- 0000B7A8  00621004 sllv        v0,v0,v1
-- 0000B7AC  3C030001 lui        v1,0x1
-- 0000B7B0  00641821 addu        v1,v1,a0
-- 0000B7B4  8C631A08 lw          v1,0x1A08(v1)
-- 0000B7B8  00021027 nor        v0,zero,v0
-- 0000B7BC  00621824 and        v1,v1,v0
-- 0000B7C0  3C010001 lui        at,0x1
-- 0000B7C4  00240821 addu        at,at,a0
-- 0000B7C8  AC231A08 sw          v1,0x1A08(at)
  end
  end
  -- do unlink_element
  local v1 = iopObj.ReadMem32(TCB_h_l+0) -- element->prev
  local v0 = iopObj.ReadMem32(TCB_h_l+4) -- element->next
  iopObj.WriteMem32(v1 + 4, v0) -- element->prev->next = element->next
  iopObj.WriteMem32(v0 + 0, v1)
end
iopObj.AddHook(0x0000C5C4, 0x02002021, fix_TerminateThread) -- move        a0,s0
iopObj.AddHook(0x0000C6F0, 0x02002021, fix_TerminateThread) -- move      a0,s0
-- _waitIpuIdle64 spin perf down problem. Bug#8289
-- NOTE: new libarary also loops just 500dec around. 0x1389 is too much.
eeInsnReplace(0x0020CF80, 0x28421389, 0x28420200) -- slti        v0,v0,0x1389
#Performance and stall fixes.</pre>
====The Warriors====
ALL
<br>Text
<pre>--vu1-injection=1
--vu1-mpg-cycles=2300
--vu1-mpg-cycles=2600,-1
--vu1-clamp-range=0x028,0x060
--ee-hook=0x48c660,FastForwardClock,0x1620ffe3
--force-pal-60hz=1</pre>
?
<br>LUA
<pre>-- Lua 5.3
-- Title: The Warriors (USA)    SLUS-21215 ( 1.04 NTSC )
--        The Warriors (Europe) SLES-53443 ( 1.01 PAL )
-- Features version: 1.00
-- Author: David Haywood
-- Date: November 15th 2015
require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
apiRequest(0.7) -- request version 0.7 API. Calling apiRequest() is mandatory. -- request version 0.7 API. Calling apiRequest() is mandatory. (0.7 is needed for Widescreen switching)
-- obtain necessary objects.
local eeObj = getEEObject()
local emuObj = getEmuObject()
local trophyObj = getTrophyObject()
local dmaObj = getDmaObject()
-- load configuration if exist
local SaveData = emuObj.LoadConfig(0)
local firstCall = 0
--[[
this is the 'setWideScreen' function of the gfx devices
from studying the code it seems that the content of 'a1' that
gets passed in determines if the requested mode is widescreen.
DevRWGraphicsDevice::setWideScreenMode(void)
00194E28  27BDFFD0 addiu      sp,sp,-0x30
00194E2C  7FB00010 sq          s0,0x0010(sp)
00194E30  E7B50028 swc1        f21,0x0028(sp)
00194E34  0080802D dmove      s0,a0
00194E38  FFBF0000 sd          ra,0x0000(sp)
00194E3C  E7B40020 swc1        f20,0x0020(sp)
00194E40  4480A800 mtc1        zero,f21
00194E44  C600044C lwc1        f0,0x044C(s0)
00194E48  46150032 c.eq.s      f0,f21
00194E4C  00000000 nop
00194E50  45010053 bc1t        0x00194FA0
00194E54  AE05045C sw          a1,0x045C(s0)
--]]
local WidesrceenFunction = function()
local a1 = eeObj.GetGPR(gpr.a1)
a1 = a1 & 1
-- force to widescreen on boot, ensures new profiles get created in widescreen mode by default etc.
-- has some unwanted side-effects tho, so don't do it
if firstCall == 1 then
a1 = 1
eeObj.SetGPR(gpr.a1, a1)
firstCall = 0
end
if a1 == 1 then
print( string.format("********* Request WIDE SCREEN mode **************" ) )
emuObj.SetDisplayAspectWide()
else
print( string.format("********* Request 4:3 mode **************" ) )
emuObj.SetDisplayAspectNormal()
end
end
-- this hook address actually differs between Europe / US.
WidescreenHook = eeObj.AddHook(0x194e18,0x27BDFFD0,WidesrceenFunction)
#official widescreen patch for The Warrior's emulator. The typos are apparently deliberate.</pre>
====Wild ARMS 3====
ALL
<br>Text
<pre>--gs-motion-factor=50
--ee-static-block-links=JAL,COP2
#graphical fixes.</pre>
SCUS_972.03
<br>LUA
<pre>require("ee-gpr-alias")
apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
local emuObj = getEmuObject()
-- fix vision logo (Wild Arms 3)
local thresholdArea = 0 -- ignore alls items : fix #112276
emuObj.SetGsTitleFix( "ignoreUpRender", thresholdArea , {  texType = 3, cbp = 0x2390, tbp = 0x288000} )
-- fix bug #9072
-- this is caused by a wrong string, which we patch directly on the disc.
emuMediaPatch(0x438a, 12 + 0x174, { 0x6e5c2535 }, { 0x11202535 })
-- Bug#8907. accuracy-muldiv is too slow to use, so here added some value to get correct value.
local eeObj = getEEObject()
eeObj.AddHook(0x001ef6ec, 0x00000000, function()
eeObj.SetFpr(0, eeObj.GetFpr(0) + 0.00001)
end)
#Graphical glitches and stall fix.</pre>


==Custom PS2emu Configuration Files ==
==Custom PS2emu Configuration Files ==
Line 105: Line 1,947:
--gs-use-mipmap=1
--gs-use-mipmap=1
#Same fix for terrain textures</pre>
#Same fix for terrain textures</pre>
SLUS_208.51
<br>LUA
<pre>apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.
-- Collision detection fix for Stage 3 onwards // Rearranging COP2 instructions that use old results
eeInsnReplace(0x1A3B94, 0x4B00682C, 0x48498800)
eeInsnReplace(0x1A3B98, 0x4B0C682C, 0x4B00682C)
eeInsnReplace(0x1A3BA4, 0x48498800, 0x484A8800)
eeInsnReplace(0x1A3BA8, 0x484A8800, 0x4B0C682C)
</pre>


====Ace Combat Zero: The Belkan War====
====Ace Combat Zero: The Belkan War====
Line 157: Line 2,011:
--cop2-clamp-results=1
--cop2-clamp-results=1
#SPS Fix</pre>
#SPS Fix</pre>
====Burnout2: POI====
SLES_510.44 / SLES_529.68
<br>LUA
<pre>apiRequest(0.1)    -- request version 0.1 API. Calling apiRequest() is mandatory.
-- SLES-51044 / SLES-52968 - Fix white parts
-- Major thanks to Maori-Jigglypuff for reversing that
eeInsnReplace(0x2485B8, 0xC6800D18, 0x3C014316)
eeInsnReplace(0x2485CC, 0xE4400000, 0xAC410000)
eeInsnReplace(0x262604, 0xC7809780, 0x3C014316)
eeInsnReplace(0x262618, 0xE4400000, 0xAC410000)
eeInsnReplace(0x2564B8, 0x8F829764, 0x24020000)</pre>
SLUS_204.97
<br>LUA
<pre>apiRequest(0.1)    -- request version 0.1 API. Calling apiRequest() is mandatory.
-- SLUS_204.97 - Fix white parts
-- Major thanks to Maori-Jigglypuff for reversing that
eeInsnReplace(0x2485A8, 0xC6800D18, 0x3C014316)
eeInsnReplace(0x2485BC, 0xE4400000, 0xAC410000)
eeInsnReplace(0x2625F4, 0xC7809780, 0x3C014316)
eeInsnReplace(0x262608, 0xE4400000, 0xAC410000)
eeInsnReplace(0x2564A8, 0x8F829764, 0x24020000)</pre>


====Cold Winter====
====Cold Winter====
Line 192: Line 2,073:
emuMediaPatch(0x186A86, 12 + 0x7f4, { 0xafbe0008 }, { 0x00000000 })
emuMediaPatch(0x186A86, 12 + 0x7f4, { 0xafbe0008 }, { 0x00000000 })
emuMediaPatch(0x186C38, 12 + 0x6ec, { 0x24060001 }, { 0x24060000 })</pre>
emuMediaPatch(0x186C38, 12 + 0x6ec, { 0x24060001 }, { 0x24060000 })</pre>
For the Japanese version (SLPS-25026) you can also use config files from PS3's PS2 emu with
<pre>--lopnor-config=1</pre>
in config.
Place config file named as "SLPS-25026_lopnor.cfgbin" in /patches/SLPS-25026/
====Disgaea 2: Cursed Memories====
SLUS-21397
<br>Text
<pre>--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-use-mipmap=1
#Fix for lines in terrain textures and flickering textures</pre>
====Dragon Ball Z: Budokai Tenkaichi 2====
ALL
<br>Text
<pre>--gs-use-clut-merge=1
--gs-kernel-cl="clutmerge"
--gs-kernel-cl-up="clutmerge2x2"
#Fix for missing life bars and other UI elements.</pre>
====Dragon Ball Z: Budokai Tenkaichi 3====
ALL
<br>Text
<pre>--gs-use-clut-merge=1
--gs-kernel-cl="clutmerge"
--gs-kernel-cl-up="clutmerge2x2"
#Fix for missing life bars and other UI elements.</pre>


====Dragon Quest VIII: Journey of the Cursed King====
====Dragon Quest VIII: Journey of the Cursed King====
All
All
<br>Text
<br>Text
<pre>--gs-uprender=2x2
<pre>--gs-kernel-cl-up="up2x2skipinterp"
--gs-upscale=EdgeSmooth
--gs-kernel-cl-up="up2x2skipinterp"
--gs-optimize-30fps=1
--gs-optimize-30fps=1
#Fixes shadows</pre>
#Fix lines in shadows</pre>


====Frogger: Ancient Shadow====
====Frogger: Ancient Shadow====
Line 215: Line 2,124:
--cop2-clamp-results=1  
--cop2-clamp-results=1  
#Fixes disappearing models during cutscenes and during gameplay</pre>
#Fixes disappearing models during cutscenes and during gameplay</pre>
====The Getaway====
PAL
<br>Text
<pre>--vu1-mpg-cycles=950
#fix lag during cutscenes
</pre>
====The Getaway: Black Monday====
SCES-52758 ONLY!
<br>cli.conf
<pre>--fpu-accurate-range=0x26B154,0x305140
#Fix for crash on Chapter 5 in the ambush.
#NOTE THIS WILL MAKE THE GAME SLOW, INFACT JUST USE IT TO COMPLETE THE CHAPTER FIVE AND THEN REMOVE IT.
#Fix By Vitt0xLar
#JAK V2 emulator used.
</pre>


====Ghost in the Shell: Stand Alone Complex====
====Ghost in the Shell: Stand Alone Complex====
Line 244: Line 2,174:
eeInsnReplace(0x1C017C, 0x4A0002FF, 0x48588800)
eeInsnReplace(0x1C017C, 0x4A0002FF, 0x48588800)
eeInsnReplace(0x1C018C, 0x48588800, 0x4a0002ff)
eeInsnReplace(0x1C018C, 0x48588800, 0x4a0002ff)
#-- Potential fix for broken interactive door // Rearranging COP2 ops so as to avoid macflag bad stuff</pre>
-- Potential fix for broken interactive door // Rearranging COP2 ops so as to avoid macflag bad stuff</pre>


====Killer7====
====Killer7====
Line 256: Line 2,186:
--vu1-clamp-results=1
--vu1-clamp-results=1
#fix for flickering polygons.</pre>
#fix for flickering polygons.</pre>
====Kim Possible: What's the Switch====
PAL
<br>Text
<pre>--vu1-mpg-cycles=950
#fix lag during cutscenes
</pre>


====Klonoa 2====
====Klonoa 2====
Line 262: Line 2,200:
<pre>--fpu-no-clamping=1
<pre>--fpu-no-clamping=1
#Fix for misplaced objects, still require fix for texturing problems. Require Rogue Galaxy emu</pre>
#Fix for misplaced objects, still require fix for texturing problems. Require Rogue Galaxy emu</pre>
====Legacy of Kain: Soul Reaver 2====
SLES_501.96
<br>Lua
<pre>
apiRequest(0.1)    -- request version 0.1 API. Calling apiRequest() is mandatory.
-- Turn off mipmapping in game engine. Completely fix flickering, and bad texturing. Don't require "gs-kernel-cl=mipmap"
-- SLES_501.96 only!
eeInsnReplace(0x2A1F80, 0x00000001, 0x00000000)</pre>


====Metal Saga====
====Metal Saga====
Line 309: Line 2,258:
--gs-kernel-cl-up="clutmerge2x2"
--gs-kernel-cl-up="clutmerge2x2"
#Fix for flickering textures and geometry</pre>
#Fix for flickering textures and geometry</pre>
====R-Racing Revolution====
SLUS_207.21
<br>LUA
<pre>apiRequest(0.1)    -- request version 0.1 API. Calling apiRequest() is mandatory.
-- Divide $v0 value by 8 before copying it to CMSAR0
-- sra $v0, 3, this time we are losing one nop on cop2. Can be important.
eeInsnReplace(0x2DDB4C, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x2DDB50, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x2DDBC4, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x2DDBC8, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x313C30, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x313C34, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x3144FC, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x314500, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x314E04, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x314E08, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x31570C, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x315710, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x315FFC, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x316000, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x3168EC, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x3168F0, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x31724C, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x317250, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x317B74, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x317B78, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x318430, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x318434, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x318D54, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x318D58, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x319AA0, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x319AA4, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x31A8D4, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x31A8D8, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x31B7A4, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x31B7A8, 0x4A0002FF, 0x48C2D801)
-- fix graphical issues</pre>


====Rygar: The Legendary Adventure====
====Rygar: The Legendary Adventure====
Line 315: Line 2,304:
<pre>--fpu-accurate-range=0x147CC0,0x147EA0
<pre>--fpu-accurate-range=0x147CC0,0x147EA0
#Fix for freeze after leaving the first area.</pre>
#Fix for freeze after leaving the first area.</pre>
====Samurai Shodown VI====
ALL
<br>Text
<pre>--gs-upscale=point
--gs-uprender=2x2
--gs-motion-factor=25
--host-audio-latency=0.01
--gs-ignore-dirty-page-border=1
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
--gs-h2l-list-opt=1
--gs-h2l-accurate-hash=1
#same as Anthology, which VI is a patched-out section of; substantial slowdown during combat has been mitigated.</pre>


====SNK vs Capcom: SVC Chaos====
====SNK vs Capcom: SVC Chaos====
Line 323: Line 2,326:
--gs-kernel-cl-up="clutmerge2x2"
--gs-kernel-cl-up="clutmerge2x2"
#Fixes missing hud/UI elements.</pre>
#Fixes missing hud/UI elements.</pre>
====SpongeBob SquarePants: Battle for Bikini Bottom====
ALL
<br>Text
<pre>--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1
#Fix for graphical issues</pre>


====Street Fighter Alpha Anthology====
====Street Fighter Alpha Anthology====
Line 405: Line 2,422:
#Fix for texture glitches</pre>
#Fix for texture glitches</pre>


====X files - resist or serve====
====X-Files - Resist or Serve====
NTSC/U
NTSC/U
<br>Text
<br>Text
Line 414: Line 2,431:
--cop2-no-clamping=0
--cop2-no-clamping=0
--cop2-clamp-results=1
--cop2-clamp-results=1
#fix for missing models</pre>
 
#fix for missing character models
 
*Jak Emu used*</pre>
 
====Zatch Bell! Mamodo Battles™====
NTSC/U
<br>Text
<pre>--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-use-mipmap=1
--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-results=1
--vu1-clamp-results=1
--fpu-no-clamping=0
--cop2-no-clamping=0
--fpu-clamp-results=1
--cop2-clamp-results=1
 
#fix for graphical glitches
 
*Jak Emu used*</pre>
 
==Fix for unplayable or major issue games==
 
====God Hand====
'''''Conf file'''''
<pre>--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1
#fix for graphical glitches, specially the missing ground.
</pre>
 
==== God Of War ====
'''''Conf file'''''
<pre>--vu-d-bit=1
--vu-t-bit=1
--vu1-opt-flags=2
--vu1-di-bits=1
--vu1-mpg-cycles=800
--vu1-injection=1
--vu1-opt-vf00=2
--vu1-jr-cache-policy=newprog
--vu1-jalr-cache-policy=newprog
--ee-block-validation=PageProt
--ee-hook=0x017A2DC,AdvanceClock
--gs-frontend-opt-mode=2
--fpu-rsqrt-fast-estimate=1
#fix for graphical glitches
 
*Jak Emu used*</pre>
 
'''''LUA file'''''
<pre>-- God Of War EU
 
-- 01 Music sound problem: music restarts every time there are many sounds to play
-- 02 Latest emu removes a lot of game lag, anyway the game still suffer of shuttering in the next levels
-- 03 Corrupted green lines around the objects, uprendering problem
 
apiRequest(2.2) -- request version 0.1 API. Calling apiRequest() is mandatory.
 
local gpr    = require("ee-gpr-alias")
local emuObj = getEmuObject()
local gsObj = getGsObject()
local thresholdArea = 600
 
-- 02 Slowdowns and performances patched in cli.conf file
 
-- 03 --gs-uprender=none removes corrupted lines around the objects and
-- local thresholdArea = 600 improves the graphics
 
-- Disable internal field shift compensation, part of post-process removal feature.
gsObj.SetDeinterlaceShift(0)
</pre>
 
 
====God of War 2====
'''''Conf file'''''
<pre>--vu1-jr-cache-policy=newprog
--vu1-jalr-cache-policy=newprog
--vu1-mpg-cycles=1000
--vu1-di-bits=1
--vu1-injection=1
--vu1-opt-flags=2
--ee-block-validation=PageProt
--ee-hook=0x186B64,AdvanceClock
--ee-hook=0x186CE4,AdvanceClock
--ee-cycle-scalar=0.8
--ee-kernel-hle=1
--ee-injection-kernel=1
--ee-injection-title=1
--fpu-accurate-muldiv-range=0x186B64,0x186CE4
--fpu-accurate-mul-fast=1
--fpu-rsqrt-fast-estimate=1
--framelimit-mode=normal
--gs-frontend-opt-mode=2
--gs-optimize-30fps=1
--cop2-di-bits=1
--safe-area-min=1.0
*Jak Emu used*</pre>
 
'''''LUA File'''''
<pre>-- God of War II EU
 
require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
 
apiRequest(2.2)
 
local emuObj = getEmuObject()
local gsObj = getGsObject()
 
local fastminEE = 1600000 -- less than this it's safe to run > 30 fps
 
-- Disable internal field shift compensation, part of post-process removal feature.
gsObj.SetDeinterlaceShift(0)
 
-- Graphic improvement: removes corrupted lines on screen with uprender on for PAL version
 
emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", { texMode=1 } ) --texMode=1 ?
emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", { texMode=2 } ) --texMode=2 is BILINEAR
 
require("utils")
local eeObj = getEEObject()
local PrecompileAddrs = Queue.new(
  {
0x100000,
0x100004,
0x100008,
0x10000C,
0x100010,
0x100014,
0x100018,
0x10001C,
0x100020,
0x100024,
0x100028,
0x10002C,
0x100030,
0x100034,
0x100038,
0x10003C,
0x100040,
0x100044,
0x100048,
0x10004C,
0x100050,
0x100054,
0x100058,
0x10005C,
0x100060,
0x100064,
0x100068,
0x10006C,
0x100070,
0x100074,
0x100078,
0x10007C,
0x100080,
0x100084,
0x100088,
0x10008C,
0x100090,
0x100094,
0x100098,
0x10009C,
0x1000A0,
0x1000A4,
0x1000A8,
0x1000AC,
0x1000B0,
0x1000B4,
0x1000B8,
0x1000BC,
0x1000C0,
0x1000C4,
0x1000C8,
0x1000CC,
0x1000D0,
0x1000D4,
0x1000D8,
0x1000DC,
0x1000E0,
0x1000E4,
0x1000E8,
0x1000EC,
0x1000F0,
0x1000F4,
0x1000F8,
0x1000FC,
0x100100,
0x100104,
0x100108,
0x10010C,
0x100110,
0x100114,
0x100118,
0x10011C,
0x100120,
0x100124,
0x100128,
0x10012C,
0x100130,
0x100134,
0x100138,
0x10013C,
0x100140,
0x100144,
0x100148,
0x10014C,
0x100150,
0x100154,
0x100158,
0x10015C,
0x100160,
0x100164,
0x100168,
0x10016C,
0x100170,
0x100174,
0x100178,
0x10017C,
0x100180,
0x100184,
0x100188,
0x10018C,
0x100190,
0x100194,
0x100198,
0x10019C,
0x1001A0,
0x1001A4,
0x1001A8,
0x1001AC,
0x1001B0, -- ei
0x1001B4,
0x1001BC,
0x1001C0,
0x1001C4,
0x1001C8,
0x1001CC,
0x1001D0,
0x1001D4,
0x1001D8,
0x1001DC,
0x1001E0,
0x1001E4,
0x1001E8,
0x1001EC,
0x1001F0,
0x1001F4,
0x1001F8,
0x1001FC,
0x100200,
0x100204,
0x100208,
0x10020C,
0x100210,
0x100214,
0x100218,
0x10021C,
0x100220,
0x100224,
0x100228,
0x10022C,
0x100230,
0x100234,
0x100238,
0x10023C,
0x100240,
0x100244,
0x100248,
0x10024C,
0x100250,
0x100254,
0x100258,
0x10025C,
0x100260,
0x100264,
0x100268,
0x10026C,
0x100270,
0x100274,
0x100278,
0x10027C,
0x100280,
0x100284,
0x100288,
0x10028C,
0x100290,
0x100294,
0x100298,
0x10029C,
0x1002A0,
0x1002A4,
0x1002A8,
0x1002AC,
0x1002B0,
0x1002B4,
0x1002B8,
0x1002BC,
0x1002C0,
0x1002C4,
0x1002C8,
0x1002CC,
0x1002D0,
0x1002D4,
0x1002D8,
0x1002DC,
0x1002E0,
0x1002E4,
0x1002E8,
0x1002EC,
0x1002F0,
0x1002F4,
0x1002F8,
0x1002FC,
0x186B30,
0x186B34,
0x186B38,
0x186B3C,
0x186B44,
0x186B48,
0x186B4C,
0x186B50,
0x186B54,
0x186B58,
0x186B5C,
0x186B60,
0x186B64,
0x186B68,
0x186B6C,
0x186B70,
0x186B74,
0x186B78,
0x186B7C,
0x186B80,
0x186B84,
0x186B84,
0x186B88,
0x186B8C,
0x186B90,
0x186B94,
0x186B98,
0x186B9C,
0x186BA0,
0x186BA4,
0x186BA8,
0x186BAC,
%0x186BB0,
0x186BB4,
0x186BB8,
0x186BBC,
0x186BC0,
0x186BC4,
0x186BC8,
0x186BCC,
0x186BD0,
0x186BD4,
0x186BD8,
0x186BDC,
0x186BE0,
0x186BE4,
0x186BE8,
0x186BEC,
0x186BF0,
0x186BF4,
0x186BF8,
0x186BFC
})
# Fixed 90% of glitches, still has lag issues
</pre>
 
==== Max Payne 2 ====
 
'''''Conf file'''''
<pre>
--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1
# Fixed green, blue and red graphical issues. The game works better.
</pre>
 
==== Psi-Ops: The Mindgate Conspiracy ====
 
'''''Conf file'''''
<pre>
--ee-kernel-hle=1
--ee-injection-kernel=1
--ee-injection-title=1
--ee-cycle-scalar=1.9
--safe-area-min=1.0
--vu0-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-no-clamping=0
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1
# Fixed low framrate issue, !!!JAK EMULATOR Used!!!.
</pre>

Revision as of 21:47, 24 January 2020

Official PS2emu Configuration Files

Here are configuration files extracted from official packages, to improve PS2 emulator compatibility on PS4. Most of them require also emulator/recompiler files from extracted pkg to work correctly.

Canis Canem Edit/Bully

SLES 535.61
LUA

apiRequest(0.1)

-- Bully bug 9392
-- Performance fix
local emuObj = getEmuObject()	
local thresholdArea = 600
emuObj.SetGsTitleFix( "ignoreUpRender", thresholdArea , {alpha=0x80000044 , zmsk=1 , tw=4, th=4  } )


Text

--fpu-accurate-mul-fast=1
--fpu-accurate-muldiv-range=0x3fa5c0,0x3fa5c0
--gs-flush-ad-xyz=SafeZWrite
--vu1-opt-vf00=2
--vu1-di-bits=0
--ee-hook=0x001f3ef4,FastForwardClock
--gs-use-deferred-l2h=0
--vu1-injection=1
--vu1-mpg-cycles=2500
--fpu-rsqrt-fast-estimate=0
--safe-area-min=1.0

SLUS-21269
SLUS-21269_features.lua

This is a substantial file. Over 150 lines with an extensive performance fix. I'm sharing the file itself as a download link.

https://drive.google.com/file/d/12gt2fONqMP1rmEB9UMw3rIpEYbz1dQq8/view

#Official widescreen support.

Destroy All Humans

SLUS_209.45
Text

--gs-use-mipmap=1
--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-ignore-dirty-page-border=1
--fpu-accurate-addsub-range=0x28bf00,0x28c100
#Fix for graphical glitches.

SLUS_209.45
SLUS-20945_features.lua

-- Lua 5.3
-- Title:   Destroy All Humans! PS2 - SLUS-20945 (USA)
-- Author:  Ernesto Corvi, Adam McInnis

-- Changelog:

apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

local eeObj		= getEEObject()
local emuObj	= getEmuObject()
local gpr = require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])

-- Widescreen
eeObj.AddHook(0x308270, 0x3c0336c5, function() -- Graphics::Script::SetScreenRatio
	local mode = eeObj.GetGpr(gpr.v0)
	
--	print(string.format("mode: %08x", mode))
	
	if mode == 0x36c59d2b then -- widescreen
		emuObj.SetDisplayAspectWide()
	elseif mode == 0x855a87ef then -- standard
		emuObj.SetDisplayAspectNormal()
	end
end)

eeObj.AddHook(0x3078F4, 0xae0000f4, function() -- Graphics::Renderer::Renderer
	local renderer = eeObj.GetGpr(gpr.s0)
	eeObj.WriteMemFloat(renderer+0x200, 1.3333333)
	eeObj.WriteMemFloat(renderer+0x204, 1.7777777)
	eeObj.WriteMem32(renderer+0x208, 2)
end)

emuObj.SetDisplayAspectWide()

-- CRC "settings.display.widescreen" = 0xbcf14d81
-- $s2 = SaveType (1 = new save)

local overlay = InsnOverlay({
	0x27bdffe0, -- addiu $sp, -0x20
	0xffbf0010, -- sd $ra, 0x10($sp)
	0x0c0d49d8, -- jal Core::Memset(void *,int,uint)
	0x00000000, -- nop
	0x24030001, -- li $v1, 1
	0x1472000b, -- bne $s2, $v1, +11
	0x00000000, -- nop
	0x0c09dacc, -- jal UFO::Progress::Get(void)
	0x00000000, -- nop
	0x3c01bcf1, -- lui $at, 0xbcf1
	0x34214d81, -- ori $at, $at, 0x4d81
	0xafa10000, -- sw $at, 0($sp)
	0x24030001, -- li $v1, 1
	0xa3a30004, -- sb $v1, 4($sp)
	0x03a0282d, -- move $a1, $sp
	0x0c09dd4c, -- jal UFO::Progress::Record::AddKey(UFO::Progress::Content const&)
	0x0040202d, -- move $a0, $v0
	0xdfbf0010, -- ld $ra, 0x10($sp)
	0x03e00008, -- jr $ra
	0x27bd0020  -- addiu $sp, 0x20
})
local call_overlay = 0x0c000000 | (overlay >> 2)
eeInsnReplace(0x2789F8, 0x0c0d49d8, call_overlay) -- UFO::Progress::Storage::PrepareWrite
#Official widescreen support.

Destroy All Humans 2

SLUS_214.39
Text

--gs-use-mipmap=1
--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
#Fix for graphical glitches.

SLUS_214.39
SLUS-21439_features.lua

-- Lua 5.3
-- Title:   Destroy All Humans! 2 PS2 - SLUS-21439 (USA)
-- Author:  Ernesto Corvi, Adam McInnis

-- Changelog:

apiRequest(0.7)	-- request version 0.1 API. Calling apiRequest() is mandatory.

local eeObj		= getEEObject()
local emuObj	= getEmuObject()
local gpr = require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])

-- Widescreen
eeObj.AddHook(0x33ca98, 0x3c0436c5, function() -- Graphics::Script::SetScreenRatio
	local mode = eeObj.GetGpr(gpr.v0)
	
--	print(string.format("mode: %08x", mode))
	
	if mode == 0x36c59d2b then -- widescreen
		emuObj.SetDisplayAspectWide()
	elseif mode == 0x855a87ef then -- standard
		emuObj.SetDisplayAspectNormal()
	end
end)

eeObj.AddHook(0x33afac, 0x0000282d, function() -- Graphics::Renderer::Renderer
	eeObj.SetGpr(gpr.a1, 2)
end)

emuObj.SetDisplayAspectWide()

-- CRC "settings.display.anamorphic" = 0x8b36afe9
-- $s2 = SaveType (1 = new save)

local overlay = InsnOverlay({
	0x27bdffe0, -- addiu $sp, -0x20
	0xffbf0010, -- sd $ra, 0x10($sp)
	0x0c059d02, -- memset
	0x00000000, -- nop
	0x24030001, -- li $v1, 1
	0x1472000b, -- bne $s2, $v1, +11
	0x00000000, -- nop
	0x0c09b400, -- jal UFO::Progress::Get(void)
	0x00000000, -- nop
	0x3c01bcf1, -- lui $at, 0x8b36
	0x34214d81, -- ori $at, $at, 0xafe9
	0xafa10000, -- sw $at, 0($sp)
	0x24030001, -- li $v1, 1
	0xa3a30004, -- sb $v1, 4($sp)
	0x03a0282d, -- move $a1, $sp
	0x0c09dd4c, -- jal UFO::Progress::Record::AddKey(UFO::Progress::Content const&)
	0x0040202d, -- move $a0, $v0
	0xdfbf0010, -- ld $ra, 0x10($sp)
	0x03e00008, -- jr $ra
	0x27bd0020  -- addiu $sp, 0x20
})
local call_overlay = 0x0c000000 | (overlay >> 2)
eeInsnReplace(0x271AD0, 0x0c059d02, call_overlay) -- UFO::Progress::Storage::PrepareWrite

-- Disable Progressive Scan and Adjust Screen Position

local overlay2 = InsnOverlay({
	0x27bdfff0, -- addiu $sp, -0x10
	0xffbf0000, -- sd $ra, 0(sp)
	0xffb00008, -- sd $s0, 8(sp)
	0x3c05000f, -- lui $a1, 0x000f
	0x34a57000, -- ori $a1, 0x7000
	0x0c0db8b6, -- jal Script::State::DoString
	0x0080802d, -- move $s0, $a0
	0x24050001, -- li $a1, 1
	0x0c0dba4c, -- jal Script::State::IsNull(int)
	0x0200202d, -- move $a0, $s0
	0xdfb00008, -- ld $s0, 8(sp)
	0xdfbf0000, -- ld $ra, 0(sp)
	0x03e00008, -- jr ra
	0x27bd0010  -- addiu $sp, 0x10
})
local call_overlay2 = 0x0c000000 | (overlay2 >> 2)
eeInsnReplace(0x2e5a14, 0x0c0dba4c, call_overlay2) -- Sim::Manager::ProcessScript near Sim::Manager::SetPauseFlag

eeObj.AddHook(0x2e5a10, 0x0240202d, function() -- Sim::Manager::ProcessScript near Sim::Manager::SetPauseFlag
	local luaString = [[
-- disable progressive scan and adjust screen
gui.i.SMOptionsDisplay.table.slots[3] = nil
gui.i.SMOptionsDisplay.table.slots[4] = nil
]]
	eeObj.WriteMemStrZ(0xf7000, luaString)
end)
#Official widescreen support.

Everybody's Tennis/Hot Shots Tennis

SCES_545.35
Text

--gs-use-deferred-l2h=0
--l2h-2d-params=0x0000000800000010,0x00000000300a1400,256
--gs-motion-factor=50
--mtap1=always
--gs-opt-frbuff-switch=1
--gs-ignore-dirty-page-border=1
--gs-ignore-rect-correction=1
--ee-native-function=memcpy,0x11e328
--ee-native-function=memset,0x11e4e0
#performance and visual fix(?)

SCES_545.35
LUA

local gpr = require("ee-gpr-alias")
require( "ee-hwaddr" )
apiRequest(1.4)

local eeObj = getEEObject()

-- function dump(addr)
--    print(string.format("=== dump %x ===", addr))
--    for i=0,0x1e do
-- 	  print(string.format("   %08x : %08x %08x %08x %08x",
-- 						  addr + i*16,
-- 						  eeObj.ReadMem32(addr + i*16 + 0),
-- 						  eeObj.ReadMem32(addr + i*16 + 4),
-- 						  eeObj.ReadMem32(addr + i*16 + 8),
-- 						  eeObj.ReadMem32(addr + i*16 +12)))
--    end
-- end

-- Bug#8285
-- This patch changes the color of background on :
--		- Language selection
--		- Company logo
--		- Start screen
--		- Some menu
-- which are in menu.bin overlay. Nothing affected in the actual game.
eeObj.DmaAddHook( 1, function()
					 if eeObj.ReadMem32(vif1_hw.TADR) == 0x1fd1c0 then
						-- On language select
						if eeObj.ReadMem32(0x4c8ef0) == 0x00ff9090 then
						   eeObj.WriteMem32(0x4c8ef0, 0)
						end
						if eeObj.ReadMem32(0x548f30) == 0x00ff9090 then
						   eeObj.WriteMem32(0x548f30, 0)
						end
						-- On company logo
						if eeObj.ReadMem32(0x4c6d70) == 0x00ff9090 then
						   eeObj.WriteMem32(0x4c6d70, 0)
						end
						if eeObj.ReadMem32(0x546db0) == 0x00ff9090 then
						   eeObj.WriteMem32(0x546db0, 0)
						end
					 end
end)


eeInsnReplace(0x103d58, 0x27bdffc0, 0x03e00008)                 -- <SyncDCache>
eeInsnReplace(0x103d5c, 0xffb20020, 0x00000000)
eeNativeHook (0x103d58, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x103dd8, 0x3c02ffff, 0x03e00008)                 -- <iSyncDCache>
eeInsnReplace(0x103ddc, 0x3442ffc0, 0x00000000)
eeNativeHook (0x103dd8, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x103e98, 0x27bdffc0, 0x03e00008)                 -- <InvalidDCache>
eeInsnReplace(0x103e9c, 0xffb20020, 0x00000000)
eeNativeHook (0x103e98, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x103f18, 0x3c02ffff, 0x03e00008)                 -- <iInvalidDCache>
eeInsnReplace(0x103f1c, 0x3442ffc0, 0x00000000)
eeNativeHook (0x103f18, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x106970, 0x3c19ffff, 0x03e00008)                 -- <sceSifWriteBackDCache>
eeInsnReplace(0x106974, 0x3739ffc0, 0x00000000)
eeNativeHook (0x106970, 0x03e00008,'AdvanceClock',0x1700)

Fahrenheit/Indigo Prophecy

SLES_535.39
Text

--ee-hook=0x002097d0,FastForwardClock,0x8c6261fc
--ee-hook=0x1a5570,AdvanceClock,,500000
--ee-hook=0x00223c48,AdvanceClock,0x0080382d,8000
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
#Performance fix.

SLES_535.39
LUA

This is a substantial file. Over 20,000 lines with an extensive performance fix. I'm sharing the file itself as a download link.

https://drive.google.com/file/d/1L2YxondID65KIAybKVCBH9KgFegqqOeQ/view

-- Performace fix (bug #9785 )
-- bug#8571
-- ignore 'no wait vsync' case.
-- unsyncv causes major slowness on loading screen, because the game pushes LOTS of identical frame data to GS.

SLES_535.39
SLES-53539_features.lua

-- Lua 5.3
-- Title:   Fahrenheit PS2 - SLES-53539 (EUR)
-- Author:  Ernesto Corvi, Adam McInnis

-- Changelog:

require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
require( "ee-cpr0-alias" ) -- for EE CPR

apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

local eeObj		= getEEObject()
local emuObj	= getEmuObject()

local L1 = function() -- QDT::SINT::SCRIPT_LOADING_SCREEN::EM::Run
	emuObj.ThrottleMax()
end
	
local L2 = function() -- QDT::SINT::SCRIPT_LOADING_SCREEN::EM::Stop
	emuObj.ThrottleNorm()
end
	
local load1 = eeObj.AddHook(0x387040, 0x3c02004b, L1) -- QDT::SINT::SCRIPT_LOADING_SCREEN::Run
local load2 = eeObj.AddHook(0x387090, 0x3c02004b, L2) -- QDT::SINT::SCRIPT_LOADING_SCREEN::Stop

-- Widescreen
eeInsnReplace(0x20a7c0, 0x3c013faa, 0x3c013fe3)
eeInsnReplace(0x20a7c4, 0x3421aaab, 0x34218e39)
emuObj.SetDisplayAspectWide()

-- Skip video mode options
local videomenuVM = { 0x04, 0x01, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00,
					  0x3B, 0x0D, 0x00, 0x00, 0x3B, 0x0B, 0x00, 0x00,
					  0x3B, 0x26, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 }
					  
local visualmenuVM = { 0x04, 0x01, 0x00, 0x00, 0xA2, 0x00, 0x00, 0x00,
					   0x3B, 0x19, 0x00, 0x00, 0x3B, 0x18, 0x00, 0x00 }

-- locates src chunk on (dst,cnt). -1 if not found, offset if found
local locateChunk = function(src, dst, count)
	local offs = -1
	
	for x = 0, count - #src do
		if eeObj.ReadMem8(dst+x) == src[1] then
			local found = true
			for y = 1, #src do
				if eeObj.ReadMem8(dst+x+y-1) ~= src[y] then
					found = false
					break
				end
			end
				
			if found == true then
				offs = x
				break
			end
		end
	end
	
	return offs
end

eeObj.AddHook(0x2812b0, 0x27bdfff0, function() -- QDT::VM::BYTE_CODE::BYTE_CODE
	local obj = eeObj.GetGpr(gpr.a1)
	local bytecode = eeObj.ReadMem32(obj+0x18)
	local count = eeObj.ReadMem32(obj+0x20)
	
	if count > #videomenuVM then
		local offs = locateChunk(videomenuVM, bytecode, count)
		if offs >= 0 then
			print("Skipping video mode menu")
			eeObj.WriteMem8(bytecode+offs+4, 8) -- beq 0x44 -> beq 0x8
		end
	end
	
	if count > #visualmenuVM then
		local offs = locateChunk(visualmenuVM, bytecode, count)
		if offs >= 0 then
			print("Skipping visual mode video menu")
			eeObj.WriteMem8(bytecode+offs+1, 2) -- beq 0xa2 -> bne 0xa2
		end
	end
end)

-- Force 60hz
eeInsnReplace(0x207ae0, 0x00a0802d, 0x24100001) -- move $s0, $a1 -> li $s0, 1

-- Fix for bug 9716, which is a bug in the game.
-- Trying to retrieve a COM handle in the game will cause an infinite
-- loop if the handle has been deallocated and the debug server is not
-- connected. There's apparently a small race condition in the Asylum
-- level that sometimes can trigger the bug.
-- The fix involves getting out of the loop.
-- It causes a small visual glitch but otherwise the game continues to work fine.

eeInsnReplace(0x1c5958, 0x10400005, 0) -- QDT::KCOM::COM_SERVICE::RetrieveComHandle
eeInsnReplace(0x1c5b6c, 0x10400005, 0) -- QDT::KCOM::COM_SERVICE::RetrieveComHandle
eeInsnReplace(0x1c5d24, 0x10400005, 0) -- QDT::KCOM::COM_SERVICE::RetrieveComHandle
#Official widescreen support, forced 60Hz/NTSC, along with a game crash bug fix.

Fatal Fury: Battle Archives volume 2

ALL
Text

--gs-uprender=none
--gs-upscale=point
--host-audio-latency=0.010
--force-frame-blend=1
#Graphical fix.

SLUS_217.23
SLUS-21723_features.lua

This is a substantial file. Over 500 lines with additional controller/fightstick support and various shader/bezel files. I'm sharing the file itself as a download link.

https://drive.google.com/file/d/1FPPPJiHOazTXaD-H6K3kLACYDSdDeAE1/view

#official widescreen support in the form of screen bezels, along with expanded fightstick support and scanline shaders.

Fu'un Super Combo!!!

SLPS_257.81
Text

--gs-uprender=2x2
--gs-upscale=point
--host-audio-latency=0.3
--ee-hook=0x127050,AdvanceClock,0x2403002b,0x4000
--ee-hook=0x106734,FastForwardClock,0x0c04149c
--ee-native-function=memcpy,0x11fa9c,0x0080402d
--force-frame-blend=1
--vif1-ignore-cmd-ints=1
#Graphical and performance fixes.

SLPS_257.81
LUA

apiRequest(1.4)

eeNativeFunction(0x11fa9c, 0x0080402d, 'memcpy')
eeNativeFunction(0x11fb48, 0x2cc20008, 'memset')

eeInsnReplace(0x1279d0, 0x27bdffc0, 0x03e00008)                 -- <SyncDCache>
eeInsnReplace(0x1279d4, 0xffb20020, 0x00000000)
eeNativeHook (0x1279d0, 0x03e00008,'AdvanceClock',0xa00)
eeInsnReplace(0x127b00, 0x27bdffc0, 0x03e00008)                 -- <InvalidDCache>
eeInsnReplace(0x127b04, 0xffb20020, 0x00000000)
eeNativeHook (0x127b00, 0x03e00008,'AdvanceClock',0xa00)
eeInsnReplace(0x12a258, 0x3c19ffff, 0x03e00008)                 -- <sceSifWriteBackDCache>
eeInsnReplace(0x12a25c, 0x3739ffc0, 0x00000000)
eeNativeHook (0x12a258, 0x03e00008,'AdvanceClock',0x1700)

require("ee-gpr-alias")

local eeObj = getEEObject()
local emuObj = getEmuObject()

-- *** viBufBeginPut (1)
--eeInsnReplace(0x105628, 0x0c049c78, 0) -- 	jal	1271e0 <WaitSema>
eeInsnReplace(0x1056c8, 0x0c049c70, 0) -- 	jal	1271c0 <SignalSema>
-- *** viBufEndPut (1)
eeInsnReplace(0x105708, 0x0c049c78, 0) -- 	jal	1271e0 <WaitSema>
--eeInsnReplace(0x105730, 0x0c049c70, 0) -- 	jal	1271c0 <SignalSema>
-- *** viBufFlush (1)
--eeInsnReplace(0x105a88, 0x0c049c78, 0) -- 	jal	1271e0 <WaitSema>
--eeInsnReplace(0x105ab8, 0x0c049c70, 0) -- 	jal	1271c0 <SignalSema>
-- *** viBufPutTs (1)
eeInsnReplace(0x105c10, 0x0c049c78, 0) -- 	jal	1271e0 <WaitSema>
eeInsnReplace(0x105cf4, 0x0c049c70, 0) -- 	jal	1271c0 <SignalSema>

-- it's redundant calling of _waitIpuIdle in libmpeg... not so huge impact tho.
eeInsnReplace(0x118620,	0x0c04672a, 0) -- 	jal	119ca8 <_waitIpuIdle>

-- bug# 9972
local emuObj = getEmuObject()
emuObj.SetGsTitleFix( "ignoreSubBuffCov", "reserved", { } )
#Crash/stall fixes.

Grand Theft Auto III

SLUS_200.62
Text

--vu1-no-clamping=0
--gs-check-trans-rejection=1
--gs-kernel-cl-up="up2x2tc"
--gs-optimize-30fps=1
--ee-hook=0x27cea8,FastForwardClock
#Performance and graphical fix.

SLUS_200.62
LUA

apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

-- Performace fix
local emuObj = getEmuObject()	
local thresholdArea = 600
emuObj.SetGsTitleFix( "ignoreUpRender", thresholdArea , {alpha=0x80008068 , zmsk=1 } )


-- Bug#9133
-- workaround ... -16020(gp) value is something wrong. the value comes from CCamera::Process().
--                unfortunately accurate math or any other flags don't help for this problem,
--				  even though it should be calculation error issue.
--				  for here, it's just given 0 radian for CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension()
--				  actually the cloud is a billboard, so it should have 0 degree in view-space.
--				  so given 0 degree must be OK.... but could cause some corruption (wrong perspective or something)
eeInsnReplace(0x318344,	0xc792c16c, 0x44809000) -- 	lwc1	$f18,-16020(gp)
#Performance fix.

SLUS_200.62
SLUS-20062_features.lua

-- Lua 5.3
-- Title:  Grand Theft Auto III PS2 - SLUS-20062 (USA) v1.40
-- Author: Nicola Salmoria
-- Date:   November 3, 2015


require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])

apiRequest(0.7)	-- need widescreen support

local eeObj		= getEEObject()
local emuObj	= getEmuObject()


local USEWIDESCREEN_ADDRESS = 0x416748

local H1 =	-- start of main()
	function()
		eeObj.WriteMem8(USEWIDESCREEN_ADDRESS, 1)	-- enable widescreen
	end

local H2 =	-- change widescreen flag
	function()
		local isWidescreen = eeObj.GetGpr(gpr.v0)
		
		if isWidescreen == 0 then
			emuObj.SetDisplayAspectNormal()
		else
			emuObj.SetDisplayAspectWide()
		end
	end

local hook1 = eeObj.AddHook(0x27ed04, 0x7fbf0000, H1)	-- <main>:
local hook2 = eeObj.AddHook(0x270e50, 0xa382b8d8, H2)	-- <CMenuManager::AnaliseMenuContents(void)>:
#Official widescreen support.

Grand Theft Auto: San Andreas

SLUS_209.46
Text

--gs-optimize-30fps=1
--ee-hook=0x34dee8,FastForwardClock
--ee-hook=0x00245ee0,FastForwardClock
--cop2-no-clamping=1
--gs-flush-ad-xyz=safe
--vu1-clamp-range=0x04a,0x069
--gs-use-deferred-l2h=0
#Performance optimisation/fix.

SLUS_209.46
LUA

apiRequest(0.6)	-- request version 0.1 API. Calling apiRequest() is mandatory.

-- bug#8979
-- The game bugged.
-- CStreaming::StreamPedsIntoRandomSlots(int*) expects 8 integers arrray to process,
-- but CCheat::LoveConquersAllCheat() function copies just only 6 integers to the stack.
-- it seems the table of the source is correct, so using lq/sq instead of ld/sd to copy
-- the contents of the table correctly.
eeInsnReplace(0x59fbb0,	0xdca20010, 0x78a20010) -- 	ld	v0,16(a1) => lq
eeInsnReplace(0x59fbb8,	0xfc820010, 0x7c820010) -- 	sd	v0,16(a0) => sq

-- bug#8979, actually different one
-- the game has another bug... see https://pss.usrd.scea.com/bugzilla/show_bug.cgi?id=8979
eeInsnReplace(0x1abdd8,	0x102000d9, 0x102000cf) -- 	beqz	at,1ac140 <CPopulation::AddPed(ePedType, unsigned int, CVector const &, bool)+0x3a0>

-- Performace fix
local emuObj = getEmuObject()	
local thresholdArea = 700
emuObj.SetGsTitleFix( "ignoreUpRender", thresholdArea , {alpha=0x80000044 , zmsk=1 } )
#Performance and rendering fixes.

SLUS_209.46
SLUS-20946_features.lua

-- Lua 5.3
-- Title: Grand Theft Auto: San Andreas - SLUS-20946 (USA) v3.00
-- Author: Nicola Salmoria
-- Date:   November 5, 2015


require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])

apiRequest(0.7)	-- need widescreen support

local eeObj		= getEEObject()
local emuObj	= getEmuObject()


local USEWIDESCREEN_ADDRESS = 0x7004ef

local H1 =	-- init widescreen flag
	function()
		eeObj.WriteMem8(USEWIDESCREEN_ADDRESS, 1)	-- enable widescreen
	end

local H2 =	-- main game loop
	function()
		local isWidescreen = eeObj.ReadMem8(USEWIDESCREEN_ADDRESS)
		
		if isWidescreen == 0 then
			emuObj.SetDisplayAspectNormal()
		else
			emuObj.SetDisplayAspectWide()
		end
	end


local hook1 = eeObj.AddHook(0x233584, 0xa200004f, H1)	-- <CMenuManager::__ct(void)>:
local hook2 = eeObj.AddHook(0x246750, 0x24040012, H2)	-- <TheGame(void)>:
#Official widescreen support.

Grand Theft Auto: Vice City

SLUS_205.52
Text

--gs-check-trans-rejection=1
--gs-kernel-cl-up="up2x2tc"
--gs-optimize-30fps=1
--ee-hook=0x277b88,FastForwardClock
--ee-hook=0x279a18,FastForwardClock
#Performance fix.

SLUS_205.52
LUA

apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.


-- Performace fix
local emuObj = getEmuObject()	
local thresholdArea = 600
emuObj.SetGsTitleFix( "ignoreUpRender", thresholdArea , {alpha=0x80008068 , zmsk=1 } )


-- Bug#9147
-- workaround ... -2104(gp) value is something wrong. the value comes from CCamera::Process().
--                unfortunately accurate math or any other flags don't help for this problem,
--				  even though it should be calculation error issue.
--				  for here, it's just given 0 radian for CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension()
--				  actually the cloud is a billboard, so it should have 0 degree in view-space.
--				  so given 0 degree must be OK.... but could cause some corruption (wrong perspective or something)
eeInsnReplace(0x334d64,	0xc792f7c8, 0x44809000) -- 	lwc1	$f18,-2104(gp)
#Performance fix.

SLUS_205.52
SLUS-20552_features.lua

-- Lua 5.3
-- Title: Grand Theft Auto: Vice City - SLUS-20552 (USA) v3.00
-- Author: Nicola Salmoria
-- Date:   November 4, 2015


require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])

apiRequest(0.7)	-- need widescreen support

local eeObj		= getEEObject()
local emuObj	= getEmuObject()


local USEWIDESCREEN_ADDRESS = 0x4ba7bc

local H1 =	-- start of main()
	function()
		eeObj.WriteMem8(USEWIDESCREEN_ADDRESS, 1)	-- enable widescreen
	end

local H2 =	-- main game loop
	function()
		local isWidescreen = eeObj.ReadMem8(USEWIDESCREEN_ADDRESS)
		
		if isWidescreen == 0 then
			emuObj.SetDisplayAspectNormal()
		else
			emuObj.SetDisplayAspectWide()
		end
	end


local hook1 = eeObj.AddHook(0x279384, 0xffbf0000, H1)	-- <main>:
local hook2 = eeObj.AddHook(0x277784, 0x00000000, H2)	-- <TheGame(void)>:


-- Fix for bug #9161. The 'flying cars' cheat causes crashes when attempting to
-- fly an helicopter. We avoid that by disabling recognition of the cheat altogether.
-- The SLPM version comes with the cheat disabled out of the box.
eeInsnReplace(0x27db2c, 0x14400015, 0x10000015)	-- bnez -> b
#Official widescreen support and removal of "flying cars" cheat due to game crash.

Jak and Daxter: The Precursor Legacy

SCES_503.61
Text

--ee-jit-pagefault-threshold=20
--gs-frontend-opt-mode=1
--gs-use-mipmap=1
--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--vif-ignore-invalid-cmd=1
--vu1-mpg-cycles=144
--cop2-no-clamping=1
--host-audio-latency=0.040
#performance and graphical fix.

SCES_503.61
LUA

-- Jak EU
apiRequest(2.2)

local gpr    		= require("ee-gpr-alias")
local emuObj 		= getEmuObject()
local eeObj			= getEEObject()
local gsObj			= getGsObject()
local eeOverlay 	= eeObj.getOverlayObject()

-- Disable internal field shift compensation, part of post-process removal feature.
gsObj.SetDeinterlaceShift(0)

-- Fix shadow 
emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", { texMode=1  } )

-- Reduce flush count 
emuObj.SetGsTitleFix( "SetSelfRender", "reserved", { fbmask= 0x00FFFFFF , renderSelf=1 , zmsk=1 , alpha=0 , texMode=1  } )

-- Disable post-processing
-- update: removed due to occasional regression (bug#10608).  post-processing is now skipped in the EE via 'depth-cue'
-- emuObj.SetGsTitleFix( "ignoreSprite", "reserved", {  texType=1 , tw=5 , th=8, zmsk=1 , alpha=0x80000044  } )

-- ------------------------- OVERLAY MANAGER --------------------------
g_OnOverlayRegistered = function(filename, start, size)
	-- global function provided for adding per-overlay callback handlers.
end

local DH8 = function()
	local s0 = eeObj.GetGpr(gpr.s0)
	local linkblock = eeObj.ReadMem32(s0+0x5c)
	
	--print( string.format("--> PRELOAD %08x %08x",s0, linkblock) )
	
	local linkblock_allocate_length 		= eeObj.ReadMem32 (linkblock + 0x00)
	local linkblock_allocate_version 		= eeObj.ReadMem32 (linkblock + 0x04)
	local linkblock_allocate_segment_count 	= eeObj.ReadMem32 (linkblock + 0x08)
	local linkblock_allocate_name 			= eeObj.ReadMemStr(linkblock + 0x0c)
	
	local linkblock_allocate_seg1_linkptr 	= eeObj.ReadMem32 (linkblock + 0x4C)
	local linkblock_allocate_seg1_dataptr 	= eeObj.ReadMem32 (linkblock + 0x50)
	local linkblock_allocate_seg1_size 		= eeObj.ReadMem32 (linkblock + 0x54)
	local linkblock_allocate_seg1_flags 	= eeObj.ReadMem32 (linkblock + 0x58)
                                                              
	local linkblock_allocate_seg2_linkptr 	= eeObj.ReadMem32 (linkblock + 0x5C)
	local linkblock_allocate_seg2_dataptr 	= eeObj.ReadMem32 (linkblock + 0x60)
	local linkblock_allocate_seg2_size 		= eeObj.ReadMem32 (linkblock + 0x64)
	local linkblock_allocate_seg2_flags 	= eeObj.ReadMem32 (linkblock + 0x68)
                                                              
	local linkblock_allocate_seg3_linkptr 	= eeObj.ReadMem32 (linkblock + 0x6C)
	local linkblock_allocate_seg3_dataptr 	= eeObj.ReadMem32 (linkblock + 0x70)
	local linkblock_allocate_seg3_size 		= eeObj.ReadMem32 (linkblock + 0x74)
	local linkblock_allocate_seg3_flags 	= eeObj.ReadMem32 (linkblock + 0x78)
	
	-- seg1 is equiv to main in Jak3
	-- seg3 is equiv to top  in Jak3
	-- seg2 appears to be unused ... ?   --jstine

	if emuObj.IsToolingVerbose() then
		print( string.format("--> LOADED SEGMENT alloc_len %08x ver %08x segcount %08x  name:\"%s\"", linkblock_allocate_length, linkblock_allocate_version, linkblock_allocate_segment_count, linkblock_allocate_name) )
		print( string.format("    seg1linkptr %08x seg1dataptr %08x seg1size %08x seg1flags %08x", linkblock_allocate_seg1_linkptr, linkblock_allocate_seg1_dataptr, linkblock_allocate_seg1_size, linkblock_allocate_seg1_flags) )
		print( string.format("    seg2linkptr %08x seg2dataptr %08x seg2size %08x seg2flags %08x", linkblock_allocate_seg2_linkptr, linkblock_allocate_seg2_dataptr, linkblock_allocate_seg2_size, linkblock_allocate_seg2_flags) )
		print( string.format("    seg3linkptr %08x seg3dataptr %08x seg3size %08x seg3flags %08x", linkblock_allocate_seg3_linkptr, linkblock_allocate_seg3_dataptr, linkblock_allocate_seg3_size, linkblock_allocate_seg3_flags) )
	end

	if linkblock_allocate_seg1_size ~= 0 then eeOverlay.Register(linkblock_allocate_name .. ".seg1",  linkblock_allocate_seg1_dataptr, linkblock_allocate_seg1_size, false) end
	if linkblock_allocate_seg3_size ~= 0 then eeOverlay.Register(linkblock_allocate_name .. ".seg3",  linkblock_allocate_seg3_dataptr, linkblock_allocate_seg3_size, true)  end

	if (g_OnOverlayRegistered ~= nil) then
		-- Make sure to execute any previously registered OnOverlay handler
		if linkblock_allocate_seg1_size ~= 0 then g_OnOverlayRegistered(linkblock_allocate_name .. ".seg1", linkblock_allocate_seg1_dataptr, linkblock_allocate_seg1_size)	end
		if linkblock_allocate_seg1_size ~= 0 then g_OnOverlayRegistered(linkblock_allocate_name .. ".seg3", linkblock_allocate_seg3_dataptr, linkblock_allocate_seg3_size)	end
	end
end

assert(g_OnOverlayRegistered ~= nil)
local prev_OnOverlayRegistered = g_OnOverlayRegistered

g_OnOverlayRegistered = function(filename, start, size)
	
	if filename == "depth-cue.seg1" then
		-- Disable full-screen post process via depth-cue.
		-- This also removes half-pixel shift during interlacing.
		-- <depth-cue.seg1+00039c>
		-- 00701DFC:67BDFFF0                daddiu       $sp,$sp,-0x10 (0xfffffff0)		-> 	03E00008                jr           $ra
		-- 00701E00:FFBE0008                sd           $fp,8($sp)                     -> 	00000000				nop

		eeObj.WriteMem32(start + 0x39c, 0x03E00008)
		eeObj.WriteMem32(start + 0x3a0, 0x00000000)
		eeObj.WriteMem32(start + 0x004, 0x03E00008)
		eeObj.WriteMem32(start + 0x008, 0x00000000)
	end

	if (prev_OnOverlayRegistered ~= nil) then
		-- Make sure to execute any previously registered OnOverlay handler
		prev_OnOverlayRegistered(filename, start, size)
	end
end

-- hooked in link_control::finish(void)>:
eeObj.AddHook(0x0010ACF8, 0x040C825, DH8)  -- this is address US:0010abe0 JP:0010abd8 EU:0010ACF8
#Graphical fix, removal of intensive post process effects.

SCES-50361
SCES-50361_features.lua

This is a substantial file. Over 700 lines with an extensive graphical and control fix. I'm sharing the file itself as a download link.

https://drive.google.com/file/d/1KppgZpiK5bgESrpSRKo6kKPTysZ-NAC9/view

#Shadows fix, control scheme changes, forced 60Hz/NTSC/Widescreen.

King of Fighters 98 Ultimate Match

ALL
Text

--force-frame-blend=1
--gs-use-deferred-l2h=0
#Graphical fix.

SLES_552.80
SLES-55280_features.lua

This is a substantial file. Over 800 lines with additional controller/fightstick support and various shader/bezel files. I'm sharing the file itself as a download link.

https://drive.google.com/file/d/1-lArL1Yqe079Ni3G-ZtHr8hqNPUsjQJy/view

#More stick support, shaders, bezels, widescreen fix.

King of Fighters 2000

ALL
Text

--gs-uprender=none
--gs-upscale=point
--host-audio-latency=0.01
--hid-pad=1
#graphical fixes and support for further fightsticks.

SLUS_208.34
LUA

-- The King of Fighters 2000

apiRequest(1.1)


local emuObj 	= getEmuObject()
--will fix sprite rendering artifact
ndx = 28
val = 0x86
-- spriteCorrectionTab[ndx] = val
emuObj.SetGsTitleFix( "globalSet",  "reserved", { fixSpriteDivTab = val | ( ndx<<16) })
#graphical fixes.

SLUS_208.34
SLUS-20834_features.lua

This is a substantial file. Over 700 lines with additional controller/fightstick support and various shader/bezel files. I'm sharing the file itself as a download link.

https://drive.google.com/file/d/1FsPnuxgEa0ymnGdU6w2tdy-eamRN6l3e/view

#More stick support, shaders, bezels, widescreen fix.

Manhunt

SLUS_208.27
Text

--ee-hook=0x4329e0,FastForwardClock,0x1600fff1
--gs-uv-shift-pointsampling=1
--ee-hook=0x1d1d60,AdvanceClock,0x27bdffb0,225
--ee-hook=0x1d71e0,AdvanceClock,0x0c09a4d0,100
#Fix crane issue, and probably fixing lightsourcing.

SLUS_208.27
Lua

-- Manhunt [US]

local gpr = require('ee-gpr-alias')

apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

local emuObj = getEmuObject()	
local eeObj  = getEEObject()

-- Bug #9413
-- Disable uprender on the draw command which samples the framebuffer (0x3200) using bilinear sampling (texMode=2)
-- All lighting effects use TriFan prim type, so use that as well to filter against.
 
emuObj.SetGsTitleFix( "forceSimpleFetch",  "reserved", {prim=5, texMode=2, tbp=0x320000} )

-- Bug#9277
-- Shorten the timeout period for some particular execution command(s).
-- When entering the crane, some instruction is executed with a wait period of 0x7333.
-- Shortening the wait period to 0x4000 it.  Note that 0x5000 is enough to fix entering the
-- crane once, but a more aggressive value was needed for subsequent entry into the crane.

local FixBug9277 = function()
	local s0 = eeObj.GetGpr(gpr.s0)
	--local v0 = eeObj.GetGpr(gpr.v0)
	--print( string.format("-------- v0=0x%08x s0=0x%08x", v0, s0) )
	if s0 == 0x7333 then 
		eeObj.SetGpr(gpr.s0, 0x5800)
	end
end

-- No longer seems necessary, when FastForwardClock is applied here instead (see _cli.conf)
eeObj.AddHookJT(0x1d71f8, 0x10000036, FixBug9277)
#Further bug fixes as well as fixing bloom/overglare from lightsources.

Max Payne

SLES_503.26
Text

--gs-use-clut-merge=1
--gs-kernel-cl="clutmerge"
--gs-kernel-cl-up="clutmerge2x2"
--vu1-no-clamping=1
--vu0-no-clamping=1
--fpu-no-clamping=1
--force-pal-60hz=1
--vu1-mpg-cycles=1000
--safe-area-min=1.0
--fpu-accurate-mul-fast=1
--fpu-accurate-muldiv-range=0x2acce0,0x2acce0

#Graphics clean-up

SLES_503.26
Features Lua

-- Max Payne [US]

-- Lua 5.3
-- Title: Max Payne - SLES-50326 (Europe FIGS) v1.00


require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])

apiRequest(0.2)	-- request version 0.2 API for throttling control.

local eeObj		= getEEObject()
local emuObj	= getEmuObject()



local TH1A =	-- start of main()
	function()
		emuObj.ThrottleMax()
	end

local TH1B =	-- init loading screen
	function()
		local mode = eeObj.GetGpr(gpr.a0)

		if mode ~= 4 then	-- not sure what mode 4 is, but doesn't precede a real loading
			emuObj.ThrottleMax()
		end
	end

local TH1C =	-- advance progress bar
	function()
		local pct = eeObj.GetFpr(2)

		if pct >= 1.0 then
			emuObj.ThrottleNorm()
		end
	end



-- register hooks

local registeredHooks = {}

maxpayne_features_unregisterHooks = function()	-- global function (called by trophy_data)
	for _, hook in pairs(registeredHooks) do
		eeObj.RemoveHook(hook)
	end
	
	registeredHooks = {}
end

maxpayne_features_registerHooks = function()	-- global function (called by trophy_data)
	registeredHooks = {
		eeObj.AddHook(0x133dc8, 0x24030001, TH1A),	-- <main>:
		eeObj.AddHook(0x15ed7c, 0x24030003, TH1B),	-- <MaxPayne_GameMode::initLoadingScreen(void)>:
		eeObj.AddHook(0x133078, 0xc4a20000, TH1C),	-- <UpdateProgressBarKH(void)>:
	}
end

Metal Slug Anthology

ALL
Text

--host-audio-latency=0.010
--gs-upscale=point
--gs-uprender=none
#fix for graphical glitches.

SLUS_215.50
LUA

-- Metal Slug Anthology PS2 - SLUS-21550 (USA)

apiRequest(1.2)	-- request version 0.1 API. Calling apiRequest() is mandatory.

local eeObj		= getEEObject()
local emuObj	= getEmuObject()

-- Fix for black screen booting an elf. This is a game bug.
-- The v1.0 of the game suffered from an intermittent bug on the real PS2
-- where sometimes it would hang on a black screen trying to launch a new elf.
-- This is apparently due to a bad IOP state, which caused sceCdInit to hang.
-- Later versions of the game (1.1, 1.2) attempted to fix this in different ways.
-- On Olympus, v1.0 (USA) hangs always, while v1.2 (EUR/JPN) works always.
-- The fix implemented here replaces a call to FlushCache() to loadImageAndReboot(),
-- which is a function that reboots the IOP and resolves the hang.

eeInsnReplace(0x189c24, 0x0c08f7f8, 0x0c061dd2) -- FlushCache() -> loadImageAndReboot()
eeInsnReplace(0x117804, 0x0c0c1e08, 0x0c045e20) -- FlushCache() -> loadImageAndReboot()

Parappa the Rapper 2

ALL
Text

--host-audio-latency=0.01

#fix for audio off sync.

SCUS_971.67
LUA


-- Parappa the Rapper 2  [SCUS-97167]


apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

require( "ee-gpr-alias" )
require( "ee-hwaddr" )

local eeObj = getEEObject()

-- ================================================================================================
-- Title issues racy combination of VIF1 and GIF transfers.  It expects GIF to finish ahead of VU
-- XGKICK (via VIF1), which is atypical among PS2 titles (XGKICK has HW priority over GIF, and so
-- GIF can only finish ahead of XGKICK in certain extreme cases).
--
-- Fixed by delaying the specific VIF1 transfer (identified by MADR) for a long time to ensure GIF
-- gains arbitration and finishes ahead of XGKICKs.
--
local fix01_dma_vif1 = 
	function()
		local ee		= eeObj
		local tgtaddr	= ee.GetGpr(gpr.s0)

		-- print( string.format("success pt.1 : %x %x", vif1_hw.CHCR, tgtaddr ) )

		if tgtaddr == vif1_hw.CHCR then

			-- expected:
			--  # DIR==1 and MOD==1  (chain)
			--  # TADR==0x01C76AA0

			local chcr = ee.GetGPR(gpr.v0)

			if (chcr & 0x05) == 0x05 then
				local tadr = ee.ReadMem32(vif1_hw.TADR);
				if tadr == 0x01C76AA0 then
					-- 0x6000 works fine, 0x6500 adds a little extra cushion.
					ee.SchedulerDelayEvent("vif1.dma", 0x6500)
					-- print( "Parappa fix applied!" )
				end
			end
		end
	end
-- ================================================================================================

eeObj.AddHook(0x0015A008, 0xAE020000, fix01_dma_vif1)

-- ================================================================================================
-- Our emulator has accuracy problems on so many places. In this title, we have problems on VU.
-- To be accurate on VU is quite painful (we won't be able to get reasonable performance with it)
-- So as workaround, we just disable bilinear textures on Render-To-Texture drawing.
-- Bug#8122
eeInsnReplace(0x118084, 0xde260008, 0x24060000) -- 	ld	a2,8(s1)
eeInsnReplace(0x118798,	0xde260008, 0x24060000) -- 	ld	a2,8(s1)
eeInsnReplace(0x118868,	0xde660008, 0x24060000) -- 	ld	a2,8(s3)
eeInsnReplace(0x119d18,	0xdc460008, 0x24060000) -- 	ld	a2,8(v0)
eeInsnReplace(0x119d18,	0xdc460008, 0x24060000) -- 	ld	a2,8(v0)

Psychonauts

SLUS_211.20
Text

--vu1-jr-cache-policy=sameprog
--vu1-jalr-cache-policy=sameprog
--ee-hook=0x101fc0,FastForwardClock,0x3c0f0036
--ee-hook=0x110390,FastForwardClock,0x8d8f0000
--ee-hook=0x101c10,FastForwardClock,0x51cf0052
--gs-vert-precision=8
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
--gs-render-tile-threshold=300000
--vu-custom-min-max=0
--vu1-di-bits=0
--vu0-di-bits=0
--vu1-opt-vf00=2
--vu0-opt-vf00=2
--vu1-injection=1
--vu1-mpg-cycles=666
--vu1-mpg-cycles=1166,$000
--vu1-mpg-cycles=950,0xffffffff
--vu0-mpg-cycles=300,0xfc
--ee-hook=0x127630,AdvanceClock,0x27bdffd0,2100
--cdvd-sector-read-cycles=4000
--iop-cycle-scalar=1.6
#Seems like substantial performance fixes

SLUS_211.20
LUA

-- psychonauts_slus21120
local gpr    = require("ee-gpr-alias")
local emuObj = getEmuObject()	

apiRequest(1.0)	-- request version 0.1 API. Calling apiRequest() is mandatory.

-- Bug#9174 - 
emuObj.SetGsTitleFix( "ignoreSubBuffCov", "reserved", { } )

-- Bug#9240 (Light maps uprender)
-- Copy z-buffer for future use with light maps. psm = SCE_GS_PSMZ24 (49)
emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", {tw=9, th=9, psm=49, zmsk=1 } )

-- Apply light maps texMode=2 (bilinear)   psm= SCE_GS_PSMCT32 (0)
emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", {tw=8, th=8, psm=0, ztst=1, texMode=2 } )

-- Bug#9176
--
-- This bug seems GPUGS interpolation problem.
-- The game draws clouds as undiscovered area on the map, but
-- Z value is unstable --- sometimes 0x320, sometimes 0x321.
-- On drawing 'Highlight' object (which is missing one), it uses z=0x320 with
-- ZTST=GEQUAL. Therefore if the cloud renders with z=0x321, this highlighted object
-- doesn't appear. But it's OK on the real PS2 because of no-drawing right edge,
-- z=0x321 won't be available on the packet (interpolation differences between
-- the real PS2 and our gs)
-- it gives some values (50.0f) to get +1 on Z value for the highlighted object.
-- this value will be used later to create the packet in _sprite_ps2_push_data(ESprite*).
--
-- This old one causes a problem on some other scenes.
-- local eeObj = getEEObject()
-- eeObj.AddHook(0x1b276c,	0xe4400024, function() 
-- 				 local v0 = eeObj.GetGpr(gpr.v0)
-- 				 local z  = eeObj.ReadMemFloat(v0+32)
-- 				 eeObj.WriteMemFloat(v0+32, z+50.0)
-- end)
-- New one by Ernesto :
-- The idea is to apply the offset only on the marker.
local eeObj = getEEObject()
local adjustMapZHook = function() -- EMapRenderWindow::drawHighlightSprites
    eeObj.SetFpr(14, eeObj.GetFpr(14) + 50.0)
end
eeObj.AddHook(0x25d654, 0x8de40068, adjustMapZHook) -- \/
eeObj.AddHook(0x25d714, 0xe7b500cc, adjustMapZHook) -- /\
eeObj.AddHook(0x25d7d0, 0xe7b500cc, adjustMapZHook) -- <
eeObj.AddHook(0x25d894, 0x46000386, adjustMapZHook) -- >


-- bug#9423 - menus render 20+ times over again, causing very low fps.
-- The whole game in general has no concept of pacing and will re-draw frames multiple times
-- between vsync refreshes.  Hook placed on GameApp::EndFrame() measures time between frames and
-- if it's too short, the EE clock is advanced significantly to compensate.

local last_time = 0
local last_diff = 0
local advanceClockForAny = function()
	local thistime = eeObj.GetClock()
	local diff = thistime - last_time
	local adv  = 0

	if diff <= 0 then
		-- sanity check, mostly for snapshot restore.
		last_diff = diff
		last_time = thistime
		return
	end
	
	-- EE @ 30fps == roughly 10 million cycles
	-- bug#9555 - We need to make a reasonable tally of VIF cycles across game display swaps.
	--   Use a combination heuristic of EE and VIF1 cycles to gues at whether the title should
	--   lock to 45fps, 30fps, or something worse.
	
	local fastminEE		= 1600000		-- less than this it's safe to run > 30 fps
	local fastminVIF_30	= 2200000		-- VU1 total that merits 30hz throttle
	local fastminVIF_45	= 1700000		-- VU1 total that merit 45hz throttle.
	local baremin_wo_vif= 6100000		-- EE values below this get promoted to this value  (~50hz)
	local forced30hz	= 9330000
	local forced45hz	= 7820000
	
	local vif1_cycles = eeObj.GetVif1Cycles()
	if (vif1_cycles > forced30hz) then
		vif1_cycles = forced30hz
	end

	local diff_vif = diff + vif1_cycles
	adv = adv + vif1_cycles

	-- Lock anything that seems like "Real Work" to either 30 or 45 FPS:
	
	if diff_vif < fastminEE then
		adv = adv + (fastminEE*2 - diff_vif)
	elseif vif1_cycles > fastminVIF_30 and (diff+(fastminVIF_30)//2) < forced30hz then
		adv = adv + (forced30hz  		- diff - (fastminVIF_30)//2)
	elseif vif1_cycles > fastminVIF_45 and (diff+(fastminVIF_45)//2) < forced45hz then
		adv = adv + (forced45hz  		- diff - (fastminVIF_45)//2)
	elseif diff < baremin_wo_vif then
		adv = adv + (baremin_wo_vif  	- diff)
	end

	-- print (string.format("DELTA: %d  ADV: %d  VIF1: %d", diff, adv, vif1_cycles))

	if adv ~= 0 then
		eeObj.AdvanceClock(adv)
	end

	-- Ensure next frame's delta time takes into consideration this frame's advancement.
	-- Otherwise each fraem delta time would get progressively worse.

	thistime = thistime + adv
	last_time = thistime
	last_diff = diff
end

local advanceClockForGame = function() advanceClockForAny(5300000, 2700000) end
eeObj.AddHookJT(0x207cf8, 0x27bdfff0, advanceClockForGame) 	  -- <GameApp::EndFrame()>:
#Performance and optimisations

Red Faction

SLUS_200.73
Text

--gs-use-deferred-l2h=1
--l2h-2d-params=0x0000000800000001,0x000000003a0a2300,512,2
--vu1=jit-sync
--ee-cycle-scalar=1.02
--ee-hook=0x00213370,FastForwardClock,0x8F8293A8
--ee-hook=0x24ce30,AdvanceClock,0x8c620000,20000
--ee-hook=0x272b44,FastForwardClock,0x3c0201ee
--ee-hook=0x272bc4,FastForwardClock,0x3c0201ee
--ee-hook=0x21b354,AdvanceClock,0x3c031000,0x1240
#performance fixes.

SLUS_200.73
LUA

-- Red Faction [US]

apiRequest(1.6)
local gpr = require("ee-gpr-alias")

-- title uses memcpy() to write to VU1 memory, so some instances will be hotfixed to
-- use slowpath_memcpy() at runtime.

eeNativeFunction(0x259820, 0x0080402d, 'memcpy')
eeNativeFunction(0x2599d8, 0x2cc20008, 'memset')

eeNativeFunction(0x253870, 0x27bdffd0, 'ieee754_acosf')
eeNativeFunction(0x254620, 0x44026000, 'ieee754_sqrtf')
eeNativeFunction(0x255a50, 0x44026000, 'cosf')
eeNativeFunction(0x255df0, 0x44026000, 'sinf')
eeNativeFunction(0x256318, 0x27bdffa0, 'acosf')

eeInsnReplace(0x24d7e0, 0x24030064, 0x03e00008)                 -- <FlushCache>
eeInsnReplace(0x24d7e4, 0x0000000c, 0x00000000)
eeNativeHook (0x24d7e0, 0x03e00008,'AdvanceClock',0xa00)
eeInsnReplace(0x24d810, 0x2403ff98, 0x03e00008)                 -- <iFlushCache>
eeInsnReplace(0x24d814, 0x0000000c, 0x00000000)
eeNativeHook (0x24d810, 0x03e00008,'AdvanceClock',0xa00)

eeInsnReplace(0x24de20, 0x27bdffe0, 0x03e00008)                 -- <SyncDCache>
eeInsnReplace(0x24de24, 0x0080302d, 0x00000000)
eeNativeHook (0x24de20, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x24de98, 0x3c02ffff, 0x03e00008)                 -- <iSyncDCache>
eeInsnReplace(0x24de9c, 0x3442ffc0, 0x00000000)
eeNativeHook (0x24de98, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x24df58, 0x27bdffe0, 0x03e00008)                 -- <InvalidDCache>
eeInsnReplace(0x24df5c, 0x0080302d, 0x00000000)
eeNativeHook (0x24df58, 0x03e00008,'AdvanceClock',0x600)
eeInsnReplace(0x24dfd0, 0x3c02ffff, 0x03e00008)                 -- <iInvalidDCache>
eeInsnReplace(0x24dfd4, 0x3442ffc0, 0x00000000)
eeNativeHook (0x24dfd0, 0x03e00008,'AdvanceClock',0x600)

local emuObj = getEmuObject()
local eeObj = getEEObject()

-- bug#10159 workaround
-- slowdown the jeep speed....

local jeepObj = 0
eeObj.AddHook(0x1376f0,	0xc6600174, function()
				 jeepObj = eeObj.GetGpr(gpr.s1)
end)
eeObj.AddHook(0x137a48,	0xc7ac00bc, function()
				 local s1 = eeObj.GetGpr(gpr.s1)
				 if s1 == jeepObj then
					eeObj.SetFpr(12, eeObj.GetFpr(12)*0.90)
				 end
end)

-- bug#10249 workaround
-- forcibly calculate the jeep's suspension.
eeObj.AddHook(0x19ee08,	0x8ec2120c, function()
				 if jeepObj - 624 == eeObj.GetGpr(gpr.s6) then
					eeObj.SetGpr(gpr.v0, 1)
				 end
end)

-- debug code for jeep movment target.
-- local px = 0.0
-- local pz = 0.0
-- eeObj.AddHook(0x1375bc,	0x26650174, function()
-- 				 local s1 = eeObj.GetGpr(gpr.s1)
-- 				 if s1 == jeepObj then
-- 					local s3 = eeObj.GetGpr(gpr.s3)
-- 					px = eeObj.ReadMemFloat(s3 + 372)
-- 					pz = eeObj.ReadMemFloat(s3 + 380)
-- 				 end
-- end)
-- eeObj.AddHook(0x1375c8, 0xa2620170, function()
-- 				 local s1 = eeObj.GetGpr(gpr.s1)
-- 				 if s1 == 0x19a7a00 then
-- 					local s3 = eeObj.GetGpr(gpr.s3)
-- 					local x = eeObj.ReadMemFloat(s3 + 372)
-- 					local z = eeObj.ReadMemFloat(s3 + 380)
-- 					if px ~= x or pz ~= z then
-- 					   print(string.format("[%f %f] => [%f %f] v0=%d",
-- 										   px, pz, x, z, eeObj.GetGpr(gpr.v0)))
-- 					end
--  				 end
-- end)
#physics calculations and performance fix.

SLUS_200.73
SLUS-20073_features.lua

-- Lua 5.3
-- Title:   Red Faction PS2 - SLUS-20073 (USA)
-- Author:  Ernesto Corvi, Adam McInnis

-- Changelog:

apiRequest(1.1)	-- request version 1.1 API. Calling apiRequest() is mandatory.

local eeObj		= getEEObject()
local emuObj	= getEmuObject()

local L1 =  -- main
	function()
		emuObj.ThrottleMax()
	end
	
local L2 =  -- main
	function()
		emuObj.ThrottleNorm()
	end
	
local load1 = eeObj.AddHook(0x165590, 0x27bdffb0, L1) -- game_load_level
local load2 = eeObj.AddHook(0x16578C, 0x7bb10010, L2) -- game_load_level

-- Widescreen support --
eeInsnReplace(0x2071c4, 0x00000000, 0x3c013f40) -- gr_setup_3d
eeInsnReplace(0x2071d0, 0x00000000, 0x4481f000) -- gr_setup_3d
eeInsnReplace(0x2072e0, 0x00000000, 0x461ea502) -- gr_setup_3d
eeInsnReplace(0x2072e8, 0x00000000, 0x461ead43) -- gr_setup_3d
eeInsnReplace(0x23a34c, 0x44826000, 0x461e0303) -- shadow_ngps_render_and_copy
eeInsnReplace(0x23a444, 0x3c024334, 0x3c024309) -- shadow_ngps_render_and_copy
emuObj.SetDisplayAspectWide()
#Official widescreen support.

Resident Evil Code: Veronica X

ALL
Text

--ee-jit-pagefault-threshold=30
#crash fix.

ALL
LUA

-- VeronicaX
apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

-- Bug# 9976
local emuObj = getEmuObject()	
emuObj.SetGsTitleFix( "clipScissors", "reserved", {alpha = 0 , frameW = 4 , psm = 0} )
#graphical fix.

Rogue Galaxy

ALL
Text

--gs-kernel-cl-up="up2x2skipinterp"
--gs-optimize-30fps=1
#visual fixes and performance optimisation.

SCUS_974_90
LUA

require("ee-gpr-alias")
apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

-- Bug#8404 WORKAROUND
-- See https://pss.usrd.scea.com/bugzilla/show_bug.cgi?id=8404
eeInsnReplace(0x124898, 0x3442ffff, 0x3442fffe) -- 	ori	v0,v0,0xffff
#unsure what this fixes.

Samurai Shodown Anthology

SLUS_216.29
Text

--gs-upscale=point
--gs-uprender=2x2
--gs-motion-factor=25
--host-audio-latency=0.01
--gs-ignore-dirty-page-border=1
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
--gs-h2l-list-opt=1
--gs-h2l-accurate-hash=1
#fix for substantial slowdown during combat.

Star Wars Bounty Hunter

ALL
Text

--gs-kernel-cl-up="OptRightTri"
--gs-vert-precision=8

Star Wars: Jedi Starfighter

SLES_503.71
Text

--gs-check-trans-rejection68=1
--gs-dirty-page-policy=1

SLES_503.71
Lua

-- Star Wars: Jedi Starfighter [SLES-50371] [EU]

require("ee-gpr-alias")
require("pad-and-key")
apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

local eeObj = getEEObject()
local emuObj = getEmuObject()

-- Bug#9013 - title calls PS2::Exit() at the end of a bonus stage.
eeInsnReplace(0x323398, 0x0c116bb4, 0x00000000) --   jal     Stop__12CTaskManagerFv
 
-- Bug#8905
-- The game sets a little bit big DH values for GS Display Register.
-- mimic overscan cropping (generic crop happens in GsScanoutArea::Populate)
local dump_display = function()
   local a5 = eeObj.GetGpr(gpr.t1)
   local ds1_h = eeObj.ReadMem32(a5+892)
   local ds2_h = eeObj.ReadMem32(a5+908)
   local dh1   = (ds1_h>>(44-32))&0x7ff
   local dh2   = (ds2_h>>(44-32))&0x7ff
   if dh1 >= 574 then
	  dh1 = 558 -- 574-16
	  ds1_h = (ds1_h & 0xfff) | (dh1 << (44-32))
	  eeObj.WriteMem32(a5+892, ds1_h)
   end
   if dh2 >= 575 then
	  dh2 = 559 -- 575-16
	  ds2_h = (ds2_h & 0xfff) | (dh2 << (44-32))
	  eeObj.WriteMem32(a5+908, ds2_h)
   end
end
eeObj.AddHook(0x4fc33c,	0x02084821, dump_display)
eeObj.AddHook(0x4fc068,	0x02084821, dump_display)

-- Bug#8944
-- The game doesn't clear the framebuffer on movie-startup and movie-display.
-- call clear functions at the appropriate points by using Replacement.
local Replace_CVideoDecoder_Draw = InsnOverlay( {
	0x27bdfff0, -- 	addiu	sp,sp,-16
	0xffbf0000, -- 	sd	ra,0(sp)

	-- swap
	0x0c13f044, -- 	jal	0x4fc110
	0x00000000, -- 	nop
	-- clear
	0x0c13f228, -- 	jal	0x4fc8a0
	0x24044000, -- 	li	a0,16384

	0xdfbf0000, -- 	ld	ra,0(sp)
	0x03e00008, -- 	jr	ra
	0x27bd0010, -- 	addiu	sp,sp,16
})
eeInsnReplace(0x427fe0,	0x0c13f044,0x0c000000 | (Replace_CVideoDecoder_Draw>>2))
local Replace_CPS2MpegPlayer_Open = InsnOverlay( {
	0x27bdfff0, -- 	addiu	sp,sp,-16
	0xffbf0000, -- 	sd	ra,0(sp)

	-- clear color
	0x44806000, -- 	mtc1	zero,$f12
	0x46006346, -- 	mov.s	$f13,$f12
	0x0c13f1d8, -- 	jal	0x4fc760
	0x46006386, -- 	mov.s	$f14,$f12
	-- clear
	0x0c13f228, -- 	jal	0x4fc8a0
	0x24044000, --  li	a0,16384
	-- swap
	0x0c13f044, --  jal	4fc110 <glSwapBuffersPSX2>	
	0x00000000, --  nop

	-- restore some registers
	0x0220302d, -- 	move	a2,s1
	0x0200382d, -- 	move	a3,s0

	0xdfbf0000, -- 	ld	ra,0(sp)
	0x03e00008, -- 	jr	ra
	0x27bd0010, -- 	addiu	sp,sp,16
})
eeInsnReplace(0x423c3c,	0x0220302d, 0x0c000000 | (Replace_CPS2MpegPlayer_Open>>2))

--
-- Bug#8981 / Bug#9006
--
local std_string_c_str = function(ptr)
   return eeObj.ReadMemStr(eeObj.ReadMem32(eeObj.ReadMem32(ptr) + 12))
end
local player_obj_found_flag = 0
local player_obj = 0
eeObj.AddHook(0x464530,	0x27bdff90, function()
				 if std_string_c_str(eeObj.GetGpr(gpr.a1)) == "_player" then
					--print(string.format("LookupGameObject %s", std_string_c_str(eeObj.GetGpr(gpr.a1))))
					player_obj_found_flag = 1
				 end
end)
eeObj.AddHook(0x464720,	0x7bb10010, function()
				 if player_obj_found_flag == 1 then
					player_obj = eeObj.ReadMem32(eeObj.GetGpr(gpr.v0)+92)
					--print(string.format("    obj    = %x", eeObj.GetGpr(gpr.v0)))
					--print(string.format("    92(v0) = %x", player_obj))
					--print(string.format("    [%f, %f, %f]", eeObj.ReadMemFloat(player_obj+116), eeObj.ReadMemFloat(player_obj+120), eeObj.ReadMemFloat(player_obj+124)))
					--print(string.format("    [%f, %f, %f]", eeObj.ReadMemFloat(player_obj+52), eeObj.ReadMemFloat(player_obj+56), eeObj.ReadMemFloat(player_obj+60)))
					player_obj_found_flag = 0
				 end
end)

eeObj.AddHook(0x147444,	0x0040282d, function()
				 local strptr = eeObj.GetGpr(gpr.v0)
				 local str    = std_string_c_str(strptr)
				 if string.match(str, "ExplosionFire")
					-- or string.match(str, "ExplosionSpark")
				 then
					local explosion_object = eeObj.ReadMem32(eeObj.GetGpr(gpr.s0)+92)
					local eo_x = eeObj.ReadMemFloat(explosion_object+116)
					local eo_y = eeObj.ReadMemFloat(explosion_object+120)
					local eo_z = eeObj.ReadMemFloat(explosion_object+124)
					-- print(string.format("exp obj : %x", explosion_object))
					-- print(string.format("        [%f, %f, %f]", eo_x, eo_y, eo_z))
					-- print(string.format("        [%f, %f, %f]", eeObj.ReadMemFloat(explosion_object+52), eeObj.ReadMemFloat(explosion_object+56), eeObj.ReadMemFloat(explosion_object+60)))

					local pl_x = eeObj.ReadMemFloat(player_obj+116)
					local pl_y = eeObj.ReadMemFloat(player_obj+120)
					local pl_z = eeObj.ReadMemFloat(player_obj+124)
					-- print(string.format("pl  obj : %x", player_obj))
					-- print(string.format("        [%f, %f, %f]", pl_x, pl_y, pl_z));

					local len = (eo_x-pl_x)*(eo_x-pl_x) + (eo_y-pl_y)*(eo_y-pl_y) + (eo_z-pl_z)*(eo_z-pl_z)
					-- print(string.format("lengh^2 = %f", len))

					-- print(string.format("str : %s", std_string_c_str(strptr)))

					if len < 960000.0 then
					   -- print("    REMOVED")
					   eeObj.SetPc(0x1474b0)
					end
				 end
end)

local overlay_addr = InsnOverlay( {
 0x8c700008, --  lw      $s0, 8($v1)
 0x8e040000, --  lw      $a0, 0($s0)
 0x8c840000, --  lw      $a0, 0($a0)
 0x3c05006c, --  lui     $a1,0x6c
 0x34a5ce28, --  ori     $a1,$a1,0xce28
 0x14850002, --  bne     $a0, $a1, <ret>
 0x00000000, --  nop
 0xac600004, --  sw      zero, 4($v1)
 0x03e00008, -- ret: jr      $ra
 0x8c630004, --  lw      $v1, 4($v1) 
} )
local call_insn = (overlay_addr >> 2) | 0x0c000000
eeInsnReplace( 0x267f84, 0x8c700008, call_insn ) -- lw $s0, 8($v1) -> jal overlay_addr
eeInsnReplace( 0x267f88, 0x8c630004, 0x00000000 ) -- lw $v1, 4($v1) -> nop

-- The game has a bug when you replay the last campaign mission in coop mode ("The Jedi Master").
-- Upon completing the mission successfully, the game asks to "Continue" or "Quit".
-- Selecting "Continue" causes the game to hang, as there's nothing to continue to (it's the last mission)
-- The following patch fixes this problem by changing to prompt to "Retry" or "Quit", as it behaves in 1p mode
 
eeObj.AddHook(0x39debc, 0x0220202d, function()
     local strptr = eeObj.GetGpr(gpr.v0)
     local str    = std_string_c_str(strptr)
     if string.match(str, "m16_fleet") then
     eeObj.SetGpr(gpr.s0, 1)
     end
end)
 
-- fix for a node corruption.
-- here's what happens (from Ernesto)
--
-- Well, I was finally able to track down the issue. It's actually difficult to explain and the actual trigger is still unknown to me, as it seems to be timing related somehow.
-- But, I found a way to reliably detect it and work around it. Basically, when the bug happens, CSGNode::AddChild will try to add a child node that's already a children of a different root node.
-- That causes all sorts of havok and it's what ends up causing the node child list to eventually be deallocated and the render to crash.
eeObj.AddHook(0x266A70, 0x27bdffc0, function()
--   local obj = eeObj.GetGpr(gpr.a0)
    local node = eeObj.GetGpr(gpr.a1)
    local parent = eeObj.ReadMem32(node+0x10)
--   local caller = eeObj.GetGpr(gpr.ra)

    if parent ~= 0 then
--      print(string.format("Node %08x already has a parent (%08x, caller: %08x)", node, parent, caller))
       eeObj.SetPC(0x266B80)
    end
end)

Star Wars Racer Revenge

SLES_503.66
Text

--ee-hook=0x0025b3b0,FastForwardClock
--ee-hook=0x0025b188,FastForwardClock
--ee-hook=0x00243274,FastForwardClock
--gs-vert-precision=8
--idec-cycles-per-qwc=768
--host-audio-latency=0.60
--fpu-no-clamping=1
--cop2-no-clamping=1
--vu1-di-bits=0
--gs-override-small-tri-area=1
--assert-path1-ad=0
--ee-ignore-segfault=Read

SLES_503.66
Lua

require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])
apiRequest(0.4)

-- Star Wars: Racer Revenge (SLES-50366) [US]

local eeObj		= getEEObject()
local emuObj   	= getEmuObject()	

eeInsnReplace(0x13d7f0, 0x1000ffff, 0x0804f45d)	-- retry FREAD() for fix #9025,

-- Track#
-- The Grand Reefs 			: 6 
-- Ruins of Carnuss Gorgull : 9
eeObj.AddHook(0x187330,	0x3c010001, function()
				 local track = eeObj.GetGpr(gpr.a1)
				 print(string.format("Track : %d", track))
				 if track == 6 or track == 9 then
					eeObj.Vu1MpgCycles(1000)	-- makes it be 30fps.
				 else
					eeObj.Vu1MpgCycles(100)		-- default value.
				 end
end)

-- Small triangle rejection. Works in conjunction with CLI setting   gs-override-small-tri-area=1
-- keep default area for texture 256x256 ( no blend)  (Anakin face)  
emuObj.SetGsTitleFix( "setRejectionArea", 500,{twIsNot=8, thIsNot=8 } )

-- Set triangle rejection area= 1000  when alpha blend is not 0 ( i.e blend is On)
emuObj.SetGsTitleFix( "setRejectionArea", 1000, {alphaIsNot=0 } )

SLES_503.66
Lua Features
Seems to also include some game fix

-- Lua 5.3
-- Title:   Star Wars Racer Revenge PS2 - SLES-50366 (EUR)
-- Author:  Ernesto Corvi

-- Changelog:

apiRequest(0.2)	-- request version 0.2 API. Calling apiRequest() is mandatory.

local eeObj		= getEEObject()
local emuObj	= getEmuObject()

local L1 =  -- PodUILoadingPage::PodUILoadingPage
	function()
		emuObj.ThrottleMax()
	end
	
local L2 =  -- PodUILoadingPage::~PodUILoadingPage
	function()
		emuObj.ThrottleNorm()
	end
	
local load1 = eeObj.AddHook(0x1caa30, 0x27bdffe0, L1)	-- PodUILoadingPage::PodUILoadingPage
local load2 = eeObj.AddHook(0x1caa70, 0x27bdffd0, L2)	-- PodUILoadingPage::~PodUILoadingPage



-- BUG 9244 - This title exhibits memory allocation problems as described on the
-- PS2 tech note titled "malloc() Issues". Overlay the FullAllocAndFree() and hook it to main()

local overlay_addr = InsnOverlay( {
	0x27bdfff0, --		addiu $sp, -0x10
	0x7fbf0000, --		sq $ra, 0($sp)
	0x0c0c1710, --  	jal malloc
	0x3c0401e0, --  	lui $a0, 0x01e0
	0x0c0c171a, --  	jal free
	0x70402628, --  	paddub $a0, $v0, 0
	0x7bbf0000, --  	lq	$ra, 0($sp)
	0x03e00008, --  	jr $ra
	0x27bd0010  --  	addiu   $sp, 0x10
} )
local call_insn = (overlay_addr >> 2) | 0x0c000000
eeInsnReplace(0x23a020, 0x0c0be0a2, call_insn) -- jal scePrintf

-- BUG 9244 - move stack down to 0x01f80000 to free up an extra 512KB
eeInsnReplace(0x100038, 0x3c0501f0, 0x3c0501f8)


Twisted Metal Black

ALL
Text

--mtap1=always
--gs-use-deferred-l2h=0
--l2h-2d-params=0x0000000400000004,0x00000000300a0000,240
--vu1-di-bits=0
--vu1-opt-vf00=2
#performance fix.

SCUS_971.01
LUA

require("ee-gpr-alias")
apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

-- This game uses an old kernel which has a bug on _TerminateThread.
-- It is necessary to check the target thread is already in readyqueue or not.

iopObj = getIOPObject()
iopInsnReplace(0x0000C5C0, 0x0C004430, 0) -- jal         0x000110C0				// unlink_element (in TerminateThread)
iopInsnReplace(0x0000C6EC, 0x0C004430, 0) -- jal         0x000110C0				// unlink_element (in iTerminateThread)
local fix_TerminateThread = function()
   local TCB = iopObj.GetGpr(gpr.s0)
   local TCB_status = iopObj.ReadMem8(TCB + 0xc)
   local TCB_h_l = TCB
   if TCB_status == 0x2 then
	  -- the target thread is on ready.
	  local TCB_h_l_prev = iopObj.ReadMem32(TCB_h_l + 0)
	  local TCB_h_l_next = iopObj.ReadMem32(TCB_h_l + 4)
	  if TCB_h_l_prev == TCB_h_l_next then		-- last_one_element(&tcb->h.l)
		 -- we need to maintain threadManCB.readymap.
		 -- print("WE NEED TO MAINTAIN threadManCB.readymap!")
		 local s0 = iopObj.ReadMem16(TCB + 0xe)	-- prio
		 local s1 = TCB
		 local a0 = s0 >> 5
		 a0 = a0 << 2
		 local v1 = s0 & 0x1f
		 local v0 = 1 << v1
		 v1 = 0x10000 + a0
		 v1 = iopObj.ReadMem32(v1 + 0x1a08)
		 v0 = ~v0
		 v1 = v1 & v0
		 local at = 0x10000+a0
		 iopObj.WriteMem32(at+0x1a08, v1)

-- 0000B798   00102142 srl         a0,s0,5
-- 0000B79C   00042080 sll         a0,a0,2
-- 0000B7A0   3203001F andi        v1,s0,0x1F
-- 0000B7A4   24020001 li          v0,0x1
-- 0000B7A8   00621004 sllv        v0,v0,v1
-- 0000B7AC   3C030001 lui         v1,0x1
-- 0000B7B0   00641821 addu        v1,v1,a0
-- 0000B7B4   8C631A08 lw          v1,0x1A08(v1)
-- 0000B7B8   00021027 nor         v0,zero,v0
-- 0000B7BC   00621824 and         v1,v1,v0
-- 0000B7C0   3C010001 lui         at,0x1
-- 0000B7C4   00240821 addu        at,at,a0
-- 0000B7C8   AC231A08 sw          v1,0x1A08(at)

	  end
   end
   -- do unlink_element
   local v1 = iopObj.ReadMem32(TCB_h_l+0)	-- element->prev
   local v0 = iopObj.ReadMem32(TCB_h_l+4)	-- element->next
   iopObj.WriteMem32(v1 + 4, v0)			-- element->prev->next = element->next
   iopObj.WriteMem32(v0 + 0, v1)
end
iopObj.AddHook(0x0000C5C4, 0x02002021, fix_TerminateThread) -- move        a0,s0
iopObj.AddHook(0x0000C6F0, 0x02002021, fix_TerminateThread) -- move       a0,s0

-- _waitIpuIdle64 spin perf down problem. Bug#8289
-- NOTE: new libarary also loops just 500dec around. 0x1389 is too much.
eeInsnReplace(0x0020CF80, 0x28421389, 0x28420200) -- slti        v0,v0,0x1389
#Performance and stall fixes.


The Warriors

ALL
Text

--vu1-injection=1
--vu1-mpg-cycles=2300
--vu1-mpg-cycles=2600,-1
--vu1-clamp-range=0x028,0x060
--ee-hook=0x48c660,FastForwardClock,0x1620ffe3
--force-pal-60hz=1

?
LUA

-- Lua 5.3
-- Title: The Warriors (USA)    SLUS-21215 ( 1.04 NTSC )
--        The Warriors (Europe) SLES-53443 ( 1.01 PAL )
-- Features version: 1.00
-- Author: David Haywood
-- Date: November 15th 2015



require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])

apiRequest(0.7)	-- request version 0.7 API. Calling apiRequest() is mandatory.	-- request version 0.7 API. Calling apiRequest() is mandatory. (0.7 is needed for Widescreen switching)

-- obtain necessary objects.
local eeObj			= getEEObject()
local emuObj		= getEmuObject()
local trophyObj		= getTrophyObject()
local dmaObj		= getDmaObject()

-- load configuration if exist
local SaveData		= emuObj.LoadConfig(0)


local firstCall = 0


--[[

this is the 'setWideScreen' function of the gfx devices
from studying the code it seems that the content of 'a1' that
gets passed in determines if the requested mode is widescreen.

DevRWGraphicsDevice::setWideScreenMode(void)
00194E28   27BDFFD0 addiu       sp,sp,-0x30
00194E2C   7FB00010 sq          s0,0x0010(sp)
00194E30   E7B50028 swc1        f21,0x0028(sp)
00194E34   0080802D dmove       s0,a0
00194E38   FFBF0000 sd          ra,0x0000(sp)
00194E3C   E7B40020 swc1        f20,0x0020(sp)
00194E40   4480A800 mtc1        zero,f21
00194E44   C600044C lwc1        f0,0x044C(s0)
00194E48   46150032 c.eq.s      f0,f21
00194E4C   00000000 nop
00194E50   45010053 bc1t        0x00194FA0
00194E54   AE05045C sw          a1,0x045C(s0)
--]]

local WidesrceenFunction = function()	
	local a1 = eeObj.GetGPR(gpr.a1)
	
	a1 = a1 & 1
	
	-- force to widescreen on boot, ensures new profiles get created in widescreen mode by default etc.
	-- has some unwanted side-effects tho, so don't do it
	if firstCall == 1 then
		a1 = 1
		eeObj.SetGPR(gpr.a1, a1)
		firstCall = 0
	end
	
	
	
	if a1 == 1 then
		print( string.format("********* Request WIDE SCREEN mode **************" ) )
		emuObj.SetDisplayAspectWide()		
	else
		print( string.format("********* Request 4:3 mode **************" ) )
		emuObj.SetDisplayAspectNormal()	
	end
	
end




-- this hook address actually differs between Europe / US.
WidescreenHook = eeObj.AddHook(0x194e18,0x27BDFFD0,WidesrceenFunction)

#official widescreen patch for The Warrior's emulator. The typos are apparently deliberate.

Wild ARMS 3

ALL
Text

--gs-motion-factor=50
--ee-static-block-links=JAL,COP2
#graphical fixes.

SCUS_972.03
LUA

require("ee-gpr-alias")
apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

local emuObj		= getEmuObject()	
-- fix vision logo (Wild Arms 3)
local thresholdArea = 0 -- ignore alls items : fix #112276
emuObj.SetGsTitleFix( "ignoreUpRender", thresholdArea , {  texType = 3, cbp = 0x2390, tbp = 0x288000} )


-- fix bug #9072
-- this is caused by a wrong string, which we patch directly on the disc.
emuMediaPatch(0x438a, 12 + 0x174, { 0x6e5c2535 }, { 0x11202535 })

-- Bug#8907. accuracy-muldiv is too slow to use, so here added some value to get correct value.
local eeObj = getEEObject()
eeObj.AddHook(0x001ef6ec, 0x00000000, function()
				 eeObj.SetFpr(0, eeObj.GetFpr(0) + 0.00001)
end)
#Graphical glitches and stall fix.

Custom PS2emu Configuration Files

Here are configuration files created by users, to improve PS2 emulator compatibility on PS4

Ace Combat 4

All versions
Text

--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-use-mipmap=1
#Fix for terrain textures

Ace Combat 5

All versions
Text

--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-use-mipmap=1
#Same fix for terrain textures

SLUS_208.51
LUA

apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

-- Collision detection fix for Stage 3 onwards // Rearranging COP2 instructions that use old results

eeInsnReplace(0x1A3B94, 0x4B00682C, 0x48498800)
eeInsnReplace(0x1A3B98, 0x4B0C682C, 0x4B00682C)
eeInsnReplace(0x1A3BA4, 0x48498800, 0x484A8800)
eeInsnReplace(0x1A3BA8, 0x484A8800, 0x4B0C682C)

Ace Combat Zero: The Belkan War

All versions
Text

--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-use-mipmap=1
#Once again, same fix for terrain textures.

SLUS_213.46
LUA

apiRequest(0.1)	-- request version 0.1 API. Calling apiRequest() is mandatory.

-- Collision detection fix.

eeInsnReplace(0x131EBC, 0x4B00682C, 0x48498800)
eeInsnReplace(0x131EC0, 0x4B0C682C, 0x4B00682C)
eeInsnReplace(0x131ECC, 0x48498800, 0x484A8800)
eeInsnReplace(0x131ED0, 0x484A8800, 0x4B0C682C)

AirBlade

All versions
Text

--vu0-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-no-clamping=0
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1
#Fix for flickering models and textures

Ape Escape 2

All versions
Text

--gs-use-mipmap=1
--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
#Fix for flickering textures

Bloody Roar 4

All
Text

--vu0-no-clamping=0
--vu0-clamp-results=1
--vu1-no-clamping=0
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-results=1
#SPS Fix

Burnout2: POI

SLES_510.44 / SLES_529.68
LUA

apiRequest(0.1)    -- request version 0.1 API. Calling apiRequest() is mandatory.

-- SLES-51044 / SLES-52968 - Fix white parts
-- Major thanks to Maori-Jigglypuff for reversing that

eeInsnReplace(0x2485B8, 0xC6800D18, 0x3C014316)
eeInsnReplace(0x2485CC, 0xE4400000, 0xAC410000)
eeInsnReplace(0x262604, 0xC7809780, 0x3C014316)
eeInsnReplace(0x262618, 0xE4400000, 0xAC410000)
eeInsnReplace(0x2564B8, 0x8F829764, 0x24020000)

SLUS_204.97
LUA

apiRequest(0.1)    -- request version 0.1 API. Calling apiRequest() is mandatory.

-- SLUS_204.97 - Fix white parts
-- Major thanks to Maori-Jigglypuff for reversing that

eeInsnReplace(0x2485A8, 0xC6800D18, 0x3C014316)
eeInsnReplace(0x2485BC, 0xE4400000, 0xAC410000)
eeInsnReplace(0x2625F4, 0xC7809780, 0x3C014316)
eeInsnReplace(0x262608, 0xE4400000, 0xAC410000)
eeInsnReplace(0x2564A8, 0x8F829764, 0x24020000)

Cold Winter

All
Text

--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-clamp-operands=1
--vu1-clamp-results=1
# fix graphic and physics, there are still issue with fmv, and minor stering issue.

Dead or Alive 2: Hardcore

SLUS_200.71
Lua

apiRequest(0.1)

-- Fix hang, fix music, and sounds effects

emuMediaPatch(0x186A71, 12 + 0x7e4, { 0x2404002b }, { 0x27c40010 })
emuMediaPatch(0x186A71, 12 + 0x7e8, { 0x0c0032b3 }, { 0x0c0032b7 })
emuMediaPatch(0x186A71, 12 + 0x7ec, { 0x27c50010 }, { 0x00000000 })
emuMediaPatch(0x186A71, 12 + 0x5e8, { 0x27bdfff0 }, { 0x03e00008 })
emuMediaPatch(0x186A71, 12 + 0x5ec, { 0xafbe0008 }, { 0x00000000 })
emuMediaPatch(0x186A7B, 12 + 0x6fc, { 0x27bdfff0 }, { 0x03e00008 })
emuMediaPatch(0x186A7B, 12 + 0x700, { 0xafbe0008 }, { 0x00000000 })
emuMediaPatch(0x186A85, 12 + 0x164, { 0x27bdfff0 }, { 0x03e00008 })
emuMediaPatch(0x186A85, 12 + 0x168, { 0xafbe0008 }, { 0x00000000 })
emuMediaPatch(0x186A85, 12 + 0x10c, { 0x27bdfff0 }, { 0x03e00008 })
emuMediaPatch(0x186A85, 12 + 0x110, { 0xafbe0008 }, { 0x00000000 })
emuMediaPatch(0x186A85, 12 + 0x1bc, { 0x27bdfff0 }, { 0x03e00008 })
emuMediaPatch(0x186A85, 12 + 0x1c0, { 0xafbe0008 }, { 0x00000000 })
emuMediaPatch(0x186A86, 12 + 0x7f0, { 0x27bdfff0 }, { 0x03e00008 })
emuMediaPatch(0x186A86, 12 + 0x7f4, { 0xafbe0008 }, { 0x00000000 })
emuMediaPatch(0x186C38, 12 + 0x6ec, { 0x24060001 }, { 0x24060000 })

For the Japanese version (SLPS-25026) you can also use config files from PS3's PS2 emu with

--lopnor-config=1

in config.

Place config file named as "SLPS-25026_lopnor.cfgbin" in /patches/SLPS-25026/

Disgaea 2: Cursed Memories

SLUS-21397
Text

--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-use-mipmap=1
#Fix for lines in terrain textures and flickering textures

Dragon Ball Z: Budokai Tenkaichi 2

ALL
Text

--gs-use-clut-merge=1
--gs-kernel-cl="clutmerge"
--gs-kernel-cl-up="clutmerge2x2"
#Fix for missing life bars and other UI elements.

Dragon Ball Z: Budokai Tenkaichi 3

ALL
Text

--gs-use-clut-merge=1
--gs-kernel-cl="clutmerge"
--gs-kernel-cl-up="clutmerge2x2"
#Fix for missing life bars and other UI elements.

Dragon Quest VIII: Journey of the Cursed King

All
Text

--gs-kernel-cl-up="up2x2skipinterp"
--gs-optimize-30fps=1
#Fix lines in shadows

Frogger: Ancient Shadow

SLUS_210.98
Text

--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1 
#Fixes disappearing models during cutscenes and during gameplay

The Getaway

PAL
Text

--vu1-mpg-cycles=950

#fix lag during cutscenes

The Getaway: Black Monday

SCES-52758 ONLY!
cli.conf

--fpu-accurate-range=0x26B154,0x305140

#Fix for crash on Chapter 5 in the ambush.

#NOTE THIS WILL MAKE THE GAME SLOW, INFACT JUST USE IT TO COMPLETE THE CHAPTER FIVE AND THEN REMOVE IT.
#Fix By Vitt0xLar
#JAK V2 emulator used.

Ghost in the Shell: Stand Alone Complex

SLES_530.20
LUA

apiRequest(0.1) -- request version 0.1 API. Calling apiRequest() is mandatory.

eeInsnReplace(0x10BC88, 0x4BEC682C, 0x48468800)
eeInsnReplace(0x10BC8C, 0x4B8D617D, 0x4bec682c)
eeInsnReplace(0x10BC90, 0x4A6D617C, 0x4b8d617d)
eeInsnReplace(0x10BC98, 0x48468800, 0x4a6d617c)
eeInsnReplace(0x12B2CC, 0x4BEC682C, 0x48468800)
eeInsnReplace(0x12B2D0, 0x4B8D617D, 0x4bec682c)
eeInsnReplace(0x12B2D4, 0x4A6D617C, 0x4b8d617d)
eeInsnReplace(0x12B2DC, 0x48468800, 0x4a6d617c)
eeInsnReplace(0x12B5F4, 0x4BEC682C, 0x48468800)
eeInsnReplace(0x12B5F8, 0x4B8D617D, 0x4bec682c)
eeInsnReplace(0x12B5FC, 0x4A6D617C, 0x4b8d617d)
eeInsnReplace(0x12B604, 0x48468800, 0x4a6d617c)
eeInsnReplace(0x1B0B58, 0x4BEC682C, 0x48468800)
eeInsnReplace(0x1B0B5C, 0x4BED617D, 0x4bec682c)
eeInsnReplace(0x1B0B68, 0x48468800, 0x4b8d617d)
eeInsnReplace(0x1BF5FC, 0x4A0002FF, 0x48588800)
eeInsnReplace(0x1BF60C, 0x48588800, 0x4a0002ff)
eeInsnReplace(0x1BFBB8, 0x4A0002FF, 0x48588800)
eeInsnReplace(0x1BFBC8, 0x48588800, 0x4a0002ff)
eeInsnReplace(0x1BF818, 0x4A0002FF, 0x48588800)
eeInsnReplace(0x1BF828, 0x48588800, 0x4a0002ff)
eeInsnReplace(0x1C017C, 0x4A0002FF, 0x48588800)
eeInsnReplace(0x1C018C, 0x48588800, 0x4a0002ff)
-- Potential fix for broken interactive door // Rearranging COP2 ops so as to avoid macflag bad stuff

Killer7

All versions
Test

--vu0-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-no-clamping=0
--vu1-clamp-operands=1
--vu1-clamp-results=1
#fix for flickering polygons.

Kim Possible: What's the Switch

PAL
Text

--vu1-mpg-cycles=950

#fix lag during cutscenes

Klonoa 2

All versions
Text

--fpu-no-clamping=1
#Fix for misplaced objects, still require fix for texturing problems. Require Rogue Galaxy emu

Legacy of Kain: Soul Reaver 2

SLES_501.96
Lua

apiRequest(0.1)    -- request version 0.1 API. Calling apiRequest() is mandatory.

-- Turn off mipmapping in game engine. Completely fix flickering, and bad texturing. Don't require "gs-kernel-cl=mipmap"
-- SLES_501.96 only!

eeInsnReplace(0x2A1F80, 0x00000001, 0x00000000)

Metal Saga

All versions
Text

--vif1-ignore-cmd-ints=1

#Fix for black-screen on SatCom/Equip menus. Game still unplayable due to immediate freeze during combat.

Need for Speed Carbon

SLES_543.22
Text

--fpu-accurate-range=0x150000,0x170000
# Fix loading freeze, game still unplayable due to 1 fps in-game. 

NBA Street Vol.2

All versions
Text

--vu1-no-clamping=0
--vu1-clamp-operands=1
--vu1-clamp-results=1
--gs-adaptive-frameskip=1
# Fix for graphical corruptions, require "JAK" emu.

Oni

SLES_501.34 SLES_501.76 SLES_501.77 SLES_501.78 SLES_501.79
Lua

apiRequest(0.1)

-- Fix for hang at loading screen

eeInsnReplace(0x1CEF7C, 0x4100FFFF, 0x00000000)

SLUS_200.64
Lua

apiRequest(0.1)

-- Fix for hang at loading screen

eeInsnReplace(0x1CF3CC, 0x4100FFFF, 0x00000000)

Phantasy Star Universe

ALL
Text

--gs-use-clut-merge=1
--gs-kernel-cl="clutmerge"
--gs-kernel-cl-up="clutmerge2x2"
#Fix for flickering textures and geometry

R-Racing Revolution

SLUS_207.21
LUA

apiRequest(0.1)    -- request version 0.1 API. Calling apiRequest() is mandatory.

-- Divide $v0 value by 8 before copying it to CMSAR0
-- sra $v0, 3, this time we are losing one nop on cop2. Can be important.

eeInsnReplace(0x2DDB4C, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x2DDB50, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x2DDBC4, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x2DDBC8, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x313C30, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x313C34, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x3144FC, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x314500, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x314E04, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x314E08, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x31570C, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x315710, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x315FFC, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x316000, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x3168EC, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x3168F0, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x31724C, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x317250, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x317B74, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x317B78, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x318430, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x318434, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x318D54, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x318D58, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x319AA0, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x319AA4, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x31A8D4, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x31A8D8, 0x4A0002FF, 0x48C2D801)
eeInsnReplace(0x31B7A4, 0x48C2D801, 0x000210C3)
eeInsnReplace(0x31B7A8, 0x4A0002FF, 0x48C2D801)
-- fix graphical issues

Rygar: The Legendary Adventure

SLUS_204.71
Text

--fpu-accurate-range=0x147CC0,0x147EA0
#Fix for freeze after leaving the first area.

Samurai Shodown VI

ALL
Text

--gs-upscale=point
--gs-uprender=2x2
--gs-motion-factor=25
--host-audio-latency=0.01
--gs-ignore-dirty-page-border=1
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
--gs-h2l-list-opt=1
--gs-h2l-accurate-hash=1
#same as Anthology, which VI is a patched-out section of; substantial slowdown during combat has been mitigated.

SNK vs Capcom: SVC Chaos

ALL
Text

--gs-use-clut-merge=1
--gs-kernel-cl="clutmerge"
--gs-kernel-cl-up="clutmerge2x2"
#Fixes missing hud/UI elements.

SpongeBob SquarePants: Battle for Bikini Bottom

ALL
Text

--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1
#Fix for graphical issues

Street Fighter Alpha Anthology

ALL
Text

--gs-motion-factor=50
--host-audio-latency=0.01
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
--gs-h2l-list-opt=1
--gs-h2l-accurate-hash=1
#Fix for performance issues. PS4 Pro required for full speed.

Tales of Destiny: Directors Cut

SLPS-25842, SLPS-25841, SCKA-20119
Text

--fpu-accurate-range=0x1C0000,0x1D0000 
--gs-use-clut-merge=1 
--gs-kernel-cl="clutmerge"
--gs-kernel-cl-up="clutmerge2x2" 
# Fix control after exiting the menu, and graphic bugs. 0x1C0000,0x1D0000 range can be clamped is someone will find it slow.

Tales of The Abyss

SLUS_213.86
Text

--gs-uprender=none
--gs-upscale=none
#fix coruption lines caused by upscsaler, remember to remove 2x2 that already exist in config
--fpu-accurate-range=0x27FFFC,0x27FFFF
--fpu-accurate-range=0x2921F4,0x2921F8
#choral castle soft lock fix
--fpu-no-clamping=0
--vu0-no-clamping=0
--vu1-no-clamping=0
--cop2-no-clamping=0
--fpu-clamp-results=1
--vu0-clamp-results=1
--vu1-clamp-results=1
--cop2-clamp-results=1
#Seems to fix not renedering characters in cut scenes

Tony Hawk Pro Skater 3

All
Text

--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-results=1
--vu1-clamp-results=1
--fpu-no-clamping=0
--cop2-no-clamping=0
--fpu-clamp-results=1
--cop2-clamp-results=1
#SPS Fix

Valkyrie Profile 2: Silmeria

All versions
Text

--gs-progressive=1
--gs-uprender=2x2
--gs-upscale=Point
--vu-hack-triace=1
--gs-kernel-cl-up="up2x2simple"
#Looks like it fix all graphical issues excluding purple effect in Forest at start of game

Vampire: Darkstalkers Collection

ALL
Text

--gs-motion-factor=50
--host-audio-latency=0.01
--gs-kernel-cl="h2lpool"
--gs-kernel-cl-up="h2lpool2x2"
--gs-h2l-list-opt=1
--gs-h2l-accurate-hash=1
#Fix for performance issues. PS4 Pro required for full speed.

Whiplash

All versions
Text

--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-use-mipmap=1
#Fix for texture glitches

X-Files - Resist or Serve

NTSC/U
Text

--vu0-no-clamping=0
--vu0-clamp-results=1
--vu1-no-clamping=0
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-results=1

#fix for missing character models

*Jak Emu used*

Zatch Bell! Mamodo Battles™

NTSC/U
Text

--gs-kernel-cl="mipmap"
--gs-kernel-cl-up="mipmap2x2"
--gs-use-mipmap=1
--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-results=1
--vu1-clamp-results=1
--fpu-no-clamping=0
--cop2-no-clamping=0
--fpu-clamp-results=1
--cop2-clamp-results=1

#fix for graphical glitches

*Jak Emu used*

Fix for unplayable or major issue games

God Hand

Conf file

--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1
#fix for graphical glitches, specially the missing ground.

God Of War

Conf file

--vu-d-bit=1
--vu-t-bit=1
--vu1-opt-flags=2
--vu1-di-bits=1
--vu1-mpg-cycles=800
--vu1-injection=1
--vu1-opt-vf00=2
--vu1-jr-cache-policy=newprog
--vu1-jalr-cache-policy=newprog
--ee-block-validation=PageProt
--ee-hook=0x017A2DC,AdvanceClock
--gs-frontend-opt-mode=2
--fpu-rsqrt-fast-estimate=1
#fix for graphical glitches

*Jak Emu used*

LUA file

-- God Of War EU

-- 01 Music sound problem: music restarts every time there are many sounds to play
-- 02 Latest emu removes a lot of game lag, anyway the game still suffer of shuttering in the next levels
-- 03 Corrupted green lines around the objects, uprendering problem

apiRequest(2.2)	-- request version 0.1 API. Calling apiRequest() is mandatory.

local gpr    		= require("ee-gpr-alias")
local emuObj 		= getEmuObject()
local gsObj			= getGsObject()
local thresholdArea = 600

-- 02 Slowdowns and performances patched in cli.conf file

-- 03 --gs-uprender=none removes corrupted lines around the objects and
-- local thresholdArea = 600 improves the graphics

-- Disable internal field shift compensation, part of post-process removal feature.
gsObj.SetDeinterlaceShift(0)


God of War 2

Conf file

--vu1-jr-cache-policy=newprog
--vu1-jalr-cache-policy=newprog
--vu1-mpg-cycles=1000
--vu1-di-bits=1
--vu1-injection=1
--vu1-opt-flags=2
--ee-block-validation=PageProt
--ee-hook=0x186B64,AdvanceClock
--ee-hook=0x186CE4,AdvanceClock
--ee-cycle-scalar=0.8
--ee-kernel-hle=1
--ee-injection-kernel=1
--ee-injection-title=1
--fpu-accurate-muldiv-range=0x186B64,0x186CE4
--fpu-accurate-mul-fast=1
--fpu-rsqrt-fast-estimate=1
--framelimit-mode=normal
--gs-frontend-opt-mode=2
--gs-optimize-30fps=1
--cop2-di-bits=1
--safe-area-min=1.0
*Jak Emu used*

LUA File

-- God of War II EU

require( "ee-gpr-alias" ) -- you can access EE GPR by alias (gpr.a0 / gpr["a0"])

apiRequest(2.2)

local emuObj	= getEmuObject()
local gsObj 	= getGsObject()

local fastminEE	= 1600000		-- less than this it's safe to run > 30 fps

-- Disable internal field shift compensation, part of post-process removal feature.
gsObj.SetDeinterlaceShift(0)

-- Graphic improvement: removes corrupted lines on screen with uprender on for PAL version

emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", { texMode=1 } ) --texMode=1 ?
emuObj.SetGsTitleFix( "forceSimpleFetch", "reserved", { texMode=2 } ) --texMode=2 is BILINEAR

require("utils")
local eeObj = getEEObject()
local PrecompileAddrs = Queue.new(
   {
	0x100000,
	0x100004,
	0x100008,
	0x10000C,
	0x100010,
	0x100014,
	0x100018,
	0x10001C,
	0x100020,
	0x100024,
	0x100028,
	0x10002C,
	0x100030,
	0x100034,
	0x100038,
	0x10003C,
	0x100040,
	0x100044,
	0x100048,
	0x10004C,
	0x100050,
	0x100054,
	0x100058,
	0x10005C,
	0x100060,
	0x100064,
	0x100068,
	0x10006C,
	0x100070,
	0x100074,
	0x100078,
	0x10007C,
	0x100080,
	0x100084,
	0x100088,
	0x10008C,
	0x100090,
	0x100094,
	0x100098,
	0x10009C,
	0x1000A0,
	0x1000A4,
	0x1000A8,
	0x1000AC,
	0x1000B0,
	0x1000B4,
	0x1000B8,
	0x1000BC,
	0x1000C0,
	0x1000C4,
	0x1000C8,
	0x1000CC,
	0x1000D0,
	0x1000D4,
	0x1000D8,
	0x1000DC,
	0x1000E0,
	0x1000E4,
	0x1000E8,
	0x1000EC,
	0x1000F0,
	0x1000F4,
	0x1000F8,
	0x1000FC,
	0x100100,
	0x100104,
	0x100108,
	0x10010C,
	0x100110,
	0x100114,
	0x100118,
	0x10011C,
	0x100120,
	0x100124,
	0x100128,
	0x10012C,
	0x100130,
	0x100134,
	0x100138,
	0x10013C,
	0x100140,
	0x100144,
	0x100148,
	0x10014C,
	0x100150,
	0x100154,
	0x100158,
	0x10015C,
	0x100160,
	0x100164,
	0x100168,
	0x10016C,
	0x100170,
	0x100174,
	0x100178,
	0x10017C,
	0x100180,
	0x100184,
	0x100188,
	0x10018C,
	0x100190,
	0x100194,
	0x100198,
	0x10019C,
	0x1001A0,
	0x1001A4,
	0x1001A8,
	0x1001AC,
	0x1001B0, -- ei
	0x1001B4,
	0x1001BC,
	0x1001C0,
	0x1001C4,
	0x1001C8,
	0x1001CC,
	0x1001D0,
	0x1001D4,
	0x1001D8,
	0x1001DC,
	0x1001E0,
	0x1001E4,
	0x1001E8,
	0x1001EC,
	0x1001F0,
	0x1001F4,
	0x1001F8,
	0x1001FC,
	0x100200,
	0x100204,
	0x100208,
	0x10020C,
	0x100210,
	0x100214,
	0x100218,
	0x10021C,
	0x100220,
	0x100224,
	0x100228,
	0x10022C,
	0x100230,
	0x100234,
	0x100238,
	0x10023C,
	0x100240,
	0x100244,
	0x100248,
	0x10024C,
	0x100250,
	0x100254,
	0x100258,
	0x10025C,
	0x100260,
	0x100264,
	0x100268,
	0x10026C,
	0x100270,
	0x100274,
	0x100278,
	0x10027C,
	0x100280,
	0x100284,
	0x100288,
	0x10028C,
	0x100290,
	0x100294,
	0x100298,
	0x10029C,
	0x1002A0,
	0x1002A4,
	0x1002A8,
	0x1002AC,
	0x1002B0,
	0x1002B4,
	0x1002B8,
	0x1002BC,
	0x1002C0,
	0x1002C4,
	0x1002C8,
	0x1002CC,
	0x1002D0,
	0x1002D4,
	0x1002D8,
	0x1002DC,
	0x1002E0,
	0x1002E4,
	0x1002E8,
	0x1002EC,
	0x1002F0,
	0x1002F4,
	0x1002F8,
	0x1002FC,
	0x186B30,
	0x186B34,
	0x186B38,
	0x186B3C,
	0x186B44,
	0x186B48,
	0x186B4C,
	0x186B50,
	0x186B54,
	0x186B58,
	0x186B5C,
	0x186B60,
	0x186B64,
	0x186B68,
	0x186B6C,
	0x186B70,
	0x186B74,
	0x186B78,
	0x186B7C,
	0x186B80,
	0x186B84,
	0x186B84,
	0x186B88,
	0x186B8C,
	0x186B90,
	0x186B94,
	0x186B98,
	0x186B9C,
	0x186BA0,
	0x186BA4,
	0x186BA8,
	0x186BAC,
	%0x186BB0,
	0x186BB4,
	0x186BB8,
	0x186BBC,
	0x186BC0,
	0x186BC4,
	0x186BC8,
	0x186BCC,
	0x186BD0,
	0x186BD4,
	0x186BD8,
	0x186BDC,
	0x186BE0,
	0x186BE4,
	0x186BE8,
	0x186BEC,
	0x186BF0,
	0x186BF4,
	0x186BF8,
	0x186BFC
})
# Fixed 90% of glitches, still has lag issues

Max Payne 2

Conf file

--vu0-no-clamping=0
--vu1-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1
# Fixed green, blue and red graphical issues. The game works better.

Psi-Ops: The Mindgate Conspiracy

Conf file

--ee-kernel-hle=1
--ee-injection-kernel=1
--ee-injection-title=1
--ee-cycle-scalar=1.9
--safe-area-min=1.0
--vu0-no-clamping=0
--vu0-clamp-operands=1
--vu0-clamp-results=1
--vu1-no-clamping=0
--vu1-clamp-operands=1
--vu1-clamp-results=1
--cop2-no-clamping=0
--cop2-clamp-operands=1
--cop2-clamp-results=1
# Fixed low framrate issue, !!!JAK EMULATOR Used!!!.