Advertisement
Guest User

Fallout shader patch to allow more than 3 lights

a guest
Sep 17th, 2020
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. // C# code, shaderText should be a string of the disassembled shader contents (from "psa.exe shaderFile.pso /Fc")
  2. // Ugly code but seems to work on every shader I tried with.
  3. private string UpdateShader(string shaderText)
  4. {
  5.     var list = shaderText.Split(new[] { "\r\n" }, StringSplitOptions.None);
  6.     var start = "";
  7.     var perLight = "";
  8.     var endLight = "";
  9.     var end = "";
  10.     bool inShaders = false;
  11.     bool endL = false;
  12.     foreach (var line in list)
  13.     {
  14.         if (!inShaders && !endL)
  15.         {
  16.             if (line.EndsWith(", c20"))
  17.             {
  18.                 inShaders = true;
  19.                 start += "\r\n";
  20.             }
  21.         }
  22.  
  23.         if (inShaders)
  24.         {
  25.             if (!endL)
  26.                 if (line.EndsWith(", c21"))
  27.                     endL = true;
  28.  
  29.             if (endL)
  30.             {
  31.                 endLight += line + "\r\n";
  32.                 if (line.Contains(", c6,"))
  33.                 {
  34.                     endLight += "\r\n";
  35.                     inShaders = false;
  36.                 }
  37.             }
  38.             else
  39.                 perLight += line + "\r\n";
  40.         }
  41.         else
  42.         {
  43.             if (!endL)
  44.                 start += line + "\r\n";
  45.             else
  46.                 end += line + "\r\n";
  47.         }
  48.     }
  49.  
  50.     endLight = endLight.Replace(", c21", ", c28").Replace(", c6,", ", c13,");
  51.  
  52.     var text = perLight;
  53.  
  54.     for (int i = 2; i < 9; i++)
  55.     {
  56.         var posRegI = 19 + i;
  57.         var posReg = $", c{posRegI}";
  58.  
  59.         var colRegI = 4 + i;
  60.         var colReg = $", c{colRegI}";
  61.  
  62.         var thisTxt = perLight.Replace(", c20", posReg);
  63.         thisTxt = thisTxt.Replace(", c5", colReg);
  64.  
  65.         thisTxt = $"\r\n// Light {i}\r\n{thisTxt}";
  66.         text = text + thisTxt;
  67.     }
  68.  
  69.     return start + "// Light 1\r\n" + text + "\r\n// Light 9\r\n" + endLight + end;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement