Skip to content

Commit

Permalink
More misc classes, GameSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
expired6978 committed Sep 19, 2023
1 parent d4e7645 commit 274d2b8
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 9 deletions.
1 change: 1 addition & 0 deletions sfse/GameChargen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "sfse/GameChargen.h"
25 changes: 25 additions & 0 deletions sfse/GameChargen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "sfse/GameUI.h"
#include "sfse/GameSingleton.h"
#include "sfse_common/Relocation.h"
#include "sfse_common/Utilities.h"

namespace TESNPCData
{
class ChargenDataModel : public IDataModel, public BSTSingletonSDM<ChargenDataModel>
{
public:
virtual ~ChargenDataModel();

static ChargenDataModel* GetSingleton()
{
RelocPtr<ChargenDataModel*> singleton(0x58F7EF8);
return *singleton;
}

// Contains main UI data model wrappers, decode these later
// This function will pull data from the TESNPC into this wrapper
DEFINE_MEMBER_FN_2(Update, void, 0x01890E98, TESNPC*, void* unk2); // Unk2 looks like somekind of restore point, is usually CharGenMenu+0x2D0
};
}
2 changes: 1 addition & 1 deletion sfse/GameConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void Console_Print(const char* fmt, ...)
va_list args;
va_start(args, fmt);

CALL_MEMBER_FN(mgr, VPrint)(fmt, args);
mgr->VPrint(fmt, args);

va_end(args);
}
Expand Down
3 changes: 1 addition & 2 deletions sfse/GameConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
class ConsoleLog
{
public:
MEMBER_FN_PREFIX(ConsoleLog);
DEFINE_MEMBER_FN(VPrint, void, 0x02883978, const char* fmt, va_list args);
DEFINE_MEMBER_FN_2(VPrint, void, 0x02883978, const char* fmt, va_list args);
};

extern RelocPtr <ConsoleLog*> g_console;
Expand Down
2 changes: 2 additions & 0 deletions sfse/GameObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,7 @@ class TESNPC :
u64 unk478; // 478
u8 unk480; // 480
u8 pad481[7]; // 481

DEFINE_MEMBER_FN_1(DeriveGeneticParentAppearance, void, 0x1B284E8, TESNPC* source);
};
static_assert(sizeof(TESNPC) == 0x488);
18 changes: 14 additions & 4 deletions sfse/GameReferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,9 @@ class TESObjectREFR : public TESForm
u8 unk10A; // 10A
u8 unk10B; // 10B

MEMBER_FN_PREFIX(TESObjectREFR);
DEFINE_MEMBER_FN(IsInSpaceship, bool, 0x02B3A714)
DEFINE_MEMBER_FN(IsInSpace, bool, 0x01A0E1C8)
DEFINE_MEMBER_FN(HasKeyword, bool, 0x0139EDB8, BGSKeyword*);
DEFINE_MEMBER_FN_0(IsInSpaceship, bool, 0x02B3A714)
DEFINE_MEMBER_FN_0(IsInSpace, bool, 0x01A0E1C8)
DEFINE_MEMBER_FN_1(HasKeyword, bool, 0x0139EDB8, BGSKeyword*);
};
static_assert(sizeof(TESObjectREFR) == 0x110);

Expand Down Expand Up @@ -382,6 +381,17 @@ class Actor : public TESObjectREFR
virtual void Unk_1A1(); // 1A1

// More...
DEFINE_MEMBER_FN_0(UpdateChargenAppearance, void, 0x02B3A714); // Only seems to work in CharGenMenu?

// This function is very slow, do not use for realtime updates, mainly used for "entire character changed"
// The fields represent which subsets of chargen to update, usually you want (false, 0x28, false)
DEFINE_MEMBER_FN_3(UpdateAppearance, void, 0x24A93EC, bool unk1, u32 flags, bool unk3);
};

class MenuActor : public Actor
{
public:
virtual ~MenuActor();
};

