Skip to content

Reimplement 18 functions that differ from the original only in symbol names - #408

Open
6and8 wants to merge 5 commits into
sourcehold:mainfrom
6and8:pr-counted-100
Open

6and8 wants to merge 5 commits into
sourcehold:mainfrom
6and8:pr-counted-100

Conversation

@6and8

@6and8 6and8 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Reimplements 18 functions whose code matches the original instruction for instruction. reccmp reports them at 80-99.9% because it cannot name some symbols in the original (the exe has no relocations), so their status lines carry a counted: remark that names what differs:

  • Global: DetectDXVersionByLoadingDDRAW (GetProcAddress import name), TestOSVersion (security cookie, memset)
  • Synchrony: InitSkirmishLobbyData (memset)
  • Map::Entities: SomeFireSpreadFunction (the constant 0x10300131 happens to look like an address in our DLL), EntityState::createSeagull and EntityState::computeVelocity (float constant names, _CIsin/_CIcos/_CItan/_CIsqrt, _ftol2_sse)
  • Map::MapPropertiesState: setStartingYearAndStartingResources and updateEventYearsAndCommitBuildingAvailability (security cookie), updateMilitaryCampaignMissionState (its two tail jumps to MouseState::resetMouseCursorState go through that function's trampoline)
  • UI::MenuItems: General_AdvancedGameOptions, SiegeAttackingForceAndStartGoods_Main, NewInvasion_UnitButtons, TriggerInvasion_Main, WaitingForHost_ConnectToLobby, FindingNetworkSessions_Buttons (callback trampolines, sprintf, jump-table labels, security cookie)
  • UI::MenuViews: HistoricCampaignIntro_DoEveryFrame, HistoricCampaignOutro_DoEveryFrame, HistoricMissionPicture_DoEveryFrame (float constant names, _ftol2_sse, a string label)

Where a pushed or compared value is shown as a raw number on one side, I checked it against the original exe's bytes: AdvancedGameOptions pushes 0xB8E6F5 in both, and the string HistoricCampaignIntro pushes is fx\speech\intro_04.wav in both.

No header changes. The only status lines touched are these 18.

Checked with a build of this branch on top of main, containing every source file of the touched folders plus the /GL callees they reach (74 files): in all 18 the remaining differences are symbol names only, with the same per-function numbers as in my full build. Main's own functions in the build keep their scores.

🤖 Generated with Claude Code

… names

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

17 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 10 of the 18 reimplemented .cpp file(s) in this PR.

The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.

rule what it asks hits
14 The shape of a file 6
20 Keep nesting low; no goto 5
23 Prefer if-else over ternary 6
Where

Rule 14 — The shape of a file

  • src/OpenSHC/Map/MapPropertiesState/updateMilitaryCampaignMissionState.cpp:1 — first include is not MapPropertiesState; the folder is the class
  • src/OpenSHC/UI/MenuItems/FindingNetworkSessions/MenuItemActionHandler_FindingNetworkSessions_Buttons.cpp:1 — first include is not FindingNetworkSessions; the folder is the class
  • src/OpenSHC/UI/MenuItems/WaitingForHost/MenuItemActionHandler_WaitingForHost_ConnectToLobby.cpp:1 — first include is not WaitingForHost; the folder is the class
  • src/OpenSHC/UI/MenuViews/HistoricCampaignIntro/MenuView_HistoricCampaignIntro_DoEveryFrame.cpp:1 — first include is not HistoricCampaignIntro; the folder is the class
  • src/OpenSHC/UI/MenuViews/HistoricCampaignOutro/MenuView_HistoricCampaignOutro_DoEveryFrame.cpp:1 — first include is not HistoricCampaignOutro; the folder is the class
  • src/OpenSHC/UI/MenuViews/HistoricMissionPicture/MenuView_HistoricMissionPicture_DoEveryFrame.cpp:1 — first include is not HistoricMissionPicture; the folder is the class

Rule 20 — Keep nesting low; no goto

  • src/OpenSHC/Map/MapPropertiesState/updateMilitaryCampaignMissionState.cpp:159 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/MapPropertiesState/updateMilitaryCampaignMissionState.cpp:251 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/MapPropertiesState/updateMilitaryCampaignMissionState.cpp:320 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/MapPropertiesState/updateMilitaryCampaignMissionState.cpp:395 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/MapPropertiesState/updateMilitaryCampaignMissionState.cpp:494 — goto; check how many predecessors the target has first

Rule 23 — Prefer if-else over ternary

  • src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_AdvancedGameOptions.cpp:177 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_AdvancedGameOptions.cpp:219 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/UI/MenuItems/NewInvasion/MenuItemActionHandler_NewInvasion_UnitButtons.cpp:31 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/UI/MenuItems/SiegeAttackingForceAndStartGoods/MenuItemActionHandler_SiegeAttackingForceAndStartGoods_Main.cpp:62 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/UI/MenuItems/SiegeAttackingForceAndStartGoods/MenuItemActionHandler_SiegeAttackingForceAndStartGoods_Main.cpp:89 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/UI/MenuItems/TriggerInvasion/MenuItemActionHandler_TriggerInvasion_Main.cpp:29 — ternary; the guide prefers extending the if-else chain

&& DAT_GameState::instance.mapAndTime.year == DAT_GameState::instance.mapAndTime.yearCopy)
|| DAT_GameState::instance.mapAndTime.year > DAT_GameState::instance.mapAndTime.yearCopy) {
DAT_GameState::instance.mapAndTime.militaryCampaignStage = 5;
goto missionWon;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is highly unlikely the original developers wrote a goto. Can you find a source code form without the goto? Usually code duplication or moving around the arms of the function works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: a missionWon flag replaces the five gotos, and the win block runs after the mission chain. MSVC threads the constant flag back into the same jumps, so the score is unchanged (99.9%, only the trampoline label).

@TheRedDaemon TheRedDaemon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, only three or four types of remarks.

loamifi-jake and others added 3 commits November 15, 2026 20:47
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tring literals for the speech files, enum names for text groups and the option colour, no goto in updateMilitaryCampaignMissionState

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 16, 2026

@TheRedDaemon TheRedDaemon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks even better. Only two small things left from my side.


#include "../General.func.hpp"

#pragma warning(disable : 4996)

@TheRedDaemon TheRedDaemon Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pragma please at the top of everything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, the pragma is the first line now.

@@ -172,15 +174,15 @@ namespace UI {
(Commands::GameCommandType)52);
sprintf(DAT_GameSynchronyState::instance.receivedChatMessage, "%s :%s",

@TheRedDaemon TheRedDaemon Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this string here (multiple times used in this file) possibly contained in string-literals?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is s__s__s_005a228c; all 18 uses in the file take it now.

… format string from string-literals

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

declaration/type change This requires changes to the generated/exported types or definitions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants