Skip to content

Commit

Permalink
[HaloScript] Add support for point references.
Browse files Browse the repository at this point in the history
  • Loading branch information
num0005 committed Jul 15, 2018
1 parent 195744d commit c6c132d
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 4 deletions.
18 changes: 18 additions & 0 deletions H2Codez/Common/BasicTagTypes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "BlamBaseTypes.h"

#define NONE -1

struct tag_ref
Expand All @@ -17,6 +19,22 @@ struct tag_block_ref
void *definition;
};

template<typename T>
struct tag_block
{
int size;
T *data;
void *defination;

tag_block_ref* get_ref() {
return reinterpret_cast<tag_block_ref*>(this);
}
tag_block_ref *operator&()
{
return get_ref();
}
};

struct byte_ref
{
int size;
Expand Down
39 changes: 38 additions & 1 deletion H2Codez/Common/BlamBaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,41 @@ struct colour
float red = 1.0f;
float green = 1.0f;
float blue = 1.0f;
};
};

struct point2d
{
short x;
short y;
};
struct real_point2d
{
float x;
float y;
};

struct real_point3d
{
float x;
float y;
float z;
};

struct real_vector2d
{
float i;
float j;
};

struct real_vector3d
{
float i;
float j;
float k;
};

struct real_euler_angles2d
{
float yaw;
float pitch;
};
45 changes: 43 additions & 2 deletions H2Codez/H2Tool/H2Tool_Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,47 @@ char __cdecl hs_convert_ai(unsigned __int16 a1)
}
}

char __cdecl hs_convert_point_ref(unsigned __int16 a1)
{
scnr_tag *scenario = get_global_scenario();
hs_convert_data_store *data_store = hs_get_converter_data_store(a1);
std::string input_string = hs_get_string_data(data_store);
auto scripting_data = scenario->scriptingData;

if (input_string.find('/') != string::npos) {
std::string point_set = input_string.substr(0, input_string.find('/'));
std::string point = input_string.substr(input_string.find('/') + 1);

int point_set_index = FIND_TAG_BLOCK_STRING(&scripting_data.data->pointSets,
sizeof(cs_point_set_block),
offsetof(cs_point_set_block, name),
point_set);
if (point_set_index != NONE)
{
cs_point_set_block *points = &scripting_data.data->pointSets.data[point_set_index];
int point_index = FIND_TAG_BLOCK_STRING(&points->points,
sizeof(cs_point_block),
offsetof(cs_point_block, name),
point);

if (point_index != NONE)
{
data_store->output = (point_set_index << 16 | point_index);
return 1;
} else {
hs_converter_error(data_store, "No such point.");
return false;
}
} else {
hs_converter_error(data_store, "No such point set.");
return false;
}
} else {
hs_converter_error(data_store, "Invalid format.");
return false;
}
}

#define set_hs_converter(type, func) \
hs_convert_lookup_table[static_cast<int>(type)] = func;

Expand All @@ -585,12 +626,12 @@ void fix_hs_converters()
set_hs_converter(hs_type::conversation, hs_convert_conversation);
set_hs_converter(hs_type::ai_orders, hs_convert_ai_orders);
set_hs_converter(hs_type::ai, hs_convert_ai);
set_hs_converter(hs_type::point_reference, hs_convert_point_ref);

// hacky workaround, lets the user directly input the ID it's meant to generate.
hs_type passthrough_types[] = {
hs_type::style, hs_type::hud_message,
hs_type::navpoint, hs_type::point_reference,
hs_type::ai_command_list
hs_type::navpoint, hs_type::ai_command_list
};

for (auto i : passthrough_types)
Expand Down
40 changes: 39 additions & 1 deletion H2Codez/Tags/ScenarioTag.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
#pragma once
#include "../Common/BasicTagTypes.h"

struct cs_point_block
{
char name[32];
real_point3d position;
short referenceFrame;
BYTE padding21[2];
int surfaceIndex;
real_euler_angles2d facingDirection;
};
CHECK_STRUCT_SIZE(cs_point_block, 60);


struct cs_point_set_block
{
char name[32];
tag_block<cs_point_block> points;

// BlockIndex1("scenario_structure_bsp_reference_block")
short bspIndex;
short manualReferenceFrame;

enum Flags : int
{
ManualReferenceFrame = 0x1,
TurretDeployment = 0x2,
};
Flags flags;
};
CHECK_STRUCT_SIZE(cs_point_set_block, 52);

struct cs_script_data_block
{
tag_block<cs_point_set_block> pointSets;

BYTE padding[120];
};
CHECK_STRUCT_SIZE(cs_script_data_block, 132);

struct scnr_tag
{
tag_ref unused_sbsp;
Expand Down Expand Up @@ -64,7 +102,7 @@ struct scnr_tag
tag_block_ref globals;
tag_block_ref references;
tag_block_ref sourceFiles;
tag_block_ref scriptingData;
tag_block<cs_script_data_block> scriptingData;
tag_block_ref cutsceneFlags;
tag_block_ref cutsceneCameraPoints;
tag_block_ref cutsceneTitles;
Expand Down
2 changes: 2 additions & 0 deletions H2Codez/h2codez.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ typedef char long_string[255 + 1];
#define CHECK_FUNCTION_SUPPORT(expersion)\
if (!expersion) \
_wassert(__FUNCTIONW__ L" doesn't support this process type.", _CRT_WIDE(__FILE__), (unsigned)(__LINE__))
#define CHECK_STRUCT_SIZE(struct_name, size)\
static_assert(sizeof(struct_name) == size, #struct_name " size is invalid" )

enum H2EK
{
Expand Down

0 comments on commit c6c132d

Please sign in to comment.