VGMaps

General Boards => Maps In Progress => Topic started by: feos on May 16, 2012, 11:08:04 AM



Title: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos 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)


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ 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?


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: DarkWolf 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...


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos on May 17, 2012, 07:46:55 AM
TerraEsperZ, lol looks like you are living in the Palaeolithic :D
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.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: DarkWolf 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.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ 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.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos 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.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ 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.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos 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 (http://code.google.com/p/gens-rerecording/source/detail?r=277)
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 (http://code.google.com/p/gens-rerecording/source/detail?r=276)
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.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ 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!


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ 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?


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos 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.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ 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 :). I've noticed that you're a contributor on the TASVideos website so hopefully they'd listen to you.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos 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


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ 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 :D

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


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos on June 01, 2012, 05:03:03 PM
I contacted to an experienced person, he told me I can add this feature myself (I don't know C++!). I did it and asked TASVideos admin to apply my patch. He told me I can do it myself too, and counted me in as a committer. Weird, huh? What's more funny, I never player Sonic!


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ on June 02, 2012, 05:15:46 AM
Well, it handles like a dream! You know those times when you don't realize how uncomfortable you are until you change something (shoes, mattress, etc) that suddenly makes your life so much better? This is what I'm feeling right now!

Ah, this is what freedom tastes like :)


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos on September 28, 2013, 11:54:19 AM
http://code.google.com/p/gens-rerecording/downloads/detail?name=Gens11svn.7z

Quote
* Graphics: Added "Pink Background" option and hotkey.
Flag is stored to config.
Color is "Magic pink", r=max, g=0, b=max.

* Graphics: Toggled layers now are saved to config as well.
TODO: Figure out hex value for pink for mode_555.
TODO: Configurable backdrop color (is it needed?)

This freaking toggle now works for any game, even though Sonic or, say, Tiny Toons use not zero color as backdrop. Toggled layers now get remembered between sessions.

Plans: add turbo toggle. add "save screen to clipborad".


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ on September 29, 2013, 09:20:32 PM
That's very good news! Thanks for your efforts in making this a reality.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos on October 06, 2013, 01:26:40 PM
http://gens-rerecording.googlecode.com/files/Gens11svn.zip

 Finally added saving screenshot to clipboard (yay!)
 Finally added ability to remove HUD/messages from screenshots (4 years later):
 determined by Tools -> AVI -> Clean AVI screen.
 Blue Pause effect off by default.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ on October 06, 2013, 02:32:18 PM
AS far as I'm concerned, the only feature missing from Gens-ReRecording to make it the perfect Genesis emulator would be a Map Viewer like in VisualBoy Advance. Unfortunately, that's probably something that would be quite complex to add in and not the sort of feature request I would expect to see fulfilled.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos on May 23, 2014, 10:04:57 AM
After I saw how Genesis nametables look, I disagree that it helps anything in mapping :) It's just a heap of level parts, not so big and completely messed up.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: TerraEsperZ on May 23, 2014, 12:10:24 PM
I don't know if you're equating Nametables with my Map Viewer idea, but such a viewer is always limited to the small portion of the map actually loaded in video memory (please my wrong use of technical terms here) and as you said, parts are not always in order.

It is useful however when there are small areas off-screen (a few tiles in any direction) that you can't reach otherwise, or to capture the actual map's graphic data (even if it's not in order) before various raster effects alter it too much such as per line palette shift and parallax scrolling, effects that more graphically intensive games tend to use a lot.


Title: Re: Position hacking script for Sonic 1, 2, 3 & Knuckles
Post by: feos on May 23, 2014, 01:37:23 PM
The thing is, the latest KMod has this feature. But the build is x64 only so I couldn't even test it out.
http://gendev.spritesmind.net/page-gensK.html