Skip to content

Commit

Permalink
phoenix -> zenkit migration P1
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Feb 14, 2024
1 parent 44456f1 commit 26b816e
Show file tree
Hide file tree
Showing 145 changed files with 1,109 additions and 1,109 deletions.
2 changes: 1 addition & 1 deletion game/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ Camera::ListenerPos Camera::listenerPosition() const {
return pos;
}

const phoenix::c_camera &Camera::cameraDef() const {
const zenkit::ICamera& Camera::cameraDef() const {
auto& camd = Gothic::cameraDef();
if(camMod==Dialog)
return camd.dialogCam();
Expand Down
2 changes: 1 addition & 1 deletion game/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,5 @@ class Camera final {
void followAng (Tempest::Vec3& spin, Tempest::Vec3 dest, float dtF);
static void followAng (float& ang, float dest, float speed, float dtF);

const phoenix::c_camera& cameraDef() const;
const zenkit::ICamera& cameraDef() const;
};
72 changes: 36 additions & 36 deletions game/game/compatibility/ikarus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ enum {
OCNPC__ENABLE_EQUIPBESTWEAPONS = 7626662, //0x745FA6
};

void Ikarus::memory_instance::set_int(const phoenix::symbol &sym, uint16_t index, int32_t value) {
void Ikarus::memory_instance::set_int(const zenkit::DaedalusSymbol& sym, uint16_t index, int32_t value) {
ptr32_t addr = address + ptr32_t(sym.offset_as_member()) + ptr32_t(index*sym.class_size());
owner.allocator.writeInt(addr, value);
}

int32_t Ikarus::memory_instance::get_int(const phoenix::symbol& sym, uint16_t index) const {
int32_t Ikarus::memory_instance::get_int(const zenkit::DaedalusSymbol& sym, uint16_t index) const {
ptr32_t addr = address + ptr32_t(sym.offset_as_member()) + ptr32_t(index * sym.class_size());
int32_t v = owner.allocator.readInt(addr);
return v;
}

void Ikarus::memory_instance::set_float(const phoenix::symbol& sym, uint16_t index, float value) {
void Ikarus::memory_instance::set_float(const zenkit::DaedalusSymbol& sym, uint16_t index, float value) {
ptr32_t addr = address + ptr32_t(sym.offset_as_member()) + ptr32_t(index*sym.class_size());
owner.allocator.writeInt(addr, *reinterpret_cast<const int32_t*>(&value));
}

float Ikarus::memory_instance::get_float(const phoenix::symbol& sym, uint16_t index) const {
float Ikarus::memory_instance::get_float(const zenkit::DaedalusSymbol& sym, uint16_t index) const {
ptr32_t addr = address + ptr32_t(sym.offset_as_member()) + ptr32_t(index * sym.class_size());
int32_t v = owner.allocator.readInt(addr);

Expand All @@ -54,14 +54,14 @@ float Ikarus::memory_instance::get_float(const phoenix::symbol& sym, uint16_t in
return f;
}

void Ikarus::memory_instance::set_string(const phoenix::symbol& sym, uint16_t index, std::string_view value) {
void Ikarus::memory_instance::set_string(const zenkit::DaedalusSymbol& sym, uint16_t index, std::string_view value) {
ptr32_t addr = address + ptr32_t(sym.offset_as_member()) + ptr32_t(index*sym.class_size());
(void)addr;
Log::d("memory_instance: ", sym.name());
// allocator.writeInt(addr, 0);
}

const std::string& Ikarus::memory_instance::get_string(const phoenix::symbol& sym, uint16_t index) const {
const std::string& Ikarus::memory_instance::get_string(const zenkit::DaedalusSymbol& sym, uint16_t index) const {
ptr32_t addr = address + ptr32_t(sym.offset_as_member()) + ptr32_t(index*sym.class_size());

Log::d("memory_instance: ", sym.name());
Expand All @@ -71,7 +71,7 @@ const std::string& Ikarus::memory_instance::get_string(const phoenix::symbol& sy
}


Ikarus::Ikarus(GameScript& /*owner*/, phoenix::vm& vm) : vm(vm) {
Ikarus::Ikarus(GameScript& /*owner*/, zenkit::DaedalusVm& vm) : vm(vm) {
Log::i("DMA mod detected: Ikarus");

// built-in data with assumed address
Expand All @@ -84,7 +84,7 @@ Ikarus::Ikarus(GameScript& /*owner*/, phoenix::vm& vm) : vm(vm) {
oGame_Pointer = allocator.pin(&gameProxy, sizeof(gameProxy), "oGame");
gameProxy._ZCSESSION_WORLD = allocator.alloc(148);

symbolsPtr = allocator.alloc(uint32_t(vm.symbols().size() * sizeof(phoenix::symbol)));
symbolsPtr = allocator.alloc(uint32_t(vm.symbols().size() * sizeof(zenkit::DaedalusSymbol)));

parserProxy.symtab_table.numInArray = int32_t(vm.symbols().size());
parserProxy.symtab_table.numAlloc = 0;//parserProxy.symtab_table.numInArray;
Expand Down Expand Up @@ -114,11 +114,11 @@ Ikarus::Ikarus(GameScript& /*owner*/, phoenix::vm& vm) : vm(vm) {
vm.override_function("MEMINT_ReplaceSlowFunctions", [ ](){ });
vm.override_function("MEM_GetAddress_Init", [this](){ mem_getaddress_init(); });
vm.override_function("MEM_PrintStackTrace", [this](){ mem_printstacktrace_implementation(); });
vm.override_function("MEM_GetFuncOffset", [this](phoenix::func func){ return mem_getfuncoffset(func); });
vm.override_function("MEM_GetFuncID", [this](phoenix::func sym) { return mem_getfuncid(sym); });
vm.override_function("MEM_GetFuncOffset", [this](zenkit::DaedalusFunction func){ return mem_getfuncoffset(func); });
vm.override_function("MEM_GetFuncID", [this](zenkit::DaedalusFunction sym) { return mem_getfuncid(sym); });
vm.override_function("MEM_CallByID", [this](int sym) { return mem_callbyid(sym); });
vm.override_function("MEM_GetFuncPtr", [this](int sym) { return mem_getfuncptr(sym); });
vm.override_function("MEM_ReplaceFunc", [this](phoenix::func dest, phoenix::func func){ mem_replacefunc(dest, func); });
vm.override_function("MEM_ReplaceFunc", [this](zenkit::DaedalusFunction dest, zenkit::DaedalusFunction func){ mem_replacefunc(dest, func); });
vm.override_function("MEM_GetFuncIdByOffset", [this](int off) { return mem_getfuncidbyoffset(off); });
vm.override_function("MEM_AssignInst", [this](int sym, int ptr) { mem_assigninst(sym, ptr); });

Expand Down Expand Up @@ -149,9 +149,9 @@ Ikarus::Ikarus(GameScript& /*owner*/, phoenix::vm& vm) : vm(vm) {
vm.override_function("MEM_Realloc", [this](int address, int oldsz, int size) { return mem_realloc(address,oldsz,size); });

// ## Control-flow ##
vm.override_function("repeat", [this](phoenix::vm& vm) { return repeat(vm); });
vm.override_function("while", [this](phoenix::vm& vm) { return while_(vm); });
vm.register_access_trap([this](phoenix::symbol& i) { return loop_trap(&i); });
vm.override_function("repeat", [this](zenkit::DaedalusVm& vm) { return repeat(vm); });
vm.override_function("while", [this](zenkit::DaedalusVm& vm) { return while_(vm); });
vm.register_access_trap([this](zenkit::DaedalusSymbol& i) { return loop_trap(&i); });

// ## Strings
vm.override_function("STR_SubStr", [this](std::string_view str, int start, int count){ return str_substr(str,start,count); });
Expand Down Expand Up @@ -203,7 +203,7 @@ Ikarus::Ikarus(GameScript& /*owner*/, phoenix::vm& vm) : vm(vm) {
// }
}

bool Ikarus::isRequired(phoenix::script& vm) {
bool Ikarus::isRequired(zenkit::DaedalusScript& vm) {
return
vm.find_symbol_by_name("MEM_InitAll") != nullptr &&
vm.find_symbol_by_name("MEM_ReadInt") != nullptr &&
Expand All @@ -227,7 +227,7 @@ void Ikarus::mem_sendtospy(int cat, std::string_view msg) {

void Ikarus::mem_getaddress_init() { /* nop */ }

void Ikarus::mem_replacefunc(phoenix::func dest, phoenix::func func) {
void Ikarus::mem_replacefunc(zenkit::DaedalusFunction dest, zenkit::DaedalusFunction func) {
auto* sf = func.value;
auto* sd = dest.value;
Log::d("mem_replacefunc: ",sd->name()," -> ",sf->name());
Expand Down Expand Up @@ -257,7 +257,7 @@ void Ikarus::mem_printstacktrace_implementation() {
Log::e("[end of stacktrace]");
}

int Ikarus::mem_getfuncoffset(phoenix::func func) {
int Ikarus::mem_getfuncoffset(zenkit::DaedalusFunction func) {
auto* sym = func.value;
if(sym == nullptr) {
Log::e("mem_getfuncptr: invalid function ptr");
Expand All @@ -266,7 +266,7 @@ int Ikarus::mem_getfuncoffset(phoenix::func func) {
return int(sym->address());
}

int Ikarus::mem_getfuncid(phoenix::func func) {
int Ikarus::mem_getfuncid(zenkit::DaedalusFunction func) {
return int(func.value->index());
}

Expand Down Expand Up @@ -302,8 +302,8 @@ void Ikarus::mem_copybytes(int src, int dst, int size) {
}

std::string Ikarus::mem_readstring(int address) {
const size_t symIndex = (size_t(address) - symbolsPtr)/sizeof(phoenix::symbol);
const size_t sub = (size_t(address) - symbolsPtr)%sizeof(phoenix::symbol);
const size_t symIndex = (size_t(address) - symbolsPtr)/sizeof(zenkit::DaedalusSymbol);
const size_t sub = (size_t(address) - symbolsPtr)%sizeof(zenkit::DaedalusSymbol);
if(symIndex>=vm.symbols().size() || sub!=0)
return "";
auto& s = vm.symbols()[symIndex];
Expand All @@ -324,7 +324,7 @@ int Ikarus::mem_getsymbolindex(std::string_view name) {
}

int Ikarus::mem_getsymbolbyindex(int index) {
return int(ptr32_t(symbolsPtr + size_t(index)*sizeof(phoenix::symbol)));
return int(ptr32_t(symbolsPtr + size_t(index)*sizeof(zenkit::DaedalusSymbol)));
}

int Ikarus::mem_getsystemtime() {
Expand Down Expand Up @@ -434,38 +434,38 @@ int Ikarus::mem_realloc(int address, int oldsz, int size) {
return int32_t(ptr);
}

std::shared_ptr<phoenix::instance> Ikarus::mem_ptrtoinst(ptr32_t address) {
std::shared_ptr<zenkit::DaedalusInstance> Ikarus::mem_ptrtoinst(ptr32_t address) {
if(address==0)
Log::d("mem_ptrtoinst: address is null");
return std::make_shared<memory_instance>(*this, address);
}

phoenix::naked_call Ikarus::repeat(phoenix::vm& vm) {
const int len = vm.pop_int();
phoenix::symbol* i = std::get<phoenix::symbol*>(vm.pop_reference());
zenkit::DaedalusNakedCall Ikarus::repeat(zenkit::DaedalusVm& vm) {
const int len = vm.pop_int();
zenkit::DaedalusSymbol* i = std::get<zenkit::DaedalusSymbol*>(vm.pop_reference());
// Log::i("repeat: ", i->get_int(), " < ", len);
if(i->get_int() < len) {
loop_start.push_back({vm.pc(), i, len});
return phoenix::naked_call();
return zenkit::DaedalusNakedCall();
}
loop_out(vm);
return phoenix::naked_call();
return zenkit::DaedalusNakedCall();
}

phoenix::naked_call Ikarus::while_(phoenix::vm& vm) {
zenkit::DaedalusNakedCall Ikarus::while_(zenkit::DaedalusVm& vm) {
const int cond = vm.pop_int();
// Log::i("while: ", cond);
if(cond !=0) {
loop_start.push_back({vm.pc() - 5*2, nullptr});
return phoenix::naked_call();
return zenkit::DaedalusNakedCall();
}
loop_out(vm);
return phoenix::naked_call();
return zenkit::DaedalusNakedCall();
}

void Ikarus::loop_trap(phoenix::symbol* i) {
void Ikarus::loop_trap(zenkit::DaedalusSymbol* i) {
auto instr = vm.instruction_at(vm.pc());
if(instr.op != phoenix::opcode::pushv)
if(instr.op != zenkit::DaedalusOpcode::pushv)
return; // Ikarus keywords are always use pushv

// Log::i("end");
Expand All @@ -486,7 +486,7 @@ void Ikarus::loop_trap(phoenix::symbol* i) {
vm.unsafe_jump(ret.pc-trap.size);
}

void Ikarus::loop_out(phoenix::vm& vm) {
void Ikarus::loop_out(zenkit::DaedalusVm& vm) {
auto end = vm.find_symbol_by_name("END");
auto rep = vm.find_symbol_by_name("REPEAT");
auto whl = vm.find_symbol_by_name("WHILE");
Expand All @@ -497,13 +497,13 @@ void Ikarus::loop_out(phoenix::vm& vm) {
int depth = 0;
for(uint32_t i=vm.pc(); i<vm.size(); ) {
const auto inst = vm.instruction_at(i);
if(inst.op==phoenix::opcode::pushv && vm.find_symbol_by_index(inst.symbol)==end) {
if(inst.op==zenkit::DaedalusOpcode::pushv && vm.find_symbol_by_index(inst.symbol)==end) {
depth--;
}
else if(inst.op==phoenix::opcode::bl && inst.address==repAddr) {
else if(inst.op==zenkit::DaedalusOpcode::bl && inst.address==repAddr) {
depth++;
}
else if(inst.op==phoenix::opcode::bl && inst.address==whlAddr) {
else if(inst.op==zenkit::DaedalusOpcode::bl && inst.address==whlAddr) {
depth++;
}
i += inst.size;
Expand Down
44 changes: 22 additions & 22 deletions game/game/compatibility/ikarus.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ class GameScript;

class Ikarus : public ScriptPlugin {
public:
Ikarus(GameScript& owner, phoenix::vm& vm);
Ikarus(GameScript& owner, zenkit::DaedalusVm& vm);

static bool isRequired(phoenix::script& vm);
static bool isRequired(zenkit::DaedalusScript& vm);

using ptr32_t = Mem32::ptr32_t;

struct memory_instance : public phoenix::transient_instance {
struct memory_instance : public zenkit::DaedalusTransientInstance {
explicit memory_instance(Ikarus &owner, ptr32_t address) : owner(owner), address(address) {}

void set_int(phoenix::symbol const& sym, uint16_t index, std::int32_t value) override;
std::int32_t get_int(phoenix::symbol const& sym, uint16_t index) const override;
void set_int(zenkit::DaedalusSymbol const& sym, uint16_t index, std::int32_t value) override;
std::int32_t get_int(zenkit::DaedalusSymbol const& sym, uint16_t index) const override;

void set_float(phoenix::symbol const& sym, uint16_t index, float value) override;
float get_float(phoenix::symbol const& sym, uint16_t index) const override;
void set_float(zenkit::DaedalusSymbol const& sym, uint16_t index, float value) override;
float get_float(zenkit::DaedalusSymbol const& sym, uint16_t index) const override;

void set_string(phoenix::symbol const& sym, uint16_t index, std::string_view value) override;
const std::string& get_string(phoenix::symbol const& sym, uint16_t index) const override;
void set_string(zenkit::DaedalusSymbol const& sym, uint16_t index, std::string_view value) override;
const std::string& get_string(zenkit::DaedalusSymbol const& sym, uint16_t index) const override;

Ikarus &owner;
ptr32_t address = 0;
Expand Down Expand Up @@ -69,11 +69,11 @@ class Ikarus : public ScriptPlugin {
void mem_setupexceptionhandler ();
void mem_getaddress_init ();
void mem_printstacktrace_implementation();
int mem_getfuncoffset (phoenix::func func);
int mem_getfuncid (phoenix::func func);
int mem_getfuncoffset (zenkit::DaedalusFunction func);
int mem_getfuncid (zenkit::DaedalusFunction func);
void mem_callbyid (int symbId);
int mem_getfuncptr (int symbId);
void mem_replacefunc (phoenix::func dest, phoenix::func func);
void mem_replacefunc (zenkit::DaedalusFunction dest, zenkit::DaedalusFunction func);
int mem_getfuncidbyoffset (int off);
void mem_assigninst (int sym, int ptr);

Expand All @@ -88,7 +88,7 @@ class Ikarus : public ScriptPlugin {
void mem_copybytes (int src, int dst, int size);
std::string mem_readstring (int address);
// pointers
std::shared_ptr<phoenix::instance> mem_ptrtoinst(ptr32_t address);
std::shared_ptr<zenkit::DaedalusInstance> mem_ptrtoinst(ptr32_t address);

// ## Basic zCParser related functions ##
int _takeref (int val);
Expand All @@ -110,21 +110,21 @@ class Ikarus : public ScriptPlugin {
void mem_setgothopt (std::string_view section, std::string_view option, std::string_view value);

// control-flow
phoenix::naked_call repeat (phoenix::vm& vm);
phoenix::naked_call while_ (phoenix::vm& vm);
void loop_trap(phoenix::symbol* i);
void loop_out(phoenix::vm& vm);
zenkit::DaedalusNakedCall repeat (zenkit::DaedalusVm& vm);
zenkit::DaedalusNakedCall while_ (zenkit::DaedalusVm& vm);
void loop_trap(zenkit::DaedalusSymbol* i);
void loop_out (zenkit::DaedalusVm& vm);

void call__stdcall(int address);
int hash(int x);

phoenix::vm& vm;
Mem32 allocator;
zenkit::DaedalusVm& vm;
Mem32 allocator;

struct Loop {
uint32_t pc = 0;
phoenix::symbol* i = nullptr;
int32_t loopLen = 0;
uint32_t pc = 0;
zenkit::DaedalusSymbol* i = nullptr;
int32_t loopLen = 0;
};
std::vector<Loop> loop_start;

Expand Down
Loading

0 comments on commit 26b816e

Please sign in to comment.