//inline RelocPtr<Actor*> g_playerCharacter(0x05595BA8);
1 change: 1 addition & 0 deletions sfse/GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
decltype(SettingT<INISettingCollection>::pCollection) SettingT<INISettingCollection>::pCollection(0x05913B98);
decltype(SettingT<INIPrefSettingCollection>::pCollection) SettingT<INIPrefSettingCollection>::pCollection(0x05913BB8);
decltype(SettingT<RegSettingCollection>::pCollection) SettingT<RegSettingCollection>::pCollection(0x059127A8);
decltype(SettingT<GameSettingCollection>::pCollection) SettingT<GameSettingCollection>::pCollection(0x058F50B8);

u32 Setting::GetType(void) const
{
Expand Down
31 changes: 29 additions & 2 deletions sfse/GameSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "sfse_common/Types.h"
#include "sfse_common/Relocation.h"
#include "sfse_common/Utilities.h"
#include "sfse/GameTypes.h"

class Setting
Expand Down Expand Up @@ -60,16 +61,33 @@ class SettingCollection
char pSettingFile[260]; // 008
u32 pad10C; // 10C
void* pHandle; // 110
};

template<typename T>
class SettingCollectionList : public SettingCollection<T>
{
public:
virtual ~SettingCollectionList();

BSSimpleList<T> SettingsA; // 118
u64 unk128; // 128
u64 unk130; // 130
};

template<typename T>
class SettingCollectionList : public SettingCollection<T>
class SettingCollectionMap : public SettingCollection<T>
{
public:
virtual ~SettingCollectionList();
virtual ~SettingCollectionMap();

u64 unk118; // BSTBTree ? Doesnt match F4 exactly
u64 unk120;
u64 unk128;
u64 unk130;
u64 unk138;
u64 unk140;
u64 unk148;
u64 unk150;
};

class INISettingCollection : public SettingCollectionList<Setting>
Expand All @@ -90,6 +108,15 @@ class RegSettingCollection : public SettingCollectionList<Setting>
virtual ~RegSettingCollection();
};

class GameSettingCollection : public SettingCollectionMap<Setting>
{
public:
virtual ~GameSettingCollection();

DEFINE_MEMBER_FN_1(GetSetting, Setting*, 0x01586734, const char*);
};
static_assert(sizeof(GameSettingCollection) == 0x158);

