/// <summary>
        /// Used to figure out if fragment shaders are actually used. (They're not; all sizes are 0.)
        /// </summary>
        private static void PrintFragmentShaderTocEntries()
        {
            byte[] fileBuffer = File.ReadAllBytes(@"C:\Program Files (x86)\Steam\steamapps\common\devildaggers\res\dd0");

            ResourceFileHandler handler = new ResourceFileHandler(BinaryFileType.Dd);

            byte[] tocBuffer = handler.ReadTocBuffer(fileBuffer);

            int i = 0;

            while (i < tocBuffer.Length - 14)             // TODO: Might still get out of range maybe... (14 bytes per chunk, but name length is variable)
            {
                byte   type = tocBuffer[i];
                string name = Utils.ReadNullTerminatedString(tocBuffer, i + 2);

                if (type != 0x11)                 // Not a fragment shader
                {
                    i += 14 + name.Length + 1;
                    continue;
                }

                byte[] buf = new byte[14 + name.Length + 1];                 // + 1 to include null terminator
                Buffer.BlockCopy(tocBuffer, i, buf, 0, buf.Length);

                uint startOffset = BitConverter.ToUInt32(tocBuffer, i + name.Length + 3);
                uint size        = BitConverter.ToUInt32(tocBuffer, i + name.Length + 7);
                uint unknown     = BitConverter.ToUInt32(tocBuffer, i + name.Length + 11);
                i += buf.Length;

                Console.WriteLine($"{GetHexRepresentation(buf, 0, sizeof(byte))} {GetHexRepresentation(buf, 2, name.Length + 1)} {GetHexRepresentation(buf, name.Length + 3, sizeof(uint))} {GetHexRepresentation(buf, name.Length + 7, sizeof(uint))} {GetHexRepresentation(buf, name.Length + 11, sizeof(uint))}");
                Console.WriteLine($"{type} {name} {startOffset} {size} {unknown}\n");
            }
        }
Esempio n. 2
0
        public void ReturnsResourceContentAndSetMimeType()
        {
            ICacheProvider cacheProvider           = new MockCacheProvider();
            DefaultStaticResourceRegistry registry = new DefaultStaticResourceRegistry(cacheProvider);

            registry.RegisterCustomResource("key", null, null, new StaticContentResource("js"), "text/javascript");

            ResourceFileHandler handler = new ResourceFileHandler(new UrlInfo("", "controller", "key"), registry);

            StringWriter writer = new StringWriter();

            HttpResponse response = new HttpResponse(writer);
            HttpRequest  request  = new HttpRequest(
                Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    "Handlers/Files/simplerequest.txt"),
                "http://localhost:1333/controller/action",
                "");

            handler.ProcessRequest(new HttpContext(request, response));

            Assert.AreEqual(200, response.StatusCode);
            Assert.AreEqual("text/javascript", response.ContentType);
            Assert.AreEqual("js", writer.GetStringBuilder().ToString());
        }
