Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add on documentation Scripting API link to github folder #2550

Open
Mte90 opened this issue Jun 9, 2022 · 7 comments
Open

Add on documentation Scripting API link to github folder #2550

Mte90 opened this issue Jun 9, 2022 · 7 comments

Comments

@Mte90
Copy link
Contributor

Mte90 commented Jun 9, 2022

It can be helpful to have as context and resources of this documentation page https://mgba.io/docs/scripting.html a link to https://github.com/mgba-emu/mgba/tree/master/res/scripts

Maybe can be handy also a tiny example as the pokemon.lua is very huge and does too many things, maybe an example like read a variable and change that content is useful to get a more friendly approach and also to lower the learning curve.

@endrift
Copy link
Member

endrift commented Jun 10, 2022

While making resources more visible and accessible is a good idea, I'm unsure what the github folder has to do with it. As far as I can tell, there are a handful of predefined files that go there, and I'm not sure which one is relevant.

@Mte90
Copy link
Contributor Author

Mte90 commented Jun 10, 2022

As it is know that GitHub profile contains the example scripts to instead to point to a specific file it is better to point to the folder that include all of them in the future.

Honestly I don't know if there are other files useful to understand that API in the repo.

@Mte90
Copy link
Contributor Author

Mte90 commented Aug 25, 2022

So I did a tiny lua script for Mario Pinball Land for a talk I will do

function detectGame()
    console:log(emu:getGameTitle())
end

count = 0
function updateBuffer()
    count = count + 1
    -- Wait around 2 seconds
    if count == 120 then
        console:log("Points: " .. emu:read16(0x3005794))
        count = 0
    end
end

callbacks:add("start", detectGame)
callbacks:add("frame", updateBuffer)
if emu then
	detectGame()
end

I was not able to find with the memory view to change those addresses as I think that change the value of those memory address by code so changing doesn't get effect but for a demo is fine.
It is fine a PR to add in the repo? It is a more simple example compared to the one for pokemon.

@Mte90
Copy link
Contributor Author

Mte90 commented Sep 5, 2022

Another tiny script this time to write:

function detectGame()
    console:log(emu:getGameTitle())
end

count = 0
function updateBuffer()
    count = count + 1
    -- Wait around 2 seconds
    if count == 120 then
        -- Unlimited arms point
        console:log('Updating ammo')
        emu:write16(0x02000072, 0xFF)
        count = 0
    end
end

callbacks:add("start", detectGame)
callbacks:add("frame", updateBuffer)
if emu then
	detectGame()
end

This one is for Metal Slug Advance USA version to set unlimited arms points.

@Mte90
Copy link
Contributor Author

Mte90 commented Oct 12, 2022

On my tests seems that without console log the write in memory is not executed with this last script.

Do you want a PR to add those examples in the repository?

@endrift
Copy link
Member

endrift commented Oct 12, 2022

Scripts that don't attempt to detect the specific game, just print it to the log, aren't really what I'd be looking for. But possibly some easy examples for more common games would be good.

@Bunkai9448
Copy link

Hi, I've been thinking on using mGBA's scripting API for help in Reverse Engineering some Japanese exclusive games. And, trying to find samples to get me started with the scripting basics, I found this.

Since you said it could be useful to do a few more easy ones, I wanted to leave the one I created. (I don't know how good or useful it is, but I think it covers the bare minimum).

It takes generic data to get the user use to the options and all, so you don't need a specific game to check (If someone needs a name for double-checking, I used Pokemon - Sapphire Version (USA), with CRC: 554DEDC4)

-- Function Defines

function detectPlatform()
	local getPlatform = emu:platform()

	local UsrBuffer = console:createBuffer("Emulated Console")
	UsrBuffer:print(string.format("Platform: %s\n",getPlatform))
end

function getChecksum()
	local checksum = 0
	for i, v in ipairs({emu:checksum(C.CHECKSUM.CRC32):byte(1, 4)}) do
		checksum = checksum * 256 + v
	end
	local UsrBuffer = console:createBuffer("Data00")
	UsrBuffer:print(string.format("Game Checksum: %s\n",checksum))	-- Decimal Notation
end

function detectGame()
    console:log(emu:getGameTitle()) 
end

function detectGameCode()
    console:log(emu:getGameCode())
end

function bufferSample() 
	local UsrBuffer = console:createBuffer("DataFF")
	UsrBuffer:print("Gotcha!\n")
	UsrBuffer:print("Gotcha_02!\n")
end

function updateBuffer()

end

-- Script stuff (actually doing things with the game)

callbacks:add("start", detectGame)
callbacks:add("frame", updateBuffer)

if emu then
	detectPlatform()
	detectGame()
	detectGameCode()
end

console:log("Previous Save loaded.")

getChecksum()
bufferSample()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants