├── .gitignore ├── README.md ├── addons └── libs │ ├── common.lua │ ├── extensions │ ├── math.lua │ ├── string.lua │ └── table.lua │ ├── hook │ ├── events.lua │ ├── helpers.lua │ └── imguidef.lua │ ├── json │ └── json.lua │ ├── ltn12.lua │ ├── mime.lua │ ├── reckoning │ ├── actor.lua │ └── constants.lua │ ├── settings.lua │ ├── socket.lua │ ├── socket │ ├── ftp.lua │ ├── headers.lua │ ├── http.lua │ ├── smtp.lua │ ├── tp.lua │ └── url.lua │ └── timer.lua ├── config └── rmod.ini ├── plugins ├── Addons.dll └── sdk │ ├── Atomic_BinaryData.h │ ├── Atomic_CommandParse.h │ ├── Atomic_Event.h │ ├── Atomic_Exception.h │ ├── Atomic_LockableObject.h │ ├── Atomic_Memory.h │ ├── Atomic_Thread.h │ ├── Plugin.h │ ├── d3d9 │ ├── DxErr.lib │ ├── d3d9.h │ ├── d3d9.lib │ ├── d3d9caps.h │ ├── d3d9types.h │ ├── d3dx9.h │ ├── d3dx9.lib │ ├── d3dx9anim.h │ ├── d3dx9core.h │ ├── d3dx9d.lib │ ├── d3dx9effect.h │ ├── d3dx9math.h │ ├── d3dx9math.inl │ ├── d3dx9mesh.h │ ├── d3dx9shader.h │ ├── d3dx9shape.h │ ├── d3dx9tex.h │ ├── d3dx9xof.h │ ├── dinput.h │ ├── dinput8.lib │ ├── dinputd.h │ ├── dxgi.lib │ └── dxguid.lib │ └── imgui.h ├── rMod.dll ├── rMod.exe ├── resources └── legal_rmod.dds └── scripts └── default.txt /.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 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | /config/imgui.ini 290 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rMod 2 | 3 | A modding project for Kingdoms of Amaluar: Reckoning. Injectable hook that introduces plugins (via C++/etc.) and addons (via Lua scripting). 4 | 5 | # rMod Repositories 6 | 7 | rMod is separated into a few repositories to help keep the project clean and have central locations for issue reports for each part separated. 8 | 9 | You can view the full list of repositories here: 10 | * https://github.com/KoA-rMod 11 | 12 | Some important repositories that you may wish to view are: 13 | 14 | * Addons: https://github.com/KoA-rMod/Addons 15 | 16 | Interested in developing plugins for rMod? Check out the example plugin source code here: 17 | 18 | * ExamplePlugin: https://github.com/KoA-rMod/ExamplePlugin 19 | 20 | # rMod Community 21 | 22 | Join the rMod community on our site (forums) and Discord server! 23 | 24 | * **Forums:** https://koa.atom0s.com/ 25 | * **Discord:** https://discordapp.com/invite/qRg969Q 26 | 27 | Be sure to check out the other repositories associated with the rMod project here: https://github.com/KoA-rMod 28 | 29 | # Reporting Issues 30 | 31 | When reporting an issue about rMod please include as much information as possible. Vague issue reports will likely be ignored or deemed incomplete due to a lack of information. You should include the following information when reporting an issue: 32 | 33 | * Windows Version 34 | * rMod Version 35 | * Game Version (Steam, Origin, etc.) 36 | * Game Version Number (v1.0.0.2, etc.) 37 | * Detailed explaination of the issue. 38 | 39 | You should include details on what you were doing when the issue happened, steps to reproduce the issue, if possible, and so on. 40 | 41 | # Pull Requests (For Developers) 42 | 43 | If you would like to contribute to the include plain text files of rMod, such as the Lua libraries, please be sure that you are following these key points. Pull requests will be rejected otherwise. 44 | 45 | * Your pull request must specifically state if it contains breaking changes that will affect features of rMod. (Addons, plugins, etc.) 46 | * Your pull request must detail everything your changes affect. 47 | * Your pull request must be thoroughly tested before being submitted. 48 | 49 | Code changes need to follow the following syntax rules: 50 | 51 | * No tabs, use 4 spaces. 52 | * 'if' statements should be in the format of 'if (statement) then' for Lua code. 53 | * 'if' statements should be in the format of 'if (statement)' for C++ code. 54 | * Braces for scope related code in C/C++ code must be on their own line. 55 | 56 | 57 | 58 | // Correct 59 | if (derp == true) 60 | { 61 | // code here.. 62 | } 63 | 64 | // Incorrect 65 | if (derp == true) { 66 | // code here.. 67 | } 68 | -------------------------------------------------------------------------------- /addons/libs/common.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | * rMod - Copyright (c) 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using rMod, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (rMod) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (rMod), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * rMod project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | ]]-- 25 | 26 | ---------------------------------------------------------------------------------------------------- 27 | -- Extensions 28 | ---------------------------------------------------------------------------------------------------- 29 | require 'extensions.math'; 30 | require 'extensions.string'; 31 | require 'extensions.table'; 32 | 33 | ---------------------------------------------------------------------------------------------------- 34 | -- Hook Related (Don't include events.lua manually!) 35 | ---------------------------------------------------------------------------------------------------- 36 | require 'hook.helpers'; 37 | require 'hook.imguidef'; 38 | 39 | ---------------------------------------------------------------------------------------------------- 40 | -- Reckoning Specific Libraries 41 | ---------------------------------------------------------------------------------------------------- 42 | require 'reckoning.constants'; 43 | require 'reckoning.actor'; 44 | 45 | ---------------------------------------------------------------------------------------------------- 46 | -- Misc Libraries 47 | ---------------------------------------------------------------------------------------------------- 48 | require 'settings'; 49 | require 'timer'; -------------------------------------------------------------------------------- /addons/libs/extensions/math.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | * rMod - Copyright (c) 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using rMod, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (rMod) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (rMod), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * rMod project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | ]]-- 25 | 26 | ---------------------------------------------------------------------------------------------------- 27 | -- func: math.distance2d 28 | -- desc: Returns the 2D distance between two sets of coords. 29 | ---------------------------------------------------------------------------------------------------- 30 | function math.distance2d(x1, y1, x2, y2) 31 | local x = x2 - x1; 32 | local y = y2 - y1; 33 | return math.sqrt((x * x) + (y * y)); 34 | end 35 | 36 | ---------------------------------------------------------------------------------------------------- 37 | -- func: math.distance3d 38 | -- desc: Returns the 3D distance between two sets of coords. 39 | ---------------------------------------------------------------------------------------------------- 40 | function math.distance3d(x1, y1, z1, x2, y2, z2) 41 | local x = x2 - x1; 42 | local y = y2 - y1; 43 | local z = z2 - z1; 44 | return math.sqrt((x * x) + (y * y) + (z * z)); 45 | end 46 | 47 | ---------------------------------------------------------------------------------------------------- 48 | -- func: math.degree2rad 49 | -- desc: Converts a degree to a radian. 50 | ---------------------------------------------------------------------------------------------------- 51 | function math.degree2rad(d) 52 | local pi = 3.14159265359; 53 | return d * (pi / 180); 54 | end 55 | 56 | ---------------------------------------------------------------------------------------------------- 57 | -- func: math.rad2degree 58 | -- desc: Converts a radian to a degree. 59 | ---------------------------------------------------------------------------------------------------- 60 | function math.rad2degree(r) 61 | local pi = 3.14159265359; 62 | return r * (180 / pi); 63 | end 64 | 65 | ---------------------------------------------------------------------------------------------------- 66 | -- func: math.clamp 67 | -- desc: Clamps a number between a min and max value. 68 | ---------------------------------------------------------------------------------------------------- 69 | function math.clamp(n, min, max) 70 | if (n < min) then return min; end 71 | if (n > max) then return max; end 72 | return n; 73 | end 74 | 75 | ---------------------------------------------------------------------------------------------------- 76 | -- func: math.round 77 | -- desc: Rounds a number to the given decimal places. 78 | ---------------------------------------------------------------------------------------------------- 79 | function math.round(n, dp) 80 | local m = 10 ^ (dp or 0); 81 | return math.floor(n * m + 0.5) / m; 82 | end 83 | 84 | ---------------------------------------------------------------------------------------------------- 85 | -- func: math.d3dcolor 86 | -- desc: Converts the given ARGB values to make a D3DCOLOR. 87 | ---------------------------------------------------------------------------------------------------- 88 | function math.d3dcolor(a, r, g, b) 89 | local a = bit.lshift(bit.band(a, 0xFF), 24); 90 | local r = bit.lshift(bit.band(r, 0xFF), 16); 91 | local g = bit.lshift(bit.band(g, 0xFF), 08); 92 | local b = bit.band(b, 0xFF); 93 | return bit.bor(bit.bor(a, r), bit.bor(g, b)); 94 | end 95 | 96 | ---------------------------------------------------------------------------------------------------- 97 | -- func: math.color_to_argb 98 | -- desc: Converts a color code to its individual a r g b values. 99 | ---------------------------------------------------------------------------------------------------- 100 | function math.color_to_argb(c) 101 | local a = bit.rshift(bit.band(c, 0xFF000000), 24); 102 | local r = bit.rshift(bit.band(c, 0x00FF0000), 16); 103 | local g = bit.rshift(bit.band(c, 0x0000FF00), 8); 104 | local b = bit.band(c, 0x000000FF); 105 | return a, r, g, b; 106 | end 107 | 108 | ---------------------------------------------------------------------------------------------------- 109 | -- func: math.colortable_to_int 110 | -- desc: Converts an imgui color table to a D3DCOLOR value. 111 | ---------------------------------------------------------------------------------------------------- 112 | function math.colortable_to_int(t) 113 | local a = t[4]; 114 | local r = t[1] * 255; 115 | local g = t[2] * 255; 116 | local b = t[3] * 255; 117 | 118 | if (a == nil) then 119 | a = 255; 120 | else 121 | a = a * 255; 122 | end 123 | 124 | return math.d3dcolor(a, r, g, b); 125 | end 126 | 127 | ---------------------------------------------------------------------------------------------------- 128 | -- func: math.bin2int 129 | -- desc: Converts a binary number to an integer. 130 | ---------------------------------------------------------------------------------------------------- 131 | function math.bin2int(b) 132 | return tonumber(b, 2); 133 | end 134 | 135 | ---------------------------------------------------------------------------------------------------- 136 | -- func: math.int2bin 137 | -- desc: Converts an integer to a binary number. 138 | ---------------------------------------------------------------------------------------------------- 139 | function math.int2bin(i) 140 | local s = string.format('%o', i); 141 | local a = { ["0"] = "000", ["1"] = "001", ["2"] = "010", ["3"] = "011", ["4"] = "100", ["5"] = "101", ["6"] = "110", ["7"] = "111" }; 142 | local b = string.gsub(s, "(.)", function(d) return a[d]; end); 143 | return b; 144 | end 145 | 146 | ---------------------------------------------------------------------------------------------------- 147 | -- func: math.rngrnd 148 | -- desc: Generates a ranged random number between a min and max point. 149 | ---------------------------------------------------------------------------------------------------- 150 | function math.rngrnd(l, h) 151 | return l + (h - l) * math.random(); 152 | end 153 | ---------------------------------------------------------------------------------------------------- 154 | -- func: math.truncate 155 | -- desc: Returns a number towards zero. 156 | ---------------------------------------------------------------------------------------------------- 157 | function math.truncate(n, dp) 158 | local m = 10 ^ (dp or 0); 159 | local f = num < 0 and math.ceil or math.floor; 160 | return f(n * m) / m; 161 | end -------------------------------------------------------------------------------- /addons/libs/extensions/string.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | * rMod - Copyright (c) 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using rMod, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (rMod) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (rMod), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * rMod project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | ]]-- 25 | 26 | ---------------------------------------------------------------------------------------------------- 27 | -- func: string.contains 28 | -- desc: Determines if a string contains the given sub-string. 29 | ---------------------------------------------------------------------------------------------------- 30 | function string.contains(s, v) 31 | return s:find(v, nil, true) ~= nil; 32 | end 33 | 34 | ---------------------------------------------------------------------------------------------------- 35 | -- func: string.startswith 36 | -- desc: Determines if a string begins with a specific string. 37 | ---------------------------------------------------------------------------------------------------- 38 | function string.startswith(s, v) 39 | return s:sub(1, #v) == v; 40 | end 41 | 42 | ---------------------------------------------------------------------------------------------------- 43 | -- func: string.endswith 44 | -- desc: Determines if a string ends with a specific string. 45 | ---------------------------------------------------------------------------------------------------- 46 | function string.endswith(s, v) 47 | return s:sub(-#v) == v; 48 | end 49 | 50 | ---------------------------------------------------------------------------------------------------- 51 | -- func: string.upperfirst 52 | -- desc: Uppercases the first letter of a string. 53 | ---------------------------------------------------------------------------------------------------- 54 | function string.upperfirst(s) 55 | return s:sub(1, 1):upper() .. s:sub(2); 56 | end 57 | 58 | ---------------------------------------------------------------------------------------------------- 59 | -- func: string.toproper 60 | -- desc: Converts a string to proper casing. 61 | ---------------------------------------------------------------------------------------------------- 62 | function string.toproper(s) 63 | local ret = ''; 64 | local t = { }; 65 | 66 | for x = 1, s:len() do 67 | t[x] = s:sub(x, x); 68 | if (t[x - 1] == ' ' or x == 1) then 69 | t[x] = t[x]:upperfirst(); 70 | end 71 | ret = ret .. t[x]; 72 | end 73 | return ret; 74 | end 75 | 76 | ---------------------------------------------------------------------------------------------------- 77 | -- func: string.insert 78 | -- desc: Inserts data into the current string at the given position. 79 | ---------------------------------------------------------------------------------------------------- 80 | function string.insert(s, p, v) 81 | local part = s:sub(1, p - 1); 82 | return part .. v .. s:sub(#part + 1); 83 | end 84 | 85 | ---------------------------------------------------------------------------------------------------- 86 | -- func: string.remove 87 | -- desc: Removes the character at the given index. 88 | ---------------------------------------------------------------------------------------------------- 89 | function string.remove(s, index) 90 | return s:sub(0, index - 1) .. s:sub(index + 1); 91 | end 92 | 93 | ---------------------------------------------------------------------------------------------------- 94 | -- func: string.lpad 95 | -- desc: Pads a string 'n' times with the given string. 96 | ---------------------------------------------------------------------------------------------------- 97 | function string.lpad(s, v, n) 98 | return (v:rep(n) .. s):sub(-(n > #s and n or #s)); 99 | end 100 | 101 | ---------------------------------------------------------------------------------------------------- 102 | -- func: string.rpad 103 | -- desc: Pads a string 'n' times with the given string. 104 | ---------------------------------------------------------------------------------------------------- 105 | function string.rpad(s, v, n) 106 | return (s .. v:rep(n)):sub(1, -(n > #s and n or #s)); 107 | end 108 | 109 | ---------------------------------------------------------------------------------------------------- 110 | -- func: string.hex 111 | -- desc: Converts a strings value to a hex string. 112 | ---------------------------------------------------------------------------------------------------- 113 | function string.hex(s, sep) 114 | sep = sep or ' '; 115 | 116 | local ret = ''; 117 | for _, v in pairs(s:totable()) do 118 | ret = ret .. string.format('%02X', v) .. sep; 119 | end 120 | return ret:trim(); 121 | end 122 | 123 | ---------------------------------------------------------------------------------------------------- 124 | -- func: string.fromhex 125 | -- desc: Converts a hex value to a string. 126 | ---------------------------------------------------------------------------------------------------- 127 | function string.fromhex(s) 128 | s = s:gsub('%s*0x', ''):gsub('[^%w]', ''); 129 | return (s:gsub('%w%w', function(c) return string.char(tonumber(c, 16)); end)); 130 | end 131 | 132 | ---------------------------------------------------------------------------------------------------- 133 | -- func: string.totable 134 | -- desc: Converts the characters of a string to a table. 135 | ---------------------------------------------------------------------------------------------------- 136 | function string.totable(s) 137 | local ret = { }; 138 | for x = 1, string.len(s) do 139 | ret[x] = string.byte(s, x); 140 | end 141 | return ret; 142 | end 143 | 144 | ---------------------------------------------------------------------------------------------------- 145 | -- func: string.clean 146 | -- desc: Cleans a string of whitespace. 147 | ---------------------------------------------------------------------------------------------------- 148 | function string.clean(s, trimend) 149 | if (trimend == nil) then trimend = true; end 150 | if (trimend) then 151 | return s:gsub('%s+', ' '):trim(); 152 | else 153 | return (s:gsub('%s+', ' ')); 154 | end 155 | end 156 | 157 | ---------------------------------------------------------------------------------------------------- 158 | -- func: string.trimstart 159 | -- desc: Trims the start of a string for whitespace. 160 | ---------------------------------------------------------------------------------------------------- 161 | function string.trimstart(s, c) 162 | if (not c) then c = ' '; end 163 | s = string.reverse(s); 164 | s = string.trimend(s, c); 165 | return string.reverse(s); 166 | end 167 | 168 | ---------------------------------------------------------------------------------------------------- 169 | -- func: string.trimend 170 | -- desc: Trims the end of a string for whitespace. 171 | ---------------------------------------------------------------------------------------------------- 172 | function string.trimend(s, c) 173 | if (not c) then c = ' '; end 174 | if (string.sub(s, -1) == c) then 175 | s = string.sub(s, 0, -2); 176 | s = string.trimend(s, c); 177 | end 178 | return s; 179 | end 180 | 181 | ---------------------------------------------------------------------------------------------------- 182 | -- func: string.trim 183 | -- desc: Trims a string of whitespace. 184 | ---------------------------------------------------------------------------------------------------- 185 | function string.trim(s, c) 186 | if (not c) then c = ' '; end 187 | s = string.trimstart(s, c); 188 | s = string.trimend(s, c); 189 | return s; 190 | end 191 | 192 | ---------------------------------------------------------------------------------------------------- 193 | -- func: string.trim2 194 | -- desc: Trims a string of whitespace. (Uses regex.) 195 | ---------------------------------------------------------------------------------------------------- 196 | function string.trim2(s, c) 197 | if (c == nil or c == false) then 198 | return s:match('^%s*(.-)%s*$'); 199 | end 200 | return s:match('^(.-)%s*$'); 201 | end 202 | 203 | ---------------------------------------------------------------------------------------------------- 204 | -- func: string.args 205 | -- desc: Returns a table of arguments parsed from a string. 206 | ---------------------------------------------------------------------------------------------------- 207 | function string:args() 208 | local STATE_NONE = 0; -- Currently within nothing.. 209 | local STATE_WORD = 1; -- Currently within a word.. 210 | local STATE_QUOTE = 2; -- Currently within a quote.. 211 | 212 | local currentState = STATE_NONE; 213 | local currentChar = nil; 214 | local nextChar = nil; 215 | local stringStart = nil; 216 | local args = { }; 217 | 218 | -- Loop the string and self any arguments.. 219 | for x = 1, string.len(self) do 220 | -- Read the current characters.. 221 | currentChar = string.sub(self, x, x); 222 | nextChar = string.sub(self, x + 1, x+1); 223 | 224 | -- Handle non-state.. 225 | if (currentState == STATE_NONE) then 226 | if (currentChar == '"') then 227 | stringStart = x+1; 228 | currentState = STATE_QUOTE; 229 | else 230 | if (currentChar ~= ' ') then 231 | stringStart = x; 232 | currentState = STATE_WORD; 233 | end 234 | end 235 | 236 | -- Handle quoted string state.. 237 | elseif (currentState == STATE_QUOTE) then 238 | if (currentChar == '"') then 239 | currentState = STATE_NONE; 240 | table.insert(args, #args+1, string.sub(self, stringStart, x - 1)); 241 | end 242 | 243 | -- Handle word string state.. 244 | elseif (currentState == STATE_WORD) then 245 | if (currentChar == ' ' or nextChar == nil or nextChar == '\0') then 246 | currentState = STATE_NONE; 247 | table.insert(args, #args+1, string.sub(self, stringStart, x - 1)); 248 | end 249 | else 250 | error('Invalid word state while parsing command arguments.'); 251 | end 252 | end 253 | 254 | -- If in a word insert into the args table.. 255 | if (currentState == STATE_WORD) then 256 | table.insert(args, #args + 1, string.sub(self, stringStart, #self + 1)); 257 | end 258 | 259 | -- Return the found arguments.. 260 | return args; 261 | end 262 | 263 | ---------------------------------------------------------------------------------------------------- 264 | -- func: string.is_quoted_arg 265 | -- desc: Determines if the string is quoted. 266 | ---------------------------------------------------------------------------------------------------- 267 | function string.is_quoted_arg() 268 | local arg = string.match(self, "^\"(.*)\"$"); 269 | return (arg ~= nil), arg; 270 | end 271 | 272 | ---------------------------------------------------------------------------------------------------- 273 | -- func: string.parseargs 274 | -- desc: Returns a table of arguments parsed from a string. 275 | ---------------------------------------------------------------------------------------------------- 276 | function string:parseargs() 277 | local STATE_NONE = 0; -- Currently within nothing.. 278 | local STATE_WORD = 1; -- Currently within a word.. 279 | local STATE_QUOTE = 2; -- Currently within a quote.. 280 | 281 | local currentState = STATE_NONE; 282 | local currentChar = nil; 283 | local nextChar = nil; 284 | local stringStart = nil; 285 | local prefix = nil; 286 | local args = { }; 287 | 288 | -- Loop the string and self any arguments.. 289 | for x = 1, string.len(self) do 290 | -- Read the current characters.. 291 | currentChar = string.sub(self, x, x); 292 | nextChar = string.sub(self, x + 1, x + 1); 293 | 294 | -- Ensure the command starts with a slash.. 295 | if (x == 1 and currentChar ~= '/') then 296 | return nil; 297 | end 298 | 299 | -- Handle non-state.. 300 | if (currentState == STATE_NONE) then 301 | if (currentChar == '"') then 302 | stringStart = x; 303 | currentState = STATE_QUOTE; 304 | elseif (currentChar ~= ' ') then 305 | stringStart = x; 306 | currentState = STATE_WORD; 307 | end 308 | 309 | -- Handle quoted string state.. 310 | elseif (currentState == STATE_QUOTE) then 311 | if (currentChar == '"') then 312 | table.insert(args, #args + 1, string.sub(self, stringStart, x)); 313 | currentState = STATE_NONE; 314 | end 315 | 316 | -- Handle word string state.. 317 | elseif (currentState == STATE_WORD) then 318 | if (currentChar == ' ') then 319 | table.insert(args, #args+1, string.sub(self, stringStart, x - 1)); 320 | if (prefix == nil) then 321 | prefix = args[#args]; 322 | end 323 | currentState = STATE_NONE; 324 | elseif (nextChar == nil or nextChar == '\0') then 325 | -- This section never actually seems to get hit during processing. 326 | -- Regardless, it needs to use a different endpoint than the block above. 327 | table.insert(args, #args + 1, string.sub(self, stringStart, x)); 328 | if (prefix == nil) then 329 | prefix = args[#args]; 330 | end 331 | currentState = STATE_NONE; 332 | elseif (prefix == nil and currentChar == '/' and x == (stringStart + 1)) then 333 | -- If command line starts with //, put that in its own argument field 334 | table.insert(args, #args + 1, string.sub(self, stringStart, x)); 335 | prefix = args[#args]; 336 | currentState = STATE_NONE; 337 | elseif (currentChar == '"') then 338 | -- A quote mark should start a new quote arg, even if there is no space delimiter. 339 | table.insert(args, #args + 1, string.sub(self, stringStart, x - 1)); 340 | currentState = STATE_QUOTE; 341 | stringStart = x; 342 | end 343 | else 344 | error('Invalid word state while parsing command arguments.'); 345 | end 346 | end 347 | 348 | -- If in a word insert into the args table.. 349 | if (currentState == STATE_WORD) then 350 | table.insert(args, #args + 1, string.sub(self, stringStart, #self)); 351 | end 352 | 353 | -- Return the found arguments.. 354 | return args; 355 | end -------------------------------------------------------------------------------- /addons/libs/extensions/table.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | * rMod - Copyright (c) 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using rMod, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (rMod) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (rMod), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * rMod project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | ]]-- 25 | 26 | ---------------------------------------------------------------------------------------------------- 27 | -- func: table.copy 28 | -- desc: Creates a new copy of the given table. 29 | ---------------------------------------------------------------------------------------------------- 30 | function table.copy(t) 31 | -- Ensure the incoming object is a table.. 32 | if (type(t) ~= 'table') then 33 | return 't'; 34 | end 35 | 36 | local t_mt = getmetatable(t); 37 | local copy = { }; 38 | 39 | -- Make a copy of all inner-tables.. 40 | for k, v in pairs(t) do 41 | if (type(v) == 'table') then 42 | v = table.copy(v); 43 | end 44 | copy[k] = v; 45 | end 46 | 47 | -- Update the metatable.. 48 | setmetatable(copy, t_mt); 49 | return copy; 50 | end 51 | 52 | ---------------------------------------------------------------------------------------------------- 53 | -- func: table.count 54 | -- desc: Returns the count of elements in the table. 55 | ---------------------------------------------------------------------------------------------------- 56 | function table.count(t) 57 | local count = 0; 58 | for _, _ in pairs(t) do 59 | count = count + 1; 60 | end 61 | return count; 62 | end 63 | 64 | ---------------------------------------------------------------------------------------------------- 65 | -- func: table.haskey 66 | -- desc: Determines if the table has a given key. 67 | ---------------------------------------------------------------------------------------------------- 68 | function table.haskey(t, key) 69 | for k, _ in pairs(t) do 70 | if (k == key) then 71 | return true; 72 | end 73 | end 74 | return false; 75 | end 76 | 77 | ---------------------------------------------------------------------------------------------------- 78 | -- func: table.hasvalue 79 | -- desc: Determines if the table has the given value. 80 | ---------------------------------------------------------------------------------------------------- 81 | function table.hasvalue(t, val) 82 | for _, v in pairs(t) do 83 | if (v == val) then 84 | return true; 85 | end 86 | end 87 | return false; 88 | end 89 | 90 | ---------------------------------------------------------------------------------------------------- 91 | -- func: table.merge 92 | -- desc: Merges a table into another one, populating missing entries. 93 | ---------------------------------------------------------------------------------------------------- 94 | function table.merge(src, dest) 95 | for k, v in pairs(src) do 96 | if (type(v) == 'table') then 97 | if (dest[k] == nil) then 98 | dest[k] = v; 99 | else 100 | table.merge(v, dest[k]); 101 | end 102 | else 103 | if (dest[k] == nil) then 104 | dest[k] = v; 105 | end 106 | end 107 | end 108 | return dest; 109 | end 110 | 111 | ---------------------------------------------------------------------------------------------------- 112 | -- func: table.null 113 | -- desc: Nils all values of the given table. 114 | ---------------------------------------------------------------------------------------------------- 115 | function table.null(t) 116 | for k, _ in pairs(t) do 117 | t[k] = nil; 118 | end 119 | end 120 | 121 | ---------------------------------------------------------------------------------------------------- 122 | -- func: table.reverse 123 | -- desc: Reverses the order of elements in a table. 124 | ---------------------------------------------------------------------------------------------------- 125 | function table.reverse(t) 126 | local len = #t; 127 | local ret = { }; 128 | 129 | for x = len, 1, -1 do 130 | ret[len - x + 1] = t[x]; 131 | end 132 | 133 | return ret; 134 | end 135 | 136 | ---------------------------------------------------------------------------------------------------- 137 | -- func: table.sortbykey 138 | -- desc: Sorts the given table by its keys. 139 | ---------------------------------------------------------------------------------------------------- 140 | function table.sortbykey(t, desc) 141 | local ret = { }; 142 | 143 | for k, _ in pairs(t) do 144 | table.insert(ret, k); 145 | end 146 | 147 | if (desc) then 148 | table.sort(ret, function(a, b) return t[a] < t[b]; end); 149 | else 150 | table.sort(ret, function(a, b) return t[a] > t[b]; end); 151 | end 152 | 153 | return ret; 154 | end 155 | 156 | ---------------------------------------------------------------------------------------------------- 157 | -- func: table.sum 158 | -- desc: Gets the sum of all number elements of a table. 159 | ---------------------------------------------------------------------------------------------------- 160 | function table.sum(t) 161 | local val = 0; 162 | for _, v in ipairs(t) do 163 | if (type(v) == 'number') then 164 | val = val + v; 165 | end 166 | end 167 | return val; 168 | end 169 | 170 | ---------------------------------------------------------------------------------------------------- 171 | -- func: table.mult 172 | -- desc: Gets the product of all number elements of a table. 173 | ---------------------------------------------------------------------------------------------------- 174 | function table.mult(t) 175 | local val = 0; 176 | for _, v in ipairs(t) do 177 | if (type(v) == 'number') then 178 | val = val * v; 179 | end 180 | end 181 | return val; 182 | end 183 | 184 | ---------------------------------------------------------------------------------------------------- 185 | -- func: table.min 186 | -- desc: Returns the lowest numeric value within a table. 187 | ---------------------------------------------------------------------------------------------------- 188 | function table.min(t) 189 | local val = nil; 190 | for _, v in ipairs(t) do 191 | if (type(v) == 'number') then 192 | if (val == nil) then 193 | val = v; 194 | else 195 | if (v < val) then 196 | val = v; 197 | end 198 | end 199 | end 200 | end 201 | return val; 202 | end 203 | 204 | ---------------------------------------------------------------------------------------------------- 205 | -- func: table.max 206 | -- desc: Returns the highest numeric value within a table. 207 | ---------------------------------------------------------------------------------------------------- 208 | function table.max(t) 209 | local val = nil; 210 | for _, v in ipairs(t) do 211 | if (type(v) == 'number') then 212 | if (val == nil) then 213 | val = v; 214 | else 215 | if (v > val) then 216 | val = v; 217 | end 218 | end 219 | end 220 | end 221 | return val; 222 | end 223 | 224 | ---------------------------------------------------------------------------------------------------- 225 | -- func: table.join 226 | -- desc: Joins a tables values together into a string with the given separator. 227 | ---------------------------------------------------------------------------------------------------- 228 | function table.join(t, sep) 229 | local ret = ''; 230 | sep = sep or ''; 231 | for k, v in pairs(t) do 232 | if (#ret == 0) then 233 | ret = tostring(v); 234 | else 235 | ret = ret .. sep .. tostring(v); 236 | end 237 | end 238 | return ret; 239 | end 240 | 241 | ---------------------------------------------------------------------------------------------------- 242 | -- func: table.foreach 243 | -- desc: Executes the given function against each table value. 244 | ---------------------------------------------------------------------------------------------------- 245 | function table.foreach(t, func) 246 | local ret = T{ }; 247 | for k, v in pairs(t) do 248 | ret[k] = func(k, v); 249 | end 250 | return ret; 251 | end 252 | 253 | ---------------------------------------------------------------------------------------------------- 254 | -- func: table.keys 255 | -- desc: Returns a table of keys from the given table. 256 | ---------------------------------------------------------------------------------------------------- 257 | function table.keys(t) 258 | local ret = { }; 259 | local count = 1; 260 | for k, _ in pairs(t) do 261 | ret[count] = k; 262 | count = count + 1; 263 | end 264 | return ret; 265 | end 266 | 267 | ---------------------------------------------------------------------------------------------------- 268 | -- func: T 269 | -- desc: Creates a metatable enabled table object. 270 | ---------------------------------------------------------------------------------------------------- 271 | function T(t) 272 | return setmetatable(t, { __index = table }); 273 | end -------------------------------------------------------------------------------- /addons/libs/hook/helpers.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | * rMod - Copyright (c) 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using rMod, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (rMod) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (rMod), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * rMod project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | ]]-- 25 | 26 | hook = hook or { }; 27 | 28 | ---------------------------------------------------------------------------------------------------- 29 | -- func: switch 30 | -- desc: Implements a C-Style switch-case handling within Lua. 31 | -- cred: Credits to: Luiz Henrique de Figueiredo's implementation, this is based on his. 32 | -- link: http://lua-users.org/wiki/SwitchStatement (Caseof Method Table) 33 | ---------------------------------------------------------------------------------------------------- 34 | function switch(c) 35 | local switch_table = 36 | { 37 | casevar = c, 38 | caseof = function(self, code) 39 | local f; 40 | if (self.casevar) then 41 | f = code[self.casevar] or code.default; 42 | else 43 | f = code.missing or code.default; 44 | end 45 | if (f) then 46 | if (type(f) == 'function') then 47 | return f(self.casevar, self); 48 | else 49 | error('case: ' .. tostring(self.casevar)); 50 | end 51 | end 52 | end 53 | }; 54 | return switch_table; 55 | end 56 | 57 | ---------------------------------------------------------------------------------------------------- 58 | -- func: try (try, catch, finally) 59 | -- desc: Implements C++ style try/catch handlers, and introduces C# style finally. 60 | -- cred: djfdyuruiry 61 | -- link: https://github.com/djfdyuruiry/lua-try-catch-finally/blob/master/try-catch-finally.lua 62 | ---------------------------------------------------------------------------------------------------- 63 | function try(trycb) 64 | local status, err = true, nil; 65 | 66 | -- Handle the try block if it is a proper function.. 67 | if (type(trycb) == 'function') then 68 | status, err = xpcall(trycb, debug.traceback); 69 | end 70 | 71 | ------------------------------------------------------------------------------------------------ 72 | -- func: finally 73 | -- desc: Implements the 'finally' callback handling for the try/catch/finally setup. 74 | ------------------------------------------------------------------------------------------------ 75 | local finally = function(finallycb, hascatchcb) 76 | -- Invoke the finally callback if present.. 77 | if (type(finallycb) == 'function') then 78 | finallycb(); 79 | end 80 | 81 | -- Throw error if no catch callback is defined.. 82 | if (not hascatchcb and not status) then 83 | error(err); 84 | end 85 | end 86 | 87 | ------------------------------------------------------------------------------------------------ 88 | -- func: catch 89 | -- desc: Implements the 'catch' callback handling for the try/catch/finally setup. 90 | ------------------------------------------------------------------------------------------------ 91 | local catch = function(catchcb) 92 | local hascatchcb = type(catchcb) == 'function'; 93 | 94 | -- Invoke the catch callback if valid and an error was caught.. 95 | if (not status and hascatchcb) then 96 | local e = err or '(Unknown Error)'; 97 | catchcb(e); 98 | end 99 | 100 | -- Return a table exposing the finally handler.. 101 | return { 102 | finally = function(finallycb) 103 | finally(finallycb, hascatchcb); 104 | end 105 | }; 106 | end 107 | 108 | -- Return a table exposing the catch and finally handlers.. 109 | return { 110 | catch = catch, 111 | finally = function(finallycb) 112 | finally(finallycb, false); 113 | end 114 | }; 115 | end -------------------------------------------------------------------------------- /addons/libs/ltn12.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- LTN12 - Filters, sources, sinks and pumps. 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: ltn12.lua,v 1.31 2006/04/03 04:45:42 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | 8 | ----------------------------------------------------------------------------- 9 | -- Declare module 10 | ----------------------------------------------------------------------------- 11 | local string = require("string") 12 | local table = require("table") 13 | local base = _G 14 | module("ltn12") 15 | 16 | filter = {} 17 | source = {} 18 | sink = {} 19 | pump = {} 20 | 21 | -- 2048 seems to be better in windows... 22 | BLOCKSIZE = 2048 23 | _VERSION = "LTN12 1.0.1" 24 | 25 | ----------------------------------------------------------------------------- 26 | -- Filter stuff 27 | ----------------------------------------------------------------------------- 28 | -- returns a high level filter that cycles a low-level filter 29 | function filter.cycle(low, ctx, extra) 30 | base.assert(low) 31 | return function(chunk) 32 | local ret 33 | ret, ctx = low(ctx, chunk, extra) 34 | return ret 35 | end 36 | end 37 | 38 | -- chains a bunch of filters together 39 | -- (thanks to Wim Couwenberg) 40 | function filter.chain(...) 41 | local n = table.getn(arg) 42 | local top, index = 1, 1 43 | local retry = "" 44 | return function(chunk) 45 | retry = chunk and retry 46 | while true do 47 | if index == top then 48 | chunk = arg[index](chunk) 49 | if chunk == "" or top == n then return chunk 50 | elseif chunk then index = index + 1 51 | else 52 | top = top+1 53 | index = top 54 | end 55 | else 56 | chunk = arg[index](chunk or "") 57 | if chunk == "" then 58 | index = index - 1 59 | chunk = retry 60 | elseif chunk then 61 | if index == n then return chunk 62 | else index = index + 1 end 63 | else base.error("filter returned inappropriate nil") end 64 | end 65 | end 66 | end 67 | end 68 | 69 | ----------------------------------------------------------------------------- 70 | -- Source stuff 71 | ----------------------------------------------------------------------------- 72 | -- create an empty source 73 | local function empty() 74 | return nil 75 | end 76 | 77 | function source.empty() 78 | return empty 79 | end 80 | 81 | -- returns a source that just outputs an error 82 | function source.error(err) 83 | return function() 84 | return nil, err 85 | end 86 | end 87 | 88 | -- creates a file source 89 | function source.file(handle, io_err) 90 | if handle then 91 | return function() 92 | local chunk = handle:read(BLOCKSIZE) 93 | if not chunk then handle:close() end 94 | return chunk 95 | end 96 | else return source.error(io_err or "unable to open file") end 97 | end 98 | 99 | -- turns a fancy source into a simple source 100 | function source.simplify(src) 101 | base.assert(src) 102 | return function() 103 | local chunk, err_or_new = src() 104 | src = err_or_new or src 105 | if not chunk then return nil, err_or_new 106 | else return chunk end 107 | end 108 | end 109 | 110 | -- creates string source 111 | function source.string(s) 112 | if s then 113 | local i = 1 114 | return function() 115 | local chunk = string.sub(s, i, i+BLOCKSIZE-1) 116 | i = i + BLOCKSIZE 117 | if chunk ~= "" then return chunk 118 | else return nil end 119 | end 120 | else return source.empty() end 121 | end 122 | 123 | -- creates rewindable source 124 | function source.rewind(src) 125 | base.assert(src) 126 | local t = {} 127 | return function(chunk) 128 | if not chunk then 129 | chunk = table.remove(t) 130 | if not chunk then return src() 131 | else return chunk end 132 | else 133 | table.insert(t, chunk) 134 | end 135 | end 136 | end 137 | 138 | function source.chain(src, f) 139 | base.assert(src and f) 140 | local last_in, last_out = "", "" 141 | local state = "feeding" 142 | local err 143 | return function() 144 | if not last_out then 145 | base.error('source is empty!', 2) 146 | end 147 | while true do 148 | if state == "feeding" then 149 | last_in, err = src() 150 | if err then return nil, err end 151 | last_out = f(last_in) 152 | if not last_out then 153 | if last_in then 154 | base.error('filter returned inappropriate nil') 155 | else 156 | return nil 157 | end 158 | elseif last_out ~= "" then 159 | state = "eating" 160 | if last_in then last_in = "" end 161 | return last_out 162 | end 163 | else 164 | last_out = f(last_in) 165 | if last_out == "" then 166 | if last_in == "" then 167 | state = "feeding" 168 | else 169 | base.error('filter returned ""') 170 | end 171 | elseif not last_out then 172 | if last_in then 173 | base.error('filter returned inappropriate nil') 174 | else 175 | return nil 176 | end 177 | else 178 | return last_out 179 | end 180 | end 181 | end 182 | end 183 | end 184 | 185 | -- creates a source that produces contents of several sources, one after the 186 | -- other, as if they were concatenated 187 | -- (thanks to Wim Couwenberg) 188 | function source.cat(...) 189 | local src = table.remove(arg, 1) 190 | return function() 191 | while src do 192 | local chunk, err = src() 193 | if chunk then return chunk end 194 | if err then return nil, err end 195 | src = table.remove(arg, 1) 196 | end 197 | end 198 | end 199 | 200 | ----------------------------------------------------------------------------- 201 | -- Sink stuff 202 | ----------------------------------------------------------------------------- 203 | -- creates a sink that stores into a table 204 | function sink.table(t) 205 | t = t or {} 206 | local f = function(chunk, err) 207 | if chunk then table.insert(t, chunk) end 208 | return 1 209 | end 210 | return f, t 211 | end 212 | 213 | -- turns a fancy sink into a simple sink 214 | function sink.simplify(snk) 215 | base.assert(snk) 216 | return function(chunk, err) 217 | local ret, err_or_new = snk(chunk, err) 218 | if not ret then return nil, err_or_new end 219 | snk = err_or_new or snk 220 | return 1 221 | end 222 | end 223 | 224 | -- creates a file sink 225 | function sink.file(handle, io_err) 226 | if handle then 227 | return function(chunk, err) 228 | if not chunk then 229 | handle:close() 230 | return 1 231 | else return handle:write(chunk) end 232 | end 233 | else return sink.error(io_err or "unable to open file") end 234 | end 235 | 236 | -- creates a sink that discards data 237 | local function null() 238 | return 1 239 | end 240 | 241 | function sink.null() 242 | return null 243 | end 244 | 245 | -- creates a sink that just returns an error 246 | function sink.error(err) 247 | return function() 248 | return nil, err 249 | end 250 | end 251 | 252 | -- chains a sink with a filter 253 | function sink.chain(f, snk) 254 | base.assert(f and snk) 255 | return function(chunk, err) 256 | if chunk ~= "" then 257 | local filtered = f(chunk) 258 | local done = chunk and "" 259 | while true do 260 | local ret, snkerr = snk(filtered, err) 261 | if not ret then return nil, snkerr end 262 | if filtered == done then return 1 end 263 | filtered = f(done) 264 | end 265 | else return 1 end 266 | end 267 | end 268 | 269 | ----------------------------------------------------------------------------- 270 | -- Pump stuff 271 | ----------------------------------------------------------------------------- 272 | -- pumps one chunk from the source to the sink 273 | function pump.step(src, snk) 274 | local chunk, src_err = src() 275 | local ret, snk_err = snk(chunk, src_err) 276 | if chunk and ret then return 1 277 | else return nil, src_err or snk_err end 278 | end 279 | 280 | -- pumps all data from a source to a sink, using a step function 281 | function pump.all(src, snk, step) 282 | base.assert(src and snk) 283 | step = step or pump.step 284 | while true do 285 | local ret, err = step(src, snk) 286 | if not ret then 287 | if err then return nil, err 288 | else return 1 end 289 | end 290 | end 291 | end 292 | 293 | -------------------------------------------------------------------------------- /addons/libs/mime.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- MIME support for the Lua language. 3 | -- Author: Diego Nehab 4 | -- Conforming to RFCs 2045-2049 5 | -- RCS ID: $Id: mime.lua,v 1.29 2007/06/11 23:44:54 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | 8 | ----------------------------------------------------------------------------- 9 | -- Declare module and import dependencies 10 | ----------------------------------------------------------------------------- 11 | local base = _G 12 | local ltn12 = require("ltn12") 13 | local mime = require("mime.core") 14 | local io = require("io") 15 | local string = require("string") 16 | module("mime") 17 | 18 | -- encode, decode and wrap algorithm tables 19 | encodet = {} 20 | decodet = {} 21 | wrapt = {} 22 | 23 | -- creates a function that chooses a filter by name from a given table 24 | local function choose(table) 25 | return function(name, opt1, opt2) 26 | if base.type(name) ~= "string" then 27 | name, opt1, opt2 = "default", name, opt1 28 | end 29 | local f = table[name or "nil"] 30 | if not f then 31 | base.error("unknown key (" .. base.tostring(name) .. ")", 3) 32 | else return f(opt1, opt2) end 33 | end 34 | end 35 | 36 | -- define the encoding filters 37 | encodet['base64'] = function() 38 | return ltn12.filter.cycle(b64, "") 39 | end 40 | 41 | encodet['quoted-printable'] = function(mode) 42 | return ltn12.filter.cycle(qp, "", 43 | (mode == "binary") and "=0D=0A" or "\r\n") 44 | end 45 | 46 | -- define the decoding filters 47 | decodet['base64'] = function() 48 | return ltn12.filter.cycle(unb64, "") 49 | end 50 | 51 | decodet['quoted-printable'] = function() 52 | return ltn12.filter.cycle(unqp, "") 53 | end 54 | 55 | local function format(chunk) 56 | if chunk then 57 | if chunk == "" then return "''" 58 | else return string.len(chunk) end 59 | else return "nil" end 60 | end 61 | 62 | -- define the line-wrap filters 63 | wrapt['text'] = function(length) 64 | length = length or 76 65 | return ltn12.filter.cycle(wrp, length, length) 66 | end 67 | wrapt['base64'] = wrapt['text'] 68 | wrapt['default'] = wrapt['text'] 69 | 70 | wrapt['quoted-printable'] = function() 71 | return ltn12.filter.cycle(qpwrp, 76, 76) 72 | end 73 | 74 | -- function that choose the encoding, decoding or wrap algorithm 75 | encode = choose(encodet) 76 | decode = choose(decodet) 77 | wrap = choose(wrapt) 78 | 79 | -- define the end-of-line normalization filter 80 | function normalize(marker) 81 | return ltn12.filter.cycle(eol, 0, marker) 82 | end 83 | 84 | -- high level stuffing filter 85 | function stuff() 86 | return ltn12.filter.cycle(dot, 2) 87 | end 88 | -------------------------------------------------------------------------------- /addons/libs/reckoning/constants.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | * rMod - Copyright (c) 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using rMod, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (rMod) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (rMod), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * rMod project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | ]]-- 25 | 26 | --[[ 27 | 28 | Data in this file is pulled directly from the game files. 29 | Everything listed here is confirmed and valid for the following game version: v1.0.0.2 30 | 31 | ]]-- 32 | 33 | reckoning = reckoning or { }; 34 | reckoning.constants = reckoning.constants or { }; 35 | 36 | ---------------------------------------------------------------------------------------------------- 37 | -- Misc Constants 38 | ---------------------------------------------------------------------------------------------------- 39 | reckoning.constants.max_fate = 264; 40 | 41 | ---------------------------------------------------------------------------------------------------- 42 | -- Exp Leveling Table 43 | ---------------------------------------------------------------------------------------------------- 44 | reckoning.constants.exp_to_level_table = 45 | { 46 | [0] = 0, 47 | [1] = 500, 48 | [2] = 1600, 49 | [3] = 3400, 50 | [4] = 6000, 51 | [5] = 9500, 52 | [6] = 14000, 53 | [7] = 19700, 54 | [8] = 26600, 55 | [9] = 34900, 56 | [10] = 44600, 57 | [11] = 55900, 58 | [12] = 68800, 59 | [13] = 83500, 60 | [14] = 100000, 61 | [15] = 118500, 62 | [16] = 139000, 63 | [17] = 161500, 64 | [18] = 186000, 65 | [19] = 213500, 66 | [20] = 244000, 67 | [21] = 277500, 68 | [22] = 314000, 69 | [23] = 354500, 70 | [24] = 399000, 71 | [25] = 447500, 72 | [26] = 500000, 73 | [27] = 557500, 74 | [28] = 620000, 75 | [29] = 687500, 76 | [30] = 760000, 77 | [31] = 839500, 78 | [32] = 926000, 79 | [33] = 1019500, 80 | [34] = 1120000, 81 | [35] = 1230500, 82 | [36] = 1351000, 83 | [37] = 1481500, 84 | [38] = 1622000, 85 | [39] = 1777500, 86 | [40] = 1948000, 87 | [41] = 2133500, 88 | [42] = 2334000, 89 | [43] = 2554500, 90 | [44] = 2795000, 91 | [45] = 3055500 92 | }; 93 | 94 | ---------------------------------------------------------------------------------------------------- 95 | -- Exp Leveling Speed Table 96 | ---------------------------------------------------------------------------------------------------- 97 | reckoning.constants.leveling_speed_table = 98 | { 99 | [0] = 150, 100 | [1] = 125, 101 | [2] = 80, 102 | [3] = 70, 103 | [4] = 60, 104 | [5] = 55, 105 | [6] = 50, 106 | [7] = 45, 107 | [8] = 40, 108 | [9] = 35, 109 | [10] = 30, 110 | [11] = 25, 111 | [12] = 20, 112 | [13] = 19, 113 | [14] = 18, 114 | [15] = 17, 115 | [16] = 16, 116 | [17] = 15, 117 | [18] = 14, 118 | [19] = 10, 119 | [20] = 8, 120 | [21] = 6, 121 | [22] = 5 122 | }; -------------------------------------------------------------------------------- /addons/libs/settings.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | * rMod - Copyright (c) 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using rMod, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (rMod) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (rMod), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * rMod project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | ]]-- 25 | 26 | hook = hook or { }; 27 | hook.settings = hook.settings or { }; 28 | 29 | -- Require the Lua JSON library.. 30 | if (hook.settings.JSON == nil) then 31 | hook.settings.JSON = require('json.json'); 32 | end 33 | 34 | ---------------------------------------------------------------------------------------------------- 35 | -- func: normalize_path 36 | -- desc: Normalizes a paths slashes to a single format. 37 | ---------------------------------------------------------------------------------------------------- 38 | local function normalize_path(path) 39 | local p = path:gsub('/', '\\'); 40 | local i = p:find('\\'); 41 | 42 | while (i ~= nil) do 43 | if (p:sub(i + 1, i + 1) == '\\') then 44 | p = p:remove(i); 45 | i = p:find('\\'); 46 | else 47 | i = p:find('\\', i + 1); 48 | end 49 | end 50 | return p; 51 | end 52 | 53 | ---------------------------------------------------------------------------------------------------- 54 | -- func: path_from_file 55 | -- desc: Obtains a path from a file location. 56 | ---------------------------------------------------------------------------------------------------- 57 | local function path_from_file(f) 58 | -- Ensure the given data has a file extension.. 59 | if (f:find('%.') == nil) then 60 | return f; 61 | end 62 | 63 | -- Find the location of the first slash.. 64 | local s = f:find('\\'); 65 | if (s == nil) then return f; end 66 | 67 | -- Find the last slash location.. 68 | while (true) do 69 | local c = f:find('\\', s + 1); 70 | if (c == nil) then break; end 71 | s = c; 72 | end 73 | 74 | -- Pull and return the file path.. 75 | return f:sub(0, s - 1); 76 | end 77 | 78 | ---------------------------------------------------------------------------------------------------- 79 | -- func: save_settings 80 | -- desc: Saves a table, as JSON, to the given file. 81 | ---------------------------------------------------------------------------------------------------- 82 | local function save_settings(name, t) 83 | -- Convert the table to json.. 84 | local data = hook.settings.JSON:encode_pretty(t, nil, { pretty = true, align_keys = false, indent = ' ' }); 85 | if (data == nil) then 86 | error('Failed to convert data to JSON for saving.'); 87 | return false; 88 | end 89 | 90 | -- Normalize the path.. 91 | local name = normalize_path(name); 92 | 93 | -- Ensure the path exists.. 94 | local dir = path_from_file(name); 95 | if (not hook.file.dir_exists(dir)) then 96 | hook.file.create_dir(dir); 97 | end 98 | 99 | -- Save the config file.. 100 | local f = io.open(name, 'w'); 101 | if (f == nil) then 102 | error('Failed to save configuration.'); 103 | return false; 104 | end 105 | 106 | -- Write and close the file.. 107 | f:write(data); 108 | f:close(); 109 | 110 | return true; 111 | end 112 | hook.settings.save = save_settings; 113 | 114 | ---------------------------------------------------------------------------------------------------- 115 | -- func: load_settings 116 | -- desc: Loads a json settings file and converts its data to a Lua table. 117 | ---------------------------------------------------------------------------------------------------- 118 | local function load_settings(name) 119 | -- Load the file for reading.. 120 | local f = io.open(name, 'r'); 121 | if (f == nil) then 122 | return nil; 123 | end 124 | 125 | -- Read the full file contents.. 126 | local raw = f:read('*a'); 127 | f:close(); 128 | 129 | -- Convert the JSON to a Lua table.. 130 | local data = hook.settings.JSON:decode(raw); 131 | if (type(data) == 'table') then return data; end 132 | 133 | -- Failed to convert.. 134 | return nil; 135 | end 136 | hook.settings.load = load_settings; 137 | 138 | ---------------------------------------------------------------------------------------------------- 139 | -- func: load_settings_merged 140 | -- desc: Loads a json settings file and converts its data to a Lua table. Afterward, merges the 141 | -- loaded settings into the parent table. 142 | ---------------------------------------------------------------------------------------------------- 143 | local function load_settings_merged(name, parent) 144 | -- Ensure the parent table is valid.. 145 | if (parent == nil or type(parent) ~= 'table') then 146 | return nil; 147 | end 148 | 149 | -- Load the settings.. 150 | local data = hook.settings.load(name); 151 | if (data == nil) then 152 | return parent; 153 | end 154 | 155 | -- Merge the tables.. 156 | return table.merge(parent, data); 157 | end 158 | hook.settings.load_merged = load_settings_merged; -------------------------------------------------------------------------------- /addons/libs/socket.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- LuaSocket helper module 3 | -- Author: Diego Nehab 4 | -- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $ 5 | ----------------------------------------------------------------------------- 6 | 7 | ----------------------------------------------------------------------------- 8 | -- Declare module and import dependencies 9 | ----------------------------------------------------------------------------- 10 | local base = _G 11 | local string = require("string") 12 | local math = require("math") 13 | local socket = require("socket.core") 14 | module("socket") 15 | 16 | ----------------------------------------------------------------------------- 17 | -- Exported auxiliar functions 18 | ----------------------------------------------------------------------------- 19 | function connect(address, port, laddress, lport) 20 | local sock, err = socket.tcp() 21 | if not sock then return nil, err end 22 | if laddress then 23 | local res, err = sock:bind(laddress, lport, -1) 24 | if not res then return nil, err end 25 | end 26 | local res, err = sock:connect(address, port) 27 | if not res then return nil, err end 28 | return sock 29 | end 30 | 31 | function bind(host, port, backlog) 32 | local sock, err = socket.tcp() 33 | if not sock then return nil, err end 34 | sock:setoption("reuseaddr", true) 35 | local res, err = sock:bind(host, port) 36 | if not res then return nil, err end 37 | res, err = sock:listen(backlog) 38 | if not res then return nil, err end 39 | return sock 40 | end 41 | 42 | try = newtry() 43 | 44 | function choose(table) 45 | return function(name, opt1, opt2) 46 | if base.type(name) ~= "string" then 47 | name, opt1, opt2 = "default", name, opt1 48 | end 49 | local f = table[name or "nil"] 50 | if not f then base.error("unknown key (".. base.tostring(name) ..")", 3) 51 | else return f(opt1, opt2) end 52 | end 53 | end 54 | 55 | ----------------------------------------------------------------------------- 56 | -- Socket sources and sinks, conforming to LTN12 57 | ----------------------------------------------------------------------------- 58 | -- create namespaces inside LuaSocket namespace 59 | sourcet = {} 60 | sinkt = {} 61 | 62 | BLOCKSIZE = 2048 63 | 64 | sinkt["close-when-done"] = function(sock) 65 | return base.setmetatable({ 66 | getfd = function() return sock:getfd() end, 67 | dirty = function() return sock:dirty() end 68 | }, { 69 | __call = function(self, chunk, err) 70 | if not chunk then 71 | sock:close() 72 | return 1 73 | else return sock:send(chunk) end 74 | end 75 | }) 76 | end 77 | 78 | sinkt["keep-open"] = function(sock) 79 | return base.setmetatable({ 80 | getfd = function() return sock:getfd() end, 81 | dirty = function() return sock:dirty() end 82 | }, { 83 | __call = function(self, chunk, err) 84 | if chunk then return sock:send(chunk) 85 | else return 1 end 86 | end 87 | }) 88 | end 89 | 90 | sinkt["default"] = sinkt["keep-open"] 91 | 92 | sink = choose(sinkt) 93 | 94 | sourcet["by-length"] = function(sock, length) 95 | return base.setmetatable({ 96 | getfd = function() return sock:getfd() end, 97 | dirty = function() return sock:dirty() end 98 | }, { 99 | __call = function() 100 | if length <= 0 then return nil end 101 | local size = math.min(socket.BLOCKSIZE, length) 102 | local chunk, err = sock:receive(size) 103 | if err then return nil, err end 104 | length = length - string.len(chunk) 105 | return chunk 106 | end 107 | }) 108 | end 109 | 110 | sourcet["until-closed"] = function(sock) 111 | local done 112 | return base.setmetatable({ 113 | getfd = function() return sock:getfd() end, 114 | dirty = function() return sock:dirty() end 115 | }, { 116 | __call = function() 117 | if done then return nil end 118 | local chunk, err, partial = sock:receive(socket.BLOCKSIZE) 119 | if not err then return chunk 120 | elseif err == "closed" then 121 | sock:close() 122 | done = 1 123 | return partial 124 | else return nil, err end 125 | end 126 | }) 127 | end 128 | 129 | 130 | sourcet["default"] = sourcet["until-closed"] 131 | 132 | source = choose(sourcet) -------------------------------------------------------------------------------- /addons/libs/socket/ftp.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- FTP support for the Lua language 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: ftp.lua,v 1.45 2007/07/11 19:25:47 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | 8 | ----------------------------------------------------------------------------- 9 | -- Declare module and import dependencies 10 | ----------------------------------------------------------------------------- 11 | local base = _G 12 | local table = require("table") 13 | local string = require("string") 14 | local math = require("math") 15 | local socket = require("socket") 16 | local url = require("socket.url") 17 | local tp = require("socket.tp") 18 | local ltn12 = require("ltn12") 19 | module("socket.ftp") 20 | 21 | ----------------------------------------------------------------------------- 22 | -- Program constants 23 | ----------------------------------------------------------------------------- 24 | -- timeout in seconds before the program gives up on a connection 25 | TIMEOUT = 60 26 | -- default port for ftp service 27 | PORT = 21 28 | -- this is the default anonymous password. used when no password is 29 | -- provided in url. should be changed to your e-mail. 30 | USER = "ftp" 31 | PASSWORD = "anonymous@anonymous.org" 32 | 33 | ----------------------------------------------------------------------------- 34 | -- Low level FTP API 35 | ----------------------------------------------------------------------------- 36 | local metat = { __index = {} } 37 | 38 | function open(server, port, create) 39 | local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT, create)) 40 | local f = base.setmetatable({ tp = tp }, metat) 41 | -- make sure everything gets closed in an exception 42 | f.try = socket.newtry(function() f:close() end) 43 | return f 44 | end 45 | 46 | function metat.__index:portconnect() 47 | self.try(self.server:settimeout(TIMEOUT)) 48 | self.data = self.try(self.server:accept()) 49 | self.try(self.data:settimeout(TIMEOUT)) 50 | end 51 | 52 | function metat.__index:pasvconnect() 53 | self.data = self.try(socket.tcp()) 54 | self.try(self.data:settimeout(TIMEOUT)) 55 | self.try(self.data:connect(self.pasvt.ip, self.pasvt.port)) 56 | end 57 | 58 | function metat.__index:login(user, password) 59 | self.try(self.tp:command("user", user or USER)) 60 | local code, reply = self.try(self.tp:check{"2..", 331}) 61 | if code == 331 then 62 | self.try(self.tp:command("pass", password or PASSWORD)) 63 | self.try(self.tp:check("2..")) 64 | end 65 | return 1 66 | end 67 | 68 | function metat.__index:pasv() 69 | self.try(self.tp:command("pasv")) 70 | local code, reply = self.try(self.tp:check("2..")) 71 | local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)" 72 | local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern)) 73 | self.try(a and b and c and d and p1 and p2, reply) 74 | self.pasvt = { 75 | ip = string.format("%d.%d.%d.%d", a, b, c, d), 76 | port = p1*256 + p2 77 | } 78 | if self.server then 79 | self.server:close() 80 | self.server = nil 81 | end 82 | return self.pasvt.ip, self.pasvt.port 83 | end 84 | 85 | function metat.__index:port(ip, port) 86 | self.pasvt = nil 87 | if not ip then 88 | ip, port = self.try(self.tp:getcontrol():getsockname()) 89 | self.server = self.try(socket.bind(ip, 0)) 90 | ip, port = self.try(self.server:getsockname()) 91 | self.try(self.server:settimeout(TIMEOUT)) 92 | end 93 | local pl = math.mod(port, 256) 94 | local ph = (port - pl)/256 95 | local arg = string.gsub(string.format("%s,%d,%d", ip, ph, pl), "%.", ",") 96 | self.try(self.tp:command("port", arg)) 97 | self.try(self.tp:check("2..")) 98 | return 1 99 | end 100 | 101 | function metat.__index:send(sendt) 102 | self.try(self.pasvt or self.server, "need port or pasv first") 103 | -- if there is a pasvt table, we already sent a PASV command 104 | -- we just get the data connection into self.data 105 | if self.pasvt then self:pasvconnect() end 106 | -- get the transfer argument and command 107 | local argument = sendt.argument or 108 | url.unescape(string.gsub(sendt.path or "", "^[/\\]", "")) 109 | if argument == "" then argument = nil end 110 | local command = sendt.command or "stor" 111 | -- send the transfer command and check the reply 112 | self.try(self.tp:command(command, argument)) 113 | local code, reply = self.try(self.tp:check{"2..", "1.."}) 114 | -- if there is not a a pasvt table, then there is a server 115 | -- and we already sent a PORT command 116 | if not self.pasvt then self:portconnect() end 117 | -- get the sink, source and step for the transfer 118 | local step = sendt.step or ltn12.pump.step 119 | local readt = {self.tp.c} 120 | local checkstep = function(src, snk) 121 | -- check status in control connection while downloading 122 | local readyt = socket.select(readt, nil, 0) 123 | if readyt[tp] then code = self.try(self.tp:check("2..")) end 124 | return step(src, snk) 125 | end 126 | local sink = socket.sink("close-when-done", self.data) 127 | -- transfer all data and check error 128 | self.try(ltn12.pump.all(sendt.source, sink, checkstep)) 129 | if string.find(code, "1..") then self.try(self.tp:check("2..")) end 130 | -- done with data connection 131 | self.data:close() 132 | -- find out how many bytes were sent 133 | local sent = socket.skip(1, self.data:getstats()) 134 | self.data = nil 135 | return sent 136 | end 137 | 138 | function metat.__index:receive(recvt) 139 | self.try(self.pasvt or self.server, "need port or pasv first") 140 | if self.pasvt then self:pasvconnect() end 141 | local argument = recvt.argument or 142 | url.unescape(string.gsub(recvt.path or "", "^[/\\]", "")) 143 | if argument == "" then argument = nil end 144 | local command = recvt.command or "retr" 145 | self.try(self.tp:command(command, argument)) 146 | local code = self.try(self.tp:check{"1..", "2.."}) 147 | if not self.pasvt then self:portconnect() end 148 | local source = socket.source("until-closed", self.data) 149 | local step = recvt.step or ltn12.pump.step 150 | self.try(ltn12.pump.all(source, recvt.sink, step)) 151 | if string.find(code, "1..") then self.try(self.tp:check("2..")) end 152 | self.data:close() 153 | self.data = nil 154 | return 1 155 | end 156 | 157 | function metat.__index:cwd(dir) 158 | self.try(self.tp:command("cwd", dir)) 159 | self.try(self.tp:check(250)) 160 | return 1 161 | end 162 | 163 | function metat.__index:type(type) 164 | self.try(self.tp:command("type", type)) 165 | self.try(self.tp:check(200)) 166 | return 1 167 | end 168 | 169 | function metat.__index:greet() 170 | local code = self.try(self.tp:check{"1..", "2.."}) 171 | if string.find(code, "1..") then self.try(self.tp:check("2..")) end 172 | return 1 173 | end 174 | 175 | function metat.__index:quit() 176 | self.try(self.tp:command("quit")) 177 | self.try(self.tp:check("2..")) 178 | return 1 179 | end 180 | 181 | function metat.__index:close() 182 | if self.data then self.data:close() end 183 | if self.server then self.server:close() end 184 | return self.tp:close() 185 | end 186 | 187 | ----------------------------------------------------------------------------- 188 | -- High level FTP API 189 | ----------------------------------------------------------------------------- 190 | local function override(t) 191 | if t.url then 192 | local u = url.parse(t.url) 193 | for i,v in base.pairs(t) do 194 | u[i] = v 195 | end 196 | return u 197 | else return t end 198 | end 199 | 200 | local function tput(putt) 201 | putt = override(putt) 202 | socket.try(putt.host, "missing hostname") 203 | local f = open(putt.host, putt.port, putt.create) 204 | f:greet() 205 | f:login(putt.user, putt.password) 206 | if putt.type then f:type(putt.type) end 207 | f:pasv() 208 | local sent = f:send(putt) 209 | f:quit() 210 | f:close() 211 | return sent 212 | end 213 | 214 | local default = { 215 | path = "/", 216 | scheme = "ftp" 217 | } 218 | 219 | local function parse(u) 220 | local t = socket.try(url.parse(u, default)) 221 | socket.try(t.scheme == "ftp", "wrong scheme '" .. t.scheme .. "'") 222 | socket.try(t.host, "missing hostname") 223 | local pat = "^type=(.)$" 224 | if t.params then 225 | t.type = socket.skip(2, string.find(t.params, pat)) 226 | socket.try(t.type == "a" or t.type == "i", 227 | "invalid type '" .. t.type .. "'") 228 | end 229 | return t 230 | end 231 | 232 | local function sput(u, body) 233 | local putt = parse(u) 234 | putt.source = ltn12.source.string(body) 235 | return tput(putt) 236 | end 237 | 238 | put = socket.protect(function(putt, body) 239 | if base.type(putt) == "string" then return sput(putt, body) 240 | else return tput(putt) end 241 | end) 242 | 243 | local function tget(gett) 244 | gett = override(gett) 245 | socket.try(gett.host, "missing hostname") 246 | local f = open(gett.host, gett.port, gett.create) 247 | f:greet() 248 | f:login(gett.user, gett.password) 249 | if gett.type then f:type(gett.type) end 250 | f:pasv() 251 | f:receive(gett) 252 | f:quit() 253 | return f:close() 254 | end 255 | 256 | local function sget(u) 257 | local gett = parse(u) 258 | local t = {} 259 | gett.sink = ltn12.sink.table(t) 260 | tget(gett) 261 | return table.concat(t) 262 | end 263 | 264 | command = socket.protect(function(cmdt) 265 | cmdt = override(cmdt) 266 | socket.try(cmdt.host, "missing hostname") 267 | socket.try(cmdt.command, "missing command") 268 | local f = open(cmdt.host, cmdt.port, cmdt.create) 269 | f:greet() 270 | f:login(cmdt.user, cmdt.password) 271 | f.try(f.tp:command(cmdt.command, cmdt.argument)) 272 | if cmdt.check then f.try(f.tp:check(cmdt.check)) end 273 | f:quit() 274 | return f:close() 275 | end) 276 | 277 | get = socket.protect(function(gett) 278 | if base.type(gett) == "string" then return sget(gett) 279 | else return tget(gett) end 280 | end) 281 | 282 | -------------------------------------------------------------------------------- /addons/libs/socket/headers.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Canonic header field capitalization 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id$ 6 | ----------------------------------------------------------------------------- 7 | module("socket.headers") 8 | 9 | canonic = { 10 | ["accept"] = "Accept", 11 | ["accept-charset"] = "Accept-Charset", 12 | ["accept-encoding"] = "Accept-Encoding", 13 | ["accept-language"] = "Accept-Language", 14 | ["accept-ranges"] = "Accept-Ranges", 15 | ["action"] = "Action", 16 | ["alternate-recipient"] = "Alternate-Recipient", 17 | ["age"] = "Age", 18 | ["allow"] = "Allow", 19 | ["arrival-date"] = "Arrival-Date", 20 | ["authorization"] = "Authorization", 21 | ["bcc"] = "Bcc", 22 | ["cache-control"] = "Cache-Control", 23 | ["cc"] = "Cc", 24 | ["comments"] = "Comments", 25 | ["connection"] = "Connection", 26 | ["content-description"] = "Content-Description", 27 | ["content-disposition"] = "Content-Disposition", 28 | ["content-encoding"] = "Content-Encoding", 29 | ["content-id"] = "Content-ID", 30 | ["content-language"] = "Content-Language", 31 | ["content-length"] = "Content-Length", 32 | ["content-location"] = "Content-Location", 33 | ["content-md5"] = "Content-MD5", 34 | ["content-range"] = "Content-Range", 35 | ["content-transfer-encoding"] = "Content-Transfer-Encoding", 36 | ["content-type"] = "Content-Type", 37 | ["date"] = "Date", 38 | ["diagnostic-code"] = "Diagnostic-Code", 39 | ["dsn-gateway"] = "DSN-Gateway", 40 | ["etag"] = "ETag", 41 | ["expect"] = "Expect", 42 | ["expires"] = "Expires", 43 | ["final-log-id"] = "Final-Log-ID", 44 | ["final-recipient"] = "Final-Recipient", 45 | ["from"] = "From", 46 | ["host"] = "Host", 47 | ["if-match"] = "If-Match", 48 | ["if-modified-since"] = "If-Modified-Since", 49 | ["if-none-match"] = "If-None-Match", 50 | ["if-range"] = "If-Range", 51 | ["if-unmodified-since"] = "If-Unmodified-Since", 52 | ["in-reply-to"] = "In-Reply-To", 53 | ["keywords"] = "Keywords", 54 | ["last-attempt-date"] = "Last-Attempt-Date", 55 | ["last-modified"] = "Last-Modified", 56 | ["location"] = "Location", 57 | ["max-forwards"] = "Max-Forwards", 58 | ["message-id"] = "Message-ID", 59 | ["mime-version"] = "MIME-Version", 60 | ["original-envelope-id"] = "Original-Envelope-ID", 61 | ["original-recipient"] = "Original-Recipient", 62 | ["pragma"] = "Pragma", 63 | ["proxy-authenticate"] = "Proxy-Authenticate", 64 | ["proxy-authorization"] = "Proxy-Authorization", 65 | ["range"] = "Range", 66 | ["received"] = "Received", 67 | ["received-from-mta"] = "Received-From-MTA", 68 | ["references"] = "References", 69 | ["referer"] = "Referer", 70 | ["remote-mta"] = "Remote-MTA", 71 | ["reply-to"] = "Reply-To", 72 | ["reporting-mta"] = "Reporting-MTA", 73 | ["resent-bcc"] = "Resent-Bcc", 74 | ["resent-cc"] = "Resent-Cc", 75 | ["resent-date"] = "Resent-Date", 76 | ["resent-from"] = "Resent-From", 77 | ["resent-message-id"] = "Resent-Message-ID", 78 | ["resent-reply-to"] = "Resent-Reply-To", 79 | ["resent-sender"] = "Resent-Sender", 80 | ["resent-to"] = "Resent-To", 81 | ["retry-after"] = "Retry-After", 82 | ["return-path"] = "Return-Path", 83 | ["sender"] = "Sender", 84 | ["server"] = "Server", 85 | ["smtp-remote-recipient"] = "SMTP-Remote-Recipient", 86 | ["status"] = "Status", 87 | ["subject"] = "Subject", 88 | ["te"] = "TE", 89 | ["to"] = "To", 90 | ["trailer"] = "Trailer", 91 | ["transfer-encoding"] = "Transfer-Encoding", 92 | ["upgrade"] = "Upgrade", 93 | ["user-agent"] = "User-Agent", 94 | ["vary"] = "Vary", 95 | ["via"] = "Via", 96 | ["warning"] = "Warning", 97 | ["will-retry-until"] = "Will-Retry-Until", 98 | ["www-authenticate"] = "WWW-Authenticate", 99 | ["x-mailer"] = "X-Mailer", 100 | } 101 | -------------------------------------------------------------------------------- /addons/libs/socket/http.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- HTTP/1.1 client support for the Lua language. 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: http.lua,v 1.72 2009/05/27 09:31:35 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | 8 | ----------------------------------------------------------------------------- 9 | -- Declare module and import dependencies 10 | ------------------------------------------------------------------------------- 11 | local socket = require("socket") 12 | local url = require("socket.url") 13 | local ltn12 = require("ltn12") 14 | local mime = require("mime") 15 | local string = require("string") 16 | local headers = require("socket.headers") 17 | local base = _G 18 | local table = require("table") 19 | module("socket.http") 20 | 21 | ----------------------------------------------------------------------------- 22 | -- Program constants 23 | ----------------------------------------------------------------------------- 24 | -- connection timeout in seconds 25 | TIMEOUT = 60 26 | -- default port for document retrieval 27 | PORT = 80 28 | -- user agent field sent in request 29 | USERAGENT = socket._VERSION 30 | 31 | ----------------------------------------------------------------------------- 32 | -- Reads MIME headers from a connection, unfolding where needed 33 | ----------------------------------------------------------------------------- 34 | local function receiveheaders(sock, headers) 35 | local line, name, value, err 36 | headers = headers or {} 37 | -- get first line 38 | line, err = sock:receive() 39 | if err then return nil, err end 40 | -- headers go until a blank line is found 41 | while line ~= "" do 42 | -- get field-name and value 43 | name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)")) 44 | if not (name and value) then return nil, "malformed reponse headers" end 45 | name = string.lower(name) 46 | -- get next line (value might be folded) 47 | line, err = sock:receive() 48 | if err then return nil, err end 49 | -- unfold any folded values 50 | while string.find(line, "^%s") do 51 | value = value .. line 52 | line = sock:receive() 53 | if err then return nil, err end 54 | end 55 | -- save pair in table 56 | if headers[name] then headers[name] = headers[name] .. ", " .. value 57 | else headers[name] = value end 58 | end 59 | return headers 60 | end 61 | 62 | ----------------------------------------------------------------------------- 63 | -- Extra sources and sinks 64 | ----------------------------------------------------------------------------- 65 | socket.sourcet["http-chunked"] = function(sock, headers) 66 | return base.setmetatable({ 67 | getfd = function() return sock:getfd() end, 68 | dirty = function() return sock:dirty() end 69 | }, { 70 | __call = function() 71 | -- get chunk size, skip extention 72 | local line, err = sock:receive() 73 | if err then return nil, err end 74 | local size = base.tonumber(string.gsub(line, ";.*", ""), 16) 75 | if not size then return nil, "invalid chunk size" end 76 | -- was it the last chunk? 77 | if size > 0 then 78 | -- if not, get chunk and skip terminating CRLF 79 | local chunk, err, part = sock:receive(size) 80 | if chunk then sock:receive() end 81 | return chunk, err 82 | else 83 | -- if it was, read trailers into headers table 84 | headers, err = receiveheaders(sock, headers) 85 | if not headers then return nil, err end 86 | end 87 | end 88 | }) 89 | end 90 | 91 | socket.sinkt["http-chunked"] = function(sock) 92 | return base.setmetatable({ 93 | getfd = function() return sock:getfd() end, 94 | dirty = function() return sock:dirty() end 95 | }, { 96 | __call = function(self, chunk, err) 97 | if not chunk then return sock:send("0\r\n\r\n") end 98 | local size = string.format("%X\r\n", string.len(chunk)) 99 | return sock:send(size .. chunk .. "\r\n") 100 | end 101 | }) 102 | end 103 | 104 | ----------------------------------------------------------------------------- 105 | -- Low level HTTP API 106 | ----------------------------------------------------------------------------- 107 | local metat = { __index = {} } 108 | 109 | function open(host, port, create) 110 | -- create socket with user connect function, or with default 111 | local c = socket.try((create or socket.tcp)()) 112 | local h = base.setmetatable({ c = c }, metat) 113 | -- create finalized try 114 | h.try = socket.newtry(function() h:close() end) 115 | -- set timeout before connecting 116 | h.try(c:settimeout(TIMEOUT)) 117 | h.try(c:connect(host, port or PORT)) 118 | -- here everything worked 119 | return h 120 | end 121 | 122 | function metat.__index:sendrequestline(method, uri) 123 | local reqline = string.format("%s %s HTTP/1.1\r\n", method or "GET", uri) 124 | return self.try(self.c:send(reqline)) 125 | end 126 | 127 | function metat.__index:sendheaders(tosend) 128 | local canonic = headers.canonic 129 | local h = "\r\n" 130 | for f, v in base.pairs(tosend) do 131 | h = (canonic[f] or f) .. ": " .. v .. "\r\n" .. h 132 | end 133 | self.try(self.c:send(h)) 134 | return 1 135 | end 136 | 137 | function metat.__index:sendbody(headers, source, step) 138 | source = source or ltn12.source.empty() 139 | step = step or ltn12.pump.step 140 | -- if we don't know the size in advance, send chunked and hope for the best 141 | local mode = "http-chunked" 142 | if headers["content-length"] then mode = "keep-open" end 143 | return self.try(ltn12.pump.all(source, socket.sink(mode, self.c), step)) 144 | end 145 | 146 | function metat.__index:receivestatusline() 147 | local status = self.try(self.c:receive(5)) 148 | -- identify HTTP/0.9 responses, which do not contain a status line 149 | -- this is just a heuristic, but is what the RFC recommends 150 | if status ~= "HTTP/" then return nil, status end 151 | -- otherwise proceed reading a status line 152 | status = self.try(self.c:receive("*l", status)) 153 | local code = socket.skip(2, string.find(status, "HTTP/%d*%.%d* (%d%d%d)")) 154 | return self.try(base.tonumber(code), status) 155 | end 156 | 157 | function metat.__index:receiveheaders() 158 | return self.try(receiveheaders(self.c)) 159 | end 160 | 161 | function metat.__index:receivebody(headers, sink, step) 162 | sink = sink or ltn12.sink.null() 163 | step = step or ltn12.pump.step 164 | local length = base.tonumber(headers["content-length"]) 165 | local t = headers["transfer-encoding"] -- shortcut 166 | local mode = "default" -- connection close 167 | if t and t ~= "identity" then mode = "http-chunked" 168 | elseif base.tonumber(headers["content-length"]) then mode = "by-length" end 169 | return self.try(ltn12.pump.all(socket.source(mode, self.c, length), 170 | sink, step)) 171 | end 172 | 173 | function metat.__index:receive09body(status, sink, step) 174 | local source = ltn12.source.rewind(socket.source("until-closed", self.c)) 175 | source(status) 176 | return self.try(ltn12.pump.all(source, sink, step)) 177 | end 178 | 179 | function metat.__index:close() 180 | return self.c:close() 181 | end 182 | 183 | ----------------------------------------------------------------------------- 184 | -- High level HTTP API 185 | ----------------------------------------------------------------------------- 186 | local function adjusturi(reqt) 187 | local u = reqt 188 | -- if there is a proxy, we need the full url. otherwise, just a part. 189 | if not reqt.proxy and not PROXY then 190 | u = { 191 | path = socket.try(reqt.path, "invalid path 'nil'"), 192 | params = reqt.params, 193 | query = reqt.query, 194 | fragment = reqt.fragment 195 | } 196 | end 197 | return url.build(u) 198 | end 199 | 200 | local function adjustproxy(reqt) 201 | local proxy = reqt.proxy or PROXY 202 | if proxy then 203 | proxy = url.parse(proxy) 204 | return proxy.host, proxy.port or 3128 205 | else 206 | return reqt.host, reqt.port 207 | end 208 | end 209 | 210 | local function adjustheaders(reqt) 211 | -- default headers 212 | local lower = { 213 | ["user-agent"] = USERAGENT, 214 | ["host"] = reqt.host, 215 | ["connection"] = "close, TE", 216 | ["te"] = "trailers" 217 | } 218 | -- if we have authentication information, pass it along 219 | if reqt.user and reqt.password then 220 | lower["authorization"] = 221 | "Basic " .. (mime.b64(reqt.user .. ":" .. reqt.password)) 222 | end 223 | -- override with user headers 224 | for i,v in base.pairs(reqt.headers or lower) do 225 | lower[string.lower(i)] = v 226 | end 227 | return lower 228 | end 229 | 230 | -- default url parts 231 | local default = { 232 | host = "", 233 | port = PORT, 234 | path ="/", 235 | scheme = "http" 236 | } 237 | 238 | local function adjustrequest(reqt) 239 | -- parse url if provided 240 | local nreqt = reqt.url and url.parse(reqt.url, default) or {} 241 | -- explicit components override url 242 | for i,v in base.pairs(reqt) do nreqt[i] = v end 243 | if nreqt.port == "" then nreqt.port = 80 end 244 | socket.try(nreqt.host and nreqt.host ~= "", 245 | "invalid host '" .. base.tostring(nreqt.host) .. "'") 246 | -- compute uri if user hasn't overriden 247 | nreqt.uri = reqt.uri or adjusturi(nreqt) 248 | -- ajust host and port if there is a proxy 249 | nreqt.host, nreqt.port = adjustproxy(nreqt) 250 | -- adjust headers in request 251 | nreqt.headers = adjustheaders(nreqt) 252 | return nreqt 253 | end 254 | 255 | local function shouldredirect(reqt, code, headers) 256 | return headers.location and 257 | string.gsub(headers.location, "%s", "") ~= "" and 258 | (reqt.redirect ~= false) and 259 | (code == 301 or code == 302 or code == 303 or code == 307) and 260 | (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") 261 | and (not reqt.nredirects or reqt.nredirects < 5) 262 | end 263 | 264 | local function shouldreceivebody(reqt, code) 265 | if reqt.method == "HEAD" then return nil end 266 | if code == 204 or code == 304 then return nil end 267 | if code >= 100 and code < 200 then return nil end 268 | return 1 269 | end 270 | 271 | -- forward declarations 272 | local trequest, tredirect 273 | 274 | function tredirect(reqt, location) 275 | local result, code, headers, status = trequest { 276 | -- the RFC says the redirect URL has to be absolute, but some 277 | -- servers do not respect that 278 | url = url.absolute(reqt.url, location), 279 | source = reqt.source, 280 | sink = reqt.sink, 281 | headers = reqt.headers, 282 | proxy = reqt.proxy, 283 | nredirects = (reqt.nredirects or 0) + 1, 284 | create = reqt.create 285 | } 286 | -- pass location header back as a hint we redirected 287 | headers = headers or {} 288 | headers.location = headers.location or location 289 | return result, code, headers, status 290 | end 291 | 292 | function trequest(reqt) 293 | -- we loop until we get what we want, or 294 | -- until we are sure there is no way to get it 295 | local nreqt = adjustrequest(reqt) 296 | local h = open(nreqt.host, nreqt.port, nreqt.create) 297 | -- send request line and headers 298 | h:sendrequestline(nreqt.method, nreqt.uri) 299 | h:sendheaders(nreqt.headers) 300 | -- if there is a body, send it 301 | if nreqt.source then 302 | h:sendbody(nreqt.headers, nreqt.source, nreqt.step) 303 | end 304 | local code, status = h:receivestatusline() 305 | -- if it is an HTTP/0.9 server, simply get the body and we are done 306 | if not code then 307 | h:receive09body(status, nreqt.sink, nreqt.step) 308 | return 1, 200 309 | end 310 | local headers 311 | -- ignore any 100-continue messages 312 | while code == 100 do 313 | headers = h:receiveheaders() 314 | code, status = h:receivestatusline() 315 | end 316 | headers = h:receiveheaders() 317 | -- at this point we should have a honest reply from the server 318 | -- we can't redirect if we already used the source, so we report the error 319 | if shouldredirect(nreqt, code, headers) and not nreqt.source then 320 | h:close() 321 | return tredirect(reqt, headers.location) 322 | end 323 | -- here we are finally done 324 | if shouldreceivebody(nreqt, code) then 325 | h:receivebody(headers, nreqt.sink, nreqt.step) 326 | end 327 | h:close() 328 | return 1, code, headers, status 329 | end 330 | 331 | local function srequest(u, b) 332 | local t = {} 333 | local reqt = { 334 | url = u, 335 | sink = ltn12.sink.table(t) 336 | } 337 | if b then 338 | reqt.source = ltn12.source.string(b) 339 | reqt.headers = { 340 | ["content-length"] = string.len(b), 341 | ["content-type"] = "application/x-www-form-urlencoded" 342 | } 343 | reqt.method = "POST" 344 | end 345 | local code, headers, status = socket.skip(1, trequest(reqt)) 346 | return table.concat(t), code, headers, status 347 | end 348 | 349 | request = socket.protect(function(reqt, body) 350 | if base.type(reqt) == "string" then return srequest(reqt, body) 351 | else return trequest(reqt) end 352 | end) 353 | -------------------------------------------------------------------------------- /addons/libs/socket/smtp.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- SMTP client support for the Lua language. 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: smtp.lua,v 1.47 2009/05/27 09:31:35 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | 8 | ----------------------------------------------------------------------------- 9 | -- Declare module and import dependencies 10 | ----------------------------------------------------------------------------- 11 | local base = _G 12 | local coroutine = require("coroutine") 13 | local string = require("string") 14 | local math = require("math") 15 | local os = require("os") 16 | local socket = require("socket") 17 | local tp = require("socket.tp") 18 | local ltn12 = require("ltn12") 19 | local headers = require("socket.headers") 20 | local mime = require("mime") 21 | module("socket.smtp") 22 | 23 | ----------------------------------------------------------------------------- 24 | -- Program constants 25 | ----------------------------------------------------------------------------- 26 | -- timeout for connection 27 | TIMEOUT = 60 28 | -- default server used to send e-mails 29 | SERVER = "localhost" 30 | -- default port 31 | PORT = 25 32 | -- domain used in HELO command and default sendmail 33 | -- If we are under a CGI, try to get from environment 34 | DOMAIN = os.getenv("SERVER_NAME") or "localhost" 35 | -- default time zone (means we don't know) 36 | ZONE = "-0000" 37 | 38 | --------------------------------------------------------------------------- 39 | -- Low level SMTP API 40 | ----------------------------------------------------------------------------- 41 | local metat = { __index = {} } 42 | 43 | function metat.__index:greet(domain) 44 | self.try(self.tp:check("2..")) 45 | self.try(self.tp:command("EHLO", domain or DOMAIN)) 46 | return socket.skip(1, self.try(self.tp:check("2.."))) 47 | end 48 | 49 | function metat.__index:mail(from) 50 | self.try(self.tp:command("MAIL", "FROM:" .. from)) 51 | return self.try(self.tp:check("2..")) 52 | end 53 | 54 | function metat.__index:rcpt(to) 55 | self.try(self.tp:command("RCPT", "TO:" .. to)) 56 | return self.try(self.tp:check("2..")) 57 | end 58 | 59 | function metat.__index:data(src, step) 60 | self.try(self.tp:command("DATA")) 61 | self.try(self.tp:check("3..")) 62 | self.try(self.tp:source(src, step)) 63 | self.try(self.tp:send("\r\n.\r\n")) 64 | return self.try(self.tp:check("2..")) 65 | end 66 | 67 | function metat.__index:quit() 68 | self.try(self.tp:command("QUIT")) 69 | return self.try(self.tp:check("2..")) 70 | end 71 | 72 | function metat.__index:close() 73 | return self.tp:close() 74 | end 75 | 76 | function metat.__index:login(user, password) 77 | self.try(self.tp:command("AUTH", "LOGIN")) 78 | self.try(self.tp:check("3..")) 79 | self.try(self.tp:command(mime.b64(user))) 80 | self.try(self.tp:check("3..")) 81 | self.try(self.tp:command(mime.b64(password))) 82 | return self.try(self.tp:check("2..")) 83 | end 84 | 85 | function metat.__index:plain(user, password) 86 | local auth = "PLAIN " .. mime.b64("\0" .. user .. "\0" .. password) 87 | self.try(self.tp:command("AUTH", auth)) 88 | return self.try(self.tp:check("2..")) 89 | end 90 | 91 | function metat.__index:auth(user, password, ext) 92 | if not user or not password then return 1 end 93 | if string.find(ext, "AUTH[^\n]+LOGIN") then 94 | return self:login(user, password) 95 | elseif string.find(ext, "AUTH[^\n]+PLAIN") then 96 | return self:plain(user, password) 97 | else 98 | self.try(nil, "authentication not supported") 99 | end 100 | end 101 | 102 | -- send message or throw an exception 103 | function metat.__index:send(mailt) 104 | self:mail(mailt.from) 105 | if base.type(mailt.rcpt) == "table" then 106 | for i,v in base.ipairs(mailt.rcpt) do 107 | self:rcpt(v) 108 | end 109 | else 110 | self:rcpt(mailt.rcpt) 111 | end 112 | self:data(ltn12.source.chain(mailt.source, mime.stuff()), mailt.step) 113 | end 114 | 115 | function open(server, port, create) 116 | local tp = socket.try(tp.connect(server or SERVER, port or PORT, 117 | TIMEOUT, create)) 118 | local s = base.setmetatable({tp = tp}, metat) 119 | -- make sure tp is closed if we get an exception 120 | s.try = socket.newtry(function() 121 | s:close() 122 | end) 123 | return s 124 | end 125 | 126 | -- convert headers to lowercase 127 | local function lower_headers(headers) 128 | local lower = {} 129 | for i,v in base.pairs(headers or lower) do 130 | lower[string.lower(i)] = v 131 | end 132 | return lower 133 | end 134 | 135 | --------------------------------------------------------------------------- 136 | -- Multipart message source 137 | ----------------------------------------------------------------------------- 138 | -- returns a hopefully unique mime boundary 139 | local seqno = 0 140 | local function newboundary() 141 | seqno = seqno + 1 142 | return string.format('%s%05d==%05u', os.date('%d%m%Y%H%M%S'), 143 | math.random(0, 99999), seqno) 144 | end 145 | 146 | -- send_message forward declaration 147 | local send_message 148 | 149 | -- yield the headers all at once, it's faster 150 | local function send_headers(tosend) 151 | local canonic = headers.canonic 152 | local h = "\r\n" 153 | for f,v in base.pairs(tosend) do 154 | h = (canonic[f] or f) .. ': ' .. v .. "\r\n" .. h 155 | end 156 | coroutine.yield(h) 157 | end 158 | 159 | -- yield multipart message body from a multipart message table 160 | local function send_multipart(mesgt) 161 | -- make sure we have our boundary and send headers 162 | local bd = newboundary() 163 | local headers = lower_headers(mesgt.headers or {}) 164 | headers['content-type'] = headers['content-type'] or 'multipart/mixed' 165 | headers['content-type'] = headers['content-type'] .. 166 | '; boundary="' .. bd .. '"' 167 | send_headers(headers) 168 | -- send preamble 169 | if mesgt.body.preamble then 170 | coroutine.yield(mesgt.body.preamble) 171 | coroutine.yield("\r\n") 172 | end 173 | -- send each part separated by a boundary 174 | for i, m in base.ipairs(mesgt.body) do 175 | coroutine.yield("\r\n--" .. bd .. "\r\n") 176 | send_message(m) 177 | end 178 | -- send last boundary 179 | coroutine.yield("\r\n--" .. bd .. "--\r\n\r\n") 180 | -- send epilogue 181 | if mesgt.body.epilogue then 182 | coroutine.yield(mesgt.body.epilogue) 183 | coroutine.yield("\r\n") 184 | end 185 | end 186 | 187 | -- yield message body from a source 188 | local function send_source(mesgt) 189 | -- make sure we have a content-type 190 | local headers = lower_headers(mesgt.headers or {}) 191 | headers['content-type'] = headers['content-type'] or 192 | 'text/plain; charset="iso-8859-1"' 193 | send_headers(headers) 194 | -- send body from source 195 | while true do 196 | local chunk, err = mesgt.body() 197 | if err then coroutine.yield(nil, err) 198 | elseif chunk then coroutine.yield(chunk) 199 | else break end 200 | end 201 | end 202 | 203 | -- yield message body from a string 204 | local function send_string(mesgt) 205 | -- make sure we have a content-type 206 | local headers = lower_headers(mesgt.headers or {}) 207 | headers['content-type'] = headers['content-type'] or 208 | 'text/plain; charset="iso-8859-1"' 209 | send_headers(headers) 210 | -- send body from string 211 | coroutine.yield(mesgt.body) 212 | end 213 | 214 | -- message source 215 | function send_message(mesgt) 216 | if base.type(mesgt.body) == "table" then send_multipart(mesgt) 217 | elseif base.type(mesgt.body) == "function" then send_source(mesgt) 218 | else send_string(mesgt) end 219 | end 220 | 221 | -- set defaul headers 222 | local function adjust_headers(mesgt) 223 | local lower = lower_headers(mesgt.headers) 224 | lower["date"] = lower["date"] or 225 | os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE) 226 | lower["x-mailer"] = lower["x-mailer"] or socket._VERSION 227 | -- this can't be overriden 228 | lower["mime-version"] = "1.0" 229 | return lower 230 | end 231 | 232 | function message(mesgt) 233 | mesgt.headers = adjust_headers(mesgt) 234 | -- create and return message source 235 | local co = coroutine.create(function() send_message(mesgt) end) 236 | return function() 237 | local ret, a, b = coroutine.resume(co) 238 | if ret then return a, b 239 | else return nil, a end 240 | end 241 | end 242 | 243 | --------------------------------------------------------------------------- 244 | -- High level SMTP API 245 | ----------------------------------------------------------------------------- 246 | send = socket.protect(function(mailt) 247 | local s = open(mailt.server, mailt.port, mailt.create) 248 | local ext = s:greet(mailt.domain) 249 | s:auth(mailt.user, mailt.password, ext) 250 | s:send(mailt) 251 | s:quit() 252 | return s:close() 253 | end) 254 | -------------------------------------------------------------------------------- /addons/libs/socket/tp.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Unified SMTP/FTP subsystem 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: tp.lua,v 1.23 2009/05/27 09:31:35 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | 8 | ----------------------------------------------------------------------------- 9 | -- Declare module and import dependencies 10 | ----------------------------------------------------------------------------- 11 | local base = _G 12 | local string = require("string") 13 | local socket = require("socket") 14 | local ltn12 = require("ltn12") 15 | module("socket.tp") 16 | 17 | ----------------------------------------------------------------------------- 18 | -- Program constants 19 | ----------------------------------------------------------------------------- 20 | TIMEOUT = 60 21 | 22 | ----------------------------------------------------------------------------- 23 | -- Implementation 24 | ----------------------------------------------------------------------------- 25 | -- gets server reply (works for SMTP and FTP) 26 | local function get_reply(c) 27 | local code, current, sep 28 | local line, err = c:receive() 29 | local reply = line 30 | if err then return nil, err end 31 | code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)")) 32 | if not code then return nil, "invalid server reply" end 33 | if sep == "-" then -- reply is multiline 34 | repeat 35 | line, err = c:receive() 36 | if err then return nil, err end 37 | current, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)")) 38 | reply = reply .. "\n" .. line 39 | -- reply ends with same code 40 | until code == current and sep == " " 41 | end 42 | return code, reply 43 | end 44 | 45 | -- metatable for sock object 46 | local metat = { __index = {} } 47 | 48 | function metat.__index:check(ok) 49 | local code, reply = get_reply(self.c) 50 | if not code then return nil, reply end 51 | if base.type(ok) ~= "function" then 52 | if base.type(ok) == "table" then 53 | for i, v in base.ipairs(ok) do 54 | if string.find(code, v) then 55 | return base.tonumber(code), reply 56 | end 57 | end 58 | return nil, reply 59 | else 60 | if string.find(code, ok) then return base.tonumber(code), reply 61 | else return nil, reply end 62 | end 63 | else return ok(base.tonumber(code), reply) end 64 | end 65 | 66 | function metat.__index:command(cmd, arg) 67 | cmd = string.upper(cmd) 68 | if arg then 69 | return self.c:send(cmd .. " " .. arg.. "\r\n") 70 | else 71 | return self.c:send(cmd .. "\r\n") 72 | end 73 | end 74 | 75 | function metat.__index:sink(snk, pat) 76 | local chunk, err = c:receive(pat) 77 | return snk(chunk, err) 78 | end 79 | 80 | function metat.__index:send(data) 81 | return self.c:send(data) 82 | end 83 | 84 | function metat.__index:receive(pat) 85 | return self.c:receive(pat) 86 | end 87 | 88 | function metat.__index:getfd() 89 | return self.c:getfd() 90 | end 91 | 92 | function metat.__index:dirty() 93 | return self.c:dirty() 94 | end 95 | 96 | function metat.__index:getcontrol() 97 | return self.c 98 | end 99 | 100 | function metat.__index:source(source, step) 101 | local sink = socket.sink("keep-open", self.c) 102 | local ret, err = ltn12.pump.all(source, sink, step or ltn12.pump.step) 103 | return ret, err 104 | end 105 | 106 | -- closes the underlying c 107 | function metat.__index:close() 108 | self.c:close() 109 | return 1 110 | end 111 | 112 | -- connect with server and return c object 113 | function connect(host, port, timeout, create) 114 | local c, e = (create or socket.tcp)() 115 | if not c then return nil, e end 116 | c:settimeout(timeout or TIMEOUT) 117 | local r, e = c:connect(host, port) 118 | if not r then 119 | c:close() 120 | return nil, e 121 | end 122 | return base.setmetatable({c = c}, metat) 123 | end 124 | 125 | -------------------------------------------------------------------------------- /addons/libs/socket/url.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- URI parsing, composition and relative URL resolution 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: url.lua,v 1.38 2006/04/03 04:45:42 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | 8 | ----------------------------------------------------------------------------- 9 | -- Declare module 10 | ----------------------------------------------------------------------------- 11 | local string = require("string") 12 | local base = _G 13 | local table = require("table") 14 | module("socket.url") 15 | 16 | ----------------------------------------------------------------------------- 17 | -- Module version 18 | ----------------------------------------------------------------------------- 19 | _VERSION = "URL 1.0.1" 20 | 21 | ----------------------------------------------------------------------------- 22 | -- Encodes a string into its escaped hexadecimal representation 23 | -- Input 24 | -- s: binary string to be encoded 25 | -- Returns 26 | -- escaped representation of string binary 27 | ----------------------------------------------------------------------------- 28 | function escape(s) 29 | return string.gsub(s, "([^A-Za-z0-9_])", function(c) 30 | return string.format("%%%02x", string.byte(c)) 31 | end) 32 | end 33 | 34 | ----------------------------------------------------------------------------- 35 | -- Protects a path segment, to prevent it from interfering with the 36 | -- url parsing. 37 | -- Input 38 | -- s: binary string to be encoded 39 | -- Returns 40 | -- escaped representation of string binary 41 | ----------------------------------------------------------------------------- 42 | local function make_set(t) 43 | local s = {} 44 | for i,v in base.ipairs(t) do 45 | s[t[i]] = 1 46 | end 47 | return s 48 | end 49 | 50 | -- these are allowed withing a path segment, along with alphanum 51 | -- other characters must be escaped 52 | local segment_set = make_set { 53 | "-", "_", ".", "!", "~", "*", "'", "(", 54 | ")", ":", "@", "&", "=", "+", "$", ",", 55 | } 56 | 57 | local function protect_segment(s) 58 | return string.gsub(s, "([^A-Za-z0-9_])", function (c) 59 | if segment_set[c] then return c 60 | else return string.format("%%%02x", string.byte(c)) end 61 | end) 62 | end 63 | 64 | ----------------------------------------------------------------------------- 65 | -- Encodes a string into its escaped hexadecimal representation 66 | -- Input 67 | -- s: binary string to be encoded 68 | -- Returns 69 | -- escaped representation of string binary 70 | ----------------------------------------------------------------------------- 71 | function unescape(s) 72 | return string.gsub(s, "%%(%x%x)", function(hex) 73 | return string.char(base.tonumber(hex, 16)) 74 | end) 75 | end 76 | 77 | ----------------------------------------------------------------------------- 78 | -- Builds a path from a base path and a relative path 79 | -- Input 80 | -- base_path 81 | -- relative_path 82 | -- Returns 83 | -- corresponding absolute path 84 | ----------------------------------------------------------------------------- 85 | local function absolute_path(base_path, relative_path) 86 | if string.sub(relative_path, 1, 1) == "/" then return relative_path end 87 | local path = string.gsub(base_path, "[^/]*$", "") 88 | path = path .. relative_path 89 | path = string.gsub(path, "([^/]*%./)", function (s) 90 | if s ~= "./" then return s else return "" end 91 | end) 92 | path = string.gsub(path, "/%.$", "/") 93 | local reduced 94 | while reduced ~= path do 95 | reduced = path 96 | path = string.gsub(reduced, "([^/]*/%.%./)", function (s) 97 | if s ~= "../../" then return "" else return s end 98 | end) 99 | end 100 | path = string.gsub(reduced, "([^/]*/%.%.)$", function (s) 101 | if s ~= "../.." then return "" else return s end 102 | end) 103 | return path 104 | end 105 | 106 | ----------------------------------------------------------------------------- 107 | -- Parses a url and returns a table with all its parts according to RFC 2396 108 | -- The following grammar describes the names given to the URL parts 109 | -- ::= :///;?# 110 | -- ::= @: 111 | -- ::= [:] 112 | -- :: = {/} 113 | -- Input 114 | -- url: uniform resource locator of request 115 | -- default: table with default values for each field 116 | -- Returns 117 | -- table with the following fields, where RFC naming conventions have 118 | -- been preserved: 119 | -- scheme, authority, userinfo, user, password, host, port, 120 | -- path, params, query, fragment 121 | -- Obs: 122 | -- the leading '/' in {/} is considered part of 123 | ----------------------------------------------------------------------------- 124 | function parse(url, default) 125 | -- initialize default parameters 126 | local parsed = {} 127 | for i,v in base.pairs(default or parsed) do parsed[i] = v end 128 | -- empty url is parsed to nil 129 | if not url or url == "" then return nil, "invalid url" end 130 | -- remove whitespace 131 | -- url = string.gsub(url, "%s", "") 132 | -- get fragment 133 | url = string.gsub(url, "#(.*)$", function(f) 134 | parsed.fragment = f 135 | return "" 136 | end) 137 | -- get scheme 138 | url = string.gsub(url, "^([%w][%w%+%-%.]*)%:", 139 | function(s) parsed.scheme = s; return "" end) 140 | -- get authority 141 | url = string.gsub(url, "^//([^/]*)", function(n) 142 | parsed.authority = n 143 | return "" 144 | end) 145 | -- get query stringing 146 | url = string.gsub(url, "%?(.*)", function(q) 147 | parsed.query = q 148 | return "" 149 | end) 150 | -- get params 151 | url = string.gsub(url, "%;(.*)", function(p) 152 | parsed.params = p 153 | return "" 154 | end) 155 | -- path is whatever was left 156 | if url ~= "" then parsed.path = url end 157 | local authority = parsed.authority 158 | if not authority then return parsed end 159 | authority = string.gsub(authority,"^([^@]*)@", 160 | function(u) parsed.userinfo = u; return "" end) 161 | authority = string.gsub(authority, ":([^:]*)$", 162 | function(p) parsed.port = p; return "" end) 163 | if authority ~= "" then parsed.host = authority end 164 | local userinfo = parsed.userinfo 165 | if not userinfo then return parsed end 166 | userinfo = string.gsub(userinfo, ":([^:]*)$", 167 | function(p) parsed.password = p; return "" end) 168 | parsed.user = userinfo 169 | return parsed 170 | end 171 | 172 | ----------------------------------------------------------------------------- 173 | -- Rebuilds a parsed URL from its components. 174 | -- Components are protected if any reserved or unallowed characters are found 175 | -- Input 176 | -- parsed: parsed URL, as returned by parse 177 | -- Returns 178 | -- a stringing with the corresponding URL 179 | ----------------------------------------------------------------------------- 180 | function build(parsed) 181 | local ppath = parse_path(parsed.path or "") 182 | local url = build_path(ppath) 183 | if parsed.params then url = url .. ";" .. parsed.params end 184 | if parsed.query then url = url .. "?" .. parsed.query end 185 | local authority = parsed.authority 186 | if parsed.host then 187 | authority = parsed.host 188 | if parsed.port then authority = authority .. ":" .. parsed.port end 189 | local userinfo = parsed.userinfo 190 | if parsed.user then 191 | userinfo = parsed.user 192 | if parsed.password then 193 | userinfo = userinfo .. ":" .. parsed.password 194 | end 195 | end 196 | if userinfo then authority = userinfo .. "@" .. authority end 197 | end 198 | if authority then url = "//" .. authority .. url end 199 | if parsed.scheme then url = parsed.scheme .. ":" .. url end 200 | if parsed.fragment then url = url .. "#" .. parsed.fragment end 201 | -- url = string.gsub(url, "%s", "") 202 | return url 203 | end 204 | 205 | ----------------------------------------------------------------------------- 206 | -- Builds a absolute URL from a base and a relative URL according to RFC 2396 207 | -- Input 208 | -- base_url 209 | -- relative_url 210 | -- Returns 211 | -- corresponding absolute url 212 | ----------------------------------------------------------------------------- 213 | function absolute(base_url, relative_url) 214 | if base.type(base_url) == "table" then 215 | base_parsed = base_url 216 | base_url = build(base_parsed) 217 | else 218 | base_parsed = parse(base_url) 219 | end 220 | local relative_parsed = parse(relative_url) 221 | if not base_parsed then return relative_url 222 | elseif not relative_parsed then return base_url 223 | elseif relative_parsed.scheme then return relative_url 224 | else 225 | relative_parsed.scheme = base_parsed.scheme 226 | if not relative_parsed.authority then 227 | relative_parsed.authority = base_parsed.authority 228 | if not relative_parsed.path then 229 | relative_parsed.path = base_parsed.path 230 | if not relative_parsed.params then 231 | relative_parsed.params = base_parsed.params 232 | if not relative_parsed.query then 233 | relative_parsed.query = base_parsed.query 234 | end 235 | end 236 | else 237 | relative_parsed.path = absolute_path(base_parsed.path or "", 238 | relative_parsed.path) 239 | end 240 | end 241 | return build(relative_parsed) 242 | end 243 | end 244 | 245 | ----------------------------------------------------------------------------- 246 | -- Breaks a path into its segments, unescaping the segments 247 | -- Input 248 | -- path 249 | -- Returns 250 | -- segment: a table with one entry per segment 251 | ----------------------------------------------------------------------------- 252 | function parse_path(path) 253 | local parsed = {} 254 | path = path or "" 255 | --path = string.gsub(path, "%s", "") 256 | string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end) 257 | for i = 1, table.getn(parsed) do 258 | parsed[i] = unescape(parsed[i]) 259 | end 260 | if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end 261 | if string.sub(path, -1, -1) == "/" then parsed.is_directory = 1 end 262 | return parsed 263 | end 264 | 265 | ----------------------------------------------------------------------------- 266 | -- Builds a path component from its segments, escaping protected characters. 267 | -- Input 268 | -- parsed: path segments 269 | -- unsafe: if true, segments are not protected before path is built 270 | -- Returns 271 | -- path: corresponding path stringing 272 | ----------------------------------------------------------------------------- 273 | function build_path(parsed, unsafe) 274 | local path = "" 275 | local n = table.getn(parsed) 276 | if unsafe then 277 | for i = 1, n-1 do 278 | path = path .. parsed[i] 279 | path = path .. "/" 280 | end 281 | if n > 0 then 282 | path = path .. parsed[n] 283 | if parsed.is_directory then path = path .. "/" end 284 | end 285 | else 286 | for i = 1, n-1 do 287 | path = path .. protect_segment(parsed[i]) 288 | path = path .. "/" 289 | end 290 | if n > 0 then 291 | path = path .. protect_segment(parsed[n]) 292 | if parsed.is_directory then path = path .. "/" end 293 | end 294 | end 295 | if parsed.is_absolute then path = "/" .. path end 296 | return path 297 | end 298 | -------------------------------------------------------------------------------- /addons/libs/timer.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | * rMod - Copyright (c) 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using rMod, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (rMod) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (rMod), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * rMod project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | ]]-- 25 | 26 | hook = hook or { }; 27 | hook.timer = hook.timer or { }; 28 | 29 | -- Timer Status Definition 30 | local TIMER_PAUSED = 0; 31 | local TIMER_STOPPED = 1; 32 | local TIMER_RUNNING = 2; 33 | 34 | -- Timer Table Definitions 35 | hook.timer.timers = { }; 36 | hook.timer.timersonce = { }; 37 | 38 | ---------------------------------------------------------------------------------------------------- 39 | -- func: create_timer 40 | -- desc: Creates a timer object inside of the timer table. 41 | ---------------------------------------------------------------------------------------------------- 42 | local function create_timer(name) 43 | if (hook.timer.timers[name] == nil) then 44 | hook.timer.timers[name] = { }; 45 | hook.timer.timers[name].Status = TIMER_STOPPED; 46 | return true; 47 | end 48 | return false; 49 | end 50 | hook.timer.create_timer = create_timer; 51 | 52 | ---------------------------------------------------------------------------------------------------- 53 | -- func: remove_timer 54 | -- desc: Removes a timer from the timer table. 55 | ---------------------------------------------------------------------------------------------------- 56 | local function remove_timer(name) 57 | hook.timer.timers[name] = nil; 58 | end 59 | hook.timer.remove_timer = remove_timer; 60 | 61 | ---------------------------------------------------------------------------------------------------- 62 | -- func: is_timer 63 | -- desc: Determines if the given name is a valid timer. 64 | ---------------------------------------------------------------------------------------------------- 65 | local function is_timer(name) 66 | return hook.timer.timers[name] ~= nil; 67 | end 68 | hook.timer.is_timer = is_timer; 69 | 70 | ---------------------------------------------------------------------------------------------------- 71 | -- func: once 72 | -- desc: Creates a one-time timer that fires after the given delay. 73 | ---------------------------------------------------------------------------------------------------- 74 | local function once(delay, func, ...) 75 | local t = { }; 76 | t.Finish = os.time() + delay; 77 | if (func) then 78 | t.Function = func; 79 | end 80 | t.Args = {...}; 81 | 82 | table.insert(hook.timer.timersonce, t); 83 | return true; 84 | end 85 | hook.timer.once = once; 86 | 87 | ---------------------------------------------------------------------------------------------------- 88 | -- func: create 89 | -- desc: Creates a timer. 90 | ---------------------------------------------------------------------------------------------------- 91 | local function create(name, delay, reps, func, ...) 92 | if (hook.timer.is_timer(name)) then 93 | hook.timer.remove_timer(name); 94 | end 95 | 96 | hook.timer.adjust_timer(name, delay, reps, func, unpack({...})); 97 | hook.timer.start_timer(name); 98 | end 99 | hook.timer.create = create; 100 | 101 | ---------------------------------------------------------------------------------------------------- 102 | -- func: start_timer 103 | -- desc: Starts a timer by its name. 104 | ---------------------------------------------------------------------------------------------------- 105 | local function start_timer(name) 106 | if (hook.timer.is_timer(name)) then 107 | hook.timer.timers[name].n = 0; 108 | hook.timer.timers[name].Status = TIMER_RUNNING; 109 | hook.timer.timers[name].Last = os.time(); 110 | return true; 111 | end 112 | return false; 113 | end 114 | hook.timer.start_timer = start_timer; 115 | 116 | ---------------------------------------------------------------------------------------------------- 117 | -- func: adjust_timer 118 | -- desc: Updates a timer objects properties. 119 | ---------------------------------------------------------------------------------------------------- 120 | local function adjust_timer(name, delay, reps, func, ...) 121 | hook.timer.create_timer(name); 122 | 123 | hook.timer.timers[name].Delay = delay; 124 | hook.timer.timers[name].Reps = reps; 125 | hook.timer.timers[name].Args = {...}; 126 | 127 | if (func ~= nil) then 128 | hook.timer.timers[name].Function = func; 129 | end 130 | 131 | return true; 132 | end 133 | hook.timer.adjust_timer = adjust_timer; 134 | 135 | ---------------------------------------------------------------------------------------------------- 136 | -- func: pause 137 | -- desc: Pauses a timer. 138 | ---------------------------------------------------------------------------------------------------- 139 | local function pause(name) 140 | if (hook.timer.is_timer(name)) then 141 | if (hook.timer.timers[name].Status == TIMER_RUNNING) then 142 | hook.timer.timers[name].Diff = os.time() - hook.timer.timers[name].Last; 143 | hook.timer.timers[name].Status = TIMER_PAUSED; 144 | return true; 145 | end 146 | end 147 | return false; 148 | end 149 | hook.timer.pause = pause; 150 | 151 | ---------------------------------------------------------------------------------------------------- 152 | -- func: unpause 153 | -- desc: Unpauses a timer. 154 | ---------------------------------------------------------------------------------------------------- 155 | local function unpause(name) 156 | if (hook.timer.is_timer(name)) then 157 | if (hook.timer.timers[name].Status == TIMER_RUNNING) then 158 | hook.timer.timers[name].Diff = nil; 159 | hook.timer.timers[name].Status = TIMER_RUNNING; 160 | return true; 161 | end 162 | end 163 | return false; 164 | end 165 | hook.timer.unpause = unpause; 166 | 167 | ---------------------------------------------------------------------------------------------------- 168 | -- func: toggle 169 | -- desc: Toggles a timers paused state. 170 | ---------------------------------------------------------------------------------------------------- 171 | local function toggle(name) 172 | if (hook.timer.is_timer(name)) then 173 | if (hook.timer.timers[name].Status == TIMER_PAUSED) then 174 | return hook.timer.unpause(name); 175 | elseif (hook.timer.timers[name].Status == TIMER_RUNNING) then 176 | return hook.timer.pause(name); 177 | end 178 | end 179 | return false; 180 | end 181 | hook.timer.toggle = toggle; 182 | 183 | ---------------------------------------------------------------------------------------------------- 184 | -- func: stop 185 | -- desc: Stops a timer. 186 | ---------------------------------------------------------------------------------------------------- 187 | local function stop(name) 188 | if (hook.timer.is_timer(name)) then 189 | hook.timer.timers[name].Status = TIMER_STOPPED; 190 | return true; 191 | end 192 | return false; 193 | end 194 | hook.timer.stop = stop; 195 | 196 | ---------------------------------------------------------------------------------------------------- 197 | -- func: pulse 198 | -- desc: Pulses the timer tables to allow timers to run. 199 | ---------------------------------------------------------------------------------------------------- 200 | local function pulse(name) 201 | -- Handle the normal timers.. 202 | for k, v in pairs(hook.timer.timers) do 203 | if (v.Status == TIMER_PAUSED) then 204 | v.Last = os.time() - v.Diff; 205 | elseif (v.Status == TIMER_RUNNING and (v.Last + v.Delay) <= os.time()) then 206 | v.Last = os.time(); 207 | v.n = v.n + 1; 208 | 209 | -- Call the timer function.. 210 | local a, b, c, d, e, f = pcall(v.Function, unpack(v.Args)); 211 | if (a == nil or a == false) then 212 | print(_addon.name .. ' - timer.lua pcall error: ' .. tostring(b)); 213 | end 214 | 215 | -- Stop the timer after its reps were met.. 216 | if (v.n >= v.Reps and v.Reps > 0) then 217 | hook.timer.stop(k); 218 | end 219 | end 220 | end 221 | 222 | -- Handle the once timers.. 223 | for k, v in pairs(hook.timer.timersonce) do 224 | if (v.Finish <= os.time()) then 225 | local a, b, c, d, e, f = pcall(v.Function, unpack(v.Args)); 226 | if (a == nil or a == false) then 227 | print(_addon.name .. ' - timer.lua pcall error: ' .. tostring(b)); 228 | end 229 | 230 | -- Remove the timer.. 231 | hook.timer.timersonce[k] = nil; 232 | end 233 | end 234 | end 235 | hook.timer.pulse = pulse; 236 | hook.events.register_event('beginscene', '__timerlib_beginscene', pulse); -------------------------------------------------------------------------------- /config/rmod.ini: -------------------------------------------------------------------------------- 1 | ;--------------------------------------------------------------------------------------------------- 2 | ; .____ ____, .___, 3 | ; .______| \/ | | | 4 | ; | | |_______.____| | 5 | ; | .__| | _ | __ | 6 | ; | | | | |_| | |__| | 7 | ; |___| |___|__|___|_______|________| 8 | ;--------------------------------------------------------------------------------------------------- 9 | ; rMod (c) 2018 atom0s [atom0s@live.com] 10 | ;--------------------------------------------------------------------------------------------------- 11 | 12 | ;--------------------------------------------------------------------------------------------------- 13 | ; DONATIONS 14 | ;--------------------------------------------------------------------------------------------------- 15 | ; 16 | ; Want to say thanks for rMod? You can donate via my Paypal here: 17 | ; https://www.paypal.me/atom0s 18 | ; 19 | ;--------------------------------------------------------------------------------------------------- 20 | ; KoA Modding Community 21 | ;--------------------------------------------------------------------------------------------------- 22 | ; 23 | ; Join the community of other modders here: 24 | ; - Forums: https://koa.atom0s.com/ 25 | ; - Discord: https://discordapp.com/invite/qRg969Q 26 | ; 27 | ;--------------------------------------------------------------------------------------------------- 28 | ; WARNING - PLEASE READ! 29 | ;--------------------------------------------------------------------------------------------------- 30 | ; 31 | ; Before editing this file, please be sure to read the comments thoroughly! 32 | ; Failure to edit this file properly can cause the game to crash which can 33 | ; lead to corrupted saves! I am not responsible for any loss of data! 34 | ; 35 | ;--------------------------------------------------------------------------------------------------- 36 | 37 | ;--------------------------------------------------------------------------------------------------- 38 | ; Section: loader 39 | ;--------------------------------------------------------------------------------------------------- 40 | ; 41 | ; Settings used by the injector/loader. 42 | ; 43 | ; path (string) 44 | ; 45 | ; The full path to your game executable. (Reckoning.exe) 46 | ; You must include the exe file name in the path for this to work properly! 47 | ; 48 | ; steam (boolean) 49 | ; 50 | ; Flag used to determine the game type. If you are using the Steam version of the game, 51 | ; you should set this to 1. Otherwise it should be 0. (Leaving it as 1 without the Steam 52 | ; version of the game wont affect anything, it is safe to leave this as 1.) 53 | ; 54 | ; steamappid (integer) 55 | ; 56 | ; The Steam application id of the game. You shouldn't need to edit this value ever. 57 | ; The application id can be obtained from the games Steam store page url: 58 | ; http://store.steampowered.com/agecheck/app/102500/ 59 | ; 60 | ;--------------------------------------------------------------------------------------------------- 61 | [loader] 62 | path = D:\Games\Steam\SteamApps\common\KOAReckoning\Reckoning.exe 63 | steam = 1 64 | steamappid = 102500 65 | 66 | ;--------------------------------------------------------------------------------------------------- 67 | ; Section: splash 68 | ;--------------------------------------------------------------------------------------------------- 69 | ; 70 | ; Settings used by the hook in relation to the splash screen and start-up of the game. 71 | ; 72 | ; quickload (boolean) 73 | ; 74 | ; Tells rMod to patch out the splash screen and intro load-ups to make loading the game 75 | ; quicker. Turning this on will remove the following: 76 | ; - The Reckoning splash screen. 77 | ; - The intro movie for 38 Studios. 78 | ; 79 | ; skiplegal (boolean) 80 | ; 81 | ; Tells rMod to patch out the legal texture that shows the usage credits and copyrights. 82 | ; (quickload must be enabled for this to work!) 83 | ; 84 | ;--------------------------------------------------------------------------------------------------- 85 | [splash] 86 | quickload = 1 87 | skiplegal = 0 88 | 89 | ;--------------------------------------------------------------------------------------------------- 90 | ; ~ Fin! 91 | ;--------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /plugins/Addons.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/plugins/Addons.dll -------------------------------------------------------------------------------- /plugins/sdk/Atomic_BinaryData.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atomic SDK - Copyright (c) 2014 - 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using Atomic SDK, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (Atomic SDK) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (Atomic SDK), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * Atomic SDK project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | */ 25 | 26 | // ReSharper disable CppInconsistentNaming 27 | 28 | #ifndef __ATOMIC_SDK_ATOMIC_BINARYDATA_H_INCLUDED__ 29 | #define __ATOMIC_SDK_ATOMIC_BINARYDATA_H_INCLUDED__ 30 | 31 | #if defined (_MSC_VER) && (_MSC_VER >= 1020) 32 | #pragma once 33 | #endif 34 | 35 | #include 36 | #include 37 | 38 | namespace Atomic 39 | { 40 | class BinaryData 41 | { 42 | public: 43 | /** 44 | * Packs data into the given buffer. (Big Endian) 45 | */ 46 | static uint32_t PackBitsBE(uint8_t* data, const uint64_t value, const uint32_t offset, const uint8_t len) 47 | { 48 | return PackBitsBE(data, value, 0, offset, len); 49 | } 50 | 51 | /** 52 | * Packs data into the given buffer. (Big Endian) 53 | */ 54 | static uint32_t PackBitsBE(uint8_t* data, uint64_t value, uint32_t byteOffset, uint32_t bitOffset, const uint8_t len) 55 | { 56 | byteOffset += bitOffset >> 3; 57 | bitOffset %= 8; 58 | 59 | auto bitmask = (uint64_t)0xFFFFFFFFFFFFFFFFLL; 60 | bitmask >>= 64 - len; 61 | bitmask <<= bitOffset; 62 | value <<= bitOffset; 63 | value &= bitmask; 64 | bitmask ^= 0xFFFFFFFFFFFFFFFFLL; 65 | 66 | if (len + bitOffset <= 8) 67 | { 68 | const auto dataPointer = (uint8_t*)&data[byteOffset]; 69 | const auto bitmaskUC = (uint8_t)bitmask; 70 | const auto valueUC = (uint8_t)value; 71 | *dataPointer &= bitmaskUC; 72 | *dataPointer |= valueUC; 73 | } 74 | else if (len + bitOffset <= 16) 75 | { 76 | const auto dataPointer = (uint16_t*)&data[byteOffset]; 77 | const auto bitmaskUC = (uint16_t)bitmask; 78 | const auto valueUC = (uint16_t)value; 79 | *dataPointer &= bitmaskUC; 80 | *dataPointer |= valueUC; 81 | } 82 | else if (len + bitOffset <= 32) 83 | { 84 | const auto dataPointer = (uint32_t*)&data[byteOffset]; 85 | const auto bitmaskUC = (uint32_t)bitmask; 86 | const auto valueUC = (uint32_t)value; 87 | *dataPointer &= bitmaskUC; 88 | *dataPointer |= valueUC; 89 | } 90 | else if (len + bitOffset <= 64) 91 | { 92 | const auto dataPointer = (uint64_t*)&data[byteOffset]; 93 | *dataPointer &= bitmask; 94 | *dataPointer |= value; 95 | } 96 | else 97 | { 98 | // We should not get here.. an error occurred.. 99 | // data size > 64bits 100 | } 101 | 102 | return (byteOffset << 3) + bitOffset + len; 103 | } 104 | 105 | /** 106 | * Unpacks data from the given buffer. (Big Endian) 107 | */ 108 | static uint64_t UnpackBitsBE(uint8_t* data, const uint32_t offset, const uint8_t len) 109 | { 110 | return UnpackBitsBE(data, 0, offset, len); 111 | } 112 | 113 | /** 114 | * Unpacks data from the given buffer. (Big Endian) 115 | */ 116 | static uint64_t UnpackBitsBE(uint8_t* data, uint32_t byteOffset, uint32_t bitOffset, const uint8_t len) 117 | { 118 | byteOffset += (bitOffset >> 3); 119 | bitOffset %= 8; 120 | 121 | uint64_t retVal; 122 | auto bitmask = (uint64_t)0xFFFFFFFFFFFFFFFFLL; 123 | bitmask >>= (64 - len); 124 | bitmask <<= bitOffset; 125 | 126 | if (len + bitOffset <= 8) 127 | { 128 | const auto dataPointer = (uint8_t*)&data[byteOffset]; 129 | retVal = (*dataPointer&(uint8_t)bitmask) >> bitOffset; 130 | } 131 | else if (len + bitOffset <= 16) 132 | { 133 | const auto dataPointer = (uint16_t*)&data[byteOffset]; 134 | retVal = (*dataPointer&(uint16_t)bitmask) >> bitOffset; 135 | } 136 | else if (len + bitOffset <= 32) 137 | { 138 | const auto dataPointer = (uint32_t*)&data[byteOffset]; 139 | retVal = (*dataPointer&(uint32_t)bitmask) >> bitOffset; 140 | } 141 | else if (len + bitOffset <= 64) 142 | { 143 | const auto dataPointer = (uint64_t*)&data[byteOffset]; 144 | retVal = (*dataPointer&(uint64_t)bitmask) >> bitOffset; 145 | } 146 | else 147 | { 148 | // We should not get here.. an error occurred.. 149 | // data size > 64bits 150 | return 0; 151 | } 152 | 153 | return retVal; 154 | } 155 | 156 | /** 157 | * Packs data into the given buffer. (Little Endian) 158 | */ 159 | static uint32_t PackBitsLE(uint8_t* data, const uint64_t value, const uint32_t offset, const uint8_t len) 160 | { 161 | return PackBitsLE(data, value, 0, offset, len); 162 | } 163 | 164 | /** 165 | * Packs data into the given buffer. (Little Endian) 166 | */ 167 | static uint32_t PackBitsLE(uint8_t* data, const uint64_t value, uint32_t byteOffset, uint32_t bitOffset, const uint8_t len) 168 | { 169 | byteOffset += bitOffset >> 3; 170 | bitOffset %= 8; 171 | 172 | uint8_t bytesNeeded; 173 | if (bitOffset + len <= 8) 174 | bytesNeeded = 1; 175 | else if (bitOffset + len <= 16) 176 | bytesNeeded = 2; 177 | else if (bitOffset + len <= 32) 178 | bytesNeeded = 4; 179 | else if (bitOffset + len <= 64) 180 | bytesNeeded = 8; 181 | else 182 | { 183 | // We should not get here.. an error occurred.. 184 | // data size > 64bits 185 | return 0; 186 | } 187 | 188 | const auto modifieddata = new uint8_t[bytesNeeded]; 189 | for (uint8_t curByte = 0; curByte < bytesNeeded; ++curByte) 190 | { 191 | modifieddata[curByte] = data[byteOffset + (bytesNeeded - 1) - curByte]; 192 | } 193 | 194 | const int32_t newBitOffset = (bytesNeeded << 3) - (bitOffset + len); 195 | PackBitsBE(&modifieddata[0], value, 0, newBitOffset, len); 196 | 197 | for (uint8_t curByte = 0; curByte < bytesNeeded; ++curByte) 198 | { 199 | data[byteOffset + (bytesNeeded - 1) - curByte] = modifieddata[curByte]; 200 | } 201 | 202 | if (modifieddata) 203 | delete[] modifieddata; 204 | 205 | return (byteOffset << 3) + bitOffset + len; 206 | } 207 | 208 | /** 209 | * Unpacks data from the given buffer. (Little Endian) 210 | */ 211 | static uint64_t UnpackBitsLE(uint8_t* data, const uint32_t offset, const uint8_t len) 212 | { 213 | return UnpackBitsLE(data, 0, offset, len); 214 | } 215 | 216 | /** 217 | * Unpacks data from the given buffer. (Little Endian) 218 | */ 219 | static uint64_t UnpackBitsLE(uint8_t* data, uint32_t byteOffset, uint32_t bitOffset, uint8_t const len) 220 | { 221 | byteOffset += bitOffset >> 3; 222 | bitOffset %= 8; 223 | 224 | uint8_t bytesNeeded; 225 | if (bitOffset + len <= 8) 226 | bytesNeeded = 1; 227 | else if (bitOffset + len <= 16) 228 | bytesNeeded = 2; 229 | else if (bitOffset + len <= 32) 230 | bytesNeeded = 4; 231 | else if (bitOffset + len <= 64) 232 | bytesNeeded = 8; 233 | else 234 | { 235 | // We should not get here.. an error occurred.. 236 | // data size > 64bits 237 | return 0; 238 | } 239 | 240 | uint64_t retVal; 241 | 242 | const auto modifieddata = new uint8_t[bytesNeeded]; 243 | for (uint8_t curByte = 0; curByte < bytesNeeded; ++curByte) 244 | { 245 | modifieddata[curByte] = data[byteOffset + (bytesNeeded - 1) - curByte]; 246 | } 247 | 248 | if (bytesNeeded == 1) 249 | { 250 | const uint8_t bitmask = 0xFF >> bitOffset; 251 | retVal = (modifieddata[0] & bitmask) >> (8 - (len + bitOffset)); 252 | } 253 | else 254 | { 255 | const int32_t newBitOffset = (bytesNeeded * 8) - (bitOffset + len); 256 | retVal = UnpackBitsBE(&modifieddata[0], 0, newBitOffset, len); 257 | } 258 | 259 | if (modifieddata) 260 | delete[] modifieddata; 261 | 262 | return retVal; 263 | } 264 | }; 265 | }; // namespace Atomic 266 | 267 | #endif // __ATOMIC_SDK_ATOMIC_BINARYDATA_H_INCLUDED__ -------------------------------------------------------------------------------- /plugins/sdk/Atomic_CommandParse.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atomic SDK - Copyright (c) 2014 - 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using Atomic SDK, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (Atomic SDK) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (Atomic SDK), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * Atomic SDK project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | */ 25 | 26 | // ReSharper disable CppDefaultCaseNotHandledInSwitchStatement 27 | // ReSharper disable CppInconsistentNaming 28 | // ReSharper disable CppMemberFunctionMayBeStatic 29 | 30 | #ifndef __ATOMIC_SDK_ATOMIC_COMMANDPARSE_H_INCLUDED__ 31 | #define __ATOMIC_SDK_ATOMIC_COMMANDPARSE_H_INCLUDED__ 32 | 33 | #if defined (_MSC_VER) && (_MSC_VER >= 1020) 34 | #pragma once 35 | #endif 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | /** 42 | * Helper Macros For Command Handling 43 | */ 44 | #ifndef HANDLECOMMAND 45 | #define HANDLECOMMAND_GA(arg1, arg2, arg3, arg4, arg5, arg6, ...) arg6 46 | #define HANDLECOMMAND_01(a) Atomic::CommandHandler::__command_parse(args[0].c_str(), a) 47 | #define HANDLECOMMAND_02(a, b) Atomic::CommandHandler::__command_parse(args[0].c_str(), a, b) 48 | #define HANDLECOMMAND_03(a, b, c) Atomic::CommandHandler::__command_parse(args[0].c_str(), a, b, c) 49 | #define HANDLECOMMAND_04(a, b, c, d) Atomic::CommandHandler::__command_parse(args[0].c_str(), a, b, c, d) 50 | #define HANDLECOMMAND_05(a, b, c, d, e) Atomic::CommandHandler::__command_parse(args[0].c_str(), a, b, c, d, e) 51 | #define HANDLECOMMAND_CC(...) HANDLECOMMAND_GA(__VA_ARGS__, HANDLECOMMAND_05, HANDLECOMMAND_04, HANDLECOMMAND_03, HANDLECOMMAND_02, HANDLECOMMAND_01,) 52 | #define HANDLECOMMAND(...) if (args.size() > 0 && HANDLECOMMAND_CC(__VA_ARGS__)(__VA_ARGS__)) 53 | #endif 54 | 55 | namespace Atomic 56 | { 57 | namespace CommandHandler 58 | { 59 | /** 60 | * Compares two strings against each other. 61 | * 62 | * @param {const char*} cmd - The first string to compare. (Usually the command.) 63 | * @param {const char*} arg1 - The second string to compare. 64 | * @returns {bool} True if strings match, arg5alse otherwise. 65 | */ 66 | static bool __forceinline __command_cmp(const char* cmd, const char* arg1) 67 | { 68 | if (cmd == nullptr || arg1 == nullptr) 69 | return false; 70 | return (_stricmp(cmd, arg1) == 0); 71 | } 72 | 73 | /** 74 | * Compares the first argument (command) to the others for a match. 75 | * 76 | * @param {T} cmd - The command to compare again. 77 | * @param {T} arg1 - Argument to match command to. 78 | * @returns {bool} True on match, false otherwise. 79 | */ 80 | template 81 | static bool __command_parse(T cmd, T arg1) 82 | { 83 | return __command_cmp(cmd, arg1); 84 | } 85 | 86 | /** 87 | * Compares the first argument (command) to the others for a match. 88 | * 89 | * @param {T} cmd - The command to compare again. 90 | * @param {T} arg1 - Argument to match command to. 91 | * @param {T} arg2 - Argument to match command to. 92 | * @returns {bool} True on match, false otherwise. 93 | */ 94 | template 95 | static bool __command_parse(T cmd, T arg1, T arg2) 96 | { 97 | return __command_cmp(cmd, arg1) || __command_cmp(cmd, arg2); 98 | } 99 | 100 | /** 101 | * Compares the first argument (command) to the others for a match. 102 | * 103 | * @param {T} cmd - The command to compare again. 104 | * @param {T} arg1 - Argument to match command to. 105 | * @param {T} arg2 - Argument to match command to. 106 | * @param {T} arg3 - Argument to match command to. 107 | * @returns {bool} True on match, false otherwise. 108 | */ 109 | template 110 | static bool __command_parse(T cmd, T arg1, T arg2, T arg3) 111 | { 112 | return __command_cmp(cmd, arg1) || __command_cmp(cmd, arg2) || __command_cmp(cmd, arg3); 113 | } 114 | 115 | /** 116 | * Compares the first argument (command) to the others for a match. 117 | * 118 | * @param {T} cmd - The command to compare again. 119 | * @param {T} arg1 - Argument to match command to. 120 | * @param {T} arg2 - Argument to match command to. 121 | * @param {T} arg3 - Argument to match command to. 122 | * @param {T} arg4 - Argument to match command to. 123 | * @returns {bool} True on match, false otherwise. 124 | */ 125 | template 126 | static bool __command_parse(T cmd, T arg1, T arg2, T arg3, T arg4) 127 | { 128 | return __command_cmp(cmd, arg1) || __command_cmp(cmd, arg2) || __command_cmp(cmd, arg3) || __command_cmp(cmd, arg4); 129 | } 130 | 131 | /** 132 | * Compares the first argument (command) to the others for a match. 133 | * 134 | * @param {T} cmd - The command to compare again. 135 | * @param {T} arg1 - Argument to match command to. 136 | * @param {T} arg2 - Argument to match command to. 137 | * @param {T} arg3 - Argument to match command to. 138 | * @param {T} arg4 - Argument to match command to. 139 | * @param {T} arg5 - Argument to match command to. 140 | * @returns {bool} True on match, false otherwise. 141 | */ 142 | template 143 | static bool __command_parse(T cmd, T arg1, T arg2, T arg3, T arg4, T arg5) 144 | { 145 | return __command_cmp(cmd, arg1) || __command_cmp(cmd, arg2) || __command_cmp(cmd, arg3) || __command_cmp(cmd, arg4) || __command_cmp(cmd, arg5); 146 | } 147 | }; // namespace CommandHandler 148 | 149 | namespace Commands 150 | { 151 | /** 152 | * isspace replacement to avoid CRT asserts. 153 | * 154 | * @param {char} szChar - Character to check for space. 155 | * @returns {bool} True if a whitespace char is found, arg5alse otherwise. 156 | */ 157 | static __forceinline bool _isspace(const char c) 158 | { 159 | const auto num = (int)c; 160 | 161 | // Checks for the following: ' ', \t \n \v \f \r 162 | if (num == 0x20 || num == 0x09 || num == 0x0A || num == 0x0B || num == 0x0C || num == 0x0D) 163 | return true; 164 | return false; 165 | } 166 | 167 | /** 168 | * Parses the given command for arguments. 169 | * 170 | * @param {const char*} pszCommand - The command to parse for arguments. 171 | * @param {std::vector*} args - Pointer to an array of std::string to hold the found arguments. 172 | * @returns {int} Returns the number of found arguments, if any. 173 | * 174 | * 175 | * @note This function mimics the *nix command 'strsep' to locate and parse strings with 176 | * inline-quotes. Thanks to the following for the basis of this function: 177 | * 178 | * http://stackoverflow.com/questions/9659697/parse-string-into-array-based-on-spaces-or-double-quotes-strings 179 | */ 180 | static int GetCommandArgs(const char* pszCommand, std::vector* args) 181 | { 182 | // The current parsing state we are in.. 183 | enum { NONE, IN_WORD, IN_STRING } state = NONE; 184 | 185 | char szCurrentArgument[255] = { 0 }; 186 | auto p = pszCommand; 187 | char *pszStart = nullptr; 188 | 189 | // Walk the string to locate arguments.. 190 | for (; *p != 0; ++p) 191 | { 192 | // Obtain the current character.. 193 | const auto currChar = (char)*p; 194 | 195 | // Handle the current state.. 196 | switch (state) 197 | { 198 | case NONE: 199 | if (Atomic::Commands::_isspace(currChar)) 200 | continue; 201 | if (currChar == '"') 202 | { 203 | state = IN_STRING; 204 | pszStart = (char*)p + 1; 205 | continue; 206 | } 207 | state = IN_WORD; 208 | pszStart = (char*)p; 209 | continue; 210 | 211 | case IN_STRING: 212 | if (currChar == '"') 213 | { 214 | strncpy_s(szCurrentArgument, pszStart, p - pszStart); 215 | args->push_back(std::string(szCurrentArgument)); 216 | state = NONE; 217 | pszStart = nullptr; 218 | } 219 | continue; 220 | 221 | case IN_WORD: 222 | if (Atomic::Commands::_isspace(currChar)) 223 | { 224 | strncpy_s(szCurrentArgument, pszStart, p - pszStart); 225 | args->push_back(std::string(szCurrentArgument)); 226 | state = NONE; 227 | pszStart = nullptr; 228 | } 229 | continue; 230 | } 231 | } 232 | 233 | // Add any left-over words.. 234 | if (pszStart != nullptr) 235 | { 236 | strncpy_s(szCurrentArgument, pszStart, p - pszStart); 237 | args->push_back(std::string(szCurrentArgument)); 238 | } 239 | 240 | // Return the number of found arguments.. 241 | return args->size(); 242 | } 243 | }; // namespace CommandHandler 244 | }; // namespace Atomic 245 | 246 | #endif // __ATOMIC_SDK_ATOMIC_COMMANDPARSE_H_INCLUDED__ -------------------------------------------------------------------------------- /plugins/sdk/Atomic_Event.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atomic SDK - Copyright (c) 2014 - 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using Atomic SDK, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (Atomic SDK) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (Atomic SDK), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * Atomic SDK project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | */ 25 | 26 | // ReSharper disable CppDefaultCaseNotHandledInSwitchStatement 27 | // ReSharper disable CppInconsistentNaming 28 | // ReSharper disable CppMemberFunctionMayBeStatic 29 | 30 | #ifndef __ATOMIC_SDK_ATOMIC_EVENT_H_INCLUDED__ 31 | #define __ATOMIC_SDK_ATOMIC_EVENT_H_INCLUDED__ 32 | 33 | #if defined (_MSC_VER) && (_MSC_VER >= 1020) 34 | #pragma once 35 | #endif 36 | 37 | #include 38 | 39 | namespace Atomic 40 | { 41 | namespace Threading 42 | { 43 | class Atomic_Event 44 | { 45 | HANDLE m_EventHandle; 46 | 47 | public: 48 | /** 49 | * Constructor and Deconstructor 50 | */ 51 | Threading::Atomic_Event(const bool manualReset = true) 52 | { 53 | this->m_EventHandle = ::CreateEvent(nullptr, manualReset, FALSE, nullptr); 54 | } 55 | virtual Atomic_Event::~Atomic_Event(void) 56 | { 57 | if (this->m_EventHandle != nullptr) 58 | ::CloseHandle(this->m_EventHandle); 59 | this->m_EventHandle = nullptr; 60 | } 61 | 62 | public: 63 | /** 64 | * Resets this event. 65 | * 66 | * @returns {bool} True on success, false otherwise. 67 | */ 68 | bool Reset(void) const 69 | { 70 | return (::ResetEvent(this->m_EventHandle) ? true : false); 71 | } 72 | 73 | /** 74 | * Raises the event. 75 | * 76 | * @returns {bool} True on success, false otherwise. 77 | */ 78 | bool Raise(void) const 79 | { 80 | return (::SetEvent(this->m_EventHandle) ? true : false); 81 | } 82 | 83 | /** 84 | * Determines if this event is signaled. 85 | * 86 | * @returns {bool} True if signaled, false otherwise. 87 | */ 88 | bool IsSignaled(void) const 89 | { 90 | return (::WaitForSingleObject(this->m_EventHandle, 0) == WAIT_OBJECT_0); 91 | } 92 | 93 | /** 94 | * Waits for the event object with the given timeout. 95 | * 96 | * @param {DWORD} dwMilliseconds - The timeout to wait for the event. 97 | * @returns {bool} True on success, false otherwise. 98 | */ 99 | bool WaitForEvent(const DWORD milliseconds) const 100 | { 101 | return (::WaitForSingleObject(this->m_EventHandle, milliseconds) == WAIT_OBJECT_0); 102 | } 103 | }; 104 | }; // namespace Threading 105 | }; // namespace Atomic 106 | 107 | #endif // __ATOMIC_SDK_ATOMIC_EVENT_H_INCLUDED__ -------------------------------------------------------------------------------- /plugins/sdk/Atomic_Exception.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atomic SDK - Copyright (c) 2014 - 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using Atomic SDK, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (Atomic SDK) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (Atomic SDK), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * Atomic SDK project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | */ 25 | 26 | // ReSharper disable CppDefaultCaseNotHandledInSwitchStatement 27 | // ReSharper disable CppInconsistentNaming 28 | // ReSharper disable CppMemberFunctionMayBeStatic 29 | 30 | #ifndef __ATOMIC_SDK_ATOMIC_EXCEPTION_H_INCLUDED__ 31 | #define __ATOMIC_SDK_ATOMIC_EXCEPTION_H_INCLUDED__ 32 | 33 | #if defined (_MSC_VER) && (_MSC_VER >= 1020) 34 | #pragma once 35 | #endif 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | namespace Atomic 42 | { 43 | namespace Exception 44 | { 45 | /** 46 | * Define misssing STATUS code. 47 | */ 48 | #ifndef STATUS_POSSIBLE_DEADLOCK 49 | #define STATUS_POSSIBLE_DEADLOCK 0xC0000194 50 | #endif 51 | 52 | /** 53 | * Macro for translating exception defines to strings. 54 | */ 55 | #define CASE(Exception) \ 56 | case Exception: \ 57 | this->m_Exception = #Exception; \ 58 | break; 59 | 60 | /** 61 | * Exception object that can obtain all exceptions. 62 | */ 63 | class Atomic_Exception 64 | { 65 | unsigned int m_ExceptionId; 66 | const char* m_Exception; 67 | 68 | public: 69 | /** 70 | * Constructor 71 | */ 72 | Atomic_Exception(const uint32_t id) 73 | : m_ExceptionId(id) 74 | , m_Exception(nullptr) 75 | { 76 | switch (this->m_ExceptionId) 77 | { 78 | CASE(EXCEPTION_ACCESS_VIOLATION); 79 | CASE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED); 80 | CASE(EXCEPTION_BREAKPOINT); 81 | CASE(EXCEPTION_DATATYPE_MISALIGNMENT); 82 | CASE(EXCEPTION_FLT_DENORMAL_OPERAND); 83 | CASE(EXCEPTION_FLT_DIVIDE_BY_ZERO); 84 | CASE(EXCEPTION_FLT_INEXACT_RESULT); 85 | CASE(EXCEPTION_FLT_INVALID_OPERATION); 86 | CASE(EXCEPTION_FLT_OVERFLOW); 87 | CASE(EXCEPTION_FLT_STACK_CHECK); 88 | CASE(EXCEPTION_FLT_UNDERFLOW); 89 | CASE(EXCEPTION_GUARD_PAGE); 90 | CASE(EXCEPTION_ILLEGAL_INSTRUCTION); 91 | CASE(EXCEPTION_IN_PAGE_ERROR); 92 | CASE(EXCEPTION_INT_DIVIDE_BY_ZERO); 93 | CASE(EXCEPTION_INT_OVERFLOW); 94 | CASE(EXCEPTION_INVALID_DISPOSITION); 95 | CASE(EXCEPTION_INVALID_HANDLE); 96 | CASE(EXCEPTION_NONCONTINUABLE_EXCEPTION); 97 | CASE(EXCEPTION_POSSIBLE_DEADLOCK); 98 | CASE(EXCEPTION_PRIV_INSTRUCTION); 99 | CASE(EXCEPTION_SINGLE_STEP); 100 | CASE(EXCEPTION_STACK_OVERFLOW); 101 | 102 | default: 103 | this->m_Exception = "Unknown exception occurred."; 104 | break; 105 | } 106 | } 107 | 108 | /** 109 | * Deconstructor 110 | */ 111 | ~Atomic_Exception(void) 112 | { } 113 | 114 | public: 115 | /** 116 | * Gets the exception id of this exception object. 117 | * 118 | * @returns {unsigned int} The exception id of this object. 119 | */ 120 | unsigned int GetExceptionId(void) const 121 | { 122 | return this->m_ExceptionId; 123 | } 124 | 125 | /** 126 | * Gets the exception string of this exception object. 127 | * 128 | * @returns {const char*} The exception string of this object. 129 | */ 130 | const char* GetException(void) const 131 | { 132 | return this->m_Exception; 133 | } 134 | }; 135 | 136 | /** 137 | * Scoped SEH translator class to automate custom exception filtering. 138 | */ 139 | class ScopedTranslator 140 | { 141 | _se_translator_function m_Function; 142 | 143 | public: 144 | /** 145 | * Constructor 146 | */ 147 | ScopedTranslator(void) 148 | { 149 | this->m_Function = ::_set_se_translator(&ScopedTranslator::ScopedTranslatorFunc); 150 | } 151 | 152 | /** 153 | * Deconstructor 154 | */ 155 | ~ScopedTranslator(void) 156 | { 157 | if (this->m_Function != nullptr) 158 | { 159 | ::_set_se_translator(this->m_Function); 160 | this->m_Function = nullptr; 161 | } 162 | } 163 | 164 | private: 165 | /** 166 | * Exception filter used to rethrow the exception wrapped with our custom object. 167 | * 168 | * @param {uint32_t} id - The id of the exception being thrown. 169 | * @param {_EXCEPTION_POINTERS*} lpPtrs - The exception pointer structure. 170 | */ 171 | static void ScopedTranslatorFunc(const uint32_t id, struct _EXCEPTION_POINTERS* lpPtrs) 172 | { 173 | // Rethrow this exception with our wrapper.. 174 | UNREFERENCED_PARAMETER(lpPtrs); 175 | throw Atomic::Exception::Atomic_Exception(id); 176 | } 177 | }; 178 | }; // namespace Exception 179 | }; // namespace Atomic 180 | 181 | #endif // __ATOMIC_SDK_ATOMIC_EXCEPTION_H_INCLUDED__ -------------------------------------------------------------------------------- /plugins/sdk/Atomic_LockableObject.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atomic SDK - Copyright (c) 2014 - 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using Atomic SDK, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (Atomic SDK) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (Atomic SDK), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * Atomic SDK project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | */ 25 | 26 | // ReSharper disable CppDefaultCaseNotHandledInSwitchStatement 27 | // ReSharper disable CppInconsistentNaming 28 | // ReSharper disable CppMemberFunctionMayBeStatic 29 | 30 | #ifndef __ATOMIC_SDK_ATOMIC_LOCKABLEOBJECT_H_INCLUDED__ 31 | #define __ATOMIC_SDK_ATOMIC_LOCKABLEOBJECT_H_INCLUDED__ 32 | 33 | #include 34 | 35 | namespace Atomic 36 | { 37 | namespace Threading 38 | { 39 | class Atomic_LockableObject 40 | { 41 | CRITICAL_SECTION m_CriticalSection; 42 | 43 | /** 44 | * Disables the copy constructor. 45 | */ 46 | Atomic_LockableObject(const Atomic_LockableObject& obj) = delete; 47 | 48 | public: 49 | /** 50 | * Constructor 51 | */ 52 | Threading::Atomic_LockableObject(void) 53 | { 54 | ::InitializeCriticalSection(&this->m_CriticalSection); 55 | } 56 | 57 | /** 58 | * Deconstructor 59 | */ 60 | virtual Atomic_LockableObject::~Atomic_LockableObject(void) 61 | { 62 | ::DeleteCriticalSection(&this->m_CriticalSection); 63 | } 64 | 65 | public: 66 | /** 67 | * Locks the critical section of this object. 68 | */ 69 | void Lock(void) 70 | { 71 | ::EnterCriticalSection(&this->m_CriticalSection); 72 | } 73 | 74 | /** 75 | * Unlocks the critical section of this object. 76 | */ 77 | void Unlock(void) 78 | { 79 | ::LeaveCriticalSection(&this->m_CriticalSection); 80 | } 81 | }; 82 | }; // namespace Threading 83 | }; // namespace Atomic 84 | 85 | #endif // __ATOMIC_SDK_ATOMIC_LOCKABLEOBJECT_H_INCLUDED__ -------------------------------------------------------------------------------- /plugins/sdk/Atomic_Memory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atomic SDK - Copyright (c) 2014 - 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using Atomic SDK, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (Atomic SDK) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (Atomic SDK), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * Atomic SDK project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | */ 25 | 26 | // ReSharper disable CppInconsistentNaming 27 | // ReSharper disable CppRedundantQualifier 28 | 29 | #ifndef __ATOMIC_SDK_ATOMIC_MEMORY_H_INCLUDED__ 30 | #define __ATOMIC_SDK_ATOMIC_MEMORY_H_INCLUDED__ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace Atomic 38 | { 39 | namespace Memory 40 | { 41 | /** 42 | * Iteratable object to reduce the overhead of using a vector. 43 | */ 44 | template 45 | struct scannableiterator_t 46 | { 47 | uintptr_t m_BaseAddress; 48 | uintptr_t m_BaseSize; 49 | 50 | scannableiterator_t(const uintptr_t base, const uintptr_t size) 51 | : m_BaseAddress(base), m_BaseSize(size) 52 | { } 53 | scannableiterator_t(const scannableiterator_t&) = delete; 54 | 55 | T* begin(void) { return (T*)this->m_BaseAddress; } 56 | T* end(void) { return (T*)(this->m_BaseAddress + this->m_BaseSize); } 57 | }; 58 | 59 | /** 60 | * Finds a pattern within the given range of data. 61 | * 62 | * @param {uintptr_t} baseAddress - The address of the data to begin searching within. 63 | * @param {uintptr_t} baseSize - The size of the data to search within. 64 | * @param {const char*} pattern - The pattern to search for. 65 | * @param {intptr_t} offset - The offset from the found location to add to the pointer. 66 | * @param {uintptr_t} count - The result count to use if the pattern is found more than once. 67 | * @returns {uintptr_t} The address where the pattern was located, 0 otherwise. 68 | */ 69 | static uintptr_t FindPattern(const uintptr_t baseAddress, const uintptr_t baseSize, const char* pattern, const intptr_t offset, const uintptr_t count) 70 | { 71 | // Convert the pattern to a vector of data.. 72 | std::vector> vpattern; 73 | for (size_t x = 0, y = (strlen(pattern) / 3) + 1; x < y; x++) 74 | { 75 | // Obtain the current byte.. 76 | std::stringstream stream(std::string(pattern + (x * 3), 2)); 77 | 78 | // Check if this is a wildcard.. 79 | if (stream.str() == "??") 80 | vpattern.push_back(std::make_pair(00, false)); 81 | else 82 | { 83 | const auto byte = strtol(stream.str().c_str(), nullptr, 16); 84 | vpattern.push_back(std::make_pair((uint8_t)byte, true)); 85 | } 86 | } 87 | 88 | // Create a scanner object to use with the STL functions.. 89 | scannableiterator_t data(baseAddress, baseSize); 90 | auto scanStart = data.begin(); 91 | auto result = (uintptr_t)0; 92 | 93 | while (true) 94 | { 95 | // Search for the pattern.. 96 | auto ret = std::search(scanStart, data.end(), vpattern.begin(), vpattern.end(), 97 | [&](uint8_t curr, std::pair currPattern) 98 | { 99 | return !currPattern.second || curr == currPattern.first; 100 | }); 101 | 102 | // Did we find a match.. 103 | if (ret != data.end()) 104 | { 105 | // If we hit the usage count, return the result.. 106 | if (result == count || count == 0) 107 | return (std::distance(data.begin(), ret) + baseAddress) + offset; 108 | 109 | // Increment the found count and scan again.. 110 | ++result; 111 | scanStart = ++ret; 112 | } 113 | else 114 | break; 115 | } 116 | 117 | return 0; 118 | } 119 | 120 | /** 121 | * Obtains the calling module handle for the given address. 122 | * 123 | * @param {uintptr_t} returnAddress - The address to locate the module owner of. 124 | * @returns {HMODULE} The module handle if found, nullptr otherwise. 125 | */ 126 | static HMODULE __stdcall GetCallingModule(const uintptr_t returnAddress) 127 | { 128 | if (returnAddress == 0) 129 | return nullptr; 130 | 131 | MEMORY_BASIC_INFORMATION mbi = { nullptr }; 132 | if (::VirtualQuery((LPCVOID)returnAddress, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == sizeof(MEMORY_BASIC_INFORMATION)) 133 | return (HMODULE)mbi.AllocationBase; 134 | 135 | return nullptr; 136 | } 137 | 138 | /** 139 | * Hooks a VTable function and overrides it with the given new function pointer. 140 | * 141 | * @param {uintptr_t} ptrVTable - The VTable pointer. 142 | * @param {uint32_t} index - The index of the function to hook. 143 | * @param {uintptr_t} ptrNewFunction - The pointer to the new function to replace with. 144 | * @returns {uintptr_t} The original function pointer on success, 0 otherwise. 145 | */ 146 | static uintptr_t HookVTableFunc(const uintptr_t ptrVTable, const uint32_t index, uintptr_t ptrNewFunction) 147 | { 148 | const auto ptr = (uint8_t*)(ptrVTable + index * sizeof(uint32_t)); 149 | auto old = *(uintptr_t**)ptr; 150 | 151 | // Prepare the overwrite buffer.. 152 | char buffer[4] = { 0 }; 153 | memcpy(buffer, (uint8_t*)&ptrNewFunction, 4); 154 | 155 | // Prepare the memory space.. 156 | DWORD oldProtect; 157 | if (!::VirtualProtect(ptr, 4, PAGE_EXECUTE_READWRITE, &oldProtect)) 158 | return 0; 159 | 160 | // Write the new VTable pointer.. 161 | ::InterlockedExchange((volatile LONG*)ptr, *(LONG*)&buffer); 162 | 163 | // Restore the memory protection.. 164 | ::VirtualProtect(ptr, 4, oldProtect, &oldProtect); 165 | 166 | // Return the original pointer.. 167 | return (uintptr_t)old; 168 | } 169 | 170 | /** 171 | * Writes a block of data to the given address. (Handles protections automatically.) 172 | * 173 | * @param {uintptr_t} address - The address to write the data to. 174 | * @param {uint8_t*} data - The data to be written. 175 | * @param {uint32_t} size - The amount of data to write. 176 | * @returns {bool} True on success, false otherwise. 177 | */ 178 | static bool WriteMem(const uintptr_t address, uint8_t* data, const uint32_t size) 179 | { 180 | // Adjust the memory protection.. 181 | DWORD oldProtect = 0; 182 | if (!::VirtualProtect((uint8_t*)address, size, PAGE_EXECUTE_READWRITE, &oldProtect)) 183 | return false; 184 | 185 | // Write the data to memory.. 186 | memcpy((uint8_t*)address, data, size); 187 | 188 | // Restore the memory protection.. 189 | ::VirtualProtect((uint8_t*)address, size, oldProtect, &oldProtect); 190 | 191 | return true; 192 | } 193 | 194 | /** 195 | * Patches the original function by replacing the original data with a call to the given cave. 196 | * 197 | * @param {uintptr_t} origFuncAddress - The original function address to patch. 198 | * @param {uintptr_t} caveFuncAddress - The cave function to be called. 199 | * @param {uint32_t} nopCount - The amount of nops to place to cleanup old data. 200 | * @param {uint8_t**} backupOutput - Pointer to a variable to store the backup data at. 201 | * @returns {uint32_t} Return address to where code can jump back after the patch, 0 if failed. 202 | */ 203 | static uint32_t CaveCall(const uintptr_t origFuncAddress, const uintptr_t caveFuncAddress, const uint32_t nopCount, uint8_t** backupOutput) 204 | { 205 | // Calculate the code cave offset.. 206 | auto offset = caveFuncAddress - origFuncAddress - 5; 207 | 208 | // Create the jump to the cave.. 209 | uint8_t call[0x05] = { 0xE8, 0x00, 0x00, 0x00, 0x00 }; 210 | memcpy(call + 1, &offset, 4); 211 | 212 | // Backup the original code.. 213 | *backupOutput = new uint8_t[0x05 + nopCount]; 214 | memcpy(*backupOutput, (uint8_t*)origFuncAddress, 0x05 + nopCount); 215 | 216 | // Prepare the nop array.. 217 | uint8_t nops[0xFF] = { 0 }; 218 | memset(nops, 0x90, nopCount); 219 | 220 | // Write the call.. 221 | WriteMem(origFuncAddress, call, 0x05); 222 | 223 | // Write any nops if needed.. 224 | if (nopCount > 0) 225 | WriteMem(origFuncAddress + 5, nops, nopCount); 226 | 227 | // Calculate the return address.. 228 | return origFuncAddress + 0x05 + nopCount; 229 | } 230 | 231 | /** 232 | * Restores a cave call placement by writing back the original data. 233 | * 234 | * @param {uintptr_t} origFuncAddress - The original function address to restore. 235 | * @param {uint8_t**} backup - Pointer to the backup data to restore. 236 | * @param {uint32_t} size - The amount of data in the backup to restore. 237 | */ 238 | static void RestoreCaveCall(const uintptr_t origFuncAddress, uint8_t** backup, const uint32_t size) 239 | { 240 | // Restore the original function data.. 241 | WriteMem(origFuncAddress, *backup, size); 242 | } 243 | }; // namespace Memory 244 | }; // namespace Atomic 245 | 246 | #endif // __ATOMIC_SDK_ATOMIC_MEMORY_H_INCLUDED__ -------------------------------------------------------------------------------- /plugins/sdk/Atomic_Thread.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atomic SDK - Copyright (c) 2014 - 2018 atom0s [atom0s@live.com] 3 | * 4 | * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 5 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to 6 | * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. 7 | * 8 | * By using Atomic SDK, you agree to the above license and its terms. 9 | * 10 | * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were 11 | * made. You must do so in any reasonable manner, but not in any way that suggests the licensor 12 | * endorses you or your use. 13 | * 14 | * Non-Commercial - You may not use the material (Atomic SDK) for commercial purposes. 15 | * 16 | * No-Derivatives - If you remix, transform, or build upon the material (Atomic SDK), you may not distribute the 17 | * modified material. You are, however, allowed to submit the modified works back to the original 18 | * Atomic SDK project in attempt to have it added to the original project. 19 | * 20 | * You may not apply legal terms or technological measures that legally restrict others 21 | * from doing anything the license permits. 22 | * 23 | * No warranties are given. 24 | */ 25 | 26 | // ReSharper disable CppDefaultCaseNotHandledInSwitchStatement 27 | // ReSharper disable CppInconsistentNaming 28 | // ReSharper disable CppMemberFunctionMayBeStatic 29 | 30 | #ifndef __ATOMIC_SDK_ATOMIC_THREAD_H_INCLUDED__ 31 | #define __ATOMIC_SDK_ATOMIC_THREAD_H_INCLUDED__ 32 | 33 | #include 34 | #include "Atomic_Event.h" 35 | 36 | namespace Atomic 37 | { 38 | namespace Threading 39 | { 40 | /** 41 | * Thread Priority Enumeration 42 | */ 43 | enum ThreadPriorty 44 | { 45 | Lowest = -2, 46 | BelowNormal = -1, 47 | Normal = 0, 48 | AboveNormal = 1, 49 | Highest = 2 50 | }; 51 | 52 | class Atomic_Thread 53 | { 54 | HANDLE m_ThreadHandle; // The thread handle of this object. 55 | DWORD m_ThreadId; // The thread id of this object. 56 | Atomic_Event m_StartEvent; // The starting event of this thread. 57 | Atomic_Event m_EndEvent; // The ending event of this thread. 58 | 59 | public: 60 | /** 61 | * Constructor 62 | */ 63 | Threading::Atomic_Thread(void) 64 | : m_ThreadHandle(nullptr), m_ThreadId(0), m_StartEvent(true), m_EndEvent(true) 65 | { } 66 | 67 | /** 68 | * Deconstructor 69 | */ 70 | virtual Atomic_Thread::~Atomic_Thread(void) 71 | { 72 | if (this->m_ThreadHandle != nullptr) 73 | this->Stop(); 74 | } 75 | 76 | public: 77 | /** 78 | * Virtual thread entry point to be overriden. 79 | */ 80 | virtual DWORD Atomic_ThreadEntry(void) = 0; 81 | 82 | /** 83 | * Internal thread entry point to be invoked. 84 | */ 85 | DWORD InternalEntry(void) 86 | { 87 | // Ensure we are valid.. 88 | if (this->IsTerminated()) 89 | return 0; 90 | 91 | // Adjust events accordingly.. 92 | this->m_EndEvent.Reset(); 93 | ::Sleep(10); 94 | this->m_StartEvent.Raise(); 95 | 96 | // Call the real entry point.. 97 | return this->Atomic_ThreadEntry(); 98 | } 99 | 100 | /** 101 | * Starts this thread object. 102 | */ 103 | void Start(void) 104 | { 105 | // Start the thread.. 106 | this->m_StartEvent.Reset(); 107 | this->m_ThreadHandle = CreateThread(nullptr, NULL, ThreadCallback, (LPVOID)this, NULL, &this->m_ThreadId); 108 | } 109 | 110 | /** 111 | * Stops this thread object. 112 | */ 113 | void Stop(void) 114 | { 115 | // Stop the thread.. 116 | this->RaiseEnd(); 117 | 118 | if (this->WaitForFinish(INFINITE)) 119 | { 120 | ::CloseHandle(this->m_ThreadHandle); 121 | this->m_ThreadHandle = nullptr; 122 | this->m_ThreadId = 0; 123 | } 124 | } 125 | 126 | /** 127 | * Waits for this thread object to finish executing. 128 | * 129 | * @param {DWORD} dwMilliseconds - The time in milliseconds to wait for the thread to finish. 130 | * @returns {bool} True on success, false otherwise. 131 | */ 132 | bool WaitForFinish(const DWORD milliseconds = INFINITE) const 133 | { 134 | if (this->m_ThreadHandle == nullptr) 135 | return false; 136 | return (::WaitForSingleObject(this->m_ThreadHandle, milliseconds) != WAIT_TIMEOUT); 137 | } 138 | 139 | /** 140 | * Sets the threads priority. 141 | * 142 | * @param {ThreadPriority} priority - The priority to set the thread to. 143 | */ 144 | void SetPriority(const ThreadPriorty priority) const 145 | { 146 | ::SetThreadPriority(this->m_ThreadHandle, priority); 147 | } 148 | 149 | /** 150 | * Gets the priority of the thread. 151 | * 152 | * @returns {int} The priority id of the thread. 153 | */ 154 | int GetPriority(void) const 155 | { 156 | return ::GetThreadPriority(this->m_ThreadHandle); 157 | } 158 | 159 | /** 160 | * Raises the end event for the thread. 161 | */ 162 | void RaiseEnd(void) const 163 | { 164 | this->m_EndEvent.Raise(); 165 | } 166 | 167 | /** 168 | * Resets the end event for the thread. 169 | */ 170 | void ResetEnd(void) const 171 | { 172 | this->m_EndEvent.Reset(); 173 | } 174 | 175 | /** 176 | * Returns if the thread is terminated or not. 177 | * 178 | * @returns {bool} True if terminated, false otherwise. 179 | */ 180 | bool IsTerminated(void) const 181 | { 182 | return this->m_EndEvent.IsSignaled(); 183 | } 184 | 185 | public: 186 | /** 187 | * Gets the thread handle. 188 | * 189 | * @returns {HANDLE} The current thread handle. 190 | */ 191 | HANDLE GetHandle(void) const 192 | { 193 | return this->m_ThreadHandle; 194 | } 195 | 196 | /** 197 | * Gets the thread id. 198 | * 199 | * @returns {DWORD} The current thread id. 200 | */ 201 | DWORD GetId(void) const 202 | { 203 | return this->m_ThreadId; 204 | } 205 | 206 | /** 207 | * Gets the thread exit code. 208 | * 209 | * @returns {DWORD} The current thread exit code. 210 | */ 211 | DWORD GetExitCode(void) const 212 | { 213 | if (this->m_ThreadHandle == nullptr) 214 | return 0; 215 | 216 | DWORD dwExitCode = 0; 217 | ::GetExitCodeThread(this->m_ThreadHandle, &dwExitCode); 218 | return dwExitCode; 219 | } 220 | 221 | private: 222 | /** 223 | * The threading callback handler to invoke the internal entrypoint of the thread. 224 | * 225 | * @param {LPVOID} lpParam - The param of this thread. (Atomic_Thread object.) 226 | * @returns {DWORD} The return of the internal thread entry points function. 227 | */ 228 | static DWORD __stdcall ThreadCallback(const LPVOID lpParam) 229 | { 230 | auto thread = (Atomic_Thread*)lpParam; 231 | return thread->InternalEntry(); 232 | } 233 | }; 234 | }; // namespace Threading 235 | }; // namespace Atomic 236 | 237 | #endif // __ATOMIC_SDK_ATOMIC_THREAD_H_INCLUDED__ -------------------------------------------------------------------------------- /plugins/sdk/d3d9/DxErr.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/plugins/sdk/d3d9/DxErr.lib -------------------------------------------------------------------------------- /plugins/sdk/d3d9/d3d9.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/plugins/sdk/d3d9/d3d9.lib -------------------------------------------------------------------------------- /plugins/sdk/d3d9/d3dx9.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9.h 6 | // Content: D3DX utility library 7 | // 8 | ////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifdef __D3DX_INTERNAL__ 11 | #error Incorrect D3DX header used 12 | #endif 13 | 14 | #ifndef __D3DX9_H__ 15 | #define __D3DX9_H__ 16 | 17 | 18 | // Defines 19 | #include 20 | 21 | #define D3DX_DEFAULT ((UINT) -1) 22 | #define D3DX_DEFAULT_NONPOW2 ((UINT) -2) 23 | #define D3DX_DEFAULT_FLOAT FLT_MAX 24 | #define D3DX_FROM_FILE ((UINT) -3) 25 | #define D3DFMT_FROM_FILE ((D3DFORMAT) -3) 26 | 27 | #ifndef D3DXINLINE 28 | #ifdef _MSC_VER 29 | #if (_MSC_VER >= 1200) 30 | #define D3DXINLINE __forceinline 31 | #else 32 | #define D3DXINLINE __inline 33 | #endif 34 | #else 35 | #ifdef __cplusplus 36 | #define D3DXINLINE inline 37 | #else 38 | #define D3DXINLINE 39 | #endif 40 | #endif 41 | #endif 42 | 43 | 44 | 45 | // Includes 46 | #include "d3d9.h" 47 | #include "d3dx9math.h" 48 | #include "d3dx9core.h" 49 | #include "d3dx9xof.h" 50 | #include "d3dx9mesh.h" 51 | #include "d3dx9shader.h" 52 | #include "d3dx9effect.h" 53 | 54 | #include "d3dx9tex.h" 55 | #include "d3dx9shape.h" 56 | #include "d3dx9anim.h" 57 | 58 | 59 | 60 | // Errors 61 | #define _FACDD 0x876 62 | #define MAKE_DDHRESULT( code ) MAKE_HRESULT( 1, _FACDD, code ) 63 | 64 | enum _D3DXERR { 65 | D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900), 66 | D3DXERR_INVALIDMESH = MAKE_DDHRESULT(2901), 67 | D3DXERR_CANNOTATTRSORT = MAKE_DDHRESULT(2902), 68 | D3DXERR_SKINNINGNOTSUPPORTED = MAKE_DDHRESULT(2903), 69 | D3DXERR_TOOMANYINFLUENCES = MAKE_DDHRESULT(2904), 70 | D3DXERR_INVALIDDATA = MAKE_DDHRESULT(2905), 71 | D3DXERR_LOADEDMESHASNODATA = MAKE_DDHRESULT(2906), 72 | D3DXERR_DUPLICATENAMEDFRAGMENT = MAKE_DDHRESULT(2907), 73 | D3DXERR_CANNOTREMOVELASTITEM = MAKE_DDHRESULT(2908), 74 | }; 75 | 76 | 77 | #endif //__D3DX9_H__ 78 | 79 | -------------------------------------------------------------------------------- /plugins/sdk/d3d9/d3dx9.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/plugins/sdk/d3d9/d3dx9.lib -------------------------------------------------------------------------------- /plugins/sdk/d3d9/d3dx9d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/plugins/sdk/d3d9/d3dx9d.lib -------------------------------------------------------------------------------- /plugins/sdk/d3d9/d3dx9shape.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9shapes.h 6 | // Content: D3DX simple shapes 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "d3dx9.h" 11 | 12 | #ifndef __D3DX9SHAPES_H__ 13 | #define __D3DX9SHAPES_H__ 14 | 15 | /////////////////////////////////////////////////////////////////////////// 16 | // Functions: 17 | /////////////////////////////////////////////////////////////////////////// 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif //__cplusplus 22 | 23 | 24 | //------------------------------------------------------------------------- 25 | // D3DXCreatePolygon: 26 | // ------------------ 27 | // Creates a mesh containing an n-sided polygon. The polygon is centered 28 | // at the origin. 29 | // 30 | // Parameters: 31 | // 32 | // pDevice The D3D device with which the mesh is going to be used. 33 | // Length Length of each side. 34 | // Sides Number of sides the polygon has. (Must be >= 3) 35 | // ppMesh The mesh object which will be created 36 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 37 | //------------------------------------------------------------------------- 38 | HRESULT WINAPI 39 | D3DXCreatePolygon( 40 | LPDIRECT3DDEVICE9 pDevice, 41 | FLOAT Length, 42 | UINT Sides, 43 | LPD3DXMESH* ppMesh, 44 | LPD3DXBUFFER* ppAdjacency); 45 | 46 | 47 | //------------------------------------------------------------------------- 48 | // D3DXCreateBox: 49 | // -------------- 50 | // Creates a mesh containing an axis-aligned box. The box is centered at 51 | // the origin. 52 | // 53 | // Parameters: 54 | // 55 | // pDevice The D3D device with which the mesh is going to be used. 56 | // Width Width of box (along X-axis) 57 | // Height Height of box (along Y-axis) 58 | // Depth Depth of box (along Z-axis) 59 | // ppMesh The mesh object which will be created 60 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 61 | //------------------------------------------------------------------------- 62 | HRESULT WINAPI 63 | D3DXCreateBox( 64 | LPDIRECT3DDEVICE9 pDevice, 65 | FLOAT Width, 66 | FLOAT Height, 67 | FLOAT Depth, 68 | LPD3DXMESH* ppMesh, 69 | LPD3DXBUFFER* ppAdjacency); 70 | 71 | 72 | //------------------------------------------------------------------------- 73 | // D3DXCreateCylinder: 74 | // ------------------- 75 | // Creates a mesh containing a cylinder. The generated cylinder is 76 | // centered at the origin, and its axis is aligned with the Z-axis. 77 | // 78 | // Parameters: 79 | // 80 | // pDevice The D3D device with which the mesh is going to be used. 81 | // Radius1 Radius at -Z end (should be >= 0.0f) 82 | // Radius2 Radius at +Z end (should be >= 0.0f) 83 | // Length Length of cylinder (along Z-axis) 84 | // Slices Number of slices about the main axis 85 | // Stacks Number of stacks along the main axis 86 | // ppMesh The mesh object which will be created 87 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 88 | //------------------------------------------------------------------------- 89 | HRESULT WINAPI 90 | D3DXCreateCylinder( 91 | LPDIRECT3DDEVICE9 pDevice, 92 | FLOAT Radius1, 93 | FLOAT Radius2, 94 | FLOAT Length, 95 | UINT Slices, 96 | UINT Stacks, 97 | LPD3DXMESH* ppMesh, 98 | LPD3DXBUFFER* ppAdjacency); 99 | 100 | 101 | //------------------------------------------------------------------------- 102 | // D3DXCreateSphere: 103 | // ----------------- 104 | // Creates a mesh containing a sphere. The sphere is centered at the 105 | // origin. 106 | // 107 | // Parameters: 108 | // 109 | // pDevice The D3D device with which the mesh is going to be used. 110 | // Radius Radius of the sphere (should be >= 0.0f) 111 | // Slices Number of slices about the main axis 112 | // Stacks Number of stacks along the main axis 113 | // ppMesh The mesh object which will be created 114 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 115 | //------------------------------------------------------------------------- 116 | HRESULT WINAPI 117 | D3DXCreateSphere( 118 | LPDIRECT3DDEVICE9 pDevice, 119 | FLOAT Radius, 120 | UINT Slices, 121 | UINT Stacks, 122 | LPD3DXMESH* ppMesh, 123 | LPD3DXBUFFER* ppAdjacency); 124 | 125 | 126 | //------------------------------------------------------------------------- 127 | // D3DXCreateTorus: 128 | // ---------------- 129 | // Creates a mesh containing a torus. The generated torus is centered at 130 | // the origin, and its axis is aligned with the Z-axis. 131 | // 132 | // Parameters: 133 | // 134 | // pDevice The D3D device with which the mesh is going to be used. 135 | // InnerRadius Inner radius of the torus (should be >= 0.0f) 136 | // OuterRadius Outer radius of the torue (should be >= 0.0f) 137 | // Sides Number of sides in a cross-section (must be >= 3) 138 | // Rings Number of rings making up the torus (must be >= 3) 139 | // ppMesh The mesh object which will be created 140 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 141 | //------------------------------------------------------------------------- 142 | HRESULT WINAPI 143 | D3DXCreateTorus( 144 | LPDIRECT3DDEVICE9 pDevice, 145 | FLOAT InnerRadius, 146 | FLOAT OuterRadius, 147 | UINT Sides, 148 | UINT Rings, 149 | LPD3DXMESH* ppMesh, 150 | LPD3DXBUFFER* ppAdjacency); 151 | 152 | 153 | //------------------------------------------------------------------------- 154 | // D3DXCreateTeapot: 155 | // ----------------- 156 | // Creates a mesh containing a teapot. 157 | // 158 | // Parameters: 159 | // 160 | // pDevice The D3D device with which the mesh is going to be used. 161 | // ppMesh The mesh object which will be created 162 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 163 | //------------------------------------------------------------------------- 164 | HRESULT WINAPI 165 | D3DXCreateTeapot( 166 | LPDIRECT3DDEVICE9 pDevice, 167 | LPD3DXMESH* ppMesh, 168 | LPD3DXBUFFER* ppAdjacency); 169 | 170 | 171 | //------------------------------------------------------------------------- 172 | // D3DXCreateText: 173 | // --------------- 174 | // Creates a mesh containing the specified text using the font associated 175 | // with the device context. 176 | // 177 | // Parameters: 178 | // 179 | // pDevice The D3D device with which the mesh is going to be used. 180 | // hDC Device context, with desired font selected 181 | // pText Text to generate 182 | // Deviation Maximum chordal deviation from true font outlines 183 | // Extrusion Amount to extrude text in -Z direction 184 | // ppMesh The mesh object which will be created 185 | // pGlyphMetrics Address of buffer to receive glyph metric data (or NULL) 186 | //------------------------------------------------------------------------- 187 | HRESULT WINAPI 188 | D3DXCreateTextA( 189 | LPDIRECT3DDEVICE9 pDevice, 190 | HDC hDC, 191 | LPCSTR pText, 192 | FLOAT Deviation, 193 | FLOAT Extrusion, 194 | LPD3DXMESH* ppMesh, 195 | LPD3DXBUFFER* ppAdjacency, 196 | LPGLYPHMETRICSFLOAT pGlyphMetrics); 197 | 198 | HRESULT WINAPI 199 | D3DXCreateTextW( 200 | LPDIRECT3DDEVICE9 pDevice, 201 | HDC hDC, 202 | LPCWSTR pText, 203 | FLOAT Deviation, 204 | FLOAT Extrusion, 205 | LPD3DXMESH* ppMesh, 206 | LPD3DXBUFFER* ppAdjacency, 207 | LPGLYPHMETRICSFLOAT pGlyphMetrics); 208 | 209 | #ifdef UNICODE 210 | #define D3DXCreateText D3DXCreateTextW 211 | #else 212 | #define D3DXCreateText D3DXCreateTextA 213 | #endif 214 | 215 | 216 | #ifdef __cplusplus 217 | } 218 | #endif //__cplusplus 219 | 220 | #endif //__D3DX9SHAPES_H__ 221 | 222 | -------------------------------------------------------------------------------- /plugins/sdk/d3d9/d3dx9xof.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9xof.h 6 | // Content: D3DX .X File types and functions 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "d3dx9.h" 11 | 12 | #if !defined( __D3DX9XOF_H__ ) 13 | #define __D3DX9XOF_H__ 14 | 15 | #if defined( __cplusplus ) 16 | extern "C" { 17 | #endif // defined( __cplusplus ) 18 | 19 | //---------------------------------------------------------------------------- 20 | // D3DXF_FILEFORMAT 21 | // This flag is used to specify what file type to use when saving to disk. 22 | // _BINARY, and _TEXT are mutually exclusive, while 23 | // _COMPRESSED is an optional setting that works with all file types. 24 | //---------------------------------------------------------------------------- 25 | typedef DWORD D3DXF_FILEFORMAT; 26 | 27 | #define D3DXF_FILEFORMAT_BINARY 0 28 | #define D3DXF_FILEFORMAT_TEXT 1 29 | #define D3DXF_FILEFORMAT_COMPRESSED 2 30 | 31 | //---------------------------------------------------------------------------- 32 | // D3DXF_FILESAVEOPTIONS 33 | // This flag is used to specify where to save the file to. Each flag is 34 | // mutually exclusive, indicates the data location of the file, and also 35 | // chooses which additional data will specify the location. 36 | // _TOFILE is paired with a filename (LPCSTR) 37 | // _TOWFILE is paired with a filename (LPWSTR) 38 | //---------------------------------------------------------------------------- 39 | typedef DWORD D3DXF_FILESAVEOPTIONS; 40 | 41 | #define D3DXF_FILESAVE_TOFILE 0x00L 42 | #define D3DXF_FILESAVE_TOWFILE 0x01L 43 | 44 | //---------------------------------------------------------------------------- 45 | // D3DXF_FILELOADOPTIONS 46 | // This flag is used to specify where to load the file from. Each flag is 47 | // mutually exclusive, indicates the data location of the file, and also 48 | // chooses which additional data will specify the location. 49 | // _FROMFILE is paired with a filename (LPCSTR) 50 | // _FROMWFILE is paired with a filename (LPWSTR) 51 | // _FROMRESOURCE is paired with a (D3DXF_FILELOADRESOUCE*) description. 52 | // _FROMMEMORY is paired with a (D3DXF_FILELOADMEMORY*) description. 53 | //---------------------------------------------------------------------------- 54 | typedef DWORD D3DXF_FILELOADOPTIONS; 55 | 56 | #define D3DXF_FILELOAD_FROMFILE 0x00L 57 | #define D3DXF_FILELOAD_FROMWFILE 0x01L 58 | #define D3DXF_FILELOAD_FROMRESOURCE 0x02L 59 | #define D3DXF_FILELOAD_FROMMEMORY 0x03L 60 | 61 | //---------------------------------------------------------------------------- 62 | // D3DXF_FILELOADRESOURCE: 63 | //---------------------------------------------------------------------------- 64 | 65 | typedef struct _D3DXF_FILELOADRESOURCE 66 | { 67 | HMODULE hModule; // Desc 68 | LPCSTR lpName; // Desc 69 | LPCSTR lpType; // Desc 70 | } D3DXF_FILELOADRESOURCE; 71 | 72 | //---------------------------------------------------------------------------- 73 | // D3DXF_FILELOADMEMORY: 74 | //---------------------------------------------------------------------------- 75 | 76 | typedef struct _D3DXF_FILELOADMEMORY 77 | { 78 | LPCVOID lpMemory; // Desc 79 | SIZE_T dSize; // Desc 80 | } D3DXF_FILELOADMEMORY; 81 | 82 | #if defined( _WIN32 ) && !defined( _NO_COM ) 83 | 84 | // {cef08cf9-7b4f-4429-9624-2a690a933201} 85 | DEFINE_GUID( IID_ID3DXFile, 86 | 0xcef08cf9, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 87 | 88 | // {cef08cfa-7b4f-4429-9624-2a690a933201} 89 | DEFINE_GUID( IID_ID3DXFileSaveObject, 90 | 0xcef08cfa, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 91 | 92 | // {cef08cfb-7b4f-4429-9624-2a690a933201} 93 | DEFINE_GUID( IID_ID3DXFileSaveData, 94 | 0xcef08cfb, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 95 | 96 | // {cef08cfc-7b4f-4429-9624-2a690a933201} 97 | DEFINE_GUID( IID_ID3DXFileEnumObject, 98 | 0xcef08cfc, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 99 | 100 | // {cef08cfd-7b4f-4429-9624-2a690a933201} 101 | DEFINE_GUID( IID_ID3DXFileData, 102 | 0xcef08cfd, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 103 | 104 | #endif // defined( _WIN32 ) && !defined( _NO_COM ) 105 | 106 | #if defined( __cplusplus ) 107 | #if !defined( DECLSPEC_UUID ) 108 | #if _MSC_VER >= 1100 109 | #define DECLSPEC_UUID( x ) __declspec( uuid( x ) ) 110 | #else // !( _MSC_VER >= 1100 ) 111 | #define DECLSPEC_UUID( x ) 112 | #endif // !( _MSC_VER >= 1100 ) 113 | #endif // !defined( DECLSPEC_UUID ) 114 | 115 | interface DECLSPEC_UUID( "cef08cf9-7b4f-4429-9624-2a690a933201" ) 116 | ID3DXFile; 117 | interface DECLSPEC_UUID( "cef08cfa-7b4f-4429-9624-2a690a933201" ) 118 | ID3DXFileSaveObject; 119 | interface DECLSPEC_UUID( "cef08cfb-7b4f-4429-9624-2a690a933201" ) 120 | ID3DXFileSaveData; 121 | interface DECLSPEC_UUID( "cef08cfc-7b4f-4429-9624-2a690a933201" ) 122 | ID3DXFileEnumObject; 123 | interface DECLSPEC_UUID( "cef08cfd-7b4f-4429-9624-2a690a933201" ) 124 | ID3DXFileData; 125 | 126 | #if defined( _COM_SMARTPTR_TYPEDEF ) 127 | _COM_SMARTPTR_TYPEDEF( ID3DXFile, 128 | __uuidof( ID3DXFile ) ); 129 | _COM_SMARTPTR_TYPEDEF( ID3DXFileSaveObject, 130 | __uuidof( ID3DXFileSaveObject ) ); 131 | _COM_SMARTPTR_TYPEDEF( ID3DXFileSaveData, 132 | __uuidof( ID3DXFileSaveData ) ); 133 | _COM_SMARTPTR_TYPEDEF( ID3DXFileEnumObject, 134 | __uuidof( ID3DXFileEnumObject ) ); 135 | _COM_SMARTPTR_TYPEDEF( ID3DXFileData, 136 | __uuidof( ID3DXFileData ) ); 137 | #endif // defined( _COM_SMARTPTR_TYPEDEF ) 138 | #endif // defined( __cplusplus ) 139 | 140 | typedef interface ID3DXFile ID3DXFile; 141 | typedef interface ID3DXFileSaveObject ID3DXFileSaveObject; 142 | typedef interface ID3DXFileSaveData ID3DXFileSaveData; 143 | typedef interface ID3DXFileEnumObject ID3DXFileEnumObject; 144 | typedef interface ID3DXFileData ID3DXFileData; 145 | 146 | ////////////////////////////////////////////////////////////////////////////// 147 | // ID3DXFile ///////////////////////////////////////////////////////////////// 148 | ////////////////////////////////////////////////////////////////////////////// 149 | 150 | #undef INTERFACE 151 | #define INTERFACE ID3DXFile 152 | 153 | DECLARE_INTERFACE_( ID3DXFile, IUnknown ) 154 | { 155 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 156 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 157 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 158 | 159 | STDMETHOD( CreateEnumObject )( THIS_ LPCVOID, D3DXF_FILELOADOPTIONS, 160 | ID3DXFileEnumObject** ) PURE; 161 | STDMETHOD( CreateSaveObject )( THIS_ LPCVOID, D3DXF_FILESAVEOPTIONS, 162 | D3DXF_FILEFORMAT, ID3DXFileSaveObject** ) PURE; 163 | STDMETHOD( RegisterTemplates )( THIS_ LPCVOID, SIZE_T ) PURE; 164 | STDMETHOD( RegisterEnumTemplates )( THIS_ ID3DXFileEnumObject* ) PURE; 165 | }; 166 | 167 | ////////////////////////////////////////////////////////////////////////////// 168 | // ID3DXFileSaveObject /////////////////////////////////////////////////////// 169 | ////////////////////////////////////////////////////////////////////////////// 170 | 171 | #undef INTERFACE 172 | #define INTERFACE ID3DXFileSaveObject 173 | 174 | DECLARE_INTERFACE_( ID3DXFileSaveObject, IUnknown ) 175 | { 176 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 177 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 178 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 179 | 180 | STDMETHOD( GetFile )( THIS_ ID3DXFile** ) PURE; 181 | STDMETHOD( AddDataObject )( THIS_ REFGUID, LPCSTR, CONST GUID*, 182 | SIZE_T, LPCVOID, ID3DXFileSaveData** ) PURE; 183 | STDMETHOD( Save )( THIS ) PURE; 184 | }; 185 | 186 | ////////////////////////////////////////////////////////////////////////////// 187 | // ID3DXFileSaveData ///////////////////////////////////////////////////////// 188 | ////////////////////////////////////////////////////////////////////////////// 189 | 190 | #undef INTERFACE 191 | #define INTERFACE ID3DXFileSaveData 192 | 193 | DECLARE_INTERFACE_( ID3DXFileSaveData, IUnknown ) 194 | { 195 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 196 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 197 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 198 | 199 | STDMETHOD( GetSave )( THIS_ ID3DXFileSaveObject** ) PURE; 200 | STDMETHOD( GetName )( THIS_ LPSTR, SIZE_T* ) PURE; 201 | STDMETHOD( GetId )( THIS_ LPGUID ) PURE; 202 | STDMETHOD( GetType )( THIS_ GUID* ) PURE; 203 | STDMETHOD( AddDataObject )( THIS_ REFGUID, LPCSTR, CONST GUID*, 204 | SIZE_T, LPCVOID, ID3DXFileSaveData** ) PURE; 205 | STDMETHOD( AddDataReference )( THIS_ LPCSTR, CONST GUID* ) PURE; 206 | }; 207 | 208 | ////////////////////////////////////////////////////////////////////////////// 209 | // ID3DXFileEnumObject /////////////////////////////////////////////////////// 210 | ////////////////////////////////////////////////////////////////////////////// 211 | 212 | #undef INTERFACE 213 | #define INTERFACE ID3DXFileEnumObject 214 | 215 | DECLARE_INTERFACE_( ID3DXFileEnumObject, IUnknown ) 216 | { 217 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 218 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 219 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 220 | 221 | STDMETHOD( GetFile )( THIS_ ID3DXFile** ) PURE; 222 | STDMETHOD( GetChildren )( THIS_ SIZE_T* ) PURE; 223 | STDMETHOD( GetChild )( THIS_ SIZE_T, ID3DXFileData** ) PURE; 224 | STDMETHOD( GetDataObjectById )( THIS_ REFGUID, ID3DXFileData** ) PURE; 225 | STDMETHOD( GetDataObjectByName )( THIS_ LPCSTR, ID3DXFileData** ) PURE; 226 | }; 227 | 228 | ////////////////////////////////////////////////////////////////////////////// 229 | // ID3DXFileData ///////////////////////////////////////////////////////////// 230 | ////////////////////////////////////////////////////////////////////////////// 231 | 232 | #undef INTERFACE 233 | #define INTERFACE ID3DXFileData 234 | 235 | DECLARE_INTERFACE_( ID3DXFileData, IUnknown ) 236 | { 237 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 238 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 239 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 240 | 241 | STDMETHOD( GetEnum )( THIS_ ID3DXFileEnumObject** ) PURE; 242 | STDMETHOD( GetName )( THIS_ LPSTR, SIZE_T* ) PURE; 243 | STDMETHOD( GetId )( THIS_ LPGUID ) PURE; 244 | STDMETHOD( Lock )( THIS_ SIZE_T*, LPCVOID* ) PURE; 245 | STDMETHOD( Unlock )( THIS ) PURE; 246 | STDMETHOD( GetType )( THIS_ GUID* ) PURE; 247 | STDMETHOD_( BOOL, IsReference )( THIS ) PURE; 248 | STDMETHOD( GetChildren )( THIS_ SIZE_T* ) PURE; 249 | STDMETHOD( GetChild )( THIS_ SIZE_T, ID3DXFileData** ) PURE; 250 | }; 251 | 252 | STDAPI D3DXFileCreate( ID3DXFile** lplpDirectXFile ); 253 | 254 | /* 255 | * DirectX File errors. 256 | */ 257 | 258 | #define _FACD3DXF 0x876 259 | 260 | #define D3DXFERR_BADOBJECT MAKE_HRESULT( 1, _FACD3DXF, 900 ) 261 | #define D3DXFERR_BADVALUE MAKE_HRESULT( 1, _FACD3DXF, 901 ) 262 | #define D3DXFERR_BADTYPE MAKE_HRESULT( 1, _FACD3DXF, 902 ) 263 | #define D3DXFERR_NOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 903 ) 264 | #define D3DXFERR_NOTDONEYET MAKE_HRESULT( 1, _FACD3DXF, 904 ) 265 | #define D3DXFERR_FILENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 905 ) 266 | #define D3DXFERR_RESOURCENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 906 ) 267 | #define D3DXFERR_BADRESOURCE MAKE_HRESULT( 1, _FACD3DXF, 907 ) 268 | #define D3DXFERR_BADFILETYPE MAKE_HRESULT( 1, _FACD3DXF, 908 ) 269 | #define D3DXFERR_BADFILEVERSION MAKE_HRESULT( 1, _FACD3DXF, 909 ) 270 | #define D3DXFERR_BADFILEFLOATSIZE MAKE_HRESULT( 1, _FACD3DXF, 910 ) 271 | #define D3DXFERR_BADFILE MAKE_HRESULT( 1, _FACD3DXF, 911 ) 272 | #define D3DXFERR_PARSEERROR MAKE_HRESULT( 1, _FACD3DXF, 912 ) 273 | #define D3DXFERR_BADARRAYSIZE MAKE_HRESULT( 1, _FACD3DXF, 913 ) 274 | #define D3DXFERR_BADDATAREFERENCE MAKE_HRESULT( 1, _FACD3DXF, 914 ) 275 | #define D3DXFERR_NOMOREOBJECTS MAKE_HRESULT( 1, _FACD3DXF, 915 ) 276 | #define D3DXFERR_NOMOREDATA MAKE_HRESULT( 1, _FACD3DXF, 916 ) 277 | #define D3DXFERR_BADCACHEFILE MAKE_HRESULT( 1, _FACD3DXF, 917 ) 278 | 279 | /* 280 | * DirectX File object types. 281 | */ 282 | 283 | #ifndef WIN_TYPES 284 | #define WIN_TYPES(itype, ptype) typedef interface itype *LP##ptype, **LPLP##ptype 285 | #endif 286 | 287 | WIN_TYPES(ID3DXFile, D3DXFILE); 288 | WIN_TYPES(ID3DXFileEnumObject, D3DXFILEENUMOBJECT); 289 | WIN_TYPES(ID3DXFileSaveObject, D3DXFILESAVEOBJECT); 290 | WIN_TYPES(ID3DXFileData, D3DXFILEDATA); 291 | WIN_TYPES(ID3DXFileSaveData, D3DXFILESAVEDATA); 292 | 293 | #if defined( __cplusplus ) 294 | } // extern "C" 295 | #endif // defined( __cplusplus ) 296 | 297 | #endif // !defined( __D3DX9XOF_H__ ) 298 | 299 | 300 | -------------------------------------------------------------------------------- /plugins/sdk/d3d9/dinput8.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/plugins/sdk/d3d9/dinput8.lib -------------------------------------------------------------------------------- /plugins/sdk/d3d9/dxgi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/plugins/sdk/d3d9/dxgi.lib -------------------------------------------------------------------------------- /plugins/sdk/d3d9/dxguid.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/plugins/sdk/d3d9/dxguid.lib -------------------------------------------------------------------------------- /rMod.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/rMod.dll -------------------------------------------------------------------------------- /rMod.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/rMod.exe -------------------------------------------------------------------------------- /resources/legal_rmod.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KoA-rMod/rMod/95b4312fc3d76ad1cd49d1423aeb772969bda417/resources/legal_rmod.dds -------------------------------------------------------------------------------- /scripts/default.txt: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # .____ ____, .___, 4 | # .______| \/ | | | 5 | # | | |_______.____| | 6 | # | .__| | _ | __ | 7 | # | | | | |_| | |__| | 8 | # |___| |___|__|___|_______|________| 9 | # 10 | # Kingdoms of Amalur: Reckoning (rMod) 11 | # 12 | #################################################################################################### 13 | # Default Script 14 | # 15 | # This script is loaded when the game is first launched and begins rendering. 16 | # You can use this script to help configure rMod to your desired setup. 17 | # Addons and plugins can be automatically loaded by adding them here. 18 | # 19 | # Commands start with: / 20 | # Comments start with: # or // 21 | #################################################################################################### 22 | 23 | #################################################################################################### 24 | # Autoload Plugins 25 | # 26 | # Add plugins here that you wish to have automatically load at the start of the game when rMod 27 | # is first injected. This can be useful for any plugins that need to be loaded as soon as possible. 28 | # 29 | # You can load plugins here using the /load command such as: 30 | # /load addons 31 | #################################################################################################### 32 | 33 | /load addons 34 | 35 | #################################################################################################### 36 | # Autoload Addons 37 | # 38 | # Add addons here that you wish to have automatically load at the start of the game when rMod 39 | # is first injected. This can be useful for any addons that need to be loaded as soon as possible. 40 | # 41 | # You can load addons here using the /addon load command such as: 42 | # /addon load expmon 43 | # 44 | # You must load the addons plugin above first before you can load addons here! 45 | #################################################################################################### 46 | 47 | #################################################################################################### 48 | # Set Keybinds 49 | # 50 | # Set any key binds here that you wish to use and have automatically setup for you each time the 51 | # game is started. Keybinds can have modifier keys as follows: 52 | # 53 | # ! = Alt Key 54 | # # = Apps Key 55 | # ^ = Control Key 56 | # + = Shift Key 57 | # @ = Windows Key 58 | # 59 | # Key binds are based on Windows virtual key codes. You can find a full list of them here: 60 | # https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx 61 | # 62 | # Key names are internally stored as their VK_ name with the VK_ part removed. For example: 63 | # VK_OEM_3 - 0xC0 - For the US standard keyboard, the '`~' key 64 | # 65 | # To bind this key, use: OEM_3 66 | #################################################################################################### 67 | 68 | /bind OEM_3 /toggleconsole --------------------------------------------------------------------------------