From 8a7821264ffe334d8512fa7a203cc05dccff0802 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 7 Oct 2023 22:57:42 -0700 Subject: [PATCH] Nearly match CTweaks.cpp --- asm/Dolphin/card/CARDBlock.s | 6 +- asm/Dolphin/card/CARDCreate.s | 3 +- asm/Dolphin/card/CARDDir.s | 7 +- asm/Dolphin/card/CARDFormat.s | 3 +- asm/Dolphin/card/CARDRead.s | 3 +- asm/Kyoto/Streams/CInputStream.s | 45 ++--- configure.py | 2 +- include/Kyoto/TOneStatic.hpp | 30 ++-- include/MetroidPrime/CMain.hpp | 1 - include/MetroidPrime/CMappableObject.hpp | 2 +- include/MetroidPrime/Tweaks/CTweakGunRes.hpp | 8 +- .../MetroidPrime/Tweaks/CTweakPlayerGun.hpp | 3 +- .../MetroidPrime/Tweaks/CTweakPlayerRes.hpp | 8 +- .../MetroidPrime/Tweaks/CTweakTargeting.hpp | 14 ++ include/MetroidPrime/Tweaks/CTweaks.hpp | 4 +- src/MetroidPrime/Tweaks/CTweaks.cpp | 165 ++++++++++++++++++ 16 files changed, 254 insertions(+), 50 deletions(-) create mode 100644 include/MetroidPrime/Tweaks/CTweakTargeting.hpp create mode 100644 src/MetroidPrime/Tweaks/CTweaks.cpp diff --git a/asm/Dolphin/card/CARDBlock.s b/asm/Dolphin/card/CARDBlock.s index 08f7914d..8ffd3af9 100644 --- a/asm/Dolphin/card/CARDBlock.s +++ b/asm/Dolphin/card/CARDBlock.s @@ -7,7 +7,7 @@ __CARDGetFatBlock: /* 803BA56C 003B74CC 80 63 00 88 */ lwz r3, 0x88(r3) /* 803BA570 003B74D0 4E 80 00 20 */ blr -WriteCallback: +.fn WriteCallback, local /* 803BA574 003B74D4 7C 08 02 A6 */ mflr r0 /* 803BA578 003B74D8 90 01 00 04 */ stw r0, 4(r1) /* 803BA57C 003B74DC 94 21 FF E0 */ stwu r1, -0x20(r1) @@ -65,8 +65,9 @@ lbl_803BA62C: /* 803BA63C 003B759C 38 21 00 20 */ addi r1, r1, 0x20 /* 803BA640 003B75A0 7C 08 03 A6 */ mtlr r0 /* 803BA644 003B75A4 4E 80 00 20 */ blr +.endfn WriteCallback -EraseCallback: +.fn EraseCallback, local /* 803BA648 003B75A8 7C 08 02 A6 */ mflr r0 /* 803BA64C 003B75AC 90 01 00 04 */ stw r0, 4(r1) /* 803BA650 003B75B0 94 21 FF D8 */ stwu r1, -0x28(r1) @@ -120,6 +121,7 @@ lbl_803BA6F4: /* 803BA704 003B7664 38 21 00 28 */ addi r1, r1, 0x28 /* 803BA708 003B7668 7C 08 03 A6 */ mtlr r0 /* 803BA70C 003B766C 4E 80 00 20 */ blr +.endfn EraseCallback .global __CARDAllocBlock __CARDAllocBlock: diff --git a/asm/Dolphin/card/CARDCreate.s b/asm/Dolphin/card/CARDCreate.s index 8ef22734..d048f393 100644 --- a/asm/Dolphin/card/CARDCreate.s +++ b/asm/Dolphin/card/CARDCreate.s @@ -2,7 +2,7 @@ .section .text, "ax" -CreateCallbackFat: +.fn CreateCallbackFat, local /* 803BD1C0 003BA120 7C 08 02 A6 */ mflr r0 /* 803BD1C4 003BA124 90 01 00 04 */ stw r0, 4(r1) /* 803BD1C8 003BA128 94 21 FF D8 */ stwu r1, -0x28(r1) @@ -81,6 +81,7 @@ lbl_803BD2DC: /* 803BD2E4 003BA244 38 21 00 28 */ addi r1, r1, 0x28 /* 803BD2E8 003BA248 7C 08 03 A6 */ mtlr r0 /* 803BD2EC 003BA24C 4E 80 00 20 */ blr +.endfn CreateCallbackFat .global CARDCreateAsync CARDCreateAsync: diff --git a/asm/Dolphin/card/CARDDir.s b/asm/Dolphin/card/CARDDir.s index e5a5a0cd..0f050d46 100644 --- a/asm/Dolphin/card/CARDDir.s +++ b/asm/Dolphin/card/CARDDir.s @@ -7,7 +7,7 @@ __CARDGetDirBlock: /* 803BA970 003B78D0 80 63 00 84 */ lwz r3, 0x84(r3) /* 803BA974 003B78D4 4E 80 00 20 */ blr -WriteCallback: +.fn WriteCallback, local /* 803BA978 003B78D8 7C 08 02 A6 */ mflr r0 /* 803BA97C 003B78DC 90 01 00 04 */ stw r0, 4(r1) /* 803BA980 003B78E0 94 21 FF E0 */ stwu r1, -0x20(r1) @@ -64,9 +64,9 @@ lbl_803BAA2C: /* 803BAA3C 003B799C 38 21 00 20 */ addi r1, r1, 0x20 /* 803BAA40 003B79A0 7C 08 03 A6 */ mtlr r0 /* 803BAA44 003B79A4 4E 80 00 20 */ blr +.endfn WriteCallback -.global EraseCallback -EraseCallback: +.fn EraseCallback, local /* 803BAA48 003B79A8 7C 08 02 A6 */ mflr r0 /* 803BAA4C 003B79AC 90 01 00 04 */ stw r0, 4(r1) /* 803BAA50 003B79B0 94 21 FF D8 */ stwu r1, -0x28(r1) @@ -120,6 +120,7 @@ lbl_803BAAF4: /* 803BAB04 003B7A64 38 21 00 28 */ addi r1, r1, 0x28 /* 803BAB08 003B7A68 7C 08 03 A6 */ mtlr r0 /* 803BAB0C 003B7A6C 4E 80 00 20 */ blr +.endfn EraseCallback .global __CARDUpdateDir __CARDUpdateDir: diff --git a/asm/Dolphin/card/CARDFormat.s b/asm/Dolphin/card/CARDFormat.s index b4a0a9c0..6b71577f 100644 --- a/asm/Dolphin/card/CARDFormat.s +++ b/asm/Dolphin/card/CARDFormat.s @@ -2,7 +2,7 @@ .section .text, "ax" -FormatCallback: +.fn FormatCallback, local /* 803BC588 003B94E8 7C 08 02 A6 */ mflr r0 /* 803BC58C 003B94EC 90 01 00 04 */ stw r0, 4(r1) /* 803BC590 003B94F0 94 21 FF E0 */ stwu r1, -0x20(r1) @@ -88,6 +88,7 @@ lbl_803BC6AC: /* 803BC6C0 003B9620 38 21 00 20 */ addi r1, r1, 0x20 /* 803BC6C4 003B9624 7C 08 03 A6 */ mtlr r0 /* 803BC6C8 003B9628 4E 80 00 20 */ blr +.endfn FormatCallback .global __CARDFormatRegionAsync __CARDFormatRegionAsync: diff --git a/asm/Dolphin/card/CARDRead.s b/asm/Dolphin/card/CARDRead.s index c219781a..3f63d132 100644 --- a/asm/Dolphin/card/CARDRead.s +++ b/asm/Dolphin/card/CARDRead.s @@ -126,7 +126,7 @@ lbl_803BD6A8: /* 803BD6C0 003BA620 7C 08 03 A6 */ mtlr r0 /* 803BD6C4 003BA624 4E 80 00 20 */ blr -ReadCallback: +.fn ReadCallback, local /* 803BD6C8 003BA628 7C 08 02 A6 */ mflr r0 /* 803BD6CC 003BA62C 90 01 00 04 */ stw r0, 4(r1) /* 803BD6D0 003BA630 94 21 FF D8 */ stwu r1, -0x28(r1) @@ -210,6 +210,7 @@ lbl_803BD7E4: /* 803BD7EC 003BA74C 38 21 00 28 */ addi r1, r1, 0x28 /* 803BD7F0 003BA750 7C 08 03 A6 */ mtlr r0 /* 803BD7F4 003BA754 4E 80 00 20 */ blr +.endfn ReadCallback .global CARDReadAsync CARDReadAsync: diff --git a/asm/Kyoto/Streams/CInputStream.s b/asm/Kyoto/Streams/CInputStream.s index 2d2eab2e..635a7392 100644 --- a/asm/Kyoto/Streams/CInputStream.s +++ b/asm/Kyoto/Streams/CInputStream.s @@ -14,18 +14,23 @@ __vt__12CInputStream: .section .sbss, "wa" .balign 8 -.global lbl_805A94F0 -lbl_805A94F0: +.obj c$101, local + .skip 0x1 +.endobj c$101 + .skip 0x1 + +.obj s$108, local .skip 0x2 -.global lbl_805A94F2 -lbl_805A94F2: - .skip 0x2 -.global lbl_805A94F4 -lbl_805A94F4: +.endobj s$108 + +.obj l$112, local .skip 0x4 -.global lbl_805A94F8 -lbl_805A94F8: +.endobj l$112 + +.obj lbl_805A94F8, local .skip 0x4 +.endobj lbl_805A94F8 + .global lbl_805A94FC lbl_805A94FC: .skip 0x4 @@ -68,12 +73,12 @@ ReadLongLong__12CInputStreamFv: ReadLong__12CInputStreamFv: /* 8033EC84 0033BBE4 94 21 FF F0 */ stwu r1, -0x10(r1) /* 8033EC88 0033BBE8 7C 08 02 A6 */ mflr r0 -/* 8033EC8C 0033BBEC 38 8D A9 34 */ addi r4, r13, lbl_805A94F4@sda21 +/* 8033EC8C 0033BBEC 38 8D A9 34 */ addi r4, r13, l$112@sda21 /* 8033EC90 0033BBF0 38 A0 00 04 */ li r5, 4 /* 8033EC94 0033BBF4 90 01 00 14 */ stw r0, 0x14(r1) /* 8033EC98 0033BBF8 48 00 02 BD */ bl Get__12CInputStreamFPvUl /* 8033EC9C 0033BBFC 80 01 00 14 */ lwz r0, 0x14(r1) -/* 8033ECA0 0033BC00 80 6D A9 34 */ lwz r3, lbl_805A94F4@sda21(r13) +/* 8033ECA0 0033BC00 80 6D A9 34 */ lwz r3, l$112@sda21(r13) /* 8033ECA4 0033BC04 7C 08 03 A6 */ mtlr r0 /* 8033ECA8 0033BC08 38 21 00 10 */ addi r1, r1, 0x10 /* 8033ECAC 0033BC0C 4E 80 00 20 */ blr @@ -82,12 +87,12 @@ ReadLong__12CInputStreamFv: ReadShort__12CInputStreamFv: /* 8033ECB0 0033BC10 94 21 FF F0 */ stwu r1, -0x10(r1) /* 8033ECB4 0033BC14 7C 08 02 A6 */ mflr r0 -/* 8033ECB8 0033BC18 38 8D A9 32 */ addi r4, r13, lbl_805A94F2@sda21 +/* 8033ECB8 0033BC18 38 8D A9 32 */ addi r4, r13, s$108@sda21 /* 8033ECBC 0033BC1C 38 A0 00 02 */ li r5, 2 /* 8033ECC0 0033BC20 90 01 00 14 */ stw r0, 0x14(r1) /* 8033ECC4 0033BC24 48 00 02 91 */ bl Get__12CInputStreamFPvUl /* 8033ECC8 0033BC28 80 01 00 14 */ lwz r0, 0x14(r1) -/* 8033ECCC 0033BC2C A0 6D A9 32 */ lhz r3, lbl_805A94F2@sda21(r13) +/* 8033ECCC 0033BC2C A0 6D A9 32 */ lhz r3, s$108@sda21(r13) /* 8033ECD0 0033BC30 7C 08 03 A6 */ mtlr r0 /* 8033ECD4 0033BC34 38 21 00 10 */ addi r1, r1, 0x10 /* 8033ECD8 0033BC38 4E 80 00 20 */ blr @@ -111,12 +116,12 @@ ReadBool__12CInputStreamFv: ReadChar__12CInputStreamFv: /* 8033ED0C 0033BC6C 94 21 FF F0 */ stwu r1, -0x10(r1) /* 8033ED10 0033BC70 7C 08 02 A6 */ mflr r0 -/* 8033ED14 0033BC74 38 8D A9 30 */ addi r4, r13, lbl_805A94F0@sda21 +/* 8033ED14 0033BC74 38 8D A9 30 */ addi r4, r13, c$101@sda21 /* 8033ED18 0033BC78 38 A0 00 01 */ li r5, 1 /* 8033ED1C 0033BC7C 90 01 00 14 */ stw r0, 0x14(r1) /* 8033ED20 0033BC80 48 00 02 35 */ bl Get__12CInputStreamFPvUl /* 8033ED24 0033BC84 80 01 00 14 */ lwz r0, 0x14(r1) -/* 8033ED28 0033BC88 88 6D A9 30 */ lbz r3, lbl_805A94F0@sda21(r13) +/* 8033ED28 0033BC88 88 6D A9 30 */ lbz r3, c$101@sda21(r13) /* 8033ED2C 0033BC8C 7C 08 03 A6 */ mtlr r0 /* 8033ED30 0033BC90 38 21 00 10 */ addi r1, r1, 0x10 /* 8033ED34 0033BC94 4E 80 00 20 */ blr @@ -427,13 +432,13 @@ __ct__12CInputStreamFi: /* 8033F14C 0033C0AC 94 21 FF F0 */ stwu r1, -0x10(r1) /* 8033F150 0033C0B0 7C 08 02 A6 */ mflr r0 /* 8033F154 0033C0B4 3C C0 80 3F */ lis r6, __vt__12CInputStream@ha -/* 8033F158 0033C0B8 3C A0 80 3D */ lis r5, lbl_803D7A68@ha +/* 8033F158 0033C0B8 3C A0 80 3D */ lis r5, "@stringBase0"@ha /* 8033F15C 0033C0BC 90 01 00 14 */ stw r0, 0x14(r1) /* 8033F160 0033C0C0 38 06 E3 88 */ addi r0, r6, __vt__12CInputStream@l /* 8033F164 0033C0C4 93 E1 00 0C */ stw r31, 0xc(r1) /* 8033F168 0033C0C8 7C 7F 1B 78 */ mr r31, r3 /* 8033F16C 0033C0CC 7C 83 23 78 */ mr r3, r4 -/* 8033F170 0033C0D0 38 85 7A 68 */ addi r4, r5, lbl_803D7A68@l +/* 8033F170 0033C0D0 38 85 7A 68 */ addi r4, r5, "@stringBase0"@l /* 8033F174 0033C0D4 90 1F 00 00 */ stw r0, 0(r31) /* 8033F178 0033C0D8 38 00 00 00 */ li r0, 0 /* 8033F17C 0033C0DC 38 A0 00 00 */ li r5, 0 @@ -457,9 +462,7 @@ __ct__12CInputStreamFi: .section .rodata .balign 8 -.global lbl_803D7A68 -lbl_803D7A68: +.obj "@stringBase0", local # ROM: 0x3D4A68 .asciz "??(??)" - .balign 4 - +.endobj "@stringBase0" diff --git a/configure.py b/configure.py index 3c04e28b..d652b505 100755 --- a/configure.py +++ b/configure.py @@ -35,7 +35,7 @@ LIBS = [ "MetroidPrime/Factories/CCharacterFactory", "MetroidPrime/Factories/CAssetFactory", ["MetroidPrime/Tweaks/CTweakPlayer", True], - "MetroidPrime/Tweaks/CTweaks", + ["MetroidPrime/Tweaks/CTweaks", False], ["MetroidPrime/Tweaks/CTweakGame", True], "MetroidPrime/CGameProjectile", ["MetroidPrime/Player/CPlayerGun", False], diff --git a/include/Kyoto/TOneStatic.hpp b/include/Kyoto/TOneStatic.hpp index 54e67587..fbe6bb85 100644 --- a/include/Kyoto/TOneStatic.hpp +++ b/include/Kyoto/TOneStatic.hpp @@ -1,31 +1,37 @@ #ifndef _TONESTATIC #define _TONESTATIC -#include "types.h" #include "stdio.h" +#include "types.h" template < typename T > class TOneStatic { public: - void* operator new(size_t sz, const char*, const char*); /* { - ReferenceCount()++; - return GetAllocSpace(); - }*/ + void* operator new(size_t sz, const char*, const char*); void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); } void operator delete(void* ptr); private: - static void* GetAllocSpace() { - static uchar sAllocSpace[sizeof(T)]; - return &sAllocSpace; - } + static void* GetAllocSpace(); static uint& ReferenceCount(); }; template < typename T > uint& TOneStatic< T >::ReferenceCount() { - static uint sReferenceCount = 0; - return sReferenceCount; + static uint sReferenceCount = 0; + return sReferenceCount; +} + +template < typename T > +void* TOneStatic< T >::GetAllocSpace() { + static char sAllocSpace[sizeof(T)]; + return &sAllocSpace; +} + +template < typename T > +void* TOneStatic< T >::operator new(size_t sz, const char*, const char*) { + ReferenceCount()++; + return GetAllocSpace(); } template < typename T > @@ -33,4 +39,6 @@ void TOneStatic< T >::operator delete(void* ptr) { ReferenceCount()--; } + + #endif // _TONESTATIC diff --git a/include/MetroidPrime/CMain.hpp b/include/MetroidPrime/CMain.hpp index 97594d60..5ace6d23 100644 --- a/include/MetroidPrime/CMain.hpp +++ b/include/MetroidPrime/CMain.hpp @@ -104,7 +104,6 @@ private: CMemorySys x6d_memorySys; CDvdRequestSys x6e_dvdRequestSys; CTweaks x70_tweaks; - uchar pad[0x14]; double xe8_; TReservedAverage< float, 4 > xf0_; TReservedAverage< float, 4 > x104_; diff --git a/include/MetroidPrime/CMappableObject.hpp b/include/MetroidPrime/CMappableObject.hpp index 869cdc19..aa73473c 100644 --- a/include/MetroidPrime/CMappableObject.hpp +++ b/include/MetroidPrime/CMappableObject.hpp @@ -52,6 +52,7 @@ public: return type >= kMOT_BlueDoor && type <= kMOT_PlasmaDoorFloor2; } + static void ReadAutomapperTweaks(const CTweakAutoMapper&); private: EMappableObjectType x0_type; EVisMode x4_visibilityMode; @@ -60,7 +61,6 @@ private: CTransform4f x10_transform; uchar x40_pad[0x10]; - static void ReadAutomapperTweaks(const CTweakAutoMapper&); CTransform4f AdjustTransformForType(); static CVector3f skDoorVerts[8]; diff --git a/include/MetroidPrime/Tweaks/CTweakGunRes.hpp b/include/MetroidPrime/Tweaks/CTweakGunRes.hpp index 45ba6eee..094977db 100644 --- a/include/MetroidPrime/Tweaks/CTweakGunRes.hpp +++ b/include/MetroidPrime/Tweaks/CTweakGunRes.hpp @@ -9,7 +9,7 @@ #include "Kyoto/CObjectReference.hpp" -class CTweakGunRes : public ITweakObject { +class CTweakGunRes : public ITweakObject, public TOneStatic { public: typedef CAssetId ResId; typedef CPlayerState::EBeamId EBeamId; @@ -21,8 +21,9 @@ public: ResId* d; }; + CTweakGunRes(CInputStream& in); ~CTweakGunRes() override; - +#if 0 ResId x4_gunMotion; ResId x8_grappleArm; ResId xc_rightHand; @@ -50,7 +51,8 @@ public: ResId xbc_grappleHit; ResId xc0_grappleMuzzle; ResId xc4_grappleSwoosh; - +#endif + char cls[0xc4]; const WeaponResourcePair* GetWeaponResourcePair(int beam) const; /* { const int b = int(beam); if (b < 0 || b > 4) { diff --git a/include/MetroidPrime/Tweaks/CTweakPlayerGun.hpp b/include/MetroidPrime/Tweaks/CTweakPlayerGun.hpp index 203d1043..15bd26f3 100644 --- a/include/MetroidPrime/Tweaks/CTweakPlayerGun.hpp +++ b/include/MetroidPrime/Tweaks/CTweakPlayerGun.hpp @@ -63,8 +63,9 @@ struct SWeaponInfo { explicit SWeaponInfo(CInputStream& in); }; -class CTweakPlayerGun : public ITweakObject { +class CTweakPlayerGun : public ITweakObject, public TOneStatic { public: + CTweakPlayerGun(CInputStream& in); ~CTweakPlayerGun() override; float GetUpLookAngle() const { return x4_upLookAngle; } diff --git a/include/MetroidPrime/Tweaks/CTweakPlayerRes.hpp b/include/MetroidPrime/Tweaks/CTweakPlayerRes.hpp index 4c28e496..03b7f267 100644 --- a/include/MetroidPrime/Tweaks/CTweakPlayerRes.hpp +++ b/include/MetroidPrime/Tweaks/CTweakPlayerRes.hpp @@ -1,15 +1,21 @@ #ifndef _CTWEAKPLAYERRES #define _CTWEAKPLAYERRES +#include + #include "Kyoto/SObjectTag.hpp" -struct CTweakPlayerRes { +struct CTweakPlayerRes : public ITweakObject, public TOneStatic { public: +/* CAssetId x4_saveStationIcon; CAssetId x8_missileStationIcon; CAssetId xc_elevatorIcon; CAssetId x10_minesBreakFirstTopIcon; CAssetId x14_minesBreakFirstBottomIcon; +*/ + char cls[0xf0]; + CTweakPlayerRes(CInputStream& in); }; extern CTweakPlayerRes* gpTweakPlayerRes; diff --git a/include/MetroidPrime/Tweaks/CTweakTargeting.hpp b/include/MetroidPrime/Tweaks/CTweakTargeting.hpp new file mode 100644 index 00000000..90480f15 --- /dev/null +++ b/include/MetroidPrime/Tweaks/CTweakTargeting.hpp @@ -0,0 +1,14 @@ +#ifndef _CTWEAKTARGETING +#define _CTWEAKTARGETING + +#include "MetroidPrime/Tweaks/ITweakObject.hpp" + +class CTweakTargeting : public ITweakObject, public TOneStatic { +public: + CTweakTargeting(CInputStream& in); + +private: + uchar cls[0x224]; +}; + +#endif // _CTWEAKTARGETING diff --git a/include/MetroidPrime/Tweaks/CTweaks.hpp b/include/MetroidPrime/Tweaks/CTweaks.hpp index 8279f923..09a043bc 100644 --- a/include/MetroidPrime/Tweaks/CTweaks.hpp +++ b/include/MetroidPrime/Tweaks/CTweaks.hpp @@ -18,9 +18,9 @@ public: void RegisterTweaks(); private: - rstl::reserved_vector< rstl::auto_ptr< ITweakObject >, 12 > x0_; + rstl::reserved_vector< rstl::auto_ptr< ITweakObject >, 14 > mTweakObjects; }; -CHECK_SIZEOF(CTweaks, 0x64) +CHECK_SIZEOF(CTweaks, 0x74) extern CTweakPlayerControl* gpTweakPlayerControlCurrent; extern CTweakPlayerControl* gpTweakPlayerControl1; diff --git a/src/MetroidPrime/Tweaks/CTweaks.cpp b/src/MetroidPrime/Tweaks/CTweaks.cpp new file mode 100644 index 00000000..47860496 --- /dev/null +++ b/src/MetroidPrime/Tweaks/CTweaks.cpp @@ -0,0 +1,165 @@ +#include +#include + +// These files must remain in this order.... +// clang-format off +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// clang-format on + +#include + +CTweakPlayer* gpTweakPlayer = nullptr; +CTweakBall* gpTweakBall = nullptr; +CTweakGame* gpTweakGame = nullptr; +CTweakParticle* gpTweakParticle = nullptr; +CTweakPlayerControl* gpTweakPlayerControlCurrent = nullptr; +CTweakPlayerControl* gpTweakPlayerControl1 = nullptr; +CTweakPlayerControl* gpTweakPlayerControl2 = nullptr; +CTweakPlayerGun* gpTweakPlayerGun = nullptr; +CTweakGui* gpTweakGui = nullptr; +CTweakGuiColors* gpTweakGuiColors = nullptr; +CTweakTargeting* gpTweakTargeting = nullptr; +CTweakAutoMapper* gpTweakAutoMapper = nullptr; +CTweakGunRes* gpTweakGunRes = nullptr; +CTweakPlayerRes* gpTweakPlayerRes = nullptr; +CTweakSlideShow* gpTweakSlideShow = nullptr; + +CAssetId IDFromFactory(CResFactory& factory, const char* filename) { + return factory.GetResourceIdByName(filename)->id; +} + +CTweaks::CTweaks() { mTweakObjects.resize(14, rstl::auto_ptr< ITweakObject >()); } + +CTweaks::~CTweaks() { + gpTweakPlayer = nullptr; + gpTweakBall = nullptr; + gpTweakGame = nullptr; + gpTweakParticle = nullptr; + gpTweakPlayerControlCurrent = nullptr; + gpTweakPlayerGun = nullptr; + gpTweakGui = nullptr; + gpTweakGuiColors = nullptr; + gpTweakTargeting = nullptr; + gpTweakAutoMapper = nullptr; + gpTweakGunRes = nullptr; + gpTweakPlayerRes = nullptr; + gpTweakSlideShow = nullptr; +} + +void CTweaks::RegisterTweaks() { + CResFactory* resFactory = gpResourceFactory; + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "Particle")), nullptr); + gpTweakParticle = new CTweakParticle(*stream); + mTweakObjects[2] = gpTweakParticle; + } + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "Player")), nullptr); + gpTweakPlayer = new CTweakPlayer(*stream); + mTweakObjects[0] = gpTweakPlayer; + } + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "CameraBob")), nullptr); + CPlayerCameraBob::ReadTweaks(*stream); + } + + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "Ball")), nullptr); + gpTweakBall = new CTweakBall(*stream); + mTweakObjects[7] = gpTweakBall; + } + + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "PlayerGun")), nullptr); + gpTweakPlayerGun = new CTweakPlayerGun(*stream); + mTweakObjects[4] = gpTweakPlayerGun; + } + + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "Targeting")), nullptr); + gpTweakTargeting = new CTweakTargeting(*stream); + mTweakObjects[8] = gpTweakTargeting; + } + + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "Game")), nullptr); + gpTweakGame = new CTweakGame(*stream); + mTweakObjects[1] = gpTweakGame; + } + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "GuiColors")), nullptr); + gpTweakGuiColors = new CTweakGuiColors(*stream); + mTweakObjects[6] = gpTweakGuiColors; + } + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "AutoMapper")), nullptr); + gpTweakAutoMapper = new CTweakAutoMapper(*stream); + mTweakObjects[2] = gpTweakAutoMapper; + CMappableObject::ReadAutomapperTweaks(*gpTweakAutoMapper); + } + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "Gui")), nullptr); + gpTweakGui = new CTweakGui(*stream); + mTweakObjects[5] = gpTweakGui; + } + + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "PlayerControls")), nullptr); + gpTweakPlayerControlCurrent = new CTweakPlayerControl(*stream); + mTweakObjects[3] = gpTweakPlayerControlCurrent; + gpTweakPlayerControl1 = gpTweakPlayerControlCurrent; + } + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "PlayerControls2")), nullptr); + gpTweakPlayerControl2 = new CTweakPlayerControl(*stream); + mTweakObjects[13] = gpTweakPlayerControl2; + } + { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "SlideShow")), nullptr); + gpTweakSlideShow = new CTweakSlideShow(*stream); + mTweakObjects[12] = gpTweakSlideShow; + } +} + +void CTweaks::RegisterResourceTweaks() { + CResFactory* resFactory = gpResourceFactory; + if (gpTweakGunRes == nullptr) { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "GunRes")), nullptr); + gpTweakGunRes = new CTweakGunRes(*stream); + mTweakObjects[10] = gpTweakGunRes; + } + + if (gpTweakPlayerRes == nullptr) { + rstl::auto_ptr< CInputStream > stream = resFactory->GetResLoader().LoadNewResourceSync( + SObjectTag('CTWK', IDFromFactory(*resFactory, "PlayerRes")), nullptr); + gpTweakPlayerRes = new CTweakPlayerRes(*stream); + mTweakObjects[11] = gpTweakPlayerRes; + } +}