Skip to content
This repository was archived by the owner on Jan 27, 2022. It is now read-only.

Commit a9b6385

Browse files
committed
Prefabs and legacy models now supported
1 parent 99c4081 commit a9b6385

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

MapPacker/AppForm.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public AppForm() {
2626
Console.WriteLine("\t[+] Make sure your vmap and compiled vpk are in the same directory.");
2727
Console.WriteLine("\t[+] Select your vmap, asset directory and sbox directory in the boxes above.");
2828
Console.WriteLine("\t[+] Click pack. The found and packed assets will be listed below.");
29-
Console.WriteLine("\nFor any additional help, contact Josh Wilson#9332 or DoctorGurke#0007 on discord or make an issue on the Github.");
29+
Console.WriteLine("\n\t[+]In case you don't want to have your content packed, just check the box and it will instead appear in a folder called yourMap_content.");
30+
Console.WriteLine("\nFor any additional help, contact 'DoctorGurke#0007' or 'Josh Wilson#9332' on discord or make an issue on the Github.");
3031
}
3132

3233
public ProgressBar bar {

MapPacker/AssetCleaner.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,7 @@ public void GetAssets() {
3434
string pathToMap = vmapFile;
3535

3636
Console.WriteLine($"reading map file: {pathToMap}");
37-
byte[] file = File.ReadAllBytes(pathToMap);
38-
AssetFile map = AssetFile.From(file);
39-
map.TrimAssetList(); // trim it to the space where assets are actually referenced, using "map_assets_references" markers
40-
41-
foreach(var item in map.SplitNull()) {
42-
if(item.EndsWith("vmat")) {
43-
GetAssetsFromMaterial(item);
44-
} else if(item.EndsWith("vmdl")) {
45-
GetAssetsFromModel(item);
46-
} else if(item.EndsWith("vpcf")) {
47-
GetAssetsFromParticle(item);
48-
} else if (item.EndsWith("vmap")) {
49-
var mapName = pathToMap.Substring(pathToMap.LastIndexOf("\\") + 1, pathToMap.Length - pathToMap.LastIndexOf("\\") - 1);
50-
if(!(item == "mapName")) {
51-
GetSkyboxAssets(item);
52-
}
53-
}
54-
}
37+
GetAssetsFromMap(pathToMap);
5538

5639
parentForm.bar.Value = 30;
5740

@@ -167,24 +150,32 @@ public void CopyFiles() {
167150
if(!parentForm.packCheck.Checked) {
168151
PackVPK();
169152
} else {
153+
SoundPlayer player = new SoundPlayer(Properties.Resources.steam_message);
154+
parentForm.bar.Value = 0;
170155
Console.WriteLine("\nAsset move completed.");
171156
MessageBox.Show("Content successfully moved!", "Complete", MessageBoxButtons.OK, MessageBoxIcon.None);
172157
}
173158
}
174159

175-
public void GetSkyboxAssets(string map) {
176-
map = CleanAssetPath(map);
177-
var mapDir = vmapFile.Substring(0, vmapFile.LastIndexOf("maps"));
160+
public void GetAssetsFromMap(string map) { // this uses a full path, since it's kinda for the original map
178161
try {
179-
var mapReference = AssetFile.From(File.ReadAllBytes($"{mapDir}{map}"));
180-
if(mapReference.IsMapSkybox()) {
181-
//Console.WriteLine($"3D Skybox reference found {map}");
182-
mapReference.TrimAssetList();
183-
foreach(var item in mapReference.SplitNull()) {
184-
if(item.EndsWith("vmat")) {
185-
GetAssetsFromMaterial(item);
186-
} else if(item.EndsWith("vmdl")) {
187-
GetAssetsFromModel(item);
162+
var mapData = File.ReadAllBytes($"{map}");
163+
AssetFile mapFile = AssetFile.From(mapData);
164+
mapFile.TrimAssetList(); // trim it to the space where assets are actually referenced, using "map_assets_references" markers
165+
166+
foreach(var item in mapFile.SplitNull()) {
167+
if(item.EndsWith("vmat")) {
168+
GetAssetsFromMaterial(item);
169+
} else if(item.EndsWith("vmdl")) {
170+
GetAssetsFromModel(item);
171+
} else if(item.EndsWith("vpcf")) {
172+
GetAssetsFromParticle(item);
173+
} else if(item.EndsWith("vmap")) {
174+
var mapItem = CleanAssetPath(item);
175+
var path = TrimAddonPath(map);
176+
if(!($"{path}\\{item}" == map)) {
177+
GetAssetsFromMap($"{path}\\{item}"); // we can assume that prefabs will also be wherever the original map is
178+
GetAssetsFromMap($"{assetPath}\\{item}"); // prefabs *could* also be in the asset directory however
188179
}
189180
}
190181
}
@@ -282,6 +273,15 @@ public static string CleanAssetPath(string item) {
282273
}
283274
return asset;
284275
}
276+
277+
public static string TrimAddonPath(string path) {
278+
// trim full path to addons/addonName/
279+
var addonsIndex = path.LastIndexOf("addons");
280+
var trim1 = path.Substring(0, addonsIndex + 7);
281+
var trim2 = path.Substring(addonsIndex + 7, path.Length - addonsIndex - 7);
282+
var addonName = trim2.Substring(0, trim2.IndexOf("\\"));
283+
return trim1 + addonName;
284+
}
285285
}
286286

287287
public class AssetFile {

0 commit comments

Comments
 (0)