Skip to content

Commit

Permalink
Detach rules shit from ra2md parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Jun 30, 2024
1 parent d7f7f05 commit d02081c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 74 deletions.
1 change: 0 additions & 1 deletion Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
<ClCompile Include="src\Ext\Script\Mission.Move.cpp" />
<ClCompile Include="src\Ext\Rules\Body.cpp" />
<ClCompile Include="src\Ext\Rules\Hooks.Image.cpp" />
<ClCompile Include="src\Ext\Rules\Hooks.INIClass.cpp" />
<ClCompile Include="src\Ext\SWType\Body.cpp" />
<ClCompile Include="src\Ext\Side\Body.cpp" />
<ClCompile Include="src\Ext\Side\Hooks.cpp" />
Expand Down
4 changes: 1 addition & 3 deletions src/Commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ DEFINE_HOOK(0x533066, CommandClassCallback_Register, 0x6)
MakeCommand<QuickSaveCommandClass>();
MakeCommand<ToggleDigitalDisplayCommandClass>();
MakeCommand<ToggleDesignatorRangeCommandClass>();
#ifndef DEBUG
Phobos::Config::DevelopmentCommands = CCINIClass::INI_Rules->ReadBool("GlobalControls", "DebugKeysEnabled", Phobos::Config::DevelopmentCommands);
#endif

if (Phobos::Config::DevelopmentCommands)
{
MakeCommand<DamageDisplayCommandClass>();
Expand Down
39 changes: 39 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,42 @@ DEFINE_HOOK(0x679CAF, RulesData_LoadAfterTypeData, 0x5)

return 0;
}

// Reenable obsolete [JumpjetControls] in RA2/YR
// Author: Uranusian
DEFINE_HOOK(0x7115AE, TechnoTypeClass_CTOR_JumpjetControls, 0xA)
{
GET(TechnoTypeClass*, pThis, ESI);
auto pRules = RulesClass::Instance();
auto pRulesExt = RulesExt::Global();

pThis->JumpjetTurnRate = pRules->TurnRate;
pThis->JumpjetSpeed = pRules->Speed;
pThis->JumpjetClimb = static_cast<float>(pRules->Climb);
pThis->JumpjetCrash = static_cast<float>(pRulesExt->JumpjetCrash);
pThis->JumpjetHeight = pRules->CruiseHeight;
pThis->JumpjetAccel = static_cast<float>(pRules->Acceleration);
pThis->JumpjetWobbles = static_cast<float>(pRules->WobblesPerSecond);
pThis->JumpjetNoWobbles = pRulesExt->JumpjetNoWobbles;
pThis->JumpjetDeviation = pRules->WobbleDeviation;

return 0x711601;
}

DEFINE_HOOK(0x6744E4, RulesClass_ReadJumpjetControls_Extra, 0x7)
{
auto pRulesExt = RulesExt::Global();
if (!pRulesExt)
return 0;

GET(CCINIClass*, pINI, EDI);
INI_EX exINI(pINI);

pRulesExt->JumpjetCrash.Read(exINI, GameStrings::JumpjetControls, "Crash");
pRulesExt->JumpjetNoWobbles.Read(exINI, GameStrings::JumpjetControls, "NoWobbles");

return 0;
}

// skip vanilla JumpjetControls and make it earlier load
// DEFINE_JUMP(LJMP, 0x668EB5, 0x668EBD); // RulesClass_Process_SkipJumpjetControls // Really necessary? won't hurt to read again
52 changes: 0 additions & 52 deletions src/Ext/Rules/Hooks.INIClass.cpp

This file was deleted.

45 changes: 27 additions & 18 deletions src/Phobos.INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ DEFINE_HOOK(0x5FACDF, OptionsClass_LoadSettings_LoadPhobosSettings, 0x5)
Phobos::Config::ShowHarvesterCounter = CCINIClass::INI_RA2MD->ReadBool("Phobos", "ShowHarvesterCounter", true);
Phobos::Config::ShowWeedsCounter = CCINIClass::INI_RA2MD->ReadBool("Phobos", "ShowWeedsCounter", true);

