├── docs ├── dev │ ├── Changelog.md │ └── toc.yml ├── guides │ ├── First-Steps.md │ ├── Contributing.md │ └── toc.yml ├── index.md ├── images │ ├── favicon.png │ ├── logo_128.png │ └── logo_48.png ├── filter_config.yml ├── pdf │ └── toc.yml ├── toc.yml ├── global_metadata.json ├── docfx.json └── faq.md ├── GitVersion.yml ├── src ├── Apps │ └── TF3.CommandLine │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── TF3.CommandLine.csproj │ │ └── Options │ │ ├── ListScriptsOptions.cs │ │ ├── ExtractOptions.cs │ │ └── RebuildOptions.cs ├── nuget.config ├── Libraries │ ├── TF3.Core │ │ ├── TF3.Core.csproj │ │ ├── Models │ │ │ ├── ConverterInfo.cs │ │ │ ├── AssetFileInfo.cs │ │ │ ├── ParameterInfo.cs │ │ │ ├── FileInfo.cs │ │ │ ├── PatchInfo.cs │ │ │ ├── AssetInfo.cs │ │ │ └── ContainerInfo.cs │ │ ├── EventArgs │ │ │ ├── ScriptEventArgs.cs │ │ │ ├── AssetEventArgs.cs │ │ │ ├── PatchEventArgs.cs │ │ │ └── ContainerEventArgs.cs │ │ ├── Helpers │ │ │ ├── HexStringJsonConverter.cs │ │ │ ├── HexStringListJsonConverter.cs │ │ │ └── ChecksumHelper.cs │ │ ├── Formats │ │ │ └── BinaryPatch.cs │ │ ├── Converters │ │ │ ├── SingleNodeToFormat.cs │ │ │ └── BinaryPatch │ │ │ │ └── Apply.cs │ │ ├── ScriptManager.cs │ │ └── Exceptions │ │ │ ├── ByteMismatchException.cs │ │ │ ├── UnknownConverterException.cs │ │ │ └── ChecksumMismatchException.cs │ └── TF3.YarhlPlugin.Common │ │ ├── TF3.YarhlPlugin.Common.csproj │ │ ├── Enums │ │ └── BitmapExtractionFormat.cs │ │ ├── Formats │ │ ├── BitmapFileFormat.cs │ │ ├── DdsFileFormat.cs │ │ └── PortableExecutableFileFormat.cs │ │ ├── Converters │ │ ├── Common │ │ │ └── ImageExtractorParameters.cs │ │ ├── BitmapImage │ │ │ ├── Replace │ │ │ │ ├── A8Replace.cs │ │ │ │ ├── L8Replace.cs │ │ │ │ ├── L16Replace.cs │ │ │ │ ├── La16Replace.cs │ │ │ │ ├── La32Replace.cs │ │ │ │ ├── Rg32Replace.cs │ │ │ │ ├── Abgr32Replace.cs │ │ │ │ ├── Argb32Replace.cs │ │ │ │ ├── Bgr24Replace.cs │ │ │ │ ├── Bgr565Replace.cs │ │ │ │ ├── Bgra32Replace.cs │ │ │ │ ├── Byte4Replace.cs │ │ │ │ ├── Rgb24Replace.cs │ │ │ │ ├── Rgb48Replace.cs │ │ │ │ ├── Rgba32Replace.cs │ │ │ │ ├── Rgba64Replace.cs │ │ │ │ ├── Short2Replace.cs │ │ │ │ ├── Short4Replace.cs │ │ │ │ ├── Bgra4444Replace.cs │ │ │ │ ├── Bgra5551Replace.cs │ │ │ │ ├── HalfSingleReplace.cs │ │ │ │ ├── HalfVector2Replace.cs │ │ │ │ ├── HalfVector4Replace.cs │ │ │ │ ├── Rgba1010102Replace.cs │ │ │ │ ├── RgbaVectorReplace.cs │ │ │ │ ├── NormalizedByte2Replace.cs │ │ │ │ ├── NormalizedByte4Replace.cs │ │ │ │ ├── NormalizedShort2Replace.cs │ │ │ │ ├── NormalizedShort4Replace.cs │ │ │ │ └── AbstractReplace.cs │ │ │ ├── ImageParameters.cs │ │ │ └── Extractor.cs │ │ ├── DdsImage │ │ │ ├── Writer.cs │ │ │ ├── Reader.cs │ │ │ └── Extractor.cs │ │ ├── FormatReplace.cs │ │ ├── PortableExecutable │ │ │ └── Writer.cs │ │ └── Po │ │ │ └── NodeContainerToPo.cs │ │ ├── Helpers │ │ ├── HexStringJsonConverter.cs │ │ └── HexStringListJsonConverter.cs │ │ └── Models │ │ └── PortableExecutableStringInfo.cs ├── Tests │ └── TF3.Tests │ │ ├── TF3.Tests.csproj │ │ ├── Converters │ │ ├── FormatReplaceTests.cs │ │ ├── SingleNodeToFormatTests.cs │ │ ├── BitmapImage │ │ │ └── ExtractToPngTests.cs │ │ └── BinaryPatch │ │ │ └── ApplyTests.cs │ │ ├── ChecksumHelperTests.cs │ │ ├── GameScriptTests.cs │ │ └── ScriptManagerTests.cs ├── Directory.Packages.props └── Directory.Build.props ├── .config └── dotnet-tools.json ├── PULL_REQUEST_TEMPLATE.md ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── .vscode ├── settings.json ├── launch.json └── tasks.json ├── SECURITY.md ├── .devcontainer ├── Dockerfile └── devcontainer.json ├── Tests.runsettings ├── LICENSE ├── GitReleaseManager.yaml ├── FAQ.md ├── README.md └── CODE_OF_CONDUCT.md /docs/dev/Changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | To be filled on preview builds. 4 | -------------------------------------------------------------------------------- /docs/guides/First-Steps.md: -------------------------------------------------------------------------------- 1 | # First steps 2 | 3 | Welcome to this project! 4 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | uid: README 3 | --- 4 | 5 | [!include[README](../README.md)] 6 | -------------------------------------------------------------------------------- /docs/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kaplas80/TF3/HEAD/docs/images/favicon.png -------------------------------------------------------------------------------- /docs/images/logo_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kaplas80/TF3/HEAD/docs/images/logo_128.png -------------------------------------------------------------------------------- /docs/images/logo_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kaplas80/TF3/HEAD/docs/images/logo_48.png -------------------------------------------------------------------------------- /docs/dev/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Changelog 2 | href: Changelog.md 3 | - name: API 4 | href: ../api/toc.yml 5 | -------------------------------------------------------------------------------- /docs/guides/Contributing.md: -------------------------------------------------------------------------------- 1 | --- 2 | uid: CONTRIBUTING 3 | --- 4 | 5 | [!include[CONTRIBUTING](../../CONTRIBUTING.md)] 6 | -------------------------------------------------------------------------------- /GitVersion.yml: -------------------------------------------------------------------------------- 1 | mode: ContinuousDeployment 2 | branches: 3 | master: 4 | regex: ^main$ 5 | tag: preview 6 | increment: Patch 7 | -------------------------------------------------------------------------------- /docs/filter_config.yml: -------------------------------------------------------------------------------- 1 | apiRules: 2 | # Remove object method inheritance 3 | - exclude: 4 | uidRegex: ^System\.Object 5 | type: Type -------------------------------------------------------------------------------- /docs/pdf/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Overview 2 | href: ../index.md 3 | 4 | - name: Guides 5 | href: ../guides/toc.yml 6 | 7 | - name: API 8 | href: ../api/toc.yml 9 | -------------------------------------------------------------------------------- /docs/guides/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Guides 2 | items: 3 | - name: First steps 4 | href: First-Steps.md 5 | - name: Contributing 6 | items: 7 | - name: Guidelines 8 | href: Contributing.md 9 | -------------------------------------------------------------------------------- /docs/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Home 2 | href: index.md 3 | 4 | - name: Guides 5 | href: guides/ 6 | 7 | - name: API 8 | href: dev/ 9 | 10 | - name: GitHub 11 | href: https://github.com/Kaplas80/TF3 12 | -------------------------------------------------------------------------------- /src/Apps/TF3.CommandLine/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "TF3.CommandLine": { 4 | "commandName": "Project", 5 | "commandLineArgs": "" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "cake.tool": { 6 | "version": "3.0.0", 7 | "commands": [ 8 | "dotnet-cake" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | A clear and concise description of what the bug or feature is. 4 | 5 | ### Example 6 | 7 | Small example on how to use the new classes and methods. 8 | 9 | This closes # 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "" 5 | labels: "" 6 | assignees: "" 7 | --- 8 | 9 | A clear and concise description of what the problem is. 10 | 11 | **Describe the solution you'd like to see.** 12 | -------------------------------------------------------------------------------- /docs/global_metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "_appTitle": "Translation Framework v3", 3 | "_appFooter": "Copyright (c) 2022 Kaplas", 4 | "_appLogoPath": "images/logo_48.png", 5 | "_appFaviconPath": "images/favicon.png", 6 | "_enableSearch": true, 7 | "_enableNewTab": true, 8 | "_gitContribute": { 9 | "apiSpecFolder": "docs/apidoc", 10 | "repo": "https://github.com/Kaplas80/TF3", 11 | "branch": "main" 12 | } 13 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "editor.rulers": [ 4 | 80, 5 | 120 6 | ], 7 | "editor.renderWhitespace": "boundary", 8 | "editor.defaultFormatter": "esbenp.prettier-vscode", 9 | "[markdown]": { 10 | "editor.formatOnSave": true, 11 | }, 12 | "[csharp]": { 13 | "editor.defaultFormatter": "ms-dotnettools.csharp", 14 | }, 15 | "prettier.proseWrap": "always", 16 | "cSpell.words": [ 17 | "Yakuza", 18 | "Yarhl", 19 | "kaplas" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Only the latest stable version is actively supported with critical bug fixed and 6 | security issues. 7 | 8 | ## Reporting a Vulnerability 9 | 10 | Vulnerabilities can be reported to my personal email address (you can check it 11 | from my [GitHub profile](https://github.com/pleonex)). 12 | 13 | All the security issues will be analyzed and a reply will be given in two 14 | working days. Once the issue is accepted it will be fixed in the current 15 | development branch and for the latest version. A new version would be released. 16 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/vscode/devcontainers/dotnet:6.0-jammy 2 | 3 | # Install Mono (for DocFX) 4 | RUN apt install -y apt-transport-https dirmngr gnupg ca-certificates \ 5 | && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \ 6 | && echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" >> /etc/apt/sources.list.d/mono-official-stable.list \ 7 | && apt update \ 8 | && apt install -y mono-devel 9 | 10 | # Bug in the installation of .NET 6 in ubuntu https://github.com/dotnet/runtime/issues/79237 11 | ENV DOTNET_ROOT=/usr/share/dotnet -------------------------------------------------------------------------------- /src/nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/TF3.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Tests/TF3.Tests/TF3.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Apps/TF3.CommandLine/TF3.CommandLine.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | win-x64;linux-x64;osx-x64 7 | linux-x64 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "Cake: Run Build", 12 | "program": "${workspaceFolder}/src/Apps/TF3.CommandLine/bin/Debug/net6.0/linux-x64/TF3.CommandLine.dll", 13 | "args": [], 14 | "cwd": "${workspaceFolder}/src/Apps/TF3.CommandLine/bin/Debug/net6.0/linux-x64", 15 | "stopAtEntry": false, 16 | "console": "internalConsole" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "" 5 | labels: "" 6 | assignees: "" 7 | --- 8 | 9 | **Describe the bug** 10 | A clear and concise description of what the bug is. 11 | 12 | **To Reproduce** 13 | Steps to reproduce the behavior: 14 | 15 | 1. Get the library from '...' and version '...' 16 | 2. Use the class and method '....' 17 | 3. See error 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Exceptions** 23 | If applicable, the full exception stacktrace that you get. 24 | 25 | **Screenshots** 26 | If applicable, add screenshots to help explain your problem. 27 | 28 | **Desktop (please complete the following information):** 29 | 30 | - OS: [e.g. Windows, Linux, Mac] 31 | - Version [e.g. 22] 32 | 33 | **Additional context** 34 | Add any other context about the problem here. 35 | -------------------------------------------------------------------------------- /Tests.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ./artifacts/test_results 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | cobertura 15 | [.*UnitTest]*,[.*IntegrationTest]* 16 | GeneratedCodeAttribute,ExcludeFromCodeCoverageAttribute 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/TF3.YarhlPlugin.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Dev (.NET 6 and Mono)", 3 | "build": { 4 | "dockerfile": "Dockerfile" 5 | }, 6 | 7 | "customizations": { 8 | "vscode": { 9 | "extensions": [ 10 | "ms-dotnettools.csharp", 11 | "shardulm94.trailing-spaces", 12 | "cake-build.cake-vscode", 13 | "streetsidesoftware.code-spell-checker", 14 | "hediet.vscode-drawio", 15 | "esbenp.prettier-vscode", 16 | "yzhang.markdown-all-in-one", 17 | "davidanson.vscode-markdownlint", 18 | "eamodio.gitlens" 19 | ] 20 | } 21 | }, 22 | 23 | "remoteUser": "vscode", 24 | 25 | // PODMAN ONLY. You may need to remove this line for Docker. 26 | // SELinux issues: https://github.com/containers/podman/issues/3683 27 | // "runArgs": [ "--security-opt", "label=disable", "--userns=keep-id" ], 28 | 29 | // Podman issues: https://github.com/microsoft/vscode-remote-release/issues/3231 30 | "containerEnv": { 31 | "HOME": "/home/vscode" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Kaplas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /GitReleaseManager.yaml: -------------------------------------------------------------------------------- 1 | # Configuration values used when creating new releases 2 | create: 3 | include-footer: false 4 | include-sha-section: false 5 | allow-update-to-published: false 6 | 7 | # Configuration values used when exporting release notes 8 | export: 9 | include-created-date-in-title: true 10 | created-date-string-format: MMMM dd, yyyy 11 | perform-regex-removal: false 12 | 13 | # Configuration values used when closing a milestone 14 | close: 15 | use-issue-comments: false 16 | # issue-comment: |- 17 | # :tada: This issue has been resolved in version {milestone} :tada: 18 | # 19 | # The release is available on: 20 | # 21 | # - [GitHub release](https://github.com/{owner}/{repository}/releases/tag/{milestone}) 22 | # 23 | # Your **[GitReleaseManager](https://github.com/GitTools/GitReleaseManager)** bot :package::rocket: 24 | 25 | # The labels that will be used to include issues in release notes. 26 | issue-labels-include: 27 | - Breaking 28 | - Bug 29 | - Documentation 30 | - Duplicate 31 | - Enhancement 32 | - Feature 33 | - Improvement 34 | - Question 35 | 36 | # The labels that will NOT be used when including issues in release notes. 37 | issue-labels-exclude: 38 | - Internal Refactoring 39 | 40 | # Overrides default pluralization and header names for specific labels. 41 | issue-labels-alias: 42 | - name: Documentation 43 | header: Documentation 44 | plural: Documentation 45 | -------------------------------------------------------------------------------- /src/Directory.Packages.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Apps/TF3.CommandLine/Options/ListScriptsOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.CommandLine.Options 22 | { 23 | /// 24 | /// Shows a list of available scripts. 25 | /// 26 | [global::CommandLine.Verb("listscripts", HelpText = "Shows a list of available scripts.")] 27 | public class ListScriptsOptions 28 | { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Tests/TF3.Tests/Converters/FormatReplaceTests.cs: -------------------------------------------------------------------------------- 1 | namespace TF3.Tests.Converters 2 | { 3 | using System; 4 | using NUnit.Framework; 5 | using TF3.YarhlPlugin.Common.Converters; 6 | using Yarhl.IO; 7 | 8 | public class FormatReplaceTests 9 | { 10 | [Test] 11 | public void NullSourceThrowsException() 12 | { 13 | var converter = new FormatReplace(); 14 | _ = Assert.Throws(() => converter.Convert(null)); 15 | } 16 | 17 | [Test] 18 | public void UninitializedConverterThrowsException() 19 | { 20 | using var format = new BinaryFormat(); 21 | var converter = new FormatReplace(); 22 | _ = Assert.Throws(() => converter.Convert(format)); 23 | } 24 | 25 | [Test] 26 | public void NullInitializationThrowsException() 27 | { 28 | using var format = new BinaryFormat(); 29 | var converter = new FormatReplace(); 30 | converter.Initialize(null); 31 | _ = Assert.Throws(() => converter.Convert(format)); 32 | } 33 | 34 | [Test] 35 | public void ConvertFormat() 36 | { 37 | using var format1 = new BinaryFormat(); 38 | using var format2 = new BinaryFormat(); 39 | var converter = new FormatReplace(); 40 | converter.Initialize(format2); 41 | 42 | BinaryFormat result = converter.Convert(format1) as BinaryFormat; 43 | Assert.AreSame(format2, result); 44 | Assert.AreNotSame(format1, result); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Enums/BitmapExtractionFormat.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Enums 22 | { 23 | /// 24 | /// Bitmap pixel formats. 25 | /// 26 | public enum BitmapExtractionFormat 27 | { 28 | /// 29 | /// PNG format. 30 | /// 31 | Png = 0, 32 | 33 | /// 34 | /// TGA format. 35 | /// 36 | Tga = 1, 37 | 38 | /// 39 | /// BMP format. 40 | /// 41 | Bmp = 2, 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "process", 6 | "command": "dotnet", 7 | "args": [ 8 | "cake" 9 | ], 10 | "group": "build", 11 | "problemMatcher": [ 12 | "$msCompile" 13 | ], 14 | "label": "Cake: Run Default" 15 | }, 16 | { 17 | "type": "process", 18 | "command": "dotnet", 19 | "args": [ 20 | "cake", 21 | "--target=Build" 22 | ], 23 | "group": { 24 | "kind": "build", 25 | "isDefault": true 26 | }, 27 | "problemMatcher": [ 28 | "$msCompile" 29 | ], 30 | "label": "Cake: Run Build" 31 | }, 32 | { 33 | "type": "process", 34 | "command": "dotnet", 35 | "args": [ 36 | "cake", 37 | "--target=BuildTest" 38 | ], 39 | "group": { 40 | "kind": "test", 41 | "isDefault": true 42 | }, 43 | "problemMatcher": [ 44 | "$msCompile" 45 | ], 46 | "label": "Cake: Run Test" 47 | }, 48 | { 49 | "type": "process", 50 | "command": "dotnet", 51 | "args": [ 52 | "cake", 53 | "--target=Build", 54 | "--configuration=Release" 55 | ], 56 | "group": "build", 57 | "problemMatcher": [ 58 | "$msCompile" 59 | ], 60 | "label": "Cake: Run Build for release" 61 | } 62 | ] 63 | } -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Models/ConverterInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Models 22 | { 23 | using System.Diagnostics.CodeAnalysis; 24 | 25 | /// 26 | /// Yarhl converter info. 27 | /// 28 | [ExcludeFromCodeCoverage] 29 | public class ConverterInfo 30 | { 31 | /// 32 | /// Gets or sets the converter type name. 33 | /// 34 | public string TypeName { get; set; } 35 | 36 | /// 37 | /// Gets or sets the converter parameter id. 38 | /// 39 | public string ParameterId { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Models/AssetFileInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Models 22 | { 23 | using System.Collections.Generic; 24 | using System.Diagnostics.CodeAnalysis; 25 | 26 | /// 27 | /// Game asset file info. 28 | /// 29 | [ExcludeFromCodeCoverage] 30 | public class AssetFileInfo : FileInfo 31 | { 32 | /// 33 | /// Gets or sets the list of converters needed to read the file. 34 | /// 35 | public List Readers { get; set; } 36 | 37 | /// 38 | /// Gets or sets the list of converters needed to write the file. 39 | /// 40 | public List Writers { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Formats/BitmapFileFormat.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Formats 22 | { 23 | using SixLabors.ImageSharp; 24 | using Yarhl.FileFormat; 25 | 26 | /// 27 | /// IFormat wrapper for SixLabors.ImageSharp.Image. 28 | /// 29 | public class BitmapFileFormat : IFormat 30 | { 31 | /// 32 | /// Initializes a new instance of the class. 33 | /// 34 | public BitmapFileFormat() 35 | { 36 | Internal = null; 37 | } 38 | 39 | /// 40 | /// Gets or sets the Image. 41 | /// 42 | public Image Internal { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Formats/DdsFileFormat.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Formats 22 | { 23 | using BCnEncoder.Shared.ImageFiles; 24 | using Yarhl.FileFormat; 25 | 26 | /// 27 | /// IFormat wrapper for BCnEncoder.Shared.ImageFiles.DdsFile. 28 | /// 29 | public class DdsFileFormat : IFormat 30 | { 31 | /// 32 | /// Initializes a new instance of the class. 33 | /// 34 | public DdsFileFormat() 35 | { 36 | Internal = null; 37 | } 38 | 39 | /// 40 | /// Gets or sets the DdsFile. 41 | /// 42 | public DdsFile Internal { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/EventArgs/ScriptEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.EventArgs 22 | { 23 | using System.Diagnostics.CodeAnalysis; 24 | 25 | /// 26 | /// Script events arguments. 27 | /// 28 | [ExcludeFromCodeCoverage] 29 | public class ScriptEventArgs 30 | { 31 | /// 32 | /// Initializes a new instance of the class. 33 | /// 34 | /// Script info. 35 | public ScriptEventArgs(GameScript script) 36 | { 37 | Data = script; 38 | } 39 | 40 | /// 41 | /// Gets the script info. 42 | /// 43 | public GameScript Data { get; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/EventArgs/AssetEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.EventArgs 22 | { 23 | using System.Diagnostics.CodeAnalysis; 24 | using TF3.Core.Models; 25 | 26 | /// 27 | /// Asset events arguments. 28 | /// 29 | [ExcludeFromCodeCoverage] 30 | public class AssetEventArgs 31 | { 32 | /// 33 | /// Initializes a new instance of the class. 34 | /// 35 | /// Asset info. 36 | public AssetEventArgs(AssetInfo assetInfo) 37 | { 38 | Data = assetInfo; 39 | } 40 | 41 | /// 42 | /// Gets the asset info. 43 | /// 44 | public AssetInfo Data { get; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/EventArgs/PatchEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.EventArgs 22 | { 23 | using System.Diagnostics.CodeAnalysis; 24 | using TF3.Core.Models; 25 | 26 | /// 27 | /// Patch events arguments. 28 | /// 29 | [ExcludeFromCodeCoverage] 30 | public class PatchEventArgs 31 | { 32 | /// 33 | /// Initializes a new instance of the class. 34 | /// 35 | /// Patch info. 36 | public PatchEventArgs(PatchInfo patchInfo) 37 | { 38 | Data = patchInfo; 39 | } 40 | 41 | /// 42 | /// Gets the patch info. 43 | /// 44 | public PatchInfo Data { get; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Models/ParameterInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Models 22 | { 23 | using System.Diagnostics.CodeAnalysis; 24 | using System.Text.Json; 25 | 26 | /// 27 | /// Converter parameter info. 28 | /// 29 | [ExcludeFromCodeCoverage] 30 | public class ParameterInfo 31 | { 32 | /// 33 | /// Gets or sets the parameter id. 34 | /// 35 | public string Id { get; set; } 36 | 37 | /// 38 | /// Gets or sets the parameter type name. 39 | /// 40 | public string TypeName { get; set; } 41 | 42 | /// 43 | /// Gets or sets the parameter value. 44 | /// 45 | public JsonElement Value { get; set; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/Common/ImageExtractorParameters.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | namespace TF3.YarhlPlugin.Common.Converters.Common 21 | { 22 | using TF3.YarhlPlugin.Common.Enums; 23 | 24 | /// 25 | /// Parameters for Bitmap extractor. 26 | /// 27 | public class ImageExtractorParameters 28 | { 29 | /// 30 | /// Initializes a new instance of the class. 31 | /// 32 | public ImageExtractorParameters() 33 | { 34 | ImageFormat = BitmapExtractionFormat.Png; 35 | } 36 | 37 | /// 38 | /// Gets or sets a value indicating the image pixel format. 39 | /// 40 | public BitmapExtractionFormat ImageFormat { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /FAQ.md: -------------------------------------------------------------------------------- 1 | # Translation Framework v3 FAQ 2 | 3 | - **How can I use it? When I double click on the exe file, it opens a black window and closes inmediately...** 4 | 5 | It is a console app. You need to open a terminal or command line to run it. 6 | 7 | - **But `Translation Framework v2` had windows and it was easier to use...** 8 | 9 | Yes, but TF2 was limited to run under Microsoft Windows. TF3 can run on Linux and macOS too. In the future, I want to add a GUI to the app, but I think it is not prioritary. 10 | 11 | - **I'm a developer, can I help you?** 12 | 13 | Of course!! Feel free to fork the project and make your own changes. And, if you have questions about the code, you can open an issue or contact me in Discord: Kaplas#7401 14 | 15 | - **I'm not a developer, can I help you?** 16 | 17 | Yes! There are many tasks that don't need coding skills: identify translatable assets in games, testing and finding bugs... 18 | Contact me if you think you can help with something. 19 | 20 | - **I want to translate `` but it is not supported in TF3. Can you add it?** 21 | 22 | I can't promise it: Adding a new game is not an easy task (usually) and I develop this app in my free time, so I can't add all the games. 23 | 24 | - **But it already supports ``, adding ` 2` should be easy!** 25 | 26 | Probably, but not always. For example, Yakuza 0 and Kiwami uses the same file formats, but Kiwami 2 is very different. 27 | 28 | - **I can pay you $XX if you add ``** 29 | 30 | Keep it in your pocket. I do it as a hobby in my free time. 31 | 32 | - **I'm going to send you this game file t...** 33 | 34 | STOP!!! Don't share it with me. It is illegal. 35 | 36 | - **TF3 throws a `Checksum mismatch` error. What can I do?** 37 | 38 | There can be two causes for this error: 39 | 40 | 1. The game has been updated: In this case, let me know, and I'll update the app as soon as possible. 41 | 2. Your game is a pirated copy: GTFO! I do not condone piracy and you won't get support here. 42 | 43 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/EventArgs/ContainerEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.EventArgs 22 | { 23 | using System.Diagnostics.CodeAnalysis; 24 | using TF3.Core.Models; 25 | 26 | /// 27 | /// Container events arguments. 28 | /// 29 | [ExcludeFromCodeCoverage] 30 | public class ContainerEventArgs 31 | { 32 | /// 33 | /// Initializes a new instance of the class. 34 | /// 35 | /// Container info. 36 | public ContainerEventArgs(ContainerInfo containerInfo) 37 | { 38 | Data = containerInfo; 39 | } 40 | 41 | /// 42 | /// Gets the container info. 43 | /// 44 | public ContainerInfo Data { get; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docs/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": [ 5 | { 6 | "files": [ 7 | "Libraries/TF3.Core/bin/**/TF3.Core.dll", 8 | "Libraries/TF3.YarlhPlugin.Common/bin/**/TF3.YarlhPlugin.Common.dll" 9 | ], 10 | "src": "../src" 11 | } 12 | ], 13 | "dest": "api", 14 | "filter": "filter_config.yml", 15 | "disableGitFeatures": false, 16 | "disableDefaultFilter": false 17 | } 18 | ], 19 | "build": { 20 | "content": [ 21 | { 22 | "files": ["api/**.yml", "dev/**"] 23 | }, 24 | { 25 | "files": ["toc.yml", "index.md"] 26 | }, 27 | { 28 | "files": ["guides/**"] 29 | }, 30 | { 31 | "files": ["README.md", "CONTRIBUTING.md"], 32 | "src": "../" 33 | } 34 | ], 35 | "resource": [ 36 | { 37 | "files": ["images/**"] 38 | } 39 | ], 40 | "dest": "_site", 41 | "globalMetadataFiles": ["global_metadata.json"], 42 | "fileMetadataFiles": [], 43 | "template": ["default", "statictoc", "default-widescreen"], 44 | "postProcessors": [], 45 | "markdownEngineName": "markdig", 46 | "noLangKeyword": false, 47 | "keepFileLink": false, 48 | "cleanupCacheHistory": false, 49 | "disableGitFeatures": false, 50 | "xrefService": ["https://xref.docs.microsoft.com/query?uid={uid}"] 51 | }, 52 | "pdf": { 53 | "content": [ 54 | { 55 | "files": ["pdf/**"] 56 | }, 57 | { 58 | "files": ["api/**.yml"], 59 | "exclude": ["**/toc.yml"] 60 | }, 61 | { 62 | "files": ["index.md"] 63 | }, 64 | { 65 | "files": ["guides/**"], 66 | "exclude": ["**/toc.yml"] 67 | }, 68 | { 69 | "files": ["README.md", "CONTRIBUTING.md"], 70 | "src": "../" 71 | } 72 | ], 73 | "resource": [ 74 | { 75 | "files": ["images/**"] 76 | } 77 | ], 78 | "dest": "_site_pdf" 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/A8Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class A8Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/L8Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class L8Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/L16Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class L16Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/La16Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class La16Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/La32Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class La32Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Rg32Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Rg32Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Abgr32Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Abgr32Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Argb32Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Argb32Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Bgr24Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Bgr24Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Bgr565Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Bgr565Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Bgra32Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Bgra32Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Byte4Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Byte4Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Rgb24Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Rgb24Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Rgb48Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Rgb48Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Rgba32Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Rgba32Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Rgba64Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Rgba64Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Short2Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Short2Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Short4Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Short4Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Bgra4444Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Bgra4444Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Bgra5551Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Bgra5551Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/HalfSingleReplace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class HalfSingleReplace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/HalfVector2Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class HalfVector2Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/HalfVector4Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class HalfVector4Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/Rgba1010102Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class Rgba1010102Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/RgbaVectorReplace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class RgbaVectorReplace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/NormalizedByte2Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class NormalizedByte2Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/NormalizedByte4Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class NormalizedByte4Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/NormalizedShort2Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class NormalizedShort2Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/NormalizedShort4Replace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using SixLabors.ImageSharp; 24 | using SixLabors.ImageSharp.PixelFormats; 25 | using Yarhl.IO; 26 | 27 | /// 28 | /// Replaces the original image with a new one. 29 | /// 30 | public class NormalizedShort4Replace : AbstractReplace 31 | { 32 | /// 33 | /// Converter initializer. 34 | /// 35 | /// 36 | /// Initialization is mandatory. 37 | /// 38 | /// New image binary. 39 | public override void Initialize(BinaryFormat parameters) 40 | { 41 | parameters.Stream.Seek(0); 42 | SetNewImage(Image.Load(parameters.Stream)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Helpers/HexStringJsonConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Luke Vo 2 | // Code from: https://stackoverflow.com/questions/70171426/c-sharp-json-converting-hex-literal-string-to-int 3 | 4 | namespace TF3.Core.Helpers 5 | { 6 | using System; 7 | using System.Diagnostics.CodeAnalysis; 8 | using System.Text.Json; 9 | using System.Text.Json.Serialization; 10 | 11 | /// 12 | /// Json serializer for hexadecimal numbers. 13 | /// 14 | /// Output type. 15 | [ExcludeFromCodeCoverage] 16 | public sealed class HexStringJsonConverter : JsonConverter 17 | { 18 | /// 19 | public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 20 | { 21 | string strValue = reader.GetString(); 22 | 23 | return Type.GetTypeCode(typeToConvert) switch 24 | { 25 | TypeCode.Byte => (T)Convert.ChangeType(Convert.ToByte(strValue, 16), typeof(T)), 26 | TypeCode.SByte => (T)Convert.ChangeType(Convert.ToSByte(strValue, 16), typeof(T)), 27 | TypeCode.UInt16 => (T)Convert.ChangeType(Convert.ToUInt16(strValue, 16), typeof(T)), 28 | TypeCode.UInt32 => (T)Convert.ChangeType(Convert.ToUInt32(strValue, 16), typeof(T)), 29 | TypeCode.UInt64 => (T)Convert.ChangeType(Convert.ToUInt64(strValue, 16), typeof(T)), 30 | TypeCode.Int16 => (T)Convert.ChangeType(Convert.ToInt16(strValue, 16), typeof(T)), 31 | TypeCode.Int32 => (T)Convert.ChangeType(Convert.ToInt32(strValue, 16), typeof(T)), 32 | TypeCode.Int64 => (T)Convert.ChangeType(Convert.ToInt64(strValue, 16), typeof(T)), 33 | _ => throw new NotSupportedException("Type not supported in converter"), 34 | }; 35 | } 36 | 37 | /// 38 | public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Helpers/HexStringJsonConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Luke Vo 2 | // Code from: https://stackoverflow.com/questions/70171426/c-sharp-json-converting-hex-literal-string-to-int 3 | 4 | namespace TF3.YarhlPlugin.Common.Helpers 5 | { 6 | using System; 7 | using System.Diagnostics.CodeAnalysis; 8 | using System.Text.Json; 9 | using System.Text.Json.Serialization; 10 | 11 | /// 12 | /// Json serializer for hexadecimal numbers. 13 | /// 14 | /// Output type. 15 | [ExcludeFromCodeCoverage] 16 | public sealed class HexStringJsonConverter : JsonConverter 17 | { 18 | /// 19 | public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 20 | { 21 | string strValue = reader.GetString(); 22 | 23 | return Type.GetTypeCode(typeToConvert) switch 24 | { 25 | TypeCode.Byte => (T)Convert.ChangeType(Convert.ToByte(strValue, 16), typeof(T)), 26 | TypeCode.SByte => (T)Convert.ChangeType(Convert.ToSByte(strValue, 16), typeof(T)), 27 | TypeCode.UInt16 => (T)Convert.ChangeType(Convert.ToUInt16(strValue, 16), typeof(T)), 28 | TypeCode.UInt32 => (T)Convert.ChangeType(Convert.ToUInt32(strValue, 16), typeof(T)), 29 | TypeCode.UInt64 => (T)Convert.ChangeType(Convert.ToUInt64(strValue, 16), typeof(T)), 30 | TypeCode.Int16 => (T)Convert.ChangeType(Convert.ToInt16(strValue, 16), typeof(T)), 31 | TypeCode.Int32 => (T)Convert.ChangeType(Convert.ToInt32(strValue, 16), typeof(T)), 32 | TypeCode.Int64 => (T)Convert.ChangeType(Convert.ToInt64(strValue, 16), typeof(T)), 33 | _ => throw new NotSupportedException("Type not supported in converter"), 34 | }; 35 | } 36 | 37 | /// 38 | public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/DdsImage/Writer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.DdsImage 22 | { 23 | using System; 24 | using TF3.YarhlPlugin.Common.Formats; 25 | using Yarhl.FileFormat; 26 | using Yarhl.IO; 27 | 28 | /// 29 | /// DDS file writer. 30 | /// 31 | public class Writer : IConverter 32 | { 33 | /// 34 | /// Writes a DDS file. 35 | /// 36 | /// The DDS format. 37 | /// The DDS file. 38 | public BinaryFormat Convert(DdsFileFormat source) 39 | { 40 | if (source == null) 41 | { 42 | throw new ArgumentNullException(nameof(source)); 43 | } 44 | 45 | var result = new BinaryFormat(); 46 | source.Internal.Write(result.Stream); 47 | return result; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Apps/TF3.CommandLine/Options/ExtractOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.CommandLine.Options 22 | { 23 | using global::CommandLine; 24 | 25 | /// 26 | /// Extract editable contents. 27 | /// 28 | [Verb("extract", HelpText = "Extract editable contents.")] 29 | public class ExtractOptions 30 | { 31 | /// 32 | /// Gets or sets the script to use. 33 | /// 34 | [Option("script", Required = true, HelpText = "Script to use")] 35 | public string Script { get; set; } 36 | 37 | /// 38 | /// Gets or sets the game directory. 39 | /// 40 | [Option("install-dir", Required = true, HelpText = "Game directory.")] 41 | public string GameDir { get; set; } 42 | 43 | /// 44 | /// Gets or sets the output directory. 45 | /// 46 | [Option("output-dir", Required = true, HelpText = "Output directory.")] 47 | public string Output { get; set; } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/DdsImage/Reader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.DdsImage 22 | { 23 | using System; 24 | using BCnEncoder.Shared.ImageFiles; 25 | using TF3.YarhlPlugin.Common.Formats; 26 | using Yarhl.FileFormat; 27 | using Yarhl.IO; 28 | 29 | /// 30 | /// DDS file reader. 31 | /// 32 | public class Reader : IConverter 33 | { 34 | /// 35 | /// Reads a DDS file. 36 | /// 37 | /// The DDS file. 38 | /// The DDS format. 39 | public DdsFileFormat Convert(BinaryFormat source) 40 | { 41 | if (source == null) 42 | { 43 | throw new ArgumentNullException(nameof(source)); 44 | } 45 | 46 | source.Stream.Seek(0); 47 | return new DdsFileFormat() 48 | { 49 | Internal = DdsFile.Load(source.Stream), 50 | }; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Models/FileInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Models 22 | { 23 | using System.Diagnostics.CodeAnalysis; 24 | using System.Text.Json.Serialization; 25 | using TF3.Core.Helpers; 26 | 27 | /// 28 | /// Game file info. 29 | /// 30 | [ExcludeFromCodeCoverage] 31 | public class FileInfo 32 | { 33 | /// 34 | /// Gets or sets the file name. 35 | /// 36 | public string Name { get; set; } 37 | 38 | /// 39 | /// Gets or sets the container id. 40 | /// 41 | public string ContainerId { get; set; } 42 | 43 | /// 44 | /// Gets or sets the file path (inside the container). 45 | /// 46 | public string Path { get; set; } 47 | 48 | /// 49 | /// Gets or sets the file checksum. 50 | /// If it is 0x0, it won't be checked. 51 | /// 52 | [JsonConverter(typeof(HexStringJsonConverter))] 53 | public ulong Checksum { get; set; } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Tests/TF3.Tests/Converters/SingleNodeToFormatTests.cs: -------------------------------------------------------------------------------- 1 | namespace TF3.Tests.Converters 2 | { 3 | using System; 4 | using NUnit.Framework; 5 | using TF3.Core.Converters; 6 | using Yarhl.FileFormat; 7 | using Yarhl.FileSystem; 8 | using Yarhl.IO; 9 | 10 | public class SingleNodeToFormatTests 11 | { 12 | [Test] 13 | public void NullSourceThrowsException() 14 | { 15 | var converter = new SingleNodeToFormat(); 16 | _ = Assert.Throws(() => converter.Convert(null)); 17 | } 18 | 19 | [Test] 20 | public void MoreThanOneChildThrowsException() 21 | { 22 | using var format = new NodeContainerFormat(); 23 | using var node1 = new Node("Node1"); 24 | using var node2 = new Node("Node2"); 25 | format.Root.Add(node1); 26 | format.Root.Add(node2); 27 | 28 | var converter = new SingleNodeToFormat(); 29 | _ = Assert.Throws(() => converter.Convert(format)); 30 | } 31 | 32 | [Test] 33 | public void ConvertCloneableFormat() 34 | { 35 | using var format = new NodeContainerFormat(); 36 | using var binaryFormat = new BinaryFormat(); 37 | using var node = new Node("Node", binaryFormat); 38 | format.Root.Add(node); 39 | 40 | var converter = new SingleNodeToFormat(); 41 | 42 | BinaryFormat result = converter.Convert(format) as BinaryFormat; 43 | Assert.IsNotNull(result); 44 | 45 | Assert.AreNotSame(binaryFormat, result); 46 | } 47 | 48 | [Test] 49 | public void ConvertNotCloneableFormat() 50 | { 51 | using var format = new NodeContainerFormat(); 52 | var notCloneable = new NotCloneableFormat(); 53 | using var node = new Node("Node", notCloneable); 54 | format.Root.Add(node); 55 | 56 | var converter = new SingleNodeToFormat(); 57 | 58 | NotCloneableFormat result = converter.Convert(format) as NotCloneableFormat; 59 | Assert.IsNotNull(result); 60 | 61 | Assert.AreSame(notCloneable, result); 62 | } 63 | 64 | private class NotCloneableFormat : IFormat 65 | { 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Translation Framework v3 (Powered by [Yarhl](https://scenegate.github.io/Yarhl/)) 2 | [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://choosealicense.com/licenses/mit/) ![Build and release](https://github.com/kaplas80/TF3/workflows/Build%20and%20release/badge.svg) 3 | 4 | ## Current State 5 | 6 | This framework is in ***alpha*** state and under active development. There might be breaking changes at any moment. 7 | 8 | ## Plugins 9 | 10 | Currently, 2 games are supported: 11 | 12 | * [Yakuza Kiwami 2 (Steam)](https://github.com/Kaplas80/TF3.YakuzaPlugins) 13 | * [Zwei: The Arges Adventure (Steam)](https://github.com/Kaplas80/TF3.ZweiPlugins) 14 | 15 | ## Requisites 16 | 17 | * [.NET 6.0 runtime](https://dotnet.microsoft.com/en-us/download) 18 | 19 | ## Usage 20 | 21 | **NOTE: This is a command line application. "Double clicking" on the exe is not enough.** 22 | 23 | 1. Create `plugins` and `scripts` directories inside the app folder. 24 | 2. Copy plugins files to the respective folders. See each plugin README for details. 25 | 3. Run the app. 26 | 27 | ### List available plugins 28 | 29 | ```shell 30 | TF3.CommandLine.exe listscripts 31 | ``` 32 | 33 | ### Extract assets 34 | 35 | ```shell 36 | TF3.CommandLine.exe extract --script [script-name] --install-dir [game-files-directory] --output-dir [output-directory] 37 | ``` 38 | 39 | ### Rebuild assets 40 | 41 | ```shell 42 | TF3.CommandLine.exe rebuild --script [script-name] --install-dir [game-files-directory] --translation-dir [translation-files-directory] --output-dir [output-directory] 43 | ``` 44 | 45 | ## FAQ 46 | 47 | If you have questions, see [FAQ](https://github.com/Kaplas80/TF3/blob/main/FAQ.md) or open a new thread in [Discussions](https://github.com/Kaplas80/TF3/discussions) 48 | 49 | ## Credits 50 | 51 | * Thanks to Pleonex for [Yarhl](https://scenegate.github.io/Yarhl/) and [PleOps.Cake](https://www.pleonex.dev/PleOps.Cake/). 52 | * Other libraries used: [CommandLineParser](https://github.com/commandlineparser/commandline), [Dahomey.Json](https://github.com/dahomey-technologies/Dahomey.Json), [xxHash](https://github.com/uranium62/xxHash), [BCnEncoder.Net](https://github.com/nominom/bcnencoder.net), [ImageSharp](https://sixlabors.com/products/imagesharp/) 53 | * Icon by [Papirus Development Team](https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/). 54 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Formats/BinaryPatch.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Formats 22 | { 23 | using System.Collections.Generic; 24 | using Yarhl.FileFormat; 25 | 26 | /// 27 | /// Binary patch format. 28 | /// Similar to 1337 patch format. 29 | /// 30 | public class BinaryPatch : IFormat 31 | { 32 | /// 33 | /// Initializes a new instance of the class. 34 | /// 35 | public BinaryPatch() 36 | { 37 | FileName = string.Empty; 38 | RawOffset = 0; 39 | Patches = new List<(long, byte, byte)>(); 40 | } 41 | 42 | /// 43 | /// Gets or sets the file to apply patch. 44 | /// 45 | public string FileName { get; set; } 46 | 47 | /// 48 | /// Gets or sets the data raw offset. 49 | /// 50 | public long RawOffset { get; set; } 51 | 52 | /// 53 | /// Gets or sets the list of byte replacements. 54 | /// 55 | public List<(long Rva, byte OriginalByte, byte NewByte)> Patches { get; set; } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/ImageParameters.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage 22 | { 23 | using TF3.YarhlPlugin.Common.Enums; 24 | 25 | /// 26 | /// Parameters for Bitmap reader. 27 | /// 28 | public class ImageParameters 29 | { 30 | /// 31 | /// Initializes a new instance of the class. 32 | /// 33 | public ImageParameters() 34 | { 35 | PixelFormat = BitmapPixelFormat.Undefined; 36 | ImageWidth = 0; 37 | ImageHeight = 0; 38 | } 39 | 40 | /// 41 | /// Gets or sets a value indicating the image pixel format. 42 | /// 43 | public BitmapPixelFormat PixelFormat { get; set; } 44 | 45 | /// 46 | /// Gets or sets a value indicating the image width (in pixels). 47 | /// 48 | public int ImageWidth { get; set; } 49 | 50 | /// 51 | /// Gets or sets a value indicating the image height (in pixels). 52 | /// 53 | public int ImageHeight { get; set; } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/FormatReplace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters 22 | { 23 | using System; 24 | using Yarhl.FileFormat; 25 | 26 | /// 27 | /// Format replacer. 28 | /// 29 | public class FormatReplace : IConverter, IInitializer 30 | { 31 | private IFormat _newFormat; 32 | 33 | /// 34 | /// Set the new format. 35 | /// 36 | /// The new format. 37 | public void Initialize(IFormat parameters) => _newFormat = parameters; 38 | 39 | /// 40 | /// Fully replace a IFormat. 41 | /// 42 | /// The original format. 43 | /// The new format. 44 | public IFormat Convert(IFormat source) 45 | { 46 | if (source == null) 47 | { 48 | throw new ArgumentNullException(nameof(source)); 49 | } 50 | 51 | if (_newFormat == null) 52 | { 53 | throw new InvalidOperationException("Uninitialized."); 54 | } 55 | 56 | return _newFormat; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/PortableExecutable/Writer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.PortableExecutable 22 | { 23 | using System; 24 | using System.Diagnostics.CodeAnalysis; 25 | using TF3.YarhlPlugin.Common.Formats; 26 | using Yarhl.FileFormat; 27 | using Yarhl.IO; 28 | 29 | /// 30 | /// Serializes PE files. 31 | /// 32 | [ExcludeFromCodeCoverage] 33 | public class Writer : IConverter 34 | { 35 | /// 36 | /// Converts a PEFile into a BinaryFormat . 37 | /// 38 | /// Input format. 39 | /// The BinaryFormat format. 40 | /// Thrown if source is null. 41 | public BinaryFormat Convert(PortableExecutableFileFormat source) 42 | { 43 | if (source == null) 44 | { 45 | throw new ArgumentNullException(nameof(source)); 46 | } 47 | 48 | DataStream stream = DataStreamFactory.FromMemory(); 49 | source.Internal.Write(stream); 50 | 51 | return new BinaryFormat(stream); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Apps/TF3.CommandLine/Options/RebuildOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.CommandLine.Options 22 | { 23 | using global::CommandLine; 24 | 25 | /// 26 | /// Rebuild editable contents. 27 | /// 28 | [Verb("rebuild", HelpText = "Rebuild editable contents.")] 29 | public class RebuildOptions 30 | { 31 | /// 32 | /// Gets or sets the script to use. 33 | /// 34 | [Option("script", Required = true, HelpText = "Script to use")] 35 | public string Script { get; set; } 36 | 37 | /// 38 | /// Gets or sets the game directory. 39 | /// 40 | [Option("install-dir", Required = true, HelpText = "Game directory.")] 41 | public string GameDir { get; set; } 42 | 43 | /// 44 | /// Gets or sets the translation directory. 45 | /// 46 | [Option("translation-dir", Required = true, HelpText = "Translation directory.")] 47 | public string TranslationDir { get; set; } 48 | 49 | /// 50 | /// Gets or sets the output directory. 51 | /// 52 | [Option("output-dir", Required = true, HelpText = "Output directory.")] 53 | public string Output { get; set; } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Models/PatchInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Models 22 | { 23 | using System.Diagnostics.CodeAnalysis; 24 | using System.Text.Json.Serialization; 25 | using TF3.Core.Helpers; 26 | 27 | /// 28 | /// Binary patch info. 29 | /// 30 | [ExcludeFromCodeCoverage] 31 | public class PatchInfo 32 | { 33 | /// 34 | /// Gets or sets the patch id. 35 | /// 36 | public string Id { get; set; } 37 | 38 | /// 39 | /// Gets or sets the file to patch. 40 | /// 41 | public FileInfo File { get; set; } 42 | 43 | /// 44 | /// Gets or sets the patch to apply. 45 | /// 46 | public string Patch { get; set; } 47 | 48 | /// 49 | /// Gets or sets the data virtual address (in exe files). 50 | /// 51 | [JsonConverter(typeof(HexStringJsonConverter))] 52 | public long VirtualAddress { get; set; } 53 | 54 | /// 55 | /// Gets or sets the data raw address (in exe files). 56 | /// 57 | [JsonConverter(typeof(HexStringJsonConverter))] 58 | public long RawAddress { get; set; } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/Po/NodeContainerToPo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.Po 22 | { 23 | using System; 24 | using Yarhl.FileFormat; 25 | using Yarhl.FileSystem; 26 | 27 | /// 28 | /// Po files merger. 29 | /// 30 | public class NodeContainerToPo : IConverter 31 | { 32 | /// 33 | /// Merges all parts (BinaryFormat) in a Po file. 34 | /// 35 | /// Po parts. 36 | /// The merged Po. 37 | public Yarhl.Media.Text.Po Convert(NodeContainerFormat source) 38 | { 39 | if (source == null) 40 | { 41 | throw new ArgumentNullException(nameof(source)); 42 | } 43 | 44 | var po = new Yarhl.Media.Text.Po(); 45 | 46 | foreach (Node part in source.Root.Children) 47 | { 48 | part.TransformWith(); 49 | Yarhl.Media.Text.Po poPart = part.GetFormatAs(); 50 | po.Header = poPart.Header; 51 | po.Add(poPart.Entries); 52 | } 53 | 54 | return po; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | Translation Framework 3 4 | Kaplas 5 | None 6 | Copyright (c) 2022 Kaplas 7 | 8 | true 9 | 10 | 13 | NETSDK1179 14 | 15 | 16 | 17 | MIT 18 | https://github.com/kaplas80/TF3 19 | https://github.com/kaplas80/TF3 20 | icon.png 21 | net;csharp;romhacking;translation 22 | README.md 23 | 24 | 25 | 26 | 27 | 28 | true 29 | true 30 | snupkg 31 | true 32 | $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb 33 | 34 | true 35 | true 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | true 45 | true 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/Tests/TF3.Tests/ChecksumHelperTests.cs: -------------------------------------------------------------------------------- 1 | namespace TF3.Tests 2 | { 3 | using System.IO; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using TF3.Core.Helpers; 7 | 8 | public class ChecksumHelperTests 9 | { 10 | private const string TestData = "Test Data"; 11 | 12 | private readonly string _tempPath = Path.Combine(Path.GetTempPath(), "TF3.Tests"); 13 | 14 | [SetUp] 15 | public void Init() 16 | { 17 | if (Directory.Exists(_tempPath)) 18 | { 19 | Directory.Delete(_tempPath, true); 20 | } 21 | 22 | Directory.CreateDirectory(_tempPath); 23 | } 24 | 25 | [TearDown] 26 | public void Cleanup() 27 | { 28 | if (Directory.Exists(_tempPath)) 29 | { 30 | Directory.Delete(_tempPath, true); 31 | } 32 | } 33 | 34 | [Test] 35 | public void CheckFile() 36 | { 37 | string filePath = Path.Combine(_tempPath, "ChecksumTest.txt"); 38 | File.WriteAllText(filePath, TestData); 39 | bool result = ChecksumHelper.Check(filePath, 0x5AB1599F68E64610); 40 | Assert.IsTrue(result); 41 | result = ChecksumHelper.Check(filePath, 0x01); 42 | Assert.IsFalse(result); 43 | } 44 | 45 | [Test] 46 | public void CheckStream() 47 | { 48 | using var stream = new MemoryStream(Encoding.ASCII.GetBytes(TestData)); 49 | bool result = ChecksumHelper.Check(stream, 0x5AB1599F68E64610); 50 | Assert.IsTrue(result); 51 | result = ChecksumHelper.Check(stream, 0x01); 52 | Assert.IsFalse(result); 53 | } 54 | 55 | [Test] 56 | public void InvalidPathThrowsException() 57 | { 58 | string filePath = Path.Combine(_tempPath, "dummy.txt"); 59 | Assert.Throws(() => ChecksumHelper.Check(filePath, 0x01)); 60 | } 61 | 62 | [Test] 63 | public void ExpectZeroReturnsTrue() 64 | { 65 | string filePath = Path.Combine(_tempPath, "ChecksumTest.txt"); 66 | File.WriteAllText(filePath, TestData); 67 | Assert.IsTrue(ChecksumHelper.Check(filePath, 0x00)); 68 | 69 | using var stream = new MemoryStream(Encoding.ASCII.GetBytes(TestData)); 70 | Assert.IsTrue(ChecksumHelper.Check(stream, 0x00)); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Converters/SingleNodeToFormat.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Converters 22 | { 23 | using System; 24 | using Yarhl.FileFormat; 25 | using Yarhl.FileSystem; 26 | 27 | /// 28 | /// Converts a NodeContainerFormat to the format of the first children. 29 | /// 30 | public class SingleNodeToFormat : IConverter 31 | { 32 | /// 33 | /// Convert a NodeContainerFormat to the format of the first children. 34 | /// 35 | /// A 'single node' NodeContainerFormat. 36 | /// The format of the node. 37 | public IFormat Convert(NodeContainerFormat source) 38 | { 39 | if (source == null) 40 | { 41 | throw new ArgumentNullException(nameof(source)); 42 | } 43 | 44 | if (source.Root.Children.Count != 1) 45 | { 46 | throw new FormatException("Node must have 1 children exactly."); 47 | } 48 | 49 | if (source.Root.Children[0].Format is ICloneableFormat) 50 | { 51 | var clone = new Node(source.Root.Children[0]); 52 | return clone.Format; 53 | } 54 | else 55 | { 56 | return source.Root.Children[0].Format; 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Models/AssetInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Models 22 | { 23 | using System.Collections.Generic; 24 | using System.Diagnostics.CodeAnalysis; 25 | 26 | /// 27 | /// Game asset info. 28 | /// 29 | [ExcludeFromCodeCoverage] 30 | public class AssetInfo 31 | { 32 | /// 33 | /// Gets or sets the asset id. 34 | /// 35 | public string Id { get; set; } 36 | 37 | /// 38 | /// Gets or sets the list of output names. 39 | /// 40 | public List OutputNames { get; set; } 41 | 42 | /// 43 | /// Gets or sets the list of files in this asset. 44 | /// 45 | public List Files { get; set; } 46 | 47 | /// 48 | /// Gets or sets the list of converters needed to extract the translatable contents. 49 | /// 50 | public List Extractors { get; set; } 51 | 52 | /// 53 | /// Gets or sets the list of converters needed to merge the translation files. 54 | /// 55 | public List TranslationMergers { get; set; } 56 | 57 | /// 58 | /// Gets or sets the name of the translator converter. 59 | /// 60 | public string Translator { get; set; } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Models/PortableExecutableStringInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Models 22 | { 23 | using System.Collections.Generic; 24 | using System.Diagnostics.CodeAnalysis; 25 | using System.Text.Json.Serialization; 26 | using TF3.YarhlPlugin.Common.Helpers; 27 | 28 | /// 29 | /// Parameters for Portable Executable reading. 30 | /// 31 | [ExcludeFromCodeCoverage] 32 | public class PortableExecutableStringInfo 33 | { 34 | /// 35 | /// Gets or sets the string found inside the executable file. 36 | /// 37 | public string FoundString { get; set; } 38 | 39 | /// 40 | /// Gets or sets the string address inside the executable file. 41 | /// 42 | [JsonConverter(typeof(HexStringJsonConverter))] 43 | public int Address { get; set; } 44 | 45 | /// 46 | /// Gets or sets the size in bytes of the string. 47 | /// 48 | public int Size { get; set; } 49 | 50 | /// 51 | /// Gets or sets the string encoding. 52 | /// 53 | public string Encoding { get; set; } 54 | 55 | /// 56 | /// Gets or sets the list of pointers referencing the string. 57 | /// 58 | [JsonConverter(typeof(HexStringListJsonConverter))] 59 | public List Pointers { get; set; } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Helpers/HexStringListJsonConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Luke Vo 2 | // Code from: https://stackoverflow.com/questions/70171426/c-sharp-json-converting-hex-literal-string-to-int 3 | 4 | namespace TF3.Core.Helpers 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Diagnostics.CodeAnalysis; 9 | using System.Text.Json; 10 | using System.Text.Json.Serialization; 11 | 12 | /// 13 | /// Json serializer for hexadecimal number arrays. 14 | /// 15 | /// Output type. 16 | [ExcludeFromCodeCoverage] 17 | public sealed class HexStringListJsonConverter : JsonConverter> 18 | { 19 | /// 20 | public override List Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 21 | { 22 | if (reader.TokenType != JsonTokenType.StartArray) 23 | { 24 | throw new JsonException("Expected StartArray token"); 25 | } 26 | 27 | var result = new List(); 28 | 29 | while (reader.Read() && reader.TokenType != JsonTokenType.EndArray) 30 | { 31 | string strValue = reader.GetString(); 32 | 33 | T value = Type.GetTypeCode(typeToConvert.GenericTypeArguments[0]) switch 34 | { 35 | TypeCode.Byte => (T)Convert.ChangeType(Convert.ToByte(strValue, 16), typeof(T)), 36 | TypeCode.SByte => (T)Convert.ChangeType(Convert.ToSByte(strValue, 16), typeof(T)), 37 | TypeCode.UInt16 => (T)Convert.ChangeType(Convert.ToUInt16(strValue, 16), typeof(T)), 38 | TypeCode.UInt32 => (T)Convert.ChangeType(Convert.ToUInt32(strValue, 16), typeof(T)), 39 | TypeCode.UInt64 => (T)Convert.ChangeType(Convert.ToUInt64(strValue, 16), typeof(T)), 40 | TypeCode.Int16 => (T)Convert.ChangeType(Convert.ToInt16(strValue, 16), typeof(T)), 41 | TypeCode.Int32 => (T)Convert.ChangeType(Convert.ToInt32(strValue, 16), typeof(T)), 42 | TypeCode.Int64 => (T)Convert.ChangeType(Convert.ToInt64(strValue, 16), typeof(T)), 43 | _ => throw new NotSupportedException("Type not supported in converter"), 44 | }; 45 | 46 | result.Add(value); 47 | } 48 | 49 | return result; 50 | } 51 | 52 | /// 53 | public override void Write(Utf8JsonWriter writer, List value, JsonSerializerOptions options) 54 | { 55 | throw new NotImplementedException(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Helpers/HexStringListJsonConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Luke Vo 2 | // Code from: https://stackoverflow.com/questions/70171426/c-sharp-json-converting-hex-literal-string-to-int 3 | 4 | namespace TF3.YarhlPlugin.Common.Helpers 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Diagnostics.CodeAnalysis; 9 | using System.Text.Json; 10 | using System.Text.Json.Serialization; 11 | 12 | /// 13 | /// Json serializer for hexadecimal number arrays. 14 | /// 15 | /// Output type. 16 | [ExcludeFromCodeCoverage] 17 | public sealed class HexStringListJsonConverter : JsonConverter> 18 | { 19 | /// 20 | public override List Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 21 | { 22 | if (reader.TokenType != JsonTokenType.StartArray) 23 | { 24 | throw new JsonException("Expected StartArray token"); 25 | } 26 | 27 | var result = new List(); 28 | 29 | while (reader.Read() && reader.TokenType != JsonTokenType.EndArray) 30 | { 31 | string strValue = reader.GetString(); 32 | 33 | T value = Type.GetTypeCode(typeToConvert.GenericTypeArguments[0]) switch 34 | { 35 | TypeCode.Byte => (T)Convert.ChangeType(Convert.ToByte(strValue, 16), typeof(T)), 36 | TypeCode.SByte => (T)Convert.ChangeType(Convert.ToSByte(strValue, 16), typeof(T)), 37 | TypeCode.UInt16 => (T)Convert.ChangeType(Convert.ToUInt16(strValue, 16), typeof(T)), 38 | TypeCode.UInt32 => (T)Convert.ChangeType(Convert.ToUInt32(strValue, 16), typeof(T)), 39 | TypeCode.UInt64 => (T)Convert.ChangeType(Convert.ToUInt64(strValue, 16), typeof(T)), 40 | TypeCode.Int16 => (T)Convert.ChangeType(Convert.ToInt16(strValue, 16), typeof(T)), 41 | TypeCode.Int32 => (T)Convert.ChangeType(Convert.ToInt32(strValue, 16), typeof(T)), 42 | TypeCode.Int64 => (T)Convert.ChangeType(Convert.ToInt64(strValue, 16), typeof(T)), 43 | _ => throw new NotSupportedException("Type not supported in converter"), 44 | }; 45 | 46 | result.Add(value); 47 | } 48 | 49 | return result; 50 | } 51 | 52 | /// 53 | public override void Write(Utf8JsonWriter writer, List value, JsonSerializerOptions options) 54 | { 55 | throw new NotImplementedException(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Models/ContainerInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Models 22 | { 23 | using System.Collections.Generic; 24 | using System.Diagnostics.CodeAnalysis; 25 | using System.Text.Json.Serialization; 26 | using TF3.Core.Helpers; 27 | 28 | /// 29 | /// Game file container info. 30 | /// 31 | [ExcludeFromCodeCoverage] 32 | public class ContainerInfo 33 | { 34 | /// 35 | /// Gets or sets the container id. 36 | /// 37 | public string Id { get; set; } 38 | 39 | /// 40 | /// Gets or sets the container name. 41 | /// 42 | public string Name { get; set; } 43 | 44 | /// 45 | /// Gets or sets the container paths. 46 | /// 47 | public List Paths { get; set; } 48 | 49 | /// 50 | /// Gets or sets the container checksums. 51 | /// If it is 0x0, the file won't be checked. 52 | /// 53 | [JsonConverter(typeof(HexStringListJsonConverter))] 54 | public List Checksums { get; set; } 55 | 56 | /// 57 | /// Gets or sets the list of converters needed to read the container. 58 | /// 59 | public List Readers { get; set; } 60 | 61 | /// 62 | /// Gets or sets the list of converters needed to write the container. 63 | /// 64 | public List Writers { get; set; } 65 | 66 | /// 67 | /// Gets or sets the list of containers in this container. 68 | /// 69 | public List Containers { get; set; } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Formats/PortableExecutableFileFormat.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Formats 22 | { 23 | using System.Collections.Generic; 24 | using System.Diagnostics.CodeAnalysis; 25 | using AsmResolver.PE.File; 26 | using TF3.YarhlPlugin.Common.Models; 27 | using Yarhl.FileFormat; 28 | using Yarhl.IO; 29 | 30 | /// 31 | /// IFormat wrapper for AsmResolver.PE.File.PEFile. 32 | /// 33 | [ExcludeFromCodeCoverage] 34 | public class PortableExecutableFileFormat : ICloneableFormat 35 | { 36 | /// 37 | /// Initializes a new instance of the class. 38 | /// 39 | public PortableExecutableFileFormat() 40 | { 41 | Internal = null; 42 | StringInfo = null; 43 | } 44 | 45 | /// 46 | /// Gets or sets the PEFile. 47 | /// 48 | public PEFile Internal { get; set; } 49 | 50 | /// 51 | /// Gets or sets the PEFile. 52 | /// 53 | public List StringInfo { get; set; } 54 | 55 | /// 56 | public virtual object DeepClone() 57 | { 58 | DataStream newStream = DataStreamFactory.FromMemory(); 59 | Internal.Write(newStream); 60 | 61 | newStream.Position = 0; 62 | var reader = new DataReader(newStream); 63 | byte[] data = reader.ReadBytes((int)newStream.Length); 64 | return new PortableExecutableFileFormat() 65 | { 66 | Internal = PEFile.FromBytes(data), 67 | StringInfo = StringInfo, 68 | }; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Replace/AbstractReplace.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage.Replace 22 | { 23 | using System; 24 | using SixLabors.ImageSharp; 25 | using TF3.YarhlPlugin.Common.Formats; 26 | using Yarhl.FileFormat; 27 | using Yarhl.IO; 28 | 29 | /// 30 | /// Replaces the original image with a new one. 31 | /// 32 | public abstract class AbstractReplace : IConverter, IInitializer 33 | { 34 | private Image _newImage; 35 | 36 | /// 37 | /// Converter initializer. 38 | /// 39 | /// 40 | /// Initialization is mandatory. 41 | /// 42 | /// New image binary. 43 | public abstract void Initialize(BinaryFormat parameters); 44 | 45 | /// 46 | /// Replaces the original bitmap with a new one. 47 | /// 48 | /// Original bitmap. 49 | /// New bitmap. 50 | public BitmapFileFormat Convert(BitmapFileFormat source) 51 | { 52 | if (source == null) 53 | { 54 | throw new ArgumentNullException(nameof(source)); 55 | } 56 | 57 | if (_newImage == null) 58 | { 59 | throw new InvalidOperationException("Uninitialized"); 60 | } 61 | 62 | return new BitmapFileFormat() 63 | { 64 | Internal = _newImage, 65 | }; 66 | } 67 | 68 | /// 69 | /// Sets the new image to insert. 70 | /// 71 | /// New image. 72 | protected void SetNewImage(Image value) => _newImage = value; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Tests/TF3.Tests/Converters/BitmapImage/ExtractToPngTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Tests.Converters.BitmapImage 22 | { 23 | using System; 24 | using NUnit.Framework; 25 | using TF3.YarhlPlugin.Common.Converters.BitmapImage; 26 | using TF3.YarhlPlugin.Common.Converters.Common; 27 | using TF3.YarhlPlugin.Common.Formats; 28 | using Yarhl.IO; 29 | 30 | public class ExtractToPngTests 31 | { 32 | private readonly byte[] _validData = { 0x01 }; 33 | 34 | [Test] 35 | public void NullSourceThrowsException() 36 | { 37 | var converter = new Extractor(); 38 | converter.Initialize(new ImageExtractorParameters()); 39 | _ = Assert.Throws(() => converter.Convert(null)); 40 | } 41 | 42 | [Test] 43 | public void NullImageThrowsException() 44 | { 45 | var converter = new Extractor(); 46 | converter.Initialize(new ImageExtractorParameters()); 47 | var format = new BitmapFileFormat(); 48 | _ = Assert.Throws(() => converter.Convert(format)); 49 | } 50 | 51 | [Test] 52 | public void Export() 53 | { 54 | using DataStream ds = DataStreamFactory.FromArray(_validData, 0, _validData.Length); 55 | using var format = new BinaryFormat(ds); 56 | 57 | var reader = new Reader(); 58 | 59 | reader.Initialize(new ImageParameters { PixelFormat = YarhlPlugin.Common.Enums.BitmapPixelFormat.A8, ImageWidth = 1, ImageHeight = 1 }); 60 | BitmapFileFormat bmp = reader.Convert(format); 61 | 62 | var converter = new Extractor(); 63 | converter.Initialize(new ImageExtractorParameters()); 64 | 65 | BinaryFormat result = converter.Convert(bmp); 66 | Assert.IsNotNull(result); 67 | Assert.IsNotNull(result.Stream); 68 | 69 | result.Stream.Position = 0; 70 | var reader1 = new DataReader(result.Stream); 71 | ulong magic = reader1.ReadUInt64(); 72 | 73 | Assert.AreEqual(727905341920923785, magic); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at benito356@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Converters/BinaryPatch/Apply.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Converters.BinaryPatch 22 | { 23 | using System; 24 | using TF3.Core.Exceptions; 25 | using Yarhl.FileFormat; 26 | using Yarhl.IO; 27 | 28 | /// 29 | /// Binary patch applier. 30 | /// 31 | public class Apply : IConverter, IInitializer 32 | { 33 | private Formats.BinaryPatch _patch; 34 | 35 | /// 36 | /// Converter initializer. 37 | /// 38 | /// 39 | /// Initialization is mandatory. 40 | /// 41 | /// Patch info. 42 | public void Initialize(Formats.BinaryPatch parameters) => _patch = parameters; 43 | 44 | /// 45 | /// Applies a binary patch to a file. 46 | /// 47 | /// The original BinaryFormat. 48 | /// The BinaryFormat with the applied patch. 49 | public BinaryFormat Convert(BinaryFormat source) 50 | { 51 | if (source == null) 52 | { 53 | throw new ArgumentNullException(nameof(source)); 54 | } 55 | 56 | if (_patch == null) 57 | { 58 | throw new InvalidOperationException("Uninitialized"); 59 | } 60 | 61 | var reader = new DataReader(source.Stream); 62 | var writer = new DataWriter(source.Stream); 63 | foreach ((long rva, byte expectedByte, byte newByte) in _patch.Patches) 64 | { 65 | source.Stream.Seek(rva + _patch.RawOffset); 66 | byte original = reader.ReadByte(); 67 | 68 | if (original != expectedByte) 69 | { 70 | throw new ByteMismatchException($"Address: 0x{rva + _patch.RawOffset:X16} - Byte: {original:X2} - Expected: {expectedByte:X2}"); 71 | } 72 | 73 | source.Stream.Seek(rva + _patch.RawOffset); 74 | writer.Write(newByte); 75 | } 76 | 77 | return source; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Tests/TF3.Tests/Converters/BinaryPatch/ApplyTests.cs: -------------------------------------------------------------------------------- 1 | namespace TF3.Tests.Converters.BinaryPatch 2 | { 3 | using System; 4 | using NUnit.Framework; 5 | using TF3.Core.Converters.BinaryPatch; 6 | using TF3.Core.Exceptions; 7 | using TF3.Core.Formats; 8 | using Yarhl.IO; 9 | 10 | public class ApplyTests 11 | { 12 | private readonly byte[] _testData = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67 }; 13 | 14 | [Test] 15 | public void NullSourceThrowsException() 16 | { 17 | var converter = new Apply(); 18 | _ = Assert.Throws(() => converter.Convert(null)); 19 | } 20 | 21 | [Test] 22 | public void UninitializedConverterThrowsException() 23 | { 24 | using DataStream ds = DataStreamFactory.FromArray(_testData, 0, _testData.Length); 25 | using var format = new BinaryFormat(ds); 26 | var converter = new Apply(); 27 | 28 | _ = Assert.Throws(() => converter.Convert(format)); 29 | } 30 | 31 | [Test] 32 | public void MismatchByteThrowsException() 33 | { 34 | var patch = new BinaryPatch() 35 | { 36 | FileName = "test.exe", 37 | RawOffset = 0, 38 | }; 39 | patch.Patches.Add((4, 0x21, 0x30)); 40 | 41 | using DataStream ds = DataStreamFactory.FromArray(_testData, 0, _testData.Length); 42 | using var format = new BinaryFormat(ds); 43 | var converter = new Apply(); 44 | converter.Initialize(patch); 45 | _ = Assert.Throws(() => converter.Convert(format)); 46 | } 47 | 48 | [Test] 49 | public void ApplyPatchWithoutOffset() 50 | { 51 | var patch = new BinaryPatch() 52 | { 53 | FileName = "test.exe", 54 | RawOffset = 0, 55 | }; 56 | patch.Patches.Add((4, 0x20, 0x30)); 57 | 58 | using DataStream ds = DataStreamFactory.FromArray(_testData, 0, _testData.Length); 59 | using var format = new BinaryFormat(ds); 60 | var converter = new Apply(); 61 | converter.Initialize(patch); 62 | converter.Convert(format); 63 | 64 | var reader = new DataReader(ds); 65 | ds.Position = 4; 66 | 67 | byte changedByte = reader.ReadByte(); 68 | Assert.AreEqual(0x30, changedByte); 69 | } 70 | 71 | [Test] 72 | public void ApplyPatchWithOffset() 73 | { 74 | var patch = new BinaryPatch() 75 | { 76 | FileName = "test.exe", 77 | RawOffset = 3, 78 | }; 79 | patch.Patches.Add((4, 0x72, 0x62)); 80 | 81 | using DataStream ds = DataStreamFactory.FromArray(_testData, 0, _testData.Length); 82 | using var format = new BinaryFormat(ds); 83 | var converter = new Apply(); 84 | converter.Initialize(patch); 85 | converter.Convert(format); 86 | 87 | var reader = new DataReader(ds); 88 | ds.Position = 7; // 4 + 3 89 | 90 | byte changedByte = reader.ReadByte(); 91 | Assert.AreEqual(0x62, changedByte); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/ScriptManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core 22 | { 23 | using System; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Text.Json; 27 | using Dahomey.Json; 28 | using Yarhl; 29 | 30 | /// 31 | /// Script manager. 32 | /// 33 | public static class ScriptManager 34 | { 35 | private static readonly List _scripts = new List(); 36 | 37 | /// 38 | /// Event triggered on errors. 39 | /// 40 | public static event EventHandler<(string file, string message)> ErrorLoading; 41 | 42 | /// 43 | /// Gets a list of loaded scripts. 44 | /// 45 | public static IReadOnlyList Scripts => _scripts.AsReadOnly(); 46 | 47 | /// 48 | /// Loads all the scripts in a directory. 49 | /// 50 | /// The directory containing the scripts. 51 | public static void LoadScripts(string path) 52 | { 53 | // This is needed to load all the Yarhl plugins and make their types available in scripts. 54 | _ = PluginManager.Instance; 55 | 56 | Clear(); 57 | 58 | JsonSerializerOptions options = new JsonSerializerOptions().SetupExtensions(); 59 | options.SetMissingMemberHandling(MissingMemberHandling.Error); 60 | 61 | foreach (string file in Directory.EnumerateFiles(path, "TF3.Script.*.json")) 62 | { 63 | try 64 | { 65 | string scriptContents = File.ReadAllText(file); 66 | GameScript script = JsonSerializer.Deserialize(scriptContents, options); 67 | _scripts.Add(script); 68 | } 69 | catch (Exception e) 70 | { 71 | ErrorLoading?.Invoke(null, (file, e.Message)); 72 | } 73 | } 74 | } 75 | 76 | /// 77 | /// Empties the loaded scripts. 78 | /// 79 | public static void Clear() 80 | { 81 | _scripts.Clear(); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/BitmapImage/Extractor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.BitmapImage 22 | { 23 | using System; 24 | using SixLabors.ImageSharp; 25 | using TF3.YarhlPlugin.Common.Converters.Common; 26 | using TF3.YarhlPlugin.Common.Enums; 27 | using TF3.YarhlPlugin.Common.Formats; 28 | using Yarhl.FileFormat; 29 | using Yarhl.IO; 30 | 31 | /// 32 | /// Bitmap to PNG converter. 33 | /// 34 | public class Extractor : IConverter, IInitializer 35 | { 36 | private ImageExtractorParameters _extractorParameters = new ImageExtractorParameters(); 37 | 38 | /// 39 | /// Initializes the extractor parameters. 40 | /// 41 | /// Extractor configuration. 42 | public void Initialize(ImageExtractorParameters parameters) => _extractorParameters = parameters; 43 | 44 | /// 45 | /// Converts a Bitmap file to a known format. 46 | /// 47 | /// The Bitmap file. 48 | /// The output file. 49 | public BinaryFormat Convert(BitmapFileFormat source) 50 | { 51 | if (source == null) 52 | { 53 | throw new ArgumentNullException(nameof(source)); 54 | } 55 | 56 | var result = new BinaryFormat(); 57 | 58 | switch (_extractorParameters.ImageFormat) 59 | { 60 | case BitmapExtractionFormat.Png: 61 | source.Internal.SaveAsPng(result.Stream); 62 | break; 63 | 64 | case BitmapExtractionFormat.Tga: 65 | source.Internal.SaveAsTga(result.Stream); 66 | break; 67 | 68 | case BitmapExtractionFormat.Bmp: 69 | source.Internal.SaveAsBmp(result.Stream); 70 | break; 71 | 72 | default: 73 | throw new FormatException("Unknown image format"); 74 | } 75 | 76 | source.Internal.Dispose(); 77 | 78 | return result; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Helpers/ChecksumHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Helpers 22 | { 23 | using System.IO; 24 | using Standart.Hash.xxHash; 25 | 26 | /// 27 | /// Checksum functions. 28 | /// 29 | public static class ChecksumHelper 30 | { 31 | /// 32 | /// Validates the checksum of a file. 33 | /// 34 | /// The input file. 35 | /// The expected checksum value. 36 | /// True if checksum matches with the expected value. 37 | public static bool Check(string file, ulong expected) 38 | { 39 | if (expected == 0) 40 | { 41 | return true; 42 | } 43 | 44 | ulong value = Calculate(file); 45 | return value == expected; 46 | } 47 | 48 | /// 49 | /// Validates the checksum of a stream. 50 | /// 51 | /// The input stream. 52 | /// The expected checksum value. 53 | /// True if checksum matches with the expected value. 54 | public static bool Check(Stream stream, ulong expected) 55 | { 56 | if (expected == 0) 57 | { 58 | return true; 59 | } 60 | 61 | ulong value = Calculate(stream); 62 | return value == expected; 63 | } 64 | 65 | /// 66 | /// Calculate the checksum of a file. 67 | /// 68 | /// The input file. 69 | /// The checksum value. 70 | private static ulong Calculate(string file) 71 | { 72 | using var s = new FileStream(file, FileMode.Open, FileAccess.Read); 73 | return Calculate(s); 74 | } 75 | 76 | /// 77 | /// Calculate the checksum of a stream. 78 | /// 79 | /// The input stream. 80 | /// The checksum value. 81 | private static ulong Calculate(Stream stream) 82 | { 83 | return xxHash64.ComputeHash(stream); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Exceptions/ByteMismatchException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Exceptions 22 | { 23 | using System; 24 | using System.Diagnostics.CodeAnalysis; 25 | using System.Runtime.Serialization; 26 | 27 | /// 28 | /// Exception thrown when byte doesn't match with the expected one when applying a patch. 29 | /// 30 | [Serializable] 31 | [ExcludeFromCodeCoverage] 32 | public class ByteMismatchException : Exception 33 | { 34 | /// 35 | /// Initializes a new instance of the class. 36 | /// 37 | public ByteMismatchException() 38 | { 39 | } 40 | 41 | /// 42 | /// Initializes a new instance of the class. 43 | /// 44 | /// The error message that explains the reason for the exception. 45 | public ByteMismatchException(string message) 46 | : base(message) 47 | { 48 | } 49 | 50 | /// 51 | /// Initializes a new instance of the class. 52 | /// 53 | /// The error message that explains the reason for the exception. 54 | /// The exception that is the cause of the current exception, 55 | /// or a null reference (Nothing in Visual Basic) if no inner exception is specified. 56 | public ByteMismatchException(string message, Exception innerException) 57 | : base(message, innerException) 58 | { 59 | } 60 | 61 | /// 62 | /// Initializes a new instance of the class. 63 | /// 64 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized object data about the exception being thrown. 65 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information about the source or destination. 66 | protected ByteMismatchException(SerializationInfo info, StreamingContext context) 67 | : base(info, context) 68 | { 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Exceptions/UnknownConverterException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Exceptions 22 | { 23 | using System; 24 | using System.Diagnostics.CodeAnalysis; 25 | using System.Runtime.Serialization; 26 | 27 | /// 28 | /// Exception thrown when a Yarhl converter is not found. 29 | /// 30 | [Serializable] 31 | [ExcludeFromCodeCoverage] 32 | public class UnknownConverterException : Exception 33 | { 34 | /// 35 | /// Initializes a new instance of the class. 36 | /// 37 | public UnknownConverterException() 38 | : base() 39 | { 40 | } 41 | 42 | /// 43 | /// Initializes a new instance of the class. 44 | /// 45 | /// The error message that explains the reason for the exception. 46 | public UnknownConverterException(string message) 47 | : base(message) 48 | { 49 | } 50 | 51 | /// 52 | /// Initializes a new instance of the class. 53 | /// 54 | /// The error message that explains the reason for the exception. 55 | /// The exception that is the cause of the current exception, 56 | /// or a null reference (Nothing in Visual Basic) if no inner exception is specified. 57 | public UnknownConverterException(string message, Exception innerException) 58 | : base(message, innerException) 59 | { 60 | } 61 | 62 | /// 63 | /// Initializes a new instance of the class. 64 | /// 65 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized object data about the exception being thrown. 66 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information about the source or destination. 67 | protected UnknownConverterException(SerializationInfo info, StreamingContext context) 68 | : base(info, context) 69 | { 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Libraries/TF3.Core/Exceptions/ChecksumMismatchException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Core.Exceptions 22 | { 23 | using System; 24 | using System.Diagnostics.CodeAnalysis; 25 | using System.Runtime.Serialization; 26 | 27 | /// 28 | /// Exception thrown when checksum doesn't match with the expected one. 29 | /// 30 | [Serializable] 31 | [ExcludeFromCodeCoverage] 32 | public class ChecksumMismatchException : Exception 33 | { 34 | /// 35 | /// Initializes a new instance of the class. 36 | /// 37 | public ChecksumMismatchException() 38 | : base() 39 | { 40 | } 41 | 42 | /// 43 | /// Initializes a new instance of the class. 44 | /// 45 | /// The error message that explains the reason for the exception. 46 | public ChecksumMismatchException(string message) 47 | : base(message) 48 | { 49 | } 50 | 51 | /// 52 | /// Initializes a new instance of the class. 53 | /// 54 | /// The error message that explains the reason for the exception. 55 | /// The exception that is the cause of the current exception, 56 | /// or a null reference (Nothing in Visual Basic) if no inner exception is specified. 57 | public ChecksumMismatchException(string message, Exception innerException) 58 | : base(message, innerException) 59 | { 60 | } 61 | 62 | /// 63 | /// Initializes a new instance of the class. 64 | /// 65 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized object data about the exception being thrown. 66 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information about the source or destination. 67 | protected ChecksumMismatchException(SerializationInfo info, StreamingContext context) 68 | : base(info, context) 69 | { 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Libraries/TF3.YarhlPlugin.Common/Converters/DdsImage/Extractor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.YarhlPlugin.Common.Converters.DdsImage 22 | { 23 | using System; 24 | using BCnEncoder.ImageSharp; 25 | using BCnEncoder.Shared; 26 | using SixLabors.ImageSharp; 27 | using SixLabors.ImageSharp.PixelFormats; 28 | using TF3.YarhlPlugin.Common.Converters.Common; 29 | using TF3.YarhlPlugin.Common.Enums; 30 | using TF3.YarhlPlugin.Common.Formats; 31 | using Yarhl.FileFormat; 32 | using Yarhl.IO; 33 | 34 | /// 35 | /// DDS to PNG converter. 36 | /// 37 | public class Extractor : IConverter, IInitializer 38 | { 39 | private ImageExtractorParameters _extractorParameters = new ImageExtractorParameters(); 40 | 41 | /// 42 | /// Initializes the extractor parameters. 43 | /// 44 | /// Extractor configuration. 45 | public void Initialize(ImageExtractorParameters parameters) => _extractorParameters = parameters; 46 | 47 | /// 48 | /// Converts a DDS file into PNG. 49 | /// 50 | /// The DDS file. 51 | /// The PNG file. 52 | public BinaryFormat Convert(DdsFileFormat source) 53 | { 54 | if (source == null) 55 | { 56 | throw new ArgumentNullException(nameof(source)); 57 | } 58 | 59 | var decoder = new BCnEncoder.Decoder.BcDecoder() 60 | { 61 | OutputOptions = 62 | { 63 | Bc4Component = ColorComponent.Luminance, 64 | }, 65 | }; 66 | 67 | using Image image = decoder.DecodeToImageRgba32(source.Internal); 68 | 69 | var result = new BinaryFormat(); 70 | switch (_extractorParameters.ImageFormat) 71 | { 72 | case BitmapExtractionFormat.Png: 73 | image.SaveAsPng(result.Stream); 74 | break; 75 | 76 | case BitmapExtractionFormat.Tga: 77 | image.SaveAsTga(result.Stream); 78 | break; 79 | 80 | default: 81 | throw new FormatException("Unknown image format"); 82 | } 83 | 84 | return result; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /docs/faq.md: -------------------------------------------------------------------------------- 1 | # TF3 FAQ 2 | 3 | ## What is TF3? 4 | 5 | TF3 is a framework designed to make easier the translation of games. 6 | 7 | ## How does it works? 8 | 9 | The steps to translate any game are (very often) the same: 10 | 11 | 1. Extract the texts (or images, or sounds...) from the original game files. 12 | 2. Translate. 13 | 3. Rebuild the game files using the translation. 14 | 15 | TF3 automatize the steps 1 and 3 by using scripts and plugins. 16 | 17 | ## Does it work with [insert game name here]? 18 | 19 | No, each game is different and TF3 needs to have specific [Yarhl Converters](https://scenegate.github.io/Yarhl/guides/Yarhl-nutshell.html#converters-putting-together-all-the-pieces) to be able to extract and repack the files. 20 | 21 | The goal of TF3 is to get rid of the common tasks and let the developer focus in the game specific ones. 22 | 23 | ## Can you create the converters for [insert game name here]? 24 | 25 | Short answer: No. 26 | 27 | Long answer: I do this in my spare time, and it isn't too much, so I focus in the games I'm interested. But my goal is that anyone (with the necessary coding skills) can create their own plugins and use them with TF3. 28 | 29 | ## But, I'm very interested in translating [insert game name here] and I can pay you $[insert amount here]! 30 | 31 | I'm sorry, but I don't do this for money. 32 | 33 | ## To what languages can I translate the supported games? 34 | 35 | With my plugins, you should be able to translate, at least, to Spanish. 36 | 37 | I try to make the plugins language independent but, often, the limitation is in the game itself. 38 | 39 | For example, Yakuza Kiwami 2 use a variable width font for the characters in ASCII range from 0x20 to 0x7F and a fixed width font for any other character in UTF8. Modifying the .exe file, I'm able to use the variable width font for the characters in range 0x20 to 0xFF, leaving enough characters to translate to Spanish but, probably, insufficient for other languages. 40 | 41 | In cases like this, if my plugin is not enough, you'll have to code your own plugin or patch the .exe by yourself. 42 | 43 | ## There is a plugin to translate the PC version of a game, but I want to translate the console version. Does it work? 44 | 45 | I don't know. Sometimes, the files in both versions are the same (or there are minor changes like the file path) and, in this cases, I'll try to do my best to be able to translate it. 46 | 47 | ## Can I help you with the project? 48 | 49 | Of course, you are welcome! You can fork the project and create pull requests to submit changes. Or you can create plugins for new games. 50 | 51 | ## I want to translate a pirate version of a game, but TF3 throws some errors and it doesn't work... 52 | 53 | I do not support piracy, so you are on your own. 54 | 55 | ## I double click TF3.exe and it opens and closes immediately. 56 | 57 | That's normal. TF3 is a command line app, so you need a (very) basic computer knowledge to open a command line window and run the app in it. 58 | 59 | Probably, in the future, there will be a GUI. 60 | 61 | ## I'm translating a game but there are missing texts (or images...) in the extracted files. 62 | 63 | Probably I missed some files when I created the plugin. Please, open an issue in the github page of the plugin indicating the **exact** missing text (a screen capture is better). 64 | 65 | ## I have found a bug in the app. How do I report it? 66 | 67 | If you find a bug, please open an issue [here](https://github.com/Kaplas80/TF3/issues). I can't fix a bug if I'm not able to reproduce it, so, please, add much info as possible. 68 | 69 | ## I have other question, how can I contact you? 70 | 71 | You can ask your questions [here](https://github.com/Kaplas80/TF3/discussions). -------------------------------------------------------------------------------- /src/Tests/TF3.Tests/GameScriptTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Tests 22 | { 23 | using System.IO; 24 | using NUnit.Framework; 25 | 26 | public class GameScriptTests 27 | { 28 | private const string TestScript = /*lang=json,strict*/ "{\"Name\":\"test-script\",\"Game\":\"Test Script\",\"Parameters\":[],\"Containers\":[],\"Assets\":[],\"Patches\":[]}"; 29 | private const string InvalidTestScript = /*lang=json,strict*/ "{\"Name\":\"test-script\",\"Game_#$\":\"Test Script\",\"Parameters\":[],\"Containers\":[],\"Assets\":[],\"Patches\":[]}"; 30 | 31 | private readonly string _tempPath = Path.Combine(Path.GetTempPath(), "TF3.Tests"); 32 | 33 | [SetUp] 34 | public void Init() 35 | { 36 | if (Directory.Exists(_tempPath)) 37 | { 38 | Directory.Delete(_tempPath, true); 39 | } 40 | 41 | _ = Directory.CreateDirectory(_tempPath); 42 | Core.ScriptManager.Clear(); 43 | } 44 | 45 | [TearDown] 46 | public void Cleanup() 47 | { 48 | if (Directory.Exists(_tempPath)) 49 | { 50 | Directory.Delete(_tempPath, true); 51 | } 52 | } 53 | 54 | [Test] 55 | public void PathWithScriptsWorks() 56 | { 57 | string scriptPath = Path.Combine(_tempPath, "TF3.Script.Test.json"); 58 | File.WriteAllText(scriptPath, TestScript); 59 | 60 | Assert.AreEqual(0, Core.ScriptManager.Scripts.Count); 61 | Core.ScriptManager.LoadScripts(_tempPath); 62 | Assert.AreEqual(1, Core.ScriptManager.Scripts.Count); 63 | } 64 | 65 | [Test] 66 | public void PathWithoutScriptsDoesNotThrow() 67 | { 68 | Assert.AreEqual(0, Core.ScriptManager.Scripts.Count); 69 | Core.ScriptManager.LoadScripts(_tempPath); 70 | Assert.AreEqual(0, Core.ScriptManager.Scripts.Count); 71 | } 72 | 73 | [Test] 74 | public void PathWithInvalidScriptsCallsEvent() 75 | { 76 | string scriptPath = Path.Combine(_tempPath, "TF3.Script.Test.json"); 77 | File.WriteAllText(scriptPath, InvalidTestScript); 78 | 79 | int calls = 0; 80 | Core.ScriptManager.ErrorLoading += (object _, (string file, string message) _) => calls++; 81 | 82 | Assert.AreEqual(0, Core.ScriptManager.Scripts.Count); 83 | Core.ScriptManager.LoadScripts(_tempPath); 84 | Assert.AreEqual(1, calls); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Tests/TF3.Tests/ScriptManagerTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Kaplas 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | namespace TF3.Tests 22 | { 23 | using System.IO; 24 | using NUnit.Framework; 25 | 26 | public class ScriptManagerTests 27 | { 28 | private const string TestScript = /*lang=json,strict*/ "{\"Name\":\"test-script\",\"Game\":\"Test Script\",\"Parameters\":[],\"Containers\":[],\"Assets\":[],\"Patches\":[]}"; 29 | private const string InvalidTestScript = /*lang=json,strict*/ "{\"Name\":\"test-script\",\"Game_#$\":\"Test Script\",\"Parameters\":[],\"Containers\":[],\"Assets\":[],\"Patches\":[]}"; 30 | 31 | private readonly string _tempPath = Path.Combine(Path.GetTempPath(), "TF3.Tests"); 32 | 33 | [SetUp] 34 | public void Init() 35 | { 36 | if (Directory.Exists(_tempPath)) 37 | { 38 | Directory.Delete(_tempPath, true); 39 | } 40 | 41 | _ = Directory.CreateDirectory(_tempPath); 42 | Core.ScriptManager.Clear(); 43 | } 44 | 45 | [TearDown] 46 | public void Cleanup() 47 | { 48 | if (Directory.Exists(_tempPath)) 49 | { 50 | Directory.Delete(_tempPath, true); 51 | } 52 | } 53 | 54 | [Test] 55 | public void PathWithScriptsWorks() 56 | { 57 | string scriptPath = Path.Combine(_tempPath, "TF3.Script.Test.json"); 58 | File.WriteAllText(scriptPath, TestScript); 59 | 60 | Assert.AreEqual(0, Core.ScriptManager.Scripts.Count); 61 | Core.ScriptManager.LoadScripts(_tempPath); 62 | Assert.AreEqual(1, Core.ScriptManager.Scripts.Count); 63 | } 64 | 65 | [Test] 66 | public void PathWithoutScriptsDoesNotThrow() 67 | { 68 | Assert.AreEqual(0, Core.ScriptManager.Scripts.Count); 69 | Core.ScriptManager.LoadScripts(_tempPath); 70 | Assert.AreEqual(0, Core.ScriptManager.Scripts.Count); 71 | } 72 | 73 | [Test] 74 | public void PathWithInvalidScriptsCallsEvent() 75 | { 76 | string scriptPath = Path.Combine(_tempPath, "TF3.Script.Test.json"); 77 | File.WriteAllText(scriptPath, InvalidTestScript); 78 | 79 | int calls = 0; 80 | Core.ScriptManager.ErrorLoading += (object _, (string file, string message) _) => calls++; 81 | 82 | Assert.AreEqual(0, Core.ScriptManager.Scripts.Count); 83 | Core.ScriptManager.LoadScripts(_tempPath); 84 | Assert.AreEqual(1, calls); 85 | } 86 | } 87 | } 88 | --------------------------------------------------------------------------------