Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/tasjudy.lua
2 views
1
--
2
-- TASJudy - Judges so you don't have to.
3
-- Author: Raiscan
4
-- Timestamp: 201508041957
5
-- Version: 0.1
6
-- To change this template use File | Settings | File Templates.
7
--
8
9
local resultsFilePath = "F:\\competition\\results\\results.txt"
10
local gracePeriod = 10000
11
local gracePeriodCounter = 0
12
local separator = ","
13
local exitOnResults = true
14
15
local FAILURE_DOES_NOT_FINISH = "DNF"
16
local FAILURE_DISQUALIFIED = "DQ"
17
18
-- Main Function --
19
function judge()
20
if movie.startsfromsavestate() then
21
console.log("Movie starts from savestate, so disqualifying")
22
23
writeFailureToResults(FAILURE_DISQUALIFIED)
24
25
endScript()
26
return
27
end
28
29
while not hasCompletedGame() do
30
31
if movieHasFinished() then
32
if gracePeriodLimiter() then
33
console.log("Movie does not finish the game :(")
34
writeFailureToResults(FAILURE_DOES_NOT_FINISH)
35
36
endScript()
37
return
38
end
39
end
40
41
--The show must go on
42
emu.frameadvance()
43
end
44
45
--We must have finished!
46
console.log("Movie finished game.")
47
writeSuccessToResults(emu.framecount(), getInGameTime())
48
49
endScript()
50
end
51
52
53
-------- HELPER FUNCTIONS BELOW ---------
54
55
-- Edit this with game completion criteria as necessary --
56
function hasCompletedGame()
57
return mainmemory.read_s8(0x002C) == 1
58
end
59
60
61
-- Edit this with functionality for in game time --
62
function getInGameTime()
63
local millis = bizstring.hex(mainmemory.read_u8(0x0050)):reverse()
64
local seconds = bizstring.hex(mainmemory.read_u8(0x004F)):reverse()
65
local minutes = bizstring.hex(mainmemory.read_u8(0x004E)):reverse()
66
67
return minutes .. ":" .. seconds .. "." .. millis
68
end
69
70
71
-- Ends the script. If exitOnResults set, exits emulator.
72
function endScript()
73
client.pause()
74
if exitOnResults then
75
client.closerom()
76
client.exitCode(emu.framecount())
77
end
78
end
79
80
-- Parses the hash of the movie file calculated by RGamma's uploader.
81
function parseHash()
82
local moviePath = movie.filename()
83
local movieFile = moviePath:match("([^\\]+)$")
84
local hash = movieFile:match("^([^.]+)")
85
86
return hash
87
end
88
89
90
-- Alias for writing results; blanks out times with reason.
91
function writeFailureToResults(reason)
92
93
writeResults(parseHash(), movie.getheader()["Author"], reason, reason, reason)
94
end
95
96
-- Alias for writing results; takes in endFrame and in game time --
97
function writeSuccessToResults(endFrame, inGameTime)
98
99
writeResults(parseHash(), movie.getheader()["Author"], endFrame, movie.length(), inGameTime)
100
end
101
102
function movieHasFinished()
103
return movie.mode() == "FINISHED" or not movie.isloaded()
104
end
105
106
-- Opens results file and writes a single line of all information gathered --
107
function writeResults(hash, author, endFrame, length, inGameTime)
108
local resultsFile, err = io.open(resultsFilePath, "a")
109
110
if err then
111
console.log("Could not write results " .. err)
112
else
113
local hash = parseHash()
114
local resultsLine = hash ..
115
separator ..
116
author ..
117
separator ..
118
endFrame ..
119
separator ..
120
length ..
121
separator ..
122
inGameTime
123
124
125
resultsFile:write(resultsLine .. "\n")
126
resultsFile:close()
127
end
128
end
129
130
function gracePeriodLimiter()
131
if gracePeriodCounter < gracePeriod then
132
gracePeriodCounter = gracePeriodCounter + 1
133
end
134
135
return gracePeriodCounter >= gracePeriod
136
end
137
138
judge()
139
140