Publish precompiled tp6.c blob (lots of dirty hacks)

This commit is contained in:
mkrsym1 2023-07-05 23:59:27 +03:00
parent 94efee7496
commit df1f611199
6 changed files with 102 additions and 42 deletions

View File

@ -1,12 +1,6 @@
#!/usr/bin/env bash
set -e
if ! [ "x$1" = "xdo" ]; then
echo "A part of the source code is witheld (game_payload/src/tp6.c) to make abuse more difficult. Please download a binary release"
exit
fi
shift
strip="x86_64-w64-mingw32-strip"
rm -f jadeite.zip

BIN
game_payload/blob/tp6c.obj Normal file

Binary file not shown.

View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
cp "$1" "$2"
cp "$1" "$3"

View File

@ -1,3 +1,7 @@
fs = import('fs')
include_dir = include_directories('include')
# Input files
sources = [
'src/main.c',
@ -8,10 +12,7 @@ sources = [
'src/hi3.c',
'src/hsr.c',
'src/utils.c',
'src/msg.c',
# File withheld to make abuse more difficult
'src/tp6.c'
'src/msg.c'
]
resources = [
'res/hi3/glb/allocations.dat',
@ -24,17 +25,53 @@ resources = [
]
# Generate resource files for ./res
res_files = custom_target(
'resources.[ho]',
output: [ 'resources.o', 'resources.h' ],
res_header = custom_target(
'resources.h',
output: 'resources.h',
input: resources,
command: [ gen_res, meson.current_source_dir(), '@OUTPUT0@', '@OUTPUT1@', '@INPUT@' ]
command: [ gen_res, '--header', meson.current_source_dir(), '@OUTPUT0@', '@INPUT@' ]
)
res_object = custom_target(
'resources.o',
output: 'resources.o',
input: resources,
command: [ gen_res, '--object', meson.current_source_dir(), '@OUTPUT0@', '@INPUT@' ]
)
if fs.exists('src/tp6.c')
# Compile the real file first (dirty hack)
tp6c_fake_exe = executable(
'tp6c.obj',
'src/tp6.c',
res_header,
link_args: [ '-r' ], # Output an object file
include_directories: include_dir
)
# another dirty hack
copy_tp6c = find_program('copy_tp6c.sh')
tp6c = custom_target(
'copy_tp6c',
output: 'tp6c.obj',
input: tp6c_fake_exe.extract_all_objects(recursive: false),
command: [
copy_tp6c,
'@INPUT0@',
'@OUTPUT0@', meson.current_source_dir() / 'blob/tp6c.obj'
]
)
else
message('Using precompiled tp6c blob. Refer to the readme for more details')
tp6c = 'blob/tp6c.obj'
endif
shared_library(
'game_payload',
sources,
res_files,
include_directories: 'include',
tp6c,
res_header,
res_object,
include_directories: include_dir,
name_prefix: ''
)

View File

@ -1,20 +1,41 @@
#!/usr/bin/env bash
# I hate this.
linker="x86_64-w64-mingw32-ld"
# Output config (terrible)
if [ "x$1" = "x--header" ]; then
gen_header=1
shift
fi
if [ "x$1" = "x--object" ]; then
gen_object=1
shift
fi
# Read project directory
proj_dir=`realpath "$1"`
shift
# Read output file destinations
resources_o=`realpath "$1"`
shift
resources_h=`realpath "$1"`
shift
if [ "x${gen_object}" = "x1" ]; then
resources_o=`realpath "$1"`
shift
fi
if [ "x${gen_header}" = "x1" ]; then
resources_h=`realpath "$1"`
shift
fi
# Make sure that the header does not exist
rm -f "${resources_h}"
rm -f "${resources_o}"
# Make sure that output files do not exist
if [ "x${gen_header}" = "x1" ]; then
rm -f "${resources_h}"
fi
if [ "x${gen_object}" = "x1" ]; then
rm -f "${resources_o}"
fi
# Recomupte relative paths to parameters
idx=0
@ -26,24 +47,28 @@ do
idx="$(("${idx}" + 1))"
done
# Create the object file
pushd "${proj_dir}" >> /dev/null
$linker -r -b binary -o "${resources_o}" "${resource_files[@]}"
popd >> /dev/null
if [ "x${gen_object}" = "x1" ]; then
# Create the object file
pushd "${proj_dir}" >> /dev/null
$linker -r -b binary -o "${resources_o}" "${resource_files[@]}"
popd >> /dev/null
fi
# Include stddef.h in the resources header (for size_t)
echo "#include <stddef.h>" >> "${resources_h}"
if [ "x${gen_header}" = "x1" ]; then
# Include stddef.h in the resources header (for size_t)
echo "#include <stddef.h>" >> "${resources_h}"
for resource in "${resource_files[@]}"
do
# Use relative path to the resource as the variable name
var_name="_binary_${resource}"
for resource in "${resource_files[@]}"
do
# Use relative path to the resource as the variable name
var_name="_binary_${resource}"
# Replace all non-alphanumeric characters with underscores
var_name=`printf "${var_name}" | sed "s/[^a-zA-Z0-9]/_/g"`
# Replace all non-alphanumeric characters with underscores
var_name=`printf "${var_name}" | sed "s/[^a-zA-Z0-9]/_/g"`
# Define externs in the header
echo "extern void *${var_name}_start;" >> "${resources_h}"
echo "extern void *${var_name}_size;" >> "${resources_h}"
echo "" >> "${resources_h}"
done
# Define externs in the header
echo "extern void *${var_name}_start;" >> "${resources_h}"
echo "extern void *${var_name}_size;" >> "${resources_h}"
echo "" >> "${resources_h}"
done
fi

View File

@ -17,14 +17,14 @@ exe_res_files = custom_target(
'launcher_p.[oh]',
output: [ 'launcher_p.o', 'launcher_p.h' ],
input: [ launcher_payload_bin ],
command: [ gen_res, './injector', '@OUTPUT0@', '@OUTPUT1@', '@INPUT@' ]
command: [ gen_res, '--header', '--object', './injector', '@OUTPUT0@', '@OUTPUT1@', '@INPUT@' ]
)
dll_res_files = custom_target(
'game_p.[oh]',
output: [ 'game_p.o', 'game_p.h' ],
input: [ game_payload_bin ],
command: [ gen_res, './injector', '@OUTPUT0@', '@OUTPUT1@', '@INPUT@' ]
command: [ gen_res, '--header', '--object', './injector', '@OUTPUT0@', '@OUTPUT1@', '@INPUT@' ]
)
# Main injector exe