Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ruarai/CompilePal
Browse files Browse the repository at this point in the history
  • Loading branch information
ruarai committed Oct 10, 2015
2 parents 5a41beb + b57d81a commit 64fe4dc
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 48 deletions.
22 changes: 15 additions & 7 deletions BSPPack/AssetUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public static List<string> findMdlMaterials(string path, List<int> skins = null)
mdl.Seek(4, SeekOrigin.Begin);
int ver = reader.ReadInt32();

if (ver > 48)
// mdl version is more recent and not supported
return materials;

List<string> modelVmts = new List<string>();
List<string> modelDirs = new List<string>();

Expand Down Expand Up @@ -173,15 +169,18 @@ public static List<string> findMdlMaterials(string path, List<int> skins = null)

public static List<string> findVmtMaterials(string fullpath)
{
// finds vtfs files associated with vmt file
// finds vmt files associated with vmt file

List<string> vmtList = new List<string>();
foreach (string line in File.ReadAllLines(fullpath))
{
string param = line.Replace("\"", " ").Replace("\t", " ").Trim();
if (Keys.vmtMaterialKeyWords.Any(key => param.StartsWith(key + " ")))
vmtList.Add("materials/" +
param.Split(new char[] { ' ' }, 2)[1].Trim() + ".vmt");
{
vmtList.Add("materials/" + param.Split(new char[] { ' ' }, 2)[1].Trim());
if (!vmtList.Last().EndsWith(".vmt"))
vmtList[vmtList.Count-1] += ".vmt";
}
}
return vmtList;
}
Expand Down Expand Up @@ -293,6 +292,15 @@ public static List<string> findPcfMaterials(string path)
return pcfs;
}

public static void findBspPakDependencies(BSP bsp, string tempdir)
{
// Search the temp folder to find dependencies of files extracted from the pak file

foreach (String file in Directory.EnumerateFiles("tmp", "*.vmt", SearchOption.AllDirectories))
foreach (string material in AssetUtils.findVmtMaterials(new FileInfo(file).FullName))
bsp.TextureList.Add(material);
}

public static void findBspUtilityFiles(BSP bsp, List<string> sourceDirectories)
{
// Utility files are other files that are not assets
Expand Down
29 changes: 12 additions & 17 deletions BSPPack/BSP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,8 @@ public void buildTextureList()
bsp.Seek(offsets[43].Key, SeekOrigin.Begin);
TextureList = new List<string>(Encoding.ASCII.GetString(reader.ReadBytes(offsets[43].Value)).Split('\0'));
for (int i = 0; i < TextureList.Count; i++)
{
TextureList[i] = "materials/" + TextureList[i] + ".vmt";

// in the special case where we are dealing with water materials
if (TextureList[i].StartsWith("materials/maps/" + mapname + "/water/"))
{
string[] nameparts = TextureList[i].Split('/').Last().Split('_');
string filename = "";
for (int j = 0; j < nameparts.Count() - 3; j++)
{
filename += nameparts[j] + "_";
}
TextureList.Add("water/" + filename.TrimEnd('_'));
}
}


// find skybox materials
Dictionary<string, string> worldspawn = entityList.First(item => item["classname"] == "worldspawn");
foreach (string s in new string[] { "bk", "dn", "ft", "lf", "rt", "up" })
Expand All @@ -147,12 +133,21 @@ public void buildEntTextureList()
EntTextureList = new List<string>();
foreach (Dictionary<string, string> ent in entityList)
{
string toAdd = "";
foreach (KeyValuePair<string, string> prop in ent)
if (Keys.vmfMaterialKeys.Contains(prop.Key.ToLower()))
EntTextureList.Add(prop.Value);
toAdd = prop.Value;

if (ent["classname"].Contains("sprite") && ent.ContainsKey("model"))
EntTextureList.Add("materials/" + ent["model"]);
toAdd = ent["model"];

if (toAdd != string.Empty)
{
toAdd = "materials/" + toAdd;
if (!toAdd.EndsWith(".vmt"))
toAdd += ".vmt";
EntTextureList.Add(toAdd);
}
}
}

