Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime data parsing and demo accurate timer #446

Merged
merged 5 commits into from
Jul 23, 2023
Merged

Conversation

eim64
Copy link
Contributor

@eim64 eim64 commented Jun 23, 2023

Adds 2 hw.dll hooks:

  • ValidStuffText
  • CL_ReadDemoMessage_OLD

That are used to read the //BXTD0 commands and corresponding runtime data each frame. These have only been tested on latest steam version of Half-Life.

Conversion back to a vector was implemented by adding a decrypt filter and load template.
demo_data_visitor is then applied to the recovered data and should contain logic such as updating timer/health. This could arguably be part of the load template, but imo it's better for parse logic to be separate.

I currently set HwDll::executing to true whenever a demo frame is read, to make the timer resume after save/loads. This is scuffed, and the Cbuf_Execute hook should be fixed to resume in demos instead, but I dont know how to.

Can be used to resolve #294

Im using filters for consistency, and is definitely over-engineered.
Unescaping/decrypting an array would be simpler and require less code.
@eim64 eim64 marked this pull request as ready for review June 23, 2023 16:48
Copy link
Contributor

@chinese-soup chinese-soup left a comment

Choose a reason for hiding this comment

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

Good stuff.

Please add Linux hooks as well:

diff --git a/BunnymodXT/modules/HwDLL.cpp b/BunnymodXT/modules/HwDLL.cpp
index 852c73f..f683a01 100644
--- a/BunnymodXT/modules/HwDLL.cpp
+++ b/BunnymodXT/modules/HwDLL.cpp
@@ -317,6 +317,16 @@ extern "C" qboolean __cdecl CL_CheckGameDirectory(char *gamedir)
 {
 	return HwDLL::HOOKED_CL_CheckGameDirectory(gamedir);
 }
+
+extern "C" int __cdecl ValidStuffText(char *buf)
+{
+	return HwDLL::HOOKED_ValidStuffText(buf);
+}
+
+extern "C" qboolean __cdecl CL_ReadDemoMessage_OLD()
+{
+	return HwDLL::HOOKED_CL_ReadDemoMessage_OLD();
+}
 #endif
 
 void HwDLL::Hook(const std::wstring& moduleName, void* moduleHandle, void* moduleBase, size_t moduleLength, bool needToIntercept)
@@ -1021,6 +1031,18 @@ void HwDLL::FindStuff()
 		else
 			EngineDevWarning("[hw dll] Could not find CL_CheckGameDirectory.\n");
 
+		ORIG_ValidStuffText = reinterpret_cast<_ValidStuffText>(MemUtils::GetSymbolAddress(m_Handle, "ValidStuffText"));
+		if (ORIG_ValidStuffText)
+			EngineDevMsg("[hw dll] Found ValidStuffText at %p.\n", ORIG_ValidStuffText);
+		else
+			EngineDevWarning("[hw dll] Could not find ValidStuffText.\n");
+
+		ORIG_CL_ReadDemoMessage_OLD = reinterpret_cast<_CL_ReadDemoMessage_OLD>(MemUtils::GetSymbolAddress(m_Handle, "CL_ReadDemoMessage_OLD"));
+		if (ORIG_CL_ReadDemoMessage_OLD)
+			EngineDevMsg("[hw dll] Found CL_ReadDemoMessage_OLD at %p.\n", ORIG_CL_ReadDemoMessage_OLD);
+		else
+			EngineDevWarning("[hw dll] Could not find CL_ReadDemoMessage_OLD.\n");
+
 		if (!cls || !psv || !svs || !svmove || !ppmove || !host_client || !sv_player || !sv_areanodes || !cmd_text || !cmd_alias || !host_frametime || !cvar_vars || !movevars || !ORIG_SV_AddLinksToPM || !ORIG_SV_SetMoveVars)
 			ORIG_Cbuf_Execute = nullptr;

BunnymodXT/runtime_data.cpp Outdated Show resolved Hide resolved
@eim64 eim64 force-pushed the master branch 2 times, most recently from 1e9d524 to 6de14da Compare July 9, 2023 11:05
Should probably be incorporated with the save data code, to avoid repeat
Copy link
Owner

@YaLTeR YaLTeR left a comment

Choose a reason for hiding this comment

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

Hey! Sorry for taking so long to look at this, I'm just completely buried in finishing TAS editor 2.

This is indeed a valuable feature to have, and it mostly matches how I would implement it. I just have a few comments, and we need to decide what to do about executing.

BunnymodXT/runtime_data.cpp Outdated Show resolved Hide resolved
BunnymodXT/modules/HwDLL.cpp Outdated Show resolved Hide resolved
BunnymodXT/runtime_data.cpp Outdated Show resolved Hide resolved
BunnymodXT/runtime_data.cpp Outdated Show resolved Hide resolved
Adds pattern and hook for ValidStuffText, CL_ReadDemoMessage_OLD.

CL_ReadDemoMessage_OLD calls ValidStuffText to verify demo commands.
We can use this to easily retirieve //BXTD0 command data for each frame.
Adds CustomHud::SetTime.

Ensures that bxt_timer_stop and similar commands are called during
demo, and that the timer stops after game end.
@YaLTeR YaLTeR merged commit e109e80 into YaLTeR:master Jul 23, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse health from BXT runtime of current demo to use for "bxt_hud_health" command
3 participants