private void readChapterThumbnails() { string filePath = modPath + "\\materials\\vgui\\chapters"; string vtf2tgaPath = gamePath + "\\bin\\vtf2tga.exe"; for (int i = 0; i < chapters.Count; i++) { if (File.Exists(filePath + "\\chapter" + (i + 1) + ".vtf")) { chapters[i].thumbnailFile = File.ReadAllBytes(filePath + "\\chapter" + (i + 1) + ".vtf"); Bitmap src = VTF.ToBitmap(chapters[i].thumbnailFile, launcher); // Crop image Bitmap target = new Bitmap(152, 86); using (Graphics gfx = Graphics.FromImage(target)) gfx.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), new Rectangle(0, 0, target.Width, target.Height), GraphicsUnit.Pixel); chapters[i].thumbnail = target; } } }
private void readBackgroundImages() { string filePath = modPath + "\\materials\\console"; string vtf2tgaPath = gamePath + "\\bin\\vtf2tga.exe"; for (int i = 0; i < chapters.Count; i++) { if (File.Exists(filePath + "\\" + chapters[i].background + ".vtf")) { chapters[i].backgroundImageFile = File.ReadAllBytes(filePath + "\\" + chapters[i].background + ".vtf"); Bitmap src = VTF.ToBitmap(chapters[i].backgroundImageFile, launcher); // Crop image if (src == null) { continue; } Bitmap target = new Bitmap(1024, 768); using (Graphics gfx = Graphics.FromImage(target)) gfx.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), new Rectangle(0, 0, src.Width, src.Height), GraphicsUnit.Pixel); chapters[i].backgroundImage = target; } if (File.Exists(filePath + "\\" + chapters[i].background + "_widescreen.vtf")) { chapters[i].backgroundImageWideFile = File.ReadAllBytes(filePath + "\\" + chapters[i].background + "_widescreen.vtf"); Bitmap src = VTF.ToBitmap(chapters[i].backgroundImageWideFile, launcher); // Crop image if (src == null) { continue; } Bitmap target = new Bitmap(1920, 1080); using (Graphics gfx = Graphics.FromImage(target)) gfx.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), new Rectangle(0, 0, src.Width, src.Height), GraphicsUnit.Pixel); chapters[i].backgroundImageWide = target; } } }
private void LoadTexture(PictureEdit pictureEdit) { string tag = pictureEdit.Tag.ToString(); int width = textureWidth; int height = textureHeight; if (openBitmapFileDialog.ShowDialog() == DialogResult.OK) { string type = new FileInfo(openBitmapFileDialog.FileName).Extension; string modPath = launcher.GetCurrentMod().installPath; Uri path1 = new Uri(modPath + "\\"); Uri path2 = new Uri(openBitmapFileDialog.FileName); Uri diff = path1.MakeRelativeUri(path2); if (type == ".vtf") { textures[tag].relativePath = diff.OriginalString; textures[tag].bytes = File.ReadAllBytes(openBitmapFileDialog.FileName); textures[tag].bitmap = VTF.ToBitmap(textures[tag].bytes, launcher); } else { textures[tag].relativePath = string.Empty; textures[tag].bitmap = new Bitmap(Bitmap.FromFile(openBitmapFileDialog.FileName), width, height); textures[tag].bytes = VTF.FromBitmap(textures[tag].bitmap, launcher); } if (textures[tag].bitmap != null) { pictureEdit.Image = textures[tag].bitmap; } } CreateToolTexture(); }
public void LoadMaterial(string fullPath) { SourceSDK.KeyValue vmt = null; if (File.Exists(fullPath)) { vmt = SourceSDK.KeyValue.readChunkfile(fullPath); } string relativePath = GetRelativePath(launcher, fullPath); this.relativePath = relativePath.Substring("\\materials\\".Length); VPKManager vpkManager = null; if (vmt != null) { vpkManager = new VPKManager(launcher); } foreach (KeyValuePair <string, PictureEdit> kv in pictureEdits) { if (vmt != null) { string value = vmt.getValue("$" + kv.Key); if (value != null) { string texturePath = vpkManager.getExtractedPath("materials/" + value + ".vtf"); if (texturePath != "" && File.Exists(texturePath)) { textures[kv.Key].relativePath = value; textures[kv.Key].bytes = File.ReadAllBytes(texturePath); textures[kv.Key].bitmap = VTF.ToBitmap(textures[kv.Key].bytes, launcher); kv.Value.Image = textures[kv.Key].bitmap; } else { ClearTexture(kv.Value); } } } else { ClearTexture(kv.Value); } } if (vmt != null && vmt.getValue("$normalmapalphaenvmapmask") == "1" && textures["bumpmap"].bitmap != null) { textures["envmapmask"].bitmap = new Bitmap(textures["bumpmap"].bitmap.Width, textures["bumpmap"].bitmap.Height); for (int i = 0; i < textures["bumpmap"].bitmap.Width; i++) { for (int j = 0; j < textures["bumpmap"].bitmap.Height; j++) { int alpha = textures["bumpmap"].bitmap.GetPixel(i, j).A; textures["envmapmask"].bitmap.SetPixel(i, j, Color.FromArgb(alpha, alpha, alpha)); } } textures["envmapmask"].bytes = VTF.FromBitmap(textures["envmapmask"].bitmap, launcher); textures["envmapmask"].relativePath = ""; pictureEnvMapMask.Image = textures["envmapmask"].bitmap; } }