Skip to content

Commit 02eeae6

Browse files
committed
Fix code
1 parent c82f386 commit 02eeae6

6 files changed

Lines changed: 26 additions & 176 deletions

File tree

GS2Engine.UnitTests/StackEntryExtensionsTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,20 @@ public void When_input_is_string_array_Then_return_StackEntry_with_type_array_an
9595
Assert.Equal(typeof(List<string>), test.GetValue()?.GetType());
9696
Assert.Equal(val, test.GetValue());
9797
}
98+
99+
[Fact]
100+
public void When_input_is_bool_Then_return_StackEntry_with_type_bool_and_value_type_bool()
101+
{
102+
//Arrange
103+
const bool val = true;
104+
105+
//Act
106+
IStackEntry test = val.ToStackEntry();
107+
108+
//Assert
109+
Assert.Equal(StackEntryType.Boolean, test.Type);
110+
Assert.Equal(typeof(bool), test.GetValue()?.GetType());
111+
Assert.Equal(val, test.GetValue());
112+
}
98113
}
99114
}

GS2Engine/GS2/ByteCode/BytecodeSegment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ public enum BytecodeSegment
55
Gs1EventFlags = 1,
66
FunctionNames = 2,
77
Strings = 3,
8-
Bytecode = 4
8+
Bytecode = 4,
99
}
1010
}

GS2Engine/GS2/ByteCode/Extensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static TString BytecodeSegmentToString(this BytecodeSegment segment) =>
99
BytecodeSegment.FunctionNames => "FunctionNames",
1010
BytecodeSegment.Strings => "Strings",
1111
BytecodeSegment.Bytecode => "Bytecode",
12-
_ => "Unknown"
12+
_ => "Unknown",
1313
};
1414

1515
public static bool IsBooleanReturningOp(this Opcode opcode) =>
@@ -24,7 +24,7 @@ public static bool IsBooleanReturningOp(this Opcode opcode) =>
2424
Opcode.OP_GTE => true,
2525
Opcode.OP_IN_RANGE => true,
2626
Opcode.OP_IN_OBJ => true,
27-
_ => false
27+
_ => false,
2828
};
2929

3030
public static bool IsReservedIdentOp(this Opcode opcode) =>
@@ -36,7 +36,7 @@ public static bool IsReservedIdentOp(this Opcode opcode) =>
3636
Opcode.OP_PLAYERO => true,
3737
Opcode.OP_LEVEL => true,
3838
Opcode.OP_TEMP => true,
39-
_ => false
39+
_ => false,
4040
};
4141

4242
public static bool IsObjectReturningOp(this Opcode opcode) =>
@@ -48,7 +48,7 @@ public static bool IsObjectReturningOp(this Opcode opcode) =>
4848
Opcode.OP_PLAYERO => true,
4949
Opcode.OP_LEVEL => true,
5050
Opcode.OP_TEMP => true,
51-
_ => false
51+
_ => false,
5252
};
5353

5454
public static TString OpcodeToString(this Opcode opcode) =>
@@ -123,7 +123,7 @@ public static TString OpcodeToString(this Opcode opcode) =>
123123
Opcode.OP_PLAYERO => "OP_PLAYERO",
124124
Opcode.OP_LEVEL => "OP_LEVEL",
125125
Opcode.OP_TEMP => "OP_TEMP",
126-
_ => "OP " + (int)opcode
126+
_ => "OP " + (int)opcode,
127127
};
128128
}
129129
}

GS2Engine/GS2/ByteCode/Opcode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,6 @@ public enum Opcode
123123
OP_LEVEL = 184,
124124
OP_TEMP = 189,
125125
OP_PARAMS = 190,
126-
OP_NUM_OPS // This is to get the number of operations
126+
OP_NUM_OPS, // This is to get the number of operations
127127
}
128128
}

GS2Engine/GS2/Script/Script.cs

Lines changed: 3 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void Reset()
8383
public TString Name { get; set; }
8484
public TString File { get; set; }
8585
private int Gs1Flags { get; set; }
86-
public ScriptMachine Machine { get; set; }
86+
public ScriptMachine Machine { get; }
8787
private DateTime? Timer { get; set; }
8888

8989
public ScriptCom[] Bytecode => _bytecode;
@@ -286,172 +286,7 @@ private static void onScriptUpdated()
286286

