int main(void) { h3mlib_ctx_t h3m = NULL; int od_index = 0; h3m_init_min(&h3m, H3M_FORMAT_ROE, H3M_SIZE_SMALL); h3m_object_add(h3m, "Castle", 5, 5, 0, &od_index); h3m_object_set_owner(h3m, od_index, 0); h3m_player_enable(h3m, 0); h3m_name_set(h3m, "h3msnake2"); if (0 != h3m_code_set_dll(h3m, "..\\..\\..\\..\\OUTPUT\\Release\\h3complete_snakeloader.dll")) { h3m_exit(&h3m); return 1; } h3m_desc_set(h3m, DESC_PREFIX_COMPLETE DESC); h3m_code_set_target(h3m, H3M_CODE_TARGET_COMPLETE); h3m_write(h3m, "h3msnake2_h3complete.h3m"); h3m_desc_set(h3m, DESC_PREFIX_HDMOD DESC); h3m_code_set_target(h3m, H3M_CODE_TARGET_HDMOD); h3m_write(h3m, "h3msnake2_hdmod.h3m"); h3m_exit(&h3m); return 0; }
int main(int argc, char **argv) { char *output_file = NULL; size_t len = 0; h3mlib_ctx_t h3m = NULL; if (argc != 3) { _print_usage(); return 1; } if (0 != h3m_read(&h3m, argv[1])) { printf("[!] Failed to open %s!", argv[1]); return 1; } if (0 != h3m_modembed_set_dll(h3m, argv[2])) { printf("[!] Failed to embed DLL %s!", argv[2]); h3m_exit(&h3m); return 1; } len = strlen(argv[1]) + sizeof(H3COMPLETE_SUFFIX); output_file = calloc(len, 1); if (output_file == NULL) { puts("[!] Failed to allocate memory!"); h3m_exit(&h3m); return 1; } // H3Complete snprintf(output_file, len - 1, "%s%s", argv[1], H3COMPLETE_SUFFIX); h3m_modembed_set_target(h3m, H3M_MODEMBED_TARGET_COMPLETE); if (0 != h3m_write(h3m, output_file)) { printf("[!] Failed to write %s!", output_file); free(output_file); h3m_exit(&h3m); return 1; } printf("[+] Embedded %s into %s\n", argv[2], output_file); // HD Mod // Note same len is used here snprintf(output_file, len - 1, "%s%s", argv[1], HDMOD_SUFFIX); h3m_modembed_set_target(h3m, H3M_MODEMBED_TARGET_HDMOD); if (0 != h3m_write(h3m, output_file)) { printf("[!] Failed to write %s!", output_file); free(output_file); h3m_exit(&h3m); return 1; } printf("[+] Embedded %s into %s\n", argv[2], output_file); free(output_file); h3m_exit(&h3m); return 0; }
int h3m_object_patch_u(h3mlib_ctx_t ctx_main, const wchar_t *filename) { struct MERGE_CTX merge = { 0 }; h3mlib_ctx_t ctx_append = NULL; if (0 != h3m_read_u(&ctx_append, filename)) { return 1; } _merge_oa(ctx_main, ctx_append, &merge); _merge_od(ctx_main, ctx_append, &merge); h3m_exit(&ctx_append); return 0; }
int h3msnake_exit(void) { if (NULL != f_state.h3m) { h3m_exit(&f_state.h3m); f_state.h3m = NULL; } if (NULL != f_state.filename) { free(f_state.filename); f_state.filename = NULL; } //TODO free nodes return 0; }
int rmg_postfix(const char *filename) { h3mlib_ctx_t h3m = NULL; struct POSTFIX_CTX ps_ctx = { 0 }; int oa_index = 0; OutputDebugStringA("@rmg_postfix"); OutputDebugStringA(filename); if (0 == g_selectable_towns) { return 0; } OutputDebugStringA("@rmg_postfix fix map"); h3m_read(&h3m, filename); if (NULL == h3m) { OutputDebugStringA("failed to open map"); return 1; } _postfix_init(h3m, &ps_ctx); h3m_add_oa_by_def(h3m, "avcranx0.def", &ps_ctx.random_town_oa); h3m_enum_od(h3m, _enum_od_cb, (void *)&ps_ctx); h3m_towns_selectable(h3m); h3m_desc_append(h3m, " [h3minternals.net]"); h3m_write(h3m, filename); h3m_exit(&h3m); return 0; }
int convert_to_roe(const wchar_t *src_path, const wchar_t *filename, const wchar_t *dest_path, convert_cb_t cb, void *cb_data) { h3mlib_ctx_t h3m = NULL; wchar_t fullpath[MAX_PATH] = { 0 }; wchar_t fullpath_out[MAX_PATH] = { 0 }; wchar_t fullpath_patch[MAX_PATH] = { 0 }; wchar_t *version = L"unknown"; enum H3M_FORMAT fm_src = 0; int ret = 0; snwprintf(fullpath, sizeof(fullpath) / sizeof(fullpath[0])-1, L"%s\\%s", src_path, filename); h3m_read_convert_u(&h3m, fullpath, H3M_FORMAT_ROE, &fm_src, NULL, NULL, NULL, NULL); if (NULL == h3m) { if (NULL != cb) { if (0 != (ret = cb(filename, fm_src, (H3M_FORMAT_ROE != fm_src) ? CONVERT_RESULT_FAIL : CONVERT_RESULT_SKIP, cb_data))) { return ret; } } return 0; } switch (fm_src) { case H3M_FORMAT_AB: version = L"AB"; break; case H3M_FORMAT_SOD: version = L"SoD"; break; case H3M_FORMAT_WOG: version = L"WoG"; break; default: version = L"??"; } snwprintf(fullpath_out, sizeof(fullpath_out) / sizeof(fullpath_out[0])-1, L"%s\\[%s-RoE] %s", dest_path, version, filename); snwprintf(fullpath_patch, sizeof(fullpath_patch)-sizeof(fullpath_patch[0]) - 1, L"h3mpatches\\patch_%s", filename); if (INVALID_FILE_ATTRIBUTES != GetFileAttributesW(fullpath_patch)) { h3m_object_patch_u(h3m, fullpath_patch); } h3m_write_u(h3m, fullpath_out); //h3m_compress(fullpath_out, fullpath_out); h3m_exit(&h3m); if (NULL != cb) { if (0 != (ret = cb(filename, fm_src, CONVERT_RESULT_SUCCESS, cb_data))) { return ret; } } return 0; }
enum H3MSNAKE_STATE h3msnake_update_state(enum H3MSNAKE_INPUT input) { enum H3MSNAKE_STATE state = H3MSNAKE_STATE_ALIVE; int x_inc = 0; int y_inc = 0; switch (input) { case H3MSNAKE_INPUT_START: ExitProcess(1); case H3MSNAKE_INPUT_LEFT: f_state.direction = DIR_LEFT; break; case H3MSNAKE_INPUT_DOWN: f_state.direction = DIR_DOWN; break; case H3MSNAKE_INPUT_UP: f_state.direction = DIR_UP; break; case H3MSNAKE_INPUT_RIGHT: f_state.direction = DIR_RIGHT; break; default: break; } //char dbg[256] = { 0 }; //sprintf(dbg, "input: %d\n", input); //OutputDebugStringA(dbg); switch (f_state.direction) { case DIR_RIGHT: x_inc = 1; break; case DIR_UP: y_inc = -1; break; case DIR_LEFT: x_inc = -1; break; case DIR_DOWN: y_inc = 1; break; default: *((int *)(0xFBADC0DE)) = 0xDEADDEAD; } if (0 != _update_nodes(x_inc, y_inc)) { int oa_index = 0; const char *def_gameover = "ava0128.def"; // Pandoras const char *def_score = f_state.def_apple; char score[12]; int terrain = f_state.terrain; h3m_exit(&f_state.h3m); f_state.h3m = NULL; h3m_init_min(&f_state.h3m, H3M_FORMAT_ROE, 36); h3m_add_oa_by_def(f_state.h3m, def_gameover, &oa_index); h3m_alg_od_text(f_state.h3m, def_gameover, oa_index, 7, 1 + 6, 0, "GAME"); h3m_alg_od_text(f_state.h3m, def_gameover, oa_index, 7, 1 + 6 + 6, 0, "OVER"); snprintf(score, sizeof(score)-1, "%d", f_state.score); h3m_add_oa_by_name(f_state.h3m, f_state.def_apple, &oa_index); h3m_alg_od_text(f_state.h3m, f_state.def_apple, oa_index, 7, 1, 0, score); //h3m_object_add(f_state.h3m, "Angel", 5, 5, 0, NULL); uint8_t terrain_types[36 * 36]; uint8_t river_types[36 * 36]; uint8_t road_types[36 * 36]; uint8_t impassable[36][36]; memset(terrain_types, terrain, sizeof(terrain_types)); memset(river_types, 0, sizeof(river_types)); memset(road_types, 0, sizeof(road_types)); memset(impassable, 1, sizeof(impassable)); h3m_generate_tiles(f_state.h3m, 36, 0, (uint8_t *)terrain_types, (uint8_t *)road_types, (uint8_t *)river_types); for (int i = 0; i < 36; ++i) { for (int j = 6; j < 30; ++j) impassable[i][j] = 0; } h3m_impassable_fill(f_state.h3m, (uint8_t *)impassable, 36); state = H3MSNAKE_STATE_DEAD; } h3m_write(f_state.h3m, f_state.filename); return state; }