Skip to content

Commit

Permalink
Add debug function for dumping preprocessed scenario and structure BS…
Browse files Browse the repository at this point in the history
…P tags.
  • Loading branch information
num0005 committed Jul 21, 2018
1 parent 7c1b490 commit 30e0529
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 9 deletions.
4 changes: 2 additions & 2 deletions H2Codez/H2Codez.vcxproj.user
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommand>C:\Program Files %28x86%29\Microsoft Games\Halo 2 Map Editor\h2sapien.exe</LocalDebuggerCommand>
<LocalDebuggerCommand>C:\Program Files %28x86%29\Microsoft Games\Halo 2 Map Editor\h2tool</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>C:\Program Files (x86)\Microsoft Games\Halo 2 Map Editor</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>structure-new-from-ass "c:\program files (x86)\microsoft games\halo 2 map editor\data\scenarios\multi\forge_world\structure\forge_world.ass" yes pause_after_run</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>build-cache-file "C:\Program Files (x86)\Microsoft Games\Halo 2 Map Editor\tags\scenarios\multi\preview\preview_1"</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommand>C:\Program Files %28x86%29\Microsoft Games\Halo 2 Map Editor\h2sapien.exe</LocalDebuggerCommand>
Expand Down
23 changes: 21 additions & 2 deletions H2Codez/H2Tool/H2ToolLibrary.inl
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ static int __cdecl TAG_LOAD(int TAG_TYPE, cstring tags_directory, int a3)

return TAG_LOAD(TAG_TYPE, tags_directory, a3);
}
static int __cdecl TAG_GET(int TAG_TYPE, int TAG_INDEX)
static void *TAG_GET(int TAG_TYPE, int TAG_INDEX)
{
typedef int(_cdecl* _TAG_GET)(int, int);
typedef void*(_cdecl* _TAG_GET)(int, int);
static _TAG_GET TAG_GET = CAST_PTR(_TAG_GET, 0x52F150);

return TAG_GET(TAG_TYPE, TAG_INDEX);
}

static void *TAG_GET(char TAG_GROUP, int TAG_INDEX)
{
return TAG_GET(static_cast<int>(TAG_GROUP), TAG_INDEX);
}

static DWORD TAG_NEW(int TAG_TYPE, char* TAG_PATH)
{
typedef DWORD(_cdecl* _TAG_NEW)(int, char*);
Expand Down Expand Up @@ -107,6 +113,19 @@ static int GET_STRING_ID(const char *string)
return get_string_id_impl(string);
}

static bool TAG_RENAME(int tag_index, const char *new_name)
{
typedef char (__cdecl *TAG_RENAME)(int tag_index, const char *new_name);
auto TAG_RENAME_IMPL = reinterpret_cast<TAG_RENAME>(0x0052F840);

return TAG_RENAME_IMPL(tag_index, new_name);
}

static bool TAG_RENAME(int tag_index, const std::string &new_name)
{
return TAG_RENAME(tag_index, new_name.c_str());
}

typedef bool (*find_tag_comparison)(void *element, void *find_data);

static unsigned int FIND_TAG_BLOCK_ELEMENT(tag_block_ref *tag_block, size_t element_size, find_tag_comparison search_func, void *data)
Expand Down
32 changes: 31 additions & 1 deletion H2Codez/H2Tool/H2Tool_Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,35 @@ void H2ToolPatches::fix_command_line()
PatchCall(0x00751F83, __crtGetCommandLineW_hook);
}

void tag_dump(int tag_index)
{
char old_name[0x200];
strncpy_s(old_name, TAG_GET_NAME(tag_index), sizeof(old_name));

std::string new_name = "dump\\";
new_name += old_name;

printf("dumping tag '%s' as '%s' ***\n", old_name, new_name.c_str());

TAG_RENAME(tag_index, new_name);
TAG_SAVE(tag_index);
TAG_RENAME(tag_index, old_name);
}

char __cdecl scenario_write_patch_file_hook(int TAG_INDEX, int a2)
{
typedef char (__cdecl *scenario_write_patch_file)(int TAG_INDEX, int a2);
auto scenario_write_patch_file_impl = reinterpret_cast<scenario_write_patch_file>(0x0056A110);

tag_dump(TAG_INDEX);

scnr_tag *scenario = (scnr_tag*)TAG_GET('scnr', TAG_INDEX);
for (int i = 0; i < scenario->structureBSPs.size; i++)
tag_dump(scenario->structureBSPs.data[i].structureBSP.tag_index);

return scenario_write_patch_file_impl(TAG_INDEX, a2);
}

