├── .gitattributes ├── .gitignore ├── DarkSoulsScripting.sln ├── DarkSoulsScripting ├── Chr.cs ├── ChrAIController.cs ├── ChrAnimInstance.cs ├── ChrAsm.cs ├── ChrController.cs ├── ChrDbg.cs ├── ChrFollowCam.cs ├── ChrMovementCtrl.cs ├── ChrSlot.cs ├── ChrTransform.cs ├── ChrUNK1.cs ├── CodeHookTypes │ ├── CodeHookBase.cs │ └── Reg32Recorder.cs ├── DarkSoulsScripting.csproj ├── Enemy.cs ├── EnemyAIController.cs ├── EnemyController.cs ├── EnemyMovementCtrl.cs ├── Extra │ ├── Dbg.cs │ ├── DebugUI │ │ ├── InspectGUI.xaml │ │ ├── InspectGUI.xaml.cs │ │ └── WpfPropertyGrid.cs │ └── Utils.cs ├── Functions │ ├── ExtraFuncs.cs │ ├── FuncAddress.cs │ ├── IngameFuncs.Unmapped.cs │ └── IngameFuncs.cs ├── Game.cs ├── GameOptions.cs ├── GameStruct.cs ├── GameTendency.cs ├── Global.cs ├── Injection │ ├── DLL │ │ └── Kernel32.cs │ ├── DSAsmCaller.cs │ ├── Kernel.cs │ ├── PSAPI.cs │ └── Structures │ │ ├── DarkSoulsVersion.cs │ │ ├── MoveableAddressOffset.cs │ │ ├── MutatableDword.cs │ │ ├── SafeDarkSoulsHandle.cs │ │ ├── SafeMarshalledHandle.cs │ │ ├── SafeRemoteHandle.cs │ │ └── SafeRemoteThreadHandle.cs ├── MSB.cs ├── MSBEntry.cs ├── Map.cs ├── MapEntry.cs ├── Misc.cs ├── Player.cs ├── PlayerController.cs ├── PlayerMovementCtrl.cs ├── PlayerStats.cs ├── Properties │ └── AssemblyInfo.cs ├── WorldChrMan.cs ├── WorldState.cs ├── X86AssemblyLib │ ├── Arithmetic │ │ ├── X86Writer.Add.cs │ │ ├── X86Writer.AddWithCarry.cs │ │ ├── X86Writer.Decrement.cs │ │ ├── X86Writer.Division.cs │ │ ├── X86Writer.Increment.cs │ │ ├── X86Writer.Multiply.cs │ │ ├── X86Writer.Negate.cs │ │ ├── X86Writer.Not.cs │ │ └── X86Writer.Subtract.cs │ ├── COPYING │ ├── ControlFlow │ │ ├── X86Writer.Call.cs │ │ ├── X86Writer.Jump.cs │ │ └── X86Writer.Patch.cs │ ├── DataTypes │ │ ├── X86Address.cs │ │ ├── X86ConditionCode.cs │ │ ├── X86Label.cs │ │ ├── X86Register16.cs │ │ ├── X86Register32.cs │ │ ├── X86Register8.cs │ │ └── X86ShiftOpCode.cs │ ├── General │ │ ├── X86Writer.Compare.cs │ │ └── X86Writer.Move.cs │ ├── IO │ │ ├── X86Writer.In.cs │ │ └── X86Writer.Out.cs │ ├── Interlock │ │ └── X86Writer.CompareExchange.cs │ ├── Logical │ │ ├── X86Writer.And.cs │ │ ├── X86Writer.Or.cs │ │ └── X86Writer.Xor.cs │ ├── Prefixes │ │ ├── X86Writer.Lock.cs │ │ └── X86Writer.Repeat.cs │ ├── Shift │ │ ├── X86Writer.ShiftLeft.cs │ │ └── X86Writer.ShiftRight.cs │ ├── Stack │ │ ├── X86Writer.Pop.cs │ │ └── X86Writer.Push.cs │ └── X86Writer.cs ├── XInput │ ├── Button.cs │ ├── ButtonState.cs │ ├── Gamepad.PS3.cs │ ├── Gamepad.PS4.cs │ ├── Gamepad.Xbox360.cs │ ├── Gamepad.XboxOne.cs │ ├── GamepadBase.cs │ └── GamepadState.cs └── [General] │ ├── CodeHooks.cs │ ├── Hook.cs │ ├── Memloc.cs │ ├── ModuleInitializer.cs │ ├── Pointers.cs │ └── [General Enums].cs ├── README.md ├── Reference - Dark Souls II RTTI.txt ├── ScriptTester ├── DarkSoulsDebugTesting.py ├── DarkSoulsScriptingBundle │ └── __init__.py ├── Example.py ├── QUICK_TEST.py └── ScriptTester.pyproj └── Tools └── InjectModuleInitializer.exe /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | *.vcxproj.filters 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # .NET Core 47 | project.lock.json 48 | project.fragment.lock.json 49 | artifacts/ 50 | **/Properties/launchSettings.json 51 | 52 | *_i.c 53 | *_p.c 54 | *_i.h 55 | *.ilk 56 | *.meta 57 | *.obj 58 | *.pch 59 | *.pdb 60 | *.pgc 61 | *.pgd 62 | *.rsp 63 | *.sbr 64 | *.tlb 65 | *.tli 66 | *.tlh 67 | *.tmp 68 | *.tmp_proj 69 | *.log 70 | *.vspscc 71 | *.vssscc 72 | .builds 73 | *.pidb 74 | *.svclog 75 | *.scc 76 | 77 | # Chutzpah Test files 78 | _Chutzpah* 79 | 80 | # Visual C++ cache files 81 | ipch/ 82 | *.aps 83 | *.ncb 84 | *.opendb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | *.VC.db 89 | *.VC.VC.opendb 90 | 91 | # Visual Studio profiler 92 | *.psess 93 | *.vsp 94 | *.vspx 95 | *.sap 96 | 97 | # TFS 2012 Local Workspace 98 | $tf/ 99 | 100 | # Guidance Automation Toolkit 101 | *.gpState 102 | 103 | # ReSharper is a .NET coding add-in 104 | _ReSharper*/ 105 | *.[Rr]e[Ss]harper 106 | *.DotSettings.user 107 | 108 | # JustCode is a .NET coding add-in 109 | .JustCode 110 | 111 | # TeamCity is a build add-in 112 | _TeamCity* 113 | 114 | # DotCover is a Code Coverage Tool 115 | *.dotCover 116 | 117 | # Visual Studio code coverage results 118 | *.coverage 119 | *.coveragexml 120 | 121 | # NCrunch 122 | _NCrunch_* 123 | .*crunch*.local.xml 124 | nCrunchTemp_* 125 | 126 | # MightyMoose 127 | *.mm.* 128 | AutoTest.Net/ 129 | 130 | # Web workbench (sass) 131 | .sass-cache/ 132 | 133 | # Installshield output folder 134 | [Ee]xpress/ 135 | 136 | # DocProject is a documentation generator add-in 137 | DocProject/buildhelp/ 138 | DocProject/Help/*.HxT 139 | DocProject/Help/*.HxC 140 | DocProject/Help/*.hhc 141 | DocProject/Help/*.hhk 142 | DocProject/Help/*.hhp 143 | DocProject/Help/Html2 144 | DocProject/Help/html 145 | 146 | # Click-Once directory 147 | publish/ 148 | 149 | # Publish Web Output 150 | *.[Pp]ublish.xml 151 | *.azurePubxml 152 | # TODO: Comment the next line if you want to checkin your web deploy settings 153 | # but database connection strings (with potential passwords) will be unencrypted 154 | *.pubxml 155 | *.publishproj 156 | 157 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 158 | # checkin your Azure Web App publish settings, but sensitive information contained 159 | # in these scripts will be unencrypted 160 | PublishScripts/ 161 | 162 | # NuGet Packages 163 | *.nupkg 164 | # The packages folder can be ignored because of Package Restore 165 | **/packages/* 166 | # except build/, which is used as an MSBuild target. 167 | !**/packages/build/ 168 | # Uncomment if necessary however generally it will be regenerated when needed 169 | #!**/packages/repositories.config 170 | # NuGet v3's project.json files produces more ignoreable files 171 | *.nuget.props 172 | *.nuget.targets 173 | 174 | # Microsoft Azure Build Output 175 | csx/ 176 | *.build.csdef 177 | 178 | # Microsoft Azure Emulator 179 | ecf/ 180 | rcf/ 181 | 182 | # Windows Store app package directories and files 183 | AppPackages/ 184 | BundleArtifacts/ 185 | Package.StoreAssociation.xml 186 | _pkginfo.txt 187 | 188 | # Visual Studio cache files 189 | # files ending in .cache can be ignored 190 | *.[Cc]ache 191 | # but keep track of directories ending in .cache 192 | !*.[Cc]ache/ 193 | 194 | # Others 195 | ClientBin/ 196 | ~$* 197 | *~ 198 | *.dbmdl 199 | *.dbproj.schemaview 200 | *.jfm 201 | *.pfx 202 | *.publishsettings 203 | node_modules/ 204 | orleans.codegen.cs 205 | 206 | # Since there are multiple workflows, uncomment next line to ignore bower_components 207 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 208 | #bower_components/ 209 | 210 | # RIA/Silverlight projects 211 | Generated_Code/ 212 | 213 | # Backup & report files from converting an old project file 214 | # to a newer Visual Studio version. Backup files are not needed, 215 | # because we have git ;-) 216 | _UpgradeReport_Files/ 217 | Backup*/ 218 | UpgradeLog*.XML 219 | UpgradeLog*.htm 220 | 221 | # SQL Server files 222 | *.mdf 223 | *.ldf 224 | 225 | # Business Intelligence projects 226 | *.rdl.data 227 | *.bim.layout 228 | *.bim_*.settings 229 | 230 | # Microsoft Fakes 231 | FakesAssemblies/ 232 | 233 | # GhostDoc plugin setting file 234 | *.GhostDoc.xml 235 | 236 | # Node.js Tools for Visual Studio 237 | .ntvs_analysis.dat 238 | 239 | # Visual Studio 6 build log 240 | *.plg 241 | 242 | # Visual Studio 6 workspace options file 243 | *.opt 244 | 245 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 246 | *.vbw 247 | 248 | # Visual Studio LightSwitch build output 249 | **/*.HTMLClient/GeneratedArtifacts 250 | **/*.DesktopClient/GeneratedArtifacts 251 | **/*.DesktopClient/ModelManifest.xml 252 | **/*.Server/GeneratedArtifacts 253 | **/*.Server/ModelManifest.xml 254 | _Pvt_Extensions 255 | 256 | # Paket dependency manager 257 | .paket/paket.exe 258 | paket-files/ 259 | 260 | # FAKE - F# Make 261 | .fake/ 262 | 263 | # JetBrains Rider 264 | .idea/ 265 | *.sln.iml 266 | 267 | # CodeRush 268 | .cr/ 269 | 270 | # Python Tools for Visual Studio (PTVS) 271 | __pycache__/ 272 | *.pyc 273 | 274 | # Cake - Uncomment if you are using it 275 | # tools/ -------------------------------------------------------------------------------- /DarkSoulsScripting.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.16 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DarkSoulsScripting", "DarkSoulsScripting\DarkSoulsScripting.csproj", "{4EEF2FFB-9E6F-490E-B8D0-19C10451B461}" 7 | EndProject 8 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "ScriptTester", "ScriptTester\ScriptTester.pyproj", "{FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|ARM = Debug|ARM 14 | Debug|x64 = Debug|x64 15 | Debug|x86 = Debug|x86 16 | DebugKopiLua|Any CPU = DebugKopiLua|Any CPU 17 | DebugKopiLua|ARM = DebugKopiLua|ARM 18 | DebugKopiLua|x64 = DebugKopiLua|x64 19 | DebugKopiLua|x86 = DebugKopiLua|x86 20 | DebugWin|Any CPU = DebugWin|Any CPU 21 | DebugWin|ARM = DebugWin|ARM 22 | DebugWin|x64 = DebugWin|x64 23 | DebugWin|x86 = DebugWin|x86 24 | Release|Any CPU = Release|Any CPU 25 | Release|ARM = Release|ARM 26 | Release|x64 = Release|x64 27 | Release|x86 = Release|x86 28 | ReleaseKopiLua|Any CPU = ReleaseKopiLua|Any CPU 29 | ReleaseKopiLua|ARM = ReleaseKopiLua|ARM 30 | ReleaseKopiLua|x64 = ReleaseKopiLua|x64 31 | ReleaseKopiLua|x86 = ReleaseKopiLua|x86 32 | ReleaseWin|Any CPU = ReleaseWin|Any CPU 33 | ReleaseWin|ARM = ReleaseWin|ARM 34 | ReleaseWin|x64 = ReleaseWin|x64 35 | ReleaseWin|x86 = ReleaseWin|x86 36 | EndGlobalSection 37 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 38 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Debug|ARM.ActiveCfg = Debug|Any CPU 41 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Debug|ARM.Build.0 = Debug|Any CPU 42 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Debug|x64.ActiveCfg = Debug|Any CPU 43 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Debug|x64.Build.0 = Debug|Any CPU 44 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Debug|x86.ActiveCfg = Debug|Any CPU 45 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Debug|x86.Build.0 = Debug|Any CPU 46 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugKopiLua|Any CPU.ActiveCfg = Debug|Any CPU 47 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugKopiLua|Any CPU.Build.0 = Debug|Any CPU 48 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugKopiLua|ARM.ActiveCfg = Debug|Any CPU 49 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugKopiLua|ARM.Build.0 = Debug|Any CPU 50 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugKopiLua|x64.ActiveCfg = Debug|Any CPU 51 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugKopiLua|x64.Build.0 = Debug|Any CPU 52 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugKopiLua|x86.ActiveCfg = Debug|Any CPU 53 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugKopiLua|x86.Build.0 = Debug|Any CPU 54 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugWin|Any CPU.ActiveCfg = Debug|Any CPU 55 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugWin|Any CPU.Build.0 = Debug|Any CPU 56 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugWin|ARM.ActiveCfg = Debug|Any CPU 57 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugWin|ARM.Build.0 = Debug|Any CPU 58 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugWin|x64.ActiveCfg = Debug|Any CPU 59 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugWin|x64.Build.0 = Debug|Any CPU 60 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugWin|x86.ActiveCfg = Debug|Any CPU 61 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.DebugWin|x86.Build.0 = Debug|Any CPU 62 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Release|Any CPU.ActiveCfg = Release|Any CPU 63 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Release|Any CPU.Build.0 = Release|Any CPU 64 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Release|ARM.ActiveCfg = Release|Any CPU 65 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Release|ARM.Build.0 = Release|Any CPU 66 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Release|x64.ActiveCfg = Release|Any CPU 67 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Release|x64.Build.0 = Release|Any CPU 68 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Release|x86.ActiveCfg = Release|Any CPU 69 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.Release|x86.Build.0 = Release|Any CPU 70 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseKopiLua|Any CPU.ActiveCfg = Release|Any CPU 71 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseKopiLua|Any CPU.Build.0 = Release|Any CPU 72 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseKopiLua|ARM.ActiveCfg = Release|Any CPU 73 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseKopiLua|ARM.Build.0 = Release|Any CPU 74 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseKopiLua|x64.ActiveCfg = Release|Any CPU 75 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseKopiLua|x64.Build.0 = Release|Any CPU 76 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseKopiLua|x86.ActiveCfg = Release|Any CPU 77 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseKopiLua|x86.Build.0 = Release|Any CPU 78 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseWin|Any CPU.ActiveCfg = Release|Any CPU 79 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseWin|Any CPU.Build.0 = Release|Any CPU 80 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseWin|ARM.ActiveCfg = Release|Any CPU 81 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseWin|ARM.Build.0 = Release|Any CPU 82 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseWin|x64.ActiveCfg = Release|Any CPU 83 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseWin|x64.Build.0 = Release|Any CPU 84 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseWin|x86.ActiveCfg = Release|Any CPU 85 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461}.ReleaseWin|x86.Build.0 = Release|Any CPU 86 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 87 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.Debug|ARM.ActiveCfg = Debug|Any CPU 88 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.Debug|x64.ActiveCfg = Debug|Any CPU 89 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.Debug|x86.ActiveCfg = Debug|Any CPU 90 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.DebugKopiLua|Any CPU.ActiveCfg = Debug|Any CPU 91 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.DebugKopiLua|ARM.ActiveCfg = Debug|Any CPU 92 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.DebugKopiLua|x64.ActiveCfg = Debug|Any CPU 93 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.DebugKopiLua|x86.ActiveCfg = Debug|Any CPU 94 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.DebugWin|Any CPU.ActiveCfg = Debug|Any CPU 95 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.DebugWin|ARM.ActiveCfg = Debug|Any CPU 96 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.DebugWin|x64.ActiveCfg = Debug|Any CPU 97 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.DebugWin|x86.ActiveCfg = Debug|Any CPU 98 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.Release|Any CPU.ActiveCfg = Release|Any CPU 99 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.Release|ARM.ActiveCfg = Release|Any CPU 100 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.Release|x64.ActiveCfg = Release|Any CPU 101 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.Release|x86.ActiveCfg = Release|Any CPU 102 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.ReleaseKopiLua|Any CPU.ActiveCfg = Release|Any CPU 103 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.ReleaseKopiLua|ARM.ActiveCfg = Release|Any CPU 104 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.ReleaseKopiLua|x64.ActiveCfg = Release|Any CPU 105 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.ReleaseKopiLua|x86.ActiveCfg = Release|Any CPU 106 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.ReleaseWin|Any CPU.ActiveCfg = Release|Any CPU 107 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.ReleaseWin|ARM.ActiveCfg = Release|Any CPU 108 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.ReleaseWin|x64.ActiveCfg = Release|Any CPU 109 | {FC0E26B0-AE42-4BE7-86BF-88BAB8C3090A}.ReleaseWin|x86.ActiveCfg = Release|Any CPU 110 | EndGlobalSection 111 | GlobalSection(SolutionProperties) = preSolution 112 | HideSolutionNode = FALSE 113 | EndGlobalSection 114 | GlobalSection(ExtensibilityGlobals) = postSolution 115 | SolutionGuid = {DBCD9733-E3DB-4D62-8D03-48DF8B0D4B44} 116 | EndGlobalSection 117 | EndGlobal 118 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrAIController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DarkSoulsScripting.Injection; 3 | 4 | namespace DarkSoulsScripting 5 | { 6 | public class ChrAIController : GameStruct 7 | where TChrController : ChrController, new() 8 | where TChrMovementCtrl : ChrMovementCtrl, new() 9 | where TChr : Chr, new() 10 | { 11 | protected override void InitSubStructures() 12 | { 13 | 14 | } 15 | 16 | public int ChrPtr { 17 | get { return Hook.RInt32(Address + 0x14); } 18 | set { Hook.WInt32(Address + 0x14, value); } 19 | } 20 | 21 | public TChr GetChr() => new TChr() { AddressReadFunc = () => ChrPtr }; 22 | 23 | public int AIScript { 24 | get { return Hook.RInt32(Address + 0x78); } 25 | set { Hook.WInt32(Address + 0x78, value); } 26 | } 27 | 28 | public int AnimationID { 29 | get { return Hook.RInt32(Address + 0x9c); } 30 | set { Hook.WInt32(Address + 0x9c, value); } 31 | } 32 | 33 | public int AIScript2 { 34 | get { return Hook.RInt32(Address + 0x80); } 35 | set { Hook.WInt32(Address + 0x80, value); } 36 | } 37 | 38 | public float PosX { 39 | get { return Hook.RFloat(Address + 0x1e0); } 40 | set { Hook.WFloat(Address + 0x1e0, value); } 41 | } 42 | 43 | public float PosY { 44 | get { return Hook.RFloat(Address + 0x1e4); } 45 | set { Hook.WFloat(Address + 0x1e4, value); } 46 | } 47 | 48 | public float PosZ { 49 | get { return Hook.RFloat(Address + 0x1e8); } 50 | set { Hook.WFloat(Address + 0x1e8, value); } 51 | } 52 | 53 | public float RotZ { 54 | get { return Hook.RFloat(Address + 0x1e8); } 55 | set { Hook.WFloat(Address + 0x1e8, value); } 56 | } 57 | 58 | public float RotY { 59 | get { return Hook.RFloat(Address + 0x1f0); } 60 | set { Hook.WFloat(Address + 0x1f0, value); } 61 | } 62 | 63 | public float RotX { 64 | get { return Hook.RFloat(Address + 0x1f4); } 65 | set { Hook.WFloat(Address + 0x1f4, value); } 66 | } 67 | 68 | public int AnimationID2 { 69 | get { return Hook.RInt32(Address + 0x208); } 70 | set { Hook.WInt32(Address + 0x208, value); } 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrAnimInstance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public class ChrAnimInstance : GameStruct 11 | { 12 | protected override void InitSubStructures() 13 | { 14 | 15 | } 16 | 17 | public float ElapsedTime 18 | { 19 | get { return RFloat(Address + 0x8); } 20 | set { WFloat(Address + 0x8, value); } 21 | } 22 | 23 | public float Weight 24 | { 25 | get { return RFloat(Address + 0x3C); } 26 | set { WFloat(Address + 0x3C, value); } 27 | } 28 | 29 | public float Speed 30 | { 31 | get { return RFloat(Address + 0x40); } 32 | set { WFloat(Address + 0x40, value); } 33 | } 34 | 35 | public int LoopCount 36 | { 37 | get { return RInt32(Address + 0x44); } 38 | set { WInt32(Address + 0x44, value); } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrAsm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DarkSoulsScripting 8 | { 9 | //TODO: Move all Equip* from PlayerStats to here with names matching those in debug menu 10 | public class ChrAsm : GameStruct 11 | { 12 | protected override void InitSubStructures() 13 | { 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DarkSoulsScripting.Injection; 3 | 4 | namespace DarkSoulsScripting 5 | { 6 | 7 | public class ChrController : GameStruct 8 | { 9 | 10 | protected override void InitSubStructures() 11 | { 12 | 13 | } 14 | 15 | public float MoveX { 16 | get { return Hook.RFloat(Address + 0x10); } 17 | set { Hook.WFloat(Address + 0x10, value); } 18 | } 19 | 20 | public float MoveY { 21 | get { return Hook.RFloat(Address + 0x18); } 22 | set { Hook.WFloat(Address + 0x18, value); } 23 | } 24 | 25 | public float CamRotSpeedH { 26 | get { return Hook.RFloat(Address + 0x50); } 27 | set { Hook.WFloat(Address + 0x50, value); } 28 | } 29 | 30 | public float CamRotSpeedV { 31 | get { return Hook.RFloat(Address + 0x54); } 32 | set { Hook.WFloat(Address + 0x54, value); } 33 | } 34 | 35 | public float CamRotH { 36 | get { return Hook.RFloat(Address + 0x60); } 37 | set { Hook.WFloat(Address + 0x60, value); } 38 | } 39 | 40 | public float CamRotV { 41 | get { return Hook.RFloat(Address + 0x64); } 42 | set { Hook.WFloat(Address + 0x64, value); } 43 | } 44 | 45 | public bool R1Held_Sometimes { 46 | get { return Hook.RBool(Address + 0x10); } 47 | set { Hook.WBool(Address + 0x10, value); } 48 | } 49 | 50 | public bool L2OrR1Held_Sometimes { 51 | get { return Hook.RBool(Address + 0x85); } 52 | set { Hook.WBool(Address + 0x85, value); } 53 | } 54 | 55 | public bool RMouseHeld { 56 | get { return Hook.RBool(Address + 0x89); } 57 | set { Hook.WBool(Address + 0x89, value); } 58 | } 59 | 60 | public bool R1Held { 61 | get { return Hook.RBool(Address + 0x8b); } 62 | set { Hook.WBool(Address + 0x8b, value); } 63 | } 64 | 65 | public bool XHeld { 66 | get { return Hook.RBool(Address + 0x92); } 67 | set { Hook.WBool(Address + 0x92, value); } 68 | } 69 | 70 | public bool L1Held { 71 | get { return Hook.RBool(Address + 0x97); } 72 | set { Hook.WBool(Address + 0x97, value); } 73 | } 74 | 75 | public bool L2OrTabHeld { 76 | get { return Hook.RBool(Address + 0x98); } 77 | set { Hook.WBool(Address + 0x98, value); } 78 | } 79 | 80 | public bool L1Held2 { 81 | get { return Hook.RBool(Address + 0xb7); } 82 | set { Hook.WBool(Address + 0xb7, value); } 83 | } 84 | 85 | public bool R1HeldOrCircleTapped { 86 | get { return Hook.RBool(Address + 0xb9); } 87 | set { Hook.WBool(Address + 0xb9, value); } 88 | } 89 | 90 | public bool RMouseOrR2Held { 91 | get { return Hook.RBool(Address + 0xbe); } 92 | set { Hook.WBool(Address + 0xbe, value); } 93 | } 94 | 95 | public bool R1OrLMouseHeld { 96 | get { return Hook.RBool(Address + 0xc0); } 97 | set { Hook.WBool(Address + 0xc0, value); } 98 | } 99 | 100 | public bool L2Held { 101 | get { return Hook.RBool(Address + 0xc2); } 102 | set { Hook.WBool(Address + 0xc2, value); } 103 | } 104 | 105 | public bool CircleTapped { 106 | get { return Hook.RBool(Address + 0xc2); } 107 | set { Hook.WBool(Address + 0xc2, value); } 108 | } 109 | 110 | public bool XHeld2 { 111 | get { return Hook.RBool(Address + 0xc7); } 112 | set { Hook.WBool(Address + 0xc7, value); } 113 | } 114 | 115 | public bool L1Held3 { 116 | get { return Hook.RBool(Address + 0xcc); } 117 | set { Hook.WBool(Address + 0xcc, value); } 118 | } 119 | 120 | public bool L2Held2 { 121 | get { return Hook.RBool(Address + 0xcd); } 122 | set { Hook.WBool(Address + 0xcd, value); } 123 | } 124 | 125 | public bool L1Held4 { 126 | get { return Hook.RBool(Address + 0xec); } 127 | set { Hook.WBool(Address + 0xec, value); } 128 | } 129 | 130 | public float SecondsR1Held { 131 | get { return Hook.RFloat(Address + 0xf0); } 132 | set { Hook.WFloat(Address + 0xf0, value); } 133 | } 134 | 135 | public float SecondsGuarding { 136 | get { return Hook.RFloat(Address + 0xf4); } 137 | set { Hook.WFloat(Address + 0xf4, value); } 138 | } 139 | 140 | public float SecondsR2Held { 141 | get { return Hook.RFloat(Address + 0x104); } 142 | set { Hook.WFloat(Address + 0x104, value); } 143 | } 144 | 145 | public float SecondsR1Held2 { 146 | get { return Hook.RFloat(Address + 0x10c); } 147 | set { Hook.WFloat(Address + 0x10c, value); } 148 | } 149 | 150 | public float SecondsL1Held { 151 | get { return Hook.RFloat(Address + 0x13c); } 152 | set { Hook.WFloat(Address + 0x13c, value); } 153 | } 154 | 155 | public float SecondsGuarding2 { 156 | get { return Hook.RFloat(Address + 0x144); } 157 | set { Hook.WFloat(Address + 0x144, value); } 158 | } 159 | 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrDbg.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public static class ChrDbg 11 | { 12 | public static bool AllNoMagicQtyConsume 13 | { 14 | get { return RBool(0x1376EE7); } 15 | set { WBool(0x1376EE7, value); } 16 | } 17 | 18 | public static bool PlayerNoDead 19 | { 20 | get { return RBool(0x13784D2); } 21 | set { WBool(0x13784D2, value); } 22 | } 23 | 24 | public static bool PlayerExterminate 25 | { 26 | get { return RBool(0x13784D3); } 27 | set { WBool(0x13784D3, value); } 28 | } 29 | 30 | public static bool AllNoStaminaConsume 31 | { 32 | get { return RBool(0x13784E4); } 33 | set { WBool(0x13784E4, value); } 34 | } 35 | 36 | public static bool AllNoMPConsume 37 | { 38 | get { return RBool(0x13784E5); } 39 | set { WBool(0x13784E5, value); } 40 | } 41 | 42 | public static bool AllNoArrowConsume 43 | { 44 | get { return RBool(0x13784E6); } 45 | set { WBool(0x13784E6, value); } 46 | } 47 | 48 | public static bool PlayerHide 49 | { 50 | get { return RBool(0x13784E7); } 51 | set { WBool(0x13784E7, value); } 52 | } 53 | 54 | public static bool PlayerSilence 55 | { 56 | get { return RBool(0x13784E8); } 57 | set { WBool(0x13784E8, value); } 58 | } 59 | 60 | public static bool AllNoDead 61 | { 62 | get { return RBool(0x13784E9); } 63 | set { WBool(0x13784E9, value); } 64 | } 65 | 66 | public static bool AllNoDamage 67 | { 68 | get { return RBool(0x13784EA); } 69 | set { WBool(0x13784EA, value); } 70 | } 71 | 72 | public static bool AllNoHit 73 | { 74 | get { return RBool(0x13784EB); } 75 | set { WBool(0x13784EB, value); } 76 | } 77 | 78 | public static bool AllNoAttack 79 | { 80 | get { return RBool(0x13784EC); } 81 | set { WBool(0x13784EC, value); } 82 | } 83 | 84 | public static bool AllNoMove 85 | { 86 | get { return RBool(0x13784ED); } 87 | set { WBool(0x13784ED, value); } 88 | } 89 | 90 | public static bool AllNoUpdateAI 91 | { 92 | get { return RBool(0x13784EE); } 93 | set { WBool(0x13784EE, value); } 94 | } 95 | 96 | public static bool DisplayMiniCompass 97 | { 98 | get { return RBool(0x137851B); } 99 | set { WBool(0x137851B, value); } 100 | } 101 | 102 | public static bool DisplayHeightMarker 103 | { 104 | get { return RBool(0x1378524); } 105 | set { WBool(0x1378524, value); } 106 | } 107 | 108 | public static bool DisplayCompass 109 | { 110 | get { return RBool(0x1378525); } 111 | set { WBool(0x1378525, value); } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrFollowCam.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public static class ChrFollowCam 11 | { 12 | public static int Address => RInt32(RInt32(RInt32(0x137D6DC) + 0x3C) + 0x60); 13 | 14 | public static float FovY 15 | { 16 | get => RFloat(Address + 0x50); 17 | set => WFloat(Address + 0x50, value); 18 | } 19 | 20 | public static float DrawDistance 21 | { 22 | get => RFloat(Address + 0x5C); 23 | set => WFloat(Address + 0x5C, value); 24 | } 25 | 26 | public static float RotX 27 | { 28 | get => RFloat(Address + 0xE0); 29 | set => WFloat(Address + 0xE0, value); 30 | } 31 | 32 | public static float RotY 33 | { 34 | get => RFloat(Address + 0xE4); 35 | set => WFloat(Address + 0xE4, value); 36 | } 37 | 38 | public static float RotZ 39 | { 40 | get => RFloat(Address + 0xE8); 41 | set => WFloat(Address + 0xE8, value); 42 | } 43 | 44 | public static float PosX 45 | { 46 | get => RFloat(Address + 0x100); 47 | set => WFloat(Address + 0x100, value); 48 | } 49 | 50 | public static float PosY 51 | { 52 | get => RFloat(Address + 0x104); 53 | set => WFloat(Address + 0x104, value); 54 | } 55 | 56 | public static float PosZ 57 | { 58 | get => RFloat(Address + 0x108); 59 | set => WFloat(Address + 0x108, value); 60 | } 61 | 62 | public static float CamRotX 63 | { 64 | get => RFloat(Address + 0x140); 65 | set => WFloat(Address + 0x140, value); 66 | } 67 | 68 | //TODO: CONFIRM 69 | public static float CamRotY 70 | { 71 | get => RFloat(Address + 0x144); 72 | set => WFloat(Address + 0x144, value); 73 | } 74 | 75 | //TODO: CONFIRM 76 | public static float CamRotZ 77 | { 78 | get => RFloat(Address + 0x148); 79 | set => WFloat(Address + 0x148, value); 80 | } 81 | 82 | public static float TargetRotX 83 | { 84 | get => RFloat(Address + 0x150); 85 | set => WFloat(Address + 0x150, value); 86 | } 87 | 88 | //TODO: CONFIRM 89 | public static float TargetRotY 90 | { 91 | get => RFloat(Address + 0x154); 92 | set => WFloat(Address + 0x154, value); 93 | } 94 | 95 | //TODO: CONFIRM 96 | public static float TargetRotZ 97 | { 98 | get => RFloat(Address + 0x158); 99 | set => WFloat(Address + 0x158, value); 100 | } 101 | 102 | /* 103 | +0x0204 float X RotSpeedMin 104 | +0x0208 float Y RotSpeedMin 105 | +0x020C float X RotSpeedMax 106 | +0x0210 float Y RotSpeedMax 107 | +0x021C float X RotHiSpeedMin 108 | +0x0220 float Y RotHiSpeedMin 109 | +0x0224 float X RotHiSpeedMax 110 | +0x0228 float Y RotHiSpeedMax 111 | 112 | */ 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrMovementCtrl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public class ChrMovementCtrl : GameStruct 11 | where TChrController : ChrController, new() 12 | { 13 | public ChrTransform Transform { get; private set; } = null; 14 | public TChrController Controller { get; private set; } = null; 15 | public PlayerController DebugPlayerController { get; private set; } = null; 16 | 17 | protected override void InitSubStructures() 18 | { 19 | Transform = new ChrTransform() { AddressReadFunc = () => TransformPtr }; 20 | Controller = new TChrController() { AddressReadFunc = () => ControllerPtr }; 21 | DebugPlayerController = new PlayerController() { AddressReadFunc = () => DebugPlayerControllerPtr }; 22 | } 23 | 24 | public Player GetChrAsPlayer() => new Player() { AddressReadFunc = () => ChrPtr }; 25 | public Enemy GetChrAsEnemy() => new Enemy() { AddressReadFunc = () => ChrPtr }; 26 | 27 | public bool EnableLogic 28 | { 29 | get { return RBit(Address + 0xC0, 7); } 30 | set { WBit(Address + 0xC0, 7, value); } 31 | } 32 | 33 | public bool DisableMapHit 34 | { 35 | get { return RBit(Address + 0xC4, 27); } 36 | set { WBit(Address + 0xC4, 27, value); } 37 | } 38 | 39 | //0x40 flag applied to Address + 0xC6 40 | //public bool DisableCollision 41 | //{ 42 | // get { return GetMapFlagB(ChrMapFlagsB.DisableCollision); } 43 | // set { SetMapFlagB(ChrMapFlagsB.DisableCollision, value); } 44 | //} 45 | 46 | public int ChrPtr 47 | { 48 | get { return RInt32(Address + 0x10); } 49 | set { WInt32(Address + 0x10, value); } 50 | } 51 | 52 | public int ControllerPtr 53 | { 54 | get { return RInt32(Address + 0x54); } 55 | set { WInt32(Address + 0x54, value); } 56 | } 57 | 58 | public int AnimationPtr 59 | { 60 | get { return RInt32(Address + 0x14); } 61 | set { WInt32(Address + 0x14, value); } 62 | } 63 | 64 | public List GetAnimInstances() 65 | { 66 | if (AnimationPtr < Hook.DARKSOULS.SafeBaseMemoryOffset) 67 | return new List(); 68 | 69 | int animStructThing = RInt32(AnimationPtr + 0xC); 70 | int startAddr = RInt32(animStructThing + 0x10); 71 | int entryCount = RInt32(animStructThing + 0x14); 72 | 73 | var result = new List(); 74 | 75 | for (int i = 0; i < entryCount; i++) 76 | { 77 | int entryAddr = RInt32(startAddr + (i * 4)); 78 | result.Add(new ChrAnimInstance() { AddressReadFunc = () => entryAddr }); 79 | } 80 | 81 | return result; 82 | } 83 | 84 | public float AnimationSpeed 85 | { 86 | get { return RFloat(AnimationPtr + 0x64); } 87 | set { WFloat(AnimationPtr + 0x64, value); } 88 | } 89 | 90 | public bool AnimDbgDrawSkeleton 91 | { 92 | get { return RBool(AnimationPtr + 0x68); } 93 | set { WBool(AnimationPtr + 0x68, value); } 94 | } 95 | 96 | public bool AnimDbgDrawBoneName 97 | { 98 | get { return RBool(AnimationPtr + 0x69); } 99 | set { WBool(AnimationPtr + 0x69, value); } 100 | } 101 | 102 | public bool AnimDbgDrawExtractMotion 103 | { 104 | get { return RBool(AnimationPtr + 0x81); } 105 | set { WBool(AnimationPtr + 0x81, value); } 106 | } 107 | 108 | public bool AnimDbgSlotLog 109 | { 110 | get { return RBool(AnimationPtr + 0x82); } 111 | set { WBool(AnimationPtr + 0x82, value); } 112 | } 113 | 114 | public int TransformPtr 115 | { 116 | get { return RInt32(Address + 0x1c); } 117 | set { WInt32(Address + 0x1c, value); } 118 | } 119 | 120 | public bool WarpActivate 121 | { 122 | get { return RBool(Address + 0xC8); } 123 | set { WBool(Address + 0xC8, value); } 124 | } 125 | 126 | public float WarpX 127 | { 128 | get { return RFloat(Address + 0xD0); } 129 | set { WFloat(Address + 0xD0, value); } 130 | } 131 | 132 | public float WarpY 133 | { 134 | get { return RFloat(Address + 0xD4); } 135 | set { WFloat(Address + 0xD4, value); } 136 | } 137 | 138 | public float WarpZ 139 | { 140 | get { return RFloat(Address + 0xD8); } 141 | set { WFloat(Address + 0xD8, value); } 142 | } 143 | 144 | //TODO: Confirm warp x and z rotation exist (I just guessed based on the pattern: [ pos x, pos y, pos y, {???}, rot y, {???} ] 145 | 146 | public float WarpRX 147 | { 148 | get { return RFloat(Address + 0xE0); } 149 | set { WFloat(Address + 0xE0, value); } 150 | } 151 | 152 | public float WarpRY 153 | { 154 | get { return RFloat(Address + 0xE4); } 155 | set { WFloat(Address + 0xE4, value); } 156 | } 157 | 158 | public float WarpRZ 159 | { 160 | get { return RFloat(Address + 0xE8); } 161 | set { WFloat(Address + 0xE8, value); } 162 | } 163 | 164 | public float WarpHeading 165 | { 166 | get { return (float)((RFloat(Address + 0xE4) / Math.PI * 180) + 180); } 167 | set { WFloat(Address + 0xE4, (float)(value * Math.PI / 180) - (float)Math.PI); } 168 | } 169 | 170 | public int DebugPlayerControllerPtr { 171 | get { return Hook.RInt32(Address + 0x244); } 172 | set { Hook.WInt32(Address + 0x244, value); } 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrSlot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DarkSoulsScripting.Injection; 3 | 4 | namespace DarkSoulsScripting 5 | { 6 | public class ChrSlot : GameStruct 7 | { 8 | public ChrTransform Transform = null; 9 | 10 | protected override void InitSubStructures() 11 | { 12 | Transform = new ChrTransform() { AddressReadFunc = () => TransformPtr }; 13 | } 14 | 15 | public int ChrPtr { 16 | get { return Hook.RInt32(Address + 0x0); } 17 | set { Hook.WInt32(Address + 0x0, value); } 18 | } 19 | 20 | public Enemy GetChrAsEnemy() 21 | { 22 | if (ChrPtr < Hook.DARKSOULS.SafeBaseMemoryOffset) 23 | return null; 24 | 25 | return new Enemy() { AddressReadFunc = () => ChrPtr }; 26 | } 27 | 28 | public Player GetChrAsPlayer() 29 | { 30 | if (ChrPtr < Hook.DARKSOULS.SafeBaseMemoryOffset) 31 | return null; 32 | 33 | return new Player() { AddressReadFunc = () => ChrPtr }; 34 | } 35 | 36 | public int CloneValue { 37 | get { return Hook.RInt32(Address + 0x8); } 38 | set { Hook.WInt32(Address + 0x8, value); } 39 | } 40 | 41 | public int UnknownPtr1 { 42 | get { return Hook.RInt32(Address + 0x10); } 43 | } 44 | 45 | public int TransformPtr { 46 | get { return Hook.RInt32(Address + 0x18); } 47 | set { Hook.WInt32(Address + 0x18, value); } 48 | } 49 | 50 | public int UnknownPtr2 { 51 | get { return Hook.RInt32(Address + 0x1c); } 52 | } 53 | 54 | //TODO: See if writeable, also see wtf it even is lol 55 | public bool DeadFlag { 56 | get { return Hook.RBool(UnknownPtr2 + 0x14); } 57 | } 58 | 59 | public bool IsHide { 60 | get { return Hook.RBit(Address + 0x14, 5); } 61 | set { Hook.WBit(Address + 0x14, 5, value); } 62 | } 63 | 64 | public bool IsDisable { 65 | get { return Hook.RBit(Address + 0x14, 7); } 66 | set { Hook.WBit(Address + 0x14, 7, value); } 67 | } 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrTransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DarkSoulsScripting.Injection; 3 | 4 | namespace DarkSoulsScripting 5 | { 6 | public class ChrTransform : GameStruct 7 | { 8 | protected override void InitSubStructures() 9 | { 10 | 11 | } 12 | 13 | public float Heading { 14 | get { return (float)((Hook.RFloat(Address + 0x4) / Math.PI * 180) + 180); } 15 | set { Hook.WFloat(Address + 0x4, (float)(value * Math.PI / 180) - (float)Math.PI); } 16 | } 17 | 18 | public float Angle { 19 | get { return Hook.RFloat(Address + 0x4); } 20 | set { Hook.WFloat(Address + 0x4, value); } 21 | } 22 | 23 | public float X { 24 | get { return Hook.RFloat(Address + 0x10); } 25 | set { Hook.WFloat(Address + 0x10, value); } 26 | } 27 | 28 | public float Y { 29 | get { return Hook.RFloat(Address + 0x14); } 30 | set { Hook.WFloat(Address + 0x14, value); } 31 | } 32 | 33 | public float Z { 34 | get { return Hook.RFloat(Address + 0x18); } 35 | set { Hook.WFloat(Address + 0x18, value); } 36 | } 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /DarkSoulsScripting/ChrUNK1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public class ChrUNK1 : GameStruct 11 | { 12 | protected override void InitSubStructures() 13 | { 14 | 15 | } 16 | 17 | public int LastHitMask { 18 | get { return RInt32(Address + 0x2C); } 19 | set { WInt32(Address + 0x2C, value); } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /DarkSoulsScripting/CodeHookTypes/Reg32Recorder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Managed.X86; 7 | using DarkSoulsScripting.Injection.Structures; 8 | using static DarkSoulsScripting.Hook; 9 | using System.IO; 10 | 11 | namespace DarkSoulsScripting.CodeHookTypes 12 | { 13 | public class Reg32Recorder : CodeHookBase 14 | { 15 | public X86Register32 Register { get; private set; } 16 | public int RecordedValue => RInt32(RecordedValueHandle.GetHandle().ToInt64()); 17 | 18 | private SafeRemoteHandle RecordedValueHandle { get; set; } 19 | 20 | /* 21 | * 01710000 - 89 35 00107101 - mov [target_ptr],esi | 6 Bytes 22 | * 0171000E - E9 79E789FF - jmp DARKSOULS.exe+BAE78C | 5 Bytes 23 | * 24 | * Total custom code size **NOT INCLUDING ORIGINAL CODE**: 11 bytes 25 | * 26 | */ 27 | 28 | private const int CustomCodeSize = 11; 29 | 30 | public Reg32Recorder(X86Register32 register, IntPtr originalLocalCodeStart, int originalLocalCodeLength, bool originalCodeAtEnd = true, byte[] specificOriginalCode = null) 31 | : base(originalLocalCodeStart, originalLocalCodeLength, CustomCodeSize + originalLocalCodeLength, originalCodeAtEnd, specificOriginalCode) 32 | { 33 | Register = register; 34 | } 35 | 36 | protected override void BuildCustomRemoteCode(X86Writer w, MemoryStream ms) 37 | { 38 | RecordedValueHandle?.Dispose(); 39 | RecordedValueHandle = new SafeRemoteHandle(sizeof(int)); 40 | 41 | //Move address in Register into the value of RecordedValueHandle 42 | // 43 | // e.g. with RecordedValueHandle = 7777 and Register = X86Register32.EAX: 44 | // mov [7777],eax 45 | w.Mov32(new X86Address(X86Register32.None, RecordedValueHandle.GetHandle().ToInt32()), Register); 46 | } 47 | 48 | public override void Dispose() 49 | { 50 | RecordedValueHandle?.Dispose(); 51 | 52 | base.Dispose(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /DarkSoulsScripting/DarkSoulsScripting.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {4EEF2FFB-9E6F-490E-B8D0-19C10451B461} 8 | Library 9 | Properties 10 | DarkSoulsScripting 11 | DarkSoulsScripting 12 | v4.7 13 | 512 14 | 15 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | 17 | 18 | true 19 | full 20 | false 21 | ..\Bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 7.1 26 | x86 27 | 28 | 29 | pdbonly 30 | true 31 | ..\Bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | InspectGUI.xaml 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | Designer 163 | MSBuild:Compile 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Enemy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public class Enemy : Chr 11 | { 12 | protected override void InitSubStructures() 13 | { 14 | base.InitSubStructures(); 15 | 16 | } 17 | 18 | public static Enemy FromPtr(int ptr) 19 | { 20 | return new Enemy() { AddressReadFunc = () => ptr }; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DarkSoulsScripting/EnemyAIController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DarkSoulsScripting 8 | { 9 | public class EnemyAIController : ChrAIController 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DarkSoulsScripting/EnemyController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DarkSoulsScripting 8 | { 9 | public class EnemyController : ChrController 10 | { 11 | public EnemyAIController AIController { get; private set; } = null; 12 | 13 | protected override void InitSubStructures() 14 | { 15 | base.InitSubStructures(); 16 | 17 | AIController = new EnemyAIController() { AddressReadFunc = () => AIControllerPtr }; 18 | } 19 | 20 | public int AIControllerPtr { 21 | get { return Hook.RInt32(Address + 0x230); } 22 | set { Hook.WInt32(Address + 0x230, value); } 23 | } 24 | 25 | public int AnimationID { 26 | get { return Hook.RInt32(Address + 0x1E8); } 27 | set { Hook.WInt32(Address + 0x1E8, value); } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DarkSoulsScripting/EnemyMovementCtrl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DarkSoulsScripting 8 | { 9 | public class EnemyMovementCtrl : ChrMovementCtrl 10 | { 11 | protected override void InitSubStructures() 12 | { 13 | base.InitSubStructures(); 14 | 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Extra/Dbg.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace DarkSoulsScripting.Extra 5 | { 6 | public class Dbg 7 | { 8 | public enum DbgPrintType 9 | { 10 | Normal, 11 | Info, 12 | Warn, 13 | Err, 14 | ClearAll 15 | } 16 | 17 | public static event OnPrintEventHandler OnPrint; 18 | public delegate void OnPrintEventHandler(System.DateTime time, DbgPrintType type, string text); 19 | 20 | public static void Print(string text) 21 | { 22 | OnPrint?.Invoke(DateTime.Now, DbgPrintType.Normal, text); 23 | } 24 | 25 | public static void PrintClearAll() 26 | { 27 | OnPrint?.Invoke(DateTime.Now, DbgPrintType.ClearAll, ""); 28 | } 29 | 30 | 31 | public static void PrintInfo(string text) 32 | { 33 | OnPrint?.Invoke(DateTime.Now, DbgPrintType.Info, text); 34 | } 35 | 36 | public static void PrintWarn(string text) 37 | { 38 | OnPrint?.Invoke(DateTime.Now, DbgPrintType.Warn, text); 39 | } 40 | 41 | public static void PrintErr(string text) 42 | { 43 | OnPrint?.Invoke(DateTime.Now, DbgPrintType.Err, text); 44 | } 45 | 46 | private static object lock_Dump = new object(); 47 | 48 | private static string debugDumpFileName = "Debug_Dump.txt"; 49 | //Public Shared Sub PrintArray(arr As Object()) 50 | // Console.WriteLine(arr.ToString() & "{" & String.Join(", ", arr.Select(Function(x) x.ToString)) & "}") 51 | //End Sub 52 | 53 | //Public Shared Sub PrintArray(arr As Integer()) 54 | // Console.WriteLine(arr.ToString() & "{" & String.Join(", ", arr.Select(Function(x) x.ToString)) & "}") 55 | //End Sub 56 | 57 | public static void Dump(string text) 58 | { 59 | lock (lock_Dump) 60 | { 61 | var time = System.DateTime.Now; 62 | var fullTimeStr = time.ToLongTimeString(); 63 | var ampm = fullTimeStr.Substring(fullTimeStr.Length - 3); 64 | fullTimeStr = fullTimeStr.Substring(0, fullTimeStr.Length - 3); 65 | var ms = time.Millisecond.ToString("000"); 66 | 67 | text = "[" + fullTimeStr + "." + ms + ampm + "] " + text; 68 | if (!System.IO.File.Exists(debugDumpFileName)) 69 | { 70 | using (var newFile = System.IO.File.CreateText(debugDumpFileName)) 71 | { 72 | newFile.WriteLine(text); 73 | } 74 | } 75 | else 76 | { 77 | using (System.IO.StreamWriter sw = new System.IO.StreamWriter(debugDumpFileName, true)) 78 | { 79 | sw.WriteLine(text); 80 | } 81 | } 82 | } 83 | } 84 | 85 | public static bool? PopupErr(string msg) 86 | { 87 | return Popup(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 88 | } 89 | 90 | public static bool? PopupErrQue(string msg) 91 | { 92 | return Popup(msg, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error); 93 | } 94 | 95 | public static bool? PopupOk(string msg, string title = "(Untitled)") 96 | { 97 | return Popup(msg, title); 98 | } 99 | 100 | public static bool? Popup(string msg, string title = "(Untitled)", MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon icon = MessageBoxIcon.None) 101 | { 102 | var result = MessageBox.Show(msg, title, buttons, icon); 103 | if (result == DialogResult.Yes || result == DialogResult.OK) 104 | { 105 | return true; 106 | } 107 | else if (result == DialogResult.No) 108 | { 109 | return false; 110 | } 111 | else 112 | { 113 | return null; 114 | } 115 | } 116 | 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Extra/DebugUI/InspectGUI.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Extra/DebugUI/InspectGUI.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace DarkSoulsScripting.DebugUI 4 | { 5 | /// 6 | /// Interaction logic for WpfPropertyGrid.xaml 7 | /// 8 | public partial class InspectGUI : Window 9 | { 10 | public InspectGUI() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Extra/Utils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DarkSoulsScripting.Injection; 3 | using static DarkSoulsScripting.Hook; 4 | using static DarkSoulsScripting.ExtraFuncs; 5 | using System.Threading; 6 | using System.Diagnostics; 7 | 8 | namespace DarkSoulsScripting.Extra 9 | { 10 | public static class Utils 11 | { 12 | public const double MinLoadingScreenDur = 3.0; 13 | 14 | public static bool BitmaskCheck(ulong input, ulong mask) 15 | { 16 | return ((input & mask) == mask); 17 | } 18 | 19 | public static bool IsGameLoading() 20 | { 21 | int ptr = RInt32(0x137DC70); 22 | if (ptr > DARKSOULS.SafeBaseMemoryOffset) 23 | return (RInt32(ptr + 0x4) < DARKSOULS.SafeBaseMemoryOffset); 24 | else 25 | return true; 26 | } 27 | 28 | public static void WaitForLoadingScreenStart() 29 | { 30 | while (!IsGameLoading()) 31 | { 32 | Wait(33); 33 | } 34 | } 35 | 36 | public static void WaitForLoadingScreenEnd() 37 | { 38 | while (IsGameLoading()) 39 | { 40 | Wait(33); 41 | } 42 | } 43 | 44 | public static void WaitLoadCycle() 45 | { 46 | WaitForLoadingScreenStart(); 47 | Wait(33); 48 | WaitForLoadingScreenEnd(); 49 | } 50 | 51 | //Function WAIT_FOR_GAME() 52 | // ingameTimeStopped = True 53 | // repeat 54 | // ingameTime = RInt32(RInt32(0x1378700) + 0x68) 55 | // ingameTimeStopped = (ingameTime == prevIngameTime) 56 | // prevIngameTime = ingameTime 57 | // until(Not ingameTimeStopped) 58 | // End 59 | 60 | //public static void WaitForGame() 61 | //{ 62 | // int curIngameTime = 0; 63 | // int prevIngameTime = 0; 64 | // bool ingameTimeStopped = true; 65 | // do 66 | // { 67 | // int ingameTimePointer = Hook.RInt32(0x1378700); 68 | // if (ingameTimePointer != 0) 69 | // { 70 | // curIngameTime = Hook.RInt32(ingameTimePointer + 0x68); 71 | // if (curIngameTime != 0) 72 | // { 73 | // //Only update time variables when a valid time value is read. 74 | // ingameTimeStopped = (prevIngameTime == 0 || prevIngameTime == curIngameTime); 75 | // prevIngameTime = curIngameTime; // 76 | // } 77 | // } 78 | 79 | // ExtraFuncs.Wait(16); 80 | // } while (ingameTimeStopped); 81 | //} 82 | 83 | //public static double WaitForGameAndMeasureDuration() 84 | //{ 85 | // var startTime = DateTime.Now; 86 | // WaitForGame(); 87 | 88 | // return (1.0 * DateTime.Now.Subtract(startTime).Ticks / TimeSpan.TicksPerSecond); 89 | //} 90 | 91 | //public static void WaitUntilAfterNextLoadingScreen() 92 | //{ 93 | // double waitDuration = 0; 94 | // do 95 | // { 96 | // waitDuration = WaitForGameAndMeasureDuration(); 97 | // } while (!(waitDuration >= MinLoadingScreenDur)); 98 | //} 99 | 100 | private static Stopwatch FixedTimestepStopwatch = null; 101 | 102 | public static long GetTickSpanFromHz(double Hz) 103 | { 104 | return (long)(TimeSpan.TicksPerSecond / Hz); 105 | } 106 | 107 | public static void FixedTimestep(Action updateLoop, long timestepTicks) 108 | { 109 | if (FixedTimestepStopwatch == null) 110 | FixedTimestepStopwatch = Stopwatch.StartNew(); 111 | updateLoop(); 112 | //Sadly this will only have a resolution of every ~15 ms or so because Windows sucks. 113 | var modTicks = (FixedTimestepStopwatch.ElapsedTicks % timestepTicks); 114 | var waitTicks = timestepTicks - modTicks; 115 | if (modTicks > (timestepTicks / 2)) 116 | { 117 | waitTicks += timestepTicks; 118 | } 119 | Thread.Sleep(TimeSpan.FromTicks(waitTicks)); 120 | //FixedTimestepStopwatch.Restart(); 121 | } 122 | 123 | public static uint GetIngameDllAddress(string moduleName) 124 | { 125 | uint[] modules = new uint[255]; 126 | uint cbNeeded = 0; 127 | PSAPI.EnumProcessModules(Hook.DARKSOULS.GetHandle(), modules, 4 * 1024, ref cbNeeded); 128 | 129 | var numModules = cbNeeded / IntPtr.Size; 130 | 131 | for (int i = 0; i <= numModules - 1; i++) 132 | { 133 | var disModule = new IntPtr(modules[i]); 134 | System.Text.StringBuilder name = new System.Text.StringBuilder(); 135 | PSAPI.GetModuleBaseName(Hook.DARKSOULS.GetHandle(), disModule, name, 255); 136 | 137 | if ((name.ToString().ToUpper().Equals(moduleName.ToUpper()))) 138 | { 139 | return modules[i]; 140 | } 141 | } 142 | 143 | return 0; 144 | } 145 | } 146 | } -------------------------------------------------------------------------------- /DarkSoulsScripting/Game.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public enum ClearState : int 11 | { 12 | none = 0, 13 | good = 1, 14 | bad = 2 15 | } 16 | 17 | public static class Game 18 | { 19 | public static Func AddressReadFunction = () => RInt32(0x1378700); 20 | public static int Address => AddressReadFunction(); 21 | 22 | public static int LocalPlayerStatsPtr 23 | { 24 | get { return RInt32(Address + 0x8); } 25 | set { WInt32(Address + 0x8, value); } 26 | } 27 | 28 | public static int OptionsPtr 29 | { 30 | get { return RInt32(Address + 0x2C); } 31 | set { WInt32(Address + 0x2C, value); } 32 | } 33 | 34 | public static int TendencyPtr 35 | { 36 | get { return RInt32(Address + 0x38); } 37 | set { WInt32(Address + 0x38, value); } 38 | } 39 | 40 | public static PlayerStats LocalPlayerStats = null; 41 | public static GameOptions Options = null; 42 | public static GameTendency Tendency = null; 43 | 44 | static Game() 45 | { 46 | LocalPlayerStats = new PlayerStats() { AddressReadFunc = () => LocalPlayerStatsPtr }; 47 | Options = new GameOptions() { AddressReadFunc = () => OptionsPtr }; 48 | Tendency = new GameTendency() { AddressReadFunc = () => TendencyPtr }; 49 | } 50 | 51 | public static int ClearCount 52 | { 53 | get { return RInt32(Address + 0x3C); } 54 | set { WInt32(Address + 0x3C, value); } 55 | } 56 | 57 | public static ClearState ClearState 58 | { 59 | get { return (ClearState)RInt32(Address + 0x40); } 60 | set { WInt32(Address + 0x40, (int)value); } 61 | } 62 | 63 | public static int FullRecover 64 | { 65 | get { return RInt32(Address + 0x44); } 66 | set { WInt32(Address + 0x44, value); } 67 | } 68 | 69 | public static int ItemComplete 70 | { 71 | get { return RInt32(Address + 0x48); } 72 | set { WInt32(Address + 0x48, value); } 73 | } 74 | 75 | public static int RescueWhite 76 | { 77 | get { return RInt32(Address + 0x4C); } 78 | set { WInt32(Address + 0x4C, value); } 79 | } 80 | 81 | //[sic] lol 82 | public static int KillBlack 83 | { 84 | get { return RInt32(Address + 0x50); } 85 | set { WInt32(Address + 0x50, value); } 86 | } 87 | 88 | public static int TrueDeath 89 | { 90 | get { return RInt32(Address + 0x54); } 91 | set { WInt32(Address + 0x54, value); } 92 | } 93 | 94 | public static int TrueDeathNum 95 | { 96 | get { return RInt32(Address + 0x58); } 97 | set { WInt32(Address + 0x58, value); } 98 | } 99 | 100 | public static int DeathNum 101 | { 102 | get { return RInt32(Address + 0x5C); } 103 | set { WInt32(Address + 0x5C, value); } 104 | } 105 | 106 | public static int IngameTime 107 | { 108 | get { return RInt32(Address + 0x68); } 109 | set { WInt32(Address + 0x68, value); } 110 | } 111 | 112 | public static int LanCutPoint 113 | { 114 | get { return RInt32(Address + 0x6C); } 115 | set { WInt32(Address + 0x6C, value); } 116 | } 117 | 118 | public static int LanCutPointTimer 119 | { 120 | get { return RInt32(Address + 0x70); } 121 | set { WInt32(Address + 0x70, value); } 122 | } 123 | 124 | public static int DeathState 125 | { 126 | get { return RInt32(Address + 0x78); } 127 | set { WInt32(Address + 0x78, value); } 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /DarkSoulsScripting/GameOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public enum BloodLevel : byte 11 | { 12 | Off = 0, 13 | Normal = 1, 14 | Mild = 2 15 | } 16 | 17 | public class GameOptions : GameStruct 18 | { 19 | protected override void InitSubStructures() 20 | { 21 | 22 | } 23 | 24 | public byte CameraSpeed 25 | { 26 | get { return RByte(Address + 0x4); } 27 | set { WByte(Address + 0x4, value); } 28 | } 29 | 30 | public byte Vibration 31 | { 32 | get { return RByte(Address + 0x5); } 33 | set { WByte(Address + 0x5, value); } 34 | } 35 | 36 | public byte Brightness 37 | { 38 | get { return RByte(Address + 0x6); } 39 | set { WByte(Address + 0x6, value); } 40 | } 41 | 42 | public byte SoundType 43 | { 44 | get { return RByte(Address + 0x7); } 45 | set { WByte(Address + 0x7, value); } 46 | } 47 | 48 | public byte VolumeBGM 49 | { 50 | get { return RByte(Address + 0x8); } 51 | set { WByte(Address + 0x8, value); } 52 | } 53 | 54 | public byte VolumeSFX 55 | { 56 | get { return RByte(Address + 0x9); } 57 | set { WByte(Address + 0x9, value); } 58 | } 59 | 60 | public byte VolumeVoice 61 | { 62 | get { return RByte(Address + 0xA); } 63 | set { WByte(Address + 0xA, value); } 64 | } 65 | 66 | public BloodLevel Blood 67 | { 68 | get { return (BloodLevel)RByte(Address + 0xB); } 69 | set { WByte(Address + 0xB, (byte)value); } 70 | } 71 | 72 | public bool Subtitles 73 | { 74 | get { return RBool(Address + 0xC); } 75 | set { WBool(Address + 0xC, value); } 76 | } 77 | 78 | public bool HUD 79 | { 80 | get { return RBool(Address + 0xD); } 81 | set { WBool(Address + 0xD, value); } 82 | } 83 | 84 | public bool CameraReverseX 85 | { 86 | get { return RBool(Address + 0xE); } 87 | set { WBool(Address + 0xE, value); } 88 | } 89 | 90 | public bool CameraReverseY 91 | { 92 | get { return RBool(Address + 0xF); } 93 | set { WBool(Address + 0xF, value); } 94 | } 95 | 96 | public bool AutoLockOn 97 | { 98 | get { return RBool(Address + 0x10); } 99 | set { WBool(Address + 0x10, value); } 100 | } 101 | 102 | public bool CameraAutoWallRecovery 103 | { 104 | get { return RBool(Address + 0x11); } 105 | set { WBool(Address + 0x11, value); } 106 | } 107 | 108 | public bool JoinLeaderboard 109 | { 110 | get { return RBool(Address + 0x12); } 111 | set { WBool(Address + 0x12, value); } 112 | } 113 | 114 | public byte DebugRankRegisterProfileIdx 115 | { 116 | get { return RByte(Address + 0x13); } 117 | set { WByte(Address + 0x13, value); } 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /DarkSoulsScripting/GameStruct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | namespace DarkSoulsScripting 5 | { 6 | public abstract class GameStruct 7 | { 8 | public int Address 9 | { 10 | get { return AddressReadFunc(); } 11 | } 12 | 13 | private Func _addressReadFunc; 14 | internal Func AddressReadFunc 15 | { 16 | get => _addressReadFunc; 17 | set 18 | { 19 | _addressReadFunc = value; 20 | InitSubStructures(); 21 | } 22 | } 23 | 24 | protected abstract void InitSubStructures(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DarkSoulsScripting/GameTendency.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public class GameTendency : GameStruct 11 | { 12 | protected override void InitSubStructures() 13 | { 14 | 15 | } 16 | 17 | public float CharacterBlackWhiteTendency 18 | { 19 | get { return RFloat(Address + 0x8); } 20 | set { WFloat(Address + 0x8, value); } 21 | } 22 | 23 | public float CharacterLeftRightTendency 24 | { 25 | get { return RFloat(Address + 0xC); } 26 | set { WFloat(Address + 0xC, value); } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Global.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public static class Global 11 | { 12 | public static int Address => RInt32(0x1378560); 13 | 14 | 15 | public static byte AreaID 16 | { 17 | get { return RByte(Address + 0xB); } 18 | set { WByte(Address + 0xB, value); } 19 | } 20 | 21 | public static byte BlockID 22 | { 23 | get { return RByte(Address + 0xA); } 24 | set { WByte(Address + 0xA, value); } 25 | } 26 | 27 | public static bool IsAliveMotion 28 | { 29 | get { return RBool(Address + 0x1C); } 30 | set { WBool(Address + 0x1C, value); } 31 | } 32 | 33 | public static bool IsReviveWait 34 | { 35 | get { return RBool(Address + 0x1F); } 36 | set { WBool(Address + 0x1F, value); } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Injection/DLL/Kernel32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace DarkSoulsScripting.Injection.DLL 9 | { 10 | //TODO: Replace old Kernel class with this one, using actual correct value types on the parameters to be 110% sure it's working as intended. 11 | public static class Kernel32 12 | { 13 | const uint INFINITE = 0xFFFFFFFF; 14 | const uint WAIT_ABANDONED = 0x00000080; 15 | const uint WAIT_OBJECT_0 = 0x00000000; 16 | const uint WAIT_TIMEOUT = 0x00000102; 17 | 18 | [Flags] 19 | public enum AllocationType 20 | { 21 | Commit = 0x1000, 22 | Reserve = 0x2000, 23 | Decommit = 0x4000, 24 | Release = 0x8000, 25 | Reset = 0x80000, 26 | Physical = 0x400000, 27 | TopDown = 0x100000, 28 | WriteWatch = 0x200000, 29 | LargePages = 0x20000000 30 | } 31 | 32 | [Flags] 33 | public enum MemoryProtection 34 | { 35 | Execute = 0x10, 36 | ExecuteRead = 0x20, 37 | ExecuteReadWrite = 0x40, 38 | ExecuteWriteCopy = 0x80, 39 | NoAccess = 0x01, 40 | ReadOnly = 0x02, 41 | ReadWrite = 0x04, 42 | WriteCopy = 0x08, 43 | GuardModifierflag = 0x100, 44 | NoCacheModifierflag = 0x200, 45 | WriteCombineModifierflag = 0x400 46 | } 47 | 48 | [DllImport("kernel32.dll", SetLastError= true, ExactSpelling= true)] 49 | static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, 50 | uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect); 51 | 52 | [DllImport("kernel32.dll")] 53 | static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, 54 | UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect); 55 | 56 | [DllImport("kernel32.dll", SetLastError = true)] 57 | static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds); 58 | 59 | [DllImport("kernel32.dll")] 60 | static extern IntPtr CreateRemoteThread(IntPtr hProcess, 61 | IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, 62 | IntPtr lpParameter, uint dwCreationFlags, out IntPtr lpThreadId); 63 | 64 | [DllImport("kernel32.dll")] 65 | static extern int VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer, uint dwLength); 66 | 67 | [StructLayout(LayoutKind.Sequential)] 68 | public struct MEMORY_BASIC_INFORMATION 69 | { 70 | public IntPtr BaseAddress; 71 | public IntPtr AllocationBase; 72 | public uint AllocationProtect; 73 | public IntPtr RegionSize; 74 | public uint State; 75 | public uint Protect; 76 | public uint Type; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Injection/PSAPI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Text; 4 | 5 | namespace DarkSoulsScripting.Injection 6 | { 7 | internal class PSAPI 8 | { 9 | [DllImport("psapi.dll", SetLastError = true)] 10 | internal static extern bool EnumProcessModules( 11 | IntPtr hProcess, 12 | [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U4)] 13 | [In()] [Out()] uint[] lphModule, 14 | uint cb, 15 | [MarshalAs(UnmanagedType.U4)] ref uint lpcbNeeded); 16 | 17 | [DllImport("psapi.dll")] 18 | internal static extern uint GetModuleBaseName(IntPtr hProcess, IntPtr hModule, StringBuilder lpBaseName, uint nSize); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Injection/Structures/DarkSoulsVersion.cs: -------------------------------------------------------------------------------- 1 | namespace DarkSoulsScripting.Injection.Structures 2 | { 3 | public enum DarkSoulsVersion 4 | { 5 | None, 6 | LatestRelease, 7 | SteamWorksBeta, 8 | Debug, 9 | AncientGFWL 10 | } 11 | } -------------------------------------------------------------------------------- /DarkSoulsScripting/Injection/Structures/MoveableAddressOffset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace DarkSoulsScripting.Injection.Structures 3 | { 4 | 5 | internal class MoveableAddressOffset 6 | { 7 | 8 | private uint offset = 0; 9 | private DSAsmCaller FuncCallerInstance { get; } 10 | 11 | public uint Location 12 | { 13 | get { return (uint)FuncCallerInstance.CodeHandle.GetHandle() + offset; } 14 | set { offset = (value - (uint)FuncCallerInstance.CodeHandle.GetHandle()); } 15 | } 16 | 17 | public MoveableAddressOffset(DSAsmCaller _funcCaller, IntPtr loc) 18 | { 19 | FuncCallerInstance = _funcCaller; 20 | Location = (uint)loc; 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Injection/Structures/MutatableDword.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace DarkSoulsScripting.Injection.Structures 5 | { 6 | [StructLayout(LayoutKind.Explicit)] 7 | public struct MutatableDword 8 | { 9 | [FieldOffset(0)] 10 | public byte Byte1; 11 | 12 | [FieldOffset(1)] 13 | public byte Byte2; 14 | 15 | [FieldOffset(2)] 16 | public byte Byte3; 17 | 18 | [FieldOffset(3)] 19 | public byte Byte4; 20 | 21 | [FieldOffset(0)] 22 | public sbyte SByte1; 23 | 24 | [FieldOffset(1)] 25 | public sbyte SByte2; 26 | 27 | [FieldOffset(2)] 28 | public sbyte SByte3; 29 | 30 | [FieldOffset(3)] 31 | public sbyte SByte4; 32 | 33 | public byte[] ByteArray 34 | { 35 | get 36 | { 37 | return new byte[] { Byte1, Byte2, Byte3, Byte4 }; 38 | } 39 | } 40 | 41 | public void SetBytes(byte[] newBytes) 42 | { 43 | if (newBytes.Length != 4) 44 | throw new ArgumentException("Byte array must be exactly 4 bytes long.", "newBytes"); 45 | 46 | Byte1 = newBytes[0]; 47 | Byte2 = newBytes[1]; 48 | Byte3 = newBytes[2]; 49 | Byte4 = newBytes[3]; 50 | } 51 | 52 | [FieldOffset(0)] 53 | public int Int1; 54 | 55 | [FieldOffset(0)] 56 | public uint UInt1; 57 | 58 | [FieldOffset(0)] 59 | public float Float1; 60 | 61 | [FieldOffset(0)] 62 | public short Short1; 63 | 64 | [FieldOffset(2)] 65 | public short Short2; 66 | 67 | [FieldOffset(0)] 68 | public ushort UShort1; 69 | 70 | [FieldOffset(2)] 71 | public ushort UShort2; 72 | 73 | public bool Bool1 74 | { 75 | get { return (Byte1 != 0); } 76 | } 77 | 78 | public bool Bool2 79 | { 80 | get { return (Byte2 != 0); } 81 | } 82 | 83 | public bool Bool3 84 | { 85 | get { return (Byte3 != 0); } 86 | } 87 | 88 | public bool Bool4 89 | { 90 | get { return (Byte4 != 0); } 91 | } 92 | 93 | public static implicit operator MutatableDword(short a) => new MutatableDword() { Int1 = a }; 94 | public static implicit operator MutatableDword(ushort a) => new MutatableDword() { UInt1 = a }; 95 | public static implicit operator MutatableDword(byte a) => new MutatableDword() { UInt1 = a }; 96 | public static implicit operator MutatableDword(sbyte a) => new MutatableDword() { Int1 = a }; 97 | public static implicit operator MutatableDword(int a) => new MutatableDword() { Int1 = a }; 98 | public static implicit operator MutatableDword(uint a) => new MutatableDword() { UInt1 = a }; 99 | public static implicit operator MutatableDword(float a) => new MutatableDword() { Float1 = a }; 100 | public static implicit operator MutatableDword(bool a) => new MutatableDword() { Int1 = a ? 1 : 0 }; 101 | 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Injection/Structures/SafeMarshalledHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.ConstrainedExecution; 3 | using System.Runtime.InteropServices; 4 | using Microsoft.Win32.SafeHandles; 5 | 6 | namespace DarkSoulsScripting.Injection.Structures 7 | { 8 | public class SafeMarshalledHandle : SafeHandleZeroOrMinusOneIsInvalid 9 | { 10 | public readonly object Obj; 11 | 12 | public readonly int Size; 13 | public SafeMarshalledHandle(object obj) : base(true) 14 | { 15 | Size = Marshal.SizeOf(obj); 16 | this.Obj = obj; 17 | Alloc(); 18 | } 19 | 20 | [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] 21 | protected override bool ReleaseHandle() 22 | { 23 | Marshal.FreeHGlobal(handle); 24 | return true; 25 | } 26 | 27 | private void Alloc() 28 | { 29 | SetHandle(Marshal.AllocHGlobal(Size)); 30 | Marshal.StructureToPtr(Obj, handle, true); 31 | } 32 | public IntPtr GetHandle() 33 | { 34 | if (IsClosed | IsInvalid) 35 | { 36 | Alloc(); 37 | } 38 | return handle; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Injection/Structures/SafeRemoteHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.ConstrainedExecution; 3 | using Microsoft.Win32.SafeHandles; 4 | 5 | namespace DarkSoulsScripting.Injection.Structures 6 | { 7 | public class SafeRemoteHandle : SafeHandleZeroOrMinusOneIsInvalid 8 | { 9 | public readonly int Size; 10 | public SafeRemoteHandle(int size) : base(true) 11 | { 12 | this.Size = size; 13 | Hook.DARKSOULS.OnDetach += DARKSOULS_OnDetach; 14 | Alloc(); 15 | } 16 | private void Alloc() 17 | { 18 | IntPtr dsHandle = Hook.DARKSOULS.GetHandle(); 19 | IntPtr h = (IntPtr)Kernel.VirtualAllocEx(dsHandle, 0, Size, Kernel.MEM_COMMIT, Kernel.PAGE_EXECUTE_READWRITE); 20 | SetHandle(h); 21 | } 22 | public IntPtr GetHandle() 23 | { 24 | if (IsClosed || IsInvalid || handle.ToInt32() < Hook.DARKSOULS.SafeBaseMemoryOffset) 25 | { 26 | Alloc(); 27 | } 28 | return handle; 29 | } 30 | private void DARKSOULS_OnDetach() 31 | { 32 | SetHandleAsInvalid(); 33 | } 34 | [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] 35 | protected override bool ReleaseHandle() 36 | { 37 | Hook.DARKSOULS.OnDetach -= DARKSOULS_OnDetach; 38 | 39 | if (handle.ToInt32() < Hook.DARKSOULS.SafeBaseMemoryOffset) 40 | { 41 | return false; 42 | } 43 | 44 | IntPtr dsHandle = Hook.DARKSOULS.GetHandle(); 45 | 46 | return Kernel.VirtualFreeEx(dsHandle, (uint)handle, 0, Kernel.MEM_RELEASE); 47 | } 48 | public void MemPatch(byte[] src, int? srcIndex = null, int? destOffset = null, int? numBytes = null) 49 | { 50 | IntPtr dsHandle = Hook.DARKSOULS.GetHandle(); 51 | if (dsHandle.ToInt32() < Hook.DARKSOULS.SafeBaseMemoryOffset) 52 | { 53 | return; 54 | } 55 | 56 | if ((destOffset ?? 0 + numBytes ?? src.Length) > Size) 57 | { 58 | throw new Exception("Bytes will not fit in allocated space."); 59 | } 60 | byte[] buf = new byte[numBytes ?? src.Length]; 61 | Array.Copy(src, srcIndex ?? 0, buf, 0, numBytes ?? src.Length); 62 | Kernel.WriteProcessMemory_SAFE(dsHandle, (uint)(handle + (destOffset ?? 0)), buf, numBytes ?? src.Length, 0); 63 | } 64 | 65 | public void MemPatch(SafeMarshalledHandle src, int? destOffset = null, int? numBytes = null) 66 | { 67 | if (handle.ToInt32() < Hook.DARKSOULS.SafeBaseMemoryOffset) 68 | { 69 | return; 70 | } 71 | 72 | if ((destOffset ?? 0 + numBytes ?? src.Size) > Size) 73 | { 74 | throw new Exception("Bytes will not fit in allocated space."); 75 | } 76 | byte[] buf = new byte[numBytes ?? src.Size]; 77 | 78 | IntPtr dsHandle = Hook.DARKSOULS.GetHandle(); 79 | 80 | Kernel.WriteProcessMemory_SAFE(dsHandle, (uint)(handle + (destOffset ?? 0)), (uint)src.GetHandle(), numBytes ?? src.Size, 0); 81 | } 82 | 83 | public byte[] GetFuncReturnValue() 84 | { 85 | byte[] result = new byte[DSAsmCaller.INT32_SIZE]; 86 | 87 | if (handle.ToInt32() < Hook.DARKSOULS.SafeBaseMemoryOffset) 88 | { 89 | return result; 90 | } 91 | 92 | IntPtr dsHandle = Hook.DARKSOULS.GetHandle(); 93 | if (!Kernel.ReadProcessMemory_SAFE(dsHandle, (uint)handle + DSAsmCaller.FUNC_RETURN_ADDR_OFFSET, result, DSAsmCaller.INT32_SIZE, 0)) 94 | { 95 | //Throw New Exception("Kernel.ReadProcessMemory Fail for SafeRemoteHandle.GetFuncReturnValue()") 96 | } 97 | return result; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Injection/Structures/SafeRemoteThreadHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.ConstrainedExecution; 3 | using Microsoft.Win32.SafeHandles; 4 | 5 | namespace DarkSoulsScripting.Injection.Structures 6 | { 7 | public class SafeRemoteThreadHandle : SafeHandleZeroOrMinusOneIsInvalid 8 | { 9 | public readonly SafeRemoteHandle Func; 10 | public SafeRemoteThreadHandle(SafeRemoteHandle func) : base(true) 11 | { 12 | this.Func = func; 13 | Hook.DARKSOULS.OnDetach += DARKSOULS_OnDetach; 14 | Alloc(); 15 | } 16 | private void Alloc() 17 | { 18 | IntPtr dsHandle = Hook.DARKSOULS.GetHandle(); 19 | uint funcHandle = (uint)Func.GetHandle(); 20 | if (funcHandle < Hook.DARKSOULS.SafeBaseMemoryOffset) 21 | { 22 | return; 23 | } 24 | 25 | SetHandle((IntPtr)Kernel.CreateRemoteThread(dsHandle, 0, 0, funcHandle, 0, 0, 0)); 26 | } 27 | public IntPtr GetHandle() 28 | { 29 | if (IsClosed || IsInvalid || handle.ToInt32() < Hook.DARKSOULS.SafeBaseMemoryOffset) 30 | { 31 | Alloc(); 32 | } 33 | return handle; 34 | } 35 | private void DARKSOULS_OnDetach() 36 | { 37 | SetHandleAsInvalid(); 38 | } 39 | [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] 40 | protected override bool ReleaseHandle() 41 | { 42 | Hook.DARKSOULS.OnDetach -= DARKSOULS_OnDetach; 43 | 44 | if (handle.ToInt32() < Hook.DARKSOULS.SafeBaseMemoryOffset) 45 | { 46 | return false; 47 | } 48 | 49 | return Kernel.CloseHandle(handle); 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /DarkSoulsScripting/MSB.cs: -------------------------------------------------------------------------------- 1 | using DarkSoulsScripting.Injection; 2 | 3 | namespace DarkSoulsScripting 4 | { 5 | //UNDER CONSTRUCTION 6 | public class MSB 7 | { 8 | 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /DarkSoulsScripting/MSBEntry.cs: -------------------------------------------------------------------------------- 1 | namespace DarkSoulsScripting 2 | { 3 | //UNDER CONSTRUCTION 4 | public class MSBEntry : GameStruct 5 | { 6 | 7 | protected override void InitSubStructures() 8 | { 9 | 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Map.cs: -------------------------------------------------------------------------------- 1 | using DarkSoulsScripting.Injection; 2 | using System.Collections.Generic; 3 | 4 | namespace DarkSoulsScripting 5 | { 6 | public static class Map 7 | { 8 | public static int Address => Hook.RInt32((0x137D644, 0)); 9 | 10 | public static int PlayerPointer { 11 | get { return Hook.RInt32(Address + 0x3C); } 12 | set { Hook.WInt32(Address + 0x3C, value); } 13 | } 14 | 15 | public static int MapEntryCount { 16 | get { return Hook.RInt32(Address + 0x70); } 17 | } 18 | 19 | public static List GetEntries() 20 | { 21 | List result = new List(); 22 | for (int i = 0; i < MapEntryCount; i++) { 23 | var addr = Hook.RInt32(Address + 0x74 + (4 * i)); 24 | result.Add(new MapEntry() { AddressReadFunc = () => addr }); 25 | } 26 | return result; 27 | } 28 | 29 | public static MapEntry Find(int area, int block) 30 | { 31 | foreach (var e in GetEntries()) 32 | { 33 | if (e.Area == (byte)area && e.Block == (byte)block) 34 | return e; 35 | } 36 | 37 | return null; 38 | } 39 | 40 | //TODO: REPLACE FUNCTION CALLS WITH DIRECT READS 41 | public static MapEntry GetCurrent() 42 | { 43 | return Find(IngameFuncs.GetCurrentMapAreaNo(), IngameFuncs.GetCurrentMapBlockNo()); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /DarkSoulsScripting/MapEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DarkSoulsScripting.Injection; 3 | using System.Collections.Generic; 4 | using static DarkSoulsScripting.Hook; 5 | 6 | namespace DarkSoulsScripting 7 | { 8 | public class MapEntry : GameStruct 9 | { 10 | public const int MAX_NAME_LENGTH = 12; 11 | 12 | protected override void InitSubStructures() 13 | { 14 | 15 | } 16 | 17 | public string GetName() 18 | { 19 | return RUnicodeStr(RInt32(RInt32(Address + 0x60) + 4), MAX_NAME_LENGTH); 20 | } 21 | 22 | public Enemy FindEnemy(int modelID, int instanceNum) 23 | { 24 | string nameFormat = $"c{modelID:4}_{instanceNum:4}"; 25 | foreach (var e in GetChrsAsEnemies()) 26 | { 27 | if (e.GetName() == nameFormat) 28 | return e; 29 | } 30 | return null; 31 | } 32 | 33 | public Enemy FindEnemyByMsbStr(str name) 34 | { 35 | foreach (var e in GetChrsAsEnemies()) 36 | { 37 | if (e.GetName() == name) 38 | return e; 39 | } 40 | return null; 41 | } 42 | 43 | public int PointerToBlockAndArea { 44 | get { return RInt32(Address + 0x4); } 45 | } 46 | 47 | public byte Block { 48 | get { return RByte(PointerToBlockAndArea + 0x6); } 49 | } 50 | 51 | public byte Area { 52 | get { return RByte(PointerToBlockAndArea + 0x7); } 53 | } 54 | 55 | public int ChrCount { 56 | get { return RInt32(Address + 0x3C); } 57 | } 58 | 59 | public int StartOfChrStruct { 60 | get { return RInt32(Address + 0x40); } 61 | } 62 | 63 | public List GetChrSlots() 64 | { 65 | List result = new List(); 66 | 67 | for (int i = 0; i < ChrCount; i++) { 68 | var addr = StartOfChrStruct + (0x20 * i); 69 | result.Add(new ChrSlot() { AddressReadFunc = () => addr }); 70 | } 71 | 72 | return result; 73 | } 74 | 75 | public List GetChrsAsEnemies() 76 | { 77 | List result = new List(); 78 | 79 | for (int i = 0; i < ChrCount; i++) { 80 | var addr = RInt32(StartOfChrStruct + (0x20 * i)); 81 | result.Add(new ChrSlot() { AddressReadFunc = () => addr }.GetChrAsEnemy()); 82 | } 83 | 84 | return result; 85 | } 86 | 87 | public List GetChrTransforms() 88 | { 89 | List result = new List(); 90 | 91 | for (int i = 0; i < ChrCount; i++) { 92 | var addr = StartOfChrStruct + (0x20 * i); 93 | result.Add(new ChrSlot() { AddressReadFunc = () => addr }.Transform); 94 | } 95 | 96 | return result; 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Misc.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public static class Misc 11 | { 12 | 13 | public static bool DisablePad 14 | { 15 | get { return RBool(0x1378622); } 16 | set { WBool(0x1378622, value); } 17 | } 18 | 19 | public static float Unknown_MakeEveryoneTPose 20 | { 21 | get { return RFloat(0x11E7CA0); } 22 | set { WFloat(0x11E7CA0, value); } 23 | } 24 | 25 | public static float Unknown_StrangeLighting 26 | { 27 | get { return RFloat(0x11E7CEC); } 28 | set { WFloat(0x11E7CEC, value); } 29 | } 30 | 31 | public static float Unknown_LightRelated 32 | { 33 | get { return RFloat(0x11E7D34); } 34 | set { WFloat(0x11E7D34, value); } 35 | } 36 | 37 | public static float Unknown_FOVRelated_1_14_Default 38 | { 39 | get { return RFloat(0x11E7DD4); } 40 | set { WFloat(0x11E7DD4, value); } 41 | } 42 | 43 | public static int ResistRegenRate 44 | { 45 | get { return RInt32(0x12DF020); } 46 | set { WInt32(0x12DF020, value); } 47 | } 48 | 49 | public static bool IsRevengeRequested 50 | { 51 | get { return RBool(0x13786F8); } 52 | set { WBool(0x13786F8, value); } 53 | } 54 | 55 | public static int GetPlayerCurrentAnimationAddress() => RInt32(RInt32(RInt32(RInt32(0x12E29E8) + 0x10) + 0x38) + 0x46C) + 0x60; 56 | 57 | public static int PlayerCurrentAnimation 58 | { 59 | get { return RInt32(GetPlayerCurrentAnimationAddress()); } 60 | set { WInt32(GetPlayerCurrentAnimationAddress(), value); } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Player.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DarkSoulsScripting 8 | { 9 | public class Player : Chr 10 | { 11 | public PlayerStats Stats { get; private set; } = null; 12 | 13 | protected override void InitSubStructures() 14 | { 15 | base.InitSubStructures(); 16 | 17 | Stats = new PlayerStats() { AddressReadFunc = () => StatsPtr }; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DarkSoulsScripting/PlayerController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DarkSoulsScripting 8 | { 9 | public class PlayerController : ChrController 10 | { 11 | 12 | protected override void InitSubStructures() 13 | { 14 | base.InitSubStructures(); 15 | 16 | 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DarkSoulsScripting/PlayerMovementCtrl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DarkSoulsScripting 8 | { 9 | public class PlayerMovementCtrl : ChrMovementCtrl 10 | { 11 | 12 | protected override void InitSubStructures() 13 | { 14 | base.InitSubStructures(); 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DarkSoulsScripting/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("DarkSoulsScripting")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("DarkSoulsScripting")] 12 | [assembly: AssemblyCopyright("Copyright © Dark Souls Modding Community 2017")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("4eef2ffb-9e6f-490e-b8d0-19c10451b461")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /DarkSoulsScripting/WorldChrMan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static DarkSoulsScripting.Hook; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public class WorldChrMan 11 | { 12 | //Taken from the Dark Souls 1 Overhaul IDA Workspace. 13 | public const int CHR_STRUCT_SIZE = 0x5F8; 14 | 15 | public static int Address => RInt32(0x137DC70); 16 | 17 | public static Player LocalPlayer { get; private set; } = null; 18 | 19 | static WorldChrMan() 20 | { 21 | LocalPlayer = new Player() { AddressReadFunc = () => RInt32(ChrsBegin + 0x0) }; 22 | } 23 | 24 | //TODO: SEE IF THESE ARE ALL ENEMIES OR WHAT. 25 | public static List GetEnemies() 26 | { 27 | var result = new List(); 28 | for (int i = ChrsBegin; i <= ChrsEnd; i += 4) 29 | { 30 | int thisEnemyAddress = RInt32(i); 31 | result.Add(new Enemy() { AddressReadFunc = () => thisEnemyAddress }); 32 | } 33 | return result; 34 | } 35 | 36 | public static EnemyPtrAccessor EnemyPtr = new EnemyPtrAccessor(); 37 | 38 | public class EnemyPtrAccessor 39 | { 40 | public int this[int index] 41 | { 42 | get => RInt32(ChrsBegin + (index * 0x4)); 43 | set => WInt32(ChrsBegin + (index * 0x4), value); 44 | } 45 | } 46 | 47 | public static int ChrsBegin 48 | { 49 | get => RInt32(Address + 0x4); 50 | set => WInt32(Address + 0x4, value); 51 | } 52 | 53 | public static int ChrsEnd 54 | { 55 | get => RInt32(Address + 0x8); 56 | set => WInt32(Address + 0x8, value); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Arithmetic/X86Writer.Add.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Add8 (X86Register8 dest, X86Register8 src) { 16 | writer.Write(new byte[] { 0x00 }); 17 | reg_emit8(dest, src); 18 | } 19 | public void Add16(X86Register16 dest, X86Register16 src) { 20 | writer.Write(new byte[] { 0x66, 0x01 }); 21 | reg_emit16(dest, src); 22 | } 23 | public void Add32(X86Register32 dest, X86Register32 src) { 24 | writer.Write(new byte[] { 0x01 }); 25 | reg_emit32(dest, src); 26 | } 27 | 28 | public void Add8(X86Address dest, X86Register8 src) { 29 | writer.Write(new byte[] { 0x00 }); 30 | dest.Emit(writer, src); 31 | } 32 | public void Add16(X86Address dest, X86Register16 src) { 33 | writer.Write(new byte[] { 0x66, 0x01 }); 34 | dest.Emit(writer, src); 35 | } 36 | public void Add32(X86Address dest, X86Register32 src) { 37 | writer.Write(new byte[] { 0x01 }); 38 | dest.Emit(writer, src); 39 | } 40 | 41 | public void Add8(X86Register8 dest, X86Address src) { 42 | writer.Write(new byte[] { 0x02 }); 43 | src.Emit(writer, dest); 44 | } 45 | public void Add16(X86Register16 dest, X86Address src) { 46 | writer.Write(new byte[] { 0x66, 0x03 }); 47 | src.Emit(writer, dest); 48 | } 49 | public void Add32(X86Register32 dest, X86Address src) { 50 | writer.Write(new byte[] { 0x03 }); 51 | src.Emit(writer, dest); 52 | } 53 | 54 | public void Add8(X86Register8 dest, Byte value) { 55 | this.writer.Write(new byte[] { 0x80 }); 56 | reg_emit8(0, dest); 57 | writer.Write(value); 58 | } 59 | public void Add16(X86Register16 dest, Int16 value) { 60 | this.writer.Write(new byte[] { 0x66, 0x81 }); 61 | reg_emit16(0, dest); 62 | writer.Write(value); 63 | } 64 | public void Add32(X86Register32 dest, Int32 value) { 65 | this.writer.Write(new byte[] { 0x81 }); 66 | reg_emit32(0, dest); 67 | writer.Write(value); 68 | } 69 | 70 | public void Add8(X86Address dest, Byte value) { 71 | this.writer.Write(new byte[] { 0x80 }); 72 | dest.Emit(writer, X86Register32.None); 73 | writer.Write(value); 74 | } 75 | public void Add16(X86Address dest, Int16 value) { 76 | this.writer.Write(new byte[] { 0x66, 0x81 }); 77 | dest.Emit(writer, X86Register32.None); 78 | writer.Write(value); 79 | } 80 | public void Add32(X86Address dest, Int32 value) { 81 | this.writer.Write(new byte[] { 0x81 }); 82 | dest.Emit(writer, X86Register32.None); 83 | writer.Write(value); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Arithmetic/X86Writer.AddWithCarry.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void AddC8(X86Register8 dest, X86Register8 src) { 16 | writer.Write(new byte[] { 0x10 }); 17 | reg_emit8(dest, src); 18 | } 19 | public void AddC16(X86Register16 dest, X86Register16 src) { 20 | writer.Write(new byte[] { 0x66, 0x11 }); 21 | reg_emit16(dest, src); 22 | } 23 | public void AddC32(X86Register32 dest, X86Register32 src) { 24 | writer.Write(new byte[] { 0x11 }); 25 | reg_emit32(dest, src); 26 | } 27 | 28 | public void AddC8(X86Address dest, X86Register8 src) { 29 | writer.Write(new byte[] { 0x10 }); 30 | dest.Emit(writer, src); 31 | } 32 | public void AddC16(X86Address dest, X86Register16 src) { 33 | writer.Write(new byte[] { 0x66, 0x11 }); 34 | dest.Emit(writer, src); 35 | } 36 | public void AddC32(X86Address dest, X86Register32 src) { 37 | writer.Write(new byte[] { 0x11 }); 38 | dest.Emit(writer, src); 39 | } 40 | 41 | public void AddC8(X86Register8 dest, X86Address src) { 42 | writer.Write(new byte[] { 0x12 }); 43 | src.Emit(writer, dest); 44 | } 45 | public void AddC16(X86Register16 dest, X86Address src) { 46 | writer.Write(new byte[] { 0x66, 0x13 }); 47 | src.Emit(writer, dest); 48 | } 49 | public void AddC32(X86Register32 dest, X86Address src) { 50 | writer.Write(new byte[] { 0x13 }); 51 | src.Emit(writer, dest); 52 | } 53 | 54 | public void AddC8(X86Register8 dest, Byte value) { 55 | this.writer.Write(new byte[] { 0x80 }); 56 | reg_emit8((X86Register8)0x2, dest); 57 | writer.Write(value); 58 | } 59 | public void AddC16(X86Register16 dest, Int16 value) { 60 | this.writer.Write(new byte[] { 0x66, 0x81 }); 61 | reg_emit16((X86Register16)0x2, dest); 62 | writer.Write(value); 63 | } 64 | public void AddC32(X86Register32 dest, Int32 value) { 65 | this.writer.Write(new byte[] { 0x81 }); 66 | reg_emit32((X86Register32)0x2, dest); 67 | writer.Write(value); 68 | } 69 | 70 | public void AddC8(X86Address dest, Byte value) { 71 | this.writer.Write(new byte[] { 0x80 }); 72 | dest.Emit(writer, (X86Register32)0x2); 73 | writer.Write(value); 74 | } 75 | public void AddC16(X86Address dest, Int16 value) { 76 | this.writer.Write(new byte[] { 0x66, 0x81 }); 77 | dest.Emit(writer, (X86Register32)0x2); 78 | writer.Write(value); 79 | } 80 | public void AddC32(X86Address dest, Int32 value) { 81 | this.writer.Write(new byte[] { 0x81 }); 82 | dest.Emit(writer, (X86Register32)0x2); 83 | writer.Write(value); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Arithmetic/X86Writer.Decrement.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void Dec8(X86Register8 reg) { 15 | writer.Write(new byte[] { 0xFE }); 16 | reg_emit8((X86Register8)1, reg); 17 | } 18 | public void Dec16(X86Register16 reg) { 19 | writer.Write(new byte[] { 0x66, 0xFF }); 20 | reg_emit16((X86Register16)1, reg); 21 | } 22 | public void Dec32(X86Register32 reg) { 23 | writer.Write(new byte[] { 0xFF }); 24 | reg_emit32((X86Register32)1, reg); 25 | } 26 | 27 | public void Dec8(X86Address mem) { 28 | writer.Write(new byte[] { 0xFE }); 29 | mem.Emit(writer, (X86Register8)1); 30 | } 31 | public void Dec16(X86Address mem) { 32 | writer.Write(new byte[] { 0x66, 0xFF }); 33 | mem.Emit(writer, (X86Register8)1); 34 | } 35 | public void Dec32(X86Address mem) { 36 | writer.Write(new byte[] { 0xFF }); 37 | mem.Emit(writer, (X86Register8)1); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Arithmetic/X86Writer.Division.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void Div8(X86Register8 src) { 15 | writer.Write(new byte[] { 0xF6 }); 16 | reg_emit8((X86Register8)6, src); 17 | } 18 | public void Div16(X86Register16 src) { 19 | writer.Write(new byte[] { 0x66, 0xF7 }); 20 | reg_emit16((X86Register16)6, src); 21 | } 22 | public void Div32(X86Register32 src) { 23 | writer.Write(new byte[] { 0xF7 }); 24 | reg_emit32((X86Register32)6, src); 25 | } 26 | 27 | public void Div8(X86Address src) { 28 | writer.Write(new byte[] { 0xF6 }); 29 | src.Emit(writer, (X86Register8)6); 30 | } 31 | public void Div16(X86Address src) { 32 | writer.Write(new byte[] { 0x66, 0xF7 }); 33 | src.Emit(writer, (X86Register8)6); 34 | } 35 | public void Div32(X86Address src) { 36 | writer.Write(new byte[] { 0xF7 }); 37 | src.Emit(writer, (X86Register8)6); 38 | } 39 | 40 | public void IDiv8(X86Register8 src) { 41 | writer.Write(new byte[] { 0xF6 }); 42 | reg_emit8((X86Register8)7, src); 43 | } 44 | public void IDiv16(X86Register16 src) { 45 | writer.Write(new byte[] { 0x66, 0xF7 }); 46 | reg_emit16((X86Register16)7, src); 47 | } 48 | public void IDiv32(X86Register32 src) { 49 | writer.Write(new byte[] { 0xF7 }); 50 | reg_emit32((X86Register32)7, src); 51 | } 52 | 53 | public void IDiv8(X86Address src) { 54 | writer.Write(new byte[] { 0xF6 }); 55 | src.Emit(writer, (X86Register8)7); 56 | } 57 | public void IDiv16(X86Address src) { 58 | writer.Write(new byte[] { 0x66, 0xF7 }); 59 | src.Emit(writer, (X86Register8)7); 60 | } 61 | public void IDiv32(X86Address src) { 62 | writer.Write(new byte[] { 0xF7 }); 63 | src.Emit(writer, (X86Register8)7); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Arithmetic/X86Writer.Increment.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void Inc8(X86Register8 reg) { 15 | writer.Write(new byte[] { 0xFE }); 16 | reg_emit8((X86Register8)0, reg); 17 | } 18 | public void Inc16(X86Register16 reg) { 19 | writer.Write(new byte[] { 0x66, 0xFF }); 20 | reg_emit16((X86Register16)0, reg); 21 | } 22 | public void Inc32(X86Register32 reg) { 23 | writer.Write(new byte[] { 0xFF }); 24 | reg_emit32((X86Register32)0, reg); 25 | } 26 | 27 | public void Inc8(X86Address mem) { 28 | writer.Write(new byte[] { 0xFE }); 29 | mem.Emit(writer, (X86Register8)0); 30 | } 31 | public void Inc16(X86Address mem) { 32 | writer.Write(new byte[] { 0x66, 0xFF }); 33 | mem.Emit(writer, (X86Register8)0); 34 | } 35 | public void Inc32(X86Address mem) { 36 | writer.Write(new byte[] { 0xFF }); 37 | mem.Emit(writer, (X86Register8)0); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Arithmetic/X86Writer.Multiply.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Mul8(X86Register8 src) { 16 | writer.Write(new byte[] { 0xF6 }); 17 | reg_emit8((X86Register8)4, src); 18 | } 19 | public void Mul16(X86Register16 src) { 20 | writer.Write(new byte[] { 0x66, 0xF7 }); 21 | reg_emit16((X86Register16)4, src); 22 | } 23 | public void Mul32(X86Register32 src) { 24 | writer.Write(new byte[] { 0xF7 }); 25 | reg_emit32((X86Register32)4, src); 26 | } 27 | 28 | public void Mul8(X86Address src) { 29 | writer.Write(new byte[] { 0xF6 }); 30 | src.Emit(writer, (X86Register8)4); 31 | } 32 | public void Mul16(X86Address src) { 33 | writer.Write(new byte[] { 0x66, 0xF7 }); 34 | src.Emit(writer, (X86Register8)4); 35 | } 36 | public void Mul32(X86Address src) { 37 | writer.Write(new byte[] { 0xF7 }); 38 | src.Emit(writer, (X86Register8)4); 39 | } 40 | 41 | public void IMul8 (X86Register8 dest, X86Register8 src) { 42 | writer.Write(new byte[] { 0x0F, 0xAE }); 43 | reg_emit8(dest, src); 44 | } 45 | public void IMul16(X86Register16 dest, X86Register16 src) { 46 | writer.Write(new byte[] { 0x66, 0x0F, 0xAF }); 47 | reg_emit16(dest, src); 48 | } 49 | public void IMul32(X86Register32 dest, X86Register32 src) { 50 | writer.Write(new byte[] { 0x0F, 0xAF }); 51 | reg_emit32(dest, src); 52 | } 53 | 54 | public void IMul8(X86Address dest, X86Register8 src) { 55 | writer.Write(new byte[] { 0x00 }); 56 | dest.Emit(writer, src); 57 | } 58 | public void IMul16(X86Address dest, X86Register16 src) { 59 | writer.Write(new byte[] { 0x66, 0x01 }); 60 | dest.Emit(writer, src); 61 | } 62 | public void IMul32(X86Address dest, X86Register32 src) { 63 | writer.Write(new byte[] { 0x01 }); 64 | dest.Emit(writer, src); 65 | } 66 | 67 | public void IMul8(X86Register8 dest, X86Address src) { 68 | writer.Write(new byte[] { 0x02 }); 69 | src.Emit(writer, dest); 70 | } 71 | public void IMul16(X86Register16 dest, X86Address src) { 72 | writer.Write(new byte[] { 0x66, 0x03 }); 73 | src.Emit(writer, dest); 74 | } 75 | public void IMul32(X86Register32 dest, X86Address src) { 76 | writer.Write(new byte[] { 0x03 }); 77 | src.Emit(writer, dest); 78 | } 79 | 80 | public void IMul8(X86Register8 dest, Byte value) { 81 | this.writer.Write(new byte[] { 0x80 }); 82 | reg_emit8(0, dest); 83 | writer.Write(value); 84 | } 85 | public void IMul16(X86Register16 dest, Int16 value) { 86 | this.writer.Write(new byte[] { 0x66, 0x81 }); 87 | reg_emit16(0, dest); 88 | writer.Write(value); 89 | } 90 | public void IMul32(X86Register32 dest, Int32 value) { 91 | this.writer.Write(new byte[] { 0x81 }); 92 | reg_emit32(0, dest); 93 | writer.Write(value); 94 | } 95 | 96 | public void IMul8(X86Address dest, Byte value) { 97 | this.writer.Write(new byte[] { 0x80 }); 98 | dest.Emit(writer, X86Register32.None); 99 | writer.Write(value); 100 | } 101 | public void IMul16(X86Address dest, Int16 value) { 102 | this.writer.Write(new byte[] { 0x66, 0x81 }); 103 | dest.Emit(writer, X86Register32.None); 104 | writer.Write(value); 105 | } 106 | public void IMul32(X86Address dest, Int32 value) { 107 | this.writer.Write(new byte[] { 0x81 }); 108 | dest.Emit(writer, X86Register32.None); 109 | writer.Write(value); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Arithmetic/X86Writer.Negate.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void Negate8(X86Register8 dest) { 15 | writer.Write(new byte[] { 0xF6 }); 16 | reg_emit8((X86Register8)3, dest); 17 | } 18 | public void Negate16(X86Register16 dest) { 19 | writer.Write(new byte[] { 0x66, 0xF7 }); 20 | reg_emit16((X86Register16)3, dest); 21 | } 22 | public void Negate32(X86Register32 dest) { 23 | writer.Write(new byte[] { 0xF7 }); 24 | reg_emit32((X86Register32)3, dest); 25 | } 26 | 27 | public void Negate8(X86Address dest) { 28 | writer.Write(new byte[] { 0xF6 }); 29 | dest.Emit(writer, (X86Register8)3); 30 | } 31 | public void Negate16(X86Address dest) { 32 | writer.Write(new byte[] { 0x66, 0xF7 }); 33 | dest.Emit(writer, (X86Register8)3); 34 | } 35 | public void Negate32(X86Address dest) { 36 | writer.Write(new byte[] { 0xF7 }); 37 | dest.Emit(writer, (X86Register8)3); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Arithmetic/X86Writer.Not.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void Not8(X86Register8 dest) { 15 | writer.Write(new byte[] { 0xF6 }); 16 | reg_emit8((X86Register8)2, dest); 17 | } 18 | public void Not16(X86Register16 dest) { 19 | writer.Write(new byte[] { 0x66, 0xF7 }); 20 | reg_emit16((X86Register16)2, dest); 21 | } 22 | public void Not32(X86Register32 dest) { 23 | writer.Write(new byte[] { 0xF7 }); 24 | reg_emit32((X86Register32)2, dest); 25 | } 26 | 27 | public void Not8(X86Address dest) { 28 | writer.Write(new byte[] { 0xF6 }); 29 | dest.Emit(writer, (X86Register8)2); 30 | } 31 | public void Not16(X86Address dest) { 32 | writer.Write(new byte[] { 0x66, 0xF7 }); 33 | dest.Emit(writer, (X86Register8)2); 34 | } 35 | public void Not32(X86Address dest) { 36 | writer.Write(new byte[] { 0xF7 }); 37 | dest.Emit(writer, (X86Register8)2); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Arithmetic/X86Writer.Subtract.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Sub8(X86Register8 dest, X86Register8 src) { 16 | writer.Write(new byte[] { 0x2A }); 17 | reg_emit8(dest, src); 18 | } 19 | public void Sub16(X86Register16 dest, X86Register16 src) { 20 | writer.Write(new byte[] { 0x66, 0x2B }); 21 | reg_emit16(dest, src); 22 | } 23 | public void Sub32(X86Register32 dest, X86Register32 src) { 24 | writer.Write(new byte[] { 0x2B }); 25 | reg_emit32(dest, src); 26 | } 27 | 28 | public void Sub8(X86Address dest, X86Register8 src) { 29 | writer.Write(new byte[] { 0x28 }); 30 | dest.Emit(writer, src); 31 | } 32 | public void Sub16(X86Address dest, X86Register16 src) { 33 | writer.Write(new byte[] { 0x66, 0x29 }); 34 | dest.Emit(writer, src); 35 | } 36 | public void Sub32(X86Address dest, X86Register32 src) { 37 | writer.Write(new byte[] { 0x29 }); 38 | dest.Emit(writer, src); 39 | } 40 | 41 | public void Sub8(X86Register8 dest, X86Address src) { 42 | writer.Write(new byte[] { 0x2A }); 43 | src.Emit(writer, dest); 44 | } 45 | public void Sub16(X86Register16 dest, X86Address src) { 46 | writer.Write(new byte[] { 0x66, 0x2B }); 47 | src.Emit(writer, dest); 48 | } 49 | public void Sub32(X86Register32 dest, X86Address src) { 50 | writer.Write(new byte[] { 0x2B }); 51 | src.Emit(writer, dest); 52 | } 53 | 54 | public void Sub8(X86Register8 dest, Byte value) { 55 | this.writer.Write(new byte[] { 0x80 }); 56 | reg_emit8((X86Register8)5, dest); 57 | writer.Write(value); 58 | } 59 | public void Sub16(X86Register16 dest, Int16 value) { 60 | this.writer.Write(new byte[] { 0x66, 0x81 }); 61 | reg_emit16((X86Register16)5, dest); 62 | writer.Write(value); 63 | } 64 | public void Sub32(X86Register32 dest, Int32 value) { 65 | this.writer.Write(new byte[] { 0x81 }); 66 | reg_emit32((X86Register32)5, dest); 67 | writer.Write(value); 68 | } 69 | 70 | public void Sub8(X86Address dest, Byte value) { 71 | this.writer.Write(new byte[] { 0x80 }); 72 | dest.Emit(writer, (X86Register32)5); 73 | writer.Write(value); 74 | } 75 | public void Sub16(X86Address dest, Int16 value) { 76 | this.writer.Write(new byte[] { 0x66, 0x81 }); 77 | dest.Emit(writer, (X86Register32)5); 78 | writer.Write(value); 79 | } 80 | public void Sub32(X86Address dest, Int32 value) { 81 | this.writer.Write(new byte[] { 0x81 }); 82 | dest.Emit(writer, (X86Register32)5); 83 | writer.Write(value); 84 | } 85 | 86 | public void Sbb8(X86Register8 dest, X86Register8 src) { 87 | writer.Write(new byte[] { 0x18 }); 88 | reg_emit8(dest, src); 89 | } 90 | public void Sbb16(X86Register16 dest, X86Register16 src) { 91 | writer.Write(new byte[] { 0x66, 0x19 }); 92 | reg_emit16(dest, src); 93 | } 94 | public void Sbb32(X86Register32 dest, X86Register32 src) { 95 | writer.Write(new byte[] { 0x19 }); 96 | reg_emit32(dest, src); 97 | } 98 | 99 | public void Sbb8(X86Address dest, X86Register8 src) { 100 | writer.Write(new byte[] { 0x18 }); 101 | dest.Emit(writer, src); 102 | } 103 | public void Sbb16(X86Address dest, X86Register16 src) { 104 | writer.Write(new byte[] { 0x66, 0x19 }); 105 | dest.Emit(writer, src); 106 | } 107 | public void Sbb32(X86Address dest, X86Register32 src) { 108 | writer.Write(new byte[] { 0x19 }); 109 | dest.Emit(writer, src); 110 | } 111 | 112 | [Obsolete("The use of Sbb8(ref, mem) does not function properly.", true)] 113 | public void Sbb8(X86Register8 dest, X86Address src) { 114 | writer.Write(new byte[] { 0x1A }); 115 | src.Emit(writer, dest); 116 | } 117 | public void Sbb16(X86Register16 dest, X86Address src) { 118 | writer.Write(new byte[] { 0x66, 0x1B }); 119 | src.Emit(writer, dest); 120 | } 121 | public void Sbb32(X86Register32 dest, X86Address src) { 122 | writer.Write(new byte[] { 0x1B }); 123 | src.Emit(writer, dest); 124 | } 125 | 126 | public void Sbb8(X86Register8 dest, Byte value) { 127 | this.writer.Write(new byte[] { 0x80 }); 128 | reg_emit8((X86Register8)3, dest); 129 | writer.Write(value); 130 | } 131 | public void Sbb16(X86Register16 dest, Int16 value) { 132 | this.writer.Write(new byte[] { 0x66, 0x81 }); 133 | reg_emit16((X86Register16)3, dest); 134 | writer.Write(value); 135 | } 136 | public void Sbb32(X86Register32 dest, Int32 value) { 137 | this.writer.Write(new byte[] { 0x81 }); 138 | reg_emit32((X86Register32)3, dest); 139 | writer.Write(value); 140 | } 141 | 142 | public void Sbb8(X86Address dest, Byte value) { 143 | this.writer.Write(new byte[] { 0x80 }); 144 | dest.Emit(writer, (X86Register32)3); 145 | writer.Write(value); 146 | } 147 | public void Sbb16(X86Address dest, Int16 value) { 148 | this.writer.Write(new byte[] { 0x66, 0x81 }); 149 | dest.Emit(writer, (X86Register32)3); 150 | writer.Write(value); 151 | } 152 | public void Sbb32(X86Address dest, Int32 value) { 153 | this.writer.Write(new byte[] { 0x81 }); 154 | dest.Emit(writer, (X86Register32)3); 155 | writer.Write(value); 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008, The Managed.X86 Project 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list 8 | of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list 10 | of conditions and the following disclaimer in the documentation and/or other 11 | materials provided with the distribution. 12 | * Neither the name of the Managed.X86 Project nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without specific 14 | prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 19 | THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 23 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/ControlFlow/X86Writer.Call.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Call(Int32 displacement) { 16 | writer.Write(new byte[] { 0xE8 }); 17 | writer.Write(displacement - 5); 18 | } 19 | public void Call(IntPtr target) { 20 | // Just make the displacement. 21 | Call(target.ToInt32() - this.Position.ToInt32()); 22 | } 23 | public void Call(X86Label label) { 24 | if (label.IsMarked) { 25 | Call(label.Position); 26 | } else { 27 | label.AddPatchRequired(); 28 | writer.Write(new byte[] { 0xE8 }); 29 | writer.Write(0xDEADBEEF); 30 | } 31 | } 32 | public void Call(X86Register32 register) { 33 | this.writer.Write(new byte[] { 0xFF }); 34 | reg_emit32((X86Register32)0x2, register); 35 | //this.writer.Write(direct.ToInt32()); 36 | } 37 | public void Call(X86Address address) { 38 | this.writer.Write(new byte[] { 0xFF }); 39 | address.Emit(writer, (X86Register32)0x2); 40 | } 41 | public void Call_Far(X86Address address) { 42 | this.writer.Write(new byte[] { 0xFF }); 43 | address.Emit(writer, (X86Register32)0x3); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/ControlFlow/X86Writer.Jump.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Jmp(Int32 displacement) { 16 | writer.Write(new byte[] { 0xE9 }); 17 | writer.Write(displacement - 5); 18 | } 19 | public void Jmp(IntPtr target) { 20 | // Just make the displacement. 21 | Jmp(target.ToInt32() - this.Position.ToInt32()); 22 | } 23 | public void Jmp(X86Label label) { 24 | if (label.IsMarked) { 25 | Jmp(label.Position); 26 | } else { 27 | label.AddPatchRequired(); 28 | writer.Write(new byte[] { 0xE9 }); 29 | writer.Write(0xDEADBEEF); 30 | } 31 | } 32 | public void Jmp(X86Register32 register) { 33 | this.writer.Write(new byte[] { 0xFF }); 34 | reg_emit32((X86Register32)0x4, register); 35 | //this.writer.Write(direct.ToInt32()); 36 | } 37 | public void Jmp(X86Address address) { 38 | this.writer.Write(new byte[] { 0xFF }); 39 | address.Emit(writer, (X86Register32)0x4); 40 | } 41 | public void JmpFar(X86Address address) { 42 | this.writer.Write(new byte[] { 0xFF }); 43 | address.Emit(writer, (X86Register32)0x5); 44 | } 45 | 46 | public void Jmp(X86ConditionCode cond, X86Label label) { 47 | if (label.IsMarked) { 48 | Jmp(cond, label.Position.ToInt32() - this.Position.ToInt32()); 49 | } else { 50 | label.AddPatchRequired(); 51 | writer.Write(new byte[] { 0x0F, (byte)(0x80 | (byte)cond) }); 52 | writer.Write(0xDEADBEEF); 53 | } 54 | } 55 | 56 | public void Jmp(X86ConditionCode cond, Int32 displacement) { 57 | if (is_imm8(displacement - 2)) { 58 | writer.Write(new byte[] { (byte)(0x70 | (byte)cond) }); 59 | imm_emit8(displacement - 2); 60 | } else { 61 | writer.Write(new byte[] { 0x0F, (byte)(0x80 | (byte)cond) }); 62 | imm_emit32(displacement - 6); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/ControlFlow/X86Writer.Patch.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | /// 16 | /// Patches the instruction at the current position to go to the specified address. 17 | /// 18 | /// Used with Jump and Call instructions 19 | /// 20 | /// The target address 21 | 22 | public void Patch(IntPtr target) { 23 | int disp, size = 0; 24 | int peek = stream.ReadByte(); 25 | int pos = this.Position.ToInt32(); 26 | switch (peek) { 27 | #region call, jump32 28 | case 0xe8: 29 | case 0xe9: ++size; break; /* call, jump32 */ 30 | #endregion 31 | #region prefix for 32-bit disp 32 | case 0x0f: { 33 | int peek2 = stream.ReadByte(); 34 | if (!(peek2 >= 0x70 && peek2 <= 0x8f)) throw new NotSupportedException(); 35 | ++size; ++pos; break; /* prefix for 32-bit disp */ 36 | } 37 | #endregion 38 | #region loop 39 | case 0xe0: 40 | case 0xe1: 41 | case 0xe2: /* loop */ 42 | #endregion 43 | case 0xeb: /* jump8 */ 44 | default: 45 | if (peek >= 0x70 && peek <= 0x7f) { 46 | break; /* conditional jump opcodes */ 47 | } else { 48 | throw new NotSupportedException(); 49 | } 50 | } 51 | disp = (target.ToInt32()) - pos; 52 | if (size != 0) imm_emit32(disp - 4); 53 | else if (is_imm8(disp - 1)) imm_emit8(disp - 1); 54 | else throw new NotSupportedException(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/DataTypes/X86Address.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | using System.IO; 12 | 13 | namespace Managed.X86 14 | { 15 | public struct X86Address { 16 | public readonly X86Register32 BaseRegister; 17 | public readonly Int32 Offset; 18 | public readonly X86Register32 IndexRegister; 19 | public readonly Byte IndexShift; 20 | 21 | public X86Address(X86Register32 baseRegister, Int32 offset) { 22 | this.BaseRegister = baseRegister; 23 | this.Offset = offset; 24 | this.IndexRegister = X86Register32.None; 25 | this.IndexShift = 0; 26 | } 27 | 28 | public X86Address(X86Register32 baseRegister, Int32 offset, X86Register32 indexRegister, byte indexShift) { 29 | this.BaseRegister = baseRegister ; 30 | this.Offset = offset; 31 | this.IndexRegister = indexRegister; 32 | this.IndexShift = indexShift; 33 | } 34 | 35 | internal void Emit(BinaryWriter writer, X86Register8 otherReg) { 36 | this.Emit(writer, (byte)otherReg); 37 | } 38 | internal void Emit(BinaryWriter writer, X86Register16 otherReg) { 39 | this.Emit(writer, (byte)otherReg); 40 | } 41 | internal void Emit(BinaryWriter writer, X86Register32 otherReg) { 42 | this.Emit(writer, (byte)otherReg); 43 | } 44 | private void Emit(BinaryWriter writer, byte otherReg) { 45 | if (otherReg == 0xFF) { otherReg = 0; } 46 | if (IndexRegister == X86Register32.None) { 47 | if (this.BaseRegister == X86Register32.None) { 48 | mem_emit( 49 | writer, 50 | otherReg, 51 | this.Offset 52 | ); 53 | } else { 54 | membase_emit( 55 | writer, 56 | otherReg, 57 | this.BaseRegister, 58 | this.Offset 59 | ); 60 | } 61 | } else { 62 | memindex_emit( 63 | writer, 64 | otherReg, 65 | this.BaseRegister, 66 | this.Offset, 67 | this.IndexRegister, 68 | this.IndexShift 69 | ); 70 | } 71 | } 72 | 73 | private void address_byte(BinaryWriter writer, Byte m, Byte o, Byte r) { 74 | writer.Write( 75 | (byte) 76 | (((m & 0x03) << 6) 77 | | ((o & 0x07) << 3) 78 | | (r & 0x07) 79 | ) 80 | ); 81 | } 82 | private void mem_emit(BinaryWriter writer, Byte r, Int32 dest) { 83 | address_byte(writer, 0, (byte)r, 5); 84 | writer.Write(dest); 85 | } 86 | private void membase_emit(BinaryWriter writer, Byte r, X86Register32 basereg, Int32 disp) { 87 | do { 88 | if ((basereg) == X86Register32.ESP) { 89 | if ((disp) == 0) { 90 | address_byte(writer, 0, (byte)r, (byte)X86Register32.ESP); 91 | address_byte(writer, 0, (byte)X86Register32.ESP, (byte)X86Register32.ESP); 92 | } else if (X86Writer.is_imm8(disp)) { 93 | address_byte(writer, 1, (byte)r, (byte)X86Register32.ESP); 94 | address_byte(writer, 0, (byte)X86Register32.ESP, (byte)X86Register32.ESP); 95 | writer.Write((byte)(disp)); 96 | } else { 97 | address_byte(writer, 2, (byte)r, (byte)X86Register32.ESP); 98 | address_byte(writer, 0, (byte)X86Register32.ESP, (byte)X86Register32.ESP); 99 | writer.Write(disp); 100 | } 101 | break; 102 | } else if (disp == 0 && basereg != X86Register32.EBP) { 103 | address_byte(writer, 0, (byte)r, (byte)basereg); 104 | } else if (X86Writer.is_imm8(disp)) { 105 | address_byte(writer, 1, (byte)r, (byte)basereg); 106 | writer.Write((byte)(disp)); 107 | } else { 108 | address_byte(writer, 2, (byte)r, (byte)basereg); 109 | writer.Write(disp); 110 | } 111 | } while (false); 112 | } 113 | private void memindex_emit(BinaryWriter writer, Byte r, X86Register32 basereg, Int32 disp, X86Register32 indexreg, Byte shift) { 114 | if (basereg == X86Register32.None) { 115 | address_byte(writer, 0, (byte)r, 4); 116 | address_byte(writer, (byte)shift, (byte)indexreg, 5); 117 | writer.Write((Int32)disp); 118 | } else if (disp == 0 && basereg == X86Register32.EBP) { 119 | address_byte(writer, 0, (byte)r, 4); 120 | address_byte(writer, (byte)shift, (byte)indexreg, (byte)basereg); 121 | } else if (X86Writer.is_imm8(disp)) { 122 | address_byte(writer, 1, (byte)r, 4); 123 | address_byte(writer, (byte)shift, (byte)indexreg, (byte)basereg); 124 | writer.Write((Byte)disp); 125 | } else { 126 | address_byte(writer, 2, (byte)r, 4); 127 | address_byte(writer, (byte)shift, (byte)indexreg, 5); 128 | writer.Write((Int32)disp); 129 | } 130 | } 131 | 132 | public override string ToString() { 133 | if (IndexRegister == X86Register32.None) { 134 | if (this.BaseRegister == X86Register32.None) { 135 | return String.Format("[{0:X}]", this.Offset); 136 | } else { 137 | return String.Format( 138 | "[{0}+{1}]", 139 | this.BaseRegister, 140 | this.Offset 141 | ).Replace("+-", "-"); 142 | } 143 | } else { 144 | return String.Format( 145 | "[{0}+{1}+{2}*{3}]", 146 | this.BaseRegister, 147 | this.Offset, 148 | this.IndexRegister, 149 | 1 << this.IndexShift 150 | ).Replace("+-", "-"); 151 | } 152 | } 153 | } 154 | } -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/DataTypes/X86ConditionCode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | public enum X86ConditionCode { 14 | Overflow = 0x0, 15 | 16 | NoOverflow = 0x1, 17 | 18 | Below = 0x2, 19 | NotAboveOrEqual = 0x2, 20 | 21 | NotBelow = 0x3, 22 | AboveOrEqual = 0x3, 23 | 24 | Equal = 0x4, 25 | Zero = 0x4, 26 | 27 | NotEqual = 0x5, 28 | NotZero = 0x5, 29 | 30 | BelowOrEqual = 0x6, 31 | NotAbove = 0x6, 32 | 33 | NotBelowOrEqual = 0x7, 34 | Above = 0x7, 35 | 36 | Sign = 0x8, 37 | 38 | NotSign = 0x9, 39 | 40 | Parity = 0xA, 41 | ParityEven = 0xA, 42 | 43 | NotParity = 0xB, 44 | ParityOdd = 0xB, 45 | 46 | LessThan = 0xC, 47 | NotGreaterThanEqualTo = 0xC, 48 | 49 | GreaterThan = 0xD, 50 | NotLessThanEqualTo = 0xD, 51 | 52 | LessThanEqualTo = 0xE, 53 | NotGreaterThan = 0xE, 54 | 55 | GreaterThanEqualTo = 0xF, 56 | NotLessThan = 0xF, 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/DataTypes/X86Label.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | using System.Collections.Generic; 12 | 13 | namespace Managed.X86 14 | { 15 | public class X86Label { 16 | readonly X86Writer writer; 17 | IntPtr? mark; 18 | 19 | List patches = new List(); 20 | 21 | internal X86Label(X86Writer writer) { 22 | this.writer = writer; 23 | } 24 | internal X86Label(X86Writer writer, IntPtr position) 25 | : this(writer) { 26 | mark = position; 27 | } 28 | 29 | public void Mark() { 30 | if (!this.mark.HasValue) { 31 | IntPtr currentPosition; 32 | this.mark = currentPosition = this.writer.Position; 33 | if (patches.Count > 0) { 34 | foreach (IntPtr patch in patches) { 35 | writer.Position = patch; 36 | writer.Patch(currentPosition); 37 | } 38 | writer.Position = currentPosition; 39 | } 40 | } 41 | } 42 | 43 | public bool IsMarked { get { return this.mark.HasValue; } } 44 | 45 | public IntPtr Position { 46 | get { 47 | if (!mark.HasValue) { throw new NotSupportedException(); } 48 | return mark.Value; 49 | } 50 | } 51 | 52 | internal void AddPatchRequired() { 53 | patches.Add(writer.Position); 54 | } 55 | 56 | public override string ToString() { 57 | if (this.mark.HasValue) { 58 | return String.Format("label:0x{0:X8}", this.mark.Value.ToInt32()); 59 | } else 60 | { 61 | return String.Format("label:0x????????"); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/DataTypes/X86Register16.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | public enum X86Register16 : byte { 14 | None = 0xff, 15 | 16 | AX = 0, 17 | CX = 1, 18 | DX = 2, 19 | BX = 3, 20 | SP = 4, 21 | BP = 5, 22 | SI = 6, 23 | DI = 7, 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/DataTypes/X86Register32.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | public enum X86Register32 : byte { 14 | None = 0xff, 15 | 16 | EAX = 0, 17 | ECX = 1, 18 | EDX = 2, 19 | EBX = 3, 20 | ESP = 4, 21 | EBP = 5, 22 | ESI = 6, 23 | EDI = 7, 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/DataTypes/X86Register8.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | public enum X86Register8 : byte { 14 | AL = 0, 15 | CL = 1, 16 | DL = 2, 17 | BL = 3, 18 | AH = 4, 19 | CH = 5, 20 | DH = 6, 21 | BH = 7, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/DataTypes/X86ShiftOpCode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | public enum X86ShiftOpCode { 14 | SHLD = 0, // TODO: Is this value correct? 15 | SHLR = 1, // TODO: Is this value correct? 16 | ROL = 0, 17 | ROR = 1, 18 | RCL = 2, 19 | RCR = 3, 20 | SHL = 4, 21 | SHR = 5, 22 | SAR = 7, 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/General/X86Writer.Compare.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Cmp8(X86Register8 dest, X86Register8 src) { 16 | writer.Write(new byte[] { 0x38 }); 17 | reg_emit8(dest, src); 18 | } 19 | public void Cmp16(X86Register16 dest, X86Register16 src) { 20 | writer.Write(new byte[] { 0x66, 0x39 }); 21 | reg_emit16(dest, src); 22 | } 23 | public void Cmp32(X86Register32 dest, X86Register32 src) { 24 | writer.Write(new byte[] { 0x39 }); 25 | reg_emit32(dest, src); 26 | } 27 | 28 | public void Cmp8(X86Register8 dest, X86Address src) { 29 | writer.Write(new byte[] { 0x3A }); 30 | src.Emit(writer, dest); 31 | } 32 | public void Cmp16(X86Register16 dest, X86Address src) { 33 | writer.Write(new byte[] { 0x66, 0x3B }); 34 | src.Emit(writer, dest); 35 | } 36 | public void Cmp32(X86Register32 dest, X86Address src) { 37 | writer.Write(new byte[] { 0x3B }); 38 | src.Emit(writer, dest); 39 | } 40 | 41 | public void Cmp8(X86Address dest, X86Register8 src) { 42 | writer.Write(new byte[] { 0x38 }); 43 | dest.Emit(writer, src); 44 | } 45 | public void Cmp16(X86Address dest, X86Register16 src) { 46 | writer.Write(new byte[] { 0x66, 0x39 }); 47 | dest.Emit(writer, src); 48 | } 49 | public void Cmp32(X86Address dest, X86Register32 src) { 50 | writer.Write(new byte[] { 0x38 }); 51 | dest.Emit(writer, src); 52 | } 53 | 54 | public void Cmp8(X86Register8 dest, Byte src) { 55 | writer.Write(new byte[] { 0x80 }); 56 | reg_emit8((X86Register8)7, dest); 57 | imm_emit8(src); 58 | } 59 | public void Cmp16(X86Register16 dest, Int16 src) { 60 | writer.Write(new byte[] { 0x66, 0x81 }); 61 | reg_emit16((X86Register16)7, dest); 62 | imm_emit16(src); 63 | } 64 | public void Cmp32(X86Register32 dest, Int32 src) { 65 | writer.Write(new byte[] { 0x81 }); 66 | reg_emit32((X86Register32)7, dest); 67 | imm_emit32(src); 68 | } 69 | 70 | public void Cmp8(X86Address dest, Byte src) { 71 | writer.Write(new byte[] { 0x80 }); 72 | dest.Emit(writer, (X86Register8)7); 73 | imm_emit8(src); 74 | } 75 | public void Cmp16(X86Address dest, Int16 src) { 76 | writer.Write(new byte[] { 0x66, 0x81 }); 77 | dest.Emit(writer, (X86Register8)7); 78 | imm_emit16(src); 79 | } 80 | public void Cmp32(X86Address dest, Int32 src) { 81 | writer.Write(new byte[] { 0x81 }); 82 | dest.Emit(writer, (X86Register8)7); 83 | imm_emit32(src); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/General/X86Writer.Move.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Mov8(X86Register8 dest, Byte value) { 16 | this.writer.Write(new byte[] { 0xc6 }); 17 | reg_emit8(0, dest); 18 | writer.Write(value); 19 | } 20 | public void Mov16(X86Register16 dest, Int16 value) { 21 | this.writer.Write(new byte[] { 0x66, 0xc7 }); 22 | reg_emit16(0, dest); 23 | writer.Write(value); 24 | } 25 | public void Mov32(X86Register32 dest, Int32 value) { 26 | this.writer.Write(new byte[] { 0xc7 }); 27 | reg_emit32(0, dest); 28 | writer.Write(value); 29 | } 30 | 31 | public void Mov8(X86Address dest, Byte value) { 32 | this.writer.Write(new byte[] { 0xc6 }); 33 | dest.Emit(writer, X86Register32.None); 34 | this.writer.Write(value); 35 | } 36 | public void Mov16(X86Address dest, Int16 value) { 37 | this.writer.Write(new byte[] { 0x66, 0xc7 }); 38 | dest.Emit(writer, X86Register32.None); 39 | this.writer.Write(value); 40 | } 41 | public void Mov32(X86Address dest, Int32 value) { 42 | this.writer.Write(new byte[] { 0xc7 }); 43 | dest.Emit(writer, X86Register32.None); 44 | this.writer.Write(value); 45 | } 46 | 47 | public void Mov8(X86Address dest, X86Register8 src) { 48 | this.writer.Write(new byte[] { 0x88 }); 49 | dest.Emit(writer, src); 50 | } 51 | public void Mov16(X86Address dest, X86Register16 src) { 52 | this.writer.Write(new byte[] { 0x66, 0x89 }); 53 | dest.Emit(writer, src); 54 | } 55 | public void Mov32(X86Address dest, X86Register32 src) { 56 | this.writer.Write(new byte[] { 0x89 }); 57 | dest.Emit(writer, src); 58 | } 59 | 60 | public void Mov8(X86Register8 dest, X86Address src) { 61 | this.writer.Write(new byte[] { 0x8a }); 62 | src.Emit(writer, dest); 63 | } 64 | public void Mov16(X86Register16 dest, X86Address src) { 65 | this.writer.Write(new byte[] { 0x66, 0x8b }); 66 | src.Emit(writer, dest); 67 | } 68 | public void Mov32(X86Register32 dest, X86Address src) { 69 | this.writer.Write(new byte[] { 0x8b }); 70 | src.Emit(writer, dest); 71 | } 72 | 73 | public void Mov8(X86Register8 dest, X86Register8 src) { 74 | writer.Write(new byte[] { 0x8a }); 75 | reg_emit8(dest, src); 76 | } 77 | public void Mov16(X86Register16 dest, X86Register16 src) { 78 | writer.Write(new byte[] { 0x66, 0x8b }); 79 | reg_emit16(dest, src); 80 | } 81 | public void Mov32(X86Register32 dest, X86Register32 src) { 82 | writer.Write(new byte[] { 0x8b }); 83 | reg_emit32(dest, src); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/IO/X86Writer.In.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | /// 16 | /// in imm 17 | /// 18 | /// Reads data from the specified I/O port, and sets the AL register 19 | /// 20 | public void In8(Byte port) { 21 | writer.Write(new byte[] { 0xE4 }); 22 | writer.Write(port); 23 | } 24 | /// 25 | /// in imm 26 | /// 27 | /// Reads data from the specified I/O port, and sets the AX register 28 | /// 29 | public void In16(Byte port) { 30 | writer.Write(new byte[] { 0x66, 0xE5 }); 31 | writer.Write(port); 32 | } 33 | /// 34 | /// in imm 35 | /// 36 | /// Reads data from the specified I/O port, and sets the EAX register 37 | /// 38 | public void In32(Byte port) { 39 | writer.Write(new byte[] { 0xE5 }); 40 | writer.Write(port); 41 | } 42 | 43 | /// 44 | /// in 45 | /// 46 | /// Reads data from an I/O port specified in DX, and sets the AL register 47 | /// 48 | public void In8() { 49 | writer.Write(new byte[] { 0xEC }); 50 | } 51 | /// 52 | /// in 53 | /// 54 | /// Reads data from an I/O port specified in DX, and sets the AX register 55 | /// 56 | public void In16() { 57 | writer.Write(new byte[] { 0x66, 0xED }); 58 | } 59 | /// 60 | /// in 61 | /// 62 | /// Reads data from an I/O port specified in DX, and sets the EAX register 63 | /// 64 | public void In32() { 65 | writer.Write(new byte[] { 0xED }); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/IO/X86Writer.Out.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | /// 16 | /// out imm 17 | /// 18 | /// Writes data from the specified I/O port, with the value from the AL register 19 | /// 20 | public void Out8(Byte port) { 21 | writer.Write(new byte[] { 0xE6 }); 22 | writer.Write(port); 23 | } 24 | /// 25 | /// out imm 26 | /// 27 | /// Writes data from the specified I/O port, with the value from the AX register 28 | /// 29 | public void Out16(Byte port) { 30 | writer.Write(new byte[] { 0x66, 0xE7 }); 31 | writer.Write(port); 32 | } 33 | /// 34 | /// out imm 35 | /// 36 | /// Writes data from the specified I/O port, with the value from the EAX register 37 | /// 38 | public void Out32(Byte port) { 39 | writer.Write(new byte[] { 0xE7 }); 40 | writer.Write(port); 41 | } 42 | 43 | /// 44 | /// out 45 | /// 46 | /// Writes data from an I/O port specified in DX, with the value from the AL register 47 | /// 48 | public void Out8() { 49 | writer.Write(new byte[] { 0xEE }); 50 | } 51 | /// 52 | /// out 53 | /// 54 | /// Writes data from an I/O port specified in DX, with the value from the AX register 55 | /// 56 | public void Out16() { 57 | writer.Write(new byte[] { 0x66, 0xEF }); 58 | } 59 | /// 60 | /// out 61 | /// 62 | /// Writes data from an I/O port specified in DX, with the value from the EAX register 63 | /// 64 | public void Out32() { 65 | writer.Write(new byte[] { 0xEF }); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Interlock/X86Writer.CompareExchange.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void CmpXChg8(X86Register8 dest, X86Register8 src) { 15 | writer.Write(new byte[] { 0x0F, 0xB0 }); 16 | reg_emit8(src, dest); 17 | } 18 | public void CmpXChg16(X86Register16 dest, X86Register16 src) { 19 | writer.Write(new byte[] { 0x66, 0x0F, 0xB1 }); 20 | reg_emit16(src, dest); 21 | } 22 | public void CmpXChg32(X86Register32 dest, X86Register32 src) { 23 | writer.Write(new byte[] { 0x0F, 0xB1 }); 24 | reg_emit32(src, dest); 25 | } 26 | 27 | public void CmpXChg8(X86Address dest, X86Register8 src) { 28 | writer.Write(new byte[] { 0x0F, 0xB0 }); 29 | dest.Emit(writer, src); 30 | } 31 | public void CmpXChg16(X86Address dest, X86Register16 src) { 32 | writer.Write(new byte[] { 0x66, 0x0F, 0xB1 }); 33 | dest.Emit(writer, src); 34 | } 35 | public void CmpXChg32(X86Address dest, X86Register32 src) { 36 | writer.Write(new byte[] { 0x0F, 0xB1 }); 37 | dest.Emit(writer, src); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Logical/X86Writer.And.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void And8(X86Register8 dest, X86Register8 src) { 16 | writer.Write(new byte[] { 0x20 }); 17 | reg_emit8(dest, src); 18 | } 19 | public void And16(X86Register16 dest, X86Register16 src) { 20 | writer.Write(new byte[] { 0x66, 0x21 }); 21 | reg_emit16(dest, src); 22 | } 23 | public void And32(X86Register32 dest, X86Register32 src) { 24 | writer.Write(new byte[] { 0x21 }); 25 | reg_emit32(dest, src); 26 | } 27 | 28 | public void And8(X86Address dest, X86Register8 src) { 29 | writer.Write(new byte[] { 0x20 }); 30 | dest.Emit(writer, src); 31 | } 32 | public void And16(X86Address dest, X86Register16 src) { 33 | writer.Write(new byte[] { 0x66, 0x21 }); 34 | dest.Emit(writer, src); 35 | } 36 | public void And32(X86Address dest, X86Register32 src) { 37 | writer.Write(new byte[] { 0x21 }); 38 | dest.Emit(writer, src); 39 | } 40 | 41 | public void And8(X86Register8 dest, X86Address src) { 42 | writer.Write(new byte[] { 0x22 }); 43 | src.Emit(writer, dest); 44 | } 45 | public void And16(X86Register16 dest, X86Address src) { 46 | writer.Write(new byte[] { 0x66, 0x23 }); 47 | src.Emit(writer, dest); 48 | } 49 | public void And32(X86Register32 dest, X86Address src) { 50 | writer.Write(new byte[] { 0x23 }); 51 | src.Emit(writer, dest); 52 | } 53 | 54 | public void And8(X86Register8 dest, Byte value) { 55 | this.writer.Write(new byte[] { 0x80 }); 56 | reg_emit8((X86Register8)4, dest); 57 | writer.Write(value); 58 | } 59 | public void And16(X86Register16 dest, Int16 value) { 60 | this.writer.Write(new byte[] { 0x66, 0x81 }); 61 | reg_emit16((X86Register16)4, dest); 62 | writer.Write(value); 63 | } 64 | public void And32(X86Register32 dest, Int32 value) { 65 | this.writer.Write(new byte[] { 0x81 }); 66 | reg_emit32((X86Register32)4, dest); 67 | writer.Write(value); 68 | } 69 | 70 | public void And8(X86Address dest, Byte value) { 71 | this.writer.Write(new byte[] { 0x80 }); 72 | dest.Emit(writer, (X86Register8)0x4); 73 | writer.Write(value); 74 | } 75 | public void And16(X86Address dest, Int16 value) { 76 | this.writer.Write(new byte[] { 0x66, 0x81 }); 77 | dest.Emit(writer, (X86Register16)0x4); 78 | writer.Write(value); 79 | } 80 | public void And32(X86Address dest, Int32 value) { 81 | this.writer.Write(new byte[] { 0x81 }); 82 | dest.Emit(writer, (X86Register32)0x4); 83 | writer.Write(value); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Logical/X86Writer.Or.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Or8(X86Register8 dest, X86Register8 src) { 16 | writer.Write(new byte[] { 0x08 }); 17 | reg_emit8(dest, src); 18 | } 19 | public void Or16(X86Register16 dest, X86Register16 src) { 20 | writer.Write(new byte[] { 0x66, 0x09 }); 21 | reg_emit16(dest, src); 22 | } 23 | public void Or32(X86Register32 dest, X86Register32 src) { 24 | writer.Write(new byte[] { 0x09 }); 25 | reg_emit32(dest, src); 26 | } 27 | 28 | public void Or8(X86Address dest, X86Register8 src) { 29 | writer.Write(new byte[] { 0x08 }); 30 | dest.Emit(writer, src); 31 | } 32 | public void Or16(X86Address dest, X86Register16 src) { 33 | writer.Write(new byte[] { 0x66, 0x09 }); 34 | dest.Emit(writer, src); 35 | } 36 | public void Or32(X86Address dest, X86Register32 src) { 37 | writer.Write(new byte[] { 0x09 }); 38 | dest.Emit(writer, src); 39 | } 40 | 41 | public void Or8(X86Register8 dest, X86Address src) { 42 | writer.Write(new byte[] { 0x0A }); 43 | src.Emit(writer, dest); 44 | } 45 | public void Or16(X86Register16 dest, X86Address src) { 46 | writer.Write(new byte[] { 0x66, 0x0B }); 47 | src.Emit(writer, dest); 48 | } 49 | public void Or32(X86Register32 dest, X86Address src) { 50 | writer.Write(new byte[] { 0x0B }); 51 | src.Emit(writer, dest); 52 | } 53 | 54 | public void Or8(X86Register8 dest, Byte value) { 55 | this.writer.Write(new byte[] { 0x80 }); 56 | reg_emit8((X86Register8)1, dest); 57 | writer.Write(value); 58 | } 59 | public void Or16(X86Register16 dest, Int16 value) { 60 | this.writer.Write(new byte[] { 0x66, 0x81 }); 61 | reg_emit16((X86Register16)1, dest); 62 | writer.Write(value); 63 | } 64 | public void Or32(X86Register32 dest, Int32 value) { 65 | this.writer.Write(new byte[] { 0x81 }); 66 | reg_emit32((X86Register32)1, dest); 67 | writer.Write(value); 68 | } 69 | 70 | public void Or8(X86Address dest, Byte value) { 71 | this.writer.Write(new byte[] { 0x80 }); 72 | dest.Emit(writer, (X86Register8)0x1); 73 | writer.Write(value); 74 | } 75 | public void Or16(X86Address dest, Int16 value) { 76 | this.writer.Write(new byte[] { 0x66, 0x81 }); 77 | dest.Emit(writer, (X86Register16)0x1); 78 | writer.Write(value); 79 | } 80 | public void Or32(X86Address dest, Int32 value) { 81 | this.writer.Write(new byte[] { 0x81 }); 82 | dest.Emit(writer, (X86Register32)0x1); 83 | writer.Write(value); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Logical/X86Writer.Xor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Xor8 (X86Register8 dest, X86Register8 src) { 16 | writer.Write(new byte[] { 0x30 }); 17 | reg_emit8(dest, src); 18 | } 19 | public void Xor16(X86Register16 dest, X86Register16 src) { 20 | writer.Write(new byte[] { 0x66, 0x31 }); 21 | reg_emit16(dest, src); 22 | } 23 | public void Xor32(X86Register32 dest, X86Register32 src) { 24 | writer.Write(new byte[] { 0x31 }); 25 | reg_emit32(dest, src); 26 | } 27 | 28 | public void Xor8(X86Address dest, X86Register8 src) { 29 | writer.Write(new byte[] { 0x30 }); 30 | dest.Emit(writer, src); 31 | } 32 | public void Xor16(X86Address dest, X86Register16 src) { 33 | writer.Write(new byte[] { 0x66, 0x31 }); 34 | dest.Emit(writer, src); 35 | } 36 | public void Xor32(X86Address dest, X86Register32 src) { 37 | writer.Write(new byte[] { 0x31 }); 38 | dest.Emit(writer, src); 39 | } 40 | 41 | public void Xor8(X86Register8 dest, X86Address src) { 42 | writer.Write(new byte[] { 0x32 }); 43 | src.Emit(writer, dest); 44 | } 45 | public void Xor16(X86Register16 dest, X86Address src) { 46 | writer.Write(new byte[] { 0x66, 0x33 }); 47 | src.Emit(writer, dest); 48 | } 49 | public void Xor32(X86Register32 dest, X86Address src) { 50 | writer.Write(new byte[] { 0x33 }); 51 | src.Emit(writer, dest); 52 | } 53 | 54 | public void Xor8(X86Register8 dest, Byte value) { 55 | this.writer.Write(new byte[] { 0x80 }); 56 | reg_emit8((X86Register8)6, dest); 57 | writer.Write(value); 58 | } 59 | public void Xor16(X86Register16 dest, Int16 value) { 60 | this.writer.Write(new byte[] { 0x66, 0x81 }); 61 | reg_emit16((X86Register16)6, dest); 62 | writer.Write(value); 63 | } 64 | public void Xor32(X86Register32 dest, Int32 value) { 65 | this.writer.Write(new byte[] { 0x81 }); 66 | reg_emit32((X86Register32)6, dest); 67 | writer.Write(value); 68 | } 69 | 70 | public void Xor8(X86Address dest, Byte value) { 71 | this.writer.Write(new byte[] { 0x80 }); 72 | dest.Emit(writer, (X86Register8)6); 73 | writer.Write(value); 74 | } 75 | public void Xor16(X86Address dest, Int16 value) { 76 | this.writer.Write(new byte[] { 0x66, 0x81 }); 77 | dest.Emit(writer, (X86Register16)6); 78 | writer.Write(value); 79 | } 80 | public void Xor32(X86Address dest, Int32 value) { 81 | this.writer.Write(new byte[] { 0x81 }); 82 | dest.Emit(writer, (X86Register32)6); 83 | writer.Write(value); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Prefixes/X86Writer.Lock.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void LockPrefix() { 15 | writer.Write(new byte[] { 0xF0 }); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Prefixes/X86Writer.Repeat.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void Repeat() { writer.Write(new byte[] { 0xF3 }); } 15 | public void RepeatZero() { writer.Write(new byte[] { 0xF3 }); } 16 | public void RepeatEqual() { writer.Write(new byte[] { 0xF3 }); } 17 | 18 | public void RepeatNotZero() { writer.Write(new byte[] { 0xF2 }); } 19 | public void RepeatNotEqual() { writer.Write(new byte[] { 0xF2 }); } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Shift/X86Writer.ShiftLeft.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void Shl8(X86Register8 reg, byte count) { 15 | if (count == 1) { 16 | writer.Write(new byte[] { 0xD0 }); 17 | reg_emit8((X86Register8)4, reg); 18 | } else { 19 | writer.Write(new byte[] { 0xC0 }); 20 | reg_emit8((X86Register8)4, reg); 21 | imm_emit8(count); 22 | } 23 | } 24 | public void Shl16(X86Register16 reg, byte count) { 25 | if (count == 1) { 26 | writer.Write(new byte[] { 0x66, 0xD1 }); 27 | reg_emit16((X86Register16)4, reg); 28 | } else { 29 | writer.Write(new byte[] { 0x66, 0xC1 }); 30 | reg_emit16((X86Register16)4, reg); 31 | imm_emit8(count); 32 | } 33 | } 34 | public void Shl32(X86Register32 reg, byte count) { 35 | if (count == 1) { 36 | writer.Write(new byte[] { 0xD1 }); 37 | reg_emit32((X86Register32)4, reg); 38 | } else { 39 | writer.Write(new byte[] { 0xC1 }); 40 | reg_emit32((X86Register32)4, reg); 41 | imm_emit8(count); 42 | } 43 | } 44 | 45 | public void Shl8(X86Address mem, byte count) { 46 | if (count == 1) { 47 | writer.Write(new byte[] { 0xD0 }); 48 | mem.Emit(writer, (X86Register8)4); 49 | } else { 50 | writer.Write(new byte[] { 0xC0 }); 51 | mem.Emit(writer, (X86Register8)4); 52 | imm_emit8(count); 53 | } 54 | } 55 | public void Shl16(X86Address mem, byte count) { 56 | if (count == 1) { 57 | writer.Write(new byte[] { 0x66, 0xD1 }); 58 | mem.Emit(writer, (X86Register8)4); 59 | } else { 60 | writer.Write(new byte[] { 0x66, 0xC1 }); 61 | mem.Emit(writer, (X86Register8)4); 62 | imm_emit8(count); 63 | } 64 | } 65 | public void Shl32(X86Address mem, byte count) { 66 | if (count == 1) { 67 | writer.Write(new byte[] { 0xD1 }); 68 | mem.Emit(writer, (X86Register8)4); 69 | } else { 70 | writer.Write(new byte[] { 0xC1 }); 71 | mem.Emit(writer, (X86Register8)4); 72 | imm_emit8(count); 73 | } 74 | } 75 | 76 | public void Shl8(X86Register8 reg) { 77 | writer.Write(new byte[] { 0xD2 }); 78 | reg_emit8((X86Register8)4, reg); 79 | } 80 | public void Shl16(X86Register16 reg) { 81 | writer.Write(new byte[] { 0x66, 0xD3 }); 82 | reg_emit16((X86Register16)4, reg); 83 | } 84 | public void Shl32(X86Register32 reg) { 85 | writer.Write(new byte[] { 0xD3 }); 86 | reg_emit32((X86Register32)4, reg); 87 | } 88 | 89 | public void Shl8(X86Address mem) { 90 | writer.Write(new byte[] { 0xD2 }); 91 | mem.Emit(writer, (X86Register8)4); 92 | } 93 | public void Shl16(X86Address mem) { 94 | writer.Write(new byte[] { 0x66, 0xD3 }); 95 | mem.Emit(writer, (X86Register8)4); 96 | } 97 | public void Shl32(X86Address mem) { 98 | writer.Write(new byte[] { 0xD3 }); 99 | mem.Emit(writer, (X86Register8)4); 100 | } 101 | 102 | public void Shl64(X86Register32 left, X86Register32 right, byte count) { 103 | writer.Write(new byte[] { 0x0F, 0xA4 }); 104 | reg_emit32(right, left); 105 | imm_emit8(count); 106 | } 107 | public void Shl64(X86Address left, X86Register32 right, byte count) { 108 | writer.Write(new byte[] { 0x0F, 0xA4 }); 109 | left.Emit(writer, right); 110 | imm_emit8(count); 111 | } 112 | 113 | public void Shl64(X86Register32 left, X86Register32 right) { 114 | writer.Write(new byte[] { 0x0F, 0xA5 }); 115 | reg_emit32(right, left); 116 | } 117 | public void Shl64(X86Address left, X86Register32 right) { 118 | writer.Write(new byte[] { 0x0F, 0xA5 }); 119 | left.Emit(writer, right); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Shift/X86Writer.ShiftRight.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void Shr8(X86Register8 reg, byte count) { 15 | if (count == 1) { 16 | writer.Write(new byte[] { 0xD0 }); 17 | reg_emit8((X86Register8)5, reg); 18 | } else { 19 | writer.Write(new byte[] { 0xC0 }); 20 | reg_emit8((X86Register8)5, reg); 21 | imm_emit8(count); 22 | } 23 | } 24 | public void Shr16(X86Register16 reg, byte count) { 25 | if (count == 1) { 26 | writer.Write(new byte[] { 0x66, 0xD1 }); 27 | reg_emit16((X86Register16)5, reg); 28 | } else { 29 | writer.Write(new byte[] { 0x66, 0xC1 }); 30 | reg_emit16((X86Register16)5, reg); 31 | imm_emit8(count); 32 | } 33 | } 34 | public void Shr32(X86Register32 reg, byte count) { 35 | if (count == 1) { 36 | writer.Write(new byte[] { 0xD1 }); 37 | reg_emit32((X86Register32)5, reg); 38 | } else { 39 | writer.Write(new byte[] { 0xC1 }); 40 | reg_emit32((X86Register32)5, reg); 41 | imm_emit8(count); 42 | } 43 | } 44 | 45 | public void Shr8(X86Address mem, byte count) { 46 | if (count == 1) { 47 | writer.Write(new byte[] { 0xD0 }); 48 | mem.Emit(writer, (X86Register8)4); 49 | } else { 50 | writer.Write(new byte[] { 0xC0 }); 51 | mem.Emit(writer, (X86Register8)4); 52 | imm_emit8(count); 53 | } 54 | } 55 | public void Shr16(X86Address mem, byte count) { 56 | if (count == 1) { 57 | writer.Write(new byte[] { 0x66, 0xD1 }); 58 | mem.Emit(writer, (X86Register8)5); 59 | } else { 60 | writer.Write(new byte[] { 0x66, 0xC1 }); 61 | mem.Emit(writer, (X86Register8)5); 62 | imm_emit8(count); 63 | } 64 | } 65 | public void Shr32(X86Address mem, byte count) { 66 | if (count == 1) { 67 | writer.Write(new byte[] { 0xD1 }); 68 | mem.Emit(writer, (X86Register8)5); 69 | } else { 70 | writer.Write(new byte[] { 0xC1 }); 71 | mem.Emit(writer, (X86Register8)5); 72 | imm_emit8(count); 73 | } 74 | } 75 | 76 | public void Shr8(X86Register8 reg) { 77 | writer.Write(new byte[] { 0xD2 }); 78 | reg_emit8((X86Register8)5, reg); 79 | } 80 | public void Shr16(X86Register16 reg) { 81 | writer.Write(new byte[] { 0x66, 0xD3 }); 82 | reg_emit16((X86Register16)5, reg); 83 | } 84 | public void Shr32(X86Register32 reg) { 85 | writer.Write(new byte[] { 0xD3 }); 86 | reg_emit32((X86Register32)5, reg); 87 | } 88 | 89 | public void Shr8(X86Address mem) { 90 | writer.Write(new byte[] { 0xD2 }); 91 | mem.Emit(writer, (X86Register8)5); 92 | } 93 | public void Shr16(X86Address mem) { 94 | writer.Write(new byte[] { 0x66, 0xD3 }); 95 | mem.Emit(writer, (X86Register8)5); 96 | } 97 | public void Shr32(X86Address mem) { 98 | writer.Write(new byte[] { 0xD3 }); 99 | mem.Emit(writer, (X86Register8)5); 100 | } 101 | 102 | public void Shr64(X86Register32 left, X86Register32 right, byte count) { 103 | writer.Write(new byte[] { 0x0F, 0xAC }); 104 | reg_emit32(right, left); 105 | imm_emit8(count); 106 | } 107 | public void Shr64(X86Address left, X86Register32 right, byte count) { 108 | writer.Write(new byte[] { 0x0F, 0xAC }); 109 | left.Emit(writer, right); 110 | imm_emit8(count); 111 | } 112 | 113 | public void Shr64(X86Register32 left, X86Register32 right) { 114 | writer.Write(new byte[] { 0x0F, 0xAD }); 115 | reg_emit32(right, left); 116 | } 117 | public void Shr64(X86Address left, X86Register32 right) { 118 | writer.Write(new byte[] { 0x0F, 0xAD }); 119 | left.Emit(writer, right); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Stack/X86Writer.Pop.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | 11 | namespace Managed.X86 12 | { 13 | partial class X86Writer { 14 | public void Pop32(X86Register32 reg) { 15 | writer.Write(new byte[] { 0x8F }); 16 | reg_emit32(0, reg); 17 | } 18 | public void Pop32(X86Address addr) { 19 | writer.Write(new byte[] { 0x8F }); 20 | addr.Emit(writer, (X86Register8)0); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/Stack/X86Writer.Push.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | 12 | namespace Managed.X86 13 | { 14 | partial class X86Writer { 15 | public void Push32(X86Register32 reg) { 16 | writer.Write(new byte[] { 0xFF }); 17 | reg_emit32((X86Register32)6, reg); 18 | } 19 | public void Push32(X86Address addr) { 20 | writer.Write(new byte[] { 0xFF }); 21 | addr.Emit(writer, (X86Register8)6); 22 | } 23 | public void Push32(Int32 imm) { 24 | if (is_imm8(imm)) { 25 | writer.Write(new byte[] { 0x6A }); 26 | imm_emit8(imm); 27 | } else { 28 | writer.Write(new byte[] { 0x68 }); 29 | imm_emit32(imm); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /DarkSoulsScripting/X86AssemblyLib/X86Writer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) 2008 The Managed.X86 Project 3 | * 4 | * Licensed under the terms of the New BSD License. 5 | * 6 | * Authors: 7 | * Alex Lyman () 8 | */ 9 | 10 | using System; 11 | using System.IO; 12 | 13 | namespace Managed.X86 14 | { 15 | public partial class X86Writer { 16 | readonly Stream stream; 17 | readonly BinaryWriter writer; 18 | readonly IntPtr baseAddress; 19 | 20 | public X86Writer(Stream stream, IntPtr baseAddress) { 21 | this.stream = stream; 22 | this.writer = new BinaryWriter(stream); 23 | this.baseAddress = baseAddress; 24 | } 25 | 26 | public IntPtr Position { 27 | get { 28 | return new IntPtr(baseAddress.ToInt32() + stream.Position); 29 | } 30 | set { 31 | stream.Seek( 32 | value.ToInt64() - baseAddress.ToInt64(), 33 | SeekOrigin.Begin 34 | ); 35 | } 36 | } 37 | 38 | #region Utilities 39 | 40 | private void address_byte(Byte m, Byte o, Byte r) { 41 | this.writer.Write( 42 | (byte) 43 | (((m & 0x03) << 6) 44 | | ((o & 0x07) << 3) 45 | | (r & 0x07) 46 | ) 47 | ); 48 | } 49 | private void reg_emit32(X86Register32 dest, X86Register32 src) { 50 | address_byte(3, (byte)(dest), (byte)(src)); 51 | } 52 | private void reg_emit16(X86Register16 dest, X86Register16 src) { 53 | address_byte(3, (byte)(dest), (byte)(src)); 54 | } 55 | private void reg_emit8(X86Register8 dest, X86Register8 src) { 56 | address_byte(3, (byte)(dest), (byte)(src)); 57 | } 58 | 59 | private void imm_emit8(Int32 value) { writer.Write((Byte)value); } 60 | private void imm_emit16(Int32 value) { writer.Write((Int16)value); } 61 | private void imm_emit32(Int32 value) { writer.Write((Int32)value); } 62 | 63 | internal static bool is_imm8(Int32 imm) { return (((int)(imm) >= -128 && (int)(imm) <= 127)); } 64 | internal static bool is_imm16(Int32 imm) { return (((int)(imm) >= -(1 << 16) && (int)(imm) <= ((1 << 16) - 1))); } 65 | 66 | #endregion 67 | 68 | public X86Label CreateLabel() { return new X86Label(this); } 69 | public X86Label CreateLabel(IntPtr position) { return new X86Label(this, position); } 70 | public X86Label CreateLabel(int offset) { return new X86Label(this, new IntPtr(this.Position.ToInt32() + offset)); } 71 | 72 | public void Nop() { writer.Write(new byte[] { 0x90 }); } 73 | 74 | public void CpuId() { writer.Write(new byte[] { 0x0F, 0xA2 }); } 75 | 76 | public void ClearCarryFlag() { writer.Write(new byte[] { 0xF8 }); } 77 | public void ClearDirectionFlag() { writer.Write(new byte[] { 0xFC }); } 78 | public void ClearInteruptFlag() { writer.Write(new byte[] { 0xFA }); } 79 | public void ComplementCarryFlag() { writer.Write(new byte[] { 0xF5 }); } 80 | 81 | public void ByteSwap(X86Register32 reg) { 82 | writer.Write( 83 | new byte[] { 84 | 0x0F, 85 | (byte)(0xC8 | (byte)reg) 86 | } 87 | ); 88 | } 89 | 90 | public void Halt() { writer.Write(new byte[] { 0xF4 }); } 91 | 92 | public void Int(byte type) { 93 | writer.Write(new byte[] { 0xCD }); 94 | writer.Write(type); 95 | } 96 | 97 | public void Return() { writer.Write(new byte[] { 0xCB }); } 98 | public void Return(Int16 stackDisp) { 99 | writer.Write(new byte[] { 0xCA }); 100 | writer.Write(stackDisp); 101 | } 102 | 103 | public void Retn() { 104 | writer.Write(new byte[] { 0xC3 }); 105 | } 106 | 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /DarkSoulsScripting/XInput/Button.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DarkSoulsScripting.XInput 8 | { 9 | [Flags] 10 | public enum Button : ushort 11 | { 12 | None = 0b0000000000000000, 13 | FaceTop = 0b1000000000000000, 14 | FaceLeft = 0b0100000000000000, 15 | FaceRight = 0b0010000000000000, 16 | FaceBottom = 0b0001000000000000, 17 | Unk1 = 0b0000100000000000, 18 | MenuTertiary = 0b0000010000000000, 19 | ShoulderRight = 0b0000001000000000, 20 | ShoulderLeft = 0b0000000100000000, 21 | StickPressRight = 0b0000000010000000, 22 | StickPressLeft = 0b0000000001000000, 23 | MenuSecondary = 0b0000000000100000, 24 | MenuPrimary = 0b0000000000010000, 25 | DirectionalPadRight = 0b0000000000001000, 26 | DirectionalPadLeft = 0b0000000000000100, 27 | DirectionalPadDown = 0b0000000000000010, 28 | DirectionalPadUp = 0b0000000000000001, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DarkSoulsScripting/XInput/ButtonState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DarkSoulsScripting.XInput 8 | { 9 | public struct ButtonState 10 | { 11 | public Button Value; 12 | 13 | public ButtonState(Button val) => Value = val; 14 | public ButtonState(ushort val) => Value = (Button)val; 15 | 16 | public bool this[Button b] 17 | { 18 | get => (Value & b) == b; 19 | set => Value = value ? (Value | b) : (Value & ~b); 20 | } 21 | 22 | public static implicit operator Button(ButtonState b) => b.Value; 23 | public static implicit operator ushort(ButtonState b) => (ushort)b.Value; 24 | public static implicit operator ButtonState(Button b) => new ButtonState(b); 25 | public static implicit operator ButtonState(ushort b) => new ButtonState(b); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DarkSoulsScripting/XInput/Gamepad.PS3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Managed.X86; 7 | using static DarkSoulsScripting.Hook; 8 | using System.Numerics; 9 | 10 | namespace DarkSoulsScripting.XInput 11 | { 12 | public sealed partial class Gamepad 13 | { 14 | public class PS3 : GamepadBase 15 | { 16 | public bool Cross { get => curState.Button[Button.FaceBottom]; set => curState.Button[Button.FaceBottom] = value; } 17 | public bool Circle { get => curState.Button[Button.FaceRight]; set => curState.Button[Button.FaceRight] = value; } 18 | public bool Square { get => curState.Button[Button.FaceLeft]; set => curState.Button[Button.FaceLeft] = value; } 19 | public bool Triangle { get => curState.Button[Button.FaceTop]; set => curState.Button[Button.FaceTop] = value; } 20 | public bool L1 { get => curState.Button[Button.ShoulderLeft]; set => curState.Button[Button.ShoulderLeft] = value; } 21 | public bool R1 { get => curState.Button[Button.ShoulderRight]; set => curState.Button[Button.ShoulderRight] = value; } 22 | public bool Start { get => curState.Button[Button.MenuPrimary]; set => curState.Button[Button.MenuPrimary] = value; } 23 | public bool Select { get => curState.Button[Button.MenuSecondary]; set => curState.Button[Button.MenuSecondary] = value; } 24 | public bool PS { get => curState.Button[Button.MenuTertiary]; set => curState.Button[Button.MenuTertiary] = value; } 25 | public bool L3 { get => curState.Button[Button.StickPressLeft]; set => curState.Button[Button.StickPressLeft] = value; } 26 | public bool R3 { get => curState.Button[Button.StickPressRight]; set => curState.Button[Button.StickPressRight] = value; } 27 | public float L2 { get => curState.LeftTrigger; set => curState.LeftTrigger = value; } 28 | public float R2 { get => curState.RightTrigger; set => curState.RightTrigger = value; } 29 | 30 | public bool PrevCross => prevState.Button[Button.FaceBottom]; 31 | public bool PrevCircle => prevState.Button[Button.FaceRight]; 32 | public bool PrevSquare => prevState.Button[Button.FaceLeft]; 33 | public bool PrevTriangle => prevState.Button[Button.FaceTop]; 34 | public bool PrevL1 => prevState.Button[Button.ShoulderLeft]; 35 | public bool PrevR1 => prevState.Button[Button.ShoulderRight]; 36 | public bool PrevStart => prevState.Button[Button.MenuPrimary]; 37 | public bool PrevSelect => prevState.Button[Button.MenuSecondary]; 38 | public bool PrevPS => prevState.Button[Button.MenuTertiary]; 39 | public bool PrevL3 => prevState.Button[Button.StickPressLeft]; 40 | public bool PrevR3 => prevState.Button[Button.StickPressRight]; 41 | public float PrevL2 => prevState.LeftTrigger; 42 | public float PrevR2 => prevState.RightTrigger; 43 | 44 | //For people who don't know the name of the Cross button: 45 | public bool X { get => curState.Button[Button.FaceBottom]; set => curState.Button[Button.FaceBottom] = value; } 46 | public bool PrevX => curState.Button[Button.FaceBottom]; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /DarkSoulsScripting/XInput/Gamepad.PS4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Managed.X86; 7 | using static DarkSoulsScripting.Hook; 8 | using System.Numerics; 9 | 10 | namespace DarkSoulsScripting.XInput 11 | { 12 | public sealed partial class Gamepad 13 | { 14 | public class PS4 : GamepadBase 15 | { 16 | public bool Cross { get => curState.Button[Button.FaceBottom]; set => curState.Button[Button.FaceBottom] = value; } 17 | public bool Circle { get => curState.Button[Button.FaceRight]; set => curState.Button[Button.FaceRight] = value; } 18 | public bool Square { get => curState.Button[Button.FaceLeft]; set => curState.Button[Button.FaceLeft] = value; } 19 | public bool Triangle { get => curState.Button[Button.FaceTop]; set => curState.Button[Button.FaceTop] = value; } 20 | public bool L1 { get => curState.Button[Button.ShoulderLeft]; set => curState.Button[Button.ShoulderLeft] = value; } 21 | public bool R1 { get => curState.Button[Button.ShoulderRight]; set => curState.Button[Button.ShoulderRight] = value; } 22 | public bool OPTIONS { get => curState.Button[Button.MenuPrimary]; set => curState.Button[Button.MenuPrimary] = value; } 23 | public bool SHARE { get => curState.Button[Button.MenuSecondary]; set => curState.Button[Button.MenuSecondary] = value; } 24 | public bool PS { get => curState.Button[Button.MenuTertiary]; set => curState.Button[Button.MenuTertiary] = value; } 25 | public bool L3 { get => curState.Button[Button.StickPressLeft]; set => curState.Button[Button.StickPressLeft] = value; } 26 | public bool R3 { get => curState.Button[Button.StickPressRight]; set => curState.Button[Button.StickPressRight] = value; } 27 | public float L2 { get => curState.LeftTrigger; set => curState.LeftTrigger = value; } 28 | public float R2 { get => curState.RightTrigger; set => curState.RightTrigger = value; } 29 | 30 | public bool PrevCross => prevState.Button[Button.FaceBottom]; 31 | public bool PrevCircle => prevState.Button[Button.FaceRight]; 32 | public bool PrevSquare => prevState.Button[Button.FaceLeft]; 33 | public bool PrevTriangle => prevState.Button[Button.FaceTop]; 34 | public bool PrevL1 => prevState.Button[Button.ShoulderLeft]; 35 | public bool PrevR1 => prevState.Button[Button.ShoulderRight]; 36 | public bool PrevOPTIONS => prevState.Button[Button.MenuPrimary]; 37 | public bool PrevSHARE => prevState.Button[Button.MenuSecondary]; 38 | public bool PrevPS => prevState.Button[Button.MenuTertiary]; 39 | public bool PrevL3 => prevState.Button[Button.StickPressLeft]; 40 | public bool PrevR3 => prevState.Button[Button.StickPressRight]; 41 | public float PrevL2 => prevState.LeftTrigger; 42 | public float PrevR2 => prevState.RightTrigger; 43 | 44 | //For people who don't know the name of the Cross button: 45 | public bool X { get => curState.Button[Button.FaceBottom]; set => curState.Button[Button.FaceBottom] = value; } 46 | 47 | public bool PrevX => curState.Button[Button.FaceBottom]; 48 | 49 | //Extra Options: 50 | public bool TouchRight { get => curState.Button[Button.MenuPrimary]; set => curState.Button[Button.MenuPrimary] = value; } 51 | public bool TouchLeft { get => curState.Button[Button.MenuSecondary]; set => curState.Button[Button.MenuSecondary] = value; } 52 | 53 | public bool PrevTouchRight => prevState.Button[Button.MenuPrimary]; 54 | public bool PrevTouchLeft => prevState.Button[Button.MenuSecondary]; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /DarkSoulsScripting/XInput/Gamepad.Xbox360.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Managed.X86; 7 | using static DarkSoulsScripting.Hook; 8 | using System.Numerics; 9 | 10 | namespace DarkSoulsScripting.XInput 11 | { 12 | public sealed partial class Gamepad 13 | { 14 | public class Xbox360 : GamepadBase 15 | { 16 | public bool A { get => curState.Button[Button.FaceBottom]; set => curState.Button[Button.FaceBottom] = value; } 17 | public bool B { get => curState.Button[Button.FaceRight]; set => curState.Button[Button.FaceRight] = value; } 18 | public bool X { get => curState.Button[Button.FaceLeft]; set => curState.Button[Button.FaceLeft] = value; } 19 | public bool Y { get => curState.Button[Button.FaceTop]; set => curState.Button[Button.FaceTop] = value; } 20 | public bool LB { get => curState.Button[Button.ShoulderLeft]; set => curState.Button[Button.ShoulderLeft] = value; } 21 | public bool RB { get => curState.Button[Button.ShoulderRight]; set => curState.Button[Button.ShoulderRight] = value; } 22 | public bool Start { get => curState.Button[Button.MenuPrimary]; set => curState.Button[Button.MenuPrimary] = value; } 23 | public bool Back { get => curState.Button[Button.MenuSecondary]; set => curState.Button[Button.MenuSecondary] = value; } 24 | public bool Guide { get => curState.Button[Button.MenuTertiary]; set => curState.Button[Button.MenuTertiary] = value; } 25 | public bool LThumb { get => curState.Button[Button.StickPressLeft]; set => curState.Button[Button.StickPressLeft] = value; } 26 | public bool RThumb { get => curState.Button[Button.StickPressRight]; set => curState.Button[Button.StickPressRight] = value; } 27 | public float LT { get => curState.LeftTrigger; set => curState.LeftTrigger = value; } 28 | public float RT { get => curState.RightTrigger; set => curState.RightTrigger = value; } 29 | 30 | public bool PrevA => prevState.Button[Button.FaceBottom]; 31 | public bool PrevB => prevState.Button[Button.FaceRight]; 32 | public bool PrevX => prevState.Button[Button.FaceLeft]; 33 | public bool PrevY => prevState.Button[Button.FaceTop]; 34 | public bool PrevLB => prevState.Button[Button.ShoulderLeft]; 35 | public bool PrevRB => prevState.Button[Button.ShoulderRight]; 36 | public bool PrevStart => prevState.Button[Button.MenuPrimary]; 37 | public bool PrevBack => prevState.Button[Button.MenuSecondary]; 38 | public bool PrevGuide => prevState.Button[Button.MenuTertiary]; 39 | public bool PrevLThumb => prevState.Button[Button.StickPressLeft]; 40 | public bool PrevRThumb => prevState.Button[Button.StickPressRight]; 41 | public float PrevLT => prevState.LeftTrigger; 42 | public float PrevRT => prevState.RightTrigger; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DarkSoulsScripting/XInput/Gamepad.XboxOne.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Managed.X86; 7 | using static DarkSoulsScripting.Hook; 8 | using System.Numerics; 9 | 10 | namespace DarkSoulsScripting.XInput 11 | { 12 | public sealed partial class Gamepad 13 | { 14 | public class XboxOne : GamepadBase 15 | { 16 | public bool A { get => curState.Button[Button.FaceBottom]; set => curState.Button[Button.FaceBottom] = value; } 17 | public bool B { get => curState.Button[Button.FaceRight]; set => curState.Button[Button.FaceRight] = value; } 18 | public bool X { get => curState.Button[Button.FaceLeft]; set => curState.Button[Button.FaceLeft] = value; } 19 | public bool Y { get => curState.Button[Button.FaceTop]; set => curState.Button[Button.FaceTop] = value; } 20 | public bool LB { get => curState.Button[Button.ShoulderLeft]; set => curState.Button[Button.ShoulderLeft] = value; } 21 | public bool RB { get => curState.Button[Button.ShoulderRight]; set => curState.Button[Button.ShoulderRight] = value; } 22 | public bool Menu { get => curState.Button[Button.MenuPrimary]; set => curState.Button[Button.MenuPrimary] = value; } 23 | public bool View { get => curState.Button[Button.MenuSecondary]; set => curState.Button[Button.MenuSecondary] = value; } 24 | public bool Xbox { get => curState.Button[Button.MenuTertiary]; set => curState.Button[Button.MenuTertiary] = value; } 25 | public bool LThumb { get => curState.Button[Button.StickPressLeft]; set => curState.Button[Button.StickPressLeft] = value; } 26 | public bool RThumb { get => curState.Button[Button.StickPressRight]; set => curState.Button[Button.StickPressRight] = value; } 27 | public float LT { get => curState.LeftTrigger; set => curState.LeftTrigger = value; } 28 | public float RT { get => curState.RightTrigger; set => curState.RightTrigger = value; } 29 | 30 | public bool PrevA => prevState.Button[Button.FaceBottom]; 31 | public bool PrevB => prevState.Button[Button.FaceRight]; 32 | public bool PrevX => prevState.Button[Button.FaceLeft]; 33 | public bool PrevY => prevState.Button[Button.FaceTop]; 34 | public bool PrevLB => prevState.Button[Button.ShoulderLeft]; 35 | public bool PrevRB => prevState.Button[Button.ShoulderRight]; 36 | public bool PrevMenu => prevState.Button[Button.MenuPrimary]; 37 | public bool PrevView => prevState.Button[Button.MenuSecondary]; 38 | public bool PrevXbox => prevState.Button[Button.MenuTertiary]; 39 | public bool PrevLThumb => prevState.Button[Button.StickPressLeft]; 40 | public bool PrevRThumb => prevState.Button[Button.StickPressRight]; 41 | public float PrevLT => prevState.LeftTrigger; 42 | public float PrevRT => prevState.RightTrigger; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DarkSoulsScripting/XInput/GamepadBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Managed.X86; 7 | using static DarkSoulsScripting.Hook; 8 | using System.Numerics; 9 | 10 | namespace DarkSoulsScripting.XInput 11 | { 12 | public abstract class GamepadBase 13 | { 14 | protected GamepadState curState; 15 | protected GamepadState prevState; 16 | 17 | public GamepadState CurrentState => curState; 18 | public GamepadState PreviousState => prevState; 19 | 20 | public bool Up { get => curState.Button[Button.DirectionalPadUp]; set => curState.Button[Button.DirectionalPadUp] = value; } 21 | public bool Down { get => curState.Button[Button.DirectionalPadDown]; set => curState.Button[Button.DirectionalPadDown] = value; } 22 | public bool Left { get => curState.Button[Button.DirectionalPadLeft]; set => curState.Button[Button.DirectionalPadLeft] = value; } 23 | public bool Right { get => curState.Button[Button.DirectionalPadRight]; set => curState.Button[Button.DirectionalPadRight] = value; } 24 | public Vector2 LS { get => curState.LeftStick; set => curState.LeftStick = value; } 25 | public Vector2 RS { get => curState.RightStick; set => curState.RightStick = value; } 26 | 27 | public bool PrevUp => prevState.Button[Button.DirectionalPadUp]; 28 | public bool PrevDown => prevState.Button[Button.DirectionalPadDown]; 29 | public bool PrevLeft => prevState.Button[Button.DirectionalPadLeft]; 30 | public bool PrevRight => prevState.Button[Button.DirectionalPadRight]; 31 | public Vector2 PrevLS => prevState.LeftStick; 32 | public Vector2 PrevRS => prevState.RightStick; 33 | 34 | public void Read() 35 | { 36 | prevState = curState; 37 | curState.ReadFrom(GetAddress()); 38 | } 39 | 40 | public void Write() 41 | { 42 | curState.WriteTo(GetAddress()); 43 | } 44 | 45 | private static uint __xinput = 0xFFFFFFFF; 46 | public static uint XInputModuleAddress 47 | { 48 | get 49 | { 50 | if (__xinput == 0xFFFFFFFF) 51 | { 52 | __xinput = DARKSOULS.ModuleOffsets["XINPUT1_3.DLL"][0]; 53 | } 54 | return __xinput; 55 | } 56 | } 57 | 58 | public static uint GetAddress() => RUInt32(RUInt32(XInputModuleAddress + 0x10C44)); 59 | 60 | public static void ApplyInputDisablePatch() 61 | { 62 | DARKSOULS.Suspend(); 63 | WBytes(XInputModuleAddress + 0x650A, new byte[] { 0x90, 0x90, 0x90 }); 64 | WBytes(XInputModuleAddress + 0x6516, new byte[] { 0x90, 0x90, 0x90 }); 65 | WUInt32(XInputModuleAddress + 0x6597, 0x90909090); 66 | WUInt32(XInputModuleAddress + 0x65AB, 0x90909090); 67 | WUInt32(XInputModuleAddress + 0x652F, 0x90909090); 68 | WUInt32(XInputModuleAddress + 0x6549, 0x90909090); 69 | WUInt32(XInputModuleAddress + 0x6563, 0x90909090); 70 | WUInt32(XInputModuleAddress + 0x657D, 0x90909090); 71 | WBytes(0xF72543, new byte[] { 0xB0, 0x01, 0x90 }); 72 | DARKSOULS.Resume(); 73 | } 74 | 75 | public static void UndoInputDisablePatch() 76 | { 77 | DARKSOULS.Suspend(); 78 | WBytes(XInputModuleAddress + 0x650A, new byte[] { 0x88, 0x50, 0x2A }); 79 | WBytes(XInputModuleAddress + 0x6516, new byte[] { 0x88, 0x50, 0x2B }); 80 | WUInt32(XInputModuleAddress + 0x6597, 0x66894A28); 81 | WUInt32(XInputModuleAddress + 0x65AB, 0x66894A28); 82 | WUInt32(XInputModuleAddress + 0x652F, 0x66894A2C); 83 | WUInt32(XInputModuleAddress + 0x6549, 0x66894A2E); 84 | WUInt32(XInputModuleAddress + 0x6563, 0x66894A30); 85 | WUInt32(XInputModuleAddress + 0x657D, 0x66894A32); 86 | WBytes(0xF72543, new byte[] { 0x0F, 0x94, 0xC0 }); 87 | DARKSOULS.Resume(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /DarkSoulsScripting/XInput/GamepadState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Numerics; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using static DarkSoulsScripting.Hook; 8 | 9 | namespace DarkSoulsScripting.XInput 10 | { 11 | public struct GamepadState 12 | { 13 | public ButtonState Button; 14 | public float LeftTrigger; 15 | public float RightTrigger; 16 | public Vector2 LeftStick; 17 | public Vector2 RightStick; 18 | 19 | public void ReadFrom(long addr) 20 | { 21 | RightTrigger = RByte(addr + 0x26) / 255.0F; 22 | LeftTrigger = RByte(addr + 0x27) / 255.0F; 23 | Button = RUInt16(addr + 0x28); 24 | LeftStick.X = 1.0F * RInt16(addr + 0x2C) / short.MaxValue; 25 | LeftStick.Y = 1.0F * RInt16(addr + 0x2E) / short.MaxValue; 26 | RightStick.X = 1.0F * RInt16(addr + 0x30) / short.MaxValue; 27 | RightStick.Y = 1.0F * RInt16(addr + 0x32) / short.MaxValue; 28 | } 29 | 30 | public void WriteTo(long addr) 31 | { 32 | WByte(addr + 0x26, (byte)(RightTrigger / byte.MaxValue)); 33 | WByte(addr + 0x27, (byte)(LeftTrigger / byte.MaxValue)); 34 | WUInt16(addr + 0x28, Button); 35 | WInt16(addr + 0x2C, (short)(LeftStick.X * short.MaxValue)); 36 | WInt16(addr + 0x2E, (short)(LeftStick.Y * short.MaxValue)); 37 | WInt16(addr + 0x30, (short)(RightStick.X * short.MaxValue)); 38 | WInt16(addr + 0x32, (short)(RightStick.Y * short.MaxValue)); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /DarkSoulsScripting/[General]/CodeHooks.cs: -------------------------------------------------------------------------------- 1 | using DarkSoulsScripting.CodeHookTypes; 2 | using Managed.X86; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace DarkSoulsScripting 10 | { 11 | public static class CodeHooks 12 | { 13 | public static Reg32Recorder TargetedChrPtrRecorder { get; private set; } = null; 14 | 15 | internal static void InitAll() 16 | { 17 | TargetedChrPtrRecorder = new Reg32Recorder(X86Register32.EAX, (IntPtr)0xFAE784, 8, true, new byte[] { 0x8B, 0x16, 0x8B, 0x82, 0xA0, 0x00, 0x00, 0x00 }); 18 | } 19 | 20 | internal static void CleanupAll() 21 | { 22 | TargetedChrPtrRecorder?.Dispose(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DarkSoulsScripting/[General]/Memloc.cs: -------------------------------------------------------------------------------- 1 | using DarkSoulsScripting.Injection.Structures; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace DarkSoulsScripting 9 | { 10 | public struct Memloc 11 | { 12 | public IntPtr Address 13 | { 14 | get 15 | { 16 | switch (Hook.DARKSOULS.Version) 17 | { 18 | case DarkSoulsVersion.LatestRelease: return addrSteamRelease; 19 | case DarkSoulsVersion.Debug: return addrSteamDebug; 20 | default: return addr_Zero; 21 | } 22 | } 23 | } 24 | 25 | private readonly IntPtr addrSteamRelease; 26 | private readonly IntPtr addrSteamDebug; 27 | 28 | private static readonly IntPtr addr_Zero = (IntPtr)0; 29 | 30 | public Memloc(long addrSteamRelease, long addrSteamDebug) 31 | { 32 | this.addrSteamRelease = new IntPtr(addrSteamRelease); 33 | this.addrSteamDebug = new IntPtr(addrSteamDebug); 34 | } 35 | 36 | public Memloc(IntPtr addrSteamRelease, IntPtr addrSteamDebug) 37 | { 38 | this.addrSteamRelease = addrSteamRelease; 39 | this.addrSteamDebug = addrSteamDebug; 40 | } 41 | 42 | public Memloc(long addrSteamRelease) 43 | { 44 | this.addrSteamRelease = new IntPtr(addrSteamRelease); 45 | this.addrSteamDebug = IntPtr.Zero; 46 | } 47 | 48 | public Memloc(IntPtr addrSteamRelease) 49 | { 50 | this.addrSteamRelease = addrSteamRelease; 51 | this.addrSteamDebug = IntPtr.Zero; 52 | } 53 | 54 | public static implicit operator Memloc(int releaseAddress) => new Memloc(releaseAddress, 0); 55 | public static implicit operator Memloc(long releaseAddress) => new Memloc(releaseAddress, 0); 56 | public static implicit operator Memloc(uint releaseAddress) => new Memloc(releaseAddress, 0); 57 | public static implicit operator Memloc(IntPtr releaseAddress) => new Memloc(releaseAddress, IntPtr.Zero); 58 | 59 | public static implicit operator Memloc((long Release, long Debug) addr) => new Memloc(addr.Release, addr.Debug); 60 | public static implicit operator Memloc((IntPtr Release, IntPtr Debug) addr) => new Memloc(addr.Release, addr.Debug); 61 | 62 | public static implicit operator int(Memloc m) => m.Address.ToInt32(); 63 | public static implicit operator uint(Memloc m) => (uint)m.Address; 64 | public static implicit operator long(Memloc m) => m.Address.ToInt64(); 65 | public static implicit operator IntPtr(Memloc m) => m.Address; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /DarkSoulsScripting/[General]/ModuleInitializer.cs: -------------------------------------------------------------------------------- 1 | // This file can be modified in any way, with two exceptions. 1) The name of 2 | // this class must be "ModuleInitializer". 2) This class must have a public or 3 | // internal parameterless "Run" method that returns void. In addition to these 4 | // modifications, this file may also be moved to any location, as long as it 5 | // remains a part of its current project. 6 | 7 | using System; 8 | using System.Threading; 9 | using System.Windows; 10 | 11 | namespace DarkSoulsScripting 12 | { 13 | internal static class ModuleInitializer 14 | { 15 | public static SafetyFinalizerHandler Finalizer = null; 16 | 17 | private static Thread CleanExitThread; 18 | private static EventWaitHandle CleanExitTrigger = new EventWaitHandle(false, EventResetMode.ManualReset); 19 | 20 | internal static void Run() 21 | { 22 | /* 23 | The kernel32 functions seem to completely block the game's draw thread. 24 | We can reduce interruptions to the game's drawing by executing the kernel calls as fast as possible. 25 | Therefore, the below line actually (very noticably) boosts the performance of both DarkSoulsScripting AND Dark Souls! 26 | */ 27 | Thread.CurrentThread.Priority = ThreadPriority.Highest; 28 | 29 | if (Hook.DARKSOULS.TryAttachToDarkSouls(out string error)) 30 | { 31 | Hook.Init(); 32 | 33 | Finalizer = new SafetyFinalizerHandler(); 34 | 35 | CleanExitThread = new Thread(new ThreadStart(DoCleanExitWait)) { IsBackground = true }; 36 | CleanExitThread.Start(); 37 | 38 | CodeHooks.InitAll(); 39 | } 40 | else 41 | { 42 | //if (MessageBox.Show(error + "\n\nWould you like to proceed anyways?", "Failed to attach to Dark Souls", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) 43 | //{ 44 | // if (System.Windows.Application.Current != null) //WPF 45 | // System.Windows.Application.Current.Shutdown(); 46 | // else if (System.Windows.Forms.Application.MessageLoop) //WinForms 47 | // System.Windows.Forms.Application.Exit(); 48 | // else //Console application 49 | // Environment.Exit(1); 50 | // Application.Current.Shutdown(1); 51 | // return; 52 | //} 53 | Console.Error.WriteLine(">>>>>>>>>>>>>>>> ERROR: " + error); 54 | Hook.Cleanup(); 55 | } 56 | } 57 | 58 | private static void CleanExit() 59 | { 60 | CodeHooks.CleanupAll(); 61 | Hook.Cleanup(); 62 | } 63 | 64 | private static void DoCleanExitWait() 65 | { 66 | bool doCleanExit = false; 67 | 68 | try 69 | { 70 | do 71 | { 72 | doCleanExit = CleanExitTrigger.WaitOne(5000); 73 | } while (!(doCleanExit)); 74 | 75 | GC.KeepAlive(Finalizer); 76 | } 77 | catch 78 | { 79 | 80 | } 81 | finally 82 | { 83 | CleanExit(); 84 | } 85 | } 86 | 87 | public class SafetyFinalizerHandler 88 | { 89 | ~SafetyFinalizerHandler() 90 | { 91 | CleanExit(); 92 | } 93 | } 94 | 95 | } 96 | } -------------------------------------------------------------------------------- /DarkSoulsScripting/[General]/Pointers.cs: -------------------------------------------------------------------------------- 1 | using static DarkSoulsScripting.Hook; 2 | 3 | namespace DarkSoulsScripting 4 | { 5 | public class Pointers 6 | { 7 | public static int PtrToPtrToCharDataPtr1 => RInt32(0x137DC70); 8 | public static int PtrToCharDataPtr1 => RInt32(PtrToPtrToCharDataPtr1 + 0x4); 9 | public static int CharDataPtr1 => RInt32(PtrToCharDataPtr1); 10 | public static int GameStatsPtr => RInt32(0x1378700); 11 | public static int CharDataPtr2 => RInt32(GameStatsPtr + 0x8); 12 | public static int CharMapDataPtr => RInt32(CharDataPtr1 + 0x28); 13 | public static int MenuPtr => RInt32(0x13786D0); 14 | public static int LinePtr => RInt32(0x1378388); 15 | public static int KeyPtr => RInt32(0x1378640); 16 | public static int EntityControllerPtr => RInt32(CharMapDataPtr + 0x54); 17 | public static int EntityAnimPtr => RInt32(CharMapDataPtr + 0x14); 18 | public static int PtrToPtrToEntityAnimInstancePtr => RInt32(EntityAnimPtr + 0xC); 19 | public static int PtrToEntityAnimInstancePtr => RInt32(PtrToPtrToEntityAnimInstancePtr + 0x10); 20 | public static int EntityAnimInstancePtr => RInt32(PtrToEntityAnimInstancePtr); 21 | } 22 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started: Visual Studio 2017 (with example project) 2 | * Download and run the .msi installer for IronPython and follow the directions (make sure Visual Studio is closed): https://github.com/IronLanguages/main/releases/tag/ipy-2.7.7 3 | * Install Python support in Visual Studio 2017: 4 | * Run the Visual Studio Installer (Quick way to get to it is under "Programs and Features" right click on Microsoft Visual Studio 2017 and click "Change" 5 | * Click "Modify" 6 | * Switch to the "Individual Components" tab 7 | * Check the box next to "Python language support" 8 | * Note: You do not need to install Python 2 or 3 runtime since you'll be using the IronPython runtime instead 9 | * Download the **source code** for the latest pre-release of DarkSoulsScripting: https://github.com/Wulf2k/DarkSoulsScripting/releases 10 | * Open the solution in Visual Studio 2017 11 | * Build the solution (*F6-key*). 12 | * Right click the *ScriptTester* project and select "Unload project", then right click on it again and select "Reload project". 13 | * Double-click the `ScriptTester.py` script in the *ScriptTester* project. 14 | * Make sure the latest Steam version of Dark Souls: Prepare to Die Edition is running. 15 | * In Dark Souls, load a character of your choosing. 16 | * Press Alt+Shift+F5 to execute the test script in the Python interactive console window and watch it do a lot of weird stuff to your game. You can follow along to help you understand how the scripting works in general. 17 | 18 | # Getting Started: PyCharm 19 | * Download and run the .msi installer for IronPython and follow the directions (make sure Visual Studio is closed): https://github.com/IronLanguages/main/releases/tag/ipy-2.7.7 20 | * Download and install the latest version of PyCharm (the free Community version works fine): https://www.jetbrains.com/pycharm/download/ 21 | * Create a new project in PyCharm: 22 | * For the interpreter, select your IronPython installation (it should be listed for you) 23 | * Download the **binary / .DLL** for the latest pre-release of DarkSoulsScripting: https://github.com/Wulf2k/DarkSoulsScripting/releases 24 | * Copy and paste the `DarkSoulsScripting.dll` file you just downloaded directly into your PyCharm project directory 25 | * Add a new python file to your project (Alt+Insert or File->New... to open the add file popup menu) 26 | * Import IronPython and DarkSoulsScripting namespaces: 27 | ```python 28 | import clr 29 | clr.AddReference("DarkSoulsScripting") 30 | from DarkSoulsScripting import * 31 | from DarkSoulsScripting.Extra import * 32 | from DarkSoulsScripting.AI_DEFINE import * 33 | from DarkSoulsScripting import IngameFuncs as f 34 | from DarkSoulsScripting import ExtraFuncs as ex 35 | ``` 36 | * **Important**: Place your text cursor on `DarkSoulsScripting`. When hovering your mouse over the text, PyCharm will give you an error: 37 | 38 | ![Unresolved reference 'DarkSoulsScripting'](https://i.imgur.com/UXKe8kR.png) 39 | 40 | * To resolve this error, you must open the quick action menu (Alt+Enter) and choose the option to generate stubs for the DarkSoulsScripting module: 41 | 42 | ![Generate stubs for binary module DarkSoulsScripting](https://i.imgur.com/yLDioDE.png) 43 | 44 | 45 | # Things to note: 46 | * Saving is automatically disabled for the rest of the play session each time you run **ANY** script. This will allow you to test things without overwriting your save (you can manually call 'SetSaveEnable' in the `Functions.Extra` module to re-enable it if you choose) 47 | -------------------------------------------------------------------------------- /ScriptTester/DarkSoulsDebugTesting.py: -------------------------------------------------------------------------------- 1 | from DarkSoulsScriptingBundle import * 2 | 3 | print str(f.GetEventMode(1501961)) -------------------------------------------------------------------------------- /ScriptTester/DarkSoulsScriptingBundle/__init__.py: -------------------------------------------------------------------------------- 1 | import clr 2 | import System 3 | clr.AddReference("DarkSoulsScripting") 4 | from DarkSoulsScripting import * 5 | from DarkSoulsScripting.Extra import * 6 | from DarkSoulsScripting.AI_DEFINE import * 7 | from DarkSoulsScripting.XInput import Gamepad 8 | from DarkSoulsScripting import IngameFuncs as f 9 | from DarkSoulsScripting import ExtraFuncs as ex -------------------------------------------------------------------------------- /ScriptTester/Example.py: -------------------------------------------------------------------------------- 1 | # Imports the default stuff. "f" for functions, "ex" for extra functions, etc 2 | from DarkSoulsScriptingBundle import * 3 | 4 | # Standard python random library for shenanigans 5 | import random 6 | 7 | # Use WorldChrMan.LocalPlayer. to access the player chr structure. 8 | WorldChrMan.LocalPlayer.DisableGravity2 = True # Yes there are 2 disable gravity values. The second one seems to be the only correct one though. Wulf still hasn't confirmed. 9 | 10 | # WorldState is currently not mapped very much, expect more values to be added here later 11 | WorldState.BonfireID = 1212962 # Sets respawn bonfire to Oolacile Township 12 | 13 | f.SetEventSpecialEffect_2(10000, 33) # Immediately curse player 14 | f.SetEventFlag(11210001, False) # Clears the "Artorias is dead" flag 15 | 16 | # Some utility modules exist (more will be added as needed): 17 | Utils.WaitLoadCycle() #Wait until after the game finishes loading. 18 | 19 | # Use f. to access ingame functions with mapped parameters 20 | f.ChrFadeIn(10000, 5.0, 0.0) 21 | 22 | # Because WorldChrMan.LocalPlayer is a Player-type Chr, it has a PlayerStats module, accessible with WorldChrMan.LocalPlayer.Stats: 23 | WorldChrMan.LocalPlayer.Stats.STR = 99 #ur stronk now 24 | 25 | # We also include many of the game's alternate methods of accessing things in memory, such as this: 26 | Game.LocalPlayerStats.STR = 99 # Does same thing as previous 27 | 28 | # Use f.Unmapped to access ALL ingame lua functions with no parameters listed (in case you need to use a function we haven't mapped out the parameters for) 29 | print str(f.Unmapped.GetTravelItemParamId(7)) #No dea what this returns. If you find out, please let me know ;) 30 | 31 | # Use ex. to access extra functions we've added to extend the functionality. 32 | ex.MsgBoxOK("Hi there. Press OK to spawn your own Artorias bodyguard to help you through Oolacile Township.") 33 | 34 | # Use Map.Find(area, block) to find a map by its area/block numbers 35 | oolacile = Map.Find(12, 1) # m12_01_00_00 36 | 37 | # Use the FindEnemy(id, instance) function on a MapEntry object to search for an enemy. 38 | artorias = oolacile.FindEnemy(4100, 0) # The enemy named "c4100_0000" in the MSB 39 | 40 | # Note: Map.Find(12, 1).FindEnemy(4100, 0) also works 41 | 42 | # the ID property in Chr structure gets the ChrID of that Chr for use with various functions. 43 | f.SetDisable(artorias.ID, False) 44 | 45 | artorias.DisableEventBackreadState = False # Does most of what the previous thing does 46 | 47 | # Do note, however, that there are some Chr's that literally always respawn and have no special events. 48 | # These Chr's will have -1 as their ID and, as such, these functions will not work. 49 | # However, you can still do some of the things those functions do by directly modifying the Chr: 50 | artorias.MovementCtrl.EnableLogic = True # Does the same thing as f.EnableLogic(artorias.ID, True) 51 | 52 | artorias.TeamType = TEAM_TYPE.BattleFriend 53 | 54 | 55 | # There are also some helper functions in many of the ingame structures mapped out that we added to make things easier: 56 | artorias.WarpToPlayer(WorldChrMan.LocalPlayer) # Warps Artorias to the exact same location as the local player 57 | 58 | #### As of Pre-Release 0.2: #### 59 | 60 | # Many structs were updated to have new values 61 | WorldChrMan.LocalPlayer.OmissionLevel = 8 62 | 63 | # Structs added: 64 | Game.ClearCount = 6 #Makes game NG+6 65 | 66 | Game.Options.CameraAutoWallRecovery = False #Disables auto wall recovery in the options menu. 67 | 68 | Game.Tendency.CharacterBlackWhiteTendency = 1 #Changes character tendency. Likely will have no effect whatsoever because this isn't Demon's Souls. 69 | 70 | ChrDbg.AllNoMPConsume = True #Would make every chr in the game not consume MP, if this was Demon's Souls (don't worry, ChrDebug also has plenty of Dark Souls debug options) 71 | 72 | ChrFollowCam.FovY = 0.8 #Messes with field of view 73 | 74 | WorldState.Autosave = False #Disables autosaving. 75 | # Do note that this setting is set to False EVERY SINGLE TIME A SCRIPT BEGINS EXECUTING for safety purposes and it stays off after the script is done. 76 | # If you wish to re-enable saving you must do so manually in your script or just exit and re-launch the game 77 | # (but doing so would cause you to lose all progress since you last ran a script and disabled autosave. 78 | 79 | while True: 80 | ex.SetLineHelpTextPos(225, 192); 81 | ex.SetLineHelpText("Current Animation: " + str(Misc.PlayerCurrentAnimation)) # Displays player current animation. Misc module contains some other neat stuff too. 82 | ex.Wait(33) 83 | -------------------------------------------------------------------------------- /ScriptTester/QUICK_TEST.py: -------------------------------------------------------------------------------- 1 | from DarkSoulsScriptingBundle import * 2 | 3 | UPDATE_RATE = 60.0 4 | gp = Gamepad.PS3() 5 | CodeHooks.TargetedChrPtrRecorder.PatchCode() 6 | 7 | def OnLoad(): 8 | ex.Wait(2000) 9 | 10 | def OnUpdate(): 11 | pass 12 | 13 | def UpdateLoop(): 14 | global playingAs 15 | justLoaded = False 16 | while Utils.IsGameLoading(): 17 | justLoaded = True 18 | ex.Wait(66) 19 | if justLoaded: 20 | OnLoad() 21 | gp.Read() 22 | OnUpdate() 23 | 24 | ticks = Utils.GetTickSpanFromHz(UPDATE_RATE) 25 | playingAs = None 26 | while True: 27 | Utils.FixedTimestep(UpdateLoop, ticks) -------------------------------------------------------------------------------- /ScriptTester/ScriptTester.pyproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Debug 4 | 2.0 5 | fc0e26b0-ae42-4be7-86bf-88bab8c3090a 6 | . 7 | DarkSoulsDebugTesting.py 8 | 9 | 10 | . 11 | IronPython|2.7-32 12 | IronPython (.NET) launcher 13 | . 14 | ScriptTester 15 | ScriptTester 16 | False 17 | 18 | 19 | true 20 | false 21 | 22 | 23 | true 24 | false 25 | 26 | 27 | 28 | Code 29 | 30 | 31 | Code 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | DarkSoulsScripting 41 | {4eef2ffb-9e6f-490e-b8d0-19c10451b461} 42 | True 43 | 44 | 45 | 46 | 47 | Code 48 | 49 | 50 | 51 | 52 | 53 | 54 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Tools/InjectModuleInitializer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wulf2k/DarkSoulsScripting/d67f155004659b3bb55ac2e27447e1ec53ac5a57/Tools/InjectModuleInitializer.exe --------------------------------------------------------------------------------