From ffdd413e674679d90156830752de7e1b83778a30 Mon Sep 17 00:00:00 2001
From: c6 <31777460+c6-dev@users.noreply.github.com>
Date: Mon, 10 Jun 2024 16:34:13 +0400
Subject: [PATCH] Add project files.
---
.gitattributes | 63 ++
.gitignore | 363 +++++++++++
HighFPSFix.sln | 24 +
HighFPSFix.vcxproj | 146 +++++
HighFPSFix.vcxproj.filters | 22 +
LICENSE.txt | 201 +++++++
README.md | 1 +
calls.h | 58 ++
common/IDataStream.cpp | 467 +++++++++++++++
common/IDataStream.h | 102 ++++
common/IDebugLog.cpp | 301 ++++++++++
common/IDebugLog.h | 132 ++++
common/IDynamicCreate.cpp | 38 ++
common/IDynamicCreate.h | 118 ++++
common/IErrors.cpp | 59 ++
common/IErrors.h | 33 +
common/IPrefix.cpp | 1 +
common/IPrefix.h | 21 +
common/ISingleton.cpp | 3 +
common/ISingleton.h | 53 ++
common/ITypes.cpp | 65 ++
common/ITypes.h | 357 +++++++++++
common/PluginAPI.h | 48 ++
common/SafeWrite.cpp | 99 +++
common/SafeWrite.h | 41 ++
common/Utilities.cpp | 1162 ++++++++++++++++++++++++++++++++++++
common/Utilities.h | 351 +++++++++++
common/utility.cpp | 637 ++++++++++++++++++++
common/utility.h | 201 +++++++
dllmain.c | 10 +
fps.h | 124 ++++
main.cpp | 20 +
32 files changed, 5321 insertions(+)
create mode 100644 .gitattributes
create mode 100644 .gitignore
create mode 100644 HighFPSFix.sln
create mode 100644 HighFPSFix.vcxproj
create mode 100644 HighFPSFix.vcxproj.filters
create mode 100644 LICENSE.txt
create mode 100644 README.md
create mode 100644 calls.h
create mode 100644 common/IDataStream.cpp
create mode 100644 common/IDataStream.h
create mode 100644 common/IDebugLog.cpp
create mode 100644 common/IDebugLog.h
create mode 100644 common/IDynamicCreate.cpp
create mode 100644 common/IDynamicCreate.h
create mode 100644 common/IErrors.cpp
create mode 100644 common/IErrors.h
create mode 100644 common/IPrefix.cpp
create mode 100644 common/IPrefix.h
create mode 100644 common/ISingleton.cpp
create mode 100644 common/ISingleton.h
create mode 100644 common/ITypes.cpp
create mode 100644 common/ITypes.h
create mode 100644 common/PluginAPI.h
create mode 100644 common/SafeWrite.cpp
create mode 100644 common/SafeWrite.h
create mode 100644 common/Utilities.cpp
create mode 100644 common/Utilities.h
create mode 100644 common/utility.cpp
create mode 100644 common/utility.h
create mode 100644 dllmain.c
create mode 100644 fps.h
create mode 100644 main.cpp
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..1ff0c42
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,63 @@
+###############################################################################
+# 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
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9491a2f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,363 @@
+## 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
\ No newline at end of file
diff --git a/HighFPSFix.sln b/HighFPSFix.sln
new file mode 100644
index 0000000..697ead0
--- /dev/null
+++ b/HighFPSFix.sln
@@ -0,0 +1,24 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.2.32630.192
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HighFPSFix", "HighFPSFix.vcxproj", "{AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}.Debug|Win32.ActiveCfg = Debug|Win32
+ {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}.Debug|Win32.Build.0 = Debug|Win32
+ {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}.Release|Win32.ActiveCfg = Release|Win32
+ {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {71BF81C1-7B0B-49CB-92D7-5D7E4612E20C}
+ EndGlobalSection
+EndGlobal
diff --git a/HighFPSFix.vcxproj b/HighFPSFix.vcxproj
new file mode 100644
index 0000000..cb83395
--- /dev/null
+++ b/HighFPSFix.vcxproj
@@ -0,0 +1,146 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}
+ nvse_plugin_example
+ Win32Proj
+ 10.0
+ HighFPSFix
+
+
+
+ DynamicLibrary
+ v143
+ MultiByte
+ true
+
+
+ DynamicLibrary
+ v143
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>16.0.28916.169
+
+
+ $(SolutionDir)$(Configuration)\
+ $(Configuration)\
+ true
+ $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(DXSDK_DIR)Lib\x86
+ $(VC_IncludePath);$(WindowsSDK_IncludePath);$(DXSDK_DIR)Include
+ true
+
+
+ $(SolutionDir)$(Configuration)\
+ $(Configuration)\
+ false
+ $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86
+ $(VC_IncludePath);$(WindowsSDK_IncludePath)
+ true
+
+
+
+ Disabled
+ $(SolutionDir);$(SolutionDir)\common;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;_USRDLL;NVSE_PLUGIN_EXAMPLE_EXPORTS;RUNTIME_VERSION=0x040020D0;RUNTIME;SSAA;%(PreprocessorDefinitions)
+ EnableFastChecks
+ MultiThreadedDebugDLL
+
+ Level3
+ ProgramDatabase
+ %(ForcedIncludeFiles)
+ stdcpp20
+ true
+
+
+
+
+ true
+ Windows
+ false
+
+ MachineX86
+ winmm.lib;%(AdditionalDependencies)
+
+
+ Installing DLL...
+ copy "$(TargetPath)" "C:\Users\user\AppData\Local\ModOrganizer\Fallout 3\mods\High FPS Fix\fose\plugins\$(TargetFileName)"
+
+
+
+
+ $(SolutionDir);$(SolutionDir)\common;;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;_USRDLL;NVSE_PLUGIN_EXAMPLE_EXPORTS;RUNTIME_VERSION=0x040020D0;RUNTIME;%(PreprocessorDefinitions)
+ MultiThreadedDLL
+
+ Level3
+ ProgramDatabase
+ %(ForcedIncludeFiles)
+ stdcpp20
+ Speed
+ StreamingSIMDExtensions2
+ Default
+ false
+ true
+ Fast
+ true
+ true
+ Full
+ false
+
+
+
+
+ true
+ Windows
+ true
+ true
+ false
+
+ MachineX86
+ winmm.lib;%(AdditionalDependencies)
+
+
+
+
+ copy "$(TargetPath)" "C:\Users\user\AppData\Local\ModOrganizer\Fallout 3\mods\High FPS Fix\fose\plugins\$(TargetFileName)"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/HighFPSFix.vcxproj.filters b/HighFPSFix.vcxproj.filters
new file mode 100644
index 0000000..70cad01
--- /dev/null
+++ b/HighFPSFix.vcxproj.filters
@@ -0,0 +1,22 @@
+
+
+
+
+ {92a4f350-f2ec-4fca-bdd3-927732d91b34}
+
+
+
+
+
+
+ fose
+
+
+
+
+ fose
+
+
+
+
+
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..877ce92
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# code
\ No newline at end of file
diff --git a/calls.h b/calls.h
new file mode 100644
index 0000000..0872370
--- /dev/null
+++ b/calls.h
@@ -0,0 +1,58 @@
+#pragma once
+// thread-safe template versions of ThisStdCall()
+
+template
+__forceinline T_Ret ThisStdCall(UInt32 _addr, void* _this, Args ...args) {
+ class T {};
+ union {
+ UInt32 addr;
+ T_Ret(T::* func)(Args...);
+ } u = { _addr };
+ return ((T*)_this->*u.func)(std::forward(args)...);
+}
+template
+__forceinline T_Ret StdCall(UInt32 _addr, Args ...args) {
+ return ((T_Ret(__stdcall*)(Args...))_addr)(std::forward(args)...);
+}
+
+template
+__forceinline T_Ret CdeclCall(UInt32 _addr, Args ...args) {
+ return ((T_Ret(__cdecl*)(Args...))_addr)(std::forward(args)...);
+}
+// Templates for UInt8 return.
+
+__forceinline UInt8 ThisStdCall_B(UInt32 _f, void* _t) {
+ class T {}; union { UInt32 x; UInt8(T::* m)(); } u = { _f };
+ return ((T*)_t->*u.m)();
+}
+
+template
+__forceinline UInt8 ThisStdCall_B(UInt32 _f, void* _t, T1 a1) {
+ class T {}; union { UInt32 x; UInt8(T::* m)(T1); } u = { _f };
+ return ((T*)_t->*u.m)(a1);
+}
+
+template
+__forceinline UInt8 ThisStdCall_B(UInt32 _f, void* _t, T1 a1, T2 a2) {
+ class T {}; union { UInt32 x; UInt8(T::* m)(T1, T2); } u = { _f };
+ return ((T*)_t->*u.m)(a1, a2);
+}
+
+template
+__forceinline UInt8 ThisStdCall_B(UInt32 _f, void* _t, T1 a1, T2 a2, T3 a3) {
+ class T {}; union { UInt32 x; UInt8(T::* m)(T1, T2, T3); } u = { _f };
+ return ((T*)_t->*u.m)(a1, a2, a3);
+}
+
+// Templates for float return.
+
+__forceinline float ThisStdCall_F(UInt32 _f, void* _t) {
+ class T {}; union { UInt32 x; float (T::* m)(); } u = { _f };
+ return ((T*)_t->*u.m)();
+}
+
+template
+__forceinline float ThisStdCall_F(UInt32 _f, void* _t, T1 a1) {
+ class T {}; union { UInt32 x; float (T::* m)(T1); } u = { _f };
+ return ((T*)_t->*u.m)(a1);
+}
\ No newline at end of file
diff --git a/common/IDataStream.cpp b/common/IDataStream.cpp
new file mode 100644
index 0000000..d149681
--- /dev/null
+++ b/common/IDataStream.cpp
@@ -0,0 +1,467 @@
+#include "IDataStream.h"
+
+/**** IDataStream *************************************************************/
+
+IDataStream::IDataStream()
+ :streamLength(0), streamOffset(0), swapBytes(false)
+{
+}
+
+IDataStream::~IDataStream()
+{
+}
+
+/**
+ * Reads and returns an 8-bit value from the stream
+ */
+UInt8 IDataStream::Read8(void)
+{
+ UInt8 out;
+
+ ReadBuf(&out, sizeof(UInt8));
+
+ return out;
+}
+
+/**
+ * Reads and returns a 16-bit value from the stream
+ */
+UInt16 IDataStream::Read16(void)
+{
+ UInt16 out;
+
+ ReadBuf(&out, sizeof(UInt16));
+
+ if (swapBytes)
+ out = Swap16(out);
+
+ return out;
+}
+
+/**
+ * Reads and returns a 32-bit value from the stream
+ */
+UInt32 IDataStream::Read32(void)
+{
+ UInt32 out;
+
+ ReadBuf(&out, sizeof(UInt32));
+
+ if (swapBytes)
+ out = Swap32(out);
+
+ return out;
+}
+
+/**
+ * Reads and returns a 64-bit value from the stream
+ */
+UInt64 IDataStream::Read64(void)
+{
+ UInt64 out;
+
+ ReadBuf(&out, sizeof(UInt64));
+
+ if (swapBytes)
+ out = Swap64(out);
+
+ return out;
+}
+
+/**
+ * Reads and returns a 32-bit floating point value from the stream
+ */
+float IDataStream::ReadFloat(void)
+{
+ UInt32 out = Read32();
+
+ return *((float*)&out);
+}
+
+/**
+ * Reads a null-or-return-terminated string from the stream
+ *
+ * If the buffer is too small to hold the entire string, it is truncated and
+ * properly terminated.
+ *
+ * @param buf the output buffer
+ * @param bufLength the size of the output buffer
+ * @return the number of characters written to the buffer
+ */
+UInt32 IDataStream::ReadString(char* buf, UInt32 bufLength, char altTerminator, char altTerminator2)
+{
+ char* traverse = buf;
+ bool breakOnReturns = false;
+
+ if ((altTerminator == '\n') || (altTerminator2 == '\n'))
+ breakOnReturns = true;
+
+ ASSERT_STR(bufLength > 0, "IDataStream::ReadString: zero-sized buffer");
+
+ if (bufLength == 1)
+ {
+ buf[0] = 0;
+ return 0;
+ }
+
+ bufLength--;
+
+ for (UInt32 i = 0; i < bufLength; i++)
+ {
+ UInt8 data = Read8();
+
+ if (breakOnReturns)
+ {
+ if (data == 0x0D)
+ {
+ if (Peek8() == 0x0A)
+ Skip(1);
+
+ break;
+ }
+ }
+
+ if (!data || (data == altTerminator) || (data == altTerminator2))
+ {
+ break;
+ }
+
+ *traverse++ = data;
+ }
+
+ *traverse++ = 0;
+
+ return traverse - buf - 1;
+}
+
+/**
+ * Reads and returns an 8-bit value from the stream without advancing the stream's position
+ */
+UInt8 IDataStream::Peek8(void)
+{
+ IDataStream_PositionSaver saver(this);
+
+ return Read8();
+}
+
+/**
+ * Reads and returns a 16-bit value from the stream without advancing the stream's position
+ */
+UInt16 IDataStream::Peek16(void)
+{
+ IDataStream_PositionSaver saver(this);
+
+ return Read16();
+}
+
+/**
+ * Reads and returns a 32-bit value from the stream without advancing the stream's position
+ */
+UInt32 IDataStream::Peek32(void)
+{
+ IDataStream_PositionSaver saver(this);
+
+ return Read32();
+}
+
+/**
+ * Reads and returns a 32-bit value from the stream without advancing the stream's position
+ */
+UInt64 IDataStream::Peek64(void)
+{
+ IDataStream_PositionSaver saver(this);
+
+ return Read64();
+}
+
+/**
+ * Reads and returns a 32-bit floating point value from the stream without advancing the stream's position
+ */
+float IDataStream::PeekFloat(void)
+{
+ IDataStream_PositionSaver saver(this);
+
+ return ReadFloat();
+}
+
+/**
+ * Reads raw data into a buffer without advancing the stream's position
+ */
+void IDataStream::PeekBuf(void* buf, UInt32 inLength)
+{
+ IDataStream_PositionSaver saver(this);
+
+ ReadBuf(buf, inLength);
+}
+
+/**
+ * Skips a specified number of bytes down the stream
+ */
+void IDataStream::Skip(SInt64 inBytes)
+{
+ SetOffset(GetOffset() + inBytes);
+}
+
+/**
+ * Writes an 8-bit value to the stream.
+ */
+void IDataStream::Write8(UInt8 inData)
+{
+ WriteBuf(&inData, sizeof(UInt8));
+}
+
+/**
+ * Writes a 16-bit value to the stream.
+ */
+void IDataStream::Write16(UInt16 inData)
+{
+ if (swapBytes)
+ inData = Swap16(inData);
+
+ WriteBuf(&inData, sizeof(UInt16));
+}
+
+/**
+ * Writes a 32-bit value to the stream.
+ */
+void IDataStream::Write32(UInt32 inData)
+{
+ if (swapBytes)
+ inData = Swap32(inData);
+
+ WriteBuf(&inData, sizeof(UInt32));
+}
+
+/**
+ * Writes a 64-bit value to the stream.
+ */
+void IDataStream::Write64(UInt64 inData)
+{
+ if (swapBytes)
+ inData = Swap64(inData);
+
+ WriteBuf(&inData, sizeof(UInt64));
+}
+
+/**
+ * Writes a 32-bit floating point value to the stream.
+ */
+void IDataStream::WriteFloat(float inData)
+{
+ if (swapBytes)
+ {
+ UInt32 temp = *((UInt32*)&inData);
+
+ temp = Swap32(temp);
+
+ WriteBuf(&temp, sizeof(UInt32));
+ }
+ else
+ {
+ WriteBuf(&inData, sizeof(float));
+ }
+}
+
+/**
+ * Writes a null-terminated string to the stream.
+ */
+void IDataStream::WriteString(const char* buf)
+{
+ WriteBuf(buf, std::strlen(buf) + 1);
+}
+
+/**
+ * Returns the length of the stream
+ */
+SInt64 IDataStream::GetLength(void)
+{
+ return streamLength;
+}
+
+/**
+ * Returns the number of bytes remaining in the stream
+ */
+SInt64 IDataStream::GetRemain(void)
+{
+ return streamLength - streamOffset;
+}
+
+/**
+ * Returns the current offset into the stream
+ */
+SInt64 IDataStream::GetOffset(void)
+{
+ return streamOffset;
+}
+
+/**
+ * Returns whether we have reached the end of the stream or not
+ */
+bool IDataStream::HitEOF(void)
+{
+ return streamOffset >= streamLength;
+}
+
+/**
+ * Moves the current offset into the stream
+ */
+void IDataStream::SetOffset(SInt64 inOffset)
+{
+ streamOffset = inOffset;
+}
+
+/**
+ * Enables or disables byte swapping for basic data transfers
+ */
+void IDataStream::SwapBytes(bool inSwapBytes)
+{
+ swapBytes = inSwapBytes;
+}
+
+IDataStream* IDataStream::GetRootParent(void)
+{
+ IDataStream* parent = GetParent();
+
+ if (parent)
+ return parent->GetRootParent();
+ else
+ return this;
+}
+
+void IDataStream::CopyStreams(IDataStream* out, IDataStream* in, UInt64 bufferSize, UInt8* buf)
+{
+ in->Rewind();
+
+ bool ourBuffer = false;
+
+ if (!buf)
+ {
+ buf = new UInt8[bufferSize];
+ ourBuffer = true;
+ }
+
+ UInt64 remain = in->GetLength();
+
+ while (remain > 0)
+ {
+ UInt64 transferSize = remain;
+
+ if (transferSize > bufferSize)
+ transferSize = bufferSize;
+
+ in->ReadBuf(buf, transferSize);
+ out->WriteBuf(buf, transferSize);
+
+ remain -= transferSize;
+ }
+
+ if (ourBuffer)
+ delete[] buf;
+}
+
+void IDataStream::CopySubStreams(IDataStream* out, IDataStream* in, UInt64 remain, UInt64 bufferSize, UInt8* buf)
+{
+ bool ourBuffer = false;
+
+ if (!buf)
+ {
+ buf = new UInt8[bufferSize];
+ ourBuffer = true;
+ }
+
+ while (remain > 0)
+ {
+ UInt64 transferSize = remain;
+
+ if (transferSize > bufferSize)
+ transferSize = bufferSize;
+
+ in->ReadBuf(buf, transferSize);
+ out->WriteBuf(buf, transferSize);
+
+ remain -= transferSize;
+ }
+
+ if (ourBuffer)
+ delete[] buf;
+}
+
+/**** IDataStream_PositionSaver ***********************************************/
+
+/**
+ * The constructor; save the stream's position
+ */
+IDataStream_PositionSaver::IDataStream_PositionSaver(IDataStream* tgt)
+{
+ stream = tgt;
+ offset = tgt->GetOffset();
+}
+
+/**
+ * The destructor; restore the stream's saved position
+ */
+IDataStream_PositionSaver::~IDataStream_PositionSaver()
+{
+ stream->SetOffset(offset);
+}
+
+/**** IDataSubStream **********************************************************/
+
+IDataSubStream::IDataSubStream()
+ :stream(NULL), subBase(0)
+{
+ //
+}
+
+IDataSubStream::IDataSubStream(IDataStream* inStream, SInt64 inOffset, SInt64 inLength)
+{
+ stream = inStream;
+ subBase = inOffset;
+ streamLength = inLength;
+
+ stream->SetOffset(inOffset);
+}
+
+IDataSubStream::~IDataSubStream()
+{
+}
+
+void IDataSubStream::Attach(IDataStream* inStream, SInt64 inOffset, SInt64 inLength)
+{
+ stream = inStream;
+ subBase = inOffset;
+ streamLength = inLength;
+
+ stream->SetOffset(inOffset);
+}
+
+void IDataSubStream::ReadBuf(void* buf, UInt32 inLength)
+{
+ ASSERT_STR(inLength <= GetRemain(), "IDataSubStream::ReadBuf: hit eof");
+
+ if (stream->GetOffset() != subBase + streamOffset)
+ stream->SetOffset(subBase + streamOffset);
+
+ stream->ReadBuf(buf, inLength);
+
+ streamOffset += inLength;
+}
+
+void IDataSubStream::WriteBuf(const void* buf, UInt32 inLength)
+{
+ if (stream->GetOffset() != subBase + streamOffset)
+ stream->SetOffset(subBase + streamOffset);
+
+ stream->WriteBuf(buf, inLength);
+
+ streamOffset += inLength;
+
+ if (streamLength < streamOffset)
+ streamLength = streamOffset;
+}
+
+void IDataSubStream::SetOffset(SInt64 inOffset)
+{
+ stream->SetOffset(subBase + inOffset);
+ streamOffset = inOffset;
+}
\ No newline at end of file
diff --git a/common/IDataStream.h b/common/IDataStream.h
new file mode 100644
index 0000000..4e08af9
--- /dev/null
+++ b/common/IDataStream.h
@@ -0,0 +1,102 @@
+#pragma once
+
+#include "common/IErrors.h"
+
+/**
+ * An arbitrary data stream
+ */
+class IDataStream
+{
+public:
+ IDataStream();
+ virtual ~IDataStream();
+
+ // read
+ virtual UInt8 Read8(void);
+ virtual UInt16 Read16(void);
+ virtual UInt32 Read32(void);
+ virtual UInt64 Read64(void);
+ virtual float ReadFloat(void);
+ virtual UInt32 ReadString(char* buf, UInt32 bufLength, char altTerminator = 0, char altTerminator2 = 0);
+ virtual void ReadBuf(void* buf, UInt32 inLength) = 0;
+
+ // peek
+ virtual UInt8 Peek8(void);
+ virtual UInt16 Peek16(void);
+ virtual UInt32 Peek32(void);
+ virtual UInt64 Peek64(void);
+ virtual float PeekFloat(void);
+ virtual void PeekBuf(void* buf, UInt32 inLength);
+
+ virtual void Skip(SInt64 inBytes);
+
+ // write
+ virtual void Write8(UInt8 inData);
+ virtual void Write16(UInt16 inData);
+ virtual void Write32(UInt32 inData);
+ virtual void Write64(UInt64 inData);
+ virtual void WriteFloat(float inData);
+ virtual void WriteString(const char* buf);
+ virtual void WriteBuf(const void* buf, UInt32 inLength) = 0;
+
+ SInt64 GetLength(void);
+ SInt64 GetRemain(void);
+ SInt64 GetOffset(void);
+ bool HitEOF(void);
+
+ virtual void SetOffset(SInt64 inOffset);
+ void Rewind(void) { SetOffset(0); }
+
+ void SwapBytes(bool inSwapBytes);
+
+ virtual SInt64 GetParentOffset(void) { return GetOffset(); }
+ virtual IDataStream* GetParent(void) { return NULL; }
+
+ IDataStream* GetRootParent(void);
+
+ static void CopyStreams(IDataStream* out, IDataStream* in, UInt64 bufferSize = 1024 * 1024, UInt8* buf = NULL);
+ static void CopySubStreams(IDataStream* out, IDataStream* in, UInt64 remain, UInt64 bufferSize = 1024 * 1024, UInt8* buf = NULL);
+
+protected:
+ SInt64 streamLength;
+ SInt64 streamOffset;
+ bool swapBytes;
+};
+
+/**
+ * A utility class to automatically save and restore the current position of an IDataStream
+ */
+class IDataStream_PositionSaver
+{
+public:
+ IDataStream_PositionSaver(IDataStream* tgt);
+ ~IDataStream_PositionSaver();
+
+private:
+ IDataStream* stream;
+ SInt64 offset;
+};
+
+class IDataSubStream : public IDataStream
+{
+public:
+ IDataSubStream();
+ IDataSubStream(IDataStream* inStream, SInt64 inOffset, SInt64 inLength);
+ ~IDataSubStream();
+
+ void Attach(IDataStream* inStream, SInt64 inOffset, SInt64 inLength);
+
+ void ReadBuf(void* buf, UInt32 inLength);
+ void WriteBuf(const void* buf, UInt32 inLength);
+ void SetOffset(SInt64 inOffset);
+
+ virtual SInt64 GetParentOffset(void) { return stream->GetOffset(); }
+ virtual IDataStream* GetParent(void) { return stream; }
+
+ SInt64 GetSubBase(void) { return subBase; }
+
+private:
+ IDataStream* stream;
+
+ SInt64 subBase;
+};
diff --git a/common/IDebugLog.cpp b/common/IDebugLog.cpp
new file mode 100644
index 0000000..b503e33
--- /dev/null
+++ b/common/IDebugLog.cpp
@@ -0,0 +1,301 @@
+#include "common/IDebugLog.h"
+#include
+#include "common/IFileStream.h"
+#include
+
+std::FILE* IDebugLog::logFile = NULL;
+char IDebugLog::sourceBuf[16] = { 0 };
+char IDebugLog::headerText[16] = { 0 };
+char IDebugLog::formatBuf[8192] = { 0 };
+int IDebugLog::indentLevel = 0;
+int IDebugLog::rightMargin = 0;
+int IDebugLog::cursorPos = 0;
+int IDebugLog::inBlock = 0;
+bool IDebugLog::autoFlush = true;
+IDebugLog::LogLevel IDebugLog::logLevel = IDebugLog::kLevel_DebugMessage;
+IDebugLog::LogLevel IDebugLog::printLevel = IDebugLog::kLevel_Message;
+
+IDebugLog::IDebugLog()
+{
+ //
+}
+
+IDebugLog::IDebugLog(const char* name)
+{
+ Open(name);
+}
+
+IDebugLog::~IDebugLog()
+{
+ if (logFile)
+ fclose(logFile);
+}
+
+void IDebugLog::Open(const char* path)
+{
+ logFile = _fsopen(path, "w", _SH_DENYWR);
+
+ if (!logFile)
+ {
+ UInt32 id = 0;
+ char name[1024];
+
+ do
+ {
+ sprintf_s(name, sizeof(name), "%s%d", path, id);
+ id++;
+
+ logFile = NULL;
+ logFile = _fsopen(name, "w", _SH_DENYWR);
+ } while (!logFile && (id < 5));
+ }
+}
+
+void IDebugLog::OpenRelative(int folderID, const char* relPath)
+{
+ char path[MAX_PATH];
+
+ ASSERT(SUCCEEDED(SHGetFolderPath(NULL, folderID, NULL, SHGFP_TYPE_CURRENT, path)));
+
+ strcat_s(path, sizeof(path), relPath);
+
+ IFileStream::MakeAllDirs(path);
+
+ Open(path);
+}
+
+/**
+ * Output a non-formatted message to the log file
+ *
+ * @param message the message
+ * @param source the source of the message, or NULL to use the previous source
+ */
+void IDebugLog::Message(const char* message, const char* source)
+{
+ if (source)
+ SetSource(source);
+
+ if (inBlock)
+ {
+ SeekCursor(RoundToTab((indentLevel * 4) + strlen(headerText)));
+ }
+ else
+ {
+ SeekCursor(indentLevel * 4);
+
+ PrintText(headerText);
+ }
+
+ PrintText(message);
+ NewLine();
+}
+
+/**
+ * Output a formatted message to the log file
+ *
+ * @note It is impossible to set the source of a formatted message.
+ * The previous source will be used.
+ */
+void IDebugLog::FormattedMessage(const char* fmt, ...)
+{
+ va_list argList;
+
+ va_start(argList, fmt);
+ vsprintf_s(formatBuf, sizeof(formatBuf), fmt, argList);
+ Message(formatBuf);
+ va_end(argList);
+}
+
+/**
+ * Output a formatted message to the log file
+ *
+ * @note It is impossible to set the source of a formatted message.
+ * The previous source will be used.
+ */
+void IDebugLog::FormattedMessage(const char* fmt, va_list args)
+{
+ vsprintf_s(formatBuf, sizeof(formatBuf), fmt, args);
+ Message(formatBuf);
+}
+
+void IDebugLog::Log(LogLevel level, const char* fmt, va_list args)
+{
+ bool log = (level <= logLevel);
+ bool print = (level <= printLevel);
+
+ if (log || print)
+ vsprintf_s(formatBuf, sizeof(formatBuf), fmt, args);
+
+ if (log)
+ Message(formatBuf);
+
+ if (print)
+ printf("%s\n", formatBuf);
+}
+
+/**
+ * Set the current message source
+ */
+void IDebugLog::SetSource(const char* source)
+{
+ strcpy_s(sourceBuf, sizeof(sourceBuf), source);
+ strcpy_s(headerText, sizeof(headerText), "[ ]\t");
+
+ char* tgt = headerText + 1;
+ char* src = sourceBuf;
+
+ for (int i = 0; (i < 8) && *src; i++, tgt++, src++)
+ *tgt = *src;
+}
+
+/**
+ * Clear the current message source
+ */
+void IDebugLog::ClearSource(void)
+{
+ sourceBuf[0] = 0;
+}
+
+/**
+ * Increase the indentation level
+ */
+void IDebugLog::Indent(void)
+{
+ indentLevel++;
+}
+
+/**
+ * Decrease the indentation level
+ */
+void IDebugLog::Outdent(void)
+{
+ if (indentLevel)
+ indentLevel--;
+}
+
+/**
+ * Enter a logical block
+ */
+void IDebugLog::OpenBlock(void)
+{
+ SeekCursor(indentLevel * 4);
+
+ PrintText(headerText);
+
+ inBlock = 1;
+}
+
+/**
+ * Close a logical block
+ */
+void IDebugLog::CloseBlock(void)
+{
+ inBlock = 0;
+}
+
+/**
+ * Enable/disable autoflush
+ *
+ * @param inAutoFlush autoflush state
+ */
+void IDebugLog::SetAutoFlush(bool inAutoFlush)
+{
+ autoFlush = inAutoFlush;
+}
+
+/**
+ * Print spaces to the log
+ *
+ * If possible, tabs are used instead of spaces.
+ */
+void IDebugLog::PrintSpaces(int numSpaces)
+{
+ int originalNumSpaces = numSpaces;
+
+ if (logFile)
+ {
+ while (numSpaces > 0)
+ {
+ if (numSpaces >= TabSize())
+ {
+ numSpaces -= TabSize();
+ fputc('\t', logFile);
+ }
+ else
+ {
+ numSpaces--;
+ fputc(' ', logFile);
+ }
+ }
+ }
+
+ cursorPos += originalNumSpaces;
+}
+
+/**
+ * Prints raw text to the log file
+ */
+void IDebugLog::PrintText(const char* buf)
+{
+ if (logFile)
+ {
+ fputs(buf, logFile);
+ if (autoFlush)
+ fflush(logFile);
+ }
+
+ const char* traverse = buf;
+ char data;
+
+ while (data = *traverse++)
+ {
+ if (data == '\t')
+ cursorPos += TabSize();
+ else
+ cursorPos++;
+ }
+}
+
+/**
+ * Moves to the next line of the log file
+ */
+void IDebugLog::NewLine(void)
+{
+ if (logFile)
+ {
+ fputc('\n', logFile);
+
+ if (autoFlush)
+ fflush(logFile);
+ }
+
+ cursorPos = 0;
+}
+
+/**
+ * Prints spaces to align the cursor to the requested position
+ *
+ * @note The cursor move will not be performed if the request would move the cursor
+ * backwards.
+ */
+void IDebugLog::SeekCursor(int position)
+{
+ if (position > cursorPos)
+ PrintSpaces(position - cursorPos);
+}
+
+/**
+ * Returns the number of spaces a tab would occupy at the current cursor position
+ */
+int IDebugLog::TabSize(void)
+{
+ return ((~cursorPos) & 3) + 1;
+}
+
+/**
+ * Rounds a number of spaces to the nearest tab
+ */
+int IDebugLog::RoundToTab(int spaces)
+{
+ return (spaces + 3) & ~3;
+}
\ No newline at end of file
diff --git a/common/IDebugLog.h b/common/IDebugLog.h
new file mode 100644
index 0000000..e4bfce9
--- /dev/null
+++ b/common/IDebugLog.h
@@ -0,0 +1,132 @@
+#pragma once
+
+#include
+
+/**
+ * A simple debug log file
+ *
+ * This class supports prefix blocks describing the source of the log event.
+ * It also allows logical blocks and outlining.\n
+ */
+class IDebugLog
+{
+public:
+ IDebugLog();
+ IDebugLog(const char* name);
+ ~IDebugLog();
+
+ static void Open(const char* path);
+ static void OpenRelative(int folderID, const char* relPath);
+
+ static void Message(const char* message, const char* source = NULL);
+ static void FormattedMessage(const char* fmt, ...);
+ static void FormattedMessage(const char* fmt, va_list args);
+
+ enum LogLevel
+ {
+ kLevel_FatalError = 0,
+ kLevel_Error,
+ kLevel_Warning,
+ kLevel_Message,
+ kLevel_VerboseMessage,
+ kLevel_DebugMessage
+ };
+
+ static void Log(LogLevel level, const char* fmt, va_list args);
+
+ static void SetSource(const char* source);
+ static void ClearSource(void);
+
+ static void Indent(void);
+ static void Outdent(void);
+
+ static void OpenBlock(void);
+ static void CloseBlock(void);
+
+ static void SetAutoFlush(bool inAutoFlush);
+
+ static void SetLogLevel(LogLevel in) { logLevel = in; }
+ static void SetPrintLevel(LogLevel in) { printLevel = in; }
+
+private:
+ static void PrintSpaces(int numSpaces);
+ static void PrintText(const char* buf);
+ static void NewLine(void);
+
+ static void SeekCursor(int position);
+
+ static int TabSize(void);
+ static int RoundToTab(int spaces);
+
+ static FILE* logFile; //!< the output file
+
+ static char sourceBuf[16]; //!< name of current source, used in prefix
+ static char headerText[16]; //!< current text to use as line prefix
+ static char formatBuf[8192]; //!< temp buffer used for formatted messages
+
+ static int indentLevel; //!< the current indentation level (in tabs)
+ static int rightMargin; //!< the column at which text should be wrapped
+ static int cursorPos; //!< current cursor position
+ static int inBlock; //!< are we in a block?
+
+ static bool autoFlush; //!< automatically flush the file after writing
+
+ static LogLevel logLevel; //!< least important log level to write
+ static LogLevel printLevel; //!< least important log level to print
+};
+
+extern IDebugLog gLog;
+
+inline void _FATALERROR(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ gLog.Log(IDebugLog::kLevel_FatalError, fmt, args);
+ va_end(args);
+}
+
+inline void _ERROR(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ gLog.Log(IDebugLog::kLevel_Error, fmt, args);
+ va_end(args);
+}
+
+inline void _WARNING(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ gLog.Log(IDebugLog::kLevel_Warning, fmt, args);
+ va_end(args);
+}
+
+inline void _MESSAGE(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ gLog.Log(IDebugLog::kLevel_Message, fmt, args);
+ va_end(args);
+}
+
+inline void _VMESSAGE(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ gLog.Log(IDebugLog::kLevel_VerboseMessage, fmt, args);
+ va_end(args);
+}
+
+inline void _DMESSAGE(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ gLog.Log(IDebugLog::kLevel_DebugMessage, fmt, args);
+ va_end(args);
+}
diff --git a/common/IDynamicCreate.cpp b/common/IDynamicCreate.cpp
new file mode 100644
index 0000000..a32e7f7
--- /dev/null
+++ b/common/IDynamicCreate.cpp
@@ -0,0 +1,38 @@
+#include "IDynamicCreate.h"
+
+#if ENABLE_IDYNAMICCREATE
+
+IClassRegistry _gClassRegistry;
+
+IClassRegistry::IClassRegistry()
+{
+ //
+}
+
+IClassRegistry::~IClassRegistry()
+{
+ //
+}
+
+void IClassRegistry::RegisterClassInfo(UInt32 id, IDynamicType* typeInfo)
+{
+ theClassRegistry[id] = typeInfo;
+}
+
+IDynamicType* IClassRegistry::LookupClassInfo(UInt32 id)
+{
+ ClassRegistryType::iterator iter = theClassRegistry.find(id);
+
+ return (iter == theClassRegistry.end()) ? NULL : (*iter).second;
+}
+
+IDynamicType* IClassRegistry::LookupClassInfo(char* name)
+{
+ for (ClassRegistryType::iterator iter = theClassRegistry.begin(); iter != theClassRegistry.end(); iter++)
+ if (!strcmp((*iter).second->GetName(), name))
+ return (*iter).second;
+
+ return NULL;
+}
+
+#endif
\ No newline at end of file
diff --git a/common/IDynamicCreate.h b/common/IDynamicCreate.h
new file mode 100644
index 0000000..70a7e23
--- /dev/null
+++ b/common/IDynamicCreate.h
@@ -0,0 +1,118 @@
+#pragma once
+
+#include