Skip to content

Commit

Permalink
ACTIONSCRIPT: Add indexed function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Feb 23, 2019
1 parent 406a565 commit a9fc66c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
19 changes: 14 additions & 5 deletions src/aurora/actionscript/asbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,15 @@ void ASBuffer::actionCallMethod(AVM &avm) {
counter += 1;
}

for (size_t i = 0; i < arguments.size(); ++i) {
avm.storeRegister(arguments[i], counter);
counter += 1;
if (function->hasRegisterIds()) {
for (size_t i = 0; i < arguments.size(); ++i) {
avm.storeRegister(arguments[i], function->getRegisterId(i));
}
} else {
for (size_t i = 0; i < arguments.size(); ++i) {
avm.storeRegister(arguments[i], counter);
counter += 1;
}
}

avm.setReturnValue(Variable());
Expand Down Expand Up @@ -584,8 +590,9 @@ void ASBuffer::actionDefineFunction2() {

bool preloadGlobalFlag = bitstream.getBit() != 0;

std::vector<uint8> parameterIds(numParams);
for (int i = 0; i < numParams; ++i) {
_script->readByte();
parameterIds[i] = _script->readByte();
readString();
}

Expand All @@ -597,6 +604,8 @@ void ASBuffer::actionDefineFunction2() {
new ScriptedFunction(
new Common::SeekableSubReadStream(_script, _script->pos(), _script->pos() + codeSize),
_constants,
parameterIds,
registerCount,
preloadThisFlag,
preloadSuperFlag,
preloadRootFlag
Expand Down Expand Up @@ -768,7 +777,7 @@ void ASBuffer::actionDefineFunction() {
}

uint16 codeSize = _script->readUint16LE();
_stack.push(ObjectPtr(new ScriptedFunction(_script->readStream(codeSize), _constants, false, false, false)));
_stack.push(ObjectPtr(new ScriptedFunction(_script->readStream(codeSize), _constants, std::vector<uint8>(), 0, false, false, false)));

_seeked = codeSize;

Expand Down
23 changes: 18 additions & 5 deletions src/aurora/actionscript/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,20 @@ namespace Aurora {

namespace ActionScript {

Function::Function(bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag) :
_preloadThisFlag(preloadThisFlag), _preloadSuperFlag(preloadSuperFlag), _preloadRootFlag(preloadRootFlag) {
Function::Function(std::vector<uint8> parameterIds, uint8 numRegisters, bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag) :
_parameterIds(parameterIds), _numRegisters(numRegisters), _preloadThisFlag(preloadThisFlag), _preloadSuperFlag(preloadSuperFlag), _preloadRootFlag(preloadRootFlag) {
}

bool Function::hasRegisterIds() {
return !_parameterIds.empty();
}

uint8 Function::getRegisterId(size_t n) {
return _parameterIds[n];
}

uint8 Function::getNumRegisters() {
return _numRegisters;
}

bool Function::getPreloadThisFlag() {
Expand All @@ -45,8 +57,9 @@ bool Function::getPreloadRootFlag() {
}

ScriptedFunction::ScriptedFunction(Common::SeekableReadStream *as, std::vector<Common::UString> constants,
std::vector<uint8> parameterIds, uint8 numRegisters,
bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag) :
Function(preloadThisFlag, preloadSuperFlag, preloadRootFlag), _stream(as), _buffer(as) {
Function(parameterIds, numRegisters, preloadThisFlag, preloadSuperFlag, preloadRootFlag), _stream(as), _buffer(as) {
_buffer.setConstantPool(constants);
}

Expand All @@ -60,14 +73,14 @@ Variable ScriptedFunction::operator()(AVM &avm) {
}

NativeFunction::NativeFunction(boost::function<Variable(AVM &)> function, bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag)
: Function(preloadThisFlag, preloadSuperFlag, preloadRootFlag), _function(function) {
: Function(std::vector<uint8>(), 0, preloadThisFlag, preloadSuperFlag, preloadRootFlag), _function(function) {
}

Variable NativeFunction::operator()(AVM &avm) {
return _function(avm);
}

DummyFunction::DummyFunction() : Function(false, false, false) {
DummyFunction::DummyFunction() : Function(std::vector<uint8>(), 0, false, false, false) {

}

Expand Down
13 changes: 12 additions & 1 deletion src/aurora/actionscript/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ typedef boost::shared_ptr<Function> FunctionPtr;

class Function : public Object {
public:
Function(bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag);
Function(std::vector<uint8> parameterIds, uint8 numRegisters, bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag);

bool hasRegisterIds();
uint8 getRegisterId(size_t n);

uint8 getNumRegisters();

bool getPreloadThisFlag();
bool getPreloadSuperFlag();
Expand All @@ -51,6 +56,10 @@ class Function : public Object {
virtual Variable operator()(AVM &avm) = 0;

private:
std::vector<uint8> _parameterIds;

uint8 _numRegisters;

bool _preloadThisFlag;
bool _preloadSuperFlag;
bool _preloadRootFlag;
Expand All @@ -61,6 +70,8 @@ class ScriptedFunction : public Function {
ScriptedFunction(
Common::SeekableReadStream *as,
std::vector<Common::UString> constantPool,
std::vector<uint8> parameterIds,
uint8 numRegisters,
bool preloadThisFlag,
bool preloadSuperFlag,
bool preloadRootFlag
Expand Down

0 comments on commit a9fc66c

Please sign in to comment.