// CONSTRUCTORS // This constructor sets everything according to specified settings. public BSP42Decompiler(BSP BSPObject, int jobnum, DecompilerThread parent) { // Set up global variables this.BSPObject = BSPObject; this.jobnum = jobnum; this.parent = parent; }
static void Main(string[] args) { BSP map = new BSP("ep1_c17_00.bsp"); vertext[] data = map.DumpLump<vertext>(); Console.WriteLine(map); Console.WriteLine("Chunks for dface_t loaded."); Console.WriteLine("Count: {0}", data.Length ); Console.ReadLine(); }
void Start() { /*if (Config.RandomSeed != 0) Random.seed = Config.RandomSeed;*/ GenerateSprite (); Paint (); bsp = new BSP (FloorSize.x, FloorSize.y, 0, 0); for (int i = 0; i < NumberOfIterations; i++) { bsp.Grow (); } bsp.Paint (LevelSprite.texture); }
public BSPCollisionViewer(BSP.BSPModel.BSPCollision tempcoll, int mapnumberx) { //InitializeComponent InitializeComponent(); mapnumber = mapnumberx; this.coll = tempcoll; bspMeta = Maps.map[mapnumber].SelectedMeta; Maps.map[mapnumber].OpenMap(MapTypes.Internal); // Load the collision planes into the BSP Collision as they are not laoded by default for (int i = 0; i < coll.PlaneReflexiveCount; i++) { Maps.map[mapnumber].BR.BaseStream.Position = Maps.map[mapnumber].SelectedMeta.offset + coll.PlaneReflexiveTranslation + i * 16; Vector4 temp = new Vector4(); temp.X = Maps.map[mapnumber].BR.ReadSingle(); temp.Y = Maps.map[mapnumber].BR.ReadSingle(); temp.Z = Maps.map[mapnumber].BR.ReadSingle(); temp.W = Maps.map[mapnumber].BR.ReadSingle(); coll.Planes[i].Add(temp); } // This will build our solid surfaces from the point / edge lists for (int i = 0; i < coll.SurfaceReflexiveCount; i++) { // Creates a new empty polygon (* Collision surfaces are not necessarily triangles) polygonInfo pi = new polygonInfo(); // Collision BSP / 3D Nodes (Offset 36 / 0) [each entry is 8 bytes long] Maps.map[mapnumber].BR.BaseStream.Position = Maps.map[mapnumber].SelectedMeta.offset + coll.SurfaceReflexiveTranslation + i * 8; pi.plane = Maps.map[mapnumber].BR.ReadInt16(); int startEdge = Maps.map[mapnumber].BR.ReadInt16(); pi.flags = Maps.map[mapnumber].BR.ReadByte(); pi.breakSurface = Maps.map[mapnumber].BR.ReadByte(); pi.material = Maps.map[mapnumber].BR.ReadInt16(); // The edges are listed in a circular order, we know the first edge, so cycle through until we get back home List<short> indices = new List<short>(); int currentEdge = startEdge; do { // Collision BSP / Edges (Offset 36 / 48) [each entry is 12 bytes long] Maps.map[mapnumber].BR.BaseStream.Position = Maps.map[mapnumber].SelectedMeta.offset + coll.FaceReflexiveTranslation + currentEdge * 12; short startVertex = Maps.map[mapnumber].BR.ReadInt16(); short endVertex = Maps.map[mapnumber].BR.ReadInt16(); short edge1 = Maps.map[mapnumber].BR.ReadInt16(); short edge2 = Maps.map[mapnumber].BR.ReadInt16(); short surfL = Maps.map[mapnumber].BR.ReadInt16(); short surfR = Maps.map[mapnumber].BR.ReadInt16(); // The edges are used by two surface that can be listed either left or right // We know what surface we are working with, so we use the edge that relates to our surface # // edge1 for Surface Left, edge2 for Surface Right if (surfL == i) { currentEdge = edge1; indices.Add(endVertex); } else if (surfR == i) { currentEdge = edge2; indices.Add(startVertex); } } while (currentEdge != startEdge); // The last vertices added is actually the first, so move it to the front indices.Insert(0, indices[indices.Count - 1]); indices.RemoveAt(indices.Count - 1); pi.indices = indices.ToArray(); polygons.Add(pi); } Maps.map[mapnumber].CloseMap(); Main(); }
public static void Main(string[] args) { var watch = new Stopwatch(); watch.Start(); _window = new RenderWindow(new VideoMode(1280, 720), "Toast", Styles.Default, new ContextSettings { AntialiasingLevel = 2 }); BSP bsp = null; var manager = new GameObjectManager(gob => bsp?.GetCollisions(gob.Bounds)); var env = new SimpleEnvironment(_window, manager); var windowCreate = watch.Elapsed.TotalSeconds; //_window.SetVerticalSyncEnabled(true); _window.SetFramerateLimit(60); var screenCenter = _window.Size / 2; _window.SetVisible(true); _window.Closed += OnClosed; _window.KeyPressed += (sender, eventArgs) => { if (eventArgs.Code == Keyboard.Key.Escape) { _window.Close(); } }; var p = env.ObjectManager.Spawn <Player>(); p.Initialize(new RectangleShape(new Vector2f(50f, 50f)) { Texture = new Texture(@"media\magic.png") { Smooth = true }, Scale = new Vector2f(4f, 4f) }, env, _window); p.Position = new Vector2f(screenCenter.X, screenCenter.Y); var numEnemies = 400; for (int i = 0; i < numEnemies; i++) { SpawnEnemy(env, new Vector2f(screenCenter.X, screenCenter.Y)); } var showFps = false; _window.KeyPressed += (sender, eventArgs) => { if (eventArgs.Code == Keyboard.Key.Tilde) { showFps = !showFps; } }; var font = new Font(@"c:\windows\fonts\ariblk.ttf"); var previous = (float)watch.Elapsed.TotalSeconds; var lag = 0f; var fpsBuffer = new Queue <float>(); while (_window.IsOpen) { env.DebugText.Clear(); var time = (float)watch.Elapsed.TotalSeconds; var dt = time - previous; previous = time; lag += dt; _window.DispatchEvents(); _window.Clear(); var preUpdate = watch.Elapsed.TotalSeconds; while (lag > env.FrameDelta) { var objects = env.ObjectManager.Objects.ToList(); for (int i = 0; i < numEnemies - objects.Count(a => a is Enemy); i++) { SpawnEnemy(env, new Vector2f(screenCenter.X, screenCenter.Y)); } objects = env.ObjectManager.Objects.ToList(); bsp = new BSP(new HashSet <GameObjectBase>(objects), new FloatRect(0, 0, _window.Size.X, _window.Size.Y)); foreach (var gameObjectBase in objects) { gameObjectBase.Update(); } manager.DestroyAll(); lag -= env.FrameDelta; } var postUpdate = watch.Elapsed.TotalSeconds; env.LogText($"update %: {100 * (postUpdate - preUpdate) / dt:F1}"); env.FrameRemainder = lag; foreach (var gameObjectBase in env.ObjectManager.Objects) { _window.Draw(gameObjectBase); } if (bsp != null) { //_window.Draw(bsp); } if (showFps) { fpsBuffer.Enqueue(1 / dt); while (fpsBuffer.Count > 100) { fpsBuffer.Dequeue(); } env.LogText($"fps: {fpsBuffer.Average():F1}"); } _window.Draw(new Text(string.Join("\n", env.DebugText), font)); _window.Display(); } }
private void FileClose_Click(object sender, RoutedEventArgs e) { currentBSP = null; }
public ParticleManifest(List <string> sourceDirectories, List <string> ignoreDirectories, List <string> excludedFiles, BSP map, string bspPath, string gameFolder) { CompilePalLogger.LogLine("Generating Particle Manifest..."); baseDirectory = gameFolder + "\\"; particles = new List <PCF>(); //Search directories for pcf and find particles that match used particle names //TODO multithread this? foreach (string sourceDirectory in sourceDirectories) { string externalPath = sourceDirectory + "\\" + internalPath; if (Directory.Exists(externalPath) && !ignoreDirectories.Contains(externalPath.Remove(externalPath.Length - 1, 1), StringComparer.OrdinalIgnoreCase)) { foreach (string file in Directory.GetFiles(externalPath)) { if (file.EndsWith(".pcf") && !excludedFiles.Contains(file.ToLower())) { PCF pcf = ParticleUtils.IsTargetParticle(file, map.ParticleList); if (pcf != null) { particles.Add(pcf); } } } } } if (particles == null || particles.Count == 0) { Error e = new Error() { Message = "Could not find any PCFs that contained used particles!", Severity = 3, ID = 403 }; CompilePalLogger.LogCompileError("Could not find any PCFs that contained used particles!\n", e); CompilePalLogger.LogCompileError("Could not find any PCFs that contained used particles!\n", new Error("Could not find any PCFs that contained used particles!\n", ErrorSeverity.Warning)); return; } //Check for pcfs that contain the same particle name //List<ParticleConflict> conflictingParticles = new List<ParticleConflict>(); List <PCF> conflictingParticles = new List <PCF>(); if (particles.Count != 1) { for (int i = 0; i < particles.Count - 1; i++) { for (int j = i + 1; j < particles.Count; j++) { //Create a list of names that intersect between the 2 lists List <string> conflictingNames = particles[i].ParticleNames.Intersect(particles[j].ParticleNames).ToList(); if (conflictingNames.Count != 0) { //pc.conflictingNames = conflictingNames; conflictingParticles.Add(particles[i]); conflictingParticles.Add(particles[j]); } } } } //Solve conflicts if (conflictingParticles.Count != 0) { //Remove duplicates conflictingParticles = conflictingParticles.Distinct().ToList(); //Remove particle if it is in a particle conflict, add back when conflict is manually resolved foreach (PCF conflictParticle in conflictingParticles) { particles.Remove(conflictParticle); } List <PCF> resolvedConflicts = new List <PCF>(); //Bring up conflict window //Have to run on STAthread Application.Current.Dispatcher.Invoke((Action) delegate { //Make taskbar icon red ProgressManager.ErrorProgress(); //Create window ConflictWindow cw = new ConflictWindow(conflictingParticles, map.ParticleList); cw.ShowDialog(); //Get resolved conflicts resolvedConflicts = cw.selectedPCFS; }); //Add resolved conflicts back into particle list particles.AddRange(resolvedConflicts); } //Remove duplicates particles = particles.Distinct().ToList(); //Dont create particle manifest if there is no particles if (particles.Count == 0) { return; } //Generate manifest file filepath = bspPath.Remove(bspPath.Length - 4, 4) + "_particles.txt"; //Write manifest using (StreamWriter sw = new StreamWriter(filepath)) { sw.WriteLine("particles_manifest"); sw.WriteLine("{"); foreach (PCF particle in particles) { string internalParticlePath = particle.FilePath.Replace(baseDirectory, ""); sw.WriteLine($" \"file\" \"!{internalParticlePath}\""); CompilePalLogger.LogLine($"PCF added to manifest: {internalParticlePath}"); } sw.WriteLine("}"); } string internalDirectory = filepath.Replace(baseDirectory, ""); //Store internal/external dir so it can be packed particleManifest = new KeyValuePair <string, string>(internalDirectory, filepath); }
/// <summary> /// Given a <see cref="Face"/> with a list of <see cref="Edge"/>s, generates a <see cref="Mesh"/> with the /// correct vertices and tessellates them into triangle fans. This is fine, since BSP faces are guaranteed /// to be closed and convex. /// </summary> /// <param name="bsp">The <see cref="BSP"/> object <paramref name="face"/> came from.</param> /// <param name="face">The <see cref="Face"/> to build a <see cref="Mesh"/> from.</param> /// <returns>The <see cref="Mesh"/> generated from the <see cref="Edge"/>s referenced by <see cref="Face"/>.</returns> public static Mesh LoadVerticesFromEdges(BSP bsp, Face face) { Vertex[] vertices = new Vertex[face.NumEdgeIndices]; int[] triangles = new int[(face.NumEdgeIndices - 2) * 3]; int firstSurfEdge = (int)bsp.surfEdges[face.FirstEdgeIndexIndex]; if (firstSurfEdge > 0) { vertices[0] = bsp.vertices[bsp.edges[firstSurfEdge].FirstVertexIndex]; } else { vertices[0] = bsp.vertices[bsp.edges[-firstSurfEdge].SecondVertexIndex]; } int currtriangle = 0; int currvert = 1; for (int i = 1; i < face.NumEdgeIndices - 1; i++) { int currSurfEdge = (int)bsp.surfEdges[face.FirstEdgeIndexIndex + i]; Vertex first; Vertex second; if (currSurfEdge > 0) { first = bsp.vertices[bsp.edges[currSurfEdge].FirstVertexIndex]; second = bsp.vertices[bsp.edges[currSurfEdge].SecondVertexIndex]; } else { first = bsp.vertices[bsp.edges[-currSurfEdge].SecondVertexIndex]; second = bsp.vertices[bsp.edges[-currSurfEdge].FirstVertexIndex]; } if (first.position != vertices[0].position && second.position != vertices[0].position) // All tris involve first vertex, so disregard edges referencing it { triangles[currtriangle * 3] = 0; bool firstFound = false; bool secondFound = false; for (int j = 1; j < currvert; j++) { if (first.position == vertices[j].position) { triangles[(currtriangle * 3) + 1] = j; firstFound = true; } } if (!firstFound) { vertices[currvert] = first; triangles[(currtriangle * 3) + 1] = currvert; currvert++; } for (int j = 1; j < currvert; j++) { if (second.position == vertices[j].position) { triangles[(currtriangle * 3) + 2] = j; secondFound = true; } } if (!secondFound) { vertices[currvert] = second; triangles[(currtriangle * 3) + 2] = currvert; currvert++; } currtriangle++; } } Mesh mesh = LoadVertices(vertices); mesh.triangles = triangles; return(mesh); }
public static void writeBSP(BSP BSPObject, string path) { byte[] entityBytes = new byte[1]; byte[] planeBytes = new byte[BSPObject.Planes.Count * 20]; byte[] textureBytes = new byte[BSPObject.Textures.Count * 64]; byte[] materialBytes = new byte[BSPObject.Materials.Count * 64]; byte[] vertexBytes = new byte[BSPObject.Vertices.Count * 12]; byte[] normalBytes = new byte[BSPObject.Normals.Length]; byte[] indexBytes = new byte[BSPObject.Indices.Count * 4]; byte[] visBytes = new byte[BSPObject.Vis.Count * BSPObject.Vis.StructLength]; byte[] nodeBytes = new byte[BSPObject.Nodes.Count * 36]; byte[] faceBytes = new byte[BSPObject.Faces.Count * 48]; byte[] lightBytes = new byte[BSPObject.Lightmaps.Count]; byte[] leafBytes = new byte[BSPObject.Leaves.Count * 48]; byte[] markfaceBytes = new byte[BSPObject.MarkSurfaces.Count * 4]; byte[] markbrushBytes = new byte[BSPObject.MarkBrushes.Count * 4]; byte[] modelBytes = new byte[BSPObject.Models.Count * 56]; byte[] brushBytes = new byte[BSPObject.Brushes.Count * 12]; byte[] brushsideBytes = new byte[BSPObject.BrushSides.Count * 8]; byte[] texinfoBytes = new byte[BSPObject.TexInfo.Count * 32]; int offset = 0; foreach (Entity e in BSPObject.Entities) { byte[] temp = e.toByteArray(); Array.Resize <byte>(ref entityBytes, entityBytes.Length + temp.Length); Array.Copy(temp, 0, entityBytes, offset, temp.Length); offset += temp.Length; } offset = 0; foreach (Plane p in BSPObject.Planes) { Array.Copy(p.toByteArray(), 0, planeBytes, offset, 20); offset += 20; } offset = 0; foreach (Texture t in BSPObject.Textures) { Array.Copy(t.toByteArray(), 0, textureBytes, offset, 64); offset += 64; } offset = 0; foreach (Texture t in BSPObject.Materials) { Array.Copy(t.toByteArray(), 0, materialBytes, offset, 64); offset += 64; } offset = 0; foreach (Vertex v in BSPObject.Vertices) { Array.Copy(v.toByteArray(), 0, vertexBytes, offset, 12); offset += 12; } offset = 0; foreach (long l in BSPObject.Indices) { Array.Copy(BitConverter.GetBytes((int)l), 0, indexBytes, offset, 4); offset += 4; } offset = 0; foreach (LumpObject o in BSPObject.Vis) { Array.Copy(o.Data, 0, visBytes, offset, BSPObject.Vis.StructLength); offset += BSPObject.Vis.StructLength; } offset = 0; foreach (Node n in BSPObject.Nodes) { Array.Copy(n.toByteArray(), 0, nodeBytes, offset, 36); offset += 36; } offset = 0; foreach (Face f in BSPObject.Faces) { Array.Copy(f.toByteArray(), 0, faceBytes, offset, 48); offset += 48; } offset = 0; foreach (long l in BSPObject.Lightmaps) { lightBytes[offset++] = (byte)l; } offset = 0; foreach (Leaf l in BSPObject.Leaves) { Array.Copy(l.toByteArray(), 0, leafBytes, offset, 48); offset += 48; } offset = 0; foreach (long l in BSPObject.MarkSurfaces) { Array.Copy(BitConverter.GetBytes((int)l), 0, markfaceBytes, offset, 4); offset += 4; } offset = 0; foreach (long l in BSPObject.MarkBrushes) { Array.Copy(BitConverter.GetBytes((int)l), 0, markbrushBytes, offset, 4); offset += 4; } offset = 0; foreach (Model m in BSPObject.Models) { Array.Copy(m.toByteArray(), 0, modelBytes, offset, 56); offset += 56; } offset = 0; foreach (Brush b in BSPObject.Brushes) { Array.Copy(b.toByteArray(), 0, brushBytes, offset, 12); offset += 12; } offset = 0; foreach (BrushSide b in BSPObject.BrushSides) { Array.Copy(b.toByteArray(), 0, brushsideBytes, offset, 8); offset += 8; } offset = 0; foreach (TexInfo t in BSPObject.TexInfo) { Array.Copy(t.toByteArray(), 0, texinfoBytes, offset, 32); offset += 32; } byte[] header = new byte[148]; header[0] = 42; offset = 148; byte[] headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 4, 4); headertemp = BitConverter.GetBytes(entityBytes.Length); Array.Copy(headertemp, 0, header, 8, 4); offset += entityBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 12, 4); headertemp = BitConverter.GetBytes(planeBytes.Length); Array.Copy(headertemp, 0, header, 16, 4); offset += planeBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 20, 4); headertemp = BitConverter.GetBytes(textureBytes.Length); Array.Copy(headertemp, 0, header, 24, 4); offset += textureBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 28, 4); headertemp = BitConverter.GetBytes(materialBytes.Length); Array.Copy(headertemp, 0, header, 32, 4); offset += materialBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 36, 4); headertemp = BitConverter.GetBytes(vertexBytes.Length); Array.Copy(headertemp, 0, header, 40, 4); offset += vertexBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 44, 4); headertemp = BitConverter.GetBytes(normalBytes.Length); Array.Copy(headertemp, 0, header, 48, 4); offset += normalBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 52, 4); headertemp = BitConverter.GetBytes(indexBytes.Length); Array.Copy(headertemp, 0, header, 56, 4); offset += indexBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 60, 4); headertemp = BitConverter.GetBytes(visBytes.Length); Array.Copy(headertemp, 0, header, 64, 4); offset += visBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 68, 4); headertemp = BitConverter.GetBytes(nodeBytes.Length); Array.Copy(headertemp, 0, header, 72, 4); offset += nodeBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 76, 4); headertemp = BitConverter.GetBytes(faceBytes.Length); Array.Copy(headertemp, 0, header, 80, 4); offset += faceBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 84, 4); headertemp = BitConverter.GetBytes(lightBytes.Length); Array.Copy(headertemp, 0, header, 88, 4); offset += lightBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 92, 4); headertemp = BitConverter.GetBytes(leafBytes.Length); Array.Copy(headertemp, 0, header, 96, 4); offset += leafBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 100, 4); headertemp = BitConverter.GetBytes(markfaceBytes.Length); Array.Copy(headertemp, 0, header, 104, 4); offset += markfaceBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 108, 4); headertemp = BitConverter.GetBytes(markbrushBytes.Length); Array.Copy(headertemp, 0, header, 112, 4); offset += markbrushBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 116, 4); headertemp = BitConverter.GetBytes(modelBytes.Length); Array.Copy(headertemp, 0, header, 120, 4); offset += modelBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 124, 4); headertemp = BitConverter.GetBytes(brushBytes.Length); Array.Copy(headertemp, 0, header, 128, 4); offset += brushBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 132, 4); headertemp = BitConverter.GetBytes(brushsideBytes.Length); Array.Copy(headertemp, 0, header, 136, 4); offset += brushsideBytes.Length; headertemp = BitConverter.GetBytes(offset); Array.Copy(headertemp, 0, header, 140, 4); headertemp = BitConverter.GetBytes(texinfoBytes.Length); Array.Copy(headertemp, 0, header, 144, 4); offset += texinfoBytes.Length; FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(stream); stream.Seek(0, SeekOrigin.Begin); bw.Write(header); bw.Write(entityBytes); bw.Write(planeBytes); bw.Write(textureBytes); bw.Write(materialBytes); bw.Write(vertexBytes); bw.Write(normalBytes); bw.Write(indexBytes); bw.Write(visBytes); bw.Write(nodeBytes); bw.Write(faceBytes); bw.Write(lightBytes); bw.Write(leafBytes); bw.Write(markfaceBytes); bw.Write(markbrushBytes); bw.Write(modelBytes); bw.Write(brushBytes); bw.Write(brushsideBytes); bw.Write(texinfoBytes); bw.Close(); Console.WriteLine("FIINISH"); }
static void Main(string[] args) { GERB gerbb = new GERB(); BSP bspp = new BSP(); DPS dpss = new DPS(); KauzaRz kauzaa = new KauzaRz(); Free freee = new Free(); ReformBlog reformBlogg = new ReformBlog(); // Console.WriteLine("Искате ли да започнете работа със Системата?"); Console.WriteLine("за да започнете работа натиснете => 0"); Console.WriteLine("за повече информация натиснете => 1 "); Console.WriteLine("за изход от Системата натиснете => 2 "); var enter = Console.ReadLine(); if (enter == "0") { PrintInfoForProgram(); var allCouncilMan = gerbb.ListCol().Concat(bspp.ListCol().Concat(dpss.ListCol().Concat(kauzaa.ListCol().Concat(freee.ListCol().Concat(reformBlogg.ListCol()))))); string[] allCouncilArr = allCouncilMan.ToArray(); // List <string> kvorum = new List <string>(); string[] toName = allCouncilArr; List <string> take = toName.ToList(); // var gerb = gerbb.ListCol(); var bsp = bspp.ListCol(); var dps = dpss.ListCol(); var reforma = reformBlogg.ListCol(); var nezavisim = freee.ListCol(); var kauza = kauzaa.ListCol(); Dictionary <string, List <string> > delegateByPoliticians = new Dictionary <string, List <string> >(); byte count = 0; //Kvorum => string za potvyrjdenie => Tuk for (int person = 0; person < all; person++) { Console.Write(toName[person] + " => "); var checking = Console.ReadLine(); Console.WriteLine(checking); File.AppendAllText(path, "Кворум:"); if (checking == "tuk") { count++; kvorum.Add($"{toName[person]}"); File.AppendAllText(path, toName[person]); take.Remove(toName[person]); // TakeInfoForPartAndPerson(gerbb, bspp, dpss, kauzaa, freee, reformBlogg, toName, delegateByPoliticians, person); } } var result = kvorum.Count > 16 ? "Има кворум" : $"Няма кворум, нужни са още/поне {16 - kvorum.Count} гласа!"; File.AppendAllText(path, result); Console.WriteLine(".................................................."); Console.WriteLine("Присъстват по партийни групи:"); File.AppendAllText(path, "Присъстват по партийни групи:"); var tempC = 0; foreach (var party in delegateByPoliticians) { Console.WriteLine(party.Key); File.AppendAllText(path, party.Key); foreach (var person in party.Value) { tempC++; Console.WriteLine($"{tempC}. " + person); File.AppendAllText(path, $"{tempC}. " + person + "\n"); } Console.WriteLine(); } Console.WriteLine(".................................................."); Console.WriteLine($"Гласували общо: {count}"); File.AppendAllText(path, $"Гласували общо: {count}" + "\n"); Console.WriteLine($"{result}"); File.AppendAllText(path, $"{result}" + "\n"); Console.WriteLine($"Присъстват следните съветници:"); for (int i = 0; i < kvorum.Count; i++) { Console.WriteLine($"{i} => {kvorum[i]}"); } File.AppendAllText(path, $"Присъстват следните съветници => \n" + string.Join($"\n=>", kvorum)); Console.WriteLine($"Отсъстват следните съветници =>"); File.AppendAllText(path, $"Отсъстват следните съветници =>"); var countMising = 1; for (int i = 0; i < take.Count; i++) { Console.WriteLine($"{countMising++} => {take[i]}"); File.AppendAllText(path, $"{countMising++} => {take[i]}" + "\n"); } Console.WriteLine(".................................................."); Dictionary <byte, string> positive = new Dictionary <byte, string>(); Dictionary <byte, string> negative = new Dictionary <byte, string>(); Dictionary <byte, string> neutral = new Dictionary <byte, string>(); byte a = 1; byte b = 1; byte c = 1;; if (kvorum.Count > 16) { Console.WriteLine("Заседанието има кворум и докладните могат да се гласуват!"); File.AppendAllText(path, "Заседанието има кворум и докладните могат да се гласуват!" + "\n"); //работи се с лист от кворума => приема се до доказване на противното, //че за да се приеме докладна трябва да има >50% от гласовете на делегатите. Console.WriteLine("Желате ли да започнете гласуването? Yes/No" + $"\nИмате кворум от => {kvorum.Count} делегата!"); File.AppendAllText(path, "Желате ли да започнете гласуването? Yes/No" + $"\nИмате кворум от => {kvorum.Count} делегата!" + "\n"); var askAction = Console.ReadLine(); var gerbCountN = new byte[3] { 0, 0, 0 }; var bspCountN = new byte[3] { 0, 0, 0 }; var dpsCountN = new byte[3] { 0, 0, 0 }; var reformaCountN = new byte[3] { 0, 0, 0 }; var kauzaCountN = new byte[3] { 0, 0, 0 }; var freeCountN = new byte[3] { 0, 0, 0 }; while (askAction != "No") { for (int i = 0; i < kvorum.Count; i++) { Console.Write(kvorum[i] + " => "); var voting = Console.ReadLine(); Console.WriteLine(voting); byte n = 0; if (voting == "z") { positive.Add(a, kvorum[i]); GetV(kvorum, gerb, gerbCountN, i); GetV(kvorum, bsp, bspCountN, i); GetV(kvorum, dps, dpsCountN, i); GetV(kvorum, reforma, reformaCountN, i); GetV(kvorum, nezavisim, freeCountN, i); GetV(kvorum, kauza, kauzaCountN, i); a++; } if (voting == "p") { negative.Add(b, kvorum[i]); GetV2(kvorum, gerb, gerbCountN, i); GetV2(kvorum, bsp, bspCountN, i); GetV2(kvorum, dps, dpsCountN, i); GetV2(kvorum, nezavisim, freeCountN, i); GetV2(kvorum, reforma, reformaCountN, i); GetV2(kvorum, kauza, kauzaCountN, i); b++; } if (voting == "v") { neutral.Add(c, kvorum[i]); GetV3(kvorum, gerb, gerbCountN, i); GetV3(kvorum, bsp, bspCountN, i); GetV3(kvorum, dps, dpsCountN, i); GetV3(kvorum, nezavisim, freeCountN, i); GetV3(kvorum, reforma, reformaCountN, i); GetV3(kvorum, kauza, kauzaCountN, i); c++; } else { continue; } } Console.WriteLine(".................................................."); Console.WriteLine("Резултат от гласуването =>"); Console.WriteLine("За"); File.AppendAllText(path, "За" + "\n"); if (positive.Count() != 0) { foreach (var za in positive) { Console.Write($"{za.Key} поредност на вота => "); foreach (var item in za.Value) { Console.Write($"{item}"); File.AppendAllText(path, $"{item}"); } Console.WriteLine(); } } else { Console.Write(" => " + 0); } Console.WriteLine("Против"); File.AppendAllText(path, "Против" + "\n"); if (negative.Count() != 0) { foreach (var protiv in negative) { Console.Write($"{protiv.Key} поредност на вота => "); foreach (var item in protiv.Value) { Console.Write(item); File.AppendAllText(path, item.ToString()); } Console.WriteLine(); } } else { Console.Write(" => " + 0); } Console.WriteLine("Въздържал се"); File.AppendAllText(path, "Въздържал се" + "\n"); if (neutral.Count() != 0) { foreach (var pass in neutral) { Console.Write($"{pass.Key} поредност на вота => "); foreach (var item in pass.Value) { Console.Write(item); File.AppendAllText(path, item.ToString()); } Console.WriteLine(); } } else { Console.Write(" => " + 0); } Console.WriteLine(".................................................."); var isOk = positive.Count() > kvorum.Count / 2; var p = positive.Count() == 0 ? 0 : positive.Count(); var nega = negative.Count() == 0 ? 0 : negative.Count(); var neutr = neutral.Count() == 0 ? 0 : neutral.Count(); Console.WriteLine(".................................................."); if (isOk) { Console.WriteLine("Докладната се приема!"); File.AppendAllText(path, "Докладната се приема!"); Console.WriteLine(p + " ЗА"); File.AppendAllText(path, p + " ЗА\n"); Console.WriteLine(nega + " Против"); File.AppendAllText(path, nega + " Против\n"); Console.WriteLine(neutr + " Въздържал се"); File.AppendAllText(path, neutr + " Въздържал се\n"); } else { Console.WriteLine("Докладната се отхвърля!"); File.AppendAllText(path, "Докладната се отхвърля!\n"); Console.WriteLine(p + " ЗА"); File.AppendAllText(path, p + " ЗА\n"); Console.WriteLine(nega + " Против"); File.AppendAllText(path, nega + " Против\n"); Console.WriteLine(neutr + " Въздържал се"); File.AppendAllText(path, neutr + " Въздържал се\n"); } Console.WriteLine(".................................................."); Console.WriteLine("По политически групи:"); File.AppendAllText(path, "По политически групи:\n"); Console.WriteLine(".................................................."); Console.WriteLine("За"); File.AppendAllText(path, "За\n"); Print(gerbCountN[0], bspCountN[0], dpsCountN[0], reformaCountN[0], kauzaCountN[0], freeCountN[0]); File.AppendAllText(path, "GERB => " + gerbCountN[0] + "\n"); File.AppendAllText(path, "BSP => " + bspCountN[0] + "\n"); File.AppendAllText(path, "DPS => " + dpsCountN[0] + "\n"); File.AppendAllText(path, "Reforma => " + reformaCountN[0] + "\n"); File.AppendAllText(path, "Kauza => " + kauzaCountN[0] + "\n"); File.AppendAllText(path, "Free => " + freeCountN[0] + "\n"); // Console.WriteLine("Против"); File.AppendAllText(path, "Против"); Print(gerbCountN[1], bspCountN[0], dpsCountN[1], reformaCountN[1], kauzaCountN[1], freeCountN[1]); File.AppendAllText(path, "GERB => " + gerbCountN[1] + "\n"); File.AppendAllText(path, "BSP => " + bspCountN[1] + "\n"); File.AppendAllText(path, "DPS => " + dpsCountN[1] + "\n"); File.AppendAllText(path, "Reforma => " + reformaCountN[1] + "\n"); File.AppendAllText(path, "Kauza => " + kauzaCountN[1] + "\n"); File.AppendAllText(path, "Free => " + freeCountN[1] + "\n"); // Console.WriteLine("Въздържал се:"); File.AppendAllText(path, "Въздържал се:"); Print(gerbCountN[2], bspCountN[2], dpsCountN[2], reformaCountN[2], kauzaCountN[2], freeCountN[2]); File.AppendAllText(path, "GERB => " + gerbCountN[2] + "\n"); File.AppendAllText(path, "BSP => " + bspCountN[2] + "\n"); File.AppendAllText(path, "DPS => " + dpsCountN[2] + "\n"); File.AppendAllText(path, "Reforma => " + reformaCountN[2] + "\n"); File.AppendAllText(path, "Kauza => " + kauzaCountN[2] + "\n"); File.AppendAllText(path, "Free => " + freeCountN[2] + "\n"); Console.WriteLine(".................................................."); File.AppendAllText(path, DateTime.Now.ToString() + "\n"); Console.ReadKey(); Console.WriteLine("Желате ли да започнете ново гласуване ? Yes/No"); //зануляване на стойностите. positive.Clear(); neutral.Clear(); negative.Clear(); for (int i = 0; i < gerbCountN.Length; i++) { gerbCountN[i] = 0; } for (int i = 0; i < bspCountN.Length; i++) { bspCountN[i] = 0; } for (int i = 0; i < dpsCountN.Length; i++) { dpsCountN[i] = 0; } for (int i = 0; i < reformaCountN.Length; i++) { reformaCountN[i] = 0; } for (int i = 0; i < kauzaCountN.Length; i++) { kauzaCountN[i] = 0; } for (int i = 0; i < freeCountN.Length; i++) { freeCountN[i] = 0; } askAction = Console.ReadLine(); } } Console.ReadKey(); } if (enter == "1") { PrintAddInfoForProgram(); } if (enter == "2") { Console.WriteLine("Благодарим Ви, че използвате Системата!"); } }
public override void Load() { mapName = Botv2.Utilities.GameHelper.getMapName(); mapPath = Path.GetDirectoryName(Bot.process.Modules[0].FileName) + "/csgo/maps/" + mapName; FileStream stream = File.OpenRead(mapPath); BSP map = new BSP(stream); List <Vector3> vertices = map.getVertices(); List <ushort[]> edges = map.getEdges(); List <Face> faces = map.getOriginalFaces(); map.getFaces(); int[] surfedges = map.getSurfedges(); int[] textureData = map.getTextureInfo(); stream.Close(); this.EdgesEffect = new BasicEffect(this.GraphicsDevice); this.EdgesEffect.World = Matrix.Identity; this.EdgesEffect.TextureEnabled = false; this.EdgesEffect.VertexColorEnabled = true; this.Edges = new VertexPositionColor[edges.Count * 2]; for (int i = 0; i < edges.Count; i++) { //if (edges[i][0] > vertices.Count - 1 || edges[i][1] > vertices.Count - 1) continue; Edges[i * 2] = new VertexPositionColor(vertices[edges[i][0]], Color.Black); Edges[(i * 2) + 1] = new VertexPositionColor(vertices[edges[i][1]], Color.Black); } Faces = new List <VertexPositionColor[]>(); for (int i = 0; i < faces.Count; i++) { Face face = faces[i]; //if (faces[i].texinfo > textureData.Length) continue; List <VertexPositionColor> temp = new List <VertexPositionColor>(); for (int b = 0; b <= face.numEdges; b++) { if (surfedges[face.firstEdge + b] < 0) { temp.Add(new VertexPositionColor(vertices[(int)edges[Math.Abs(surfedges[face.firstEdge + b])][0]], Color.LightGray)); temp.Add(new VertexPositionColor(vertices[(int)edges[Math.Abs(surfedges[face.firstEdge + b])][1]], Color.LightGray)); continue; } int edgeIndex = Math.Abs(surfedges[face.firstEdge + b]); int verticeOne = edges[edgeIndex][1]; int verticeTwo = edges[edgeIndex][0]; temp.Add(new VertexPositionColor(vertices[verticeOne], Color.LightGray)); temp.Add(new VertexPositionColor(vertices[verticeTwo], Color.LightGray)); } Faces.Add(temp.ToArray()); } }
public virtual void Run() { DateTime begin = DateTime.Now; try { Entities output = null; if (doomMap != null) { // If this is a Doom map extracted from a WAD //Window.setProgress(jobnum, 0, doomMap.getSubSectors().size(), "Decompiling..."); WADDecompiler decompiler = new WADDecompiler(doomMap, jobnum, this); output = decompiler.decompile(); } else { DecompilerThread.OnMessage(this, "Opening file " + BSPFile.FullName); //Window.setProgress(jobnum, 0, 1, "Reading..."); BSPReader reader = new BSPReader(BSPFile, openAs); reader.readBSP(); //if (!reader.WAD) { BSPObject = reader.BSPData; /*try { * Window.setProgress(jobnum, 0, reader.BSPData.getBrushes().size() + reader.BSPData.getEntities().size(), "Decompiling..."); * } catch (System.NullReferenceException e) { * try { * Window.setProgress(jobnum, 0, reader.BSPData.getLeaves().size() + reader.BSPData.getEntities().size(), "Decompiling..."); * } catch (System.NullReferenceException f) { * Window.setProgress(jobnum, 0, 1, "Decompiling..."); // What's going on here? Put in a failsafe progress bar for now * } * }*/ switch (reader.Version) { case mapType.TYPE_QUAKE: //DecompilerThread.OnMessage(this, "ERROR: Algorithm for decompiling Quake BSPs not written yet.",Window.VERBOSITY_ALWAYS); //throw new java.lang.Exception(); // Throw an exception to the exception handler to indicate it didn't work QuakeDecompiler decompiler29 = new QuakeDecompiler(reader.BSPData, jobnum, this); output = decompiler29.decompile(); break; case mapType.TYPE_NIGHTFIRE: BSP42Decompiler decompiler42 = new BSP42Decompiler(reader.BSPData, jobnum, this); output = decompiler42.decompile(); break; case mapType.TYPE_QUAKE2: case mapType.TYPE_SIN: case mapType.TYPE_SOF: case mapType.TYPE_DAIKATANA: BSP38Decompiler decompiler38 = new BSP38Decompiler(reader.BSPData, jobnum, this); output = decompiler38.decompile(); break; case mapType.TYPE_SOURCE17: case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_DMOMAM: case mapType.TYPE_VINDICTUS: case mapType.TYPE_TACTICALINTERVENTION: SourceBSPDecompiler sourceDecompiler = new SourceBSPDecompiler(reader.BSPData, jobnum, this); output = sourceDecompiler.decompile(); break; case mapType.TYPE_QUAKE3: case mapType.TYPE_RAVEN: case mapType.TYPE_COD: case mapType.TYPE_COD2: case mapType.TYPE_COD4: case mapType.TYPE_STEF2: case mapType.TYPE_STEF2DEMO: case mapType.TYPE_MOHAA: case mapType.TYPE_FAKK: BSP46Decompiler decompiler46 = new BSP46Decompiler(reader.BSPData, jobnum, this); output = decompiler46.decompile(); break; case mapType.TYPE_DOOM: case mapType.TYPE_HEXEN: foreach (DoomMap map in reader.DoomMaps) { WADDecompiler wadDecompiler = new WADDecompiler(map, jobnum, this); Entities holyshit = wadDecompiler.decompile(); MAPMaker.outputMaps(holyshit, map.MapName, map.Folder + map.WadName + "\\", map.Version); } break; default: DecompilerThread.OnMessage(this, "ERROR: Unknown BSP version: " + reader.Version); throw new System.Exception(); // Throw an exception to the exception handler to indicate it didn't work } //} } if (output != null) { //Window.setProgress(jobnum, 1, 1, "Saving..."); if (doomMap == null) { MAPMaker.outputMaps(output, BSPObject.MapNameNoExtension, BSPObject.Folder, BSPObject.Version); } else { MAPMaker.outputMaps(output, doomMap.MapName, doomMap.Folder + doomMap.WadName + "\\", doomMap.Version); } } //Window.setProgress(jobnum, 1, 1, "Done!"); //System.Drawing.Color tempAux = System.Drawing.Color.FromArgb(64, 192, 64); //Window.setProgressColor(jobnum, ref tempAux); DateTime end = DateTime.Now; DecompilerThread.OnMessage(this, "Time taken: " + (end - begin).ToString() + (char)0x0D + (char)0x0A); OnFinish(this, jobnum); } catch (System.OutOfMemoryException) { string st = ""; if (openAs != mapType.TYPE_UNDEFINED) { st = "VM ran out of memory on job " + (jobnum + 1) + ". Are you using \"Open as...\" with the wrong game?" + (char)0x0D + (char)0x0A + "If not, please let me know on the issue tracker!" + (char)0x0D + (char)0x0A + "http://code.google.com/p/jbn-bsp-lump-tools/issues/entry"; } else { st = "VM ran out of memory on job " + (jobnum + 1) + "." + (char)0x0D + (char)0x0A + "Please let me know on the issue tracker!" + (char)0x0D + (char)0x0A + "http://code.google.com/p/jbn-bsp-lump-tools/issues/entry"; } //Window.setProgress(jobnum, 1, 1, "ERROR! See log!"); //System.Drawing.Color tempAux4 = System.Drawing.Color.FromArgb(255, 128, 128); //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" //Window.setProgressColor(jobnum, ref tempAux4); OnError(this, st); } catch (Exception e) { string st; if (openAs != mapType.TYPE_UNDEFINED) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" st = "" + (char)0x0D + (char)0x0A + "Exception caught in job " + (jobnum + 1) + ": " + e + (char)0x0D + (char)0x0A + "Are you using \"Open as...\" with the wrong game?" + (char)0x0D + (char)0x0A + "If not, please let me know on the issue tracker!" + (char)0x0D + (char)0x0A + "http://code.google.com/p/jbn-bsp-lump-tools/issues/entry"; } else { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" st = "" + (char)0x0D + (char)0x0A + "Exception caught in job " + (jobnum + 1) + ": " + e + (char)0x0D + (char)0x0A + "Please let me know on the issue tracker!" + (char)0x0D + (char)0x0A + "http://code.google.com/p/jbn-bsp-lump-tools/issues/entry"; } /*System.String stackTrace = "Stack Trace: " + (char) 0x0D + (char) 0x0A; * StackTraceElement[] trace = e.getStackTrace(); * for (int i = 0; i < trace.length; i++) * { * stackTrace += (trace[i].toString() + Window.LF); * } * //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" * DecompilerThread.OnMessage(this, e.Message + Window.LF + stackTrace); * DecompilerThread.OnMessage(this, ); * Window.setProgress(jobnum, 1, 1, "ERROR! See log!"); * System.Drawing.Color tempAux3 = System.Drawing.Color.FromArgb(255, 128, 128); * //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" * Window.setProgressColor(jobnum, ref tempAux3);*/ OnError(this, st); } finally { doomMap = null; BSPObject = null; BSPFile = null; Thread.CurrentThread.Abort(); } /*else * { * Window.print("Job " + (jobnum + 1) + " aborted by user."); * Window.print(" When: While initializing job."); * DecompilerThread.OnMessage(this, ); * Window.setProgress(jobnum, 1, 1, "Aborted!"); * System.Drawing.Color tempAux5 = System.Drawing.Color.FromArgb(255, 128, 128); * //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" * Window.setProgressColor(jobnum, ref tempAux5); * SupportClass.ThreadClass.Current().Interrupt(); * }*/ //Window.setAbortButtonEnabled(jobnum, false); }
private void DrawWorld(WindowRenderTarget device, CSGOImplementation csgo) { if (csgo.CurrentMap == null) { return; } if (csgo.GetValue <YesNo>("wireframeEnabled") == YesNo.No) { return; } BSP map = csgo.CurrentMap; Color color = new Color((int)csgo.GetValue <float>("wireframeColorR"), (int)csgo.GetValue <float>("wireframeColorG"), (int)csgo.GetValue <float>("wireframeColorB"), (int)csgo.GetValue <float>("wireframeColorA")); float distanceMeters = csgo.GetValue <float>("wireframeDistance"); float scale = 1f; bool drawOnlyMe = (csgo.GetValue <YesNo>("wireframeDrawAroundMe") == YesNo.Yes); Target drawTarget = csgo.GetValue <Target>("wireframeDrawTarget"); for (int f = 0; f < map.OriginalFaces.Length; f++) { Face face = map.OriginalFaces[f]; if (map.TextureInfo.Length > face.texinfo) { if ((map.TextureInfo[face.texinfo] & SurfFlag.SURF_NODRAW) == SurfFlag.SURF_NODRAW) { continue; } } for (int e = 0; e < face.numEdges; e++) { float dist = 1f; int surfedge = map.Surfedges[face.firstEdge + e]; ushort[] edge = map.Edges[Math.Abs(surfedge)]; Vector3 line3d1, line3d2; if (surfedge > 0) { line3d1 = map.Vertices[edge[0]]; line3d2 = map.Vertices[edge[1]]; } else { line3d1 = map.Vertices[edge[1]]; line3d2 = map.Vertices[edge[0]]; } bool valid = false; dist = Geometry.GetDistanceToPoint(line3d1, csgo.LocalPlayer.Vector3) * UNIT_TO_METERS; //valid = true; //if (dist > distanceMeters) // break; if (!drawOnlyMe) { foreach (Player player in csgo.Players) { if (player == null) { continue; } if (!player.IsValid()) { continue; } if (drawTarget != Target.Everyone) { if (drawTarget == Target.Allies && (player.InTeam != csgo.LocalPlayer.InTeam)) { continue; } if (drawTarget == Target.Enemies && (player.InTeam == csgo.LocalPlayer.InTeam)) { continue; } } float tmpDist = Geometry.GetDistanceToPoint(line3d1, player.Vector3) * UNIT_TO_METERS; if ( tmpDist < distanceMeters/* || * Geometry.GetDistanceToPoint(line3d2, player.Vector3) * UNIT_TO_METERS < distanceMeters*/ ) { valid = true; if (tmpDist < dist) { dist = tmpDist; } } } if (!valid) { break; } } else { if (dist > distanceMeters) { break; } } Vector2[] line = Geometry.WorldToScreen(csgo.ViewMatrix, csgo.ScreenSize, line3d1, line3d2); if (line[0] == Vector2.Zero || line[1] == Vector2.Zero) { continue; } Color col = color; if (csgo.GetValue <OnOff>("wireframeFading") == OnOff.On) { scale = 1f - 1f / distanceMeters * dist; col = color; col.A = (byte)(((float)col.A) * scale); } DrawLine(device, col, line[0].X, line[0].Y, line[1].X, line[1].Y, 1f); } } }
static void Main(string[] args) { Console.Title = "Test3"; /*if (args.Length == 0) * args = new string[] { "maps_q3.pk3" };*/ int TargetVer = 0; int StartIdx = 0; if (args.Length == 0) { Console.WriteLine("bspconv [version] file(.bsp|.pk3) [file2(.bsp|.pk3)]+"); Console.WriteLine(); Console.WriteLine("\tversion - 46 (Quake 3) or 47 (Quake Live), output version. Input version any."); return; } if (args.Length > 1 && int.TryParse(args[0], out TargetVer)) { StartIdx = 1; } else { TargetVer = 47; StartIdx = 0; } Console.WriteLine("Converting to IBSP {0}", TargetVer); for (int i = StartIdx; i < args.Length; i++) { string FileNameExt = args[i]; if (!File.Exists(FileNameExt)) { Console.WriteLine("Could not find {0}", FileNameExt); continue; } string FileName = Path.GetFileNameWithoutExtension(FileNameExt); string Extension = Path.GetExtension(FileNameExt); string OutName = FileName + "_IBSP" + TargetVer + Extension; if (Extension == ".bsp") { Console.WriteLine("Converting {0}", FileNameExt); BSP Map = BSP.FromFile(FileNameExt); Map.Version = TargetVer; File.WriteAllBytes(OutName, Map.ToByteArray()); } else if (Extension == ".pk3") { OpenZip(FileNameExt, true, (In) => { OpenZip(OutName, false, (Out) => { ConvertFromPK3(TargetVer, In, Out); }); }); } else { Console.WriteLine("Skipping {0}, unknown extension type {1}", FileNameExt, Extension); } } }
private void sDXThread(object sender) { showwarning(); vam = new VAMemory("csgo"); csgo = new Memory("csgo"); bEngine = getModule("engine.dll"); bClient = getModule("client.dll"); Button[] buttons = new Button[] { new ToggleableButton("Aimbot", delegate() { aimbottoggle = !aimbottoggle; }), new ToggleableButton("Wallhack", delegate() { wallhacktoggle = !wallhacktoggle; }), new ToggleableButton("ESP", delegate() { esptoggle = !esptoggle; }), new ToggleableButton("Bhop", delegate() { bhoptoggle = !bhoptoggle; }, true), new ToggleableButton("Triggerbot", delegate() { triggertoggle = !triggertoggle; }), new ToggleableButton("Noflash", delegate() { noflashtoggle = !noflashtoggle; }), //new SliderButton("FOV: %value%", delegate (float f) { randomFloat = f; }, abstractValue: 180f) }; menu = new Menu(buttons, (int)Math.Floor((decimal)(Height * 55.5 / 100)), 0); d = new Thread(() => { bool c = false; while (true) { while (c == false) { while (GetAsyncKeyState(0x26) < 0) { //aimbottoggle = !aimbottoggle; if (c == false) { menu.shiftSelected(false); } c = true; } while (GetAsyncKeyState(0x28) < 0) { //wallhacktoggle = !wallhacktoggle; if (c == false) { menu.shiftSelected(true); } c = true; } while (GetAsyncKeyState(0x25) < 0 || GetAsyncKeyState(0x27) < 0) { //esptoggle = !esptoggle; if (c == false) { menu.activateCurrent(); } c = true; } if (c == true) { showMenu = true; //start timer if (timer.Enabled == true) { timer.Stop(); } menuOffTicks = 150; timer.Start(); } } c = false; } }); d.Start(); bhop = new Thread(() => { while (true) { jumpy(); Thread.Sleep(1); } }); bhop.Start(); Thread checkmap = new Thread(() => { while (true) { var clientstate = vam.ReadInt32((IntPtr)(bEngine + Offsets.oClientState)); var name = vam.ReadByteArray((IntPtr)(clientstate + 0x28C), 32); var stringthing = Encoding.ASCII.GetString(name); stringthing = Regex.Replace(stringthing, @"[^\u0020-\u007F].*$+", string.Empty); var isInGame = vam.ReadInt32((IntPtr)clientstate + 0x108); if ((lastmap == "" || lastmap != stringthing) && isInGame == 6) { string location = Process.GetProcessesByName("csgo")[0].MainModule.FileName; location = location.Substring(0, location.Length - 8); //stringthing = stringthing.Substring(0, stringthing.IndexOf(@"\")); location += @"csgo\maps\" + stringthing + ".bsp"; if (stringthing.Length > 0) { map = new BSP(location); lastmap = stringthing; } } yield return(0); } }); checkmap.Start(); while (true) { device.BeginDraw(); device.Clear(new RawColor4(1f, 1f, 1f, 0f)); int id = 0; var g2 = GetForegroundWindow(); GetWindowThreadProcessId(g2, out id); #if !DEBUG if (id != csgoProcess.Id) { device.EndDraw(); continue; } #endif if (showMenu == true) { menu.showMenu(device, font); } t = new RECT(); GetWindowRect(GetForegroundWindow(), out t); int sd = t.Right; int st = t.Bottom; windowWidth = t.Right - t.Left; windowHeight = t.Bottom - t.Top; device.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased;// you can set another text mode //device.DrawText("http://detolly.no | Private Cheat | Copyright 2017.", font, new SharpDX.Mathematics.Interop.RawRectangleF(t.Left + 5, t.Top + 20, t.Right + 600, t.Bottom + 20), redBrush); //device.DrawText("F1 | Aimbot: " + (aimbottoggle ? "On." : "Off.") + " | Fov: " + currentFov, font, new SharpDX.Mathematics.Interop.RawRectangleF(t.Left + 5, t.Top + 60, t.Right + 600, t.Bottom + 100), redBrush); //device.DrawText("F2 | Wallhack: " + (wallhacktoggle ? "On." : "Off."), font, new SharpDX.Mathematics.Interop.RawRectangleF(t.Left + 5, t.Top + 100, t.Right + 600, t.Bottom + 100), redBrush); //device.DrawText("F3 | ESP: " + (esptoggle ? "On." : "Off."), font, new SharpDX.Mathematics.Interop.RawRectangleF(t.Left + 5, t.Top + 140, 600, t.Bottom + 140), redBrush); //device.DrawText("F6 | Triggerbot: " + (triggertoggle ? "On." : "Off."), font, new SharpDX.Mathematics.Interop.RawRectangleF(t.Left + 5, t.Top + 220, t.Right + 600, t.Bottom + 220), redBrush); //device.DrawText("F4 | Bhop: " + (bhoptoggle ? "On." : "Off."), font, new SharpDX.Mathematics.Interop.RawRectangleF(t.Left + 5, t.Top + 180, t.Right + 600, t.Bottom + 220), redBrush); //var g22 = getMatrixFloats2(csgo, bClient); //string g22text = ""; //for (int i = 0; i < g22.Length; i++) //{ // for (int x = 0; x < g22[i].Length; x++) // { // g22text += g22[i][x] + "\t"; // } // g22text += "\r\n"; //} //g22text += "First Length: " + g22.Length + "\tSecond Length: " + g22[0].Length; //device.DrawText( // g22text, // font, // new SharpDX.Mathematics.Interop.RawRectangleF(0,100000,100000,windowHeight/2), // blueBrush // ); //device.DrawText("Player Position: " + getLocalPlayerPosition(vam, bClient).x + ", " + getLocalPlayerPosition(vam, bClient).y + ", " + getLocalPlayerPosition(vam, bClient).z // , font // , new SharpDX.Mathematics.Interop.RawRectangleF(0, windowHeight - 20, 1000, windowHeight) // , redBrush); Esp(); device.EndDraw(); seethroughthing(); Aimbot(); tragger(); noflash(); if (performance) { Thread.Sleep(5); } } }
public static void Swap(BSP me, int a1, int a2) { // Entities foreach (Entity e in me.Entities) { Vector3D origin = e.Origin; double temp = origin[a1]; origin[a1] = origin[a2]; origin[a2] = temp; e.Origin = origin; } // Planes foreach (Plane p in me.Planes) { Vector3D normal = p.Normal; double temp = normal[a1]; normal[a1] = normal[a2]; normal[a2] = temp; p.Normal = normal; } // Vertices foreach (Vertex v in me.Vertices) { Vector3D vertex = v.Vector; double temp = vertex[a1]; vertex[a1] = vertex[a2]; vertex[a2] = temp; v.Vector = vertex; } // Nodes foreach (Node n in me.Nodes) { Vector3D mins = n.Mins; Vector3D maxs = n.Maxs; double mintemp = mins[a1]; mins[a1] = mins[a2]; mins[a2] = mintemp; double maxtemp = maxs[a1]; maxs[a1] = maxs[a2]; maxs[a2] = maxtemp; n.Mins = mins; n.Maxs = maxs; } // Leaves foreach (Leaf l in me.Leaves) { Vector3D mins = l.Mins; Vector3D maxs = l.Maxs; double mintemp = mins[a1]; mins[a1] = mins[a2]; mins[a2] = mintemp; double maxtemp = maxs[a1]; maxs[a1] = maxs[a2]; maxs[a2] = maxtemp; l.Mins = mins; l.Maxs = maxs; } // Models foreach (Model m in me.Models) { Vector3D mins = m.Mins; Vector3D maxs = m.Maxs; double mintemp = mins[a1]; mins[a1] = mins[a2]; mins[a2] = mintemp; double maxtemp = maxs[a1]; maxs[a1] = maxs[a2]; maxs[a2] = maxtemp; m.Mins = mins; m.Maxs = maxs; } // Texinfos foreach (TexInfo ti in me.TexInfo) { Vector3D sAxis = ti.SAxis; Vector3D tAxis = ti.TAxis; double stemp = sAxis[a1]; sAxis[a1] = sAxis[a2]; sAxis[a2] = stemp; double ttemp = tAxis[a1]; tAxis[a1] = tAxis[a2]; tAxis[a2] = ttemp; ti.SAxis = sAxis; ti.TAxis = tAxis; } }
// METHODS public void readBSP() { try { byte[] theLump = new byte[0]; byte[] vis = new byte[0]; BSPObject = new BSP(BSPFile.FullName); Console.WriteLine("Opening " + BSPFile.FullName); for (int i = 0; i < 18; i++) { try { theLump = readLumpNum(i); switch (i) { case 0: BSPObject.Entities = Entity.createLump(theLump); break; case 1: BSPObject.Planes = Plane.createLump(theLump); break; case 2: BSPObject.Textures = Texture.createLump(theLump); break; case 3: BSPObject.Materials = Texture.createLump(theLump); break; case 4: BSPObject.Vertices = Vertex.createLump(theLump); break; case 5: BSPObject.Normals = new Lump <LumpObject>(theLump.Length, 0); break; case 6: BSPObject.Indices = new NumList(theLump, NumList.dataType.UINT); break; case 7: vis = theLump; break; case 8: BSPObject.Nodes = Node.createLump(theLump); break; case 9: BSPObject.Faces = Face.createLump(theLump); break; case 10: BSPObject.Lightmaps = new NumList(theLump, NumList.dataType.UBYTE); break; case 11: BSPObject.Leaves = Leaf.createLump(theLump); break; case 12: BSPObject.MarkSurfaces = new NumList(theLump, NumList.dataType.UINT); break; case 13: BSPObject.MarkBrushes = new NumList(theLump, NumList.dataType.UINT); break; case 14: BSPObject.Models = Model.createLump(theLump); break; case 15: BSPObject.Brushes = Brush.createLump(theLump); break; case 16: BSPObject.BrushSides = BrushSide.createLump(theLump); break; case 17: BSPObject.TexInfo = TexInfo.createLump(theLump); break; } } catch { dumpLump(theLump); } } try { int visLength = BSPObject.Leaves[2].PVS; if (visLength > 0 && vis.Length > 0) { BSPObject.Vis = new Lump <LumpObject>(vis, visLength); } } catch (ArgumentOutOfRangeException) {; } if (BSPObject.Vis == null) { BSPObject.Vis = new Lump <LumpObject>(0, 0); } BSPObject.printBSPReport(); } catch (System.IO.IOException) { Console.WriteLine("Unable to access BSP file! Is it open in another program?"); } br.Close(); }
public static void ReplacingCorruption(BSP me, CorruptionValue values, double range, double percentage) { Random rand = new Random(); // Populate a list with all possible values to be replaced List <double> valuesToReplace = new List <double>(); foreach (Vertex v in me.Vertices) { for (int i = 0; i < 2; i++) { if (!valuesToReplace.Contains(v[i])) { valuesToReplace.Add(v[i]); } } } foreach (Plane p in me.Planes) { if (!valuesToReplace.Contains(p.Dist)) { valuesToReplace.Add(p.Dist); } } // Figure out, based on the probability of corruption, how many values to corrupt from the list int numCorruptions = (int)Math.Ceiling(valuesToReplace.Count * percentage); // Perform that many corruptions for (int i = 0; i < numCorruptions; i++) { int indexToCorrupt = rand.Next(0, valuesToReplace.Count); double valueToCorrupt = valuesToReplace[indexToCorrupt]; double newValue = 0.0; if (values == CorruptionValue.RELATIVE) { newValue = valueToCorrupt + (rand.NextDouble() * 2.0 * range) - range; } else if (values == CorruptionValue.RANDOM) { newValue = (rand.NextDouble() * 2.0 * range) - range; } // Replace EVERY instance of the value with the corruption valuesToReplace[indexToCorrupt] = newValue; foreach (Vertex v in me.Vertices) { for (int j = 0; j < 3; j++) { if (v[j] == valueToCorrupt) { v[j] = newValue; } } } foreach (Plane p in me.Planes) { if (p.Dist == valueToCorrupt) { p.Dist = newValue; } } } }
private WalkResult Walk(BSP bsp) { var pair = bsp.Split(); if (pair.Length == 2) { return(JoinResult( Walk(pair[0]), Walk(pair[1]) )); } else { var firstIdx3 = coct.CollisionList.Count; var vifPacketIndices = new List <ushort>(); foreach (var point in pair[0].Points) { var mesh = point.bigMesh; vifPacketIndices.AddRange(mesh.vifPacketIndices); foreach (var set in TriangleStripsToTriangleFans(mesh.triangleStripList)) { var quad = set.Count == 4; var v1 = mesh.vertexList[set[0]]; var v2 = mesh.vertexList[set[1]]; var v3 = mesh.vertexList[set[2]]; var v4 = quad ? mesh.vertexList[set[3]] : Vector3.Zero; coct.CompleteAndAdd( new Collision { Vertex1 = helper.AllocateVertex(v1.X, -v1.Y, -v1.Z), // why -Y and -Z ? Vertex2 = helper.AllocateVertex(v2.X, -v2.Y, -v2.Z), Vertex3 = helper.AllocateVertex(v3.X, -v3.Y, -v3.Z), Vertex4 = Convert.ToInt16(quad ? helper.AllocateVertex(v4.X, -v4.Y, -v4.Z) : -1), SurfaceFlagsIndex = helper.AllocateSurfaceFlags(mesh.matDef.surfaceFlags), }, inflate: 1 ); } } var lastIdx3 = coct.CollisionList.Count; var firstIdx2 = coct.CollisionMeshList.Count; var collisionMesh = coct.CompleteAndAdd( new CollisionMesh { CollisionStart = Convert.ToUInt16(firstIdx3), CollisionEnd = Convert.ToUInt16(lastIdx3), } ); vifPacketRenderingGroup.Add( vifPacketIndices .Distinct() .ToArray() ); return(new WalkResult { meshIndex = firstIdx2, }); } }
/// <summary> /// Builds a Displacement <see cref="Mesh"/> from the <see cref="DisplacementInfo"/> referenced by /// <paramref name="face"/>, with UVs calculated from <see cref="Face.textureInfo"/> using /// <paramref name="dims"/> as the <see cref="Texture2D"/> width and height. /// </summary> /// <param name="bsp">The <see cref="BSP"/> object which <paramref name="face"/> came from.</param> /// <param name="face">A face referencing a <see cref="DisplacementInfo"/> and a <see cref="TextureInfo"/>.</param> /// <param name="dims">The dimensions of the <see cref="Texture2D"/> to map onto the resulting <see cref="Mesh"/>.</param> /// <returns>The <see cref="Mesh"/> created from the <see cref="DisplacementInfo"/>.</returns> public static Mesh CreateDisplacementMesh(BSP bsp, Face face, Vector2 dims) { Mesh mesh = null; if (face.NumEdgeIndices > 0) { mesh = LoadVerticesFromEdges(bsp, face); } else { Debug.LogWarning("Cannot create displacement, face contains no edges."); return(null); } Vector3[] faceCorners = mesh.vertices; int[] faceTriangles = mesh.triangles; if (faceCorners.Length != 4 || faceTriangles.Length != 6) { Debug.LogWarning("Cannot create displacement mesh because " + faceCorners.Length + " corners and " + faceTriangles.Length + " triangle indices."); return(null); } Displacement displacement = bsp.dispInfos[face.DisplacementIndex]; int numSideTriangles = (int)Mathf.Pow(2, displacement.Power); DisplacementVertex[] displacementVertices = displacement.Vertices.ToArray(); Vector3[] corners = new Vector3[4]; Vector3 start = displacement.StartPosition.SwizzleYZ() * inch2MeterScale; if ((faceCorners[faceTriangles[0]] - start).sqrMagnitude < .01f) { corners[0] = faceCorners[faceTriangles[0]]; corners[1] = faceCorners[faceTriangles[1]]; corners[2] = faceCorners[faceTriangles[5]]; corners[3] = faceCorners[faceTriangles[4]]; } else if ((faceCorners[faceTriangles[1]] - start).sqrMagnitude < .01f) { corners[0] = faceCorners[faceTriangles[1]]; corners[1] = faceCorners[faceTriangles[4]]; corners[2] = faceCorners[faceTriangles[0]]; corners[3] = faceCorners[faceTriangles[5]]; } else if ((faceCorners[faceTriangles[5]] - start).sqrMagnitude < .01f) { corners[0] = faceCorners[faceTriangles[5]]; corners[1] = faceCorners[faceTriangles[0]]; corners[2] = faceCorners[faceTriangles[4]]; corners[3] = faceCorners[faceTriangles[1]]; } else if ((faceCorners[faceTriangles[4]] - start).sqrMagnitude < .01f) { corners[0] = faceCorners[faceTriangles[4]]; corners[1] = faceCorners[faceTriangles[5]]; corners[2] = faceCorners[faceTriangles[1]]; corners[3] = faceCorners[faceTriangles[0]]; } else { Debug.LogWarning("Cannot create displacement mesh because start position isn't one of the face corners.\n" + "Start position: " + start + "\n" + "Corners: " + faceCorners[faceTriangles[0]] + " " + faceCorners[faceTriangles[1]] + " " + faceCorners[faceTriangles[5]] + " " + faceCorners[faceTriangles[4]]); return(null); } Vector3[] offsets = new Vector3[displacementVertices.Length]; for (int i = 0; i < displacementVertices.Length; ++i) { offsets[i] = displacementVertices[i].Normal.SwizzleYZ() * displacementVertices[i].Magnitude * inch2MeterScale; } Vector2[] uv = new Vector2[4]; Vector2[] uv2 = new Vector2[4]; mesh.vertices = corners; mesh.uv = uv; mesh.uv2 = uv2; mesh.CalculateUVs(bsp.GetTextureInfo(face), dims); mesh.CalculateTerrainVertices(offsets, numSideTriangles); mesh.triangles = BuildDisplacementTriangles(numSideTriangles); mesh.NegateVs(); mesh.RecalculateNormals(); mesh.RecalculateBounds(); return(mesh); }
// The bloated unused "null" lump. We can just set its length to 0. // Depending on the complexity of the map, this can reduce size a good deal. public static void optimizeNormals(BSP me) { me.Normals.Length = 0; Console.WriteLine("Deleted normals lump"); }
public static void Flip(BSP me, int axis) { // Entities foreach (Entity e in me.Entities) { Vector3D origin = e.Origin; origin[axis] = -origin[axis]; e.Origin = origin; } // Planes foreach (Plane p in me.Planes) { Vector3D normal = p.Normal; normal[axis] = -normal[axis]; p.Normal = normal; } // Vertices foreach (Vertex v in me.Vertices) { Vector3D vertex = v.Vector; vertex[axis] = -vertex[axis]; v.Vector = vertex; } // Nodes foreach (Node n in me.Nodes) { Vector3D mins = n.Mins; Vector3D maxs = n.Maxs; double minAxis = mins[axis]; double maxAxis = maxs[axis]; mins[axis] = -maxAxis; maxs[axis] = -minAxis; n.Mins = mins; n.Maxs = maxs; } // Leaves foreach (Leaf l in me.Leaves) { Vector3D mins = l.Mins; Vector3D maxs = l.Maxs; double minAxis = mins[axis]; double maxAxis = maxs[axis]; mins[axis] = -maxAxis; maxs[axis] = -minAxis; l.Mins = mins; l.Maxs = maxs; } // Models foreach (Model m in me.Models) { Vector3D mins = m.Mins; Vector3D maxs = m.Maxs; double minAxis = mins[axis]; double maxAxis = maxs[axis]; mins[axis] = -maxAxis; maxs[axis] = -minAxis; m.Mins = mins; m.Maxs = maxs; } // Texinfos foreach (TexInfo ti in me.TexInfo) { Vector3D sAxis = ti.SAxis; Vector3D tAxis = ti.TAxis; sAxis[axis] = -sAxis[axis]; tAxis[axis] = -tAxis[axis]; ti.SAxis = sAxis; ti.TAxis = tAxis; } }
// There's two ways to optimize indices: the quick, potentially erroneous way, or the slow, // safe way. The quick way simply finds the largest number in the indices lump, creates a // new lump which only goes that high, then sets all face "indices" references to zero. Since // all index groups follow the same pattern (0,1,2,0,2,3,0,3,4,etc.) then the face will simply // use as much of the index list as it needs. // The long way is to analyze each group to ensure commonality, and reuse parts of one group // if it matches another. // In theory, only the slow way should be used because the quick way makes too many assumptions // about the data, but in practice the data ALWAYS follows the same pattern. Therefore either // method should give the same result, and should crush this lump to 200 bytes or less. public static void optimizeIndices(BSP me) { // TODO }
public void TestBSPByFilename() { var bsp = new BSP("testdata/map.bsp"); Assert.NotNull(bsp); }
public override void WriteMap(BrushMap map) { int brushCount = 0; int patchCount = 0; int meshCount = 0; int faceCount = 0; int vertCount = 0; int triCount = 0; BSP bsp = new BSP(map); bsp.TestDivide(); bsp.GridDivide(map, 6, 1, 6); //Sorting.SpaceSort ss = new Sorting.SpaceSort(map); Dictionary<string, int> textures = new Dictionary<string,int>(); foreach (Entity e in map.Entities) { foreach (Brush b in e.Brushes) { brushCount++; faceCount += b.Faces.Count; foreach (Face f in b.Faces) { vertCount += f.Vertices.Count; if (textures.ContainsKey(f.TexName)) textures[f.TexName] = textures[f.TexName] + 1; else textures[f.TexName] = 1; triCount += f.Indices.Count / 3; } } foreach (Patch p in e.Patches) { if (p.LiteralMesh) meshCount++; else patchCount++; vertCount += p.Columns * p.Rows; triCount += p.Columns * p.Rows * 2; if (textures.ContainsKey(p.TextureName)) textures[p.TextureName] = textures[p.TextureName] + 1; else textures[p.TextureName] = 1; } } int texOnce = 0; int texMany = 0; foreach (string s in textures.Keys) { if (textures[s] > 1) texMany++; else texOnce++; } Console.WriteLine(""); Console.WriteLine("Map Info:"); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("GEOMETRY"); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine(String.Format(" {0} entities", map.Entities.Count)); Console.WriteLine(String.Format(" {0} brushes", brushCount)); Console.WriteLine(String.Format(" {0} faces", faceCount)); Console.WriteLine(String.Format(" {0} patches", patchCount)); Console.WriteLine(String.Format(" {0} meshes", meshCount)); Console.WriteLine(String.Format(" {0} vertices", vertCount)); Console.WriteLine(String.Format(" {0} triangles", triCount)); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("TEXTURES"); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine(String.Format(" {0} Total Textures", textures.Keys.Count)); Console.WriteLine(String.Format(" {0} Reused", texMany)); Console.WriteLine(String.Format(" {0} Unique", texOnce)); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("MEMORY ESTIMATE"); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine(String.Format(" {0} Vertices", GetFileSizeString(vertCount * sizeof(float) * 5))); Console.WriteLine(String.Format(" {0} Indices", GetFileSizeString(triCount * 3 * sizeof(short)))); Console.WriteLine(String.Format(" {0} All Geometry", GetFileSizeString(vertCount * sizeof(float) * 5 + triCount * 3 * sizeof(short)))); Console.WriteLine(String.Format(" {0} Textures", map.Entities.Count)); }
public virtual void Run() { DateTime begin = DateTime.Now; try { Entities output = null; if (doomMap != null) { // If this is a Doom map extracted from a WAD //Window.setProgress(jobnum, 0, doomMap.getSubSectors().size(), "Decompiling..."); WADDecompiler decompiler = new WADDecompiler(doomMap, jobnum, this); output = decompiler.decompile(); } else { DecompilerThread.OnMessage(this, "Opening file " + BSPFile.FullName); //Window.setProgress(jobnum, 0, 1, "Reading..."); BSPReader reader = new BSPReader(BSPFile, openAs); reader.readBSP(); //if (!reader.WAD) { BSPObject = reader.BSPData; /*try { Window.setProgress(jobnum, 0, reader.BSPData.getBrushes().size() + reader.BSPData.getEntities().size(), "Decompiling..."); } catch (System.NullReferenceException e) { try { Window.setProgress(jobnum, 0, reader.BSPData.getLeaves().size() + reader.BSPData.getEntities().size(), "Decompiling..."); } catch (System.NullReferenceException f) { Window.setProgress(jobnum, 0, 1, "Decompiling..."); // What's going on here? Put in a failsafe progress bar for now } }*/ switch (reader.Version){ case mapType.TYPE_QUAKE: //DecompilerThread.OnMessage(this, "ERROR: Algorithm for decompiling Quake BSPs not written yet.",Window.VERBOSITY_ALWAYS); //throw new java.lang.Exception(); // Throw an exception to the exception handler to indicate it didn't work QuakeDecompiler decompiler29 = new QuakeDecompiler(reader.BSPData, jobnum, this); output = decompiler29.decompile(); break; case mapType.TYPE_NIGHTFIRE: BSP42Decompiler decompiler42 = new BSP42Decompiler(reader.BSPData, jobnum, this); output = decompiler42.decompile(); break; case mapType.TYPE_QUAKE2: case mapType.TYPE_SIN: case mapType.TYPE_SOF: case mapType.TYPE_DAIKATANA: BSP38Decompiler decompiler38 = new BSP38Decompiler(reader.BSPData, jobnum, this); output = decompiler38.decompile(); break; case mapType.TYPE_SOURCE17: case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_DMOMAM: case mapType.TYPE_VINDICTUS: case mapType.TYPE_TACTICALINTERVENTION: SourceBSPDecompiler sourceDecompiler = new SourceBSPDecompiler(reader.BSPData, jobnum, this); output = sourceDecompiler.decompile(); break; case mapType.TYPE_QUAKE3: case mapType.TYPE_RAVEN: case mapType.TYPE_COD: case mapType.TYPE_COD2: case mapType.TYPE_COD4: case mapType.TYPE_STEF2: case mapType.TYPE_STEF2DEMO: case mapType.TYPE_MOHAA: case mapType.TYPE_FAKK: BSP46Decompiler decompiler46 = new BSP46Decompiler(reader.BSPData, jobnum, this); output = decompiler46.decompile(); break; case mapType.TYPE_DOOM: case mapType.TYPE_HEXEN: foreach (DoomMap map in reader.DoomMaps) { WADDecompiler wadDecompiler = new WADDecompiler(map, jobnum, this); Entities holyshit = wadDecompiler.decompile(); MAPMaker.outputMaps(holyshit, map.MapName, map.Folder + map.WadName + "\\", map.Version); } break; default: DecompilerThread.OnMessage(this, "ERROR: Unknown BSP version: " + reader.Version); throw new System.Exception(); // Throw an exception to the exception handler to indicate it didn't work } //} } if (output != null) { //Window.setProgress(jobnum, 1, 1, "Saving..."); if (doomMap == null) { MAPMaker.outputMaps(output, BSPObject.MapNameNoExtension, BSPObject.Folder, BSPObject.Version); } else { MAPMaker.outputMaps(output, doomMap.MapName, doomMap.Folder + doomMap.WadName + "\\", doomMap.Version); } } //Window.setProgress(jobnum, 1, 1, "Done!"); //System.Drawing.Color tempAux = System.Drawing.Color.FromArgb(64, 192, 64); //Window.setProgressColor(jobnum, ref tempAux); DateTime end = DateTime.Now; DecompilerThread.OnMessage(this, "Time taken: " + (end - begin).ToString() + (char) 0x0D + (char) 0x0A); OnFinish(this, jobnum); } catch (System.OutOfMemoryException) { string st = ""; if (openAs != mapType.TYPE_UNDEFINED) { st = "VM ran out of memory on job " + (jobnum + 1) + ". Are you using \"Open as...\" with the wrong game?" + (char) 0x0D + (char) 0x0A + "If not, please let me know on the issue tracker!" + (char) 0x0D + (char) 0x0A + "http://code.google.com/p/jbn-bsp-lump-tools/issues/entry"; } else { st = "VM ran out of memory on job " + (jobnum + 1) + "." + (char) 0x0D + (char) 0x0A + "Please let me know on the issue tracker!" + (char) 0x0D + (char) 0x0A + "http://code.google.com/p/jbn-bsp-lump-tools/issues/entry"; } //Window.setProgress(jobnum, 1, 1, "ERROR! See log!"); //System.Drawing.Color tempAux4 = System.Drawing.Color.FromArgb(255, 128, 128); //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" //Window.setProgressColor(jobnum, ref tempAux4); OnError(this, st); } catch (Exception e) { string st; if (openAs != mapType.TYPE_UNDEFINED) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" st="" + (char) 0x0D + (char) 0x0A + "Exception caught in job " + (jobnum + 1) + ": " + e + (char) 0x0D + (char) 0x0A + "Are you using \"Open as...\" with the wrong game?" + (char) 0x0D + (char) 0x0A + "If not, please let me know on the issue tracker!" + (char) 0x0D + (char) 0x0A + "http://code.google.com/p/jbn-bsp-lump-tools/issues/entry"; } else { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" st="" + (char) 0x0D + (char) 0x0A + "Exception caught in job " + (jobnum + 1) + ": " + e + (char) 0x0D + (char) 0x0A + "Please let me know on the issue tracker!" + (char) 0x0D + (char) 0x0A + "http://code.google.com/p/jbn-bsp-lump-tools/issues/entry"; } /*System.String stackTrace = "Stack Trace: " + (char) 0x0D + (char) 0x0A; StackTraceElement[] trace = e.getStackTrace(); for (int i = 0; i < trace.length; i++) { stackTrace += (trace[i].toString() + Window.LF); } //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" DecompilerThread.OnMessage(this, e.Message + Window.LF + stackTrace); DecompilerThread.OnMessage(this, ); Window.setProgress(jobnum, 1, 1, "ERROR! See log!"); System.Drawing.Color tempAux3 = System.Drawing.Color.FromArgb(255, 128, 128); //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" Window.setProgressColor(jobnum, ref tempAux3);*/ OnError(this, st); } finally { doomMap = null; BSPObject = null; BSPFile = null; Thread.CurrentThread.Abort(); } /*else { Window.print("Job " + (jobnum + 1) + " aborted by user."); Window.print(" When: While initializing job."); DecompilerThread.OnMessage(this, ); Window.setProgress(jobnum, 1, 1, "Aborted!"); System.Drawing.Color tempAux5 = System.Drawing.Color.FromArgb(255, 128, 128); //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" Window.setProgressColor(jobnum, ref tempAux5); SupportClass.ThreadClass.Current().Interrupt(); }*/ //Window.setAbortButtonEnabled(jobnum, false); }
public override void Run(CompileContext context) { CompileErrors = new List <Error>(); genParticleManifest = GetParameterString().Contains("-particlemanifest"); incParticleManifest = GetParameterString().Contains("-incparticlemanifest"); incSoundscape = GetParameterString().Contains("-incsoundscape"); incLevelSounds = GetParameterString().Contains("-inclevelsounds"); excludeDir = GetParameterString().Contains("-excludedir"); excludeFile = GetParameterString().Contains("-excludefile"); //TODO try to find a way to cut down on duplicate processes between utility and pack steps try { CompilePalLogger.LogLine("\nCompilePal - Utilities"); Keys.vmtTextureKeyWords = File.ReadAllLines(System.IO.Path.Combine(keysFolder, "texturekeys.txt")).ToList(); Keys.vmtMaterialKeyWords = File.ReadAllLines(System.IO.Path.Combine(keysFolder, "materialkeys.txt")).ToList(); Keys.vmfSoundKeys = File.ReadAllLines(System.IO.Path.Combine(keysFolder, "vmfsoundkeys.txt")).ToList(); Keys.vmfMaterialKeys = File.ReadAllLines(System.IO.Path.Combine(keysFolder, "vmfmaterialkeys.txt")).ToList(); Keys.vmfModelKeys = File.ReadAllLines(System.IO.Path.Combine(keysFolder, "vmfmodelkeys.txt")).ToList(); excludedDirectories = new List <string>(); excludedFiles = new List <string>(); CompilePalLogger.LogLine("Finding sources of game content..."); gameFolder = context.Configuration.GameFolder; sourceDirectories = BSPPack.BSPPack.GetSourceDirectories(gameFolder); bspPath = context.CopyLocation; //Parse parameters to get ignore directories if (excludeDir) { char[] paramChars = GetParameterString().ToCharArray(); List <string> parameters = ParseParameters(paramChars); //Get excluded directories from parameter list foreach (string parameter in parameters) { if (parameter.Contains("excludedir")) { var @dirPath = parameter.Replace("\"", "").Replace("excludedir ", "").TrimEnd(' '); //Test that directory exists if (Directory.Exists(dirPath)) { excludedDirectories.Add(dirPath); } else { CompilePalLogger.LogCompileError($"Could not find directory: {dirPath}\n", new Error($"Could not find directory: {dirPath}\n", ErrorSeverity.Warning)); } } } } if (excludeFile) { char[] paramChars = GetParameterString().ToCharArray(); List <string> parameters = ParseParameters(paramChars); //Get excluded files from parameter list foreach (string parameter in parameters) { if (parameter.Contains("excludefile")) { var @filePath = parameter.Replace("\"", "").Replace("excludefile ", "").Replace('/', '\\').ToLower().TrimEnd(' '); //Test that file exists if (File.Exists(filePath)) { excludedFiles.Add(filePath); } else { CompilePalLogger.LogCompileError($"Could not find file: {filePath}\n", new Error($"Could not find file: {filePath}\n", ErrorSeverity.Warning)); } } } } if (genParticleManifest) { if (!File.Exists(bspPath)) { throw new FileNotFoundException(); } CompilePalLogger.LogLine("Reading BSP..."); BSP map = new BSP(new FileInfo(bspPath)); ParticleManifest manifest = new ParticleManifest(sourceDirectories, excludedDirectories, excludedFiles, map, bspPath, gameFolder); //Set fields in bsppack so manifest gets detected correctly BSPPack.BSPPack.genParticleManifest = true; BSPPack.BSPPack.particleManifest = manifest.particleManifest; } if (incParticleManifest) { CompilePalLogger.LogLine("Attempting to update particle manifest"); bool success = UpdateManifest("_particles.txt"); if (!success) { CompilePalLogger.LogCompileError("Could not update manifest!\n", new Error("Could not update manifest!", ErrorSeverity.Error)); } } if (incLevelSounds) { CompilePalLogger.LogLine("Attempting to update level sounds"); bool success = UpdateManifest("_level_sounds.txt"); if (!success) { CompilePalLogger.LogCompileError("Could not update level sounds!\n", new Error("Could not update level sounds!", ErrorSeverity.Error)); } } if (incSoundscape) { CompilePalLogger.LogLine("Attempting to update soundscape"); //Get all script directories List <string> directories = new List <string>(); foreach (string directory in sourceDirectories) { if (Directory.Exists(directory + "\\scripts\\")) { directories.Add(directory + "\\scripts\\"); } } bool success = UpdateManifest("soundscapes_", directories, true); if (!success) { CompilePalLogger.LogCompileError("Could not update soundscape!\n", new Error("Could not update soundscape!", ErrorSeverity.Error)); } } } catch (FileNotFoundException) { CompilePalLogger.LogCompileError($"Could not find {context.CopyLocation}\n", new Error($"Could not find {context.CopyLocation}", ErrorSeverity.Error)); } catch (Exception e) { CompilePalLogger.LogLine("Something broke:"); CompilePalLogger.LogCompileError($"{e}\n", new Error(e.ToString(), "CompilePal Internal Error", ErrorSeverity.FatalError)); } }
// METHODS public void readBSP() { try { version = Version; byte[] theLump = new byte[0]; BSPObject = new BSP(BSPFile.FullName, version); switch(version) { case mapType.TYPE_VINDICTUS: case mapType.TYPE_TACTICALINTERVENTION: case mapType.TYPE_SOURCE17: case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_DMOMAM: DecompilerThread.OnMessage(this, "Source BSP"); stream.Seek(8, SeekOrigin.Begin); int test = br.ReadInt32(); if(bigEndian) { test = DataReader.swapEndian(test); } if(test < 1032) { // If what's usually the offset is less than the length of the header and directory isL4D2 = true; // This is Left 4 Dead 2 } // Lump 35, Game lump // Need to handle this here in order to detect Vindictus maps. // This lump SUCKS. It's a lump containing nested lumps for game specific data. // What we need out of it is the static prop lump. theLump = readLumpNum(35); try { readGameLump(theLump, lumpOffset); } catch { dumpLump(theLump); } for(int i=0;i<64;i++) { try { switch(i) { case 0: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; case 1: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 2: theLump = readLumpNum(i); BSPObject.TexDatas = SourceTexData.createLump(theLump); break; case 3: theLump = readLumpNum(i); BSPObject.Vertices = Vertex.createLump(theLump, version); break; case 5: theLump = readLumpNum(i); BSPObject.Nodes = Node.createLump(theLump, version); break; case 6: theLump = readLumpNum(i); BSPObject.TexInfo = TexInfo.createLump(theLump, version); break; case 7: theLump = readLumpNum(i); BSPObject.Faces = Face.createLump(theLump, version); break; case 10: theLump = readLumpNum(i); BSPObject.Leaves = Leaf.createLump(theLump, version); break; case 12: theLump = readLumpNum(i); BSPObject.Edges = Edge.createLump(theLump, version); break; case 13: theLump = readLumpNum(i); BSPObject.SurfEdges = new NumList(theLump, NumList.dataType.INT); break; case 14: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 17: theLump = readLumpNum(i); if(version == mapType.TYPE_VINDICTUS) { BSPObject.MarkBrushes = new NumList(theLump, NumList.dataType.UINT); } else { BSPObject.MarkBrushes = new NumList(theLump, NumList.dataType.USHORT); } break; case 18: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 19: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; case 26: theLump = readLumpNum(i); BSPObject.DispInfos = SourceDispInfo.createLump(theLump, version); break; case 27: theLump = readLumpNum(i); BSPObject.OriginalFaces = Face.createLump(theLump, version); break; case 33: theLump = readLumpNum(i); BSPObject.DispVerts = SourceDispVertex.createLump(theLump); break; case 40: theLump = readLumpNum(i); if (Settings.extractZip) { Console.Write("Extracting internal PAK file... "); writeLump(BSPObject.MapName+".zip", theLump); } break; case 42: theLump = readLumpNum(i); BSPObject.Cubemaps = SourceCubemap.createLump(theLump, version); break; case 43: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 44: theLump = readLumpNum(i); BSPObject.TexTable = new NumList(theLump, NumList.dataType.INT); break; case 48: theLump = readLumpNum(i); BSPObject.DispTris = new NumList(theLump, NumList.dataType.USHORT); break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_NIGHTFIRE: DecompilerThread.OnMessage(this, "BSP v42 (Nightfire)"); for(int i=0;i<18;i++) { try { switch(i) { case 0: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; case 1: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 2: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 3: theLump = readLumpNum(i); BSPObject.Materials = Texture.createLump(theLump, version); break; case 4: theLump = readLumpNum(i); BSPObject.Vertices = Vertex.createLump(theLump, version); break; case 9: theLump = readLumpNum(i); BSPObject.Faces = Face.createLump(theLump, version); break; case 11: theLump = readLumpNum(i); BSPObject.Leaves = Leaf.createLump(theLump, version); break; case 13: theLump = readLumpNum(i); BSPObject.MarkBrushes = new NumList(theLump, NumList.dataType.UINT); break; case 14: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 15: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 16: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; case 17: theLump = readLumpNum(i); BSPObject.TexInfo = TexInfo.createLump(theLump, version); break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_QUAKE2: case mapType.TYPE_SIN: case mapType.TYPE_DAIKATANA: case mapType.TYPE_SOF: DecompilerThread.OnMessage(this, "BSP v38 (Quake 2/SiN/Daikatana/Soldier of Fortune)"); for(int i=0;i<19;i++) { try { switch(i) { case 0: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; case 1: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 2: theLump = readLumpNum(i); BSPObject.Vertices = Vertex.createLump(theLump, version); break; case 4: theLump = readLumpNum(i); BSPObject.Nodes = Node.createLump(theLump, version); break; case 5: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 6: theLump = readLumpNum(i); BSPObject.Faces = Face.createLump(theLump, version); break; case 8: theLump = readLumpNum(i); BSPObject.Leaves = Leaf.createLump(theLump, version); break; case 10: theLump = readLumpNum(i); BSPObject.MarkBrushes = new NumList(theLump, NumList.dataType.USHORT); break; case 11: theLump = readLumpNum(i); BSPObject.Edges = Edge.createLump(theLump, version); break; case 12: theLump = readLumpNum(i); BSPObject.SurfEdges = new NumList(theLump, NumList.dataType.INT); break; case 13: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 14: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 15: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; /*case 18: theLump = readLumpNum(i); BSPObject.AreaPortals = AreaPortal.createLump(theLump, version); break;*/ } } catch { dumpLump(theLump); } } break; case mapType.TYPE_QUAKE: DecompilerThread.OnMessage(this, "Quake 1/Half-life BSP"); for (int i = 0; i < 15; i++) { try { switch (i) { case 0: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; case 1: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 2: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 3: theLump = readLumpNum(i); BSPObject.Vertices = Vertex.createLump(theLump, version); break; case 5: theLump = readLumpNum(i); BSPObject.Nodes = Node.createLump(theLump, version); break; case 6: theLump = readLumpNum(i); BSPObject.TexInfo = TexInfo.createLump(theLump, version); break; case 7: theLump = readLumpNum(i); BSPObject.Faces = Face.createLump(theLump, version); break; case 10: theLump = readLumpNum(i); BSPObject.Leaves = Leaf.createLump(theLump, version); break; case 11: theLump = readLumpNum(i); BSPObject.MarkSurfaces = new NumList(theLump, NumList.dataType.USHORT); break; case 12: theLump = readLumpNum(i); BSPObject.Edges = Edge.createLump(theLump, version); break; case 13: theLump = readLumpNum(i); BSPObject.SurfEdges = new NumList(theLump, NumList.dataType.INT); break; case 14: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_STEF2: case mapType.TYPE_STEF2DEMO: DecompilerThread.OnMessage(this, "Star Trek Elite Force 2 BSP"); for (int i = 0; i < 30; i++) { try { switch (i) { case 0: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 1: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 5: theLump = readLumpNum(i); BSPObject.Faces = Face.createLump(theLump, version); break; case 6: theLump = readLumpNum(i); BSPObject.Vertices = Vertex.createLump(theLump, version); break; case 12: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; case 13: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 15: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 16: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_MOHAA: DecompilerThread.OnMessage(this, "MOHAA BSP (modified id Tech 3)"); for(int i=0;i<28;i++) { try { switch (i) { case 0: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 1: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 3: theLump = readLumpNum(i); BSPObject.Faces = Face.createLump(theLump, version); break; case 4: theLump = readLumpNum(i); BSPObject.Vertices = Vertex.createLump(theLump, version); break; case 11: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; case 12: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 13: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 14: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; //case 24: // theLump = readLumpNum(i); // BSPObject.StaticProps = StaticProp.createLump(theLump); // break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_FAKK: DecompilerThread.OnMessage(this, "Heavy Metal FAKK² BSP"); for(int i=0;i<20;i++) { try { switch (i) { case 0: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 1: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 10: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; case 11: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 13: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 14: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_RAVEN: case mapType.TYPE_QUAKE3: DecompilerThread.OnMessage(this, "BSP v46 (id Tech 3)"); for(int i=0;i<18;i++) { try { switch (i) { case 0: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; case 1: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 2: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 7: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 8: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 9: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; case 10: theLump = readLumpNum(i); BSPObject.Vertices = Vertex.createLump(theLump, version); break; case 13: theLump = readLumpNum(i); BSPObject.Faces = Face.createLump(theLump, version); break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_COD: DecompilerThread.OnMessage(this, "BSP v59 (Call of Duty)"); for(int i=0;i<33;i++) { try { switch (i) { case 0: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 2: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 3: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; case 4: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 27: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 29: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_COD2: DecompilerThread.OnMessage(this, "Call of Duty 2 BSP"); for(int i=0;i<40;i++) { try { switch (i) { case 0: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 4: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 5: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; case 6: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 35: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 37: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_COD4: DecompilerThread.OnMessage(this, "Call of Duty 4 BSP"); for(int i=0;i<55;i++) { try { switch (i) { case 0: theLump = readLumpNum(i); BSPObject.Textures = Texture.createLump(theLump, version); break; case 4: theLump = readLumpNum(i); BSPObject.Planes = Plane.createLump(theLump, version); break; case 5: theLump = readLumpNum(i); BSPObject.BrushSides = BrushSide.createLump(theLump, version); break; case 8: theLump = readLumpNum(i); BSPObject.Brushes = Brush.createLump(theLump, version); break; case 37: theLump = readLumpNum(i); BSPObject.Models = Model.createLump(theLump, version); break; case 39: theLump = readLumpNum(i); BSPObject.Entities = Entity.createLump(theLump); break; } } catch { dumpLump(theLump); } } break; case mapType.TYPE_DOOM: case mapType.TYPE_HEXEN: DecompilerThread.OnMessage(this, "WAD file found"); stream.Seek(4, SeekOrigin.Begin); int numLumps = br.ReadInt32(); for(int i=0;i<numLumps;i++) { string name = getLumpName(i); if((name.Length == 5 && name[0] == 'M' && name[1] == 'A' && name[2] == 'P' && name[3] >= '0' && name[3] <= '9' && name[4] >= '0' && name[4] <= '9') || ((name.Length == 4 && name[0] == 'E' && name[1] >= '0' && name[1] <= '9' && name[2] == 'M' && name[3] >= '0' && name[3] <= '9'))) { if(getLumpName(i+11) == "BEHAVIOR") { version = mapType.TYPE_HEXEN; } DecompilerThread.OnMessage(this, "Map: " + name); DoomMap currentMap = new DoomMap(BSPFile.FullName, name, version); int[] headerInfo = getLumpInfo(i); if (headerInfo[1] > 0 && Settings.extractZip) { Console.Write("Extracting Map Header "); writeLump(name+".txt", readLumpNum(i)); } currentMap.Things = DThing.createLump(readLumpNum(i+1), version); currentMap.Linedefs = DLinedef.createLump(readLumpNum(i+2), version); currentMap.Sidedefs = DSidedef.createLump(readLumpNum(i+3)); currentMap.Vertices = Vertex.createLump(readLumpNum(i+4), version); currentMap.Segments = DSegment.createLump(readLumpNum(i+5)); currentMap.SubSectors = Edge.createLump(readLumpNum(i+6), version); currentMap.Nodes = DNode.createLump(readLumpNum(i+7)); currentMap.Sectors = DSector.createLump(readLumpNum(i+8)); doomMaps.Add(currentMap); currentMap.printBSPReport(); } } break; default: DecompilerThread.OnMessage(this, "Tried to populate structures for a format not implemented yet!"); break; } BSPObject.printBSPReport(); } catch (System.IO.IOException) { DecompilerThread.OnMessage(this, "Unable to access BSP file! Is it open in another program?"); } br.Close(); }
static void Main(string[] args) { Console.Title = "Test3"; /*if (args.Length == 0) * args = new string[] { "maps_q3.pk3" };*/ int TargetVer = 0; int StartIdx = 0; if (args.Length == 0) { Console.WriteLine("bspconv [version] file(.bsp|.pk3) [file2(.bsp|.pk3)]+"); Console.WriteLine(); Console.WriteLine("\tversion - 46 (Quake 3) or 47 (Quake Live), output version. Input version any."); return; } if (args.Length > 1 && int.TryParse(args[0], out TargetVer)) { StartIdx = 1; } else { TargetVer = 47; StartIdx = 0; } Console.WriteLine("Converting to IBSP {0}", TargetVer); for (int i = StartIdx; i < args.Length; i++) { string FileNameExt = args[i]; if (!File.Exists(FileNameExt)) { Console.WriteLine("Could not find {0}", FileNameExt); continue; } string FileName = Path.GetFileNameWithoutExtension(FileNameExt); string Extension = Path.GetExtension(FileNameExt); string OutName = FileName + "_IBSP" + TargetVer + Extension; if (Extension == ".bsp") { Console.WriteLine("Converting {0}", FileNameExt); BSP Map = BSP.FromFile(FileNameExt); Map.Version = TargetVer; File.WriteAllBytes(OutName, Map.ToByteArray()); } else if (Extension == ".pk3") { OpenZip(FileNameExt, true, (In) => { OpenZip(OutName, false, (Out) => { int EntryNum = 0; int Count = In.Entries.Count; foreach (var Entry in In.Entries) { Console.Title = string.Format("{0:0}%", ((float)EntryNum / Count) * 100); EntryNum++; if (Entry.Length == 0) { continue; } string EntryExt = Path.GetExtension(Entry.FullName); ZipArchiveEntry OutEntry = Out.CreateEntry(Entry.FullName, CompressionLevel.Optimal); OpenEntry(Entry, true, (InStream) => { if (EntryExt == ".bsp") { Console.WriteLine("Converting {0}", Entry.FullName); BSP Map = BSP.FromStream(InStream); Map.Version = TargetVer; OpenEntry(OutEntry, false, (OutStream) => Map.Serialize(OutStream)); } else { OpenEntry(OutEntry, false, (OutStream) => InStream.CopyTo(OutStream)); } }); } }); }); } else { Console.WriteLine("Skipping {0}, unknown extension type {1}", FileNameExt, Extension); } } }