Advertisement
EESweetieBot

.CRS to .XML Mod Parser

Mar 18th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.60 KB | None | 0 0
  1. // Just put this code somewhere else, call "cod()" and it's all automatically parsed.
  2. // INPUT: Convert the .crs into .txt and overwrite the code.
  3. // OUTPUT: output_mods.xml
  4.         public static void cod()
  5.         {
  6.             File.WriteAllText(@"output_mods.xml",string.Empty);
  7.             List<string> itgmods = new List<string>() {"<ActorFrame><children>","<Layer","Type=\"Quad\"","InitCommand=\"hidden,1\"","OnCommand=\"%function(self)","mods={"};
  8.             List<string> xmlmods = new List<string>();
  9.             // Insert file name here.                  v
  10.             using(StreamReader sr = new StreamReader(@"INSERTNAME.txt")) {
  11.                 string line;
  12.                 while ((line=sr.ReadLine()) != null) {
  13.                     string s = "", e = "", eol = "";
  14.                     string[] m = {};
  15.                     if (line.Length >= 6 && line.Substring(0,6) == "#MODS:") {
  16.                         line = line.Remove(0,6);
  17.                         if (line.Substring(0,5) == "TIME=") {
  18.                             string fuck = "";
  19.                             string ery = line.Substring(5);
  20.                             List<string> shit = new List<string>() {"1","2","3","4","5","6","7","8","9","0","."};
  21.                             bool isnum = true;
  22.                             int curr = 0;
  23.                             while(isnum) {
  24.                                 if(shit.Any(x => x == ery[curr].ToString())) {
  25.                                     fuck = fuck + ery[curr];
  26.                                     curr = curr + 1;
  27.                                 } else {
  28.                                     s = fuck;
  29.                                     break;
  30.                                 }
  31.                             }
  32.                         }
  33.                         line = line.Remove(0,6+s.Length);
  34.                         if (line.Substring(0,4) == "END=") {
  35.                             eol = "end";
  36.                             string fuck = "";
  37.                             string ery = line.Substring(4);
  38.                             List<string> shit = new List<string>() {"1","2","3","4","5","6","7","8","9","0","."};
  39.                             bool isnum = true;
  40.                             int curr = 0;
  41.                             while(isnum) {
  42.                                 if(shit.Any(x => x == ery[curr].ToString())) {
  43.                                     fuck = fuck + ery[curr];
  44.                                     curr = curr + 1;
  45.                                 } else {
  46.                                     e = fuck;
  47.                                     break;
  48.                                 }
  49.                             }
  50.                         } else if (line.Substring(0,4) == "LEN=") {;
  51.                             eol = "len";
  52.                             string fuck = "";
  53.                             string ery = line.Substring(5);
  54.                             List<string> shit = new List<string>() {"1","2","3","4","5","6","7","8","9","0","."};
  55.                             bool isnum = true;
  56.                             int curr = 0;
  57.                             // Using the same shit as the TIME
  58.                             while(isnum) {
  59.                                 // If letter is num
  60.                                 if(shit.Any(x => x == ery[curr].ToString())) {
  61.                                     fuck = fuck + ery[curr];
  62.                                     curr = curr + 1;
  63.                                 } else {
  64.                                     e = fuck;
  65.                                     break;
  66.                                 }
  67.                             }
  68.                         }
  69.                         line = line.Remove(0,4+e.Length);
  70.                         if (e.Substring(0,1) == ".") {
  71.                             line = line.Remove(0,7);
  72.                         } else {
  73.                             line = line.Remove(0,6);
  74.                         }
  75.                         line = line.Substring(0,line.Length-1);
  76.                         m = line.Split(',');
  77.                         if (s+e+eol != "") {
  78.                             parseMods(s,e,m,eol,xmlmods);
  79.                         }
  80.                     }
  81.                 }
  82.             }
  83.             foreach(string s in xmlmods) {
  84.                 itgmods.Add(s);
  85.             }
  86.             itgmods.Add("}");
  87.             itgmods.Add("end\"");
  88.             itgmods.Add("/>");
  89.             itgmods.Add("</children></ActorFrame>");
  90.             foreach(string s in itgmods) {
  91.                 using(StreamWriter sw = new StreamWriter(@"output_mods.xml",true)) {
  92.                     sw.WriteLine(s);
  93.                 }
  94.             }
  95.         }
  96.         public static void parseMods(string Start, string End, string[] Mods, string EndType,List<string> output) {
  97.             string mod = "{";
  98.             mod = mod + Start + ",";
  99.             mod = mod + End + ",";
  100.             if(Mods.Count() == 1) {
  101.                 mod = mod + "\'" + Mods[0] + "\',";
  102.             } else {
  103.                 string tempmod = "";
  104.                 tempmod = tempmod + "\'";
  105.                 foreach(string s in Mods) {
  106.                     tempmod = tempmod + s + ",";
  107.                 }
  108.                 tempmod = tempmod.Substring(0,tempmod.Length-1);
  109.                 tempmod = tempmod + "\',";
  110.                 mod = mod + tempmod;
  111.             }
  112.             mod = mod + "\'" + EndType + "\'";
  113.             mod = mod + "},";
  114.             output.Add(mod);
  115.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement