Posts for Warepire

Post subject: LUA assistance needed, calculating angles.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
I am kinda new at LUA scripting, and I cannot figure out why my angle math isn't working. I would appreciate some help. The script is for Bugs Bunny Lost In Time on PSX, gameID SLUS-00838. The game maps the word so that 0,0,0 is in a corner, so I cannot rely on the position to get a proper angle, I figured using the speed values would also work, but it seems that it doesn't, because according to that, I never steer away more than 3 degrees from "straight forward". Can someone please explain what I am doing wrong? Script:
Language: lua

--position, speed and direction local Xpos local XposOld = 0 local Ypos local YposOld = 0 local Zpos local ZposOld = 0 local Xspeed = 0 local Yspeed = 0 local Zspeed = 0 --not really a need to look at Y-speed as it seems to be independent of XZ speed, might still be useful for jumping. local XZspeed local XZdirection = 0 --stats local health local inlvlCarrots local inlvlGoldenCarrots local inlvlClocks local inlvlACME local totalCarrots local totalGoldenCarrots local totalClocks local abilities local jump = false local music = false local sesame = false local fan = false local function hud() --Actual speed vector addresses, not very good as they show speed even when you're blocked by a wall etc. --addr 00069D30 X Speed [signed word] --addr 00069D34 Y Speed(?) [signed word] --addr 00069D38 Z Speed [signed word] Xpos = memory.readdwordsigned(0x00069DC0) Ypos = memory.readdwordsigned(0x00069DC4) Zpos = memory.readdwordsigned(0x00069DC8) --will not show the proper speed on the first frame of a level --the game only runs at 30 fps. local tempXspeed = Xpos - XposOld local tempYspeed = Ypos - YposOld local tempZspeed = Zpos - ZposOld local tempXZdirection = math.atan2(tempZspeed, tempXspeed) if tempXspeed ~= 0 or tempYspeed ~= 0 or tempZspeed ~= 0 then Xspeed = math.abs(tempXspeed) Yspeed = math.abs(tempYspeed) Zspeed = math.abs(tempZspeed) XZdirection = tempXZdirection end XZspeed = math.sqrt(Xspeed*Xspeed + Zspeed*Zspeed) health = memory.readbyte(0x00010041) inlvlCarrots = memory.readbyte(0x00069525) inlvlGoldenCarrots = memory.readbyte(0x00069574) inlvlClocks = memory.readbyte(0x00069514) inlvlACME = memory.readbyte(0x00010044) totalCarrots = memory.readbyte(0x00010043) totalGoldenCarrots = (memory.readbyte(0x0001013C)*256) + memory.readbyte(0x00010047) --addr 0x0001013C is a roll-over counter for addr 0x00010047 totalClocks = memory.readbyte(0x00010045) abilities = memory.readbyte(0x00010048) --0x08 == SuperJump if abilities >= 0x08 then jump = true abilities = abilities - 0x08 end -- TODO: Get the flags for the rest of the abilities gui.opacity(1.0) gui.text(0,0,string.format("Pos (%6d,%6d,%6d)\n",Xpos,Ypos,Zpos) ..string.format("Speed XZ: %3d Angle: %3d\n",XZspeed,XZdirection) ..string.format("Speed Y: %3d\n\n",Yspeed) ..string.format("Health: %d\n",health) ..string.format("Carrots: %d\n",totalCarrots) ..string.format("LVL Golden: %2d Total Golden: %3d\n",inlvlGoldenCarrots,totalGoldenCarrots) ..string.format("LVL Clocks: %2d Total Clocks: %3d\n",inlvlClocks,totalClocks) ..string.format("ACME boxes: %d\n\n",inlvlACME) ..string.format("Jump: %s\n",tostring(jump)) ..string.format("Music: %s\n",tostring(music)) ..string.format("Sesame: %s\n",tostring(sesame)) ..string.format("Fan: %s\n",tostring(fan))) XposOld = Xpos YposOld = Ypos ZposOld = Zpos end gui.register(hud)
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Open with Args - Lets you right-click any exe and provide switches to it without having to open cmd first. Very useful. Universal Extractor - Saved my ass many times when it comes to obscure archive formats and failing installers.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Replying backward for great justice: .sey etov I ,gniniatretne ylgnisirprus saw tahT
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Nice finding the flag for area-type, I failed to when I tried, a hint is that it's unsigned, the values will make more sense to you if you read it as unsigned. The speed value of the Wakeboard is actually a dword (readdwordsigned), you might be able to read it as a byte... but then remove the "signed". This is how you get the atlas sphere velocity in the direction you're going:
Language: LUA

