Skip to content

Commit

Permalink
Some more work
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinW1998 committed Oct 14, 2014
1 parent 99acd17 commit 5afb410
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 13 deletions.
66 changes: 66 additions & 0 deletions HelpLua/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,24 @@ <h1>LunaDll for Lua Tutorial/Reference</h1><br /><br />
</div></td>
<td>Gets a specfic value by NPC offset-address. See constants for datatypes.</td>
</tr>
<tr>
<td><div class="code">
<p>myNPC:kill()</p>
</div></td>
<td>Kills the npc with the standard kill animation.</td>
</tr>
<tr>
<td><div class="code">
<p>myNPC:kill([int] killanimation)</p>
</div></td>
<td><p>Kills the npc with the kill animation of your choice.</p>
<p>Known ids are:</p>
<p>1 - Standard kill animation</p>
<p>6 - Lava kill</p>
<p>8 - Spin jump kill</p>
<p>9 - dissapear (no animation)</p>
<p>10 - Link kill (like link would kill this npc)</p></td>
</tr>
<tr>
<td colspan="2"><p>This class provides fields and functions to modify the npc. It is <strong>not recommended</strong> to save this class for later, as the internal arrayindex changes when enemies get killed. </p></tr>
</table>
Expand Down Expand Up @@ -591,6 +609,54 @@ <h1>LunaDll for Lua Tutorial/Reference</h1><br /><br />
</div></td>
<td>Places a image/sprite by resource-number imgResource at xPos, yPos. Extra string data field provided. Leave a empty string if not used. You can set the time if needed.</td>
</tr>
<tr>
<td height="25"><div class="code">
<p>[int] gravity()</p>
</div></td>
<td>Returns the gravity in this level. 12 = Default</td>
</tr>
<tr>
<td height="25"><div class="code">
<p>gravity([int] value)</p>
</div></td>
<td>Sets the gravity in this level. 12 = Default</td>
</tr>
<tr>
<td height="25"><div class="code">
<p>[int] earthquake()</p>
</div></td>
<td>Returns the earthquake-effect in this level. 0 = No earth quake. Resets to 0 after a time. Higher number = Higher earthquake-effect.</td>
</tr>
<tr>
<td height="25"><div class="code">
<p>earthquake([int] value)</p>
</div></td>
<td>Sets the earthquake-effect in this level. 0 = No earth quake. Resets to 0 after a time. Higher number = Higher earthquake-effect.</td>
</tr>
<tr>
<td height="25"><div class="code">
<p>[int] jumpheight()</p>
</div></td>
<td>Returns the jumpheight-factor of every character. 20 = Default</td>
</tr>
<tr>
<td height="25"><div class="code">
<p>jumpheight([int] value)</p>
</div></td>
<td>Sets the jumpheight-factor of every character. 20 = Default</td>
</tr>
<tr>
<td height="25"><div class="code">
<p>[int] jumpheightBounce()</p>
</div></td>
<td>Returns the jumpheight-factor (when bounced off from a npc) of every character. 20 = Default</td>
</tr>
<tr>
<td height="25"><div class="code">
<p>jumpheightBounce([int] value)</p>
</div></td>
<td>Sets the jumpheight-factor (when bounced off from a npc) of every character. 20 = Default</td>
</tr>
</table>
<p>&nbsp;</p>
<table width="100%" border="1">
Expand Down
10 changes: 10 additions & 0 deletions LunaDll/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ enum PRIORITY {
#define GM_NPCS_PTR *(DWORD*)0x00B259E8 // +0xAD58 + 0x20 to NPCs
#define GM_NPCS_COUNT *(WORD*)0x00B2595A
#define GM_PLAYERS_PTR *(DWORD*)0x00B25A20
#define GM_PLAYERS_COUNT *(WORD*)0x00B2595E;
#define GM_EDIT_PLAYERS_PTR *(DWORD*)0x00CF74D8 // Editor Template player

// HUD stuff
#define GM_STAR_COUNT *(DWORD*)0x00B251E0
Expand All @@ -68,6 +70,7 @@ enum PRIORITY {
// States
#define GM_FREEZWITCH_ACTIV *(WORD*)0x00B2C8B4
#define GM_PAUSE_OPEN *(WORD*)0x00B250E2
#define GM_CUR_MENUCHOICE *(WORD*)0x00B2C880 // Current menu choice

// Camera
#define GM_CAMERA_X *(DWORD*)0x00B2B984
Expand Down Expand Up @@ -111,16 +114,23 @@ enum PRIORITY {

// Cheats
#define GM_PLAYER_INVULN *(WORD*)0x00B2C8C0 // 0xFFFF = invuln
#define GM_PLAYER_INFJUMP *(WORD*)0x00B2C8AC // 0xFFFF = infinite jumps
#define GM_CHEATED *(WORD*)0x00B2C8C4 // 0xFFFF = cheated

// Miscs
#define GM_GRAVITY *(WORD*)0x00B2C6F4 // 12 = default, 0 = non-falling
#define GM_JUMPHIGHT *(WORD*)0x00B2C6DC // 20 = default, higher number = higher jumps
#define GM_JUMPHIGHT_BOUNCE *(WORD*)0x00B2C6E2 // Same as normal jumphight, but from NPC
#define GM_EARTHQUAKE *(WORD*)0x00B250AC // 0 = default, higher number = bigger shaking, slowly resets to 0

#define GM_MARIO_VS_LUIGI_T *(WORD*)0x00B2D760 // 0 = default, if higher than 0 then display text "Mario VS Luigi"
#define GM_WINS_T *(WORD*)0x00B2D762 // 0 = default, if higher than 0 then display text "WINS!"

#define GM_WINNING *(WORD*)0x00B2C59E // 0 = not winning, if higher than 0 then winning by this win-type
#define GM_LEAVE_LEVEL *(WORD*)0x00B2C5B4 // 0xFFFF = leave current level

#define GM_UNK_OV_DATABLOCK *(DWORD*)0x00B25164 // Pointer to some kind of overworld data block involving locked character selection (not 100% sure)

//Hitbox
#define GM_HITBOX_H_PTR *(WORD*)0x00B2C6FC // player hitbox height for each character/power-up state (starts with small mario through small link, then cycles same way through each power up)
#define GM_HITBOX_H_D_PTR *(WORD*)0x00B2C742 // hitbox heights while ducking
Expand Down
102 changes: 102 additions & 0 deletions LunaDll/LuaMain/LuaProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../Level.h"
#include "../CSprite.h"
#include "../CSpriteManager.h"
#include "../Blocks.h"



Expand Down Expand Up @@ -292,6 +293,20 @@ void LuaProxy::NPC::mem(int offset, LuaProxy::L_FIELDTYPE ftype, luabind::object
}
}

void LuaProxy::NPC::kill()
{
NPCMOB* mnpc = ::NPC::Get(m_index);
void* ptr = ((&(*(byte*)mnpc)) + 290);
MemAssign((int)ptr, 1.0, OP_Assign, (FIELDTYPE)FT_WORD);
}

void LuaProxy::NPC::kill(int killEffectID)
{
NPCMOB* mnpc = ::NPC::Get(m_index);
void* ptr = ((&(*(byte*)mnpc)) + 290);
MemAssign((int)ptr, (double)killEffectID, OP_Assign, (FIELDTYPE)FT_WORD);
}

luabind::object LuaProxy::NPC::mem(int offset, LuaProxy::L_FIELDTYPE ftype, lua_State* L)
{
int iftype = (int)ftype;
Expand Down Expand Up @@ -1861,3 +1876,90 @@ void LuaProxy::Player::setUnused184(short var_unused184)
}

/* Generated by code! [END]*/


unsigned short LuaProxy::gravity()
{
return GM_GRAVITY;
}


void LuaProxy::gravity(unsigned short value)
{
GM_GRAVITY = value;
}


unsigned short LuaProxy::earthquake()
{
return GM_EARTHQUAKE;
}


void LuaProxy::earthquake(unsigned short value)
{
GM_EARTHQUAKE = value;
}


unsigned short LuaProxy::jumpheight()
{
return GM_JUMPHIGHT;
}


void LuaProxy::jumpheight(unsigned short value)
{
GM_JUMPHIGHT = value;
}


unsigned short LuaProxy::jumpheightBounce()
{
return GM_JUMPHIGHT_BOUNCE;
}


void LuaProxy::jumpheightBounce(unsigned short value)
{
GM_JUMPHIGHT_BOUNCE = value;
}


LuaProxy::Block::Block(int index) : m_index(index)
{}

void LuaProxy::Block::mem(int offset, LuaProxy::L_FIELDTYPE ftype, luabind::object value)
{
int iftype = (int)ftype;
if(iftype >= 1 && iftype <= 5){
::Block* pBlock = &::Blocks::GetBase()[m_index];
void* ptr = ((&(*(byte*)pBlock)) + offset);
MemAssign((int)ptr, luabind::object_cast<double>(value), OP_Assign, (FIELDTYPE)ftype);
}
}

luabind::object LuaProxy::Block::mem(int offset, LuaProxy::L_FIELDTYPE ftype, lua_State *L)
{
int iftype = (int)ftype;
double val = 0;
if(iftype >= 1 && iftype <= 5){
::Block* pBlock = &::Blocks::GetBase()[m_index];
void* ptr = ((&(*(byte*)pBlock)) + offset);
val = GetMem((int)ptr, (FIELDTYPE)ftype);
}
switch (ftype) {
case LFT_BYTE:
return luabind::object(L, (byte)val);
case LFT_WORD:
return luabind::object(L, (short)val);
case LFT_DWORD:
return luabind::object(L, (int)val);
case LFT_FLOAT:
return luabind::object(L, (float)val);
case LFT_DFLOAT:
return luabind::object(L, (double)val);
default:
return luabind::object();
}
}
21 changes: 21 additions & 0 deletions LunaDll/LuaMain/LuaProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ namespace LuaProxy {
void placeSprite(int type, int imgResource, int xPos, int yPos, const char* extra, int time);
void placeSprite(int type, int imgResource, int xPos, int yPos, const char* extra);
void placeSprite(int type, int imgResource, int xPos, int yPos);
unsigned short gravity();
void gravity(unsigned short value);
unsigned short earthquake();
void earthquake(unsigned short value);
unsigned short jumpheight();
void jumpheight(unsigned short value);
unsigned short jumpheightBounce();
void jumpheightBounce(unsigned short value);


namespace SaveBankProxy {
void setValue(const char* key, double value);
Expand Down Expand Up @@ -100,6 +109,8 @@ namespace LuaProxy {
double speedY();
void setSpeedY(double speedY);
void mem(int offset, L_FIELDTYPE ftype, luabind::object value);
void kill();
void kill(int killEffectID);
luabind::object mem(int offset, L_FIELDTYPE ftype, lua_State* L);
private:
bool isValid();
Expand Down Expand Up @@ -383,4 +394,14 @@ namespace LuaProxy {
};


class Block
{
public:
Block(int index);
void mem(int offset, L_FIELDTYPE ftype, luabind::object value);
luabind::object mem(int offset, L_FIELDTYPE ftype, lua_State* L);
private:
int m_index;
};

}
67 changes: 58 additions & 9 deletions LunaDll/LuaMain/LunaLuaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../Level.h"
#include "../MiscFuncs.h"
#include "../PlayerMOB.h"
#include "../NPCs.h"

#include "LuaHelper.h"
#include "LuaProxy.h"
Expand Down Expand Up @@ -166,6 +167,15 @@ void LunaLua::initCodeFile(lua_State *&L, wstring main_path, wstring lapi_path,
def("placeSprite", (void(*)(int, int, int, int, const char*, int))&LuaProxy::placeSprite),
def("placeSprite", (void(*)(int, int, int, int, const char*))&LuaProxy::placeSprite),
def("placeSprite", (void(*)(int, int, int, int))&LuaProxy::placeSprite),
def("gravity", (unsigned short(*)())&LuaProxy::gravity),
def("gravity", (void(*)(unsigned short))&LuaProxy::gravity),
def("earthquake", (unsigned short(*)())&LuaProxy::earthquake),
def("earthquake", (void(*)(unsigned short))&LuaProxy::earthquake),
def("jumpheight", (unsigned short(*)())&LuaProxy::jumpheight),
def("jumpheight", (void(*)(unsigned short))&LuaProxy::jumpheight),
def("jumpheightBounce", (unsigned short(*)())&LuaProxy::jumpheightBounce),
def("jumpheightBounce", (void(*)(unsigned short))&LuaProxy::jumpheightBounce),


namespace_("UserData")[
def("setValue", &LuaProxy::SaveBankProxy::setValue),
Expand Down Expand Up @@ -195,6 +205,8 @@ void LunaLua::initCodeFile(lua_State *&L, wstring main_path, wstring lapi_path,
.def(constructor<int>())
.def("mem", static_cast<void (LuaProxy::NPC::*)(int, LuaProxy::L_FIELDTYPE, luabind::object)>(&LuaProxy::NPC::mem))
.def("mem", static_cast<luabind::object (LuaProxy::NPC::*)(int, LuaProxy::L_FIELDTYPE, lua_State*)>(&LuaProxy::NPC::mem))
.def("kill", static_cast<void (LuaProxy::NPC::*)()>(&LuaProxy::NPC::kill))
.def("kill", static_cast<void (LuaProxy::NPC::*)(int)>(&LuaProxy::NPC::kill))
.property("id", &LuaProxy::NPC::id)
.property("direction", &LuaProxy::NPC::direction, &LuaProxy::NPC::setDirection)
.property("x", &LuaProxy::NPC::x, &LuaProxy::NPC::setX)
Expand Down Expand Up @@ -343,8 +355,12 @@ void LunaLua::initCodeFile(lua_State *&L, wstring main_path, wstring lapi_path,
.property("Unused17E", &LuaProxy::Player::unused17E, &LuaProxy::Player::setUnused17E)
.property("Unused180", &LuaProxy::Player::unused180, &LuaProxy::Player::setUnused180)
.property("Unused182", &LuaProxy::Player::unused182, &LuaProxy::Player::setUnused182)
.property("Unused184", &LuaProxy::Player::unused184, &LuaProxy::Player::setUnused184)
.property("Unused184", &LuaProxy::Player::unused184, &LuaProxy::Player::setUnused184),

class_<LuaProxy::Block>("Block")
.def(constructor<int>())
.def("mem", static_cast<void (LuaProxy::Block::*)(int, LuaProxy::L_FIELDTYPE, luabind::object)>(&LuaProxy::Block::mem))
.def("mem", static_cast<luabind::object (LuaProxy::Block::*)(int, LuaProxy::L_FIELDTYPE, lua_State*)>(&LuaProxy::Block::mem))
];

_G["player"] = new LuaProxy::Player();
Expand Down Expand Up @@ -457,18 +473,51 @@ void LunaLua::DoCodeFile(lua_State *L)
}

//debug stuff
//int cCounter = 0;
#define __DEBUG_IDA 0

#if __DEBUG_IDA
/*int cCounter = 0;
struct debugXYStruct{
double x;
double y;
};*/

#endif


void LunaLua::Do()
{
//debug stuff
// cCounter++;
// if(cCounter % 100 == 0){
// typedef int coinfunc(void);
// coinfunc* f = (coinfunc*)0x00A3C580;
// f();
// }

#if __DEBUG_IDA
//cCounter++;
//NPCMOB* mNPC = NPC::GetFirstMatch(-1,-1);
//if(cCounter % 600 == 0){
/*typedef int somefunc();
somefunc* f = (somefunc*)0x00A621A0;
f();
PlayerMOB* mPlayer = Player::Get(1);
typedef int somecoinfunc(int, int, int, int, int);
int a = 3;
int b = 1;
int c = 0;
int d = 0;
somecoinfunc* f = (somecoinfunc*)0x009E7380;
debugXYStruct debg;
debg.x = mPlayer->CurXPos;
debg.y = mPlayer->CurYPos;
f((int)&a,(int)&debg,(int)&b,(int)&c,(int)&d);
mNPC->Ypos = mNPC->Ypos - 32.0;
a = 11;
b = 1065353216;
f((int)&a,(int)&mNPC->Xpos,(int)&b,(int)&c,(int)&d);
*(WORD*)((&(*(byte*)mNPC)) + 290) = 1;
//f((int)&a,(int)&mNPC->Xpos,(int)&b,(int)&c,(int)&d);*/
//}
#endif

PlayerMOB* demo = Player::Get(1);
if(demo == 0)
Expand Down
Loading

0 comments on commit 5afb410

Please sign in to comment.