Skip to content

Commit 6a9ce47

Browse files
authored
Merge pull request #307 from chaoticgd/trainer
Add the beginnings of a trainer
2 parents 324f002 + 194b648 commit 6a9ce47

32 files changed

+2199
-52
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ set(RELEASE_FILES
5959
$<TARGET_FILE:wrencheditor>
6060
$<TARGET_FILE:wrenchlauncher>
6161
$<TARGET_FILE:wrenchsaveeditor>
62+
$<TARGET_FILE:wrenchtrainer>
6263
$<TARGET_FILE:wrenchvis>
6364
"${CMAKE_BINARY_DIR}/editor.wad"
6465
"${CMAKE_BINARY_DIR}/gui.wad"
6566
"${CMAKE_BINARY_DIR}/launcher.wad"
6667
"${CMAKE_BINARY_DIR}/memcard.wad"
68+
"${CMAKE_BINARY_DIR}/trainer.wad"
6769
)
6870
set(RELEASE_DOCS_DIRECTORY "${CMAKE_SOURCE_DIR}/docs")
6971
set(RELEASE_LICENSES_DIRECTORY "${CMAKE_SOURCE_DIR}/data/licenses")

data/licenses/pine.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Gauvain "GovanifY" Roussel-Tarbouriech
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

data/trainer/trainer_types_dl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma wrench parser on
2+
3+
struct MobyInstance
4+
{
5+
};

data/trainer/trainer_types_gc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma wrench parser on
2+
3+
struct MobyInstance
4+
{
5+
};

data/trainer/trainer_types_rac.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma wrench parser on
2+
3+
struct MobyInstance
4+
{
5+
};

data/trainer/trainer_types_uya.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma wrench parser on
2+
3+
struct MobyInstance
4+
{
5+
};

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_subdirectory(instancemgr)
1717
add_subdirectory(gui)
1818
add_subdirectory(launcher)
1919
add_subdirectory(editor)
20+
add_subdirectory(trainer)
2021
add_subdirectory(wrenchbuild)
2122
add_subdirectory(saveeditor)
2223
add_subdirectory(wrenchvis)
@@ -53,5 +54,6 @@ if(WIN32)
5354
target_sources(wrencheditor PUBLIC utf8.manifest)
5455
target_sources(wrenchlauncher PUBLIC utf8.manifest)
5556
target_sources(wrenchsaveeditor PUBLIC utf8.manifest)
57+
target_sources(wrenchtrainer PUBLIC utf8.manifest)
5658
target_sources(wrenchvis PUBLIC utf8.manifest)
5759
endif()

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ add_library(wrenchcore STATIC
2424
elf.cpp
2525
stdout_thread.cpp
2626
gltf.cpp
27+
release.cpp
2728
${CMAKE_SOURCE_DIR}/thirdparty/md5.cpp
2829
)
2930
target_link_libraries(wrenchcore wrenchwtf wrenchplatform)

src/core/build_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ enum class Game : u8
2626
UNKNOWN = 0, RAC = 1, GC = 2, UYA = 3, DL = 4
2727
};
2828

29+
enum
30+
{
31+
MAX_GAME = 5
32+
};
33+
2934
enum class Region : u8
3035
{
3136
UNKNOWN = 0, US = 1, EU = 2, JAPAN = 3
Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,53 +51,40 @@ static const Release RELEASES[] = {
5151
{"scus_974.87", Game::DL, Region::US, "Ratchet: Deadlocked"} // us public beta
5252
};
5353

54-
static std::pair<Game, const char*> GAME_SEARCH_PATTERNS[] = {
55-
{Game::DL, "Deadlocked"},
56-
{Game::UYA, "Up Your Arsenal"},
57-
{Game::GC, "Going Commando"},
58-
{Game::RAC, "Ratchet & Clank"}
59-
};
60-
61-
Release identify_release(const IsoDirectory& root, InputStream& iso)
54+
Release identify_release(const std::string& elf_name)
6255
{
6356
Release result;
64-
// First check all of the known releases.
65-
for (const IsoFileRecord& file : root.files) {
66-
for (const Release& release : RELEASES) {
67-
if (release.elf_name == file.name) {
68-
result = release;
69-
break;
70-
}
57+
for (const Release& release : RELEASES) {
58+
if (release.elf_name == elf_name) {
59+
result = release;
60+
break;
7161
}
7262
}
73-
if (result.game == Game::UNKNOWN) {
74-
// Unknown build, try to identify it in a dirtier slower way.
75-
for (const IsoFileRecord& record : root.files) {
76-
if (record.size > 4) {
77-
// Look for the boot ELF.
78-
u8 magic[4] = {};
79-
iso.seek(record.lba.bytes());
80-
iso.read_n(magic, 4);
81-
if (memcmp(magic, "\x7f\x45\x4c\x46", 4) == 0) {
82-
iso.seek(record.lba.bytes());
83-
std::vector<u8> elf = iso.read_multiple<u8>(record.size);
84-
// Look for the names of the respective games in the boot ELF.
85-
for (auto [game, pattern] : GAME_SEARCH_PATTERNS) {
86-
for (s32 i = 0; i < (s32) elf.size() - strlen(pattern); i++) {
87-
if (memcmp(&elf[i], pattern, strlen(pattern)) == 0) {
88-
printf("Unknown build identified as %s.\n", game_to_string(game).c_str());
89-
result.elf_name = record.name;
90-
result.game = game;
91-
result.name = "unknown";
92-
break;
93-
}
94-
}
95-
if (result.game != Game::UNKNOWN) {
96-
break;
97-
}
98-
}
99-
}
100-
}
63+
return result;
64+
}
65+
66+
static std::string normalise_game_id(const std::string& game_id)
67+
{
68+
std::string result;
69+
for (char c : game_id) {
70+
if (c >= 'A' && c <= 'Z') {
71+
result.push_back(c + ('a' - 'A'));
72+
} else if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) {
73+
result.push_back(c);
74+
}
75+
}
76+
return result;
77+
}
78+
79+
Release identify_release_fuzzy(const std::string& game_id)
80+
{
81+
std::string normal_game_id = normalise_game_id(game_id);
82+
83+
Release result;
84+
for (const Release& release : RELEASES) {
85+
if (normalise_game_id(release.elf_name) == normal_game_id) {
86+
result = release;
87+
break;
10188
}
10289
}
10390
return result;

0 commit comments

Comments
 (0)