Skip to content

Commit

Permalink
tasofro: fix spellcards support for data/csv/story/*, and add an enum…
Browse files Browse the repository at this point in the history
… for game IDs (as cf98a5a for thcrap-tsa). [V]
  • Loading branch information
brliron committed Aug 30, 2017
1 parent a49c124 commit 33c56d9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
10 changes: 9 additions & 1 deletion thcrap_tasofro/src/spellcards_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include <thcrap.h>
#include "thcrap_tasofro.h"
#include <vfs.h>
#include "spellcards_generator.h"

Expand Down Expand Up @@ -80,9 +81,16 @@ json_t* spell_story_generator(std::unordered_map<std::string, json_t*> in_data,

json_t *ret = nullptr;
if (max_spell_id != -1) {
DWORD story_spell_col;
if (game_id >= TH145) {
story_spell_col = 8;
}
else {
story_spell_col = 10;
}
// Build the json object.
ret = json_object();
VLA(char, spell_name, 6 /* story- */ + strlen(character_name) + 8 /* -stageNN */ + 3 /* -NN */ + 2 /* -N */ + 1);
VLA(char, spell_name, 6 /* story- */ + strlen(character_name) + story_spell_col /* -stageNN */ + 3 /* -NN */ + 2 /* -N */ + 1);
for (int spell_id = 1; spell_id <= max_spell_id; spell_id++) {
const char *last_spell_translation = nullptr;
for (int difficulty_id = 1; difficulty_id <= 4; difficulty_id++) {
Expand Down
39 changes: 27 additions & 12 deletions thcrap_tasofro/src/thcrap_tasofro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,34 @@
#include "plugin.h"
#include "crypt.h"

tasofro_game_t game_id;

// Translate strings to IDs.
static tasofro_game_t game_id_from_string(const char *game)
{
if (!strcmp(game, "th135")) {
return TH135;
}
else if (!strcmp(game, "th145")) {
return TH145;
}
return TH_FUTURE;
}

// TODO: read the file names list in JSON format
int __stdcall thcrap_plugin_init()
{
char* filenames_list;
size_t filenames_list_size;

const char *game = json_object_get_string(runconfig_get(), "game");
game_id = game_id_from_string(game);

int base_tasofro_removed = stack_remove_if_unneeded("base_tasofro");
if (base_tasofro_removed == 1) {
return 1;
} else if(base_tasofro_removed == -1) {
const char *game = json_object_get_string(runconfig_get(), "game");
if(game && !strcmp(game, "th145")) {
if(game_id == TH145) {
log_mboxf(NULL, MB_OK | MB_ICONINFORMATION,
"Support for TH14.5 has been moved out of the sandbox.\n"
"\n"
Expand All @@ -42,16 +58,11 @@ int __stdcall thcrap_plugin_init()
}

const char *crypt = json_object_get_string(runconfig_get(), "crypt");
if (strcmp(crypt, "th135") == 0) {
ICrypt::instance = new CryptTh135();
}
else if (strcmp(crypt, "th145") == 0) {
if (game_id >= TH145) {
ICrypt::instance = new CryptTh145();
}
else {
log_printf("thcrap_tasofro: unknown value for crypt in runconfig: \"%s\" (known values: th135, th145).\n"
"Defaulting to th145.\n", crypt);
ICrypt::instance = new CryptTh145();
ICrypt::instance = new CryptTh135();
}

patchhook_register("*/stage*.pl", patch_pl);
Expand All @@ -63,9 +74,13 @@ int __stdcall thcrap_plugin_init()
patchhook_register("*.txt", patch_plaintext);

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);
jsonvfs_game_add("data/csv/Item*.csv.jdiff", { "spells.js" }, spell_player_generator);
jsonvfs_game_add("data/system/char_select3/*/equip/*/000.png.csv.jdiff", { "spells.js" }, spell_char_select_generator);
if (game_id >= TH145) {
jsonvfs_game_add("data/csv/spellcard/*.csv.jdiff", { "spells.js" }, spell_player_generator);
jsonvfs_game_add("data/system/char_select3/*/equip/*/000.png.csv.jdiff",{ "spells.js" }, spell_char_select_generator);
}
else {
jsonvfs_game_add("data/csv/Item*.csv.jdiff", { "spells.js" }, spell_player_generator);
}

filenames_list = (char*)stack_game_file_resolve("fileslist.txt", &filenames_list_size);
LoadFileNameListFromMemory(filenames_list, filenames_list_size);
Expand Down
18 changes: 18 additions & 0 deletions thcrap_tasofro/src/thcrap_tasofro.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
#include <bp_file.h>
#include <jansson.h>

typedef enum {
// • filename hash: uses hash = ch ^ 0x1000193 * hash
// • spells: using data/csv/Item*.csv
// • spells: data/csv/story/*/*.csv has columns for popularity
TH135,

// • filename hash: uses hash = (hash ^ ch) * 0x1000193
// • XOR: uses an additional AUX parameter
// • XOR: key compunents are multiplied by -1
// • spells: using data/csv/spellcards/*.csv and data/system/char_select3/*/equip/*/000.png.csv
TH145,

// Any future game without relevant changes
TH_FUTURE,
} tasofro_game_t;

extern tasofro_game_t game_id;

struct FileHeader
{
DWORD filename_hash;
Expand Down
2 changes: 1 addition & 1 deletion thcrap_tsa/src/thcrap_tsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
tsa_game_t game_id;

// Translate strings to IDs.
tsa_game_t game_id_from_string(const char *game)
static tsa_game_t game_id_from_string(const char *game)
{
if(!strcmp(game, "th06")) {
return TH06;
Expand Down

0 comments on commit 33c56d9

Please sign in to comment.