Esempio n. 1
0
        /// <summary>
        /// Wrapper around Oodle Kraken Decompress. Decompresses an inputBuffer to an outputBuffer of correct size
        /// </summary>
        /// <param name="inputBuffer"></param>
        /// <param name="outputBuffer"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public static unsafe int Decompress(byte[] inputBuffer, byte[] outputBuffer)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
#pragma warning disable 162

                if (true)
                {
                    var inputHandle   = GCHandle.Alloc(inputBuffer, GCHandleType.Pinned);
                    var inputAddress  = inputHandle.AddrOfPinnedObject();
                    var outputHandle  = GCHandle.Alloc(outputBuffer, GCHandleType.Pinned);
                    var outputAddress = outputHandle.AddrOfPinnedObject();



                    var r = OodleLoadLib.OodleLZ_Decompress(inputAddress,
                                                            outputAddress,
                                                            inputBuffer.Length,
                                                            outputBuffer.Length
                                                            );

                    inputHandle.Free();
                    outputHandle.Free();

                    return(r);
                }

                return(OodleNative.OodleLZ_Decompress(
                           inputBuffer,
                           inputBuffer.Length,
                           outputBuffer,
                           outputBuffer.Length,
                           OodleNative.OodleLZ_FuzzSafe.No, OodleNative.OodleLZ_CheckCRC.No,
                           OodleNative.OodleLZ_Verbosity.None,
                           0,
                           0,
                           0,
                           0,
                           0,
                           0,
                           OodleNative.OodleLZ_Decode.Unthreaded));

#pragma warning restore 162
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return(OozNative.Kraken_Decompress(inputBuffer, inputBuffer.Length, outputBuffer,
                                                   outputBuffer.Length));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var serviceLocator = ServiceLocator.Default;

            serviceLocator.RegisterType <IProgress <double>, PercentProgressService>();
            serviceLocator.RegisterType <IHashService, HashService>();
            serviceLocator.RegisterType <Red4ParserService>();
            serviceLocator.RegisterType <RIG>();
            serviceLocator.RegisterType <MeshTools>();
            serviceLocator.RegisterType <ModTools>();
            var oodlePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oo2ext_7_win64.dll");

            OodleLoadLib.Load(oodlePath);
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var oodlePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oo2ext_7_win64.dll");

            OodleLoadLib.Load(oodlePath);

            var host = GenericHost.CreateHostBuilder(args);

            host.ConfigureServices((hostContext, services) =>
            {
                services.AddHostedService <WorkerHostedService>();
            });
            host.Build().RunAsync();
        }
Esempio n. 4
0
        public Task HandleStartup()
        {
            if (!OodleLoadLib.Load(_settingsManager.GetRED4OodleDll()))
            {
                throw new FileNotFoundException($"oo2ext_7_win64.dll not found.");
            }

            var todo = new List <Func <IGameArchiveManager> >()
            {
                LoadArchiveManager,
            };

            Parallel.ForEach(todo, _ => Task.Run(_));
            return(Task.CompletedTask);
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            // try get oodle dll from game
            if ((RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) && !TryCopyOodleLib())
            {
                Console.WriteLine("Could not automatically find oo2ext_7_win64.dll. " +
                                  "Please manually copy and paste the DLL found in <gamedir>\\Cyberpunk 2077\\bin\\x64\\oo2ext_7_win64.dll into this folder: " +
                                  $"{AppDomain.CurrentDomain.BaseDirectory}.");
                return;
            }

            var oodlePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oo2ext_7_win64.dll");

            OodleLoadLib.Load(oodlePath);


            var rootCommand = new RootCommand
            {
                new ArchiveCommand(),

                new UnbundleCommand(),
                new UncookCommand(),
                new ImportCommand(),
                new PackCommand(),
                new ExportCommand(),

                new DumpCommand(),
                new CR2WCommand(),

                new HashCommand(),
                new OodleCommand(),

                new SettingsCommand(),
            };

            var parser = new CommandLineBuilder(rootCommand)
                         .UseDefaults()
                         .UseHost(GenericHost.CreateHostBuilder)
                         .Build();

            parser.Invoke(args);
        }
