示例#1
0
        public static void GenerateMaterialMapping()
        {
            const int    paletteOffset            = 0x10;
            const int    materialCount            = 129;
            const int    materialIndexOffset      = 0xdbc8;
            const int    materialOpaqueInfoOffset = materialIndexOffset + materialCount * 2;
            const int    materialMaskOffset       = materialIndexOffset + materialCount * 4;
            const ushort opaqueMask = 0xffff;

            var importSettings = FindOrCreateAssetAtPath <ImportSettings>(ImportSettingsPath);

            importSettings.SetDefaultMaterials();
            UnpackCode();

            var paletteData = Resource.ReadResourceMap(Resource.Load("SDMAIN.PVS"))["!pal"];

            importSettings.palette = new List <Color>();
            for (int i = paletteOffset; i < paletteData.Length; i += 3)
            {
                var color = new Color(paletteData[i] / 63f, paletteData[i + 1] / 63f, paletteData[i + 2] / 63f);
                importSettings.palette.Add(color);
            }

            importSettings.materialDescriptions = new List <MaterialDescription>();
            for (int i = 0; i < materialCount; i++)
            {
                var paletteIndex        = unpackedCode[materialIndexOffset + i * 2];
                var isOpaque            = unpackedCode[materialOpaqueInfoOffset + i * 2] == 0;
                var mask                = isOpaque ? opaqueMask : ExeLoaderEmulation.ReadUshortAt(unpackedCode, materialMaskOffset + i * 2);
                var materialDescription = new MaterialDescription(paletteIndex, isOpaque, mask);
                importSettings.materialDescriptions.Add(materialDescription);
            }
        }
示例#2
0
        private static void UnpackCode()
        {
            if (unpackedCode != null)
            {
                return;
            }

            var executableImage = ExeLoaderEmulation.CreateExePackedImage();

            unpackedCode = ExeLoaderEmulation.ExtractDataFromPackedExecutable(executableImage);
        }