Repository: nazonoSAUNA/patch.aul
Branch: master
Commit: 2441800fe810
Files: 167
Total size: 957.7 KB
Directory structure:
gitextract_6ahg5_lo/
├── .gitattributes
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── ------.md
│ │ ├── aviutl--------------.md
│ │ └── patch-aul------.md
│ ├── pull_request_template.md
│ └── workflows/
│ └── CI.yml
├── .gitignore
├── .gitmodules
├── COPYING
├── COPYING.LESSER
├── LICENSE
├── credits.md
├── patch/
│ ├── .editorconfig
│ ├── add_dll_ref.hpp
│ ├── clprogram.cl
│ ├── config.hpp
│ ├── config_rw.hpp
│ ├── cryptostring.hpp
│ ├── debug_log.hpp
│ ├── gate.hpp
│ ├── global.hpp
│ ├── global_minimum.hpp
│ ├── hash.hpp
│ ├── init.cpp
│ ├── init.hpp
│ ├── json.h
│ ├── macro.h
│ ├── moduledata.hpp
│ ├── multi_threading.hpp
│ ├── mylua.hpp
│ ├── mywindow.hpp
│ ├── offset_address.hpp
│ ├── overwrite_resource.cpp
│ ├── overwrite_resource.hpp
│ ├── packages.config
│ ├── patch.cpp
│ ├── patch.hpp
│ ├── patch.rc
│ ├── patch.vcxproj
│ ├── patch.vcxproj.filters
│ ├── patch_access_key.hpp
│ ├── patch_add_extension.cpp
│ ├── patch_add_extension.hpp
│ ├── patch_alpha_bg.hpp
│ ├── patch_aup_layer_setting.hpp
│ ├── patch_aup_scene_setting.hpp
│ ├── patch_aviutl_wndproc_override.cpp
│ ├── patch_aviutl_wndproc_override.hpp
│ ├── patch_base.hpp
│ ├── patch_blend.cpp
│ ├── patch_blend.hpp
│ ├── patch_colorpalette_cache.hpp
│ ├── patch_console.cpp
│ ├── patch_console.hpp
│ ├── patch_copybuffer_smem.hpp
│ ├── patch_dialog_new_file.hpp
│ ├── patch_exception_history.hpp
│ ├── patch_exception_log.cpp
│ ├── patch_exception_log.hpp
│ ├── patch_exception_log_dialog.cpp
│ ├── patch_exception_log_dialog.hpp
│ ├── patch_exeditwindow_sizing.hpp
│ ├── patch_exo_aviutlfilter.hpp
│ ├── patch_exo_fold_gui.hpp
│ ├── patch_exo_midpt_and_tra.hpp
│ ├── patch_exo_sceneidx.hpp
│ ├── patch_exo_specialcolorconv.hpp
│ ├── patch_exo_trackminusval.cpp
│ ├── patch_exo_trackminusval.hpp
│ ├── patch_exo_trackparam.hpp
│ ├── patch_failed_file_drop.hpp
│ ├── patch_failed_longer_path.cpp
│ ├── patch_failed_longer_path.hpp
│ ├── patch_failed_sjis_msgbox.cpp
│ ├── patch_failed_sjis_msgbox.hpp
│ ├── patch_fast.hpp
│ ├── patch_fast_border.cpp
│ ├── patch_fast_border.hpp
│ ├── patch_fast_cl.hpp
│ ├── patch_fast_create_figure.cpp
│ ├── patch_fast_create_figure.hpp
│ ├── patch_fast_directionalblur.cpp
│ ├── patch_fast_directionalblur.hpp
│ ├── patch_fast_displacementmap.cpp
│ ├── patch_fast_displacementmap.hpp
│ ├── patch_fast_exeditwindow.cpp
│ ├── patch_fast_exeditwindow.hpp
│ ├── patch_fast_flash.cpp
│ ├── patch_fast_flash.hpp
│ ├── patch_fast_getputpixeldata.cpp
│ ├── patch_fast_getputpixeldata.hpp
│ ├── patch_fast_glow.cpp
│ ├── patch_fast_glow.hpp
│ ├── patch_fast_lensblur.cpp
│ ├── patch_fast_lensblur.hpp
│ ├── patch_fast_polortransform.cpp
│ ├── patch_fast_polortransform.hpp
│ ├── patch_fast_radiationalblur.cpp
│ ├── patch_fast_radiationalblur.hpp
│ ├── patch_fast_setting_dialog.cpp
│ ├── patch_fast_setting_dialog.hpp
│ ├── patch_fast_text.cpp
│ ├── patch_fast_text.hpp
│ ├── patch_fileinfo.hpp
│ ├── patch_font_dialog.hpp
│ ├── patch_helpful_msgbox.cpp
│ ├── patch_helpful_msgbox.hpp
│ ├── patch_ignore_media_param_reset.hpp
│ ├── patch_lua.cpp
│ ├── patch_lua.hpp
│ ├── patch_lua_getvalueex.cpp
│ ├── patch_lua_getvalueex.hpp
│ ├── patch_lua_rand.cpp
│ ├── patch_lua_rand.hpp
│ ├── patch_lua_randex.cpp
│ ├── patch_lua_randex.hpp
│ ├── patch_obj_colorcorrection.cpp
│ ├── patch_obj_colorcorrection.hpp
│ ├── patch_obj_glow.hpp
│ ├── patch_obj_lensblur.cpp
│ ├── patch_obj_lensblur.hpp
│ ├── patch_obj_noise.hpp
│ ├── patch_obj_specialcolorconv.hpp
│ ├── patch_playback_speed.hpp
│ ├── patch_rclickmenu_delete.cpp
│ ├── patch_rclickmenu_delete.hpp
│ ├── patch_rclickmenu_split.cpp
│ ├── patch_rclickmenu_split.hpp
│ ├── patch_redo.cpp
│ ├── patch_redo.hpp
│ ├── patch_scroll_objdlg.hpp
│ ├── patch_setting_dialog_excolorconfig.cpp
│ ├── patch_setting_dialog_excolorconfig.hpp
│ ├── patch_setting_dialog_move.hpp
│ ├── patch_setting_dialog_wndproc_override.cpp
│ ├── patch_setting_dialog_wndproc_override.hpp
│ ├── patch_setting_gui.hpp
│ ├── patch_setting_new_project.cpp
│ ├── patch_setting_new_project.hpp
│ ├── patch_splash.cpp
│ ├── patch_splash.hpp
│ ├── patch_susie_load.cpp
│ ├── patch_susie_load.hpp
│ ├── patch_sysinfo_write.hpp
│ ├── patch_text_op_size.hpp
│ ├── patch_theme_cc.hpp
│ ├── patch_tra_aviutlfilter.hpp
│ ├── patch_tra_change_drawfilter.cpp
│ ├── patch_tra_change_drawfilter.hpp
│ ├── patch_tra_specified_speed.hpp
│ ├── patch_undo.cpp
│ ├── patch_undo.hpp
│ ├── resource.h
│ ├── restorable_patch.hpp
│ ├── stopwatch.hpp
│ ├── timer.hpp
│ ├── util.hpp
│ ├── util_int.hpp
│ ├── util_magic.hpp
│ ├── util_others.cpp
│ ├── util_others.hpp
│ ├── util_pe.hpp
│ ├── util_resource.hpp
│ └── version.hpp
├── patch.aul.txt
├── patch.sln
└── readme.md
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
================================================
FILE: .github/ISSUE_TEMPLATE/------.md
================================================
---
name: 新機能の提案
about: 既存の挙動を変更する/新しい機能の追加
title: "+〇〇〇〇〇〇"
labels: enhancement
assignees: ''
---
**背景**
どのような理由でこの機能を提案するかの説明
**概要**
提案する機能はどのようなものなのかの説明
物によっては画像があると分かりやすい
**没案**
他に検討した案
**その他**
他に書きたいことがあれば
================================================
FILE: .github/ISSUE_TEMPLATE/aviutl--------------.md
================================================
---
name: AviUtl/周辺プラグインのバグの報告
about: patch.aulに直してほしいバグ
title: "*〇〇〇〇〇〇"
labels: enhancement
assignees: ''
---
【!】報告の前に必ずこの挙動がpatch.aulを導入していない状態で引き起こされる事象であることを確認してください
patch.aulを導入した結果期待していない挙動になるのであれば、これはpatch.aulのバグとして扱い、別のテンプレートが用意されています
**概要**
起こってしまうことの説明を簡単に
何かメッセージが表示されるのであれば、全文を正確にコピーする
**再現手順**
どのような操作をするとこのバグを観測できるのか
(例)
1. XXXプラグイン version XXXを導入する
2. 新規プロジェクトにXXXオブジェクトを配置する
3. XXXオブジェクトの設定を開く
**起こってほしかったこと**
バグが起きなければどうなるのか
**スクリーンショット**
必要だと思えば添付する
**環境**
AviUtl/拡張編集のバージョンは一応書いておく
導入しているフィルタ/入力/出力/色変換/その他のプラグインの情報をバージョンを添えて正確に書く
もし例外が発生しているのであれば、詳細情報が書かれたファイルを添付することでも環境の説明になる
**その他**
もし他に何か書きたいことがあれば
================================================
FILE: .github/ISSUE_TEMPLATE/patch-aul------.md
================================================
---
name: patch.aulのバグの報告
about: patch.aulが起因であるバグはここから
title: "/〇〇〇〇〇〇"
labels: bug
assignees: ''
---
【!】報告の前に必ずこの挙動がpatch.aulを導入したことにより引き起こされる事象であることを確認してください
AviUtl/拡張編集/その他プラグインのバグの報告には別のテンプレートが用意されています
**概要**
起こってしまうことの説明を簡単に
何かメッセージが表示されるのであれば、全文を正確にコピーする
**再現手順**
どのような操作をするとこのバグを観測できるのか
(例)
1. XXXプラグイン version XXXを導入する
2. 新規プロジェクトにXXXオブジェクトを配置する
3. XXXオブジェクトの設定を開く
**起こってほしかったこと**
バグが起きなければどうなるのか
**スクリーンショット**
必要だと思えば添付する
**環境**
AviUtl/拡張編集のバージョンは自明なので省略できる
導入しているフィルタ/入力/出力/色変換/その他のプラグインの情報をバージョンを添えて正確に書く
もし例外が発生しているのであれば、詳細情報が書かれたファイルを添付することでも環境の説明になる
**その他**
もし他に何か書きたいことがあれば
================================================
FILE: .github/pull_request_template.md
================================================
**関係する Issue**
関係する Issue の番号を以下に書いてください。
- #0 を閉じる
- #0 に関連
**変更点**
この PR での変更点について教えてください。
- ○○の追加
- ○○の修正
**内容の精査**
以下の点について教えてください。
- [ ] コードにおかしな点がないことを確認しました。
- [ ] 実際にビルドして試しました。
**スクリーンショット(任意)**
スクリーンショットを Ctrl+V で追加できます。
================================================
FILE: .github/workflows/CI.yml
================================================
name: CI
on:
push:
pull_request:
jobs:
build:
runs-on: windows-2022
strategy:
matrix:
configuration: [Debug, Release]
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Use Developer Command Prompt
uses: ilammy/msvc-dev-cmd@v1
- name: Install CUDA Toolkit
uses: Jimver/cuda-toolkit@v0.2.7
- name: Setup NuGet
uses: nuget/setup-nuget@v1
- name: Restore NuGet package
run : nuget restore patch.sln
- name: Create Directories
run : |
mkdir pack
mkdir test
- name: Build patch.aul
run : devenv patch.sln /Build "${{ matrix.configuration }}|x86"
================================================
FILE: .gitignore
================================================
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
.vscode/
test/
pack/
Release_PDB/
================================================
FILE: .gitmodules
================================================
[submodule "patch/aviutl_exedit_sdk"]
path = patch/aviutl_exedit_sdk
url = https://github.com/ePi5131/aviutl_exedit_sdk
[submodule "patch/winwrap"]
path = patch/winwrap
url = https://github.com/ePi5131/winwrap
================================================
FILE: COPYING
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
================================================
FILE: COPYING.LESSER
================================================
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
================================================
FILE: LICENSE
================================================
© 2022-2023 ePi
patch.aulはLGPLv3の元ライセンスする。ライセンスの詳細はCOPYING,COPYING.LESSERファイルを参照すること。
================================================
FILE: credits.md
================================================
# 使用したライブラリについて
## Boost
> Boost Software License - Version 1.0 - August 17th, 2003
>
> Permission is hereby granted, free of charge, to any person or organization
> obtaining a copy of the software and accompanying documentation covered by
> this license (the "Software") to use, reproduce, display, distribute,
> execute, and transmit the Software, and to prepare derivative works of the
> Software, and to permit third-parties to whom the Software is furnished to
> do so, all subject to the following:
>
> The copyright notices in the Software and this entire statement, including
> the above license grant, this restriction and the following disclaimer,
> must be included in all copies of the Software, in whole or in part, and
> all derivative works of the Software, unless such copies or derivative
> works are solely in the form of machine-executable object code generated by
> a source language processor.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
> SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
> FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
> ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> DEALINGS IN THE SOFTWARE.
## aviutl_exedit_sdk
## winwrap
これらは私が書いたライブラリであり、1条項BSDライセンスの下頒布している。文面は以下の通り。
> Copyright (c) 2022
> ePi All rights reserved.
>
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
>
> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
> THIS SOFTWARE IS PROVIDED BY ePi “AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ePi BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## json.h
このプログラムはUnlicenseで頒布されているが、ここに使用したことを記述しておく。
================================================
FILE: patch/.editorconfig
================================================
# Rules in this file were initially inferred by Visual Studio IntelliCode from the D:\dev\patch\patch\ codebase based on best match to current usage at 2021/08/07
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
[*.{cpp,hpp}]
charset = utf-8
================================================
FILE: patch/add_dll_ref.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include "global.hpp"
// 自身の参照カウントを増やす
inline class add_dll_ref_t {
inline static bool loading_self = false;
public:
bool dllmain_if_break() noexcept {
return loading_self;
}
void add_ref() noexcept {
loading_self = true;
LoadLibraryW(GLOBAL::patchaul_path.c_str());
loading_self = false;
}
} add_dll_ref;
================================================
FILE: patch/clprogram.cl
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
kernel void PolorTransform(global short* dst, global short* src, int obj_w, int obj_h, int obj_line,
int center_length, int radius, float angle, float uzu, float uzu_a){
int x = get_global_id(0);
int y = get_global_id(1);
int x_dist = x - radius;
int y_dist = y - radius;
float dist = sqrt((float)(x_dist * x_dist + y_dist * y_dist));
int range = (int)round((float)obj_w / max(dist, 1.0f) * 57.6115417480468f + uzu_a);
int yy_t256 = (int)round((float)(((obj_h + center_length) << 8) / radius) * dist);
int yy_range_fr = 0x100 - (yy_t256 & 0xff);
int yy_begin = (yy_t256 >> 8) - center_length;
int xx_t256 = (int)round((((float)radius - dist) * uzu + angle - atan2((float)y_dist, (float)x_dist)) * (float)obj_w * 40.7436637878417f) - range / 2;
int xx_range_fr = 0x100 - (xx_t256 & 0xff);
int xx_begin = (xx_t256 >> 8) % obj_w;
range = max(0x100,range);
int yy = yy_begin;
int sum_y = 0;
int sum_cb = 0;
int sum_cr = 0;
int sum_a = 0;
global short* pix;
int src_a;
if (0 <= yy && yy < obj_h) {
int range_remain = range;
int xx = xx_begin;
if (xx_range_fr) {
pix = src + (xx + yy * obj_line) * 4;
sum_a = pix[3] * xx_range_fr * yy_range_fr >> 16;
sum_y = pix[0] * sum_a >> 12;
sum_cb = pix[1] * sum_a >> 12;
sum_cr = pix[2] * sum_a >> 12;
range_remain -= xx_range_fr;
xx++;
xx %= obj_w;
}
int pix_range = range_remain >> 8;
for(int i=0;i> 8;
sum_y += pix[0] * src_a >> 12;
sum_cb += pix[1] * src_a >> 12;
sum_cr += pix[2] * src_a >> 12;
sum_a += src_a;
xx++;
xx %= obj_w;
}
range_remain &= 0xff;
if (range_remain) {
pix = src + (xx + yy * obj_line) * 4;
src_a = pix[3] * range_remain * yy_range_fr >> 16;
sum_y += pix[0] * src_a >> 12;
sum_cb += pix[1] * src_a >> 12;
sum_cr += pix[2] * src_a >> 12;
sum_a += src_a;
}
}
yy++;
yy_range_fr = 0x100 - yy_range_fr;
if (0 <= yy && yy < obj_h) {
int range_remain = range;
int xx = xx_begin;
if (xx_range_fr != 0x100) {
pix = src + (xx + yy * obj_line) * 4;
src_a = pix[3] * xx_range_fr * yy_range_fr >> 16;
sum_y += pix[0] * src_a >> 12;
sum_cb += pix[1] * src_a >> 12;
sum_cr += pix[2] * src_a >> 12;
sum_a += src_a;
range_remain -= xx_range_fr;
xx++;
xx %= obj_w;
}
int pix_range = range_remain >> 8;
for(int i=0;i> 8;
sum_y += pix[0] * src_a>> 12;
sum_cb += pix[1] * src_a >> 12;
sum_cr += pix[2] * src_a >> 12;
sum_a += src_a;
xx++;
xx %= obj_w;
}
range_remain &= 0xff;
if (range_remain) {
pix = src + (xx + yy * obj_line) * 4;
src_a = pix[3] * range_remain * yy_range_fr >> 16;
sum_y += pix[0] * src_a >> 12;
sum_cb += pix[1] * src_a >> 12;
sum_cr += pix[2] * src_a >> 12;
sum_a += src_a;
}
}
dst += (x + y * obj_line) * 4;
if (sum_a) {
float a_float = 4096.0f / (float)sum_a;
dst[0] = (short)round((float)sum_y * a_float);
dst[1] = (short)round((float)sum_cb * a_float);
dst[2] = (short)round((float)sum_cr * a_float);
dst[3] = (short)((sum_a << 8) / range);
} else {
dst[0] = dst[1] = dst[2] = dst[3] = 0;
}
}
kernel void DisplacementMap_move(global short* dst, global short* src, global short* mem,
int obj_w, int obj_h, int obj_line, int param0, int param1, int ox, int oy) {
int x = get_global_id(0);
int y = get_global_id(1);
dst += (x + y * obj_line) * 4;
mem += (x + y * obj_line) * 4;
int p0 = min(mem[0], mem[obj_line * 4]);
int p1 = max(mem[4], mem[obj_line * 4 + 4]);
p0 = (p0 - 0x800) * param0 / 5;
p1 = (p1 - 0x800) * param0 / 5 + 0x1000;
if (p1 < p0) {
int tmp = p0;
p0 = p1;
p1 = tmp;
}
int xx_range = p1 - p0;
int xx_begin = p0 + (x << 12);
int xx_end = xx_range + xx_begin;
p0 = min(mem[1], mem[5]);
p1 = max(mem[obj_line * 4 + 1], mem[obj_line * 4 + 5]);
p0 = (p0 - 0x800) * param1 / 5;
p1 = (p1 - 0x800) * param1 / 5 + 0x1000;
if (p1 < p0) {
int tmp = p0;
p0 = p1;
p1 = tmp;
}
int yy_range = p1 - p0;
int yy_begin = p0 + (y << 12);
int yy_end = yy_range + yy_begin;
if (xx_range < 0x1000) {
xx_begin += (xx_range - 0x1000) >> 1;
xx_end = xx_begin + 0x1000;
xx_range = 0x1000;
}
if (yy_range < 0x1000) {
yy_begin += (yy_range - 0x1000) >> 1;
yy_end = yy_begin + 0x1000;
yy_range = 0x1000;
}
int xx_level = 12;
int yy_level = 12;
while (0x20000 < xx_range) {
xx_begin >>= 1;
xx_end++;
xx_end >>= 1;
xx_range = xx_end - xx_begin;
xx_level--;
}
while (0x20000 < yy_range) {
yy_begin >>= 1;
yy_end++;
yy_end >>= 1;
yy_range = yy_end - yy_begin;
yy_level--;
}
xx_level &= 0x1f;
yy_level &= 0x1f;
xx_begin = max(xx_begin, 0);
xx_end = min(xx_end, obj_w << xx_level);
yy_begin = max(yy_begin, 0);
yy_end = min(yy_end, obj_h << yy_level);
float dsum_y = 0.0f;
float dsum_cb = 0.0f;
float dsum_cr = 0.0f;
float dsum_a = 0.0f;
int yy = yy_begin;
while (yy < yy_end) {
int yy_itr = yy >> yy_level;
int sum_y = 0;
int sum_cb = 0;
int sum_cr = 0;
int sum_a = 0;
int xx = xx_begin;
while (xx < xx_end) {
int xx_itr = xx >> xx_level;
int fraction;
if (xx & 0xfff) {
fraction = -xx & 0xfff;
} else {
fraction = min(xx_end - xx, 0x1000);
}
global short* srct = src + (xx_itr + yy_itr * obj_line) * 4;
int src_a = srct[3] * fraction >> 8;
sum_y += srct[0] * src_a >> 16;
sum_cb += srct[1] * src_a >> 16;
sum_cr += srct[2] * src_a >> 16;
sum_a += src_a;
xx += fraction;
}
int fraction;
if (yy & 0xfff) {
fraction = -yy & 0xfff;
} else {
fraction = min(yy_end - yy, 0x1000);
}
float fraction_rate = (float)fraction * 0.000244140625f;
dsum_y += (float)sum_y * fraction_rate;
dsum_cb += (float)sum_cb * fraction_rate;
dsum_cr += (float)sum_cr * fraction_rate;
dsum_a += (float)sum_a * fraction_rate;
yy += fraction;
}
if (256.0f <= dsum_a) {
float inv_a = 65536.0f / dsum_a;
dst[0] = (short)round(dsum_y * inv_a);
dst[1] = (short)round(dsum_cb * inv_a);
dst[2] = (short)round(dsum_cr * inv_a);
dst[3] = (short)round(dsum_a / ((float)yy_range / 1024.0f) / ((float)xx_range / 1024.0f));
} else {
dst[0] = dst[1] = dst[2] = dst[3] = 0;
}
}
kernel void DisplacementMap_zoom(global short* dst, global short* src, global short* mem,
int obj_w, int obj_h, int obj_line, int param0, int param1, int ox, int oy){
int x = get_global_id(0);
int y = get_global_id(1);
dst += (x + y * obj_line) * 4;
mem += (x + y * obj_line) * 4;
int xx_min, xx_max, yy_min, yy_max;
int xx_temp, yy_temp;
float zoom;
float xxd = (float)(x * 0x1000 - ox);
if (0 < param0) {
zoom = (1024.0f / (float)(param0 + 1000) - 1.0) * 0.00048828125f;
} else {
zoom = (float)param0 * -0.00000048828125f;
}
float temp = xxd * zoom;
xx_min = xx_max = x * 0x1000 + (int)((float)(mem[0] - 0x800) * temp);
xx_temp = x * 0x1000 + (int)((float)(mem[obj_line * 4] - 0x800) * temp);
xx_min = min(xx_min, xx_temp);
xx_max = max(xx_max, xx_temp);
temp = (xxd + 4096.0f) * zoom;
xx_temp = (x + 1) * 0x1000 + (int)((float)(mem[4] - 0x800) * temp);
xx_min = min(xx_min, xx_temp);
xx_max = max(xx_max, xx_temp);
xx_temp = (x + 1) * 0x1000 + (int)((float)(mem[(obj_line + 1) * 4] - 0x800) * temp);
int xx_begin = min(xx_min, xx_temp);
int xx_end = max(xx_max, xx_temp);
float yyd = (float)(y * 0x1000 - oy);
if (0 < param1) {
zoom = (1024.0f / (float)(param1 + 1000) - 1.0) * 0.00048828125f;
} else {
zoom = (float)param1 * -0.00000048828125f;
}
temp = yyd * zoom;
yy_min = yy_max = y * 0x1000 + (int)((float)(mem[1] - 0x800) * temp);
yy_temp = y * 0x1000 + (int)((float)(mem[5] - 0x800) * temp);
yy_min = min(yy_min, yy_temp);
yy_max = max(yy_max, yy_temp);
temp = (yyd + 4096.0f) * zoom;
yy_temp = (y + 1) * 0x1000 + (int)((float)(mem[(obj_line + 1) * 4] - 0x800) * temp);
yy_min = min(yy_min, yy_temp);
yy_max = max(yy_max, yy_temp);
yy_temp = (y + 1) * 0x1000 + (int)((float)(mem[obj_line * 4 + 5] - 0x800) * temp);
int yy_begin = min(yy_min, yy_temp);
int yy_end = max(yy_max, yy_temp);
int xx_range = xx_end - xx_begin;
int yy_range = yy_end - yy_begin;
if (xx_range < 0x1000) {
xx_begin += (xx_range - 0x1000) >> 1;
xx_end = xx_begin + 0x1000;
xx_range = 0x1000;
}
if (yy_range < 0x1000) {
yy_begin += (yy_range - 0x1000) >> 1;
yy_end = yy_begin + 0x1000;
yy_range = 0x1000;
}
int xx_level = 12;
int yy_level = 12;
while (0x20000 < xx_range) {
xx_begin >>= 1;
xx_end++;
xx_end >>= 1;
xx_range = xx_end - xx_begin;
xx_level--;
}
while (0x20000 < yy_range) {
yy_begin >>= 1;
yy_end++;
yy_end >>= 1;
yy_range = yy_end - yy_begin;
yy_level--;
}
xx_level &= 0x1f;
yy_level &= 0x1f;
xx_begin = max(xx_begin, 0);
xx_end = min(xx_end, obj_w << xx_level);
yy_begin = max(yy_begin, 0);
yy_end = min(yy_end, obj_h << yy_level);
float dsum_y = 0.0f;
float dsum_cb = 0.0f;
float dsum_cr = 0.0f;
float dsum_a = 0.0f;
int yy = yy_begin;
while (yy < yy_end) {
int yy_itr = yy >> yy_level;
int sum_y = 0;
int sum_cb = 0;
int sum_cr = 0;
int sum_a = 0;
int xx = xx_begin;
while (xx < xx_end) {
int xx_itr = xx >> xx_level;
int fraction;
if (xx & 0xfff) {
fraction = -xx & 0xfff;
} else {
fraction = min(xx_end - xx, 0x1000);
}
global short* srct = src + (xx_itr + yy_itr * obj_line) * 4;
int src_a = srct[3] * fraction >> 8;
sum_y += srct[0] * src_a >> 16;
sum_cb += srct[1] * src_a >> 16;
sum_cr += srct[2] * src_a >> 16;
sum_a += src_a;
xx += fraction;
}
int fraction;
if (yy & 0xfff) {
fraction = -yy & 0xfff;
} else {
fraction = min(yy_end - yy, 0x1000);
}
float fraction_rate = (float)fraction * 0.000244140625f;
dsum_y += (float)sum_y * fraction_rate;
dsum_cb += (float)sum_cb * fraction_rate;
dsum_cr += (float)sum_cr * fraction_rate;
dsum_a += (float)sum_a * fraction_rate;
yy += fraction;
}
if (256.0f <= dsum_a) {
float inv_a = 65536.0f / dsum_a;
dst[0] = (short)round(dsum_y * inv_a);
dst[1] = (short)round(dsum_cb * inv_a);
dst[2] = (short)round(dsum_cr * inv_a);
dst[3] = (short)round(dsum_a / ((float)yy_range / 1024.0f) / ((float)xx_range / 1024.0f));
} else {
dst[0] = dst[1] = dst[2] = dst[3] = 0;
}
}
kernel void DisplacementMap_rot(global short* dst, global short* src, global short* mem,
int obj_w, int obj_h, int obj_line, int param0, int param1, int ox, int oy){
int x = get_global_id(0);
int y = get_global_id(1);
dst += (x + y * obj_line) * 4;
mem += (x + y * obj_line) * 4;
int xx_min, xx_max, yy_min, yy_max;
int xx_temp, yy_temp;
float xxd = (float)((x << 12) - ox);
float yyd = (float)((y << 12) - oy);
float xxd_next = xxd + 4096.0f;
float yyd_next = yyd + 4096.0f;
float paramrad = (float)param0 * (float)-0.000003067961642955197f;
float rad = (float)(mem[0] - 0x800) * paramrad;
float sinv = sin(rad);
float cosv = cos(rad);
xx_min = xx_max = (int)(xxd * cosv - yyd * sinv);
yy_min = yy_max = (int)(xxd * sinv + yyd * cosv);
rad = (float)(mem[4] - 0x800) * paramrad;
sinv = sin(rad);
cosv = cos(rad);
xx_temp = (int)(xxd_next * cosv - yyd * sinv);
yy_temp = (int)(xxd_next * sinv + yyd * cosv);
xx_min = min(xx_min, xx_temp);
xx_max = max(xx_max, xx_temp);
yy_min = min(yy_min, yy_temp);
yy_max = max(yy_max, yy_temp);
rad = (float)(mem[obj_line * 4] - 0x800) * paramrad;
sinv = sin(rad);
cosv = cos(rad);
xx_temp = (int)(xxd * cosv - yyd_next * sinv);
yy_temp = (int)(xxd * sinv + yyd_next * cosv);
xx_min = min(xx_min, xx_temp);
xx_max = max(xx_max, xx_temp);
yy_min = min(yy_min, yy_temp);
yy_max = max(yy_max, yy_temp);
rad = (float)(mem[(obj_line + 1) * 4] - 0x800) * paramrad;
sinv = sin(rad);
cosv = cos(rad);
xx_temp = (int)(xxd_next * cosv - yyd_next * sinv);
yy_temp = (int)(xxd_next * sinv + yyd_next * cosv);
int xx_begin = min(xx_min, xx_temp) + ox;
int xx_end = max(xx_max, xx_temp) + ox;
int yy_begin = min(yy_min, yy_temp) + oy;
int yy_end = max(yy_max, yy_temp) + oy;
int xx_range = xx_end - xx_begin;
int yy_range = yy_end - yy_begin;
if (xx_range < 0x1000) {
xx_begin += (xx_range - 0x1000) >> 1;
xx_end = xx_begin + 0x1000;
xx_range = 0x1000;
}
if (yy_range < 0x1000) {
yy_begin += (yy_range - 0x1000) >> 1;
yy_end = yy_begin + 0x1000;
yy_range = 0x1000;
}
int xx_level = 12;
int yy_level = 12;
while (0x20000 < xx_range) {
xx_begin >>= 1;
xx_end++;
xx_end >>= 1;
xx_range = xx_end - xx_begin;
xx_level--;
}
while (0x20000 < yy_range) {
yy_begin >>= 1;
yy_end++;
yy_end >>= 1;
yy_range = yy_end - yy_begin;
yy_level--;
}
xx_level &= 0x1f;
yy_level &= 0x1f;
xx_begin = max(xx_begin, 0);
xx_end = min(xx_end, obj_w << xx_level);
yy_begin = max(yy_begin, 0);
yy_end = min(yy_end, obj_h << yy_level);
float dsum_y = 0.0f;
float dsum_cb = 0.0f;
float dsum_cr = 0.0f;
float dsum_a = 0.0f;
int yy = yy_begin;
while (yy < yy_end) {
int yy_itr = yy >> yy_level;
int sum_y = 0;
int sum_cb = 0;
int sum_cr = 0;
int sum_a = 0;
int xx = xx_begin;
while (xx < xx_end) {
int xx_itr = xx >> xx_level;
int fraction;
if (xx & 0xfff) {
fraction = -xx & 0xfff;
} else {
fraction = min(xx_end - xx, 0x1000);
}
global short* srct = src + (xx_itr + yy_itr * obj_line) * 4;
int src_a = srct[3] * fraction >> 8;
sum_y += srct[0] * src_a >> 16;
sum_cb += srct[1] * src_a >> 16;
sum_cr += srct[2] * src_a >> 16;
sum_a += src_a;
xx += fraction;
}
int fraction;
if (yy & 0xfff) {
fraction = -yy & 0xfff;
} else {
fraction = min(yy_end - yy, 0x1000);
}
float fraction_rate = (float)fraction * 0.000244140625f;
dsum_y += (float)sum_y * fraction_rate;
dsum_cb += (float)sum_cb * fraction_rate;
dsum_cr += (float)sum_cr * fraction_rate;
dsum_a += (float)sum_a * fraction_rate;
yy += fraction;
}
if (256.0f <= dsum_a) {
float inv_a = 65536.0f / dsum_a;
dst[0] = (short)round(dsum_y * inv_a);
dst[1] = (short)round(dsum_cb * inv_a);
dst[2] = (short)round(dsum_cr * inv_a);
dst[3] = (short)round(dsum_a / ((float)yy_range / 1024.0f) / ((float)xx_range / 1024.0f));
} else {
dst[0] = dst[1] = dst[2] = dst[3] = 0;
}
}
kernel void RadiationalBlur_Media(
global short* dst, global short* src, int src_w, int src_h, int buffer_line,
int rb_blur_cx, int rb_blur_cy, int rb_obj_cx, int rb_obj_cy, int rb_range, int rb_pixel_range) {
int x = get_global_id(0);
int y = get_global_id(1);
int pixel_itr = x + y * buffer_line;
x += rb_obj_cx;
y += rb_obj_cy;
int cx = rb_blur_cx - x;
int cy = rb_blur_cy - y;
int c_dist_times8 = (int)round(sqrt((float)(cx * cx + cy * cy)) * 8.0f);
int range = rb_range * c_dist_times8 / 1000;
if (rb_pixel_range < c_dist_times8) {
range = rb_pixel_range * rb_range / 1000;
c_dist_times8 = rb_pixel_range;
} else if (8 < c_dist_times8) {
c_dist_times8 *= 8;
range *= 8;
} else if (4 < c_dist_times8) {
c_dist_times8 *= 4;
range *= 4;
} else if (2 < c_dist_times8) {
c_dist_times8 *= 2;
range *= 2;
}
if (2 <= c_dist_times8 && 2 <= range) {
int sum_a = 0;
int sum_cr = 0;
int sum_cb = 0;
int sum_y = 0;
for (int i = 0; i < range; i++) {
int x_itr = x + i * cx / c_dist_times8;
int y_itr = y + i * cy / c_dist_times8;
if (0 <= x_itr && x_itr < src_w && 0 <= y_itr && y_itr < src_h) {
short4 itr = vload4(x_itr + y_itr * buffer_line, src);
int itr_a = itr.w;
sum_a += itr_a;
if (0x1000 < itr_a) {
itr_a = 0x1000;
}
sum_y += itr.x * itr_a / 4096;
sum_cb += itr.y * itr_a / 4096;
sum_cr += itr.z * itr_a / 4096;
}
}
if (sum_a != 0) {
vstore4(
(short4)(
round(sum_y * 4096.0f / sum_a),
round(sum_cb * 4096.0f / sum_a),
round(sum_cr * 4096.0f / sum_a),
sum_a / range
),
pixel_itr, dst
);
} else {
dst[pixel_itr * 4 + 3] = 0;
}
} else {
if (x < 0 || y < 0 || src_w <= x || src_h <= y) {
vstore4((short4)(0, 0, 0, 0), pixel_itr, dst);
} else {
vstore4(vload4(x + y * buffer_line, src), pixel_itr, dst);
}
}
}
kernel void RadiationalBlur_Filter(
global short* dst, global short* src, int buffer_line,
int rb_blur_cx, int rb_blur_cy, int rb_range, int rb_pixel_range) {
int x = get_global_id(0);
int y = get_global_id(1);
int cx = rb_blur_cx - x;
int cy = rb_blur_cy - y;
int c_dist_times8 = (int)round(sqrt((float)(cx * cx + cy * cy)) * 8.0f);
int range = rb_range * c_dist_times8 / 1000;
if (rb_pixel_range < c_dist_times8) {
range = (rb_pixel_range * rb_range) / 1000;
c_dist_times8 = rb_pixel_range;
} else if (8 < c_dist_times8) {
c_dist_times8 *= 8;
range *= 8;
} else if (4 < c_dist_times8) {
c_dist_times8 *= 4;
range *= 4;
} else if (2 < c_dist_times8) {
c_dist_times8 *= 2;
range *= 2;
}
int offset = (x + y * buffer_line) * 3;
if (2 <= c_dist_times8 && 2 <= range) {
int sum_y = 0;
int sum_cb = 0;
int sum_cr = 0;
for (int i = 0; i < range; i++) {
int x_itr = x + i * cx / c_dist_times8;
int y_itr = y + i * cy / c_dist_times8;
int pix_offset = (x_itr + y_itr * buffer_line) * 3;
sum_y += src[pix_offset];
sum_cb += src[++pix_offset];
sum_cr += src[++pix_offset];
}
dst[offset] = (short)(sum_y / range);
dst[++offset] = (short)(sum_cb / range);
dst[++offset] = (short)(sum_cr / range);
} else {
dst[offset] = src[offset];
dst[offset + 1] = src[offset + 1];
dst[offset + 2] = src[offset + 2];
}
}
kernel void RadiationalBlur_Filter_Far(
global short* dst, global short* src, int scene_w, int scene_h, int buffer_line,
int rb_blur_cx, int rb_blur_cy, int rb_range, int rb_pixel_range) {
int x = get_global_id(0);
int y = get_global_id(1);
int cx = rb_blur_cx - x;
int cy = rb_blur_cy - y;
int c_dist_times8 = (int)round(sqrt((float)(cx * cx + cy * cy)) * 8.0f);
int range = rb_range * c_dist_times8 / 1000;
if (rb_pixel_range < c_dist_times8) {
range = (rb_pixel_range * rb_range) / 1000;
c_dist_times8 = rb_pixel_range;
} else if (8 < c_dist_times8) {
c_dist_times8 *= 8;
range *= 8;
} else if (4 < c_dist_times8) {
c_dist_times8 *= 4;
range *= 4;
} else if (2 < c_dist_times8) {
c_dist_times8 *= 2;
range *= 2;
}
int offset = (x + y * buffer_line) * 3;
if (2 <= c_dist_times8 && 2 <= range) {
int sum_y = 0;
int sum_cb = 0;
int sum_cr = 0;
for (int i = 0; i < range; i++) {
int x_itr = x + i * cx / c_dist_times8;
int y_itr = y + i * cy / c_dist_times8;
if (0 <= x_itr && 0 <= y_itr && x_itr < scene_w && y_itr < scene_h) {
int pix_offset = (x_itr + y_itr * buffer_line) * 3;
sum_y += src[pix_offset];
sum_cb += src[++pix_offset];
sum_cr += src[++pix_offset];
}
}
dst[offset] = (short)(sum_y / range);
dst[++offset] = (short)(sum_cb / range);
dst[++offset] = (short)(sum_cr / range);
} else {
dst[offset] = src[offset];
dst[offset + 1] = src[offset + 1];
dst[offset + 2] = src[offset + 2];
}
}
kernel void Flash(global short* dst, global short* src, int src_w, int src_h, int exedit_buffer_line,
int g_cx,
int g_cy,
int g_range,
int g_pixel_range,
int g_temp_x,
int g_temp_y,
int g_r_intensity
) {
int xi = get_global_id(0);
int yi = get_global_id(1);
int x = xi + g_temp_x;
int y = yi + g_temp_y;
int pixel_itr = xi + yi * exedit_buffer_line;
int cx = g_cx - x;
int cy = g_cy - y;
int c_dist_times8 = (int)round(sqrt((float)(cx * cx + cy * cy)) * 8.0f);
int range = g_range * c_dist_times8 / 1000;
if (g_pixel_range < c_dist_times8) {
range = g_pixel_range * g_range / 1000;
c_dist_times8 = g_pixel_range;
} else if (8 < c_dist_times8) {
c_dist_times8 *= 8;
range *= 8;
} else if (4 < c_dist_times8) {
c_dist_times8 *= 4;
range *= 4;
} else if (2 < c_dist_times8) {
c_dist_times8 *= 2;
range *= 2;
}
int sum_y, sum_cb, sum_cr;
if (2 <= c_dist_times8 && 2 <= range) {
sum_y = sum_cb = sum_cr = 0;
for (int i = 0; i < range; i++) {
int x_itr = x + i * cx / c_dist_times8;
int y_itr = y + i * cy / c_dist_times8;
if (0 <= x_itr && 0 <= y_itr && x_itr < src_w && y_itr < src_h) {
short4 itr = vload4(x_itr + y_itr * exedit_buffer_line, src);
if (itr.w != 0) {
if (itr.w < 4096) {
sum_y += itr.x * itr.w / 4096;
sum_cb += itr.y * itr.w / 4096;
sum_cr += itr.z * itr.w / 4096;
} else {
sum_y += itr.x;
sum_cb += itr.y;
sum_cr += itr.z;
}
}
}
}
sum_y /= range;
sum_cb /= range;
sum_cr /= range;
} else {
if (x < 0 || y < 0 || src_w <= x || src_h <= y) {
vstore4((short4)(0, 0, 0, 0), pixel_itr, dst);
return;
} else {
short4 itr = vload4(x + y * exedit_buffer_line, src);
sum_y = itr.x * itr.w / 4096;
sum_cb = itr.y * itr.w / 4096;
sum_cr = itr.z * itr.w / 4096;
}
}
int ya = sum_y - g_r_intensity;
if (ya < 1) {
vstore4((short4)(0, 0, 0, 0), pixel_itr, dst);
} else {
sum_cb -= g_r_intensity * sum_cb / sum_y;
sum_cr -= g_r_intensity * sum_cr / sum_y;
if (ya < 4096) {
vstore4(
(short4)(
4096,
sum_cb * 4096 / ya,
sum_cr * 4096 / ya,
ya
),
pixel_itr, dst
);
} else {
vstore4(
(short4)(
ya,
sum_cb,
sum_cr,
4096
),
pixel_itr, dst
);
}
}
}
kernel void FlashColor(global short* dst, global short* src, int src_w, int src_h, int exedit_buffer_line,
int g_cx,
int g_cy,
int g_range,
int g_pixel_range,
int g_temp_x,
int g_temp_y,
int g_r_intensity,
short g_color_y,
short g_color_cb,
short g_color_cr
) {
int xi = get_global_id(0);
int yi = get_global_id(1);
int x = xi + g_temp_x;
int y = yi + g_temp_y;
int pixel_itr = xi + yi * exedit_buffer_line;
int cx = g_cx - x;
int cy = g_cy - y;
int c_dist_times8 = (int)round(sqrt((float)(cx * cx + cy * cy)) * 8.0f);
int range = g_range * c_dist_times8 / 1000;
if (g_pixel_range < c_dist_times8) {
range = g_pixel_range * g_range / 1000;
c_dist_times8 = g_pixel_range;
} else if (8 < c_dist_times8) {
c_dist_times8 *= 8;
range *= 8;
} else if (4 < c_dist_times8) {
c_dist_times8 *= 4;
range *= 4;
} else if (2 < c_dist_times8) {
c_dist_times8 *= 2;
range *= 2;
}
int itr_y, itr_cb, itr_cr;
if (2 <= c_dist_times8 && 2 <= range) {
int sum_a = 0;
for (int i = 0; i < range; i++) {
int x_itr = x + i * cx / c_dist_times8;
int y_itr = y + i * cy / c_dist_times8;
if (0 <= x_itr && 0 <= y_itr && x_itr < src_w && y_itr < src_h) {
short4 itr = vload4(x_itr + y_itr * exedit_buffer_line, src);
int itr_a = itr.w;
if (itr_a != 0) {
if (itr_a < 4096) {
sum_a += itr_a;
} else {
sum_a += 4096;
}
}
}
}
sum_a /= range;
itr_y = g_color_y * sum_a / 4096;
itr_cb = g_color_cb * sum_a / 4096;
itr_cr = g_color_cr * sum_a / 4096;
} else {
if (x < 0 || y < 0 || src_w <= x || src_h <= y) {
vstore4((short4)(0, 0, 0, 0), pixel_itr, dst);
return;
} else {
short4 itr = vload4(x + y * exedit_buffer_line, src);
int itr_a = itr.w;
itr_y = g_color_y * itr_a / 4096;
itr_cb = g_color_cb * itr_a / 4096;
itr_cr = g_color_cr * itr_a / 4096;
}
}
int ya = itr_y - g_r_intensity;
if (ya < 1) {
vstore4((short4)(0, 0, 0, 0), pixel_itr, dst);
} else {
itr_cb -= g_r_intensity * itr_cb / itr_y;
itr_cr -= g_r_intensity * itr_cr / itr_y;
if (ya < 4096) {
vstore4(
(short4)(
4096,
itr_cb * 4096 / ya,
itr_cr * 4096 / ya,
ya
),
pixel_itr, dst
);
} else {
vstore4(
(short4)(
ya,
itr_cb,
itr_cr,
4096
),
pixel_itr, dst
);
}
}
}
kernel void DirectionalBlur_Media(global short* dst, global short* src, int obj_w, int obj_h, int obj_line,
int x_begin, int x_end, int x_step, int y_begin, int y_end, int y_step, int range) {
int x = get_global_id(0);
int y = get_global_id(1);
int pix_range = range * 2 + 1;
dst += (x + y * obj_line) * 4;
int sum_y = 0;
int sum_cb = 0;
int sum_cr = 0;
int sum_a = 0;
int x_itr = ((x + x_begin) << 16) + 0x8000 - range * x_step;
int y_itr = ((y + y_begin) << 16) + 0x8000 - range * y_step;
for (int n = 0; n < pix_range; n++) {
int xx = x_itr >> 16;
int yy = y_itr >> 16;
if (0 <= xx && xx < obj_w && 0 <= yy && yy < obj_h) {
global short* pix = src + (xx + yy * obj_line) * 4;
int src_a = min((int)pix[3], 0x1000);
sum_y += pix[0] * src_a >> 12;
sum_cb += pix[1] * src_a >> 12;
sum_cr += pix[2] * src_a >> 12;
sum_a += src_a;
}
x_itr += x_step;
y_itr += y_step;
}
if (0 < sum_a) {
float a_float = 4096.0f / (float)sum_a;
dst[0] = (short)round((float)sum_y * a_float);
dst[1] = (short)round((float)sum_cb * a_float);
dst[2] = (short)round((float)sum_cr * a_float);
} else {
dst[0] = dst[1] = dst[2] = 0;
}
dst[3] = (short)(sum_a / pix_range);
}
kernel void DirectionalBlur_original_size(global short* dst, global short* src, int obj_w, int obj_h, int obj_line,
int x_step, int y_step, int range) {
int x = get_global_id(0);
int y = get_global_id(1);
int pix_range = range * 2 + 1;
dst += (x + y * obj_line) * 4;
int x_itr = (x << 16) + 0x8000 - range * x_step;
int y_itr = (y << 16) + 0x8000 - range * y_step;
int sum_y = 0;
int sum_cb = 0;
int sum_cr = 0;
int sum_a = 0;
int cnt = 0;
for (int n = 0; n < pix_range; n++) {
int xx = x_itr >> 16;
int yy = y_itr >> 16;
if (0 <= xx && xx < obj_w && 0 <= yy && yy < obj_h) {
global short* pix = src + (xx + yy * obj_line) * 4;
int src_a = min((int)pix[3], 0x1000);
sum_y += pix[0] * src_a >> 12;
sum_cb += pix[1] * src_a >> 12;
sum_cr += pix[2] * src_a >> 12;
sum_a += src_a;
cnt++;
}
x_itr += x_step;
y_itr += y_step;
}
if(cnt == 0) cnt = 0xffffff;
if (0 < sum_a) {
float a_float = 4096.0f / (float)sum_a;
dst[0] = (short)round((float)sum_y * a_float);
dst[1] = (short)round((float)sum_cb * a_float);
dst[2] = (short)round((float)sum_cr * a_float);
} else {
dst[0] = dst[1] = dst[2] = 0;
}
dst[3] = (short)(sum_a / cnt);
}
kernel void DirectionalBlur_Filter(global short* dst, global short* src, int scene_w, int scene_h, int scene_line,
int x_step, int y_step, int range) {
int x = get_global_id(0);
int y = get_global_id(1);
int pix_range = range * 2 + 1;
dst += (x + y * scene_line) * 3;
int x_itr = (x << 16) + 0x8000 - range * x_step;
int y_itr = (y << 16) + 0x8000 - range * y_step;
int sum_y = 0;
int sum_cb = 0;
int sum_cr = 0;
int cnt = 0;
for (int n = 0; n < pix_range; n++) {
int xx = x_itr >> 16;
int yy = y_itr >> 16;
if (0 <= xx && xx < scene_w && 0 <= yy && yy < scene_h) {
global short* pix = src + (xx + yy * scene_line) * 3;
sum_y += pix[0];
sum_cb += pix[1];
sum_cr += pix[2];
cnt++;
}
x_itr += x_step;
y_itr += y_step;
}
if(cnt == 0) cnt = 0xffffff;
dst[0] = (short)(sum_y / cnt);
dst[1] = (short)(sum_cb / cnt);
dst[2] = (short)(sum_cr / cnt);
}
kernel void LensBlur_Media(global char* dst, global char* src, int obj_w, int obj_h, int obj_line,
int range, int rangep05_sqr, int range_t3m1, int rangem1_sqr) {
int x = get_global_id(0);
int y = get_global_id(1);
int top = -min(y, range);
int bottom = min(obj_h - y - 1, range);
int left = -min(x, range);
int right = min(obj_w - x - 1, range);
float sum_y = 0.0f;
int sum_cb = 0;
int sum_cr = 0;
int sum_a = 0;
int cor_sum = 0;
int offset = (x + left + (y + top) * obj_line) * 8;
for (int yy = top; yy <= bottom; yy++) {
int sqr = yy * yy + left * left;
int offset2 = offset;
for (int xx = left; xx <= right; xx++) {
if (sqr < rangep05_sqr) {
int cor_a;
if (rangem1_sqr < sqr) {
cor_a = ((rangep05_sqr - sqr) << 12) / range_t3m1;
} else {
cor_a = 4096;
}
cor_sum += cor_a;
cor_a = *(global short*)&src[offset2 + 6] * cor_a >> 12;
sum_y += *(global float*)&src[offset2] * (float)cor_a;
sum_cb += src[offset2 + 4] * cor_a;
sum_cr += src[offset2 + 5] * cor_a;
sum_a += cor_a;
}
sqr += 1 + xx * 2;
offset2 += 8;
}
offset += obj_line * 8;
}
dst += (x + y * obj_line) * 8;
if (0 < sum_a) {
*(global float*)dst = sum_y / (float)sum_a;
dst[4] = (char)(((sum_a >> 1) + sum_cb) / sum_a);
dst[5] = (char)(((sum_a >> 1) + sum_cr) / sum_a);
*(global short*)&dst[6] = (short)round((float)sum_a * (4096.0f / (float)cor_sum));
} else {
*(global int*)dst = 0;
*(global int*)&dst[4] = 0;
}
}
kernel void LensBlur_Filter(global char* dst, global char* src, int scene_w, int scene_h, int scene_line,
int range, int rangep05_sqr, int range_t3m1, int rangem1_sqr) {
int x = get_global_id(0);
int y = get_global_id(1);
int top = -min(y, range);
int bottom = min(scene_h - y - 1, range);
int left = -min(x, range);
int right = min(scene_w - x - 1, range);
short tofloat[2];
float sum_y = 0.0f;
int sum_cb = 0;
int sum_cr = 0;
int sum_a = 0;
int offset = (x + left + (y + top) * scene_line) * 6;
for (int yy = top; yy <= bottom; yy++) {
int sqr = yy * yy + left * left;
int offset2 = offset;
for (int xx = left; xx <= right; xx++) {
if (sqr < rangep05_sqr) {
int cor_a;
if (rangem1_sqr < sqr) {
cor_a = ((rangep05_sqr - sqr) << 12) / range_t3m1;
} else {
cor_a = 4096;
}
tofloat[0] = *(global short*)&src[offset2];
tofloat[1] = *(global short*)&src[offset2 + 2];
sum_y += *(float*)tofloat * (float)cor_a;
sum_cb += src[offset2 + 4] * cor_a;
sum_cr += src[offset2 + 5] * cor_a;
sum_a += cor_a;
}
sqr += 1 + xx * 2;
offset2 += 6;
}
offset += scene_line * 6;
}
dst += (x + y * scene_line) * 6;
*(float*)tofloat = sum_y / (float)sum_a;
*(global short*)&dst[0] = tofloat[0];
*(global short*)&dst[2] = tofloat[1];
dst[4] = (char)(((sum_a >> 1) + sum_cb) / sum_a);
dst[5] = (char)(((sum_a >> 1) + sum_cr) / sum_a);
}
================================================
FILE: patch/config.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include "macro.h"
#include "util_resource.hpp"
#include "config_rw.hpp"
#include "patch.hpp"
class Config2 {
bool invalid_json;
public:
void load(std::wstring_view path) {
auto hFile = CreateFileW(path.data(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE) return;
DWORD ignore;
auto size_low = GetFileSize(hFile, &ignore);
auto file = std::make_unique(size_low);
if (ReadFile(hFile, file.get(), size_low, &ignore, NULL) == FALSE) {
patch_resource_message_stack.emplace_back(new patch_resource_message_class_w(PATCH_RS_PATCH_FAILED_TO_LOAD_SETTING, MB_TASKMODAL | MB_ICONEXCLAMATION));
return;
}
CloseHandle(hFile);
json_value_s* root = nullptr;
BOOST_SCOPE_EXIT_ALL(&root) { free(root); };
root = json_parse(file.get(), size_low);
if (root == nullptr) {
patch_resource_message_stack.emplace_back(new patch_resource_message_class_w(PATCH_RS_PATCH_INVALID_SETTING_JSON, MB_TASKMODAL | MB_ICONEXCLAMATION));
invalid_json = true;
return;
}
ConfigReader cr(root);
cr.regist("switch", [](json_value_s* value) {
ConfigReader cr(value);
#ifdef PATCH_SWITCH_ACCESS_KEY
patch::access_key.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_COLORPALETTE_CACHE
patch::colorpalette_cache.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FILEINFO
patch::fileinfo.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_SUSIE_LOAD
patch::susie_load.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_SPLASH
patch::splash.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_AUP_SCENE_SETTING
patch::aup_scene_setting.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_AUP_LAYER_SETTING
patch::aup_layer_setting.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_EXO_AVIUTL_FILTER
patch::exo_aviutlfilter.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_EXO_SCENEIDX
patch::exo_sceneidx.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_EXO_TRACKPARAM
patch::exo_trackparam.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_EXO_TRACK_MINUSVAL
patch::exo_trackminusval.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_EXO_MIDPT_AND_TRA
patch::exo_midpt_and_tra.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_EXO_SPECIALCOLORCONV
patch::exo_specialcolorconv.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_EXO_FOLD_GUI
patch::exo_fold_gui.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_TRA_AVIUTL_FILTER
patch::tra_aviutlfilter.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_TRA_CHANGE_DRAWFILTER
patch::tra_change_drawfilter.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_TRA_SPECIFIED_SPEED
patch::tra_specified_speed.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_SETTING_NEW_PROJECT
patch::setting_new_project.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_TEXT_OP_SIZE
patch::text_op_size.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_IGNORE_MEDIA_PARAM_RESET
patch::ignore_media_param_reset.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FONT_DIALOG
patch::font_dialog.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_SCROLL_OBJDLG
patch::scroll_objdlg.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_ALPHA_BG
patch::alpha_bg.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_HELPFUL_MSGBOX
patch::helpful_msgbox.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAILED_SJIS_MSGBOX
patch::failed_sjis_msgbox.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAILED_LONGER_PATH
patch::failed_longer_path.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAILED_FILE_DROP
patch::failed_file_drop.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_THEME_CC
patch::theme_cc.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_EXEDITWINDOW_SIZING
patch::exeditwindow_sizing.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_SETTINGDIALOG_MOVE
patch::setting_dialog_move.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_OBJ_COLORCORRECTION
patch::ColorCorrection.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_OBJ_GLOW
patch::Glow.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_OBJ_LENSBLUR
patch::LensBlur.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_OBJ_NOISE
patch::Noise.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_OBJ_SPECIALCOLORCONV
patch::obj_specialcolorconv.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_SETTINGDIALOG_EXCOLORCONFIG
patch::excolorconfig.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_RCLICKMENU_SPLIT
patch::rclickmenu_split.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_RCLICKMENU_DELETE
patch::rclickmenu_delete.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_BLEND
patch::blend.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_ADD_EXTENSION
patch::add_extension.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_DIALOG_NEW_FILE
patch::dialog_new_file.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_PLAYBACK_SPEED
patch::playback_speed.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_UNDO
patch::undo.switch_load(cr);
#ifdef PATCH_SWITCH_UNDO_REDO
patch::redo.switch_load(cr);
#endif
#endif
#ifdef PATCH_SWITCH_CONSOLE
patch::console.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_LUA
patch::lua.switch_load(cr);
#ifdef PATCH_SWITCH_LUA_GETVALUE
patch::lua_getvalueex.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_LUA_RAND
patch::lua_rand.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_LUA_RANDEX
patch::lua_randex.switch_load(cr);
#endif
#endif
#ifdef PATCH_SWITCH_FAST
patch::fast::fast.switch_load(cr);
#ifdef PATCH_SWITCH_FAST_EXEDITWINDOW
patch::fast_exeditwindow.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_SETTINGDIALOG
patch::fast_setting_dialog.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_TEXT
patch::fast::text.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_CREATE_FIGURE
patch::fast::create_figure.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_BORDER
patch::fast::Border.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_GLOW
patch::fast::Glow.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_CL
patch::fast::cl.switch_load(cr);
#ifdef PATCH_SWITCH_FAST_RADIATIONALBLUR
patch::fast::RadiationalBlur.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_POLORTRANSFORM
patch::fast::PolorTransform.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_DISPLACEMENTMAP
patch::fast::DisplacementMap.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_FLASH
patch::fast::Flash.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_DIRECTIONALBLUR
patch::fast::DirectionalBlur.switch_load(cr);
#endif
#ifdef PATCH_SWITCH_FAST_LENSBLUR
patch::fast::LensBlur.switch_load(cr);
#endif
#endif
#endif
cr.load();
});
#ifdef PATCH_SWITCH_CONSOLE
cr.regist("console", [](json_value_s* value) {
ConfigReader cr(value);
patch::console.config_load(cr);
cr.load();
});
#endif
#ifdef PATCH_SWITCH_THEME_CC
cr.regist("theme_cc", [](json_value_s* value) {
ConfigReader cr(value);
patch::theme_cc.config_load(cr);
cr.load();
});
#endif
#ifdef PATCH_SWITCH_UNDO_REDO
cr.regist("redo", [](json_value_s* value) {
ConfigReader cr(value);
patch::redo.config_load(cr);
cr.load();
});
#endif
#ifdef PATCH_SWITCH_FAST_EXEDITWINDOW
cr.regist("fast_exeditwindow", [](json_value_s* value) {
ConfigReader cr(value);
patch::fast_exeditwindow.config_load(cr);
cr.load();
});
#endif
#ifdef PATCH_SWITCH_FAST_TEXT
cr.regist("fast_text", [](json_value_s* value) {
ConfigReader cr(value);
patch::fast::text.config_load(cr);
cr.load();
});
#endif
cr.load();
}
void store(std::wstring_view path) {
if (invalid_json)return;
auto hFile = CreateFileW(path.data(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
patch_resource_message_w(PATCH_RS_PATCH_FAILED_TO_SAVE_SETTING, MB_TASKMODAL | MB_ICONEXCLAMATION);
return;
}
BOOST_SCOPE_EXIT_ALL(&hFile) {
CloseHandle(hFile);
};
int level = 0;
ConfigWriter cw(level);
#ifdef PATCH_SWITCH_CONSOLE
{
ConfigWriter console(++level);
patch::console.config_store(console);
std::stringstream ss;
console.write(ss);
cw.append("console", ss.str());
--level;
}
#endif
#ifdef PATCH_SWITCH_THEME_CC
{
ConfigWriter theme_cc(++level);
patch::theme_cc.config_store(theme_cc);
std::stringstream ss;
theme_cc.write(ss);
cw.append("theme_cc", ss.str());
--level;
}
#endif
#ifdef PATCH_SWITCH_UNDO_REDO
{
ConfigWriter redo(++level);
patch::redo.config_store(redo);
std::stringstream ss;
redo.write(ss);
cw.append("redo", ss.str());
--level;
}
#endif
#ifdef PATCH_SWITCH_FAST_EXEDITWINDOW
{
ConfigWriter fast_exeditwindow(++level);
patch::fast_exeditwindow.config_store(fast_exeditwindow);
std::stringstream ss;
fast_exeditwindow.write(ss);
cw.append("fast_exeditwindow", ss.str());
--level;
}
#endif
#ifdef PATCH_SWITCH_FAST_TEXT
{
ConfigWriter fast_text(++level);
patch::fast::text.config_store(fast_text);
std::stringstream ss;
fast_text.write(ss);
cw.append("fast_text", ss.str());
--level;
}
#endif
{
ConfigWriter switch_(++level);
#ifdef PATCH_SWITCH_ACCESS_KEY
patch::access_key.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_COLORPALETTE_CACHE
patch::colorpalette_cache.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FILEINFO
patch::fileinfo.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_SUSIE_LOAD
patch::susie_load.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_SPLASH
patch::splash.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_AUP_SCENE_SETTING
patch::aup_scene_setting.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_AUP_LAYER_SETTING
patch::aup_layer_setting.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_EXO_AVIUTL_FILTER
patch::exo_aviutlfilter.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_EXO_SCENEIDX
patch::exo_sceneidx.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_EXO_TRACKPARAM
patch::exo_trackparam.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_EXO_TRACK_MINUSVAL
patch::exo_trackminusval.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_EXO_MIDPT_AND_TRA
patch::exo_midpt_and_tra.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_EXO_SPECIALCOLORCONV
patch::exo_specialcolorconv.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_EXO_FOLD_GUI
patch::exo_fold_gui.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_TRA_AVIUTL_FILTER
patch::tra_aviutlfilter.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_TRA_CHANGE_DRAWFILTER
patch::tra_change_drawfilter.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_TRA_SPECIFIED_SPEED
patch::tra_specified_speed.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_SETTING_NEW_PROJECT
patch::setting_new_project.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_TEXT_OP_SIZE
patch::text_op_size.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_IGNORE_MEDIA_PARAM_RESET
patch::ignore_media_param_reset.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FONT_DIALOG
patch::font_dialog.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_SCROLL_OBJDLG
patch::scroll_objdlg.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_ALPHA_BG
patch::alpha_bg.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_HELPFUL_MSGBOX
patch::helpful_msgbox.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAILED_SJIS_MSGBOX
patch::failed_sjis_msgbox.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAILED_LONGER_PATH
patch::failed_longer_path.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAILED_FILE_DROP
patch::failed_file_drop.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_THEME_CC
patch::theme_cc.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_EXEDITWINDOW_SIZING
patch::exeditwindow_sizing.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_SETTINGDIALOG_MOVE
patch::setting_dialog_move.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_OBJ_COLORCORRECTION
patch::ColorCorrection.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_OBJ_GLOW
patch::Glow.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_OBJ_LENSBLUR
patch::LensBlur.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_OBJ_NOISE
patch::Noise.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_OBJ_SPECIALCOLORCONV
patch::obj_specialcolorconv.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_SETTINGDIALOG_EXCOLORCONFIG
patch::excolorconfig.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_RCLICKMENU_SPLIT
patch::rclickmenu_split.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_RCLICKMENU_DELETE
patch::rclickmenu_delete.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_BLEND
patch::blend.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_ADD_EXTENSION
patch::add_extension.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_DIALOG_NEW_FILE
patch::dialog_new_file .switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_PLAYBACK_SPEED
patch::playback_speed.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_UNDO
patch::undo.switch_store(switch_);
#ifdef PATCH_SWITCH_UNDO_REDO
patch::redo.switch_store(switch_);
#endif
#endif
#ifdef PATCH_SWITCH_CONSOLE
patch::console.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_LUA
patch::lua.switch_store(switch_);
#ifdef PATCH_SWITCH_LUA_GETVALUE
patch::lua_getvalueex.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_LUA_RAND
patch::lua_rand.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_LUA_RANDEX
patch::lua_randex.switch_store(switch_);
#endif
#endif
#ifdef PATCH_SWITCH_FAST
patch::fast::fast.switch_store(switch_);
#ifdef PATCH_SWITCH_FAST_EXEDITWINDOW
patch::fast_exeditwindow.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_SETTINGDIALOG
patch::fast_setting_dialog.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_TEXT
patch::fast::text.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_CREATE_FIGURE
patch::fast::create_figure.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_BORDER
patch::fast::Border.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_GLOW
patch::fast::Glow.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_CL
patch::fast::cl.switch_store(switch_);
#ifdef PATCH_SWITCH_FAST_RADIATIONALBLUR
patch::fast::RadiationalBlur.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_POLORTRANSFORM
patch::fast::PolorTransform.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_DISPLACEMENTMAP
patch::fast::DisplacementMap.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_FLASH
patch::fast::Flash.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_DIRECTIONALBLUR
patch::fast::DirectionalBlur.switch_store(switch_);
#endif
#ifdef PATCH_SWITCH_FAST_LENSBLUR
patch::fast::LensBlur.switch_store(switch_);
#endif
#endif
#endif
std::stringstream ss;
switch_.write(ss);
cw.append("switch", ss.str());
--level;
}
std::stringstream ss;
cw.write(ss);
auto s = ss.str();
DWORD ignore;
WriteFile(hFile, s.c_str(), s.size(), &ignore, nullptr);
}
};
inline Config2 config2;
================================================
FILE: patch/config_rw.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "json.h"
#include "util_others.hpp"
namespace config_type {
struct ColorBGR {
union {
struct {
uint8_t b, g, r;
uint8_t valid;
};
uint32_t val;
};
ColorBGR() : val{} {}
ColorBGR(uint32_t x) : val(x) {
val = x;
valid = 1;
}
ColorBGR(int b, int g, int r) :b(b), g(g), r(r), valid(1) {}
ColorBGR(std::string_view x) {
if (x.size() < 6) {
b = g = r = valid = 0;
return;
}
auto itr = x.data();
std::from_chars(itr, itr + 2, r, 16);
itr += 2;
std::from_chars(itr, itr + 2, g, 16);
itr += 2;
std::from_chars(itr, itr + 2, b, 16);
valid = 1;
}
inline static ColorBGR from_rgb(uint32_t x) {
if (std::is_constant_evaluated()) {
return (x >> 16 & 0xff) || (x & 0xff00) || (x << 16 & 0xff0000);
}
else {
return _byteswap_ulong(x << 8);
}
}
constexpr uint32_t to_col() const noexcept {
return val & 0xffffff;
}
constexpr uint32_t to_col_rgb() const noexcept {
if (std::is_constant_evaluated()) {
return b << 16 | g << 8 | r;
}
else {
return _byteswap_ulong(val) >> 8;
}
}
std::string to_string() const {
return "{:02x}{:02x}{:02x}"_fmt(r, g, b);
}
std::string to_jsonstring() const {
if(valid) return "\"{:02x}{:02x}{:02x}\""_fmt(r, g, b);
return std::string{};
}
constexpr bool is_valid() const noexcept {
return valid;
}
bool operator==(ColorBGR x) const {
if (this->valid) {
if (!x.valid)return false;
else return (this->val & 0xffffff) == (x.val & 0xffffff);
}
else return !x.valid;
}
};
// ColorBGR2つの配列、またはColorBGR1つ、またはnulloptを表す
// [ "ffffff", "ffffff" ] や ["ffffff"]、"ffffff" など
struct ColorBGR2_Opt {
std::array ary{};
ColorBGR2_Opt() : ary{} {}
ColorBGR2_Opt(ColorBGR c1, ColorBGR c2) : ary{ c1,c2 } {}
inline void load(json_value_s* value) {
if (auto js = json_value_as_string(value)) {
ary[0] = std::string_view(js->string, js->string_size);
ary[1].valid = 0;
}
else if (auto ja = json_value_as_array(value)) {
if (ja->length == 0) {
ary[0].valid = 0;
}
else if (ja->length == 1) {
if (auto js = json_value_as_string(ja->start->value)) {
ary[0] = std::string_view(js->string, js->string_size);
ary[1].valid = 0;
}
}
else {
auto v = ja->start;
bool valid = true;
for (size_t i = 0; i < 2; i++) {
if (auto js = json_value_as_string(v->value)) {
ary[i] = std::string_view(js->string, js->string_size);
if (!ary[i].is_valid()) {
valid = false;
break;
}
}
v = v->next;
}
if (!valid) ary[0].valid = 0;
}
}
}
std::string to_jsonstring() const {
if (ary[0].is_valid()) {
if (ary[1].is_valid())
return "[ {}, {} ]"_fmt(ary[0].to_jsonstring(), ary[1].to_jsonstring());
else
return ary[0].to_jsonstring();
}
return std::string{};
}
constexpr bool has_value() const {
return ary[0].is_valid();
}
constexpr int count() const {
if (!ary[0].is_valid()) return 0;
return 1 + ary[1].is_valid();
}
};
// ColorBGRを2つ持つかnullopt
struct ColorBGR2 {
std::array ary;
ColorBGR2() : ary{} {}
ColorBGR2(ColorBGR c1, ColorBGR c2) : ary{ c1,c2 } {}
inline void load(json_value_s* value) {
if (auto ja = json_value_as_array(value)) {
if (ja->length > 1) {
auto v = ja->start;
bool valid = true;
for (size_t i = 0; i < 2; i++) {
if (auto js = json_value_as_string(v->value)) {
ary[i] = std::string_view(js->string, js->string_size);
if (!ary[i].is_valid()) {
valid = false;
break;
}
}
v = v->next;
}
if (!valid) ary[0].valid = 0;
}
}
}
std::string to_jsonstring() const {
if (ary[0].is_valid())
return "[ {}, {} ]"_fmt(ary[0].to_jsonstring(), ary[1].to_jsonstring());
return std::string{};
}
constexpr bool has_value() const {
return ary[0].is_valid();
}
constexpr int count() const {
if (!ary[0].is_valid()) return 0;
return 1 + ary[1].is_valid();
}
};
struct ColorBGR3 {
std::array ary;
ColorBGR3() : ary{} {}
ColorBGR3(ColorBGR c1, ColorBGR c2, ColorBGR c3) : ary{ c1,c2,c3 } {}
inline void load(json_value_s* value) {
if (auto ja = json_value_as_array(value)) {
if (ja->length > 2) {
auto v = ja->start;
bool valid = true;
for (size_t i = 0; i < 3; i++) {
if (auto js = json_value_as_string(v->value)) {
ary[i] = std::string_view(js->string, js->string_size);
if (!ary[i].is_valid()) {
valid = false;
break;
}
}
v = v->next;
}
if (!valid) ary[0].valid = 0;
}
}
}
constexpr bool has_value() const {
return ary[0].is_valid();
}
std::string to_jsonstring() const {
if (has_value())
return "[ {}, {}, {} ]"_fmt(ary[0].to_jsonstring(), ary[1].to_jsonstring(), ary[2].to_jsonstring());
return std::string{};
}
};
}
template
concept ConfigWriterHasToJsonString = requires (T x) {
x.to_jsonstring();
};
inline std::string mytostring(int x) {
std::string ret(std::numeric_limits::digits10 + 2, '\0');
std::to_chars(ret.data(), ret.data() + ret.size(), x);
ret.resize(ret.find_first_of('\0'));
return ret;
}
inline std::string mytostring(double x) {
std::string ret(std::numeric_limits::max_exponent10 + 9, '\0');
std::to_chars(ret.data(), ret.data() + ret.size(), x);
ret.resize(ret.find_first_of('\0'));
return ret;
}
template
concept ConfigWriterCanToChars = requires(T x) {
mytostring(x);
};
template
concept ConfigReaderHasLoad = requires(T x) {
x.load(std::declval());
};
class ConfigWriter {
std::stringstream ss;
struct KeyAndValue {
std::string key, value;
};
std::vector vkv;
int level;
inline static void WriteLevel(std::stringstream& ss, int level) {
for (int i = 0; i < level; i++) ss << '\t';
}
// {\n を書く
inline static void WriteBlockBegin(std::stringstream& ss) {
ss << "{\n";
}
// } を書く
inline static void WriteBlockEnd(std::stringstream& ss) {
ss << "}";
}
// [["key" : ]] を書く
inline static void WriteKey(std::stringstream& ss, std::string_view key) {
ss << "\"" << key << "\" : ";
}
template
inline static void WriteReturn(std::stringstream& ss) {
if constexpr (comma) ss << ",\n";
else ss << "\n";
}
public:
ConfigWriter(int level) : level(level) {}
void append(std::string_view key, std::string_view value) {
if(value.size() && value[0] != '\0') vkv.emplace_back(std::string(key), std::string(value));
}
template
void append(std::string_view key, const T& value) {
auto result = value.to_jsonstring();
if(result[0] != '\0') vkv.emplace_back(std::string(key), result);
}
void append(std::string_view key, bool value) {
vkv.emplace_back(std::string(key), value ? "true" : "false");
}
void append(std::string_view key, const RECT& value) {
vkv.emplace_back(std::string(key), "[ {}, {}, {}, {} ]"_fmt(value.left, value.top, value.right, value.bottom));
}
template
void append(std::string_view key, const std::array& value) {
if (value.size() > 0) {
std::stringstream ss;
ss << "[ ";
const auto last = value.size() - 1;
for (size_t i = 0; i < last; i++) {
ss << value[i] << ", ";
}
ss << value[last] << " ]";
vkv.emplace_back(std::string(key), ss.str());
}
else {
vkv.emplace_back(std::string(key), "[]");
}
}
template
void append(std::string_view key, const T& value) {
vkv.emplace_back(std::string(key), mytostring(value));
}
template
void append(std::string_view key, const std::optional& value) {
if (value) {
append(key, *value);
}
}
void write(std::stringstream& ss) const {
auto s = vkv.size();
if (s == 0)return;
WriteBlockBegin(ss);
for (size_t i = 0; i < s - 1; i++) {
WriteLevel(ss, level + 1);
WriteKey(ss, vkv[i].key);
ss << vkv[i].value;
WriteReturn(ss);
}
WriteLevel(ss, level + 1);
WriteKey(ss, vkv[s - 1].key);
ss << vkv[s - 1].value;
WriteReturn(ss);
WriteLevel(ss, level);
WriteBlockEnd(ss);
}
int get_level() const { return level; }
};
class ConfigReader {
json_value_s* value;
using RegisterFunction = std::function;
using MapType = std::unordered_map;
MapType map;
public:
ConfigReader(json_value_s* value) : value(value) {}
void load() {
auto obj = json_value_as_object(value);
if (obj == nullptr)return;
for (auto elm = obj->start; elm != nullptr; elm = elm->next) {
if (auto itr = map.find(elm->name->string); itr != map.end()) {
itr->second(elm->value);
}
}
}
template
void regist(const std::string& str, T func) {
map.try_emplace(str, func);
}
inline static bool load_variable(json_value_s* jv, bool& value) {
if (json_value_is_false(jv)) {
value = false;
return true;
}
else if (json_value_is_true(jv)) {
value = true;
return true;
}
return false;
}
template
inline static bool load_variable(json_value_s* jv, Int& value) {
if (auto n = json_value_as_number(jv); n) {
Int ret{};
std::from_chars(n->number, n->number + n->number_size, ret);
value = ret;
return true;
}
return false;
}
template
inline static bool load_variable(json_value_s* jv, Float& value) {
if (auto n = json_value_as_number(jv); n) {
Float ret;
std::from_chars(n->number, n->number + n->number_size, ret);
value = ret;
return true;
}
return false;
}
inline static void load_variable(json_value_s* jv, config_type::ColorBGR& value) {
if (auto s = json_value_as_string(jv); s) {
value = config_type::ColorBGR(std::string_view(s->string, s->string_size));
}
else {
value.valid = 0;
}
}
inline static void load_variable(json_value_s* jv, std::optional& value) {
if (auto ja = json_value_as_array(jv); ja) {
if (ja->length >= 4) {
auto itr = ja->start;
std::array buf;
for (size_t i = 0; i < 4; i++, itr = itr->next) {
if (auto jn = json_value_as_number(itr->value); jn) {
std::from_chars(jn->number, jn->number + jn->number_size, buf[i]);
}
else {
value = std::nullopt;
return;
}
}
value.emplace(RECT{
.left = buf[0],
.top = buf[1],
.right = buf[2],
.bottom = buf[3]
});
}
else {
value = std::nullopt;
}
}
else {
value = std::nullopt;
}
}
template
inline static void load_variable(json_value_s* jv, std::optional>& value) {
if (auto ja = json_value_as_array(jv); ja) {
if (ja->length >= N) {
auto itr = ja->start;
std::array buf;
for (size_t i = 0; i < N; i++, itr = itr->next) {
if (auto jn = json_value_as_number(itr->value); jn) {
std::from_chars(jn->number, jn->number + jn->number_size, buf[i]);
}
else {
value = std::nullopt;
return;
}
}
value = buf;
}
else {
value = std::nullopt;
return;
}
}
else {
int buf;
if (auto jn = json_value_as_number(jv); jn) {
std::from_chars(jn->number, jn->number + jn->number_size, buf);
}
else {
value = std::nullopt;
return;
}
value.emplace();
auto& v = value.value();
for (size_t i = 0; i < N; i++) {
v[i] = buf;
}
return;
}
}
template
inline static void load_variable(json_value_s* jv, T& value) {
value.load(jv);
}
template
inline static void load_variable(json_value_s* jv, std::optional& value) {
T t;
if (load_variable(jv, t)) {
value.emplace(std::move(t));
}
else {
value = std::nullopt;
}
}
};
================================================
FILE: patch/cryptostring.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include
#include
#include
///
/// バイナリに生の文字列を残さないためのクラス
///
template
class cryptostring {
template struct KeyV {};
template<> struct KeyV { inline static constexpr char value = 0b00101101i8; };
template<> struct KeyV { inline static constexpr wchar_t value = 0b1001010110001100i16; };
template
[[nodiscard]] constexpr static T bit_rotate_l(const T x, size_t a) {
auto ux = std::bit_cast>(x);
return std::bit_cast(std::rotl(ux, a));
}
template
[[nodiscard]] constexpr static T bit_rotate_r(const T x, size_t a) {
auto ux = std::bit_cast>(x);
return std::bit_cast(std::rotr(ux, a));
}
std::array ary;
bool decrypted = false;
public:
constexpr cryptostring(const CharT(&str)[N]) {
for (size_t i = 0; i < N; i++) ary[i] = str[i] ^ bit_rotate_l(KeyV::value, (i * 3) % (CHAR_BIT * sizeof(CharT)));
}
[[nodiscard]] CharT* get() {
if (!decrypted) [[unlikely]] {
for (size_t i = 0; i < N; i++) ary[i] ^= bit_rotate_l(KeyV::value, (i * 3) % (CHAR_BIT * sizeof(CharT)));
decrypted = true;
}
return ary.data();
}
void re_encrypt() {
if (decrypted) [[likely]] {
for (size_t i = 0; i < N; i++) ary[i] ^= bit_rotate_l(KeyV::value, (i * 3) % (CHAR_BIT * sizeof(CharT)));
decrypted = false;
}
}
};
template
inline constexpr cryptostring make_cryptostring(const CharT(&str)[N]) {
return cryptostring(str);
}
inline cryptostring cstr_kernel32_dll("KERNEL32.DLL");
inline cryptostring cstr_user32_dll("USER32.DLL");
inline cryptostring cstr_EnumResourceLanguagesA("EnumResourceLanguagesA");
inline cryptostring cstr_LoadLibraryA("LoadLibraryA");
inline cryptostring cstr_LoadLibraryW("LoadLibraryW");
inline cryptostring cstr_MessageBoxA("MessageBoxA");
inline cryptostring cstr_gdi32_dll("GDI32.DLL");
inline cryptostring cstr_GetGlyphOutlineW("GetGlyphOutlineW");
inline cryptostring cstr_DeleteObject("DeleteObject");
inline cryptostring cstr_CreateFontIndirectW("CreateFontIndirectW");
inline cryptostring cstr_GetModuleHandleA("GetModuleHandleA");
inline cryptostring cstr_GetModuleHandleW("GetModuleHandleW");
inline cryptostring cstr_Module32First("Module32First");
inline cryptostring cstr_Module32FirstW("Module32FirstW");
inline cryptostring cstr_Module32Next("Module32Next");
inline cryptostring cstr_Module32NextW("Module32NextW");
================================================
FILE: patch/debug_log.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include "util_others.hpp"
inline class debug_log_t {
private:
std::mutex mtx;
public:
template
void operator()(const T& v) {
std::lock_guard lock(mtx);
std::cout << v << std::endl;
}
template
void operator()(Args... args) {
std::lock_guard lock(mtx);
format_to_os(std::cout, args...);
std::endl(std::cout);
}
} debug_log;
================================================
FILE: patch/gate.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
class Gate {
std::mutex mtx;
std::condition_variable cond;
bool flag;
public:
Gate() :mtx{}, cond{}, flag{} {}
Gate(bool opened) :mtx{}, cond{}, flag{opened} {}
void open() {
{
std::lock_guard lock(mtx);
flag = true;
}
cond.notify_one();
}
void wait() {
std::unique_lock lock(mtx);
cond.wait(lock, [this] { return flag; });
flag = false;
}
};
================================================
FILE: patch/global.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include
#include
#include "global_minimum.hpp"
namespace GLOBAL {
inline HMODULE exedit_hmod;
inline uint32_t& exedit_base = (uint32_t&)exedit_hmod;
inline std::byte executable_memory[USN_PAGE_SIZE * 16];
inline std::byte* executable_memory_cursor = executable_memory;
inline std::wstring patchaul_path;
inline std::wstring patchaul_config_path;
inline std::string patchaul_path_a;
}
================================================
FILE: patch/global_minimum.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include
namespace GLOBAL {
inline HMODULE aviutl_hmod;
inline uint32_t& aviutl_base = (uint32_t&)aviutl_hmod;
inline HINSTANCE patchaul_hinst;
inline void init_minimum(HINSTANCE patch_hmod) {
GLOBAL::patchaul_hinst = patch_hmod;
GLOBAL::aviutl_base = std::bit_cast(GetModuleHandleA(NULL));
}
}
================================================
FILE: patch/hash.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include
#include
#include
#include
struct SHA256 {
private:
inline constexpr static uint32_t K[] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
};
inline constexpr static uint32_t H0[] = { 0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19 };
static uint32_t Sigma0(uint32_t x) {
return std::rotr(x, 2) ^ std::rotr(x, 13) ^ std::rotr(x, 22);
}
static uint32_t Sigma1(uint32_t x) {
return std::rotr(x, 6) ^ std::rotr(x, 11) ^ std::rotr(x, 25);
}
static uint32_t sigma0(uint32_t x) {
return std::rotr(x, 7) ^ std::rotr(x, 18) ^ (x >> 3);
}
static uint32_t sigma1(uint32_t x) {
return std::rotr(x, 17) ^ std::rotr(x, 19) ^ (x >> 10);
}
static uint32_t Ch(uint32_t x, uint32_t y, uint32_t z) {
return (x & y) ^ (~x & z);
}
static uint32_t Maj(uint32_t x, uint32_t y, uint32_t z) {
return (x & y) ^ (y & z) ^ (z & x);
}
public:
std::byte data[32];
SHA256(std::string_view filename) {
#if _DEBUG && 1 // 重いので
std::fill(std::begin(data), std::end(data), std::byte{});
#else
std::vector buf;
{
auto hFile = CreateFileA(filename.data(), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE) throw std::runtime_error("Failed to open file.");
BOOST_SCOPE_EXIT_ALL(hFile) {
CloseHandle(hFile);
};
DWORD sizehigh;
auto sizelow = GetFileSize(hFile, &sizehigh);
buf.resize(sizelow);
DWORD read;
if (!ReadFile(hFile, buf.data(), sizelow, &read, nullptr)) throw std::runtime_error("Failed to read file.");
}
uint32_t H[8];
std::memcpy(H, H0, sizeof(H0));
auto process = [&](const byte* msg) {
uint32_t W[64];
for (size_t t = 0; t < 16; t++) {
W[t] = _byteswap_ulong(*reinterpret_cast(msg + t * 4));
}
for (size_t t = 16; t < 64; t++) {
W[t] = sigma1(W[t - 2]) + W[t - 7] + sigma0(W[t - 15]) + W[t - 16];
}
auto a = H[0];
auto b = H[1];
auto c = H[2];
auto d = H[3];
auto e = H[4];
auto f = H[5];
auto g = H[6];
auto h = H[7];
for (size_t t = 0; t < 64; t++) {
auto T1 = h + Sigma1(e) + Ch(e, f, g) + K[t] + W[t];
auto T2 = Sigma0(a) + Maj(a, b, c);
h = g;
g = f;
f = e;
e = d + T1;
d = c;
c = b;
b = a;
a = T1 + T2;
}
H[0] += a;
H[1] += b;
H[2] += c;
H[3] += d;
H[4] += e;
H[5] += f;
H[6] += g;
H[7] += h;
};
auto buf_size_d64 = buf.size() / 64;
auto buf_size_m64 = buf.size() % 64;
for (size_t i = 0; i < buf_size_d64; i++) process(&buf[i * 64]);
uint8_t last_msg[64];
std::memcpy(last_msg, buf.data() + buf_size_d64 * 64, buf_size_m64);
last_msg[buf_size_m64] = 0x80;
if (buf_size_m64 < 56) {
std::memset(last_msg + buf_size_m64 + 1, 0, 58 - buf_size_m64);
auto size = buf.size();
last_msg[59] = static_cast(size >> 29);
last_msg[60] = static_cast(size >> 21);
last_msg[61] = static_cast(size >> 13);
last_msg[62] = static_cast(size >> 5);
last_msg[63] = static_cast(size << 3);
process(last_msg);
}
else {
std::memset(last_msg + buf_size_m64 + 1, 0, 63 - buf_size_m64);
process(last_msg);
std::memset(last_msg, 0, 59);
auto size = buf.size();
last_msg[59] = static_cast(size >> 29);
last_msg[60] = static_cast(size >> 21);
last_msg[61] = static_cast(size >> 13);
last_msg[62] = static_cast(size >> 5);
last_msg[63] = static_cast(size << 3);
process(last_msg);
}
for (size_t i = 0; i < 8; i++) {
*reinterpret_cast(data + i * 4) = _byteswap_ulong(H[i]);
}
#endif
}
template requires(sizeof...(T) == std::extent_v)
constexpr SHA256(T&&... list) noexcept : data{ static_cast(std::forward(list))... } {}
static std::optional make_opt(std::string_view filename) {
try {
return SHA256(filename);
}
catch (const std::runtime_error&) {
return std::nullopt;
}
}
std::string tostring() const {
std::string ret;
ret.reserve(64);
static const char chs[] = "0123456789ABCDEF";
for (auto b : data) {
ret.append(1, chs[(std::to_integer(b) >> 4) & 0xf]);
ret.append(1, chs[std::to_integer(b) & 0xf]);
}
return ret;
}
};
inline bool operator==(const SHA256& a, const SHA256& b) {
return std::equal(std::begin(a.data), std::end(a.data), std::begin(b.data));
}
================================================
FILE: patch/init.cpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#include "init.hpp"
#include
#include
#include "cryptostring.hpp"
#include "util_others.hpp"
#include "util_resource.hpp"
#include "config.hpp"
void init_t::InitAtDllMain() {
ExchangeFunction(GLOBAL::aviutl_hmod, cstr_kernel32_dll.get(), cstr_EnumResourceLanguagesA.get(), EnumResourceLanguagesA_Wrap);
}
void init_t::InitAtPatchLoaded() {
{
static const char aviutl_version_str[] = {
'1','.','1','0','\0','\0','\0','\0'
};
if (memcmp(reinterpret_cast(GLOBAL::aviutl_base + OFS::AviUtl::VersionString), aviutl_version_str, sizeof(aviutl_version_str)) != 0) {
MessageBoxW(NULL, L"patch.aul requires AviUtl *1.10*.\nAviUtl version 1.10以外では動作しません.", L"patch.aul", MB_ICONEXCLAMATION);
return;
}
}
GLOBAL::patchaul_path = WinWrap::Module{ GLOBAL::patchaul_hinst }.getFileNameW();
GLOBAL::patchaul_path_a = WinWrap::Module{ GLOBAL::patchaul_hinst }.getFileNameA();
GLOBAL::patchaul_config_path = GLOBAL::patchaul_path + L".json";
//GLOBAL::config.load(GLOBAL::patchaul_config_path);
config2.load(GLOBAL::patchaul_config_path);
add_dll_ref.add_ref();
ModulesData::update();
{
DWORD oldProtect;
VirtualProtect(GLOBAL::executable_memory, sizeof(GLOBAL::executable_memory), PAGE_EXECUTE_READWRITE, &oldProtect);
}
InjectFunction_fastcall(GLOBAL::aviutl_base + OFS::AviUtl::InitAuf, InitAufBefore, 10);
ExchangeFunction(GLOBAL::aviutl_hmod, cstr_kernel32_dll.get(), cstr_LoadLibraryA.get(), LoadLibraryAWrap);
overwrite_resource();
#ifdef PATCH_SWITCH_SPLASH
if (PATCH_SWITCHER_MEMBER(PATCH_SWITCH_SPLASH)) {
patch::splash.init();
patch::splash.set_phase(L"patch.aulの準備中", L"");
patch::splash.start();
}
#endif
#ifdef PATCH_SWITCH_CONSOLE
patch::console.init();
#endif
#ifdef PATCH_SWITCH_EXCEPTION_LOG
patch::exception_log();
#endif
#ifdef PATCH_SWITCH_SYSINFO_MODIFY
patch::sysinfo_info_write();
#endif
#ifdef PATCH_SWITCH_ACCESS_KEY
patch::access_key.init();
#endif
#ifdef PATCH_SWITCH_COLORPALETTE_CACHE
patch::colorpalette_cache.init();
#endif
#ifdef PATCH_SWITCH_FILEINFO
patch::fileinfo.init();
#endif
}
void init_t::InitAtExeditLoad() {
mywindow.init();
#ifdef PATCH_SWITCH_THEME_CC
patch::theme_cc.init();
#endif
#ifdef PATCH_SWITCH_AUP_SCENE_SETTING
patch::aup_scene_setting.init();
#endif
#ifdef PATCH_SWITCH_TRA_AVIUTL_FILTER
patch::tra_aviutlfilter.init();
#endif
#ifdef PATCH_SWITCH_TRA_CHANGE_DRAWFILTER
patch::tra_change_drawfilter.init();
#endif
#ifdef PATCH_SWITCH_TRA_SPECIFIED_SPEED
patch::tra_specified_speed.init();
#endif
#ifdef PATCH_SWITCH_SETTING_NEW_PROJECT
patch::setting_new_project.init();
#endif
#ifdef PATCH_SWITCH_AUP_LAYER_SETTING
patch::aup_layer_setting.init();
#endif
#ifdef PATCH_SWITCH_EXO_AVIUTL_FILTER
patch::exo_aviutlfilter.init();
#endif
#ifdef PATCH_SWITCH_EXO_SCENEIDX
patch::exo_sceneidx.init();
#endif
#ifdef PATCH_SWITCH_EXO_TRACKPARAM
patch::exo_trackparam.init();
#endif
#ifdef PATCH_SWITCH_EXO_TRACK_MINUSVAL
patch::exo_trackminusval.init();
#endif
#ifdef PATCH_SWITCH_EXO_MIDPT_AND_TRA
patch::exo_midpt_and_tra.init();
#endif
#ifdef PATCH_SWITCH_EXO_SPECIALCOLORCONV
patch::exo_specialcolorconv.init();
#endif
#ifdef PATCH_SWITCH_EXO_FOLD_GUI
patch::exo_fold_gui.init();
#endif
#ifdef PATCH_SWITCH_CONSOLE
patch::console.init_at_exedit_init();
#endif
#ifdef PATCH_SWITCH_TEXT_OP_SIZE
patch::text_op_size.init();
#endif
#ifdef PATCH_SWITCH_IGNORE_MEDIA_PARAM_RESET
patch::ignore_media_param_reset.init();
#endif
#ifdef PATCH_SWITCH_SCROLL_OBJDLG
patch::scroll_objdlg.init();
#endif
#ifdef PATCH_SWITCH_SUSIE_LOAD
patch::susie_load.init();
#endif
#ifdef PATCH_SWITCH_HELPFUL_MSGBOX
patch::helpful_msgbox.init();
#endif
#ifdef PATCH_SWITCH_FAILED_SJIS_MSGBOX
patch::failed_sjis_msgbox.init();
#endif
#ifdef PATCH_SWITCH_FAILED_LONGER_PATH
patch::failed_longer_path.init();
#endif
#ifdef PATCH_SWITCH_FAILED_FILE_DROP
patch::failed_file_drop.init();
#endif
#ifdef PATCH_SWITCH_OBJ_COLORCORRECTION
patch::ColorCorrection.init();
#endif
#ifdef PATCH_SWITCH_OBJ_GLOW
patch::Glow.init();
#endif
#ifdef PATCH_SWITCH_OBJ_LENSBLUR
patch::LensBlur.init();
#endif
#ifdef PATCH_SWITCH_OBJ_NOISE
patch::Noise.init();
#endif
#ifdef PATCH_SWITCH_OBJ_SPECIALCOLORCONV
patch::obj_specialcolorconv.init();
#endif
#ifdef PATCH_SWITCH_SETTINGDIALOG_EXCOLORCONFIG
patch::excolorconfig.init();
#endif
#ifdef PATCH_SWITCH_RCLICKMENU_SPLIT
patch::rclickmenu_split.init();
#endif
#ifdef PATCH_SWITCH_RCLICKMENU_DELETE
patch::rclickmenu_delete.init();
#endif
#ifdef PATCH_SWITCH_BLEND
patch::blend.init();
#endif
#ifdef PATCH_SWITCH_ADD_EXTENSION
patch::add_extension.init();
#endif
#ifdef PATCH_SWITCH_DIALOG_NEW_FILE
patch::dialog_new_file.init();
#endif
#ifdef PATCH_SWITCH_PLAYBACK_SPEED
patch::playback_speed.init();
#endif
patch::setting_dialog();
#ifdef PATCH_SWITCH_FAST
patch::fast::fast.init();
if (patch::fast::fast.is_enabled_i()) {
#ifdef PATCH_SWITCH_FAST_GETPUTPIXELDATA
patch::fast::getputpixeldata();
#endif
#ifdef PATCH_SWITCH_FAST_SETTINGDIALOG
patch::fast_setting_dialog.init();
#endif
#ifdef PATCH_SWITCH_FAST_EXEDITWINDOW
patch::fast_exeditwindow.init();
#endif
#ifdef PATCH_SWITCH_FAST_TEXT
patch::fast::text.init();
#endif
#ifdef PATCH_SWITCH_FAST_CREATE_FIGURE
patch::fast::create_figure.init();
#endif
#ifdef PATCH_SWITCH_FAST_BORDER
patch::fast::Border.init();
#endif
#ifdef PATCH_SWITCH_FAST_GLOW
patch::fast::Glow.init();
#endif
#ifdef PATCH_SWITCH_CL
if (patch::fast::cl.init()) {
if (patch::fast::cl.is_enabled_i()) {
#ifdef PATCH_SWITCH_FAST_POLORTRANSFORM
patch::fast::PolorTransform.init();
#endif
#ifdef PATCH_SWITCH_FAST_DISPLACEMENTMAP
patch::fast::DisplacementMap.init();
#endif
#ifdef PATCH_SWITCH_FAST_RADIATIONALBLUR
patch::fast::RadiationalBlur.init();
#endif
#ifdef PATCH_SWITCH_FAST_FLASH
patch::fast::Flash.init();
#endif
#ifdef PATCH_SWITCH_FAST_DIRECTIONALBLUR
patch::fast::DirectionalBlur.init();
#endif
#ifdef PATCH_SWITCH_FAST_LENSBLUR
patch::fast::LensBlur.init();
#endif
}
}
else {
patch_resource_message_w(PATCH_RS_PATCH_CANT_USE_CL, MB_TASKMODAL | MB_ICONEXCLAMATION);
}
#endif
}
#endif
#ifdef PATCH_SWITCH_UNDO
patch::undo.init();
if (patch::undo.is_enabled_i()) {
#ifdef PATCH_SWITCH_UNDO_REDO
patch::redo.init();
#endif
}
#endif
//GLOBAL::config.store(GLOBAL::patchaul_config_path);
config2.store(GLOBAL::patchaul_config_path);
}
void init_t::InitAufBefore() {
patch::aviutl_wndproc_override.go();
}
BOOL WINAPI init_t::EnumResourceLanguagesA_Wrap(HMODULE hModule, LPCSTR lpType, LPCSTR lpName, ENUMRESLANGPROCA lpEnumFunc, LONG_PTR lParam) {
ExchangeFunction((HMODULE)GLOBAL::aviutl_base, cstr_kernel32_dll.get(), cstr_EnumResourceLanguagesA.get(), EnumResourceLanguagesA);
InitAtPatchLoaded();
return FALSE;
}
HMODULE WINAPI init_t::LoadLibraryAWrap(LPCSTR lpLibFileName) {
HMODULE ret = LoadLibraryA(lpLibFileName);
if (ret == NULL)return NULL;
LPCSTR filename = PathFindFileNameA(lpLibFileName);
if (lstrcmpiA(filename, "exedit.auf") == 0) {
GLOBAL::exedit_hmod = ret;
auto filters = reinterpret_cast(GetProcAddress(ret, AviUtl::GetFilterTableListName))();
if (strcmp(filters[0]->information, "拡張編集(exedit) version 0.92 by KENくん") != 0) {
MessageBoxW(NULL, L"patch.aul requires Exedit version *0.92*.\n拡張編集 version 0.92以外では動作しません.", L"patch.aul", MB_ICONEXCLAMATION);
return ret;
}
original_func_init = std::exchange(filters[0]->func_init, func_initWrap);
original_func_WndProc = std::exchange(filters[0]->func_WndProc, func_WndProcWrap);
#ifdef _DEBUG
original_func_proc = std::exchange(filters[0]->func_proc, func_procWrap);
#endif
InitAtExeditLoad();
}
#ifdef PATCH_SWITCH_CANCEL_BOOST_CONFLICT
else if (lstrcmpiA(filename, "Boost.auf") == 0) {
if (auto ptr = search_import(ret, cstr_kernel32_dll.get(), cstr_GetModuleHandleA.get())) {
OverWriteOnProtectHelper(ptr, 4).store_i32(0, &init_t::Boost_GetModuleHandleA_Wrap);
}
if (auto ptr = search_import(ret, cstr_kernel32_dll.get(), cstr_GetModuleHandleW.get())) {
OverWriteOnProtectHelper(ptr, 4).store_i32(0, &init_t::Boost_GetModuleHandleW_Wrap);
}
if (auto ptr = search_import(ret, cstr_kernel32_dll.get(), cstr_LoadLibraryA.get())) {
OverWriteOnProtectHelper(ptr, 4).store_i32(0, &init_t::Boost_LoadLibraryA_Wrap);
}
if (auto ptr = search_import(ret, cstr_kernel32_dll.get(), cstr_LoadLibraryW.get())) {
OverWriteOnProtectHelper(ptr, 4).store_i32(0, &init_t::Boost_LoadLibraryW_Wrap);
}
if (auto ptr = search_import(ret, cstr_kernel32_dll.get(), cstr_Module32First.get())) {
OverWriteOnProtectHelper(ptr, 4).store_i32(0, &init_t::Boost_Module32First_Wrap);
}
if (auto ptr = search_import(ret, cstr_kernel32_dll.get(), cstr_Module32FirstW.get())) {
OverWriteOnProtectHelper(ptr, 4).store_i32(0, &init_t::Boost_Module32FirstW_Wrap);
}
if (auto ptr = search_import(ret, cstr_kernel32_dll.get(), cstr_Module32Next.get())) {
OverWriteOnProtectHelper(ptr, 4).store_i32(0, &init_t::Boost_Module32Next_Wrap);
}
if (auto ptr = search_import(ret, cstr_kernel32_dll.get(), cstr_Module32NextW.get())) {
OverWriteOnProtectHelper(ptr, 4).store_i32(0, &init_t::Boost_Module32NextW_Wrap);
}
}
#endif
#ifdef PATCH_SWITCH_WARNING_OLD_LSW
else if (lstrcmpiA(filename, "lwcolor.auc") == 0) {
static const SHA256 r940_hash(0xc7, 0xe2, 0x51, 0xde, 0xd2, 0xf8, 0x21, 0xcb, 0x1b, 0xc6, 0xb1, 0x9a, 0x66, 0x43, 0xd3, 0x0d, 0xa4, 0xeb, 0xd6, 0x97, 0x1e, 0x34, 0x1a, 0xb2, 0x11, 0xd9, 0x41, 0x1d, 0xcc, 0xbf, 0x9a, 0x18);
SHA256 hash(lpLibFileName);
if (hash == r940_hash) {
auto ret = patch_resource_message_w(PATCH_RS_PATCH_OLD_LSW, MB_ICONEXCLAMATION | MB_YESNO);
if (ret == IDYES) {
static cryptostring lsw_url(L"https://scrapbox.io/aviutl/L-SMASH_Works");
web_confirm(lsw_url.get());
}
}
}
#endif
else {
static std::set list = {
"bakusoku.auf",
"eclipse_fast.auf",
"redo.auf",
};
std::string check = filename;
std::transform(check.begin(), check.end(), check.begin(), [](auto c) { return std::tolower(c); });
if (list.find(check) != list.end()) {
FreeLibrary(ret);
auto ret = patch_resource_message_w(PATCH_RS_PATCH_CONFLICT_PLUGIN, MB_TASKMODAL | MB_ICONINFORMATION | MB_YESNO, string_convert_A2W(filename));
if (ret) {
switch (*ret) {
case IDYES:
DeleteFileA(lpLibFileName);
}
}
return NULL;
}
}
return ret;
}
BOOL __cdecl init_t::func_WndProcWrap(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, AviUtl::EditHandle* editp, AviUtl::FilterPlugin* fp) {
switch (message) {
#ifdef PATCH_SWITCH_EXEDITWINDOW_SIZING
case WM_SIZING:
if (auto ret = patch::exeditwindow_sizing.wndproc(wparam, lparam) == -1) break;
else return ret;
#endif
case AviUtl::FilterPlugin::WindowMessage::Command:
#ifdef PATCH_SWITCH_UNDO_REDO
if (wparam == PATCH_EXEDITMENU_REDO) {
if (patch::redo.is_enabled_i()) {
patch::redo.run_redo();
}
return TRUE;
}
#endif
}
return original_func_WndProc(hwnd, message, wparam, lparam, editp, fp);
}
BOOL __cdecl init_t::func_initWrap(AviUtl::FilterPlugin* fp) {
if (original_func_init(fp) == FALSE) return FALSE;
#ifdef PATCH_SWITCH_UNDO_REDO
fp->exfunc->add_menu_item(fp, "やり直す", fp->hwnd, PATCH_EXEDITMENU_REDO, 'Y', AviUtl::ExFunc::AddMenuItemFlag::Ctrl);
#endif
#ifdef PATCH_SWITCH_LUA
patch::lua.init();
#ifdef PATCH_SWITCH_LUA_RAND
patch::lua_rand.init();
#endif
#ifdef PATCH_SWITCH_LUA_RANDEX
patch::lua_randex.init();
#endif
#ifdef PATCH_SWITCH_LUA_GETVALUE
patch::lua_getvalueex.init();
#endif
#endif
return TRUE;
}
BOOL __cdecl init_t::func_procWrap(AviUtl::FilterPlugin* fp, AviUtl::FilterProcInfo* fpip) {
//std::cout << " = = = = = = " << std::endl;
#ifdef PATCH_SWITCH_ALPHA_BG
patch::alpha_bg.func_proc(fp, fpip);
#endif
return original_func_proc(fp, fpip);
}
#ifdef PATCH_SWITCH_CANCEL_BOOST_CONFLICT
HMODULE WINAPI init_t::Boost_GetModuleHandleA_Wrap(LPCSTR lpModuleName) {
auto filename = PathFindFileNameA(lpModuleName);
if (lstrcmpiA(filename, "patch.aul") == 0) {
return NULL;
}
return GetModuleHandleA(lpModuleName);
}
HMODULE WINAPI init_t::Boost_GetModuleHandleW_Wrap(LPCWSTR lpModuleName) {
auto filename = PathFindFileNameW(lpModuleName);
if (lstrcmpiW(filename, L"patch.aul") == 0) {
return NULL;
}
return GetModuleHandleW(lpModuleName);
}
HMODULE WINAPI init_t::Boost_LoadLibraryA_Wrap(LPCSTR lpLibFileName) {
auto filename = PathFindFileNameA(lpLibFileName);
if (lstrcmpiA(filename, "patch.aul") == 0) {
return NULL;
}
return LoadLibraryA(lpLibFileName);
}
HMODULE WINAPI init_t::Boost_LoadLibraryW_Wrap(LPCWSTR lpLibFileName) {
auto filename = PathFindFileNameW(lpLibFileName);
if (lstrcmpiW(filename, L"patch.aul") == 0) {
return NULL;
}
return LoadLibraryW(lpLibFileName);
}
BOOL WINAPI init_t::Boost_Module32First_Wrap(HANDLE hSnapshot, LPMODULEENTRY32 lpme) {
auto ret = Module32First(hSnapshot, lpme);
if (ret && lstrcmpiA(lpme->szModule, "patch.aul") == 0) {
return Module32Next(hSnapshot, lpme);
}
return ret;
}
BOOL WINAPI init_t::Boost_Module32FirstW_Wrap(HANDLE hSnapshot, LPMODULEENTRY32W lpme) {
auto ret = Module32FirstW(hSnapshot, lpme);
if (ret && lstrcmpiW(lpme->szModule, L"patch.aul") == 0) {
return Module32NextW(hSnapshot, lpme);
}
return ret;
}
BOOL WINAPI init_t::Boost_Module32Next_Wrap(HANDLE hSnapshot, LPMODULEENTRY32 lpme) {
auto ret = Module32Next(hSnapshot, lpme);
if (ret && lstrcmpiA(lpme->szModule, "patch.aul") == 0) {
return Module32Next(hSnapshot, lpme);
}
return ret;
}
BOOL WINAPI init_t::Boost_Module32NextW_Wrap(HANDLE hSnapshot, LPMODULEENTRY32W lpme) {
auto ret = Module32NextW(hSnapshot, lpme);
if (ret && lstrcmpiW(lpme->szModule, L"patch.aul") == 0) {
return Module32NextW(hSnapshot, lpme);
}
return ret;
}
#endif
================================================
FILE: patch/init.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include "cryptostring.hpp"
#include "add_dll_ref.hpp"
#include "util.hpp"
#include "global.hpp"
#include "offset_address.hpp"
#include "util.hpp"
#include "patch.hpp"
#include "debug_log.hpp"
#include "overwrite_resource.hpp"
#include "patch_exception_log.hpp"
#include "mywindow.hpp"
inline class init_t {
public:
inline static BOOL(__cdecl* original_func_WndProc)(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, AviUtl::EditHandle* editp, AviUtl::FilterPlugin* fp);
inline static BOOL(__cdecl* original_func_init)(AviUtl::FilterPlugin* fp);
inline static BOOL(__cdecl* original_func_proc)(AviUtl::FilterPlugin* fp, AviUtl::FilterProcInfo* fpip);
static BOOL __cdecl func_WndProcWrap(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, AviUtl::EditHandle* editp, AviUtl::FilterPlugin* fp);
static BOOL __cdecl func_initWrap(AviUtl::FilterPlugin* fp);
static BOOL __cdecl func_procWrap(AviUtl::FilterPlugin* fp, AviUtl::FilterProcInfo* fpip);
static BOOL WINAPI EnumResourceLanguagesA_Wrap(HMODULE hModule, LPCSTR lpType, LPCSTR lpName, ENUMRESLANGPROCA lpEnumFunc, LONG_PTR lParam);
static HMODULE WINAPI LoadLibraryAWrap(LPCSTR lpLibFileName);
#ifdef PATCH_SWITCH_CANCEL_BOOST_CONFLICT
static HMODULE WINAPI Boost_GetModuleHandleA_Wrap(LPCSTR lpModuleName);
static HMODULE WINAPI Boost_GetModuleHandleW_Wrap(LPCWSTR lpModuleName);
static HMODULE WINAPI Boost_LoadLibraryA_Wrap(LPCSTR lpLibFileName);
static HMODULE WINAPI Boost_LoadLibraryW_Wrap(LPCWSTR lpLibFileName);
static BOOL WINAPI Boost_Module32First_Wrap(HANDLE hSnapshot, LPMODULEENTRY32 lpme);
static BOOL WINAPI Boost_Module32FirstW_Wrap(HANDLE hSnapshot, LPMODULEENTRY32W lpme);
static BOOL WINAPI Boost_Module32Next_Wrap(HANDLE hSnapshot, LPMODULEENTRY32 lpme);
static BOOL WINAPI Boost_Module32NextW_Wrap(HANDLE hSnapshot, LPMODULEENTRY32W lpme);
#endif
// DllMain呼び出しのタイミングでやる処理
// できるだけ少なくしたい
static void InitAtDllMain();
// LoadLibrary("patch.aul")直後にやる処理
// EnumResourceLanguagesAの乗っ取りで実現
// EnumResourceLanguagesAが失敗したことにして,patch.aulは正しい言語拡張リソースではないことにする
static void InitAtPatchLoaded();
// exedit.aufのLoadLibrary直後にやる処理
// 拡張編集へのインジェクションはここでやる
static void InitAtExeditLoad();
// フィルタプラグインの読み込みを開始するタイミングでやる処理
static void InitAufBefore();
} init;
================================================
FILE: patch/json.h
================================================
/*
The latest version of this library is available on GitHub;
https://github.com/sheredom/json.h.
*/
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to .
*/
#ifndef SHEREDOM_JSON_H_INCLUDED
#define SHEREDOM_JSON_H_INCLUDED
#if defined(_MSC_VER)
#pragma warning(push)
/* disable warning: no function prototype given: converting '()' to '(void)' */
#pragma warning(disable : 4255)
/* disable warning: '__cplusplus' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
#pragma warning(disable : 4668)
/* disable warning: 'bytes padding added after construct' */
#pragma warning(disable : 4820)
#endif
#include
#include
#if defined(_MSC_VER)
#define json_weak __inline
#elif defined(__clang__) || defined(__GNUC__)
#define json_weak __attribute__((weak))
#else
#error Non clang, non gcc, non MSVC compiler found!
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct json_value_s;
struct json_parse_result_s;
enum json_parse_flags_e {
json_parse_flags_default = 0,
/* allow trailing commas in objects and arrays. For example, both [true,] and
{"a" : null,} would be allowed with this option on. */
json_parse_flags_allow_trailing_comma = 0x1,
/* allow unquoted keys for objects. For example, {a : null} would be allowed
with this option on. */
json_parse_flags_allow_unquoted_keys = 0x2,
/* allow a global unbracketed object. For example, a : null, b : true, c : {}
would be allowed with this option on. */
json_parse_flags_allow_global_object = 0x4,
/* allow objects to use '=' instead of ':' between key/value pairs. For
example, a = null, b : true would be allowed with this option on. */
json_parse_flags_allow_equals_in_object = 0x8,
/* allow that objects don't have to have comma separators between key/value
pairs. */
json_parse_flags_allow_no_commas = 0x10,
/* allow c-style comments (either variants) to be ignored in the input JSON
file. */
json_parse_flags_allow_c_style_comments = 0x20,
/* deprecated flag, unused. */
json_parse_flags_deprecated = 0x40,
/* record location information for each value. */
json_parse_flags_allow_location_information = 0x80,
/* allow strings to be 'single quoted'. */
json_parse_flags_allow_single_quoted_strings = 0x100,
/* allow numbers to be hexadecimal. */
json_parse_flags_allow_hexadecimal_numbers = 0x200,
/* allow numbers like +123 to be parsed. */
json_parse_flags_allow_leading_plus_sign = 0x400,
/* allow numbers like .0123 or 123. to be parsed. */
json_parse_flags_allow_leading_or_trailing_decimal_point = 0x800,
/* allow Infinity, -Infinity, NaN, -NaN. */
json_parse_flags_allow_inf_and_nan = 0x1000,
/* allow multi line string values. */
json_parse_flags_allow_multi_line_strings = 0x2000,
/* allow simplified JSON to be parsed. Simplified JSON is an enabling of a set
of other parsing options. */
json_parse_flags_allow_simplified_json =
(json_parse_flags_allow_trailing_comma |
json_parse_flags_allow_unquoted_keys |
json_parse_flags_allow_global_object |
json_parse_flags_allow_equals_in_object |
json_parse_flags_allow_no_commas),
/* allow JSON5 to be parsed. JSON5 is an enabling of a set of other parsing
options. */
json_parse_flags_allow_json5 =
(json_parse_flags_allow_trailing_comma |
json_parse_flags_allow_unquoted_keys |
json_parse_flags_allow_c_style_comments |
json_parse_flags_allow_single_quoted_strings |
json_parse_flags_allow_hexadecimal_numbers |
json_parse_flags_allow_leading_plus_sign |
json_parse_flags_allow_leading_or_trailing_decimal_point |
json_parse_flags_allow_inf_and_nan |
json_parse_flags_allow_multi_line_strings)
};
/* Parse a JSON text file, returning a pointer to the root of the JSON
* structure. json_parse performs 1 call to malloc for the entire encoding.
* Returns 0 if an error occurred (malformed JSON input, or malloc failed). */
json_weak struct json_value_s *json_parse(const void *src, size_t src_size);
/* Parse a JSON text file, returning a pointer to the root of the JSON
* structure. json_parse performs 1 call to alloc_func_ptr for the entire
* encoding. Returns 0 if an error occurred (malformed JSON input, or malloc
* failed). If an error occurred, the result struct (if not NULL) will explain
* the type of error, and the location in the input it occurred. If
* alloc_func_ptr is null then malloc is used. */
json_weak struct json_value_s *
json_parse_ex(const void *src, size_t src_size, size_t flags_bitset,
void *(*alloc_func_ptr)(void *, size_t), void *user_data,
struct json_parse_result_s *result);
/* Extracts a value and all the data that makes it up into a newly created
* value. json_extract_value performs 1 call to malloc for the entire encoding.
*/
json_weak struct json_value_s *
json_extract_value(const struct json_value_s *value);
/* Extracts a value and all the data that makes it up into a newly created
* value. json_extract_value performs 1 call to alloc_func_ptr for the entire
* encoding. If alloc_func_ptr is null then malloc is used. */
json_weak struct json_value_s *
json_extract_value_ex(const struct json_value_s *value,
void *(*alloc_func_ptr)(void *, size_t), void *user_data);
/* Write out a minified JSON utf-8 string. This string is an encoding of the
* minimal string characters required to still encode the same data.
* json_write_minified performs 1 call to malloc for the entire encoding. Return
* 0 if an error occurred (malformed JSON input, or malloc failed). The out_size
* parameter is optional as the utf-8 string is null terminated. */
json_weak void *json_write_minified(const struct json_value_s *value,
size_t *out_size);
/* Write out a pretty JSON utf-8 string. This string is encoded such that the
* resultant JSON is pretty in that it is easily human readable. The indent and
* newline parameters allow a user to specify what kind of indentation and
* newline they want (two spaces / three spaces / tabs? \r, \n, \r\n ?). Both
* indent and newline can be NULL, indent defaults to two spaces (" "), and
* newline defaults to linux newlines ('\n' as the newline character).
* json_write_pretty performs 1 call to malloc for the entire encoding. Return 0
* if an error occurred (malformed JSON input, or malloc failed). The out_size
* parameter is optional as the utf-8 string is null terminated. */
json_weak void *json_write_pretty(const struct json_value_s *value,
const char *indent, const char *newline,
size_t *out_size);
/* Reinterpret a JSON value as a string. Returns null is the value was not a
* string. */
json_weak struct json_string_s *
json_value_as_string(struct json_value_s *const value);
/* Reinterpret a JSON value as a number. Returns null is the value was not a
* number. */
json_weak struct json_number_s *
json_value_as_number(struct json_value_s *const value);
/* Reinterpret a JSON value as an object. Returns null is the value was not an
* object. */
json_weak struct json_object_s *
json_value_as_object(struct json_value_s *const value);
/* Reinterpret a JSON value as an array. Returns null is the value was not an
* array. */
json_weak struct json_array_s *
json_value_as_array(struct json_value_s *const value);
/* Whether the value is true. */
json_weak int json_value_is_true(const struct json_value_s *const value);
/* Whether the value is false. */
json_weak int json_value_is_false(const struct json_value_s *const value);
/* Whether the value is null. */
json_weak int json_value_is_null(const struct json_value_s *const value);
/* The various types JSON values can be. Used to identify what a value is. */
enum json_type_e {
json_type_string,
json_type_number,
json_type_object,
json_type_array,
json_type_true,
json_type_false,
json_type_null
};
/* A JSON string value. */
struct json_string_s {
/* utf-8 string */
const char *string;
/* The size (in bytes) of the string */
size_t string_size;
};
/* A JSON string value (extended). */
struct json_string_ex_s {
/* The JSON string this extends. */
struct json_string_s string;
/* The character offset for the value in the JSON input. */
size_t offset;
/* The line number for the value in the JSON input. */
size_t line_no;
/* The row number for the value in the JSON input, in bytes. */
size_t row_no;
};
/* A JSON number value. */
struct json_number_s {
/* ASCII string containing representation of the number. */
const char *number;
/* the size (in bytes) of the number. */
size_t number_size;
};
/* an element of a JSON object. */
struct json_object_element_s {
/* the name of this element. */
struct json_string_s *name;
/* the value of this element. */
struct json_value_s *value;
/* the next object element (can be NULL if the last element in the object). */
struct json_object_element_s *next;
};
/* a JSON object value. */
struct json_object_s {
/* a linked list of the elements in the object. */
struct json_object_element_s *start;
/* the number of elements in the object. */
size_t length;
};
/* an element of a JSON array. */
struct json_array_element_s {
/* the value of this element. */
struct json_value_s *value;
/* the next array element (can be NULL if the last element in the array). */
struct json_array_element_s *next;
};
/* a JSON array value. */
struct json_array_s {
/* a linked list of the elements in the array. */
struct json_array_element_s *start;
/* the number of elements in the array. */
size_t length;
};
/* a JSON value. */
struct json_value_s {
/* a pointer to either a json_string_s, json_number_s, json_object_s, or. */
/* json_array_s. Should be cast to the appropriate struct type based on what.
*/
/* the type of this value is. */
void *payload;
/* must be one of json_type_e. If type is json_type_true, json_type_false, or.
*/
/* json_type_null, payload will be NULL. */
size_t type;
};
/* a JSON value (extended). */
struct json_value_ex_s {
/* the JSON value this extends. */
struct json_value_s value;
/* the character offset for the value in the JSON input. */
size_t offset;
/* the line number for the value in the JSON input. */
size_t line_no;
/* the row number for the value in the JSON input, in bytes. */
size_t row_no;
};
/* a parsing error code. */
enum json_parse_error_e {
/* no error occurred (huzzah!). */
json_parse_error_none = 0,
/* expected either a comma or a closing '}' or ']' to close an object or. */
/* array! */
json_parse_error_expected_comma_or_closing_bracket,
/* colon separating name/value pair was missing! */
json_parse_error_expected_colon,
/* expected string to begin with '"'! */
json_parse_error_expected_opening_quote,
/* invalid escaped sequence in string! */
json_parse_error_invalid_string_escape_sequence,
/* invalid number format! */
json_parse_error_invalid_number_format,
/* invalid value! */
json_parse_error_invalid_value,
/* reached end of buffer before object/array was complete! */
json_parse_error_premature_end_of_buffer,
/* string was malformed! */
json_parse_error_invalid_string,
/* a call to malloc, or a user provider allocator, failed. */
json_parse_error_allocator_failed,
/* the JSON input had unexpected trailing characters that weren't part of the.
*/
/* JSON value. */
json_parse_error_unexpected_trailing_characters,
/* catch-all error for everything else that exploded (real bad chi!). */
json_parse_error_unknown
};
/* error report from json_parse_ex(). */
struct json_parse_result_s {
/* the error code (one of json_parse_error_e). */
size_t error;
/* the character offset for the error in the JSON input. */
size_t error_offset;
/* the line number for the error in the JSON input. */
size_t error_line_no;
/* the row number for the error, in bytes. */
size_t error_row_no;
};
#ifdef __cplusplus
} /* extern "C". */
#endif
#include
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#if defined(_MSC_VER) && (_MSC_VER < 1920)
#define json_uintmax_t unsigned __int64
#else
#include
#define json_uintmax_t uintmax_t
#endif
#if defined(_MSC_VER)
#define json_strtoumax _strtoui64
#else
#define json_strtoumax strtoumax
#endif
#if defined(__cplusplus) && (__cplusplus >= 201103L)
#define json_null nullptr
#else
#define json_null 0
#endif
#if defined(__clang__)
#pragma clang diagnostic push
/* we do one big allocation via malloc, then cast aligned slices of this for. */
/* our structures - we don't have a way to tell the compiler we know what we. */
/* are doing, so disable the warning instead! */
#pragma clang diagnostic ignored "-Wcast-align"
/* We use C style casts everywhere. */
#pragma clang diagnostic ignored "-Wold-style-cast"
/* We need long long for strtoull. */
#pragma clang diagnostic ignored "-Wc++11-long-long"
/* Who cares if nullptr doesn't work with C++98, we don't use it there! */
#pragma clang diagnostic ignored "-Wc++98-compat"
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#elif defined(_MSC_VER)
#pragma warning(push)
/* disable 'function selected for inline expansion' warning. */
#pragma warning(disable : 4711)
/* disable '#pragma warning: there is no warning number' warning. */
#pragma warning(disable : 4619)
/* disable 'warning number not a valid compiler warning' warning. */
#pragma warning(disable : 4616)
/* disable 'Compiler will insert Spectre mitigation for memory load if
* /Qspectre. */
/* switch specified' warning. */
#pragma warning(disable : 5045)
#endif
struct json_parse_state_s {
const char *src;
size_t size;
size_t offset;
size_t flags_bitset;
char *data;
char *dom;
size_t dom_size;
size_t data_size;
size_t line_no; /* line counter for error reporting. */
size_t line_offset; /* (offset-line_offset) is the character number (in
bytes). */
size_t error;
};
json_weak int json_hexadecimal_digit(const char c);
int json_hexadecimal_digit(const char c) {
if ('0' <= c && c <= '9') {
return c - '0';
}
if ('a' <= c && c <= 'f') {
return c - 'a' + 10;
}
if ('A' <= c && c <= 'F') {
return c - 'A' + 10;
}
return -1;
}
json_weak int json_hexadecimal_value(const char *c, const unsigned long size,
unsigned long *result);
int json_hexadecimal_value(const char *c, const unsigned long size,
unsigned long *result) {
const char *p;
int digit;
if (size > sizeof(unsigned long) * 2) {
return 0;
}
*result = 0;
for (p = c; (unsigned long)(p - c) < size; ++p) {
*result <<= 4;
digit = json_hexadecimal_digit(*p);
if (digit < 0 || digit > 15) {
return 0;
}
*result |= (unsigned char)digit;
}
return 1;
}
json_weak int json_skip_whitespace(struct json_parse_state_s *state);
int json_skip_whitespace(struct json_parse_state_s *state) {
size_t offset = state->offset;
const size_t size = state->size;
const char *const src = state->src;
/* the only valid whitespace according to ECMA-404 is ' ', '\n', '\r' and
* '\t'. */
switch (src[offset]) {
default:
return 0;
case ' ':
case '\r':
case '\t':
case '\n':
break;
}
do {
switch (src[offset]) {
default:
/* Update offset. */
state->offset = offset;
return 1;
case ' ':
case '\r':
case '\t':
break;
case '\n':
state->line_no++;
state->line_offset = offset;
break;
}
offset++;
} while (offset < size);
/* Update offset. */
state->offset = offset;
return 1;
}
json_weak int json_skip_c_style_comments(struct json_parse_state_s *state);
int json_skip_c_style_comments(struct json_parse_state_s *state) {
/* do we have a comment?. */
if ('/' == state->src[state->offset]) {
/* skip '/'. */
state->offset++;
if ('/' == state->src[state->offset]) {
/* we had a comment of the form //. */
/* skip second '/'. */
state->offset++;
while (state->offset < state->size) {
switch (state->src[state->offset]) {
default:
/* skip the character in the comment. */
state->offset++;
break;
case '\n':
/* if we have a newline, our comment has ended! Skip the newline. */
state->offset++;
/* we entered a newline, so move our line info forward. */
state->line_no++;
state->line_offset = state->offset;
return 1;
}
}
/* we reached the end of the JSON file! */
return 1;
} else if ('*' == state->src[state->offset]) {
/* we had a comment in the C-style long form. */
/* skip '*'. */
state->offset++;
while (state->offset + 1 < state->size) {
if (('*' == state->src[state->offset]) &&
('/' == state->src[state->offset + 1])) {
/* we reached the end of our comment! */
state->offset += 2;
return 1;
} else if ('\n' == state->src[state->offset]) {
/* we entered a newline, so move our line info forward. */
state->line_no++;
state->line_offset = state->offset;
}
/* skip character within comment. */
state->offset++;
}
/* Comment wasn't ended correctly which is a failure. */
return 1;
}
}
/* we didn't have any comment, which is ok too! */
return 0;
}
json_weak int json_skip_all_skippables(struct json_parse_state_s *state);
int json_skip_all_skippables(struct json_parse_state_s *state) {
/* skip all whitespace and other skippables until there are none left. note
* that the previous version suffered from read past errors should. the
* stream end on json_skip_c_style_comments eg. '{"a" ' with comments flag.
*/
int did_consume = 0;
const size_t size = state->size;
if (json_parse_flags_allow_c_style_comments & state->flags_bitset) {
do {
if (state->offset == size) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
did_consume = json_skip_whitespace(state);
/* This should really be checked on access, not in front of every call.
*/
if (state->offset == size) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
did_consume |= json_skip_c_style_comments(state);
} while (0 != did_consume);
} else {
do {
if (state->offset == size) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
did_consume = json_skip_whitespace(state);
} while (0 != did_consume);
}
if (state->offset == size) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
return 0;
}
json_weak int json_get_value_size(struct json_parse_state_s *state,
int is_global_object);
json_weak int json_get_string_size(struct json_parse_state_s *state,
size_t is_key);
int json_get_string_size(struct json_parse_state_s *state, size_t is_key) {
size_t offset = state->offset;
const size_t size = state->size;
size_t data_size = 0;
const char *const src = state->src;
const int is_single_quote = '\'' == src[offset];
const char quote_to_use = is_single_quote ? '\'' : '"';
const size_t flags_bitset = state->flags_bitset;
unsigned long codepoint;
unsigned long high_surrogate = 0;
if ((json_parse_flags_allow_location_information & flags_bitset) != 0 &&
is_key != 0) {
state->dom_size += sizeof(struct json_string_ex_s);
} else {
state->dom_size += sizeof(struct json_string_s);
}
if ('"' != src[offset]) {
/* if we are allowed single quoted strings check for that too. */
if (!((json_parse_flags_allow_single_quoted_strings & flags_bitset) &&
is_single_quote)) {
state->error = json_parse_error_expected_opening_quote;
state->offset = offset;
return 1;
}
}
/* skip leading '"' or '\''. */
offset++;
while ((offset < size) && (quote_to_use != src[offset])) {
/* add space for the character. */
data_size++;
switch (src[offset]) {
default:
break;
case '\0':
case '\t':
state->error = json_parse_error_invalid_string;
state->offset = offset;
return 1;
}
if ('\\' == src[offset]) {
/* skip reverse solidus character. */
offset++;
if (offset == size) {
state->error = json_parse_error_premature_end_of_buffer;
state->offset = offset;
return 1;
}
switch (src[offset]) {
default:
state->error = json_parse_error_invalid_string_escape_sequence;
state->offset = offset;
return 1;
case '"':
case '\\':
case '/':
case 'b':
case 'f':
case 'n':
case 'r':
case 't':
/* all valid characters! */
offset++;
break;
case 'u':
if (!(offset + 5 < size)) {
/* invalid escaped unicode sequence! */
state->error = json_parse_error_invalid_string_escape_sequence;
state->offset = offset;
return 1;
}
codepoint = 0;
if (!json_hexadecimal_value(&src[offset + 1], 4, &codepoint)) {
/* escaped unicode sequences must contain 4 hexadecimal digits! */
state->error = json_parse_error_invalid_string_escape_sequence;
state->offset = offset;
return 1;
}
/* Valid sequence!
* see: https://en.wikipedia.org/wiki/UTF-8#Invalid_code_points.
* 1 7 U + 0000 U + 007F 0xxxxxxx.
* 2 11 U + 0080 U + 07FF 110xxxxx
* 10xxxxxx.
* 3 16 U + 0800 U + FFFF 1110xxxx
* 10xxxxxx 10xxxxxx.
* 4 21 U + 10000 U + 10FFFF 11110xxx
* 10xxxxxx 10xxxxxx 10xxxxxx.
* Note: the high and low surrogate halves used by UTF-16 (U+D800
* through U+DFFF) and code points not encodable by UTF-16 (those after
* U+10FFFF) are not legal Unicode values, and their UTF-8 encoding must
* be treated as an invalid byte sequence. */
if (high_surrogate != 0) {
/* we previously read the high half of the \uxxxx\uxxxx pair, so now
* we expect the low half. */
if (codepoint >= 0xdc00 &&
codepoint <= 0xdfff) { /* low surrogate range. */
data_size += 3;
high_surrogate = 0;
} else {
state->error = json_parse_error_invalid_string_escape_sequence;
state->offset = offset;
return 1;
}
} else if (codepoint <= 0x7f) {
data_size += 0;
} else if (codepoint <= 0x7ff) {
data_size += 1;
} else if (codepoint >= 0xd800 &&
codepoint <= 0xdbff) { /* high surrogate range. */
/* The codepoint is the first half of a "utf-16 surrogate pair". so we
* need the other half for it to be valid: \uHHHH\uLLLL. */
if (offset + 11 > size || '\\' != src[offset + 5] ||
'u' != src[offset + 6]) {
state->error = json_parse_error_invalid_string_escape_sequence;
state->offset = offset;
return 1;
}
high_surrogate = codepoint;
} else if (codepoint >= 0xd800 &&
codepoint <= 0xdfff) { /* low surrogate range. */
/* we did not read the other half before. */
state->error = json_parse_error_invalid_string_escape_sequence;
state->offset = offset;
return 1;
} else {
data_size += 2;
}
/* escaped codepoints after 0xffff are supported in json through utf-16
* surrogate pairs: \uD83D\uDD25 for U+1F525. */
offset += 5;
break;
}
} else if (('\r' == src[offset]) || ('\n' == src[offset])) {
if (!(json_parse_flags_allow_multi_line_strings & flags_bitset)) {
/* invalid escaped unicode sequence! */
state->error = json_parse_error_invalid_string_escape_sequence;
state->offset = offset;
return 1;
}
offset++;
} else {
/* skip character (valid part of sequence). */
offset++;
}
}
/* If the offset is equal to the size, we had a non-terminated string! */
if (offset == size) {
state->error = json_parse_error_premature_end_of_buffer;
state->offset = offset - 1;
return 1;
}
/* skip trailing '"' or '\''. */
offset++;
/* add enough space to store the string. */
state->data_size += data_size;
/* one more byte for null terminator ending the string! */
state->data_size++;
/* update offset. */
state->offset = offset;
return 0;
}
json_weak int is_valid_unquoted_key_char(const char c);
int is_valid_unquoted_key_char(const char c) {
return (('0' <= c && c <= '9') || ('a' <= c && c <= 'z') ||
('A' <= c && c <= 'Z') || ('_' == c));
}
json_weak int json_get_key_size(struct json_parse_state_s *state);
int json_get_key_size(struct json_parse_state_s *state) {
const size_t flags_bitset = state->flags_bitset;
if (json_parse_flags_allow_unquoted_keys & flags_bitset) {
size_t offset = state->offset;
const size_t size = state->size;
const char *const src = state->src;
size_t data_size = state->data_size;
/* if we are allowing unquoted keys, first grok for a quote... */
if ('"' == src[offset]) {
/* ... if we got a comma, just parse the key as a string as normal. */
return json_get_string_size(state, 1);
} else if ((json_parse_flags_allow_single_quoted_strings & flags_bitset) &&
('\'' == src[offset])) {
/* ... if we got a comma, just parse the key as a string as normal. */
return json_get_string_size(state, 1);
} else {
while ((offset < size) && is_valid_unquoted_key_char(src[offset])) {
offset++;
data_size++;
}
/* one more byte for null terminator ending the string! */
data_size++;
if (json_parse_flags_allow_location_information & flags_bitset) {
state->dom_size += sizeof(struct json_string_ex_s);
} else {
state->dom_size += sizeof(struct json_string_s);
}
/* update offset. */
state->offset = offset;
/* update data_size. */
state->data_size = data_size;
return 0;
}
} else {
/* we are only allowed to have quoted keys, so just parse a string! */
return json_get_string_size(state, 1);
}
}
json_weak int json_get_object_size(struct json_parse_state_s *state,
int is_global_object);
int json_get_object_size(struct json_parse_state_s *state,
int is_global_object) {
const size_t flags_bitset = state->flags_bitset;
const char *const src = state->src;
const size_t size = state->size;
size_t elements = 0;
int allow_comma = 0;
int found_closing_brace = 0;
if (is_global_object) {
/* if we found an opening '{' of an object, we actually have a normal JSON
* object at the root of the DOM... */
if (!json_skip_all_skippables(state) && '{' == state->src[state->offset]) {
/* . and we don't actually have a global object after all! */
is_global_object = 0;
}
}
if (!is_global_object) {
if ('{' != src[state->offset]) {
state->error = json_parse_error_unknown;
return 1;
}
/* skip leading '{'. */
state->offset++;
}
state->dom_size += sizeof(struct json_object_s);
if ((state->offset == size) && !is_global_object) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
do {
if (!is_global_object) {
if (json_skip_all_skippables(state)) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
if ('}' == src[state->offset]) {
/* skip trailing '}'. */
state->offset++;
found_closing_brace = 1;
/* finished the object! */
break;
}
} else {
/* we don't require brackets, so that means the object ends when the input
* stream ends! */
if (json_skip_all_skippables(state)) {
break;
}
}
/* if we parsed at least once element previously, grok for a comma. */
if (allow_comma) {
if (',' == src[state->offset]) {
/* skip comma. */
state->offset++;
allow_comma = 0;
} else if (json_parse_flags_allow_no_commas & flags_bitset) {
/* we don't require a comma, and we didn't find one, which is ok! */
allow_comma = 0;
} else {
/* otherwise we are required to have a comma, and we found none. */
state->error = json_parse_error_expected_comma_or_closing_bracket;
return 1;
}
if (json_parse_flags_allow_trailing_comma & flags_bitset) {
continue;
} else {
if (json_skip_all_skippables(state)) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
}
}
if (json_get_key_size(state)) {
/* key parsing failed! */
state->error = json_parse_error_invalid_string;
return 1;
}
if (json_skip_all_skippables(state)) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
if (json_parse_flags_allow_equals_in_object & flags_bitset) {
const char current = src[state->offset];
if ((':' != current) && ('=' != current)) {
state->error = json_parse_error_expected_colon;
return 1;
}
} else {
if (':' != src[state->offset]) {
state->error = json_parse_error_expected_colon;
return 1;
}
}
/* skip colon. */
state->offset++;
if (json_skip_all_skippables(state)) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
if (json_get_value_size(state, /* is_global_object = */ 0)) {
/* value parsing failed! */
return 1;
}
/* successfully parsed a name/value pair! */
elements++;
allow_comma = 1;
} while (state->offset < size);
if ((state->offset == size) && !is_global_object && !found_closing_brace) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
state->dom_size += sizeof(struct json_object_element_s) * elements;
return 0;
}
json_weak int json_get_array_size(struct json_parse_state_s *state);
int json_get_array_size(struct json_parse_state_s *state) {
const size_t flags_bitset = state->flags_bitset;
size_t elements = 0;
int allow_comma = 0;
const char *const src = state->src;
const size_t size = state->size;
if ('[' != src[state->offset]) {
/* expected array to begin with leading '['. */
state->error = json_parse_error_unknown;
return 1;
}
/* skip leading '['. */
state->offset++;
state->dom_size += sizeof(struct json_array_s);
while (state->offset < size) {
if (json_skip_all_skippables(state)) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
if (']' == src[state->offset]) {
/* skip trailing ']'. */
state->offset++;
state->dom_size += sizeof(struct json_array_element_s) * elements;
/* finished the object! */
return 0;
}
/* if we parsed at least once element previously, grok for a comma. */
if (allow_comma) {
if (',' == src[state->offset]) {
/* skip comma. */
state->offset++;
allow_comma = 0;
} else if (!(json_parse_flags_allow_no_commas & flags_bitset)) {
state->error = json_parse_error_expected_comma_or_closing_bracket;
return 1;
}
if (json_parse_flags_allow_trailing_comma & flags_bitset) {
allow_comma = 0;
continue;
} else {
if (json_skip_all_skippables(state)) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
}
}
if (json_get_value_size(state, /* is_global_object = */ 0)) {
/* value parsing failed! */
return 1;
}
/* successfully parsed an array element! */
elements++;
allow_comma = 1;
}
/* we consumed the entire input before finding the closing ']' of the array!
*/
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
json_weak int json_get_number_size(struct json_parse_state_s *state);
int json_get_number_size(struct json_parse_state_s *state) {
const size_t flags_bitset = state->flags_bitset;
size_t offset = state->offset;
const size_t size = state->size;
int had_leading_digits = 0;
const char *const src = state->src;
state->dom_size += sizeof(struct json_number_s);
if ((json_parse_flags_allow_hexadecimal_numbers & flags_bitset) &&
(offset + 1 < size) && ('0' == src[offset]) &&
(('x' == src[offset + 1]) || ('X' == src[offset + 1]))) {
/* skip the leading 0x that identifies a hexadecimal number. */
offset += 2;
/* consume hexadecimal digits. */
while ((offset < size) && (('0' <= src[offset] && src[offset] <= '9') ||
('a' <= src[offset] && src[offset] <= 'f') ||
('A' <= src[offset] && src[offset] <= 'F'))) {
offset++;
}
} else {
int found_sign = 0;
int inf_or_nan = 0;
if ((offset < size) &&
(('-' == src[offset]) ||
((json_parse_flags_allow_leading_plus_sign & flags_bitset) &&
('+' == src[offset])))) {
/* skip valid leading '-' or '+'. */
offset++;
found_sign = 1;
}
if (json_parse_flags_allow_inf_and_nan & flags_bitset) {
const char inf[9] = "Infinity";
const size_t inf_strlen = sizeof(inf) - 1;
const char nan[4] = "NaN";
const size_t nan_strlen = sizeof(nan) - 1;
if (offset + inf_strlen < size) {
int found = 1;
size_t i;
for (i = 0; i < inf_strlen; i++) {
if (inf[i] != src[offset + i]) {
found = 0;
break;
}
}
if (found) {
/* We found our special 'Infinity' keyword! */
offset += inf_strlen;
inf_or_nan = 1;
}
}
if (offset + nan_strlen < size) {
int found = 1;
size_t i;
for (i = 0; i < nan_strlen; i++) {
if (nan[i] != src[offset + i]) {
found = 0;
break;
}
}
if (found) {
/* We found our special 'NaN' keyword! */
offset += nan_strlen;
inf_or_nan = 1;
}
}
}
if (found_sign && !inf_or_nan && (offset < size) &&
!('0' <= src[offset] && src[offset] <= '9')) {
/* check if we are allowing leading '.'. */
if (!(json_parse_flags_allow_leading_or_trailing_decimal_point &
flags_bitset) ||
('.' != src[offset])) {
/* a leading '-' must be immediately followed by any digit! */
state->error = json_parse_error_invalid_number_format;
state->offset = offset;
return 1;
}
}
if ((offset < size) && ('0' == src[offset])) {
/* skip valid '0'. */
offset++;
/* we need to record whether we had any leading digits for checks later.
*/
had_leading_digits = 1;
if ((offset < size) && ('0' <= src[offset] && src[offset] <= '9')) {
/* a leading '0' must not be immediately followed by any digit! */
state->error = json_parse_error_invalid_number_format;
state->offset = offset;
return 1;
}
}
/* the main digits of our number next. */
while ((offset < size) && ('0' <= src[offset] && src[offset] <= '9')) {
offset++;
/* we need to record whether we had any leading digits for checks later.
*/
had_leading_digits = 1;
}
if ((offset < size) && ('.' == src[offset])) {
offset++;
if (!('0' <= src[offset] && src[offset] <= '9')) {
if (!(json_parse_flags_allow_leading_or_trailing_decimal_point &
flags_bitset) ||
!had_leading_digits) {
/* a decimal point must be followed by at least one digit. */
state->error = json_parse_error_invalid_number_format;
state->offset = offset;
return 1;
}
}
/* a decimal point can be followed by more digits of course! */
while ((offset < size) && ('0' <= src[offset] && src[offset] <= '9')) {
offset++;
}
}
if ((offset < size) && ('e' == src[offset] || 'E' == src[offset])) {
/* our number has an exponent! Skip 'e' or 'E'. */
offset++;
if ((offset < size) && ('-' == src[offset] || '+' == src[offset])) {
/* skip optional '-' or '+'. */
offset++;
}
if ((offset < size) && !('0' <= src[offset] && src[offset] <= '9')) {
/* an exponent must have at least one digit! */
state->error = json_parse_error_invalid_number_format;
state->offset = offset;
return 1;
}
/* consume exponent digits. */
do {
offset++;
} while ((offset < size) && ('0' <= src[offset] && src[offset] <= '9'));
}
}
if (offset < size) {
switch (src[offset]) {
case ' ':
case '\t':
case '\r':
case '\n':
case '}':
case ',':
case ']':
/* all of the above are ok. */
break;
case '=':
if (json_parse_flags_allow_equals_in_object & flags_bitset) {
break;
}
state->error = json_parse_error_invalid_number_format;
state->offset = offset;
return 1;
default:
state->error = json_parse_error_invalid_number_format;
state->offset = offset;
return 1;
}
}
state->data_size += offset - state->offset;
/* one more byte for null terminator ending the number string! */
state->data_size++;
/* update offset. */
state->offset = offset;
return 0;
}
json_weak int json_get_value_size(struct json_parse_state_s *state,
int is_global_object);
int json_get_value_size(struct json_parse_state_s *state,
int is_global_object) {
const size_t flags_bitset = state->flags_bitset;
const char *const src = state->src;
size_t offset;
const size_t size = state->size;
if (json_parse_flags_allow_location_information & flags_bitset) {
state->dom_size += sizeof(struct json_value_ex_s);
} else {
state->dom_size += sizeof(struct json_value_s);
}
if (is_global_object) {
return json_get_object_size(state, /* is_global_object = */ 1);
} else {
if (json_skip_all_skippables(state)) {
state->error = json_parse_error_premature_end_of_buffer;
return 1;
}
/* can cache offset now. */
offset = state->offset;
switch (src[offset]) {
case '"':
return json_get_string_size(state, 0);
case '\'':
if (json_parse_flags_allow_single_quoted_strings & flags_bitset) {
return json_get_string_size(state, 0);
} else {
/* invalid value! */
state->error = json_parse_error_invalid_value;
return 1;
}
case '{':
return json_get_object_size(state, /* is_global_object = */ 0);
case '[':
return json_get_array_size(state);
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return json_get_number_size(state);
case '+':
if (json_parse_flags_allow_leading_plus_sign & flags_bitset) {
return json_get_number_size(state);
} else {
/* invalid value! */
state->error = json_parse_error_invalid_number_format;
return 1;
}
case '.':
if (json_parse_flags_allow_leading_or_trailing_decimal_point &
flags_bitset) {
return json_get_number_size(state);
} else {
/* invalid value! */
state->error = json_parse_error_invalid_number_format;
return 1;
}
default:
if ((offset + 4) <= size && 't' == src[offset + 0] &&
'r' == src[offset + 1] && 'u' == src[offset + 2] &&
'e' == src[offset + 3]) {
state->offset += 4;
return 0;
} else if ((offset + 5) <= size && 'f' == src[offset + 0] &&
'a' == src[offset + 1] && 'l' == src[offset + 2] &&
's' == src[offset + 3] && 'e' == src[offset + 4]) {
state->offset += 5;
return 0;
} else if ((offset + 4) <= size && 'n' == state->src[offset + 0] &&
'u' == state->src[offset + 1] &&
'l' == state->src[offset + 2] &&
'l' == state->src[offset + 3]) {
state->offset += 4;
return 0;
} else if ((json_parse_flags_allow_inf_and_nan & flags_bitset) &&
(offset + 3) <= size && 'N' == src[offset + 0] &&
'a' == src[offset + 1] && 'N' == src[offset + 2]) {
return json_get_number_size(state);
} else if ((json_parse_flags_allow_inf_and_nan & flags_bitset) &&
(offset + 8) <= size && 'I' == src[offset + 0] &&
'n' == src[offset + 1] && 'f' == src[offset + 2] &&
'i' == src[offset + 3] && 'n' == src[offset + 4] &&
'i' == src[offset + 5] && 't' == src[offset + 6] &&
'y' == src[offset + 7]) {
return json_get_number_size(state);
}
/* invalid value! */
state->error = json_parse_error_invalid_value;
return 1;
}
}
}
json_weak void json_parse_value(struct json_parse_state_s *state,
int is_global_object,
struct json_value_s *value);
json_weak void json_parse_string(struct json_parse_state_s *state,
struct json_string_s *string);
void json_parse_string(struct json_parse_state_s *state,
struct json_string_s *string) {
size_t offset = state->offset;
size_t bytes_written = 0;
const char *const src = state->src;
const char quote_to_use = '\'' == src[offset] ? '\'' : '"';
char *data = state->data;
unsigned long high_surrogate = 0;
unsigned long codepoint;
string->string = data;
/* skip leading '"' or '\''. */
offset++;
while (quote_to_use != src[offset]) {
if ('\\' == src[offset]) {
/* skip the reverse solidus. */
offset++;
switch (src[offset++]) {
default:
return; /* we cannot ever reach here. */
case 'u': {
codepoint = 0;
if (!json_hexadecimal_value(&src[offset], 4, &codepoint)) {
return; /* this shouldn't happen as the value was already validated.
*/
}
offset += 4;
if (codepoint <= 0x7fu) {
data[bytes_written++] = (char)codepoint; /* 0xxxxxxx. */
} else if (codepoint <= 0x7ffu) {
data[bytes_written++] =
(char)(0xc0u | (codepoint >> 6)); /* 110xxxxx. */
data[bytes_written++] =
(char)(0x80u | (codepoint & 0x3fu)); /* 10xxxxxx. */
} else if (codepoint >= 0xd800 &&
codepoint <= 0xdbff) { /* high surrogate. */
high_surrogate = codepoint;
continue; /* we need the low half to form a complete codepoint. */
} else if (codepoint >= 0xdc00 &&
codepoint <= 0xdfff) { /* low surrogate. */
/* combine with the previously read half to obtain the complete
* codepoint. */
const unsigned long surrogate_offset =
0x10000u - (0xD800u << 10) - 0xDC00u;
codepoint = (high_surrogate << 10) + codepoint + surrogate_offset;
high_surrogate = 0;
data[bytes_written++] =
(char)(0xF0u | (codepoint >> 18)); /* 11110xxx. */
data[bytes_written++] =
(char)(0x80u | ((codepoint >> 12) & 0x3fu)); /* 10xxxxxx. */
data[bytes_written++] =
(char)(0x80u | ((codepoint >> 6) & 0x3fu)); /* 10xxxxxx. */
data[bytes_written++] =
(char)(0x80u | (codepoint & 0x3fu)); /* 10xxxxxx. */
} else {
/* we assume the value was validated and thus is within the valid
* range. */
data[bytes_written++] =
(char)(0xe0u | (codepoint >> 12)); /* 1110xxxx. */
data[bytes_written++] =
(char)(0x80u | ((codepoint >> 6) & 0x3fu)); /* 10xxxxxx. */
data[bytes_written++] =
(char)(0x80u | (codepoint & 0x3fu)); /* 10xxxxxx. */
}
} break;
case '"':
data[bytes_written++] = '"';
break;
case '\\':
data[bytes_written++] = '\\';
break;
case '/':
data[bytes_written++] = '/';
break;
case 'b':
data[bytes_written++] = '\b';
break;
case 'f':
data[bytes_written++] = '\f';
break;
case 'n':
data[bytes_written++] = '\n';
break;
case 'r':
data[bytes_written++] = '\r';
break;
case 't':
data[bytes_written++] = '\t';
break;
case '\r':
data[bytes_written++] = '\r';
/* check if we have a "\r\n" sequence. */
if ('\n' == src[offset]) {
data[bytes_written++] = '\n';
offset++;
}
break;
case '\n':
data[bytes_written++] = '\n';
break;
}
} else {
/* copy the character. */
data[bytes_written++] = src[offset++];
}
}
/* skip trailing '"' or '\''. */
offset++;
/* record the size of the string. */
string->string_size = bytes_written;
/* add null terminator to string. */
data[bytes_written++] = '\0';
/* move data along. */
state->data += bytes_written;
/* update offset. */
state->offset = offset;
}
json_weak void json_parse_key(struct json_parse_state_s *state,
struct json_string_s *string);
void json_parse_key(struct json_parse_state_s *state,
struct json_string_s *string) {
if (json_parse_flags_allow_unquoted_keys & state->flags_bitset) {
const char *const src = state->src;
char *const data = state->data;
size_t offset = state->offset;
/* if we are allowing unquoted keys, check for quoted anyway... */
if (('"' == src[offset]) || ('\'' == src[offset])) {
/* ... if we got a quote, just parse the key as a string as normal. */
json_parse_string(state, string);
} else {
size_t size = 0;
string->string = state->data;
while (is_valid_unquoted_key_char(src[offset])) {
data[size++] = src[offset++];
}
/* add null terminator to string. */
data[size] = '\0';
/* record the size of the string. */
string->string_size = size++;
/* move data along. */
state->data += size;
/* update offset. */
state->offset = offset;
}
} else {
/* we are only allowed to have quoted keys, so just parse a string! */
json_parse_string(state, string);
}
}
json_weak void json_parse_object(struct json_parse_state_s *state,
int is_global_object,
struct json_object_s *object);
void json_parse_object(struct json_parse_state_s *state, int is_global_object,
struct json_object_s *object) {
const size_t flags_bitset = state->flags_bitset;
const size_t size = state->size;
const char *const src = state->src;
size_t elements = 0;
int allow_comma = 0;
struct json_object_element_s *previous = json_null;
if (is_global_object) {
/* if we skipped some whitespace, and then found an opening '{' of an. */
/* object, we actually have a normal JSON object at the root of the DOM...
*/
if ('{' == src[state->offset]) {
/* . and we don't actually have a global object after all! */
is_global_object = 0;
}
}
if (!is_global_object) {
/* skip leading '{'. */
state->offset++;
}
(void)json_skip_all_skippables(state);
/* reset elements. */
elements = 0;
while (state->offset < size) {
struct json_object_element_s *element = json_null;
struct json_string_s *string = json_null;
struct json_value_s *value = json_null;
if (!is_global_object) {
(void)json_skip_all_skippables(state);
if ('}' == src[state->offset]) {
/* skip trailing '}'. */
state->offset++;
/* finished the object! */
break;
}
} else {
if (json_skip_all_skippables(state)) {
/* global object ends when the file ends! */
break;
}
}
/* if we parsed at least one element previously, grok for a comma. */
if (allow_comma) {
if (',' == src[state->offset]) {
/* skip comma. */
state->offset++;
allow_comma = 0;
continue;
}
}
element = (struct json_object_element_s *)state->dom;
state->dom += sizeof(struct json_object_element_s);
if (json_null == previous) {
/* this is our first element, so record it in our object. */
object->start = element;
} else {
previous->next = element;
}
previous = element;
if (json_parse_flags_allow_location_information & flags_bitset) {
struct json_string_ex_s *string_ex =
(struct json_string_ex_s *)state->dom;
state->dom += sizeof(struct json_string_ex_s);
string_ex->offset = state->offset;
string_ex->line_no = state->line_no;
string_ex->row_no = state->offset - state->line_offset;
string = &(string_ex->string);
} else {
string = (struct json_string_s *)state->dom;
state->dom += sizeof(struct json_string_s);
}
element->name = string;
(void)json_parse_key(state, string);
(void)json_skip_all_skippables(state);
/* skip colon or equals. */
state->offset++;
(void)json_skip_all_skippables(state);
if (json_parse_flags_allow_location_information & flags_bitset) {
struct json_value_ex_s *value_ex = (struct json_value_ex_s *)state->dom;
state->dom += sizeof(struct json_value_ex_s);
value_ex->offset = state->offset;
value_ex->line_no = state->line_no;
value_ex->row_no = state->offset - state->line_offset;
value = &(value_ex->value);
} else {
value = (struct json_value_s *)state->dom;
state->dom += sizeof(struct json_value_s);
}
element->value = value;
json_parse_value(state, /* is_global_object = */ 0, value);
/* successfully parsed a name/value pair! */
elements++;
allow_comma = 1;
}
/* if we had at least one element, end the linked list. */
if (previous) {
previous->next = json_null;
}
if (0 == elements) {
object->start = json_null;
}
object->length = elements;
}
json_weak void json_parse_array(struct json_parse_state_s *state,
struct json_array_s *array);
void json_parse_array(struct json_parse_state_s *state,
struct json_array_s *array) {
const char *const src = state->src;
const size_t size = state->size;
size_t elements = 0;
int allow_comma = 0;
struct json_array_element_s *previous = json_null;
/* skip leading '['. */
state->offset++;
(void)json_skip_all_skippables(state);
/* reset elements. */
elements = 0;
do {
struct json_array_element_s *element = json_null;
struct json_value_s *value = json_null;
(void)json_skip_all_skippables(state);
if (']' == src[state->offset]) {
/* skip trailing ']'. */
state->offset++;
/* finished the array! */
break;
}
/* if we parsed at least one element previously, grok for a comma. */
if (allow_comma) {
if (',' == src[state->offset]) {
/* skip comma. */
state->offset++;
allow_comma = 0;
continue;
}
}
element = (struct json_array_element_s *)state->dom;
state->dom += sizeof(struct json_array_element_s);
if (json_null == previous) {
/* this is our first element, so record it in our array. */
array->start = element;
} else {
previous->next = element;
}
previous = element;
if (json_parse_flags_allow_location_information & state->flags_bitset) {
struct json_value_ex_s *value_ex = (struct json_value_ex_s *)state->dom;
state->dom += sizeof(struct json_value_ex_s);
value_ex->offset = state->offset;
value_ex->line_no = state->line_no;
value_ex->row_no = state->offset - state->line_offset;
value = &(value_ex->value);
} else {
value = (struct json_value_s *)state->dom;
state->dom += sizeof(struct json_value_s);
}
element->value = value;
json_parse_value(state, /* is_global_object = */ 0, value);
/* successfully parsed an array element! */
elements++;
allow_comma = 1;
} while (state->offset < size);
/* end the linked list. */
if (previous) {
previous->next = json_null;
}
if (0 == elements) {
array->start = json_null;
}
array->length = elements;
}
json_weak void json_parse_number(struct json_parse_state_s *state,
struct json_number_s *number);
void json_parse_number(struct json_parse_state_s *state,
struct json_number_s *number) {
const size_t flags_bitset = state->flags_bitset;
size_t offset = state->offset;
const size_t size = state->size;
size_t bytes_written = 0;
const char *const src = state->src;
char *data = state->data;
number->number = data;
if (json_parse_flags_allow_hexadecimal_numbers & flags_bitset) {
if (('0' == src[offset]) &&
(('x' == src[offset + 1]) || ('X' == src[offset + 1]))) {
/* consume hexadecimal digits. */
while ((offset < size) &&
(('0' <= src[offset] && src[offset] <= '9') ||
('a' <= src[offset] && src[offset] <= 'f') ||
('A' <= src[offset] && src[offset] <= 'F') ||
('x' == src[offset]) || ('X' == src[offset]))) {
data[bytes_written++] = src[offset++];
}
}
}
while (offset < size) {
int end = 0;
switch (src[offset]) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
case 'e':
case 'E':
case '+':
case '-':
data[bytes_written++] = src[offset++];
break;
default:
end = 1;
break;
}
if (0 != end) {
break;
}
}
if (json_parse_flags_allow_inf_and_nan & flags_bitset) {
const size_t inf_strlen = 8; /* = strlen("Infinity");. */
const size_t nan_strlen = 3; /* = strlen("NaN");. */
if (offset + inf_strlen < size) {
if ('I' == src[offset]) {
size_t i;
/* We found our special 'Infinity' keyword! */
for (i = 0; i < inf_strlen; i++) {
data[bytes_written++] = src[offset++];
}
}
}
if (offset + nan_strlen < size) {
if ('N' == src[offset]) {
size_t i;
/* We found our special 'NaN' keyword! */
for (i = 0; i < nan_strlen; i++) {
data[bytes_written++] = src[offset++];
}
}
}
}
/* record the size of the number. */
number->number_size = bytes_written;
/* add null terminator to number string. */
data[bytes_written++] = '\0';
/* move data along. */
state->data += bytes_written;
/* update offset. */
state->offset = offset;
}
json_weak void json_parse_value(struct json_parse_state_s *state,
int is_global_object,
struct json_value_s *value);
void json_parse_value(struct json_parse_state_s *state, int is_global_object,
struct json_value_s *value) {
const size_t flags_bitset = state->flags_bitset;
const char *const src = state->src;
const size_t size = state->size;
size_t offset;
(void)json_skip_all_skippables(state);
/* cache offset now. */
offset = state->offset;
if (is_global_object) {
value->type = json_type_object;
value->payload = state->dom;
state->dom += sizeof(struct json_object_s);
json_parse_object(state, /* is_global_object = */ 1,
(struct json_object_s *)value->payload);
} else {
switch (src[offset]) {
case '"':
case '\'':
value->type = json_type_string;
value->payload = state->dom;
state->dom += sizeof(struct json_string_s);
json_parse_string(state, (struct json_string_s *)value->payload);
break;
case '{':
value->type = json_type_object;
value->payload = state->dom;
state->dom += sizeof(struct json_object_s);
json_parse_object(state, /* is_global_object = */ 0,
(struct json_object_s *)value->payload);
break;
case '[':
value->type = json_type_array;
value->payload = state->dom;
state->dom += sizeof(struct json_array_s);
json_parse_array(state, (struct json_array_s *)value->payload);
break;
case '-':
case '+':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
value->type = json_type_number;
value->payload = state->dom;
state->dom += sizeof(struct json_number_s);
json_parse_number(state, (struct json_number_s *)value->payload);
break;
default:
if ((offset + 4) <= size && 't' == src[offset + 0] &&
'r' == src[offset + 1] && 'u' == src[offset + 2] &&
'e' == src[offset + 3]) {
value->type = json_type_true;
value->payload = json_null;
state->offset += 4;
} else if ((offset + 5) <= size && 'f' == src[offset + 0] &&
'a' == src[offset + 1] && 'l' == src[offset + 2] &&
's' == src[offset + 3] && 'e' == src[offset + 4]) {
value->type = json_type_false;
value->payload = json_null;
state->offset += 5;
} else if ((offset + 4) <= size && 'n' == src[offset + 0] &&
'u' == src[offset + 1] && 'l' == src[offset + 2] &&
'l' == src[offset + 3]) {
value->type = json_type_null;
value->payload = json_null;
state->offset += 4;
} else if ((json_parse_flags_allow_inf_and_nan & flags_bitset) &&
(offset + 3) <= size && 'N' == src[offset + 0] &&
'a' == src[offset + 1] && 'N' == src[offset + 2]) {
value->type = json_type_number;
value->payload = state->dom;
state->dom += sizeof(struct json_number_s);
json_parse_number(state, (struct json_number_s *)value->payload);
} else if ((json_parse_flags_allow_inf_and_nan & flags_bitset) &&
(offset + 8) <= size && 'I' == src[offset + 0] &&
'n' == src[offset + 1] && 'f' == src[offset + 2] &&
'i' == src[offset + 3] && 'n' == src[offset + 4] &&
'i' == src[offset + 5] && 't' == src[offset + 6] &&
'y' == src[offset + 7]) {
value->type = json_type_number;
value->payload = state->dom;
state->dom += sizeof(struct json_number_s);
json_parse_number(state, (struct json_number_s *)value->payload);
}
break;
}
}
}
struct json_value_s *
json_parse_ex(const void *src, size_t src_size, size_t flags_bitset,
void *(*alloc_func_ptr)(void *user_data, size_t size),
void *user_data, struct json_parse_result_s *result) {
struct json_parse_state_s state;
void *allocation;
struct json_value_s *value;
size_t total_size;
int input_error;
if (result) {
result->error = json_parse_error_none;
result->error_offset = 0;
result->error_line_no = 0;
result->error_row_no = 0;
}
if (json_null == src) {
/* invalid src pointer was null! */
return json_null;
}
state.src = (const char *)src;
state.size = src_size;
state.offset = 0;
state.line_no = 1;
state.line_offset = 0;
state.error = json_parse_error_none;
state.dom_size = 0;
state.data_size = 0;
state.flags_bitset = flags_bitset;
input_error = json_get_value_size(
&state, (int)(json_parse_flags_allow_global_object & state.flags_bitset));
if (0 == input_error) {
json_skip_all_skippables(&state);
if (state.offset != state.size) {
/* our parsing didn't have an error, but there are characters remaining in
* the input that weren't part of the JSON! */
state.error = json_parse_error_unexpected_trailing_characters;
input_error = 1;
}
}
if (input_error) {
/* parsing value's size failed (most likely an invalid JSON DOM!). */
if (result) {
result->error = state.error;
result->error_offset = state.offset;
result->error_line_no = state.line_no;
result->error_row_no = state.offset - state.line_offset;
}
return json_null;
}
/* our total allocation is the combination of the dom and data sizes (we. */
/* first encode the structure of the JSON, and then the data referenced by. */
/* the JSON values). */
total_size = state.dom_size + state.data_size;
if (json_null == alloc_func_ptr) {
allocation = malloc(total_size);
} else {
allocation = alloc_func_ptr(user_data, total_size);
}
if (json_null == allocation) {
/* malloc failed! */
if (result) {
result->error = json_parse_error_allocator_failed;
result->error_offset = 0;
result->error_line_no = 0;
result->error_row_no = 0;
}
return json_null;
}
/* reset offset so we can reuse it. */
state.offset = 0;
/* reset the line information so we can reuse it. */
state.line_no = 1;
state.line_offset = 0;
state.dom = (char *)allocation;
state.data = state.dom + state.dom_size;
if (json_parse_flags_allow_location_information & state.flags_bitset) {
struct json_value_ex_s *value_ex = (struct json_value_ex_s *)state.dom;
state.dom += sizeof(struct json_value_ex_s);
value_ex->offset = state.offset;
value_ex->line_no = state.line_no;
value_ex->row_no = state.offset - state.line_offset;
value = &(value_ex->value);
} else {
value = (struct json_value_s *)state.dom;
state.dom += sizeof(struct json_value_s);
}
json_parse_value(
&state, (int)(json_parse_flags_allow_global_object & state.flags_bitset),
value);
return (struct json_value_s *)allocation;
}
struct json_value_s *json_parse(const void *src, size_t src_size) {
return json_parse_ex(src, src_size, json_parse_flags_default, json_null,
json_null, json_null);
}
struct json_extract_result_s {
size_t dom_size;
size_t data_size;
};
struct json_value_s *json_extract_value(const struct json_value_s *value) {
return json_extract_value_ex(value, json_null, json_null);
}
json_weak struct json_extract_result_s
json_extract_get_number_size(const struct json_number_s *const number);
json_weak struct json_extract_result_s
json_extract_get_string_size(const struct json_string_s *const string);
json_weak struct json_extract_result_s
json_extract_get_object_size(const struct json_object_s *const object);
json_weak struct json_extract_result_s
json_extract_get_array_size(const struct json_array_s *const array);
json_weak struct json_extract_result_s
json_extract_get_value_size(const struct json_value_s *const value);
struct json_extract_result_s
json_extract_get_number_size(const struct json_number_s *const number) {
struct json_extract_result_s result;
result.dom_size = sizeof(struct json_number_s);
result.data_size = number->number_size;
return result;
}
struct json_extract_result_s
json_extract_get_string_size(const struct json_string_s *const string) {
struct json_extract_result_s result;
result.dom_size = sizeof(struct json_string_s);
result.data_size = string->string_size + 1;
return result;
}
struct json_extract_result_s
json_extract_get_object_size(const struct json_object_s *const object) {
struct json_extract_result_s result;
size_t i;
const struct json_object_element_s *element = object->start;
result.dom_size = sizeof(struct json_object_s) +
(sizeof(struct json_object_element_s) * object->length);
result.data_size = 0;
for (i = 0; i < object->length; i++) {
const struct json_extract_result_s string_result =
json_extract_get_string_size(element->name);
const struct json_extract_result_s value_result =
json_extract_get_value_size(element->value);
result.dom_size += string_result.dom_size;
result.data_size += string_result.data_size;
result.dom_size += value_result.dom_size;
result.data_size += value_result.data_size;
element = element->next;
}
return result;
}
struct json_extract_result_s
json_extract_get_array_size(const struct json_array_s *const array) {
struct json_extract_result_s result;
size_t i;
const struct json_array_element_s *element = array->start;
result.dom_size = sizeof(struct json_array_s) +
(sizeof(struct json_array_element_s) * array->length);
result.data_size = 0;
for (i = 0; i < array->length; i++) {
const struct json_extract_result_s value_result =
json_extract_get_value_size(element->value);
result.dom_size += value_result.dom_size;
result.data_size += value_result.data_size;
element = element->next;
}
return result;
}
struct json_extract_result_s
json_extract_get_value_size(const struct json_value_s *const value) {
struct json_extract_result_s result = {0, 0};
switch (value->type) {
default:
break;
case json_type_object:
result = json_extract_get_object_size(
(const struct json_object_s *)value->payload);
break;
case json_type_array:
result = json_extract_get_array_size(
(const struct json_array_s *)value->payload);
break;
case json_type_number:
result = json_extract_get_number_size(
(const struct json_number_s *)value->payload);
break;
case json_type_string:
result = json_extract_get_string_size(
(const struct json_string_s *)value->payload);
break;
}
result.dom_size += sizeof(struct json_value_s);
return result;
}
struct json_extract_state_s {
char *dom;
char *data;
};
json_weak void json_extract_copy_value(struct json_extract_state_s *const state,
const struct json_value_s *const value);
void json_extract_copy_value(struct json_extract_state_s *const state,
const struct json_value_s *const value) {
struct json_string_s *string;
struct json_number_s *number;
struct json_object_s *object;
struct json_array_s *array;
struct json_value_s *new_value;
memcpy(state->dom, value, sizeof(struct json_value_s));
new_value = (struct json_value_s *)state->dom;
state->dom += sizeof(struct json_value_s);
new_value->payload = state->dom;
if (json_type_string == value->type) {
memcpy(state->dom, value->payload, sizeof(struct json_string_s));
string = (struct json_string_s *)state->dom;
state->dom += sizeof(struct json_string_s);
memcpy(state->data, string->string, string->string_size + 1);
string->string = state->data;
state->data += string->string_size + 1;
} else if (json_type_number == value->type) {
memcpy(state->dom, value->payload, sizeof(struct json_number_s));
number = (struct json_number_s *)state->dom;
state->dom += sizeof(struct json_number_s);
memcpy(state->data, number->number, number->number_size);
number->number = state->data;
state->data += number->number_size;
} else if (json_type_object == value->type) {
struct json_object_element_s *element;
size_t i;
memcpy(state->dom, value->payload, sizeof(struct json_object_s));
object = (struct json_object_s *)state->dom;
state->dom += sizeof(struct json_object_s);
element = object->start;
object->start = (struct json_object_element_s *)state->dom;
for (i = 0; i < object->length; i++) {
struct json_value_s *previous_value;
struct json_object_element_s *previous_element;
memcpy(state->dom, element, sizeof(struct json_object_element_s));
element = (struct json_object_element_s *)state->dom;
state->dom += sizeof(struct json_object_element_s);
string = element->name;
memcpy(state->dom, string, sizeof(struct json_string_s));
string = (struct json_string_s *)state->dom;
state->dom += sizeof(struct json_string_s);
element->name = string;
memcpy(state->data, string->string, string->string_size + 1);
string->string = state->data;
state->data += string->string_size + 1;
previous_value = element->value;
element->value = (struct json_value_s *)state->dom;
json_extract_copy_value(state, previous_value);
previous_element = element;
element = element->next;
if (element) {
previous_element->next = (struct json_object_element_s *)state->dom;
}
}
} else if (json_type_array == value->type) {
struct json_array_element_s *element;
size_t i;
memcpy(state->dom, value->payload, sizeof(struct json_array_s));
array = (struct json_array_s *)state->dom;
state->dom += sizeof(struct json_array_s);
element = array->start;
array->start = (struct json_array_element_s *)state->dom;
for (i = 0; i < array->length; i++) {
struct json_value_s *previous_value;
struct json_array_element_s *previous_element;
memcpy(state->dom, element, sizeof(struct json_array_element_s));
element = (struct json_array_element_s *)state->dom;
state->dom += sizeof(struct json_array_element_s);
previous_value = element->value;
element->value = (struct json_value_s *)state->dom;
json_extract_copy_value(state, previous_value);
previous_element = element;
element = element->next;
if (element) {
previous_element->next = (struct json_array_element_s *)state->dom;
}
}
}
}
struct json_value_s *json_extract_value_ex(const struct json_value_s *value,
void *(*alloc_func_ptr)(void *,
size_t),
void *user_data) {
void *allocation;
struct json_extract_result_s result;
struct json_extract_state_s state;
size_t total_size;
if (json_null == value) {
/* invalid value was null! */
return json_null;
}
result = json_extract_get_value_size(value);
total_size = result.dom_size + result.data_size;
if (json_null == alloc_func_ptr) {
allocation = malloc(total_size);
} else {
allocation = alloc_func_ptr(user_data, total_size);
}
state.dom = (char *)allocation;
state.data = state.dom + result.dom_size;
json_extract_copy_value(&state, value);
return (struct json_value_s *)allocation;
}
struct json_string_s *json_value_as_string(struct json_value_s *const value) {
if (value->type != json_type_string) {
return json_null;
}
return (struct json_string_s *)value->payload;
}
struct json_number_s *json_value_as_number(struct json_value_s *const value) {
if (value->type != json_type_number) {
return json_null;
}
return (struct json_number_s *)value->payload;
}
struct json_object_s *json_value_as_object(struct json_value_s *const value) {
if (value->type != json_type_object) {
return json_null;
}
return (struct json_object_s *)value->payload;
}
struct json_array_s *json_value_as_array(struct json_value_s *const value) {
if (value->type != json_type_array) {
return json_null;
}
return (struct json_array_s *)value->payload;
}
int json_value_is_true(const struct json_value_s *const value) {
return value->type == json_type_true;
}
int json_value_is_false(const struct json_value_s *const value) {
return value->type == json_type_false;
}
int json_value_is_null(const struct json_value_s *const value) {
return value->type == json_type_null;
}
json_weak int
json_write_minified_get_value_size(const struct json_value_s *value,
size_t *size);
json_weak int json_write_get_number_size(const struct json_number_s *number,
size_t *size);
int json_write_get_number_size(const struct json_number_s *number,
size_t *size) {
json_uintmax_t parsed_number;
size_t i;
if (number->number_size >= 2) {
switch (number->number[1]) {
default:
break;
case 'x':
case 'X':
/* the number is a json_parse_flags_allow_hexadecimal_numbers hexadecimal
* so we have to do extra work to convert it to a non-hexadecimal for JSON
* output. */
parsed_number = json_strtoumax(number->number, json_null, 0);
i = 0;
while (0 != parsed_number) {
parsed_number /= 10;
i++;
}
*size += i;
return 0;
}
}
/* check to see if the number has leading/trailing decimal point. */
i = 0;
/* skip any leading '+' or '-'. */
if ((i < number->number_size) &&
(('+' == number->number[i]) || ('-' == number->number[i]))) {
i++;
}
/* check if we have infinity. */
if ((i < number->number_size) && ('I' == number->number[i])) {
const char *inf = "Infinity";
size_t k;
for (k = i; k < number->number_size; k++) {
const char c = *inf++;
/* Check if we found the Infinity string! */
if ('\0' == c) {
break;
} else if (c != number->number[k]) {
break;
}
}
if ('\0' == *inf) {
/* Inf becomes 1.7976931348623158e308 because JSON can't support it. */
*size += 22;
/* if we had a leading '-' we need to record it in the JSON output. */
if ('-' == number->number[0]) {
*size += 1;
}
}
return 0;
}
/* check if we have nan. */
if ((i < number->number_size) && ('N' == number->number[i])) {
const char *nan = "NaN";
size_t k;
for (k = i; k < number->number_size; k++) {
const char c = *nan++;
/* Check if we found the NaN string! */
if ('\0' == c) {
break;
} else if (c != number->number[k]) {
break;
}
}
if ('\0' == *nan) {
/* NaN becomes 1 because JSON can't support it. */
*size += 1;
return 0;
}
}
/* if we had a leading decimal point. */
if ((i < number->number_size) && ('.' == number->number[i])) {
/* 1 + because we had a leading decimal point. */
*size += 1;
goto cleanup;
}
for (; i < number->number_size; i++) {
const char c = number->number[i];
if (!('0' <= c && c <= '9')) {
break;
}
}
/* if we had a trailing decimal point. */
if ((i + 1 == number->number_size) && ('.' == number->number[i])) {
/* 1 + because we had a trailing decimal point. */
*size += 1;
goto cleanup;
}
cleanup:
*size += number->number_size; /* the actual string of the number. */
/* if we had a leading '+' we don't record it in the JSON output. */
if ('+' == number->number[0]) {
*size -= 1;
}
return 0;
}
json_weak int json_write_get_string_size(const struct json_string_s *string,
size_t *size);
int json_write_get_string_size(const struct json_string_s *string,
size_t *size) {
size_t i;
for (i = 0; i < string->string_size; i++) {
switch (string->string[i]) {
case '"':
case '\\':
case '\b':
case '\f':
case '\n':
case '\r':
case '\t':
*size += 2;
break;
default:
*size += 1;
break;
}
}
*size += 2; /* need to encode the surrounding '"' characters. */
return 0;
}
json_weak int
json_write_minified_get_array_size(const struct json_array_s *array,
size_t *size);
int json_write_minified_get_array_size(const struct json_array_s *array,
size_t *size) {
struct json_array_element_s *element;
*size += 2; /* '[' and ']'. */
if (1 < array->length) {
*size += array->length - 1; /* ','s seperate each element. */
}
for (element = array->start; json_null != element; element = element->next) {
if (json_write_minified_get_value_size(element->value, size)) {
/* value was malformed! */
return 1;
}
}
return 0;
}
json_weak int
json_write_minified_get_object_size(const struct json_object_s *object,
size_t *size);
int json_write_minified_get_object_size(const struct json_object_s *object,
size_t *size) {
struct json_object_element_s *element;
*size += 2; /* '{' and '}'. */
*size += object->length; /* ':'s seperate each name/value pair. */
if (1 < object->length) {
*size += object->length - 1; /* ','s seperate each element. */
}
for (element = object->start; json_null != element; element = element->next) {
if (json_write_get_string_size(element->name, size)) {
/* string was malformed! */
return 1;
}
if (json_write_minified_get_value_size(element->value, size)) {
/* value was malformed! */
return 1;
}
}
return 0;
}
json_weak int
json_write_minified_get_value_size(const struct json_value_s *value,
size_t *size);
int json_write_minified_get_value_size(const struct json_value_s *value,
size_t *size) {
switch (value->type) {
default:
/* unknown value type found! */
return 1;
case json_type_number:
return json_write_get_number_size((struct json_number_s *)value->payload,
size);
case json_type_string:
return json_write_get_string_size((struct json_string_s *)value->payload,
size);
case json_type_array:
return json_write_minified_get_array_size(
(struct json_array_s *)value->payload, size);
case json_type_object:
return json_write_minified_get_object_size(
(struct json_object_s *)value->payload, size);
case json_type_true:
*size += 4; /* the string "true". */
return 0;
case json_type_false:
*size += 5; /* the string "false". */
return 0;
case json_type_null:
*size += 4; /* the string "null". */
return 0;
}
}
json_weak char *json_write_minified_value(const struct json_value_s *value,
char *data);
json_weak char *json_write_number(const struct json_number_s *number,
char *data);
char *json_write_number(const struct json_number_s *number, char *data) {
json_uintmax_t parsed_number, backup;
size_t i;
if (number->number_size >= 2) {
switch (number->number[1]) {
default:
break;
case 'x':
case 'X':
/* The number is a json_parse_flags_allow_hexadecimal_numbers hexadecimal
* so we have to do extra work to convert it to a non-hexadecimal for JSON
* output. */
parsed_number = json_strtoumax(number->number, json_null, 0);
/* We need a copy of parsed number twice, so take a backup of it. */
backup = parsed_number;
i = 0;
while (0 != parsed_number) {
parsed_number /= 10;
i++;
}
/* Restore parsed_number to its original value stored in the backup. */
parsed_number = backup;
/* Now use backup to take a copy of i, or the length of the string. */
backup = i;
do {
*(data + i - 1) = '0' + (char)(parsed_number % 10);
parsed_number /= 10;
i--;
} while (0 != parsed_number);
data += backup;
return data;
}
}
/* check to see if the number has leading/trailing decimal point. */
i = 0;
/* skip any leading '-'. */
if ((i < number->number_size) &&
(('+' == number->number[i]) || ('-' == number->number[i]))) {
i++;
}
/* check if we have infinity. */
if ((i < number->number_size) && ('I' == number->number[i])) {
const char *inf = "Infinity";
size_t k;
for (k = i; k < number->number_size; k++) {
const char c = *inf++;
/* Check if we found the Infinity string! */
if ('\0' == c) {
break;
} else if (c != number->number[k]) {
break;
}
}
if ('\0' == *inf++) {
const char *dbl_max;
/* if we had a leading '-' we need to record it in the JSON output. */
if ('-' == number->number[0]) {
*data++ = '-';
}
/* Inf becomes 1.7976931348623158e308 because JSON can't support it. */
for (dbl_max = "1.7976931348623158e308"; '\0' != *dbl_max; dbl_max++) {
*data++ = *dbl_max;
}
return data;
}
}
/* check if we have nan. */
if ((i < number->number_size) && ('N' == number->number[i])) {
const char *nan = "NaN";
size_t k;
for (k = i; k < number->number_size; k++) {
const char c = *nan++;
/* Check if we found the NaN string! */
if ('\0' == c) {
break;
} else if (c != number->number[k]) {
break;
}
}
if ('\0' == *nan++) {
/* NaN becomes 0 because JSON can't support it. */
*data++ = '0';
return data;
}
}
/* if we had a leading decimal point. */
if ((i < number->number_size) && ('.' == number->number[i])) {
i = 0;
/* skip any leading '+'. */
if ('+' == number->number[i]) {
i++;
}
/* output the leading '-' if we had one. */
if ('-' == number->number[i]) {
*data++ = '-';
i++;
}
/* insert a '0' to fix the leading decimal point for JSON output. */
*data++ = '0';
/* and output the rest of the number as normal. */
for (; i < number->number_size; i++) {
*data++ = number->number[i];
}
return data;
}
for (; i < number->number_size; i++) {
const char c = number->number[i];
if (!('0' <= c && c <= '9')) {
break;
}
}
/* if we had a trailing decimal point. */
if ((i + 1 == number->number_size) && ('.' == number->number[i])) {
i = 0;
/* skip any leading '+'. */
if ('+' == number->number[i]) {
i++;
}
/* output the leading '-' if we had one. */
if ('-' == number->number[i]) {
*data++ = '-';
i++;
}
/* and output the rest of the number as normal. */
for (; i < number->number_size; i++) {
*data++ = number->number[i];
}
/* insert a '0' to fix the trailing decimal point for JSON output. */
*data++ = '0';
return data;
}
i = 0;
/* skip any leading '+'. */
if ('+' == number->number[i]) {
i++;
}
for (; i < number->number_size; i++) {
*data++ = number->number[i];
}
return data;
}
json_weak char *json_write_string(const struct json_string_s *string,
char *data);
char *json_write_string(const struct json_string_s *string, char *data) {
size_t i;
*data++ = '"'; /* open the string. */
for (i = 0; i < string->string_size; i++) {
switch (string->string[i]) {
case '"':
*data++ = '\\'; /* escape the control character. */
*data++ = '"';
break;
case '\\':
*data++ = '\\'; /* escape the control character. */
*data++ = '\\';
break;
case '\b':
*data++ = '\\'; /* escape the control character. */
*data++ = 'b';
break;
case '\f':
*data++ = '\\'; /* escape the control character. */
*data++ = 'f';
break;
case '\n':
*data++ = '\\'; /* escape the control character. */
*data++ = 'n';
break;
case '\r':
*data++ = '\\'; /* escape the control character. */
*data++ = 'r';
break;
case '\t':
*data++ = '\\'; /* escape the control character. */
*data++ = 't';
break;
default:
*data++ = string->string[i];
break;
}
}
*data++ = '"'; /* close the string. */
return data;
}
json_weak char *json_write_minified_array(const struct json_array_s *array,
char *data);
char *json_write_minified_array(const struct json_array_s *array, char *data) {
struct json_array_element_s *element = json_null;
*data++ = '['; /* open the array. */
for (element = array->start; json_null != element; element = element->next) {
if (element != array->start) {
*data++ = ','; /* ','s seperate each element. */
}
data = json_write_minified_value(element->value, data);
if (json_null == data) {
/* value was malformed! */
return json_null;
}
}
*data++ = ']'; /* close the array. */
return data;
}
json_weak char *json_write_minified_object(const struct json_object_s *object,
char *data);
char *json_write_minified_object(const struct json_object_s *object,
char *data) {
struct json_object_element_s *element = json_null;
*data++ = '{'; /* open the object. */
for (element = object->start; json_null != element; element = element->next) {
if (element != object->start) {
*data++ = ','; /* ','s seperate each element. */
}
data = json_write_string(element->name, data);
if (json_null == data) {
/* string was malformed! */
return json_null;
}
*data++ = ':'; /* ':'s seperate each name/value pair. */
data = json_write_minified_value(element->value, data);
if (json_null == data) {
/* value was malformed! */
return json_null;
}
}
*data++ = '}'; /* close the object. */
return data;
}
json_weak char *json_write_minified_value(const struct json_value_s *value,
char *data);
char *json_write_minified_value(const struct json_value_s *value, char *data) {
switch (value->type) {
default:
/* unknown value type found! */
return json_null;
case json_type_number:
return json_write_number((struct json_number_s *)value->payload, data);
case json_type_string:
return json_write_string((struct json_string_s *)value->payload, data);
case json_type_array:
return json_write_minified_array((struct json_array_s *)value->payload,
data);
case json_type_object:
return json_write_minified_object((struct json_object_s *)value->payload,
data);
case json_type_true:
data[0] = 't';
data[1] = 'r';
data[2] = 'u';
data[3] = 'e';
return data + 4;
case json_type_false:
data[0] = 'f';
data[1] = 'a';
data[2] = 'l';
data[3] = 's';
data[4] = 'e';
return data + 5;
case json_type_null:
data[0] = 'n';
data[1] = 'u';
data[2] = 'l';
data[3] = 'l';
return data + 4;
}
}
void *json_write_minified(const struct json_value_s *value, size_t *out_size) {
size_t size = 0;
char *data = json_null;
char *data_end = json_null;
if (json_null == value) {
return json_null;
}
if (json_write_minified_get_value_size(value, &size)) {
/* value was malformed! */
return json_null;
}
size += 1; /* for the '\0' null terminating character. */
data = (char *)malloc(size);
if (json_null == data) {
/* malloc failed! */
return json_null;
}
data_end = json_write_minified_value(value, data);
if (json_null == data_end) {
/* bad chi occurred! */
free(data);
return json_null;
}
/* null terminated the string. */
*data_end = '\0';
if (json_null != out_size) {
*out_size = size;
}
return data;
}
json_weak int json_write_pretty_get_value_size(const struct json_value_s *value,
size_t depth, size_t indent_size,
size_t newline_size,
size_t *size);
json_weak int json_write_pretty_get_array_size(const struct json_array_s *array,
size_t depth, size_t indent_size,
size_t newline_size,
size_t *size);
int json_write_pretty_get_array_size(const struct json_array_s *array,
size_t depth, size_t indent_size,
size_t newline_size, size_t *size) {
struct json_array_element_s *element;
*size += 1; /* '['. */
if (0 < array->length) {
/* if we have any elements we need to add a newline after our '['. */
*size += newline_size;
*size += array->length - 1; /* ','s seperate each element. */
for (element = array->start; json_null != element;
element = element->next) {
/* each element gets an indent. */
*size += (depth + 1) * indent_size;
if (json_write_pretty_get_value_size(element->value, depth + 1,
indent_size, newline_size, size)) {
/* value was malformed! */
return 1;
}
/* each element gets a newline too. */
*size += newline_size;
}
/* since we wrote out some elements, need to add a newline and indentation.
*/
/* to the trailing ']'. */
*size += depth * indent_size;
}
*size += 1; /* ']'. */
return 0;
}
json_weak int
json_write_pretty_get_object_size(const struct json_object_s *object,
size_t depth, size_t indent_size,
size_t newline_size, size_t *size);
int json_write_pretty_get_object_size(const struct json_object_s *object,
size_t depth, size_t indent_size,
size_t newline_size, size_t *size) {
struct json_object_element_s *element;
*size += 1; /* '{'. */
if (0 < object->length) {
*size += newline_size; /* need a newline next. */
*size += object->length - 1; /* ','s seperate each element. */
for (element = object->start; json_null != element;
element = element->next) {
/* each element gets an indent and newline. */
*size += (depth + 1) * indent_size;
*size += newline_size;
if (json_write_get_string_size(element->name, size)) {
/* string was malformed! */
return 1;
}
*size += 3; /* seperate each name/value pair with " : ". */
if (json_write_pretty_get_value_size(element->value, depth + 1,
indent_size, newline_size, size)) {
/* value was malformed! */
return 1;
}
}
*size += depth * indent_size;
}
*size += 1; /* '}'. */
return 0;
}
json_weak int json_write_pretty_get_value_size(const struct json_value_s *value,
size_t depth, size_t indent_size,
size_t newline_size,
size_t *size);
int json_write_pretty_get_value_size(const struct json_value_s *value,
size_t depth, size_t indent_size,
size_t newline_size, size_t *size) {
switch (value->type) {
default:
/* unknown value type found! */
return 1;
case json_type_number:
return json_write_get_number_size((struct json_number_s *)value->payload,
size);
case json_type_string:
return json_write_get_string_size((struct json_string_s *)value->payload,
size);
case json_type_array:
return json_write_pretty_get_array_size(
(struct json_array_s *)value->payload, depth, indent_size, newline_size,
size);
case json_type_object:
return json_write_pretty_get_object_size(
(struct json_object_s *)value->payload, depth, indent_size,
newline_size, size);
case json_type_true:
*size += 4; /* the string "true". */
return 0;
case json_type_false:
*size += 5; /* the string "false". */
return 0;
case json_type_null:
*size += 4; /* the string "null". */
return 0;
}
}
json_weak char *json_write_pretty_value(const struct json_value_s *value,
size_t depth, const char *indent,
const char *newline, char *data);
json_weak char *json_write_pretty_array(const struct json_array_s *array,
size_t depth, const char *indent,
const char *newline, char *data);
char *json_write_pretty_array(const struct json_array_s *array, size_t depth,
const char *indent, const char *newline,
char *data) {
size_t k, m;
struct json_array_element_s *element;
*data++ = '['; /* open the array. */
if (0 < array->length) {
for (k = 0; '\0' != newline[k]; k++) {
*data++ = newline[k];
}
for (element = array->start; json_null != element;
element = element->next) {
if (element != array->start) {
*data++ = ','; /* ','s seperate each element. */
for (k = 0; '\0' != newline[k]; k++) {
*data++ = newline[k];
}
}
for (k = 0; k < depth + 1; k++) {
for (m = 0; '\0' != indent[m]; m++) {
*data++ = indent[m];
}
}
data = json_write_pretty_value(element->value, depth + 1, indent, newline,
data);
if (json_null == data) {
/* value was malformed! */
return json_null;
}
}
for (k = 0; '\0' != newline[k]; k++) {
*data++ = newline[k];
}
for (k = 0; k < depth; k++) {
for (m = 0; '\0' != indent[m]; m++) {
*data++ = indent[m];
}
}
}
*data++ = ']'; /* close the array. */
return data;
}
json_weak char *json_write_pretty_object(const struct json_object_s *object,
size_t depth, const char *indent,
const char *newline, char *data);
char *json_write_pretty_object(const struct json_object_s *object, size_t depth,
const char *indent, const char *newline,
char *data) {
size_t k, m;
struct json_object_element_s *element;
*data++ = '{'; /* open the object. */
if (0 < object->length) {
for (k = 0; '\0' != newline[k]; k++) {
*data++ = newline[k];
}
for (element = object->start; json_null != element;
element = element->next) {
if (element != object->start) {
*data++ = ','; /* ','s seperate each element. */
for (k = 0; '\0' != newline[k]; k++) {
*data++ = newline[k];
}
}
for (k = 0; k < depth + 1; k++) {
for (m = 0; '\0' != indent[m]; m++) {
*data++ = indent[m];
}
}
data = json_write_string(element->name, data);
if (json_null == data) {
/* string was malformed! */
return json_null;
}
/* " : "s seperate each name/value pair. */
*data++ = ' ';
*data++ = ':';
*data++ = ' ';
data = json_write_pretty_value(element->value, depth + 1, indent, newline,
data);
if (json_null == data) {
/* value was malformed! */
return json_null;
}
}
for (k = 0; '\0' != newline[k]; k++) {
*data++ = newline[k];
}
for (k = 0; k < depth; k++) {
for (m = 0; '\0' != indent[m]; m++) {
*data++ = indent[m];
}
}
}
*data++ = '}'; /* close the object. */
return data;
}
json_weak char *json_write_pretty_value(const struct json_value_s *value,
size_t depth, const char *indent,
const char *newline, char *data);
char *json_write_pretty_value(const struct json_value_s *value, size_t depth,
const char *indent, const char *newline,
char *data) {
switch (value->type) {
default:
/* unknown value type found! */
return json_null;
case json_type_number:
return json_write_number((struct json_number_s *)value->payload, data);
case json_type_string:
return json_write_string((struct json_string_s *)value->payload, data);
case json_type_array:
return json_write_pretty_array((struct json_array_s *)value->payload, depth,
indent, newline, data);
case json_type_object:
return json_write_pretty_object((struct json_object_s *)value->payload,
depth, indent, newline, data);
case json_type_true:
data[0] = 't';
data[1] = 'r';
data[2] = 'u';
data[3] = 'e';
return data + 4;
case json_type_false:
data[0] = 'f';
data[1] = 'a';
data[2] = 'l';
data[3] = 's';
data[4] = 'e';
return data + 5;
case json_type_null:
data[0] = 'n';
data[1] = 'u';
data[2] = 'l';
data[3] = 'l';
return data + 4;
}
}
void *json_write_pretty(const struct json_value_s *value, const char *indent,
const char *newline, size_t *out_size) {
size_t size = 0;
size_t indent_size = 0;
size_t newline_size = 0;
char *data = json_null;
char *data_end = json_null;
if (json_null == value) {
return json_null;
}
if (json_null == indent) {
indent = " "; /* default to two spaces. */
}
if (json_null == newline) {
newline = "\n"; /* default to linux newlines. */
}
while ('\0' != indent[indent_size]) {
++indent_size; /* skip non-null terminating characters. */
}
while ('\0' != newline[newline_size]) {
++newline_size; /* skip non-null terminating characters. */
}
if (json_write_pretty_get_value_size(value, 0, indent_size, newline_size,
&size)) {
/* value was malformed! */
return json_null;
}
size += 1; /* for the '\0' null terminating character. */
data = (char *)malloc(size);
if (json_null == data) {
/* malloc failed! */
return json_null;
}
data_end = json_write_pretty_value(value, 0, indent, newline, data);
if (json_null == data_end) {
/* bad chi occurred! */
free(data);
return json_null;
}
/* null terminated the string. */
*data_end = '\0';
if (json_null != out_size) {
*out_size = size;
}
return data;
}
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#endif
#endif /* SHEREDOM_JSON_H_INCLUDED. */
================================================
FILE: patch/macro.h
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
//#define PATCH_INTERNAL
#define PATCH_VERSION_NAME "patch.aul " PATCH_VERSION_STR
#ifdef PATCH_INTERNAL
#define PATCH_VERSION_STR "internal build:" __DATE__ " " __TIME__ ""
#define PATCH_SWITCH_EXCEPTION_LOG
#define PATCH_SWITCH_SYSINFO_MODIFY
#define PATCH_SWITCH_TRANSRATE
#define PATCH_SWITCH_SETTING_GUI
#define PATCH_SWITCH_ACCESS_KEY access_key
#define PATCH_SWITCH_FILEINFO file_info
#define PATCH_SWITCH_SUSIE_LOAD susie_load
#define PATCH_SWITCH_SPLASH splash
#define PATCH_SWITCH_TRA_AVIUTL_FILTER tra_aviutl_filter
#define PATCH_SWITCH_EXO_AVIUTL_FILTER exo_aviutl_filter
#define PATCH_SWITCH_EXO_TRACK_MINUSVAL exo_track_minusval
#define PATCH_SWITCH_EXO_SCENEIDX exo_sceneidx
#define PATCH_SWITCH_EXO_TRACKPARAM exo_trackparam
#define PATCH_SWITCH_EXO_SPECIALCOLORCONV exo_specialcolorconv
#define PATCH_SWITCH_TEXT_OP_SIZE text_op_size
#define PATCH_SWITCH_IGNORE_MEDIA_PARAM_RESET ignore_media_param_reset
#define PATCH_SWITCH_FONT_DIALOG font_dialog
#define PATCH_SWITCH_SCROLL_OBJDLG scroll_objdlg
#define PATCH_SWITCH_ALPHA_BG alpha_bg
#define PATCH_SWITCH_HELPFUL_MSGBOX helpful_msgbox
#define PATCH_SWITCH_THEME_CC theme_cc
#define PATCH_SWITCH_EXEDITWINDOW_SIZING exeditwindow_sizing
#define PATCH_SWITCH_SETTINGDIALOG_MOVE settingdialog_move
#define PATCH_SWITCH_SETTINGDIALOG_EXCOLORCONFIG settingdialog_excolorconfig
#define PATCH_SWITCH_UNDO undo
#ifdef PATCH_SWITCH_UNDO
#define PATCH_SWITCH_UNDO_REDO undo_redo
#endif
#define PATCH_SWITCH_CONSOLE console
#ifdef PATCH_SWITCH_CONSOLE
#define PATCH_SWITCH_DEBUGSTRING console_debug_string
#endif // ifdef PATCH_SWITCH_CONSOLE
#define PATCH_SWITCH_LUA lua
#ifdef PATCH_SWITCH_LUA
#define PATCH_SWITCH_LUA_ENV lua_env
#define PATCH_SWITCH_LUA_GETVALUE lua_getvalueex
#define PATCH_SWITCH_LUA_RAND lua_rand
#define PATCH_SWITCH_LUA_RANDEX lua_randex
#define PATCH_SWITCH_LUA_PATH lua_path
//#define PATCH_SWITCH_LUA_COPYBUFFER_SMEM lua_copybuffer_smem
#endif // ifdef PATCH_SWITCH_LUA
#define PATCH_SWITCH_FAST fast
#ifdef PATCH_SWITCH_FAST
#define PATCH_SWITCH_FAST_GETPUTPIXELDATA fast_getputpixeldata
#define PATCH_SWITCH_FAST_SETTINGDIALOG fast_settingdialog
#define PATCH_SWITCH_FAST_EXEDITWINDOW fast_exeditwindow
#define PATCH_SWITCH_CL cl
#ifdef PATCH_SWITCH_CL
#define PATCH_SWITCH_FAST_POLORTRANSFORM fast_polortransform
#define PATCH_SWITCH_FAST_RADIATIONALBLUR fast_radiationalblur
#define PATCH_SWITCH_FAST_FLASH fast_flash
#endif // define PATCH_SWITCH_CL
#endif //define PATCH_SWITCH_FAST
#else // ifdef PATCH_INTERNAL
#define PATCH_VERSION_STR "r43 beta1"
#define PATCH_SWITCH_EXCEPTION_LOG
#define PATCH_SWITCH_SYSINFO_MODIFY
#define PATCH_SWITCH_ACCESS_KEY access_key
#define PATCH_SWITCH_COLORPALETTE_CACHE colorpalette_cache
#define PATCH_SWITCH_TRA_AVIUTL_FILTER tra_aviutl_filter
#define PATCH_SWITCH_TRA_CHANGE_DRAWFILTER tra_change_drawfilter
#define PATCH_SWITCH_TRA_SPECIFIED_SPEED tra_specified_speed
#define PATCH_SWITCH_AUP_SCENE_SETTING aup_scene_setting
#define PATCH_SWITCH_AUP_LAYER_SETTING aup_layer_setting
#define PATCH_SWITCH_EXO_AVIUTL_FILTER exo_aviutl_filter
#define PATCH_SWITCH_EXO_TRACK_MINUSVAL exo_track_minusval
#define PATCH_SWITCH_EXO_SCENEIDX exo_sceneidx
#define PATCH_SWITCH_EXO_TRACKPARAM exo_trackparam
#define PATCH_SWITCH_EXO_MIDPT_AND_TRA exo_midpt_tra
#define PATCH_SWITCH_EXO_SPECIALCOLORCONV exo_specialcolorconv
#define PATCH_SWITCH_EXO_FOLD_GUI exo_fold_gui
#define PATCH_SWITCH_TEXT_OP_SIZE text_op_size
#define PATCH_SWITCH_IGNORE_MEDIA_PARAM_RESET ignore_media_param_reset
#define PATCH_SWITCH_THEME_CC theme_cc
#define PATCH_SWITCH_EXEDITWINDOW_SIZING exeditwindow_sizing
#define PATCH_SWITCH_SETTINGDIALOG_MOVE settingdialog_move
#define PATCH_SWITCH_SETTINGDIALOG_EXCOLORCONFIG settingdialog_excolorconfig
#define PATCH_SWITCH_CANCEL_BOOST_CONFLICT
#define PATCH_SWITCH_WARNING_OLD_LSW
#define PATCH_SWITCH_FAILED_SJIS_MSGBOX failed_sjis
#define PATCH_SWITCH_FAILED_LONGER_PATH failed_longpath
#define PATCH_SWITCH_FAILED_FILE_DROP failed_filedrop
#define PATCH_SWITCH_OBJ_COLORCORRECTION obj_colorcorrection
#define PATCH_SWITCH_OBJ_GLOW obj_glow
#define PATCH_SWITCH_OBJ_LENSBLUR obj_lensblur
#define PATCH_SWITCH_OBJ_NOISE obj_noise
#define PATCH_SWITCH_OBJ_SPECIALCOLORCONV obj_specialcolorconv
#define PATCH_SWITCH_RCLICKMENU_SPLIT rclickmenu_split
#define PATCH_SWITCH_RCLICKMENU_DELETE rclickmenu_delete
#define PATCH_SWITCH_BLEND blend
#define PATCH_SWITCH_ADD_EXTENSION add_extension
#define PATCH_SWITCH_DIALOG_NEW_FILE dlg_newfile
#define PATCH_SWITCH_PLAYBACK_SPEED pb_speed
#define PATCH_SWITCH_SETTING_NEW_PROJECT setting_newproject
#define PATCH_SWITCH_UNDO undo
#ifdef PATCH_SWITCH_UNDO
#define PATCH_SWITCH_UNDO_REDO undo_redo
#ifdef PATCH_SWITCH_UNDO_REDO
#define PATCH_SWITCH_UNDO_REDO_SHIFT undo_redo_shift
#endif
#endif
#define PATCH_SWITCH_CONSOLE console
#ifdef PATCH_SWITCH_CONSOLE
#define PATCH_SWITCH_DEBUGSTRING console_debug_string
#endif // ifdef PATCH_SWITCH_CONSOLE
#define PATCH_SWITCH_LUA lua
#ifdef PATCH_SWITCH_LUA
#define PATCH_SWITCH_LUA_ENV lua_env
#define PATCH_SWITCH_LUA_GETVALUE lua_getvalue
#define PATCH_SWITCH_LUA_RAND lua_rand
#define PATCH_SWITCH_LUA_RANDEX lua_randex
#define PATCH_SWITCH_LUA_PATH lua_path
//#define PATCH_SWITCH_LUA_COPYBUFFER_SMEM lua_copybuffer_smem
#endif // ifdef PATCH_SWITCH_LUA
#define PATCH_SWITCH_FAST fast
#ifdef PATCH_SWITCH_FAST
#define PATCH_SWITCH_FAST_SETTINGDIALOG fast_settingdialog
#define PATCH_SWITCH_FAST_EXEDITWINDOW fast_exeditwindow
#define PATCH_SWITCH_FAST_TEXT fast_text
#define PATCH_SWITCH_FAST_CREATE_FIGURE fast_create_figure
#define PATCH_SWITCH_FAST_BORDER fast_border
#define PATCH_SWITCH_FAST_GLOW fast_glow
#define PATCH_SWITCH_CL cl
#ifdef PATCH_SWITCH_CL
#define PATCH_SWITCH_FAST_POLORTRANSFORM fast_polortransform
#define PATCH_SWITCH_FAST_DISPLACEMENTMAP fast_displacementmap
#define PATCH_SWITCH_FAST_RADIATIONALBLUR fast_radiationalblur
#define PATCH_SWITCH_FAST_FLASH fast_flash
#define PATCH_SWITCH_FAST_DIRECTIONALBLUR fast_directionalblur
#define PATCH_SWITCH_FAST_LENSBLUR fast_lensblur
#endif // define PATCH_SWITCH_CL
#endif //define PATCH_SWITCH_FAST
#endif // ifdef PATCH_INTERNAL
#define PATCH_SWITCHER_DEFINE_STRING(s) #s
#define PATCH_SWITCHER_DEFINE_STRINGX(s) PATCH_SWITCHER_DEFINE_STRING(s)
#define PATCH_SWITCHER_DEFINE_VALUE(s) s
#define PATCH_SWITCHER_KEY_JOINNER(a, b) a ## b
#define PATCH_SWITCHER_KEY_JOINNERX(a, b) PATCH_SWITCHER_KEY_JOINNER(a, b)
#define PATCH_SWITCHER_DEFINE(name, def) bool name = def; inline static constexpr const char PATCH_SWITCHER_KEY_JOINNER(key_, name)[] = PATCH_SWITCHER_DEFINE_STRING(name);
#define PATCH_SWITCHER_DEFINE_EX(name, def, key) bool name = def; inline static constexpr const char PATCH_SWITCHER_KEY_JOINNER(key_, name)[] = PATCH_SWITCHER_DEFINE_STRING(key);
#define PATCH_SWITCHER_IF(name) if (load_variable(elm, PATCH_SWITCHER_KEY_JOINNER(key_, name), name)) continue;
#define PATCH_SWITCHER_STORE(name) tj(PATCH_SWITCHER_KEY_JOINNER(key_, name), name);
#define PATCH_SWITCHER_MEMBER(name) GLOBAL::config.switcher.name
================================================
FILE: patch/moduledata.hpp
================================================
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include
#include
#include
#include