├── .gitattributes ├── .gitignore ├── SC2000X.sln └── SC2000X ├── AssemblyData.cpp ├── AssemblyData.h ├── FileVersion.h ├── Hash.cpp ├── Hash.h ├── Instructions.h ├── Logger.cpp ├── Logger.h ├── Patcher.cpp ├── Patcher.h ├── Registry.cpp ├── Registry.h ├── SC2000X.cpp ├── SC2000X.rc ├── SC2000X.vcxproj ├── SC2000X.vcxproj.filters ├── SC2KRegistry.cpp ├── SC2KRegistry.h ├── SC2KVersion.h ├── icon.ico └── resource.h /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /SC2000X.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SC2000X", "SC2000X\SC2000X.vcxproj", "{834BEA1B-1189-4A35-BEED-AEB13EADE0CD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {834BEA1B-1189-4A35-BEED-AEB13EADE0CD}.Debug|x64.ActiveCfg = Debug|x64 17 | {834BEA1B-1189-4A35-BEED-AEB13EADE0CD}.Debug|x64.Build.0 = Debug|x64 18 | {834BEA1B-1189-4A35-BEED-AEB13EADE0CD}.Debug|x86.ActiveCfg = Debug|Win32 19 | {834BEA1B-1189-4A35-BEED-AEB13EADE0CD}.Debug|x86.Build.0 = Debug|Win32 20 | {834BEA1B-1189-4A35-BEED-AEB13EADE0CD}.Release|x64.ActiveCfg = Release|x64 21 | {834BEA1B-1189-4A35-BEED-AEB13EADE0CD}.Release|x64.Build.0 = Release|x64 22 | {834BEA1B-1189-4A35-BEED-AEB13EADE0CD}.Release|x86.ActiveCfg = Release|Win32 23 | {834BEA1B-1189-4A35-BEED-AEB13EADE0CD}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {915A77AE-CBA3-4728-AD9E-2DB9C312E27A} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SC2000X/AssemblyData.cpp: -------------------------------------------------------------------------------- 1 | #include "AssemblyData.h" 2 | 3 | //Only one function is being patched currently 4 | void AssemblyData::GenerateData(const VersionInfo& vinfo, std::vector& ins) 5 | { 6 | AssemblyData::PatchDialogCrashing(vinfo, ins); 7 | } 8 | 9 | //The issue stems from calling DIALOG_DISPLAY_CALC. If this returns 0, the programmers 10 | //just simply assumed calling GetWindowLong + GetParent would return the correct result 11 | //and fail to null check it. This happens in both DIALOG_CONTROLLER and in "DialogFunc". 12 | //The GetWindowLong + GetParent "backup" never returns a desired result... 13 | void AssemblyData::PatchDialogCrashing(const VersionInfo& vinfo, std::vector& ins) 14 | { 15 | DWORD function_entry = vinfo.offsets->functions.DIALOG_CONTROLLER; 16 | Instructions instructions(function_entry + 0xA); 17 | //Bypasses 2nd arg (UINT) comparison against 0x30/0x110 18 | //This prevents calling DialogFunc which apparently isn't needed to show Save/Load Tile Set 19 | instructions << ByteArray{ 0x75, 0x20 }; //jnz short 0x20 instead of 0x7 bytes 20 | 21 | instructions.relocate(function_entry + 0x6A); 22 | //DIALOG_DISPLAY_CALC does useful things, but there is never a point where 23 | //It fails to make a calculation (0 return), and then GetWindowLong+GetParent 24 | //fixes the issue. If we reach this point, just return. 25 | instructions << ByteArray{ 0xEB, 0xEB }; //jmp to xor eax, eax block 26 | ins.push_back(instructions); 27 | printf("Generated Dialog Crashing Patch\n"); 28 | } -------------------------------------------------------------------------------- /SC2000X/AssemblyData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Instructions.h" 3 | #include "SC2KVersion.h" 4 | 5 | //Currently does NOT use a "DetourMaster" since there is no current need 6 | //to extend the Windows PE. This may change in the future. 7 | class AssemblyData { 8 | public: 9 | static void GenerateData(const VersionInfo&, std::vector&); 10 | private: 11 | static void PatchDialogCrashing(const VersionInfo&, std::vector&); 12 | }; -------------------------------------------------------------------------------- /SC2000X/FileVersion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | typedef DWORD(CALLBACK* GetFileVersionInfoSizeExA2)(DWORD, LPCSTR, LPDWORD); 8 | typedef DWORD(CALLBACK* GetFileVersionInfoExA2)(DWORD, LPCSTR, DWORD, DWORD, LPVOID); 9 | typedef DWORD(CALLBACK* VerQueryValueA2)(LPCVOID, LPCSTR, LPVOID*, PUINT); 10 | 11 | struct FileVersion 12 | { 13 | static bool PrintFileVersionInfo(LPCSTR filename) 14 | { 15 | //This bullshit of not having the static libraries has been going on for too long 16 | HINSTANCE hInst = LoadLibrary("Version.dll"); 17 | if (hInst == NULL) return false; 18 | FARPROC _GetFileVersionInfoSizeExA2Address = GetProcAddress(hInst, "GetFileVersionInfoSizeExA"); 19 | FARPROC _GetFileVersionInfoExA2Address = GetProcAddress(hInst, "GetFileVersionInfoExA"); 20 | FARPROC _VerQueryValueA2Address = GetProcAddress(hInst, "VerQueryValueA"); 21 | if (_GetFileVersionInfoSizeExA2Address == NULL) return false; 22 | if (_GetFileVersionInfoExA2Address == NULL) return false; 23 | if (_VerQueryValueA2Address == NULL) return false; 24 | GetFileVersionInfoSizeExA2 GetFileVersionInfoSizeExA_ = (GetFileVersionInfoSizeExA2)_GetFileVersionInfoSizeExA2Address; 25 | GetFileVersionInfoExA2 GetFileVersionInfoExA_ = (GetFileVersionInfoExA2)_GetFileVersionInfoExA2Address; 26 | VerQueryValueA2 VerQueryValueA_ = (VerQueryValueA2)_VerQueryValueA2Address; 27 | 28 | DWORD flags = FILE_VER_GET_NEUTRAL | FILE_VER_GET_LOCALISED; 29 | DWORD handle = 0; 30 | DWORD size = GetFileVersionInfoSizeExA_(flags, filename, &handle); 31 | if (size == 0) 32 | { 33 | printf("GetFileVersionInfoSizeExA returned a size of 0\n"); 34 | return false; 35 | } 36 | LPVOID pVersionInfo = new BYTE[size]; 37 | if (!GetFileVersionInfoExA_(flags, filename, NULL, size, pVersionInfo)) 38 | { 39 | printf("GetFileVersionInfoExA returned false\n"); 40 | return false; 41 | } 42 | 43 | UINT puLen2; 44 | struct LANGANDCODEPAGE { 45 | WORD wLanguage; 46 | WORD wCodePage; 47 | } *lpTranslate; 48 | 49 | if (!VerQueryValueA_(pVersionInfo, "\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &puLen2)) 50 | { 51 | printf("VerQueryValueA returned false\n"); 52 | return false; 53 | } 54 | 55 | const std::string descriptions[4] = { 56 | "FileVersion", "CompanyName", "FileDescription", "OriginalFilename" 57 | }; 58 | 59 | for (size_t i = 0; i < 4; ++i) 60 | { 61 | UINT puLen; 62 | char buffer[256]; 63 | sprintf_s(buffer, sizeof(buffer), 64 | "\\StringFileInfo\\%04lx%04lx\\%s", 65 | lpTranslate->wLanguage, 66 | lpTranslate->wCodePage, 67 | descriptions[i].c_str()); 68 | LPCSTR lpBuffer; 69 | if (!VerQueryValueA_(pVersionInfo, buffer, (LPVOID*)&lpBuffer, &puLen)) 70 | { 71 | printf("VerQueryValueA returned false\n"); 72 | return false; 73 | } 74 | printf("%s: %s\n", descriptions[i].c_str(), lpBuffer); 75 | } 76 | return true; 77 | } 78 | }; -------------------------------------------------------------------------------- /SC2000X/Hash.cpp: -------------------------------------------------------------------------------- 1 | #include "Hash.h" 2 | #include 3 | //f1ad828513d75004345e3324b3d97e46 4 | bool Hash::GenerateMD5(const std::string& filename, std::string& hash) 5 | { 6 | std::wstring filename_wstring = std::wstring(filename.begin(), filename.end()); 7 | return GenerateMD5(filename_wstring, hash); 8 | } 9 | 10 | bool Hash::GenerateMD5(const std::wstring& filename_wstring, std::string& hash) 11 | { 12 | LPCWSTR filename = filename_wstring.c_str(); 13 | 14 | DWORD cbHash = 16; 15 | HCRYPTHASH hHash = 0; 16 | HCRYPTPROV hProv = 0; 17 | BYTE rgbHash[16]; 18 | CHAR rgbDigits[] = "0123456789abcdef"; 19 | HANDLE hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, 20 | OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); 21 | 22 | if (hFile == INVALID_HANDLE_VALUE) 23 | { 24 | printf("Hash::GenerateMD5 has failed because CreateFileW has an invalid handle.\n"); 25 | return false; 26 | } 27 | 28 | CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); 29 | CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash); 30 | 31 | BOOL bResult = FALSE; 32 | DWORD BUFSIZE = 4096; 33 | BYTE rgbFile[4096]; 34 | DWORD cbRead = 0; 35 | while (bResult = ReadFile(hFile, rgbFile, BUFSIZE, &cbRead, NULL)) 36 | { 37 | if (0 == cbRead) 38 | break; 39 | CryptHashData(hHash, rgbFile, cbRead, 0); 40 | } 41 | 42 | std::string md5_hash = ""; 43 | if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) 44 | { 45 | for (DWORD i = 0; i < cbHash; i++) 46 | { 47 | char buffer[3]; //buffer needs terminating null 48 | sprintf_s(buffer, 3, "%c%c", rgbDigits[rgbHash[i] >> 4], rgbDigits[rgbHash[i] & 0xf]); 49 | md5_hash.append(buffer); 50 | } 51 | hash = md5_hash; 52 | CryptDestroyHash(hHash); 53 | CryptReleaseContext(hProv, 0); 54 | CloseHandle(hFile); 55 | return true; 56 | } 57 | else 58 | { 59 | CloseHandle(hFile); 60 | printf("Hash::GenerateMD5 has failed because CryptGetHashParam returned false.\n"); 61 | return false; 62 | } 63 | } 64 | 65 | bool Hash::ValidateMD5(const std::string& hash) 66 | { 67 | return false; 68 | } -------------------------------------------------------------------------------- /SC2000X/Hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct Hash 5 | { 6 | static bool GenerateMD5(const std::string&, std::string&); 7 | static bool GenerateMD5(const std::wstring&, std::string&); 8 | static bool ValidateMD5(const std::string&); 9 | }; -------------------------------------------------------------------------------- /SC2000X/Instructions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | typedef std::initializer_list ByteArray; 7 | 8 | struct Instruction { 9 | BYTE byte; 10 | DWORD address; 11 | Instruction(DWORD address, BYTE byte) 12 | { 13 | this->address = address; 14 | this->byte = byte; 15 | } 16 | }; 17 | 18 | struct StringValue { 19 | std::string string; 20 | unsigned int size_alignment; 21 | StringValue(std::string string, unsigned int size_alignment) 22 | { 23 | this->string = string; 24 | this->size_alignment = size_alignment; 25 | } 26 | }; 27 | 28 | class Instructions 29 | { 30 | public: 31 | 32 | void operator<<(BYTE b) 33 | { 34 | container.push_back(Instruction(current_location++, b)); 35 | } 36 | 37 | void operator<<(std::initializer_list bytes) 38 | { 39 | for (BYTE b : bytes) 40 | { 41 | container.push_back(Instruction(current_location++, b)); 42 | } 43 | } 44 | 45 | void operator<<(DWORD address) 46 | { 47 | BYTE byte[sizeof(DWORD)]; 48 | memcpy(byte, &address, sizeof(DWORD)); 49 | for (int i = 0; i < sizeof(DWORD); i++) 50 | { 51 | container.push_back(Instruction(current_location++, byte[i])); 52 | } 53 | } 54 | 55 | void operator<<(StringValue string_value) 56 | { 57 | unsigned int track_address = 0; 58 | for (char character : string_value.string) 59 | { 60 | operator<<(BYTE(character)); 61 | track_address++; 62 | } 63 | if (track_address < string_value.size_alignment) 64 | relocate(current_location + (string_value.size_alignment - track_address)); 65 | } 66 | 67 | Instructions(DWORD address) 68 | { 69 | current_location = address; 70 | } 71 | 72 | void relocate(DWORD address) 73 | { 74 | current_location = address; 75 | } 76 | 77 | void nop(size_t amount) 78 | { 79 | for (size_t i = 0; i < amount; i++) 80 | operator<<(BYTE(0x90)); 81 | } 82 | 83 | void jmp(DWORD address, BOOL change_location) 84 | { 85 | DWORD next_address = current_location + 0x5; 86 | DWORD encoding = address - next_address; 87 | operator<<(BYTE(0xE9)); 88 | operator<<(encoding); 89 | if (change_location) 90 | current_location = address; 91 | } 92 | 93 | void jmp(DWORD address) 94 | { 95 | jmp(address, TRUE); 96 | } 97 | 98 | void jnz(DWORD address) 99 | { 100 | DWORD next_address = current_location + 0x6; 101 | DWORD encoding = address - next_address; 102 | operator<<(BYTE(0x0F)); 103 | operator<<(BYTE(0x85)); 104 | operator<<(encoding); 105 | } 106 | 107 | void jz(DWORD address) 108 | { 109 | DWORD next_address = current_location + 0x6; 110 | DWORD encoding = address - next_address; 111 | operator<<(BYTE(0x0F)); 112 | operator<<(BYTE(0x84)); 113 | operator<<(encoding); 114 | } 115 | 116 | void jge(DWORD address) 117 | { 118 | DWORD next_address = current_location + 0x6; 119 | DWORD encoding = address - next_address; 120 | operator<<(BYTE(0x0F)); 121 | operator<<(BYTE(0x8D)); 122 | operator<<(encoding); 123 | } 124 | 125 | void cmp(DWORD address, BYTE value) 126 | { 127 | //operator<<(BYTE(0x3E)); //segment overload 128 | operator<<(ByteArray{ 0x83, 0x3D }); //cmp 129 | operator<<(address); 130 | operator<<(value); 131 | } 132 | 133 | void call(DWORD address) 134 | { 135 | DWORD next_address = current_location + 0x5; 136 | DWORD encoding = address - next_address; 137 | operator<<(BYTE(0xE8)); 138 | operator<<(encoding); 139 | } 140 | 141 | //FF /2 CALL r/m32 142 | //https://c9x.me/x86/html/file_module_x86_id_26.html 143 | //http://ref.x86asm.net/coder32.html#modrm_byte_32 144 | //https://stackoverflow.com/questions/15017659/how-to-read-the-intel-opcode-notation/41616657#41616657 145 | void call_disp32(DWORD address) 146 | { 147 | //3E = DS segment override prefix 148 | //FF 15 = call near absolute indirect, /2 disp32 = 0x15 149 | operator<<(ByteArray{ 0xFF, 0x15 }); 150 | operator<<(address); 151 | } 152 | 153 | void call_rm32(DWORD address) 154 | { 155 | //3E = DS segment override prefix (unused) 156 | //FF 15 = call near absolute indirect, /2 disp32 = 0x15 157 | operator<<(ByteArray{ 0xFF, 0x15 }); 158 | operator<<(address); 159 | } 160 | 161 | void push_rm32(DWORD address) 162 | { 163 | //3E = DS segment override prefix (unused) 164 | //FF 35 = push near absolute indirect, /6 disp32 = 0x35 165 | operator<<(ByteArray{ 0xFF, 0x35 }); 166 | operator<<(address); 167 | } 168 | 169 | std::vector GetInstructions() 170 | { 171 | return container; 172 | } 173 | 174 | DWORD GetCurrentLocation() 175 | { 176 | return current_location; 177 | } 178 | 179 | private: 180 | std::vector container; 181 | DWORD current_location; 182 | }; 183 | 184 | class DataValue : public Instructions 185 | { 186 | public: 187 | DataValue(DWORD address, BYTE value) : Instructions(address) 188 | { 189 | operator<<(value); 190 | } 191 | }; -------------------------------------------------------------------------------- /SC2000X/Logger.cpp: -------------------------------------------------------------------------------- 1 | #include "Logger.h" 2 | #include 3 | HANDLE Logger::hConsole = NULL; 4 | 5 | void Logger::Initialize(HANDLE handle) 6 | { 7 | hConsole = handle; 8 | } 9 | 10 | void Logger::PrintWarning(const std::string& warning) 11 | { 12 | SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY); 13 | printf("\nWARNING:\n%s\n", warning.c_str()); 14 | SetConsoleTextAttribute(hConsole, FOREGROUND_GRAY); 15 | } 16 | 17 | std::wstring Logger::Prompt(WORD wAttributes, const wchar_t* string) 18 | { 19 | std::wstring input; 20 | SetConsoleTextAttribute(hConsole, wAttributes); 21 | printf("%ls", string); 22 | SetConsoleTextAttribute(hConsole, FOREGROUND_WHITE); 23 | std::getline(std::wcin, input); 24 | SetConsoleTextAttribute(hConsole, FOREGROUND_GRAY); 25 | return input; 26 | } 27 | 28 | HANDLE Logger::GetConsole() 29 | { 30 | return hConsole; 31 | } -------------------------------------------------------------------------------- /SC2000X/Logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #define FOREGROUND_GRAY FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE 6 | #define FOREGROUND_WHITE FOREGROUND_GRAY | FOREGROUND_INTENSITY 7 | 8 | class Logger 9 | { 10 | public: 11 | static void Initialize(HANDLE); 12 | static void PrintWarning(const std::string&); 13 | static HANDLE GetConsole(); 14 | static std::wstring Prompt(WORD, const wchar_t*); 15 | private: 16 | static HANDLE hConsole; 17 | }; -------------------------------------------------------------------------------- /SC2000X/Patcher.cpp: -------------------------------------------------------------------------------- 1 | #include "Patcher.h" 2 | 3 | const DWORD WIN32_PE_ENTRY = 0x400000; 4 | bool Patcher::Patch(std::string fname, std::vector ins) 5 | { 6 | PEINFO info; 7 | if (!GetSectionInfo(fname.c_str(), info)) return false; 8 | auto module_it = info.data_map.find(".text"); 9 | if (module_it == info.data_map.end()) 10 | { 11 | printf("The .text section does not appear to be loaded!\n"); 12 | return false; 13 | } 14 | FILE* efile; 15 | int result = fopen_s(&efile, fname.c_str(), "rb+"); 16 | if (efile == nullptr) 17 | { 18 | printf("Failed to open: %s, Error code: %d", fname.c_str(), result); 19 | return false; 20 | } 21 | size_t bytes_written = 0; 22 | for (Instructions is : ins) 23 | { 24 | for (Instruction in : is.GetInstructions()) 25 | { 26 | DWORD address = GetFileOffset(in.address, module_it->second); 27 | fseek(efile, address, SEEK_SET); 28 | fprintf(efile, "%c", in.byte); 29 | ++bytes_written; 30 | } 31 | } 32 | printf("Total bytes patches: %u\n", bytes_written); 33 | fclose(efile); 34 | return true; 35 | } 36 | 37 | DWORD Patcher::GetFileOffset(DWORD address, const PEDATA& data) 38 | { 39 | return (address - data.RealVirtualAddress) + data.RawDataPointer; 40 | } 41 | 42 | bool Patcher::GetSectionInfo(const char* filepath, PEINFO& info) 43 | { 44 | HANDLE file = CreateFile(filepath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 45 | if (file == INVALID_HANDLE_VALUE) 46 | { 47 | printf("Invalid handle to %s, GetLastError: %lu\n", filepath, GetLastError()); 48 | return false; 49 | } 50 | 51 | DWORD fileSize = GetFileSize(file, NULL); 52 | BYTE* pByte = new BYTE[fileSize]; 53 | DWORD dw; 54 | if (!ReadFile(file, pByte, fileSize, &dw, NULL)) 55 | { 56 | printf("ReadFile failed on: %s, GetLastError: %lu\n", filepath, GetLastError()); 57 | return false; 58 | } 59 | 60 | PIMAGE_DOS_HEADER dos = (PIMAGE_DOS_HEADER)pByte; 61 | if (dos->e_magic != IMAGE_DOS_SIGNATURE) 62 | { 63 | printf("Error with retrieving IMAGE_DOS_SIGNATURE (MZ check failed)\n"); 64 | return false; 65 | } 66 | 67 | PIMAGE_FILE_HEADER FH = (PIMAGE_FILE_HEADER)(pByte + dos->e_lfanew + sizeof(DWORD)); 68 | PIMAGE_OPTIONAL_HEADER OH = (PIMAGE_OPTIONAL_HEADER)(pByte + dos->e_lfanew + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER)); 69 | PIMAGE_SECTION_HEADER SH = (PIMAGE_SECTION_HEADER)(pByte + dos->e_lfanew + sizeof(IMAGE_NT_HEADERS)); 70 | for (WORD i = 0; i < FH->NumberOfSections; ++i) 71 | { 72 | std::string name(reinterpret_cast(SH[i].Name)); 73 | info.data_map[name].VirtualAddress = SH[i].VirtualAddress; 74 | info.data_map[name].RealVirtualAddress = SH[i].VirtualAddress + WIN32_PE_ENTRY; 75 | info.data_map[name].RawDataPointer = SH[i].PointerToRawData; 76 | info.data_map[name].VirtualSize = SH[i].Misc.VirtualSize; 77 | printf("Loaded section: %s\n", name.c_str()); 78 | } 79 | return CloseHandle(file); 80 | } -------------------------------------------------------------------------------- /SC2000X/Patcher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Instructions.h" 3 | #include 4 | 5 | typedef std::string SectionHeaderName; 6 | struct PEDATA 7 | { 8 | DWORD RealVirtualAddress; 9 | DWORD VirtualAddress; 10 | DWORD RawDataPointer; 11 | DWORD VirtualSize; 12 | }; 13 | 14 | struct PEINFO 15 | { 16 | std::map data_map; 17 | }; 18 | 19 | class Patcher 20 | { 21 | public: 22 | static bool Patch(std::string, std::vector); 23 | private: 24 | static inline DWORD GetFileOffset(DWORD, const PEDATA&); 25 | static bool GetSectionInfo(const char*, PEINFO&); 26 | 27 | }; 28 | -------------------------------------------------------------------------------- /SC2000X/Registry.cpp: -------------------------------------------------------------------------------- 1 | #include "Registry.h" 2 | #include 3 | 4 | BOOL Registry::SetValues(const RegistryKey key, const RegistryEntry values[], size_t size) 5 | { 6 | HKEY hKey; 7 | DWORD disposition; 8 | LSTATUS status_createkeyex = RegCreateKeyExW(key.hKey, key.SubKey.c_str(), 9 | 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disposition); 10 | if (status_createkeyex != ERROR_SUCCESS) 11 | { 12 | printf("[Registry::SetValues] RegCreateKeyExW (%ls) = %d\n", 13 | key.SubKey.c_str(), status_createkeyex); 14 | return FALSE; 15 | } 16 | printf("Current Key=%ls\n", key.SubKey.c_str()); 17 | 18 | for (size_t index = 0; index < size; ++index) 19 | { 20 | const RegistryEntry& entry = values[index]; 21 | const size_t v_size = entry.Value->Size; 22 | 23 | //TODO Create a query for DWORD values 24 | DWORD queryType; 25 | WCHAR queryData[256] = { 0 }; 26 | DWORD cbData = sizeof(queryData) - 1; 27 | LSTATUS status_queryvalue = RegQueryValueExW(hKey, 28 | entry.Name.c_str(), NULL, &queryType, 29 | (LPBYTE)queryData, &cbData); 30 | 31 | bool overwrite = false; 32 | if (status_queryvalue == ERROR_SUCCESS) 33 | { 34 | std::wstring data_wstring(queryData); 35 | if (data_wstring.compare(entry.Value->wstring.c_str()) == 0) 36 | { 37 | printf("Existing %ls=%ls\n", entry.Name.c_str(), 38 | data_wstring.c_str()); 39 | continue; 40 | } 41 | overwrite = true; 42 | } 43 | 44 | printf("%s %ls=%ls\n", overwrite ? "Overwriting" : "Setting", 45 | entry.Name.c_str(), entry.Value->wstring.c_str()); 46 | 47 | LSTATUS status_setvalue = RegSetValueExW(hKey, 48 | entry.Name.c_str(), NULL, 49 | entry.Value->dwType, 50 | entry.Value->Data, 51 | entry.Value->Size); 52 | 53 | if (status_setvalue != ERROR_SUCCESS) 54 | { 55 | printf("Unable to set the registry key. LSTATUS=%d\n", status_setvalue); 56 | return FALSE; 57 | } 58 | 59 | } 60 | LSTATUS status_closekey = RegCloseKey(hKey); 61 | if (status_closekey != ERROR_SUCCESS) 62 | { 63 | printf("[Registry::SetValues] RegCloseKey (%ls) = %d\n", 64 | key.SubKey.c_str(), status_closekey); 65 | //If we set all our values, still return TRUE 66 | } 67 | return TRUE; 68 | } -------------------------------------------------------------------------------- /SC2000X/Registry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | struct RegistryValue { 7 | const DWORD dwType; 8 | const DWORD Size; 9 | const std::wstring wstring; 10 | LPBYTE Data; 11 | 12 | explicit RegistryValue(const std::wstring& value) : 13 | dwType(REG_SZ), Size((value.size() + 1) * sizeof(wchar_t)), 14 | wstring(value) 15 | { 16 | Data = (LPBYTE) malloc(Size); 17 | if (Data == nullptr) throw std::bad_alloc(); 18 | memcpy(Data, value.c_str(), Size); 19 | } 20 | 21 | explicit RegistryValue(const DWORD& value) : 22 | dwType(REG_DWORD), Size(sizeof(DWORD)), 23 | wstring(std::to_wstring(value)) 24 | { 25 | Data = (LPBYTE) malloc(Size); 26 | if (Data == nullptr) throw std::bad_alloc(); 27 | memcpy(Data, &value, Size); 28 | } 29 | 30 | RegistryValue(const RegistryValue& v) : 31 | dwType(v.dwType), Size(v.Size), wstring(v.wstring) 32 | { 33 | Data = (LPBYTE)malloc(Size); 34 | if (Data == nullptr) throw std::bad_alloc(); 35 | memcpy(Data, v.Data, Size); 36 | } 37 | 38 | ~RegistryValue() 39 | { 40 | free(Data); 41 | Data = nullptr; 42 | } 43 | 44 | }; 45 | 46 | struct RegistryEntry { 47 | const std::wstring Name; 48 | const RegistryValue* Value; 49 | RegistryEntry(std::wstring Name, const RegistryValue& Value) : 50 | Name(Name), Value(new RegistryValue(Value)) 51 | { 52 | } 53 | RegistryEntry() = delete; 54 | ~RegistryEntry() 55 | { 56 | delete Value; 57 | Value = nullptr; 58 | } 59 | }; 60 | 61 | struct RegistryKey { 62 | HKEY hKey; 63 | std::wstring SubKey; 64 | RegistryKey(HKEY hKey, std::wstring SubKey) 65 | { 66 | this->hKey = hKey; 67 | this->SubKey = SubKey; 68 | } 69 | RegistryKey() = default; 70 | }; 71 | 72 | namespace Registry { 73 | BOOL SetValues(const RegistryKey, const RegistryEntry[], size_t); 74 | } -------------------------------------------------------------------------------- /SC2000X/SC2000X.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Aleksander Krimsky 3 | * www.krimsky.net | www.alekasm.com 4 | * Icon from iconarchive.org, accessed 29 July 2021 5 | * https://iconarchive.com/show/standard-city-icons-by-aha-soft/city-icon.html 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "Logger.h" 19 | #include "Registry.h" 20 | #include "Hash.h" 21 | #include "SC2KRegistry.h" 22 | #include "SC2KVersion.h" 23 | #include "Patcher.h" 24 | #include "AssemblyData.h" 25 | #include "FileVersion.h" 26 | 27 | int main() 28 | { 29 | //Shared between installer and patcher 30 | std::filesystem::path exe_path; 31 | std::filesystem::path exe_parent_path; 32 | std::filesystem::path root_path; 33 | 34 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 35 | Logger::Initialize(hConsole); 36 | SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY); 37 | printf("Welcome to SC2000X - An Open-Source SimCity 2000(Win95) Patcher\n"); 38 | SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN); 39 | printf("Current Version: 1.0\n"); 40 | printf("Aleksander Krimsky - alekasm.com | krimsky.net\n\n"); 41 | SetConsoleTextAttribute(hConsole, FOREGROUND_GRAY); 42 | printf("Current Features:\n"); 43 | printf("- Performs installation/setup\n"); 44 | printf("- Fixes Dialog Crash Bug\n\n"); 45 | 46 | HANDLE hToken = NULL; 47 | if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) 48 | { 49 | TOKEN_ELEVATION elevation; 50 | DWORD dwSize; 51 | if (GetTokenInformation(hToken, TokenElevation, &elevation, sizeof(elevation), &dwSize)) 52 | { 53 | if (elevation.TokenIsElevated) 54 | { 55 | goto label_start; 56 | } 57 | } 58 | } 59 | 60 | { 61 | std::string warning = "It appears you are running SC2000X without elevated permissions!\n\n"; 62 | warning.append("If you run into errors, try any of the following:\n"); 63 | warning.append("1. Right-click -> \"Run-as-Administrator\"\n"); 64 | warning.append("2. Move the game files to a user directory (ie Desktop)\n"); 65 | warning.append("3. Ensure the game is not located on read-only/removable storage ie usb/cd/iso/zip\n"); 66 | Logger::PrintWarning(warning); 67 | } 68 | 69 | label_start: 70 | { 71 | exe_path.clear(); 72 | exe_parent_path.clear(); 73 | root_path.clear(); 74 | std::wstring input = Logger::Prompt(FOREGROUND_WHITE, L"Enter your SIMCITY.EXE file location: "); 75 | exe_path = std::filesystem::path(input); 76 | if (!exe_path.has_extension()) 77 | exe_path.append(L"SimCity.exe"); 78 | try 79 | { 80 | exe_path = std::filesystem::canonical(exe_path); 81 | exe_parent_path = exe_path.parent_path(); 82 | root_path = exe_parent_path.parent_path(); 83 | } 84 | catch (const std::exception& e) 85 | { 86 | printf("%s\n", e.what()); 87 | goto label_start; 88 | } 89 | printf("Canonical Path=%ls\n", exe_path.wstring().c_str()); 90 | printf("Parent Path=%ls\n", exe_parent_path.wstring().c_str()); 91 | printf("Root Path=%ls\n", root_path.wstring().c_str()); 92 | } 93 | 94 | label_install_prompt: 95 | { 96 | std::wstring run_installer = Logger::Prompt(FOREGROUND_WHITE, 97 | L"Would you like to install the game? (required to run) Y/n: "); 98 | std::transform(run_installer.begin(), run_installer.end(), run_installer.begin(), ::tolower); 99 | if (!run_installer.empty() && run_installer.at(0) == L'n') goto label_patcher_prompt; 100 | } 101 | 102 | label_install: 103 | { 104 | printf("\nInstalling SimCity 2000(Win95)...\n"); 105 | if (!SC2KRegistry::SetLocalization()) goto label_start; 106 | if (!SC2KRegistry::SetPaths(root_path, exe_parent_path)) goto label_start; 107 | if (!SC2KRegistry::SetRegistration()) goto label_start; 108 | if (!SC2KRegistry::SetOptions()) goto label_start; 109 | if (!SC2KRegistry::SetSCURK()) goto label_start; 110 | if (!SC2KRegistry::SetVersion()) goto label_start; 111 | if (!SC2KRegistry::SetWindows()) goto label_start; 112 | printf("Finished installing SimCity 2000(Win95)\n"); 113 | } 114 | 115 | label_patcher_prompt: 116 | { 117 | std::wstring run_patcher = Logger::Prompt(FOREGROUND_WHITE, 118 | L"Would you like to patch the game? Y/n: "); 119 | std::transform(run_patcher.begin(), run_patcher.end(), run_patcher.begin(), ::tolower); 120 | if (!run_patcher.empty() && run_patcher.at(0) == L'n') goto label_finished; 121 | } 122 | 123 | label_patcher: 124 | { 125 | FileVersion::PrintFileVersionInfo(exe_path.string().c_str()); 126 | std::string hash; 127 | bool hash_result = Hash::GenerateMD5(exe_path.wstring(), hash); 128 | if (!hash_result) goto label_start; 129 | printf("Hash=%s\n", hash.c_str()); 130 | auto vinfo_it = SC2KVersion::VersionInfoMap.find(hash); 131 | if (vinfo_it == SC2KVersion::VersionInfoMap.end()) 132 | { 133 | std::string warning = "SC2000X was unable to recognize the game with the hash above!\n"; 134 | warning.append("Either the game is already modified or it does not exist in the "); 135 | warning.append("SC2000X list of recognized versions. Please submit a copy of your SIMCITY.exe for "); 136 | warning.append("evaluation.\n"); 137 | Logger::PrintWarning(warning); 138 | goto label_start; 139 | } 140 | VersionInfo vinfo = vinfo_it->second; 141 | printf("Recognized Version: %s\n", vinfo.description.c_str()); 142 | std::filesystem::path sc2000x_path(exe_parent_path); 143 | sc2000x_path.append("SC2000X.EXE"); 144 | std::error_code copy_error; 145 | std::filesystem::copy(exe_path, sc2000x_path, 146 | std::filesystem::copy_options::overwrite_existing, copy_error); 147 | if (copy_error.value()) 148 | { 149 | char buffer[512]; 150 | snprintf(buffer, sizeof(buffer), 151 | "Failed to copy file from: %ls\nto: %ls\nError Code: %d\n%s\n", 152 | exe_path.wstring().c_str(), 153 | sc2000x_path.wstring().c_str(), 154 | copy_error.value(), 155 | copy_error.message().c_str()); 156 | Logger::PrintWarning(buffer); 157 | goto label_start; 158 | } 159 | std::vector instructions; 160 | AssemblyData::GenerateData(vinfo, instructions); 161 | //Okay, I got lazy and used std string here, I really don't care right now 162 | bool patch_result = Patcher::Patch(sc2000x_path.string(), instructions); 163 | if (!patch_result) goto label_patcher_prompt; 164 | } 165 | 166 | label_finished: 167 | SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY); 168 | printf("\nSC2000X is now finished!\n"); 169 | SetConsoleTextAttribute(hConsole, FOREGROUND_WHITE); 170 | _getch(); 171 | } -------------------------------------------------------------------------------- /SC2000X/SC2000X.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_ICON1 ICON "icon.ico" 56 | 57 | #endif // English (United States) resources 58 | ///////////////////////////////////////////////////////////////////////////// 59 | 60 | 61 | 62 | #ifndef APSTUDIO_INVOKED 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // 65 | // Generated from the TEXTINCLUDE 3 resource. 66 | // 67 | 68 | 69 | ///////////////////////////////////////////////////////////////////////////// 70 | #endif // not APSTUDIO_INVOKED 71 | 72 | -------------------------------------------------------------------------------- /SC2000X/SC2000X.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {834bea1b-1189-4a35-beed-aeb13eade0cd} 25 | SC2000X 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | MultiByte 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | MultiByte 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | stdcpp17 92 | MultiThreadedDebug 93 | 94 | 95 | Console 96 | true 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | true 104 | true 105 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 106 | true 107 | stdcpp17 108 | MultiThreaded 109 | 110 | 111 | Console 112 | true 113 | true 114 | true 115 | 116 | 117 | 118 | 119 | Level3 120 | true 121 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 122 | true 123 | 124 | 125 | Console 126 | true 127 | 128 | 129 | 130 | 131 | Level3 132 | true 133 | true 134 | true 135 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 136 | true 137 | 138 | 139 | Console 140 | true 141 | true 142 | true 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /SC2000X/SC2000X.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | 73 | 74 | Resource Files 75 | 76 | 77 | 78 | 79 | Resource Files 80 | 81 | 82 | -------------------------------------------------------------------------------- /SC2000X/SC2KRegistry.cpp: -------------------------------------------------------------------------------- 1 | #include "SC2KRegistry.h" 2 | #include "Registry.h" 3 | #include 4 | 5 | bool SC2KRegistry::SetLocalization() 6 | { 7 | RegistryKey rkey; 8 | rkey.hKey = HKEY_CURRENT_USER; 9 | rkey.SubKey = L"Software\\Maxis\\SimCity 2000\\Localize"; 10 | const RegistryEntry rvals_localize[] = { RegistryEntry(L"Language", RegistryValue(L"USA")) }; 11 | return Registry::SetValues(rkey, rvals_localize, 1); 12 | } 13 | 14 | bool SC2KRegistry::SetPaths( 15 | const std::filesystem::path& root_path, 16 | const std::filesystem::path& exe_parent_path) 17 | { 18 | std::unordered_map KeyDirectoryMap; 19 | KeyDirectoryMap[L"Home"] = exe_parent_path.wstring(); 20 | auto it = SC2KRegistry::RequiredSubDirectories.begin(); 21 | for (; it != SC2KRegistry::RequiredSubDirectories.end(); ++it) 22 | { 23 | std::filesystem::path find_path(root_path); 24 | find_path.append(it->first); 25 | try 26 | { 27 | find_path = std::filesystem::canonical(find_path); 28 | } 29 | catch (const std::exception&) 30 | { 31 | if (it->second.Required) 32 | { 33 | char buffer[256]; 34 | snprintf(buffer, sizeof(buffer), 35 | "The required path does not exist: %ls\n", 36 | find_path.wstring().c_str()); 37 | Logger::PrintWarning(std::string(buffer)); 38 | return false; 39 | } 40 | else 41 | { 42 | char buffer[256]; 43 | snprintf(buffer, sizeof(buffer), 44 | "The optional path does not exist: %ls\nAlthough not required, some game features may not be present.", 45 | find_path.wstring().c_str()); 46 | Logger::PrintWarning(std::string(buffer)); 47 | } 48 | } 49 | //Adds presumed paths 50 | for (const std::wstring& Key : it->second.KeyValues) 51 | { 52 | KeyDirectoryMap[Key] = find_path.wstring(); 53 | } 54 | } 55 | 56 | RegistryKey rkey; 57 | rkey.hKey = HKEY_CURRENT_USER; 58 | rkey.SubKey = L"Software\\Maxis\\SimCity 2000\\Paths"; 59 | 60 | //Do not use stack-allocated values for RegistryValues, they will be pointer casted. 61 | const RegistryEntry rvalues[] { 62 | RegistryEntry(L"Cities", RegistryValue(KeyDirectoryMap.at(L"Cities"))), 63 | RegistryEntry(L"Data", RegistryValue(KeyDirectoryMap.at(L"Data"))), 64 | RegistryEntry(L"Goodies", RegistryValue(KeyDirectoryMap.at(L"Goodies"))), 65 | RegistryEntry(L"Graphics", RegistryValue(KeyDirectoryMap.at(L"Graphics"))), 66 | RegistryEntry(L"Home", RegistryValue(KeyDirectoryMap.at(L"Home"))), 67 | RegistryEntry(L"Music", RegistryValue(KeyDirectoryMap.at(L"Music"))), 68 | RegistryEntry(L"SaveGame", RegistryValue(KeyDirectoryMap.at(L"SaveGame"))), 69 | RegistryEntry(L"Scenarios", RegistryValue(KeyDirectoryMap.at(L"Scenarios"))), 70 | RegistryEntry(L"TileSets", RegistryValue(KeyDirectoryMap.at(L"TileSets"))) 71 | }; 72 | 73 | return Registry::SetValues(rkey, rvalues, 9); 74 | } 75 | 76 | bool SC2KRegistry::SetRegistration() 77 | { 78 | printf("\n"); 79 | std::wstring mayor_name = Logger::Prompt(FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY, 80 | L"In SimCity 2000, you will become the fearless leader of many living Sims.\nWhat should they call you? "); 81 | 82 | wchar_t buffer[256]; 83 | swprintf(buffer, sizeof(buffer) / sizeof(wchar_t), 84 | L"Please tell me again, %ls, from what fine company do you hail? ", mayor_name.c_str()); 85 | std::wstring company_name = Logger::Prompt(FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY, buffer); 86 | printf("\n"); 87 | 88 | RegistryKey rkey; 89 | rkey.hKey = HKEY_CURRENT_USER; 90 | rkey.SubKey = L"Software\\Maxis\\SimCity 2000\\Registration"; 91 | RegistryEntry rvalues[] = 92 | { 93 | RegistryEntry(L"Mayor Name", RegistryValue(mayor_name)), 94 | RegistryEntry(L"Company Name", RegistryValue(company_name)) 95 | }; 96 | return Registry::SetValues(rkey, rvalues, 2); 97 | } 98 | 99 | bool SC2KRegistry::SetOptions() 100 | { 101 | RegistryKey rkey; 102 | rkey.hKey = HKEY_CURRENT_USER; 103 | rkey.SubKey = L"Software\\Maxis\\SimCity 2000\\Options"; 104 | const RegistryEntry rvalues[] { 105 | RegistryEntry(L"AutoBudget", RegistryValue(DWORD(0x0))), 106 | RegistryEntry(L"AutoGoto", RegistryValue(DWORD(0x1))), 107 | RegistryEntry(L"AutoSave", RegistryValue(DWORD(0x0))), 108 | RegistryEntry(L"Disasters", RegistryValue(DWORD(0x1))), 109 | RegistryEntry(L"Music", RegistryValue(DWORD(0x1))), 110 | RegistryEntry(L"Sound", RegistryValue(DWORD(0x1))), 111 | RegistryEntry(L"Speed", RegistryValue(DWORD(0x1))) 112 | }; 113 | return Registry::SetValues(rkey, rvalues, 7); 114 | } 115 | 116 | bool SC2KRegistry::SetSCURK() 117 | { 118 | RegistryKey rkey; 119 | rkey.hKey = HKEY_CURRENT_USER; 120 | rkey.SubKey = L"Software\\Maxis\\SimCity 2000\\SCURK"; 121 | const RegistryEntry rvalues[]{ 122 | RegistryEntry(L"CycleColors", RegistryValue(DWORD(0x1))), 123 | RegistryEntry(L"GridHeight", RegistryValue(DWORD(0x2))), 124 | RegistryEntry(L"GridWidth", RegistryValue(DWORD(0x2))), 125 | RegistryEntry(L"ShowClipRegion", RegistryValue(DWORD(0x0))), 126 | RegistryEntry(L"ShowDrawGrid", RegistryValue(DWORD(0x0))), 127 | RegistryEntry(L"SnapToGrid", RegistryValue(DWORD(0x0))), 128 | RegistryEntry(L"Sound", RegistryValue(DWORD(0x1))) 129 | }; 130 | return Registry::SetValues(rkey, rvalues, 7); 131 | } 132 | 133 | bool SC2KRegistry::SetVersion() 134 | { 135 | //This is likely completely useless because I know there are different 136 | //versions based on filesize and md5sum 137 | RegistryKey rkey; 138 | rkey.hKey = HKEY_CURRENT_USER; 139 | rkey.SubKey = L"Software\\Maxis\\SimCity 2000\\Version"; 140 | 141 | const RegistryEntry rvalues[]{ 142 | RegistryEntry(L"SCURK", RegistryValue(DWORD(0x100))), 143 | RegistryEntry(L"SimCity 2000", RegistryValue(DWORD(0x100))) 144 | }; 145 | return Registry::SetValues(rkey, rvalues, 2); 146 | } 147 | 148 | bool SC2KRegistry::SetWindows() 149 | { 150 | //This is likely completely useless because I know there are different 151 | //versions based on filesize and md5sum 152 | RegistryKey rkey; 153 | rkey.hKey = HKEY_CURRENT_USER; 154 | rkey.SubKey = L"Software\\Maxis\\SimCity 2000\\Windows"; 155 | 156 | const RegistryEntry rvalues[]{ 157 | RegistryEntry(L"Color Check", RegistryValue(DWORD(0x0))), 158 | RegistryEntry(L"SimCity 2000", RegistryValue(L"8 1")) 159 | }; 160 | return Registry::SetValues(rkey, rvalues, 2); 161 | } -------------------------------------------------------------------------------- /SC2000X/SC2KRegistry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "Logger.h" 6 | 7 | struct PathRegistryKeyValue 8 | { 9 | bool Required; 10 | std::vector KeyValues; 11 | PathRegistryKeyValue(const std::vector& KeyValues, bool Required) 12 | { 13 | this->KeyValues = KeyValues; 14 | this->Required = Required; 15 | } 16 | PathRegistryKeyValue() = delete; 17 | }; 18 | 19 | namespace SC2KRegistry 20 | { 21 | static const std::unordered_map RequiredSubDirectories = 22 | { 23 | {L"SC2K/CITIES", PathRegistryKeyValue({L"Cities", L"SaveGame"}, true)}, 24 | {L"SC2K/DATA", PathRegistryKeyValue({L"Data"}, true)}, 25 | {L"GOODIES", PathRegistryKeyValue({L"Goodies"}, false)}, 26 | {L"SC2K/BITMAPS", PathRegistryKeyValue({L"Graphics"}, true)}, 27 | {L"SC2K/SOUNDS", PathRegistryKeyValue({L"Music"}, true)}, 28 | {L"SC2K/SCENARIO", PathRegistryKeyValue({L"Scenarios"}, true)}, 29 | {L"SC2K/SCURKART", PathRegistryKeyValue({L"TileSets"}, true)} 30 | }; 31 | 32 | extern bool SetLocalization(); 33 | extern bool SetPaths( 34 | const std::filesystem::path& root_path, 35 | const std::filesystem::path& exe_parent_path); 36 | extern bool SetRegistration(); 37 | extern bool SetOptions(); 38 | extern bool SetSCURK(); 39 | extern bool SetVersion(); 40 | extern bool SetWindows(); 41 | } -------------------------------------------------------------------------------- /SC2000X/SC2KVersion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | //df136923ca204e3451ed4349f08b5d1f (my version, August 14, 1995 - 1.23MB) - SVERSION.INF matches this one 5 | //f1ad828513d75004345e3324b3d97e46 (archive.org version, March 6, 1996 - 1.32MB) 6 | 7 | enum VersionType { VERSION_AUG1995, VERSION_MAR1996}; 8 | 9 | struct FunctionOffset 10 | { 11 | DWORD DIALOG_CONTROLLER; 12 | DWORD DIALOG_DISPLAY_CALC; 13 | }; 14 | 15 | struct GameOffsets { 16 | FunctionOffset functions; 17 | }; 18 | 19 | const struct VersionAug1995Offsets : GameOffsets 20 | { 21 | VersionAug1995Offsets() 22 | { 23 | functions.DIALOG_CONTROLLER = 0x49EE88; 24 | functions.DIALOG_DISPLAY_CALC = 0x4A2AF1; 25 | } 26 | } version_aug1995offsets; 27 | 28 | const struct VersionMar1996Offsets : GameOffsets 29 | { 30 | VersionMar1996Offsets() 31 | { 32 | functions.DIALOG_CONTROLLER = 0x4A04EF; 33 | functions.DIALOG_DISPLAY_CALC = 0x4A3BFD; 34 | } 35 | } version_mar1996offsets; 36 | 37 | 38 | struct VersionInfo { 39 | const std::string description; 40 | const VersionType version; 41 | const GameOffsets* offsets; 42 | VersionInfo() = delete; 43 | VersionInfo(VersionType version, const GameOffsets* offsets, std::string description) : 44 | version(version), description(description), offsets(offsets) 45 | { 46 | } 47 | }; 48 | 49 | namespace SC2KVersion 50 | { 51 | const std::unordered_map VersionInfoMap = { 52 | {"df136923ca204e3451ed4349f08b5d1f", VersionInfo(VERSION_AUG1995, &version_aug1995offsets, "August 14, 1995 (1.23MB)")}, 53 | {"f1ad828513d75004345e3324b3d97e46", VersionInfo(VERSION_MAR1996, &version_mar1996offsets, "March 6, 1996 (1.32MB)")} 54 | }; 55 | } -------------------------------------------------------------------------------- /SC2000X/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alekasm/SC2000X/c58120e30fdea0675a40814e3389466807da53b1/SC2000X/icon.ico -------------------------------------------------------------------------------- /SC2000X/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by SC2000X.rc 4 | // 5 | #define IDI_ICON1 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | --------------------------------------------------------------------------------