Esempio n. 6
0
        private static long Decompress(Span <byte> inputBufferSpan, Span <byte> outputBufferSpan)
        {
            unsafe
            {
                fixed(byte *bpi = &inputBufferSpan.GetPinnableReference())
                fixed(byte *bpo = &outputBufferSpan.GetPinnableReference())
                {
                    IntPtr pInputBufferSpan  = (IntPtr)bpi;
                    IntPtr pOutputBufferSpan = (IntPtr)bpo;

                    var r = OodleLoadLib.OodleLZ_Decompress(pInputBufferSpan,
                                                            pOutputBufferSpan,
                                                            inputBufferSpan.Length,
                                                            outputBufferSpan.Length
                                                            );

                    return(r);
                }
            }
        }
Esempio n. 7
0
        public Task HandleStartup()
        {
            // load oodle
            if (!OodleLoadLib.Load(_settingsManager.GetRED4OodleDll()))
            {
                throw new FileNotFoundException($"oo2ext_7_win64.dll not found.");
            }

            // load archives
            var todo = new List <Func <IArchiveManager> >()
            {
                LoadArchiveManager,
            };

            Parallel.ForEach(todo, _ => Task.Run(_));

            // requires oodle
            InitializeBk();
            InitializeRedDB();

            return(Task.CompletedTask);
        }
Esempio n. 8
0
        protected static void Setup(TestContext context)
        {
            #region cp77 game dir

            // Init
            Console.WriteLine("BaseTestClass.BaseTestInitialize()");
            s_config = new ConfigurationBuilder()
                       .AddJsonFile("appsettings.json")
                       .Build();
            s_writeToFile = bool.Parse(s_config.GetSection(s_writeToFileSetting).Value);

            // overrides hardcoded appsettings.json
            var cp77Dir = Environment.GetEnvironmentVariable("CP77_DIR", EnvironmentVariableTarget.User);
            if (!string.IsNullOrEmpty(cp77Dir) && new DirectoryInfo(cp77Dir).Exists)
            {
                s_gameDirectoryPath = cp77Dir;
            }
            else
            {
                s_gameDirectoryPath = s_config.GetSection(s_gameDirectorySetting).Value;
            }

            if (string.IsNullOrEmpty(s_gameDirectoryPath))
            {
                throw new ConfigurationErrorsException($"'{s_gameDirectorySetting}' is not configured");
            }

            var gameDirectory = new DirectoryInfo(s_gameDirectoryPath);
            if (!gameDirectory.Exists)
            {
                throw new ConfigurationErrorsException($"'{s_gameDirectorySetting}' is not a valid directory");
            }

            #endregion

            #region oodle

            var gameBinDir = new DirectoryInfo(Path.Combine(gameDirectory.FullName, "bin", "x64"));
            var oodleInfo  = new FileInfo(Path.Combine(gameBinDir.FullName, "oo2ext_7_win64.dll"));
            if (!oodleInfo.Exists)
            {
                Assert.Fail("Could not find oo2ext_7_win64.dll.");
            }
            var ass = AppDomain.CurrentDomain.BaseDirectory;
            var appOodleFileName = Path.Combine(ass, "oo2ext_7_win64.dll");
            if (!File.Exists(appOodleFileName))
            {
                oodleInfo.CopyTo(appOodleFileName);
            }
            if (!OodleLoadLib.Load(appOodleFileName))
            {
                Assert.Fail("Could not load oo2ext_7_win64.dll.");
            }

            #endregion

            //protobuf
            RuntimeTypeModel.Default[typeof(IGameArchive)].AddSubType(20, typeof(Archive));

            // IoC
            ServiceLocator.Default.RegisterInstance <ILoggerService>(new CatelLoggerService(false));
            ServiceLocator.Default.RegisterType <IHashService, HashService>();
            ServiceLocator.Default.RegisterType <IProgressService <double>, ProgressService <double> >();
            ServiceLocator.Default.RegisterType <Red4ParserService>();
            ServiceLocator.Default.RegisterType <RIG>();              //Cp77FileService
            ServiceLocator.Default.RegisterType <MeshTools>();        //RIG, Cp77FileService

            ServiceLocator.Default.RegisterType <ModTools>();         //Cp77FileService, ILoggerService, IProgress, IHashService, Mesh, Target

            var hashService = ServiceLocator.Default.ResolveType <IHashService>();


            s_bm = new ArchiveManager(hashService);
            var archivedir = new DirectoryInfo(Path.Combine(gameDirectory.FullName, "archive", "pc", "content"));
            s_bm.LoadFromFolder(archivedir);
            s_groupedFiles = s_bm.GroupedFiles;
        }
