Skip to content

Commit

Permalink
UseHiDefCharacters: use GH00 anims from Media folder to fix hair
Browse files Browse the repository at this point in the history
Anims in Media folder include hair anims, while the normal Chr folder anims don't.
Some reason the Media folder ones go unused, not sure if these are some newer versions that added them in (but accidentally went unused), or maybe they're older ones before they removed them for some reason.
  • Loading branch information
emoose committed Sep 16, 2024
1 parent 7afbd09 commit e280241
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
12 changes: 11 additions & 1 deletion src/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ enum ChrSet
CHR_DR_H00 = 19
};

struct s_chrset_info // not actual name
{
const char* bin_ptr;
int field_4; // always 0?
int xmtset_no_8;
int field_C; // always 0?
};
static_assert(sizeof(s_chrset_info) == 0x10);

enum SOUND_CMD
{
/* 0x0800 */ SND_LOOP = (1 << 11),
Expand Down Expand Up @@ -293,7 +302,8 @@ struct tagEvWorkRobot
uint32_t workId_0;
uint32_t dword4;
ChrSet chrset_8;
__declspec(align(8)) _D3DMATRIX d3dmatrix10;
uint8_t unk_C[4];
_D3DMATRIX d3dmatrix10;
D3DVECTOR field_50;
D3DVECTOR field_5C;
int dword68;
Expand Down
4 changes: 4 additions & 0 deletions src/game_addrs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace Game

inline int* sel_bgm_kind_buf = nullptr;

inline s_chrset_info* chrset_info = nullptr;

inline int* app_time = nullptr; // used by SetTweeningTable etc
inline int* sprani_num_ticks = nullptr; // number of game ticks being ran in the current frame (can be 0 if above 60FPS)

Expand Down Expand Up @@ -139,6 +141,8 @@ namespace Game

sel_bgm_kind_buf = Module::exe_ptr<int>(0x430364);

chrset_info = Module::exe_ptr<s_chrset_info>(0x254860);

app_time = Module::exe_ptr<int>(0x49EDB8);
sprani_num_ticks = Module::exe_ptr<int>(0x380278);

Expand Down
30 changes: 12 additions & 18 deletions src/hooks_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,10 @@ DrawDistanceIncrease DrawDistanceIncrease::instance;

class UseHiDefCharacters : public Hook
{
inline static SafetyHookInline rob_disp_init{};
static void rob_disp_init_dest(tagEvWorkRobot* a1)
{
// OSAGE handles the moving/bouncing parts of the model
// Seems only ending cutscenes actually make use of it, driver/passenger models are skipped
// The HQ models will still use any data from rob_osage_matrix array if it's set however
// This data doesn't seem to get cleared after ending cutscene, so HQ models use the last values set during cutscene
// Causing issues like HQClarissa's hair to seperate from body...
//
// rob_disp_init gets called when character is being setup, we can just clear the matrix data for the character here

rob_disp_init.call(a1);

D3DMATRIX* rob_osage_matrix = Module::exe_ptr<D3DMATRIX>(0x458710);
memset(&rob_osage_matrix[0x20 * a1->workId_0], 0, 0x20 * sizeof(D3DMATRIX));
}
inline static const char ChrDrGh00_path[] = "Media\\CHR_DR_GH00.bin";
inline static const char ChrDrGh00_gamepath[] = "\\Media\\CHR_DR_GH00.bin";
inline static const char ChrDrGh00Usa_path[] = "Media\\CHR_DR_GH00_USA.bin";
inline static const char ChrDrGh00Usa_gamepath[] = "\\Media\\CHR_DR_GH00_USA.bin";

public:
std::string_view description() override
Expand All @@ -203,8 +191,14 @@ class UseHiDefCharacters : public Hook

bool apply() override
{
constexpr int rob_osage_dest_Addr = 0x114BF0;
rob_disp_init = safetyhook::create_inline(Module::exe_ptr(rob_osage_dest_Addr), rob_disp_init_dest);
// Switch Chr\CHR_DR_GH00*.bin usages to read from Media\CHR_DR_GH00*.bin instead, if they exist
// (Chr\ versions are missing hair anims which Media\ versions fortunately include - Media\ versions are otherwise unused)
{
if (std::filesystem::exists(ChrDrGh00_path))
Game::chrset_info[ChrSet::CHR_DR_GH00].bin_ptr = ChrDrGh00_gamepath;
if (std::filesystem::exists(ChrDrGh00Usa_path))
Game::chrset_info[ChrSet::CHR_DR_GH00_USA].bin_ptr = ChrDrGh00Usa_gamepath;
}

int* driver_chrsets = Module::exe_ptr<int>(0x2549B0);
int* heroine_chrsets = Module::exe_ptr<int>(0x2549C8);
Expand Down

0 comments on commit e280241

Please sign in to comment.