// Custom game speeds, 6 - i so that GS6 is index 0, just like in the engine
Phobos::Config::CampaignDefaultGameSpeed = 6 - CCINIClass::INI_RA2MD->ReadInteger("Phobos", "CampaignDefaultGameSpeed", 4);
if (Phobos::Config::CampaignDefaultGameSpeed > 6 || Phobos::Config::CampaignDefaultGameSpeed < 0)
{
Phobos::Config::CampaignDefaultGameSpeed = 2;
}

{
const byte temp = (byte)Phobos::Config::CampaignDefaultGameSpeed;

Patch::Apply_RAW(0x55D77A, { temp }); // We overwrite the instructions that force GameSpeed to 2 (GS4)
Patch::Apply_RAW(0x55D78D, { temp }); // when speed control is off. Doesn't need a hook.
}

Phobos::Config::ShowDesignatorRange = CCINIClass::INI_RA2MD->ReadBool("Phobos", "ShowDesignatorRange", false);

CCINIClass* pINI_UIMD = CCINIClass::LoadINIFile(GameStrings::UIMD_INI);

// LoadingScreen
Expand Down Expand Up @@ -145,25 +161,17 @@ DEFINE_HOOK(0x5FACDF, OptionsClass_LoadSettings_LoadPhobosSettings, 0x5)

CCINIClass::UnloadINIFile(pINI_UIMD);

CCINIClass* pINI_RULESMD = CCINIClass::LoadINIFile(GameStrings::RULESMD_INI);

Phobos::Config::ArtImageSwap = pINI_RULESMD->ReadBool(GameStrings::General, "ArtImageSwap", false);
return 0;
}

// Custom game speeds, 6 - i so that GS6 is index 0, just like in the engine
Phobos::Config::CampaignDefaultGameSpeed = 6 - CCINIClass::INI_RA2MD->ReadInteger("Phobos", "CampaignDefaultGameSpeed", 4);
if (Phobos::Config::CampaignDefaultGameSpeed > 6 || Phobos::Config::CampaignDefaultGameSpeed < 0)
{
Phobos::Config::CampaignDefaultGameSpeed = 2;
}
DEFINE_HOOK(0x52D21F, InitRules_ThingsThatShouldntBeSerailized, 0x6)
{
CCINIClass* const pINI_RULESMD = CCINIClass::INI_Rules;

{
const byte temp = (byte)Phobos::Config::CampaignDefaultGameSpeed;
RulesClass::Instance->Read_JumpjetControls(pINI_RULESMD);

Patch::Apply_RAW(0x55D77A, { temp }); // We overwrite the instructions that force GameSpeed to 2 (GS4)
Patch::Apply_RAW(0x55D78D, { temp }); // when speed control is off. Doesn't need a hook.
}
Phobos::Config::ArtImageSwap = pINI_RULESMD->ReadBool(GameStrings::General, "ArtImageSwap", false);

Phobos::Config::ShowDesignatorRange = CCINIClass::INI_RA2MD->ReadBool("Phobos", "ShowDesignatorRange", false);

Phobos::Misc::CustomGS = pINI_RULESMD->ReadBool(GameStrings::General, "CustomGS", false);

Expand Down Expand Up @@ -196,12 +204,13 @@ DEFINE_HOOK(0x5FACDF, OptionsClass_LoadSettings_LoadPhobosSettings, 0x5)
Patch::Apply_RAW(0x69A310, { 0x8B, 0x44, 0x24, 0x04, 0xD1, 0xE0, 0x40 });

Phobos::Config::SaveVariablesOnScenarioEnd = pINI_RULESMD->ReadBool(GameStrings::General, "SaveVariablesOnScenarioEnd", false);

CCINIClass::UnloadINIFile(pINI_RULESMD);

#ifndef DEBUG
Phobos::Config::DevelopmentCommands = pINI_RULESMD->ReadBool("GlobalControls", "DebugKeysEnabled", Phobos::Config::DevelopmentCommands);
#endif
return 0;
}


bool Phobos::ShouldQuickSave = false;
std::wstring Phobos::CustomGameSaveDescription {};

Expand Down

0 comments on commit d02081c

Please sign in to comment.