VGMaps
November 22, 2017, 10:44:26 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1] 2   Go Down
  Print  
Author Topic: Position hacking script for Sonic 1, 2, 3 & Knuckles  (Read 9108 times)
0 Members and 1 Guest are viewing this topic.
feos
Jr. Member
**
Offline Offline

Posts: 65


TASVideos.org


« on: May 16, 2012, 11:08:04 AM »

Script for Gens-rerecording. Here lies the emulator, use version 11b.
http://code.google.com/p/gens-rerecording/downloads/detail?name=Gens11b.zip
Copy the code, paste into a text file, change filename to Sonic-Pos-Hack.lua
Drag the script into emulator window while running any of these 4 games.
Uncommenting a line means removing -- before it. That way emulator would read this line. Use Notepad++ or any other text editor.

Pressing X, Y, Z or Mode you can move Sonic all over the screen. The timer is frozen. Will edit the script, if I can make Sonic invincible all the time.

Code:
-- feos, 2012, for Gens-rr
-- Sonic position hacking for mapping levels
-- May be recorded to emulator movie

emu.registerbefore(function()
keys = input.get()
buttons = joypad.get()

-- Uncomment that if you use Sonic 1
--xAddress, yAddress = 0xFFD008, 0xFFD00C

-- Uncomment that if you use Sonic 2
--xAddress, yAddress = 0xFFB008, 0xFFB00C

-- Uncomment that if you use Sonic 3 & Knuckles
--xAddress, yAddress = 0xFFB010, 0xFFB014

memory.writebyte(0xFFFE25, 50)
x = memory.readword(xAddress)
y = memory.readword(yAddress)
if buttons.X    then memory.writeword(xAddress, x-3) end -- Right
if buttons.Z    then memory.writeword(xAddress, x+3) end -- Left
if buttons.mode then memory.writeword(yAddress, y-3) end -- Up
if buttons.Y    then memory.writeword(yAddress, y+3) end -- Down

-- Color zero layer to pink
p, t=vdp.readpalette(3,1)
c=pal.getcolor(t[1],1)
c.R=255
c.G=0
c.B=255
c.A=255
pal.setcolor(t[1],1,c)
vdp.writepalette(3,t[1])
end)
« Last Edit: May 28, 2012, 08:47:01 PM by feos » Logged

TerraEsperZ
Hero Member
*****
Offline Offline

Posts: 2225



« Reply #1 on: May 16, 2012, 06:28:50 PM »

I doubt I'll ever have the time or interest to actually ever map Sonic 2, 3 and Knuckles (though I do retain hope of finishing Sonic 1 someday) but it's nice to have this script around. However, for mapping purposes, Gens-rerecording is far from ideal since the last I checked, it didn't have the ability to turn on and off graphical layers. Actually feos, didn't you actually ask something about having the functionalities of Gens Kmod integrated in Gens-rr some time ago? Did the Gens-rr team ever got back to you about that?
Logged

Current project that I really should try to finish:
-Drill Dozer (GBA)
-Sonic 3D Blast (Genesis)
-Naya's Quest (PC)
-Lilly Looking Through (PC)

Pending project:
-A ton of stuff that will never be finished
DarkWolf
Hero Member
*****
Offline Offline

Posts: 621



« Reply #2 on: May 17, 2012, 07:05:41 AM »

If you have access to enough of the Genesis' components via the lua interface, you might be able to dump layers or sprites via scripting instead.  Hell if it's robust enough you might even have lua do stitching for you...
Logged
feos
Jr. Member
**
Offline Offline

Posts: 65


TASVideos.org


« Reply #3 on: May 17, 2012, 07:46:55 AM »

TerraEsperZ, lol looks like you are living in the Palaeolithic Cheesy
All latest revisions of Gens-rr (just use my link above) allow to switch off any layer, swap layers, show sprites above everithing. That's how I record a movie, switch off layers 1 and 3, dump avi from that movie, feed it to screenshotautostitcher, fix flaws. Then I leave layer 1 only and dump canvas map. I only couldn't color the zero layer to pink, it is still blue in Sonic.

And working with layers is not only impossible in lua, but it even allows no hotkeys. Gens-rr is kinda forbidden by dev. I asked about adding some Kmod stuff, but ended up with that script for zero layer, it was the only thing really lacking in Gens-rr.

Code:
p,t=vdp.readpalette(1,1)
c=pal.getcolor(t[1],1)
c.R=255
c.G=0
c.B=255
c.A=255
pal.setcolor(t[1],1,c)
vdp.writepalette(1,t[1])

I added it to main script.
Logged

DarkWolf
Hero Member
*****
Offline Offline

Posts: 621



