Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ target/
src/Tweaks
*.iso
/release

.vscode/
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,27 @@ else ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os")
endif ()

option(RANDOMIZER "")

if (RANDOMIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRANDOMIZER -fno-threadsafe-statics")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DRANDOMIZER")
endif ()


message(${CMAKE_CXX_FLAGS})

set(SOURCE_FILES
src/include/PrimeAPI.h

src/include/rstl/string.h
src/include/rstl/rstl.h
src/include/rstl/vector.h
src/include/rstl/auto_ptr.h
src/include/rstl/list.h
src/include/rstl/pair.h
src/include/rstl/hash_map.h

src/include/dvd.h
src/include/types.h
src/include/os.h
Expand Down Expand Up @@ -65,6 +75,16 @@ set(SOURCE_FILES
src/include/prime/CGameArea.hpp
src/include/prime/CPlayMovie.hpp
src/include/prime/CScriptSpawnPoint.hpp
src/include/prime/CMappableObj.hpp
src/include/prime/CMapWorldInfo.hpp

src/include/kyoto/CObjectReference.hpp
src/include/kyoto/CSimplePool.hpp
src/include/kyoto/CToken.hpp
src/include/kyoto/CVParamTransfer.hpp
src/include/kyoto/IObj.hpp
src/include/kyoto/IObjectStore.hpp
src/include/kyoto/SObjectTag.hpp

src/PracticeMod.hpp
src/include/GetField.hpp
Expand Down Expand Up @@ -122,6 +142,8 @@ set(SOURCE_FILES
src/PracticeMod.cpp
src/prime-practice.cpp
src/hooks.cpp

src/randomizer/randomizer_patches.cpp
)

add_gc_static_binary(prime2-practice src/prime-practice.lst
Expand Down
36 changes: 36 additions & 0 deletions src/include/kyoto/CObjectReference.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include "kyoto/CVParamTransfer.hpp"
#include "kyoto/SObjectTag.hpp"
#include "rstl/auto_ptr.h"

class IObj;
class IObjectStore;
class CObjectReference {
public:
CObjectReference(const rstl::auto_ptr< IObj >& obj);
~CObjectReference();
CObjectReference(IObjectStore& store, const rstl::auto_ptr< IObj >& obj, const SObjectTag& tag,
CVParamTransfer xfer);

bool IsLoaded() const { return x10_object != nullptr; }

void AddReference() { x0_refCount++; }
int RemoveReference();
void Lock();
void Unlock();
IObj* GetObject();
void Unload();
void CancelLoad();
bool IsLoading() const;
const SObjectTag& GetTag() const { return x4_objTag; }

private:
short x0_refCount : 16;
short x2_lockCount : 15;
short x3_loading : 1;
SObjectTag x4_objTag;
IObjectStore* xc_objectStore;
IObj* x10_object;
CVParamTransfer x14_params;
};
43 changes: 43 additions & 0 deletions src/include/kyoto/CSimplePool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "types.h"

#include "rstl/hash_map.h"
#include "rstl/rc_ptr.h"

#include "kyoto/CToken.hpp"
#include "kyoto/IObjectStore.hpp"

class IFactory;

class CSimplePool : public IObjectStore {
public:
CSimplePool(IFactory& factory) : x18_factory(factory) {}
~CSimplePool();

// virtual CToken GetObj(const SObjectTag& tag, CVParamTransfer xfer);
// virtual CToken GetObj(const SObjectTag& tag);
// virtual CToken GetObj(const char* name);
// virtual CToken GetObj(const char* name, CVParamTransfer xfer);
// virtual bool HasObject(const SObjectTag& tag);
// virtual bool ObjectIsLive(const SObjectTag& tag);
// virtual IFactory& GetFactory() { return x18_factory; }
// virtual void Flush();
// virtual void ObjectUnreferenced(const SObjectTag& tag);

void fn_8029c7e8(const SObjectTag& tag);

inline CToken GetObj(const SObjectTag& tag) {
auto fn = VtableLookup<CToken (*)(CSimplePool *, const SObjectTag&)>(this, 1);
return fn(this, tag);
}

private:
u8 x4_;
u8 x5_;
rstl::hash_map< void*, void*, void, void > x8_resources;
IFactory& x18_factory;
rstl::rc_ptr< CVParamTransfer > x1c_paramXfr;
};

extern CSimplePool* gpSimplePool;
45 changes: 45 additions & 0 deletions src/include/kyoto/CToken.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include "kyoto/CObjectReference.hpp"
#include "kyoto/IObj.hpp"

class CToken {
public:
CToken() : x0_objRef(nullptr), x4_lockHeld(false) {}
CToken(CObjectReference* ref) : x0_objRef(ref), x4_lockHeld(false) {
x0_objRef->AddReference();
}
CToken(IObj* obj); // : x0_objRef(new CObjectReference(obj)), x4_lockHeld(false) {}
CToken(const CToken& other);
// ~CToken();

CToken* CToken_dtor(u16 param);

CObjOwnerDerivedFromIObjUntyped* GetObj();
void Lock();
void Unlock();
bool IsLoaded() const { return x0_objRef->IsLoaded(); }
void RemoveRef();
CToken& operator=(const CToken&);
bool HasReference() const { return x0_objRef != nullptr; }
const SObjectTag& GetTag() const { return x0_objRef->GetTag(); }
FourCC GetReferenceType() { return GetTag().type; }

bool HasLock() { return x4_lockHeld; }

const CObjectReference* GetRef() const { return x0_objRef; }
inline CObjectReference* GetRefNonConst() { return x0_objRef; }

// for crimes
inline void InitializeFromOther(const CToken& other) {
x0_objRef = other.x0_objRef;
x0_objRef->AddReference();
if (other.x4_lockHeld) {
Lock();
}
}

private:
CObjectReference* x0_objRef;
bool x4_lockHeld;
};
30 changes: 30 additions & 0 deletions src/include/kyoto/CVParamTransfer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "rstl/rc_ptr.h"
#include "kyoto/IObj.hpp"

class IVParamObj : public IObj {};

template < typename T >
class TObjOwnerParam : public IVParamObj {
public:
~TObjOwnerParam() {}
TObjOwnerParam(T data) : x4_data(data) {}
T GetData() const { return static_cast<T>(x4_data); }

private:
T x4_data;
};

class CVParamTransfer {
public:
CVParamTransfer() {}
template < typename T >
CVParamTransfer(TObjOwnerParam< T >* obj) : x0_obj(obj) {}
static CVParamTransfer Null();

const IVParamObj& operator*() const { return *x0_obj; }

private:
rstl::rc_ptr< IVParamObj > x0_obj;
};
48 changes: 48 additions & 0 deletions src/include/kyoto/IObj.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include "rstl/auto_ptr.h"
#include "kyoto/SObjectTag.hpp"

extern const SObjectTag gkInvalidObjectTag;

class IObj {
public:
virtual ~IObj() {}
};

class CObjOwnerDerivedFromIObjUntyped : public IObj {
public:
~CObjOwnerDerivedFromIObjUntyped() {}
template < typename T >
CObjOwnerDerivedFromIObjUntyped(T* obj) : m_objPtr(obj) {}
template < typename T >
CObjOwnerDerivedFromIObjUntyped(const rstl::auto_ptr< T >& obj) : m_objPtr(obj.release()) {}

void* GetContents() { return m_objPtr; }

protected:
void* m_objPtr;
};

template < typename T >
class TObjOwnerDerivedFromIObj : public CObjOwnerDerivedFromIObjUntyped {
public:
~TObjOwnerDerivedFromIObj() {
if (Owned()) {
delete Owned();
}
}
T* Owned() { return static_cast< T* >(m_objPtr); }

static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetNewDerivedObject(T* obj) {
return new TObjOwnerDerivedFromIObj< T >(obj);
}
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > >
GetNewDerivedObject(const rstl::auto_ptr< T >& obj) {
return new TObjOwnerDerivedFromIObj< T >(obj);
}

private:
TObjOwnerDerivedFromIObj(T* obj) : CObjOwnerDerivedFromIObjUntyped(obj) {}
TObjOwnerDerivedFromIObj(const rstl::auto_ptr< T >& obj) : CObjOwnerDerivedFromIObjUntyped(obj) {}
};
18 changes: 18 additions & 0 deletions src/include/kyoto/IObjectStore.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "kyoto/CToken.hpp"

class IFactory;
class IObjectStore {
public:
IObjectStore() {}
// virtual CToken GetObj(const SObjectTag& tag, CVParamTransfer xfer) = 0;
// virtual CToken GetObj(const SObjectTag& tag) = 0;
// virtual CToken GetObj(const char* name) = 0;
// virtual CToken GetObj(const char* name, CVParamTransfer xfer) = 0;
// virtual bool HasObject(const SObjectTag& tag) = 0;
// virtual bool ObjectIsLive(const SObjectTag& tag) = 0;
// virtual IFactory& GetFactory() = 0;
// virtual void Flush() = 0;
// virtual void ObjectUnreferenced(const SObjectTag& tag) = 0;
};
18 changes: 18 additions & 0 deletions src/include/kyoto/SObjectTag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "types.h"

#define kInvalidAssetId 0xFFFFFFFFu

typedef uint FourCC;

struct SObjectTag {
FourCC type;
CAssetId id;

SObjectTag() {}
SObjectTag(FourCC type, CAssetId id) : type(type), id(id) {}
SObjectTag(const SObjectTag& other) : type(other.type), id(other.id) {}

static const char* Type2Text(FourCC type);
};
9 changes: 8 additions & 1 deletion src/include/prime/CGraphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "GetField.hpp"
#include "MathyTypes.hpp"

typedef struct {} CTevPass;

enum ERglCullMode { ERglCullMode_None = 0, ERglCullMode_Front = 1, ERglCullMode_Back = 2, ERglCullMode_All = 3 };

enum ERglPrimitive {
Expand Down Expand Up @@ -67,6 +69,7 @@ class CGraphics {
static void SetAlphaCompare(ERglAlphaFunc func0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc func1, u8 ref1);
static void DisableAllLights();
static void SetTevStates(int i);
static void SetTevOp(_GXTevOp, CTevPass*);
};

class CGX {
Expand All @@ -82,14 +85,18 @@ class CGX {
static void SetBlendMode(_GXBlendMode, _GXBlendFactor, _GXBlendFactor, _GXLogicOp);
static void SetVtxDescv(_GXVtxDescList *list);
static void SetArray(u32 attr, const void *base, unsigned char stride);
static void Begin(u32 prim, u32 fmt, ushort verts);
static void Begin(u32 prim, u32 fmt, u16 verts);
static void End();
static void SetNumChans(int);
static void SetNumTexGens(int);
static void SetTexCoordGen(u16 texCoord, u32 gen_typ, u32 gen_src, u32 mtxsrc, bool normalize, u32 postMix);
};

class CTexture {
private:
public:
static void InvalidateTexmap(int texMapId);
void LoadMipLevel(int param1, int param2);
};

extern CTevPass g_tevPass_80416c2c;
8 changes: 8 additions & 0 deletions src/include/prime/CMapWorldInfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "GetField.hpp"

class CMapWorldInfo {
public:
bool IsObjectUnmapped(u32* editorId) const;
};
36 changes: 36 additions & 0 deletions src/include/prime/CMappableObj.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include "GetField.hpp"
#include "CMapWorldInfo.hpp"

typedef enum EMappableObjectType {
// door types
EMappableObjectType_NormalDoor = 0x0,
EMappableObjectType_MissileDoor,
EMappableObjectType_DarkDoor,
EMappableObjectType_AnnihilatorDoor,
EMappableObjectType_LightDoor,
EMappableObjectType_SuperMissileDoor,
EMappableObjectType_SeekerMissileDoor,
EMappableObjectType_PowerBombDoor,

// regular icon types
EMappableObjectType_Elevator = 0x10,
EMappableObjectType_SaveStation,
EMappableObjectType_Unused_0x12,
EMappableObjectType_Unused_0x13,
EMappableObjectType_AmmoStation,
EMappableObjectType_Portal,
EMappableObjectType_LightTeleporter,
EMappableObjectType_TranslatorGate,
EMappableObjectType_UpArrow,
EMappableObjectType_DownArrow,
} EMappableObjectType;

class CMappableObject {
public:
void Draw(u32 curArea, const CMapWorldInfo& mwInfo, float alpha, bool needsVtxLoad);

inline EMappableObjectType *getMappableObjectType() { return GetField<EMappableObjectType>(this, 0x0); }
inline u32 *getEditorId() { return GetField<uint>(this, 0x8); }
};
Loading