mihaip / infinite-mac

A classic Mac loaded with everything you'd want
https://infinitemac.org
Apache License 2.0
1.17k stars 70 forks source link

Change Date/Time #199

Closed bshep closed 8 months ago

bshep commented 1 year ago

Just wondering if there is any way to change the date on the emulator, if I use the date/time control panel it just reverts to the current date/time.

I want to change it so I can run old demos that have 'expired'.

Maybe this is something simple I'm missing but I haven't figured it out.

that-ben commented 1 year ago

Yes, it's because emulators use the host computer's clock so even if you try to manually set a different date/time, it instantly picks up the host clock's date/time the next second and overwrites your emulated clock with it. This happens every second. Interesting idea though. I wonder if this is something that could be hacked using Javascript @mihaip

bshep commented 1 year ago

thanks for the reply @that-ben, I looked at the source and it looks like it is using the Date.now() method to get the current time, I tried overriding this method using tampermonkey with no luck. I see the fake date time in the JS console but the emulator doesnt seem to pick it up.

My guess is this is related to reactjs in some way but i cant seem to figure it out.

This is the code i used to override the date.

    var d = new Date(2012, 0, 20)
    //override Date constructor so all newly constructed dates return this Friday
    var oldDate = Date;
    Date = function(){return d};
    Date.now = function(){ return 1327039200000};
mihaip commented 1 year ago

I believe the emulator overwrites the Mac's date/time in the 1hz interrupt loop: https://github.com/mihaip/macemu/blob/49787f862b1941a32c0a80077e1ecededdce5b06/BasiliskII/src/Unix/main_unix.cpp#L1258-L1259

Changing that to instead just set the value at startup and then increment it might work.

bshep commented 1 year ago

I believe the emulator overwrites the Mac's date/time in the 1hz interrupt loop: https://github.com/mihaip/macemu/blob/49787f862b1941a32c0a80077e1ecededdce5b06/BasiliskII/src/Unix/main_unix.cpp#L1258-L1259

Changing that to instead just set the value at startup and then increment it might work.

Thanks for the reply.

Maybe just setting an offset would be enough, that way managing the 'new time' will be easier, just subtract the offset?

EDIT: Just confirmed that changing this line: https://github.com/mihaip/infinite-mac/blob/e5995fcbfa1bb04a0534433319e21fa474fd5dde/src/emulator/BasiliskII.js#L4695

to: var date = new Date((readI53FromI64(time)*1000)-(15*365*24*60*60*1000)); will offset the emulators time by 15yrs, so it should be possible to change the offset and have the emulator show any date needed. Not sure the consequences of changing this on the fly though.

johsoderi commented 1 year ago

An option to let the user set the time manually would be very useful. I want to play a game that checks the age of a serial and demands that you renew it if it's too old, but the servers are of course no longer up, meaning I can't play the game.

that-ben commented 1 year ago

True, sometimes, you just have to roll the year back to early 2000's.

mihaip commented 8 months ago

This is now implemented, you can now trigger the KanjiTalk new year easter egg anytime: https://infinitemac.org/1996/KanjiTalk%207.5.3?machine=Mac+II&date=2024-01-01&edit

that-ben commented 8 months ago

Wow, that is so cool! Infinite Mac has become so much more useful and all these tweaks and hacks make it even more jaw dropping. I really appreciate you implementing all these Mihai, thanks for what you're doing!

bshep commented 8 months ago

Thank you so much!