Skip to content

Commit

Permalink
Fixed crash due to vector allocation on the stack within a game type
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWichelmann committed Dec 26, 2017
1 parent 77e417d commit 4752c5b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
4 changes: 2 additions & 2 deletions AoETechTree/AoETechTree.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>v141_xp</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>v141_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand Down
11 changes: 10 additions & 1 deletion AoKHBlacksmith.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ A modded sample empires2_x1_p1.dat is in the "DATA" folder. "Editor" contains a


[b]Requirements[/b]
The tech tree view itself was built with Microsoft Visual Studio 2015, so you'll need [url=https://www.microsoft.com/de-de/download/details.aspx?id=48145]the appropiate Visual C++ redistributable[/url].
The tech tree view itself was built with Microsoft Visual Studio 2017, so you'll need [url=https://go.microsoft.com/fwlink/?LinkId=746572]the appropiate Visual C++ redistributable[/url].

The editor depends on the .NET Framework 4.5. It should already be installed on current windows systems; if not, you can find it [url=https://www.microsoft.com/en-us/download/details.aspx?id=30653]here[/url].

Expand All @@ -45,6 +45,15 @@ This software is published under the MIT/X11 license. Please read the LICENSE fo

[b]Updates[/b]

[u]1.2.4[/u]
View:
- Fixed crash when opening the tech tree during a game (thanks to danielpereira for reporting it and providing test data)
- Updated to Visual Studio 2017 -> the required redistributable changed, see above for a link

[u]1.2.3[/u]
Editor:
- Fixed a crash when opening DAT files with modified terrain data

[u]1.2.2[/u]
- Added configurable legend labels for the recently introduced custom node background types (thanks to Bala Arizalu for the idea!)

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You can edit it with this tool: https://github.com/Janworks/AoETechTreeTool

If you want to do more modding than just changing the tech tree view itself, use the TechTreeEditor, which also exports the new tech tree format: https://github.com/Janworks/TechTreeEditor

I created this software while working on the (german) Agearena AddOn (http://www.agearena.de/forum/index.php?mode=viewforum&forum_id=7) and will update it periodically.
I created this software while working on the (german) Agearena AddOn (https://agearena.de/forum/viewtopic.php?f=6&t=1014) and will update it periodically.


## USAGE
Expand All @@ -28,9 +28,9 @@ For mod developers using their own Games/[MODNAME] subfolder, the call may be:

## SYSTEM REQUIREMENTS

As this software is build with Microsoft Visual Studio 2015, you'll need the appropiate Visual C++ redistributable: (https://www.microsoft.com/de-de/download/details.aspx?id=48145)
As this software is build with Microsoft Visual Studio 2017, you'll need the appropiate Visual C++ redistributable: (https://go.microsoft.com/fwlink/?LinkId=746572)

This software was tested with the UserPatch v1.4 installed, so there should be no incompabilities.
This software was tested with the UserPatch v1.4 installed, so there should not be any incompabilities.

Also some virus scanners may have problems with this software, as it uses DLL injection to patch the running Age of Empires II process. This method is also used by many viruses, so some virus scanners block it by default. If you have problems running this software, try to create an exception in the scanner's filter rules.

Expand All @@ -39,5 +39,5 @@ Also some virus scanners may have problems with this software, as it uses DLL in

This software is published under the MIT/X11 license. Please read the LICENSE for further information.

The general approach to do a DLL injection ist based on the Code-Project article "A More Complete DLL Injection Solution Using CreateRemoteThread" (http://www.codeproject.com/Articles/20084/A-More-Complete-DLL-Injection-Solution-Using-Creat).
The general approach to do a DLL injection is based on the Code-Project article "A More Complete DLL Injection Solution Using CreateRemoteThread" (http://www.codeproject.com/Articles/20084/A-More-Complete-DLL-Injection-Solution-Using-Creat).
I would like to thank the author for his detailed explanations and examples and recommend this article to everybody who wants to get a deeper understanding of how a DLL injection is performed.
4 changes: 2 additions & 2 deletions TechTree/TechTree.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>v141_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>v141_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
28 changes: 23 additions & 5 deletions TechTree/TechTreeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ TechTreeWindow *TechTreeWindow::Constructor(Window *underlyingWindow, int unknow
static_cast<LabelControlVTable *>(_legendResearchedLabel->_VTable)->AssignTextFromLanguageDlls(_legendResearchedLabel, 20128);

// Create node type labels
_legendNodeTypeLabels = new std::vector<LabelControl *>();
int nodeTypeLabelCount = _renderer->GetLegendNodeTypeCount();
for(int i = 0; i < nodeTypeLabelCount; ++i)
{
Expand All @@ -188,7 +189,7 @@ TechTreeWindow *TechTreeWindow::Constructor(Window *underlyingWindow, int unknow
legendNodeTypeLabel->SetStyleText2Colors(0, 0);
legendNodeTypeLabel->sub_545D70(0);
static_cast<LabelControlVTable *>(legendNodeTypeLabel->_VTable)->AssignTextFromLanguageDlls(legendNodeTypeLabel, _renderer->GetLegendNodeTypeLabelDllId(i));
_legendNodeTypeLabels.push_back(legendNodeTypeLabel);
_legendNodeTypeLabels->push_back(legendNodeTypeLabel);
}

// Create "Disabled" label
Expand Down Expand Up @@ -330,10 +331,27 @@ void TechTreeWindow::Destructor()
_scrollRightButton = nullptr;
delete _arrowSlp;

// Destroy various labels
// Delete node type legend labels
int nodeTypeLabelCount = _legendNodeTypeLabels->size();
for(int i = 0; i < nodeTypeLabelCount; ++i)
delete _legendNodeTypeLabels->at(i);
delete _legendNodeTypeLabels;

// Destroy various controls
delete _civBonusLabel;
_civBonusLabel = nullptr;
// TODO A few are missing...
delete _civSelectionComboBox;
_civSelectionComboBox = nullptr;
delete _gameCivsLabel;
_gameCivsLabel = nullptr;
delete _legendNotResearchedLabel;
_legendNotResearchedLabel = nullptr;
delete _legendResearchedLabel;
_legendResearchedLabel = nullptr;
delete _legendDisabledLabel;
_legendDisabledLabel = nullptr;
delete _popupLabel;
_popupLabel = nullptr;

// Remove underlying window reference
_underlyingWindow = nullptr;
Expand Down Expand Up @@ -623,11 +641,11 @@ void TechTreeWindow::ApplyScrollOffset(int horizontalScrollOffset, int verticalS
legendResearchedLabelRectangle->Height);

// Update legend label positions
for(int i = 0; i < _legendNodeTypeLabels.size(); ++i)
for(int i = 0; i < _legendNodeTypeLabels->size(); ++i)
{
// Get rectangle and update position
const Rect *currLegendLabelRectangle = _renderer->GetLegendNodeTypeLabelRectangle(i);
_legendNodeTypeLabels[i]->UpdatePositionAndSizeData(
_legendNodeTypeLabels->at(i)->UpdatePositionAndSizeData(
currLegendLabelRectangle->X - _horizontalScrollOffset,
currLegendLabelRectangle->Y - _verticalScrollOffset,
currLegendLabelRectangle->Width,
Expand Down
3 changes: 2 additions & 1 deletion TechTree/TechTreeWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class TechTreeWindow : public Window
LabelControl *_legendResearchedLabel;

// The node type legend labels.
std::vector<LabelControl *> _legendNodeTypeLabels;
// Is allocated on the heap, since this class is derived from an ingame object -> no stack allocation of complex types.
std::vector<LabelControl *> *_legendNodeTypeLabels;

// The "Disabled" legend label.
LabelControl *_legendDisabledLabel;
Expand Down

0 comments on commit 4752c5b

Please sign in to comment.