Added dkr_encryptor & /cheats directory within /assets/

This commit is contained in:
David Benepe
2020-06-15 09:30:56 -05:00
parent 62e4697f20
commit 6f6791a99f
10 changed files with 167 additions and 6 deletions
+11 -2
View File
@@ -55,10 +55,11 @@ FixPath = $(subst /,,$1)
N64CRC = $(TOOLS_DIR)/n64crc
TEXBUILDER = $(TOOLS_DIR)/dkr_texbuilder
COMPRESS = $(TOOLS_DIR)/dkr_decompressor -c
ENCRYPT = $(TOOLS_DIR)/dkr_encryptor
ASM_DIRS := asm asm/boot asm/assets
SRC_DIRS := src
ASSETS_DIRS := animations bin levels objects text textures ucode
ASSETS_DIRS := animations bin cheats levels objects text textures ucode
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
@@ -122,7 +123,12 @@ UCODE_OUT_DIR = $(BUILD_DIR)/ucode
UCODE = $(wildcard $(UCODE_IN_DIR)/*.bin)
UCODE_BUILT := $(patsubst $(UCODE_IN_DIR)/%.bin,$(UCODE_OUT_DIR)/%.bin,$(UCODE))
ALL_ASSETS_BUILT := $(ANIMATIONS_BUILT) $(BINS_BUILT) $(LEVELS_BUILT) $(OBJECTS_BUILT) $(TEXTURES_BUILT) $(TEXTURES_BIN_BUILT) $(TEXT_BUILT) $(UCODE_BUILT)
CHEATS_IN_DIR = $(ASSETS_DIR)/cheats
CHEATS_OUT_DIR = $(BUILD_DIR)/cheats
CHEATS = $(wildcard $(CHEATS_IN_DIR)/*.ebin)
CHEATS_BUILT := $(patsubst $(CHEATS_IN_DIR)/%.ebin,$(CHEATS_OUT_DIR)/%.ebin,$(CHEATS))
ALL_ASSETS_BUILT := $(ANIMATIONS_BUILT) $(BINS_BUILT) $(CHEATS_BUILT) $(LEVELS_BUILT) $(OBJECTS_BUILT) $(TEXTURES_BUILT) $(TEXTURES_BIN_BUILT) $(TEXT_BUILT) $(UCODE_BUILT)
######################## Targets #############################
@@ -154,6 +160,9 @@ $(ANIMATIONS_OUT_DIR)/%.cbin: $(ANIMATIONS_IN_DIR)/%.cbin
$(BINS_OUT_DIR)/%.bin: $(BINS_IN_DIR)/%.bin
$(ASSETS_OBJCOPY) $^ $@
$(CHEATS_OUT_DIR)/%.ebin: $(CHEATS_IN_DIR)/%.ebin
$(ENCRYPT) $^ $@
$(LEVELS_OUT_DIR)/%.bin: $(LEVELS_IN_DIR)/%.bin
$(ASSETS_OBJCOPY) $^ $@
+2
View File
@@ -4631,6 +4631,8 @@
.incbin "./build/text/menu_text_french.37ed10.bin"
.incbin "./build/text/menu_text_german.37fb30.bin"
.incbin "./build/bin/unknown.380bb0.bin"
.incbin "./build/cheats/magic_codes.3833a0.ebin"
.incbin "./build/bin/unknown.383760.bin"
.balign 16
.incbin "./build/levels/level_object_maps_lut.383aa0.bin"
.incbin "./build/levels/level_object_map.383cd0.cbin"
+8 -2
View File
@@ -96,8 +96,14 @@ include: "extract-textures/textures_2-us-1.0.extract-config"
# ------------------------------------------------------- #
# [0x380BB0, 0x383AA0] = Unknown
[0x2EF0]: "Binary", "unknown", "bin"
# [0x380BB0, 0x3833A0] = Unknown
[0x27F0]: "Binary", "unknown", "bin"
# [0x3833A0, 0x383760] = Unknown
[0x3C0]: "Encrypted", "magic_codes", "cheats"
# [0x383760, 0x383AA0] = Unknown
[0x340]: "Binary", "unknown", "bin"
# ------------------------------------------------------- #
+1
View File
@@ -1,4 +1,5 @@
/n64crc
/dkr_decompressor
/dkr_encryptor
/dkr_extractor
/dkr_texbuilder
+3 -1
View File
@@ -3,7 +3,7 @@ CXX := g++
CFLAGS := -I . -Wall -Wextra -Wno-unused-parameter -pedantic -std=c99 -O2 -s
LDFLAGS := -lm
PROGRAMS := n64crc
CXX_PROGRAMS := dkr_decompressor dkr_extractor dkr_texbuilder
CXX_PROGRAMS := dkr_decompressor dkr_encryptor dkr_extractor dkr_texbuilder
default: all
@@ -12,6 +12,8 @@ n64crc_SOURCES := n64crc.c
dkr_decompressor_SOURCES := dkr_decompressor.cpp $(wildcard dkr_decompressor_src/*.cpp dkr_decompressor_src/*.c)
dkr_decompressor_CXXFLAGS := -lstdc++fs -lcrypto -lssl
dkr_encryptor_SOURCES := dkr_encryptor.cpp
dkr_extractor_SOURCES := dkr_extractor.cpp $(wildcard dkr_decompressor_src/*.cpp dkr_decompressor_src/*.c dkr_extractor_classes/*.cpp n64graphics/*.c)
dkr_extractor_CXXFLAGS := -lstdc++fs -lcrypto -lssl
+84
View File
@@ -0,0 +1,84 @@
#include <iostream>
#include <fstream>
#include <vector>
void show_help() {
std::cout << "Usage: ./dkr_encryptor <input_file> <output_file>" << std::endl;
}
void encrypt_data(std::vector<uint8_t>& data) {
int numWords = data.size() / 4;
int a, b, c, d, sp0, sp1, sp2, sp3;
for(int i = 0; i < numWords; i++) {
a = (data[(i * 4) + 3] & 0xC0) >> 6;
b = (data[(i * 4) + 0] & 0xC0);
c = (data[(i * 4) + 1] & 0xC0) >> 2;
d = (data[(i * 4) + 2] & 0xC0) >> 4;
sp0 = a | b | c | d;
a = (data[(i * 4) + 3] & 0x30) >> 4;
b = (data[(i * 4) + 0] & 0x30) << 2;
c = (data[(i * 4) + 1] & 0x30);
d = (data[(i * 4) + 2] & 0x30) >> 2;
sp1 = a | b | c | d;
a = (data[(i * 4) + 3] & 0x0C) >> 2;
b = (data[(i * 4) + 0] & 0x0C) << 4;
c = (data[(i * 4) + 1] & 0x0C) << 2;
d = (data[(i * 4) + 2] & 0x0C);
sp2 = a | b | c | d;
a = (data[(i * 4) + 3] & 0x03);
b = (data[(i * 4) + 0] ) << 6;
c = (data[(i * 4) + 1] & 0x03) << 4;
d = (data[(i * 4) + 2] & 0x03) << 2;
sp3 = a | b | c | d;
a = (sp0 & 0xAA) >> 1;
b = (sp0 & 0x55) << 1;
data[(i * 4) + 0] = a | b;
a = (sp1 & 0xAA) >> 1;
b = (sp1 & 0x55) << 1;
data[(i * 4) + 1] = a | b;
a = (sp2 & 0xAA) >> 1;
b = (sp2 & 0x55) << 1;
data[(i * 4) + 2] = a | b;
a = (sp3 & 0xAA) >> 1;
b = (sp3 & 0x55) << 1;
data[(i * 4) + 3] = a | b;
}
}
void read_binary_file(std::vector<uint8_t>& data, std::string filename) {
std::ifstream is;
is.open(filename.c_str(), std::ios::binary);
is.seekg(0, std::ios::end);
size_t filesize = is.tellg();
is.seekg(0, std::ios::beg);
data.resize(filesize);
is.read((char *)data.data(), filesize);
is.close();
}
void write_binary_file(std::vector<uint8_t>& data, std::string& filename) {
std::ofstream wf(filename.c_str(), std::ios::out | std::ios::binary);
for(int i = 0; i < data.size(); i++)
wf.write((char *)&data[i], 1);
wf.close();
}
int main(int argc, char* argv[]) {
if(argc != 3) {
show_help();
return 1;
}
std::string inputFile = argv[1];
std::string outputFile = argv[2];
std::vector<uint8_t> data;
read_binary_file(data, inputFile);
encrypt_data(data);
write_binary_file(data, outputFile);
return 0;
}
+52
View File
@@ -114,6 +114,51 @@ void extract_compressed(std::vector<uint8_t>& data, int startOffset, int endOffs
extract_binary(data, startOffset, endOffset, name, ".cbin", subfolder, outFolder);
}
// Only used for the magic codes.
void decrypt_data(std::vector<uint8_t>& data) {
int numWords = data.size() / 4;
int a, b, c, d, sp0, sp1, sp2, sp3;
for(int i = 0; i < numWords; i++) {
a = (data[(i * 4) + 3] & 0xC0) >> 6;
b = (data[(i * 4) + 0] & 0xC0);
c = (data[(i * 4) + 1] & 0xC0) >> 2;
d = (data[(i * 4) + 2] & 0xC0) >> 4;
sp0 = a | b | c | d;
a = (data[(i * 4) + 3] & 0x30) >> 4;
b = (data[(i * 4) + 0] & 0x30) << 2;
c = (data[(i * 4) + 1] & 0x30);
d = (data[(i * 4) + 2] & 0x30) >> 2;
sp1 = a | b | c | d;
a = (data[(i * 4) + 3] & 0x0C) >> 2;
b = (data[(i * 4) + 0] & 0x0C) << 4;
c = (data[(i * 4) + 1] & 0x0C) << 2;
d = (data[(i * 4) + 2] & 0x0C);
sp2 = a | b | c | d;
a = (data[(i * 4) + 3] & 0x03);
b = (data[(i * 4) + 0] ) << 6;
c = (data[(i * 4) + 1] & 0x03) << 4;
d = (data[(i * 4) + 2] & 0x03) << 2;
sp3 = a | b | c | d;
a = (sp0 & 0xAA) >> 1;
b = (sp0 & 0x55) << 1;
data[(i * 4) + 0] = a | b;
a = (sp1 & 0xAA) >> 1;
b = (sp1 & 0x55) << 1;
data[(i * 4) + 1] = a | b;
a = (sp2 & 0xAA) >> 1;
b = (sp2 & 0x55) << 1;
data[(i * 4) + 2] = a | b;
a = (sp3 & 0xAA) >> 1;
b = (sp3 & 0x55) << 1;
data[(i * 4) + 3] = a | b;
}
}
void extract_encrypted(std::vector<uint8_t>& data, int startOffset, int endOffset, std::string& name, std::string& subfolder, std::string& outFolder) {
decrypt_data(data);
extract_binary(data, startOffset, endOffset, name, ".ebin", subfolder, outFolder);
}
int get_texture_size(int width, int height, int textureFormat) {
switch(textureFormat) {
case TEX_FORMAT_RGBA32:
@@ -379,6 +424,13 @@ void extract_range(std::string subfolder, ConfigRange& range, ROM& rom) {
numberOfFilesExtracted++;
break;
}
case ConfigRangeType::ENCRYPTED:
{
std::vector<uint8_t> data = rom.get_bytes_from_range(startOffset, range.get_size());
extract_encrypted(data, startOffset, endOffset, name, subfolder, outFolder);
numberOfFilesExtracted++;
break;
}
case ConfigRangeType::TEXTURE:
{
std::string flip_verticallyString = range.get_property(3);
@@ -137,6 +137,7 @@ ConfigRangeType Config::get_range_type(std::string typeString) {
if(type == "binary") return ConfigRangeType::BINARY;
if(type == "noextract") return ConfigRangeType::NOEXTRACT;
if(type == "compressed") return ConfigRangeType::COMPRESSED;
if(type == "encrypted") return ConfigRangeType::ENCRYPTED;
if(type == "texture") return ConfigRangeType::TEXTURE;
std::cout << "Unknown extraction type: " << type << std::endl;
@@ -16,6 +16,7 @@ enum ConfigRangeType {
BINARY,
NOEXTRACT,
COMPRESSED,
ENCRYPTED,
TEXTURE
};
+4 -1
View File
@@ -151,7 +151,10 @@ class LD:
if fileExtension == '.png' and int(fileProperties[1]) != 0:
continue
ramAddress = fileProperties[0]
outFileExtension = '.cbin' if fileExtension == '.cbin' else '.bin'
if fileExtension == '.cbin' or fileExtension == '.ebin':
outFileExtension = fileExtension
else:
outFileExtension = '.bin'
outFilename = 'build/' + matchedGroups[0] + '.' + matchedGroups[1] + outFileExtension
if int(ramAddress, 16) >= ASSETS_START:
assetFiles.append((outFilename, ramAddress, fileExtension))