Skip to content
Draft
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
15 changes: 15 additions & 0 deletions libzhl/IsaacRepentance_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ bool Isaac::IsInGame() {
return g_Manager->GetState() == 2 && g_Game;
}

Vector * Isaac::WorldToScreen(Vector * ret, Vector* pos) {
Game * game = g_Game;
if (!game) {
ret = pos;
return ret;
}
float scale = g_DisplayPixelsPerPoint * g_PointScale;
Room* room = game->_room;
float f1 = floor((((g_WIDTH - 338.0f) * 0.5f + (pos->x - 60.0f) * 0.65f) * scale + 0.5f));
float f2 = floor((((g_HEIGHT - 182.0f) * 0.5f + (pos->y - 140.0f) * 0.65f) * scale + 0.5f));
ret->x = f1 / scale + room->_renderScrollOffset.x + game->_screenShakeOffset.x;
ret->y = f2 / scale + room->_renderScrollOffset.y + game->_screenShakeOffset.y;
return ret;
}

bool Entity_Player::AddSmeltedTrinket(int trinketID, bool firstTime) {
bool trinketAdded = false;

Expand Down
2 changes: 2 additions & 0 deletions libzhl/LuaCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ namespace lua {
const char* CollectionMenuMT = "CollectionMenu";
const char* ConsoleMT = "Console";
const char* ControllerSelectMenuMT = "ControllerSelectMenu";
const char* CordMT = "Cord";
const char* ColorModifierMT = "ColorModifier";
const char* CustomChallengeMenuMT = "CustomChallengeMenu";
const char* CutscenesMenuMT = "CutscenesMenu";
Expand Down Expand Up @@ -788,6 +789,7 @@ namespace lua {
const char* PlayerManagerMT = "PlayerManager";
const char* PocketItemMT = "PocketItem";
const char* PointMT = "Point";
const char* PointDequeMT = "PointDeque";
const char* ProceduralEffectMT = "ProceduralEffect";
const char* ProceduralItemMT = "ProceduralItem";
const char* ProceduralItemManagerMT = "ProceduralItemManager";
Expand Down
2 changes: 2 additions & 0 deletions libzhl/LuaCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ namespace lua {
extern LIBZHL_API const char* ConsoleMT;
extern LIBZHL_API const char* ControllerSelectMenuMT;
extern LIBZHL_API const char* ColorModifierMT;
extern LIBZHL_API const char* CordMT;
extern LIBZHL_API const char* CustomChallengeMenuMT;
extern LIBZHL_API const char* CutscenesMenuMT;
extern LIBZHL_API const char* GridEntitiesSaveStateVectorMT;
Expand Down Expand Up @@ -223,6 +224,7 @@ namespace lua {
extern LIBZHL_API const char* PlayerManagerMT;
extern LIBZHL_API const char* PocketItemMT;
extern LIBZHL_API const char* PointMT;
extern LIBZHL_API const char* PointDequeMT;
extern LIBZHL_API const char* ProceduralEffectMT;
extern LIBZHL_API const char* ProceduralItemMT;
extern LIBZHL_API const char* ProceduralItemManagerMT;
Expand Down
6 changes: 3 additions & 3 deletions libzhl/functions/BeamRenderer.zhl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void BeamRenderer::End();

// we don't actually use Point here, just a deque, but for some reason
// the deque insists that Point must be defined before BeamRenderer
struct BeamRenderer depends (ANM2, Point) {
struct BeamRenderer depends (ANM2, PointDeque) {
{{
BeamRenderer(ANM2& anm2, unsigned int layer, bool useOverlayData, bool unkBool) : _anm2(anm2), _layer(layer), _useOverlayData(useOverlayData), _unkBool(unkBool) {}

Expand All @@ -25,5 +25,5 @@ struct BeamRenderer depends (ANM2, Point) {
unsigned int _layer : 0x4;
bool _useOverlayData : 0x8;
bool _unkBool : 0x9;
deque_Point _points : 0xc;
} : 0x30;
PointDeque _points : 0xc;
} : 0x20;
1 change: 1 addition & 0 deletions libzhl/functions/Isaac.zhl
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ static __x86_64_output Vector Isaac::GetCollectibleSpawnPosition(Vector* target)
struct Isaac {
{{
LIBZHL_API static bool IsInGame();
LIBZHL_API static Vector * WorldToScreen(Vector * buffer, Vector * pos);
}}
} : 0;
19 changes: 11 additions & 8 deletions libzhl/functions/Point.zhl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"558bec83ec10568bf1f30f1046":
__thiscall void Point::UpdateNormal(Vector* unk);

struct Point depends (Vector) {
{{
Point() : _pos(Vector()), _spritesheetCoordinate(0.0f), _width(1.0f) {}
Point(Vector const& pos, float spritesheetCoordinate, float width) : _pos(pos), _spritesheetCoordinate(spritesheetCoordinate), _width(width) {}
Point() : _pos(Vector()), _lastPos(_pos), _target(nullptr), _spritesheetCoordinate(0.0f), _width(1.0f), _fixed(false) {}
Point(Vector pos, Entity* target, float spritesheetCoordinate, float width, bool fixed) : _pos(pos), _lastPos(pos), _target(target), _spritesheetCoordinate(spritesheetCoordinate), _width(width) , _fixed(fixed) {}
}}
Vector _pos : 0x0;
float _width : 0x8, _spritesheetCoordinate : 0xc;
} : 0x10;
Vector _pos : 0x0, _lastPos : 0x8;
Entity * _target : 0x10;
float _width : 0x14, _spritesheetCoordinate : 0x18;
bool _fixed : 0x1c;
} : 0x20;

struct PointDeque depends (Point) {
deque_Point deque : 0x0;
} : 0x14;
5 changes: 3 additions & 2 deletions libzhl/functions/Room.zhl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ __thiscall float<xmm0> Room::GetTimeScale(Vector* unused, Entity* ent);
"558bec8b55??56578b02":
__thiscall void Room::TriggerEffectRemoved(ItemConfig_Item* item, int unused);

struct Room depends (EntityList, RoomDescriptor, TemporaryEffects, RailManager) {
struct Room depends (EntityList, RoomDescriptor, TemporaryEffects, RailManager, Vector) {
{{
inline Camera* GetCamera() { return *(Camera**)((char*)this + 0x11F8); }
inline bool GetRedHeartDamage() { return *(bool*)((char*)this + 0x120C); }
Expand Down Expand Up @@ -124,7 +124,8 @@ struct Room depends (EntityList, RoomDescriptor, TemporaryEffects, RailManager)
GridEntity* _doors[8] : 0x724;
uint32_t _doorGridPositions[8] : 0x744;
int _roomClearDelay : 0x11ec;
Camera *_Camera : 0x11f8;
Camera *_Camera : 0x11f8; //0x11F8
Vector _renderScrollOffset : 0x1204;
bool _redHeartDamage : 0x120c;
EntityList _entityList : 0x1218;
int _greedWaveTimer : 0x7130;
Expand Down
14 changes: 14 additions & 0 deletions libzhl/functions/Vector2.zhl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ struct Vector { {{
y *= amount;
return *this;
}

Vector& operator+=(const Vector& other)
{
x += other.x;
y += other.y;
return *this;
}

Vector& operator-=(const Vector& other)
{
x -= other.x;
y -= other.y;
return *this;
}
}}
float x : 0x0, y : 0x4;
} : 0x8;
88 changes: 12 additions & 76 deletions repentogon/LuaInterfaces/LuaBeamRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ LUA_FUNCTION(Lua_CreateBeamDummy) {
return 1;
}

void ConstructPoint(lua_State* L, Point& point, uint8_t offset) {
point._pos = *lua::GetUserdata<Vector*>(L, offset, lua::Metatables::VECTOR, "Vector");
point._spritesheetCoordinate = (float)luaL_checknumber(L, offset+1);
point._width = (float)luaL_optnumber(L, offset+2, 1.0f);
}

LUA_FUNCTION(Lua_BeamAdd) {
BeamRenderer* beam = lua::GetUserdata<BeamRenderer*>(L, 1, lua::metatables::BeamMT);
Point point;
Expand All @@ -62,9 +56,11 @@ LUA_FUNCTION(Lua_BeamAdd) {
}
else
{
ConstructPoint(L, point, 2);
point._pos = *lua::GetUserdata<Vector*>(L, 2, lua::Metatables::VECTOR, "Vector");
point._spritesheetCoordinate = (float)luaL_checknumber(L, 3);
point._width = (float)luaL_optnumber(L, 4, 1.0f);
}
beam->_points.push_back(point);
beam->_points.deque.push_back(point);

return 0;
}
Expand All @@ -74,7 +70,7 @@ LUA_FUNCTION(Lua_BeamRender) {
int8_t error = -1;
bool clearPoints = lua::luaL_optboolean(L, 2, true);

if (beam->_points.size() < 2) {
if (beam->_points.deque.size() < 2) {
error = 0;
goto funcEnd;
}
Expand All @@ -99,7 +95,7 @@ LUA_FUNCTION(Lua_BeamRender) {

#pragma warning(suppress:4533)
ColorMod color;
for (auto it = beam->_points.begin(); it != beam->_points.end(); ++it) {
for (auto it = beam->_points.deque.begin(); it != beam->_points.deque.end(); ++it) {
g_BeamRenderer->Add(&it->_pos, &color, it->_width, it->_spritesheetCoordinate);
}

Expand All @@ -109,7 +105,7 @@ LUA_FUNCTION(Lua_BeamRender) {
funcEnd:

if (clearPoints) {
beam->_points.clear();
beam->_points.deque.clear();
}

if (error != -1) {
Expand Down Expand Up @@ -234,10 +230,10 @@ LUA_FUNCTION(Lua_BeamRenderer__gc) {
LUA_FUNCTION(Lua_BeamGetPoints) {
BeamRenderer* beam = lua::GetUserdata<BeamRenderer*>(L, 1, lua::metatables::BeamMT);
lua_newtable(L);
for (size_t i = 0; i < beam->_points.size(); ++i) {
for (size_t i = 0; i < beam->_points.deque.size(); ++i) {
lua_pushinteger(L, i + 1);
Point* ud = (Point*)lua_newuserdata(L, sizeof(Point));
*ud = beam->_points[i];
*ud = beam->_points.deque[i];
luaL_setmetatable(L, lua::metatables::PointMT);
lua_rawset(L, -3);
}
Expand Down Expand Up @@ -266,60 +262,12 @@ LUA_FUNCTION(Lua_BeamSetPoints) {
list.push_back(*lua::GetUserdata<Point*>(L, -1, lua::metatables::PointMT));
lua_pop(L, 1);
}
beam->_points = list;
beam->_points.deque = list;
}

return 0;
}

LUA_FUNCTION(Lua_PointConstructor) {
Point point;
ConstructPoint(L, point, 1);

Point* toLua = lua::place<Point>(L, lua::metatables::PointMT);
*toLua = point;
luaL_setmetatable(L, lua::metatables::PointMT);

return 1;
}

LUA_FUNCTION(Lua_PointGetSpritesheetCoordinate) {
Point* point = lua::GetUserdata<Point*>(L, 1, lua::metatables::PointMT);
lua_pushnumber(L, point->_spritesheetCoordinate);
return 1;
}

LUA_FUNCTION(Lua_PointSetSpritesheetCoordinate) {
Point* point = lua::GetUserdata<Point*>(L, 1, lua::metatables::PointMT);
point->_spritesheetCoordinate = (float)luaL_checknumber(L, 2);
return 0;
}

LUA_FUNCTION(Lua_PointGetWidth) {
Point* point = lua::GetUserdata<Point*>(L, 1, lua::metatables::PointMT);
lua_pushnumber(L, point->_width);
return 1;
}

LUA_FUNCTION(Lua_PointSetWidth) {
Point* point = lua::GetUserdata<Point*>(L, 1, lua::metatables::PointMT);
point->_width = (float)luaL_checknumber(L, 2);
return 0;
}

LUA_FUNCTION(Lua_PointGetPosition) {
Point* point = lua::GetUserdata<Point*>(L, 1, lua::metatables::PointMT);
Vector* toLua = lua::luabridge::UserdataValue<Vector>::place(L, lua::GetMetatableKey(lua::Metatables::VECTOR));
*toLua = point->_pos;
return 1;
}

LUA_FUNCTION(Lua_PointSetPosition) {
Point* point = lua::GetUserdata<Point*>(L, 1, lua::metatables::PointMT);
point->_pos = *lua::GetUserdata<Vector*>(L, 2, lua::Metatables::VECTOR, "Vector");
return 0;
}

static void RegisterBeamRenderer(lua_State* L) {
luaL_Reg functions[] = {
{ "Add", Lua_BeamAdd},
Expand All @@ -334,24 +282,12 @@ static void RegisterBeamRenderer(lua_State* L) {
{ "SetUnkBool", Lua_BeamSetUnkBool},
{ "GetPoints", Lua_BeamGetPoints},
{ "SetPoints", Lua_BeamSetPoints},
{ "GetFixed", Lua_BeamGetPoints},
{ "SetFixed", Lua_BeamSetPoints},
{ NULL, NULL }
};
lua::RegisterNewClass(L, lua::metatables::BeamMT, lua::metatables::BeamMT, functions, Lua_BeamRenderer__gc);
lua_register(L, lua::metatables::BeamMT, Lua_CreateBeamDummy);

luaL_Reg pointFunctions[] = {
{ "GetSpritesheetCoordinate", Lua_PointGetSpritesheetCoordinate},
{ "SetSpritesheetCoordinate", Lua_PointSetSpritesheetCoordinate},
{ "GetHeight", Lua_PointGetSpritesheetCoordinate}, // deprecated
{ "SetHeight", Lua_PointSetSpritesheetCoordinate}, // deprecated
{ "GetWidth", Lua_PointGetWidth},
{ "SetWidth", Lua_PointSetWidth},
{ "GetPosition", Lua_PointGetPosition},
{ "SetPosition", Lua_PointSetPosition},
{ NULL, NULL }
};
lua::RegisterNewClass(L, lua::metatables::PointMT, lua::metatables::PointMT, pointFunctions);
lua_register(L, lua::metatables::PointMT, Lua_PointConstructor);
}

HOOK_METHOD(LuaEngine, RegisterClasses, () -> void) {
Expand Down
Loading