Skip to content

Commit

Permalink
UI/Lua: Show REF version (commit/tag) and APIs to obtain it
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Mar 30, 2024
1 parent 3c686e4 commit 00c0bd9
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ src/sdk/generated
cmake-build*
.idea/
build_vs2019_devmode_DMC5.bat
src/CommitHash.autogenerated
72 changes: 72 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -2577,6 +2583,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -4419,6 +4431,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -4616,6 +4634,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -4813,6 +4837,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -7479,6 +7509,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -7676,6 +7712,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -8697,6 +8739,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -9716,6 +9764,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -10737,6 +10791,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -11758,6 +11818,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down Expand Up @@ -12779,6 +12845,12 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
"${CMAKE_BINARY_DIR}/lib/${CMKR_TARGET}"
)

add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)
endif()
Expand Down
35 changes: 35 additions & 0 deletions MakeCommitHash.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@echo off

IF EXIST "src/CommitHash.autogenerated" (
echo The file "src/CommitHash.autogenerated" already exists.
exit /b 0
)

FOR /F "tokens=*" %%g IN ('git rev-parse HEAD') DO (SET REF_COMMIT_HASH=%%g)

FOR /F "tokens=*" %%t IN ('git describe --tags --abbrev^=0') DO (SET REF_TAG=%%t)

FOR /F "tokens=*" %%c IN ('git describe --tags --long') DO (
FOR /F "tokens=1,2 delims=-" %%a IN ("%%c") DO (
SET REF_TAG_LONG=%%a
SET REF_COMMITS_PAST_TAG=%%b
)
)

FOR /F "tokens=2 delims==" %%a IN ('wmic OS get localdatetime /value') DO (
SET datetime=%%a
)

SET year=%datetime:~0,4%
SET month=%datetime:~4,2%
SET day=%datetime:~6,2%
SET hour=%datetime:~8,2%
SET minute=%datetime:~10,2%

echo #pragma once > src/CommitHash.autogenerated
echo #define REF_COMMIT_HASH "%REF_COMMIT_HASH%" >> src/CommitHash.autogenerated
echo #define REF_TAG "%REF_TAG%" >> src/CommitHash.autogenerated
echo #define REF_TAG_LONG "%REF_TAG_LONG%" >> src/CommitHash.autogenerated
echo #define REF_COMMITS_PAST_TAG %REF_COMMITS_PAST_TAG% >> src/CommitHash.autogenerated
echo #define REF_BUILD_DATE "%day%.%month%.%year%" >> src/CommitHash.autogenerated
echo #define REF_BUILD_TIME "%hour%:%minute%" >> src/CommitHash.autogenerated
7 changes: 7 additions & 0 deletions cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ link-libraries = [
"DirectXTK",
"DirectXTK12"
]
cmake-after="""
add_custom_command(
TARGET ${CMKR_TARGET} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating commit hash..."
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/MakeCommitHash.bat
)
"""

[template.game.properties]
OUTPUT_NAME = "dinput8"
Expand Down
14 changes: 10 additions & 4 deletions src/REFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern "C" {
#include "LicenseStrings.hpp"
#include "mods/REFrameworkConfig.hpp"
#include "mods/IntegrityCheckBypass.hpp"
#include "CommitHash.autogenerated"
#include "REFramework.hpp"

namespace fs = std::filesystem;
Expand Down Expand Up @@ -1177,8 +1178,10 @@ void REFramework::draw_ui() {

ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_::ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(300, 500), ImGuiCond_::ImGuiCond_Once);

static const auto REF_NAME = std::format("REFramework [{}+{}-{:.8}]", REF_TAG, REF_COMMITS_PAST_TAG, REF_COMMIT_HASH);
bool is_open = true;
ImGui::Begin("REFramework", &is_open);
ImGui::Begin(REF_NAME.c_str(), &is_open);
ImGui::Text("Default Menu Key: Insert");
ImGui::Checkbox("Transparency", &m_ui_option_transparent);
ImGui::SameLine();
Expand Down Expand Up @@ -1232,10 +1235,13 @@ void REFramework::draw_about() {
ImGui::Text("Inspired by the Kanan project.");
ImGui::Text("https://github.com/praydog/REFramework");
ImGui::Text("http://praydog.com");
ImGui::Text("Commit hash: %s", std::format("{:.8}", REF_COMMIT_HASH).c_str());
ImGui::Text("Tag: %s", REF_TAG);
ImGui::Text("Commits past tag: %i", REF_COMMITS_PAST_TAG);
ImGui::Text("Build date: %s", REF_BUILD_DATE);
ImGui::Text("Build time: %s", REF_BUILD_TIME);

if (ImGui::CollapsingHeader("Licenses")) {
ImGui::TreePush("Licenses");

if (ImGui::TreeNode("Licenses")) {
struct License {
std::string name;
std::string text;
Expand Down
35 changes: 34 additions & 1 deletion src/mods/ScriptRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "bindings/Json.hpp"
#include "bindings/FS.hpp"

#include "CommitHash.autogenerated"
#include "ScriptRunner.hpp"

#include <lstate.h> // weird include order because of sol
Expand Down Expand Up @@ -75,6 +76,32 @@ sol::object get_hook_storage(sol::this_state s, size_t hash) {
}
}

namespace api::reframework {
std::string get_commit_hash() {
return REF_COMMIT_HASH;
}

std::string get_tag() {
return REF_TAG;
}

std::string get_tag_long() {
return REF_TAG_LONG;
}

std::string get_commits_past_tag() {
return std::to_string(REF_COMMITS_PAST_TAG);
}

std::string get_build_date() {
return REF_BUILD_DATE;
}

std::string get_build_time() {
return REF_BUILD_TIME;
}
}

ScriptState::ScriptState(const ScriptState::GarbageCollectionData& gc_data,bool is_main_state) {
std::scoped_lock _{ m_execution_mutex };
m_is_main_state = is_main_state;
Expand Down Expand Up @@ -321,7 +348,13 @@ ScriptState::ScriptState(const ScriptState::GarbageCollectionData& gc_data,bool
}

return sol::make_object(s, sol::lua_nil);
}
},
"get_commit_hash", api::reframework::get_commit_hash,
"get_tag", api::reframework::get_tag,
"get_tag_long", api::reframework::get_tag_long,
"get_commits_past_tag", api::reframework::get_commits_past_tag,
"get_build_date", api::reframework::get_build_date,
"get_build_time", api::reframework::get_build_time
);

m_lua["reframework"] = g_framework.get();
Expand Down

0 comments on commit 00c0bd9

Please sign in to comment.