Skip to content

Commit

Permalink
[+] Added Lawn Functions
Browse files Browse the repository at this point in the history
[+] Added Challenge
[+] Added More Convenience Functions
[+] Added More Unions for Easier Naming
[+] Added Zombie Functions
[+] Added LunaHook Wrappers (UNTESTED)

TODO:
Add the rest of the Zombie functions. (Stopped at IsTangleKelpTarget)

Add the rest of the Lawn functions.

Test LunaWrappers.
  • Loading branch information
0xVB committed Sep 5, 2024
1 parent ab79d03 commit 293f6f8
Show file tree
Hide file tree
Showing 21 changed files with 1,882 additions and 76 deletions.
10 changes: 9 additions & 1 deletion include/Luna/Hook/LunaHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#define i32 int
usize getInstructionSize(const u8* bytes, i32** rel32 = nullptr);

#define LUNAHOOK_MAX_PARAMS 128

#ifndef LUNAHOOK_PARAM_COUNT
#define LUNAHOOK_PARAM_COUNT LUNAHOOK_MAX_PARAMS
#endif

class LunaHookThread
{
LunaHookThread();
Expand Down Expand Up @@ -32,6 +38,7 @@ class LunaHookThread
static void DetourFooter(LunaHookThread*);
class CodeBuffer;
public:
typedef unsigned int (__cdecl* LunaWrapper)(...);

struct Parameter
{
Expand Down Expand Up @@ -61,7 +68,7 @@ class LunaHookThread
DWORD _addr;
DWORD _oldProt;

Parameter _parameters[128];
Parameter _parameters[LUNAHOOK_PARAM_COUNT];
unsigned char _paramCount;
size_t _paramCodeSize;
size_t _stackSize;
Expand All @@ -80,6 +87,7 @@ class LunaHookThread
void AddStackParameters(u8 ParamCount);

void Finalize(void* DetourTo);
LunaWrapper AllocateWrapper();
static FunctionSignature* New(LunaHookThread*, DWORD Address);
};

Expand Down
2 changes: 1 addition & 1 deletion include/Lunacy/CGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Sexy::Padding
int mRight;
int mBottom;

Padding(int Left, int Top, int Right, int Bottom);
Padding(int Left = 0, int Top = 0, int Right = 0, int Bottom = 0);
};

class Sexy::Matrix3
Expand Down
31 changes: 31 additions & 0 deletions include/Lunacy/Challange.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#include "CGeometry.h"

class Challenge
{
public:
LawnApp* mApp;
Lawn* mLawn;
bool mBeghouledMouseCapture;
int mBeghouledMouseDownX;
int mBeghouledMouseDownY;
bool mBeghouledEated[9][6];
bool mBeghouledPurcasedUpgrade[3];
int mBeghouledMatchesThisMove;
ChallengeState mChallengeState;
int mChallengeStateCounter;
int mConveyorBeltCounter;
int mChallengeScore;
bool mShowBowlingLine;
SeedType mLastConveyorSeedType;
int mSurvivalStage;
int mSlotMachineRollCount;
ReanimationID mReanimChallenge;
ReanimationID mReanimCloud[6];
int mCloudCounter[6];
int mChallengeGridX;
int mChallengeGridY;
int mScaryPotterPots;
int mRainCounter;
int mTreeOfWisdomTalkIndex;
};
12 changes: 12 additions & 0 deletions include/Lunacy/ConstEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ enum PickupID { PICKUPID_NULL };
enum ZombieID { ZOMBIEID_NULL };
enum PlantID { PLANTID_NULL };

