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.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef SAVEABLE_H
|
|
|
|
#define SAVEABLE_H
|
|
|
|
|
2019-11-28 23:22:01 +00:00
|
|
|
#include "compat.h"
|
2019-10-09 16:09:05 +00:00
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
typedef void *saveable_code;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void *base;
|
|
|
|
unsigned int size;
|
|
|
|
} saveable_data;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
saveable_code *code;
|
|
|
|
unsigned int numcode;
|
|
|
|
|
|
|
|
saveable_data *data;
|
|
|
|
unsigned int numdata;
|
|
|
|
} saveable_module;
|
|
|
|
|
2019-11-28 23:22:01 +00:00
|
|
|
template <typename T>
|
2020-09-04 19:24:48 +00:00
|
|
|
constexpr enable_if_t<!std::is_pointer<T>::value, size_t> SAVE_SIZEOF(T const & obj) noexcept
|
2019-11-28 23:22:01 +00:00
|
|
|
{
|
|
|
|
return sizeof(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SAVE_CODE(s) (void*)(s)
|
|
|
|
#define SAVE_DATA(s) { (void*)&(s), SAVE_SIZEOF(s) }
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-11-28 23:22:01 +00:00
|
|
|
#define NUM_SAVEABLE_ITEMS(x) ARRAY_SIZE(x)
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned int module;
|
|
|
|
unsigned int index;
|
|
|
|
} savedcodesym;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned int module;
|
|
|
|
unsigned int index;
|
|
|
|
unsigned int offset;
|
|
|
|
} saveddatasym;
|
|
|
|
|
|
|
|
void Saveable_Init(void);
|
2019-11-28 23:22:01 +00:00
|
|
|
void Saveable_Init_Dynamic(void);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
int Saveable_FindCodeSym(void *ptr, savedcodesym *sym);
|
|
|
|
int Saveable_FindDataSym(void *ptr, saveddatasym *sym);
|
|
|
|
|
|
|
|
int Saveable_RestoreCodeSym(savedcodesym *sym, void **ptr);
|
|
|
|
int Saveable_RestoreDataSym(saveddatasym *sym, void **ptr);
|
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
#endif
|