├── .gitattributes ├── .github ├── CODEOWNERS ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── ci.yml ├── .gitignore ├── .gitmodules ├── DraculaDominus.py ├── LICENSE ├── LICENSES.txt ├── M2Debug.py ├── M2Install.py ├── M2Install.yml ├── M2Package.bat ├── M2Patch.py ├── M2Test.py ├── MGSM2Fix.ini ├── MGSM2Fix.rc ├── MGSM2Fix.sln ├── MGSM2Fix.vcxproj ├── MGSM2Fix.vcxproj.filters ├── README.md ├── build_zydis.cmd ├── game_actions_2131630.vdf ├── requirements.txt ├── resource.h └── src ├── FunctionTraits ├── CompilerVersions.cppm ├── CompilerVersions.h ├── Demo.cpp ├── LICENSE ├── README.md ├── TypeTraits.cppm └── TypeTraits.h ├── analog.cpp ├── analog.h ├── borderless.cpp ├── borderless.h ├── config.cpp ├── config.h ├── d3d11.cpp ├── d3d11.h ├── d3d11PixelUpscaler.hlsl ├── d3d11VertexUpscaler.hlsl ├── dllmain.cpp ├── epi.cpp ├── epi.h ├── ketchup.cpp ├── ketchup.h ├── m2 ├── epi.h └── psx.h ├── m2config.cpp ├── m2config.h ├── m2fix.h ├── m2fixbase.h ├── m2game.h ├── m2hook.h ├── m2machine.h ├── m2utils.cpp ├── m2utils.h ├── mgs1.cpp ├── mgs1.h ├── psx.cpp ├── psx.h ├── sqbinary.h ├── sqemutask.h ├── sqglobals.h ├── sqhelper.h ├── sqhook.cpp ├── sqhook.h ├── sqinput.h ├── sqinputhub.h ├── sqinvoker.h ├── sqrat ├── Doxyfile ├── README.txt ├── gtest-1.3.0 │ ├── CHANGES │ ├── CONTRIBUTORS │ ├── COPYING │ ├── README │ ├── build_gtest.sh │ ├── include │ │ └── gtest │ │ │ ├── gtest-death-test.h │ │ │ ├── gtest-message.h │ │ │ ├── gtest-param-test.h │ │ │ ├── gtest-param-test.h.pump │ │ │ ├── gtest-spi.h │ │ │ ├── gtest-test-part.h │ │ │ ├── gtest-typed-test.h │ │ │ ├── gtest.h │ │ │ ├── gtest_pred_impl.h │ │ │ ├── gtest_prod.h │ │ │ └── internal │ │ │ ├── gtest-death-test-internal.h │ │ │ ├── gtest-filepath.h │ │ │ ├── gtest-internal.h │ │ │ ├── gtest-linked_ptr.h │ │ │ ├── gtest-param-util-generated.h │ │ │ ├── gtest-param-util-generated.h.pump │ │ │ ├── gtest-param-util.h │ │ │ ├── gtest-port.h │ │ │ ├── gtest-string.h │ │ │ ├── gtest-type-util.h │ │ │ └── gtest-type-util.h.pump │ ├── msvc │ │ └── gtest.vcproj │ └── src │ │ ├── gtest-all.cc │ │ ├── gtest-death-test.cc │ │ ├── gtest-filepath.cc │ │ ├── gtest-internal-inl.h │ │ ├── gtest-port.cc │ │ ├── gtest-test-part.cc │ │ ├── gtest-typed-test.cc │ │ ├── gtest.cc │ │ └── gtest_main.cc ├── include │ ├── sqmodule.h │ ├── sqrat.h │ ├── sqrat │ │ ├── sqratAllocator.h │ │ ├── sqratArray.h │ │ ├── sqratClass.h │ │ ├── sqratClassType.h │ │ ├── sqratConst.h │ │ ├── sqratFunction.h │ │ ├── sqratGlobalMethods.h │ │ ├── sqratMemberMethods.h │ │ ├── sqratObject.h │ │ ├── sqratOverloadMethods.h │ │ ├── sqratScript.h │ │ ├── sqratTable.h │ │ ├── sqratTypes.h │ │ ├── sqratUtil.h │ │ └── sqratVM.h │ └── sqratimport.h ├── running_tests.txt ├── sq │ ├── sq.c │ └── sq.vcproj ├── sqimport │ ├── sqratimport.cpp │ └── sqratimport.vcproj ├── sqrat.sln ├── sqrattest │ ├── ArrayBinding.cpp │ ├── ClassBinding.cpp │ ├── ClassInstances.cpp │ ├── ClassProperties.cpp │ ├── ConstBindings.cpp │ ├── Fixture.h │ ├── FuncInputArgumentType.cpp │ ├── FunctionOverload.cpp │ ├── FunctionParams.cpp │ ├── ImportTest.cpp │ ├── Main.cpp │ ├── NullPointerReturn.cpp │ ├── RunStackHandling.cpp │ ├── ScriptLoading.cpp │ ├── SqratVM.cpp │ ├── SqratVM2.cpp │ ├── SquirrelFunctions.cpp │ ├── SuspendVM.cpp │ ├── TableBinding.cpp │ ├── UniqueObject.cpp │ ├── Vector.cpp │ ├── Vector.h │ ├── build_tests.sh │ ├── build_tests_msys.sh │ ├── run_tests.sh │ ├── scripts │ │ ├── hello.nut │ │ └── samplemodule.nut │ └── sqrattest.vcproj └── sqratthread │ ├── sqratThread.cpp │ ├── sqratThread.h │ └── sqratthread.vcproj ├── sqsystemdata.h ├── sqsystemprof.h ├── sqtitleprof.h ├── sqtrace.cpp ├── squirk.h ├── squirrel ├── COPYRIGHT ├── include │ ├── sqstdaux.h │ ├── sqstdblob.h │ ├── sqstdio.h │ ├── sqstdmath.h │ ├── sqstdstring.h │ ├── sqstdsystem.h │ └── squirrel.h ├── sqdbg │ ├── serialize_state.nut │ ├── sqdbgserver.cpp │ ├── sqdbgserver.h │ ├── sqrdbg.cpp │ └── sqrdbg.h ├── sqstdlib │ ├── sqstdaux.cpp │ ├── sqstdblob.cpp │ ├── sqstdblobimpl.h │ ├── sqstdio.cpp │ ├── sqstdmath.cpp │ ├── sqstdrex.cpp │ ├── sqstdstream.cpp │ ├── sqstdstream.h │ ├── sqstdstring.cpp │ └── sqstdsystem.cpp └── squirrel │ ├── sqapi.cpp │ ├── sqarray.h │ ├── sqbaselib.cpp │ ├── sqclass.cpp │ ├── sqclass.h │ ├── sqclosure.h │ ├── sqcompiler.cpp │ ├── sqcompiler.h │ ├── sqdebug.cpp │ ├── sqfuncproto.h │ ├── sqfuncstate.cpp │ ├── sqfuncstate.h │ ├── sqlexer.cpp │ ├── sqlexer.h │ ├── sqmem.cpp │ ├── sqobject.cpp │ ├── sqobject.h │ ├── sqopcodes.h │ ├── sqpcheader.h │ ├── sqstate.cpp │ ├── sqstate.h │ ├── sqstring.h │ ├── sqtable.cpp │ ├── sqtable.h │ ├── squserdata.h │ ├── squtils.h │ ├── sqvm.cpp │ └── sqvm.h ├── stdafx.cpp ├── stdafx.h ├── versionchecker.cpp ├── versionchecker.h ├── warning_background_shuffle.cpp └── warning_background_shuffle.hpp /.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 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @nuggslet 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | ko_fi: nuggs 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help reproduce and fix the issue 4 | title: '[Bug]: ' 5 | labels: ["bug"] 6 | --- 7 | 8 | 9 | ## Issue Summary: 10 | 11 | 12 | 13 | ## MGSM2Fix & Game Version Number: 14 | 15 | 16 | 17 | ## Log Files: 18 | 19 | 20 | 21 | ## Reproduction: 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '[Feature Request]: ' 5 | labels: ["enhancement"] 6 | --- 7 | 8 | 9 | ## Feature Summary: 10 | 11 | 12 | 13 | ### Is your proposal related to a problem? 14 | 15 | 16 | 17 | ### Describe the solution you'd like 18 | 19 | 20 | 21 | ### Describe alternatives you've considered 22 | 23 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/imgui"] 2 | path = src/imgui 3 | url = https://github.com/ocornut/imgui 4 | [submodule "src/spdlog"] 5 | path = src/spdlog 6 | url = https://github.com/gabime/spdlog 7 | [submodule "src/inipp"] 8 | path = src/inipp 9 | url = https://github.com/mcmtroffaes/inipp 10 | [submodule "src/zydis"] 11 | path = src/zydis 12 | url = https://github.com/zyantific/zydis 13 | [submodule "src/safetyhook"] 14 | path = src/safetyhook 15 | url = https://github.com/cursey/safetyhook 16 | -------------------------------------------------------------------------------- /DraculaDominus.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | '''DraculaDominus.py: ROM extraction utility for M2ENGAGE [Castlevania Dominus Collection].''' 4 | 5 | import os 6 | import json 7 | 8 | __author__ = 'nuggslet' 9 | __license__ = 'MIT' 10 | 11 | def dracula_unpack(src, dst): 12 | files = os.path.join(src, 'files.bin') 13 | files = open(files, 'rb') 14 | meta = os.path.join(src, 'files_info.psb.json') 15 | meta = open(meta, 'r') 16 | 17 | meta = json.load(meta) 18 | for info in meta['list']: 19 | files.seek(info['offset']) 20 | data = files.read(info['bytes']) 21 | path = info['path'].lstrip('/\\') 22 | path = os.path.join(dst, path) 23 | path = os.path.normpath(path) 24 | 25 | os.makedirs(os.path.dirname(path), exist_ok=True) 26 | file = open(path, 'wb') 27 | file.write(data) 28 | file.close() 29 | 30 | def main(): 31 | import argparse 32 | parser = argparse.ArgumentParser('DraculaDominus', description='ROM extraction utility for M2ENGAGE [Castlevania Dominus Collection]') 33 | 34 | parser.add_argument('src') 35 | parser.add_argument('dst') 36 | 37 | args = parser.parse_args() 38 | dracula_unpack(args.src, args.dst) 39 | 40 | if __name__ == '__main__': 41 | main() 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023-2025 nuggslet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /M2Debug.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | '''M2Debug.py: Debugger for M2ENGAGE [Metal Gear Solid].''' 4 | 5 | import socket 6 | 7 | __author__ = 'nuggslet' 8 | __license__ = 'MIT' 9 | 10 | class M2Debug: 11 | def __init__(self, socket): 12 | self.s = socket 13 | 14 | def ready(self): 15 | msg = b'rd\n' 16 | self.s.send(msg) 17 | 18 | def evaluate(self, closure): 19 | closure = closure.replace('\r', '').replace('\n', '') 20 | msg = b'ev:%s\0\n' % closure.encode('ascii') 21 | r = self.s.makefile('r') 22 | self.s.send(msg) 23 | return r.readline() 24 | 25 | def main(): 26 | import argparse 27 | parser = argparse.ArgumentParser('M2Debug', description='Debugger for M2ENGAGE [Metal Gear Solid]') 28 | 29 | parser.add_argument('--host', default='127.0.0.1') 30 | parser.add_argument('--port', type=int, default=27615) 31 | args = parser.parse_args() 32 | 33 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 34 | s.connect((args.host, args.port)) 35 | s = M2Debug(s) 36 | 37 | s.ready() 38 | while True: 39 | print(s.evaluate(input('> '))) 40 | 41 | if __name__ == "__main__": 42 | main() 43 | -------------------------------------------------------------------------------- /M2Install.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | '''M2Install.py: Installer utility for M2Fix.''' 4 | 5 | import os 6 | import sys 7 | import yaml 8 | import shutil 9 | import zipfile 10 | 11 | __author__ = 'nuggslet' 12 | __license__ = 'MIT' 13 | 14 | def main(): 15 | import argparse 16 | parser = argparse.ArgumentParser('M2Install', description='Installer utility for M2Fix') 17 | 18 | parser.add_argument('file', nargs='?') 19 | parser.add_argument('arch', nargs='?') 20 | parser.add_argument('--package', action='store_true') 21 | args = parser.parse_args() 22 | 23 | rules = os.path.join(os.path.dirname(__file__), 'M2Install.yml') 24 | rules = open(rules, 'r', encoding='utf-8') 25 | rules = yaml.load(rules, Loader=yaml.Loader) 26 | 27 | if args.package: 28 | file = os.path.realpath(__file__) 29 | file = os.path.dirname(file) 30 | file = os.path.join(file, 'MGSM2Fix.zip') 31 | file = zipfile.ZipFile(file, 'r') 32 | for arch in rules: 33 | for rule in rules[arch]: 34 | if os.path.isfile(rule): os.remove(rule) 35 | rule = os.path.dirname(rule) 36 | file.extractall(rule) 37 | file.close() 38 | else: 39 | if args.arch not in rules: return 40 | for rule in rules[args.arch]: 41 | shutil.copy(args.file, rule) 42 | rule = os.path.dirname(rule) 43 | file = os.path.join(rule, 'MGSM2Fix32.asi') 44 | if os.path.isfile(file): os.remove(file) 45 | file = os.path.join(rule, 'MGSM2Fix64.asi') 46 | if os.path.isfile(file): os.remove(file) 47 | 48 | if __name__ == "__main__": 49 | if 'GITHUB_WORKSPACE' in os.environ: sys.exit() 50 | main() 51 | -------------------------------------------------------------------------------- /M2Install.yml: -------------------------------------------------------------------------------- 1 | # M2Install.yaml: install manifest for M2Fix development. 2 | # This is nuggs's personal manifest, so it isn't immediately useful to anyone else, but it's here to serve as an example. 3 | x64: 4 | - F:\Steam\steamapps\common\MGS Master Collection Bonus Content\MGSM2Fix.asi 5 | - I:\Steam\steamapps\common\Castlevania Dominus Collection\MGSM2Fix.asi 6 | - F:\Steam\steamapps\common\Ray’z Arcade Chronology\MGSM2Fix.asi 7 | - F:\Steam\steamapps\common\GRADIUS origin collection\MGSM2Fix.asi 8 | x86: 9 | - F:\Steam\steamapps\common\MGS1\MGSM2Fix.asi 10 | - I:\Steam\steamapps\common\Contra Anniversary Collection\MGSM2Fix.asi 11 | - I:\Steam\steamapps\common\Castlevania Advance Collection\MGSM2Fix.asi 12 | - I:\Steam\steamapps\common\Castlevania Anniversary Collection\MGSM2Fix.asi 13 | - F:\Steam\steamapps\common\Darius Cozmic Collection Arcade\MGSM2Fix.asi 14 | - F:\Steam\steamapps\common\G-Darius HD\MGSM2Fix.asi 15 | - F:\Steam\steamapps\common\Operation Night Strikers\MGSM2Fix.asi 16 | - E:\Epic Games\CastlevaniaAnniversaXJ2A3\MGSM2Fix.asi 17 | -------------------------------------------------------------------------------- /M2Package.bat: -------------------------------------------------------------------------------- 1 | REM M2Package.bat: Release archive packager for M2Fix. 2 | 3 | @echo off 4 | pushd "%~dp0" 5 | 6 | for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -products * -latest -requires Microsoft.Component.MSBuild`) do ( 7 | if /i "%%i"=="installationPath" ( 8 | set vsdir=%%j 9 | ) 10 | ) 11 | 12 | echo %vsdir% 13 | 14 | if exist "%vsdir%\Common7\Tools\VsMSBuildCmd.bat" ( 15 | call "%vsdir%\Common7\Tools\VsMSBuildCmd" 16 | cd "%~dp0" 17 | ) 18 | 19 | REM Clean builds 20 | echo -------------------------------------------------------- 21 | echo [INFO] Cleaning previous builds… 22 | MSBuild MGSM2Fix.sln /p:Configuration=Debug /p:Platform=x86 /t:Clean /verbosity:minimal 23 | MSBuild MGSM2Fix.sln /p:Configuration=Debug /p:Platform=x64 /t:Clean /verbosity:minimal 24 | MSBuild MGSM2Fix.sln /p:Configuration=Release /p:Platform=x86 /t:Clean /verbosity:minimal 25 | MSBuild MGSM2Fix.sln /p:Configuration=Release /p:Platform=x64 /t:Clean /verbosity:minimal 26 | 27 | REM Build 28 | echo -------------------------------------------------------- 29 | echo [INFO] Building Release/x86… 30 | MSBuild MGSM2Fix.sln /p:Configuration=Release /p:Platform=x86 /verbosity:minimal 31 | if errorlevel 1 ( 32 | echo [ERROR] Build failed for Release x86. 33 | exit /b 1 34 | ) 35 | 36 | echo [INFO] Building Release/x64… 37 | MSBuild MGSM2Fix.sln /p:Configuration=Release /p:Platform=x64 /verbosity:minimal 38 | if errorlevel 1 ( 39 | echo [ERROR] Build failed for Release x64. 40 | exit /b 1 41 | ) 42 | 43 | echo -------------------------------------------------------- 44 | echo [INFO] Building Debug/x86… 45 | MSBuild MGSM2Fix.sln /p:Configuration=Debug /p:Platform=x86 /verbosity:minimal 46 | if errorlevel 1 ( 47 | echo [ERROR] Build failed for Debug x86. 48 | exit /b 1 49 | ) 50 | 51 | echo [INFO] Building Debug/x64… 52 | MSBuild MGSM2Fix.sln /p:Configuration=Debug /p:Platform=x64 /verbosity:minimal 53 | if errorlevel 1 ( 54 | echo [ERROR] Build failed for Debug x64. 55 | exit /b 1 56 | ) 57 | 58 | echo -------------------------------------------------------- 59 | echo [INFO] Cleaning and preparing dist\ folder… 60 | if exist dist\ ( 61 | rd /S /Q dist\ 62 | ) 63 | md dist\ 64 | 65 | echo -------------------------------------------------------- 66 | if defined GITHUB_WORKSPACE ( 67 | echo [INFO] GITHUB_WORKSPACE detected — copying ASI Loader files… 68 | xcopy /I /Y /F loader\* dist\ 69 | if errorlevel 1 ( 70 | echo [ERROR] Failed to copy loader\ to dist\ 71 | exit /b 1 72 | ) 73 | ) else ( 74 | echo [INFO] GITHUB_WORKSPACE not defined — skipping ASI Loader files. 75 | ) 76 | 77 | echo Copying README.md -^> dist\README.md>&2 78 | copy /Y README.md dist\README.md 79 | if errorlevel 1 ( 80 | echo [ERROR] Failed to copy README.md to dist\ 81 | exit /b 1 82 | ) 83 | 84 | echo Copying LICENSES.txt -^> dist\LICENSES.txt>&2 85 | copy /Y LICENSES.txt dist\LICENSES.txt 86 | if errorlevel 1 ( 87 | echo [ERROR] Failed to copy LICENSES.txt to dist\ 88 | exit /b 1 89 | ) 90 | 91 | echo Copying MGSM2Fix.ini -^> dist\MGSM2Fix.ini>&2 92 | copy /Y MGSM2Fix.ini dist\MGSM2Fix.ini 93 | if errorlevel 1 ( 94 | echo [ERROR] Failed to copy MGSM2Fix.ini to dist\ 95 | exit /b 1 96 | ) 97 | 98 | echo Copying Release\MGSM2Fix.asi -^> dist\MGSM2Fix32.asi>&2 99 | copy /Y Release\MGSM2Fix.asi dist\MGSM2Fix32.asi 100 | if errorlevel 1 ( 101 | echo [ERROR] Failed to copy Release\MGSM2Fix.asi to dist\MGSM2Fix32.asi 102 | exit /b 1 103 | ) 104 | 105 | echo Copying x64\Release\MGSM2Fix.asi -^> dist\MGSM2Fix64.asi>&2 106 | copy /Y x64\Release\MGSM2Fix.asi dist\MGSM2Fix64.asi 107 | if errorlevel 1 ( 108 | echo [ERROR] Failed to copy x64\Release\MGSM2Fix.asi to dist\MGSM2Fix64.asi 109 | exit /b 1 110 | ) 111 | 112 | REM Remove old archive 113 | echo -------------------------------------------------------- 114 | echo [INFO] Removing old MGSM2Fix.zip if it exists… 115 | if exist MGSM2Fix.zip ( 116 | del /Q MGSM2Fix.zip 117 | ) 118 | 119 | REM Create archive 120 | echo -------------------------------------------------------- 121 | echo [INFO] Creating MGSM2Fix.zip archive… 122 | powershell -command ^ 123 | "Compress-Archive -Path 'dist\*' -DestinationPath 'MGSM2Fix.zip' -Force" 124 | 125 | if exist MGSM2Fix.zip ( 126 | echo [INFO] Archive created successfully: MGSM2Fix.zip 127 | ) else ( 128 | echo [ERROR] Failed to create MGSM2Fix.zip 129 | exit /b 1 130 | ) 131 | 132 | echo ======================================================== 133 | echo [INFO] M2Package.bat completed successfully. 134 | echo ======================================================== 135 | popd 136 | endlocal 137 | exit /b 0 138 | -------------------------------------------------------------------------------- /M2Test.py: -------------------------------------------------------------------------------- 1 | import psutil 2 | import win32gui 3 | import win32con 4 | import win32api 5 | import win32process 6 | import subprocess 7 | import time 8 | 9 | pid = 0 10 | for proc in psutil.process_iter(['pid', 'name']): 11 | if proc.info['name'].lower() != 'steam.exe': continue 12 | pid = proc.info['pid'] 13 | break 14 | 15 | launcher = psutil.Process(pid) 16 | exe = launcher.exe() 17 | 18 | apps = [ 19 | 2131630, 20 | 2306740, 21 | 1018020, 22 | 1018010, 23 | 1552550, 24 | 2369900, 25 | 2478020, 26 | 1638330, 27 | 1640160, 28 | ] 29 | 30 | for id in apps: 31 | subprocess.run([exe, '-applaunch', str(id)]) 32 | 33 | app = None 34 | while not app: 35 | children = proc.children(recursive=False) 36 | for child in children: 37 | try: 38 | if child.name().lower() == 'steamwebhelper.exe': continue 39 | if child.name().lower() == 'gameoverlayui.exe': continue 40 | app = child 41 | except psutil.NoSuchProcess: continue 42 | break 43 | 44 | def GetWindows(pid): 45 | def _GetWindows(hwnd, hwnds): 46 | if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd): 47 | _, _pid = win32process.GetWindowThreadProcessId(hwnd) 48 | if _pid == pid: hwnds.append(hwnd) 49 | return True 50 | 51 | hwnds = [] 52 | win32gui.EnumWindows(_GetWindows, hwnds) 53 | return hwnds 54 | 55 | def CloseWindow(hwnd): 56 | win32gui.ShowWindow(hwnd, win32con.SW_RESTORE) 57 | win32gui.SetForegroundWindow(hwnd) 58 | 59 | win32api.PostMessage(hwnd, win32con.WM_SYSKEYDOWN, win32con.VK_MENU, 0x20000000) 60 | win32api.PostMessage(hwnd, win32con.WM_SYSKEYDOWN, win32con.VK_F4, 0x203D0001) 61 | win32api.PostMessage(hwnd, win32con.WM_SYSKEYUP, win32con.VK_F4, 0xC03D0001) 62 | win32api.PostMessage(hwnd, win32con.WM_SYSKEYUP, win32con.VK_MENU, 0xC0000000) 63 | 64 | hwnds = GetWindows(app.pid) 65 | while not hwnds: hwnds = GetWindows(app.pid) 66 | 67 | time.sleep(10) 68 | CloseWindow(hwnds[0]) 69 | 70 | try: result = app.wait(10) 71 | except Exception as e: 72 | result = e 73 | app.kill() 74 | app.wait(10) 75 | 76 | status = "PASS" 77 | if result != 0: status = "FAIL (%s)" % result 78 | print("Title %u: %s" % (id, status)) 79 | -------------------------------------------------------------------------------- /MGSM2Fix.ini: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;; General ;;;;;;;;;; 2 | 3 | [External Resolution] 4 | ; Enter your chosen resolution. 5 | ; You can leave these at 0 if you want your desktop resolution used instead. 6 | Enabled = true 7 | Width = 0 8 | Height = 0 9 | Windowed = false 10 | Borderless = true 11 | 12 | [Internal Resolution] 13 | ; MGS1 only: Enables render resolution scaling. 14 | ; What most people would call a "4K mod" or a resolution upscaler. 15 | ; Only height is needed - width is set intrinsically by the game. 16 | ; Leave the height at 0 if you wish to use the external resolution. 17 | ; 18 | ; Additionally, set Widescreen to 'true' to enable proper widescreen without horizontal stretching. 19 | ; (Note: the in-game settings must also be set to 'Widescreen' for this to take effect, and won't kick in until you exit the settings menu). 20 | Enabled = false 21 | Height = 0 22 | Widescreen = false 23 | 24 | [Launcher] 25 | ; Skips the warnings / logos on start. 26 | SkipNotice = true 27 | ; MGS1 only: Starts the game directly with the previously saved settings and game version. 28 | ; Change the game version/settings by going back to the game selection menu via the in-game pause menu. 29 | StartGame = false 30 | 31 | [Patches] 32 | ; MGS1 only: Reverts the Master Collection texture swap for Johnny's underpants. 33 | RemoveUnderpants = true 34 | ; MGS1 only: Restores the mosaic blur effect on Johnny from original western releases. 35 | EnableMosaic = true 36 | ; MGS1 only: Reverts the Master Collection texture swaps for ghost exorcism. 37 | RestoreGhosts = true 38 | ; MGS1 only: Reverts the Master Collection texture swaps for medicine items. 39 | RestoreMedicine = true 40 | 41 | ; MGS1 only: !ADVANCED OPTION! Master toggle for *all* RAM patches. 42 | ; May interfere with achievements! 43 | DisableRAM = false 44 | ; MGS1 only: !ADVANCED OPTION! Master toggle for *all* CD-ROM patches. 45 | ; May interfere with achievements! 46 | DisableCDROM = false 47 | 48 | [Game] 49 | ; MGS1 only: Enables the in-game developer menu (stage select). 50 | ; When enabled, the menu starts up in place of the title screen. 51 | ; Selecting 'title' on the menu will load the title screen as normal. 52 | StageSelect = false 53 | 54 | [Update Notifications] 55 | ; If set to true, MGSM2Fix will notify you when launching the game if a new MGSM2Fix update is available for download. 56 | CheckForUpdates = true 57 | ; If you want console notification when starting the game if a MGSM2Fix update is available. 58 | ; Update notifications will still be printed to the log file when set to false. 59 | ConsoleNotifications = true 60 | 61 | ;;;;;;;;;; Developer ;;;;;;;;;; 62 | 63 | [Squirrel Debugger] 64 | ; Injects SQDbg into the Squirrel VM. 65 | ; Advanced option, leave it disabled if you just want to play the game. 66 | Enabled = false 67 | Port = 27615 68 | AutoUpdate = true 69 | Exclusive = false 70 | 71 | [Tracing] 72 | ; Enables tracing of Squirrel scripts to the log file. 73 | Level = 0 74 | ; Enables tracing of Squirrel native calls to the log file. 75 | NativeLevel = 0 76 | ; Enables tracing of spammy emulator hooks to the log file. 77 | EmulatorLevel = 0 78 | ; Enables tracing of DirectX API calls to the log file. 79 | RendererLevel = 0 80 | ; Enables a command prompt "developer console" window to display the log. 81 | Console = false 82 | -------------------------------------------------------------------------------- /MGSM2Fix.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuggslet/MGSM2Fix/eac1f52611b71ee3d7d9e88efd4818a862f54391/MGSM2Fix.rc -------------------------------------------------------------------------------- /MGSM2Fix.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.3.32901.215 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MGSM2Fix", "MGSM2Fix.vcxproj", "{C6644269-B721-4F94-BE7F-77BFB2343BA5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Debug|x64.ActiveCfg = Debug|x64 17 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Debug|x64.Build.0 = Debug|x64 18 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Debug|x64.Deploy.0 = Debug|x64 19 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Debug|x86.ActiveCfg = Debug|Win32 20 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Debug|x86.Build.0 = Debug|Win32 21 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Debug|x86.Deploy.0 = Debug|Win32 22 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Release|x64.ActiveCfg = Release|x64 23 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Release|x64.Build.0 = Release|x64 24 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Release|x64.Deploy.0 = Release|x64 25 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Release|x86.ActiveCfg = Release|Win32 26 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Release|x86.Build.0 = Release|Win32 27 | {C6644269-B721-4F94-BE7F-77BFB2343BA5}.Release|x86.Deploy.0 = Release|Win32 28 | EndGlobalSection 29 | GlobalSection(SolutionProperties) = preSolution 30 | HideSolutionNode = FALSE 31 | EndGlobalSection 32 | GlobalSection(ExtensibilityGlobals) = postSolution 33 | SolutionGuid = {BD882CE7-25BA-4751-8EB4-4B14C55192CA} 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Metal Gear Solid Master Collection Fix (M2Fix) 2 | [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Z8Z7S6BTK)
3 | [![MGSM2Fix](https://github.com/nuggslet/MGSM2Fix/actions/workflows/ci.yml/badge.svg)](https://github.com/nuggslet/MGSM2Fix/actions/workflows/ci.yml)[![Github All Releases](https://img.shields.io/github/downloads/nuggslet/MGSM2Fix/total.svg)](https://github.com/nuggslet/MGSM2Fix/releases) 4 | 5 | This is a fix that adds custom resolutions, mod support and more to Metal Gear Solid & Metal Gear / Snake's Revenge within the MGS Master Collection, and many more M2ENGAGE titles.
6 | 7 | ## Games Supported 8 | - Metal Gear Solid 9 | - Metal Gear / Snake's Revenge (Vol.1 Bonus Content) 10 | - Contra Anniversary Collection 11 | - Castlevania Anniversary Collection 12 | - Castlevania Advance Collection 13 | - Castlevania Dominus Collection 14 | - Ray’z Arcade Chronology 15 | - Darius Cozmic Collection Arcade 16 | - G-Darius HD 17 | 18 | See Lyall's [MGSHDFix](https://github.com/ShizCalev/MGSHDFix) for the other games in the MGS Master Collection. 19 | 20 | ## Features 21 | - Custom internal render resolution & widescreen support (MGS 1). 22 | - Borderless/windowed mode. 23 | - Corrects the monitor going to sleep during long periods with no input (e.g. during cutscenes). 24 | - Control over Master Collection game patches. 25 | - ~~Analog input (MGS 1).~~ - Fixed by Konami officially via patch 1.5.0 on 13th March 2024. 26 | - Launcher skip (MGS 1, boots last launched game version). 27 | - Skip intro logos. 28 | - Modding support (MGS 1, via Ketchup - see below). 29 | - Debug features (including stage select menu in MGS 1). 30 | 31 | ## Installation 32 | - Grab the latest release of MGSM2Fix from [here](https://github.com/nuggslet/MGSM2Fix/releases) - or the preview release if you're feeling adventurous. 33 | - Extract the contents of the release into the game folder.
(e.g. "**steamapps\common\MGS1**" or "**steamapps\common\MGS Master Collection Bonus Content**" for Steam games). 34 | 35 | ### Steam Deck/Linux additional instructions 36 | - Open up the Steam game properties and put `WINEDLLOVERRIDES="dinput8=n,b;d3d11=n,b" %command%` in the launch options. 37 | 38 | ## Configuration 39 | - See **MGSM2Fix.ini** to adjust settings for the fix. 40 | 41 | ## Modding (MGS 1; Ketchup) 42 | 'Ketchup' is a mod loader for MGS 1 in the Master Collection. 43 | 44 | It currently supports PPF3 format mods to each ISO under the following folders in the "**steamapps\common\MGS1**" directory: 45 | ``` 46 | mods\INTEGRAL\INTEGRAL\0\ 47 | mods\INTEGRAL\INTEGRAL\1\ 48 | mods\INTEGRAL\VR-DISK\ 49 | mods\VR-DISK_US\ 50 | mods\VR-DISK_EU\ 51 | mods\MGS1_JP\0\ 52 | mods\MGS1_JP\1\ 53 | mods\MGS1_US\0\ 54 | mods\MGS1_US\1\ 55 | mods\MGS1_UK\0\ 56 | mods\MGS1_UK\1\ 57 | mods\MGS1_DE\0\ 58 | mods\MGS1_DE\1\ 59 | mods\MGS1_FR\0\ 60 | mods\MGS1_FR\1\ 61 | mods\MGS1_IT\0\ 62 | mods\MGS1_IT\1\ 63 | mods\MGS1_ES\0\ 64 | mods\MGS1_ES\1\ 65 | ``` 66 | Where `0` and `1` refer to disk 1 and disk 2 respectively. 67 | 68 | See [makeppf](https://github.com/meunierd/ppf) for creating PPF3 patches/mods. PPF3 mods derived from original PSX CD releases should work correctly with Master Collection. 69 | 70 | If your mods conflict with the built-in Master Collection patches, for the time being it may be useful to enable the `DisableRAM` and `DisableCDROM` settings in **MGSM2Fix.ini**. 71 | Once all of the Master Collection patches have been identified and grouped (please help, there are lots!) this heavy-handed approach should no longer be necessary. 72 | 73 | Additional mod formats may be supported in future. 74 | 75 | ## Known Issues 76 | Please report any issues you see. 77 | This list will contain bugs which may or may not be fixed. 78 | 79 | ## Screenshots 80 | 81 | | ![MGS 1](https://github.com/user-attachments/assets/e8c0f73b-24df-4264-a86a-0f20a87e3dd8)
![MGS 1](https://github.com/user-attachments/assets/65d14662-95f4-49e4-9aad-2f2cdeaaaa06) | 82 | |:--:| 83 | | Metal Gear Solid | 84 | 85 | ## Credits 86 | Many thanks to [@Lyall](https://github.com/Lyall) and co. for MGSHDFix, from which this project derives its general structure;
87 | [@ShizCalev/Afevis](https://github.com/shizcalev), [@Bud11](https://github.com/bud11) and [@orzcode](https://github.com/orzcode) for contributing fixes and being generally helpful;
88 | Countless people in the MGN Discord for testing and encouraging the project along;
89 | [Ultimate ASI Loader](https://github.com/ThirteenAG/Ultimate-ASI-Loader) for ASI loading;
90 | [inipp](https://github.com/mcmtroffaes/inipp) for **MGSM2Fix.ini** reading;
91 | [spdlog](https://github.com/gabime/spdlog) for logging;
92 | [safetyhook](https://github.com/cursey/safetyhook) for hooking;
93 | [Squirrel](http://squirrel-lang.org/) for one at least two virtual machines this project tinkers with;
94 | [Sqrat](https://scrat.sourceforge.net/index.html) for Squirrel bindings in C++;
95 | [FunctionTraits](https://github.com/HexadigmSystems/FunctionTraits) for improving the safetyhook calling convention experience. 96 | -------------------------------------------------------------------------------- /build_zydis.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enabledelayedexpansion 3 | 4 | echo === Building Zydis if needed === 5 | 6 | REM --- Detect platform (arg > env var > default x64) --- 7 | set "PLAT=%~1" 8 | if "%PLAT%"=="" set "PLAT=%Platform%" 9 | if "%PLAT%"=="" set "PLAT=x64" 10 | 11 | REM --- Locate Zydis project file --- 12 | set "ZY_PROJECT=%~dp0src\zydis\msvc\zydis\Zydis.vcxproj" 13 | if not exist %ZY_PROJECT% ( 14 | echo ERROR: Zydis project file not found at %ZY_PROJECT% 15 | exit /b 1 16 | ) 17 | 18 | REM --- Get current submodule commit hash --- 19 | pushd "%~dp0src\zydis" >nul 20 | for /f %%H in ('git rev-parse HEAD') do set "ZY_HASH=%%H" 21 | if not defined ZY_HASH ( 22 | echo ERROR: Could not read Zydis git hash. Is the submodule initialized? 23 | popd >nul 24 | exit /b 1 25 | ) 26 | popd >nul 27 | 28 | REM --- Configure paths --- 29 | if /i "%PLAT%"=="x64" ( 30 | set "ZY_LIB=%~dp0src\zydis\msvc\bin\ReleaseX64\Zydis.lib" 31 | set "HASH_FILE=%~dp0src\zydis\msvc\bin\ReleaseX64\.zydis_build_hash" 32 | set "MSBUILD_ARGS=/p:Configuration="Release MT" /p:Platform=x64 /m /nologo /verbosity:minimal" 33 | ) else if /i "%PLAT%"=="Win32" ( 34 | set "ZY_LIB=%~dp0src\zydis\msvc\bin\ReleaseX86\Zydis.lib" 35 | set "HASH_FILE=%~dp0src\zydis\msvc\bin\ReleaseX86\.zydis_build_hash" 36 | set "MSBUILD_ARGS=/p:Configuration="Release MT" /p:Platform=Win32 /m /nologo /verbosity:minimal" 37 | ) else ( 38 | echo ERROR: Unsupported platform %PLAT% 39 | endlocal 40 | exit /b 1 41 | ) 42 | 43 | REM --- Decide if rebuild is needed --- 44 | set "NEED_BUILD=0" 45 | if not exist "%ZY_LIB%" set "NEED_BUILD=1" 46 | if not exist "%HASH_FILE%" set "NEED_BUILD=1" 47 | 48 | if exist "%HASH_FILE%" ( 49 | set /p OLD_HASH=<"%HASH_FILE%" 50 | if not "!OLD_HASH!"=="%ZY_HASH%" set "NEED_BUILD=1" 51 | ) 52 | 53 | REM --- Build if needed --- 54 | if "%NEED_BUILD%"=="1" ( 55 | echo [Zydis] Building Release MT %PLAT% 56 | msbuild %ZY_PROJECT% %MSBUILD_ARGS% 57 | if errorlevel 1 ( 58 | echo ERROR: Zydis Release MT %PLAT% build failed 59 | exit /b 1 60 | ) 61 | >"%HASH_FILE%" echo %ZY_HASH% 62 | ) else ( 63 | echo [Zydis] Release MT %PLAT% up to date, skipping 64 | ) 65 | 66 | echo === Zydis build check complete === 67 | endlocal 68 | exit /b 0 69 | -------------------------------------------------------------------------------- /game_actions_2131630.vdf: -------------------------------------------------------------------------------- 1 | "In Game Actions" 2 | { 3 | "actions" 4 | { 5 | "InGameControls" 6 | { 7 | "title" "#Set_Ingame" 8 | "legacy_set" "0" 9 | "StickPadGyro" 10 | { 11 | "l_move" 12 | { 13 | "title" "#Action_LMove" 14 | "input_mode" "joystick_move" 15 | } 16 | "r_move" 17 | { 18 | "title" "#Action_RMove" 19 | "input_mode" "joystick_move" 20 | } 21 | } 22 | "Button" 23 | { 24 | "key_up" "#Action_Up" 25 | "key_down" "#Action_Down" 26 | "key_left" "#Action_Left" 27 | "key_right" "#Action_Right" 28 | "a_button" "#Action_A" 29 | "b_button" "#Action_B" 30 | "x_button" "#Action_X" 31 | "y_button" "#Action_Y" 32 | "start_button" "#Action_Start" 33 | "select_button" "#Action_Select" 34 | "l1_button" "#Action_L1" 35 | "l2_button" "#Action_L2" 36 | "l3_button" "#Action_L3" 37 | "r1_button" "#Action_R1" 38 | "r2_button" "#Action_R2" 39 | "r3_button" "#Action_R3" 40 | } 41 | } 42 | } 43 | "localization" 44 | { 45 | "english" 46 | { 47 | "Set_Ingame" "In-Game Controls" 48 | "Action_LMove" "LeftStick" 49 | "Action_RMove" "RightStick" 50 | "Action_Up" "Up" 51 | "Action_Down" "Down" 52 | "Action_Left" "Left" 53 | "Action_Right" "Right" 54 | "Action_A" "A Button" 55 | "Action_B" "B Button" 56 | "Action_X" "X Button" 57 | "Action_Y" "Y Button" 58 | "Action_Start" "Start Button" 59 | "Action_Select" "Select Button" 60 | "Action_L1" "L1 Button" 61 | "Action_L2" "L2 Button" 62 | "Action_L3" "L3 Button" 63 | "Action_R1" "R1 Button" 64 | "Action_R2" "R2 Button" 65 | "Action_R3" "R3 Button" 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML 2 | -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // ReSharper disable CppClangTidyModernizeMacroToEnum 3 | 4 | // Core name & version 5 | #define FIX_NAME "MGSM2Fix" 6 | #define PRIMARY_REPO_URL "https://github.com/nuggslet/MGSM2Fix" 7 | #define FALLBACK_REPO_URL "https://github.com/h-i-d-e-o/MGSM2Fix" 8 | 9 | #define VERSION_MAJOR 3 10 | #define VERSION_MINOR 0 11 | #define VERSION_PATCH 0 12 | 13 | 14 | #define STRINGIFY_HELPER(x) #x 15 | #define STRINGIFY(x) STRINGIFY_HELPER(x) 16 | #define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH) 17 | 18 | // Metadata 19 | #define COMPANY_NAME "nuggslet" 20 | #define PRODUCT_NAME FIX_NAME 21 | #define FILE_DESCRIPTION FIX_NAME " ASI Plugin" 22 | #define INTERNAL_NAME FIX_NAME ".asi" 23 | #define ORIGINAL_FILENAME FIX_NAME ".asi" 24 | #define PRODUCT_VERSION VERSION_STRING 25 | #define FILE_VERSION VERSION_STRING 26 | #define LEGAL_COPYRIGHT "(C) 2025 nuggslet. Licensed under the MIT License." 27 | #define LEGAL_TRADEMARKS "" 28 | #define COMMENTS "" 29 | 30 | 31 | //{{NO_DEPENDENCIES}} 32 | // Microsoft Visual C++ generated include file. 33 | // Used by MGSM2Fix.rc 34 | // 35 | #define IDR_NUT1 105 36 | #define IDR_HLSL1 106 37 | #define IDR_HLSL2 107 38 | 39 | // Next default values for new objects 40 | // 41 | #ifdef APSTUDIO_INVOKED 42 | #ifndef APSTUDIO_READONLY_SYMBOLS 43 | #define _APS_NEXT_RESOURCE_VALUE 108 44 | #define _APS_NEXT_COMMAND_VALUE 40001 45 | #define _APS_NEXT_CONTROL_VALUE 1001 46 | #define _APS_NEXT_SYMED_VALUE 101 47 | #endif 48 | #endif 49 | -------------------------------------------------------------------------------- /src/FunctionTraits/CompilerVersions.cppm: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // LICENSE NOTICE 3 | // -------------- 4 | // Copyright (c) Hexadigm Systems 5 | // 6 | // Permission to use this software is granted under the following license: 7 | // https://www.hexadigm.com/GenericLib/License.html 8 | // 9 | // This copyright notice must be included in this and all copies of the 10 | // software as described in the above license. 11 | // 12 | // DESCRIPTION 13 | // ----------- 14 | // Module version of "CompilerVersions.h". Simply defers to 15 | // "CompilerVersions.h" to export all public declarations in that header. 16 | // For complete details on module support in "FunctionTraits", see 17 | // https://github.com/HexadigmSystems/FunctionTraits#moduleusage 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | module; 21 | 22 | ///////////////////////////////////////////////////////////// 23 | // Let "CompilerVersions.h" just below know we're building 24 | // the "CompilerVersions" module. Following is only #defined 25 | // when we are ... 26 | ///////////////////////////////////////////////////////////// 27 | #define STDEXT_BUILDING_MODULE_COMPILERVERSIONS 28 | #include "CompilerVersions.h" 29 | #undef STDEXT_BUILDING_MODULE_COMPILERVERSIONS 30 | 31 | export module CompilerVersions; 32 | 33 | ////////////////////////////////////////////////////////////////////// 34 | // Interface for this module. We simply rely on "using" declarations 35 | // in the code below to export all public declarations from 36 | // "CompilerVersions.h" above. See the following for details on using 37 | // this module: 38 | // 39 | // https://github.com/HexadigmSystems/FunctionTraits#moduleusage 40 | // 41 | // IMPORTANT: 42 | // --------- 43 | // Note that GCC is currently buggy at this writing (modules still 44 | // under development), and fails to compile the code below (so until 45 | // corrected, this module can't be used in GCC). See the following 46 | // GCC bug reports (both identifying the same issue): 47 | // 48 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109679 49 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113129 50 | ////////////////////////////////////////////////////////////////////// 51 | export namespace StdExt 52 | { 53 | using StdExt::tchar; 54 | using StdExt::tstring_view; 55 | using StdExt::tcout; 56 | using StdExt::GetCompilerName; 57 | } -------------------------------------------------------------------------------- /src/FunctionTraits/LICENSE: -------------------------------------------------------------------------------- 1 | See https://www.hexadigm.com/GenericLib/License.html -------------------------------------------------------------------------------- /src/analog.cpp: -------------------------------------------------------------------------------- 1 | #include "analog.h" 2 | 3 | #include "m2fix.h" 4 | 5 | #include "sqemutask.h" 6 | #include "mgs1.h" 7 | 8 | #include "sqinput.h" 9 | #include "sqinputhub.h" 10 | 11 | unsigned char *Analog_PadPTR; 12 | unsigned int __fastcall Analog_ReadPad(unsigned int addr, unsigned int id, unsigned char *state) 13 | { 14 | if (Analog_PadPTR != state) { 15 | spdlog::info("[Emulator] Pad state is {}.", fmt::ptr(state)); 16 | } 17 | 18 | Analog_PadPTR = state; 19 | return M2Hook::GetInstance().Invoke(Analog_ReadPad, addr, id, state); 20 | } 21 | 22 | void MGS1::AnalogLoop() 23 | { 24 | if (!Analog_PadPTR) return; 25 | 26 | SQInputHub::SetDirectionMerge(0); 27 | SQEmuTask::SetInputDirectionMerge(0); 28 | 29 | SQInputHub::SetDeadzone(0.0); 30 | SQEmuTask::SetInputDeadzone(0.0); 31 | 32 | SQFloat xL = SQInput::GetAnalogStickX(); 33 | SQFloat yL = SQInput::GetAnalogStickY(); 34 | 35 | SQFloat xR = SQInput::GetRightAnalogStickX(); 36 | SQFloat yR = SQInput::GetRightAnalogStickY(); 37 | 38 | // Normalize an axis from (-1, 1) to (0, 255) with 128 = center 39 | // https://github.com/grumpycoders/pcsx-redux/blob/a072e38d78c12a4ce1dadf951d9cdfd7ea59220b/src/core/pad.cc#L664-L673 40 | const auto axisToUint8 = [](float axis) { 41 | constexpr float scale = 1.3f; 42 | const float scaledValue = std::clamp(axis * scale, -1.0f, 1.0f); 43 | return (uint8_t)(std::clamp(std::round(((scaledValue + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f)); 44 | }; 45 | 46 | if (SQSystemData::SettingPad::GetPlaySide_MGS1() == 0) { 47 | Analog_PadPTR[0x44] = axisToUint8(xL); 48 | Analog_PadPTR[0x45] = axisToUint8(yL); 49 | Analog_PadPTR[0x46] = axisToUint8(xR); 50 | Analog_PadPTR[0x47] = axisToUint8(yR); 51 | 52 | for (unsigned int i = 0x48; i < 0x54; i++) { 53 | Analog_PadPTR[i] = 128; 54 | } 55 | } 56 | else 57 | { 58 | for (unsigned int i = 0x44; i < 0x4C; i++) { 59 | Analog_PadPTR[i] = 128; 60 | } 61 | 62 | Analog_PadPTR[0x4C] = axisToUint8(xL); 63 | Analog_PadPTR[0x4D] = axisToUint8(yL); 64 | Analog_PadPTR[0x4E] = axisToUint8(xR); 65 | Analog_PadPTR[0x4F] = axisToUint8(yR); 66 | 67 | for (unsigned int i = 0x50; i < 0x54; i++) { 68 | Analog_PadPTR[i] = 128; 69 | } 70 | } 71 | } 72 | 73 | void Analog::Load() 74 | { 75 | switch (M2Fix::Game()) 76 | { 77 | case M2FixGame::MGS1: 78 | { 79 | M2Hook::GetInstance().Hook( 80 | "C7 44 24 08 F3 5A 00 00 C7 44 24 0C 00 00 00 00", 81 | 0, Analog_ReadPad, "[Analog] sio_read_pad" 82 | ); 83 | 84 | M2Hook::GetInstance().Patch( 85 | "66 89 4F 0C F3 0F 2C C0 0F B7 C0 66 89 47 0E 75", 0, 86 | "66 89 4F 08 F3 0F 2C C0 0F B7 C0 66 89 47 0A 75", 87 | "[Analog] MInputHubDM::GetWin" 88 | ); 89 | 90 | M2Hook::GetInstance().Patch( 91 | "88 4C 10 44 83 FB 06 7C 86 8B 44 24 18 45 89 6C", 0, 92 | "90 90 90 90", 93 | "[Analog] sio_update_pad" 94 | ); 95 | 96 | break; 97 | } 98 | 99 | default: break; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/analog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "m2fixbase.h" 4 | 5 | class Analog : public M2FixBase 6 | { 7 | public: 8 | static auto & GetInstance() 9 | { 10 | static Analog instance; 11 | return instance; 12 | } 13 | 14 | static void LoadInstance() { 15 | GetInstance().Load(); 16 | } 17 | 18 | virtual void Load() override; 19 | }; 20 | -------------------------------------------------------------------------------- /src/borderless.cpp: -------------------------------------------------------------------------------- 1 | #include "borderless.h" 2 | 3 | #include "m2fix.h" 4 | 5 | void Borderless::Load() 6 | { 7 | switch (M2Fix::Game()) 8 | { 9 | case M2FixGame::MGS1: 10 | { 11 | M2Hook::GetInstance().Patch( 12 | "B8 00 00 CE 02 BE 00 00 CA 02", 0, 13 | "B8 00 00 00 90 BE 00 00 00 90", 14 | "[Borderless-32A] MWin::CreateWindow" 15 | ); 16 | 17 | break; 18 | } 19 | 20 | case M2FixGame::Contra: 21 | case M2FixGame::Dracula: 22 | case M2FixGame::DraculaAdvance: 23 | case M2FixGame::Darius: 24 | case M2FixGame::Darius101: 25 | { 26 | bool ret = false; 27 | 28 | ret = M2Hook::GetInstance().Patch( 29 | "B8 00 00 0B 02 C7 85 70 FF FF FF 00 00 CB 00 74 " 30 | "0F B8 00 00 0F 02 C7 85 70 FF FF FF 00 00 CF 00", 0, 31 | "B8 00 00 00 90 C7 85 70 FF FF FF 00 00 CB 00 74 " 32 | "0F B8 00 00 00 90 C7 85 70 FF FF FF 00 00 CF 00", 33 | "[Borderless-32B] MWin::CreateWindow" 34 | ); 35 | 36 | if (!ret) { 37 | ret = M2Hook::GetInstance().Patch( 38 | "BA 00 00 CA 12 EB 02 33 D2", 0, 39 | "BA 00 00 00 90 90 90 90 90", 40 | "[Borderless-32C] MWin::CreateWindow" 41 | ); 42 | } 43 | 44 | break; 45 | } 46 | 47 | case M2FixGame::NightStrikers: 48 | { 49 | M2Hook::GetInstance().Patch( 50 | "BE 00 00 CB 02 B9 00 00 CB 00 74 0A BE 00 00 CF " 51 | "02 B9 00 00 CF 00", 0, 52 | "BE 00 00 00 90 B9 00 00 CB 00 74 0A BE 00 00 00 " 53 | "90 B9 00 00 CF 00", 54 | "[Borderless-32D] MWin::CreateWindow" 55 | ); 56 | 57 | break; 58 | } 59 | 60 | case M2FixGame::MGSR: 61 | case M2FixGame::DraculaDominus: 62 | case M2FixGame::Ray: 63 | case M2FixGame::Gradius: 64 | { 65 | M2Hook::GetInstance().Patch( 66 | "BE 00 00 CB 02 41 BE 00 00 CB 00 44 ?? ?? ?? ?? " 67 | "?? ?? 74 0B BE 00 00 CF 02 41 BE 00 00 CF 00", 0, 68 | "BE 00 00 00 90 41 BE 00 00 00 00 90 90 90 90 90 " 69 | "90 90 90 90 90 90 90 90 90 90 90 90 90 90 90", 70 | "[Borderless-64A] MWin::CreateWindow" 71 | ); 72 | 73 | break; 74 | } 75 | 76 | default: break; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/borderless.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "m2fixbase.h" 4 | 5 | class Borderless : public M2FixBase 6 | { 7 | public: 8 | static auto & GetInstance() 9 | { 10 | static Borderless instance; 11 | return instance; 12 | } 13 | 14 | static void LoadInstance() { 15 | GetInstance().Load(); 16 | } 17 | 18 | virtual void Load() override; 19 | }; 20 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "m2fixbase.h" 4 | 5 | template 6 | class M2InteropBasicString; 7 | using M2InteropString = M2InteropBasicString; 8 | 9 | class Config : public M2FixBase 10 | { 11 | public: 12 | static auto & GetInstance() 13 | { 14 | static Config instance; 15 | return instance; 16 | } 17 | 18 | static void LoadInstance() { 19 | GetInstance().Load(); 20 | } 21 | 22 | virtual void Load() override; 23 | 24 | private: 25 | #ifdef _WIN64 26 | static const char *GetCfgValue(uintptr_t *ctx, const M2InteropString id); 27 | static int GetCfgValueEx(uintptr_t *ctx, const M2InteropString *id); 28 | 29 | #else 30 | static const char * __fastcall GetCfgValue(uintptr_t *ctx, uintptr_t _EDX, const M2InteropString id, uintptr_t index); 31 | static int __fastcall GetCfgValueEx(uintptr_t *ctx, uintptr_t _EDX, const M2InteropString *id); 32 | #endif 33 | }; 34 | -------------------------------------------------------------------------------- /src/d3d11PixelUpscaler.hlsl: -------------------------------------------------------------------------------- 1 | Texture2D sourceTex : register(t0); 2 | SamplerState samLinear : register(s0); 3 | 4 | float4 main(float2 uv : TEXCOORD) : SV_Target 5 | { 6 | return sourceTex.Sample(samLinear, uv); 7 | } 8 | -------------------------------------------------------------------------------- /src/d3d11VertexUpscaler.hlsl: -------------------------------------------------------------------------------- 1 | struct VS_OUT { 2 | float2 uv : TEXCOORD0; 3 | float4 pos : SV_POSITION; 4 | }; 5 | 6 | VS_OUT main(uint vertexId : SV_VertexID) 7 | { 8 | float2 pos[3] = { 9 | float2(-1.0f, -1.0f), 10 | float2(-1.0f, 3.0f), 11 | float2( 3.0f, -1.0f) 12 | }; 13 | 14 | float2 uv[3] = { 15 | float2(0.0f, 0.0f), 16 | float2(0.0f, 2.0f), 17 | float2(2.0f, 0.0f) 18 | }; 19 | 20 | VS_OUT output; 21 | output.uv = uv[vertexId]; 22 | output.uv = float2(output.uv.x, 1.0f - output.uv.y); 23 | output.pos = float4(pos[vertexId], 0.0f, 1.0f); 24 | return output; 25 | } 26 | -------------------------------------------------------------------------------- /src/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "m2fix.h" 2 | 3 | DWORD WINAPI ThreadProc(LPVOID lpThreadParameter) 4 | { 5 | HINSTANCE hinstDLL = reinterpret_cast(lpThreadParameter); 6 | M2Fix::Main(hinstDLL); 7 | 8 | M2Utils::memsetRelease(); 9 | return 1; 10 | } 11 | 12 | void Main(HINSTANCE hinstDLL) 13 | { 14 | M2Utils::memsetHook(); 15 | 16 | HANDLE handle = CreateThread(NULL, 0, ThreadProc, hinstDLL, NULL, 0); 17 | if (!handle) return; 18 | 19 | SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST); 20 | CloseHandle(handle); 21 | 22 | // fixes the monitor going to sleep during cutscenes 23 | SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); 24 | } 25 | 26 | BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 27 | { 28 | if (fdwReason == DLL_PROCESS_ATTACH) 29 | { 30 | Main(hinstDLL); 31 | } 32 | else if (fdwReason == DLL_PROCESS_DETACH) 33 | { 34 | spdlog::shutdown(); 35 | } 36 | 37 | return TRUE; 38 | } 39 | -------------------------------------------------------------------------------- /src/epi.cpp: -------------------------------------------------------------------------------- 1 | #include "m2fix.h" 2 | #include "epi.h" 3 | 4 | void EPI::Print(const char *fmt, ...) 5 | { 6 | static std::string buffer; 7 | 8 | va_list va; 9 | va_start(va, fmt); 10 | std::vector buf(_vscprintf(fmt, va) + 1, 0); 11 | char *data = buf.data(); 12 | vsprintf(data, fmt, va); 13 | va_end(va); 14 | 15 | if (data[strcspn(data, "\r\n")] == 0) { 16 | buffer += std::string(data); 17 | return; 18 | } 19 | 20 | data[strcspn(data, "\r\n")] = 0; 21 | buffer += std::string(data); 22 | if (buffer.length() == 0) return; 23 | 24 | spdlog::info("[EPI] [printf] {}", buffer); 25 | buffer.clear(); 26 | } 27 | 28 | void EPI::Load() 29 | { 30 | std::string module; 31 | switch (M2Fix::Game()) 32 | { 33 | case M2FixGame::MGS1: 34 | case M2FixGame::Contra: 35 | case M2FixGame::Dracula: 36 | case M2FixGame::DraculaAdvance: 37 | case M2FixGame::Darius: 38 | case M2FixGame::Darius101: 39 | case M2FixGame::NightStrikers: 40 | { 41 | M2Hook::GetInstance(module).Hook( 42 | "8B 4C 24 04 8D 54 24 08 E8 ?? ?? FF FF 85 C0 74", 43 | 0, Print, "[EPI-32] printf" 44 | ); 45 | 46 | break; 47 | } 48 | 49 | case M2FixGame::DraculaDominus: 50 | module = "emu_integration"; 51 | [[fallthrough]]; 52 | case M2FixGame::MGSR: 53 | case M2FixGame::Ray: 54 | case M2FixGame::Gradius: 55 | { 56 | M2Hook::GetInstance(module).Hook( 57 | "48 89 4C 24 08 48 89 54 24 10 4C 89 44 24 18 4C " 58 | "89 4C 24 20 48 83 EC 28 48 8D 54 24 38 E8 ?? ?? " 59 | "?? ?? 48 85 C0 74 08 48 8B C8 E8 ?? ??", 60 | 0, Print, "[EPI-64] printf" 61 | ); 62 | 63 | break; 64 | } 65 | 66 | default: break; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/epi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "m2fixbase.h" 4 | 5 | class EPI : public M2FixBase 6 | { 7 | public: 8 | static auto & GetInstance() 9 | { 10 | static EPI instance; 11 | return instance; 12 | } 13 | 14 | static void LoadInstance() { 15 | GetInstance().Load(); 16 | } 17 | 18 | virtual void Load() override; 19 | 20 | private: 21 | static void Print(const char *fmt, ...); 22 | }; 23 | -------------------------------------------------------------------------------- /src/ketchup.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | typedef struct { 6 | unsigned int id; 7 | unsigned int ram_base; 8 | unsigned int ram_range; 9 | } Ketchup_DiskInfo; 10 | 11 | typedef struct { 12 | std::string name; 13 | std::vector disks; 14 | } Ketchup_VersionInfo; 15 | 16 | typedef struct { 17 | unsigned int id; 18 | std::string name; 19 | std::vector versions; 20 | } Ketchup_TitleInfo; 21 | 22 | template 23 | class Ketchup 24 | { 25 | public: 26 | Ketchup() {} 27 | 28 | static bool Process(HSQUIRRELVM v); 29 | 30 | constexpr static unsigned int PSX_ImageBase = 0x10000; 31 | constexpr static unsigned int PSX_SectorSize = 0x800; 32 | constexpr static unsigned int PSX_SectorStride = 0x130; 33 | constexpr static unsigned int PSX_SectorRange = PSX_SectorSize + PSX_SectorStride; 34 | 35 | static unsigned int PSX_DiskRange(unsigned int size) { 36 | return (size / PSX_SectorSize) * PSX_SectorRange; 37 | } 38 | 39 | private: 40 | static std::filesystem::path RootPath(Ketchup_TitleInfo &title, Ketchup_VersionInfo &version, Ketchup_DiskInfo &disk, std::string base = "mods"); 41 | 42 | static bool ApplyBlock(HSQUIRRELVM v, 43 | Ketchup_TitleInfo &title, Ketchup_VersionInfo &version, Ketchup_DiskInfo &disk, 44 | int64_t offset, unsigned char *data, size_t size); 45 | static bool Apply(HSQUIRRELVM v, Ketchup_TitleInfo &title, Ketchup_VersionInfo &version, Ketchup_DiskInfo &disk, std::ifstream &data); 46 | 47 | static bool ApplyPPF3(HSQUIRRELVM v, Ketchup_TitleInfo &title, Ketchup_VersionInfo &version, Ketchup_DiskInfo &disk, std::ifstream &data); 48 | static int MetaPPF_FileId(std::ifstream &data, int version); 49 | 50 | static bool ProcessDisk(HSQUIRRELVM v, Ketchup_TitleInfo &title, Ketchup_VersionInfo &version, Ketchup_DiskInfo &disk); 51 | static bool ProcessVersion(HSQUIRRELVM v, Ketchup_TitleInfo &title, Ketchup_VersionInfo &version); 52 | static bool ProcessTitle(HSQUIRRELVM v, Ketchup_TitleInfo &title); 53 | }; 54 | -------------------------------------------------------------------------------- /src/m2/epi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef enum { 4 | PAD_BUTTON_A = 0x1, 5 | PAD_BUTTON_B = 0x2, 6 | PAD_BUTTON_C = 0x4, 7 | PAD_BUTTON_X = 0x8, 8 | PAD_BUTTON_Y = 0x10, 9 | PAD_BUTTON_L = 0x10, 10 | PAD_BUTTON_Z = 0x20, 11 | PAD_BUTTON_R = 0x20, 12 | PAD_DOWN = 0x40, 13 | PAD_LEFT = 0x80, 14 | PAD_RIGHT = 0x100, 15 | PAD_COIN = 0x200, 16 | PAD_SELECT = 0x200, 17 | PAD_START = 0x400, 18 | PAD_UP = 0x800, 19 | PAD_DISCONNECTED = 0x1000, 20 | PAD_BUTTON_L2 = 0x4000, 21 | PAD_BUTTON_R2 = 0x8000, 22 | PAD_RPD_GC_POS = 0x2000000, 23 | PAD_RPD_GC_NEG = 0x4000000, 24 | PAD_SHORTCUT = 0x20000000, 25 | PAD_MENU = 0x40000000, 26 | PAD_RPD = 0x80000000, 27 | } M2EpiPadFlag; 28 | 29 | typedef enum { 30 | MD_6B_DISABLE = 0x1, 31 | MD_MULTITAP_0 = 0x2, 32 | MD_MULTITAP_1 = 0x4, 33 | USE_ANALOG = 0x8, 34 | DIRECTION_4 = 0x10, 35 | } M2EpiArchSubInfo; 36 | 37 | typedef enum { 38 | BUTTON_CIRCLE = 0, 39 | BUTTON_CROSS = 1, 40 | BUTTON_TRIANGLE = 2, 41 | BUTTON_SQUARE = 3, 42 | BUTTON_R1 = 4, 43 | BUTTON_R2 = 5, 44 | BUTTON_R3 = 6, 45 | BUTTON_L1 = 7, 46 | BUTTON_L2 = 8, 47 | BUTTON_L3 = 9, 48 | BUTTON_SELECT = 10, 49 | BUTTON_START = 11, 50 | BUTTON_TOUCH = 12, 51 | } PlatformButtonId; 52 | -------------------------------------------------------------------------------- /src/m2config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | #include "m2fixbase.h" 6 | 7 | class M2Config : public M2FixBase 8 | { 9 | public: 10 | M2Config() 11 | { 12 | bPatchesRemoveUnderpants = true; 13 | bPatchesEnableMosaic = true; 14 | bPatchesRestoreGhosts = true; 15 | bPatchesRestoreMedicine = true; 16 | } 17 | 18 | static auto & GetInstance() 19 | { 20 | static M2Config instance; 21 | return instance; 22 | } 23 | 24 | static void LoadInstance() 25 | { 26 | GetInstance().Load(); 27 | } 28 | 29 | virtual void Load() override; 30 | 31 | public: 32 | static inline bool bDebuggerEnabled; 33 | static inline int iDebuggerPort; 34 | static inline bool bDebuggerAutoUpdate; 35 | static inline bool bDebuggerExclusive; 36 | static inline std::optional bSmoothing; 37 | static inline std::optional bScanline; 38 | static inline std::optional bDotMatrix; 39 | static inline bool bBreak; 40 | static inline bool bConsole; 41 | static inline bool bError; 42 | static inline int iLevel; 43 | static inline int iNativeLevel; 44 | static inline int iEmulatorLevel; 45 | static inline int iRendererLevel; 46 | static inline bool bExternalEnabled; 47 | static inline int iExternalWidth; 48 | static inline int iExternalHeight; 49 | static inline bool bWindowedMode; 50 | static inline bool bBorderlessMode; 51 | static inline bool bInternalEnabled; 52 | static inline int iInternalHeight; 53 | static inline bool bInternalWidescreen; 54 | static inline bool bAnalogMode; 55 | static inline bool bLauncherSkipNotice; 56 | static inline bool bLauncherStartGame; 57 | static inline bool bGameStageSelect; 58 | static inline bool bPatchesDisableRAM; 59 | static inline bool bPatchesDisableCDROM; 60 | static inline bool bPatchesRemoveUnderpants; 61 | static inline bool bPatchesEnableMosaic; 62 | static inline bool bPatchesRestoreGhosts; 63 | static inline bool bPatchesRestoreMedicine; 64 | static inline bool bShouldCheckForUpdates; 65 | static inline bool bConsoleUpdateNotifications; 66 | 67 | static inline std::string sFullscreenMode; 68 | static inline std::string sExternalWidth; 69 | static inline std::string sExternalHeight; 70 | 71 | private: 72 | inipp::Ini m_ini; 73 | }; 74 | -------------------------------------------------------------------------------- /src/m2fixbase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | class M2FixBase 6 | { 7 | public: 8 | M2FixBase() {} 9 | 10 | virtual void Load() {}; 11 | }; 12 | -------------------------------------------------------------------------------- /src/m2game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | #include "m2fixbase.h" 6 | #include "m2machine.h" 7 | #include "ketchup.h" 8 | 9 | class M2Game : public M2FixBase 10 | { 11 | public: 12 | M2Game() {} 13 | 14 | static auto & GetInstance() 15 | { 16 | static M2Game instance; 17 | return instance; 18 | } 19 | 20 | virtual std::vector> MachineInstances() 21 | { 22 | return { M2Machine::GetInstance() }; 23 | } 24 | 25 | virtual std::vector *SQKetchupHook() { return nullptr; } 26 | 27 | virtual void SQOnMemoryDefine() {} 28 | virtual void SQOnUpdateGadgets() {} 29 | 30 | virtual std::pair EPIModuleHook() { return {}; } 31 | 32 | virtual void EPIOnLoadImage(void *image, size_t size) {} 33 | virtual bool EPIOnMachineCommand(std::any machine, int cmd, unsigned int **args) { return true; } 34 | virtual bool EPIOnCommandCPU(std::any cpu, int cmd, unsigned int **args) { return true; } 35 | 36 | virtual void GWRenderGeometry(int & gw_width, int & gw_height, int & fb_width, int & fb_height, int & img_width, int & img_height) {} 37 | virtual bool GWBlank() { return false; } 38 | }; 39 | 40 | #include "mgs1.h" 41 | -------------------------------------------------------------------------------- /src/m2machine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "m2fixbase.h" 4 | #include "stdafx.h" 5 | 6 | class M2Machine: public M2FixBase 7 | { 8 | public: 9 | M2Machine() {} 10 | 11 | static auto & GetInstance() 12 | { 13 | static M2Machine instance; 14 | return instance; 15 | } 16 | 17 | virtual void Load() {} 18 | virtual void BindModules() {} 19 | virtual void UpdateScreenGeometry(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) {} 20 | }; 21 | -------------------------------------------------------------------------------- /src/m2utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "m2hook.h" 4 | #include "stdafx.h" 5 | 6 | class M2Utils 7 | { 8 | public: 9 | M2Utils() {} 10 | 11 | static void LogSystemInfo(); 12 | 13 | static void CompatibilityWarnings(); 14 | 15 | static void memsetHook(); 16 | static void *memsetWait(void *str, int c, size_t n); 17 | static void memsetRelease(); 18 | 19 | static std::mutex memsetHookMutex; 20 | static bool memsetHookCalled; 21 | 22 | static std::mutex mainThreadFinishedMutex; 23 | static std::condition_variable mainThreadFinishedVar; 24 | static bool mainThreadFinished; 25 | 26 | static bool IsSteamOS(); 27 | static std::string GetSteamOSVersion(); 28 | }; 29 | -------------------------------------------------------------------------------- /src/psx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "m2machine.h" 4 | #include "m2/psx.h" 5 | #include "m2hook.h" 6 | #include "stdafx.h" 7 | 8 | using PSX_ModuleTables = std::map> *, std::function>; 9 | 10 | class PSX : public M2Machine 11 | { 12 | public: 13 | PSX() {} 14 | 15 | static auto & GetInstance() 16 | { 17 | static PSX instance; 18 | return instance; 19 | } 20 | 21 | virtual void Load() override; 22 | virtual void BindModules() override; 23 | virtual void UpdateScreenGeometry(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) override; 24 | 25 | static void main(struct M2_EmuR3000 *cpu); 26 | 27 | private: 28 | static M2_EmuPSX_Module *LoadSystemModule(M2_EmuPSX_Module *mod); 29 | static M2_EmuPSX_Module *LoadKernelModule(M2_EmuPSX_Module *mod); 30 | static M2_EmuPSX_Module *LoadUserModule(M2_EmuPSX_Module *mod); 31 | 32 | static void * __fastcall LoadModule(M2_EmuPSX_Module *mod, void *list); 33 | static void * __fastcall ListInsert(void *list, void *object); 34 | 35 | static int Kernel_Function(struct M2_EmuR3000 *cpu, int cycle, unsigned int address); 36 | static int Kernel_Vector(struct M2_EmuR3000 *cpu, int cycle, unsigned int address); 37 | static int Kernel_Call(struct M2_EmuR3000 *cpu, int cycle, unsigned int address); 38 | 39 | static void BindKernelModules(std::vector> &table = ModuleTable_Kernel); 40 | static void BindUserModules(PSX_ModuleTables & tables, const char *basename); 41 | 42 | static void CommandR3000(struct M2_EmuR3000 *cpu, int cmd, unsigned int **args); 43 | static void CommandPSX(struct M2_EmuPSX *psx, int cmd, unsigned int **args); 44 | static void CommandR3000101(struct M2_EmuR3000 *cpu, int cmd, unsigned int **args); 45 | static void CommandPSX101(struct M2_EmuPSX *psx, int cmd, unsigned int **args); 46 | static void LoadImage(void *image, size_t size); 47 | 48 | static void R3000_Hook(const char *table, int index, PSXFUNCTION func); 49 | 50 | #ifndef _WIN64 51 | static void GTE_RTP(safetyhook::Context & ctx); 52 | #endif 53 | 54 | public: 55 | static std::map ModuleHandlers; 56 | 57 | static unsigned int VideoMode; 58 | static M2_EmuPSX *Emulator; 59 | 60 | private: 61 | 62 | static std::map LibraryHandlers; 63 | static std::map Libraries; 64 | 65 | static std::vector> ModuleTable_Kernel; 66 | 67 | static std::map ModuleMap; 68 | 69 | static unsigned int ScreenWidth; 70 | static unsigned int ScreenHeight; 71 | static unsigned int ScreenScaleX; 72 | static unsigned int ScreenScaleY; 73 | static unsigned int ScreenMode; 74 | 75 | typedef struct { 76 | unsigned int spec; 77 | int index; 78 | std::variant table; 79 | } R3000_InstructionRecord; 80 | 81 | static std::map R3000_InstructionRecords; 82 | static std::map R3000_HookTable; 83 | static std::function R3000_Decode; 84 | }; 85 | -------------------------------------------------------------------------------- /src/sqbinary.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqinvoker.h" 4 | 5 | template 6 | class SQBinary : public SQInvoker 7 | { 8 | public: 9 | SQBinary(HSQOBJECT binary) : SQInvoker(binary) {} 10 | 11 | SQInteger At(SQInteger offset) { 12 | return this->Invoke(__func__, offset); 13 | } 14 | 15 | SQInteger Size() { 16 | return this->Invoke(__func__); 17 | } 18 | 19 | }; 20 | 21 | template SQBinary; 22 | template SQBinary; 23 | template SQBinary; 24 | template SQBinary; 25 | -------------------------------------------------------------------------------- /src/sqemutask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqinvoker.h" 4 | 5 | #include 6 | 7 | template 8 | class SQEmuTask : public SQInvoker 9 | { 10 | public: 11 | SQEmuTask() : SQInvoker(_SC("g_emu_task")) {} 12 | 13 | static SQInteger GetInfoInteger(const SQChar *key) { 14 | return SQEmuTask().Invoke(__func__, key); 15 | } 16 | static void SetInfoInteger(const SQChar *key, SQInteger value) { 17 | return SQEmuTask().Invoke(__func__, key, value); 18 | } 19 | 20 | static SQInteger GetRamValue(SQInteger width, SQInteger offset) { 21 | return SQEmuTask().Invoke(__func__, width, offset); 22 | } 23 | static void SetRamValue(SQInteger width, SQInteger offset, SQInteger value) { 24 | return SQEmuTask().Invoke(__func__, width, offset, value); 25 | } 26 | 27 | static void EntryCdRomPatch(SQInteger offset, Sqrat::Array & data) { 28 | return SQEmuTask().Invoke(__func__, offset, data); 29 | } 30 | static void ReleaseCdRomPatch() { 31 | return SQEmuTask().Invoke(__func__); 32 | } 33 | 34 | static SQBool GetSmoothing() { 35 | return SQEmuTask().Invoke(__func__); 36 | } 37 | static void SetSmoothing(SQBool enable) { 38 | return SQEmuTask().Invoke(__func__, enable); 39 | } 40 | 41 | static SQBool GetScanline() { 42 | return SQEmuTask().Invoke(__func__); 43 | } 44 | static void SetScanline(SQBool enable) { 45 | return SQEmuTask().Invoke(__func__, enable); 46 | } 47 | 48 | static SQInteger GetInputDirectionMerge() { 49 | return SQEmuTask().Invoke(__func__); 50 | } 51 | static void SetInputDirectionMerge(SQInteger mode) { 52 | return SQEmuTask().Invoke(__func__, mode); 53 | } 54 | 55 | static SQFloat GetInputDeadzone() { 56 | return SQEmuTask().Invoke(__func__); 57 | } 58 | static void SetInputDeadzone(SQFloat value) { 59 | return SQEmuTask().Invoke(__func__, value); 60 | } 61 | 62 | static void UpdateEmuScreen() { 63 | return SQEmuTask().Invoke(__func__); 64 | } 65 | 66 | template 67 | static Destination RamCopy(Destination dst, Source src, std::size_t size) { 68 | Destination dest = dst; 69 | if constexpr (std::is_pointer_v && std::is_integral_v) { 70 | const uint8_t * _src = reinterpret_cast(src); 71 | while (size >= sizeof(uint32_t)) { 72 | const uint32_t * __src = reinterpret_cast(_src); 73 | SetRamValue(sizeof(uint32_t) * CHAR_BIT, dst, *__src); 74 | size -= sizeof(uint32_t); _src += sizeof(uint32_t); dst += sizeof(uint32_t); 75 | } 76 | if (size >= sizeof(uint16_t)) { 77 | const uint16_t * __src = reinterpret_cast(_src); 78 | SetRamValue(sizeof(uint16_t) * CHAR_BIT, dst, *__src); 79 | size -= sizeof(uint16_t); _src += sizeof(uint16_t); dst += sizeof(uint16_t); 80 | } 81 | if (size >= sizeof(uint8_t)) { 82 | const uint8_t * __src = reinterpret_cast(_src); 83 | SetRamValue(sizeof(uint8_t) * CHAR_BIT, dst, *__src); 84 | size -= sizeof(uint8_t); _src += sizeof(uint8_t); dst += sizeof(uint8_t); 85 | } 86 | return dest; 87 | } 88 | else if constexpr (std::is_pointer_v && std::is_integral_v) { 89 | uint8_t * _dst = reinterpret_cast(dst); 90 | while (size >= sizeof(uint32_t)) { 91 | uint32_t * __dst = reinterpret_cast(_dst); 92 | *__dst = GetRamValue(sizeof(uint32_t) * CHAR_BIT, src); 93 | size -= sizeof(uint32_t); src += sizeof(uint32_t); _dst += sizeof(uint32_t); 94 | } 95 | if (size >= sizeof(uint16_t)) { 96 | uint16_t * __dst = reinterpret_cast(_dst); 97 | *__dst = GetRamValue(sizeof(uint16_t) * CHAR_BIT, src); 98 | size -= sizeof(uint16_t); src += sizeof(uint16_t); _dst += sizeof(uint16_t); 99 | } 100 | if (size >= sizeof(uint8_t)) { 101 | uint8_t * __dst = reinterpret_cast(_dst); 102 | *__dst = GetRamValue(sizeof(uint8_t) * CHAR_BIT, src); 103 | size -= sizeof(uint8_t); src += sizeof(uint8_t); _dst += sizeof(uint8_t); 104 | } 105 | return dest; 106 | } 107 | else static_assert(false); 108 | return dest; 109 | } 110 | 111 | }; 112 | 113 | template SQEmuTask; 114 | template SQEmuTask; 115 | template SQEmuTask; 116 | template SQEmuTask; 117 | -------------------------------------------------------------------------------- /src/sqglobals.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqrat.h" 4 | 5 | template 6 | class SQGlobals : public Sqrat::Object 7 | { 8 | public: 9 | SQGlobals() : Sqrat::Object(Sqrat::RootTable()) {} 10 | 11 | static int GetTitle() 12 | { 13 | return SQGlobals().GetSlot(_SC("s_current_title_dev_id")).Cast(); 14 | } 15 | 16 | static std::string GetExecutable() 17 | { 18 | auto rom = SQGlobals().GetSlot(_SC("s_rom_fileparse")); 19 | return 20 | rom.GetSlot("path").Cast() + 21 | rom.GetSlot("name").Cast() + 22 | rom.GetSlot("ext").Cast(); 23 | } 24 | 25 | static int GetDisk() 26 | { 27 | return SQGlobals().GetSlot(_SC("s_now_disk_no")).Cast(); 28 | } 29 | }; 30 | 31 | template SQGlobals; 32 | template SQGlobals; 33 | template SQGlobals; 34 | template SQGlobals; 35 | -------------------------------------------------------------------------------- /src/sqhelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqrat.h" 4 | 5 | template 6 | class SQHelper 7 | { 8 | public: 9 | SQHelper() {} 10 | 11 | template 12 | static std::vector MakeVector(Sqrat::Array &array) 13 | { 14 | std::vector vector(array.Length()); 15 | array.GetArray(vector.data(), vector.size()); 16 | return vector; 17 | } 18 | 19 | template 20 | static std::vector MakeVector(Sqrat::Object &object) 21 | { 22 | if (object.GetType() != OT_ARRAY) return {}; 23 | auto & array = static_cast &>(object); 24 | return MakeVector(array); 25 | } 26 | 27 | template 28 | static Sqrat::Array MakeArray(const std::vector &vector) 29 | { 30 | Sqrat::Array array; 31 | for (auto & item : vector) array.Append(item); 32 | return array; 33 | } 34 | 35 | // DO NOT USE e,g. `char` / `unsigned char` here. Use `int` / `unsigned int`. 36 | static Sqrat::Object GetObject(SQInteger idx, HSQUIRRELVM v = Sqrat::DefaultVM::Get()) 37 | { 38 | HSQOBJECT object; 39 | sq_getstackobj(v, idx, &object); 40 | return Sqrat::Object(object); 41 | } 42 | 43 | template 44 | static T *AcquireForeignObject(HSQUIRRELVM v = Sqrat::DefaultVM::Get()) 45 | { 46 | if (!sq_getforeignptr(v)) { 47 | sq_setforeignptr(v, new T {}); 48 | } 49 | return reinterpret_cast(sq_getforeignptr(v)); 50 | } 51 | }; 52 | 53 | template SQHelper; 54 | template SQHelper; 55 | template SQHelper; 56 | template SQHelper; 57 | -------------------------------------------------------------------------------- /src/sqinput.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqinvoker.h" 4 | 5 | template 6 | class SQInput : public SQInvoker 7 | { 8 | public: 9 | SQInput() : SQInvoker(_SC("g_input")) {} 10 | 11 | static SQFloat GetAnalogStickX() { 12 | return SQInput().Invoke(__func__); 13 | } 14 | 15 | static SQFloat GetAnalogStickY() { 16 | return SQInput().Invoke(__func__); 17 | } 18 | 19 | static SQFloat GetRightAnalogStickX() { 20 | return SQInput().Invoke(__func__); 21 | } 22 | 23 | static SQFloat GetRightAnalogStickY() { 24 | return SQInput().Invoke(__func__); 25 | } 26 | 27 | }; 28 | 29 | template SQInput; 30 | template SQInput; 31 | template SQInput; 32 | template SQInput; 33 | -------------------------------------------------------------------------------- /src/sqinputhub.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqinvoker.h" 4 | 5 | template 6 | class SQInputHub : public SQInvoker 7 | { 8 | public: 9 | SQInputHub() : SQInvoker(_SC("g_inputHub")) {} 10 | 11 | static void SetDirectionMerge(SQInteger mode) { 12 | return SQInputHub().Invoke(__func__, mode); 13 | } 14 | 15 | static void SetDeadzone(SQFloat value) { 16 | return SQInputHub().Invoke(__func__, value); 17 | } 18 | 19 | }; 20 | 21 | template SQInputHub; 22 | template SQInputHub; 23 | template SQInputHub; 24 | template SQInputHub; 25 | -------------------------------------------------------------------------------- /src/sqinvoker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqpcheader.h" 4 | #include "sqvm.h" 5 | #include "sqrat.h" 6 | 7 | #include 8 | #include 9 | 10 | template 11 | class SQInvoker 12 | { 13 | public: 14 | SQInvoker(const SQChar *name) 15 | { 16 | Sqrat::RootTable root = Sqrat::RootTable(); 17 | m_instance = root.GetSlot(name); 18 | } 19 | 20 | SQInvoker(const HSQOBJECT &obj) 21 | { 22 | m_instance = obj; 23 | } 24 | 25 | protected: 26 | inline Sqrat::Function Function(const char *function) 27 | { 28 | std::string name(function); 29 | name[0] = tolower(name[0]); 30 | return m_instance.GetFunction(name.c_str()); 31 | } 32 | 33 | template 34 | inline Return Invoke(Sqrat::Function function, Args ... args) 35 | { 36 | constexpr std::size_t count = sizeof...(Args); 37 | if constexpr (std::is_void_v) { 38 | if (function.IsNull()) return; 39 | if constexpr (count == 0) return function.Execute(); 40 | else return function.Execute(args ...); 41 | } else { 42 | if (function.IsNull()) return {}; 43 | Sqrat::SharedPtr ret; 44 | if constexpr (count == 0) ret = function.Evaluate(); 45 | else ret = function.Evaluate(args ...); 46 | if (!ret) return {}; 47 | return *ret; 48 | } 49 | } 50 | 51 | template 52 | inline Return Invoke(const char *function, Args ... args) 53 | { 54 | return Invoke(Function(function), args ...); 55 | } 56 | 57 | protected: 58 | Sqrat::Table m_instance; 59 | }; 60 | 61 | template SQInvoker; 62 | template SQInvoker; 63 | template SQInvoker; 64 | template SQInvoker; 65 | -------------------------------------------------------------------------------- /src/sqrat/README.txt: -------------------------------------------------------------------------------- 1 | Sqrat - Squirrel Binding Utility 2 | 3 | © 2009 Brandon Jones 4 | © 2011-2014 Li-Cheng (Andy) Tai 5 | © 2013-2015 Brandon Haffen AKA Wizzard 6 | 7 | 8 | Sqrat is a C++ binding utility for the Squirrel language. 9 | Up-to-date documentation can be created using Doxygen. 10 | Slightly outdated documentation can be found at 11 | http://scrat.sourceforge.net/0.9/ 12 | 13 | Sqrat only contains C++ headers so for installation you just 14 | need to copy the files in the include directory to 15 | some common header path, such as /usr/local/include. 16 | 17 | However, an autotool based build system can be checked out from 18 | the code repository (not in the relase tar file to reduce file size) 19 | which allows you to install, on POSIX systems, with 20 | the familiar commands of 21 | 22 | autotool/configure --prefix= 23 | make && make install 24 | 25 | You can then run 26 | 27 | make check 28 | 29 | to run the unit tests. 30 | 31 | Alternatively you can follow the steps in 32 | running_tests.txt 33 | 34 | to directly run unit tests. 35 | 36 | For more information, see index.html in the docs subdirectory 37 | 38 | Discussion and User Support 39 | 40 | Discussion about Sqrat happens at the Squirrel language forum, 41 | the Bindings section 42 | http://squirrel-lang.org/forums/default.aspx?g=topics&f=4 43 | 44 | Bug Reporting 45 | 46 | Bug reports or feature enhancement requests and patches can 47 | be submitted at the SourceForge Sqrat site 48 | https://sourceforge.net/tracker/?group_id=261661&atid=2349886 49 | -------------------------------------------------------------------------------- /src/sqrat/gtest-1.3.0/CHANGES: -------------------------------------------------------------------------------- 1 | Changes for 1.3.0: 2 | 3 | * New feature: death tests on Windows, Cygwin, and Mac. 4 | * New feature: ability to use Google Test assertions in other testing 5 | frameworks. 6 | * New feature: ability to run disabled test via 7 | --gtest_also_run_disabled_tests. 8 | * New feature: the --help flag for printing the usage. 9 | * New feature: access to Google Test flag values in user code. 10 | * New feature: a script that packs Google Test into one .h and one 11 | .cc file for easy deployment. 12 | * New feature: support for distributing test functions to multiple 13 | machines (requires support from the test runner). 14 | * Bug fixes and implementation clean-up. 15 | 16 | Changes for 1.2.1: 17 | 18 | * Compatibility fixes for Linux IA-64 and IBM z/OS. 19 | * Added support for using Boost and other TR1 implementations. 20 | * Changes to the build scripts to support upcoming release of Google C++ 21 | Mocking Framework. 22 | * Added Makefile to the distribution package. 23 | * Improved build instructions in README. 24 | 25 | Changes for 1.2.0: 26 | 27 | * New feature: value-parameterized tests. 28 | * New feature: the ASSERT/EXPECT_(NON)FATAL_FAILURE(_ON_ALL_THREADS) 29 | macros. 30 | * Changed the XML report format to match JUnit/Ant's. 31 | * Added tests to the Xcode project. 32 | * Added scons/SConscript for building with SCons. 33 | * Added src/gtest-all.cc for building Google Test from a single file. 34 | * Fixed compatibility with Solaris and z/OS. 35 | * Enabled running Python tests on systems with python 2.3 installed, 36 | e.g. Mac OS X 10.4. 37 | * Bug fixes. 38 | 39 | Changes for 1.1.0: 40 | 41 | * New feature: type-parameterized tests. 42 | * New feature: exception assertions. 43 | * New feature: printing elapsed time of tests. 44 | * Improved the robustness of death tests. 45 | * Added an Xcode project and samples. 46 | * Adjusted the output format on Windows to be understandable by Visual Studio. 47 | * Minor bug fixes. 48 | 49 | Changes for 1.0.1: 50 | 51 | * Added project files for Visual Studio 7.1. 52 | * Fixed issues with compiling on Mac OS X. 53 | * Fixed issues with compiling on Cygwin. 54 | 55 | Changes for 1.0.0: 56 | 57 | * Initial Open Source release of Google Test 58 | -------------------------------------------------------------------------------- /src/sqrat/gtest-1.3.0/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This file contains a list of people who've made non-trivial 2 | # contribution to the Google C++ Testing Framework project. People 3 | # who commit code to the project are encouraged to add their names 4 | # here. Please keep the list sorted by first names. 5 | 6 | Ajay Joshi 7 | Balázs Dán 8 | Bharat Mediratta 9 | Chandler Carruth 10 | Chris Prince 11 | Chris Taylor 12 | Dan Egnor 13 | Eric Roman 14 | Jeffrey Yasskin 15 | Jói Sigurðsson 16 | Keir Mierle 17 | Keith Ray 18 | Kenton Varda 19 | Markus Heule 20 | Mika Raento 21 | Patrick Hanna 22 | Patrick Riley 23 | Peter Kaminski 24 | Preston Jackson 25 | Rainer Klaffenboeck 26 | Russ Cox 27 | Russ Rufer 28 | Sean Mcafee 29 | Sigurður Ásgeirsson 30 | Tracy Bialik 31 | Vadim Berman 32 | Vlad Losev 33 | Zhanyong Wan 34 | -------------------------------------------------------------------------------- /src/sqrat/gtest-1.3.0/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2008, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /src/sqrat/gtest-1.3.0/build_gtest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -ex 2 | g++ -fpermissive -I. -I./include -c src/gtest-all.cc && \ 3 | ar -rv libgtest.a gtest-all.o -------------------------------------------------------------------------------- /src/sqrat/gtest-1.3.0/include/gtest/gtest_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Google C++ Testing Framework definitions useful in production code. 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 36 | 37 | // When you need to test the private or protected members of a class, 38 | // use the FRIEND_TEST macro to declare your tests as friends of the 39 | // class. For example: 40 | // 41 | // class MyClass { 42 | // private: 43 | // void MyMethod(); 44 | // FRIEND_TEST(MyClassTest, MyMethod); 45 | // }; 46 | // 47 | // class MyClassTest : public testing::Test { 48 | // // ... 49 | // }; 50 | // 51 | // TEST_F(MyClassTest, MyMethod) { 52 | // // Can call MyClass::MyMethod() here. 53 | // } 54 | 55 | #define FRIEND_TEST(test_case_name, test_name)\ 56 | friend class test_case_name##_##test_name##_Test 57 | 58 | #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 59 | -------------------------------------------------------------------------------- /src/sqrat/gtest-1.3.0/src/gtest-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // Google C++ Testing Framework (Google Test) 33 | // 34 | // Sometimes it's desirable to build Google Test by compiling a single file. 35 | // This file serves this purpose. 36 | #include "src/gtest.cc" 37 | #include "src/gtest-death-test.cc" 38 | #include "src/gtest-filepath.cc" 39 | #include "src/gtest-port.cc" 40 | #include "src/gtest-test-part.cc" 41 | #include "src/gtest-typed-test.cc" 42 | -------------------------------------------------------------------------------- /src/sqrat/gtest-1.3.0/src/gtest-test-part.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // The Google C++ Testing Framework (Google Test) 33 | 34 | #include 35 | 36 | // Indicates that this translation unit is part of Google Test's 37 | // implementation. It must come before gtest-internal-inl.h is 38 | // included, or there will be a compiler error. This trick is to 39 | // prevent a user from accidentally including gtest-internal-inl.h in 40 | // his code. 41 | #define GTEST_IMPLEMENTATION_ 1 42 | #include "src/gtest-internal-inl.h" 43 | #undef GTEST_IMPLEMENTATION_ 44 | 45 | namespace testing { 46 | 47 | // Gets the summary of the failure message by omitting the stack trace 48 | // in it. 49 | internal::String TestPartResult::ExtractSummary(const char* message) { 50 | const char* const stack_trace = strstr(message, internal::kStackTraceMarker); 51 | return stack_trace == NULL ? internal::String(message) : 52 | internal::String(message, stack_trace - message); 53 | } 54 | 55 | // Prints a TestPartResult object. 56 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { 57 | return os << result.file_name() << ":" 58 | << result.line_number() << ": " 59 | << (result.type() == TPRT_SUCCESS ? "Success" : 60 | result.type() == TPRT_FATAL_FAILURE ? "Fatal failure" : 61 | "Non-fatal failure") << ":\n" 62 | << result.message() << std::endl; 63 | } 64 | 65 | // Constructs an empty TestPartResultArray. 66 | TestPartResultArray::TestPartResultArray() 67 | : list_(new internal::List) { 68 | } 69 | 70 | // Destructs a TestPartResultArray. 71 | TestPartResultArray::~TestPartResultArray() { 72 | delete list_; 73 | } 74 | 75 | // Appends a TestPartResult to the array. 76 | void TestPartResultArray::Append(const TestPartResult& result) { 77 | list_->PushBack(result); 78 | } 79 | 80 | // Returns the TestPartResult at the given index (0-based). 81 | const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { 82 | if (index < 0 || index >= size()) { 83 | printf("\nInvalid index (%d) into TestPartResultArray.\n", index); 84 | internal::abort(); 85 | } 86 | 87 | const internal::ListNode* p = list_->Head(); 88 | for (int i = 0; i < index; i++) { 89 | p = p->next(); 90 | } 91 | 92 | return p->element(); 93 | } 94 | 95 | // Returns the number of TestPartResult objects in the array. 96 | int TestPartResultArray::size() const { 97 | return list_->size(); 98 | } 99 | 100 | namespace internal { 101 | 102 | HasNewFatalFailureHelper::HasNewFatalFailureHelper() 103 | : has_new_fatal_failure_(false), 104 | original_reporter_(UnitTest::GetInstance()->impl()-> 105 | GetTestPartResultReporterForCurrentThread()) { 106 | UnitTest::GetInstance()->impl()->SetTestPartResultReporterForCurrentThread( 107 | this); 108 | } 109 | 110 | HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { 111 | UnitTest::GetInstance()->impl()->SetTestPartResultReporterForCurrentThread( 112 | original_reporter_); 113 | } 114 | 115 | void HasNewFatalFailureHelper::ReportTestPartResult( 116 | const TestPartResult& result) { 117 | if (result.fatally_failed()) 118 | has_new_fatal_failure_ = true; 119 | original_reporter_->ReportTestPartResult(result); 120 | } 121 | 122 | } // namespace internal 123 | 124 | } // namespace testing 125 | -------------------------------------------------------------------------------- /src/sqrat/gtest-1.3.0/src/gtest-typed-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include 33 | #include 34 | 35 | namespace testing { 36 | namespace internal { 37 | 38 | #if GTEST_HAS_TYPED_TEST_P 39 | 40 | // Verifies that registered_tests match the test names in 41 | // defined_test_names_; returns registered_tests if successful, or 42 | // aborts the program otherwise. 43 | const char* TypedTestCasePState::VerifyRegisteredTestNames( 44 | const char* file, int line, const char* registered_tests) { 45 | typedef ::std::set::const_iterator DefinedTestIter; 46 | registered_ = true; 47 | 48 | Message errors; 49 | ::std::set tests; 50 | for (const char* names = registered_tests; names != NULL; 51 | names = SkipComma(names)) { 52 | const String name = GetPrefixUntilComma(names); 53 | if (tests.count(name) != 0) { 54 | errors << "Test " << name << " is listed more than once.\n"; 55 | continue; 56 | } 57 | 58 | bool found = false; 59 | for (DefinedTestIter it = defined_test_names_.begin(); 60 | it != defined_test_names_.end(); 61 | ++it) { 62 | if (name == *it) { 63 | found = true; 64 | break; 65 | } 66 | } 67 | 68 | if (found) { 69 | tests.insert(name); 70 | } else { 71 | errors << "No test named " << name 72 | << " can be found in this test case.\n"; 73 | } 74 | } 75 | 76 | for (DefinedTestIter it = defined_test_names_.begin(); 77 | it != defined_test_names_.end(); 78 | ++it) { 79 | if (tests.count(*it) == 0) { 80 | errors << "You forgot to list test " << *it << ".\n"; 81 | } 82 | } 83 | 84 | const String& errors_str = errors.GetString(); 85 | if (errors_str != "") { 86 | fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), 87 | errors_str.c_str()); 88 | fflush(stderr); 89 | abort(); 90 | } 91 | 92 | return registered_tests; 93 | } 94 | 95 | #endif // GTEST_HAS_TYPED_TEST_P 96 | 97 | } // namespace internal 98 | } // namespace testing 99 | -------------------------------------------------------------------------------- /src/sqrat/gtest-1.3.0/src/gtest_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include 31 | 32 | #include 33 | 34 | int main(int argc, char **argv) { 35 | std::cout << "Running main() from gtest_main.cc\n"; 36 | 37 | testing::InitGoogleTest(&argc, argv); 38 | return RUN_ALL_TESTS(); 39 | } 40 | -------------------------------------------------------------------------------- /src/sqrat/include/sqrat.h: -------------------------------------------------------------------------------- 1 | // 2 | // Sqrat: Squirrel C++ Binding Utility 3 | // 4 | 5 | // 6 | // Copyright (c) 2009 Brandon Jones 7 | // 8 | // This software is provided 'as-is', without any express or implied 9 | // warranty. In no event will the authors be held liable for any damages 10 | // arising from the use of this software. 11 | // 12 | // Permission is granted to anyone to use this software for any purpose, 13 | // including commercial applications, and to alter it and redistribute it 14 | // freely, subject to the following restrictions: 15 | // 16 | // 1. The origin of this software must not be misrepresented; you must not 17 | // claim that you wrote the original software. If you use this software 18 | // in a product, an acknowledgment in the product documentation would be 19 | // appreciated but is not required. 20 | // 21 | // 2. Altered source versions must be plainly marked as such, and must not be 22 | // misrepresented as being the original software. 23 | // 24 | // 3. This notice may not be removed or altered from any source 25 | // distribution. 26 | // 27 | 28 | /*! \mainpage Sqrat Main Page 29 | * 30 | * \section intro_sec Introduction 31 | * 32 | * Sqrat is a C++ library for Squirrel that facilitates exposing classes and other native functionality to Squirrel scripts. It models the underlying Squirrel API closely to give access to a wider range of functionality than other binding libraries. In addition to the binding library, Sqrat features a threading library and a module import library. 33 | * 34 | * \section install_sec Installation 35 | * 36 | * Sqrat only contains C++ headers so for installation you just need to copy the files in the include directory to some common header path. 37 | * 38 | * \section sec_faq Frequently Asked Questions 39 | * 40 | * Q: My application is crashing when I call sq_close. Why is this happening?
41 | * A: All Sqrat::Object instances and derived type instances must be destroyed before calling sq_close. 42 | * 43 | * \section discuss_sec Discussion and User Support 44 | * 45 | * Discussion about Sqrat happens at the Squirrel language forum, the Bindings section 46 | * http://squirrel-lang.org/forums/default.aspx?g=topics&f=4 47 | * 48 | * \section bug_sec Bug Reporting 49 | * 50 | * Bug reports or feature enhancement requests and patches can be submitted at the SourceForge Sqrat site 51 | * https://sourceforge.net/p/scrat/sqrat/ 52 | * 53 | * You're invited to make documentation suggestions for Sqrat. Together, we can make Sqrat as easy to understand as possible! 54 | */ 55 | 56 | #if !defined(_SCRAT_MAIN_H_) 57 | #define _SCRAT_MAIN_H_ 58 | 59 | #include 60 | 61 | #include "sqrat/sqratTable.h" 62 | #include "sqrat/sqratClass.h" 63 | #include "sqrat/sqratFunction.h" 64 | #include "sqrat/sqratConst.h" 65 | #include "sqrat/sqratUtil.h" 66 | #include "sqrat/sqratScript.h" 67 | #include "sqrat/sqratArray.h" 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/sqrat/include/sqratimport.h: -------------------------------------------------------------------------------- 1 | // 2 | // SqImport: Supports importing of squirrel modules 3 | // 4 | 5 | // 6 | // Copyright (c) 2009 Brandon Jones 7 | // 8 | // This software is provided 'as-is', without any express or implied 9 | // warranty. In no event will the authors be held liable for any damages 10 | // arising from the use of this software. 11 | // 12 | // Permission is granted to anyone to use this software for any purpose, 13 | // including commercial applications, and to alter it and redistribute it 14 | // freely, subject to the following restrictions: 15 | // 16 | // 1. The origin of this software must not be misrepresented; you must not 17 | // claim that you wrote the original software. If you use this software 18 | // in a product, an acknowledgment in the product documentation would be 19 | // appreciated but is not required. 20 | // 21 | // 2. Altered source versions must be plainly marked as such, and must not be 22 | // misrepresented as being the original software. 23 | // 24 | // 3. This notice may not be removed or altered from any source 25 | // distribution. 26 | // 27 | 28 | #if !defined(_SQ_IMPORT_H_) 29 | #define _SQ_IMPORT_H_ 30 | 31 | #include 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | /// To be documented... 35 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 36 | template 37 | SQUIRREL_API SQRESULT sqrat_import(HSQUIRRELVM v); 38 | 39 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 40 | /// To be documented... 41 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 42 | template 43 | SQUIRREL_API SQRESULT sqrat_register_importlib(HSQUIRRELVM v); 44 | 45 | #endif /*_SQ_IMPORT_H_*/ 46 | -------------------------------------------------------------------------------- /src/sqrat/running_tests.txt: -------------------------------------------------------------------------------- 1 | currently there are shell scripts to facilitate running the built in unit tests 2 | on GNU/Linux and Unix like systems. 3 | 4 | Steps: 5 | (cd gtest-1.3.0 && ./build_gtest.sh) 6 | (cd sqrattest && ./build_tests.sh && ./run_tests.sh) 7 | 8 | You can edit build_tests.sh to point to the location of your squirrel include 9 | and library directory paths, if they are not in /usr/local/. 10 | 11 | Batch files to do the same on Microsoft Windows: contributions welcome! -------------------------------------------------------------------------------- /src/sqrat/sqrat.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sqrattest", "sqrattest\sqrattest.vcproj", "{9EC4B19C-F37A-45C8-B7D5-C846C47F4CD0}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077} = {E2A9E1AF-60A2-46D3-961E-D2409ABA8077} 7 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7} = {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7} 8 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4} = {4AF3668E-3792-4116-8F27-B9B896DE3BA4} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "gtest-1.3.0\msvc\gtest.vcproj", "{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}" 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sq", "sq\sq.vcproj", "{B3603CE9-B950-4111-B2DE-8259F44A8851}" 14 | ProjectSection(ProjectDependencies) = postProject 15 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4} = {4AF3668E-3792-4116-8F27-B9B896DE3BA4} 16 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077} = {E2A9E1AF-60A2-46D3-961E-D2409ABA8077} 17 | EndProjectSection 18 | EndProject 19 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sqratthread", "sqratthread\sqratthread.vcproj", "{E2A9E1AF-60A2-46D3-961E-D2409ABA8077}" 20 | EndProject 21 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sqratimport", "sqimport\sqratimport.vcproj", "{4AF3668E-3792-4116-8F27-B9B896DE3BA4}" 22 | EndProject 23 | Global 24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 25 | Debug|Win32 = Debug|Win32 26 | Debug|x64 = Debug|x64 27 | Release|Win32 = Release|Win32 28 | Release|x64 = Release|x64 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {9EC4B19C-F37A-45C8-B7D5-C846C47F4CD0}.Debug|Win32.ActiveCfg = Debug|Win32 32 | {9EC4B19C-F37A-45C8-B7D5-C846C47F4CD0}.Debug|Win32.Build.0 = Debug|Win32 33 | {9EC4B19C-F37A-45C8-B7D5-C846C47F4CD0}.Debug|x64.ActiveCfg = Debug|x64 34 | {9EC4B19C-F37A-45C8-B7D5-C846C47F4CD0}.Debug|x64.Build.0 = Debug|x64 35 | {9EC4B19C-F37A-45C8-B7D5-C846C47F4CD0}.Release|Win32.ActiveCfg = Release|Win32 36 | {9EC4B19C-F37A-45C8-B7D5-C846C47F4CD0}.Release|Win32.Build.0 = Release|Win32 37 | {9EC4B19C-F37A-45C8-B7D5-C846C47F4CD0}.Release|x64.ActiveCfg = Release|x64 38 | {9EC4B19C-F37A-45C8-B7D5-C846C47F4CD0}.Release|x64.Build.0 = Release|x64 39 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug|Win32.ActiveCfg = Debug|Win32 40 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug|Win32.Build.0 = Debug|Win32 41 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug|x64.ActiveCfg = Debug|x64 42 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug|x64.Build.0 = Debug|x64 43 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release|Win32.ActiveCfg = Release|Win32 44 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release|Win32.Build.0 = Release|Win32 45 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release|x64.ActiveCfg = Release|x64 46 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release|x64.Build.0 = Release|x64 47 | {B3603CE9-B950-4111-B2DE-8259F44A8851}.Debug|Win32.ActiveCfg = Debug|Win32 48 | {B3603CE9-B950-4111-B2DE-8259F44A8851}.Debug|Win32.Build.0 = Debug|Win32 49 | {B3603CE9-B950-4111-B2DE-8259F44A8851}.Debug|x64.ActiveCfg = Debug|x64 50 | {B3603CE9-B950-4111-B2DE-8259F44A8851}.Debug|x64.Build.0 = Debug|x64 51 | {B3603CE9-B950-4111-B2DE-8259F44A8851}.Release|Win32.ActiveCfg = Release|Win32 52 | {B3603CE9-B950-4111-B2DE-8259F44A8851}.Release|Win32.Build.0 = Release|Win32 53 | {B3603CE9-B950-4111-B2DE-8259F44A8851}.Release|x64.ActiveCfg = Release|x64 54 | {B3603CE9-B950-4111-B2DE-8259F44A8851}.Release|x64.Build.0 = Release|x64 55 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077}.Debug|Win32.ActiveCfg = Debug|Win32 56 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077}.Debug|Win32.Build.0 = Debug|Win32 57 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077}.Debug|x64.ActiveCfg = Debug|x64 58 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077}.Debug|x64.Build.0 = Debug|x64 59 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077}.Release|Win32.ActiveCfg = Release|Win32 60 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077}.Release|Win32.Build.0 = Release|Win32 61 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077}.Release|x64.ActiveCfg = Release|x64 62 | {E2A9E1AF-60A2-46D3-961E-D2409ABA8077}.Release|x64.Build.0 = Release|x64 63 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4}.Debug|Win32.ActiveCfg = Debug|Win32 64 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4}.Debug|Win32.Build.0 = Debug|Win32 65 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4}.Debug|x64.ActiveCfg = Debug|x64 66 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4}.Debug|x64.Build.0 = Debug|x64 67 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4}.Release|Win32.ActiveCfg = Release|Win32 68 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4}.Release|Win32.Build.0 = Release|Win32 69 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4}.Release|x64.ActiveCfg = Release|x64 70 | {4AF3668E-3792-4116-8F27-B9B896DE3BA4}.Release|x64.Build.0 = Release|x64 71 | EndGlobalSection 72 | GlobalSection(SolutionProperties) = preSolution 73 | HideSolutionNode = FALSE 74 | EndGlobalSection 75 | EndGlobal 76 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/ClassProperties.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Brandon Jones 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #include 25 | #include 26 | #include "Fixture.h" 27 | 28 | using namespace Sqrat; 29 | 30 | struct Item { 31 | Item() {} 32 | Item(const Item& i) : name(i.name) {} 33 | string name; 34 | }; 35 | 36 | class Player { 37 | public: 38 | Player() : health(10) {}; 39 | 40 | int Health() const { 41 | return health; 42 | } 43 | 44 | void SetHealth(const int& h) { 45 | health = h; 46 | if(health < 0) { 47 | health = 0; 48 | } 49 | } 50 | 51 | bool Dead() const { 52 | return (health == 0); 53 | } 54 | 55 | Item LeftHand() const { 56 | return leftHand; 57 | } 58 | 59 | void SetLeftHand(const Item& i) { 60 | leftHand = i; 61 | } 62 | 63 | Item RightHand() const { 64 | return rightHand; 65 | } 66 | 67 | void SetRightHand(const Item& i) { 68 | rightHand = i; 69 | } 70 | 71 | private: 72 | int health; 73 | Item leftHand; 74 | Item rightHand; 75 | }; 76 | 77 | TEST_F(SqratTest, ClassProperties) { 78 | DefaultVM::Set(vm); 79 | 80 | RootTable().Bind(_SC("Item"), 81 | Class(vm, _SC("Item")) 82 | .Var(_SC("name"), &Item::name) 83 | ); 84 | 85 | RootTable().Bind(_SC("Player"), 86 | Class(vm, _SC("Player")) 87 | // Properties 88 | .Prop(_SC("health"), &Player::Health, &Player::SetHealth) 89 | .Prop(_SC("dead"), &Player::Dead) // Read Only Property 90 | .Prop(_SC("leftHand"), &Player::LeftHand, &Player::SetLeftHand) 91 | .Prop(_SC("rightHand"), &Player::RightHand, &Player::SetRightHand) 92 | ); 93 | 94 | Script script; 95 | script.CompileString(_SC(" \ 96 | p <- Player(); \ 97 | gTest.EXPECT_INT_EQ(p.health, 10); \ 98 | p.health = 5; \ 99 | gTest.EXPECT_INT_EQ(p.health, 5); \ 100 | p.health -= 3; \ 101 | gTest.EXPECT_INT_EQ(p.health, 2); \ 102 | p.health -= 3; \ 103 | gTest.EXPECT_INT_EQ(p.health, 0); \ 104 | gTest.EXPECT_TRUE(p.dead); \ 105 | \ 106 | item1 <- Item(); \ 107 | item1.name = \"Sword\"; \ 108 | p.rightHand = item1; \ 109 | item2 <- Item(); \ 110 | item2.name = \"Shield\"; \ 111 | p.leftHand = item2; \ 112 | gTest.EXPECT_STR_EQ(p.rightHand.name, \"Sword\"); \ 113 | gTest.EXPECT_STR_EQ(p.leftHand.name, \"Shield\"); \ 114 | ")); 115 | if (Sqrat::Error::Occurred(vm)) { 116 | FAIL() << _SC("Compile Failed: ") << Sqrat::Error::Message(vm); 117 | } 118 | 119 | script.Run(); 120 | if (Sqrat::Error::Occurred(vm)) { 121 | FAIL() << _SC("Run Failed: ") << Sqrat::Error::Message(vm); 122 | } 123 | } -------------------------------------------------------------------------------- /src/sqrat/sqrattest/ConstBindings.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Brandon Jones 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #include 25 | #include 26 | #include "Fixture.h" 27 | 28 | using namespace Sqrat; 29 | 30 | TEST_F(SqratTest, ConstBindings) { 31 | DefaultVM::Set(vm); 32 | 33 | ConstTable(vm).Enum(_SC("Color"), Enumeration(vm) 34 | .Const(_SC("Black"), 0) 35 | .Const(_SC("Red"), 1) 36 | .Const(_SC("Green"), 2) 37 | .Const(_SC("Blue"), 3) 38 | ); 39 | 40 | ConstTable().Const(_SC("Version"), _SC("1.0.0")); 41 | 42 | Script script; 43 | script.CompileString(_SC(" \ 44 | gTest.EXPECT_INT_EQ(Color.Black, 0); \ 45 | gTest.EXPECT_INT_EQ(Color.Red, 1); \ 46 | gTest.EXPECT_INT_EQ(Color.Green, 2); \ 47 | gTest.EXPECT_INT_EQ(Color.Blue, 3); \ 48 | gTest.EXPECT_STR_EQ(Version, \"1.0.0\"); \ 49 | ")); 50 | if (Sqrat::Error::Occurred(vm)) { 51 | FAIL() << _SC("Compile Failed: ") << Sqrat::Error::Message(vm); 52 | } 53 | 54 | script.Run(); 55 | if (Sqrat::Error::Occurred(vm)) { 56 | FAIL() << _SC("Run Failed: ") << Sqrat::Error::Message(vm); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/Fixture.h: -------------------------------------------------------------------------------- 1 | #if !defined(SQRAT_TEST_FIXTURE_H) 2 | #define SQRAT_TEST_FIXTURE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Sqrat { 16 | 17 | class SqratTest : public ::testing::Test { 18 | protected: 19 | HSQUIRRELVM vm; 20 | 21 | virtual void SetUp() { 22 | vm = sq_open(1024); 23 | #if SQUIRREL_VERSION_NUMBER >= 300 24 | sq_setprintfunc(vm, printfunc, printfunc); 25 | #else 26 | sq_setprintfunc(vm, printfunc); 27 | #endif 28 | 29 | sq_newclosure(vm, errorhandler,0); 30 | sq_seterrorhandler(vm); 31 | 32 | BindTestFunctions(); 33 | } 34 | 35 | virtual void TearDown() { 36 | sq_close(vm); 37 | } 38 | 39 | #ifdef SQUNICODE 40 | #define scvprintf vwprintf 41 | #else 42 | #define scvprintf vprintf 43 | #endif 44 | 45 | static void printfunc(HSQUIRRELVM v,const SQChar *s,...) { 46 | va_list vl; 47 | va_start(vl, s); 48 | scvprintf(s, vl); 49 | va_end(vl); 50 | } 51 | 52 | static SQInteger errorhandler(HSQUIRRELVM v) { 53 | const SQChar *sErr = 0; 54 | if(sq_gettop(v)>=1) { 55 | if(SQ_SUCCEEDED(sq_getstring(v,2,&sErr))) { 56 | ADD_FAILURE() << _SC("A Script Error Occured: ") << sErr; 57 | } 58 | else { 59 | ADD_FAILURE() << _SC("An Unknown Script Error Occured.") << sErr; 60 | } 61 | } 62 | return 0; 63 | } 64 | 65 | // Test Macros 66 | 67 | // Assert 68 | static void SQ_ASSERT_TRUE(bool a) { 69 | ASSERT_TRUE(a); 70 | } 71 | 72 | static void SQ_ASSERT_FALSE(bool a) { 73 | ASSERT_FALSE(a); 74 | } 75 | 76 | static void SQ_ASSERT_INT_EQ(int a, int b) { 77 | ASSERT_EQ(a, b); 78 | } 79 | 80 | static void SQ_ASSERT_INT_NE(int a, int b) { 81 | ASSERT_NE(a, b); 82 | } 83 | 84 | static void SQ_ASSERT_FLOAT_EQ(float a, float b) { 85 | ASSERT_FLOAT_EQ(a, b); 86 | } 87 | 88 | static void SQ_ASSERT_FLOAT_NE(float a, float b) { 89 | ASSERT_NE(a, b); 90 | } 91 | 92 | static void SQ_ASSERT_STR_EQ(string a, string b) { 93 | ASSERT_STREQ(a.c_str(), b.c_str()); 94 | } 95 | 96 | static void SQ_ASSERT_STR_NE(string a, string b) { 97 | ASSERT_STRNE(a.c_str(), b.c_str()); 98 | } 99 | 100 | // Expect 101 | static void SQ_EXPECT_TRUE(bool a) { 102 | EXPECT_TRUE(a); 103 | } 104 | 105 | static void SQ_EXPECT_FALSE(bool a) { 106 | EXPECT_FALSE(a); 107 | } 108 | 109 | static void SQ_EXPECT_INT_EQ(int a, int b) { 110 | EXPECT_EQ(a, b); 111 | } 112 | 113 | static void SQ_EXPECT_INT_NE(int a, int b) { 114 | EXPECT_NE(a, b); 115 | } 116 | 117 | static void SQ_EXPECT_FLOAT_EQ(float a, float b) { 118 | EXPECT_FLOAT_EQ(a, b); 119 | } 120 | 121 | static void SQ_EXPECT_FLOAT_NE(float a, float b) { 122 | EXPECT_NE(a, b); 123 | } 124 | 125 | static void SQ_EXPECT_STR_EQ(string a, string b) { 126 | EXPECT_STREQ(a.c_str(), b.c_str()); 127 | } 128 | 129 | static void SQ_EXPECT_STR_NE(string a, string b) { 130 | EXPECT_STRNE(a.c_str(), b.c_str()); 131 | } 132 | 133 | void BindTestFunctions() { 134 | 135 | RootTable(vm).Bind(_SC("gTest"), Table(vm) 136 | .Func(_SC("ASSERT_TRUE"), &SQ_ASSERT_TRUE) 137 | .Func(_SC("ASSERT_FALSE"), &SQ_ASSERT_FALSE) 138 | .Func(_SC("ASSERT_INT_EQ"), &SQ_ASSERT_INT_EQ) 139 | .Func(_SC("ASSERT_INT_NE"), &SQ_ASSERT_INT_NE) 140 | .Func(_SC("ASSERT_FLOAT_EQ"), &SQ_ASSERT_FLOAT_EQ) 141 | .Func(_SC("ASSERT_FLOAT_NE"), &SQ_ASSERT_FLOAT_NE) 142 | .Func(_SC("ASSERT_STR_EQ"), &SQ_ASSERT_STR_EQ) 143 | .Func(_SC("ASSERT_STR_NE"), &SQ_ASSERT_STR_NE) 144 | 145 | .Func(_SC("EXPECT_TRUE"), &SQ_EXPECT_TRUE) 146 | .Func(_SC("EXPECT_FALSE"), &SQ_EXPECT_FALSE) 147 | .Func(_SC("EXPECT_INT_EQ"), &SQ_EXPECT_INT_EQ) 148 | .Func(_SC("EXPECT_INT_NE"), &SQ_EXPECT_INT_NE) 149 | .Func(_SC("EXPECT_FLOAT_EQ"), &SQ_EXPECT_FLOAT_EQ) 150 | .Func(_SC("EXPECT_FLOAT_NE"), &SQ_EXPECT_FLOAT_NE) 151 | .Func(_SC("EXPECT_STR_EQ"), &SQ_EXPECT_STR_EQ) 152 | .Func(_SC("EXPECT_STR_NE"), &SQ_EXPECT_STR_NE) 153 | ); 154 | 155 | } 156 | }; 157 | 158 | } 159 | 160 | #endif 161 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/FuncInputArgumentType.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Li-Cheng (Andy) Tai 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #include 25 | #include 26 | #include "Fixture.h" 27 | 28 | 29 | using namespace Sqrat; 30 | 31 | class Vector2 32 | { 33 | public: 34 | float value; 35 | 36 | //some Vector Math overloads and members here 37 | operator float() const 38 | { 39 | return 1.0f; /* test only */ 40 | } 41 | 42 | 43 | Vector2 operator +(const Vector2& v) 44 | { 45 | value += v.value; 46 | return v; /* test only */ 47 | } 48 | 49 | inline float add(const Vector2& v) 50 | { 51 | return (*this) + v; //it crashes right here as it references to an nonexistent obj 52 | } 53 | 54 | 55 | bool boolFunc() 56 | { 57 | return true; 58 | } 59 | 60 | bool boolFunc2() 61 | { 62 | return false; 63 | } 64 | 65 | }; 66 | 67 | static const SQChar *sq_code = _SC("\ 68 | local v = Vector2();\ 69 | local v2 = Vector2();\ 70 | \ 71 | local b = v2.boolFunc(); \ 72 | \ 73 | \ 74 | local b = v2.boolFunc(); \ 75 | \ 76 | gTest.EXPECT_TRUE(b); \ 77 | gTest.EXPECT_INT_EQ(b, 1); \ 78 | gTest.EXPECT_FLOAT_EQ(b, 1.0); \ 79 | b = v2.boolFunc2(); \ 80 | \ 81 | gTest.EXPECT_FALSE(b); \ 82 | gTest.EXPECT_INT_EQ(b, 0); \ 83 | gTest.EXPECT_FLOAT_EQ(b, 0.0); \ 84 | \ 85 | print (b) ; \ 86 | b = v2.boolFunc2(); \ 87 | \ 88 | print (b) ; \ 89 | \ 90 | v.add(v2); /*good*/ \ 91 | print(\"1\\n\");\ 92 | local raised = false;\ 93 | try { \ 94 | v.add(10); \ 95 | gTest.EXPECT_INT_EQ(0, 1); \ 96 | } catch (ex) {\ 97 | raised = true;\ 98 | print(ex + \"\\n\"); \ 99 | }\ 100 | gTest.EXPECT_TRUE(raised); \ 101 | print(\"2\\n\");\ 102 | raised = false;\ 103 | try { \ 104 | v.add(); \ 105 | gTest.EXPECT_INT_EQ(0, 1); \ 106 | } catch (ex) {\ 107 | raised = true;\ 108 | print(ex + \"\\n\"); \ 109 | }\ 110 | gTest.EXPECT_TRUE(raised); \ 111 | print(\"3\\n\");\ 112 | raised = false;\ 113 | try {\ 114 | v.add(\"text\"); \ 115 | gTest.EXPECT_INT_EQ(0, 1); \ 116 | } catch (ex) {\ 117 | raised = true;\ 118 | print(ex + \"\\n\"); \ 119 | }\ 120 | gTest.EXPECT_TRUE(raised); \ 121 | print(\"4\\n\");\ 122 | "); 123 | 124 | 125 | 126 | TEST_F(SqratTest, NumericArgumentTypeConversionAndCheck) { 127 | DefaultVM::Set(vm); 128 | 129 | Sqrat::Class classVector2(vm, _SC("Vector2")); 130 | 131 | classVector2.Func(_SC("add"), &Vector2::add); 132 | 133 | classVector2.Func(_SC("boolFunc"), &Vector2::boolFunc); 134 | classVector2.Func(_SC("boolFunc2"), &Vector2::boolFunc2); 135 | Sqrat::RootTable(vm).Bind(_SC("Vector2"), classVector2); 136 | 137 | Script script; 138 | script.CompileString(sq_code); 139 | if (Sqrat::Error::Occurred(vm)) { 140 | FAIL() << _SC("Compile Failed: ") << Sqrat::Error::Message(vm); 141 | } 142 | 143 | script.Run(); 144 | if (Sqrat::Error::Occurred(vm)) { 145 | FAIL() << _SC("Run Failed: ") << Sqrat::Error::Message(vm); 146 | } 147 | 148 | } 149 | 150 | class F 151 | { 152 | public: 153 | int func(int i, char j) 154 | { 155 | return 1; 156 | } 157 | 158 | const char * func(char c, const char *s) 159 | { 160 | return s; 161 | } 162 | 163 | }; 164 | 165 | static const char *sq_code2 = _SC("\ 166 | f <- F();\ 167 | gTest.EXPECT_INT_EQ(1, f.f1(2. 'v'));\ 168 | gTest.EXPECT_STR_EQ(\"test\", f.f2('t', \"test\")); \ 169 | "); 170 | 171 | 172 | 173 | TEST_F(SqratTest, FunctionOfSameNumberOfArgumentsButDifferentTypesBinding) { 174 | DefaultVM::Set(vm); 175 | 176 | Sqrat::Class Fclass(vm, _SC("F")); 177 | Fclass.Func(_SC("f1"), &F::func); 178 | Fclass.Func(_SC("f2"), &F::func); 179 | 180 | Sqrat::RootTable(vm).Bind(_SC("F"), Fclass); 181 | 182 | Script script; 183 | script.CompileString(sq_code2); 184 | if (Sqrat::Error::Occurred(vm)) { 185 | FAIL() << _SC("Compile Failed: ") << Sqrat::Error::Message(vm); 186 | } 187 | 188 | script.Run(); 189 | if (Sqrat::Error::Occurred(vm)) { 190 | FAIL() << _SC("Run Failed: ") << Sqrat::Error::Message(vm); 191 | } 192 | 193 | } 194 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/ImportTest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Brandon Jones 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #include 25 | #include 26 | #include 27 | #include "Fixture.h" 28 | 29 | using namespace Sqrat; 30 | 31 | TEST_F(SqratTest, ImportScript) { 32 | DefaultVM::Set(vm); 33 | 34 | sqrat_register_importlib(vm); 35 | 36 | Script script; 37 | script.CompileString(_SC(" \ 38 | ::import(\"scripts/samplemodule\"); \ 39 | \ 40 | gTest.EXPECT_FLOAT_EQ(3.1415, ::PI); \ 41 | gTest.EXPECT_INT_EQ(10, ::RectArea(2, 5)); \ 42 | gTest.EXPECT_FLOAT_EQ(12.566, ::CircleArea(2)); \ 43 | ")); 44 | if (Sqrat::Error::Occurred(vm)) { 45 | FAIL() << _SC("Compile Failed: ") << Sqrat::Error::Message(vm); 46 | } 47 | 48 | script.Run(); 49 | if (Sqrat::Error::Occurred(vm)) { 50 | FAIL() << _SC("Run Failed: ") << Sqrat::Error::Message(vm); 51 | } 52 | } 53 | 54 | TEST_F(SqratTest, ImportScriptIntoTable) { 55 | DefaultVM::Set(vm); 56 | 57 | sqrat_register_importlib(vm); 58 | 59 | Script script; 60 | script.CompileString(_SC(" \ 61 | mod <- ::import(\"scripts/samplemodule\", {}); \ 62 | \ 63 | gTest.EXPECT_FLOAT_EQ(3.1415, mod.PI); \ 64 | gTest.EXPECT_INT_EQ(10, mod.RectArea(2, 5)); \ 65 | gTest.EXPECT_FLOAT_EQ(12.566, mod.CircleArea(2)); \ 66 | ")); 67 | if (Sqrat::Error::Occurred(vm)) { 68 | FAIL() << _SC("Compile Failed: ") << Sqrat::Error::Message(vm); 69 | } 70 | 71 | script.Run(); 72 | if (Sqrat::Error::Occurred(vm)) { 73 | FAIL() << _SC("Run Failed: ") << Sqrat::Error::Message(vm); 74 | } 75 | } -------------------------------------------------------------------------------- /src/sqrat/sqrattest/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char* argv[]) { 4 | ::testing::InitGoogleTest(&argc, argv); 5 | return RUN_ALL_TESTS(); 6 | } -------------------------------------------------------------------------------- /src/sqrat/sqrattest/NullPointerReturn.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Li-Cheng (Andy) Tai 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #include 25 | #include 26 | #include "Fixture.h" 27 | 28 | 29 | using namespace Sqrat; 30 | 31 | 32 | class Entity 33 | { 34 | public: 35 | Entity *FindEntity() { return NULL ; } 36 | 37 | }; 38 | 39 | 40 | static const SQChar *sq_code = _SC("\ 41 | local entity = Entity(); \ 42 | gTest.EXPECT_FALSE(entity == null); \ 43 | entity = entity.FindEntity(); \ 44 | gTest.EXPECT_TRUE(entity == null); \ 45 | "); 46 | 47 | 48 | 49 | TEST_F(SqratTest, NullPointerReturn) { 50 | DefaultVM::Set(vm); 51 | 52 | Class entity(vm, _SC("Entity")); 53 | entity.Func(_SC("FindEntity"), &Entity::FindEntity); 54 | RootTable().Bind(_SC("Entity"), entity); 55 | 56 | Script script; 57 | script.CompileString(sq_code); 58 | if (Sqrat::Error::Occurred(vm)) { 59 | FAIL() << _SC("Compile Failed: ") << Sqrat::Error::Message(vm); 60 | } 61 | 62 | script.Run(); 63 | if (Sqrat::Error::Occurred(vm)) { 64 | FAIL() << _SC("Run Failed: ") << Sqrat::Error::Message(vm); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/RunStackHandling.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Li-Cheng (Andy) Tai, atai@atai.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | 25 | #include 26 | #include 27 | #include "Fixture.h" 28 | 29 | /* this test would generally not fail. Its main purpose is to test for leaks 30 | when compiling scripts in memory multiple times; need to use valgrind or just watch 31 | memory increase when run */ 32 | 33 | using namespace Sqrat; 34 | 35 | //#define DUMPSTACK sq_dumpstack(vm); /* require atai's version of Squirrel */ 36 | #define DUMPSTACK 37 | 38 | TEST_F(SqratTest, RunStackHandling) 39 | { 40 | DefaultVM::Set(vm); 41 | static const int num_run = 1024 * 10 ; /* 10 times the typical Squirrel stack size */ 42 | int i; 43 | Script script; 44 | 45 | script.CompileString(_SC("function f(a) { return a + 1; } ; t <- 1; t = f(t); ")); 46 | if (Sqrat::Error::Occurred(vm)) { 47 | FAIL() << _SC("Compile failed: ") << Sqrat::Error::Message(vm); 48 | } 49 | script.Run(); 50 | Script script2; 51 | DUMPSTACK 52 | for (i = 0; i < num_run; i++) 53 | { 54 | 55 | script2.CompileString(_SC("t = f(t); /*print(t.tostring() + \"\\n\");*/")); 56 | script2.Run(); 57 | DUMPSTACK 58 | } 59 | if (Sqrat::Error::Occurred(vm)) { 60 | FAIL() << _SC("Run failed: ") << Sqrat::Error::Message(vm); 61 | } 62 | string err_msg; 63 | bool b ; 64 | 65 | for (i = 0; i < num_run; i++) 66 | { 67 | Script script3; 68 | err_msg = _SC(""); 69 | script3.CompileString(_SC("t = f(t); /*print(t.tostring() + \"\\n\");*/")); 70 | b = script3.Run(err_msg); 71 | ASSERT_TRUE(b); 72 | ASSERT_TRUE(err_msg == _SC("")); 73 | DUMPSTACK 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /src/sqrat/sqrattest/ScriptLoading.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Brandon Jones 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #include 25 | #include 26 | #include "Fixture.h" 27 | 28 | using namespace Sqrat; 29 | 30 | TEST_F(SqratTest, LoadScriptFromString) { 31 | // 32 | // Compile and run from string 33 | // 34 | 35 | DefaultVM::Set(vm); 36 | 37 | Script script; 38 | script.CompileString(_SC(" \ 39 | x <- 1 + 2; \ 40 | gTest.EXPECT_STR_EQ(x, 3); \ 41 | ")); 42 | if (Sqrat::Error::Occurred(vm)) { 43 | FAIL() << _SC("Script Compile Failed: ") << Sqrat::Error::Message(vm); 44 | } 45 | 46 | script.Run(); 47 | if (Sqrat::Error::Occurred(vm)) { 48 | FAIL() << _SC("Script Run Failed: ") << Sqrat::Error::Message(vm); 49 | } 50 | } 51 | 52 | TEST_F(SqratTest, LoadScriptFromFile) { 53 | // 54 | // Compile and run from file 55 | // 56 | 57 | DefaultVM::Set(vm); 58 | 59 | Script script; 60 | script.CompileFile(_SC("scripts/hello.nut")); 61 | if (Sqrat::Error::Occurred(vm)) { 62 | FAIL() << _SC("Script Compile Failed: ") << Sqrat::Error::Message(vm); 63 | } 64 | 65 | script.Run(); 66 | if (Sqrat::Error::Occurred(vm)) { 67 | FAIL() << _SC("Script Run Failed: ") << Sqrat::Error::Message(vm); 68 | } 69 | } -------------------------------------------------------------------------------- /src/sqrat/sqrattest/SqratVM.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Li-Cheng (Andy) Tai, atai@atai.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include "Fixture.h" 29 | /* test demonstrating Sourceforge bug 3507590 */ 30 | 31 | using namespace Sqrat; 32 | 33 | class simpleclass 34 | { 35 | public: 36 | simpleclass() {} 37 | void memfun() {} 38 | }; 39 | 40 | void bind(HSQUIRRELVM vm) 41 | { 42 | Sqrat::Class sqClass(vm, _SC("simpleclass")); 43 | sqClass 44 | .Func(_SC("memfun"), &simpleclass::memfun); 45 | Sqrat::RootTable(vm).Bind(_SC("simpleclass"), sqClass); 46 | 47 | } 48 | 49 | TEST_F(SqratTest, SqratVM) 50 | { 51 | SqratVM vm1; 52 | SqratVM vm2; 53 | 54 | bind(vm1.GetVM()); 55 | bind(vm2.GetVM()); 56 | 57 | } -------------------------------------------------------------------------------- /src/sqrat/sqrattest/SqratVM2.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Li-Cheng (Andy) Tai, atai@atai.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include "Fixture.h" 29 | /* test demonstrating Sourceforge bug 3507590 */ 30 | 31 | using namespace Sqrat; 32 | 33 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/SquirrelFunctions.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Brandon Jones 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #include 25 | #include 26 | #include "Fixture.h" 27 | 28 | using namespace Sqrat; 29 | 30 | TEST_F(SqratTest, CallSquirrelFunction) { 31 | DefaultVM::Set(vm); 32 | 33 | Script script; 34 | script.CompileString(_SC(" \ 35 | function AddTwo(a, b) { \ 36 | return a + b; \ 37 | } \ 38 | function MultiplyTwo(a, b) { \ 39 | return a * b; \ 40 | } \ 41 | function returnTrue() { \ 42 | return true; \ 43 | }\ 44 | function returnFalse() { \ 45 | return false; \ 46 | }\ 47 | ")); 48 | if (Sqrat::Error::Occurred(vm)) { 49 | FAIL() << _SC("Script Compile Failed: ") << Sqrat::Error::Message(vm); 50 | } 51 | 52 | script.Run(); // Must run the script before the function will be available 53 | if (Sqrat::Error::Occurred(vm)) { 54 | FAIL() << _SC("Script Run Failed: ") << Sqrat::Error::Message(vm); 55 | } 56 | 57 | // Method one for function retrieval: via the constructor 58 | Function addTwo(RootTable(), _SC("AddTwo")); 59 | ASSERT_FALSE(addTwo.IsNull()); 60 | EXPECT_EQ(*addTwo.Evaluate(1, 2), 3); 61 | 62 | // Method two for function retrieval: from the class or table 63 | Function multiplyTwo = RootTable().GetFunction(_SC("MultiplyTwo")); 64 | ASSERT_FALSE(multiplyTwo.IsNull()); 65 | EXPECT_EQ(*multiplyTwo.Evaluate(2, 3), 6); 66 | 67 | Function returnTrue = RootTable().GetFunction(_SC("returnTrue")); 68 | ASSERT_FALSE(returnTrue.IsNull()); 69 | ASSERT_TRUE(*returnTrue.Evaluate()); 70 | ASSERT_TRUE(*returnTrue.Evaluate()); 71 | 72 | Function returnFalse = RootTable().GetFunction(_SC("returnFalse")); 73 | ASSERT_FALSE(returnFalse.IsNull()); 74 | ASSERT_FALSE(*returnFalse.Evaluate()); 75 | ASSERT_FALSE(*returnFalse.Evaluate()); 76 | 77 | } 78 | 79 | int NativeOp(int a, int b, Function opFunc) { 80 | if(opFunc.IsNull()) { 81 | return -1; 82 | } 83 | return *opFunc.Evaluate(a, b); 84 | } 85 | 86 | TEST_F(SqratTest, FunctionAsArgument) { 87 | DefaultVM::Set(vm); 88 | 89 | RootTable().Func(_SC("NativeOp"), &NativeOp); 90 | 91 | Script script; 92 | script.CompileString(_SC(" \ 93 | function SubTwo(a, b) { \ 94 | return a - b; \ 95 | } \ 96 | gTest.EXPECT_INT_EQ(::NativeOp(5, 1, SubTwo), 4); \ 97 | ")); 98 | if (Sqrat::Error::Occurred(vm)) { 99 | FAIL() << _SC("Script Compile Failed: ") << Sqrat::Error::Message(vm); 100 | } 101 | 102 | script.Run(); 103 | if (Sqrat::Error::Occurred(vm)) { 104 | FAIL() << _SC("Script Run Failed: ") << Sqrat::Error::Message(vm); 105 | } 106 | } -------------------------------------------------------------------------------- /src/sqrat/sqrattest/SuspendVM.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Li-Cheng (Andy) Tai, atai@atai.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | 25 | #include 26 | #include 27 | #include "Fixture.h" 28 | /* test demonstrating Sourceforge bug 3507590 */ 29 | 30 | using namespace Sqrat; 31 | 32 | class C 33 | { 34 | 35 | public: 36 | int suspend() 37 | { 38 | return sq_suspendvm(DefaultVM::Get()); 39 | } 40 | }; 41 | 42 | 43 | TEST_F(SqratTest, SuspendVM) 44 | { 45 | DefaultVM::Set(vm); 46 | int i; 47 | Class cclass(vm, _SC("C")); 48 | cclass.Func(_SC("suspend"), &C::suspend); 49 | 50 | RootTable().Bind(_SC("C"), cclass); 51 | Script script; 52 | script.CompileString(_SC("\ 53 | c <- C(); \ 54 | //c.suspend(); /* this would fail in the curent Sqrat; no solution yet */\ 55 | ::suspend(); \ 56 | gTest.EXPECT_INT_EQ(1, 0); /* should not reach here */ \ 57 | ")); 58 | if (Sqrat::Error::Occurred(vm)) { 59 | FAIL() << _SC("Compile Failed: ") << Sqrat::Error::Message(vm); 60 | } 61 | 62 | script.Run(); 63 | if (Sqrat::Error::Occurred(vm)) { 64 | FAIL() << _SC("Run Failed: ") << Sqrat::Error::Message(vm); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/sqrat/sqrattest/UniqueObject.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Fixture.h" 4 | 5 | struct CxxObject { 6 | CxxObject& cxx_ptr() { 7 | return *this; 8 | } 9 | }; 10 | 11 | char const script_code[] = "\ 12 | v <- CxxObject();\ 13 | gTest.EXPECT_STR_EQ(v.tostring, v.cxx_ptr().tostring);\ 14 | \ 15 | target <- null;\ 16 | function set_target(v) {\ 17 | ::target = v;\ 18 | }\ 19 | function test_target(v) {\ 20 | gTest.EXPECT_STR_EQ(::target.tostring, v.tostring);\ 21 | }\ 22 | "; 23 | 24 | using namespace Sqrat; 25 | 26 | TEST_F(SqratTest, UniqueObject) { 27 | DefaultVM::Set(vm); 28 | 29 | Class cls(vm, _SC("CxxObject")); 30 | cls.Func(_SC("cxx_ptr"), &CxxObject::cxx_ptr); 31 | RootTable(vm).Bind(_SC("CxxObject"), cls); 32 | 33 | Script script; 34 | std::string err; 35 | if (!script.CompileString(script_code, err)) { 36 | FAIL() << _SC("Compile failed: ") << err; 37 | } 38 | if (!script.Run(err)) { 39 | FAIL() << _SC("Script failed: ") << err; 40 | } 41 | 42 | Function set_target(RootTable(vm), "set_target"), test_target(RootTable(vm), "test_target"); 43 | CxxObject* obj = new CxxObject; 44 | set_target(obj); 45 | test_target(obj); 46 | delete obj; 47 | } 48 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/Vector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Brandon Jones 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #include "Vector.h" 25 | #include 26 | 27 | using namespace Sqrat; 28 | 29 | Vec2::Vec2( void ) : x(0.0f), y(0.0f) {}; 30 | Vec2::Vec2( const Vec2 &v ) : x(v.x), y(v.y) {}; 31 | Vec2::Vec2( const float vx, const float vy ) : x(vx), y(vy) {}; 32 | 33 | bool Vec2::operator ==( const Vec2 &v ) const { 34 | return (x == v.x && y == v.y); 35 | } 36 | 37 | Vec2 Vec2::operator -( void ) const { 38 | return Vec2(-x, -y); 39 | } 40 | 41 | Vec2 Vec2::operator +( const Vec2& v ) const { 42 | return Vec2(x + v.x, y + v.y); 43 | } 44 | 45 | Vec2 Vec2::operator -( const Vec2& v ) const { 46 | return Vec2(x - v.x, y - v.y); 47 | } 48 | 49 | Vec2 Vec2::operator *( const float f ) const { 50 | return Vec2(x * f, y * f); 51 | } 52 | 53 | Vec2 Vec2::operator /( const float f ) const { 54 | return Vec2(x / f, y / f); 55 | } 56 | 57 | Vec2& Vec2::operator =( const Vec2& v ) { 58 | x = v.x; 59 | y = v.y; 60 | return *this; 61 | } 62 | 63 | float Vec2::Length( void ) const { 64 | return sqrt( (x * x) + (y * y) ); 65 | } 66 | 67 | float Vec2::Distance( const Vec2 &v ) const { 68 | return sqrt( (x-v.x) * (x-v.x) + (y-v.y) * (y-v.y) ); 69 | } 70 | 71 | Vec2& Vec2::Normalize( void ) { 72 | float invLen = 1.0f / Length(); 73 | x *= invLen; 74 | y *= invLen; 75 | return *this; 76 | } 77 | 78 | float Vec2::Dot( const Vec2 &v ) const { 79 | return x*v.x + y*v.y; 80 | } -------------------------------------------------------------------------------- /src/sqrat/sqrattest/Vector.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Brandon Jones 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 12 | // 1. The origin of this software must not be misrepresented; you must not 13 | // claim that you wrote the original software. If you use this software 14 | // in a product, an acknowledgment in the product documentation would be 15 | // appreciated but is not required. 16 | // 17 | // 2. Altered source versions must be plainly marked as such, and must not be 18 | // misrepresented as being the original software. 19 | // 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #if !defined(SQRAT_TEST_VECTOR_H) 25 | #define SQRAT_TEST_VECTOR_H 26 | 27 | #include 28 | 29 | namespace Sqrat { 30 | // A simple Vector class used to demonstrate binding 31 | class Vec2 { 32 | public: 33 | float x, y; 34 | 35 | Vec2( void ); 36 | Vec2( const Vec2 &v ); 37 | Vec2( const float vx, const float vy ); 38 | 39 | bool operator ==( const Vec2 &v ) const; 40 | Vec2 operator -( void ) const; 41 | Vec2 operator +( const Vec2& v ) const; 42 | Vec2 operator -( const Vec2& v ) const; 43 | Vec2 operator *( const float f ) const; 44 | Vec2 operator /( const float f ) const; 45 | Vec2& operator =( const Vec2& v ); 46 | 47 | float Length( void ) const; 48 | float Distance( const Vec2 &v ) const; 49 | Vec2& Normalize( void ); 50 | float Dot( const Vec2 &v ) const; 51 | }; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/build_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -ex 2 | 3 | #shopt -s nullglob 4 | 5 | SQUIRREL_INCLUDE=/usr/local/include/squirrel 6 | SQUIRREL_LIB=/usr/local/lib 7 | CFLAGS="-g -O0 -I. -I../include -I../gtest-1.3.0/include -I${SQUIRREL_INCLUDE}" 8 | LDFLAGS=-L${SQUIRREL_LIB} 9 | LIBS="../gtest-1.3.0/libgtest.a -lsqstdlib -lsquirrel -lstdc++ -lm " 10 | 11 | mkdir -p bin 12 | 13 | gcc $CFLAGS \ 14 | ../sqimport/sqratimport.cpp ImportTest.cpp Main.cpp \ 15 | -o bin/ImportTest ${LDFLAGS} ${LIBS} -ldl 16 | 17 | TEST_CPPS="ClassBinding.cpp\ 18 | ClassInstances.cpp\ 19 | ClassProperties.cpp\ 20 | ConstBindings.cpp\ 21 | FunctionOverload.cpp\ 22 | ScriptLoading.cpp\ 23 | SquirrelFunctions.cpp\ 24 | TableBinding.cpp\ 25 | FunctionParams.cpp \ 26 | RunStackHandling.cpp \ 27 | SuspendVM.cpp \ 28 | NullPointerReturn.cpp\ 29 | FuncInputArgumentType.cpp \ 30 | ArrayBinding.cpp \ 31 | UniqueObject.cpp " 32 | 33 | for f in $TEST_CPPS; do 34 | gcc $CFLAGS \ 35 | ${f} Vector.cpp Main.cpp \ 36 | -o bin/${f%.cpp} ${LDFLAGS} ${LIBS} 37 | done 38 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/build_tests_msys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -ex 2 | 3 | #shopt -s nullglob 4 | 5 | SQUIRREL_INCLUDE=C:/SQUIRREL3/include 6 | SQUIRREL_LIB=C:/SQUIRREL3/lib 7 | CFLAGS="-g -O0 -I. -I../include -IC:/gtest-1.7.0/include -I${SQUIRREL_INCLUDE}" 8 | LDFLAGS=-L${SQUIRREL_LIB} 9 | LIBS="C:/gtest-1.7.0/build/libgtest.a -lsqstdlib -lsquirrel -lstdc++ -lm" 10 | 11 | mkdir -p bin 12 | 13 | gcc $CFLAGS \ 14 | ../sqimport/sqratimport.cpp ImportTest.cpp Main.cpp \ 15 | -o bin/ImportTest ${LDFLAGS} ${LIBS} 16 | 17 | TEST_CPPS="ClassBinding.cpp\ 18 | ClassInstances.cpp\ 19 | ClassProperties.cpp\ 20 | ConstBindings.cpp\ 21 | FunctionOverload.cpp\ 22 | ScriptLoading.cpp\ 23 | SquirrelFunctions.cpp\ 24 | TableBinding.cpp\ 25 | FunctionParams.cpp \ 26 | RunStackHandling.cpp \ 27 | SuspendVM.cpp \ 28 | NullPointerReturn.cpp\ 29 | FuncInputArgumentType.cpp \ 30 | ArrayBinding.cpp \ 31 | UniqueObject.cpp " 32 | 33 | for f in $TEST_CPPS; do 34 | gcc $CFLAGS \ 35 | ${f} Vector.cpp Main.cpp \ 36 | -o bin/${f%.cpp} ${LDFLAGS} ${LIBS} 37 | done 38 | -------------------------------------------------------------------------------- /src/sqrat/sqrattest/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -x 2 | 3 | for f in bin/*; do 4 | ${f} 5 | done -------------------------------------------------------------------------------- /src/sqrat/sqrattest/scripts/hello.nut: -------------------------------------------------------------------------------- 1 | x <- 1 + 2; 2 | gTest.EXPECT_STR_EQ(x, 3); -------------------------------------------------------------------------------- /src/sqrat/sqrattest/scripts/samplemodule.nut: -------------------------------------------------------------------------------- 1 | PI <- 3.1415; 2 | 3 | function RectArea(w, h) { 4 | return w * h; 5 | } 6 | 7 | function CircleArea(radius) { 8 | return PI * (radius * radius); 9 | } -------------------------------------------------------------------------------- /src/sqrat/sqratthread/sqratThread.h: -------------------------------------------------------------------------------- 1 | // 2 | // SqratThread: Sqrat threading module 3 | // 4 | 5 | // 6 | // Copyright (c) 2009 Brandon Jones 7 | // 8 | // This software is provided 'as-is', without any express or implied 9 | // warranty. In no event will the authors be held liable for any damages 10 | // arising from the use of this software. 11 | // 12 | // Permission is granted to anyone to use this software for any purpose, 13 | // including commercial applications, and to alter it and redistribute it 14 | // freely, subject to the following restrictions: 15 | // 16 | // 1. The origin of this software must not be misrepresented; you must not 17 | // claim that you wrote the original software. If you use this software 18 | // in a product, an acknowledgment in the product documentation would be 19 | // appreciated but is not required. 20 | // 21 | // 2. Altered source versions must be plainly marked as such, and must not be 22 | // misrepresented as being the original software. 23 | // 24 | // 3. This notice may not be removed or altered from any source 25 | // distribution. 26 | // 27 | 28 | #if !defined(_SQRAT_THREAD_H_) 29 | #define _SQRAT_THREAD_H_ 30 | 31 | #include "sqmodule.h" 32 | 33 | template 34 | __declspec(dllexport) SQRESULT sqmodule_load(HSQUIRRELVM v, HSQAPI api); 35 | 36 | 37 | #endif /*_SQRAT_THREAD_H_*/ 38 | -------------------------------------------------------------------------------- /src/sqsystemdata.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqinvoker.h" 4 | #include "sqhelper.h" 5 | 6 | class SystemDataSettingEtc { 7 | 8 | }; 9 | 10 | template 11 | class SQSystemData : public SQInvoker 12 | { 13 | public: 14 | enum class Index { 15 | SETTING_PAD, 16 | SETTING_SCREEN, 17 | SETTING_SOUND, 18 | SETTING_SAVEDATA, 19 | SETTING_ETC, 20 | SETTING_NETWORK, 21 | SETTING_GAME, 22 | BACKUP_FLAGS, 23 | WINDOW_INFO, 24 | PURCHASE_RECORD, 25 | WORK_MEDAL, 26 | WORK_TRIAL, 27 | SRAM_DATA, 28 | WORK_TITLE, 29 | }; 30 | 31 | class SettingPad : public SQInvoker 32 | { 33 | public: 34 | SettingPad() : SQInvoker(_SC("g_systemdata")) { 35 | auto obj = this->Invoke>("get_value", static_cast(Index::SETTING_PAD)); 36 | this->m_instance = obj.GetObject(); 37 | } 38 | 39 | static int GetPlaySide_MGS1() { 40 | return SettingPad().Invoke("get_playside_mgs"); 41 | } 42 | 43 | static void SetPlaySide_MGS1(int side) { 44 | return SettingPad().Invoke("set_playside_mgs", side); 45 | } 46 | }; 47 | 48 | class SettingETC : public SQInvoker 49 | { 50 | public: 51 | SettingETC() : SQInvoker(_SC("g_systemdata")) { 52 | auto obj = this->Invoke>("get_value", static_cast(Index::SETTING_ETC)); 53 | this->m_instance = obj.GetObject(); 54 | } 55 | 56 | static std::string GetVersion() { 57 | return SettingETC().Invoke("get_game_regionTag"); 58 | } 59 | }; 60 | 61 | SQSystemData() : SQInvoker(_SC("g_systemdata")) {} 62 | }; 63 | 64 | template SQSystemData; 65 | template SQSystemData; 66 | template SQSystemData; 67 | template SQSystemData; 68 | -------------------------------------------------------------------------------- /src/sqsystemprof.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqrat.h" 4 | 5 | template 6 | class SQSystemProf : public Sqrat::Object 7 | { 8 | public: 9 | SQSystemProf() : Sqrat::Object(Sqrat::RootTable()[_SC("s_root_systemprof")][_SC("root")]) 10 | {} 11 | 12 | static std::string GetName() 13 | { 14 | return SQSystemProf()["dev_name"].Cast(); 15 | } 16 | }; 17 | 18 | template SQSystemProf; 19 | template SQSystemProf; 20 | template SQSystemProf; 21 | template SQSystemProf; 22 | -------------------------------------------------------------------------------- /src/sqtitleprof.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqrat.h" 4 | 5 | #include "sqglobals.h" 6 | #include "sqsystemdata.h" 7 | 8 | template 9 | class SQTitleProf : public Sqrat::Object 10 | { 11 | public: 12 | SQTitleProf() : Sqrat::Object(Sqrat::RootTable()[_SC("s_current_title_prof")]) 13 | {} 14 | 15 | static std::string GetName() 16 | { 17 | return SQTitleProf()["title"]["dev_name"].Cast(); 18 | } 19 | 20 | static unsigned GetVersions() 21 | { 22 | return SQTitleProf()["m2epi"]["version"].GetSize(); 23 | } 24 | 25 | static std::string GetExecutable(std::string version = SQSystemData::SettingETC::GetVersion()) 26 | { 27 | return SQTitleProf()["m2epi"]["version"][version.c_str()]["rom"].Cast(); 28 | } 29 | 30 | static unsigned GetDisks(std::string version = SQSystemData::SettingETC::GetVersion()) 31 | { 32 | auto obj = SQTitleProf()["m2epi"]["version"][version.c_str()]["disk"]; 33 | if (obj.IsNull()) return 0; 34 | switch (obj.GetType()) { 35 | case OT_STRING: return 1; 36 | default: return obj.GetSize(); 37 | } 38 | } 39 | 40 | static std::string GetDisk( 41 | unsigned id = SQGlobals::GetDisk(), 42 | std::string version = SQSystemData::SettingETC::GetVersion() 43 | ) { 44 | auto obj = SQTitleProf()["m2epi"]["version"][version.c_str()]["disk"]; 45 | auto disks = GetDisks(version); 46 | if (id >= disks) return {}; 47 | if (disks > 1) obj = obj[id]; 48 | return obj.Cast(); 49 | } 50 | 51 | static unsigned GetMemoryDefine(std::string name, 52 | unsigned disk = SQGlobals::GetDisk(), 53 | std::string version = SQSystemData::SettingETC::GetVersion() 54 | ) { 55 | auto obj = SQTitleProf()["memory_define"]; 56 | if (GetVersions() > 1) obj = obj[version.c_str()]; 57 | obj = obj[name.c_str()]; 58 | if (obj.GetType() != OT_INTEGER) obj = obj[disk]; 59 | return obj.Cast(); 60 | } 61 | }; 62 | 63 | template SQTitleProf; 64 | template SQTitleProf; 65 | template SQTitleProf; 66 | template SQTitleProf; 67 | -------------------------------------------------------------------------------- /src/squirk.h: -------------------------------------------------------------------------------- 1 | enum class Squirk { 2 | Standard, 3 | AlignObject, 4 | StandardShared, 5 | AlignObjectShared, 6 | }; 7 | -------------------------------------------------------------------------------- /src/squirrel/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2003-2009 Alberto Demichelis 2 | 3 | This software is provided 'as-is', without any 4 | express or implied warranty. In no event will the 5 | authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software 9 | for any purpose, including commercial applications, 10 | and to alter it and redistribute it freely, subject 11 | to the following restrictions: 12 | 13 | 1. The origin of this software must not be 14 | misrepresented; you must not claim that 15 | you wrote the original software. If you 16 | use this software in a product, an 17 | acknowledgment in the product 18 | documentation would be appreciated but is 19 | not required. 20 | 21 | 2. Altered source versions must be plainly 22 | marked as such, and must not be 23 | misrepresented as being the original 24 | software. 25 | 26 | 3. This notice may not be removed or 27 | altered from any source distribution. 28 | ----------------------------------------------------- 29 | END OF COPYRIGHT -------------------------------------------------------------------------------- /src/squirrel/include/sqstdaux.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_AUXLIB_H_ 3 | #define _SQSTD_AUXLIB_H_ 4 | 5 | template 6 | SQUIRREL_API void sqstd_seterrorhandlers(HSQUIRRELVM v); 7 | template 8 | SQUIRREL_API void sqstd_printcallstack(HSQUIRRELVM v); 9 | 10 | #endif /* _SQSTD_AUXLIB_H_ */ 11 | -------------------------------------------------------------------------------- /src/squirrel/include/sqstdblob.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTDBLOB_H_ 3 | #define _SQSTDBLOB_H_ 4 | 5 | template 6 | SQUIRREL_API SQUserPointer sqstd_createblob(HSQUIRRELVM v, SQInteger size); 7 | template 8 | SQUIRREL_API SQRESULT sqstd_getblob(HSQUIRRELVM v,SQInteger idx,SQUserPointer *ptr); 9 | template 10 | SQUIRREL_API SQInteger sqstd_getblobsize(HSQUIRRELVM v,SQInteger idx); 11 | 12 | template 13 | SQUIRREL_API SQRESULT sqstd_register_bloblib(HSQUIRRELVM v); 14 | 15 | #endif /*_SQSTDBLOB_H_*/ 16 | 17 | -------------------------------------------------------------------------------- /src/squirrel/include/sqstdio.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTDIO_H_ 3 | #define _SQSTDIO_H_ 4 | 5 | #define SQSTD_STREAM_TYPE_TAG 0x80000000 6 | 7 | struct SQStream { 8 | virtual ~SQStream() {} 9 | virtual SQInteger Read(void *buffer, SQInteger size) = 0; 10 | virtual SQInteger Write(void *buffer, SQInteger size) = 0; 11 | virtual SQInteger Flush() = 0; 12 | virtual SQInteger Tell() = 0; 13 | virtual SQInteger Len() = 0; 14 | virtual SQInteger Seek(SQInteger offset, SQInteger origin) = 0; 15 | virtual bool IsValid() = 0; 16 | virtual bool EOS() = 0; 17 | }; 18 | 19 | #define SQ_SEEK_CUR 0 20 | #define SQ_SEEK_END 1 21 | #define SQ_SEEK_SET 2 22 | 23 | typedef void* SQFILE; 24 | 25 | SQUIRREL_API SQFILE sqstd_fopen(const SQChar *,const SQChar *); 26 | SQUIRREL_API SQInteger sqstd_fread(SQUserPointer, SQInteger, SQInteger, SQFILE); 27 | SQUIRREL_API SQInteger sqstd_fwrite(const SQUserPointer, SQInteger, SQInteger, SQFILE); 28 | SQUIRREL_API SQInteger sqstd_fseek(SQFILE , SQInteger , SQInteger); 29 | SQUIRREL_API SQInteger sqstd_ftell(SQFILE); 30 | SQUIRREL_API SQInteger sqstd_fflush(SQFILE); 31 | SQUIRREL_API SQInteger sqstd_fclose(SQFILE); 32 | SQUIRREL_API SQInteger sqstd_feof(SQFILE); 33 | 34 | template 35 | SQUIRREL_API SQRESULT sqstd_createfile(HSQUIRRELVM v, SQFILE file,SQBool own); 36 | template 37 | SQUIRREL_API SQRESULT sqstd_getfile(HSQUIRRELVM v, SQInteger idx, SQFILE *file); 38 | 39 | //compiler helpers 40 | template 41 | SQUIRREL_API SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror); 42 | template 43 | SQUIRREL_API SQRESULT sqstd_dofile(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror); 44 | template 45 | SQUIRREL_API SQRESULT sqstd_writeclosuretofile(HSQUIRRELVM v,const SQChar *filename); 46 | 47 | template 48 | SQUIRREL_API SQRESULT sqstd_register_iolib(HSQUIRRELVM v); 49 | 50 | #endif /*_SQSTDIO_H_*/ 51 | 52 | -------------------------------------------------------------------------------- /src/squirrel/include/sqstdmath.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_MATH_H_ 3 | #define _SQSTD_MATH_H_ 4 | 5 | template 6 | SQUIRREL_API SQRESULT sqstd_register_mathlib(HSQUIRRELVM v); 7 | 8 | #endif /*_SQSTD_MATH_H_*/ 9 | -------------------------------------------------------------------------------- /src/squirrel/include/sqstdstring.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_STRING_H_ 3 | #define _SQSTD_STRING_H_ 4 | 5 | typedef unsigned int SQRexBool; 6 | typedef struct SQRex SQRex; 7 | 8 | typedef struct { 9 | const SQChar *begin; 10 | SQInteger len; 11 | } SQRexMatch; 12 | 13 | SQUIRREL_API SQRex *sqstd_rex_compile(const SQChar *pattern,const SQChar **error); 14 | SQUIRREL_API void sqstd_rex_free(SQRex *exp); 15 | SQUIRREL_API SQBool sqstd_rex_match(SQRex* exp,const SQChar* text); 16 | SQUIRREL_API SQBool sqstd_rex_search(SQRex* exp,const SQChar* text, const SQChar** out_begin, const SQChar** out_end); 17 | SQUIRREL_API SQBool sqstd_rex_searchrange(SQRex* exp,const SQChar* text_begin,const SQChar* text_end,const SQChar** out_begin, const SQChar** out_end); 18 | SQUIRREL_API SQInteger sqstd_rex_getsubexpcount(SQRex* exp); 19 | SQUIRREL_API SQBool sqstd_rex_getsubexp(SQRex* exp, SQInteger n, SQRexMatch *subexp); 20 | 21 | template 22 | SQUIRREL_API SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output); 23 | 24 | template 25 | SQUIRREL_API SQRESULT sqstd_register_stringlib(HSQUIRRELVM v); 26 | 27 | #endif /*_SQSTD_STRING_H_*/ 28 | -------------------------------------------------------------------------------- /src/squirrel/include/sqstdsystem.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_SYSTEMLIB_H_ 3 | #define _SQSTD_SYSTEMLIB_H_ 4 | 5 | template 6 | SQUIRREL_API SQInteger sqstd_register_systemlib(HSQUIRRELVM v); 7 | 8 | #endif /* _SQSTD_SYSTEMLIB_H_ */ 9 | -------------------------------------------------------------------------------- /src/squirrel/sqdbg/sqdbgserver.h: -------------------------------------------------------------------------------- 1 | #ifndef _SQ_DBGSERVER_H_ 2 | #define _SQ_DBGSERVER_H_ 3 | 4 | #define MAX_BP_PATH 512 5 | #define MAX_MSG_LEN 2049 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #ifdef _WIN32 12 | # include 13 | #else 14 | # include 15 | # define SOCKET int 16 | # define INVALID_SOCKET (-1) 17 | #endif 18 | 19 | typedef std::basic_string SQDBGString; 20 | 21 | struct BreakPoint{ 22 | BreakPoint(){_line=0;} 23 | BreakPoint(SQInteger line, const SQChar *src){ _line = line; _src = src; } 24 | BreakPoint(const BreakPoint& bp){ _line = bp._line; _src=bp._src; } 25 | bool operator<(const BreakPoint& bp) const 26 | { 27 | if(_line 63 | using VMStateMap = std::map, VMState*>; 64 | typedef std::set BreakPointSet; 65 | typedef BreakPointSet::iterator BreakPointSetItor; 66 | 67 | typedef std::set WatchSet; 68 | typedef WatchSet::iterator WatchSetItor; 69 | 70 | typedef std::vector SQCharVec; 71 | template 72 | struct SQDbgServer{ 73 | public: 74 | enum eDbgState{ 75 | eDBG_Running, 76 | eDBG_StepOver, 77 | eDBG_StepInto, 78 | eDBG_StepReturn, 79 | eDBG_Suspended, 80 | eDBG_Disabled, 81 | }; 82 | 83 | SQDbgServer(HSQUIRRELVM v); 84 | ~SQDbgServer(); 85 | bool Init(HSQUIRRELVM v); 86 | //returns true if a message has been received 87 | bool WaitForClient(); 88 | bool ReadMsg(); 89 | void BusyWait(); 90 | void Hook(HSQUIRRELVM v,SQInteger type,SQInteger line,const SQChar *src,const SQChar *func); 91 | void ParseMsg(const char *msg); 92 | bool ParseBreakpoint(const char *msg,BreakPoint &out); 93 | bool ParseWatch(const char *msg,Watch &out); 94 | bool ParseRemoveWatch(const char *msg,SQInteger &id); 95 | void Terminated(); 96 | // 97 | void BreakExecution(); 98 | void Send(const SQChar *s,...); 99 | void SendChunk(const SQChar *chunk); 100 | void Break(HSQUIRRELVM v,SQInteger line,const SQChar *src,const SQChar *type,const SQChar *error=NULL); 101 | 102 | 103 | void SerializeState(HSQUIRRELVM v); 104 | //COMMANDS 105 | void AddBreakpoint(BreakPoint &bp); 106 | void AddWatch(Watch &w); 107 | void RemoveWatch(SQInteger id); 108 | void RemoveBreakpoint(BreakPoint &bp); 109 | 110 | // 111 | void SetErrorHandlers(HSQUIRRELVM v); 112 | VMState *GetVMState(HSQUIRRELVM v); 113 | 114 | //XML RELATED STUFF/////////////////////// 115 | #define MAX_NESTING 10 116 | struct XMLElementState { 117 | SQChar name[256]; 118 | bool haschildren; 119 | }; 120 | 121 | XMLElementState xmlstate[MAX_NESTING]; 122 | SQInteger _xmlcurrentement; 123 | 124 | void BeginDocument(); 125 | void BeginElement(const SQChar *name); 126 | void Attribute(const SQChar *name, const SQChar *value); 127 | void EndElement(const SQChar *name); 128 | void EndDocument(); 129 | 130 | const SQChar *escape_xml(const SQChar *x); 131 | ////////////////////////////////////////////// 132 | HSQUIRRELVM _v; 133 | HSQOBJECT _debugroot; 134 | eDbgState _state; 135 | SOCKET _accept; 136 | SOCKET _endpoint; 137 | BreakPointSet _breakpoints; 138 | WatchSet _watches; 139 | //int _recursionlevel; 140 | //int _maxrecursion; 141 | 142 | bool _ready; 143 | bool _exclusive; 144 | bool _autoupdate; 145 | HSQOBJECT _serializefunc; 146 | SQCharVec _scratchstring; 147 | 148 | SQInteger _line; 149 | SQDBGString _src; 150 | SQDBGString _break_type; 151 | VMStateMap _vmstate; 152 | }; 153 | 154 | #ifdef _WIN32 155 | #define sqdbg_closesocket(x) closesocket((x)) 156 | #else 157 | #define sqdbg_closesocket(x) close((x)) 158 | #endif 159 | 160 | template SQDbgServer; 161 | template SQDbgServer; 162 | template SQDbgServer; 163 | template SQDbgServer; 164 | 165 | #endif //_SQ_DBGSERVER_H_ 166 | -------------------------------------------------------------------------------- /src/squirrel/sqdbg/sqrdbg.h: -------------------------------------------------------------------------------- 1 | #ifndef _SQ_RDBG_H_ 2 | #define _SQ_RDBG_H_ 3 | 4 | #ifdef _WIN32 5 | #pragma comment(lib, "WSOCK32.LIB") 6 | #endif 7 | 8 | template 9 | struct SQDbgServer; 10 | template 11 | using HSQREMOTEDBG = SQDbgServer*; 12 | 13 | template 14 | HSQREMOTEDBG sq_rdbg_init(HSQUIRRELVM v,unsigned short port,SQBool autoupdate,SQBool exclusive); 15 | template 16 | SQRESULT sq_rdbg_waitforconnections(HSQREMOTEDBG rdbg); 17 | template 18 | SQRESULT sq_rdbg_shutdown(HSQREMOTEDBG rdbg); 19 | template 20 | SQRESULT sq_rdbg_update(HSQREMOTEDBG rdbg); 21 | 22 | #endif //_SQ_RDBG_H_ 23 | -------------------------------------------------------------------------------- /src/squirrel/sqstdlib/sqstdaux.cpp: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #include 3 | #include 4 | #include 5 | 6 | template 7 | void sqstd_printcallstack(HSQUIRRELVM v) 8 | { 9 | SQPRINTFUNCTION pf = sq_getprintfunc(v); 10 | if(pf) { 11 | SQStackInfos si; 12 | SQInteger i; 13 | SQBool b; 14 | SQFloat f; 15 | const SQChar *s; 16 | SQInteger level=1; //1 is to skip this function that is level 0 17 | const SQChar *name=0; 18 | SQInteger seq=0; 19 | pf(v,_SC("\nCALLSTACK\n")); 20 | while(SQ_SUCCEEDED(sq_stackinfos(v,level,&si))) 21 | { 22 | const SQChar *fn=_SC("unknown"); 23 | const SQChar *src=_SC("unknown"); 24 | if(si.funcname)fn=si.funcname; 25 | if(si.source)src=si.source; 26 | pf(v,_SC("*FUNCTION [%s()] %s line [%d]\n"),fn,src,si.line); 27 | level++; 28 | } 29 | level=0; 30 | pf(v,_SC("\nLOCALS\n")); 31 | 32 | for(level=0;level<10;level++){ 33 | seq=0; 34 | while((name = sq_getlocal(v,level,seq))) 35 | { 36 | seq++; 37 | switch(sq_gettype(v,-1)) 38 | { 39 | case OT_NULL: 40 | pf(v,_SC("[%s] NULL\n"),name); 41 | break; 42 | case OT_INTEGER: 43 | sq_getinteger(v,-1,&i); 44 | pf(v,_SC("[%s] %d\n"),name,i); 45 | break; 46 | case OT_FLOAT: 47 | sq_getfloat(v,-1,&f); 48 | pf(v,_SC("[%s] %.14g\n"),name,f); 49 | break; 50 | case OT_USERPOINTER: 51 | pf(v,_SC("[%s] USERPOINTER\n"),name); 52 | break; 53 | case OT_STRING: 54 | sq_getstring(v,-1,&s); 55 | pf(v,_SC("[%s] \"%s\"\n"),name,s); 56 | break; 57 | case OT_TABLE: 58 | pf(v,_SC("[%s] TABLE\n"),name); 59 | break; 60 | case OT_ARRAY: 61 | pf(v,_SC("[%s] ARRAY\n"),name); 62 | break; 63 | case OT_CLOSURE: 64 | pf(v,_SC("[%s] CLOSURE\n"),name); 65 | break; 66 | case OT_NATIVECLOSURE: 67 | pf(v,_SC("[%s] NATIVECLOSURE\n"),name); 68 | break; 69 | case OT_GENERATOR: 70 | pf(v,_SC("[%s] GENERATOR\n"),name); 71 | break; 72 | case OT_USERDATA: 73 | pf(v,_SC("[%s] USERDATA\n"),name); 74 | break; 75 | case OT_THREAD: 76 | pf(v,_SC("[%s] THREAD\n"),name); 77 | break; 78 | case OT_CLASS: 79 | pf(v,_SC("[%s] CLASS\n"),name); 80 | break; 81 | case OT_INSTANCE: 82 | pf(v,_SC("[%s] INSTANCE\n"),name); 83 | break; 84 | case OT_WEAKREF: 85 | pf(v,_SC("[%s] WEAKREF\n"),name); 86 | break; 87 | case OT_BOOL:{ 88 | sq_getbool(v,-1,&b); 89 | pf(v,_SC("[%s] %s\n"),name,b?_SC("true"):_SC("false")); 90 | } 91 | break; 92 | default: assert(0); break; 93 | } 94 | sq_pop(v,1); 95 | } 96 | } 97 | } 98 | } 99 | 100 | template 101 | static SQInteger _sqstd_aux_printerror(HSQUIRRELVM v) 102 | { 103 | SQPRINTFUNCTION pf = sq_getprintfunc(v); 104 | if(pf) { 105 | const SQChar *sErr = 0; 106 | if(sq_gettop(v)>=1) { 107 | if(SQ_SUCCEEDED(sq_getstring(v,2,&sErr))) { 108 | pf(v,_SC("\nAN ERROR HAS OCCURED [%s]\n"),sErr); 109 | } 110 | else{ 111 | pf(v,_SC("\nAN ERROR HAS OCCURED [unknown]\n")); 112 | } 113 | sqstd_printcallstack(v); 114 | } 115 | } 116 | return 0; 117 | } 118 | 119 | template 120 | void _sqstd_compiler_error(HSQUIRRELVM v,const SQChar *sErr,const SQChar *sSource,SQInteger line,SQInteger column) 121 | { 122 | SQPRINTFUNCTION pf = sq_getprintfunc(v); 123 | if(pf) { 124 | pf(v,_SC("%s line = (%d) column = (%d) : error %s\n"),sSource,line,column,sErr); 125 | } 126 | } 127 | 128 | template 129 | void sqstd_seterrorhandlers(HSQUIRRELVM v) 130 | { 131 | sq_setcompilererrorhandler(v,_sqstd_compiler_error); 132 | sq_newclosure(v,_sqstd_aux_printerror,0); 133 | sq_seterrorhandler(v); 134 | } 135 | -------------------------------------------------------------------------------- /src/squirrel/sqstdlib/sqstdblobimpl.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_BLOBIMPL_H_ 3 | #define _SQSTD_BLOBIMPL_H_ 4 | 5 | struct SQBlob : public SQStream 6 | { 7 | SQBlob(SQInteger size) { 8 | _size = size; 9 | _allocated = size; 10 | _buf = (unsigned char *)sq_malloc(size); 11 | memset(_buf, 0, _size); 12 | _ptr = 0; 13 | _owns = true; 14 | } 15 | virtual ~SQBlob() { 16 | sq_free(_buf, _allocated); 17 | } 18 | SQInteger Write(void *buffer, SQInteger size) { 19 | if(!CanAdvance(size)) { 20 | GrowBufOf(_ptr + size - _size); 21 | } 22 | memcpy(&_buf[_ptr], buffer, size); 23 | _ptr += size; 24 | return size; 25 | } 26 | SQInteger Read(void *buffer,SQInteger size) { 27 | SQInteger n = size; 28 | if(!CanAdvance(size)) { 29 | if((_size - _ptr) > 0) 30 | n = _size - _ptr; 31 | else return 0; 32 | } 33 | memcpy(buffer, &_buf[_ptr], n); 34 | _ptr += n; 35 | return n; 36 | } 37 | bool Resize(SQInteger n) { 38 | if(!_owns) return false; 39 | if(n != _allocated) { 40 | unsigned char *newbuf = (unsigned char *)sq_malloc(n); 41 | memset(newbuf,0,n); 42 | if(_size > n) 43 | memcpy(newbuf,_buf,n); 44 | else 45 | memcpy(newbuf,_buf,_size); 46 | sq_free(_buf,_allocated); 47 | _buf=newbuf; 48 | _allocated = n; 49 | if(_size > _allocated) 50 | _size = _allocated; 51 | if(_ptr > _allocated) 52 | _ptr = _allocated; 53 | } 54 | return true; 55 | } 56 | bool GrowBufOf(SQInteger n) 57 | { 58 | bool ret = true; 59 | if(_size + n > _allocated) { 60 | if(_size + n > _size * 2) 61 | ret = Resize(_size + n); 62 | else 63 | ret = Resize(_size * 2); 64 | } 65 | _size = _size + n; 66 | return ret; 67 | } 68 | bool CanAdvance(SQInteger n) { 69 | if(_ptr+n>_size)return false; 70 | return true; 71 | } 72 | SQInteger Seek(SQInteger offset, SQInteger origin) { 73 | switch(origin) { 74 | case SQ_SEEK_SET: 75 | if(offset > _size || offset < 0) return -1; 76 | _ptr = offset; 77 | break; 78 | case SQ_SEEK_CUR: 79 | if(_ptr + offset > _size || _ptr + offset < 0) return -1; 80 | _ptr += offset; 81 | break; 82 | case SQ_SEEK_END: 83 | if(_size + offset > _size || _size + offset < 0) return -1; 84 | _ptr = _size + offset; 85 | break; 86 | default: return -1; 87 | } 88 | return 0; 89 | } 90 | bool IsValid() { 91 | return _buf?true:false; 92 | } 93 | bool EOS() { 94 | return _ptr == _size; 95 | } 96 | SQInteger Flush() { return 0; } 97 | SQInteger Tell() { return _ptr; } 98 | SQInteger Len() { return _size; } 99 | SQUserPointer GetBuf(){ return _buf; } 100 | private: 101 | SQInteger _size; 102 | SQInteger _allocated; 103 | SQInteger _ptr; 104 | unsigned char *_buf; 105 | bool _owns; 106 | }; 107 | 108 | #endif //_SQSTD_BLOBIMPL_H_ 109 | -------------------------------------------------------------------------------- /src/squirrel/sqstdlib/sqstdmath.cpp: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define SINGLE_ARG_FUNC(_funcname) template static SQInteger math_##_funcname(HSQUIRRELVM v){ \ 8 | SQFloat f; \ 9 | sq_getfloat(v,2,&f); \ 10 | sq_pushfloat(v,(SQFloat)_funcname(f)); \ 11 | return 1; \ 12 | } 13 | 14 | #define TWO_ARGS_FUNC(_funcname) template static SQInteger math_##_funcname(HSQUIRRELVM v){ \ 15 | SQFloat p1,p2; \ 16 | sq_getfloat(v,2,&p1); \ 17 | sq_getfloat(v,3,&p2); \ 18 | sq_pushfloat(v,(SQFloat)_funcname(p1,p2)); \ 19 | return 1; \ 20 | } 21 | 22 | template 23 | static SQInteger math_srand(HSQUIRRELVM v) 24 | { 25 | SQInteger i; 26 | if(SQ_FAILED(sq_getinteger(v,2,&i))) 27 | return sq_throwerror(v,_SC("invalid param")); 28 | srand((unsigned int)i); 29 | return 0; 30 | } 31 | 32 | template 33 | static SQInteger math_rand(HSQUIRRELVM v) 34 | { 35 | sq_pushinteger(v,rand()); 36 | return 1; 37 | } 38 | 39 | template 40 | static SQInteger math_abs(HSQUIRRELVM v) 41 | { 42 | SQInteger n; 43 | sq_getinteger(v,2,&n); 44 | sq_pushinteger(v,(SQInteger)abs((int)n)); 45 | return 1; 46 | } 47 | 48 | SINGLE_ARG_FUNC(sqrt) 49 | SINGLE_ARG_FUNC(fabs) 50 | SINGLE_ARG_FUNC(sin) 51 | SINGLE_ARG_FUNC(cos) 52 | SINGLE_ARG_FUNC(asin) 53 | SINGLE_ARG_FUNC(acos) 54 | SINGLE_ARG_FUNC(log) 55 | SINGLE_ARG_FUNC(log10) 56 | SINGLE_ARG_FUNC(tan) 57 | SINGLE_ARG_FUNC(atan) 58 | TWO_ARGS_FUNC(atan2) 59 | TWO_ARGS_FUNC(pow) 60 | SINGLE_ARG_FUNC(floor) 61 | SINGLE_ARG_FUNC(ceil) 62 | SINGLE_ARG_FUNC(exp) 63 | 64 | #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),math_##name,nparams,tycheck} 65 | template 66 | static SQRegFunction mathlib_funcs[] = { 67 | _DECL_FUNC(sqrt,2,_SC(".n")), 68 | _DECL_FUNC(sin,2,_SC(".n")), 69 | _DECL_FUNC(cos,2,_SC(".n")), 70 | _DECL_FUNC(asin,2,_SC(".n")), 71 | _DECL_FUNC(acos,2,_SC(".n")), 72 | _DECL_FUNC(log,2,_SC(".n")), 73 | _DECL_FUNC(log10,2,_SC(".n")), 74 | _DECL_FUNC(tan,2,_SC(".n")), 75 | _DECL_FUNC(atan,2,_SC(".n")), 76 | _DECL_FUNC(atan2,3,_SC(".nn")), 77 | _DECL_FUNC(pow,3,_SC(".nn")), 78 | _DECL_FUNC(floor,2,_SC(".n")), 79 | _DECL_FUNC(ceil,2,_SC(".n")), 80 | _DECL_FUNC(exp,2,_SC(".n")), 81 | _DECL_FUNC(srand,2,_SC(".n")), 82 | _DECL_FUNC(rand,1,NULL), 83 | _DECL_FUNC(fabs,2,_SC(".n")), 84 | _DECL_FUNC(abs,2,_SC(".n")), 85 | {0,0}, 86 | }; 87 | 88 | #ifndef M_PI 89 | #define M_PI (3.14159265358979323846) 90 | #endif 91 | 92 | template 93 | SQRESULT sqstd_register_mathlib(HSQUIRRELVM v) 94 | { 95 | SQInteger i=0; 96 | while(mathlib_funcs[i].name!=0) { 97 | sq_pushstring(v,mathlib_funcs[i].name,-1); 98 | sq_newclosure(v,mathlib_funcs[i].f,0); 99 | sq_setparamscheck(v,mathlib_funcs[i].nparamscheck,mathlib_funcs[i].typemask); 100 | sq_setnativeclosurename(v,-1,mathlib_funcs[i].name); 101 | sq_createslot(v,-3); 102 | i++; 103 | } 104 | sq_pushstring(v,_SC("RAND_MAX"),-1); 105 | sq_pushinteger(v,RAND_MAX); 106 | sq_createslot(v,-3); 107 | sq_pushstring(v,_SC("PI"),-1); 108 | sq_pushfloat(v,(SQFloat)M_PI); 109 | sq_createslot(v,-3); 110 | return SQ_OK; 111 | } 112 | -------------------------------------------------------------------------------- /src/squirrel/sqstdlib/sqstdstream.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_STREAM_H_ 3 | #define _SQSTD_STREAM_H_ 4 | 5 | template 6 | SQInteger _stream_readblob(HSQUIRRELVM v); 7 | template 8 | SQInteger _stream_readline(HSQUIRRELVM v); 9 | template 10 | SQInteger _stream_readn(HSQUIRRELVM v); 11 | template 12 | SQInteger _stream_writeblob(HSQUIRRELVM v); 13 | template 14 | SQInteger _stream_writen(HSQUIRRELVM v); 15 | template 16 | SQInteger _stream_seek(HSQUIRRELVM v); 17 | template 18 | SQInteger _stream_tell(HSQUIRRELVM v); 19 | template 20 | SQInteger _stream_len(HSQUIRRELVM v); 21 | template 22 | SQInteger _stream_eos(HSQUIRRELVM v); 23 | template 24 | SQInteger _stream_flush(HSQUIRRELVM v); 25 | 26 | #define _DECL_STREAM_FUNC(name,nparams,typecheck) {_SC(#name),_stream_##name,nparams,typecheck} 27 | template 28 | SQRESULT declare_stream(HSQUIRRELVM v, const SQChar* name,SQUserPointer typetag,const SQChar* reg_name,SQRegFunction *methods,SQRegFunction *globals); 29 | #endif /*_SQSTD_STREAM_H_*/ 30 | -------------------------------------------------------------------------------- /src/squirrel/sqstdlib/sqstdsystem.cpp: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef SQUNICODE 9 | #include 10 | #define scgetenv _wgetenv 11 | #define scsystem _wsystem 12 | #define scasctime _wasctime 13 | #define scremove _wremove 14 | #define screname _wrename 15 | #else 16 | #define scgetenv getenv 17 | #define scsystem system 18 | #define scasctime asctime 19 | #define scremove remove 20 | #define screname rename 21 | #endif 22 | 23 | template 24 | static SQInteger _system_getenv(HSQUIRRELVM v) 25 | { 26 | const SQChar *s; 27 | if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){ 28 | sq_pushstring(v,scgetenv(s),-1); 29 | return 1; 30 | } 31 | return 0; 32 | } 33 | 34 | template 35 | static SQInteger _system_system(HSQUIRRELVM v) 36 | { 37 | const SQChar *s; 38 | if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){ 39 | sq_pushinteger(v,scsystem(s)); 40 | return 1; 41 | } 42 | return sq_throwerror(v,_SC("wrong param")); 43 | } 44 | 45 | template 46 | static SQInteger _system_clock(HSQUIRRELVM v) 47 | { 48 | sq_pushfloat(v,((SQFloat)clock())/(SQFloat)CLOCKS_PER_SEC); 49 | return 1; 50 | } 51 | 52 | template 53 | static SQInteger _system_time(HSQUIRRELVM v) 54 | { 55 | time_t t; 56 | time(&t); 57 | sq_pushinteger(v,*((SQInteger *)&t)); 58 | return 1; 59 | } 60 | 61 | template 62 | static SQInteger _system_remove(HSQUIRRELVM v) 63 | { 64 | const SQChar *s; 65 | sq_getstring(v,2,&s); 66 | if(scremove(s)==-1) 67 | return sq_throwerror(v,_SC("remove() failed")); 68 | return 0; 69 | } 70 | 71 | template 72 | static SQInteger _system_rename(HSQUIRRELVM v) 73 | { 74 | const SQChar *oldn,*newn; 75 | sq_getstring(v,2,&oldn); 76 | sq_getstring(v,3,&newn); 77 | if(screname(oldn,newn)==-1) 78 | return sq_throwerror(v,_SC("rename() failed")); 79 | return 0; 80 | } 81 | 82 | template 83 | static void _set_integer_slot(HSQUIRRELVM v,const SQChar *name,SQInteger val) 84 | { 85 | sq_pushstring(v,name,-1); 86 | sq_pushinteger(v,val); 87 | sq_rawset(v,-3); 88 | } 89 | 90 | template 91 | static SQInteger _system_date(HSQUIRRELVM v) 92 | { 93 | time_t t; 94 | SQInteger it; 95 | SQInteger format = 'l'; 96 | if(sq_gettop(v) > 1) { 97 | sq_getinteger(v,2,&it); 98 | t = it; 99 | if(sq_gettop(v) > 2) { 100 | sq_getinteger(v,3,(SQInteger*)&format); 101 | } 102 | } 103 | else { 104 | time(&t); 105 | } 106 | tm *date; 107 | if(format == 'u') 108 | date = gmtime(&t); 109 | else 110 | date = localtime(&t); 111 | if(!date) 112 | return sq_throwerror(v,_SC("crt api failure")); 113 | sq_newtable(v); 114 | _set_integer_slot(v, _SC("sec"), date->tm_sec); 115 | _set_integer_slot(v, _SC("min"), date->tm_min); 116 | _set_integer_slot(v, _SC("hour"), date->tm_hour); 117 | _set_integer_slot(v, _SC("day"), date->tm_mday); 118 | _set_integer_slot(v, _SC("month"), date->tm_mon); 119 | _set_integer_slot(v, _SC("year"), date->tm_year+1900); 120 | _set_integer_slot(v, _SC("wday"), date->tm_wday); 121 | _set_integer_slot(v, _SC("yday"), date->tm_yday); 122 | return 1; 123 | } 124 | 125 | 126 | 127 | #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_system_##name,nparams,pmask} 128 | template 129 | static SQRegFunction systemlib_funcs[]={ 130 | _DECL_FUNC(getenv,2,_SC(".s")), 131 | _DECL_FUNC(system,2,_SC(".s")), 132 | _DECL_FUNC(clock,1,NULL), 133 | _DECL_FUNC(time,1,NULL), 134 | _DECL_FUNC(date,-1,_SC(".nn")), 135 | _DECL_FUNC(remove,2,_SC(".s")), 136 | _DECL_FUNC(rename,3,_SC(".ss")), 137 | {0,0} 138 | }; 139 | 140 | template 141 | SQInteger sqstd_register_systemlib(HSQUIRRELVM v) 142 | { 143 | SQInteger i=0; 144 | while(systemlib_funcs[i].name!=0) 145 | { 146 | sq_pushstring(v,systemlib_funcs[i].name,-1); 147 | sq_newclosure(v,systemlib_funcs[i].f,0); 148 | sq_setparamscheck(v,systemlib_funcs[i].nparamscheck,systemlib_funcs[i].typemask); 149 | sq_setnativeclosurename(v,-1,systemlib_funcs[i].name); 150 | sq_createslot(v,-3); 151 | i++; 152 | } 153 | return 1; 154 | } 155 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqarray.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQARRAY_H_ 3 | #define _SQARRAY_H_ 4 | 5 | template 6 | struct SQArray : public CHAINABLE_OBJ 7 | { 8 | private: 9 | SQArray(SQSharedState *ss,SQInteger nsize){_values.resize(nsize); INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);} 10 | ~SQArray() 11 | { 12 | REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this); 13 | } 14 | public: 15 | static SQArray* Create(SQSharedState *ss,SQInteger nInitialSize){ 16 | SQArray *newarray=(SQArray*)SQ_MALLOC(sizeof(SQArray)); 17 | new (newarray) SQArray(ss,nInitialSize); 18 | return newarray; 19 | } 20 | #ifndef NO_GARBAGE_COLLECTOR 21 | void Mark(SQCollectable **chain); 22 | #endif 23 | void Finalize(){ 24 | _values.resize(0); 25 | } 26 | bool Get(const SQInteger nidx,SQObjectPtr &val) 27 | { 28 | if(nidx>=0 && nidx<(SQInteger)_values.size()){ 29 | SQObjectPtr &o = _values[nidx]; 30 | val = _realval(o); 31 | return true; 32 | } 33 | else return false; 34 | } 35 | bool Set(const SQInteger nidx,const SQObjectPtr &val) 36 | { 37 | if(nidx>=0 && nidx<(SQInteger)_values.size()){ 38 | _values[nidx]=val; 39 | return true; 40 | } 41 | else return false; 42 | } 43 | SQInteger Next(const SQObjectPtr &refpos,SQObjectPtr &outkey,SQObjectPtr &outval) 44 | { 45 | SQUnsignedInteger idx=TranslateIndex(refpos); 46 | while(idx<_values.size()){ 47 | //first found 48 | outkey=(SQInteger)idx; 49 | SQObjectPtr &o = _values[idx]; 50 | outval = _realval(o); 51 | //return idx for the next iteration 52 | return ++idx; 53 | } 54 | //nothing to iterate anymore 55 | return -1; 56 | } 57 | SQArray *Clone(){SQArray *anew=Create(_opt_ss(this),Size()); anew->_values.copy(_values); return anew; } 58 | SQInteger Size() const {return _values.size();} 59 | void Resize(SQInteger size,SQObjectPtr &fill = _null_) { _values.resize(size,fill); ShrinkIfNeeded(); } 60 | void Reserve(SQInteger size) { _values.reserve(size); } 61 | void Append(const SQObject &o){_values.push_back(o);} 62 | void Extend(const SQArray *a); 63 | SQObjectPtr &Top(){return _values.top();} 64 | void Pop(){_values.pop_back(); ShrinkIfNeeded(); } 65 | bool Insert(SQInteger idx,const SQObject &val){ 66 | if(idx < 0 || idx > (SQInteger)_values.size()) 67 | return false; 68 | _values.insert(idx,val); 69 | return true; 70 | } 71 | void ShrinkIfNeeded() { 72 | if(_values.size() <= _values.capacity()>>2) //shrink the array 73 | _values.shrinktofit(); 74 | } 75 | bool Remove(SQInteger idx){ 76 | if(idx < 0 || idx >= (SQInteger)_values.size()) 77 | return false; 78 | _values.remove(idx); 79 | ShrinkIfNeeded(); 80 | return true; 81 | } 82 | void Release() 83 | { 84 | sq_delete(this,SQArray); 85 | } 86 | SQObjectPtrVec _values; 87 | }; 88 | 89 | template SQArray; 90 | template SQArray; 91 | template SQArray; 92 | template SQArray; 93 | 94 | #endif //_SQARRAY_H_ 95 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqclosure.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQCLOSURE_H_ 3 | #define _SQCLOSURE_H_ 4 | 5 | template 6 | struct SQFunctionProto; 7 | 8 | template 9 | struct SQClosure : public CHAINABLE_OBJ 10 | { 11 | private: 12 | SQClosure(SQSharedState *ss,SQFunctionProto *func){_function=func; INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);} 13 | public: 14 | static SQClosure *Create(SQSharedState *ss,SQFunctionProto *func){ 15 | SQClosure *nc=(SQClosure*)SQ_MALLOC(sizeof(SQClosure)); 16 | new (nc) SQClosure(ss,func); 17 | return nc; 18 | } 19 | void Release(){ 20 | sq_delete(this,SQClosure); 21 | } 22 | SQClosure *Clone() 23 | { 24 | SQClosure * ret = SQClosure::Create(_opt_ss(this),_funcproto(_function)); 25 | ret->_env = _env; 26 | ret->_outervalues.copy(_outervalues); 27 | ret->_defaultparams.copy(_defaultparams); 28 | return ret; 29 | } 30 | ~SQClosure() 31 | { 32 | REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this); 33 | } 34 | bool Save(SQVM *v,SQUserPointer up,SQWRITEFUNC write); 35 | static bool Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &ret); 36 | #ifndef NO_GARBAGE_COLLECTOR 37 | void Mark(SQCollectable **chain); 38 | void Finalize(){_outervalues.resize(0); } 39 | #endif 40 | SQObjectPtr _env; 41 | SQObjectPtr _function; 42 | SQObjectPtrVec _outervalues; 43 | SQObjectPtrVec _defaultparams; 44 | }; 45 | ////////////////////////////////////////////// 46 | template 47 | struct SQGenerator : public CHAINABLE_OBJ 48 | { 49 | enum SQGeneratorState{eRunning,eSuspended,eDead}; 50 | private: 51 | SQGenerator(SQSharedState *ss,SQClosure *closure){_closure=closure;_state=eRunning;_ci._generator=NULL;INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);} 52 | public: 53 | static SQGenerator *Create(SQSharedState *ss,SQClosure *closure){ 54 | SQGenerator *nc=(SQGenerator*)SQ_MALLOC(sizeof(SQGenerator)); 55 | new (nc) SQGenerator(ss,closure); 56 | return nc; 57 | } 58 | ~SQGenerator() 59 | { 60 | REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this); 61 | } 62 | void Kill(){ 63 | _state=eDead; 64 | _stack.resize(0); 65 | _closure=_null_;} 66 | void Release(){ 67 | sq_delete(this,SQGenerator); 68 | } 69 | bool Yield(SQVM *v); 70 | bool Resume(SQVM *v,SQInteger target); 71 | #ifndef NO_GARBAGE_COLLECTOR 72 | void Mark(SQCollectable **chain); 73 | void Finalize(){_stack.resize(0);_closure=_null_;} 74 | #endif 75 | SQObjectPtr _closure; 76 | SQObjectPtrVec _stack; 77 | SQObjectPtrVec _vargsstack; 78 | CallInfo _ci; 79 | ExceptionsTraps _etraps; 80 | SQGeneratorState _state; 81 | }; 82 | 83 | template 84 | struct SQNativeClosure : public CHAINABLE_OBJ 85 | { 86 | private: 87 | SQNativeClosure(SQSharedState *ss,SQFUNCTION func){_function=func;INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this); } 88 | public: 89 | static SQNativeClosure *Create(SQSharedState *ss,SQFUNCTION func) 90 | { 91 | SQNativeClosure *nc=(SQNativeClosure*)SQ_MALLOC(sizeof(SQNativeClosure)); 92 | new (nc) SQNativeClosure(ss,func); 93 | return nc; 94 | } 95 | SQNativeClosure *Clone() 96 | { 97 | SQNativeClosure * ret = SQNativeClosure::Create(_opt_ss(this),_function); 98 | ret->_env = _env; 99 | ret->_name = _name; 100 | ret->_outervalues.copy(_outervalues); 101 | ret->_typecheck.copy(_typecheck); 102 | ret->_nparamscheck = _nparamscheck; 103 | return ret; 104 | } 105 | ~SQNativeClosure() 106 | { 107 | REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain,this); 108 | } 109 | void Release(){ 110 | sq_delete(this,SQNativeClosure); 111 | } 112 | #ifndef NO_GARBAGE_COLLECTOR 113 | void Mark(SQCollectable **chain); 114 | void Finalize(){_outervalues.resize(0);} 115 | #endif 116 | SQInteger _nparamscheck; 117 | SQIntVec _typecheck; 118 | SQObjectPtrVec _outervalues; 119 | SQObjectPtr _env; 120 | SQFUNCTION _function; 121 | SQObjectPtr _name; 122 | }; 123 | 124 | template SQClosure; 125 | template SQClosure; 126 | template SQClosure; 127 | template SQClosure; 128 | 129 | template SQGenerator; 130 | template SQGenerator; 131 | template SQGenerator; 132 | template SQGenerator; 133 | 134 | template SQNativeClosure; 135 | template SQNativeClosure; 136 | template SQNativeClosure; 137 | template SQNativeClosure; 138 | 139 | #endif //_SQCLOSURE_H_ 140 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqcompiler.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQCOMPILER_H_ 3 | #define _SQCOMPILER_H_ 4 | 5 | template 6 | struct SQVM; 7 | 8 | #define TK_IDENTIFIER 258 9 | #define TK_STRING_LITERAL 259 10 | #define TK_INTEGER 260 11 | #define TK_FLOAT 261 12 | #define TK_DELEGATE 262 13 | #define TK_DELETE 263 14 | #define TK_EQ 264 15 | #define TK_NE 265 16 | #define TK_LE 266 17 | #define TK_GE 267 18 | #define TK_SWITCH 268 19 | #define TK_ARROW 269 20 | #define TK_AND 270 21 | #define TK_OR 271 22 | #define TK_IF 272 23 | #define TK_ELSE 273 24 | #define TK_WHILE 274 25 | #define TK_BREAK 275 26 | #define TK_FOR 276 27 | #define TK_DO 277 28 | #define TK_NULL 278 29 | #define TK_FOREACH 279 30 | #define TK_IN 280 31 | #define TK_NEWSLOT 281 32 | #define TK_MODULO 282 33 | #define TK_LOCAL 283 34 | #define TK_CLONE 284 35 | #define TK_FUNCTION 285 36 | #define TK_RETURN 286 37 | #define TK_TYPEOF 287 38 | #define TK_UMINUS 288 39 | #define TK_PLUSEQ 289 40 | #define TK_MINUSEQ 290 41 | #define TK_CONTINUE 291 42 | #define TK_YIELD 292 43 | #define TK_TRY 293 44 | #define TK_CATCH 294 45 | #define TK_THROW 295 46 | #define TK_SHIFTL 296 47 | #define TK_SHIFTR 297 48 | #define TK_RESUME 298 49 | #define TK_DOUBLE_COLON 299 50 | #define TK_CASE 300 51 | #define TK_DEFAULT 301 52 | #define TK_THIS 302 53 | #define TK_PLUSPLUS 303 54 | #define TK_MINUSMINUS 304 55 | #define TK_PARENT 305 56 | #define TK_USHIFTR 306 57 | #define TK_CLASS 307 58 | #define TK_EXTENDS 308 59 | #define TK_CONSTRUCTOR 310 60 | #define TK_INSTANCEOF 311 61 | #define TK_VARPARAMS 312 62 | #define TK_VARGC 313 63 | #define TK_VARGV 314 64 | #define TK_TRUE 315 65 | #define TK_FALSE 316 66 | #define TK_MULEQ 317 67 | #define TK_DIVEQ 318 68 | #define TK_MODEQ 319 69 | #define TK_ATTR_OPEN 320 70 | #define TK_ATTR_CLOSE 321 71 | #define TK_STATIC 322 72 | #define TK_ENUM 323 73 | #define TK_CONST 324 74 | 75 | 76 | typedef void(*CompilerErrorFunc)(void *ud, const SQChar *s); 77 | template 78 | bool Compile(SQVM *vm, SQLEXREADFUNC rg, SQUserPointer up, const SQChar *sourcename, SQObjectPtr &out, bool raiseerror, bool lineinfo); 79 | #endif //_SQCOMPILER_H_ 80 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqdebug.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | see copyright notice in squirrel.h 3 | */ 4 | #include "sqpcheader.h" 5 | #include 6 | #include "sqvm.h" 7 | #include "sqfuncproto.h" 8 | #include "sqclosure.h" 9 | #include "sqstring.h" 10 | 11 | template 12 | SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi) 13 | { 14 | SQInteger cssize = v->_callsstacksize; 15 | if (cssize > level) { 16 | auto &ci = v->_callsstack[cssize-level-1]; 17 | if(sq_isclosure(ci._closure)) { 18 | SQClosure *c = _closure(ci._closure); 19 | SQFunctionProto *proto = _funcproto(c->_function); 20 | fi->funcid = proto; 21 | fi->name = obj_type(proto->_name) == OT_STRING?_stringval(proto->_name):_SC("unknown"); 22 | fi->source = obj_type(proto->_name) == OT_STRING?_stringval(proto->_sourcename):_SC("unknown"); 23 | return SQ_OK; 24 | } 25 | } 26 | return sq_throwerror(v,_SC("the object is not a closure")); 27 | } 28 | 29 | template SQRESULT sq_getfunctioninfo(HSQUIRRELVM v, SQInteger idx, SQFunctionInfo *fi); 30 | template SQRESULT sq_getfunctioninfo(HSQUIRRELVM v, SQInteger idx, SQFunctionInfo *fi); 31 | template SQRESULT sq_getfunctioninfo(HSQUIRRELVM v, SQInteger idx, SQFunctionInfo *fi); 32 | template SQRESULT sq_getfunctioninfo(HSQUIRRELVM v, SQInteger idx, SQFunctionInfo *fi); 33 | 34 | template 35 | SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si) 36 | { 37 | SQInteger cssize = v->_callsstacksize; 38 | if (cssize > level) { 39 | memset(si, 0, sizeof(SQStackInfos)); 40 | auto &ci = v->_callsstack[cssize-level-1]; 41 | switch (obj_type(ci._closure)) { 42 | case OT_CLOSURE:{ 43 | SQFunctionProto *func = _funcproto(_closure(ci._closure)->_function); 44 | if (obj_type(func->_name) == OT_STRING) 45 | si->funcname = _stringval(func->_name); 46 | if (obj_type(func->_sourcename) == OT_STRING) 47 | si->source = _stringval(func->_sourcename); 48 | si->line = func->GetLine(ci._ip); 49 | } 50 | break; 51 | case OT_NATIVECLOSURE: 52 | si->source = _SC("NATIVE"); 53 | si->funcname = _SC("unknown"); 54 | if(obj_type(_nativeclosure(ci._closure)->_name) == OT_STRING) 55 | si->funcname = _stringval(_nativeclosure(ci._closure)->_name); 56 | si->line = -1; 57 | break; 58 | default: break; //shutup compiler 59 | } 60 | return SQ_OK; 61 | } 62 | return SQ_ERROR; 63 | } 64 | 65 | template SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si); 66 | template SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si); 67 | template SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si); 68 | template SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si); 69 | 70 | template 71 | void SQVM::Raise_Error(const SQChar *s, ...) 72 | { 73 | va_list vl; 74 | va_start(vl, s); 75 | scvsprintf(_sp(rsl((SQInteger)scstrlen(s)+(NUMBER_MAX_CHAR*2))), s, vl); 76 | va_end(vl); 77 | _lasterror = SQString::Create(_ss(this),_spval,-1); 78 | } 79 | 80 | template 81 | void SQVM::Raise_Error(SQObjectPtr &desc) 82 | { 83 | _lasterror = desc; 84 | } 85 | 86 | template 87 | SQString *SQVM::PrintObjVal(const SQObject &o) 88 | { 89 | switch(obj_type(o)) { 90 | case OT_STRING: return _string(o); 91 | case OT_INTEGER: 92 | scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%d"), _integer(o)); 93 | return SQString::Create(_ss(this), _spval); 94 | break; 95 | case OT_FLOAT: 96 | scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%.14g"), _float(o)); 97 | return SQString::Create(_ss(this), _spval); 98 | break; 99 | default: 100 | return SQString::Create(_ss(this), GetTypeName(o)); 101 | } 102 | } 103 | 104 | template 105 | void SQVM::Raise_IdxError(SQObject &o) 106 | { 107 | SQObjectPtr oval = PrintObjVal(o); 108 | Raise_Error(_SC("the index '%.50s' does not exist"), _stringval(oval)); 109 | } 110 | 111 | template 112 | void SQVM::Raise_CompareError(const SQObject &o1, const SQObject &o2) 113 | { 114 | SQObjectPtr oval1 = PrintObjVal(o1), oval2 = PrintObjVal(o2); 115 | Raise_Error(_SC("comparsion between '%.50s' and '%.50s'"), _stringval(oval1), _stringval(oval2)); 116 | } 117 | 118 | template 119 | void SQVM::Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger type) 120 | { 121 | SQObjectPtr exptypes = SQString::Create(_ss(this), _SC(""), -1); 122 | SQInteger found = 0; 123 | for(SQInteger i=0; i<16; i++) 124 | { 125 | SQInteger mask = 0x00000001 << i; 126 | if(typemask & (mask)) { 127 | if(found>0) StringCat(exptypes,SQString::Create(_ss(this), _SC("|"), -1), exptypes); 128 | found ++; 129 | StringCat(exptypes,SQString::Create(_ss(this), IdType2Name((SQObjectType)mask), -1), exptypes); 130 | } 131 | } 132 | Raise_Error(_SC("parameter %d has an invalid type '%s' ; expected: '%s'"), nparam, IdType2Name((SQObjectType)type), _stringval(exptypes)); 133 | } 134 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqfuncstate.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQFUNCSTATE_H_ 3 | #define _SQFUNCSTATE_H_ 4 | /////////////////////////////////// 5 | #include "squtils.h" 6 | 7 | template 8 | struct SQFuncState 9 | { 10 | SQFuncState(SQSharedState *ss,SQFuncState *parent,CompilerErrorFunc efunc,void *ed); 11 | ~SQFuncState(); 12 | #ifdef _DEBUG_DUMP 13 | void Dump(SQFunctionProto *func); 14 | #endif 15 | void Error(const SQChar *err); 16 | SQFuncState *PushChildState(SQSharedState *ss); 17 | void PopChildState(); 18 | void AddInstruction(SQOpcode _op,SQInteger arg0=0,SQInteger arg1=0,SQInteger arg2=0,SQInteger arg3=0){SQInstruction i(_op,arg0,arg1,arg2,arg3);AddInstruction(i);} 19 | void AddInstruction(SQInstruction &i); 20 | void SetIntructionParams(SQInteger pos,SQInteger arg0,SQInteger arg1,SQInteger arg2=0,SQInteger arg3=0); 21 | void SetIntructionParam(SQInteger pos,SQInteger arg,SQInteger val); 22 | SQInstruction &GetInstruction(SQInteger pos){return _instructions[pos];} 23 | void PopInstructions(SQInteger size){for(SQInteger i=0;i &name); 32 | void AddParameter(const SQObject &name); 33 | void AddOuterValue(const SQObject &name); 34 | SQInteger GetLocalVariable(const SQObject &name); 35 | SQInteger GetOuterVariable(const SQObject &name); 36 | SQInteger GenerateCode(); 37 | SQInteger GetStackSize(); 38 | SQInteger CalcStackFrameSize(); 39 | void AddLineInfos(SQInteger line,bool lineop,bool force=false); 40 | SQFunctionProto *BuildProto(); 41 | SQInteger AllocStackPos(); 42 | SQInteger PushTarget(SQInteger n=-1); 43 | SQInteger PopTarget(); 44 | SQInteger TopTarget(); 45 | SQInteger GetUpTarget(SQInteger n); 46 | bool IsLocal(SQUnsignedInteger stkpos); 47 | SQObject CreateString(const SQChar *s,SQInteger len = -1); 48 | SQObject CreateTable(); 49 | bool IsConstant(const SQObject &name,SQObject &e); 50 | SQInteger _returnexp; 51 | SQLocalVarInfoVec _vlocals; 52 | SQIntVec _targetstack; 53 | SQInteger _stacksize; 54 | bool _varparams; 55 | bool _bgenerator; 56 | SQIntVec _unresolvedbreaks; 57 | SQIntVec _unresolvedcontinues; 58 | SQObjectPtrVec _functions; 59 | SQObjectPtrVec _parameters; 60 | SQOuterVarVec _outervalues; 61 | SQInstructionVec _instructions; 62 | SQLocalVarInfoVec _localvarinfos; 63 | SQObjectPtr _literals; 64 | SQObjectPtr _strings; 65 | SQObjectPtr _name; 66 | SQObjectPtr _sourcename; 67 | SQInteger _nliterals; 68 | SQLineInfoVec _lineinfos; 69 | SQFuncState *_parent; 70 | SQIntVec _breaktargets; 71 | SQIntVec _continuetargets; 72 | SQIntVec _defaultparams; 73 | SQInteger _lastline; 74 | SQInteger _traps; //contains number of nested exception traps 75 | bool _optimization; 76 | SQSharedState *_sharedstate; 77 | sqvector*> _childstates; 78 | SQInteger GetConstant(const SQObject &cons); 79 | private: 80 | CompilerErrorFunc _errfunc; 81 | void *_errtarget; 82 | }; 83 | 84 | template SQFuncState; 85 | template SQFuncState; 86 | template SQFuncState; 87 | template SQFuncState; 88 | 89 | #endif //_SQFUNCSTATE_H_ 90 | 91 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqlexer.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQLEXER_H_ 3 | #define _SQLEXER_H_ 4 | 5 | #ifdef SQUNICODE 6 | typedef SQChar LexChar; 7 | #else 8 | typedef unsigned char LexChar; 9 | #endif 10 | 11 | template 12 | struct SQLexer 13 | { 14 | SQLexer(); 15 | ~SQLexer(); 16 | void Init(SQSharedState *ss,SQLEXREADFUNC rg,SQUserPointer up,CompilerErrorFunc efunc,void *ed); 17 | void Error(const SQChar *err); 18 | SQInteger Lex(); 19 | const SQChar *Tok2Str(SQInteger tok); 20 | private: 21 | SQInteger GetIDType(SQChar *s); 22 | SQInteger ReadString(SQInteger ndelim,bool verbatim); 23 | SQInteger ReadNumber(); 24 | void LexBlockComment(); 25 | SQInteger ReadID(); 26 | void Next(); 27 | SQInteger _curtoken; 28 | SQTable *_keywords; 29 | public: 30 | SQInteger _prevtoken; 31 | SQInteger _currentline; 32 | SQInteger _lasttokenline; 33 | SQInteger _currentcolumn; 34 | const SQChar *_svalue; 35 | SQInteger _nvalue; 36 | SQFloat _fvalue; 37 | SQLEXREADFUNC _readf; 38 | SQUserPointer _up; 39 | LexChar _currdata; 40 | SQSharedState *_sharedstate; 41 | sqvector _longstr; 42 | CompilerErrorFunc _errfunc; 43 | void *_errtarget; 44 | }; 45 | 46 | template SQLexer; 47 | template SQLexer; 48 | template SQLexer; 49 | template SQLexer; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqmem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | see copyright notice in squirrel.h 3 | */ 4 | #include "sqpcheader.h" 5 | 6 | #include 7 | 8 | #pragma runtime_checks("", off) 9 | 10 | void * (__fastcall *_sq_vm_realloc)(void *, SQUnsignedInteger, SQUnsignedInteger); 11 | 12 | void *sq_vm_malloc(SQUnsignedInteger size) 13 | { 14 | if (_sq_vm_realloc) { 15 | void *p = _sq_vm_realloc(nullptr, 0, size); 16 | #ifndef _WIN64 17 | __asm { add esp, 4 } // "fastcall" but with caller cleanup of the stack argument - LTO?! 18 | #endif 19 | return p; 20 | } 21 | 22 | return nullptr; 23 | } 24 | 25 | void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size) 26 | { 27 | if (_sq_vm_realloc) { 28 | p = _sq_vm_realloc(p, oldsize, size); 29 | #ifndef _WIN64 30 | __asm { add esp, 4 } // "fastcall" but with caller cleanup of the stack argument - LTO?! 31 | #endif 32 | return p; 33 | } 34 | 35 | return nullptr; 36 | } 37 | 38 | void sq_vm_free(void *p, SQUnsignedInteger size) 39 | { 40 | if (_sq_vm_realloc) { 41 | _sq_vm_realloc(p, size, 0); 42 | #ifndef _WIN64 43 | __asm { add esp, 4 } // "fastcall" but with caller cleanup of the stack argument - LTO?! 44 | #endif 45 | } 46 | } 47 | 48 | #pragma runtime_checks("", restore) 49 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqopcodes.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQOPCODES_H_ 3 | #define _SQOPCODES_H_ 4 | 5 | #define MAX_FUNC_STACKSIZE 0xFF 6 | #define MAX_LITERALS ((SQInteger)0x7FFFFFFF) 7 | 8 | enum BitWiseOP { 9 | BW_AND = 0, 10 | BW_OR = 2, 11 | BW_XOR = 3, 12 | BW_SHIFTL = 4, 13 | BW_SHIFTR = 5, 14 | BW_USHIFTR = 6 15 | }; 16 | 17 | enum CmpOP { 18 | CMP_G = 0, 19 | CMP_GE = 2, 20 | CMP_L = 3, 21 | CMP_LE = 4 22 | }; 23 | enum SQOpcode 24 | { 25 | _OP_LINE= 0x00, 26 | _OP_LOAD= 0x01, 27 | _OP_LOADINT= 0x02, 28 | _OP_LOADFLOAT= 0x03, 29 | _OP_DLOAD= 0x04, 30 | _OP_TAILCALL= 0x05, 31 | _OP_CALL= 0x06, 32 | _OP_PREPCALL= 0x07, 33 | _OP_PREPCALLK= 0x08, 34 | _OP_GETK= 0x09, 35 | _OP_MOVE= 0x0A, 36 | _OP_NEWSLOT= 0x0B, 37 | _OP_DELETE= 0x0C, 38 | _OP_SET= 0x0D, 39 | _OP_GET= 0x0E, 40 | _OP_EQ= 0x0F, 41 | _OP_NE= 0x10, 42 | _OP_ARITH= 0x11, 43 | _OP_BITW= 0x12, 44 | _OP_RETURN= 0x13, 45 | _OP_LOADNULLS= 0x14, 46 | _OP_LOADROOTTABLE= 0x15, 47 | _OP_LOADBOOL= 0x16, 48 | _OP_DMOVE= 0x17, 49 | _OP_JMP= 0x18, 50 | _OP_JNZ= 0x19, 51 | _OP_JZ= 0x1A, 52 | _OP_LOADFREEVAR= 0x1B, 53 | _OP_VARGC= 0x1C, 54 | _OP_GETVARGV= 0x1D, 55 | _OP_NEWTABLE= 0x1E, 56 | _OP_NEWARRAY= 0x1F, 57 | _OP_APPENDARRAY= 0x20, 58 | _OP_GETPARENT= 0x21, 59 | _OP_COMPARITH= 0x22, 60 | _OP_COMPARITHL= 0x23, 61 | _OP_INC= 0x24, 62 | _OP_INCL= 0x25, 63 | _OP_PINC= 0x26, 64 | _OP_PINCL= 0x27, 65 | _OP_CMP= 0x28, 66 | _OP_EXISTS= 0x29, 67 | _OP_INSTANCEOF= 0x2A, 68 | _OP_AND= 0x2B, 69 | _OP_OR= 0x2C, 70 | _OP_NEG= 0x2D, 71 | _OP_NOT= 0x2E, 72 | _OP_BWNOT= 0x2F, 73 | _OP_CLOSURE= 0x30, 74 | _OP_YIELD= 0x31, 75 | _OP_RESUME= 0x32, 76 | _OP_FOREACH= 0x33, 77 | _OP_POSTFOREACH= 0x34, 78 | _OP_DELEGATE= 0x35, 79 | _OP_CLONE= 0x36, 80 | _OP_TYPEOF= 0x37, 81 | _OP_PUSHTRAP= 0x38, 82 | _OP_POPTRAP= 0x39, 83 | _OP_THROW= 0x3A, 84 | _OP_CLASS= 0x3B, 85 | _OP_NEWSLOTA= 0x3C, 86 | }; 87 | 88 | struct SQInstructionDesc { 89 | const SQChar *name; 90 | }; 91 | 92 | struct SQInstruction 93 | { 94 | SQInstruction(){}; 95 | SQInstruction(SQOpcode _op,SQInteger a0=0,SQInteger a1=0,SQInteger a2=0,SQInteger a3=0) 96 | { op = _op; 97 | _arg0 = (unsigned char)a0;_arg1 = (SQInt32)a1; 98 | _arg2 = (unsigned char)a2;_arg3 = (unsigned char)a3; 99 | } 100 | 101 | 102 | SQInt32 _arg1; 103 | unsigned char op; 104 | unsigned char _arg0; 105 | unsigned char _arg2; 106 | unsigned char _arg3; 107 | }; 108 | 109 | #include "squtils.h" 110 | typedef sqvector SQInstructionVec; 111 | 112 | #define NEW_SLOT_ATTRIBUTES_FLAG 0x01 113 | #define NEW_SLOT_STATIC_FLAG 0x02 114 | 115 | #endif // _SQOPCODES_H_ 116 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqpcheader.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQPCHEADER_H_ 3 | #define _SQPCHEADER_H_ 4 | 5 | #if defined(_MSC_VER) && defined(_DEBUG) 6 | #include 7 | #endif 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | //squirrel stuff 15 | #include "squirrel.h" 16 | #include "sqobject.h" 17 | #include "sqstate.h" 18 | 19 | #endif //_SQPCHEADER_H_ 20 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqstring.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTRING_H_ 3 | #define _SQSTRING_H_ 4 | 5 | inline SQHash _hashstr (const SQChar *s, size_t l) 6 | { 7 | SQHash h = (SQHash)l; /* seed */ 8 | size_t step = (l>>5)|1; /* if string is too long, don't hash all its chars */ 9 | for (; l>=step; l-=step) 10 | h = h ^ ((h<<5)+(h>>2)+(unsigned short)*(s++)); 11 | return h; 12 | } 13 | 14 | template 15 | struct SQString : public SQRefCounted 16 | { 17 | SQString(){} 18 | ~SQString(){} 19 | public: 20 | static SQString *Create(SQSharedState *ss, const SQChar *, SQInteger len = -1 ); 21 | SQInteger Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval); 22 | void Release(); 23 | SQSharedState *_sharedstate; 24 | SQString *_next; //chain for the string table 25 | SQInteger _len; 26 | 27 | #if defined(_SQ_M2) && defined(_WIN64) 28 | SQInteger _m2_unknown; 29 | #endif 30 | 31 | SQHash _hash; 32 | SQChar _val[1]; 33 | }; 34 | 35 | template SQString; 36 | template SQString; 37 | template SQString; 38 | template SQString; 39 | 40 | #endif //_SQSTRING_H_ 41 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/sqtable.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQTABLE_H_ 3 | #define _SQTABLE_H_ 4 | /* 5 | * The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.) 6 | * http://www.lua.org/copyright.html#4 7 | * http://www.lua.org/source/4.0.1/src_ltable.c.html 8 | */ 9 | 10 | #include "sqstring.h" 11 | 12 | 13 | #define hashptr(p) ((SQHash)(((SQInteger)p) >> 3)) 14 | 15 | template 16 | inline SQHash HashObj(const SQObjectPtr &key) 17 | { 18 | switch(obj_type(key)) { 19 | case OT_STRING: return _string(key)->_hash; 20 | case OT_FLOAT: return (SQHash)((SQInteger)_float(key)); 21 | case OT_BOOL: case OT_INTEGER: return (SQHash)((SQInteger)_integer(key)); 22 | default: return hashptr(key._unVal.pRefCounted); 23 | } 24 | } 25 | 26 | template 27 | struct SQTable : public SQDelegable 28 | { 29 | private: 30 | struct _HashNode 31 | { 32 | _HashNode() { next = NULL; } 33 | SQObjectPtr val; 34 | SQObjectPtr key; 35 | _HashNode *next; 36 | }; 37 | _HashNode *_firstfree; 38 | _HashNode *_nodes; 39 | SQInteger _numofnodes; 40 | SQInteger _usednodes; 41 | 42 | /////////////////////////// 43 | void AllocNodes(SQInteger nSize); 44 | void Rehash(bool force); 45 | SQTable(SQSharedState *ss, SQInteger nInitialSize); 46 | void _ClearNodes(); 47 | public: 48 | static SQTable* Create(SQSharedState *ss,SQInteger nInitialSize) 49 | { 50 | SQTable *newtable = (SQTable*)SQ_MALLOC(sizeof(SQTable)); 51 | new (newtable) SQTable(ss, nInitialSize); 52 | newtable->_delegate = NULL; 53 | return newtable; 54 | } 55 | void Finalize(); 56 | SQTable *Clone(); 57 | ~SQTable() 58 | { 59 | SQDelegable::SetDelegate(NULL); 60 | REMOVE_FROM_CHAIN(&SQDelegable::_sharedstate->_gc_chain, this); 61 | for (SQInteger i = 0; i < _numofnodes; i++) _nodes[i].~_HashNode(); 62 | SQ_FREE(_nodes, _numofnodes * sizeof(_HashNode)); 63 | } 64 | #ifndef NO_GARBAGE_COLLECTOR 65 | void Mark(SQCollectable **chain); 66 | #endif 67 | inline _HashNode *_Get(const SQObjectPtr &key,SQHash hash) 68 | { 69 | _HashNode *n = &_nodes[hash]; 70 | do{ 71 | if(_rawval(n->key) == _rawval(key) && obj_type(n->key) == obj_type(key)){ 72 | return n; 73 | } 74 | }while((n = n->next)); 75 | return NULL; 76 | } 77 | bool Get(const SQObjectPtr &key,SQObjectPtr &val); 78 | void Remove(const SQObjectPtr &key); 79 | bool Set(const SQObjectPtr &key, const SQObjectPtr &val); 80 | //returns true if a new slot has been created false if it was already present 81 | bool NewSlot(const SQObjectPtr &key,const SQObjectPtr &val); 82 | SQInteger Next(bool getweakrefs,const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval); 83 | 84 | SQInteger CountUsed(){ return _usednodes;} 85 | void Clear(); 86 | void Release() 87 | { 88 | sq_delete(this, SQTable); 89 | } 90 | 91 | }; 92 | 93 | template SQTable; 94 | template SQTable; 95 | template SQTable; 96 | template SQTable; 97 | 98 | #endif //_SQTABLE_H_ 99 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/squserdata.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQUSERDATA_H_ 3 | #define _SQUSERDATA_H_ 4 | 5 | template 6 | struct SQUserData : SQDelegable 7 | { 8 | SQUserData(SQSharedState *ss){ SQDelegable::_delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); } 9 | ~SQUserData() 10 | { 11 | REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain, this); 12 | SQDelegable::SetDelegate(NULL); 13 | } 14 | static SQUserData* Create(SQSharedState *ss, SQInteger size) 15 | { 16 | SQUserData* ud = (SQUserData*)SQ_MALLOC(sizeof(SQUserData)+(size-1)); 17 | new (ud) SQUserData(ss); 18 | ud->_size = size; 19 | ud->_typetag = 0; 20 | return ud; 21 | } 22 | #ifndef NO_GARBAGE_COLLECTOR 23 | void Mark(SQCollectable **chain); 24 | void Finalize(){SQDelegable::SetDelegate(NULL);} 25 | #endif 26 | void Release() { 27 | if (_hook) _hook(_val,_size); 28 | SQInteger tsize = _size - 1; 29 | this->~SQUserData(); 30 | SQ_FREE(this, sizeof(SQUserData) + tsize); 31 | } 32 | 33 | SQInteger _size; 34 | SQRELEASEHOOK _hook; 35 | SQUserPointer _typetag; 36 | SQChar _val[1]; 37 | }; 38 | 39 | template SQUserData; 40 | template SQUserData; 41 | template SQUserData; 42 | template SQUserData; 43 | 44 | #endif //_SQUSERDATA_H_ 45 | -------------------------------------------------------------------------------- /src/squirrel/squirrel/squtils.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQUTILS_H_ 3 | #define _SQUTILS_H_ 4 | 5 | void *sq_vm_malloc(SQUnsignedInteger size); 6 | void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size); 7 | void sq_vm_free(void *p, SQUnsignedInteger size); 8 | 9 | #define sq_new(__ptr,__type) {__ptr=(__type *)sq_vm_malloc(sizeof(__type));new (__ptr) __type;} 10 | #define sq_delete(__ptr,__type) {__ptr->~__type();sq_vm_free(__ptr,sizeof(__type));} 11 | #define SQ_MALLOC(__size) sq_vm_malloc((__size)); 12 | #define SQ_FREE(__ptr,__size) sq_vm_free((__ptr),(__size)); 13 | #define SQ_REALLOC(__ptr,__oldsize,__size) sq_vm_realloc((__ptr),(__oldsize),(__size)); 14 | 15 | //sqvector mini vector class, supports objects by value 16 | template class sqvector 17 | { 18 | public: 19 | sqvector() 20 | { 21 | _vals = NULL; 22 | _size = 0; 23 | _allocated = 0; 24 | } 25 | sqvector(const sqvector& v) 26 | { 27 | copy(v); 28 | } 29 | void copy(const sqvector& v) 30 | { 31 | resize(v._size); 32 | for(SQUnsignedInteger i = 0; i < v._size; i++) { 33 | new ((void *)&_vals[i]) T(v._vals[i]); 34 | } 35 | _size = v._size; 36 | } 37 | ~sqvector() 38 | { 39 | if(_allocated) { 40 | for(SQUnsignedInteger i = 0; i < _size; i++) 41 | _vals[i].~T(); 42 | SQ_FREE(_vals, (_allocated * sizeof(T))); 43 | } 44 | } 45 | void reserve(SQUnsignedInteger newsize) { _realloc(newsize); } 46 | void resize(SQUnsignedInteger newsize, const T& fill = T()) 47 | { 48 | if(newsize > _allocated) 49 | _realloc(newsize); 50 | if(newsize > _size) { 51 | while(_size < newsize) { 52 | new ((void *)&_vals[_size]) T(fill); 53 | _size++; 54 | } 55 | } 56 | else{ 57 | for(SQUnsignedInteger i = newsize; i < _size; i++) { 58 | _vals[i].~T(); 59 | } 60 | _size = newsize; 61 | } 62 | } 63 | void shrinktofit() { if(_size > 4) { _realloc(_size); } } 64 | T& top() const { return _vals[_size - 1]; } 65 | inline SQUnsignedInteger size() const { return _size; } 66 | bool empty() const { return (_size <= 0); } 67 | inline T &push_back(const T& val = T()) 68 | { 69 | if(_allocated <= _size) 70 | _realloc(_size * 2); 71 | return *(new ((void *)&_vals[_size++]) T(val)); 72 | } 73 | inline void pop_back() 74 | { 75 | _size--; _vals[_size].~T(); 76 | } 77 | void insert(SQUnsignedInteger idx, const T& val) 78 | { 79 | resize(_size + 1); 80 | for(SQUnsignedInteger i = _size - 1; i > idx; i--) { 81 | _vals[i] = _vals[i - 1]; 82 | } 83 | _vals[idx] = val; 84 | } 85 | void remove(SQUnsignedInteger idx) 86 | { 87 | _vals[idx].~T(); 88 | if(idx < (_size - 1)) { 89 | memmove(&_vals[idx], &_vals[idx+1], sizeof(T) * (_size - idx - 1)); 90 | } 91 | _size--; 92 | } 93 | SQUnsignedInteger capacity() { return _allocated; } 94 | inline T &back() const { return _vals[_size - 1]; } 95 | inline T& operator[](SQUnsignedInteger pos) const{ return _vals[pos]; } 96 | T* _vals; 97 | private: 98 | void _realloc(SQUnsignedInteger newsize) 99 | { 100 | newsize = (newsize > 0)?newsize:4; 101 | _vals = (T*)SQ_REALLOC(_vals, _allocated * sizeof(T), newsize * sizeof(T)); 102 | _allocated = newsize; 103 | } 104 | SQUnsignedInteger _size; 105 | SQUnsignedInteger _allocated; 106 | }; 107 | 108 | #endif //_SQUTILS_H_ 109 | -------------------------------------------------------------------------------- /src/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /src/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "safetyhook.hpp" 4 | #include "TypeTraits.h" 5 | using namespace StdExt; 6 | #include "Zydis/Zydis.h" 7 | 8 | #define WIN32_LEAN_AND_MEAN 9 | #define NOMINMAX 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #undef Yield 37 | #undef GetObject 38 | #undef LoadImage 39 | 40 | #include "resource.h" 41 | 42 | #include "sqpcheader.h" 43 | #include "sqcompiler.h" 44 | #include "sqvm.h" 45 | #include "sqarray.h" 46 | #include "sqtable.h" 47 | #include "sqclass.h" 48 | #include "sqclosure.h" 49 | #include "sqfuncproto.h" 50 | #include "squserdata.h" 51 | #include "sqstring.h" 52 | #include "sqstdstring.h" 53 | 54 | #include "sqrat.h" 55 | 56 | #include "inipp.h" 57 | #include "spdlog.h" 58 | #include "async.h" 59 | #include "spdlog/sinks/basic_file_sink.h" 60 | #include "spdlog/sinks/stdout_sinks.h" 61 | #include "spdlog/sinks/wincolor_sink.h" 62 | -------------------------------------------------------------------------------- /src/versionchecker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "resource.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class LatestVersionChecker 9 | { 10 | public: 11 | explicit LatestVersionChecker(const std::filesystem::path& cacheFile = FIX_NAME "_version_cache.txt"); 12 | 13 | bool checkForUpdates(); 14 | 15 | private: 16 | std::filesystem::path m_cacheFile; 17 | 18 | #if defined(PRIMARY_REPO_URL) || defined(FALLBACK_REPO_URL) 19 | 20 | struct RepoInfo 21 | { 22 | std::wstring apiHost; 23 | std::wstring apiPath; 24 | std::string displayName; 25 | }; 26 | 27 | bool loadCache(std::string& cachedLatest, std::string& warnedVersion, bool& cacheIsFresh); 28 | void saveCache(const std::string& latestVersion, const std::string& warnedVersion); 29 | bool queryLatestVersion(const RepoInfo& repoInfo, std::string& latestVersion); 30 | std::wstring buildUserAgent() const; 31 | RepoInfo parseRepoUrl(const std::string& url) const; 32 | 33 | static int compareSemVer(const std::string& a, const std::string& b); 34 | static std::string currentTimeISO8601(); 35 | static std::chrono::system_clock::time_point parseISO8601(const std::string& timeStr); 36 | static constexpr int iCacheTTLHours = 24; // Cache TTL in hours 37 | 38 | #endif 39 | }; 40 | -------------------------------------------------------------------------------- /src/warning_background_shuffle.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "warning_background_shuffle.hpp" 3 | 4 | #include "m2utils.h" 5 | 6 | 7 | void BackgroundShuffleWarning::Check() 8 | { 9 | if (M2Utils::IsSteamOS()) 10 | { 11 | return; 12 | } 13 | HKEY hKey; 14 | DWORD value = 0; 15 | DWORD size = sizeof(value); 16 | 17 | if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Wallpapers", 0, KEY_READ, &hKey) != ERROR_SUCCESS) 18 | { 19 | return; // key doesn't exist, bail 20 | } 21 | 22 | LSTATUS status = RegQueryValueExW(hKey, L"BackgroundType", nullptr, nullptr, reinterpret_cast(&value), &size); 23 | RegCloseKey(hKey); 24 | 25 | if (status == ERROR_SUCCESS && value > 1) 26 | { 27 | const char* message = 28 | "Warning:\n\n" 29 | "Having Windows wallpaper set to Slideshow / Window Spotlight mode is known to cause stuttering while in DirectX games.\n" 30 | "\n" 31 | "If you experience intermittent stuttering, change your wallpaper to a static picture in your personalization settings."; 32 | 33 | MessageBoxA(nullptr, message, "Performance Warning", MB_ICONWARNING | MB_OK); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/warning_background_shuffle.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace BackgroundShuffleWarning 4 | { 5 | void Check(); 6 | } 7 | --------------------------------------------------------------------------------