enum ClickCode : signed int
{
DOUBLE_RIGHTCLICK = -2,
RIGHTCLICK = -1,

LEFTCLICK = 1,
DOUBLE_LEFTCLICK = 2,

MOUSEWHEEL_CLICK = 3
};
enum AdviceType
{
ADVICE_NONE = -1,
Expand Down Expand Up @@ -800,6 +810,7 @@ enum ProjectileMotion
};
enum ProjectileType
{
PROJECTILE_NONE = -1,
PROJECTILE_PEA,
PROJECTILE_SNOWPEA,
PROJECTILE_CABBAGE,
Expand Down Expand Up @@ -1344,6 +1355,7 @@ enum ZombiePhase
};
enum ZombieType
{
ZOMBIE_NONE = -1,
ZOMBIE_INVALID = -1,
ZOMBIE_NORMAL,
ZOMBIE_FLAG,
Expand Down
18 changes: 12 additions & 6 deletions include/Lunacy/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,26 @@ class GameObject
AssociationManager* GetManager();

public:
int mRow;
union
{
int mRow;
int mLane;
};
int mRenderOrder;

GameObject();
float DistanceFrom(Sexy::IVector2);
bool CollidesWith(Sexy::IRect);
int GetLane();
int GetColumn();

Sexy::IVector2 GetGridPos();

Projectile* GetNearestProjectile(float MinDist = 0, ProjectileType Filter = (ProjectileType)-1, bool IsBlacklist = false);
GridItem* GetNearestGridItem(float MinDist = 0, GridItemType = GRIDITEM_NONE, bool IsBlacklist = false);
Zombie* GetNearestZombie(float MinDist = 0, ZombieType = (ZombieType)-1, bool IsBlacklist = false);
Pickup* GetNearestPickup(float MinDist = 0, PickupType = PICKUP_NONE, bool IsBlacklist = false);
Plant* GetNearestPlant(float MinDist = 0, SeedType = SEED_NONE, bool IsBlacklist = false);
Projectile* GetNearestProjectile(float MinDist = 0, float MaxDist = 9e5, ProjectileType Filter = (ProjectileType)-1, bool IsBlacklist = false);
GridItem* GetNearestGridItem(float MinDist = 0, float MaxDist = 9e5, GridItemType = GRIDITEM_NONE, bool IsBlacklist = false);
Zombie* GetNearestZombie(float MinDist = 0, float MaxDist = 9e5, ZombieType = (ZombieType)-1, bool IsBlacklist = false);
Pickup* GetNearestPickup(float MinDist = 0, float MaxDist = 9e5, PickupType = PICKUP_NONE, bool IsBlacklist = false);
Plant* GetNearestPlant(float MinDist = 0, float MaxDist = 9e5, SeedType = SEED_NONE, bool IsBlacklist = false);

std::list<Projectile*> GetProjectilesAround(int LaneRange = 1, int ColRange = 1, ProjectileType = (ProjectileType)-1, bool IsBlacklist = false);
std::list<GridItem*> GetGridItemsAround(int LaneRange = 1, int ColRange = 1, GridItemType = GRIDITEM_NONE, bool IsBlacklist = false);
Expand Down
6 changes: 5 additions & 1 deletion include/Lunacy/GridItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class GridItem
struct
{
int mCol;
int mLane;
union
{
int mLane;
int mRow;
};
};
Sexy::IVector2 GridPos;
};
Expand Down
185 changes: 177 additions & 8 deletions include/Lunacy/Lawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
#include "Listeners.h"
#include "UIElement.h"

class HitResult
{
public:
GameObjectType mType;
void* aObject;
};

