public Scene(string filename) { path = filename; name = Path.GetFileNameWithoutExtension(filename); byte[] data = File.ReadAllBytes(filename); using (MemoryStream ms = new MemoryStream(data, 4, data.Length - 4)) { using (BinaryReaderEx br = new BinaryReaderEx(ms)) { Read(br); string vrmpath = Path.ChangeExtension(filename, ".vrm"); if (File.Exists(vrmpath)) { Console.WriteLine("VRAM found!"); ctrvram = CtrVrm.FromFile(vrmpath); LoadTextures(); /* if (ctrvram != null) foreach (var m in texmaps) { ctrvram.GetTexture(m.tl, ".\\textures\\", m.name); Console.WriteLine(m.name); Console.ReadKey(); } */ } } } }
private void button8_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "CTR VRAM file|*.vrm"; if (ofd.ShowDialog() == DialogResult.OK) { Tim buf = CtrVrm.FromFile(ofd.FileName); MessageBox.Show(buf.data.Length / 256 + ""); if (scn != null) { Dictionary <string, TextureLayout> tex = scn.GetTexturesList(); MessageBox.Show(tex.Count.ToString()); foreach (TextureLayout tl in tex.Values) { //buf.GetTexturePage(tl, ""); } } buf.SaveBMP("test.bmp", BMPHeader.GrayScalePalette(16)); //buf.palbmp.Save("palletes.png", System.Drawing.Imaging.ImageFormat.Png); //Process.Start("palletes.png"); } }
public Scene(string filename, Tim vram = null) { path = filename; name = Path.GetFileNameWithoutExtension(filename); using (BinaryReaderEx br = new BinaryReaderEx(File.OpenRead(filename))) { Read(br); } if (vram != null) { ctrvram = vram; return; } string vrmpath = Path.ChangeExtension(filename, ".vrm"); if (File.Exists(vrmpath)) { Console.WriteLine("VRAM found!"); //ctrvram = CtrVrm.FromFile(vrmpath); SetVram(CtrVrm.FromFile(vrmpath)); } }
public Scene(string s) { path = s; name = Path.GetFileNameWithoutExtension(s); MemoryStream ms = new MemoryStream(File.ReadAllBytes(s)); BinaryReaderEx br = new BinaryReaderEx(ms); int size = br.ReadInt32(); //this is for files with external offs file if ((size & 0xFF) == 0x80) { ms = new MemoryStream(br.ReadBytes(size)); br = new BinaryReaderEx(ms); } else { ms = new MemoryStream(br.ReadBytes((int)br.BaseStream.Length - 4)); br = new BinaryReaderEx(ms); } Read(br); string vrmpath = Path.ChangeExtension(s, ".vram"); if (File.Exists(vrmpath)) { Console.WriteLine("VRAM found!"); ctrvram = CtrVrm.FromFile(vrmpath); } }
private void button18_Click_1(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "CTR VRAM file|*.vram"; if (ofd.ShowDialog() == DialogResult.OK) { Tim buf = CtrVrm.FromFile(ofd.FileName); Bitmap bmp = new Bitmap(160, 80); Graphics g = Graphics.FromImage(bmp); using (BinaryReaderEx br2 = new BinaryReaderEx(File.Open("ui_map", FileMode.Open))) { int z = br2.ReadInt32(); List <TexMap> list = new List <TexMap>(); for (int i = 0; i < 50; i++) { list.Add(new TexMap(br2)); } int x = 0; int y = 0; foreach (TexMap map in list) { buf.GetTexture(map.tl, "tex", map.name); Bitmap b = (Bitmap)Bitmap.FromFile("tex" + "\\" + map.name + ".png"); g.DrawImage(b, x * 16, y * 16); x++; if (x >= 10) { x = 0; y++; } } bmp.Save("font.png", System.Drawing.Imaging.ImageFormat.Png); } /* * Dictionary<string, TextureLayout> tex = scn.GetTexturesList(); * MessageBox.Show(tex.Count.ToString()); * } */ buf.SaveBMP("test.bmp", BMPHeader.GrayScalePalette(16)); //buf.palbmp.Save("palletes.png", System.Drawing.Imaging.ImageFormat.Png); Process.Start("font.png"); } }
static void Main(string[] args) { if (args.Length > 0) { ModelPack mpk = new ModelPack(args[0]); mpk.Extract(CtrVrm.FromFile("ui_textures.vram")); //Console.ReadKey(); } }
static void ConvertFile(string s) { string basepath = Path.GetDirectoryName(s); string name = Path.GetFileNameWithoutExtension(s); string ext = Path.GetExtension(s).ToLower(); switch (ext) { case ".lev": { Scene scn = Scene.FromFile(s); scn.quads = scn.quads.OrderBy(o => o.id).ToList(); scn.Export(basepath, ExportFlags.All); break; } case ".ctr": case ".dyn": { CtrModel d = new CtrModel(s); d.Export(basepath); break; } case ".mpk": { ModelPack mpk = new ModelPack(s); mpk.Extract(Path.Combine(basepath, name), CtrVrm.FromFile(Path.Combine(basepath, "shared.vrm"))); break; } } Console.WriteLine("Done!"); }
public void Start() { byte[] data = File.ReadAllBytes(LevPath); using (MemoryStream ms = new MemoryStream(data, 4, data.Length - 4)) { fileSize = (uint)data.Length; using (BinaryReaderEx br = new BinaryReaderEx(ms)) { Read(br); bool vram_path_is = File.Exists(VrmPath); if (vram_path_is) { Debug.Log("VRAM found!"); ctrvram = CtrVrm.FromFile(VrmPath); //tex = CtrVrm.buffer.ConvertedTexture; Debug.Log(CtrVrm.buffer.bpp); Debug.Log(CtrVrm.buffer.clutsize); Debug.Log(CtrVrm.buffer.datasize); Dictionary <string, TextureLayout> dictionary = GetTexturesList(Detail.Med); midTextures = new Dictionary <string, Texture2D>(); foreach (KeyValuePair <string, TextureLayout> entry in dictionary) { Tim texture = CtrVrm.buffer.GetTimTexture(entry.Value); Texture2D tex2D = new Texture2D(texture.region.Width * 4, texture.region.Height, TextureFormat.ARGB32, false); for (int y = 0; y < texture.region.Height; y++) { for (int x = 0; x < texture.region.Width; x++) { var clutValue = texture.data[x + texture.region.Width * y]; for (int clut = 0; clut < 4 * 4; clut += 4) { var pixelValue = texture.clutdata[(clutValue >> clut) & 15]; float pixelRed = pixelValue & 31; pixelValue = (ushort)(pixelValue >> 5); float pixelGreen = pixelValue & 31; pixelValue = (ushort)(pixelValue >> 5); float pixelBlue = pixelValue & 31; pixelValue = (ushort)(pixelValue >> 5); int pixelAlpha = pixelValue & 1; tex2D.SetPixel(x * 4 + clut / 4, y, new Color(pixelRed / 31f, pixelGreen / 31f, pixelBlue / 31f, pixelAlpha == 1 ? 0f : 1.0f)); } } } tex2D.Apply(); tex2D.filterMode = FilterMode.Point; midTextures.Add(entry.Key, tex2D); } dictionary = GetTexturesList(Detail.Low); lowTextures = new Dictionary <string, Texture2D>(); foreach (KeyValuePair <string, TextureLayout> entry in dictionary) { Tim texture = CtrVrm.buffer.GetTimTexture(entry.Value); Texture2D tex2D = new Texture2D(texture.region.Width * 4, texture.region.Height, TextureFormat.ARGB32, false); for (int y = 0; y < texture.region.Height; y++) { for (int x = 0; x < texture.region.Width; x++) { var clutValue = texture.data[x + texture.region.Width * y]; for (int clut = 0; clut < 4 * 4; clut += 4) { var pixelValue = texture.clutdata[(clutValue >> clut) & 15]; float pixelRed = pixelValue & 31; pixelValue = (ushort)(pixelValue >> 5); float pixelGreen = pixelValue & 31; pixelValue = (ushort)(pixelValue >> 5); float pixelBlue = pixelValue & 31; pixelValue = (ushort)(pixelValue >> 5); int pixelAlpha = pixelValue & 1; tex2D.SetPixel(x * 4 + clut / 4, y, new Color(pixelRed / 31f, pixelGreen / 31f, pixelBlue / 31f, pixelAlpha == 1 ? 0f : 1.0f)); } } } tex2D.Apply(); tex2D.filterMode = FilterMode.Point; lowTextures.Add(entry.Key, tex2D); } } GenerateVis(); Render(); ShowPickups(); } } using (MemoryStream ms = new MemoryStream(data, 0, 4)) { using (BinaryReaderEx br = new BinaryReaderEx(ms)) { fileSize = br.ReadUInt32Big(); } } }
static void ConvertFile(string filename) { string basepath = Path.GetDirectoryName(filename); string name = Path.GetFileNameWithoutExtension(filename); string ext = Path.GetExtension(filename).ToLower(); switch (ext) { case ".lev": { Scene scn = Scene.FromFile(filename); //scn.quads = scn.quads.OrderBy(o => o.id).ToList(); scn.Export(basepath, ExportFlags.All); break; } case ".ctr": case ".dyn": { CtrModel d = CtrModel.FromFile(filename); d.Export(basepath); break; } case ".obj": { OBJ obj = OBJ.FromFile(filename); CtrModel ctr = CtrModel.FromObj(obj); ctr.Save(basepath); break; } case ".ply": { CtrModel ctr = CtrModel.FromPly(filename); ctr.Save(basepath); break; } case ".mpk": { string vrampath = Path.ChangeExtension(filename, "vrm"); if (!File.Exists(vrampath)) { vrampath = Path.Combine(Path.GetDirectoryName(filename), "shared.vrm"); if (!File.Exists(vrampath)) { Console.WriteLine("Warning! No vram file found.\r\nPlease put shared.vrm file with mpk you want to extract."); vrampath = ""; } } ModelPack mpk = ModelPack.FromFile(filename); mpk.Extract(Path.Combine(basepath, name), CtrVrm.FromFile(vrampath).GetVram()); break; } default: { Console.WriteLine($"Unsupported file: {filename}"); return; } } Console.WriteLine("Done!"); }