Skip to content

Commit 5e1531f

Browse files
committed
Add project files.
1 parent 7de3faf commit 5e1531f

File tree

3 files changed

+238
-0
lines changed

3 files changed

+238
-0
lines changed

Legacy-Container-Extract.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33723.286
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Legacy-Container-Extract", "Legacy-Container-Extract\Legacy-Container-Extract.csproj", "{FF5C2474-A0C3-4D16-955F-EC1CDB81A599}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{FF5C2474-A0C3-4D16-955F-EC1CDB81A599}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{FF5C2474-A0C3-4D16-955F-EC1CDB81A599}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{FF5C2474-A0C3-4D16-955F-EC1CDB81A599}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{FF5C2474-A0C3-4D16-955F-EC1CDB81A599}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B257149C-109C-4079-985E-46D432C18A4F}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<RootNamespace>Legacy_Container_Extract</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
</Project>
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
Console.Write("Enter the directory of files: ");
10+
string directory = Console.ReadLine();
11+
12+
if (!Directory.Exists(directory))
13+
{
14+
Console.WriteLine("Directory not found.");
15+
return;
16+
}
17+
18+
string[] files = Directory.GetFiles(directory);
19+
string outputDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content");
20+
Directory.CreateDirectory(outputDirectory);
21+
22+
string convertAllType = null;
23+
string ignoreAllType = null;
24+
25+
foreach (var file in files)
26+
{
27+
try
28+
{
29+
byte[] fileBytes = File.ReadAllBytes(file);
30+
31+
string fileContent = System.Text.Encoding.ASCII.GetString(fileBytes);
32+
int blfIndex = fileContent.IndexOf("_blf");
33+
34+
if (blfIndex == -1)
35+
continue;
36+
37+
string content = System.Text.Encoding.ASCII.GetString(fileBytes.Skip(0xD0C0).Take(0x7F).ToArray()).Trim('\0');
38+
string sanitizedContent = string.Concat(content.Split(Path.GetInvalidFileNameChars()));
39+
string creatorName = System.Text.Encoding.ASCII.GetString(fileBytes.Skip(0xD088).Take(0x0F).ToArray()).Trim('\0');
40+
string creatorXUID = BitConverter.ToString(fileBytes.Skip(0xD080).Take(0x08).ToArray()).Replace("-", "");
41+
string modifierName = System.Text.Encoding.ASCII.GetString(fileBytes.Skip(0xD0AC).Take(0x0F).ToArray()).Trim('\0');
42+
string modifierXUID = BitConverter.ToString(fileBytes.Skip(0xD0A4).Take(0x08).ToArray()).Replace("-", "");
43+
string description = System.Text.Encoding.ASCII.GetString(fileBytes.Skip(0xD1C0).Take(0xFF).ToArray()).Trim('\0');
44+
string headerType = System.Text.Encoding.ASCII.GetString(fileBytes.Skip(0xD2F0).Take(0x04).ToArray()).Trim('\0');
45+
string contentType = null;
46+
47+
switch (headerType)
48+
{
49+
case "mpvr":
50+
contentType = "Gametypes";
51+
break;
52+
case "mvar":
53+
contentType = "Map variants";
54+
break;
55+
case "athr":
56+
contentType = "Theater films";
57+
break;
58+
case "scnc":
59+
contentType = "Screenshots";
60+
break;
61+
}
62+
63+
Console.WriteLine();
64+
Console.WriteLine($"File: {Path.GetFileName(file)}");
65+
Console.WriteLine($"Creator: {creatorName} (XUID: {creatorXUID})");
66+
Console.WriteLine($"Modifier: {modifierName} (XUID: {modifierXUID})");
67+
Console.WriteLine($"Content: {content}");
68+
Console.WriteLine($"Description: {description}");
69+
Console.WriteLine($"Header Type: {headerType}");
70+
71+
if (headerType == ignoreAllType)
72+
{
73+
Console.WriteLine($"Skipping all files of type: {headerType}");
74+
continue;
75+
}
76+
77+
if (headerType == convertAllType)
78+
{
79+
Console.WriteLine($"Automatically converting all files of type: {headerType}");
80+
}
81+
else
82+
{
83+
Console.Write("Would you like to convert this file? (y)es / (n)o / (a)ll of type / (i)gnore all of type: ");
84+
string response = Console.ReadLine()?.ToLower();
85+
86+
if (response == "a")
87+
{
88+
convertAllType = headerType;
89+
}
90+
else if (response == "i")
91+
{
92+
ignoreAllType = headerType;
93+
Console.WriteLine($"Skipping all files of type: {headerType}");
94+
continue;
95+
}
96+
else if (response != "y")
97+
{
98+
continue;
99+
}
100+
}
101+
102+
if (headerType == "scnc")
103+
{
104+
int jpgStartIndex = FindJpgStart(fileBytes, blfIndex);
105+
int jpgEndIndex = FindJpgEnd(fileBytes, jpgStartIndex);
106+
107+
if (jpgStartIndex == -1 || jpgEndIndex == -1)
108+
{
109+
Console.WriteLine("Valid JPEG range not found. Skipping file.");
110+
continue;
111+
}
112+
113+
byte[] jpgBytes = fileBytes.Skip(jpgStartIndex).Take(jpgEndIndex - jpgStartIndex + 1).ToArray();
114+
115+
string headerDirectory = Path.Combine(outputDirectory, contentType);
116+
Directory.CreateDirectory(headerDirectory);
117+
118+
string outputFile = Path.Combine(headerDirectory, sanitizedContent + ".jpg");
119+
File.WriteAllBytes(outputFile, jpgBytes);
120+
Console.WriteLine($"JPEG file saved: {outputFile}");
121+
continue;
122+
}
123+
124+
int stopSequenceIndex = FindStopSequence(fileBytes, blfIndex);
125+
126+
if (stopSequenceIndex == -1)
127+
{
128+
Console.WriteLine("Stop sequence not found. Skipping file.");
129+
continue;
130+
}
131+
132+
byte[] extractedBytes = fileBytes.Skip(blfIndex).Take(stopSequenceIndex - blfIndex).ToArray();
133+
134+
string extension = null;
135+
if (headerType == "mpvr")
136+
{
137+
extension = ".bin";
138+
}
139+
else if (headerType == "mvar")
140+
{
141+
extension = ".mvar";
142+
}
143+
else if (headerType == "athr")
144+
{
145+
extension = ".film";
146+
}
147+
148+
string headerDirectoryForOthers = Path.Combine(outputDirectory, contentType);
149+
Directory.CreateDirectory(headerDirectoryForOthers);
150+
151+
string outputFileForOthers = Path.Combine(headerDirectoryForOthers, sanitizedContent + extension);
152+
File.WriteAllBytes(outputFileForOthers, extractedBytes);
153+
Console.WriteLine($"File saved: {outputFileForOthers}");
154+
}
155+
catch (Exception ex)
156+
{
157+
Console.WriteLine($"Error processing file {Path.GetFileName(file)}: {ex.Message}");
158+
}
159+
}
160+
161+
Console.WriteLine("Processing complete.");
162+
}
163+
164+
static int FindStopSequence(byte[] fileBytes, int startIndex)
165+
{
166+
string stopSequence = "_eof";
167+
int stopIndex = System.Text.Encoding.ASCII.GetString(fileBytes).IndexOf(stopSequence, startIndex);
168+
169+
if (stopIndex != -1)
170+
{
171+
return stopIndex + stopSequence.Length + 0x0D;
172+
}
173+
174+
return -1;
175+
}
176+
177+
static int FindJpgStart(byte[] fileBytes, int startIndex)
178+
{
179+
byte[] jpgStartPattern = { 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46 };
180+
for (int i = startIndex; i <= fileBytes.Length - jpgStartPattern.Length; i++)
181+
{
182+
if (fileBytes.Skip(i).Take(jpgStartPattern.Length).SequenceEqual(jpgStartPattern))
183+
{
184+
return i;
185+
}
186+
}
187+
return -1;
188+
}
189+
190+
static int FindJpgEnd(byte[] fileBytes, int startIndex)
191+
{
192+
byte[] jpgEndPattern = { 0xFF, 0xD9 };
193+
for (int i = startIndex; i <= fileBytes.Length - jpgEndPattern.Length; i++)
194+
{
195+
if (fileBytes.Skip(i).Take(jpgEndPattern.Length).SequenceEqual(jpgEndPattern))
196+
{
197+
return i + jpgEndPattern.Length - 1;
198+
}
199+
}
200+
return -1;
201+
}
202+
}

0 commit comments

Comments
 (0)