-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrefabsClass.cs
More file actions
180 lines (173 loc) · 7.75 KB
/
PrefabsClass.cs
File metadata and controls
180 lines (173 loc) · 7.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace ThemesOutputer
{
public class PrefabsClass
{
public static void Preeeefabs(List<string> yeetdirs, string tpath)
{
try
{
var h = new List<string> { "\\", "/", ":", "*", "?", "\"", ">", "<", "|"};
foreach (string yeey in yeetdirs)
{
var themes = new List<string>();
var names = new List<string>();
string text = Yeeeeetext(yeey);
if (text != null)
{
using (StringReader reader = new StringReader(text))
{
string line;
while ((line = reader.ReadLine()) != null)
{
//Still can't remember what the heck this thing is doing with my program
if (line != " ")
{
line = line.Remove(line.LastIndexOf(","));
names.Add(line);
}
}
}
//For loop for all themes found in level. So for loop loops the amount of prefabs level.lsb had.
for (int i = 0; i < names.Count; i++)
{
themes.Add(names[i]);
if (i == names.Count - 1)
{
themes[i] = themes[i].Remove(themes[i].LastIndexOf("]")); //The last theme is dick so we must calm it down
}
int idx = names[i].IndexOf("name");
int idxa = names[i].IndexOf("type");
names[i] = names[i].Remove(idxa - 3);
names[i] = names[i].Substring(idx + 7);
for(int a=0;a<h.Count; a++)
{
names[i] = names[i].Replace(h[a], "");
}
string fileName = @$"{tpath}\{names[i]}.lsp"; //Completed path with name and path
FileInfo fi = new FileInfo(fileName);
//Check if file already exists. If yes, delete it.
if (fi.Exists)
{
//if the same theme exists in folder.
fi.Delete();
}
// Create a new file
using (StreamWriter sw = fi.CreateText())
{
sw.WriteLine(themes[i]);//It writes theme string into the file in one line. might update later so there will be /n everywhere
Console.WriteLine($"File Created! Name: {names[i]}");//Tells us that File created without any errors
}
}
}
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
public static List<string> PathP()
{
string path;
var yeetdirs = new List<string>();
try
{
Console.WriteLine("Please write a path to level.lsb which you want to use for Extracting the prefabs.\n or... [REDACTED]");
path = Console.ReadLine();
if (path.Contains("\""))
{
//This removes the "" symbols from the path. That happens when you drag folder/file in Console - Path will look like "C:\System32\Secrets\Pirate.lsb" and that code removes " "
path = path.Remove(path.LastIndexOf("\""));
path = path.Substring(path.IndexOf("\"") + 1);
}
if (path.Contains("level.lsb"))
{
//If user just dragged the level level.lsb so this path will include the level.lsb at the end. Due to conflits(User might not include the level.lsb at the end i had to remove this to fix conflict
path = path.Remove(path.LastIndexOf("\\level.lsb"));
}
if (path == "yeet")
{
try
{
Console.WriteLine("Please write the Disk Drive on which you have installed Steam");
string DiskDrive = Console.ReadLine();
string[] h = Directory.GetDirectories($@"{DiskDrive}:\Program Files (x86)\Steam\steamapps\workshop\content\440310\");
yeetdirs = h.ToList();
Console.WriteLine($"The number of directories(levels) in your workshop is: {yeetdirs.Count}");
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
else
{
yeetdirs.Add(path);
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
return yeetdirs;
}
public static string TPathP()
{
Console.WriteLine("Please write the system path to folder where you want prefabs to be extracted. without \\ at the end");
string tpath = Console.ReadLine();
//Path to folder where Themes will drop their bodies
if (tpath.Contains("\""))
{
tpath = tpath.Remove(tpath.LastIndexOf("\""));
tpath = tpath.Substring(tpath.IndexOf("\"") + 1);
}
return tpath;
}
public static string Yeeeeetext(string yeey)
{
int heey = 0;
string text = "";
var foundIndexes = new List<int>();
var fileStream = new FileStream(@$"{yeey}\level.lsb", FileMode.Open, FileAccess.Read);
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
string line;
while ((line = streamReader.ReadLine()) != null)
{
//We read the entire level.lsb here
text = line;
}
}
int idx = text.IndexOf("prefabs");
int idxa = text.IndexOf("themes");
if (idx != -1)
{
text = text.Remove(idxa - 1); //Removes some chars to make clear string of theme
text = text.Substring(idx + 10); //Removes some chars to make clear string of theme
Console.WriteLine($"The index of themes: {idx}, and index of he: {idxa}");
for (int i = text.IndexOf("{\"n"); i > -1; i = text.IndexOf("{\"n", i + 1))
{
//for loop end when i=-1 ('{' not found)
foundIndexes.Add(i);
}
for (int a = 1; a < foundIndexes.Count; a++)
{
//Something which I do not remember. I might need to call to memory and ask what the fuck is this.
foundIndexes[a] = foundIndexes[a] + heey;
heey = heey + 1;
text = text.Insert(foundIndexes[a], "\n");
}
return text;
}
else
{
return null;
}
}
}
}