Skip to content

Commit

Permalink
Refactor code to use new tag interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
num0005 committed Oct 10, 2018
1 parent 909bdb0 commit 4c55be2
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 123 deletions.
14 changes: 0 additions & 14 deletions H2Codez/Common/BasicTagTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@

#include "BlamBaseTypes.h"

#define NONE -1

struct datum
{
short index;
short salt;
datum(size_t info)
{
index = LOWORD(info);
salt = HIWORD(info);
}
};
CHECK_STRUCT_SIZE(datum, 4);

struct tag_ref
{
int tag_type;
Expand Down
23 changes: 23 additions & 0 deletions H2Codez/Common/BlamBaseTypes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
#pragma once
#include "../stdafx.h"

#define NONE -1

struct datum
{
short index;
short salt;
datum(size_t info)
{
index = LOWORD(info);
salt = HIWORD(info);
}
bool is_valid()
{
return (index != NONE) && (salt != NONE);
}

long as_long()
{
return *reinterpret_cast<long*>(this);
}
};
CHECK_STRUCT_SIZE(datum, 4);

struct colour_rgb;
/* channel intensity is represented on a 0 to 1 scale */
struct colour_rgba
Expand Down
6 changes: 3 additions & 3 deletions H2Codez/H2Codez.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@
<ClInclude Include="H2Sapien\RenderDebug.h">
<Filter>Source Files\Patches\H2Sapien</Filter>
</ClInclude>
<ClInclude Include="Common\TagInterface.h">
<Filter>Source Files\Common Interfaces\Tags</Filter>
</ClInclude>
<ClInclude Include="Common\Pathfinding.h">
<Filter>Source Files\Common Interfaces</Filter>
</ClInclude>
<ClInclude Include="H2Sapien\HaloScript.h">
<Filter>Source Files\Patches\H2Sapien</Filter>
</ClInclude>
<ClInclude Include="Common\TagInterface.h">
<Filter>Source Files\Common Interfaces</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand Down
80 changes: 0 additions & 80 deletions H2Codez/H2Tool/H2ToolLibrary.inl
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,8 @@ static const char* get_h2tool_version()
static _get_h2tool_build_date get_h2tool_build_date = CAST_PTR(_get_h2tool_build_date, 0xEA760);

return get_h2tool_build_date();

}
static int __cdecl TAG_LOAD(int TAG_TYPE, cstring tags_directory, int a3)
{
typedef int(_cdecl* _TAG_LOAD)(int, cstring, int);
static _TAG_LOAD TAG_LOAD = CAST_PTR(_TAG_LOAD, 0x533930);

return TAG_LOAD(TAG_TYPE, tags_directory, a3);
}
static void *TAG_GET(int TAG_TYPE, int TAG_INDEX)
{
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*);
static _TAG_NEW TAG_NEW = CAST_PTR(_TAG_NEW, 0x5313F0);

return TAG_NEW(TAG_TYPE, TAG_PATH);
}

inline static DWORD TAG_NEW(int TAG_TYPE, const char* TAG_PATH)
{
return TAG_NEW(TAG_TYPE, const_cast<char*>(TAG_PATH));
}

inline static DWORD TAG_NEW(int TAG_TYPE, std::string TAG_PATH)
{
return TAG_NEW(TAG_TYPE, TAG_PATH.c_str());
}

