예제 #1
0
        private async Task UnluacDecompile(ModAction <UnluacDecompileAction> modAction, string tempFolder)
        {
            foreach (var file in modAction.action.TargetFiles)
            {
                var physicalTargetPath = ResolvePath(file, modAction.mod, configuration);
                var fileInfo           = new FileInfo(physicalTargetPath);

                var targetPath = Path.Combine(tempFolder, $"{Path.GetFileNameWithoutExtension(fileInfo.Name)}_decomp{fileInfo.Extension}");

                // Check if this has already been decompiled
                if (decompiledFiles.Contains(physicalTargetPath))
                {
                    continue;
                }

                if (!File.Exists(physicalTargetPath))
                {
                    throw new Exception($"Unable to find target path: {physicalTargetPath}");
                }

                // Decompile the file, and replace the file
                await UnluacUtility.Decompile(physicalTargetPath, targetPath);

                MoveFile_Internal(targetPath, physicalTargetPath, modAction.mod);

                decompiledFiles.Add(physicalTargetPath);
            }
        }
예제 #2
0
        public static async Task ApplyChanges(Configuration configuration, CharacterModification[] data)
        {
            var tempFolder = FileWriterUtility.CreateTempFolder();

            // Start with a blank canvas
            RemoveAllChanges(configuration);

            if (data.Length == 0)
            {
                return;
            }

            try
            {
                await ExtractFiles(configuration, tempFolder);

                var json = GenerateCharacterJson(data);

                var virtualreaderFile           = Path.Combine(tempFolder, "presentation", "virtualreaderpc_data.lua");
                var virtualreaderDecompiledFile = Path.Combine(tempFolder, "virtualreaderpc_data_decomp.lua");
                var igpLocksFile = Path.Combine(tempFolder, "igp", "locks__lua.chd");

                await UnluacUtility.Decompile(virtualreaderFile, virtualreaderDecompiledFile);

                // Write any data as required to the virtualreader file, make sure to offset by bytesWritten if needed
                int bytesWritten = 0;
                FileWriterUtility.WriteToFile(virtualreaderDecompiledFile, json, 0x0000A5C6, true, out bytesWritten);

                foreach (var character in data.Where(c => !string.IsNullOrEmpty(c.ReplacementCharacter)))
                {
                    var offset = FindReplacementOffset(igpLocksFile, character.ReplacementCharacter);
                    FileWriterUtility.WriteToFile(igpLocksFile, character.Config.PresentationData.Name, offset, false, out bytesWritten);
                }
            }
            catch (Exception ex)
            {
                Directory.Delete(tempFolder, true);
                return;
            }

            CopyFiles(configuration, tempFolder);
            Directory.Delete(tempFolder, true);
        }