forked from electronicarts/CnC_Remastered_Collection
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in Root-Core/cncremastered (pull request electronicarts#3)
Updated Red Alert port to 06f73fb
- Loading branch information
Showing
21 changed files
with
520 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ BUILDING_GAP=2 | |
QUEUE_JUMP_CUTOFF=3 | ||
TIB_GROWTH_SCALE=1 | ||
WALL_BUILD_LENGTH=5 | ||
BUILDING_GAP_OFFSET=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ INSTANT_CAPTURE=1 | |
QUEUE_JUMP_CUTOFF=3 | ||
ORE_GROWTH_SCALE=1 | ||
WALL_BUILD_LENGTH=5 | ||
BUILDING_GAP_OFFSET=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <cstdio> | ||
#include "FUNCTION.H" | ||
|
||
//Prints to steamapps\common\CnCRemastered\log\CnCDLL_Log_16000.txt | ||
template <typename... ARGS> | ||
void CFE_Debug_Printf(const char* const format, const ARGS&... args) { | ||
const int bufferSize = snprintf(nullptr, 0, format, args...); | ||
char* printed = (char*)malloc(bufferSize + 1); | ||
snprintf(printed, bufferSize + 1, format, args...); | ||
|
||
GlyphX_Debug_Print(printed); | ||
delete printed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "FUNCTION.H" | ||
|
||
extern bool DLL_Export_Get_Input_Key_State(KeyNumType key); | ||
|
||
bool CFE_Patch_Is_Wall(const ObjectTypeClass& object) | ||
{ | ||
return object.What_Am_I() == RTTI_BUILDINGTYPE && static_cast<const BuildingTypeClass&>(object).IsWall; | ||
} | ||
|
||
bool CFE_Patch_Can_Have_Rally_Point(const ObjectClass& object) | ||
{ | ||
return object.What_Am_I() == RTTI_BUILDING && static_cast<const BuildingClass&>(object).Can_Have_Rally_Point(); | ||
} | ||
|
||
bool CFE_Patch_Should_Extend_Walls() | ||
{ | ||
return ActiveCFEPatchConfig.WallBuildLength > 1 && !DLL_Export_Get_Input_Key_State(KN_LCTRL); | ||
} | ||
|
||
bool CFE_Patch_Unit_Should_Rally(const FootClass& object) | ||
{ | ||
switch (object.What_Am_I()) | ||
{ | ||
case RTTI_UNIT: | ||
return !static_cast<const UnitClass&>(object).Class->IsToHarvest; | ||
default: | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <algorithm> | ||
#include <Windows.h> | ||
#include <ShlObj.h> | ||
#include <string> | ||
|
||
#include "FUNCTION.H" | ||
#include "INI.H" | ||
#include "RANGEWRAPPER.H" | ||
|
||
std::string Get_User_Mod_Dir() | ||
{ | ||
std::string dirPath; | ||
char documentsPath[1024]; | ||
HRESULT result = SHGetFolderPathA(NULL, CSIDL_MYDOCUMENTS, NULL, NULL, documentsPath); | ||
if (SUCCEEDED(result)) | ||
{ | ||
dirPath = documentsPath; | ||
dirPath += "\\CnCRemastered\\Mods\\Red_Alert"; | ||
} | ||
return dirPath; | ||
} | ||
|
||
bool Load_INI_File(INIClass& ini, const char* path) | ||
{ | ||
CCFileClass file(path); | ||
if (file.Is_Available()) | ||
{ | ||
ini.Clear(); | ||
return ini.Load(file); | ||
} | ||
return false; | ||
} | ||
|
||
void Populate_CFE_Patch_Config_From_INI(const INIClass& ini) | ||
{ | ||
static constexpr int InvalidSetting = std::numeric_limits<int>::lowest(); | ||
const auto GetSetting = [&ini](auto& target, const char* section, const char* entry) | ||
{ | ||
const int value = ini.Get_Int(section, entry, InvalidSetting); | ||
if (value != InvalidSetting) | ||
target = value; | ||
}; | ||
|
||
|
||
|
||
//cfehunter 12/06/2020 It's really starting to get to the point where I should make feature flags | ||
//Features | ||
GetSetting(ActiveCFEPatchConfig.EnableASPathing, "FEATURES", "ASTAR_PATHING"); | ||
GetSetting(ActiveCFEPatchConfig.EnableOOMRepair, "FEATURES", "OOM_REPAIR"); | ||
GetSetting(ActiveCFEPatchConfig.EnableRallyPoints, "FEATURES", "RALLY_POINTS"); | ||
GetSetting(ActiveCFEPatchConfig.EnableHarvyQueueJump, "FEATURES", "HARVY_QUEUE_JUMP"); | ||
GetSetting(ActiveCFEPatchConfig.EnableInstantCapture, "FEATURES", "INSTANT_CAPTURE"); | ||
|
||
//Settings | ||
GetSetting(ActiveCFEPatchConfig.HarvyQueueJumpCutoff, "SETTINGS", "QUEUE_JUMP_CUTOFF"); | ||
GetSetting(ActiveCFEPatchConfig.OreGrowthScale, "SETTINGS", "ORE_GROWTH_SCALE"); | ||
GetSetting(ActiveCFEPatchConfig.WallBuildLength, "SETTINGS", "WALL_BUILD_LENGTH"); | ||
GetSetting(ActiveCFEPatchConfig.BuildingGapOffset, "SETTINGS", "BUILDING_GAP_OFFSET"); | ||
|
||
//Clamp Wall Length between 1 (build at all) and 10 (buffer limits) | ||
ActiveCFEPatchConfig.WallBuildLength = (std::max)(1, (std::min)(ActiveCFEPatchConfig.WallBuildLength, 10)); | ||
} | ||
|
||
bool Create_CFE_Patch_Directory(const char* path) | ||
{ | ||
const int directory_result = SHCreateDirectoryExA(NULL, path, NULL); | ||
return directory_result == ERROR_SUCCESS || directory_result == ERROR_ALREADY_EXISTS; | ||
} | ||
|
||
bool Reconcile_Config_With_Default(const INIClass& default, INIClass& config) | ||
{ | ||
bool changed = false; | ||
using KVPair = std::pair<const char*, const char*>; | ||
for (const char* section : default) | ||
{ | ||
for (KVPair entry : make_iterator_range(default.section_begin(section), default.section_end(section))) | ||
{ | ||
if (!config.Is_Present(section, entry.first)) | ||
{ | ||
config.Put_String(section, entry.first, entry.second); | ||
changed = true; | ||
} | ||
} | ||
} | ||
|
||
return changed; | ||
} | ||
|
||
//cfehunter 12/06/2020 I really miss std::filesystem | ||
void Initialise_CFE_Patch_Config() | ||
{ | ||
static constexpr const char* DefaultININame = "DEFAULT.CFEPATCH_RA.INI"; | ||
|
||
const std::string ini_dir = Get_User_Mod_Dir() + "\\CFEPatch"; | ||
const std::string ini_path = ini_dir + "\\CFEPATCH_RA.INI"; | ||
|
||
INIClass default_ini; | ||
Load_INI_File(default_ini, DefaultININame); | ||
|
||
|
||
|
||
//Initialise from the default config | ||
Populate_CFE_Patch_Config_From_INI(default_ini); | ||
|
||
//Overwrite settings from the user config | ||
INIClass user_ini; | ||
if (Load_INI_File(user_ini, ini_path.c_str())) | ||
{ | ||
Populate_CFE_Patch_Config_From_INI(user_ini); | ||
|
||
//Add any missing settings | ||
if (Reconcile_Config_With_Default(default_ini, user_ini)) | ||
{ | ||
//Create the target directory | ||
if (Create_CFE_Patch_Directory(ini_dir.c_str())) | ||
{ | ||
//Write the modified ini to a temp file | ||
const std::string write_path = ini_path + ".temp"; | ||
if (FILE* target_file = fopen(write_path.c_str(), "w")) | ||
{ | ||
fclose(target_file); | ||
|
||
//If it was written successfully, overwrite the existing config | ||
CCFileClass write_file(write_path.c_str()); | ||
if (user_ini.Save(write_file)) | ||
{ | ||
write_file.Close(); | ||
CopyFileA(write_path.c_str(), ini_path.c_str(), FALSE); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
//Clone the default | ||
CCFileClass defaultConfig(DefaultININame); | ||
if (defaultConfig.Is_Available()) | ||
{ | ||
//Create directories and clone the default config | ||
if (Create_CFE_Patch_Directory(ini_dir.c_str())) | ||
{ | ||
//Copy the default ini to the user directory so they can modify it later | ||
CopyFileA(defaultConfig.File_Name(), ini_path.c_str(), TRUE); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.