287287
private static void optimizeByteCode()
288288
{
289-
/*
290-
TString str;
291-
uint hashcode;
292-
TScriptProperty* pTVar1;
293-
int oIndex;
294-
void* __fn;
295-
void* in_R8;
296-
TProperties* properties;
297-
TScriptCom* bytecodeByte1;
298-
TScriptCom* bytecodeByte2;
299-
int length;
300-
unsigned char opCode;
301-
unsigned char opCode2;
302-
303-
oIndex = 0;
304-
length = this->bytecodeLength;
305-
if (1 < length)
306-
do
307-
{
308-
properties = TScriptUniverse_properties;
309-
bytecodeByte1 = &this->bytecode[oIndex];
310-
bytecodeByte2 = &this->bytecode[oIndex + 1];
311-
opCode = bytecodeByte1->byte;
312-
switch (opCode)
313-
{
314-
case '\x14':
315-
opCode2 = bytecodeByte2->byte;
316-
if (opCode2 < 0x4c)
317-
{
318-
if (opCode2 < 0x48)
319-
{
320-
if ((unsigned char)opCode2 - 0x3c < 8) {
321-
if (oIndex + 2 < length && (this->bytecode[(long)oIndex + 2].byte == '2')) {
322-
bytecodeByte1->byte = opCode2 + 0x9c;
323-
oIndex = oIndex + 2;
324-
}
325-
else {
326-
bytecodeByte1->byte = opCode2 + 0x8c;
327-
oIndex = oIndex + 1;
328-
}
329-
}
330-
}
331-
else
332-
{
333-
oIndex = oIndex + 1;
334-
bytecodeByte1->byte = opCode2 + 0x98;
335-
}
336-
}
337-
else if (opCode2 == 0x83)
338-
{
339-
bytecodeByte1->byte = -0x10;
340-
oIndex = oIndex + 1;
341-
}
342-
343-
break;
344-
case '\x16':
345-
switch (bytecodeByte2->
346-
347-
byte) {
348-
case '\x06':
349-
case '-':
350-
case '/':
351-
str = bytecodeByte1->variableName;
352-
hashcode = THashList::getHashcode(str);
353-
__fn = (void*)hashcode;
354-
/*
355-
pTVar1 = (TScriptProperty *)
356-
THashList::getObjectEncoded(&properties->hashList,hashcode,str);
357-
if ((pTVar1 != (TScriptProperty *)0x0) && (pTVar1->isFunction != false)) {
358-
str.clear();
359-
bytecodeByte1->byte = -0xf;
360-
if ((this->graalVar).protected_object < pTVar1->functionLevel) {
361-
length = TServerList::getServerPrivileges();
362-
if (length < (int)(uint)pTVar1->functionLevel) {
363-
pTVar1 = TScriptProperty::clone
364-
(pTVar1,__fn,(void *)(ulong)pTVar1->functionLevel,0x408390,in_R8)
365-
;
366-
bytecodeByte1->scriptProperty = pTVar1;
367-
pTVar1->functionLevel = 10;
368-
break;
369-
}
370-
}
371-
bytecodeByte1->scriptProperty = pTVar1;
372-
}
373-
*
374-
break;
375-
case '#':
376-
if (oIndex < length + -2)
377-
{
378-
opCode2 = this->bytecode[(long)oIndex + 2].byte;
379-
if (opCode2 == 0x22)
380-
{
381-
bytecodeByte1->byte = -0x13;
382-
oIndex = oIndex + 2;
383-
}
384-
else if (opCode2 < 0x23)
385-
{
386-
if (opCode2 != 0x21) goto LAB_0032d73b;
387-
bytecodeByte1->byte = -0x14;
388-
oIndex = oIndex + 2;
389-
}
390-
else if (opCode2 == 0x24)
391-
{
392-
bytecodeByte1->byte = -0x12;
393-
oIndex = oIndex + 2;
394-
}
395-
else
396-
{
397-
if (opCode2 != 0x2f ||
398-
((oIndex + 3 < length && (this->bytecode[(long)oIndex + 3].byte == '-'))))
399-
goto LAB_0032d73b;
400-
bytecodeByte1->byte = -0x11;
401-
oIndex = oIndex + 2;
402-
}
403-
}
404-
else
405-
{
406-
bytecodeByte1->byte = -0x16;
407-
oIndex = oIndex + 1;
408-
}
409-
410-
break;
411-
case '$':
412-
bytecodeByte1->byte = -0x15;
413-
oIndex = oIndex + 1;
414-
}
415-
break;
416-
case '.':
417-
opCode2 = bytecodeByte2->byte - 0x1e;
418-
if (opCode2 < 0x18)
419-
{
420-
/*
421-
/* WARNING: Could not recover jumptable at 0x0032d702. Too many branches */
422-
/* WARNING: Treating indirect jump as call *
423-
(*(code *)(&DAT_00408390 + *(int *)(&DAT_00408390 + (ulong)opCode2 * 4)))
424-
(length,opCode,&DAT_00408390 + *(int *)(&DAT_00408390 + (ulong)opCode2 * 4));
425-
return;
426-
*
427-
}
428-
429-
break;
430-
case '/':
431-
if (bytecodeByte2->byte == '-') {
432-
bytecodeByte1->byte = -0xe;
433-
bytecodeByte1->value = bytecodeByte2->value;
434-
oIndex = oIndex + 1;
435-
}
436-
break;
437-
case '<':
438-
case '=':
439-
case '>':
440-
case '?':
441-
case '@':
442-
case 'A':
443-
case 'B':
444-
case 'C':
445-
if (bytecodeByte2->byte == '2') {
446-
bytecodeByte1->byte = opCode + -0x6c;
447-
oIndex = oIndex + 1;
448-
}
449-
}
450-
451-
length = this->bytecodeLength;
452-
oIndex = oIndex + 1;
453-
} while (oIndex < length + -1);
454-
*/
289+
455290
}
456291

457292
private async Task<IStackEntry> Execute(string functionName, Stack<IStackEntry>? parameters = null) =>
@@ -518,7 +353,7 @@ public async Task<IStackEntry> TriggerEvent(string eventName)
518353
return 0.ToStackEntry();
519354
}
520355

521-
public void SetTimer(double value) => Timer = DateTime.UtcNow.AddSeconds(value);
356+
private void SetTimer(double value) => Timer = DateTime.UtcNow.AddSeconds(value);
522357

523358

524359
public async Task<IStackEntry> RunEvents()

GS2Engine/GS2/Script/ScriptCom.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace GS2Engine.GS2.Script
55
public class ScriptCom
66
{
77
public Opcode OpCode { get; set; }
8-
public uint LoopCount { get; set; } = 0;
8+
public uint LoopCount { get; set; }
99
public double Value { get; set; }
1010
public TString? VariableName { get; set; }
1111
}

0 commit comments

Comments
 (0)