Esempio n. 9
0
        public static void InitializeBk()
        {
            var settings = ServiceLocator.Default.ResolveType <ISettingsManager>();

            string[] binkhelpers = { @"Resources\Media\t1.kark", @"Resources\Media\t2.kark", @"Resources\Media\t3.kark", @"Resources\Media\t4.kark", @"Resources\Media\t5.kark" };

            if (string.IsNullOrEmpty(settings.GetRED4GameRootDir()))
            {
                Trace.WriteLine("That worked to cancel Loading oodle! :D");
                return;
            }

            var oodlePath = settings.GetRED4OodleDll();

            if (!File.Exists(settings.GetRED4OodleDll()))
            {
                return;
            }

            OodleLoadLib.Load(oodlePath);

            foreach (var path in binkhelpers)
            {
                switch (path)
                {
                case @"Resources\Media\t1.kark":
                    if (File.Exists(Path.Combine(ISettingsManager.GetWorkDir(), "test.exe")))
                    {
                    }
                    else
                    {
                        var q = OodleTask(path, Path.Combine(ISettingsManager.GetWorkDir(), "test.exe"), true, false);
                    }
                    break;

                case @"Resources\Media\t2.kark":
                    if (File.Exists(Path.Combine(ISettingsManager.GetWorkDir(), "testconv.exe")))
                    {
                    }
                    else
                    {
                        var q = OodleTask(path, Path.Combine(ISettingsManager.GetWorkDir(), "testconv.exe"), true, false);
                    }
                    break;

                case @"Resources\Media\t3.kark":
                    if (File.Exists(Path.Combine(ISettingsManager.GetWorkDir(), "testc.exe")))
                    {
                    }
                    else
                    {
                        var q = OodleTask(path, Path.Combine(ISettingsManager.GetWorkDir(), "testc.exe"), true, false);
                    }
                    break;

                case @"Resources\Media\t4.kark":
                    if (File.Exists(Path.Combine(ISettingsManager.GetWorkDir(), "radutil.dll")))
                    {
                    }
                    else
                    {
                        var q = OodleTask(path, Path.Combine(ISettingsManager.GetWorkDir(), "radutil.dll"), true, false);
                    }
                    break;

                case @"Resources\Media\t5.kark":
                    if (File.Exists(Path.Combine(ISettingsManager.GetWorkDir(), "bink2make.dll")))
                    {
                    }
                    else
                    {
                        var q = OodleTask(path, Path.Combine(ISettingsManager.GetWorkDir(), "bink2make.dll"), true, false);
                    }
                    break;
                }
            }
        }
