Skip to content

Commit

Permalink
tasofro: add binhacks support
Browse files Browse the repository at this point in the history
  • Loading branch information
brliron committed Jul 2, 2017
1 parent e50728e commit b702a46
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 11 deletions.
52 changes: 52 additions & 0 deletions thcrap_tasofro/src/plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Touhou Community Reliant Automatic Patcher
* Tasogare Frontier support plugin
*
* ----
*
* Tasofro plugins patching.
*/

#include "thcrap.h"
#include "thcrap_tasofro.h"
#include "plugin.h"
#include <map>

static json_t *cur_patch = nullptr;

int BP_detour_plugin(x86_reg_t *regs, json_t *bp_info)
{
// Parameters
// ----------
HMODULE *plugin = (HMODULE*)json_object_get_register(bp_info, regs, "plugin");
// ----------

iat_detour_apply(*plugin);

if (cur_patch) {
json_t *binhacks = json_object_get(cur_patch, "binhacks");
if (binhacks) {
binhacks_apply(binhacks, *plugin);
}
json_decref(cur_patch);
cur_patch = nullptr;
}

return 1;
}

int patch_dll(void*, size_t, size_t, json_t *patch)
{
// We only want to make thcrap load the jdiff file, we'll patch the DLL file after its sections are mapped in memory.
if (cur_patch) {
json_decref(cur_patch);
}
cur_patch = patch;
json_incref(cur_patch);
return 0;
}

LPCSTR WINAPI tasofro_CharNextA(LPSTR lpsz)
{
return CharNextU(lpsz);
}
23 changes: 23 additions & 0 deletions thcrap_tasofro/src/plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Touhou Community Reliant Automatic Patcher
* Tasogare Frontier support plugin
*
* ----
*
* Tasofro plugins patching.
*/

#pragma once

#include <thcrap.h>
#include <jansson.h>

#ifdef __cplusplus
extern "C" {
#endif

int patch_dll(void *file_inout, size_t size_out, size_t size_in, json_t *patch);

#ifdef __cplusplus
}
#endif
12 changes: 1 addition & 11 deletions thcrap_tasofro/src/thcrap_tasofro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int __stdcall thcrap_plugin_init()
patchhook_register("*/stage*.pl", patch_pl);
patchhook_register("*/ed_*.pl", patch_pl);
patchhook_register("*.csv", patch_tfcs);
patchhook_register("*.dll", patch_dll);

jsonvfs_game_add("data/csv/story/*/stage*.csv.jdiff", { "spells.js" }, spell_story_generator);
jsonvfs_game_add("data/csv/spellcard/*.csv.jdiff", { "spells.js" }, spell_player_generator);
Expand Down Expand Up @@ -203,14 +204,3 @@ int BP_replace_file(x86_reg_t *regs, json_t *bp_info)
size = 0;
return 1;
}

int BP_detour_plugin(x86_reg_t *regs, json_t *bp_info)
{
// Parameters
// ----------
HMODULE *plugin = (HMODULE*)json_object_get_register(bp_info, regs, "plugin");
// ----------

iat_detour_apply(*plugin);
return 1;
}
2 changes: 2 additions & 0 deletions thcrap_tasofro/thcrap_tasofro.def
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ EXPORTS
BP_file_header
BP_replace_file
BP_detour_plugin

tasofro_CharNextA
2 changes: 2 additions & 0 deletions thcrap_tasofro/thcrap_tasofro.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
<ClCompile Include="src\crypt_block.cpp" />
<ClCompile Include="src\csv.cpp" />
<ClCompile Include="src\pl.cpp" />
<ClCompile Include="src\plugin.cpp" />
<ClCompile Include="src\spellcards_generator.cpp" />
<ClCompile Include="src\tfcs.cpp" />
<ClCompile Include="src\thcrap_tasofro.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="src\files_list.cpp" />
<ClInclude Include="src\pl.h" />
<ClInclude Include="src\plugin.h" />
<ClInclude Include="src\spellcards_generator.h" />
<ClInclude Include="src\tfcs.h" />
<ClInclude Include="src\thcrap_tasofro.h" />
Expand Down

0 comments on commit b702a46

Please sign in to comment.