Skip to content

Commit

Permalink
[+] New Particles
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVB committed Sep 10, 2024
1 parent f17c585 commit c95e700
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
4 changes: 3 additions & 1 deletion include/Lunacy/ConstEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,9 @@ enum ParticleEffect
PARTICLE_STARBURST,
PARTICLE_CREDITS_FOG,
PARTICLE_PERSENT_PICK_UP_ARROW,
NUM_PARTICLES

NUM_PARTICLES,
BASE_NUM_PARTICLES = 0x6A,
};
enum PlantPriority
{
Expand Down
2 changes: 1 addition & 1 deletion include/Lunacy/Lawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
class HitResult
{
public:
GameObjectType mType;
void* aObject;
GameObjectType mType;
};

class Lawn : Sexy::UIElement, Sexy::ButtonListener
Expand Down
17 changes: 17 additions & 0 deletions include/Lunacy/Particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,26 @@ class EmitterDefinition

class ParticleDefinition
{
private:
static unsigned int* _gParticleDefSize;
static unsigned int _gParticleDefCapacity;
static ParticleDefinition** _gParticleDefs;

static unsigned int* _gEmitterDefSize;
static EmitterDefinition** _gEmitterDefs;

public:
EmitterDefinition* mEmitterDefs;
int mEmitterDefCount;

static ParticleDefinition* GetDefinitions();
static ParticleDefinition* GetDefinition(ParticleEffect);

// Reallocates the ParticleDefinition array to allow you to create new particles.
// Warning: calling this function when there are any particles in the game will cause a crash.
// Call it only during the game's loading when there are no particles present.
static ParticleDefinition* Reallocate(unsigned int NewCapacity);
static ParticleDefinition* CloneParticle(ParticleEffect);
};

class ParticleEmitter
Expand Down
59 changes: 59 additions & 0 deletions src/Lunacy/Particle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "Lunacy/Particle.h"

unsigned int ParticleDefinition::_gParticleDefCapacity = BASE_NUM_PARTICLES;
unsigned int* ParticleDefinition::_gParticleDefSize = (unsigned int*)0x6A9F08;
unsigned int* ParticleDefinition::_gEmitterDefSize = (unsigned int*)0x6A9F10;

ParticleDefinition** ParticleDefinition::_gParticleDefs = (ParticleDefinition**)0x6A9F0C;
EmitterDefinition** ParticleDefinition::_gEmitterDefs = (EmitterDefinition**)0x6A9F14;

ParticleDefinition* ParticleDefinition::GetDefinitions()
{
return (ParticleDefinition*)_gParticleDefs;
}

ParticleDefinition* ParticleDefinition::GetDefinition(ParticleEffect Type)
{
return ((ParticleDefinition*)(_gParticleDefs)) + Type;
}

unsigned int Reallocations = 0;
ParticleDefinition* ParticleDefinition::Reallocate(unsigned int NewCapacity)
{
Reallocations++;

auto NewArray = (ParticleDefinition*)operator new(sizeof(ParticleDefinition) * NewCapacity);
auto OldArray = *_gParticleDefs;

// Copy data
memset(NewArray, 0, sizeof(ParticleDefinition) * NewCapacity);
memcpy(NewArray, OldArray, sizeof(ParticleDefinition) * (*_gParticleDefSize));

// Move references
*_gParticleDefs = NewArray;
_gParticleDefCapacity = NewCapacity;

// Delete old array
if (Reallocations > 1)
delete OldArray;
return NewArray;
}

ParticleDefinition* ParticleDefinition::CloneParticle(ParticleEffect Type)
{
if (_gParticleDefCapacity == *_gParticleDefSize)
Reallocate(*_gParticleDefSize + 0x10);

auto NewParticle = *_gParticleDefs + *_gParticleDefSize;
auto OldParticle = *_gParticleDefs + Type;
(*_gParticleDefSize)++;

auto NewDefinition = (EmitterDefinition*)operator new(sizeof(EmitterDefinition) * OldParticle->mEmitterDefCount);
auto OldDefinition = OldParticle->mEmitterDefs;

memcpy(NewDefinition, OldDefinition, sizeof(EmitterDefinition) * OldParticle->mEmitterDefCount);
NewParticle->mEmitterDefCount = OldParticle->mEmitterDefCount;
NewParticle->mEmitterDefs = NewDefinition;

return NewParticle;
}
3 changes: 2 additions & 1 deletion src/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Luna/Application.hpp"
#include "Lunacy/Lunacy.hpp"
#include <windows.h>
#include <iostream>

Expand All @@ -16,6 +17,6 @@ BOOL APIENTRY DllMain
const auto app = Application::getSingleton();
if (!app->initialize()) return FALSE;
app->getLogger()->log(LogLevel::none, "Luna %s has been initialized.", LUNA_VERSION);

return TRUE;
}

0 comments on commit c95e700

Please sign in to comment.