local AtlasVelocity = math.abs(memory.readdwordsigned(0x02002544)) + math.abs(memory.readdwordsigned(0x02002548))
The abs function in the math library (included by default in the lua engine) removes the signs making the value positive always. For Y velocity, that is the only address I found that increases and decreases "properly" when you jump. Also, when programming, use tabs to change the "depth" of things. Example using your code:
-- SPEED AND/OR PIXEL POS.
if area == 1 then -- Normal
	gui.text(8,38," SpeedX: " .. memory.readbytesigned(0x02015059),"orange")
	gui.text(8,30," PixelX: " .. memory.readshort(0x02014FD9),"orange")
else if area == 2 then -- Bonus
	gui.text(8,38," SpeedX: " .. memory.readbytesigned(0x02015471),"#CCFF33")
	gui.text(8,30," PixelX: " .. memory.readshort(0x020153F1),"#CCFF33")
else if area == 51 then -- Wakeboard
	gui.text(1,112,"Speed -43/" .. memory.readbytesigned(0x02000F44),"#CC99CC")
end end end
It increases readability of the code tenfold. Final tip for now: The usermovies allow uploading of watches and lua scripts.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
I would say that the text speed is one of the biggest hits on entertainment value in the published run, so I am all for a version change to JP in that regard. The easier fights on the other hand will make it less impressive. Tough choice. I did mean the Critical Sword, good that you realized that. The crits do work when just holding the sword, there's at least one instance of that happening in the published TAS. If the crits of the Critical Sword can be manipulated, it might still be worth collecting if it isn't too off route. It all depends on how difficult it is to manipulate Gems as the Critical Sword is the most useful after getting the Lucky Blade if I recall correctly. (Meaning that Lucky Blade will never be equipped).
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Now I need to figure out how to run lsnes so I can watch this. (unless someone makes an encode). The Japanese version has some differences compared to the US/European, one being that there is no conveyor belt in the middle section fighting the monster in Leo's painting. Everhate is speedrunning this game, he speaks about the JP vs US differences during this attempt: http://www.twitch.tv/everhate/c/3333865 Here's hes current PB: http://www.twitch.tv/everhate/c/3342748 Something I was thinking about is in a TAS if it could be worth switching back to the Psycho Blade for the Poseidon fight. Manipulating critical hits on him should make him go down faster than with the Lucky Blade, despite the Psycho Blade being weaker. What I am not sure of is if the extra weapon switches save time, or if through luck manipulation with both gems and crits it doesn't need to be equipped at all. I want to remember beating the game without even collecting the Lucky Blade once, but there seems to be a flag that gets set when you have that Blade, and if you don't have that Blade you cannot talk to a certain NPC (forgot which) needed to advance the story.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
I still have a watch file for Crash Bandicoot N-Tranced Here's all the speed addresses except for the space-fly levels:
0x02015058 dword signed X Velocity (not bonus)
0x0201505C dword signed Y Velocity (not bonus)
0x02015064 dword signed X Position (not bonus)
0x02015068 dword signed Y Position (not bonus)
0x02015470 dword signed X Velocity (bonus)
0x02015474 dword signed Y Velocity (bonus)
0x0201547C dword signed X Position (bonus)
0x02015480 dword signed Y Position (bonus)
0x02002544 dword signed Atlas sphere speed 1
0x02002548 dword signed Atlas sphere speed 2
0x02000F44 dword signed Wakeboard speed
To get speed in the direction you're going with the Atlas sphere, you need to take the abs of the numbers, and then add them together. Top speed is 1024. What would be really useful is a hitbox viewer for the Wakeboard levels, it's close to impossible to make it entertaining otherwise without losing the top speed.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Thanks for the compiled list jlun2, knew some, others not. Added all of them to the list except "Syobon Action would fail to start if the System time was set at a certain range", it's possible games will react weird if they get a value that is much lower/higher than they anticipate, there are too many Win32 games to build an internal database and limit the system time to various ranges depending on game. So that specific problem will just have to exist. synnchan: FRAPS also uses DLL hooking to record video, so there is a very big risk that using FRAPS to dump AVI will cause desyncs or soft-locks. Ilari: Yeah, save-states are pretty unstable, the biggest problem is threading which I have some ideas for, I already fixed one of the reasons to why thread-wrapping crashes. Handles in general are a big problem, saving a state with a valid handle, then before loading the state the handle is freed... really bad.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Good catch, that has to be addressed. Thanks!
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Nach: I have since reworked the detection, that piece of code is out-dated. But I appreciate your input. :)
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Interesting, thanks. I'll make a note of that for my ever-growing "look into" list.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
synnchan wrote:
I'm considering buying a Laptop just for hourglass, because I can't get anything to work here on my Win 7 64 bits. Does hourglass work on a Laptop with Win XP 32 bits as well or must it be a Desktop Computer?
How does it not work? We have it running decently on Win 7 x64. (Sure XP works better like mentioned, but I still would like to know)
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
I have since acquired Dustforce thanks to keylie, so I have better debugging abilities for this game now. Adding mouse input however exposed another problem with how we do windowing, which has to be resolved before we can finalize mouse input. Adding mouse support is a lot more work than we thought.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
From GPL v3:
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
By your definition jlun2 this means any project licensed under the GPL v3 license non-open source.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Might be better asked at the PCSX2 forums.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Lord Zelkova wrote:
Warepire wrote:
-lots of text-
I didn't think about lag so I will make sure not to abuse it. You basically answered my question fully and then some. I really need to learn how to use LUA scripting as it sound extremely useful. There is a moving image that appears in the chat and I am able to move the chat along two frames before that image appears. Any chance a script can catch something like that? That would basically remove any worrying about dialog on a very text heavy game and would make my life much easier.
If it is somehow represented in memory and you can find the responsible address(es), then you can have a script that informs you of such an upcoming event. Otherwise it becomes more difficult but may still be doable. One way such a bot can predict it is if the image info doesn't exist in memory until the frame you can see it, find the info when it is on screen, write a bot that saves state, goes forward 2-3 frames, checks for the image related info, then loads state and if the info was found, write a heads-up on screen.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Excessive use of auto-fire and auto-hold can induce lag in some games, so even if you can hold a button through-out the entire TAS, it might save frames not to hold it when it isn't needed, and also it looks more professional if it's only held when necessary. If you have a movement where you need to press a button on every other frame for 4-5 seconds, auto-fire can make that section faster instead of going frame-advance, hold button, frame advance, release button, frame advance, hold button ... Same goes for auto hold. These tools were added for comfort, this is also why we have LUA scripts despite there being RAM watch etc. Because it can be so much nicer seeing things as images or following the object they're representing on screen, specially when keeping track of many addresses. Also it gives you the power to write bots that do things for you if it's a very repetitive thing. I cannot speak for how Kriole TASed Aria Of Sorrow and Dawn Of Sorrow, but such movement can be an example of when you might want to write a short bot. Bots can also become more advanced like the scripts used in the current NES Rockman TAS, or even to the point where the bot no longer is a LUA script, but a program specially designed to TAS a certain game (MrWint's Pokemon Blue for example)
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
There's always something blocking my ideas. :(
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
I am not sure I spotted all the improvements, but it looked great! Something I didn't think of before but spotted now: In Ice 15, is it possible to early grab a bomb and place it somewhere so it will explode near you as you collect the gems and take some damage? Or does the penguin damage you too much for it to be possible?
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
That rupee dive... Awesome WIP, one of the coolest things I've seen this year.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
While trying to find better a better way to monitor speed I discovered this little thing in Nowhere while goofing off: The "walked off a ledge" jump can be triggered from TNT boxes. Should make the TNT box GC not require the Ears-action anymore. (I triggered in on the second TNT box, and the jump let me collect the carrot) Also regarding the mallet GC, you get one more green box than you need, perhaps a box can be successfully thrown during the green box GC box stuff to trigger the spawn of the mallet GC. It's really hard to get the box thrown in the right angle, but TASing should fix it. EDIT: Updated RAM watch: http://tasvideos.org/userfiles/info/11121287892615633 The watch adds position coordinates, and a GC roll-over counter (not kidding...) LUA script version: http://tasvideos.org/userfiles/info/11121287892615633 This is my first ever LUA script, so it's very simple and probably clumsy, but it does what I want, so I am quite proud. The script uses the position coordinates to calculate speed instead of the speed vector, the speed is quite interesting, do play around with it to get a feel for it. Still want to find: In-level totals of GCs, clocks and ACME boxes.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
I think the Chinese bootleg version of ALttP "The Legend of Zelda: San Shen Zhi Li" could make a really funny TAS...
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
Mario, the overlord of parkour...
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
zwataketa wrote:
How exactly do you record a movie with the standalone flash player?
You can't, but if the flash game has been compiled into an exe (like N, or Abobo's Big Adventure) it SHOULD work in Hourglass... if it wasn't for some bug causing seg faults or memory access violations leading to instant crashes. I will debug that some day... Can't say when.
Warepire
He/Him
Editor, Experienced Forum User
Joined: 3/2/2010
Posts: 2174
Location: A little to the left of nowhere (Sweden)
WST wrote:
Well, I wanted this to be a question for those who do not know the answer. But since you answerred correctly, and even explained your answer, it’s not interesting anymore. The only thing I’d like to notice is that the color is not actually red, and also depends on the camera — on mine it is clearly white.
Sorry for ruining the fun, I got a little carried away :( I've only ever seen IR lights turn red on camera before, so that part I didn't know. Thanks for the explanation of that.