├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── Android.mk ├── Application.mk ├── LICENSE ├── build.ps1 ├── main.cpp ├── ndkpath.txt └── thirdparty └── inipp.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: AML Mod Compiler 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | 14 | - name: Checkout repository... 15 | uses: actions/checkout@v3 16 | 17 | - name: Download AndroidModLoader`s mod template... 18 | uses: wei/wget@v1 19 | with: 20 | args: -O ./AML_src.zip https://github.com/RusJJ/AndroidModLoader/archive/refs/heads/main.zip 21 | 22 | - name: Install AndroidModLoader`s mod template... 23 | run: | 24 | unzip ./AML_src.zip 25 | mv ./AndroidModLoader-main/mod ./mod 26 | 27 | - name: Get CLEOMod... 28 | uses: wei/wget@v1 29 | with: 30 | args: -O ./cleo.h https://github.com/AndroidModLoader/GTA_CLEOMod/raw/RUSJJ_CLEO_MOD/cleo.h 31 | 32 | - name: Get CLEOMod - Addon Interface... 33 | uses: wei/wget@v1 34 | with: 35 | args: -O ./cleoaddon.h https://github.com/AndroidModLoader/GTA_CLEOMod/raw/RUSJJ_CLEO_MOD/cleoaddon.h 36 | 37 | - name: Install Android NDK (r24)... 38 | uses: nttld/setup-ndk@v1.2.0 39 | with: 40 | ndk-version: r24 41 | local-cache: true 42 | 43 | - name: Build the code... 44 | run: ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk 45 | 46 | - name: Upload the mod! 47 | uses: actions/upload-artifact@v3 48 | with: 49 | name: compiled-mod.zip 50 | path: ./libs 51 | -------------------------------------------------------------------------------- /.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/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | 400 | # Own 401 | mod/ 402 | libs/ 403 | *.bak 404 | build.ps1 405 | ndkpath.txt 406 | GTASA_ENUMS.h 407 | GTASA_STRUCTS.h 408 | RW_STRUCTS.h 409 | .vscode/settings.json 410 | cleo.h 411 | cleoaddon.h 412 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_CPP_EXTENSION := .cpp .cc 5 | LOCAL_MODULE := CLEO_IniFiles 6 | LOCAL_SRC_FILES := main.cpp mod/logger.cpp 7 | LOCAL_CFLAGS += -O2 -mfloat-abi=softfp -DNDEBUG -std=c++17 8 | LOCAL_C_INCLUDES += ./include 9 | LOCAL_LDLIBS += -llog # ARM64 library requires it so... 10 | include $(BUILD_SHARED_LIBRARY) -------------------------------------------------------------------------------- /Application.mk: -------------------------------------------------------------------------------- 1 | APP_STL := c++_static 2 | APP_ABI := armeabi-v7a 3 | APP_OPTIM := release -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 RusJJ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | $NDKPath = Get-Content $PSScriptRoot/NDKPath.txt 2 | Write-Output "NDK located at: $NDKPath" 3 | 4 | $buildScript = "$NDKPath/build/ndk-build" 5 | if (-not ($PSVersionTable.PSEdition -eq "Core")) { 6 | $buildScript += ".cmd" 7 | } 8 | 9 | Write-Output "[BUILD] Starting NDK..." 10 | & $buildScript NDK_PROJECT_PATH=$PSScriptRoot APP_BUILD_SCRIPT=$PSScriptRoot/Android.mk NDK_APPLICATION_MK=$PSScriptRoot/Application.mk NDK_DEBUG=0 11 | Write-Output "[BUILD] Done!" 12 | 13 | Exit $LASTEXITCODE -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "thirdparty/inipp.h" 9 | 10 | #include "cleo.h" 11 | cleo_ifs_t* cleo = nullptr; 12 | 13 | #include "cleoaddon.h" 14 | cleo_addon_ifs_t* cleoaddon = nullptr; 15 | 16 | inline void CreateDirs(std::string root, const char* filename_with_dir) 17 | { 18 | std::string sFileDir = std::string(filename_with_dir); 19 | size_t found = sFileDir.find_last_of("/"); 20 | if(found < 0) return; // Is not in any directories 21 | 22 | sFileDir = sFileDir.substr(0, found); 23 | std::string baseroot = root; 24 | DIR* dir = opendir((root + sFileDir).c_str()); 25 | if(!dir) 26 | { 27 | char only_file_path[128]; 28 | snprintf(only_file_path, sizeof(only_file_path), "%s", sFileDir.c_str()); 29 | 30 | char* pch = strtok(only_file_path, "/"); 31 | if(pch) 32 | { 33 | while(pch != NULL) 34 | { 35 | baseroot += pch; 36 | baseroot += '/'; 37 | 38 | mkdir(baseroot.c_str(), 0777); 39 | pch = strtok(NULL, "/"); 40 | } 41 | } 42 | else 43 | { 44 | mkdir(baseroot.c_str(), 0777); 45 | } 46 | } 47 | else 48 | { 49 | closedir(dir); 50 | } 51 | } 52 | 53 | MYMOD(net.alexblade.rusjj.inifiles, CLEO4 IniFiles, 1.3, Alexander Blade & RusJJ) 54 | BEGIN_DEPLIST() 55 | ADD_DEPENDENCY_VER(net.rusjj.cleolib, 2.0.1.6) 56 | END_DEPLIST() 57 | 58 | #define CLEO_RegisterOpcode(x, h) cleo->RegisterOpcode(x, h); cleo->RegisterOpcodeFunction(#h, h) 59 | #define CLEO_Fn(h) void h (void *handle, uint32_t *ip, uint16_t opcode, const char *name) 60 | 61 | std::string sGameFilesRoot; 62 | static char szConvertedValue[16]; 63 | 64 | CLEO_Fn(READ_INT_FROM_INI_FILE) 65 | { 66 | inipp::Ini ini; 67 | char filename[128], section[64], key[64]; 68 | int result = 0, i = 0; 69 | cleoaddon->ReadString(handle, filename, sizeof(filename)); filename[sizeof(filename)-1] = 0; 70 | cleoaddon->ReadString(handle, section, sizeof(section)); section[sizeof(section)-1] = 0; 71 | cleoaddon->ReadString(handle, key, sizeof(key)); key[sizeof(key)-1] = 0; 72 | while(filename[i] != 0) // A little hack 73 | { 74 | if(filename[i] == '\\') filename[i] = '/'; 75 | ++i; 76 | } 77 | 78 | // Create dir if not exists? start 79 | CreateDirs(sGameFilesRoot, filename); 80 | // Create dir if not exists? end 81 | 82 | std::ifstream is((sGameFilesRoot + filename).c_str()); 83 | bool didReadValue = false; 84 | if(is.is_open()) 85 | { 86 | ini.parse(is); 87 | didReadValue = inipp::get_value(ini.sections[section], key, result); 88 | is.close(); 89 | } 90 | cleo->GetPointerToScriptVar(handle)->i = result; 91 | cleoaddon->UpdateCompareFlag(handle, didReadValue); 92 | ini.clear(); 93 | } 94 | 95 | CLEO_Fn(WRITE_INT_TO_INI_FILE) 96 | { 97 | inipp::Ini ini; 98 | char filename[128], section[64], key[64]; 99 | int i = 0, value = cleo->ReadParam(handle)->i; 100 | cleoaddon->ReadString(handle, filename, sizeof(filename)); filename[sizeof(filename)-1] = 0; 101 | cleoaddon->ReadString(handle, section, sizeof(section)); section[sizeof(section)-1] = 0; 102 | cleoaddon->ReadString(handle, key, sizeof(key)); key[sizeof(key)-1] = 0; 103 | while(filename[i] != 0) // A little hack 104 | { 105 | if(filename[i] == '\\') filename[i] = '/'; 106 | ++i; 107 | } 108 | 109 | // Create dir if not exists? start 110 | CreateDirs(sGameFilesRoot, filename); 111 | // Create dir if not exists? end 112 | 113 | std::ifstream is((sGameFilesRoot + filename).c_str()); 114 | if(is.is_open()) 115 | { 116 | ini.parse(is); 117 | is.close(); 118 | } 119 | else ini.clear(); 120 | 121 | sprintf(szConvertedValue, "%d", value); 122 | ini.sections[section][key] = szConvertedValue; 123 | 124 | std::ofstream os((sGameFilesRoot + filename).c_str(), std::ios::trunc); 125 | if(os.is_open()) 126 | { 127 | ini.generate(os); 128 | os.flush(); 129 | os.close(); 130 | } 131 | ini.clear(); 132 | } 133 | 134 | CLEO_Fn(READ_FLOAT_FROM_INI_FILE) 135 | { 136 | inipp::Ini ini; 137 | char filename[128], section[64], key[64]; 138 | float result = 0.0f; int i = 0; 139 | cleoaddon->ReadString(handle, filename, sizeof(filename)); filename[sizeof(filename)-1] = 0; 140 | cleoaddon->ReadString(handle, section, sizeof(section)); section[sizeof(section)-1] = 0; 141 | cleoaddon->ReadString(handle, key, sizeof(key)); key[sizeof(key)-1] = 0; 142 | while(filename[i] != 0) // A little hack 143 | { 144 | if(filename[i] == '\\') filename[i] = '/'; 145 | ++i; 146 | } 147 | 148 | // Create dir if not exists? start 149 | CreateDirs(sGameFilesRoot, filename); 150 | // Create dir if not exists? end 151 | 152 | std::ifstream is((sGameFilesRoot + filename).c_str()); 153 | bool didReadValue = false; 154 | if(is.is_open()) 155 | { 156 | ini.parse(is); 157 | didReadValue = inipp::get_value(ini.sections[section], key, result); 158 | is.close(); 159 | } 160 | cleo->GetPointerToScriptVar(handle)->f = result; 161 | cleoaddon->UpdateCompareFlag(handle, didReadValue); 162 | ini.clear(); 163 | } 164 | 165 | CLEO_Fn(WRITE_FLOAT_TO_INI_FILE) 166 | { 167 | inipp::Ini ini; 168 | char filename[128], section[64], key[64]; 169 | int i = 0; float value = cleo->ReadParam(handle)->f; 170 | cleoaddon->ReadString(handle, filename, sizeof(filename)); filename[sizeof(filename)-1] = 0; 171 | cleoaddon->ReadString(handle, section, sizeof(section)); section[sizeof(section)-1] = 0; 172 | cleoaddon->ReadString(handle, key, sizeof(key)); key[sizeof(key)-1] = 0; 173 | while(filename[i] != 0) // A little hack 174 | { 175 | if(filename[i] == '\\') filename[i] = '/'; 176 | ++i; 177 | } 178 | 179 | // Create dir if not exists? start 180 | CreateDirs(sGameFilesRoot, filename); 181 | // Create dir if not exists? end 182 | 183 | std::ifstream is((sGameFilesRoot + filename).c_str()); 184 | if(is.is_open()) 185 | { 186 | ini.parse(is); 187 | is.close(); 188 | } 189 | else ini.clear(); 190 | 191 | sprintf(szConvertedValue, "%f", value); 192 | ini.sections[section][key] = szConvertedValue; 193 | 194 | std::ofstream os((sGameFilesRoot + filename).c_str(), std::ios::trunc); 195 | if(os.is_open()) 196 | { 197 | ini.generate(os); 198 | os.flush(); 199 | os.close(); 200 | } 201 | ini.clear(); 202 | } 203 | 204 | char valRes[100]; 205 | CLEO_Fn(READ_STRING_FROM_INI_FILE) 206 | { 207 | inipp::Ini ini; 208 | char filename[128], section[64], key[64]; 209 | valRes[0] = 0; int i = 0; 210 | cleoaddon->ReadString(handle, filename, sizeof(filename)); filename[sizeof(filename)-1] = 0; 211 | cleoaddon->ReadString(handle, section, sizeof(section)); section[sizeof(section)-1] = 0; 212 | cleoaddon->ReadString(handle, key, sizeof(key)); key[sizeof(key)-1] = 0; 213 | while(filename[i] != 0) // A little hack 214 | { 215 | if(filename[i] == '\\') filename[i] = '/'; 216 | ++i; 217 | } 218 | 219 | // Create dir if not exists? start 220 | CreateDirs(sGameFilesRoot, filename); 221 | // Create dir if not exists? end 222 | 223 | std::ifstream is((sGameFilesRoot + filename).c_str()); 224 | bool didReadValue = false; 225 | if(is.is_open()) 226 | { 227 | ini.parse(is); 228 | sprintf(valRes, "%s", ini.sections[section][key].c_str()); 229 | didReadValue = (valRes[0] != 0); 230 | is.close(); 231 | } 232 | cleoaddon->WriteString(handle, valRes); 233 | cleoaddon->UpdateCompareFlag(handle, didReadValue); 234 | ini.clear(); 235 | } 236 | 237 | CLEO_Fn(WRITE_STRING_TO_INI_FILE) 238 | { 239 | inipp::Ini ini; 240 | char filename[128], section[64], key[64], value[128] {0}; 241 | int i = 0; 242 | cleoaddon->ReadString(handle, value, sizeof(value)); 243 | cleoaddon->ReadString(handle, filename, sizeof(filename)); filename[sizeof(filename)-1] = 0; 244 | cleoaddon->ReadString(handle, section, sizeof(section)); section[sizeof(section)-1] = 0; 245 | cleoaddon->ReadString(handle, key, sizeof(key)); key[sizeof(key)-1] = 0; 246 | while(filename[i] != 0) // A little hack 247 | { 248 | if(filename[i] == '\\') filename[i] = '/'; 249 | ++i; 250 | } 251 | 252 | // Create dir if not exists? start 253 | CreateDirs(sGameFilesRoot, filename); 254 | // Create dir if not exists? end 255 | 256 | std::ifstream is((sGameFilesRoot + filename).c_str()); 257 | if(is.is_open()) 258 | { 259 | ini.parse(is); 260 | is.close(); 261 | } 262 | else ini.clear(); 263 | 264 | ini.sections[section][key] = value; 265 | 266 | std::ofstream os((sGameFilesRoot + filename).c_str(), std::ios::trunc); 267 | if(os.is_open()) 268 | { 269 | ini.generate(os); 270 | os.flush(); 271 | os.close(); 272 | } 273 | ini.clear(); 274 | } 275 | 276 | extern "C" void OnModLoad() 277 | { 278 | logger->SetTag("[CLEO] IniFiles"); 279 | logger->Info("Starting..."); 280 | if(!(cleo = (cleo_ifs_t*)GetInterface("CLEO"))) 281 | { 282 | logger->Error("Cannot load a mod: CLEO's interface is unknown!"); 283 | return; 284 | } 285 | if(!(cleoaddon = (cleo_addon_ifs_t*)GetInterface("CLEOAddon"))) 286 | { 287 | logger->Error("Cannot load a mod: CLEO's Addon interface is unknown!"); 288 | return; 289 | } 290 | 291 | sGameFilesRoot = aml->GetAndroidDataPath(); 292 | sGameFilesRoot += "/"; 293 | 294 | CLEO_RegisterOpcode(0x0AF0, READ_INT_FROM_INI_FILE); // 0AF0=4,%4d% = read_int_from_ini_file %1s% section %2s% key %3s% 295 | CLEO_RegisterOpcode(0x0AF1, WRITE_INT_TO_INI_FILE); // 0AF1=4,write_int %1d% to_ini_file %2s% section %3s% key %4s% 296 | CLEO_RegisterOpcode(0x0AF2, READ_FLOAT_FROM_INI_FILE); // 0AF2=4,%4d% = read_float_from_ini_file %1s% section %2s% key %3s% 297 | CLEO_RegisterOpcode(0x0AF3, WRITE_FLOAT_TO_INI_FILE); // 0AF3=4,write_float %1d% to_ini_file %2s% section %3s% key %4s% 298 | CLEO_RegisterOpcode(0x0AF4, READ_STRING_FROM_INI_FILE); // 0AF4=4,%4d% = read_string_from_ini_file %1s% section %2s% key %3s% 299 | CLEO_RegisterOpcode(0x0AF5, WRITE_STRING_TO_INI_FILE); // 0AF5=4,write_string %1s% to_ini_file %2s% section %3s% key %4s% 300 | } -------------------------------------------------------------------------------- /ndkpath.txt: -------------------------------------------------------------------------------- 1 | D:\android-ndk -------------------------------------------------------------------------------- /thirdparty/inipp.h: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2017-2020 Matthias C. M. Troffaes 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace inipp { 40 | 41 | namespace detail { 42 | 43 | // trim functions based on http://stackoverflow.com/a/217605 44 | 45 | template 46 | inline void ltrim(std::basic_string & s, const std::locale & loc) { 47 | s.erase(s.begin(), 48 | std::find_if(s.begin(), s.end(), 49 | [&loc](CharT ch) { return !std::isspace(ch, loc); })); 50 | } 51 | 52 | template 53 | inline void rtrim(std::basic_string & s, const std::locale & loc) { 54 | s.erase(std::find_if(s.rbegin(), s.rend(), 55 | [&loc](CharT ch) { return !std::isspace(ch, loc); }).base(), 56 | s.end()); 57 | } 58 | 59 | template 60 | inline void rtrim2(std::basic_string& s, UnaryPredicate pred) { 61 | s.erase(std::find_if(s.begin(), s.end(), pred), s.end()); 62 | } 63 | 64 | // string replacement function based on http://stackoverflow.com/a/3418285 65 | 66 | template 67 | inline bool replace(std::basic_string & str, const std::basic_string & from, const std::basic_string & to) { 68 | auto changed = false; 69 | size_t start_pos = 0; 70 | while ((start_pos = str.find(from, start_pos)) != std::basic_string::npos) { 71 | str.replace(start_pos, from.length(), to); 72 | start_pos += to.length(); 73 | changed = true; 74 | } 75 | return changed; 76 | } 77 | 78 | } // namespace detail 79 | 80 | template 81 | inline bool extract(const std::basic_string & value, T & dst) { 82 | CharT c; 83 | std::basic_istringstream is{ value }; 84 | T result; 85 | if ((is >> std::boolalpha >> result) && !(is >> c)) { 86 | dst = result; 87 | return true; 88 | } 89 | else { 90 | return false; 91 | } 92 | } 93 | 94 | template 95 | inline bool extract(const std::basic_string & value, std::basic_string & dst) { 96 | dst = value; 97 | return true; 98 | } 99 | 100 | template 101 | inline bool get_value(const std::map, std::basic_string> & sec, const std::basic_string & key, T & dst) { 102 | const auto it = sec.find(key); 103 | if (it == sec.end()) return false; 104 | return extract(it->second, dst); 105 | } 106 | 107 | template 108 | inline bool get_value(const std::map, std::basic_string>& sec, const CharT* key, T& dst) { 109 | return get_value(sec, std::basic_string(key), dst); 110 | } 111 | 112 | template 113 | class Format 114 | { 115 | public: 116 | // used for generating 117 | const CharT char_section_start; 118 | const CharT char_section_end; 119 | const CharT char_assign; 120 | const CharT char_comment; 121 | 122 | // used for parsing 123 | virtual bool is_section_start(CharT ch) const { return ch == char_section_start; } 124 | virtual bool is_section_end(CharT ch) const { return ch == char_section_end; } 125 | virtual bool is_assign(CharT ch) const { return ch == char_assign; } 126 | virtual bool is_comment(CharT ch) const { return ch == char_comment; } 127 | 128 | // used for interpolation 129 | const CharT char_interpol; 130 | const CharT char_interpol_start; 131 | const CharT char_interpol_sep; 132 | const CharT char_interpol_end; 133 | 134 | Format(CharT section_start, CharT section_end, CharT assign, CharT comment, CharT interpol, CharT interpol_start, CharT interpol_sep, CharT interpol_end) 135 | : char_section_start(section_start) 136 | , char_section_end(section_end) 137 | , char_assign(assign) 138 | , char_comment(comment) 139 | , char_interpol(interpol) 140 | , char_interpol_start(interpol_start) 141 | , char_interpol_sep(interpol_sep) 142 | , char_interpol_end(interpol_end) {} 143 | 144 | Format() : Format('[', ']', '=', ';', '$', '{', ':', '}') {} 145 | 146 | const std::basic_string local_symbol(const std::basic_string& name) const { 147 | return char_interpol + (char_interpol_start + name + char_interpol_end); 148 | } 149 | 150 | const std::basic_string global_symbol(const std::basic_string& sec_name, const std::basic_string& name) const { 151 | return local_symbol(sec_name + char_interpol_sep + name); 152 | } 153 | }; 154 | 155 | template 156 | class Ini 157 | { 158 | public: 159 | using String = std::basic_string; 160 | using Section = std::map; 161 | using Sections = std::map; 162 | 163 | Sections sections; 164 | std::list errors; 165 | std::shared_ptr> format; 166 | 167 | static const int max_interpolation_depth = 10; 168 | 169 | Ini() : format(std::make_shared>()) {}; 170 | Ini(std::shared_ptr> fmt) : format(fmt) {}; 171 | 172 | void generate(std::basic_ostream& os) const { 173 | for (auto const & sec : sections) { 174 | os << format->char_section_start << sec.first << format->char_section_end << std::endl; 175 | for (auto const & val : sec.second) { 176 | os << val.first << format->char_assign << val.second << std::endl; 177 | } 178 | os << std::endl; 179 | } 180 | } 181 | 182 | void parse(std::basic_istream & is) { 183 | String line; 184 | String section; 185 | const std::locale loc{"C"}; 186 | while (std::getline(is, line)) { 187 | detail::ltrim(line, loc); 188 | detail::rtrim(line, loc); 189 | const auto length = line.length(); 190 | if (length > 0) { 191 | const auto pos = std::find_if(line.begin(), line.end(), [this](CharT ch) { return format->is_assign(ch); }); 192 | const auto & front = line.front(); 193 | if (format->is_comment(front)) { 194 | } 195 | else if (format->is_section_start(front)) { 196 | if (format->is_section_end(line.back())) 197 | section = line.substr(1, length - 2); 198 | else 199 | errors.push_back(line); 200 | } 201 | else if (pos != line.begin() && pos != line.end()) { 202 | String variable(line.begin(), pos); 203 | String value(pos + 1, line.end()); 204 | detail::rtrim(variable, loc); 205 | detail::ltrim(value, loc); 206 | auto & sec = sections[section]; 207 | if (sec.find(variable) == sec.end()) 208 | sec.insert(std::make_pair(variable, value)); 209 | else 210 | errors.push_back(line); 211 | } 212 | else { 213 | errors.push_back(line); 214 | } 215 | } 216 | } 217 | } 218 | 219 | void interpolate() { 220 | int global_iteration = 0; 221 | auto changed = false; 222 | // replace each "${variable}" by "${section:variable}" 223 | for (auto & sec : sections) 224 | replace_symbols(local_symbols(sec.first, sec.second), sec.second); 225 | // replace each "${section:variable}" by its value 226 | do { 227 | changed = false; 228 | const auto syms = global_symbols(); 229 | for (auto & sec : sections) 230 | changed |= replace_symbols(syms, sec.second); 231 | } while (changed && (max_interpolation_depth > global_iteration++)); 232 | } 233 | 234 | void default_section(const Section & sec) { 235 | for (auto & sec2 : sections) 236 | for (const auto & val : sec) 237 | sec2.second.insert(val); 238 | } 239 | 240 | void strip_trailing_comments() { 241 | const std::locale loc{ "C" }; 242 | for (auto & sec : sections) 243 | for (auto & val : sec.second) { 244 | detail::rtrim2(val.second, [this](CharT ch) { return format->is_comment(ch); }); 245 | detail::rtrim(val.second, loc); 246 | } 247 | } 248 | 249 | void clear() { 250 | sections.clear(); 251 | errors.clear(); 252 | } 253 | 254 | private: 255 | using Symbols = std::list>; 256 | 257 | const Symbols local_symbols(const String & sec_name, const Section & sec) const { 258 | Symbols result; 259 | for (const auto & val : sec) 260 | result.push_back(std::make_pair(format->local_symbol(val.first), format->global_symbol(sec_name, val.first))); 261 | return result; 262 | } 263 | 264 | const Symbols global_symbols() const { 265 | Symbols result; 266 | for (const auto & sec : sections) 267 | for (const auto & val : sec.second) 268 | result.push_back( 269 | std::make_pair(format->global_symbol(sec.first, val.first), val.second)); 270 | return result; 271 | } 272 | 273 | bool replace_symbols(const Symbols & syms, Section & sec) const { 274 | auto changed = false; 275 | for (auto & sym : syms) 276 | for (auto & val : sec) 277 | changed |= detail::replace(val.second, sym.first, sym.second); 278 | return changed; 279 | } 280 | }; 281 | 282 | } // namespace inipp 283 | --------------------------------------------------------------------------------