Esempio n. 10
0
        public static void Bot(DirectoryInfo dir)
        {
            var serviceLocator = ServiceLocator.Default;

            serviceLocator.RegisterType <ILoggerService, CatelLoggerService>();
            serviceLocator.RegisterType <IProgress <double>, PercentProgressService> ();
            serviceLocator.RegisterType <IHashService, HashService>();
            serviceLocator.RegisterType <Red4ParserService>();
            serviceLocator.RegisterType <RIG>();
            serviceLocator.RegisterType <MeshTools>();
            serviceLocator.RegisterType <ModTools>();
            var oodlePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oo2ext_7_win64.dll");

            OodleLoadLib.Load(oodlePath);

            var _wolvenkitFileService = serviceLocator.ResolveType <Red4ParserService>();

            var mts   = Directory.GetFiles(dir.FullName, "*.mt", SearchOption.AllDirectories);
            var remts = Directory.GetFiles(dir.FullName, "*.remt", SearchOption.AllDirectories);

            var all = new List <string>();

            all.AddRange(mts);
            all.AddRange(remts);

            /*
             * List<string> typer = new List<string>();
             * foreach (string a in all)
             * {
             *  typer.Add($"case \"{Path.GetFileName(a)}\":");
             *  typer.Add($"if(rawMaterial._{Path.GetFileNameWithoutExtension(a)} == null)");
             *  typer.Add($"    rawMaterial._{Path.GetFileNameWithoutExtension(a)} = new _{Path.GetFileNameWithoutExtension(a)}();");
             *  typer.Add($"rawMaterial._{Path.GetFileNameWithoutExtension(a)}.Read(cMaterialInstance);");
             *  typer.Add($"rawMaterial.MaterialType = MaterialTypes._{Path.GetFileNameWithoutExtension(a)}.ToString();");
             *  typer.Add("break;");
             * }
             * foreach (string a in all)
             * {
             *  typer.Add($"case MaterialTypes._{Path.GetFileNameWithoutExtension(a)}:");
             *  typer.Add($"mat._{Path.GetFileNameWithoutExtension(a)}.write(ref mi);");
             *  typer.Add("if (mat.BaseMaterial == null)");
             *  typer.Add($"mat.BaseMaterial = @\"{a.Replace(@"D:\unbundle\",string.Empty)}\";");
             *  typer.Add("break;");
             * }
             *
             * foreach (string a in all)
             * {
             *  typer.Add("[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]");
             *  typer.Add($"public _{Path.GetFileNameWithoutExtension(a)} _{Path.GetFileNameWithoutExtension(a)}    {{ get; set; }}");
             * }
             * File.WriteAllLines(@"switch.cs", typer);
             * //
             */

            var    ck    = new List <string>();
            var    types = new List <string>();
            string file  = @"MaterialTypes.cs";



            List <string> enumtyper   = new List <string>();
            List <string> typer       = new List <string>();
            List <string> inittyper   = new List <string>();
            List <string> deinittyper = new List <string>();



            enumtyper.Add("public enum MaterialTypes\n{");
            foreach (string a in all)
            {
                var ms   = new MemoryStream(File.ReadAllBytes(a));
                var cr2w = _wolvenkitFileService.TryReadCr2WFile(ms);

                var b = cr2w.Chunks.Select(_ => _.Data).OfType <CMaterialTemplate>().First();
                enumtyper.Add("   " + "_" + Path.GetFileNameWithoutExtension(a) + ",");
                //Console.WriteLine(b.Name.Value);
                typer.Add($"public partial class _{Path.GetFileNameWithoutExtension(a)}\n{{");
                inittyper.Add($"public partial class _{Path.GetFileNameWithoutExtension(a)}\n{{");
                inittyper.Add($"   public _{Path.GetFileNameWithoutExtension(a)}()   {{}}");
                inittyper.Add($"   public void Read(CMaterialInstance cMaterialInstance)\n   {{");
                inittyper.Add($"       for (int i = 0; i < cMaterialInstance.CMaterialInstanceData.Count; i++)\n       {{");
                inittyper.Add($"           var data = cMaterialInstance.CMaterialInstanceData[i];");

                deinittyper.Add($"public partial class _{Path.GetFileNameWithoutExtension(a)}\n{{");
                deinittyper.Add($"  public void write(ref CR2WFile cr2w)\n    {{");
                deinittyper.Add($"      var m = (cr2w.Chunks[0].Data as CMaterialInstance).CMaterialInstanceData;");
                //                if (data.REDName == "MultilayerSetup")
                List <string> rem = new List <string>();
                for (int i = 1; i < cr2w.Chunks.Count; i++)
                {
                    var d = cr2w.Chunks[i].Data;

                    if (d.REDType == "CMaterialParameterColor")
                    {
                        var val = (d as CMaterialParameterColor).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterColor).Color.REDType;
                        //Console.WriteLine(type); CColor
                        typer.Add($"    public Color {val} {{ get; set;}} = new Color({(d as CMaterialParameterColor).Color.Red.Value}, {(d as CMaterialParameterColor).Color.Green.Value}, {(d as CMaterialParameterColor).Color.Blue.Value}, {(d as CMaterialParameterColor).Color.Alpha.Value});      //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = new Color(data.Variant as CColor);");

                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new CColor(cr2w, v, \"{val}\") {{ IsSerialized = true, Red = new CUInt8() {{ Value = (Byte){val}.Red }}, Green = new CUInt8() {{ Value = (Byte){val}.Green }}, Blue = new CUInt8() {{ Value = (Byte){val}.Blue }}, Alpha = new CUInt8() {{ Value = (Byte){val}.Alpha }} }}; v.Variant = p;}}");
                    }
                    //if (!types.Contains(cr2w.Chunks[i].Data.REDType))
                    //types.Add(cr2w.Chunks[i].Data.REDType);

                    if (d.REDType == "CMaterialParameterScalar")
                    {
                        var val = (d as CMaterialParameterScalar).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterScalar).Scalar.REDType;
                        //Console.WriteLine(type); //CFloat
                        typer.Add($"    public float {val} {{ get; set; }} = {(d as CMaterialParameterScalar).Scalar.Value}f;     //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as CFloat).Value;");

                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new CFloat(cr2w, v, \"{val}\") {{ IsSerialized = true ,Value = (float){val}}}; v.Variant = p;}}");
                    }

                    if (d.REDType == "CMaterialParameterTexture")
                    {
                        var val = (d as CMaterialParameterTexture).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterTexture).Texture.REDType;
                        //Console.WriteLine(type); rRef<ITexture>
                        typer.Add($"    public string {val} {{ get; set; }} = @\"{(d as CMaterialParameterTexture).Texture.DepotPath}\";    //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<ITexture>).DepotPath;");

                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<ITexture>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }

                    if (d.REDType == "CMaterialParameterVector")
                    {
                        var val = (d as CMaterialParameterVector).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterVector).Vector.REDType;
                        //Console.WriteLine(type); //Vector4
                        typer.Add($"    public Vec4 {val} {{ get; set; }} = new Vec4({(d as CMaterialParameterVector).Vector.X.Value}f,{(d as CMaterialParameterVector).Vector.Y.Value}f,{(d as CMaterialParameterVector).Vector.Z.Value}f,{(d as CMaterialParameterVector).Vector.W.Value}f);    //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = new Vec4(data.Variant as Vector4);");


                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new Vector4(cr2w, v, \"{val}\") {{ IsSerialized = true }}; v.Variant = p;");
                        deinittyper.Add($"          p.X = new CFloat(cr2w, p, \"X\") {{ IsSerialized = true, Value = (float){val}.X}}; p.Y = new CFloat(cr2w, p, \"Y\") {{ IsSerialized = true, Value = (float){val}.Y}}; p.Z = new CFloat(cr2w, p, \"Z\") {{ IsSerialized = true, Value = (float){val}.Z}}; p.W = new CFloat(cr2w, p, \"W\") {{ IsSerialized = true, Value = (float){val}.W}};}}");
                    }

                    if (d.REDType == "CMaterialParameterTextureArray")
                    {
                        var val = (d as CMaterialParameterTextureArray).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterTextureArray).Texture.REDType;
                        //Console.WriteLine(type); rRef<ITexture>
                        typer.Add($"    public string {val} {{ get; set; }} = @\"{(d as CMaterialParameterTextureArray).Texture.DepotPath}\";    //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<ITexture>).DepotPath;");

                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<ITexture>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }

                    if (d.REDType == "CMaterialParameterMultilayerMask")
                    {
                        var val = (d as CMaterialParameterMultilayerMask).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterMultilayerMask).Mask.REDType;
                        //Console.WriteLine(type); rRef<Multilayer_Mask>
                        typer.Add($"    public string {val} {{ get; set; }} = @\"{(d as CMaterialParameterMultilayerMask).Mask.DepotPath}\";     //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<Multilayer_Mask>).DepotPath;");


                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<Multilayer_Mask>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }

                    if (d.REDType == "CMaterialParameterMultilayerSetup")
                    {
                        var val = (d as CMaterialParameterMultilayerSetup).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterMultilayerSetup).Setup.REDType;
                        //Console.WriteLine(type); //rRef<Multilayer_Setup>
                        typer.Add($"    public string {val} {{ get; set; }} = @\"{(d as CMaterialParameterMultilayerSetup).Setup.DepotPath}\";     //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<Multilayer_Setup>).DepotPath;");


                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<Multilayer_Setup>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }

                    if (d.REDType == "CMaterialParameterStructBuffer")
                    {
                        var val = (d as CMaterialParameterStructBuffer).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        //var type = (d as CMaterialParameterStructBuffer).REDType;
                        //Console.WriteLine(val);
                        typer.Add($"    public DataBuffer {val} {{ get; set; }}");
                    }

                    if (d.REDType == "CMaterialParameterCube")
                    {
                        var val = (d as CMaterialParameterCube).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterCube).Texture.REDType;
                        //Console.WriteLine(type);  rRef<ITexture>
                        typer.Add($"    public string {val} {{ get; set; }} =  @\"{(d as CMaterialParameterCube).Texture.DepotPath}\";     //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<ITexture>).DepotPath;");


                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<ITexture>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }

                    if (d.REDType == "CMaterialParameterGradient")
                    {
                        var val = (d as CMaterialParameterGradient).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterGradient).Gradient.REDType;
                        //Console.WriteLine(type); rRef<CGradient>
                        typer.Add($"    public string {val} {{ get; set; }} = @\"{(d as CMaterialParameterGradient).Gradient.DepotPath}\";     //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<CGradient>).DepotPath;");


                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<CGradient>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }

                    if (d.REDType == "CMaterialParameterHairParameters")
                    {
                        var val = (d as CMaterialParameterHairParameters).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterHairParameters).HairProfile.REDType;
                        //Console.WriteLine(type); rRef<CHairProfile>
                        typer.Add($"    public string {val} {{ get; set;}} = @\"{(d as CMaterialParameterHairParameters).HairProfile.DepotPath}\";     //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<CHairProfile>).DepotPath;");


                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<CHairProfile>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }

                    if (d.REDType == "CMaterialParameterCpuNameU64")
                    {
                        var val = (d as CMaterialParameterCpuNameU64).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterCpuNameU64).Name.REDType;
                        //Console.WriteLine(a);  CName
                        //Console.WriteLine(type);
                        typer.Add($"    public string {val} {{ get; set; }} = @\"{(d as CMaterialParameterCpuNameU64).Name.Value}\";     //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as CName).Value;");
                    }

                    if (d.REDType == "CMaterialParameterTerrainSetup")
                    {
                        var val = (d as CMaterialParameterTerrainSetup).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterTerrainSetup).Setup.REDType;
                        //Console.WriteLine(type); rRef<CTerrainSetup>
                        typer.Add($"    public string {val} {{ get; set; }} = @\"{(d as CMaterialParameterTerrainSetup).Setup.DepotPath}\";     //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<CTerrainSetup>).DepotPath;");


                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<CTerrainSetup>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }

                    if (d.REDType == "CMaterialParameterSkinParameters")
                    {
                        var val = (d as CMaterialParameterSkinParameters).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterSkinParameters).SkinProfile.REDType;
                        //Console.WriteLine(type); rRef<CSkinProfile>
                        typer.Add($"    public string {val} {{ get; set; }} = @\"{(d as CMaterialParameterSkinParameters).SkinProfile.DepotPath}\";      //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<CSkinProfile>).DepotPath;");


                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<CSkinProfile>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }

                    if (d.REDType == "CMaterialParameterFoliageParameters")
                    {
                        var val = (d as CMaterialParameterFoliageParameters).ParameterName.Value;
                        if (!rem.Contains(val))
                        {
                            rem.Add(val);
                        }
                        else
                        {
                            continue;
                        }
                        var type = (d as CMaterialParameterFoliageParameters).FoliageProfile.REDType;
                        //Console.WriteLine(type); rRef<CFoliageProfile>
                        typer.Add($"    public string {val} {{ get; set; }} = @\"{(d as CMaterialParameterFoliageParameters).FoliageProfile.DepotPath}\";     //{type}");
                        inittyper.Add($"           if (data.REDName == \"{val}\")");
                        inittyper.Add($"               {val} = (data.Variant as rRef<CFoliageProfile>).DepotPath;");


                        deinittyper.Add($"      if({val} != null){{");
                        deinittyper.Add($"          var v = new CVariantSizeNameType(cr2w, m, \"{val}\") {{ IsSerialized = true }}; m.Add(v);");
                        deinittyper.Add($"          var p = new rRef<CFoliageProfile>(cr2w, v, \"{val}\") {{ IsSerialized = true, DepotPath = {val} }}; v.Variant = p; }}");
                    }
                }
                typer.Add($"}}");

                inittyper.Add($"       }}");
                inittyper.Add($"   }}");
                inittyper.Add($"}}");

                //deinittyper.Add($"       }}");
                deinittyper.Add($"   }}");
                deinittyper.Add($"}}");
            }
            enumtyper.Add("}");

            File.WriteAllLines(file, typer);
            File.WriteAllLines(@"MaterialInit.cs", inittyper);
            File.WriteAllLines(@"MaterialEnum.cs", enumtyper);
            File.WriteAllLines(@"MaterialDeinit.cs", deinittyper);
        }
