├── .gitattributes
├── .gitignore
├── HighFPSFix.sln
├── HighFPSFix.vcxproj
├── HighFPSFix.vcxproj.filters
├── LICENSE.txt
├── README.md
├── calls.h
├── common
├── IDataStream.cpp
├── IDataStream.h
├── IDebugLog.cpp
├── IDebugLog.h
├── IDynamicCreate.cpp
├── IDynamicCreate.h
├── IErrors.cpp
├── IErrors.h
├── IPrefix.cpp
├── IPrefix.h
├── ISingleton.cpp
├── ISingleton.h
├── ITypes.cpp
├── ITypes.h
├── PluginAPI.h
├── SafeWrite.cpp
├── SafeWrite.h
├── Utilities.cpp
├── Utilities.h
├── utility.cpp
└── utility.h
├── dllmain.c
├── fps.h
└── main.cpp
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/HighFPSFix.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio Version 17
3 | VisualStudioVersion = 17.2.32630.192
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HighFPSFix", "HighFPSFix.vcxproj", "{AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|Win32 = Debug|Win32
10 | Release|Win32 = Release|Win32
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}.Debug|Win32.ActiveCfg = Debug|Win32
14 | {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}.Debug|Win32.Build.0 = Debug|Win32
15 | {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}.Release|Win32.ActiveCfg = Release|Win32
16 | {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}.Release|Win32.Build.0 = Release|Win32
17 | EndGlobalSection
18 | GlobalSection(SolutionProperties) = preSolution
19 | HideSolutionNode = FALSE
20 | EndGlobalSection
21 | GlobalSection(ExtensibilityGlobals) = postSolution
22 | SolutionGuid = {71BF81C1-7B0B-49CB-92D7-5D7E4612E20C}
23 | EndGlobalSection
24 | EndGlobal
25 |
--------------------------------------------------------------------------------
/HighFPSFix.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {AE7CFEE7-4058-4E3C-ADC2-AE7480EE2028}
15 | nvse_plugin_example
16 | Win32Proj
17 | 10.0
18 | HighFPSFix
19 |
20 |
21 |
22 | DynamicLibrary
23 | v143
24 | MultiByte
25 | true
26 |
27 |
28 | DynamicLibrary
29 | v143
30 | MultiByte
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | <_ProjectFileVersion>16.0.28916.169
44 |
45 |
46 | $(SolutionDir)$(Configuration)\
47 | $(Configuration)\
48 | true
49 | $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(DXSDK_DIR)Lib\x86
50 | $(VC_IncludePath);$(WindowsSDK_IncludePath);$(DXSDK_DIR)Include
51 | true
52 |
53 |
54 | $(SolutionDir)$(Configuration)\
55 | $(Configuration)\
56 | false
57 | $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86
58 | $(VC_IncludePath);$(WindowsSDK_IncludePath)
59 | true
60 |
61 |
62 |
63 | Disabled
64 | $(SolutionDir);$(SolutionDir)\common;%(AdditionalIncludeDirectories)
65 | WIN32;_DEBUG;_WINDOWS;_USRDLL;NVSE_PLUGIN_EXAMPLE_EXPORTS;RUNTIME_VERSION=0x040020D0;RUNTIME;SSAA;%(PreprocessorDefinitions)
66 | EnableFastChecks
67 | MultiThreadedDebugDLL
68 |
69 | Level3
70 | ProgramDatabase
71 | %(ForcedIncludeFiles)
72 | stdcpp20
73 | true
74 |
75 |
76 |
77 |
78 | true
79 | Windows
80 | false
81 |
82 | MachineX86
83 | winmm.lib;%(AdditionalDependencies)
84 |
85 |
86 | Installing DLL...
87 | copy "$(TargetPath)" "C:\Users\user\AppData\Local\ModOrganizer\Fallout 3\mods\High FPS Fix\fose\plugins\$(TargetFileName)"
88 |
89 |
90 |
91 |
92 | $(SolutionDir);$(SolutionDir)\common;;%(AdditionalIncludeDirectories)
93 | WIN32;NDEBUG;_WINDOWS;_USRDLL;NVSE_PLUGIN_EXAMPLE_EXPORTS;RUNTIME_VERSION=0x040020D0;RUNTIME;%(PreprocessorDefinitions)
94 | MultiThreadedDLL
95 |
96 | Level3
97 | ProgramDatabase
98 | %(ForcedIncludeFiles)
99 | stdcpp20
100 | Speed
101 | StreamingSIMDExtensions2
102 | Default
103 | false
104 | true
105 | Fast
106 | true
107 | true
108 | Full
109 | false
110 |
111 |
112 |
113 |
114 | true
115 | Windows
116 | true
117 | true
118 | false
119 |
120 | MachineX86
121 | winmm.lib;%(AdditionalDependencies)
122 |
123 |
124 |
125 |
126 | copy "$(TargetPath)" "C:\Users\ykzmd\AppData\Local\ModOrganizer\Fallout 3\mods\High FPS Fix\fose\plugins\$(TargetFileName)"
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/HighFPSFix.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {92a4f350-f2ec-4fca-bdd3-927732d91b34}
6 |
7 |
8 |
9 |
10 |
11 |
12 | fose
13 |
14 |
15 |
16 |
17 | fose
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # High FPS Physics Fix
2 |
3 | Fixes gameplay issues that occur in Fallout 3 when the game is running at framerates over 60.
4 |
5 | **Please note that 120 is considered a safe maximum and going above that is not advised.**
6 |
7 | To learn how to configure the game and your drivers for the best possible performance, read and follow [The Performance Guide](https://performance.moddinglinked.com/falloutnv.html#DriversAndOS) - most of it applies to both New Vegas and Fallout 3.
8 |
9 | Ported from [New Vegas Tick Fix](https://www.nexusmods.com/newvegas/mods/66537).
10 |
11 | Incompatible with [Fallout 3 Tick Fix](https://www.nexusmods.com/fallout3/mods/23542) and `bTickFix` option in [Stewie's Tweaks](https://www.nexusmods.com/fallout3/mods/23561) - their functionality is included.
12 |
13 | *Credits to carxt for the original code.*
14 |
--------------------------------------------------------------------------------
/calls.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | // thread-safe template versions of ThisStdCall()
3 |
4 | template
5 | __forceinline T_Ret ThisStdCall(UInt32 _addr, void* _this, Args ...args) {
6 | class T {};
7 | union {
8 | UInt32 addr;
9 | T_Ret(T::* func)(Args...);
10 | } u = { _addr };
11 | return ((T*)_this->*u.func)(std::forward(args)...);
12 | }
13 | template
14 | __forceinline T_Ret StdCall(UInt32 _addr, Args ...args) {
15 | return ((T_Ret(__stdcall*)(Args...))_addr)(std::forward(args)...);
16 | }
17 |
18 | template
19 | __forceinline T_Ret CdeclCall(UInt32 _addr, Args ...args) {
20 | return ((T_Ret(__cdecl*)(Args...))_addr)(std::forward(args)...);
21 | }
22 | // Templates for UInt8 return.
23 |
24 | __forceinline UInt8 ThisStdCall_B(UInt32 _f, void* _t) {
25 | class T {}; union { UInt32 x; UInt8(T::* m)(); } u = { _f };
26 | return ((T*)_t->*u.m)();
27 | }
28 |
29 | template
30 | __forceinline UInt8 ThisStdCall_B(UInt32 _f, void* _t, T1 a1) {
31 | class T {}; union { UInt32 x; UInt8(T::* m)(T1); } u = { _f };
32 | return ((T*)_t->*u.m)(a1);
33 | }
34 |
35 | template
36 | __forceinline UInt8 ThisStdCall_B(UInt32 _f, void* _t, T1 a1, T2 a2) {
37 | class T {}; union { UInt32 x; UInt8(T::* m)(T1, T2); } u = { _f };
38 | return ((T*)_t->*u.m)(a1, a2);
39 | }
40 |
41 | template
42 | __forceinline UInt8 ThisStdCall_B(UInt32 _f, void* _t, T1 a1, T2 a2, T3 a3) {
43 | class T {}; union { UInt32 x; UInt8(T::* m)(T1, T2, T3); } u = { _f };
44 | return ((T*)_t->*u.m)(a1, a2, a3);
45 | }
46 |
47 | // Templates for float return.
48 |
49 | __forceinline float ThisStdCall_F(UInt32 _f, void* _t) {
50 | class T {}; union { UInt32 x; float (T::* m)(); } u = { _f };
51 | return ((T*)_t->*u.m)();
52 | }
53 |
54 | template
55 | __forceinline float ThisStdCall_F(UInt32 _f, void* _t, T1 a1) {
56 | class T {}; union { UInt32 x; float (T::* m)(T1); } u = { _f };
57 | return ((T*)_t->*u.m)(a1);
58 | }
--------------------------------------------------------------------------------
/common/IDataStream.cpp:
--------------------------------------------------------------------------------
1 | #include "IDataStream.h"
2 |
3 | /**** IDataStream *************************************************************/
4 |
5 | IDataStream::IDataStream()
6 | :streamLength(0), streamOffset(0), swapBytes(false)
7 | {
8 | }
9 |
10 | IDataStream::~IDataStream()
11 | {
12 | }
13 |
14 | /**
15 | * Reads and returns an 8-bit value from the stream
16 | */
17 | UInt8 IDataStream::Read8(void)
18 | {
19 | UInt8 out;
20 |
21 | ReadBuf(&out, sizeof(UInt8));
22 |
23 | return out;
24 | }
25 |
26 | /**
27 | * Reads and returns a 16-bit value from the stream
28 | */
29 | UInt16 IDataStream::Read16(void)
30 | {
31 | UInt16 out;
32 |
33 | ReadBuf(&out, sizeof(UInt16));
34 |
35 | if (swapBytes)
36 | out = Swap16(out);
37 |
38 | return out;
39 | }
40 |
41 | /**
42 | * Reads and returns a 32-bit value from the stream
43 | */
44 | UInt32 IDataStream::Read32(void)
45 | {
46 | UInt32 out;
47 |
48 | ReadBuf(&out, sizeof(UInt32));
49 |
50 | if (swapBytes)
51 | out = Swap32(out);
52 |
53 | return out;
54 | }
55 |
56 | /**
57 | * Reads and returns a 64-bit value from the stream
58 | */
59 | UInt64 IDataStream::Read64(void)
60 | {
61 | UInt64 out;
62 |
63 | ReadBuf(&out, sizeof(UInt64));
64 |
65 | if (swapBytes)
66 | out = Swap64(out);
67 |
68 | return out;
69 | }
70 |
71 | /**
72 | * Reads and returns a 32-bit floating point value from the stream
73 | */
74 | float IDataStream::ReadFloat(void)
75 | {
76 | UInt32 out = Read32();
77 |
78 | return *((float*)&out);
79 | }
80 |
81 | /**
82 | * Reads a null-or-return-terminated string from the stream
83 | *
84 | * If the buffer is too small to hold the entire string, it is truncated and
85 | * properly terminated.
86 | *
87 | * @param buf the output buffer
88 | * @param bufLength the size of the output buffer
89 | * @return the number of characters written to the buffer
90 | */
91 | UInt32 IDataStream::ReadString(char* buf, UInt32 bufLength, char altTerminator, char altTerminator2)
92 | {
93 | char* traverse = buf;
94 | bool breakOnReturns = false;
95 |
96 | if ((altTerminator == '\n') || (altTerminator2 == '\n'))
97 | breakOnReturns = true;
98 |
99 | ASSERT_STR(bufLength > 0, "IDataStream::ReadString: zero-sized buffer");
100 |
101 | if (bufLength == 1)
102 | {
103 | buf[0] = 0;
104 | return 0;
105 | }
106 |
107 | bufLength--;
108 |
109 | for (UInt32 i = 0; i < bufLength; i++)
110 | {
111 | UInt8 data = Read8();
112 |
113 | if (breakOnReturns)
114 | {
115 | if (data == 0x0D)
116 | {
117 | if (Peek8() == 0x0A)
118 | Skip(1);
119 |
120 | break;
121 | }
122 | }
123 |
124 | if (!data || (data == altTerminator) || (data == altTerminator2))
125 | {
126 | break;
127 | }
128 |
129 | *traverse++ = data;
130 | }
131 |
132 | *traverse++ = 0;
133 |
134 | return traverse - buf - 1;
135 | }
136 |
137 | /**
138 | * Reads and returns an 8-bit value from the stream without advancing the stream's position
139 | */
140 | UInt8 IDataStream::Peek8(void)
141 | {
142 | IDataStream_PositionSaver saver(this);
143 |
144 | return Read8();
145 | }
146 |
147 | /**
148 | * Reads and returns a 16-bit value from the stream without advancing the stream's position
149 | */
150 | UInt16 IDataStream::Peek16(void)
151 | {
152 | IDataStream_PositionSaver saver(this);
153 |
154 | return Read16();
155 | }
156 |
157 | /**
158 | * Reads and returns a 32-bit value from the stream without advancing the stream's position
159 | */
160 | UInt32 IDataStream::Peek32(void)
161 | {
162 | IDataStream_PositionSaver saver(this);
163 |
164 | return Read32();
165 | }
166 |
167 | /**
168 | * Reads and returns a 32-bit value from the stream without advancing the stream's position
169 | */
170 | UInt64 IDataStream::Peek64(void)
171 | {
172 | IDataStream_PositionSaver saver(this);
173 |
174 | return Read64();
175 | }
176 |
177 | /**
178 | * Reads and returns a 32-bit floating point value from the stream without advancing the stream's position
179 | */
180 | float IDataStream::PeekFloat(void)
181 | {
182 | IDataStream_PositionSaver saver(this);
183 |
184 | return ReadFloat();
185 | }
186 |
187 | /**
188 | * Reads raw data into a buffer without advancing the stream's position
189 | */
190 | void IDataStream::PeekBuf(void* buf, UInt32 inLength)
191 | {
192 | IDataStream_PositionSaver saver(this);
193 |
194 | ReadBuf(buf, inLength);
195 | }
196 |
197 | /**
198 | * Skips a specified number of bytes down the stream
199 | */
200 | void IDataStream::Skip(SInt64 inBytes)
201 | {
202 | SetOffset(GetOffset() + inBytes);
203 | }
204 |
205 | /**
206 | * Writes an 8-bit value to the stream.
207 | */
208 | void IDataStream::Write8(UInt8 inData)
209 | {
210 | WriteBuf(&inData, sizeof(UInt8));
211 | }
212 |
213 | /**
214 | * Writes a 16-bit value to the stream.
215 | */
216 | void IDataStream::Write16(UInt16 inData)
217 | {
218 | if (swapBytes)
219 | inData = Swap16(inData);
220 |
221 | WriteBuf(&inData, sizeof(UInt16));
222 | }
223 |
224 | /**
225 | * Writes a 32-bit value to the stream.
226 | */
227 | void IDataStream::Write32(UInt32 inData)
228 | {
229 | if (swapBytes)
230 | inData = Swap32(inData);
231 |
232 | WriteBuf(&inData, sizeof(UInt32));
233 | }
234 |
235 | /**
236 | * Writes a 64-bit value to the stream.
237 | */
238 | void IDataStream::Write64(UInt64 inData)
239 | {
240 | if (swapBytes)
241 | inData = Swap64(inData);
242 |
243 | WriteBuf(&inData, sizeof(UInt64));
244 | }
245 |
246 | /**
247 | * Writes a 32-bit floating point value to the stream.
248 | */
249 | void IDataStream::WriteFloat(float inData)
250 | {
251 | if (swapBytes)
252 | {
253 | UInt32 temp = *((UInt32*)&inData);
254 |
255 | temp = Swap32(temp);
256 |
257 | WriteBuf(&temp, sizeof(UInt32));
258 | }
259 | else
260 | {
261 | WriteBuf(&inData, sizeof(float));
262 | }
263 | }
264 |
265 | /**
266 | * Writes a null-terminated string to the stream.
267 | */
268 | void IDataStream::WriteString(const char* buf)
269 | {
270 | WriteBuf(buf, std::strlen(buf) + 1);
271 | }
272 |
273 | /**
274 | * Returns the length of the stream
275 | */
276 | SInt64 IDataStream::GetLength(void)
277 | {
278 | return streamLength;
279 | }
280 |
281 | /**
282 | * Returns the number of bytes remaining in the stream
283 | */
284 | SInt64 IDataStream::GetRemain(void)
285 | {
286 | return streamLength - streamOffset;
287 | }
288 |
289 | /**
290 | * Returns the current offset into the stream
291 | */
292 | SInt64 IDataStream::GetOffset(void)
293 | {
294 | return streamOffset;
295 | }
296 |
297 | /**
298 | * Returns whether we have reached the end of the stream or not
299 | */
300 | bool IDataStream::HitEOF(void)
301 | {
302 | return streamOffset >= streamLength;
303 | }
304 |
305 | /**
306 | * Moves the current offset into the stream
307 | */
308 | void IDataStream::SetOffset(SInt64 inOffset)
309 | {
310 | streamOffset = inOffset;
311 | }
312 |
313 | /**
314 | * Enables or disables byte swapping for basic data transfers
315 | */
316 | void IDataStream::SwapBytes(bool inSwapBytes)
317 | {
318 | swapBytes = inSwapBytes;
319 | }
320 |
321 | IDataStream* IDataStream::GetRootParent(void)
322 | {
323 | IDataStream* parent = GetParent();
324 |
325 | if (parent)
326 | return parent->GetRootParent();
327 | else
328 | return this;
329 | }
330 |
331 | void IDataStream::CopyStreams(IDataStream* out, IDataStream* in, UInt64 bufferSize, UInt8* buf)
332 | {
333 | in->Rewind();
334 |
335 | bool ourBuffer = false;
336 |
337 | if (!buf)
338 | {
339 | buf = new UInt8[bufferSize];
340 | ourBuffer = true;
341 | }
342 |
343 | UInt64 remain = in->GetLength();
344 |
345 | while (remain > 0)
346 | {
347 | UInt64 transferSize = remain;
348 |
349 | if (transferSize > bufferSize)
350 | transferSize = bufferSize;
351 |
352 | in->ReadBuf(buf, transferSize);
353 | out->WriteBuf(buf, transferSize);
354 |
355 | remain -= transferSize;
356 | }
357 |
358 | if (ourBuffer)
359 | delete[] buf;
360 | }
361 |
362 | void IDataStream::CopySubStreams(IDataStream* out, IDataStream* in, UInt64 remain, UInt64 bufferSize, UInt8* buf)
363 | {
364 | bool ourBuffer = false;
365 |
366 | if (!buf)
367 | {
368 | buf = new UInt8[bufferSize];
369 | ourBuffer = true;
370 | }
371 |
372 | while (remain > 0)
373 | {
374 | UInt64 transferSize = remain;
375 |
376 | if (transferSize > bufferSize)
377 | transferSize = bufferSize;
378 |
379 | in->ReadBuf(buf, transferSize);
380 | out->WriteBuf(buf, transferSize);
381 |
382 | remain -= transferSize;
383 | }
384 |
385 | if (ourBuffer)
386 | delete[] buf;
387 | }
388 |
389 | /**** IDataStream_PositionSaver ***********************************************/
390 |
391 | /**
392 | * The constructor; save the stream's position
393 | */
394 | IDataStream_PositionSaver::IDataStream_PositionSaver(IDataStream* tgt)
395 | {
396 | stream = tgt;
397 | offset = tgt->GetOffset();
398 | }
399 |
400 | /**
401 | * The destructor; restore the stream's saved position
402 | */
403 | IDataStream_PositionSaver::~IDataStream_PositionSaver()
404 | {
405 | stream->SetOffset(offset);
406 | }
407 |
408 | /**** IDataSubStream **********************************************************/
409 |
410 | IDataSubStream::IDataSubStream()
411 | :stream(NULL), subBase(0)
412 | {
413 | //
414 | }
415 |
416 | IDataSubStream::IDataSubStream(IDataStream* inStream, SInt64 inOffset, SInt64 inLength)
417 | {
418 | stream = inStream;
419 | subBase = inOffset;
420 | streamLength = inLength;
421 |
422 | stream->SetOffset(inOffset);
423 | }
424 |
425 | IDataSubStream::~IDataSubStream()
426 | {
427 | }
428 |
429 | void IDataSubStream::Attach(IDataStream* inStream, SInt64 inOffset, SInt64 inLength)
430 | {
431 | stream = inStream;
432 | subBase = inOffset;
433 | streamLength = inLength;
434 |
435 | stream->SetOffset(inOffset);
436 | }
437 |
438 | void IDataSubStream::ReadBuf(void* buf, UInt32 inLength)
439 | {
440 | ASSERT_STR(inLength <= GetRemain(), "IDataSubStream::ReadBuf: hit eof");
441 |
442 | if (stream->GetOffset() != subBase + streamOffset)
443 | stream->SetOffset(subBase + streamOffset);
444 |
445 | stream->ReadBuf(buf, inLength);
446 |
447 | streamOffset += inLength;
448 | }
449 |
450 | void IDataSubStream::WriteBuf(const void* buf, UInt32 inLength)
451 | {
452 | if (stream->GetOffset() != subBase + streamOffset)
453 | stream->SetOffset(subBase + streamOffset);
454 |
455 | stream->WriteBuf(buf, inLength);
456 |
457 | streamOffset += inLength;
458 |
459 | if (streamLength < streamOffset)
460 | streamLength = streamOffset;
461 | }
462 |
463 | void IDataSubStream::SetOffset(SInt64 inOffset)
464 | {
465 | stream->SetOffset(subBase + inOffset);
466 | streamOffset = inOffset;
467 | }
--------------------------------------------------------------------------------
/common/IDataStream.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "common/IErrors.h"
4 |
5 | /**
6 | * An arbitrary data stream
7 | */
8 | class IDataStream
9 | {
10 | public:
11 | IDataStream();
12 | virtual ~IDataStream();
13 |
14 | // read
15 | virtual UInt8 Read8(void);
16 | virtual UInt16 Read16(void);
17 | virtual UInt32 Read32(void);
18 | virtual UInt64 Read64(void);
19 | virtual float ReadFloat(void);
20 | virtual UInt32 ReadString(char* buf, UInt32 bufLength, char altTerminator = 0, char altTerminator2 = 0);
21 | virtual void ReadBuf(void* buf, UInt32 inLength) = 0;
22 |
23 | // peek
24 | virtual UInt8 Peek8(void);
25 | virtual UInt16 Peek16(void);
26 | virtual UInt32 Peek32(void);
27 | virtual UInt64 Peek64(void);
28 | virtual float PeekFloat(void);
29 | virtual void PeekBuf(void* buf, UInt32 inLength);
30 |
31 | virtual void Skip(SInt64 inBytes);
32 |
33 | // write
34 | virtual void Write8(UInt8 inData);
35 | virtual void Write16(UInt16 inData);
36 | virtual void Write32(UInt32 inData);
37 | virtual void Write64(UInt64 inData);
38 | virtual void WriteFloat(float inData);
39 | virtual void WriteString(const char* buf);
40 | virtual void WriteBuf(const void* buf, UInt32 inLength) = 0;
41 |
42 | SInt64 GetLength(void);
43 | SInt64 GetRemain(void);
44 | SInt64 GetOffset(void);
45 | bool HitEOF(void);
46 |
47 | virtual void SetOffset(SInt64 inOffset);
48 | void Rewind(void) { SetOffset(0); }
49 |
50 | void SwapBytes(bool inSwapBytes);
51 |
52 | virtual SInt64 GetParentOffset(void) { return GetOffset(); }
53 | virtual IDataStream* GetParent(void) { return NULL; }
54 |
55 | IDataStream* GetRootParent(void);
56 |
57 | static void CopyStreams(IDataStream* out, IDataStream* in, UInt64 bufferSize = 1024 * 1024, UInt8* buf = NULL);
58 | static void CopySubStreams(IDataStream* out, IDataStream* in, UInt64 remain, UInt64 bufferSize = 1024 * 1024, UInt8* buf = NULL);
59 |
60 | protected:
61 | SInt64 streamLength;
62 | SInt64 streamOffset;
63 | bool swapBytes;
64 | };
65 |
66 | /**
67 | * A utility class to automatically save and restore the current position of an IDataStream
68 | */
69 | class IDataStream_PositionSaver
70 | {
71 | public:
72 | IDataStream_PositionSaver(IDataStream* tgt);
73 | ~IDataStream_PositionSaver();
74 |
75 | private:
76 | IDataStream* stream;
77 | SInt64 offset;
78 | };
79 |
80 | class IDataSubStream : public IDataStream
81 | {
82 | public:
83 | IDataSubStream();
84 | IDataSubStream(IDataStream* inStream, SInt64 inOffset, SInt64 inLength);
85 | ~IDataSubStream();
86 |
87 | void Attach(IDataStream* inStream, SInt64 inOffset, SInt64 inLength);
88 |
89 | void ReadBuf(void* buf, UInt32 inLength);
90 | void WriteBuf(const void* buf, UInt32 inLength);
91 | void SetOffset(SInt64 inOffset);
92 |
93 | virtual SInt64 GetParentOffset(void) { return stream->GetOffset(); }
94 | virtual IDataStream* GetParent(void) { return stream; }
95 |
96 | SInt64 GetSubBase(void) { return subBase; }
97 |
98 | private:
99 | IDataStream* stream;
100 |
101 | SInt64 subBase;
102 | };
103 |
--------------------------------------------------------------------------------
/common/IDebugLog.cpp:
--------------------------------------------------------------------------------
1 | #include "common/IDebugLog.h"
2 | #include
3 | #include "common/IFileStream.h"
4 | #include
5 |
6 | std::FILE* IDebugLog::logFile = NULL;
7 | char IDebugLog::sourceBuf[16] = { 0 };
8 | char IDebugLog::headerText[16] = { 0 };
9 | char IDebugLog::formatBuf[8192] = { 0 };
10 | int IDebugLog::indentLevel = 0;
11 | int IDebugLog::rightMargin = 0;
12 | int IDebugLog::cursorPos = 0;
13 | int IDebugLog::inBlock = 0;
14 | bool IDebugLog::autoFlush = true;
15 | IDebugLog::LogLevel IDebugLog::logLevel = IDebugLog::kLevel_DebugMessage;
16 | IDebugLog::LogLevel IDebugLog::printLevel = IDebugLog::kLevel_Message;
17 |
18 | IDebugLog::IDebugLog()
19 | {
20 | //
21 | }
22 |
23 | IDebugLog::IDebugLog(const char* name)
24 | {
25 | Open(name);
26 | }
27 |
28 | IDebugLog::~IDebugLog()
29 | {
30 | if (logFile)
31 | fclose(logFile);
32 | }
33 |
34 | void IDebugLog::Open(const char* path)
35 | {
36 | logFile = _fsopen(path, "w", _SH_DENYWR);
37 |
38 | if (!logFile)
39 | {
40 | UInt32 id = 0;
41 | char name[1024];
42 |
43 | do
44 | {
45 | sprintf_s(name, sizeof(name), "%s%d", path, id);
46 | id++;
47 |
48 | logFile = NULL;
49 | logFile = _fsopen(name, "w", _SH_DENYWR);
50 | } while (!logFile && (id < 5));
51 | }
52 | }
53 |
54 | void IDebugLog::OpenRelative(int folderID, const char* relPath)
55 | {
56 | char path[MAX_PATH];
57 |
58 | ASSERT(SUCCEEDED(SHGetFolderPath(NULL, folderID, NULL, SHGFP_TYPE_CURRENT, path)));
59 |
60 | strcat_s(path, sizeof(path), relPath);
61 |
62 | IFileStream::MakeAllDirs(path);
63 |
64 | Open(path);
65 | }
66 |
67 | /**
68 | * Output a non-formatted message to the log file
69 | *
70 | * @param message the message
71 | * @param source the source of the message, or NULL to use the previous source
72 | */
73 | void IDebugLog::Message(const char* message, const char* source)
74 | {
75 | if (source)
76 | SetSource(source);
77 |
78 | if (inBlock)
79 | {
80 | SeekCursor(RoundToTab((indentLevel * 4) + strlen(headerText)));
81 | }
82 | else
83 | {
84 | SeekCursor(indentLevel * 4);
85 |
86 | PrintText(headerText);
87 | }
88 |
89 | PrintText(message);
90 | NewLine();
91 | }
92 |
93 | /**
94 | * Output a formatted message to the log file
95 | *
96 | * @note It is impossible to set the source of a formatted message.
97 | * The previous source will be used.
98 | */
99 | void IDebugLog::FormattedMessage(const char* fmt, ...)
100 | {
101 | va_list argList;
102 |
103 | va_start(argList, fmt);
104 | vsprintf_s(formatBuf, sizeof(formatBuf), fmt, argList);
105 | Message(formatBuf);
106 | va_end(argList);
107 | }
108 |
109 | /**
110 | * Output a formatted message to the log file
111 | *
112 | * @note It is impossible to set the source of a formatted message.
113 | * The previous source will be used.
114 | */
115 | void IDebugLog::FormattedMessage(const char* fmt, va_list args)
116 | {
117 | vsprintf_s(formatBuf, sizeof(formatBuf), fmt, args);
118 | Message(formatBuf);
119 | }
120 |
121 | void IDebugLog::Log(LogLevel level, const char* fmt, va_list args)
122 | {
123 | bool log = (level <= logLevel);
124 | bool print = (level <= printLevel);
125 |
126 | if (log || print)
127 | vsprintf_s(formatBuf, sizeof(formatBuf), fmt, args);
128 |
129 | if (log)
130 | Message(formatBuf);
131 |
132 | if (print)
133 | printf("%s\n", formatBuf);
134 | }
135 |
136 | /**
137 | * Set the current message source
138 | */
139 | void IDebugLog::SetSource(const char* source)
140 | {
141 | strcpy_s(sourceBuf, sizeof(sourceBuf), source);
142 | strcpy_s(headerText, sizeof(headerText), "[ ]\t");
143 |
144 | char* tgt = headerText + 1;
145 | char* src = sourceBuf;
146 |
147 | for (int i = 0; (i < 8) && *src; i++, tgt++, src++)
148 | *tgt = *src;
149 | }
150 |
151 | /**
152 | * Clear the current message source
153 | */
154 | void IDebugLog::ClearSource(void)
155 | {
156 | sourceBuf[0] = 0;
157 | }
158 |
159 | /**
160 | * Increase the indentation level
161 | */
162 | void IDebugLog::Indent(void)
163 | {
164 | indentLevel++;
165 | }
166 |
167 | /**
168 | * Decrease the indentation level
169 | */
170 | void IDebugLog::Outdent(void)
171 | {
172 | if (indentLevel)
173 | indentLevel--;
174 | }
175 |
176 | /**
177 | * Enter a logical block
178 | */
179 | void IDebugLog::OpenBlock(void)
180 | {
181 | SeekCursor(indentLevel * 4);
182 |
183 | PrintText(headerText);
184 |
185 | inBlock = 1;
186 | }
187 |
188 | /**
189 | * Close a logical block
190 | */
191 | void IDebugLog::CloseBlock(void)
192 | {
193 | inBlock = 0;
194 | }
195 |
196 | /**
197 | * Enable/disable autoflush
198 | *
199 | * @param inAutoFlush autoflush state
200 | */
201 | void IDebugLog::SetAutoFlush(bool inAutoFlush)
202 | {
203 | autoFlush = inAutoFlush;
204 | }
205 |
206 | /**
207 | * Print spaces to the log
208 | *
209 | * If possible, tabs are used instead of spaces.
210 | */
211 | void IDebugLog::PrintSpaces(int numSpaces)
212 | {
213 | int originalNumSpaces = numSpaces;
214 |
215 | if (logFile)
216 | {
217 | while (numSpaces > 0)
218 | {
219 | if (numSpaces >= TabSize())
220 | {
221 | numSpaces -= TabSize();
222 | fputc('\t', logFile);
223 | }
224 | else
225 | {
226 | numSpaces--;
227 | fputc(' ', logFile);
228 | }
229 | }
230 | }
231 |
232 | cursorPos += originalNumSpaces;
233 | }
234 |
235 | /**
236 | * Prints raw text to the log file
237 | */
238 | void IDebugLog::PrintText(const char* buf)
239 | {
240 | if (logFile)
241 | {
242 | fputs(buf, logFile);
243 | if (autoFlush)
244 | fflush(logFile);
245 | }
246 |
247 | const char* traverse = buf;
248 | char data;
249 |
250 | while (data = *traverse++)
251 | {
252 | if (data == '\t')
253 | cursorPos += TabSize();
254 | else
255 | cursorPos++;
256 | }
257 | }
258 |
259 | /**
260 | * Moves to the next line of the log file
261 | */
262 | void IDebugLog::NewLine(void)
263 | {
264 | if (logFile)
265 | {
266 | fputc('\n', logFile);
267 |
268 | if (autoFlush)
269 | fflush(logFile);
270 | }
271 |
272 | cursorPos = 0;
273 | }
274 |
275 | /**
276 | * Prints spaces to align the cursor to the requested position
277 | *
278 | * @note The cursor move will not be performed if the request would move the cursor
279 | * backwards.
280 | */
281 | void IDebugLog::SeekCursor(int position)
282 | {
283 | if (position > cursorPos)
284 | PrintSpaces(position - cursorPos);
285 | }
286 |
287 | /**
288 | * Returns the number of spaces a tab would occupy at the current cursor position
289 | */
290 | int IDebugLog::TabSize(void)
291 | {
292 | return ((~cursorPos) & 3) + 1;
293 | }
294 |
295 | /**
296 | * Rounds a number of spaces to the nearest tab
297 | */
298 | int IDebugLog::RoundToTab(int spaces)
299 | {
300 | return (spaces + 3) & ~3;
301 | }
--------------------------------------------------------------------------------
/common/IDebugLog.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | /**
6 | * A simple debug log file
7 | *
8 | * This class supports prefix blocks describing the source of the log event.
9 | * It also allows logical blocks and outlining.\n
10 | */
11 | class IDebugLog
12 | {
13 | public:
14 | IDebugLog();
15 | IDebugLog(const char* name);
16 | ~IDebugLog();
17 |
18 | static void Open(const char* path);
19 | static void OpenRelative(int folderID, const char* relPath);
20 |
21 | static void Message(const char* message, const char* source = NULL);
22 | static void FormattedMessage(const char* fmt, ...);
23 | static void FormattedMessage(const char* fmt, va_list args);
24 |
25 | enum LogLevel
26 | {
27 | kLevel_FatalError = 0,
28 | kLevel_Error,
29 | kLevel_Warning,
30 | kLevel_Message,
31 | kLevel_VerboseMessage,
32 | kLevel_DebugMessage
33 | };
34 |
35 | static void Log(LogLevel level, const char* fmt, va_list args);
36 |
37 | static void SetSource(const char* source);
38 | static void ClearSource(void);
39 |
40 | static void Indent(void);
41 | static void Outdent(void);
42 |
43 | static void OpenBlock(void);
44 | static void CloseBlock(void);
45 |
46 | static void SetAutoFlush(bool inAutoFlush);
47 |
48 | static void SetLogLevel(LogLevel in) { logLevel = in; }
49 | static void SetPrintLevel(LogLevel in) { printLevel = in; }
50 |
51 | private:
52 | static void PrintSpaces(int numSpaces);
53 | static void PrintText(const char* buf);
54 | static void NewLine(void);
55 |
56 | static void SeekCursor(int position);
57 |
58 | static int TabSize(void);
59 | static int RoundToTab(int spaces);
60 |
61 | static FILE* logFile; //!< the output file
62 |
63 | static char sourceBuf[16]; //!< name of current source, used in prefix
64 | static char headerText[16]; //!< current text to use as line prefix
65 | static char formatBuf[8192]; //!< temp buffer used for formatted messages
66 |
67 | static int indentLevel; //!< the current indentation level (in tabs)
68 | static int rightMargin; //!< the column at which text should be wrapped
69 | static int cursorPos; //!< current cursor position
70 | static int inBlock; //!< are we in a block?
71 |
72 | static bool autoFlush; //!< automatically flush the file after writing
73 |
74 | static LogLevel logLevel; //!< least important log level to write
75 | static LogLevel printLevel; //!< least important log level to print
76 | };
77 |
78 | extern IDebugLog gLog;
79 |
80 | inline void _FATALERROR(const char* fmt, ...)
81 | {
82 | va_list args;
83 |
84 | va_start(args, fmt);
85 | gLog.Log(IDebugLog::kLevel_FatalError, fmt, args);
86 | va_end(args);
87 | }
88 |
89 | inline void _ERROR(const char* fmt, ...)
90 | {
91 | va_list args;
92 |
93 | va_start(args, fmt);
94 | gLog.Log(IDebugLog::kLevel_Error, fmt, args);
95 | va_end(args);
96 | }
97 |
98 | inline void _WARNING(const char* fmt, ...)
99 | {
100 | va_list args;
101 |
102 | va_start(args, fmt);
103 | gLog.Log(IDebugLog::kLevel_Warning, fmt, args);
104 | va_end(args);
105 | }
106 |
107 | inline void _MESSAGE(const char* fmt, ...)
108 | {
109 | va_list args;
110 |
111 | va_start(args, fmt);
112 | gLog.Log(IDebugLog::kLevel_Message, fmt, args);
113 | va_end(args);
114 | }
115 |
116 | inline void _VMESSAGE(const char* fmt, ...)
117 | {
118 | va_list args;
119 |
120 | va_start(args, fmt);
121 | gLog.Log(IDebugLog::kLevel_VerboseMessage, fmt, args);
122 | va_end(args);
123 | }
124 |
125 | inline void _DMESSAGE(const char* fmt, ...)
126 | {
127 | va_list args;
128 |
129 | va_start(args, fmt);
130 | gLog.Log(IDebugLog::kLevel_DebugMessage, fmt, args);
131 | va_end(args);
132 | }
133 |
--------------------------------------------------------------------------------
/common/IDynamicCreate.cpp:
--------------------------------------------------------------------------------
1 | #include "IDynamicCreate.h"
2 |
3 | #if ENABLE_IDYNAMICCREATE
4 |
5 | IClassRegistry _gClassRegistry;
6 |
7 | IClassRegistry::IClassRegistry()
8 | {
9 | //
10 | }
11 |
12 | IClassRegistry::~IClassRegistry()
13 | {
14 | //
15 | }
16 |
17 | void IClassRegistry::RegisterClassInfo(UInt32 id, IDynamicType* typeInfo)
18 | {
19 | theClassRegistry[id] = typeInfo;
20 | }
21 |
22 | IDynamicType* IClassRegistry::LookupClassInfo(UInt32 id)
23 | {
24 | ClassRegistryType::iterator iter = theClassRegistry.find(id);
25 |
26 | return (iter == theClassRegistry.end()) ? NULL : (*iter).second;
27 | }
28 |
29 | IDynamicType* IClassRegistry::LookupClassInfo(char* name)
30 | {
31 | for (ClassRegistryType::iterator iter = theClassRegistry.begin(); iter != theClassRegistry.end(); iter++)
32 | if (!strcmp((*iter).second->GetName(), name))
33 | return (*iter).second;
34 |
35 | return NULL;
36 | }
37 |
38 | #endif
--------------------------------------------------------------------------------
/common/IDynamicCreate.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include