« Reply #4 on: May 17, 2012, 08:58:10 AM »

I don't mean toggling layers, I mean like reading a tile map or the sprite table then assembling an image or data structure based on that.  Lua supports disk i/o, so you could theoretically dump lots of useful information.

Do you know if there is any more detailed documentation?  Your script uses what appears to be a global table called vdp, but it isn't listed in the lua doc that comes with the emulator.
Logged
TerraEsperZ
Hero Member
*****
Offline Offline

Posts: 2225



« Reply #5 on: May 17, 2012, 09:50:02 AM »

Well in my defense, I haven't been following the emulation scene that closely for the last few years. I just got tired to switching from one leading emulator for a system to the next big one, then having to repeat the process a few years later which made all my previous savestates irrelevant. And yeah, I realize that makes me an old fart since I've been emulating the Genesis for over 15 years, using respectively Genecyst, then KGen and finally Gens with KMod.

I'll give Gens-rr a look but I hope they haven't changed the way colors are rendered since basic Gens because I really don't want newer maps to have slightly different colors from my old ones.
Logged

Current project that I really should try to finish:
-Drill Dozer (GBA)
-Sonic 3D Blast (Genesis)
-Naya's Quest (PC)
-Lilly Looking Through (PC)

Pending project:
-A ton of stuff that will never be finished
feos
Jr. Member
**
Offline Offline

Posts: 65


TASVideos.org


« Reply #6 on: May 17, 2012, 09:51:02 AM »

The Russian guy who gave me that unique script seemed to be reading from source codes, a.k.a. lua engine of gens-rr.
http://www.emu-land.net/forum/index.php/topic,34000.msg697761.html#msg697761
VDP handling was added in version 11b only. I doubt hacking the ROM to pull out maps would be easier than my flying around.
Logged

TerraEsperZ
Hero Member
*****
Offline Offline

Posts: 2225



« Reply #7 on: May 27, 2012, 12:27:24 PM »

Well I've resolved to try and finish mapping the first Sonic the Hedgehog game, and in the spirit of this, I'm looking for more information about the recent lua commands you posted. I can't find anything online about the vdp functions and their parameters so there's no way at the moment to try and find out why the background color can't be changed in Sonic (I haven't tried in other games). I'm also really disappointed that there's no way to enable/disable layers with hot keys.
Logged

Current project that I really should try to finish:
-Drill Dozer (GBA)
-Sonic 3D Blast (Genesis)
-Naya's Quest (PC)
-Lilly Looking Through (PC)

Pending project:
-A ton of stuff that will never be finished
feos
Jr. Member
**
Offline Offline

Posts: 65


TASVideos.org


« Reply #8 on: May 28, 2012, 07:31:55 AM »

http://code.google.com/p/gens-rerecording/issues/detail?id=64
http://code.google.com/p/gens-rerecording/source/browse/trunk/+gens-rerecording/Gens/luascript.cpp

Quote from: Revision 277 log
implemented new lua functions vdp.readpalette([line][,count]), vdp.writepaletteline([line,]palettedata), palette.new(), palette.getcolor(palette,index), palette.setcolor(palette,index,color), palette.rawdata(palette), and memory.writebyterange(address,[length,]data)

Quote from: Revision 276 log
implemented vdp.writecell lua function, takes address and a vdp cell or table of vdp cells, returns number successfully written, changed return format of vdp.readcell, now returns a lua_integer number of successfully read cells and a table of userdata vdp cells, instead of a table of tables of pixel values, with index 0 as the number of successfully read cells.
« Last Edit: May 28, 2012, 07:46:30 AM by feos » Logged

TerraEsperZ
Hero Member
*****
Offline Offline

Posts: 2225



« Reply #9 on: May 28, 2012, 05:47:18 PM »

I'm still not sure about the variable types returned by the vdp functions, but I've at least found why your code for the pink background didn't work; we weren't manipulating the correct palette line.

Code:
while true do

-- Color zero layer to pink
p, t=vdp.readpalette(3,1)
c=pal.getcolor(t[1],1)
c.R=255
c.G=0
c.B=255
c.A=255
pal.setcolor(t[1],1,c)
vdp.writepalette(3,t[1])

emu.frameadvance()
end

Since I'm using the game's built-in Debug mode to move around, the rest of your script isn't as useful to me, especially since by moving Sonic around, you still have to deal with all the collisions. From what little I've found on the subject, the first Sonic game doesn't seem to have camera coordinates that are separate from Sonic's position, unlike the other Genesis games. At least I hope so...

I'm still trying to determine if there's a timer that controls all the moving objects like in the Sonic Advance series. I've found several variables that act like counters but freezing them doesn't seem to affect platforms so far.

