-- script.lua -- CastlevaniaLoS autofix script x = "" pos = nil pos1 = nil defpos = nil lastdefpos = nil dclpos = nil lastdclpos = nil c7pos = nil lastc7pos = nil rpos = nil xpos = nil sr = "" sx = "" sy = "" sz = "" svx = "" svy = "" svz = "" sw = "" zdepth="" sxv="" syv="" PrecomputedFog = nil isDone = false doSearch = true AddNextStr = true IsFirst = true Unfix = false ScreenToLS = nil SceneColorTexture = nil TexCorPos = nil TexCorPos2 = nil SamplerName = "" MulEnd = nil rposEnd = nil; LightAttenuationTexture = nil textcordpos = nil textcordreg = "" FixSceneColorTexture = true FixShadowsHalo = true UniformPixelVector = nil MinZ_MaxZRatio = nil ShadowTexture = nil VPreg = "" VPPos = nil LstIdx = 0; LightMapTextures = nil UniformPixelScalars = nil ScreenPositionScaleBias = nil DepthRT = nil matViewProjectionInv = nil ShadowMapMatSplit= nil rtemp = "" DepthMapSampler=nil vin = "" SceneBlurSampler = nil ReflectionSampler = nil IceEnvSampler = nil -- search for constants names it helps to determinate shader for i = 1, #SText do if DepthRT == nil then DepthRT = string.find(SText[i], "Depth_RT") end if matViewProjectionInv == nil then matViewProjectionInv = string.find(SText[i], "matViewProjectionInv") end if SceneBlurSampler == nil then SceneBlurSampler = string.find(SText[i], "SceneBlurSampler") end if ShadowMapMatSplit == nil then ShadowMapMatSplit = string.find(SText[i], "ShadowMap_MatSplit") end if DepthMapSampler == nil then DepthMapSampler = string.find(SText[i], "DepthMapSampler") end if ReflectionSampler == nil then ReflectionSampler = string.find(SText[i], "Reflection_Sampler", 1, true) end if IceEnvSampler == nil then IceEnvSampler = string.find(SText[i], "IceEnv_Sampler", 1, true) end if string.find(SText[i], "ps_3_0") ~= nil then break end end if isDone == false then if ((DepthRT ~= nil) or ((DepthMapSampler ~= nil) or ((IceEnvSampler ~= nil) and (ReflectionSampler ~= nil)))) and (SceneBlurSampler == nil) then zdepth ="" for i = 1, #SText do AddNextStr = true if (TexCorPos == nil) and (DepthRT ~= nil) then TexCorPos = string.find(SText[i], "dcl_texcoord2 v0.xyw") end if (TexCorPos2 == nil) and ((DepthMapSampler ~= nil) or ((IceEnvSampler ~= nil) and (ReflectionSampler ~= nil))) then vin = "" TexCorPos2 = string.find(SText[i], "dcl_texcoord1 v0") if (TexCorPos2 == nil) then TexCorPos2 = string.find(SText[i], "dcl_texcoord1 v1") if (TexCorPos2 ~= nil) then vin = "v1" end else vin = "v0" end if (TexCorPos2 == nil) then TexCorPos2 = string.find(SText[i], "dcl_texcoord1 v2") if (TexCorPos2 ~= nil) then vin = "v2" end end if (TexCorPos2 ~= nil) then rpos = string.find(SText[i], "." ,1, true) if(rpos ~= nil) then if(string.find(SText[i], "xyw" ,rpos, true) == nil) then TexCorPos2 = nil end end end end lastdefpos = string.find(SText[i], "def") if lastdefpos ~= nil then defpos = i + 1 end if (lastdefpos == nil) and (defpos ~= nil) then if i == defpos then x = x .. " def c200, 0.0, 0.5, 0.0625, 0 " .. string.char(10) x = x .. " def c201, 0, 0, 1.0, 0.5 " .. string.char(10) end lastdclpos = string.find(SText[i], "dcl_2") if lastdclpos == nil then lastdclpos = string.find(SText[i], "dcl_cube") end if lastdclpos ~= nil then dclpos = i + 1 end if (lastdclpos == nil) and (dclpos ~= nil) then if i == dclpos then x = x .. " dcl_2d s13" .. string.char(10) x = x .. " dcl vPos.xy" .. string.char(10) end end end if TexCorPos ~= nil then --mul r0.xy, r0.x, v0 rpos = string.find(SText[i], "v0") if rpos ~= nil then rpos, rposEnd = string.find(SText[i], "mul ") if rpos ~= nil then rpos = string.find(SText[i], "." ,rposEnd, true) sr = string.sub(SText[i], rposEnd, rpos - 1) sx = string.sub(SText[i], rpos + 1, rpos + 1) sy = string.sub(SText[i], rpos + 2, rpos + 2) x = x .. SText[i] .. string.char(10) x = x .. " texldl r21, c200.z, s13" .. string.char(10) x = x .. " if_ne r21.x, c200.x" .. string.char(10) x = x .. " mov r19.xy, vPos.xy" .. string.char(10) x = x .. " add r19.x, r19.x, -c201.w" .. string.char(10) x = x .. " mov r22.x, c210.x" .. string.char(10) x = x .. " mul r22.x, r22.x, c201.w" .. string.char(10) x = x .. " rcp r20.x, r22.x" .. string.char(10) x = x .. " mad " .. sr .."." .. sx .. ", r19.x, r20.x, -c201.z" .. string.char(10) x = x .. " add r19.y, r19.y, -c201.w" .. string.char(10) x = x .. " mov r22.x, c210.y" .. string.char(10) x = x .. " mul r22.x, r22.x, c201.w" .. string.char(10) x = x .. " rcp r20.y, r22.x" .. string.char(10) x = x .. " mul r19.y, r19.y, r20.y" .. string.char(10) x = x .. " add " .. sr .."." .. sy .. ", c201.z, -r19.y" .. string.char(10) x = x .. " endif" .. string.char(10) isDone = true AddNextStr = false end end end if (TexCorPos2 ~= nil) and (vin ~= "") then --mul r0.xy, r0.x, v0 rpos, rposEnd = string.find(SText[i], vin) if (rposEnd ~= nil) then c7pos = rposEnd if not((string.len(SText[i]) < rposEnd + 1) or ((string.byte(SText[i], rposEnd + 1) == 46) and (string.len(SText[i]) >= rposEnd + 3))) then rpos = nil c7pos = nil end end if rpos ~= nil then rpos, rposEnd = string.find(SText[i], "mul ") if (rpos ~= nil) and (IceEnvSampler ~= nil) and (ReflectionSampler ~= nil) then rpos = string.find(SText[i - 1], "rcp ") end if rpos ~= nil then rpos = string.find(SText[i], "." ,rposEnd, true) sr = string.sub(SText[i], rposEnd, rpos - 1) sx = string.sub(SText[i], rpos + 1, rpos + 1) sy = string.sub(SText[i], rpos + 2, rpos + 2) sz = string.sub(SText[i], rpos + 3, rpos + 3) if(c7pos ~= nil) and (IceEnvSampler ~= nil) and (ReflectionSampler ~= nil) then c7pos = string.find(SText[i], "." , c7pos, true) if(c7pos ~= nil) then svx = string.sub(SText[i], c7pos + 1, c7pos + 1) svy = string.sub(SText[i], c7pos + 2, c7pos + 2) svz = string.sub(SText[i], c7pos + 3, c7pos + 3) if(svy == "x") then sx = sy sy = sz end end end x = x .. SText[i] .. string.char(10) x = x .. " texldl r21, c200.z, s13" .. string.char(10) x = x .. " if_ne r21.x, c200.x" .. string.char(10) x = x .. " mov r19.xy, vPos.xy" .. string.char(10) x = x .. " add r19.x, r19.x, -c201.w" .. string.char(10) x = x .. " mov r22.x, c210.x" .. string.char(10) x = x .. " mul r22.x, r22.x, c201.w" .. string.char(10) x = x .. " rcp r20.x, r22.x" .. string.char(10) x = x .. " mad " .. sr .."." .. sx .. ", r19.x, r20.x, -c201.z" .. string.char(10) x = x .. " add r19.y, r19.y, -c201.w" .. string.char(10) x = x .. " mov r22.x, c210.y" .. string.char(10) x = x .. " mul r22.x, r22.x, c201.w" .. string.char(10) x = x .. " rcp r20.y, r22.x" .. string.char(10) x = x .. " mul r19.y, r19.y, r20.y" .. string.char(10) x = x .. " add " .. sr .."." .. sy .. ", c201.z, -r19.y" .. string.char(10) x = x .. " endif" .. string.char(10) isDone = true AddNextStr = false end end end if (matViewProjectionInv ~= nil) and (doSearch) and (DepthMapSampler == nil) then if(ShadowMapMatSplit ~= nil) then rpos, rposEnd = string.find(SText[i], "c14,", 1, true) else rpos, rposEnd = string.find(SText[i], "c2,", 1, true) end if (rpos ~= nil) and (zdepth == "") then rpos = string.find(SText[i], "mad ", 1, true) if (rpos ~= nil) then rpos = string.find(SText[i], "," , 1, true) rposEnd = string.find(SText[i], "," , rpos + 2, true) zdepth = string.sub(SText[i], rpos + 1, rposEnd - 1) end end if(ShadowMapMatSplit ~= nil) then rpos, rposEnd = string.find(SText[i], "c12,", 1, true) else rpos, rposEnd = string.find(SText[i], "c0,", 1, true) end if (rpos ~= nil) and (sxv == "") then rpos = string.find(SText[i], "mad ", 1, true) if (rpos ~= nil) then rpos = string.find(SText[i], "," , 1, true) rposEnd = string.find(SText[i], "," , rpos + 2, true) sxv = string.sub(SText[i], rpos + 1, rposEnd - 1) x = x .. " mov r16.x, " .. sxv .. string.char(10) x = x .. SText[i] .. string.char(10) AddNextStr = false end end if(ShadowMapMatSplit ~= nil) then rpos, rposEnd = string.find(SText[i], "c13", 1, true) else rpos, rposEnd = string.find(SText[i], "c1", 1, true) end if (rposEnd ~= nil) then if not((string.len(SText[i]) < rposEnd + 1) or (string.byte(SText[i], rposEnd + 1) == 32) or (string.byte(SText[i], rposEnd + 1) == 9) or (string.byte(SText[i], rposEnd + 1) == 10) or (string.byte(SText[i], rposEnd + 1) == 44)) then rpos = nil end end if (rpos ~= nil) and (syv == "") then rpos = string.find(SText[i], "mul ", 1, true) if (rpos ~= nil) then if (string.byte(SText[i], rposEnd + 1) == 44) then rpos = rposEnd + 1 rposEnd = string.len(SText[i]) + 1 else rpos = string.find(SText[i], "," , 1, true) rposEnd = string.find(SText[i], "," , rpos + 2, true) end syv = string.sub(SText[i], rpos + 1, rposEnd - 1) x = x .. " mov r16.y, " .. syv .. string.char(10) x = x .. SText[i] .. string.char(10) AddNextStr = false end end if(ShadowMapMatSplit ~= nil) then rpos, rposEnd = string.find(SText[i], "c15", 1, true) else rpos, rposEnd = string.find(SText[i], "c3", 1, true) end if (rposEnd ~= nil) then if not((string.len(SText[i]) < rposEnd + 1) or (string.byte(SText[i], rposEnd + 1) == 32) or (string.byte(SText[i], rposEnd + 1) == 9) or (string.byte(SText[i], rposEnd + 1) == 10) or (string.byte(SText[i], rposEnd + 1) == 44)) then rpos = nil end end if (rpos ~= nil) then rpos, rposEnd = string.find(SText[i], "add ", 1, true) if (rpos ~= nil) then rpos = string.find(SText[i], "," , rposEnd, true) rtemp = string.sub(SText[i], rposEnd + 1, rpos - 1) x = x .. SText[i] .. string.char(10) x = x .. " texldl r21, c200.z, s13" .. string.char(10) x = x .. " if_ne r21.x, c200.x" .. string.char(10) x = x .. " rcp r20.w, " .. rtemp .. ".w" .. string.char(10) x = x .. " mul r22.xyz, r20.w," .. rtemp .. string.char(10) x = x .. " mul r20, r22.y, c171" .. string.char(10) x = x .. " mad r20, r22.x, c170, r20" .. string.char(10) x = x .. " mad r20, r22.z, c172, r20" .. string.char(10) x = x .. " add r20, r20, c173" .. string.char(10) x = x .. " mov r20.x, r16.x" .. string.char(10) x = x .. " add r21.y, r20.w, -r21.y" .. string.char(10) x = x .. " mul r21.x, r21.x, r21.y" .. string.char(10) x = x .. " rcp r20.w, r20.w" .. string.char(10) x = x .. " mul r21.x, r21.x, r20.w" .. string.char(10) x = x .. " add r20.x, r20.x, -r21.x" .. string.char(10) if(ShadowMapMatSplit ~= nil) then x = x .. " mul r22, r16.y, c13" .. string.char(10) x = x .. " mad r22, r20.x, c12, r22" .. string.char(10) if(zdepth ~= "") then x = x .. " mad r22, ".. zdepth ..", c14, r22" .. string.char(10) end x = x .. " add " .. rtemp ..", r22, c15" .. string.char(10) else x = x .. " mul r22, r16.y, c1" .. string.char(10) x = x .. " mad r22, r20.x, c0, r22" .. string.char(10) if(zdepth ~= "") then x = x .. " mad r22, ".. zdepth ..", c2, r22" .. string.char(10) end x = x .. " add " .. rtemp ..", r22, c3" .. string.char(10) end x = x .. " endif" .. string.char(10) isDone = true AddNextStr = false doSearch = false end end end if AddNextStr then x = x .. SText[i] .. string.char(10) end end if (isDone) and (ShadowMapMatSplit == nil) then x = x .. string.char(10) .. "//usepres" end end end if isDone then return x else return "" end;