Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Source/DivaModLoader/AetDb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "Types.h"
#include "AetDb.h"

struct AetSetEntry
{
struct AetSetInfo
{
uint32_t id;
const char* name;
INSERT_PADDING(0x20);
};

INSERT_PADDING(0x8);
AetSetInfo info;
};

struct AetSetComparer
{
bool operator()(const AetSetEntry& entry, uint32_t id) const { return entry.info.id < id; }
bool operator()(uint32_t id, const AetSetEntry& entry) const { return id < entry.info.id; }
};

static prj::vector<AetSetEntry>* aetSetEntries = reinterpret_cast<prj::vector<AetSetEntry>*>(0x1414AB488);
static AetSetEntry::AetSetInfo* defaultAetSetEntry = reinterpret_cast<AetSetEntry::AetSetInfo*>(0x140DAEC60);

// See `AetDbImp.asm` for implementation.
HOOK(AetSetEntry::AetSetInfo*, __fastcall, GetAetSetEntry, 0x1518B3D40, void* a1, uint32_t id);

AetSetEntry::AetSetInfo* getAetSetEntryImp(void* a1, uint32_t id)
{
// Execute a binary search for the AetSetInfo. This vector is already sorted by the game so
// we don't need to worry about that. Also make sure the returned AetSet id matches because
// when the entry is missing, std::equal_range will return the nearest entry and we don't
// want that!
auto it = std::equal_range(aetSetEntries->begin(), aetSetEntries->end(), id, AetSetComparer()).first;
if (it == aetSetEntries->end() || it->info.id != id)
return defaultAetSetEntry;

return &it->info;
}

void AetDB::init()
{
// NOP-out the code that creates the lookup array for AetSetInfo
WRITE_NOP(0x14029363F, 0x69);
INSTALL_HOOK(GetAetSetEntry);
}
6 changes: 6 additions & 0 deletions Source/DivaModLoader/AetDb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

struct AetDB
{
static void init();
};
44 changes: 44 additions & 0 deletions Source/DivaModLoader/AetDbImp.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.code

?getAetSetEntryImp@@YAPEAUAetSetInfo@AetSetEntry@@PEAXI@Z proto

?implOfGetAetSetEntry@@YAPEAUAetSetInfo@AetSetEntry@@PEAXI@Z:
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15

mov r15, rsp
sub rsp, 20h
and rsp, 0FFFFFFFFFFFFFFF0h

call ?getAetSetEntryImp@@YAPEAUAetSetInfo@AetSetEntry@@PEAXI@Z
mov rsp, r15

pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
ret

public ?implOfGetAetSetEntry@@YAPEAUAetSetInfo@AetSetEntry@@PEAXI@Z

end
2 changes: 2 additions & 0 deletions Source/DivaModLoader/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Utilities.h"
#include "PvLoader.h"
#include "ThumbnailLoader.h"
#include "AetDb.h"

HRESULT(*originalDirectInput8Create)(HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN);
extern "C" __declspec(dllexport) HRESULT DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID* ppvOut, LPUNKNOWN punkOuter)
Expand Down Expand Up @@ -108,4 +109,5 @@ void Context::postInit()
CodeLoader::postInit();
PvLoader::init();
ThumbnailLoader::init();
AetDB::init();
}
3 changes: 3 additions & 0 deletions Source/DivaModLoader/DivaModLoader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="AetDb.h" />
<ClInclude Include="Allocator.h" />
<ClInclude Include="CodeLoader.h" />
<ClInclude Include="Config.h" />
Expand All @@ -119,6 +120,7 @@
<ClInclude Include="Utilities.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AetDb.cpp" />
<ClCompile Include="Allocator.cpp" />
<ClCompile Include="CodeLoader.cpp" />
<ClCompile Include="Config.cpp" />
Expand All @@ -139,6 +141,7 @@
<ClCompile Include="ThumbnailLoader.cpp" />
</ItemGroup>
<ItemGroup>
<MASM Include="AetDbImp.asm" />
<MASM Include="SaveDataImp.asm" />
<MASM Include="PvLoaderImp.asm" />
<MASM Include="SpriteLoaderImp.asm" />
Expand Down
3 changes: 3 additions & 0 deletions Source/DivaModLoader/DivaModLoader.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ClInclude Include="SaveData.h" />
<ClInclude Include="PvLoader.h" />
<ClInclude Include="ThumbnailLoader.h" />
<ClInclude Include="AetDb.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Pch.cpp" />
Expand All @@ -35,11 +36,13 @@
<ClCompile Include="Allocator.cpp" />
<ClCompile Include="PvLoader.cpp" />
<ClCompile Include="ThumbnailLoader.cpp" />
<ClCompile Include="AetDb.cpp" />
</ItemGroup>
<ItemGroup>
<MASM Include="StrArrayImp.asm" />
<MASM Include="SaveDataImp.asm" />
<MASM Include="SpriteLoaderImp.asm" />
<MASM Include="PvLoaderImp.asm" />
<MASM Include="AetDbImp.asm" />
</ItemGroup>
</Project>