class Lawn : Sexy::UIElement, Sexy::ButtonListener
{
#pragma region Fields
Expand Down Expand Up @@ -159,6 +166,7 @@ class Lawn : Sexy::UIElement, Sexy::ButtonListener
GridItem* AddLadder(int Column, int Lane);
GridItem* AddCrater(int Column, int Lane);
GridItem* AddGrave(int Column, int Lane, bool DoEffects = true, bool KillPlants = true);
GridItem* GetGridItemAt(int Col, int Row, GridItemType = GRIDITEM_NONE);

int CountGraves();

Expand All @@ -167,13 +175,17 @@ class Lawn : Sexy::UIElement, Sexy::ButtonListener
Pickup* NewPacket(SeedType, int X, int Y);

Zombie* NewZombie(ZombieType, int Lane, int FromWave = 0);
void KillAllZombies(int Col = -1, int Row = -1, ZombieType = ZOMBIE_NONE, bool DropLoot = false);
void __inline KillAllZombies(ZombieType Type, int Col = -1, int Row = -1, bool DropLoot = false) { KillAllZombies(Col, Row, Type, DropLoot); }
void SpawnZombiesFromPool();
void SpawnZombiesFromSky();
void SpawnZombiesFromGrave();

Plant* NewPlant(int Column, int Lane, SeedType, SeedType ImitaterType);
void DoPlantingEffects(int Column, int Lane, Plant*);
void KillPlantCell(int Col = -1, int Lane = -1);
void KillAllPlants(int Col = -1, int Row = -1, SeedType = SEED_NONE);
void __inline KillAllPlants(SeedType Type, int Col = -1, int Row = -1) { KillAllPlants(Col, Row, Type); }
Plant* GetPlantAt(int Col, int Row, SeedType = SEED_NONE);

Projectile* NewProjectile(int X, int Y, int RenderOrder, int Lane, ProjectileType);

Expand All @@ -191,16 +203,173 @@ class Lawn : Sexy::UIElement, Sexy::ButtonListener
Sexy::IRect GridToPixelArea(int Col, int Lane, int HSize = 3, int VSize = 3);
Sexy::IRect PixelToGridArea(int X, int Y, int W = 100, int H = 100);

Projectile* GetNearestProjectile(Sexy::FVector2, float MinDistance = 0, ProjectileType Filter = (ProjectileType)-1, bool IsBlacklist = false);
GridItem* GetNearestGridItem(Sexy::FVector2, float MinDistance = 0, GridItemType = GRIDITEM_NONE, bool IsBlacklist = false);
Zombie* GetNearestZombie(Sexy::FVector2, float MinDistance = 0, ZombieType = (ZombieType)-1, bool IsBlacklist = false);
Pickup* GetNearestPickup(Sexy::FVector2, float MinDistance = 0, PickupType = PICKUP_NONE, bool IsBlacklist = false);
Plant* GetNearestPlant(Sexy::FVector2, float MinDistance = 0, SeedType = SEED_NONE, bool IsBlacklist = false);
Projectile* GetNearestProjectile(Sexy::FVector2, float MinDistance = 0, float MaxDistance = 9e5, ProjectileType Filter = PROJECTILE_NONE, bool IsBlacklist = false);
GridItem* GetNearestGridItem(Sexy::FVector2, float MinDistance = 0, float MaxDistance = 9e5, GridItemType = GRIDITEM_NONE, bool IsBlacklist = false);
Zombie* GetNearestZombie(Sexy::FVector2, float MinDistance = 0, float MaxDistance = 9e5, ZombieType = ZOMBIE_NONE, bool IsBlacklist = false);
Pickup* GetNearestPickup(Sexy::FVector2, float MinDistance = 0, float MaxDistance = 9e5, PickupType = PICKUP_NONE, bool IsBlacklist = false);
Plant* GetNearestPlant(Sexy::FVector2, float MinDistance = 0, float MaxDistance = 9e5, SeedType = SEED_NONE, bool IsBlacklist = false);

std::list<Projectile*> GetProjectilesInArea(Sexy::IRect, ProjectileType = (ProjectileType)-1, bool IsBlacklist = false);
std::list<Projectile*> GetProjectilesInArea(Sexy::IRect, ProjectileType = PROJECTILE_NONE, bool IsBlacklist = false);
std::list<GridItem*> GetGridItemsInArea(Sexy::IRect, GridItemType = GRIDITEM_NONE, bool IsBlacklist = false);
std::list<Zombie*> GetZombiesInArea(Sexy::IRect, ZombieType = (ZombieType)-1, bool IsBlacklist = false);
std::list<Zombie*> GetZombiesInArea(Sexy::IRect, ZombieType = ZOMBIE_NONE, bool IsBlacklist = false);
std::list<Pickup*> GetPickupsInArea(Sexy::IRect, PickupType = PICKUP_NONE, bool IsBlacklist = false);
std::list<Plant*> GetPlantsInArea(Sexy::IRect, SeedType = SEED_NONE, bool IsBlacklist = false);
#pragma endregion
#pragma region Base Methods
Lawn(LawnApp*);
void Dispose();

int CountPlants(SeedType = SEED_NONE);
bool AreEnemiesOnScreen();
int CountEnemiesOnScreen();
int CountLawnMowers();

void TrySaveGame();
bool NeedSaveGame();
bool LoadGame(PopString& FileName);

GridItem* GetRake();
bool CanAddGraveAt(int Col, int Row);

int GetNumWavesPerFlag();
bool IsFlagWave(int WaveNumber);

static bool __stdcall CanZombieSpawnOnLevel(ZombieType, int Level);
ZombieType GetIntroducedZombieType();
bool LaneCanHaveZombie(int Row, ZombieType);
void InitZombieWavesForLevel(int Level);
int PickLaneForNewZombie(ZombieType);
void RemoveZombiesForRepick();
void RemoveCutsceneZombies();
bool ChooseSeedsForLevel();
void InitSurvivalStage();
void RemoveAllZombies();
void PickZombieWaves();
void InitZombieWaves();
void InitLawnMowers();
bool CanAddBobsled();
void StartLevel();
void InitLevel();
void PlaceRake();

void SetEffectsPlaying(bool);
int GetLevelRandSeed();
void LoadBackground();
void PickBackground();

void GetShovelButtonRect(Sexy::IRect*);
void GetZenButtonRect(GameObjectType, Sexy::IRect*);
Sexy::IRect __inline GetShovelButtonRect()
{
Sexy::IRect aRect;
GetShovelButtonRect(&aRect);
return aRect;
}
Sexy::IRect __inline GetZenButtonRect(GameObjectType Type)
{
Sexy::IRect aRect;
GetZenButtonRect(Type, &aRect);
return aRect;
}

void FadeOutLevel();
bool IsPlantEquipped();
SeedType GetEquippedPlantType();
void RefreshEquippedSeed();

bool CanPlantAt(int Col, int Row, SeedType);
bool IsPoolCell(int Col, int Row);
bool IsIceCell(int Col, int Row);

GridItem* GridItemHitTest(int MouseX, int MouseY);
Zombie* ZombieHitTest(int MouseX, int MouseY);
Plant* PlantHitTest(int MouseX, int MouseY);
Plant* SpecialPlantHitTest(int MouseX, int MouseY);

bool MouseHitTest(int X, int Y, HitResult* Out);
void PickUpTool(GameObjectType);
bool CanInteractWithButtons();
void SetPause(bool);
void ClearCursor();

void UpdateMousePosition();
void UpdateToolTip();
void MouseDownWithPlant(int X, int Y, ClickCode);
void MouseDownWithTool(int X, int Y, ClickCode, CursorType);

void ShowTutorialArrow(int X, int Y);
void RemoveTutorialArrow();

int GetWaveHealth(int WaveIndex);
int __inline GetWaveHealth() { return GetWaveHealth(mCurrentWave); }
void SpawnNextWave();
void StopZombieSounds();
int GetSurvivalFlagsCompleted();
void ZombiesWon(Zombie*);
void __inline ZombiesWon() { ZombiesWon(NewZombie(ZOMBIE_NORMAL, 0)); }

bool IsFinalSurvivalStage();
bool LevelAwardDropped();
void UpdateSunSkyfall();
void UpdateZombieSpawning();
void UpdateIce();
void UpdateProgressMeter();
bool CanSpawnZombiesInLane(int Lane);
bool HasProgressMeter();
bool ProgressMeterHasFlags();

void ClearFogAroundPlant(Plant*, int Size);
void UpdateFog();

void DrawIce(Sexy::Graphics*);
void DrawBackground(Sexy::Graphics*);
void DrawProgressMeter(Sexy::Graphics*);
void DrawHouseDoorBottom(Sexy::Graphics*);
void DrawHouseDoorTop(Sexy::Graphics*);
void DrawLevelName(Sexy::Graphics*);
void DrawZenButtons(Sexy::Graphics*);
void DrawShovel(Sexy::Graphics*);
void DrawDebugText(Sexy::Graphics*);
void DrawObjectRects(Sexy::Graphics*);
void DrawFadeOut(Sexy::Graphics*);
void DrawTopRightUI(Sexy::Graphics*);
void DrawBottomUI(Sexy::Graphics*);
void DrawCoinBank(Sexy::Graphics*);
void DrawFog(Sexy::Graphics*);
void DrawTopUI(Sexy::Graphics*);

void SetMustacheMode(bool);
void SetFutureMode(bool);
void SetPinataMode(bool);
void SetDanceMode(bool);
void SetSuperMowerMode(bool);

void AddSun(int);
bool TakeSun(int);
bool CanTakeSun(int);
int GetSunBeingCollected();
int GetCoinsBeingCollected();
int GetNumSeedsInBank();

bool IsConveyorBeltLevel();
bool StageHasGraves();
bool IsNightStage();
bool StageHasRoof();
bool StageHasPool();
bool StageHasFog();
int LeftFogColumn();
bool StageHasZombiesWalkInFromRight();
int GetSeedPacketXPosition(int PacketIndex);
int GetSeedBankExtraWidth();

bool SeedNotRecommendedForLevel(SeedType);
bool CanDropLoot();
bool IsBungeeTargetingCell(int Col, int Row);
Zombie* GetZomboss();
void DoFwoosh(int Row);
void UpdateFwoosh();
bool PlantingRequirementsMet(SeedType);

#pragma endregion

};
7 changes: 1 addition & 6 deletions include/Lunacy/LawnMower.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,4 @@ class LawnMower
void EnableSuperMower();

LawnMower(int Lane);
};

LawnMower* TryToGet(LawnMowerID ID)
{
return LawnApp::GetApp()->mLawn->mLawnMowers.Fetch(ID);
}
};
Loading

0 comments on commit 293f6f8

Please sign in to comment.