By the way feos, thanks for selling Gens-Rerecording to me! Even though I'm a bit angry that it renders the colors a bit differently than the old Gens (which might necessitates me to re-do some maps that are already done), the simple fact that it renders everything in 32 bits colors instead of forcing the desktop in 16 bits colors means that I don't have to exit the emulator everything I want to actually paste a screenshot in my paint program which is a big time saver!
Logged

Current project that I really should try to finish:
-Drill Dozer (GBA)
-Sonic 3D Blast (Genesis)
-Naya's Quest (PC)
-Lilly Looking Through (PC)

Pending project:
-A ton of stuff that will never be finished
TerraEsperZ
Hero Member
*****
Offline Offline

Posts: 2225



« Reply #10 on: May 31, 2012, 06:59:40 PM »

Unfortunately, Gens-Rerecording is brought down pretty hard by one simple omission: not being able to bind keyboard shorcuts to enable or disable the various graphic layers. The simple fact that you have to go through 2 levels of menu just to do that means that it's actually worse to capture screenshots that regular Gens. The Gens-Rerecording source code page seems to have been last updated in 2009 so I'm not sure if asking for that option will lead to anything. Why did they not include those commands to bind shortcuts to when everything else is?
Logged

Current project that I really should try to finish:
-Drill Dozer (GBA)
-Sonic 3D Blast (Genesis)
-Naya's Quest (PC)
-Lilly Looking Through (PC)

Pending project:
-A ton of stuff that will never be finished
feos
Jr. Member
**
Offline Offline

Posts: 65


TASVideos.org


« Reply #11 on: June 01, 2012, 06:32:29 AM »

Why would you need to switch layers so often? I thought one makes the main layer map, then the parallax, then adds sprites. I can try falling on my knees begging someone to add this feature, but I need the answer about reason for the one who potentially can code it. Those coders guys tend to doubt about the weight of our reasons.
Logged

TerraEsperZ
Hero Member
*****
Offline Offline

Posts: 2225



« Reply #12 on: June 01, 2012, 10:04:42 AM »

I'm sorry if I came off as whiny or entitled. It's just that it's frustrating to discover a tool that works so well in every respect *except* in that one particular way that could so easily be fixed. It wouldn't even be a big change and require much coding. You can already do what I'm asking through the menus, and you can bind keyboard shortcuts to almost every menu commands. It should just be a matter of adding the "Enable" command for the separate layers in the keyboard shorcut list.

As for why I need that, well... Turning on and off the foreground is important in order to capture sprites alone for reference, and turning on and off the sprites is important to capture the foreground alone. And finally, turning on and off the background is useful if you want to see how it moves or is aligned compared to the foreground for later placement in your map. Also, sometimes it's not easy to figure out if something is part of the foreground, background or is a sprite, and switching quickly is the easiest way to see the difference. Considering the huge list of commands you can bind shortcuts to, the lack of layer control is puzzling if intentional, but I'd rather think it was simply forgotten when layer control was added in the emulator.

If you have any pull with the Gens-Rerecording people, I'd of course greatly appreciate you asking them for this Smiley. I've noticed that you're a contributor on the TASVideos website so hopefully they'd listen to you.
Logged

Current project that I really should try to finish:
-Drill Dozer (GBA)
-Sonic 3D Blast (Genesis)
-Naya's Quest (PC)
-Lilly Looking Through (PC)

Pending project:
-A ton of stuff that will never be finished
feos
Jr. Member
**
Offline Offline

Posts: 65


TASVideos.org


« Reply #13 on: June 01, 2012, 04:26:56 PM »

There you go. Default hotkeys for layers are Ctrl+F1 (Scroll A), Ctrl+F2 (Scroll B), Ctrl+F3 (Sprites). Will think about inbulit zero layer color switch.
http://code.google.com/p/gens-rerecording/downloads/detail?name=Gens11svn.zip
« Last Edit: October 20, 2013, 02:12:24 AM by feos » Logged

TerraEsperZ
Hero Member
*****
Offline Offline

Posts: 2225



« Reply #14 on: June 01, 2012, 04:54:21 PM »

feos...

Thank you, thank you, THANK YOU!!!

I was hoping to maybe see my request granted at best after several weeks seeing as the emulator doesn't seem to be actively worked on anymore. But practically on the same day? You just made my Genesis mapping so much easier Cheesy

You can bet that I'm starting this the moment I get home in an hour!
Logged

Current project that I really should try to finish:
-Drill Dozer (GBA)
-Sonic 3D Blast (Genesis)
-Naya's Quest (PC)
-Lilly Looking Through (PC)

Pending project:
-A ton of stuff that will never be finished
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!