Expand Down
35 changes: 32 additions & 3 deletions BSPPack/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ static void Main(string[] args)
BSP map = new BSP(new FileInfo(bspPath));
AssetUtils.findBspUtilityFiles(map, sourceDirectories);

string unpackDir = Path.GetTempPath() + Guid.NewGuid();
UnpackBSP(unpackDir);
AssetUtils.findBspPakDependencies(map, unpackDir);

Console.WriteLine("Initializing pak file...");
PakFile pakfile = new PakFile(map , sourceDirectories);

Expand Down Expand Up @@ -106,16 +110,41 @@ static void Main(string[] args)
}
}

static void UnpackBSP(string unpackDir)
{
// unpacks the pak file and extracts it to a temp location

/* info: vbsp.exe creates files in the pak file that may have
* dependencies that are not listed anywhere else, as is the
* case for water materials. We use this method to extract the
* pak file to a temp folder and read the dependencies of its files. */

string arguments = "-extractfiles \"$bspold\" \"$dir\"";
arguments = arguments.Replace("$bspold", bspPath);
arguments = arguments.Replace("$dir", unpackDir);

var startInfo = new ProcessStartInfo(bspZip, arguments);
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.EnvironmentVariables["VPROJECT"] = gameFolder;

var p = new Process { StartInfo = startInfo };
p.Start();
}

static void PackBSP()
{
string arguments = "-addlist \"$bspnew\" \"$list\" \"$bspold\" -game \"$game\"";
string arguments = "-addlist \"$bspnew\" \"$list\" \"$bspold\"";
arguments = arguments.Replace("$bspnew", bspPath);
arguments = arguments.Replace("$bspold", bspPath);
arguments = arguments.Replace("$list", "files.txt");
arguments = arguments.Replace("$game", gameFolder);

var p = new Process { StartInfo = { Arguments = arguments, FileName = bspZip, UseShellExecute = false, RedirectStandardOutput = true } };
var startInfo = new ProcessStartInfo(bspZip, arguments);
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.EnvironmentVariables["VPROJECT"] = gameFolder;

var p = new Process { StartInfo = startInfo };
p.OutputDataReceived += p_OutputDataReceived;

p.Start();
Expand Down
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
Download
==========

### Download
https://github.com/ruarai/CompilePal/releases/latest

![CompilePal](http://i.imgur.com/jPEig83.png)

Compile Pal X is the official rewrite of Compile Pal - the amazing wrapper for the source map compiling tools that makes compiling a breeze.

An easy to manage UI:
![ui](http://i.imgur.com/D3usvmP.png)

Taskbar progress display:

![progress](http://i.imgur.com/85G1iDQ.gif)

Automatic file packing:

![packing](http://i.imgur.com/kKLsboM.png)

Configuration
==========

Compile Pal should automatically find any game configurations - as long as the game's SDK was run last. Game Configurations are cached between sessions, and you can choose between them at launch.

Packing
==========
PACK is a feature that allows for the automatic packing of custom content into a map BSP. It does not cover all custom content, so is best suited for when you simply want to share a map with a friend.
![ui](http://i.imgur.com/D3usvmP.png)

Error Checking
Packing
==========
PACK is a feature that allows for the automatic packing of custom content into a map BSP. Thanks to the work of Maxdup, this feature is now ready to be used in production.

### Packable Content
- Materials
- Models
- Model Skins
- Skybox Textures
- Sprites
- Water Materials
- Color Correction
- Detail Files
- Menu Photos
- Soundscapes
- Soundscripts
- Particle Manifests
- Much more...

## Error Checking
Compile Pal can detect and provide information relating to errors using the Interlopers error listings.

Download
==========
![errors](http://i.imgur.com/JA3gH3x.png)
![errors](http://i.imgur.com/Ckz5XyA.png)

## Contributors

### Developers
- Ruarai
- Maxdup

https://github.com/ruarai/CompilePal/releases/latest

### Bug Testing
- wareya
- Gangleider
- Matt2468rv
- Sevin7

0 comments on commit 64fe4dc

Please sign in to comment.