template<typename T>
class SettingT
{
Expand Down
45 changes: 45 additions & 0 deletions sfse/GameSingleton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

template <class T>
class BSTSingletonImplicit
{
public:
using value_type = T;
};

template <class T>
class BSTSingletonExplicit
{
public:
using value_type = T;
};

template <class T>
struct BSTSingletonSDMOpStaticBuffer
{
public:
using value_type = T;
};

template <class Traits>
struct BSTSingletonSDMBase :
public Traits,
public BSTSingletonSDMOpStaticBuffer<typename Traits::value_type>
{
public:
};

template <class T, class Buffer>
struct BSTSDMTraits
{
public:
using value_type = T;
};

template <class T, template <class> class Buffer = BSTSingletonSDMOpStaticBuffer>
struct BSTSingletonSDM :
public BSTSingletonSDMBase<BSTSDMTraits<T, Buffer<T>>>
{
public:
using value_type = T;
};
1 change: 1 addition & 0 deletions sfse/GameUI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "sfse/GameUI.h"
11 changes: 11 additions & 0 deletions sfse/GameUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

class IDataModel
{
public:
virtual ~IDataModel();

virtual void Unk_01();
virtual void Unk_02();
virtual void Unk_03();
};
29 changes: 29 additions & 0 deletions sfse/Hooks_Scaleform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "Hooks_Scaleform.h"
#include "sfse_common/Relocation.h"
#include "sfse_common/Types.h"
#include "sfse_common/Log.h"
#include "sfse_common/SafeWrite.h"

#include <stdarg.h>
#ifdef _DEBUG
#include <windows.h>
#endif

// Scaleform::Log vtable
RelocAddr <uintptr_t> kHook_Scaleform_Log_Offset(0x04077C48 + 0x08);

void Scaleform_LogMessageVarg(void*/*Scaleform::GFx::Log::State* */ logger, u32 messageType, const char* fmt, va_list args)
{
DebugLog::log(DebugLog::kLevel_Message, fmt, args);
#ifdef _DEBUG
char szBuff[1024];
vsnprintf_s(szBuff, sizeof(szBuff), fmt, args);
strcat_s(szBuff, "\n");
OutputDebugString(szBuff);
#endif
}

void Hooks_Scaleform_Apply()
{
safeWrite64(kHook_Scaleform_Log_Offset, (uintptr_t)Scaleform_LogMessageVarg);
}
3 changes: 3 additions & 0 deletions sfse/Hooks_Scaleform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void Hooks_Scaleform_Apply();
48 changes: 48 additions & 0 deletions sfse/Hooks_Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,39 @@
#include "sfse_common/Log.h"
#include "xbyak/xbyak.h"

#ifdef _DEBUG
#include "sfse/GameObjects.h"
#include "sfse/GameChargen.h"
#include "sfse/GameSettings.h"

bool Test_Execute(const SCRIPT_PARAMETER* paramInfo, const char*, TESObjectREFR* thisObj, TESObjectREFR* containingObj, Script* script, ScriptLocals* locals, float* result, u32* opcodeOffsetPtr)
{
if (thisObj) {
dumpClass(thisObj, 0x1100 >> 3/*0x110 >> 3*/);
TESNPC* npc = (TESNPC*)thisObj->data.objectReference;
_MESSAGE("Name: %s", npc->strFullName.c_str());
dumpClass(npc, 0x488 >> 3);
dumpClass(TESNPCData::ChargenDataModel::GetSingleton(), 0x700 >> 3);

npc->MorphWeight.x = 1.0f;
npc->MorphWeight.y = 1.0f;
npc->MorphWeight.z = 1.0f;
bool unk1 = false;
u32 unk2 = 0x28;
bool unk3 = false;
static_cast<Actor*>(thisObj)->UpdateAppearance(unk1, unk2, unk3);
}
else
{
auto& gameSettings = (*SettingT<GameSettingCollection>::pCollection);
auto setting = gameSettings->GetSetting("sSkinToneDisplayName");
Console_Print("Game Settings: %s", setting->name);
}
Console_Print("Dump Complete");
return true;
}
#endif

bool GetSFSEVersion_Execute(const SCRIPT_PARAMETER* paramInfo, const char*, TESObjectREFR* thisObj, TESObjectREFR* containingObj, Script* script, ScriptLocals* locals, float* result, u32* opcodeOffsetPtr)
{
_MESSAGE("GetSFSEVersion_Execute");
Expand Down Expand Up @@ -43,6 +76,21 @@ void ConsoleCommandInit_Hook(void* unk1)
cmd.bInvalidatesCellList = 0;
break;
}
#ifdef _DEBUG
else if (!strcmp(iter->pFunctionName, "GameComment"))
{
Script::SCRIPT_FUNCTION& cmd = *iter;
cmd.pFunctionName = "test";
cmd.pShortName = "";
cmd.pHelpString = "";
cmd.bReferenceFunction = 0;
cmd.sParamCount = 0;
cmd.pExecuteFunction = Test_Execute;
cmd.bEditorFilter = 0;
cmd.bInvalidatesCellList = 0;
break;
}
#endif
}
}

Expand Down
2 changes: 2 additions & 0 deletions sfse/sfse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "Hooks_Version.h"
#include "Hooks_Script.h"
#include "Hooks_Scaleform.h"

HINSTANCE g_moduleHandle = nullptr;

Expand Down Expand Up @@ -141,6 +142,7 @@ void SFSE_Initialize()

Hooks_Version_Apply();
Hooks_Script_Apply();
Hooks_Scaleform_Apply();

FlushInstructionCache(GetCurrentProcess(), NULL, 0);

Expand Down

0 comments on commit 274d2b8

Please sign in to comment.