static DWORD __cdecl TAG_UNLOAD(int TAG_INDEX)
{
typedef DWORD(_cdecl* _TAG_UNLOAD)(int);
static _TAG_UNLOAD TAG_UNLOAD = CAST_PTR(_TAG_UNLOAD, 0x52F7C0);

return TAG_UNLOAD(TAG_INDEX);
}
static DWORD __cdecl TAG_SAVE(int TAG_INDEX)
{
typedef DWORD(_cdecl* _TAG_SAVE)(int);
static _TAG_SAVE _TAG_SAVE_ = CAST_PTR(_TAG_SAVE, 0x532F40);

return _TAG_SAVE_(TAG_INDEX);
}
static CHAR*__cdecl TAG_GET_NAME(int TAG_INDEX)
{
typedef CHAR*(_cdecl* TAG_GET_NAME)(int);
static TAG_GET_NAME TAG_GET_NAME_ = CAST_PTR(TAG_GET_NAME, 0x52CF50);

return TAG_GET_NAME_(TAG_INDEX);
}
static bool __cdecl TAG_ADD_IMPORT_INFO_BLOCK(void* IMPORT_INFO_OFFSET)
{
typedef bool(_cdecl* TAG_ADD_IMPORT_INFO_BLOCK)(void*);
Expand All @@ -90,13 +31,7 @@ static bool __cdecl TAG_FILE_CHECK_READ_ONLY_ACCESS(int TAG_INDEX, int a2)

return TAG_FILE_CHECK_READ_ONLY_ACCESS(TAG_INDEX, a2);
}
static void* __cdecl TAG_BLOCK_ADD_ELEMENT(void* TAG_ADDRESS)
{
typedef void*(_cdecl* TAG_BLOCK_ADD_ELEMENT)(void*);
static TAG_BLOCK_ADD_ELEMENT TAG_BLOCK_ADD_ELEMENT_ = CAST_PTR(TAG_BLOCK_ADD_ELEMENT, 0x533CA0);

return TAG_BLOCK_ADD_ELEMENT_(TAG_ADDRESS);
}
static int __cdecl TAG_BLOCK_GET_ELEMENT_WITH_SIZE(void* FIELD_OFFSET, int ELEMENT_INDEX, int FIELD_SIZE)
{
typedef int(_cdecl* TAG_BLOCK_GET_ELEMENT_WITH_SIZE)(void*, int, int);
Expand All @@ -113,19 +48,6 @@ 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 Expand Up @@ -160,8 +82,6 @@ static unsigned int FIND_TAG_BLOCK_STRING_ID(tag_block_ref *tag_block, size_t el
return FIND_TAG_BLOCK_ELEMENT(tag_block, element_size, reinterpret_cast<find_tag_comparison>(&string_id_comparison), &search_info);
}



struct string_cmp_info
{
size_t offset;
Expand Down
16 changes: 7 additions & 9 deletions H2Codez/H2Tool/H2Tool_Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,17 +638,15 @@ void H2ToolPatches::fix_command_line()

void tag_dump(int tag_index)
{
char old_name[0x200];
strncpy_s(old_name, TAG_GET_NAME(tag_index), sizeof(old_name));
std::string old_name = tags::get_name(tag_index);

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

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

TAG_RENAME(tag_index, new_name);
TAG_SAVE(tag_index);
TAG_RENAME(tag_index, old_name);
tags::rename_tag(tag_index, new_name);
tags::save_tag(tag_index);
tags::rename_tag(tag_index, old_name);
}

template<typename T>
Expand All @@ -671,7 +669,7 @@ 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);

scnr_tag *scenario = (scnr_tag*)TAG_GET('scnr', TAG_INDEX);
scnr_tag *scenario = tags::get_tag<scnr_tag>('scnr', TAG_INDEX);

// fix the compiler not setting up AI orders right and causing weird things to happen with scripts
for (size_t i = 0; i < scenario->orders.size; i++)
Expand Down
3 changes: 3 additions & 0 deletions H2Codez/H2Tool/H2Tool_Commands.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "stdafx.h"
#include "..\Common\BlamBaseTypes.h"

enum tool_command_argument_type : long {
_tool_command_argument_type_0,
Expand Down Expand Up @@ -44,6 +45,8 @@ struct s_tool_import_definations_
DWORD unk_1;
DWORD unk_2;
};

typedef bool(_cdecl* tool_dev_command_proc)(wchar_t *a1, datum tags);
struct s_tool_h2dev_command {
cstring command_name;
cstring command_description;
Expand Down
30 changes: 15 additions & 15 deletions H2Codez/H2Tool/H2Tool_extra_commands.inl
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ static void _cdecl h2dev_extra_commands_proc(wchar_t ** arguments)
{
std::string f_parameter = wstring_to_string.to_bytes(command_parameter_0);
H2PCTool.WriteLog("Tag Type %X \n %s", cmd->tag_type, f_parameter);
DWORD tag_index = TAG_LOAD(cmd->tag_type, f_parameter.c_str(), 7);
datum tag = tags::load_tag(cmd->tag_type, f_parameter.c_str(), 7);

if (cmd->command_impl(nullptr, tag_index))// call Function via address
if (cmd->command_impl(nullptr, tag))// call Function via address
return;
printf("\n usage : %s\n Description : %s\n", cmd->command_name, cmd->command_description);
}
Expand Down Expand Up @@ -182,7 +182,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 = (DWORD)TAG_GET('mode', TAG_INDEX);
DWORD MODE_TAG = (DWORD)tags::get_tag('mode', TAG_INDEX);
DWORD import_info_block_offset = MODE_TAG + 0xC;

if (MODE_TAG != -1) {
Expand Down Expand Up @@ -295,7 +295,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 = (DWORD)TAG_GET('mode', TAG_INDEX);
DWORD mode_tag_file = (DWORD)tags::get_tag('mode', TAG_INDEX);
DWORD import_info_block_offset = mode_tag_file + 0xC;

DWORD SBSP_FOLDER_LOAD_1 = 0x41C835;
Expand All @@ -320,8 +320,8 @@ static bool _cdecl h2pc_generate_render_model_(DWORD TAG_INDEX, filo& FILE_REF)
if (k_render_model_imported && global_geometry_imported_count > 0)
{
printf(" == saving temporary render_model \n");
TAG_SAVE(TAG_INDEX);//creating the current render_model file in Disk
TAG_UNLOAD(TAG_INDEX);
tags::save_tag(TAG_INDEX);//creating the current render_model file in Disk
tags::unload_tag(TAG_INDEX);


std::string render_model_file_name_ = strrchr(c_out_path, '\\');
Expand Down Expand Up @@ -382,28 +382,28 @@ static bool _cdecl h2pc_import_render_model_proc(wcstring* arguments)
if (tool_build_paths(arguments[0], "render", filo, out_path, wide_path))
{
path = wstring_to_string.to_bytes(wide_path);
DWORD TAG_INDEX = TAG_LOAD('mode', path.c_str(), 7);
if (TAG_INDEX != -1)
datum TAG_INDEX = tags::load_tag('mode', path.c_str(), 7);
if (TAG_INDEX.is_valid())
{
DWORD RENDER_MODEL_TAG = (DWORD)TAG_GET('mode', TAG_INDEX);
DWORD RENDER_MODEL_TAG = (DWORD)tags::get_tag('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))
b_render_imported = false;

TAG_UNLOAD(TAG_INDEX);
tags::unload_tag(TAG_INDEX);
if (!b_render_imported)
return b_render_imported;
}
auto dir_name = FiloInterface::get_path_info(&filo, PATH_FLAGS::CONTAINING_DIRECTORY_NAME);
printf(" ### creating new render model file with name '%s' \n ", dir_name.c_str());
TAG_INDEX = TAG_NEW('mode', path);
TAG_INDEX = tags::new_tag('mode', path);

if (TAG_INDEX != -1)
if (TAG_INDEX.is_valid())
{
if (TAG_FILE_CHECK_READ_ONLY_ACCESS(TAG_INDEX, false))
if (TAG_FILE_CHECK_READ_ONLY_ACCESS(TAG_INDEX.as_long(), false))
{
if (h2pc_generate_render_model_(TAG_INDEX, filo))
if (h2pc_generate_render_model_(TAG_INDEX.as_long(), filo))
{
b_render_imported = true;
//TAG_SAVE(TAG_INDEX);
Expand All @@ -418,7 +418,7 @@ static bool _cdecl h2pc_import_render_model_proc(wcstring* arguments)
else
{
printf(" ### ERROR render model '%s' is not writable\n", dir_name.c_str());
TAG_UNLOAD(TAG_INDEX);
tags::unload_tag(TAG_INDEX);
b_render_imported = false;
}
}
Expand Down
1 change: 1 addition & 0 deletions H2Codez/H2Tool/LostToolCommands.inl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
See license\OpenSauce\Halo2_CheApe for specific license information
*/
#include "../stdafx.h"
#include "H2Tool_Commands.h"
#include "Animations.inl"
#include "Sounds.inl"

Expand Down
1 change: 1 addition & 0 deletions H2Codez/h2codez.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "stdafx.h"
#include "H2Tool\H2Tool_Commands.h"
#include "H2Guerilla\H2Guerilla.h"
#include "H2Sapien\H2Sapien.h"
#include "Common\H2EKCommon.h"
Expand Down
1 change: 0 additions & 1 deletion H2Codez/h2codez.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ typedef wchar_t* wstring;
// Constant '\0\0' terminated unicode string
typedef const wchar_t* wcstring;
typedef void(_cdecl* _tool_command_proc)(const wchar_t *argv[]);
typedef bool(_cdecl* tool_dev_command_proc)(wchar_t *a1, DWORD TAG_INDEX);
typedef void(_cdecl* _tool_import__defination_proc)(void* FILE_REFERENCE, void* ref_ptr);
typedef char long_string[255 + 1];

Expand Down
1 change: 0 additions & 1 deletion H2Codez/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "h2codez.h"
#include "util\Detours\detours.h"
#include "util\Logs.h"
#include "H2Tool\H2Tool_Commands.h"
#include "util\Settings.h"

extern Settings conf;
Expand Down

0 comments on commit 4c55be2

Please sign in to comment.