SRL Archive - Reflection Discussion

[Suggestion] Don't terminate if hooks are outdated


Coh3n

2011-05-04 11:25:13

I want to know if it's worth it before I actually make the changes. If I was to chagne Reflection.simba so the scripter can choose whether to terminate the script if the hooks are outdated, would that pull request be accepted? I wouldn't change anything in SetupReflection, so no scripts would break, but it would be nice for scripts, such as MSI, that have the option to use 100% color, so if the hooks are outdated, it will still continue with color.

Bobzilla69

2011-05-04 11:27:50

in my ratinator script i use this to see if we are using reflection or color

if Players[CurrentPlayer].Booleans[0] then //checks reflection is usable
begin
if (not (SmartGetFieldInt(0, hook_static_LoginIndex) = -1)) then
begin
Write('Reflection is usable');
end else
begin
Players[CurrentPlayer].Booleans[0]:= False;
Write('Reflection not working, using color');
end;
end;

so it should be possible you will just have to use a variable i suppose like i have done to know what to do

Coh3n

2011-05-04 11:29:52

Yeah, we do a similar thing in MSI. The thing is, that way, the hooks aren't automatically updated. SetupReflectionEx automatically updates the hooks if they haven't been committed to github yet. Your method, and the one MSI currently uses, does not.

Bobzilla69

2011-05-04 11:31:48

ahhh i see, sorry cant help then :(

Coh3n

2011-05-04 11:33:02

From: Bobzilla69
ahhh i see, sorry cant help then :(

No you helped. :) It shows that I wouldn't be the only one that would use this option.

pyroryan

2011-05-04 11:37:07

Yes unless someone shows up with a good reason to suggest otherwise.

Coh3n

2011-05-04 11:37:58

From: pyroryan
Yes unless someone shows up with a good reason to suggest otherwise.

Okay, thanks. :)

Rich

2011-05-04 12:27:31

One way would be to change UpdateHooks, and SetupReflectionEx a little bit:
Procedure UpdateHooks(Terminate : Boolean);
var
myFile, ClientRev, RevHook: Integer;
begin
ClientRev := r_GetCurrentGit('clientversion');
RevHook := r_GetCurrentGit('hookrevision');
if (ClientRev = ClientVersion) and (RevHook = HookRev) then
begin
Writeln('[Reflection] No new hooks have been uploaded yet; please be patient!');
if Terminate then
begin
Writeln('[Reflection] Terminating script');
TerminateScript;
end;
Writeln('[Reflection] Running script with outdated hooks');
end;
Writeln('[Reflection] You''re using outdated hooks (version ' + ToStr(ClientVersion) + '.' + ToStr(HookRev) + '); updating you to version' + ToStr(ClientRev) + '.' + ToStr(RevHook) + '!');
myFile := RewriteFile(AppPath + 'includes\reflection\core\hooks.simba', False);
WriteFileString(myFile, GetPage('http://harry.lu/srl/Hooks.txt'));
CloseFile(myFile);
Writeln('[Reflection] Updated you to ' + ToStr(ClientRev) + '.' + ToStr(RevHook) + '; please restart your script!');
TerminateScript;
end;

//SNIP

Procedure SetupReflectionEx(Update, Terminate : Boolean);
begin
SetupConstants;
if(SmartGetFieldInt(0, hook_static_LoginIndex) = -1) then
begin
Writeln('[Reflection] Hooks outdated!');
If Update then
UpdateHooks(Terminate)
else
TerminateScript;
end;

end;
Of course, this would break scripts. To not break scripts, Terminate could be set as a global var, like MouseSpeed, and by default would be False (which would run on outdated, so set as True in SetupReflectionEx which wouldn't run on outdated hooks [like it does by default ATM]), so if the scripter/user wants to change it, they could do so as a constant in their script, which would be called AFTER SetupReflectionEx.


var
Terminate : Boolean;

Procedure UpdateHooks;
var
myFile, ClientRev, RevHook: Integer;
begin
ClientRev := r_GetCurrentGit('clientversion');
RevHook := r_GetCurrentGit('hookrevision');
if (ClientRev = ClientVersion) and (RevHook = HookRev) then
begin
Writeln('[Reflection] No new hooks have been uploaded yet; please be patient!');
if Terminate then
begin
Writeln('[Reflection] Terminating script');
TerminateScript;
end;
Writeln('[Reflection] Running script with outdated hooks');
end;
Writeln('[Reflection] You''re using outdated hooks (version ' + ToStr(ClientVersion) + '.' + ToStr(HookRev) + '); updating you to version' + ToStr(ClientRev) + '.' + ToStr(RevHook) + '!');
myFile := RewriteFile(AppPath + 'includes\reflection\core\hooks.simba', False);
WriteFileString(myFile, GetPage('http://harry.lu/srl/Hooks.txt'));
CloseFile(myFile);
Writeln('[Reflection] Updated you to ' + ToStr(ClientRev) + '.' + ToStr(RevHook) + '; please restart your script!');
TerminateScript;
end;

//SNIP

Procedure SetupReflectionEx(Update : Boolean);
begin
Terminate:= True;
SetupConstants;
if(SmartGetFieldInt(0, hook_static_LoginIndex) = -1) then
begin
Writeln('[Reflection] Hooks outdated!');
If Update then
UpdateHooks(Terminate)
else
TerminateScript;
end;
end;

Script example:

program Hello;
{.include SRL/SRL.scar}
{.include reflection/reflection.scar}

const
HooksTerminate = False

procedure ScriptyStuff;
begin
//BLA
end;

begin
SetupSRL;
SetupReflectionEx(True);
Terminate:= HooksTerminate;
ScriptyStuff;
end.

Coh3n

2011-05-04 13:25:48

I already sent a pull request.

https://github.com/SRL/srl-reflection/pull/31

Rich

2011-05-04 13:55:15

Wouldn't the global var be because so no scripts broke?

Coh3n

2011-05-04 13:57:29

From: Rich
Wouldn't the global var be because so no scripts broke?

I didn't look at yours, but with mine, unless the scripter uses SetupReflectionEx, the script won't break.

E: I actually did exactly what you did in the first one.

Rich

2011-05-04 14:05:13

From: Coh3n
I didn't look at yours, but with mine, unless the scripter uses SetupReflectionEx, the script won't break.

E: I actually did exactly what you did in the first one.
Great minds think alike.