-- script.lua -- Receives a table, returns the sum of its components. -- io.write("The table the script received has:\n"); x = "" pos = nil pos1 = nil defpos = nil lastdefpos = nil dclpos = nil lastdclpos = nil c7pos = nil lastc7pos = nil rpos = nil xpos = nil sr = "" sx = "" sw = "" isDone = false doSearch = true AddNextStr = true IsFirst = true ScreenToLS = nil SceneColorTexture = nil SamplerPos = 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 Texture2D_2 = nil regcnt = 0 NvStereoFixTexture = nil PixelTexture2D_0 = nil PixelTexture2D_1 = nil PixelTexture2D_2 = nil PixelTexture2D_3 = nil -- search for constants names it helps to determinate shader for i = 1, #SText do if pos == nil then pos = string.find(SText[i], "bReceiveDynamicShadows") end if pos1 == nil then pos1 = string.find(SText[i], "ViewProjectionMatrix") LstIdx = i + 1 end if LightAttenuationTexture == nil then LightAttenuationTexture = string.find(SText[i], "LightAttenuationTexture") end if LightMapTextures == nil then LightMapTextures = string.find(SText[i], "LightMapTextures") if LightMapTextures ~= nil then LightMapTextures = i end end if UniformPixelScalars == nil then UniformPixelScalars = string.find(SText[i], "UniformPixelScalars") end if ScreenPositionScaleBias == nil then ScreenPositionScaleBias = string.find(SText[i], "ScreenPositionScaleBias") end if Texture2D_2 == nil then Texture2D_2 = string.find(SText[i], "Texture2D_") end if SceneColorTexture == nil then SceneColorTexture = string.find(SText[i], "SceneColorTexture") if SceneColorTexture ~= nil then SceneColorTexture = i end end if ScreenToLS == nil then ScreenToLS = string.find(SText[i], "ScreenToLight") end if ShadowTexture == nil then ShadowTexture = string.find(SText[i], "ShadowTexture") end if ScreenToLS == nil then ScreenToLS = string.find(SText[i], "ScreenToShadowMatrix") end if UniformPixelVector == nil then UniformPixelVector = string.find(SText[i], "UniformPixelVector") end if MinZ_MaxZRatio == nil then MinZ_MaxZRatio = string.find(SText[i], "MinZ_MaxZRatio") end if NvStereoFixTexture == nil then NvStereoFixTexture = string.find(SText[i], "NvStereoFixTexture") end if PixelTexture2D_0 == nil then PixelTexture2D_0 = string.find(SText[i], "PixelTexture2D_0") end if PixelTexture2D_1 == nil then PixelTexture2D_1 = string.find(SText[i], "PixelTexture2D_1") end if PixelTexture2D_2 == nil then PixelTexture2D_2 = string.find(SText[i], "PixelTexture2D_2") if PixelTexture2D_2 ~= nil then PixelTexture2D_2 = i end end if PixelTexture2D_3 == nil then PixelTexture2D_3 = string.find(SText[i], "PixelTexture2D_3") end --x = x .. SText[i] .. string.char(13) if string.find(SText[i], "ps_3_0") ~= nil then break end end if isDone == false then -- it's probably dynamic shadows/lights -- will try to inject out fixing code after retriving value from W buffer if (SceneColorTexture ~= nil) and (ScreenToLS ~= nil) then for i = SceneColorTexture + 1, #SText do AddNextStr = true if doSearch then if SamplerPos == nil then SamplerPos = string.find(SText[i], "SceneColorTexture") end if SamplerPos ~= nil then if SamplerName == "" then SamplerPos = string.find(SText[i], "s", SamplerPos + 16) SamplerName = string.sub(SText[i], SamplerPos, SamplerPos + 1) end if SamplerName ~= "" then 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) 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 s14" .. string.char(10) end if c7pos == nil then c7pos = string.find(SText[i], SamplerName) if c7pos ~= nil then c7pos = string.find(SText[i], "texld") if c7pos ~= nil then if MinZ_MaxZRatio ~= nil then c7pos = i + 6 else c7pos = i + 6 end end end end if c7pos == i then rpos, MulEnd = string.find(SText[c7pos], "mul ") if rpos == nil then rpos, MulEnd = string.find(SText[c7pos], "mul_pp ") end if rpos ~= nil then --rpos = rpos + 4 xpos = string.find(SText[c7pos], ".", MulEnd, true) sr = string.sub(SText[c7pos], MulEnd, xpos - 1) sx = string.sub(SText[c7pos], xpos + 1, xpos + 1) xpos, rposEnd = string.find(SText[c7pos], sr, xpos + 1) sw = string.sub(SText[c7pos], rposEnd + 2, rposEnd + 2) x = x .. SText[i] .. string.char(10) x = x .. " texldl r11, c200.z, s14" .. string.char(10) x = x .. " add r11.y, " .. sr .. "." .. sw .. ", -r11.y" .. string.char(10) x = x .. " mul r11.x, r11.x, r11.y" .. string.char(10) x = x .. " add " .. sr .. "." .. sx .. ", " .. sr .. "." .. sx .. ", -r11.x" .. string.char(10) doSearch = false isDone = true AddNextStr = false end end end end end end if FixSceneColorTexture then if textcordreg ~= "" then rpos, rposEnd = string.find(SText[i], textcordreg) if rpos ~= nil then if regcnt < 3 then rpos = nil end regcnt = regcnt + 1 end if rpos ~= nil then if IsFirst then x = x .. " mov r16.xyw, " .. textcordreg .. string.char(10) x = x .. " texldl r11, c200.z, s14" .. string.char(10) x = x .. " add r11.y, r16.w, -r11.y" .. string.char(10) x = x .. " mul r11.x, r11.x, r11.y" .. string.char(10) x = x .. " add r16.x, r16.x, r11.x" .. string.char(10) end IsFirst = false; str = string.sub(SText[i], 1, rpos - 1) str = str .. "r16" .. string.sub(SText[i], rposEnd + 1) isDone = true SText[i] = str end end if textcordpos == nil then textcordpos, rposEnd = string.find(SText[i], "dcl_texcoord v") if textcordpos ~= nil then textcordpos = string.find(SText[i], "." ,rposEnd - 1, true) if textcordpos ~= nil then textcordreg = string.sub(SText[i], rposEnd - 1, textcordpos - 1) else x = "" break end end end end end if AddNextStr then x = x .. SText[i] .. string.char(10) end end end end -- not used in remember me , yet ? if false then -- fog if (SceneColorTexture ~= nil) and NvStereoFixTexture and PixelTexture2D_0 and PixelTexture2D_1 and PixelTexture2D_2 and MinZ_MaxZRatio then for i = PixelTexture2D_2 + 1, #SText do AddNextStr = true if doSearch then if SamplerPos == nil then SamplerPos = string.find(SText[i], "PixelTexture2D_0") end if SamplerPos ~= nil then if SamplerName == "" then SamplerPos = string.find(SText[i], "s", SamplerPos + 16) SamplerName = string.sub(SText[i], SamplerPos, SamplerPos + 1) end if SamplerName ~= "" then c7pos = string.find(SText[i], SamplerName) if (c7pos ~= nil) and (i > 7) then rpos, rposEnd = string.find(SText[i - 6], "cmp ") if rpos ~= nil then AddNextStr = false doSearch = false isDone = true xpos, MulEnd = string.find(SText[i - 6], ",", rposEnd, true) sr = string.sub(SText[i - 6], rposEnd, xpos - 1) xpos, MulEnd = string.find(SText[i - 6], ",", MulEnd + 1, true) xpos = string.find(SText[i - 6], ",", MulEnd + 1, true) sx = string.sub(SText[i - 6], MulEnd + 1, xpos - 1) SText[i - 6] = " mov " .. sr .. ", " .. sx .. string.char(10) break end end end end end end if isDone then for i = PixelTexture2D_2 + 1, #SText do x = x .. SText[i] .. string.char(10) end end end end -- not used in remember me , yet ? if false then -- water reflections if (LightMapTextures and NvStereoFixTexture and PixelTexture2D_0 and PixelTexture2D_1 and PixelTexture2D_2 and PixelTexture2D_3 and MinZ_MaxZRatio) then --isDone = true for i = 1, #SText do AddNextStr = true if doSearch then if textcordreg ~= "" then --isDone = true rpos, rposEnd = string.find(SText[i], textcordreg) if rpos ~= nil then rpos, rposEnd = string.find(SText[i], "cmp ") if rpos ~= nil then rpos, rposEnd = string.find(SText[i - 5], "mad ") if rpos ~= nil then xpos, MulEnd = string.find(SText[i - 5], ",", rposEnd, true) xpos, rposEnd = string.find(SText[i - 5], ".", MulEnd + 1, true) sx = string.sub(SText[i - 5], 1, xpos - 1) .. '_abs.' xpos, MulEnd = string.find(SText[i - 5], ".", rposEnd + 1, true) sx = sx .. string.sub(SText[i - 5], rposEnd + 1, xpos - 1) .. '_abs.' .. string.sub(SText[i - 5], MulEnd + 1, string.len(SText[i - 5])) .. string.char(10) SText[i - 5] = sx --doSearch = false isDone = true --break end end end end if textcordpos == nil then textcordpos, rposEnd = string.find(SText[i], "dcl_texcoord5 v") if textcordpos ~= nil then textcordpos = string.find(SText[i], "." ,rposEnd - 1, true) if textcordpos ~= nil then textcordreg = string.sub(SText[i], rposEnd - 1, textcordpos - 1) else x = "" break end end end end end if isDone then for i = 1, #SText do x = x .. SText[i] .. string.char(10) end end end end if isDone then return x else return "" end;