Esempio n. 11
0
        // 0x4b, 0x41, 0x52, 0x4b

        #region Methods

        /// <summary>
        ///
        /// </summary>
        /// <param name="inputBytes"></param>
        /// <param name="inputCount"></param>
        /// <param name="outputBuffer"></param>
        /// <param name="algo"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="NotImplementedException"></exception>
        public static int Compress(
            byte[] inputBytes,
            // int inputOffset,
            int inputCount,
            ref IEnumerable <byte> outputBuffer,
            // int outputOffset,
            // int outputCount,
            OodleNative.OodleLZ_Compressor algo   = OodleNative.OodleLZ_Compressor.Kraken,
            OodleNative.OodleLZ_Compression level = OodleNative.OodleLZ_Compression.Normal,
            bool useREDHeader = true)
        {
            if (inputBytes == null)
            {
                throw new ArgumentNullException(nameof(inputBytes));
            }

            if (inputCount <= 0 || inputCount > inputBytes.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(inputCount));
            }

            if (outputBuffer == null)
            {
                throw new ArgumentNullException(nameof(outputBuffer));
            }



            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var compressedBufferSizeNeeded = OodleHelper.GetCompressedBufferSizeNeeded(inputCount);
                var compressedBuffer           = new byte[compressedBufferSizeNeeded];

                var inputHandle   = GCHandle.Alloc(inputBytes, GCHandleType.Pinned);
                var inputAddress  = inputHandle.AddrOfPinnedObject();
                var outputHandle  = GCHandle.Alloc(compressedBuffer, GCHandleType.Pinned);
                var outputAddress = outputHandle.AddrOfPinnedObject();

                var result = 0;
                if (true)
                {
                    result = (int)OodleLoadLib.OodleLZ_Compress(
                        inputAddress,
                        outputAddress,
                        inputCount,
                        algo,
                        level
                        );
                }
                else
