Skip to content

Commit

Permalink
Handle more lua <-> RED type conversions, CreateHandle now deduces ty…
Browse files Browse the repository at this point in the history
…pe automagically
  • Loading branch information
maximegmd committed Dec 22, 2020
1 parent 21d124f commit ecc3883
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 173 deletions.
14 changes: 7 additions & 7 deletions src/disable_intro_movies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Image.h"
#include <spdlog/spdlog.h>
#include "Pattern.h"
#include "reverse/REDString.h"
#include "RED4ext/REDhash.hpp"

using TInitScriptMemberVariable = void*(void* a1, void* a2, uint64_t a3, uint64_t nameHash, void* a5, void* a6, void* a7);
TInitScriptMemberVariable* RealInitScriptMemberVariable = nullptr;
Expand All @@ -17,12 +17,12 @@ void* HookInitScriptMemberVariable(void* a1, void* a2, uint64_t a3, uint64_t nam
// Ideally I think the real solution is to change GameFramework/InitialState INI variable from "Initialization" to "PreGameSession" or "MainMenu" instead
// Unfortunately that causes a black screen on launch though, likely only works properly on non-shipping builds

if (nameHash == REDString::Hash("logoTrainWBBink") ||
nameHash == REDString::Hash("logoTrainNamcoBink") ||
nameHash == REDString::Hash("logoTrainStadiaBink") ||
nameHash == REDString::Hash("logoTrainNoRTXBink") ||
nameHash == REDString::Hash("logoTrainRTXBink") ||
nameHash == REDString::Hash("introMessageBink"))
if (nameHash == RED4ext::FNV1a("logoTrainWBBink") ||
nameHash == RED4ext::FNV1a("logoTrainNamcoBink") ||
nameHash == RED4ext::FNV1a("logoTrainStadiaBink") ||
nameHash == RED4ext::FNV1a("logoTrainNoRTXBink") ||
nameHash == RED4ext::FNV1a("logoTrainRTXBink") ||
nameHash == RED4ext::FNV1a("introMessageBink"))
{
nameHash = ~nameHash;
}
Expand Down
10 changes: 5 additions & 5 deletions src/enable_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <spdlog/spdlog.h>
#include <MinHook.h>
#include "Pattern.h"
#include "reverse/REDString.h"
#include "RED4ext/REDhash.hpp"

using ScriptExecutionPointer = uint64_t;

Expand Down Expand Up @@ -32,12 +32,12 @@ void HookRegisterScriptFunction(void* a, uint64_t hash, uint64_t hash2, void* fu
{
// IsFinal (global)
// if false shows debug menu option on main menu & pause menu
if (hash == REDString::Hash("IsFinal"))
if (hash == RED4ext::FNV1a("IsFinal"))
func = &HookIsFinal;

// AreDebugContextsEnabled (global)
// unknown effect
else if (hash == REDString::Hash("AreDebugContextsEnabled"))
else if (hash == RED4ext::FNV1a("AreDebugContextsEnabled"))
func = &HookIsDebug;

RealRegisterScriptFunction(a, hash, hash2, func);
Expand All @@ -48,12 +48,12 @@ void HookRegisterScriptMemberFunction(void* a, void* parentClass, uint64_t hash,
// WorldMapMenuGameController::CanDebugTeleport
// allows using world_map_menu_debug_teleport binding on map screen to teleport
// (must be set inside r6\config\inputUserMappings.xml first)
if (hash == REDString::Hash("CanDebugTeleport"))
if (hash == RED4ext::FNV1a("CanDebugTeleport"))
func = &HookIsDebug;

// TargetShootComponent::IsDebugEnabled
// unknown effect
else if (hash == REDString::Hash("IsDebugEnabled"))
else if (hash == RED4ext::FNV1a("IsDebugEnabled"))
func = &HookIsDebug;

RealRegisterScriptMemberFunction(a, parentClass, hash, hash2, func, flag);
Expand Down
1 change: 0 additions & 1 deletion src/options_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <sstream>
#include "Options.h"
#include "Pattern.h"
#include "reverse/REDString.h"
#include "reverse/GameOptions.h"

bool HookGameOptionGetBoolean(GameOption* apThis, uint8_t* apVariable, GameOptionType aType)
Expand Down
12 changes: 6 additions & 6 deletions src/overlay/Overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include "imgui_impl_dx12.h"
#include "imgui_impl_win32.h"
#include "RED4ext/REDreverse/CString.hpp"
#include "reverse/Engine.h"
#include "reverse/REDString.h"
#include "reverse/Scripting.h"

static std::shared_ptr<Overlay> s_pOverlay;
Expand Down Expand Up @@ -90,7 +90,7 @@ void Overlay::DrawImgui(IDXGISwapChain3* apSwapChain)
ImGui::SetItemDefaultFocus();
if (execute)
{
Get().Log(command);
Get().Log(std::string("> ") + command);

Scripting::Get().ExecuteLua(command);

Expand Down Expand Up @@ -172,7 +172,7 @@ TScriptCall** GetScriptCallArray()

void Overlay::HookLog(ScriptContext* apContext, ScriptStack* apStack, void*, void*)
{
REDString text("");
RED4ext::REDreverse::CString text("");
apStack->unk30 = nullptr;
apStack->unk38 = nullptr;
auto opcode = *(apStack->m_code++);
Expand Down Expand Up @@ -221,7 +221,7 @@ void Overlay::HookLogChannel(ScriptContext* apContext, ScriptStack* apStack, voi
opcode = *(apStack->m_code++);
GetScriptCallArray()[opcode](apStack->m_context, apStack, &channel_hash, nullptr);

REDString text("");
RED4ext::REDreverse::CString text("");
apStack->unk30 = nullptr;
apStack->unk38 = nullptr;
opcode = *(apStack->m_code++);
Expand Down Expand Up @@ -267,8 +267,8 @@ void Overlay::HookTDBIDToStringDEBUG(ScriptContext* apContext, ScriptStack* apSt
tdbid_value.hash, tdbid_value.unk4)
: fmt::format("<TDBID:{:08X}:{:02X}:{:04X}:{:02X}>",
tdbid_value.hash, tdbid_value.unk4, tdbid_value.unk5, tdbid_value.unk7);
REDString s(tdbid_debug.c_str());
((REDString*)result)->Copy(&s);
RED4ext::REDreverse::CString s(tdbid_debug.c_str());
static_cast<RED4ext::REDreverse::CString*>(result)->Copy(&s);
s.Destroy();
}
}
Expand Down
1 change: 0 additions & 1 deletion src/overlay/Overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

struct ScriptContext;
struct ScriptStack;
struct REDString;

using TPresentD3D12 = long(IDXGISwapChain3* pSwapChain, UINT SyncInterval, UINT Flags);
using TSetMousePosition = BOOL(void* apThis, HWND Wnd, long X, long Y);
Expand Down
2 changes: 1 addition & 1 deletion src/overlay/Overlay_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void Overlay::EarlyHooks(Image* apImage)
spdlog::error("\tCould not hook LogChannel function!");
}
else
spdlog::info("\LogChannel function hook complete!");
spdlog::info("\tLogChannel function hook complete!");
}

pLocation = FindSignature({
Expand Down
13 changes: 13 additions & 0 deletions src/reverse/BasicTypes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "BasicTypes.h"

#include "RED4ext/REDreverse/CName.hpp"

std::string Quaternion::ToString() const noexcept
{
return "Quaternion{ x: " + std::to_string(x) + " y: " + std::to_string(y) + " z: " + std::to_string(z) + " w: " + std::to_string(w) + " }";
}

std::string CName::ToString() const noexcept
{
return "CName{ hash: " + std::to_string(hash) + " - '" + RED4ext::REDreverse::CName::ToString(hash) + "' }";
}
33 changes: 33 additions & 0 deletions src/reverse/BasicTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#include <string>

namespace RED4ext {
namespace REDreverse {
namespace Scripting {
struct IScriptable;
}
}
}

struct Quaternion
{
float x;
float y;
float z;
float w;

std::string ToString() const noexcept;
};

struct StrongHandle
{
RED4ext::REDreverse::Scripting::IScriptable* handle;
uint32_t* refCount;
};

struct CName
{
uint64_t hash;

std::string ToString() const noexcept;
};
4 changes: 1 addition & 3 deletions src/reverse/GameOptions.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "Engine.h"

#include <string>
#include <spdlog/spdlog.h>
#include <sstream>

#include "GameOptions.h"
#include "overlay/Overlay.h"
#include "REDString.h"
#include "RED4ext/REDreverse/CString.hpp"

static std::vector<GameOption*> s_gameOptions;

Expand Down
8 changes: 6 additions & 2 deletions src/reverse/GameOptions.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#pragma once
#include <vector>

class REDString;
namespace RED4ext {
namespace REDreverse {
struct CString;
}
}

enum class GameOptionType : uint8_t
{
Expand All @@ -28,7 +32,7 @@ struct GameOption
bool* pBoolean;
int32_t* pInteger;
float* pFloat;
REDString* pString;
RED4ext::REDreverse::CString* pString;
};

union
Expand Down
56 changes: 0 additions & 56 deletions src/reverse/REDString.cpp

This file was deleted.

45 changes: 0 additions & 45 deletions src/reverse/REDString.h

This file was deleted.

Loading

0 comments on commit ecc3883

Please sign in to comment.