Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuff for pksm-core G1&2 support #67

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 4 additions & 125 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,19 @@ on:

jobs:
build:
runs-on: macos-latest
runs-on: ubuntu-latest
container: devkitpro/devkitarm
name: Build pkmn-chest
outputs:
commit_tag: ${{ steps.build.outputs.commit_tag }}
commit_hash: ${{ steps.build.outputs.commit_hash }}
author_name: ${{ steps.build.outputs.author_name }}
committer_name: ${{ steps.build.outputs.committer_name }}
commit_subject: ${{ steps.build.outputs.commit_subject }}
commit_message: ${{ steps.build.outputs.commit_message }}
steps:
- name: Checkout repo
uses: actions/checkout@v1
with:
submodules: recursive
- name: Install tools
run: |
curl -L https://github.com/Universal-Team/bmp2ds/releases/download/v1.0.0/bmp2ds-macos -o bmp2ds
curl -L https://github.com/Universal-Team/bmp2ds/releases/download/v1.0.0/bmp2ds-linux -o bmp2ds
chmod +x bmp2ds
mv bmp2ds /usr/local/bin

curl -LO https://github.com/devkitPro/pacman/releases/latest/download/devkitpro-pacman-installer.pkg
sudo installer -pkg devkitpro-pacman-installer.pkg -target /
sudo dkp-pacman -Sy
sudo dkp-pacman -S nds-dev --noconfirm
- name: Build
id: build
run: |
Expand All @@ -46,123 +35,13 @@ jobs:

make all dsi

sudo mv tools-osx/make_cia /usr/local/bin
sudo mv tools-linux/make_cia /usr/local/bin
make cia

mkdir -p ~/artifacts
cp pkmn-chest.* ~/artifacts

echo ::set-output name=commit_tag::$(git describe --abbrev=0 --tags)
echo ::set-output name=commit_hash::$(git log --format=%h -1)