Esempio n. 3
0
        private static AnalyzerFileResult?TryReadResourceFile(string sourceFileName, byte[] sourceFileBytes)
        {
            try
            {
                ResourceFileHandler fileHandler = new ResourceFileHandler(BinaryFileType.None);                 // Since we're only validating the file, we can pass None as BinaryFileType.
                fileHandler.ValidateFile(sourceFileBytes);

                byte[] tocBuffer = ResourceFileHandler.ReadTocBuffer(sourceFileBytes);

                return(new AnalyzerFileResult(sourceFileName, (uint)sourceFileBytes.Length, (uint)tocBuffer.Length + ResourceFileHandler.HeaderSize, ResourceFileHandler.ReadChunks(tocBuffer).Cast <IChunk>().ToList()));
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 4
0
        public void IfFileDoesNotExistsSetsStatusTo404()
        {
            var registry = new DefaultStaticResourceRegistry();

            var handler = new ResourceFileHandler(new UrlInfo("", "controller", "action"), registry);

            var writer = new StringWriter();

            var res = new HttpResponse(writer);
            var req = new HttpRequest(
                Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory, "Handlers/Files/simplerequest.txt"),
                "http://localhost:1333/controller/action", "");

            handler.ProcessRequest(new HttpContext(req, res));

            Assert.AreEqual(404, res.StatusCode);
        }
		public void IfFileDoesNotExistsSetsStatusTo404()
		{
			var registry = new DefaultStaticResourceRegistry();

			var handler = new ResourceFileHandler(new UrlInfo("", "controller", "action"), registry);

			var writer = new StringWriter();

			var res = new HttpResponse(writer);
			var req = new HttpRequest(
				Path.Combine(
					AppDomain.CurrentDomain.BaseDirectory, "Handlers/Files/simplerequest.txt"),
					"http://localhost:1333/controller/action", "");

			handler.ProcessRequest(new HttpContext(req, res));

			Assert.AreEqual(404, res.StatusCode);
		}
        private static void PrintTextureHeaders(int count)
        {
            byte[] fileBuffer = File.ReadAllBytes(@"C:\Program Files (x86)\Steam\steamapps\common\devildaggers\res\dd0");

            ResourceFileHandler handler = new ResourceFileHandler(BinaryFileType.Dd);

            byte[] tocBuffer = handler.ReadTocBuffer(fileBuffer);

            int i = 0;
            int j = 0;

            while (i < tocBuffer.Length - 14)             // TODO: Might still get out of range maybe... (14 bytes per chunk, but name length is variable)
            {
                byte   type = tocBuffer[i];
                string name = Utils.ReadNullTerminatedString(tocBuffer, i + 2);

                if (type != 0x02)                 // Not a texture
                {
                    i += 14 + name.Length + 1;
                    continue;
                }

                byte[] buf = new byte[14 + name.Length + 1];                 // + 1 to include null terminator
                Buffer.BlockCopy(tocBuffer, i, buf, 0, buf.Length);

                uint startOffset = BitConverter.ToUInt32(tocBuffer, i + name.Length + 3);
                i += buf.Length;

                ushort unknown = BitConverter.ToUInt16(fileBuffer, (int)startOffset);
                uint   width   = BitConverter.ToUInt32(fileBuffer, (int)startOffset + sizeof(ushort));
                uint   height  = BitConverter.ToUInt32(fileBuffer, (int)startOffset + sizeof(ushort) + sizeof(uint));
                byte   mipmaps = fileBuffer[(int)startOffset + sizeof(ushort) + sizeof(uint) + sizeof(uint)];

                Console.WriteLine(name);
                Console.WriteLine($"{GetHexRepresentation(fileBuffer, (int)startOffset, 11)}");
                Console.WriteLine($"{unknown} {width} {height} {mipmaps}\n");
                if (++j >= count)
                {
                    break;
                }
            }
        }
		public void ReturnsResourceContentAndSetMimeType()
		{
			var registry = new DefaultStaticResourceRegistry();
			registry.RegisterCustomResource("key", null, null, new StaticContentResource("js"), "text/javascript", null);

			var handler = new ResourceFileHandler(new UrlInfo("", "controller", "key"), registry);

			var writer = new StringWriter();

			var res = new HttpResponse(writer);
			var req = new HttpRequest(
				Path.Combine(
					AppDomain.CurrentDomain.BaseDirectory, "Handlers/Files/simplerequest.txt"),
					"http://localhost:1333/controller/action", "");

			handler.ProcessRequest(new HttpContext(req, res));

			Assert.AreEqual(200, res.StatusCode);
			Assert.AreEqual("text/javascript", res.ContentType);
			Assert.AreEqual("js", writer.GetStringBuilder().ToString());
		}
        private static void PrintFirstModelVertex(int count)
        {
            byte[] fileBuffer = File.ReadAllBytes(@"C:\Program Files (x86)\Steam\steamapps\common\devildaggers\res\dd0");

            ResourceFileHandler handler = new ResourceFileHandler(BinaryFileType.Dd);

            byte[] tocBuffer = handler.ReadTocBuffer(fileBuffer);

            int i = 0;
            int j = 0;

            while (i < tocBuffer.Length - 14)             // TODO: Might still get out of range maybe... (14 bytes per chunk, but name length is variable)
            {
                byte   type = tocBuffer[i];
                string name = Utils.ReadNullTerminatedString(tocBuffer, i + 2);

                if (type != 0x01)                 // Not a model
                {
                    i += 14 + name.Length + 1;
                    continue;
                }

                byte[] buf = new byte[14 + name.Length + 1];                 // + 1 to include null terminator
                Buffer.BlockCopy(tocBuffer, i, buf, 0, buf.Length);

                uint startOffset = BitConverter.ToUInt32(tocBuffer, i + name.Length + 3);
                i += buf.Length;

                Console.WriteLine(name);
                Console.WriteLine($"{GetHexRepresentation(fileBuffer, (int)startOffset + 10, 32)}");
                if (++j >= count)
                {
                    break;
                }
            }
        }