Merge branch 'master' into battle_engine_v2

This commit is contained in:
DizzyEggg 2019-05-15 13:31:53 +02:00
commit 94045ace0b
31 changed files with 39074 additions and 8584 deletions

1
.gitignore vendored
View File

@ -27,5 +27,6 @@ Thumbs.db
build/
.DS_Store
*.ddump
.idea/
porymap.project.cfg
.vscode/

View File

@ -22,9 +22,15 @@ install:
matrix:
include:
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
env: _="Build"
script:
- ./build_tools.sh
- ./build_tools.sh g++-7
- make -j2 compare
after_success:
- .travis/calcrom/webhook.sh pokeemerald

View File

@ -23,6 +23,7 @@ MAP = $(ROM:.gba=.map)
C_SUBDIR = src
ASM_SUBDIR = asm
DATA_SRC_SUBDIR = src/data
DATA_ASM_SUBDIR = data
SONG_SUBDIR = sound/songs
MID_SUBDIR = sound/songs/midi
@ -53,6 +54,7 @@ PREPROC := tools/preproc/preproc$(EXE)
RAMSCRGEN := tools/ramscrgen/ramscrgen$(EXE)
FIX := tools/gbafix/gbafix$(EXE)
MAPJSON := tools/mapjson/mapjson$(EXE)
JSONPROC := tools/jsonproc/jsonproc$(EXE)
# Clear the default suffixes
.SUFFIXES:
@ -86,6 +88,8 @@ OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS))
SUBDIRS := $(sort $(dir $(OBJS)))
AUTO_GEN_TARGETS :=
$(shell mkdir -p $(SUBDIRS))
rom: $(ROM)
@ -101,6 +105,7 @@ clean: tidy
rm -f $(DATA_ASM_SUBDIR)/layouts/layouts.inc $(DATA_ASM_SUBDIR)/layouts/layouts_table.inc
rm -f $(DATA_ASM_SUBDIR)/maps/connections.inc $(DATA_ASM_SUBDIR)/maps/events.inc $(DATA_ASM_SUBDIR)/maps/groups.inc $(DATA_ASM_SUBDIR)/maps/headers.inc
find $(DATA_ASM_SUBDIR)/maps \( -iname 'connections.inc' -o -iname 'events.inc' -o -iname 'header.inc' \) -exec rm {} +
rm -f $(AUTO_GEN_TARGETS)
tidy:
rm -f $(ROM) $(ELF) $(MAP)
@ -109,6 +114,7 @@ tidy:
include graphics_file_rules.mk
include map_data_rules.mk
include spritesheet_rules.mk
include json_data_rules.mk
include songs.mk
%.s: ;

File diff suppressed because it is too large Load Diff

View File

@ -4,4 +4,4 @@ OBJDUMP="$DEVKITARM/bin/arm-none-eabi-objdump -D -bbinary -marmv4t -Mforce-thumb
OPTIONS="--start-address=$(($1)) --stop-address=$(($1 + $2))"
$OBJDUMP $OPTIONS baserom.gba > baserom.dump
$OBJDUMP $OPTIONS pokeemerald.gba > pokeemerald.dump
diff baserom.dump pokeemerald.dump
diff -u baserom.dump pokeemerald.dump

View File

@ -9,3 +9,4 @@ make -C tools/ramscrgen CXX=${1:-g++}
make -C tools/gbafix CXX=${1:-g++}
make -C tools/mid2agb CXX=${1:-g++}
make -C tools/mapjson CXX=${1:-g++}
make -C tools/jsonproc CXX=${1:-g++}

View File