# Webhook info
echo "::set-output name=author_name::$(git log -1 $GITHUB_SHA --pretty=%aN)"
echo "::set-output name=committer_name::$(git log -1 $GITHUB_SHA --pretty=%cN)"
echo "::set-output name=commit_subject::$(git log -1 $GITHUB_SHA --pretty=%s)"
echo "::set-output name=commit_message::$(git log -1 $GITHUB_SHA --pretty=%b)"
- name: Publish build to GH Actions
uses: actions/upload-artifact@v2
with:
path: ~/artifacts/*
name: build

# Only run this for non-PR jobs.
publish_build:
runs-on: ubuntu-latest
name: Publish build to Universal-Team/extras
if: ${{ success() && !startsWith(github.ref, 'refs/pull') }}
needs: build
env:
COMMIT_TAG: ${{ needs.build.outputs.commit_tag }}
COMMIT_HASH: ${{ needs.build.outputs.commit_hash }}
AUTHOR_NAME: ${{ needs.build.outputs.author_name }}
COMMIT_SUBJECT: ${{ needs.build.outputs.commit_subject }}
COMMIT_MESSAGE: ${{ needs.build.outputs.commit_message }}
outputs:
current_date: ${{ steps.commit.outputs.current_date }}
steps:
- name: Install tools
run: |
sudo apt-get update
sudo apt-get install qrencode -y
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: build
path: build
- name: Upload to ${{ github.repository }} release
if: ${{ startsWith(github.ref, 'refs/tags') }}
run: |
ID=$(jq --raw-output '.release.id' $GITHUB_EVENT_PATH)

for file in ${{ github.workspace }}/build/*; do
AUTH_HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
CONTENT_LENGTH="Content-Length: $(stat -c%s $file)"
CONTENT_TYPE="Content-Type: application/7z-x-compressed"
UPLOAD_URL="https://uploads.github.com/repos/${{ github.repository }}/releases/$ID/assets?name=$(basename $file)"

curl -XPOST -H "$AUTH_HEADER" -H "$CONTENT_LENGTH" -H "$CONTENT_TYPE" --upload-file "$file" "$UPLOAD_URL"
done
- name: Commit and push to Universal-Team/extras
id: commit
run: |
CURRENT_DATE=$(date +"%Y%m%d-%H%M%S")
echo ::set-output name=current_date::$CURRENT_DATE

git config --global user.email "[email protected]"
git config --global user.name "TWLBot"
git clone --depth 1 https://${{ secrets.TWLBOT_TOKEN }}@github.com/Universal-Team/extras.git
mkdir -p extras/builds/pkmn-chest
cd extras/builds/pkmn-chest
qrencode -o pkmn-chest.png https://raw.githubusercontent.com/Universal-Team/extras/v$CURRENT_DATE/builds/pkmn-chest/pkmn-chest.cia
qrencode -o pkmn-chest-release.png https://github.com/Universal-Team/pkmn-chest/releases/download/$COMMIT_TAG/pkmn-chest.cia
cp ${{ github.workspace }}/build/* .
git stage .
git commit -m "pkmn-chest | $COMMIT_HASH"
git tag v$CURRENT_DATE
git push origin master v$CURRENT_DATE
- name: Release to Universal-Team/extras
run: |
AUTH_HEADER="Authorization: token ${{ secrets.TWLBOT_TOKEN }}"
CONTENT_TYPE="Content-Type: application/json"
API_URL="https://api.github.com/repos/Universal-Team/extras/releases"
RELEASE_INFO="{\"tag_name\": \"v${{ steps.commit.outputs.current_date }}\", \"name\": \"pkmn-chest | $COMMIT_HASH\", \"body\": \"$AUTHOR_NAME - $COMMIT_SUBJECT\n\n$COMMIT_MESSAGE\", \"prerelease\": true}"

RESPONSE=$(curl -XPOST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" "$API_URL" -d "$RELEASE_INFO")

ID=$(echo $RESPONSE | jq --raw-output '.id')

for file in ${{ github.workspace }}/build/*; do
AUTH_HEADER="Authorization: token ${{ secrets.TWLBOT_TOKEN }}"
CONTENT_LENGTH="Content-Length: $(stat -c%s $file)"
CONTENT_TYPE="Content-Type: application/7z-x-compressed"
UPLOAD_URL="https://uploads.github.com/repos/Universal-Team/extras/releases/$ID/assets?name=$(basename $file)"

curl -XPOST -H "$AUTH_HEADER" -H "$CONTENT_LENGTH" -H "$CONTENT_TYPE" --upload-file "$file" "$UPLOAD_URL"
done

send_webhook:
runs-on: ubuntu-latest
needs: [publish_build, build]
name: Send Discord webhook
if: ${{ !startsWith(github.ref, 'refs/pull') }}
env:
CURRENT_DATE: ${{ needs.publish_build.outputs.current_date }}
AUTHOR_NAME: ${{ needs.build.outputs.author_name }}
COMMITTER_NAME: ${{ needs.build.outputs.committer_name }}
COMMIT_SUBJECT: ${{ needs.build.outputs.commit_subject }}
COMMIT_MESSAGE: ${{ needs.build.outputs.commit_message }}
steps:
- name: Send success webhook
if: ${{ success() }}
run: |
curl -o send.sh https://raw.githubusercontent.com/Universal-Team/discord-webhooks/master/send-ghactions.sh
chmod +x send.sh
export IMAGE=https://raw.githubusercontent.com/Universal-Team/extras/v$CURRENT_DATE/builds/pkmn-chest/pkmn-chest.png
./send.sh success ${{ secrets.WEBHOOK_URL }}
- name: Send failure webhook
if: ${{ failure() }}
run: |
curl -o send.sh https://raw.githubusercontent.com/Universal-Team/discord-webhooks/master/send-ghactions.sh
chmod +x send.sh
./send.sh failure ${{ secrets.WEBHOOK_URL }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
arm9/include/utils/version.hpp
graphics/bmp2ds
nitrofiles/i18n/**/*.txt
nitrofiles/personals/*
nitrofiles/version.txt

*.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "arm9/core"]
path = arm9/core
url = https://github.com/Flagbrew/PKSM-Core.git
url = https://github.com/FlagBrew/PKSM-Core.git
12 changes: 6 additions & 6 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@
"name": "NDS | Windows",
"includePath": [
"${workspaceFolder}/**",
"/devkitpro/libnds/include/**",
"/devkitpro/devkitARM/include/**",
"/devkitpro/devkitARM/arm-none-eabi/include/**"
"C:/devkitpro/libnds/include/**",
"C:/devkitpro/devkitARM/include/**",
"C:/devkitpro/devkitARM/arm-none-eabi/include/**"
],
"defines": [
"ARM9",
"VER_NUMBER=\"vX.X\""
],
"macFrameworkPath": [],
"compilerPath": "/devkitpro/devkitARM/bin/arm-none-eabi-g++.exe",
"compilerPath": "C:/devkitpro/devkitARM/bin/arm-none-eabi-g++.exe",
"cStandard": "c11",
"cppStandard": "c++20",
"intelliSenseMode": "gcc-x64",
"forcedInclude": [
"/devkitpro/libnds/include/nds/arm9/input.h",
"/devkitpro/devkitARM/arm-none-eabi/include/sys/unistd.h"
"C:/devkitpro/libnds/include/nds/arm9/input.h",
"C:/devkitpro/devkitARM/arm-none-eabi/include/sys/unistd.h"
],
"browse": {
"path": [],
Expand Down
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GAME_SUBTITLE1 := Universal-Team

include $(DEVKITARM)/ds_rules

.PHONY : all skip-gs checkarm9 graphics lang cia sound clean format
.PHONY : all skip-gs checkarm9 graphics lang personal cia sound clean format

#---------------------------------------------------------------------------------
# main targets
Expand Down Expand Up @@ -46,6 +46,18 @@ $(NITRO_FILES)/i18n/%.txt : arm9/core/strings/%.txt

lang : $(LANG_TARGETS)

PERSONAL_DIRS := personals
PERSONAL_FILES := personal*
PERSONAL_SOURCES := $(foreach pdir,$(PERSONAL_DIRS),$(foreach file,$(PERSONAL_FILES),$(wildcard arm9/core/$(pdir)/$(file))))
PERSONAL_TARGETS := $(subst arm9/core,$(NITRO_FILES),$(PERSONAL_SOURCES))

$(NITRO_FILES)/personals/% : arm9/core/personals/%
@echo $$(basename $<)
@[ -d "$(@D)" ] || mkdir -p "$(@D)"
@cp -f $< $@

personal : $(PERSONAL_TARGETS)

#---------------------------------------------------------------------------------
sound:
$(MAKE) -C sound
Expand All @@ -55,7 +67,7 @@ arm9/$(TARGET).elf:
$(MAKE) -C arm9

#---------------------------------------------------------------------------------
$(TARGET).nds : graphics sound lang $(NITRO_FILES) arm9/$(TARGET).elf
$(TARGET).nds : graphics sound lang personal $(NITRO_FILES) arm9/$(TARGET).elf
ndstool -c $(TARGET).nds -9 arm9/$(TARGET).elf \
-b1 icon.bmp "$(GAME_TITLE);$(GAME_SUBTITLE1)" $(_ADDFILES) \
-g \#\#\#\# 00 "HOMEBREW" 87 -z 80040000 -a 00000138
Expand All @@ -80,6 +92,7 @@ clean:
@$(MAKE) -C graphics clean
@$(MAKE) -C sound clean
@rm -f $(LANG_TARGETS)
@rm -f $(PERSONAL_TARGETS)
@rm -f $(TARGET).nds $(TARGET).arm9

format:
Expand Down
2 changes: 1 addition & 1 deletion arm9/core
Submodule core updated 196 files
1 change: 1 addition & 0 deletions arm9/include/PKSMCORE_CONFIG.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PKSMCORE_CONFIG

#define _PKSMCORE_LANG_FOLDER "nitro:/i18n/"
#define _PKSMCORE_PERSONAL_FOLDER "nitro:/personals/"
#define _PKSMCORE_GETLINE_FUNC __getline
#define _PKSMCORE_DISABLE_THREAD_SAFETY

Expand Down
2 changes: 1 addition & 1 deletion arm9/include/loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "Sav.hpp"

extern std::shared_ptr<pksm::Sav> save;
extern std::unique_ptr<pksm::Sav> save;

bool loadSave(std::string savePath);

Expand Down
2 changes: 1 addition & 1 deletion arm9/source/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

static std::string saveFileName;

std::shared_ptr<pksm::Sav> save;
std::unique_ptr<pksm::Sav> save;

bool loadSave(std::string savePath) {
save = nullptr;
Expand Down
27 changes: 20 additions & 7 deletions arm9/source/menus/aMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int aMenu(int pkmX, int pkmY, std::vector<Label> &buttons, int buttonMode) {

FILE *out = fopen(getPkxOutputPath(*currentPokemon(pkmX, pkmY)).c_str(), "wb");
if(out) {
fwrite(currentPokemon(pkmX, pkmY)->rawData(), 1, 136, out);
fwrite(currentPokemon(pkmX, pkmY)->rawData().data(), 1, currentPokemon(pkmX, pkmY)->getLength(), out);
fclose(out);
}

Expand Down Expand Up @@ -373,7 +373,7 @@ int aMenu(int pkmX, int pkmY, std::vector<Label> &buttons, int buttonMode) {
.c_str(),
"wb");
if(out) {
fwrite(currentPokemon(x, y)->rawData(), 1, 136, out);
fwrite(currentPokemon(x, y)->rawData().data(), 1, currentPokemon(x, y)->getLength(), out);
fclose(out);
}
}
Expand Down Expand Up @@ -422,12 +422,18 @@ int aMenu(int pkmX, int pkmY, std::vector<Label> &buttons, int buttonMode) {
chdir((mainDrive() + ":/_nds/pkmn-chest/in").c_str());

// Get a pk4/5
std::string fileName = browseForFile({"pk3", "pk4", "pk5", "pk6", "pk7"}, false);
std::string fileName = browseForFile({"pk1", "pk2", "pk3", "pk4", "pk5", "pk6", "pk7"}, false);

// If the fileName isn't blank, inject the Pokémon
if(fileName != "") {
pksm::Generation gen;
switch(fileName[fileName.size() - 1]) {
case '1':
gen = pksm::Generation::ONE;
break;
case '2':
gen = pksm::Generation::TWO;
break;
case '3':
gen = pksm::Generation::THREE;
break;
Expand Down Expand Up @@ -474,11 +480,11 @@ int aMenu(int pkmX, int pkmY, std::vector<Label> &buttons, int buttonMode) {
u8 buffer[size];
fread(buffer, 1, sizeof(buffer), in);
if(topScreen)
Banks::bank->pkm(*pksm::PKX::getPKM(gen, buffer), currentBankBox, pkmPos(pkmX, pkmY));
Banks::bank->pkm(*pksm::PKX::getPKM(gen, buffer, size), currentBankBox, pkmPos(pkmX, pkmY));
else if(inParty)
save->pkm(*save->transfer(*pksm::PKX::getPKM(gen, buffer)), pkmPos(pkmX, pkmY));
save->pkm(*save->transfer(*pksm::PKX::getPKM(gen, buffer, size)), pkmPos(pkmX, pkmY));
else
save->pkm(*save->transfer(*pksm::PKX::getPKM(gen, buffer)),
save->pkm(*save->transfer(*pksm::PKX::getPKM(gen, buffer, size)),
currentSaveBox,
pkmPos(pkmX, pkmY),
false);
Expand Down Expand Up @@ -523,6 +529,11 @@ int aMenu(int pkmX, int pkmY, std::vector<Label> &buttons, int buttonMode) {
pkm->encryptionConstant(pksm::randomNumber(1, 0xFFFFFFFF));
pkm->version(save->version());
switch(pkm->version()) {
case pksm::GameVersion::GD:
case pksm::GameVersion::SV:
case pksm::GameVersion::C:
pkm->metLocation(0x02); // Route 29 (GSC)
break;
case pksm::GameVersion::R:
case pksm::GameVersion::S:
case pksm::GameVersion::E:
Expand Down Expand Up @@ -579,11 +590,13 @@ int aMenu(int pkmX, int pkmY, std::vector<Label> &buttons, int buttonMode) {
pkm->nature(),
pkm->alternativeForm(),
pkm->abilityNumber(),
pkm->shiny(),
pkm->TSV(),
pkm->PID(),
pkm->generation()));
pkm->metDate(Date::today());
pkm->metLevel(pkm->generation() <= pksm::Generation::THREE ? 5 : 1);
if(pkm->generation() == pksm::Generation::THREE) {
if(pkm->generation() <= pksm::Generation::THREE) {
pkm->level(5); // There was no level 1 before gen 4
std::string name = i18n::species(Config::getLang("lang"), pkm->species());
pkm->nickname(StringUtils::toUpper(name));
Expand Down
Loading