Skip to content

Commit fce4740

Browse files
committed
only set var value once in binds
fix stack trace crashing the game output current time in crash/fail log
1 parent 68c1d05 commit fce4740

20 files changed

Lines changed: 116 additions & 82 deletions

Amalgam/Amalgam.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@
10781078
<ClCompile Include="src\SDK\Helpers\TraceFilters\TraceFilters.cpp" />
10791079
<ClCompile Include="src\SDK\SDK.cpp" />
10801080
<ClCompile Include="src\SDK\Helpers\ConVars\ConVars.cpp" />
1081-
<ClCompile Include="src\Utils\CrashLog\CrashLog.cpp" />
1081+
<ClCompile Include="src\Utils\ErrorLog\ErrorLog.cpp" />
10821082
<ClCompile Include="src\Utils\Hooks\Hooks.cpp" />
10831083
<ClCompile Include="src\Utils\Interfaces\Interfaces.cpp" />
10841084
<ClCompile Include="src\Utils\KeyHandler\KeyHandler.cpp" />
@@ -1458,7 +1458,7 @@
14581458
<ClInclude Include="src\SDK\SDK.h" />
14591459
<ClInclude Include="src\SDK\Vars.h" />
14601460
<ClInclude Include="src\SDK\Helpers\ConVars\ConVars.h" />
1461-
<ClInclude Include="src\Utils\CrashLog\CrashLog.h" />
1461+
<ClInclude Include="src\Utils\ErrorLog\ErrorLog.h" />
14621462
<ClInclude Include="src\Utils\Macros\Macros.h" />
14631463
<ClInclude Include="src\Utils\Hash\FNV1A.h" />
14641464
<ClInclude Include="src\Utils\Hooks\Hooks.h" />

Amalgam/Amalgam.vcxproj.filters

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<ClCompile Include="src\SDK\Definitions\Misc\ChecksumCRC.cpp" />
8383
<ClCompile Include="src\Hooks\Direct3DDevice9.cpp" />
8484
<ClCompile Include="src\SDK\Events\Events.cpp" />
85-
<ClCompile Include="src\Utils\CrashLog\CrashLog.cpp" />
85+
<ClCompile Include="src\Utils\ErrorLog\ErrorLog.cpp" />
8686
<ClCompile Include="src\BytePatches\BytePatches.cpp" />
8787
<ClCompile Include="include\ImGui\imgui_freetype.cpp" />
8888
<ClCompile Include="src\Features\Misc\AutoVote\AutoVote.cpp" />
@@ -458,7 +458,7 @@
458458
<ClInclude Include="src\SDK\Definitions\Main\CCaptureFlag.h" />
459459
<ClInclude Include="src\SDK\Definitions\Interfaces\IPanel.h" />
460460
<ClInclude Include="src\SDK\Definitions\Interfaces\CTFGCClientSystem.h" />
461-
<ClInclude Include="src\Utils\CrashLog\CrashLog.h" />
461+
<ClInclude Include="src\Utils\ErrorLog\ErrorLog.h" />
462462
<ClInclude Include="src\BytePatches\BytePatches.h" />
463463
<ClInclude Include="include\freetype\config\ftconfig.h" />
464464
<ClInclude Include="include\freetype\config\ftheader.h" />

Amalgam/src/Core/Core.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,44 @@ static inline bool CheckDXLevel()
3131
auto mat_dxlevel = H::ConVars.FindVar("mat_dxlevel");
3232
if (mat_dxlevel->GetInt() < 90)
3333
{
34-
//const char* sMessage = "You are running with graphics options that Amalgam does not support. -dxlevel must be at least 90.";
35-
const char* sMessage = "You are running with graphics options that Amalgam does not support. It is recommended for -dxlevel to be at least 90.";
34+
/*
35+
const char* sMessage = "You are running with graphics options that Amalgam does not support. -dxlevel must be at least 90.";
3636
U::Core.AppendFailText(sMessage);
3737
SDK::Output("Amalgam", sMessage, { 175, 150, 255 }, OUTPUT_CONSOLE | OUTPUT_DEBUG | OUTPUT_TOAST | OUTPUT_MENU);
38-
//return false;
38+
return false;
39+
*/
40+
41+
const char* sMessage = "You are running with graphics options that Amalgam does not support. It is recommended for -dxlevel to be at least 90.";
42+
SDK::Output("Amalgam", sMessage, { 175, 150, 255 }, OUTPUT_CONSOLE | OUTPUT_DEBUG | OUTPUT_TOAST | OUTPUT_MENU);
3943
}
4044