@ -39,36 +39,39 @@ gUnknown_082F449C:: @ 82F449C
.byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x07, 0x08
.byte 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06
.byte 0x08, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05
.byte 0x06, 0x07, 0x08, 0x04, 0x05, 0x06, 0x00, 0x00
.byte 0x06, 0x07, 0x08
gUknnown_082F45AF::
.byte 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03
.byte 0x04, 0x05, 0x05, 0x06, 0x03, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x05
.byte 0x06, 0x06, 0x07, 0x02, 0x02, 0x03, 0x04, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x05
.byte 0x05, 0x06, 0x07, 0x07, 0x08, 0x01, 0x01, 0x02
.byte 0x03, 0x00, 0x00, 0x00, 0x04, 0x05, 0x06, 0x06
.byte 0x07, 0x08, 0x08, 0x09, 0x00, 0x00, 0x01, 0x02
.byte 0x02, 0x03, 0x04, 0x01, 0x00, 0x01, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x03, 0x04, 0x05, 0x05, 0x06, 0x03
.byte 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x04, 0x05, 0x06, 0x06, 0x07, 0x02, 0x02
.byte 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x03, 0x04, 0x05, 0x05, 0x06, 0x07, 0x07, 0x08
.byte 0x01, 0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0x04
.byte 0x05, 0x06, 0x06, 0x07, 0x08, 0x08, 0x09, 0x00
.byte 0x00, 0x01, 0x02, 0x02, 0x03, 0x04, 0x01, 0x00
.byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01
.byte 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00
.byte 0x01, 0x02, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01
.byte 0x02, 0x01, 0x02, 0x03, 0x02, 0x03, 0x00, 0x00
.byte 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x01, 0x02
.byte 0x01, 0x02, 0x03, 0x02, 0x03, 0x04, 0x03, 0x04
.byte 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x09, 0x09
.byte 0x01, 0x01, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09
.byte 0x09, 0x09, 0x00, 0x00, 0x01, 0x01, 0x00, 0x09
.byte 0x09, 0x09, 0x09, 0x09, 0x02, 0x02, 0x00, 0x00
.byte 0x01, 0x01, 0x01, 0x09, 0x09, 0x09, 0x03, 0x03
.byte 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x09
.byte 0x03, 0x03, 0x04, 0x04, 0x00, 0x00, 0x01, 0x01
.byte 0x02, 0x02, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00
.byte 0x04, 0x06, 0x00, 0x00, 0x00, 0x03, 0x05, 0x07
.byte 0x00, 0x00, 0x02, 0x04, 0x06, 0x08, 0x00, 0x01
.byte 0x03, 0x05, 0x06, 0x09
.byte 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x02, 0x01
.byte 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x03, 0x00, 0x01, 0x00, 0x01, 0x02, 0x01, 0x02
.byte 0x03, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x04
.byte 0x00, 0x01, 0x00, 0x01, 0x02, 0x01, 0x02, 0x03
.byte 0x02, 0x03, 0x04, 0x03, 0x04, 0x00, 0x00, 0x00
.byte 0x00, 0x09, 0x09, 0x09, 0x09, 0x01, 0x01, 0x01
.byte 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x00
.byte 0x00, 0x01, 0x01, 0x00, 0x09, 0x09, 0x09, 0x09
.byte 0x09, 0x02, 0x02, 0x00, 0x00, 0x01, 0x01, 0x01
.byte 0x09, 0x09, 0x09, 0x03, 0x03, 0x00, 0x00, 0x01
.byte 0x01, 0x02, 0x02, 0x03, 0x09, 0x03, 0x03, 0x04
.byte 0x04, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03
.byte 0x05, 0x00, 0x00, 0x00, 0x00, 0x04, 0x06, 0x00
.byte 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x02
.byte 0x04, 0x06, 0x08, 0x00, 0x01, 0x03, 0x05, 0x06
.byte 0x09
.align 2
gUnknown_082F7DF0_UnrefDupe:: @ 82F4698

View File