#pragma warning disable 162
                {
                    result = (int)OodleNative.Compress(
                        (int)algo,
                        inputAddress,
                        inputCount,
                        outputAddress,
                        (int)level,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        0
                        );
                }
#pragma warning restore 162



                inputHandle.Free();
                outputHandle.Free();

                if (result == 0 || inputCount <= (result + 8))
                {
                    outputBuffer = inputBytes;
                    return(outputBuffer.Count());
                }


                if (useREDHeader)
                {
                    //resize buffer
                    var writelist = new List <byte>()
                    {
                        0x4B, 0x41, 0x52, 0x4B  //KARK, TODO: make this dependent on the compression algo
                    };
                    writelist.AddRange(BitConverter.GetBytes(inputCount));
                    writelist.AddRange(compressedBuffer.Take(result));

                    outputBuffer = writelist;
                }
                else
                {
                    outputBuffer = compressedBuffer.Take(result);
                }

                return(outputBuffer.Count());
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                //TODO: use ooz to compress
                outputBuffer = inputBytes;
                return(outputBuffer.Count());

                // try
                // {
                //     var result = OozNative.Compress(
                //         (int)algo,
                //         inputAddress,
                //         outputAddress,
                //         inputCount,
                //         IntPtr.Zero,
                //         IntPtr.Zero
                //     );
                //     inputHandle.Free();
                //     outputHandle.Free();
                //     return result;
                // }
                // catch (Exception e)
                // {
                //     Console.WriteLine(e);
                //     throw;
                // }
            }
            else
            {
                throw new NotImplementedException();
            }
        }