Exemplo n.º 1
0
        public static uint Generate(byte[] input, int start, int length)
        {
            CRC32 crC32 = new CRC32();

            crC32.ProcessBlock(input, start, length);
            return(crC32.Finalize());
        }
Exemplo n.º 2
0
        public static unsafe uint Generate(byte *input, int len)
        {
            CRC32 crC32 = new CRC32();

            crC32.ProcessBlock(input, len);
            return(crC32.Finalize());
        }
Exemplo n.º 3
0
        public static uint Generate(byte[] input)
        {
            CRC32 crC32 = new CRC32();

            crC32.ProcessBlock(input);
            return(crC32.Finalize());
        }
Exemplo n.º 4
0
        public static uint Generate(Stream stream, int bufferLength)
        {
            CRC32 crC32 = new CRC32();

            byte[] numArray = new byte[bufferLength];
            while (stream.Position != stream.Length)
            {
                int blockLen = stream.Read(numArray, 0, bufferLength);
                crC32.ProcessBlock(numArray, blockLen);
            }
            return(crC32.Finalize());
        }
Exemplo n.º 5
0
        private static bool AttemptCompile(ModConfiguration config)
        {
            if (config.noCompilation)
            {
                return(false);
            }
            List <string> filesNoCloud = DuckFile.GetFilesNoCloud(config.directory, "*.cs", SearchOption.AllDirectories);

            if (filesNoCloud.Count == 0)
            {
                return(false);
            }
            config.isDynamic = true;
            CRC32 crC32 = new CRC32();

            byte[] numArray = new byte[2048];
            foreach (string path in filesNoCloud)
            {
                using (FileStream fileStream = File.Open(path, FileMode.Open))
                {
                    while (fileStream.Position != fileStream.Length)
                    {
                        int blockLen = fileStream.Read(numArray, 0, numArray.Length);
                        crC32.ProcessBlock(numArray, blockLen);
                    }
                }
            }
            uint num = crC32.Finalize();

            if (!ModLoader.forceRecompilation && File.Exists(config.hashPath))
            {
                if (File.Exists(config.tempAssemblyPath))
                {
                    try
                    {
                        if ((int)BitConverter.ToUInt32(File.ReadAllBytes(config.hashPath), 0) == (int)num)
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            File.WriteAllBytes(config.hashPath, BitConverter.GetBytes(num));
            if (ModLoader._provider == null)
            {
                ModLoader._provider   = new CSharpCodeProvider();
                ModLoader._parameters = new CompilerParameters(((IEnumerable <Assembly>)AppDomain.CurrentDomain.GetAssemblies()).Select <Assembly, string>((Func <Assembly, string>)(assembly => assembly.Location)).ToArray <string>());
                ModLoader._parameters.GenerateExecutable = ModLoader._parameters.GenerateInMemory = false;
            }
            if (File.Exists(config.buildLogPath))
            {
                File.SetAttributes(config.buildLogPath, FileAttributes.Normal);
                File.Delete(config.buildLogPath);
            }
            ModLoader._parameters.OutputAssembly = config.tempAssemblyPath;
            CompilerResults compilerResults = ModLoader._provider.CompileAssemblyFromFile(ModLoader._parameters, filesNoCloud.ToArray());

            if (compilerResults.Errors.Count == 0)
            {
                return(true);
            }
            File.WriteAllLines(config.buildLogPath, compilerResults.Output.OfType <string>());
            return(false);
        }