void H2ToolPatches::Initialize()
{
H2PCTool.WriteLog("Dll Successfully Injected to H2Tool");
Expand All @@ -720,8 +749,9 @@ void H2ToolPatches::Initialize()
std::string cmd = GetCommandLineA();
if (cmd.find("shared_tag_removal") != string::npos)
apply_shared_tag_removal_scheme();


if (conf.getBoolean("dump_tags_packaging", false))
PatchCall(0x00588A66, scenario_write_patch_file_hook);
}


Expand Down
6 changes: 3 additions & 3 deletions H2Codez/H2Tool/H2Tool_extra_commands.inl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ tag_data_struct** global_sbsp_data_list;
static void _cdecl TAG_RENDER_MODEL_IMPORT_PROC(filo *sFILE_REF, char* _TAG_INDEX_)
{
DWORD TAG_INDEX = (DWORD)_TAG_INDEX_;
DWORD MODE_TAG = TAG_GET('mode', TAG_INDEX);
DWORD MODE_TAG = (DWORD)TAG_GET('mode', TAG_INDEX);
DWORD import_info_block_offset = MODE_TAG + 0xC;

if (MODE_TAG != -1) {
Expand Down Expand Up @@ -288,7 +288,7 @@ static void *jms_collision_geometry_import_defination_ = CAST_PTR(void*, 0x97C35
static bool _cdecl h2pc_generate_render_model_(DWORD TAG_INDEX, filo& FILE_REF)
{

DWORD mode_tag_file = TAG_GET('mode', TAG_INDEX);
DWORD mode_tag_file = (DWORD)TAG_GET('mode', TAG_INDEX);
DWORD import_info_block_offset = mode_tag_file + 0xC;

DWORD SBSP_FOLDER_LOAD_1 = 0x41C835;
Expand Down Expand Up @@ -378,7 +378,7 @@ static bool _cdecl h2pc_import_render_model_proc(wcstring* arguments)
DWORD TAG_INDEX = TAG_LOAD('mode', path.c_str(), 7);
if (TAG_INDEX != -1)
{
DWORD RENDER_MODEL_TAG = TAG_GET('mode', TAG_INDEX);
DWORD RENDER_MODEL_TAG = (DWORD)TAG_GET('mode', TAG_INDEX);
DWORD import_info_field = RENDER_MODEL_TAG + 0xC;

if (!load_model_object_definations_(import_info_field, jms_collision_geometry_import_defination_, 1, filo))
Expand Down
29 changes: 28 additions & 1 deletion H2Codez/Tags/ScenarioTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@
#pragma pack(1)
#include "../Common/BasicTagTypes.h"

struct scenario_structure_bsp_reference_block
{
BYTE padding26[16];
// TagReference("sbsp")
tag_ref structureBSP;
// TagReference("ltmp")
tag_ref structureLightmap;
BYTE padding27[4];
float uNUSEDRadianceEstSearchDistance;
BYTE padding28[4];
float uNUSEDLuminelsPerWorldUnit;
float uNUSEDOutputWhiteReference;
BYTE padding29[8];

enum Flags : short
{
DefaultSkyEnabled = 0x1,
};
Flags flags;
BYTE padding30[2];
// BlockIndex1("scenario_sky_reference_block")
short defaultSky;
BYTE padding31[2];
};
CHECK_STRUCT_SIZE(scenario_structure_bsp_reference_block, 84);


struct cs_point_block
{
char name[32];
Expand Down Expand Up @@ -118,7 +145,7 @@ struct scnr_tag
tag_ref customObjectNames;
tag_ref chapterTitleText;
tag_ref hUDMessages;
tag_block_ref structureBSPs;
tag_block<scenario_structure_bsp_reference_block> structureBSPs;
tag_block_ref scenarioResources;
tag_block_ref scenarioResources_unused;
tag_block_ref hsUnitSeats;
Expand Down

0 comments on commit 30e0529

Please sign in to comment.