diff --git a/README.md b/README.md index 47d695ce..513b359a 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,8 @@ If you have any issues, or you prefer to set up the project manually, follow the ## Manual Setup +The project can be built on Linux, or Windows using WSL. Follow the instructions below to set up the build environment. + ### Clone the repo Clone the repository to your local machine: @@ -71,9 +73,9 @@ git clone https://github.com/TheOnlyZac/sly1 cd sly1 ``` -### Install Python packages +### Install python packages -Splat is used for binary splitting, and Ninja is used for building the project. You will need Python 3. Install dependencies with pip: +You will need Python 3.8 or higher. ```bash pip install -U -r requirements.txt @@ -81,8 +83,6 @@ pip install -U -r requirements.txt ### Setup build environment -The project can be built on Windows (using WSL) or Linux. Follow the instructions below to set up the build environment. - 1. Setup wine: @@ -124,7 +124,7 @@ To build the project you will need to extract the original ELF file from your ow ### Build the project -The project can be built on Linux (or Windows using WSL). It builds the executable `SCUS_971.98`. +The project builds the executable `SCUS_971.98`. ```bash python configure.py @@ -143,12 +143,11 @@ To only clean without reconfiguring (i.e. delete build files) use: python configure.py --only-clean ``` - ## Running Running the executable requires [PCSX2 2.0](https://pcsx2.net/). You must have your own copy of the original game and the BIOS from your own PS2. They are not included in this repo and we cannot provide them for you. -Once you have those and you have built the executable, you can run it in one of these three ways: +Once you have those and you have built the executable, you can run it in one of three ways: ### 1. Autorun script @@ -170,7 +169,6 @@ Replace `pcsx2-1.7.exe` with the path to your PCSX2 v1.7 executable (for Linux i Copy `SCUS_971.98` from the `out` dir to your PCSX2 Games folder and rename it to `SCUS_971.98.elf`. Right click on the game in PCSX2 and click "Properties...". Go to "Disc Path", click "Browse", and select the ISO of your game backup. Then click "Close" and start the game as normal. - ## Project Structure The project is divided into the following directories: @@ -192,7 +190,6 @@ When you build the executable, the following directories will be created: * `obj` - Compiled object files. * `out` - Compiled executables. - ## FAQ #### What is a decompilation? @@ -215,7 +212,6 @@ Yes. This was the first PS2 decompilation project that targeted the PS2 and util If you want to contribute, check out [CONTRIBUTING.md](/docs/CONTRIBUTING.md) and feel free to [join our discord server](https://discord.gg/gh5xwfj) if you have any questions! - ## Star History diff --git a/config/sly1.yaml b/config/sly1.yaml index ec1313bd..50b2674f 100644 --- a/config/sly1.yaml +++ b/config/sly1.yaml @@ -63,7 +63,7 @@ segments: - [0x1be78, asm, P2/splice/method] #- [0x1bf98, asm, P2/splice/pair] - [0x1bf98, asm, P2/splice/proc] - - [0x1c008, asm, P2/splice/ref] + - [0x1c008, cpp, P2/splice/ref] - [0x1ca28, asm, P2/splice/serialize] - [0x1cd28, asm, P2/splice/sidebag] - [0x1cf70, cpp, P2/splice/spliceutils] diff --git a/config/symbol_addrs.txt b/config/symbol_addrs.txt index 6b09c3d4..61976544 100644 --- a/config/symbol_addrs.txt +++ b/config/symbol_addrs.txt @@ -20,6 +20,52 @@ spliceutils__static_initialization_and_destruction_0 = 0x11C0A8; // type:func _GLOBAL_$I$g_splotheapPair = 0x11C0E8; // type:func _GLOBAL_$D$g_splotheapPair = 0x11C108; // type:func + +//////////////////////////////////////////////////////////////// +// P2/splice/ref.cpp +//////////////////////////////////////////////////////////////// +__4CRef = 0x11B008; // type:func +__4CRefRC4CRef = 0x11B018; // type:func +_$_4CRef = 0x11B060; // type:func +__as__4CRefRC4CRef = 0x11B0A8; // type:func +__eq__4CRefRC4CRef = 0x11B0F8; // type:func +CloneTo__4CRefP4CRefP6CFrame = 0x11B258; // type:func +Decref__4CRef = 0x11B418; // type:func +Incref__4CRef = 0x11B4A8; // type:func +SetTag__4CRef4TAGK = 0x11B538; // type:func +SetS32__4CRefi = 0x11B570; // type:func +SetF32__4CReff = 0x11B5B0; // type:func +SetBool__4CRefi = 0x11B5F0; // type:func +SetSymid__4CRefUi = 0x11B640; // type:func +SetBifk__4CRef4BIFK = 0x11B680; // type:func +SetPair__4CRefP5CPair = 0x11B6C0; // type:func +SetProc__4CRefP5CProc = 0x11B700; // type:func +SetVector__4CRefP6VECTOR = 0x11B740; // type:func +SetMatrix__4CRefP7MATRIX4 = 0x11B788; // type:func +SetClq__4CRefP3CLQ = 0x11B7D0; // type:func +SetLm__4CRefP2LM = 0x11B818; // type:func +SetSmp__4CRefP3SMP = 0x11B860; // type:func +SetBasic__4CRefP5BASIC = 0x11B8A8; // type:func +SetMethod__4CRefP7CMethod = 0x11B8E8; // type:func +RefCoerceS32__4CRef = 0x11B928; // type:func +RefCoerceF32__4CRef = 0x11B9A8; // type:func + + +//////////////////////////////////////////////////////////////// +// P2/vecmat.cpp +//////////////////////////////////////////////////////////////// +IncrefVector__FP6VECTOR = 0x11c580; // type:func +DecrefVector__FP6VECTOR = 0x11c5b0; // type:func +IncrefMatrix__FP7MATRIX4 = 0x11c690; // type:func +DecrefMatrix__FP7MATRIX4 = 0x11c6c0; // type:func +IncrefClq__FP3CLQ = 0x11c7c0; // type:func +DecrefClq__FP3CLQ = 0x11c7f0; // type:func +IncrefLm__FP2LM = 0x11c8d0; // type:func +DecrefLm__FP2LM = 0x11c900; // type:func +IncrefSmp__FP3SMP = 0x11c9e0; // type:func +DecrefSmp__FP3SMP = 0x11ca20; // type:func + + //////////////////////////////////////////////////////////////// // P2/989snd.c //////////////////////////////////////////////////////////////// @@ -660,6 +706,11 @@ g_unkblot4 = 0x26dac8; // size:0x280 g_unkblot5 = 0x26dd48; // size:0x280 g_unkblot6 = 0x26dfc8; // size:0x280 g_unkblot7 = 0x26e248; // size:0x280 +g_unkblot8 = 0x26e4e0; // size:0x280 +g_unkblot9 = 0x26e760; // size:0x280 +g_unkblot10 = 0x26e9f8; // size:0x280 +g_unkblot11 = 0x26eed0; // size:0x280 +g_totals = 0x26f138; // size:0x280 //////////////////////////////////////////////////////////////// @@ -673,6 +724,9 @@ IRotatePowerUp__FP3JOYiiPi = 0x1d3100; // type:func //////////////////////////////////////////////////////////////// // P2/sw.c //////////////////////////////////////////////////////////////// +IncrementSwHandsOff__FP2SW = 0x1dda20; // type:func +DecrementSwHandsOff__FP2SW = 0x1dda50; // type:func + g_psw = 0x275710; // size:0x4 diff --git a/include/alo.h b/include/alo.h index c1a97240..dacb7fc0 100644 --- a/include/alo.h +++ b/include/alo.h @@ -33,6 +33,7 @@ struct ALO : public LO //XF xf; //VECTOR pso + undefined4 padding[0x94]; // ... }; diff --git a/include/sce/memset.h b/include/sce/memset.h index 499d7a0e..c9b15c75 100644 --- a/include/sce/memset.h +++ b/include/sce/memset.h @@ -8,9 +8,6 @@ #include "common.h" -typedef uint s32; -typedef uint size_t; - extern "C" { void* memset(void* ptr, s32 value, size_t num); diff --git a/include/screen.h b/include/screen.h index 4a9b88da..c8843d1c 100644 --- a/include/screen.h +++ b/include/screen.h @@ -136,6 +136,8 @@ struct TOTALS : public BLOT GRFLS grflsReshow; }; +extern TOTALS g_totals; + // MARK: Note struct NOTE : public BLOT diff --git a/include/splice/bif.h b/include/splice/bif.h index 7ecd3b28..70b257cd 100644 --- a/include/splice/bif.h +++ b/include/splice/bif.h @@ -6,6 +6,14 @@ #include "common.h" -// ... +/** + * @enum BIFK + * + * @todo Fill in enum. + */ +enum BIFK +{ + // ... +}; #endif // SPLICE_BIF_H diff --git a/include/splice/method.h b/include/splice/method.h index 716b0f46..cd0f14b2 100644 --- a/include/splice/method.h +++ b/include/splice/method.h @@ -6,6 +6,14 @@ #include "common.h" -// ... +/** + * @class CMethod + * + * @todo Fill in class. + */ +class CMethod +{ + // ... +}; #endif // SPLICE_METHOD_H diff --git a/include/splice/pair.h b/include/splice/pair.h new file mode 100644 index 00000000..b7a3e47c --- /dev/null +++ b/include/splice/pair.h @@ -0,0 +1,19 @@ +/** + * @file splice/pair.h + */ +#ifndef SPLICE_PAIR_H +#define SPLICE_PAIR_H + +#include "common.h" + +/** + * @class CPair + * + * @todo Fill in class. + */ +class CPair +{ + // ... +}; + +#endif // SPLICE_PAIR_H diff --git a/include/splice/proc.h b/include/splice/proc.h index cae2a80d..adecf7ac 100644 --- a/include/splice/proc.h +++ b/include/splice/proc.h @@ -6,6 +6,14 @@ #include "common.h" -// ... +/** + * @class CProc + * + * @todo Fill in class. + */ +class CProc +{ + // ... +}; #endif // SPLICE_PROC_H diff --git a/include/splice/ref.h b/include/splice/ref.h index 5789400b..fc2f9dd0 100644 --- a/include/splice/ref.h +++ b/include/splice/ref.h @@ -5,7 +5,105 @@ #define SPLICE_REF_H #include "common.h" +#include +#include +#include +#include +#include +#include -// ... +enum TAGK +{ + TAGK_Nil = -1, + TAGK_None = 0, + TAGK_Set = 1, + TAGK_Define = 2, + TAGK_DefineMacro = 3, + TAGK_DefineMacroLambda = 4, + TAGK_Assert = 5, + TAGK_If = 6, + TAGK_Or = 7, + TAGK_And = 8, + TAGK_Cond = 9, + TAGK_Else = 10, + TAGK_Case = 11, + TAGK_Let = 12, + TAGK_While = 13, + TAGK_Lambda = 14, + TAGK_Begin = 15, + TAGK_Import = 16, + TAGK_Quote = 17, + TAGK_Dot = 18, + TAGK_Pipe = 19, + TAGK_S32 = 20, + TAGK_F32 = 21, + TAGK_Vector = 22, + TAGK_Matrix = 23, + TAGK_Clq = 24, + TAGK_Lm = 25, + TAGK_Smp = 26, + TAGK_Bool = 27, + TAGK_Symid = 28, + TAGK_Bifk = 29, + TAGK_Pair = 30, + TAGK_Proc = 31, + TAGK_Basic = 32, + TAGK_Method = 33, + TAGK_Void = 34, + TAGK_Err = 35, + TAGK_Max = 36 +}; + +union TAG +{ + int m_n; + float m_g; + int m_bool; + uint m_symid; + BIFK m_bifk; + CPair* m_ppair; + CProc* m_pproc; + VECTOR* m_pvector; + MATRIX4* m_pmatrix; + CLQ* m_pclq; + LM* m_plm; + SMP* m_psmp; + BASIC* m_pbasic; + CMethod* m_pmethod; +}; + +class CRef +{ +public: + CRef(); + CRef(const CRef &ref); + ~CRef(); + CRef &operator=(const CRef &ref); + bool operator==(const CRef &ref) const; + void CloneTo(CRef *prefClone, CFrame *pframeClone) const; + void Decref(); + void Incref(); + void SetTag(TAGK tagk); + void SetS32(s32 n); + void SetF32(f32 g); + void SetBool(int fBool); + void SetSymid(u32 symid); + void SetBifk(BIFK bifk); + void SetPair(CPair *ppair); + void SetProc(CProc *pproc); + void SetVector(VECTOR *pvector); + void SetMatrix(MATRIX4 *pmatrix); + void SetClq(CLQ *pclq); + void SetLm(LM *plm); + void SetSmp(SMP *psmp); + void SetBasic(BASIC *pbasic); + void SetMethod(CMethod *pmethod); + s32 RefCoerceS32() const; + f32 RefCoerceF32() const; + +private: + TAGK m_tagk; + TAG m_tag; +}; #endif // SPLICE_REF_H diff --git a/include/splice/vecmat.h b/include/splice/vecmat.h index 6e967417..31b44018 100644 --- a/include/splice/vecmat.h +++ b/include/splice/vecmat.h @@ -6,6 +6,24 @@ #include "common.h" -// ... +void IncrefVector(VECTOR *pvector); + +void DecrefVector(VECTOR *pvector); + +void IncrefMatrix(MATRIX4 *pmatrix); + +void DecrefMatrix(MATRIX4 *pmatrix); + +void IncrefClq(CLQ *pclq); + +void DecrefClq(CLQ *pclq); + +void IncrefLm(LM *plm); + +void DecrefLm(LM *plm); + +void IncrefSmp(SMP *psmp); + +void DecrefSmp(SMP *psmp); #endif // SPLICE_VECMAT_H diff --git a/include/types.h b/include/types.h index 1d078e92..7ca8ab9d 100644 --- a/include/types.h +++ b/include/types.h @@ -38,4 +38,19 @@ typedef unsigned short undefined2; typedef unsigned int undefined4; typedef unsigned long undefined8; +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; + +typedef signed char s8; +typedef signed short s16; +typedef signed int s32; +typedef signed long long s64; + +typedef float f32; +typedef double f64; + +typedef uint size_t; + #endif // TYPES_H diff --git a/requirements.txt b/requirements.txt index 88a5e6c3..d3c441b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -spimdisasm>=1.18.0 +spimdisasm>=1.27.0 rabbitizer>=1.8.0 -splat64>=0.24.4 +splat64==0.24.6 tqdm n64img pygfxd diff --git a/scripts/setup_build_environment.sh b/scripts/setup_build_environment.sh index ec5bd221..bbcc13d6 100755 --- a/scripts/setup_build_environment.sh +++ b/scripts/setup_build_environment.sh @@ -24,7 +24,7 @@ sudo apt-get install wine32 sudo apt-get install binutils-mips-linux-gnu # Setup compiler -./setup-progd-linux.sh +./setup_progd_linux.sh popd > /dev/null echo "Build environment setup complete." diff --git a/scripts/setup_progd_linux.sh b/scripts/setup_progd_linux.sh index 609ab4c4..cf8b1f86 100755 --- a/scripts/setup_progd_linux.sh +++ b/scripts/setup_progd_linux.sh @@ -3,6 +3,8 @@ # A simple script to set up the ProDG compilers + SCE Runtime Library # to build the Sly 1 decompilation project. +set -e + WINE_ROOT=~/.wine/drive_c TOP=$(cd "$(dirname "$0")"; pwd)/.. @@ -31,7 +33,7 @@ echo Starting ProDG setup script... download "https://github.com/TheOnlyZac/compilers/releases/download/ee-gcc2.95.2-SN-v2.73a/ee-gcc2.95.2-SN-v2.73a.tar.gz" # apply environment variables from the registry file -wine regedit prodg_env.reg +# wine regedit prodg_env.reg # Extract the compiler into the tools dir echo "Extracting compiler to $TOP/tools..." diff --git a/src/P2/bis.c b/src/P2/bis.c index 2668cbb7..37d8f332 100644 --- a/src/P2/bis.c +++ b/src/P2/bis.c @@ -126,7 +126,8 @@ uint CBinaryInputStream::U32Read() return v; } } -INCLUDE_ASM(const s32, "P2/bis", func_00137CB8); // Not really a function, not sure why it's necessary. + +INCLUDE_ASM(const s32, "P2/bis", func_00137CB8); char CBinaryInputStream::S8Read() { diff --git a/src/P2/splice/ref.cpp b/src/P2/splice/ref.cpp new file mode 100644 index 00000000..7514a112 --- /dev/null +++ b/src/P2/splice/ref.cpp @@ -0,0 +1,163 @@ +#include +#include + +CRef::CRef() +{ + m_tagk = TAGK_Nil; +} + +INCLUDE_ASM(const s32, "P2/splice/ref", __4CRefRC4CRef); + +INCLUDE_ASM(const s32, "P2/splice/ref", _$_4CRef); + +INCLUDE_ASM(const s32, "P2/splice/ref", __as__4CRefRC4CRef); + +INCLUDE_ASM(const s32, "P2/splice/ref", __eq__4CRefRC4CRef); + +INCLUDE_ASM(const s32, "P2/splice/ref", CloneTo__4CRefP4CRefP6CFrame); + +INCLUDE_ASM(const s32, "P2/splice/ref", Decref__4CRef); + +INCLUDE_ASM(const s32, "P2/splice/ref", Incref__4CRef); +/* todo: match rodata +void CRef::Incref() +{ + switch(m_tagk) + { + case TAGK_Vector: + IncrefVector(m_tag.m_pvector); + break; + case TAGK_Matrix: + IncrefMatrix(m_tag.m_pmatrix); + break; + case TAGK_Clq: + IncrefClq(m_tag.m_pclq); + break; + case TAGK_Lm: + IncrefLm(m_tag.m_plm); + break; + case TAGK_Smp: + IncrefSmp(m_tag.m_psmp); + break; + } +}*/ + +void CRef::SetTag(TAGK tagk) +{ + Decref(); + m_tagk = tagk; +} + +void CRef::SetS32(s32 n) +{ + Decref(); + m_tag.m_n = n; + m_tagk = TAGK_S32; +} + +void CRef::SetF32(f32 g) +{ + Decref(); + m_tag.m_g = g; + m_tagk = TAGK_F32; +} + +void CRef::SetBool(int fBool) +{ + Decref(); + if (fBool) + { + m_tag.m_bool = 1; + } + else + { + m_tag.m_bool = 0; + } + m_tagk = TAGK_Bool; +} + +void CRef::SetSymid(u32 symid) +{ + Decref(); + m_tag.m_symid = symid; + m_tagk = TAGK_Symid; +} + +void CRef::SetBifk(BIFK bifk) +{ + Decref(); + m_tag.m_bifk = bifk; + m_tagk = TAGK_Bifk; +} + +void CRef::SetPair(CPair* ppair) +{ + Decref(); + m_tag.m_ppair = ppair; + m_tagk = TAGK_Pair; +} + +void CRef::SetProc(CProc* pproc) +{ + Decref(); + m_tag.m_pproc = pproc; + m_tagk = TAGK_Proc; +} + +void CRef::SetVector(VECTOR* pvector) +{ + IncrefVector(pvector); + Decref(); + m_tag.m_pvector = pvector; + m_tagk = TAGK_Vector; +} + +void CRef::SetMatrix(MATRIX4* pmatrix) +{ + IncrefMatrix(pmatrix); + Decref(); + m_tag.m_pmatrix = pmatrix; + m_tagk = TAGK_Matrix; +} + +void CRef::SetClq(CLQ* pclq) +{ + IncrefClq(pclq); + Decref(); + m_tag.m_pclq = pclq; + m_tagk = TAGK_Clq; +} + +void CRef::SetLm(LM* plm) +{ + IncrefLm(plm); + Decref(); + m_tag.m_plm = plm; + m_tagk = TAGK_Lm; +} + +void CRef::SetSmp(SMP* psmp) +{ + IncrefSmp(psmp); + Decref(); + m_tag.m_psmp = psmp; + m_tagk = TAGK_Smp; +} + +void CRef::SetBasic(BASIC* pbasic) +{ + Decref(); + m_tag.m_pbasic = pbasic; + m_tagk = TAGK_Basic; +} + +void CRef::SetMethod(CMethod* pmethod) +{ + Decref(); + m_tag.m_pmethod = pmethod; + m_tagk = TAGK_Method; +} + +INCLUDE_ASM(const s32, "P2/splice/ref", RefCoerceS32__4CRef); + +INCLUDE_ASM(const s32, "P2/splice/ref", RefCoerceF32__4CRef);