@ -334,7 +334,7 @@ LittlerootTown_ProfessorBirchsLab_EventScript_1FA061:: @ 81FA061
LittlerootTown_ProfessorBirchsLab_EventScript_1FA06C:: @ 81FA06C
bufferspeciesname 0, SPECIES_CYNDAQUIL
setvar VAR_TEMP_1, 155
setvar VAR_TEMP_1, SPECIES_CYNDAQUIL
givemon SPECIES_CYNDAQUIL, 5, ITEM_NONE, 0x0, 0x0, 0
compare VAR_RESULT, 0
goto_if_eq LittlerootTown_ProfessorBirchsLab_EventScript_1FA0A1
@ -379,7 +379,7 @@ LittlerootTown_ProfessorBirchsLab_EventScript_1FA0FD:: @ 81FA0FD
LittlerootTown_ProfessorBirchsLab_EventScript_1FA10D:: @ 81FA10D
bufferspeciesname 0, SPECIES_TOTODILE
setvar VAR_TEMP_1, 158
setvar VAR_TEMP_1, SPECIES_TOTODILE
givemon SPECIES_TOTODILE, 5, ITEM_NONE, 0x0, 0x0, 0
compare VAR_RESULT, 0
goto_if_eq LittlerootTown_ProfessorBirchsLab_EventScript_1FA142
@ -424,7 +424,7 @@ LittlerootTown_ProfessorBirchsLab_EventScript_1FA19E:: @ 81FA19E
LittlerootTown_ProfessorBirchsLab_EventScript_1FA1AE:: @ 81FA1AE
bufferspeciesname 0, SPECIES_CHIKORITA
setvar VAR_TEMP_1, 152
setvar VAR_TEMP_1, SPECIES_CHIKORITA
givemon SPECIES_CHIKORITA, 5, ITEM_NONE, 0x0, 0x0, 0
compare VAR_RESULT, 0
goto_if_eq LittlerootTown_ProfessorBirchsLab_EventScript_1FA1E3

View File

@ -84,7 +84,7 @@ MossdeepCity_StevensHouse_EventScript_22285B:: @ 822285B
end
MossdeepCity_StevensHouse_EventScript_222865:: @ 8222865
setvar VAR_TEMP_1, 398
setvar VAR_TEMP_1, SPECIES_BELDUM
givemon SPECIES_BELDUM, 5, ITEM_NONE, 0x0, 0x0, 0
compare VAR_RESULT, 0
goto_if_eq MossdeepCity_StevensHouse_EventScript_222895

View File

@ -83,7 +83,7 @@ Route119_WeatherInstitute_2F_EventScript_26FFC8:: @ 826FFC8
Route119_WeatherInstitute_2F_EventScript_27004D:: @ 827004D
msgbox Route119_WeatherInstitute_2F_Text_270650, MSGBOX_DEFAULT
setvar VAR_TEMP_1, 385
setvar VAR_TEMP_1, SPECIES_CASTFORM
givemon SPECIES_CASTFORM, 25, ITEM_MYSTIC_WATER, 0x0, 0x0, 0
compare VAR_RESULT, 0
goto_if_eq Route119_WeatherInstitute_2F_EventScript_270085

View File

@ -156,7 +156,7 @@ RustboroCity_DevonCorp_2F_EventScript_211A2C:: @ 8211A2C
end
RustboroCity_DevonCorp_2F_EventScript_211A3E:: @ 8211A3E
setvar VAR_TEMP_1, 388
setvar VAR_TEMP_1, SPECIES_LILEEP
givemon SPECIES_LILEEP, 20, ITEM_NONE, 0x0, 0x0, 0
compare VAR_RESULT, 0
goto_if_eq RustboroCity_DevonCorp_2F_EventScript_211A6E
@ -205,7 +205,7 @@ RustboroCity_DevonCorp_2F_EventScript_211AD7:: @ 8211AD7
end
RustboroCity_DevonCorp_2F_EventScript_211AE1:: @ 8211AE1
setvar VAR_TEMP_1, 390
setvar VAR_TEMP_1, SPECIES_ANORITH
givemon SPECIES_ANORITH, 20, ITEM_NONE, 0x0, 0x0, 0
compare VAR_RESULT, 0
goto_if_eq RustboroCity_DevonCorp_2F_EventScript_211B11

View File

