Forum Replies Created
-
AuthorPosts
-
The mystery continues.
The problem is definitely on the reflection end. In fact, I can’t get reflection to work at all. In my current project, I have literally hundreds of imported classes, as well as a few in the local file. However, the following outputs absolutely nothing:
Monkey1234Local this:=TypeInfo.GetTypes()For Local t:= Eachin thisPrint "->" + t.Kind + " " + t.NameNextFrom the documentation, the TypeInfo.GetTypes() should return an array of user-defined types, but this is returning nothing at all. Is there a reflection filter or something I need to setup first?
Thanks! Quite helpful!
Ouch, this keeps getting stranger.
It’s easy to see the first obvious problem with this test.. MX2 text can’t represent characters $80-$FF? Strange! The strangest thing is that $FF isn’t even possible, and equates to $00? Run the test below and look at the last entry. Yes, I see that the first byte is $FF for >$80… But that stops at $FFFE. Where is $FFFF? Is this expected behavior or a bug?
Monkey1234567891011121314151617#Import "<std>"Using std..Function Main()Local db:DataBuffer=New DataBuffer(255)For Local i:=0 To 255db.PokeUByte(i,i)NextLocal test:=db.PeekString(0)For Local i:= 0 To 255Print test[i] + " : " + Hex(test[i])NextEndThank you very much, this is very helpful.
I’ll definitely still work on figuring out what is causing it to fail in pure Mx2, but at least it won’t hold me up on my project!
Thanks for the answer. I guess I can do it in C/C++, but I was hoping to learn to do it in native Mx2 as a learning exercise.
I do a lot of work with various REST APIs and having a working HMAC-SHA256 implementation is super important to me. Could you take a peek at the very simple code in my other post? http://monkeycoder.co.nz/forums/topic/help-porting-hmac-sha256-code/#post-15900
Thanks!
Here is a full project to show the issue. Everything looks right, but I can’t figure out why it’s not returning expected results
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192#Import"<std>"#Import"<libc>"Using std..Using libc..' Simple HMAC-SHA256 function' See:' https://en.wikipedia.org/wiki/HMAC' https://tools.ietf.org/html/rfc2104' https://www.freeformatter.com/hmac-generator.htmlFunction HMAC256:String(key:String,message:String)Local B:=64 ' Blocksize (bytes)Local K:=New DataBuffer(B) ' KeyLocal ipad:=New DataBuffer(B) ' Inner padLocal opad:=New DataBuffer(B) ' Outer pad' Lets handle our key first!' Truncate the key if over blocksize,If key.Length>B Then key=SHA256(key)Zero(K.Data,B)K.PokeString(0,key)Display(K.Data,B,"KEY BYTES")' Lets fill ipad and opadFor Local i:=0 To B-1ipad.PokeUByte(i,$36~K.PeekUByte(i))opad.PokeUByte(i,$5c~K.PeekUByte(i))NextDisplay(ipad.Data,B,"IPAD BYTES AFTER XOR")Display(opad.Data,B,"OPAD BYTES AFTER XOR")Return SHA256(opad.PeekString(0) + SHA256(ipad.PeekString(0)+message))EndFunction Zero(db:UByte Ptr,len:Int)For Local i:=0 To len-1db[i]=$0NextEndFunction LPad:String(str:String,len:Int,char:String)While str.Length < lenstr=char+strEndReturn strEndFunction Display(arr:UByte Ptr,len:Int,title:String="")Local lineHex:StringLocal lineAscii:StringLocal retVal:StringLocal j:=0If title<>""Print titlePrint "==========================================================="EndFor Local i:=0 To len-1lineHex+=LPad(Hex(arr[i]),2,"0") + " "lineAscii+=String.FromChar(arr[i]) + " "If (i Mod 8)+1=8lineHex += "| "EndifIf (i Mod 16)+1=16Print LPad(Hex(j),4,"0") + ": "+ lineHex + lineAscii'retVal+=lineHex + "|| "+lineAscii+"~n"lineAscii=""lineHex=""j+=16EndifNextIf lineHex<>"" Then Print LPad(Hex(j),4,"0") + ": "+lineHex + lineAsciiPrint "~n"End FunctionFunction Main()Local key:="jondecker76"Local data:= "hello"Local expectedResult:="ab9ce9ef1575259bdb2beb438d8501479b5a63298bc33e4f4fdee87760fd3b75"Local result:=HMAC256(key,data)If result=expectedResultPrint "The expected result was returned!"ElsePrint "~nThe result " + result + " is incorrect!"EndifEndStill working on this. I’m much happier with the state of the code, but it still isn’t returning expected results :/
Monkey12345678910111213141516171819Function HMAC256:String(key:String,message:String)Local B:=64 ' Blocksize (bytes)Local K:=New DataBuffer(B) ' KeyLocal ipad:=New DataBuffer(B) ' Inner pad stringLocal opad:=New DataBuffer(B) ' Outer pad string' Lets handle our key first!' Truncate the key if over bloccksizeIf key.Length>B Then key=SHA256(key)K.PokeString(0,key)' Lets fill ipad and opadFor Local i:=0 To B-1ipad.PokeUByte(i,$36~K.PeekUByte(i))opad.PokeUByte(i,$5c~K.PeekUByte(i))NextReturn SHA256(opad.PeekString(0) + SHA256(ipad.PeekString(0)+ message))EndI finally figured out how the httprequest should be used. However, there is a bug where wget is returning exit status 8 where it shouldn’t. Reported bug: https://github.com/blitz-research/monkey2/issues/451
I gave it a try Mark, no go. I tried setting it in the local shell and even through /etc/environment. I tried setting to both 0 and 1 with the same results. I’ll keep poking around and let you know if I find anything fruitful
I’m on Nvidia with proprietary drivers, I could try the opensource one to see if there is a difference.
With a timer, everything does work properly, it’s the just vsync that doesn’t work.
February 12, 2018 at 7:31 am in reply to: Simple cheat code class (My first attempt at using Monkey2!) #13616Thank you again. I think I’m finally getting a handle on things
Here is the current state of things. I’ll start on joystick stuff soon then look for ways to clean things up a bit
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179Namespace CheatSequence#Import "<std>"#Import "<mojo>"Using std..Using mojo..' ------------------------------------------------------------------------------------------------------------------' SIMPLE CHEAT CLASS' ------------------------------------------------------------------------------------------------------------------' We will define some constantsEnum StrokeTypeKey = 1Joy = 2EndClass CheatSequencePublicField numStrokes:Int ' Number of strokes in this sequenceField strokeCounter:Int ' Current stroke in the sequenceField strokes:Map<Int,SequenceStroke> ' Map of strokes in the sequenceField timeOut:Int ' millisecs timeoutField lastStrokeTimestamp:Int ' timestamp of last stroke inputField OnSuccess:Void() ' Signal when sequence is successful (first class function)' Create a new cheat sequence' Default to a 1 second timeoutMethod New(thisTimeOut:Int=1000)numStrokes=0strokeCounter=0timeOut=thisTimeOutstrokes=New Map<Int,SequenceStroke>Enabled=True ' enable by defaultEnd' Create and populate sequence all at onceMethod New(thisTimeout:Int,strokeType:Int,strokeValues:Int[])Self.New(thisTimeout)AddStrokes(strokeType,strokeValues)End Method' Add a stroke to the sequenceMethod AddStroke(strokeType:Int,strokeValue:Int)strokes.Add(numStrokes,New SequenceStroke(strokeType,strokeValue))numStrokes+= 1End Method' Add several strokes of the same stroke type to the sequenceMethod AddStrokes( strokeType:Int,strokeValues:Int[] )For Local strokeValue:=Eachin strokeValuesAddStroke(strokeType,strokeValue)NextEnd' Enable/Disable the cheatSequenceProperty Enabled:Bool()Return _enabledSetter( value:Bool )If value=_enabled Return_enabled=valueIf _enabledApp.KeyEventFilter+=ProcessKeys ' subscribe to filterElseApp.KeyEventFilter-=ProcessKeys ' unsubscribe from filterEndifEndPrivateField _enabled:Bool' Process key strokes as they are fired by the App.KeyEventFilterMethod ProcessKeys( event:KeyEvent )' A key hit was signaled. Lets update the sequenceUpdateSequence( event )' and check does a user finish the sequenceIf Success()OnSuccess() ' and emit event if successEndifEnd' The sequence gets updated each keypressMethod UpdateSequence(thisEvent:KeyEvent)If Millisecs()-lastStrokeTimestamp > timeOut And strokeCounter>0'We timed out, lets restartSelf.strokeCounter=0lastStrokeTimestamp=Millisecs()Else' We didn't timeout, so lets update the sequenceIf thisEvent.Type = EventType.KeyDownIf strokes.Get(strokeCounter).strokeType=StrokeType.Key And strokes.Get(strokeCounter).strokeValue=thisEvent.KeySelf.strokeCounter+=1Self.lastStrokeTimestamp=Millisecs()ElseSelf.strokeCounter=0EndifEndifEndifEnd Method' Check to see if the cheat is successfulMethod Success:Bool()If (Self.strokeCounter=Self.numStrokes)Self.strokeCounter=0Return TrueEndifReturn FalseEndEnd' Store a cheat stroke. This includes the kind of stroke (keyboard, joystick, etc..)' the value of the stroke (whick key or button)Class SequenceStrokeField strokeType:IntField strokeValue:IntMethod New(thisStrokeType:Int,thisStrokeValue:Int)strokeType=thisStrokeTypestrokeValue=thisStrokeValueEndEnd' ------------------------------------------------------------------------------------------------------------------' END SIMPLE CHEAT CLASS' ------------------------------------------------------------------------------------------------------------------Class MyWindow Extends WindowField contraCheat:CheatSequenceField lives:IntMethod New()Super.New( "Cheat Test!",640,480,WindowFlags.Fullscreen )lives=3' Create our UUDDLRLRBA<Enter> cheat sequencecontraCheat = New CheatSequence(1000,StrokeType.Key,New Int[](Key.Up,Key.Up,Key.Down,Key.Down,Key.Left,Key.Right,Key.Left,Key.Right,Key.B,Key.A,Key.Enter))' Increase lives by 30 if the cheat sequence is successfully enteredcontraCheat.OnSuccess=Lambda()lives+=30EndEndMethod OnRender( canvas:Canvas ) Override' Debug display of cheat sequenceLocal delta:=Millisecs() - contraCheat.lastStrokeTimestampcanvas.Color=Color.Goldcanvas.DrawText("Lives: " + lives,App.ActiveWindow.Width/2 ,App.ActiveWindow.Height/2)canvas.Color=Color.Whitecanvas.DrawText("Try the cheat! UUDDLRLRBA<Enter>",4,App.ActiveWindow.Height-95)canvas.DrawText("Timer: " + delta,4,App.ActiveWindow.Height-55)canvas.DrawText("numStokes: " + contraCheat.numStrokes,4,App.ActiveWindow.Height-40)canvas.DrawText("strokeCounter : " + contraCheat.strokeCounter,4,App.ActiveWindow.Height-25)App.RequestRender()EndMethod OnKeyEvent( event:KeyEvent ) Overrideselect event.TypeCase EventType.KeyDown' Exit the appIf ( event.Key=Key.Escape ) Then App.Terminate()EndEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndFebruary 11, 2018 at 6:01 pm in reply to: Simple cheat code class (My first attempt at using Monkey2!) #13613I’ve been improving on this today and playing with it more. There’s only one problem so far with using the key event filter.
The App.KeyEventFilter isn’t a one-shot, so each press of the key registers 2-3 hits even on quick strokes. Since Update is only called when the KeyEventFilter is fired, there isn’t an elegant way to hand my own one-shot code. For now I’m hacking my way around it with a timer to ensure at least so much time goes by between keypresses, but it’s definitely not optimal.
It would be nice if A) KeyEventFilter was only sent once at the beginning of each press or B) a certain code was sent on release of the key. But neither of these are present. So for now I will have to either keep using the delta timing method I’m using now, or have an Update that needs run from Main each iteration so that the KeyEventFilter can be one-shotted.
February 11, 2018 at 6:07 am in reply to: Simple cheat code class (My first attempt at using Monkey2!) #13608Thank you!
I just learned more from this single exercise than I have in the last week reading everything I could. Very clean and elegant, now it’s making a lot more sense!
February 10, 2018 at 6:14 pm in reply to: Simple cheat code class (My first attempt at using Monkey2!) #13606Thanks for the tips nerobot
I implemented the AddStrokes method, and you’re right – it’s much cleaner for usage
I’m lost on the App.KeyEventFilter though… There is no real documentation, and looking at the source has me scratching my head. It’s a field, but has a void return type?? And parameters? Wouldn’t that make it a method instead of a field? So confusing! I also looked at event.monkey2 and was left equally confused. There’s so much I have to learn about Monkey 2
I just tried to access via Ted2go but get booted from the server for not identifying via SASL? It’s been a long time since I’ve even used IRC, and searching for a simple answer is bringing up answers that will take days to read and understand. Any tips on how to get connected?
-
AuthorPosts