2015-05-19 21:54:34 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2005 Jonathon Fowler <jf@jonof.id.au>
|
|
|
|
|
|
|
|
This file is part of JFShadowWarrior
|
|
|
|
|
|
|
|
Shadow Warrior is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
#include "ns.h"
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "compat.h"
|
2020-01-22 21:49:51 +00:00
|
|
|
#include "tarray.h"
|
2019-10-09 17:58:09 +00:00
|
|
|
BEGIN_SW_NS
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "saveable.h"
|
|
|
|
|
2020-01-22 21:49:51 +00:00
|
|
|
static TArray<saveable_module*> saveablemodules;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
void Saveable_Init(void)
|
|
|
|
{
|
2020-01-22 21:49:51 +00:00
|
|
|
if (saveablemodules.Size() > 0) return;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-11-28 23:22:01 +00:00
|
|
|
Saveable_Init_Dynamic();
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
#define MODULE(x) { \
|
|
|
|
extern saveable_module saveable_ ## x; \
|
2020-01-22 21:49:51 +00:00
|
|
|
saveablemodules.Push(&saveable_ ## x); \
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE(actor)
|
|
|
|
MODULE(ai)
|
|
|
|
MODULE(build)
|
|
|
|
MODULE(bunny)
|
|
|
|
MODULE(coolg)
|
|
|
|
MODULE(coolie)
|
|
|
|
MODULE(eel)
|
|
|
|
MODULE(girlninj)
|
|
|
|
MODULE(goro)
|
|
|
|
MODULE(hornet)
|
|
|
|
MODULE(jweapon)
|
|
|
|
MODULE(lava)
|
|
|
|
MODULE(miscactr)
|
|
|
|
MODULE(morph)
|
|
|
|
MODULE(ninja)
|
|
|
|
MODULE(panel)
|
|
|
|
MODULE(player)
|
|
|
|
MODULE(quake)
|
|
|
|
MODULE(ripper)
|
|
|
|
MODULE(ripper2)
|
|
|
|
MODULE(rotator)
|
|
|
|
MODULE(serp)
|
|
|
|
MODULE(skel)
|
|
|
|
MODULE(skull)
|
|
|
|
MODULE(slidor)
|
|
|
|
MODULE(spike)
|
|
|
|
MODULE(sprite)
|
|
|
|
MODULE(sumo)
|
|
|
|
MODULE(track)
|
|
|
|
MODULE(vator)
|
|
|
|
MODULE(wallmove)
|
|
|
|
MODULE(weapon)
|
|
|
|
MODULE(zilla)
|
|
|
|
MODULE(zombie)
|
|
|
|
|
|
|
|
MODULE(sector)
|
2020-01-22 21:49:51 +00:00
|
|
|
MODULE(text)
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Saveable_FindCodeSym(void *ptr, savedcodesym *sym)
|
|
|
|
{
|
|
|
|
unsigned m,i;
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
sym->module = 0; // module 0 is the "null module" for null pointers
|
|
|
|
sym->index = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:49:51 +00:00
|
|
|
for (m=0; m<saveablemodules.Size(); m++)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
for (i=0; i<saveablemodules[m]->numcode; i++)
|
|
|
|
{
|
|
|
|
if (ptr != saveablemodules[m]->code[i]) continue;
|
|
|
|
|
|
|
|
sym->module = 1+m;
|
|
|
|
sym->index = i;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Saveable_FindDataSym(void *ptr, saveddatasym *sym)
|
|
|
|
{
|
|
|
|
unsigned m,i;
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
sym->module = 0;
|
|
|
|
sym->index = 0;
|
|
|
|
sym->offset = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:49:51 +00:00
|
|
|
for (m = 0; m < saveablemodules.Size(); m++)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
for (i=0; i<saveablemodules[m]->numdata; i++)
|
|
|
|
{
|
|
|
|
if (ptr < saveablemodules[m]->data[i].base) continue;
|
|
|
|
if (ptr >= (void *)((intptr_t)saveablemodules[m]->data[i].base +
|
|
|
|
saveablemodules[m]->data[i].size)) continue;
|
|
|
|
|
|
|
|
sym->module = 1+m;
|
|
|
|
sym->index = i;
|
|
|
|
sym->offset = (intptr_t)ptr - (intptr_t)saveablemodules[m]->data[i].base;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Saveable_RestoreCodeSym(savedcodesym *sym, void **ptr)
|
|
|
|
{
|
|
|
|
if (sym->module == 0)
|
|
|
|
{
|
|
|
|
*ptr = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:49:51 +00:00
|
|
|
if (sym->module > saveablemodules.Size()) return -1;
|
2015-05-19 21:54:34 +00:00
|
|
|
if (sym->index >= saveablemodules[sym->module-1]->numcode) return -1;
|
|
|
|
|
|
|
|
*ptr = saveablemodules[sym->module-1]->code[sym->index];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Saveable_RestoreDataSym(saveddatasym *sym, void **ptr)
|
|
|
|
{
|
|
|
|
if (sym->module == 0)
|
|
|
|
{
|
|
|
|
*ptr = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:49:51 +00:00
|
|
|
if (sym->module > saveablemodules.Size()) return -1;
|
2015-05-19 21:54:34 +00:00
|
|
|
if (sym->index >= saveablemodules[sym->module-1]->numdata) return -1;
|
|
|
|
if (sym->offset >= saveablemodules[sym->module-1]->data[sym->index].size) return -1;
|
|
|
|
|
|
|
|
*ptr = (void *)((intptr_t)saveablemodules[sym->module-1]->data[sym->index].base + sym->offset);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-10-09 16:09:05 +00:00
|
|
|
END_SW_NS
|