4145
return true;
4246
}
4347

4448
void CCore::AppendFailText(const char* sMessage)
4549
{
50+
if (m_ssFailStream.str().empty())
51+
{
52+
m_ssFailStream << "Built @ " __DATE__ ", " __TIME__ ", " __CONFIGURATION__ "\n";
53+
m_ssFailStream << std::format("Time @ {}, {}\n", SDK::GetDate(), SDK::GetTime());
54+
m_ssFailStream << "\n";
55+
}
56+
4657
m_ssFailStream << std::format("{}\n", sMessage);
4758
OutputDebugStringA(std::format("{}\n", sMessage).c_str());
4859
}
4960

5061
void CCore::LogFailText()
5162
{
52-
m_ssFailStream << "\nBuilt @ " __DATE__ ", " __TIME__ ", " __CONFIGURATION__ "\n";
53-
m_ssFailStream << "Ctrl + C to copy. \n";
5463
try
5564
{
5665
std::ofstream file;
5766
file.open(F::Configs.m_sConfigPath + "fail_log.txt", std::ios_base::app);
5867
file << m_ssFailStream.str() + "\n\n\n";
5968
file.close();
69+
70+
m_ssFailStream << "\n";
71+
m_ssFailStream << "Ctrl + C to copy. \n";
6072
m_ssFailStream << "Logged to Amalgam\\fail_log.txt. ";
6173
}
6274
catch (...) {}

Amalgam/src/DllMain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#include <Windows.h>
22
#include "Core/Core.h"
3-
#include "Utils/CrashLog/CrashLog.h"
3+
#include "Utils/ErrorLog/ErrorLog.h"
44

55
DWORD WINAPI MainThread(LPVOID lpParam)
66
{
7-
U::CrashLog.Initialize(lpParam);
7+
U::ErrorLog.Initialize(lpParam);
88

99
U::Core.Load();
1010
U::Core.Loop();
1111
U::Core.Unload();
1212

13-
U::CrashLog.Unload();
13+
U::ErrorLog.Unload();
1414

1515
FreeLibraryAndExitThread(static_cast<HMODULE>(lpParam), EXIT_SUCCESS);
1616
}

Amalgam/src/Features/Binds/Binds.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ static inline void SetMain(BaseVar*& pBase, int iBind)
1616
}
1717
#define Set(t, b) if (IsType(t)) SetMain<t>(pBase, b);
1818