@ -92,6 +92,11 @@
#define T2_READ_32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
#define T2_READ_PTR(ptr) (void*) T2_READ_32(ptr)
// Macros for checking the joypad
#define TEST_BUTTON(field, button) ({(field) & (button);})
#define JOY_NEW(button) TEST_BUTTON(gMain.newKeys, button)
#define JOY_HELD(button) TEST_BUTTON(gMain.heldKeys, button)
#define S16TOPOSFLOAT(val) \
({ \
s16 v = (val); \

View File

@ -284,6 +284,8 @@ bool8 sub_800DE7C(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2, u8 idx);
bool8 sub_800DF34(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2, u8 idx);
s32 sub_800E87C(u8 idx);
void sub_8011BA4(void);
void sub_8010198(void);
void sub_8011AC8(void);
void LinkRfu_FatalError(void);
bool32 sub_8011A9C(void);
void sub_80104B0(void);

6
include/pokemon_jump.h Executable file → Normal file
View File

@ -3,9 +3,9 @@
#include "main.h"
void sub_802EB24(u8, u8, u8, u8, u8);
bool32 sub_802EB84(void);
void sub_802A9A8(u16 monId, MainCallback callback);
bool32 sub_802C908(u16 species);
#endif // GUARD_POKEMON_JUMP_H
#endif //GUARD_POKEMON_JUMP_H

8
json_data_rules.mk Executable file
View File

@ -0,0 +1,8 @@
# JSON files are run through jsonproc, which is a tool that converts JSON data to an output file
# based on an Inja template. https://github.com/pantor/inja
AUTO_GEN_TARGETS += $(DATA_SRC_SUBDIR)/wild_encounters.h
$(DATA_SRC_SUBDIR)/wild_encounters.h: $(DATA_SRC_SUBDIR)/wild_encounters.json $(DATA_SRC_SUBDIR)/wild_encounters.json.txt
$(JSONPROC) $^ $@
$(C_BUILDDIR)/wild_encounter.o: c_dep += $(DATA_SRC_SUBDIR)/wild_encounters.h

View File

@ -68,6 +68,7 @@ SECTIONS {
src/berry_crush.o(.text);
asm/berry_crush.o(.text);
src/berry_powder.o(.text);
src/dodrio_berry_picking.o(.text);
asm/dodrio_berry_picking.o(.text);
src/pokemon_jump.o(.text);
asm/pokemon_jump.o(.text);
@ -434,6 +435,7 @@ SECTIONS {
src/union_room_chat.o(.rodata);
data/berry_crush.o(.rodata);
data/berry_powder.o(.rodata);
src/dodrio_berry_picking.o(.rodata);
data/dodrio_berry_picking.o(.rodata);
src/pokemon_jump.o(.rodata);
data/pokemon_jump.o(.rodata);

1
src/data/.gitignore vendored Executable file
View File

@ -0,0 +1 @@
wild_encounters.h

File diff suppressed because it is too large Load Diff

12186
src/data/wild_encounters.json Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,67 @@
{{ doNotModifyHeader }}
## for wild_encounter_group in wild_encounter_groups
## for encounter in wild_encounter_group.encounters
{% if existsIn(encounter, "land_mons") %}
const struct WildPokemon {{ encounter.base_label }}_LandMons[] =
{
## for wild_mon in encounter.land_mons.mons
{ {{ wild_mon.min_level }}, {{ wild_mon.max_level }}, {{ wild_mon.species }} },
## endfor
};
const struct WildPokemonInfo {{ encounter.base_label }}_LandMonsInfo = { {{encounter.land_mons.encounter_rate}}, {{ encounter.base_label }}_LandMons };
{% endif %}
{% if existsIn(encounter, "water_mons") %}
const struct WildPokemon {{ encounter.base_label }}_WaterMons[] =
{
## for wild_mon in encounter.water_mons.mons
{ {{ wild_mon.min_level }}, {{ wild_mon.max_level }}, {{ wild_mon.species }} },
## endfor
};
const struct WildPokemonInfo {{ encounter.base_label }}_WaterMonsInfo = { {{encounter.water_mons.encounter_rate}}, {{ encounter.base_label }}_WaterMons };
{% endif %}
{% if existsIn(encounter, "rock_smash_mons") %}
const struct WildPokemon {{ encounter.base_label }}_RockSmashMons[] =
{
## for wild_mon in encounter.rock_smash_mons.mons
{ {{ wild_mon.min_level }}, {{ wild_mon.max_level }}, {{ wild_mon.species }} },
## endfor
};
const struct WildPokemonInfo {{ encounter.base_label }}_RockSmashMonsInfo = { {{encounter.rock_smash_mons.encounter_rate}}, {{ encounter.base_label }}_RockSmashMons };
{% endif %}
{% if existsIn(encounter, "fishing_mons") %}
const struct WildPokemon {{ encounter.base_label }}_FishingMons[] =
{
## for wild_mon in encounter.fishing_mons.mons
{ {{ wild_mon.min_level }}, {{ wild_mon.max_level }}, {{ wild_mon.species }} },
## endfor
};
const struct WildPokemonInfo {{ encounter.base_label }}_FishingMonsInfo = { {{encounter.fishing_mons.encounter_rate}}, {{ encounter.base_label }}_FishingMons };
{% endif %}
## endfor
const struct WildPokemonHeader {{ wild_encounter_group.label }}[] =
{
## for encounter in wild_encounter_group.encounters
{
.mapGroup = {% if wild_encounter_group.for_maps %}MAP_GROUP({{ removePrefix(encounter.map, "MAP_") }}){% else %}0{% endif %},
.mapNum = {% if wild_encounter_group.for_maps %}MAP_NUM({{ removePrefix(encounter.map, "MAP_") }}){% else %}{{ loop.index1 }}{% endif %},
.landMonsInfo = {% if existsIn(encounter, "land_mons") %}&{{ encounter.base_label }}_LandMonsInfo{% else %}NULL{% endif %},
.waterMonsInfo = {% if existsIn(encounter, "water_mons") %}&{{ encounter.base_label }}_WaterMonsInfo{% else %}NULL{% endif %},
.rockSmashMonsInfo = {% if existsIn(encounter, "rock_smash_mons") %}&{{ encounter.base_label }}_RockSmashMonsInfo{% else %}NULL{% endif %},
.fishingMonsInfo = {% if existsIn(encounter, "fishing_mons") %}&{{ encounter.base_label }}_FishingMonsInfo{% else %}NULL{% endif %},
},
## endfor
{
.mapGroup = MAP_GROUP(UNDEFINED),
.mapNum = MAP_NUM(UNDEFINED),
.landMonsInfo = NULL,
.waterMonsInfo = NULL,
.rockSmashMonsInfo = NULL,
.fishingMonsInfo = NULL,
},
};
## endfor

2355
src/dodrio_berry_picking.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,6 @@ struct UnkStruct_2022C6C
};
IWRAM_DATA struct UnkStruct_3000DAC * gUnknown_03000DAC;
IWRAM_DATA bool32 gUnknown_03000DB0;
EWRAM_DATA struct UnkStruct_2022C6C * gUnknown_02022C6C = NULL;

View File

@ -43,6 +43,16 @@ EWRAM_DATA static u32 sFeebasRngValue = 0;
#include "data/wild_encounters.h"
//Special Feebas-related data.
const struct WildPokemon gWildFeebasRoute119Data = {20, 25, SPECIES_FEEBAS};
const u16 gRoute119WaterTileData[] =
{
0, 0x2D, 0,
0x2E, 0x5B, 0x83,
0x5C, 0x8B, 0x12A,
};
// code
void DisableWildEncounters(bool8 disabled)
{

View File

@ -9,6 +9,7 @@
.include "src/link_rfu.o"
.include "src/union_room.o"
.include "src/union_room_battle.o"
.include "src/dodrio_berry_picking.o"
.include "src/rtc.o"
.include "src/main_menu.o"
.include "src/rom_8034C54.o"

View File

@ -17,29 +17,7 @@
.include "src/union_room_chat.o"
.include "src/berry_crush.o"
.include "src/berry_powder.o"
.align 2
@ dodrio_berry_picking
gUnknown_02022C98: @ 2022C98
.space 0x4
gUnknown_02022C9C: @ 2022C9C
.space 0x14
gUnknown_02022CB0: @ 2022CB0
.space 0x8
gUnknown_02022CB8: @ 2022CB8
.space 0x2C
gUnknown_02022CE4: @ 2022CE4
.space 0x10
gUnknown_02022CF4: @ 2022CF4
.space 0x4
gUnknown_02022CF8: @ 2022CF8
.space 0x4
.include "src/dodrio_berry_picking.o"
@ pokemon_jump
gUnknown_02022CFC: @ 2022CFC

1
tools/jsonproc/.gitignore vendored Executable file
View File

@ -0,0 +1 @@
jsonproc

17
tools/jsonproc/Makefile Executable file
View File

@ -0,0 +1,17 @@
CXX := g++
CXXFLAGS := -Wall -std=c++11 -O2
INCLUDES := -I .
SRCS := jsonproc.cpp
HEADERS := jsonproc.h inja.hpp nlohmann/json.hpp
.PHONY: clean
jsonproc: $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) $(INCLUDES) $(SRCS) -o $@ $(LDFLAGS)
clean:
$(RM) jsonproc jsonproc.exe

3396
tools/jsonproc/inja.hpp Executable file

File diff suppressed because it is too large Load Diff

91
tools/jsonproc/jsonproc.cpp Executable file
View File

@ -0,0 +1,91 @@
// jsonproc.cpp
#include "jsonproc.h"
#include <map>
#include <string>
using std::string;
#include <inja.hpp>
using namespace inja;
using json = nlohmann::json;
std::map<string, string> customVars;
void set_custom_var(string key, string value)
{
customVars[key] = value;
}
string get_custom_var(string key)
{
return customVars[key];
}
int main(int argc, char *argv[])
{
if (argc != 4)
FATAL_ERROR("USAGE: jsonproc <json-filepath> <template-filepath> <output-filepath>\n");
string jsonfilepath = argv[1];
string templateFilepath = argv[2];
string outputFilepath = argv[3];
Environment env;
// Add custom command callbacks.
env.add_callback("doNotModifyHeader", 0, [jsonfilepath, templateFilepath](Arguments& args) {
return "//\n// DO NOT MODIFY THIS FILE! IT IS AUTO-GENERATED FROM " + jsonfilepath +" and Inja template " + templateFilepath + "\n//\n";
});
env.add_callback("setVar", 2, [=](Arguments& args) {
string key = args.at(0)->get<string>();
string value = args.at(1)->get<string>();
set_custom_var(key, value);
return "";
});
env.add_callback("getVar", 1, [=](Arguments& args) {
string key = args.at(0)->get<string>();
return get_custom_var(key);
});
env.add_callback("concat", 2, [](Arguments& args) {
string first = args.at(0)->get<string>();
string second = args.at(1)->get<string>();
return first + second;
});
env.add_callback("removePrefix", 2, [](Arguments& args) {
string rawValue = args.at(0)->get<string>();
string prefix = args.at(1)->get<string>();
string::size_type i = rawValue.find(prefix);
if (i != 0)
return rawValue;
return rawValue.erase(0, prefix.length());
});
// Add custom command callbacks.
env.add_callback("removeSuffix", 2, [](Arguments& args) {
string rawValue = args.at(0)->get<string>();
string suffix = args.at(1)->get<string>();
string::size_type i = rawValue.rfind(suffix);
if (i == string::npos)
return rawValue;
return rawValue.substr(0, i);
});
try
{
env.write_with_json_file(templateFilepath, jsonfilepath, outputFilepath);
}
catch (const std::exception& e)
{
FATAL_ERROR("JSONPROC_ERROR: %s\n", e.what());
}
return 0;
}

32
tools/jsonproc/jsonproc.h Executable file
View File

@ -0,0 +1,32 @@
// jsonproc.h
#ifndef JSONPROC_H
#define JSONPROC_H
#include <cstdlib>
#include <cstdio>
using std::fprintf; using std::exit;
#include <cstdlib>
#ifdef _MSC_VER
#define FATAL_ERROR(format, ...) \
do \
{ \
fprintf(stderr, format, __VA_ARGS__); \
exit(1); \
} while (0)
#else
#define FATAL_ERROR(format, ...) \
do \
{ \
fprintf(stderr, format, ##__VA_ARGS__); \
exit(1); \
} while (0)
#endif // _MSC_VER
#endif // JSONPROC_H

20842
tools/jsonproc/nlohmann/json.hpp Executable file

File diff suppressed because it is too large Load Diff