19+
static std::unordered_map<BaseVar*, bool> s_mVars = {};
20+
1921
static inline void LoopVars(int iBind, std::vector<BaseVar*>& vVars = G::Vars)
2022
{
2123
const bool bDefault = iBind == DEFAULT_BIND;
2224
for (auto pBase : vVars)
2325
{
24-
if (pBase->m_iFlags & (NOSAVE | NOBIND) && !bDefault)
26+
if (s_mVars.contains(pBase) || pBase->m_iFlags & (NOSAVE | NOBIND) && !bDefault)
2527
continue;
2628

29+
s_mVars[pBase];
2730
Set(bool, iBind)
2831
else Set(int, iBind)
2932
else Set(float, iBind)
@@ -44,7 +47,7 @@ static inline void GetBinds(int iParent, CTFPlayer* pLocal, CTFWeaponBase* pWeap
4447
if (vBinds.empty())
4548
return;
4649

47-
for (int i = int(vBinds.size() - 1); i >= 0; i--) // reverse so higher binds have priority over vars
50+
for (int i = 0; i < vBinds.size(); i++)
4851
{
4952
auto& tBind = vBinds[i];
5053
if (iParent != tBind.m_iParent || !tBind.m_bEnabled)
@@ -130,8 +133,9 @@ static inline void GetBinds(int iParent, CTFPlayer* pLocal, CTFWeaponBase* pWeap
130133

131134
void CBinds::SetVars(CTFPlayer* pLocal, CTFWeaponBase* pWeapon, bool bManage)
132135
{
133-
LoopVars(DEFAULT_BIND);
136+
s_mVars.clear();
134137
GetBinds(DEFAULT_BIND, pLocal, pWeapon, m_vBinds, bManage);
138+
LoopVars(DEFAULT_BIND);
135139
}
136140

137141
void CBinds::Run()

Amalgam/src/Features/Commands/Commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static std::unordered_map<uint32_t, CommandCallback> s_mCommands = {
6969
}
7070
},
7171
{
72-
FNV1A::Hash32Const("clearchat"),
72+
FNV1A::Hash32Const("clear_chat"),
7373
[](const std::deque<const char*>& vArgs)
7474
{
7575
I::ClientModeShared->m_pChatElement->SetText("");

Amalgam/src/Features/ImGui/Menu/Menu.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ void CMenu::MenuLogs(int iTab)
12441244
{
12451245
if (I::EngineClient->IsInGame())
12461246
{
1247-
std::lock_guard lock(F::PlayerUtils.m_mutex);
1247+
std::lock_guard tLock(m_tMutex);
12481248
const auto& vPlayers = F::PlayerUtils.m_vPlayerCache;
12491249

12501250
std::unordered_map<uint64_t, std::vector<const ListPlayer*>> mParties = {};
@@ -2462,9 +2462,11 @@ void CMenu::MenuSettings(int iTab)
24622462

24632463
drawConfigs(sStaticName);
24642464
} EndSection();
2465-
SetCursorPosX(GetCursorPosX() + 8);
24662465
PushStyleColor(ImGuiCol_Text, F::Render.Inactive.Value);
2466+
SetCursorPosX(GetCursorPosX() + GetStyle().WindowPadding.x);
24672467
FText("Built @ " __DATE__ ", " __TIME__ ", " __CONFIGURATION__);
2468+
//SetCursorPosX(GetCursorPosX() + GetStyle().WindowPadding.x);
2469+
//FText(std::format("Time @ {}, {}", SDK::GetDate(), SDK::GetTime()).c_str());
24682470
PopStyleColor();
24692471

24702472
/* Column 2 */
@@ -2585,7 +2587,7 @@ void CMenu::MenuSettings(int iTab)
25852587
if (iParent != _tBind.m_iParent || mBinds.contains(_iBind))
25862588
continue;
25872589

2588-
mBinds[_iBind] = true;
2590+
mBinds[_iBind];
25892591

25902592
i++;
25912593
//if (iParent == iLayer && iNumber >= i)
@@ -2628,7 +2630,7 @@ void CMenu::MenuSettings(int iTab)
26282630
if (iParent != DEFAULT_BIND - 1 && iParent != _tBind.m_iParent || mBinds.contains(_iBind))
26292631
continue;
26302632

2631-
mBinds[_iBind] = true;
2633+
mBinds[_iBind];
26322634

26332635
std::string sType; std::string sInfo;
26342636
switch (_tBind.m_iType)

Amalgam/src/Features/ImGui/Menu/Menu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "../../../SDK/SDK.h"
33
#include "../Render.h"
44
#include <ImGui/TextEditor.h>
5+
#include <mutex>
56

67
struct Output_t
78
{
@@ -38,6 +39,8 @@ class CMenu
3839
bool m_bIsOpen = false;
3940
bool m_bInKeybind = false;
4041
bool m_bWindowHovered = false;
42+
43+
std::mutex m_tMutex;
4144
};
4245

4346
ADD_FEATURE(CMenu, Menu);

Amalgam/src/Features/Players/PlayerUtils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "PlayerUtils.h"
22

3-
#include "../../SDK/Definitions/Types.h"
3+
#include "../ImGui/Menu/Menu.h"
44
#include "../Output/Output.h"
5+
#include "../../SDK/Definitions/Types.h"
56

67
uint32_t CPlayerlistUtils::GetAccountID(int iIndex)
78
{
@@ -433,8 +434,9 @@ void CPlayerlistUtils::Store()
433434
if (!tTimer.Run(1.f))
434435
return;
435436

436-
std::lock_guard lock(m_mutex);
437+
std::lock_guard tLock(F::Menu.m_tMutex);
437438
m_vPlayerCache.clear();
439+
438440
auto pResource = H::Entities.GetResource();
439441
if (!pResource)
440442
return;

Amalgam/src/Features/Players/PlayerUtils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22
#include "../../SDK/SDK.h"
3-
#include <mutex>
43

54
#define DEFAULT_TAG 0
65
#define IGNORED_TAG (DEFAULT_TAG-1)
@@ -60,8 +59,6 @@ class CPlayerlistUtils
6059
bool m_bLoad = true;
6160
bool m_bSave = false;
6261

63-
std::mutex m_mutex;
64-
6562
private:
6663
std::vector<int> m_vDummy = {};
6764

0 commit comments

Comments
 (0)